Merge pull request #6683 from Microsoft/strip_quotes_in_modules_names

strip quotes from module names during deduplication
This commit is contained in:
Vladimir Matveev 2016-01-27 20:05:32 -08:00
commit 0981719bed
4 changed files with 85 additions and 3 deletions

View File

@ -7068,14 +7068,22 @@ const _super = (function (geti, seti) {
for (let i = 0; i < externalImports.length; i++) {
const text = getExternalModuleNameText(externalImports[i], emitRelativePathAsModuleName);
if (hasProperty(groupIndices, text)) {
if (text === undefined) {
continue;
}
// text should be quoted string
// for deduplication purposes in key remove leading and trailing quotes so 'a' and "a" will be considered the same
const key = text.substr(1, text.length - 2);
if (hasProperty(groupIndices, key)) {
// deduplicate/group entries in dependency list by the dependency name
const groupIndex = groupIndices[text];
const groupIndex = groupIndices[key];
dependencyGroups[groupIndex].push(externalImports[i]);
continue;
}
else {
groupIndices[text] = dependencyGroups.length;
groupIndices[key] = dependencyGroups.length;
dependencyGroups.push([externalImports[i]]);
}

View File

@ -0,0 +1,32 @@
tests/cases/compiler/deduplicateImportsInSystem.ts(1,17): error TS2307: Cannot find module 'f1'.
tests/cases/compiler/deduplicateImportsInSystem.ts(2,17): error TS2307: Cannot find module 'f2'.
tests/cases/compiler/deduplicateImportsInSystem.ts(3,17): error TS2307: Cannot find module 'f3'.
tests/cases/compiler/deduplicateImportsInSystem.ts(4,17): error TS2307: Cannot find module 'f2'.
tests/cases/compiler/deduplicateImportsInSystem.ts(5,17): error TS2307: Cannot find module 'f2'.
tests/cases/compiler/deduplicateImportsInSystem.ts(6,17): error TS2307: Cannot find module 'f1'.
tests/cases/compiler/deduplicateImportsInSystem.ts(8,1): error TS2304: Cannot find name 'console'.
==== tests/cases/compiler/deduplicateImportsInSystem.ts (7 errors) ====
import {A} from "f1";
~~~~
!!! error TS2307: Cannot find module 'f1'.
import {B} from "f2";
~~~~
!!! error TS2307: Cannot find module 'f2'.
import {C} from "f3";
~~~~
!!! error TS2307: Cannot find module 'f3'.
import {D} from 'f2';
~~~~
!!! error TS2307: Cannot find module 'f2'.
import {E} from "f2";
~~~~
!!! error TS2307: Cannot find module 'f2'.
import {F} from 'f1';
~~~~
!!! error TS2307: Cannot find module 'f1'.
console.log(A + B + C + D + E + F)
~~~~~~~
!!! error TS2304: Cannot find name 'console'.

View File

@ -0,0 +1,33 @@
//// [deduplicateImportsInSystem.ts]
import {A} from "f1";
import {B} from "f2";
import {C} from "f3";
import {D} from 'f2';
import {E} from "f2";
import {F} from 'f1';
console.log(A + B + C + D + E + F)
//// [deduplicateImportsInSystem.js]
System.register(["f1", "f2", "f3"], function(exports_1) {
"use strict";
var f1_1, f2_1, f3_1, f2_2, f2_3, f1_2;
return {
setters:[
function (f1_1_1) {
f1_1 = f1_1_1;
f1_2 = f1_1_1;
},
function (f2_1_1) {
f2_1 = f2_1_1;
f2_2 = f2_1_1;
f2_3 = f2_1_1;
},
function (f3_1_1) {
f3_1 = f3_1_1;
}],
execute: function() {
console.log(f1_1.A + f2_1.B + f3_1.C + f2_2.D + f2_3.E + f1_2.F);
}
}
});

View File

@ -0,0 +1,9 @@
// @module: system
import {A} from "f1";
import {B} from "f2";
import {C} from "f3";
import {D} from 'f2';
import {E} from "f2";
import {F} from 'f1';
console.log(A + B + C + D + E + F)