-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Package scopes #4913
Package scopes #4913
Changes from 4 commits
ecf7c1d
c232afc
b2cd788
02166e2
cb6e430
3bfd92a
314cfc1
c89ef0b
ffb38da
ab269f6
1e32030
ae158ad
3e58162
f86c28d
4224586
149a1d9
22c6377
312d97c
b1ea98c
d32cedb
340702e
41c21b5
fd33df3
733db05
1163d38
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,7 +123,9 @@ namespace ts { | |
let anySignature = createSignature(undefined, undefined, emptyArray, anyType, undefined, 0, false, false); | ||
let unknownSignature = createSignature(undefined, undefined, emptyArray, unknownType, undefined, 0, false, false); | ||
|
||
let globals: SymbolTable = {}; | ||
let globalScope: Scope = { | ||
symbols: {} | ||
}; | ||
|
||
let globalESSymbolConstructorSymbol: Symbol; | ||
|
||
|
@@ -423,6 +425,12 @@ namespace ts { | |
} | ||
switch (location.kind) { | ||
case SyntaxKind.SourceFile: | ||
if ((<SourceFile>location).package) { | ||
if (hasProperty((<SourceFile>location).package.symbols, name)) { | ||
result = (<SourceFile>location).package.symbols[name]; | ||
break loop; | ||
} | ||
} | ||
if (!isExternalModule(<SourceFile>location)) break; | ||
case SyntaxKind.ModuleDeclaration: | ||
let moduleExports = getSymbolOfNode(location).exports; | ||
|
@@ -575,7 +583,7 @@ namespace ts { | |
} | ||
|
||
if (!result) { | ||
result = getSymbol(globals, name, meaning); | ||
result = getSymbol(globalScope.symbols, name, meaning); | ||
} | ||
|
||
if (!result) { | ||
|
@@ -970,7 +978,8 @@ namespace ts { | |
} | ||
let isRelative = isExternalModuleNameRelative(moduleName); | ||
if (!isRelative) { | ||
let symbol = getSymbol(globals, "\"" + moduleName + "\"", SymbolFlags.ValueModule); | ||
let file = getSourceFileOfNode(location); | ||
let symbol = getSymbol(file.package ? file.package.symbols : globalScope.symbols, "\"" + moduleName + "\"", SymbolFlags.ValueModule); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if (symbol) { | ||
return symbol; | ||
} | ||
|
@@ -1178,6 +1187,11 @@ namespace ts { | |
} | ||
switch (location.kind) { | ||
case SyntaxKind.SourceFile: | ||
if ((<SourceFile>location).package) { | ||
if (result = callback((<SourceFile>location).package.symbols)) { | ||
return result; | ||
} | ||
} | ||
if (!isExternalModule(<SourceFile>location)) { | ||
break; | ||
} | ||
|
@@ -1195,7 +1209,7 @@ namespace ts { | |
} | ||
} | ||
|
||
return callback(globals); | ||
return callback(globalScope.symbols); | ||
} | ||
|
||
function getQualifiedLeftMeaning(rightMeaning: SymbolFlags) { | ||
|
@@ -13871,6 +13885,9 @@ namespace ts { | |
|
||
switch (location.kind) { | ||
case SyntaxKind.SourceFile: | ||
if ((<SourceFile>location).package) { | ||
copySymbols((<SourceFile>location).package.symbols, meaning); | ||
} | ||
if (!isExternalModule(<SourceFile>location)) { | ||
break; | ||
} | ||
|
@@ -13913,7 +13930,7 @@ namespace ts { | |
location = location.parent; | ||
} | ||
|
||
copySymbols(globals, meaning); | ||
copySymbols(globalScope.symbols, meaning); | ||
} | ||
|
||
/** | ||
|
@@ -14525,7 +14542,11 @@ namespace ts { | |
} | ||
|
||
function hasGlobalName(name: string): boolean { | ||
return hasProperty(globals, name); | ||
return hasProperty(globalScope.symbols, name); | ||
} | ||
|
||
function hasPackageInternalName(file: SourceFile, name: string): boolean { | ||
return file.package && hasProperty(file.package.symbols, name); | ||
} | ||
|
||
function getReferencedValueSymbol(reference: Identifier): Symbol { | ||
|
@@ -14587,6 +14608,7 @@ namespace ts { | |
isNestedRedeclaration, | ||
isValueAliasDeclaration, | ||
hasGlobalName, | ||
hasPackageInternalName, | ||
isReferencedAliasDeclaration, | ||
getNodeCheckFlags, | ||
isTopLevelValueImportEqualsWithEntityName, | ||
|
@@ -14612,18 +14634,28 @@ namespace ts { | |
bindSourceFile(file); | ||
}); | ||
|
||
// Initialize global symbol table | ||
let packages: Map<PackageDescriptor> = {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
// Initialize package/global symbol table(s) | ||
forEach(host.getSourceFiles(), file => { | ||
if (!isExternalModule(file)) { | ||
mergeSymbolTable(globals, file.locals); | ||
if (file.package) { | ||
if (!packages[file.package.packageFile]) { | ||
packages[file.package.packageFile] = file.package; | ||
} | ||
file.package = packages[file.package.packageFile]; // Dedupe packages | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be in an |
||
mergeSymbolTable(file.package.symbols, file.locals); | ||
} else { | ||
mergeSymbolTable(globalScope.symbols, file.locals); | ||
} | ||
} | ||
}); | ||
|
||
// Initialize special symbols | ||
getSymbolLinks(undefinedSymbol).type = undefinedType; | ||
getSymbolLinks(argumentsSymbol).type = getGlobalType("IArguments"); | ||
getSymbolLinks(unknownSymbol).type = unknownType; | ||
globals[undefinedSymbol.name] = undefinedSymbol; | ||
globalScope.symbols[undefinedSymbol.name] = undefinedSymbol; | ||
// Initialize special types | ||
globalArrayType = <GenericType>getGlobalType("Array", /*arity*/ 1); | ||
globalObjectType = getGlobalType("Object"); | ||
|
@@ -14670,6 +14702,10 @@ namespace ts { | |
} | ||
|
||
anyArrayType = createArrayType(anyType); | ||
|
||
forEachValue(packages, package => { // Once all packages are merged and global scope is setup, merge global scope into each package | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move comment above |
||
mergeSymbolTable(package.symbols, globalScope.symbols); | ||
}); | ||
} | ||
|
||
function createInstantiatedPromiseLikeType(): ObjectType { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get why it's nice to have this, but you don't actually end up using
globalScope
on its own - we always just grabsymbols
anyhow.