mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-11-18 20:11:14 +00:00
Cleanup in binder: rename and move
This commit is contained in:
1 parent
4fdef85608
commit
d2b933e0d6
3 files changed
+25
-24
No files matched your search
+15
-15
@@ -2045,7 +2045,7 @@ namespace ts {
|
||||
bindThisPropertyAssignment(node as BinaryExpression);
|
||||
break;
|
||||
case SpecialPropertyAssignmentKind.Property:
|
||||
bindStaticBinaryExpressionAssignment(node as BinaryExpression);
|
||||
bindSpecialPropertyAssignment(node as BinaryExpression);
|
||||
break;
|
||||
case SpecialPropertyAssignmentKind.None:
|
||||
// Nothing to do
|
||||
@@ -2296,7 +2296,6 @@ namespace ts {
|
||||
}
|
||||
|
||||
function bindExportsPropertyAssignment(node: BinaryExpression) {
|
||||
// TODO: Maybe this should support nested exports too
|
||||
// When we create a property via 'exports.foo = bar', the 'exports.foo' property access
|
||||
// expression is the declaration
|
||||
setCommonJsModuleIndicator(node);
|
||||
@@ -2375,8 +2374,9 @@ namespace ts {
|
||||
}
|
||||
|
||||
|
||||
function bindStaticBinaryExpressionAssignment(node: BinaryExpression) {
|
||||
function bindSpecialPropertyAssignment(node: BinaryExpression) {
|
||||
const lhs = node.left as PropertyAccessEntityNameExpression;
|
||||
// Fix up parent pointers since we're going to use these nodes before we bind into them
|
||||
lhs.parent = node;
|
||||
if (isIdentifier(lhs.expression) && container === file && isNameOfExportsOrModuleExportsAliasDeclaration(file, lhs.expression)) {
|
||||
// This can be an alias for the 'exports' or 'module.exports' names, e.g.
|
||||
@@ -2388,26 +2388,16 @@ namespace ts {
|
||||
bindStaticPropertyAssignment(lhs);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For nodes like `x.y = z`, declare a member 'y' on 'x' if x is a function or class or {}, or not declared.
|
||||
* For nodes like `x.y = z`, declare a member 'y' on 'x' if x is a function (or IIFE) or class or {}, or not declared.
|
||||
* Also works for expression statements preceded by JSDoc, like / ** @type number * / x.y;
|
||||
*/
|
||||
function bindStaticPropertyAssignment(node: PropertyAccessEntityNameExpression) {
|
||||
// Fix up parent pointers since we're going to use these nodes before we bind into them
|
||||
node.expression.parent = node;
|
||||
bindPropertyAssignment(node.expression, node, /*isPrototypeProperty*/ false);
|
||||
}
|
||||
|
||||
function lookupSymbolForPropertyAccess(node: EntityNameExpression): Symbol | undefined {
|
||||
if (isIdentifier(node)) {
|
||||
return lookupSymbolForNameWorker(container, node.escapedText);
|
||||
}
|
||||
else {
|
||||
const symbol = getJSInitializerSymbol(lookupSymbolForPropertyAccess(node.expression));
|
||||
return symbol && symbol.exports && symbol.exports.get(node.name.escapedText);
|
||||
}
|
||||
}
|
||||
|
||||
function bindPropertyAssignment(name: EntityNameExpression, propertyAccess: PropertyAccessEntityNameExpression, isPrototypeProperty: boolean) {
|
||||
// Look up the property in the local scope, since property assignments should follow the declaration
|
||||
let symbol = getJSInitializerSymbol(lookupSymbolForPropertyAccess(name));
|
||||
@@ -2451,6 +2441,16 @@ namespace ts {
|
||||
declareSymbol(symbolTable, symbol, propertyAccess, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
|
||||
}
|
||||
|
||||
function lookupSymbolForPropertyAccess(node: EntityNameExpression): Symbol | undefined {
|
||||
if (isIdentifier(node)) {
|
||||
return lookupSymbolForNameWorker(container, node.escapedText);
|
||||
}
|
||||
else {
|
||||
const symbol = getJSInitializerSymbol(lookupSymbolForPropertyAccess(node.expression));
|
||||
return symbol && symbol.exports && symbol.exports.get(node.name.escapedText);
|
||||
}
|
||||
}
|
||||
|
||||
function forEachIdentifierInEntityName(e: EntityNameExpression, action: (e: Identifier, symbol: Symbol) => Symbol): Symbol {
|
||||
if (isIdentifier(e)) {
|
||||
return action(e, lookupSymbolForPropertyAccess(e));
|
||||
|
||||
@@ -14767,13 +14767,14 @@ namespace ts {
|
||||
let patternWithComputedProperties = false;
|
||||
let hasComputedStringProperty = false;
|
||||
let hasComputedNumberProperty = false;
|
||||
// TODO: This seems like it might be wrong, or at least should come earlier
|
||||
// (maybe check SymbolFlags.JSContainer? This currently misses normal declarations like `var my = {}`, but shouldn't)
|
||||
if (isInJSFile && node.symbol && node.symbol.exports && node.properties.length === 0) {
|
||||
const symbol = getMergedSymbol(node.symbol);
|
||||
propertiesTable = symbol.exports;
|
||||
symbol.exports.forEach(symbol => propertiesArray.push(getMergedSymbol(symbol)));
|
||||
return createObjectLiteralType();
|
||||
if (isInJSFile && node.properties.length === 0) {
|
||||
// an empty JS object literal that nonetheless has members is a JS namespace
|
||||
const symbol = getSymbolOfNode(node);
|
||||
if (symbol.exports) {
|
||||
propertiesTable = symbol.exports;
|
||||
symbol.exports.forEach(symbol => propertiesArray.push(getMergedSymbol(symbol)));
|
||||
return createObjectLiteralType();
|
||||
}
|
||||
}
|
||||
propertiesTable = createSymbolTable();
|
||||
|
||||
|
||||
@@ -34,9 +34,9 @@ var am;
|
||||
=== tests/cases/conformance/salsa/roots.js ===
|
||||
var Common = {};
|
||||
>Common : typeof Common
|
||||
>{} : { [x: string]: any; }
|
||||
>{} : { [x: string]: any; Item: typeof I; Object: typeof (Anonymous class); }
|
||||
|
||||
var Workspace = {};
|
||||
>Workspace : typeof Workspace
|
||||
>{} : { [x: string]: any; }
|
||||
>{} : { [x: string]: any; Object: typeof (Anonymous class); }
|
||||
|
||||
Reference in new issue
Block a user