Skip to content

Commit 0981719

Browse files
committed
Merge pull request #6683 from Microsoft/strip_quotes_in_modules_names
strip quotes from module names during deduplication
2 parents c353252 + 5b68d65 commit 0981719

File tree

4 files changed

+85
-3
lines changed

4 files changed

+85
-3
lines changed

src/compiler/emitter.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7068,14 +7068,22 @@ const _super = (function (geti, seti) {
70687068

70697069
for (let i = 0; i < externalImports.length; i++) {
70707070
const text = getExternalModuleNameText(externalImports[i], emitRelativePathAsModuleName);
7071-
if (hasProperty(groupIndices, text)) {
7071+
if (text === undefined) {
7072+
continue;
7073+
}
7074+
7075+
// text should be quoted string
7076+
// for deduplication purposes in key remove leading and trailing quotes so 'a' and "a" will be considered the same
7077+
const key = text.substr(1, text.length - 2);
7078+
7079+
if (hasProperty(groupIndices, key)) {
70727080
// deduplicate/group entries in dependency list by the dependency name
7073-
const groupIndex = groupIndices[text];
7081+
const groupIndex = groupIndices[key];
70747082
dependencyGroups[groupIndex].push(externalImports[i]);
70757083
continue;
70767084
}
70777085
else {
7078-
groupIndices[text] = dependencyGroups.length;
7086+
groupIndices[key] = dependencyGroups.length;
70797087
dependencyGroups.push([externalImports[i]]);
70807088
}
70817089

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
tests/cases/compiler/deduplicateImportsInSystem.ts(1,17): error TS2307: Cannot find module 'f1'.
2+
tests/cases/compiler/deduplicateImportsInSystem.ts(2,17): error TS2307: Cannot find module 'f2'.
3+
tests/cases/compiler/deduplicateImportsInSystem.ts(3,17): error TS2307: Cannot find module 'f3'.
4+
tests/cases/compiler/deduplicateImportsInSystem.ts(4,17): error TS2307: Cannot find module 'f2'.
5+
tests/cases/compiler/deduplicateImportsInSystem.ts(5,17): error TS2307: Cannot find module 'f2'.
6+
tests/cases/compiler/deduplicateImportsInSystem.ts(6,17): error TS2307: Cannot find module 'f1'.
7+
tests/cases/compiler/deduplicateImportsInSystem.ts(8,1): error TS2304: Cannot find name 'console'.
8+
9+
10+
==== tests/cases/compiler/deduplicateImportsInSystem.ts (7 errors) ====
11+
import {A} from "f1";
12+
~~~~
13+
!!! error TS2307: Cannot find module 'f1'.
14+
import {B} from "f2";
15+
~~~~
16+
!!! error TS2307: Cannot find module 'f2'.
17+
import {C} from "f3";
18+
~~~~
19+
!!! error TS2307: Cannot find module 'f3'.
20+
import {D} from 'f2';
21+
~~~~
22+
!!! error TS2307: Cannot find module 'f2'.
23+
import {E} from "f2";
24+
~~~~
25+
!!! error TS2307: Cannot find module 'f2'.
26+
import {F} from 'f1';
27+
~~~~
28+
!!! error TS2307: Cannot find module 'f1'.
29+
30+
console.log(A + B + C + D + E + F)
31+
~~~~~~~
32+
!!! error TS2304: Cannot find name 'console'.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//// [deduplicateImportsInSystem.ts]
2+
import {A} from "f1";
3+
import {B} from "f2";
4+
import {C} from "f3";
5+
import {D} from 'f2';
6+
import {E} from "f2";
7+
import {F} from 'f1';
8+
9+
console.log(A + B + C + D + E + F)
10+
11+
//// [deduplicateImportsInSystem.js]
12+
System.register(["f1", "f2", "f3"], function(exports_1) {
13+
"use strict";
14+
var f1_1, f2_1, f3_1, f2_2, f2_3, f1_2;
15+
return {
16+
setters:[
17+
function (f1_1_1) {
18+
f1_1 = f1_1_1;
19+
f1_2 = f1_1_1;
20+
},
21+
function (f2_1_1) {
22+
f2_1 = f2_1_1;
23+
f2_2 = f2_1_1;
24+
f2_3 = f2_1_1;
25+
},
26+
function (f3_1_1) {
27+
f3_1 = f3_1_1;
28+
}],
29+
execute: function() {
30+
console.log(f1_1.A + f2_1.B + f3_1.C + f2_2.D + f2_3.E + f1_2.F);
31+
}
32+
}
33+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @module: system
2+
import {A} from "f1";
3+
import {B} from "f2";
4+
import {C} from "f3";
5+
import {D} from 'f2';
6+
import {E} from "f2";
7+
import {F} from 'f1';
8+
9+
console.log(A + B + C + D + E + F)

0 commit comments

Comments
 (0)