Skip to content
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

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ecf7c1d
Some types - I'll get back to this
weswigham Sep 18, 2015
c232afc
trashy initial prototype - ironing out issues
weswigham Sep 19, 2015
b2cd788
Remove debug stuff, working package scopes
weswigham Sep 21, 2015
02166e2
merge with master
weswigham Sep 21, 2015
cb6e430
Merge branch 'master' into package-scopes
weswigham Oct 5, 2015
3bfd92a
Fix issues remaining form merge, lint
weswigham Oct 5, 2015
314cfc1
update tests
weswigham Oct 5, 2015
c89ef0b
another test, update unit tests to use equals, lint
weswigham Oct 6, 2015
ffb38da
another tests and lint
weswigham Oct 6, 2015
ab269f6
Merge branch 'master' into package-scopes
weswigham Oct 9, 2015
1e32030
Merge branch 'master' into package-scopes
weswigham Nov 10, 2015
ae158ad
cleaning up with changes form pr
weswigham Nov 10, 2015
3e58162
finish cleaning up pr lints
weswigham Nov 10, 2015
f86c28d
pull out export
weswigham Nov 10, 2015
4224586
Update with work items from PR
weswigham Nov 11, 2015
149a1d9
Merge branch 'master' into package-scopes
weswigham Nov 12, 2015
22c6377
Merge branch 'master' into package-scopes
weswigham Nov 13, 2015
312d97c
use relative paths for package names
weswigham Nov 13, 2015
b1ea98c
use ts.
weswigham Nov 13, 2015
d32cedb
move convertToRelativePath into core so the generateDiagnostics scrip…
weswigham Nov 14, 2015
340702e
Merge branch 'master' into package-scopes
weswigham Nov 17, 2015
41c21b5
fix lint
weswigham Nov 17, 2015
fd33df3
Merge branch 'master' into package-scopes
weswigham Nov 17, 2015
733db05
Merge branch 'master' into package-scopes
weswigham Nov 30, 2015
1163d38
accept baselines
weswigham Nov 30, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 45 additions & 9 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Copy link
Member

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 grab symbols anyhow.

symbols: {}
};

let globalESSymbolConstructorSymbol: Symbol;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -575,7 +583,7 @@ namespace ts {
}

if (!result) {
result = getSymbol(globals, name, meaning);
result = getSymbol(globalScope.symbols, name, meaning);
}

if (!result) {
Expand Down Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const

if (symbol) {
return symbol;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -1195,7 +1209,7 @@ namespace ts {
}
}

return callback(globals);
return callback(globalScope.symbols);
}

function getQualifiedLeftMeaning(rightMeaning: SymbolFlags) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -13913,7 +13930,7 @@ namespace ts {
location = location.parent;
}

copySymbols(globals, meaning);
copySymbols(globalScope.symbols, meaning);
}

/**
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -14587,6 +14608,7 @@ namespace ts {
isNestedRedeclaration,
isValueAliasDeclaration,
hasGlobalName,
hasPackageInternalName,
isReferencedAliasDeclaration,
getNodeCheckFlags,
isTopLevelValueImportEqualsWithEntityName,
Expand All @@ -14612,18 +14634,28 @@ namespace ts {
bindSourceFile(file);
});

// Initialize global symbol table
let packages: Map<PackageDescriptor> = {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const


// 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in an else, and move the comment to above the line.

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");
Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move comment above

mergeSymbolTable(package.symbols, globalScope.symbols);
});
}

function createInstantiatedPromiseLikeType(): ObjectType {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/diagnosticInformationMap.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ namespace ts {
A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums: { code: 2651, category: DiagnosticCategory.Error, key: "A member initializer in a enum declaration cannot reference members declared after it, including members defined in other enums." },
Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration_instead: { code: 2652, category: DiagnosticCategory.Error, key: "Merged declaration '{0}' cannot include a default export declaration. Consider adding a separate 'export default {0}' declaration instead." },
Non_abstract_class_expression_does_not_implement_inherited_abstract_member_0_from_class_1: { code: 2653, category: DiagnosticCategory.Error, key: "Non-abstract class expression does not implement inherited abstract member '{0}' from class '{1}'." },
Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition: { code: 2654, category: DiagnosticCategory.Error, key: "Exported external package typings file cannot contain tripleslash references. Please contact the package author to update the package definition." },
Exported_external_package_typings_file_cannot_contain_script_file_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition: { code: 2654, category: DiagnosticCategory.Error, key: "Exported external package typings file cannot contain script file tripleslash references. Please contact the package author to update the package definition." },
Exported_external_package_typings_can_only_be_in_d_ts_files_Please_contact_the_package_author_to_update_the_package_definition: { code: 2655, category: DiagnosticCategory.Error, key: "Exported external package typings can only be in '.d.ts' files. Please contact the package author to update the package definition." },
Exported_external_package_typings_file_0_is_not_a_module_Please_contact_the_package_author_to_update_the_package_definition: { code: 2656, category: DiagnosticCategory.Error, key: "Exported external package typings file '{0}' is not a module. Please contact the package author to update the package definition." },
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1704,7 +1704,7 @@
"category": "Error",
"code": 2653
},
"Exported external package typings file cannot contain tripleslash references. Please contact the package author to update the package definition.": {
"Exported external package typings file cannot contain script file tripleslash references. Please contact the package author to update the package definition.": {
"category": "Error",
"code": 2654
},
Expand Down
1 change: 1 addition & 0 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi

function isUniqueName(name: string): boolean {
return !resolver.hasGlobalName(name) &&
!resolver.hasPackageInternalName(currentSourceFile, name) &&
!hasProperty(currentSourceFile.identifiers, name) &&
!hasProperty(generatedNameSet, name);
}
Expand Down
Loading