Export the respective let binding when a decorated class is exported.

This commit is contained in:
Daniel Rosenwasser 2016-04-06 20:34:01 -07:00
parent f0839e6fc2
commit 42351a8a99

View File

@ -180,7 +180,7 @@ namespace ts {
function classElementVisitorWorker(node: Node): VisitResult<Node> {
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
)