[Release 2.1] fix11754 global augmentation (#12133)

* Exclude global augmentation from module resolution logic

* Address PR: check using string literal instead of NodeFlags.globalAugmentation
This commit is contained in:
Yui 2016-11-10 10:24:20 -08:00 committed by Mohamed Hegazy
parent 6ba4b87dc7
commit f7c40d3d61
6 changed files with 45 additions and 2 deletions

View File

@ -526,7 +526,9 @@ namespace ts {
const newSourceFilePath = getNormalizedAbsolutePath(newSourceFile.fileName, currentDirectory);
if (resolveModuleNamesWorker) {
const moduleNames = map(concatenate(newSourceFile.imports, newSourceFile.moduleAugmentations), getTextOfLiteral);
// Because global augmentation doesn't have string literal name, we can check for global augmentation as such.
const nonGlobalAugmentation = filter(newSourceFile.moduleAugmentations, (moduleAugmentation) => moduleAugmentation.kind === SyntaxKind.StringLiteral);
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);
@ -1290,7 +1292,9 @@ namespace ts {
collectExternalModuleReferences(file);
if (file.imports.length || file.moduleAugmentations.length) {
file.resolvedModules = createMap<ResolvedModule>();
const moduleNames = map(concatenate(file.imports, file.moduleAugmentations), getTextOfLiteral);
// Because global augmentation doesn't have string literal name, we can check for global augmentation as such.
const nonGlobalAugmentation = filter(file.moduleAugmentations, (moduleAugmentation) => moduleAugmentation.kind === SyntaxKind.StringLiteral);
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];

View File

@ -0,0 +1,10 @@
//// [a.ts]
export { };
declare global {
var x: number;
}
//// [a.js]
"use strict";

View File

@ -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))
}

View File

@ -0,0 +1,10 @@
=== tests/cases/conformance/externalModules/a.ts ===
export { };
declare global {
>global : any
var x: number;
>x : number
}

View File

@ -0,0 +1,8 @@
// @traceResolution: true
// @fileName: a.ts
export { };
declare global {
var x: number;
}