1import { 2 Bundle, 3 CatchClause, chainBundle, isBlock, Node, SourceFile, SyntaxKind, TransformationContext, TransformFlags, 4 visitEachChild, visitNode, VisitResult, 5} from "../_namespaces/ts"; 6 7/** @internal */ 8export function transformES2019(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle { 9 const factory = context.factory; 10 return chainBundle(context, transformSourceFile); 11 12 function transformSourceFile(node: SourceFile) { 13 if (node.isDeclarationFile) { 14 return node; 15 } 16 17 return visitEachChild(node, visitor, context); 18 } 19 20 function visitor(node: Node): VisitResult<Node> { 21 if ((node.transformFlags & TransformFlags.ContainsES2019) === 0) { 22 return node; 23 } 24 switch (node.kind) { 25 case SyntaxKind.CatchClause: 26 return visitCatchClause(node as CatchClause); 27 default: 28 return visitEachChild(node, visitor, context); 29 } 30 } 31 32 function visitCatchClause(node: CatchClause): CatchClause { 33 if (!node.variableDeclaration) { 34 return factory.updateCatchClause( 35 node, 36 factory.createVariableDeclaration(factory.createTempVariable(/*recordTempVariable*/ undefined)), 37 visitNode(node.block, visitor, isBlock) 38 ); 39 } 40 return visitEachChild(node, visitor, context); 41 } 42} 43