Skip to content

Commit bca3d01

Browse files
Limit scope of function expressions to themselves.
1 parent 035962b commit bca3d01

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

src/compiler/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,10 +1582,10 @@ module ts {
15821582
Tuple = 0x00002000, // Tuple
15831583
Union = 0x00004000, // Union
15841584
Anonymous = 0x00008000, // Anonymous
1585-
/* @internal */
1585+
/* @internal */
15861586
FromSignature = 0x00010000, // Created for signature assignment check
15871587
ObjectLiteral = 0x00020000, // Originates in an object literal
1588-
/* @internal */
1588+
/* @internal */
15891589
ContainsUndefinedOrNull = 0x00040000, // Type is or contains Undefined or Null type
15901590
/* @internal */
15911591
ContainsObjectLiteral = 0x00080000, // Type is or contains object literal type

src/services/services.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4988,18 +4988,6 @@ module ts {
49884988
return location.getText();
49894989
}
49904990

4991-
// Special case for function expressions, whose names are solely local to their bodies.
4992-
// TODO (drosen): Why would we have to lookup the interned name for a function expression?
4993-
// Shouldn't we have found a scope? Consider a 'Debug.fail()'.
4994-
let functionExpression: FunctionExpression;
4995-
if (symbol.valueDeclaration && symbol.valueDeclaration.kind === SyntaxKind.FunctionExpression) {
4996-
functionExpression = <FunctionExpression>symbol.valueDeclaration;
4997-
4998-
if (functionExpression.name) {
4999-
return functionExpression.name.text;
5000-
}
5001-
}
5002-
50034991
// Try to get the local symbol if we're dealing with an 'export default'
50044992
// since that symbol has the "true" name.
50054993
let localExportDefaultSymbol = getLocalSymbolForExportDefault(symbol);
@@ -5008,7 +4996,20 @@ module ts {
50084996
return stripQuotes(symbol.name);
50094997
}
50104998

4999+
/**
5000+
* Determines the smallest scope in which a symbol may have named references.
5001+
*
5002+
* Returns undefined if the scope cannot be determined, often implying that
5003+
* a reference to a symbol can occur anywhere.
5004+
*/
50115005
function getSymbolScope(symbol: Symbol): Node {
5006+
// If this is the symbol of a function expression, then named references
5007+
// are limited to its own scope.
5008+
let valueDeclaration = symbol.valueDeclaration;
5009+
if (valueDeclaration && valueDeclaration.kind === SyntaxKind.FunctionExpression) {
5010+
return valueDeclaration;
5011+
}
5012+
50125013
// If this is private property or method, the scope is the containing class
50135014
if (symbol.flags & (SymbolFlags.Property | SymbolFlags.Method)) {
50145015
let privateDeclaration = forEach(symbol.getDeclarations(), d => (d.flags & NodeFlags.Private) ? d : undefined);

0 commit comments

Comments
 (0)