Skip to content

Commit bee7d06

Browse files
committed
Binder-based prop-assignment decls: messy version
1 parent d4f6c8c commit bee7d06

3 files changed

Lines changed: 15 additions & 9 deletions

File tree

src/compiler/binder.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ namespace ts {
274274
}
275275
switch (node.kind) {
276276
case SyntaxKind.Identifier:
277-
// THIS IS WRONG
277+
// TODO: THIS IS WRONG
278278
return (node as any as Identifier).escapedText;
279279
case SyntaxKind.Constructor:
280280
return InternalSymbolName.Constructor;
@@ -2010,6 +2010,7 @@ namespace ts {
20102010
node.flowNode = currentFlow;
20112011
}
20122012
if (isSpecialPropertyDeclaration(node as PropertyAccessExpression)) {
2013+
// TODO: this is wrong now that I allow it anywhere
20132014
bindThisPropertyAssignment(node as PropertyAccessExpression);
20142015
}
20152016
break;
@@ -2397,17 +2398,21 @@ namespace ts {
23972398
if (targetSymbol && isDeclarationOfFunctionOrClassExpression(targetSymbol)) {
23982399
targetSymbol = (targetSymbol.valueDeclaration as VariableDeclaration).initializer.symbol;
23992400
}
2400-
if (isMagic && (!targetSymbol || !(targetSymbol.flags & SymbolFlags.Namespace))) {
2401-
// TODO: Magic may not be required
2402-
// TODO: Container.locals as symbolTable is probably wrong sometimes (maybe it's sometimes exports?)
2403-
// TODO: Container.symbol as parent is probably wrong sometimes
2404-
// TODO: propertyAccessExpression.expression isn't a Declaration
2405-
targetSymbol = declareSymbol(container.locals, container.symbol, propertyAccessExpression.expression as any as Declaration, SymbolFlags.NamespaceModule, SymbolFlags.NamespaceModuleExcludes);
2401+
Debug.assert(propertyAccessExpression.parent.kind === SyntaxKind.BinaryExpression);
2402+
if (isMagic &&
2403+
(!targetSymbol || !(targetSymbol.flags & SymbolFlags.Namespace)) &&
2404+
((propertyAccessExpression.parent as BinaryExpression).right.kind === SyntaxKind.ClassExpression || (propertyAccessExpression.parent as BinaryExpression).right.kind === SyntaxKind.FunctionExpression) &&
2405+
propertyAccessExpression.parent.parent.parent.kind === SyntaxKind.SourceFile) {
2406+
// TODO: Magic may not be required (but is so far)
2407+
Debug.assert(isIdentifier(propertyAccessExpression.expression));
2408+
// TODO: This should be exports if the tgargetSymbol is found, and already exported, otherwise locals
2409+
const symbolTable = container.symbol && container.symbol.exports ? container.symbol.exports : container.locals;
2410+
targetSymbol = declareSymbol(symbolTable, container.symbol, propertyAccessExpression.expression as Identifier, SymbolFlags.NamespaceModule, SymbolFlags.NamespaceModuleExcludes);
24062411
}
24072412
if (targetSymbol && isDeclarationOfFunctionOrClassExpression(targetSymbol)) {
24082413
targetSymbol = (targetSymbol.valueDeclaration as VariableDeclaration).initializer.symbol;
24092414
}
2410-
if (!isMagic && (!targetSymbol || !(targetSymbol.flags & (SymbolFlags.Function | SymbolFlags.Class)))) {
2415+
if (!targetSymbol || !(targetSymbol.flags & (SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.NamespaceModule))) {
24112416
return;
24122417
}
24132418

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ namespace ts {
633633
Node, // Unique name based on the node in the 'original' property.
634634
}
635635

636-
export interface Identifier extends PrimaryExpression {
636+
export interface Identifier extends PrimaryExpression, Declaration {
637637
kind: SyntaxKind.Identifier;
638638
/**
639639
* Prefer to use `id.unescapedText`. (Note: This is available only in services, not internally to the TypeScript compiler.)

src/services/services.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ namespace ts {
416416
_updateExpressionBrand: any;
417417
_unaryExpressionBrand: any;
418418
_expressionBrand: any;
419+
_declarationBrand: any;
419420
/*@internal*/typeArguments: NodeArray<TypeNode>;
420421
constructor(_kind: SyntaxKind.Identifier, pos: number, end: number) {
421422
super(pos, end);

0 commit comments

Comments
 (0)