From 5b68d6559a8e126fac23388e199be29c3dab9a97 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 27 Jan 2016 15:27:11 -0800 Subject: [PATCH] strip quotes from module names during deduplication --- src/compiler/emitter.ts | 14 ++++++-- .../deduplicateImportsInSystem.errors.txt | 32 ++++++++++++++++++ .../reference/deduplicateImportsInSystem.js | 33 +++++++++++++++++++ .../compiler/deduplicateImportsInSystem.ts | 9 +++++ 4 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 tests/baselines/reference/deduplicateImportsInSystem.errors.txt create mode 100644 tests/baselines/reference/deduplicateImportsInSystem.js create mode 100644 tests/cases/compiler/deduplicateImportsInSystem.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 0a40047f686..4d771bd2538 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -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]]); } diff --git a/tests/baselines/reference/deduplicateImportsInSystem.errors.txt b/tests/baselines/reference/deduplicateImportsInSystem.errors.txt new file mode 100644 index 00000000000..d1bfe88160e --- /dev/null +++ b/tests/baselines/reference/deduplicateImportsInSystem.errors.txt @@ -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'. \ No newline at end of file diff --git a/tests/baselines/reference/deduplicateImportsInSystem.js b/tests/baselines/reference/deduplicateImportsInSystem.js new file mode 100644 index 00000000000..956d293cad1 --- /dev/null +++ b/tests/baselines/reference/deduplicateImportsInSystem.js @@ -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); + } + } +}); diff --git a/tests/cases/compiler/deduplicateImportsInSystem.ts b/tests/cases/compiler/deduplicateImportsInSystem.ts new file mode 100644 index 00000000000..2fcbc16be05 --- /dev/null +++ b/tests/cases/compiler/deduplicateImportsInSystem.ts @@ -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) \ No newline at end of file