From 42351a8a99038e1cd600a33d424a1536caf9f5e6 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 6 Apr 2016 20:34:01 -0700 Subject: [PATCH] Export the respective let binding when a decorated class is exported. --- src/compiler/transformers/ts.ts | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 1d8dd46edee..d1e28c58911 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -180,7 +180,7 @@ namespace ts { function classElementVisitorWorker(node: Node): VisitResult { switch (node.kind) { case SyntaxKind.Constructor: - // TypeScript constructors are transformed in `transformClassDeclaration`. + // TypeScript constructors are transformed in `visitClassDeclaration`. // We elide them here as `visitorWorker` checks transform flags, which could // erronously include an ES6 constructor without TypeScript syntax. return undefined; @@ -257,7 +257,7 @@ namespace ts { // TypeScript index signatures are elided. case SyntaxKind.Decorator: - // TypeScript decorators are elided. They will be emitted as part of transformClassDeclaration. + // TypeScript decorators are elided. They will be emitted as part of visitClassDeclaration. case SyntaxKind.TypeAliasDeclaration: // TypeScript type-only declarations are elided. @@ -266,7 +266,7 @@ namespace ts { // TypeScript property declarations are elided. case SyntaxKind.Constructor: - // TypeScript constructors are transformed in `transformClassDeclaration`. + // TypeScript constructors are transformed in `visitClassDeclaration`. return undefined; case SyntaxKind.InterfaceDeclaration: @@ -601,11 +601,9 @@ namespace ts { addNode(statements, createVariableStatement( /*modifiers*/ undefined, - createVariableDeclarationList([ + createLetDeclarationList([ createVariableDeclaration(decoratedClassAlias) - ], - /*location*/ undefined, - NodeFlags.Let) + ]) ) ); @@ -616,19 +614,25 @@ namespace ts { /*location*/ node); } + // When emitting as a *default* export, we'll add a subsequent `export default` statement, + // so we should only be creating a local binding without any modifiers. + // Otherwise, we need preserve and visit all the modifiers. + const bindingModifiers = + isDefaultExternalModuleExport(node) + ? undefined + : visitNodes(node.modifiers, visitor, isModifier); + // let ${name} = ${classExpression}; addNode(statements, setOriginalNode( createVariableStatement( - /*modifiers*/ undefined, - createVariableDeclarationList([ + bindingModifiers, + createLetDeclarationList([ createVariableDeclaration( name, classExpression ) - ], - /*location*/ undefined, - NodeFlags.Let) + ]) ), /*original*/ node )