mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Fixed emit for decorated classes that eventually get exported.
This commit is contained in:
parent
e13a07e3bd
commit
482dfb61be
@ -561,8 +561,11 @@ namespace ts {
|
||||
function visitVariableStatement(node: VariableStatement): VisitResult<Statement> {
|
||||
// If the variable is for a generated declaration,
|
||||
// we should maintain it and just strip off the 'export' modifier if necesary.
|
||||
const original = getOriginalNode(node);
|
||||
if (original.kind === SyntaxKind.EnumDeclaration || original.kind === SyntaxKind.ModuleDeclaration) {
|
||||
const originalKind = getOriginalNode(node).kind;
|
||||
if (originalKind === SyntaxKind.ModuleDeclaration ||
|
||||
originalKind === SyntaxKind.EnumDeclaration ||
|
||||
originalKind === SyntaxKind.ClassDeclaration) {
|
||||
|
||||
if (!hasModifier(node, ModifierFlags.Export)) {
|
||||
return node;
|
||||
}
|
||||
@ -686,7 +689,10 @@ namespace ts {
|
||||
statements.push(node);
|
||||
}
|
||||
|
||||
if (node.name) {
|
||||
// Decorators end up creating a series of assignment expressions which overwrite
|
||||
// the local binding that we export, so we need to defer from exporting decorated classes
|
||||
// until the decoration assignments take place. We do this when visiting expression-statements.
|
||||
if (node.name && !(node.decorators && node.decorators.length)) {
|
||||
addExportMemberAssignments(statements, node.name);
|
||||
}
|
||||
|
||||
@ -696,9 +702,19 @@ namespace ts {
|
||||
function visitExpressionStatement(node: ExpressionStatement): VisitResult<Statement> {
|
||||
const original = getOriginalNode(node);
|
||||
const origKind = original.kind;
|
||||
|
||||
if (origKind === SyntaxKind.EnumDeclaration || origKind === SyntaxKind.ModuleDeclaration) {
|
||||
return visitExpressionStatementForEnumOrNamespaceDeclaration(node, <EnumDeclaration | ModuleDeclaration>original);
|
||||
}
|
||||
else if (origKind === SyntaxKind.ClassDeclaration) {
|
||||
// The decorated assignment for a class name will need to be transformed.
|
||||
const classDecl = original as ClassDeclaration;
|
||||
if (classDecl.name) {
|
||||
const statements = [node];
|
||||
addExportMemberAssignments(statements, classDecl.name);
|
||||
return statements;
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
@ -1304,7 +1304,7 @@ namespace ts {
|
||||
function addConstructorDecorationStatement(statements: Statement[], node: ClassDeclaration, decoratedClassAlias: Identifier) {
|
||||
const expression = generateConstructorDecorationExpression(node, decoratedClassAlias);
|
||||
if (expression) {
|
||||
statements.push(createStatement(expression));
|
||||
statements.push(setOriginalNode(createStatement(expression), node));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user