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

[Release 2.1] fix11754 global augmentation #12133

Merged
merged 2 commits into from
Nov 10, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
2 changes: 2 additions & 0 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5418,6 +5418,8 @@ namespace ts {
// parse 'global' as name of global scope augmentation
node.name = parseIdentifier();
node.flags |= NodeFlags.GlobalAugmentation;
// We need to store flags at the name as well so we can use it to filter out global augmentation from going through module resolution.
node.name.flags |= NodeFlags.GlobalAugmentation;
Copy link
Contributor

Choose a reason for hiding this comment

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

do not think you need a flag. it is going to be the only module augmentation whose name is not a string literal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that is true. though would it more confusing when we are checking it? I guess I can make comment about it

}
else {
node.name = parseLiteralNode(/*internName*/ true);
Expand Down
6 changes: 4 additions & 2 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,8 @@ namespace ts {

const newSourceFilePath = getNormalizedAbsolutePath(newSourceFile.fileName, currentDirectory);
if (resolveModuleNamesWorker) {
const moduleNames = map(concatenate(newSourceFile.imports, newSourceFile.moduleAugmentations), getTextOfLiteral);
const nonGlobalAugmentation = filter(newSourceFile.moduleAugmentations, (moduleAugmentation) => !(moduleAugmentation.flags & NodeFlags.GlobalAugmentation));
const moduleNames = map(concatenate(newSourceFile.imports, nonGlobalAugmentation), getTextOfLiteral);
const resolutions = resolveModuleNamesWorker(moduleNames, newSourceFilePath);
// ensure that module resolution results are still correct
const resolutionsChanged = hasChangesInResolutions(moduleNames, resolutions, oldSourceFile.resolvedModules, moduleResolutionIsEqualTo);
Expand Down Expand Up @@ -1290,7 +1291,8 @@ namespace ts {
collectExternalModuleReferences(file);
if (file.imports.length || file.moduleAugmentations.length) {
file.resolvedModules = createMap<ResolvedModule>();
const moduleNames = map(concatenate(file.imports, file.moduleAugmentations), getTextOfLiteral);
const nonGlobalAugmentation = filter(file.moduleAugmentations, (moduleAugmentation) => !(moduleAugmentation.flags & NodeFlags.GlobalAugmentation));
const moduleNames = map(concatenate(file.imports, nonGlobalAugmentation), getTextOfLiteral);
const resolutions = resolveModuleNamesWorker(moduleNames, getNormalizedAbsolutePath(file.fileName, currentDirectory));
for (let i = 0; i < moduleNames.length; i++) {
const resolution = resolutions[i];
Expand Down
10 changes: 10 additions & 0 deletions tests/baselines/reference/globalAugmentationModuleResolution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//// [a.ts]

export { };

declare global {
var x: number;
}

//// [a.js]
"use strict";
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
=== tests/cases/conformance/externalModules/a.ts ===

export { };

declare global {
>global : Symbol(global, Decl(a.ts, 1, 11))

var x: number;
>x : Symbol(x, Decl(a.ts, 4, 5))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
10 changes: 10 additions & 0 deletions tests/baselines/reference/globalAugmentationModuleResolution.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
=== tests/cases/conformance/externalModules/a.ts ===

export { };

declare global {
>global : any

var x: number;
>x : number
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @traceResolution: true

// @fileName: a.ts
export { };

declare global {
var x: number;
}