Skip to content

Commit 9b8b750

Browse files
committed
Always put assignments in locals.
This means that Javascript property assignments always create a namespace, never statics on a class. The ES5->ES6 class refactoring still needs to be updated.
1 parent ee5f91c commit 9b8b750

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

src/compiler/binder.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,12 @@ namespace ts {
428428
return symbol;
429429
}
430430

431-
function declareModuleMember(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags): Symbol {
432-
const hasExportModifier = getCombinedModifierFlags(node) & ModifierFlags.Export;
431+
function declareModuleMember(
432+
node: Declaration,
433+
symbolFlags: SymbolFlags,
434+
symbolExcludes: SymbolFlags,
435+
hasExportModifier = getCombinedModifierFlags(node) & ModifierFlags.Export
436+
): Symbol {
433437
if (symbolFlags & SymbolFlags.Alias) {
434438
if (node.kind === SyntaxKind.ExportSpecifier || (node.kind === SyntaxKind.ImportEqualsDeclaration && hasExportModifier)) {
435439
return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
@@ -2361,7 +2365,7 @@ namespace ts {
23612365
constructorFunction.parent = classPrototype;
23622366
classPrototype.parent = leftSideOfAssignment;
23632367

2364-
bindPropertyAssignment(constructorFunction.escapedText, leftSideOfAssignment, /*isPrototypeProperty*/ true, /*isMagic*/ false);
2368+
bindPropertyAssignment(constructorFunction.escapedText, leftSideOfAssignment, /*isPrototypeProperty*/ true);
23652369
}
23662370

23672371
function bindStaticPropertyAssignment(node: BinaryExpression) {
@@ -2384,7 +2388,7 @@ namespace ts {
23842388
bindExportsPropertyAssignment(node);
23852389
}
23862390
else {
2387-
bindPropertyAssignment(target.escapedText, leftSideOfAssignment, /*isPrototypeProperty*/ false, /*isMagic*/ true);
2391+
bindPropertyAssignment(target.escapedText, leftSideOfAssignment, /*isPrototypeProperty*/ false);
23882392
}
23892393
}
23902394
}
@@ -2393,26 +2397,28 @@ namespace ts {
23932397
return (container.symbol && container.symbol.exports && container.symbol.exports.get(name)) || (container.locals && container.locals.get(name));
23942398
}
23952399

2396-
function bindPropertyAssignment(functionName: __String, propertyAccessExpression: PropertyAccessExpression, isPrototypeProperty: boolean, isMagic: boolean) {
2400+
function bindPropertyAssignment(functionName: __String, propertyAccessExpression: PropertyAccessExpression, isPrototypeProperty: boolean) {
23972401
let targetSymbol = lookupSymbolForName(functionName);
2402+
targetSymbol = targetSymbol && targetSymbol.exportSymbol || targetSymbol;
23982403
if (targetSymbol && isDeclarationOfFunctionOrClassExpression(targetSymbol)) {
23992404
targetSymbol = (targetSymbol.valueDeclaration as VariableDeclaration).initializer.symbol;
24002405
}
24012406
Debug.assert(propertyAccessExpression.parent.kind === SyntaxKind.BinaryExpression);
2402-
if (isMagic &&
2407+
if (!isPrototypeProperty &&
24032408
(!targetSymbol || !(targetSymbol.flags & SymbolFlags.Namespace)) &&
2409+
// TODO: Rewrite to be easier to read
24042410
((propertyAccessExpression.parent as BinaryExpression).right.kind === SyntaxKind.ClassExpression || (propertyAccessExpression.parent as BinaryExpression).right.kind === SyntaxKind.FunctionExpression) &&
24052411
propertyAccessExpression.parent.parent.parent.kind === SyntaxKind.SourceFile) {
2406-
// TODO: Magic may not be required (but is so far)
2412+
// TODO: Update refactoring to understand that ES5 classes now have statics in a namespace instead
2413+
const hasExportModifier = getCombinedModifierFlags(targetSymbol.valueDeclaration) & ModifierFlags.Export;
24072414
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);
2415+
Debug.assertEqual(propertyAccessExpression.expression.kind, SyntaxKind.Identifier);
2416+
targetSymbol = declareModuleMember(propertyAccessExpression.expression as Identifier, SymbolFlags.NamespaceModule, SymbolFlags.NamespaceModuleExcludes, hasExportModifier);
24112417
}
24122418
if (targetSymbol && isDeclarationOfFunctionOrClassExpression(targetSymbol)) {
24132419
targetSymbol = (targetSymbol.valueDeclaration as VariableDeclaration).initializer.symbol;
24142420
}
2415-
if (!targetSymbol || !(targetSymbol.flags & (SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.NamespaceModule))) {
2421+
if (!targetSymbol || !(targetSymbol.flags & (SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.NamespaceModule | SymbolFlags.ExportValue))) {
24162422
return;
24172423
}
24182424

0 commit comments

Comments
 (0)