From bee7d06761bebbe2a935aeda740de9ec0e2dda8c Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Wed, 22 Nov 2017 13:52:45 -0800 Subject: [PATCH] Binder-based prop-assignment decls: messy version --- src/compiler/binder.ts | 21 +++++++++++++-------- src/compiler/types.ts | 2 +- src/services/services.ts | 1 + 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 94c2af92cdd..d82dd1053bd 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -274,7 +274,7 @@ namespace ts { } switch (node.kind) { case SyntaxKind.Identifier: - // THIS IS WRONG + // TODO: THIS IS WRONG return (node as any as Identifier).escapedText; case SyntaxKind.Constructor: return InternalSymbolName.Constructor; @@ -2010,6 +2010,7 @@ namespace ts { node.flowNode = currentFlow; } if (isSpecialPropertyDeclaration(node as PropertyAccessExpression)) { + // TODO: this is wrong now that I allow it anywhere bindThisPropertyAssignment(node as PropertyAccessExpression); } break; @@ -2397,17 +2398,21 @@ namespace ts { if (targetSymbol && isDeclarationOfFunctionOrClassExpression(targetSymbol)) { targetSymbol = (targetSymbol.valueDeclaration as VariableDeclaration).initializer.symbol; } - if (isMagic && (!targetSymbol || !(targetSymbol.flags & SymbolFlags.Namespace))) { - // TODO: Magic may not be required - // TODO: Container.locals as symbolTable is probably wrong sometimes (maybe it's sometimes exports?) - // TODO: Container.symbol as parent is probably wrong sometimes - // TODO: propertyAccessExpression.expression isn't a Declaration - targetSymbol = declareSymbol(container.locals, container.symbol, propertyAccessExpression.expression as any as Declaration, SymbolFlags.NamespaceModule, SymbolFlags.NamespaceModuleExcludes); + Debug.assert(propertyAccessExpression.parent.kind === SyntaxKind.BinaryExpression); + if (isMagic && + (!targetSymbol || !(targetSymbol.flags & SymbolFlags.Namespace)) && + ((propertyAccessExpression.parent as BinaryExpression).right.kind === SyntaxKind.ClassExpression || (propertyAccessExpression.parent as BinaryExpression).right.kind === SyntaxKind.FunctionExpression) && + propertyAccessExpression.parent.parent.parent.kind === SyntaxKind.SourceFile) { + // TODO: Magic may not be required (but is so far) + Debug.assert(isIdentifier(propertyAccessExpression.expression)); + // TODO: This should be exports if the tgargetSymbol is found, and already exported, otherwise locals + const symbolTable = container.symbol && container.symbol.exports ? container.symbol.exports : container.locals; + targetSymbol = declareSymbol(symbolTable, container.symbol, propertyAccessExpression.expression as Identifier, SymbolFlags.NamespaceModule, SymbolFlags.NamespaceModuleExcludes); } if (targetSymbol && isDeclarationOfFunctionOrClassExpression(targetSymbol)) { targetSymbol = (targetSymbol.valueDeclaration as VariableDeclaration).initializer.symbol; } - if (!isMagic && (!targetSymbol || !(targetSymbol.flags & (SymbolFlags.Function | SymbolFlags.Class)))) { + if (!targetSymbol || !(targetSymbol.flags & (SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.NamespaceModule))) { return; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 53c36ac6caa..9979139a913 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -633,7 +633,7 @@ namespace ts { Node, // Unique name based on the node in the 'original' property. } - export interface Identifier extends PrimaryExpression { + export interface Identifier extends PrimaryExpression, Declaration { kind: SyntaxKind.Identifier; /** * Prefer to use `id.unescapedText`. (Note: This is available only in services, not internally to the TypeScript compiler.) diff --git a/src/services/services.ts b/src/services/services.ts index d62fc88a649..f479a47f398 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -416,6 +416,7 @@ namespace ts { _updateExpressionBrand: any; _unaryExpressionBrand: any; _expressionBrand: any; + _declarationBrand: any; /*@internal*/typeArguments: NodeArray; constructor(_kind: SyntaxKind.Identifier, pos: number, end: number) { super(pos, end);