Skip to content

Commit 54ad3ae

Browse files
committed
Fix shouldEmitImportEqualsDeclaration
1 parent 4874e98 commit 54ad3ae

File tree

83 files changed

+289
-549
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+289
-549
lines changed

internal/transformers/tstransforms/importelision.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,10 @@ func (tx *ImportElisionTransformer) shouldEmitAliasDeclaration(node *ast.Node) b
124124
}
125125

126126
func (tx *ImportElisionTransformer) shouldEmitImportEqualsDeclaration(node *ast.ImportEqualsDeclaration) bool {
127-
if !tx.shouldEmitAliasDeclaration(node.AsNode()) {
128-
return false
129-
}
130-
if node.ModuleReference.Kind == ast.KindExternalModuleReference {
131-
return true
132-
}
133127
// preserve old compiler's behavior: emit import declaration (even if we do not consider them referenced) when
134128
// - current file is not external module
135129
// - import declaration is top level and target is value imported by entity name
136-
return tx.currentSourceFile != nil && ast.IsExternalModule(tx.currentSourceFile) && tx.isTopLevelValueImportEqualsWithEntityName(node.AsNode())
130+
return tx.shouldEmitAliasDeclaration(node.AsNode()) || (!ast.IsExternalModule(tx.currentSourceFile) && tx.isTopLevelValueImportEqualsWithEntityName(node.AsNode()))
137131
}
138132

139133
func (tx *ImportElisionTransformer) isReferencedAliasDeclaration(node *ast.Node) bool {

testdata/baselines/reference/submodule/compiler/aliasBug.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ var foo;
3737
})(baz = bar.baz || (bar.baz = {}));
3838
})(bar = foo.bar || (foo.bar = {}));
3939
})(foo || (foo = {}));
40+
var provide = foo;
4041
var p = new provide.Provide();
4142
function use() {
4243
var p1; // error here, but should be okay

testdata/baselines/reference/submodule/compiler/aliasBug.js.diff

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
--- old.aliasBug.js
22
+++ new.aliasBug.js
3-
@@= skipped -36, +36 lines =@@
4-
})(baz = bar.baz || (bar.baz = {}));
3+
@@= skipped -37, +37 lines =@@
54
})(bar = foo.bar || (foo.bar = {}));
65
})(foo || (foo = {}));
7-
-var provide = foo;
6+
var provide = foo;
87
-var booz = foo.bar.baz;
98
var p = new provide.Provide();
109
function use() {

testdata/baselines/reference/submodule/compiler/aliasErrors.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ var foo;
4848
})(baz = bar.baz || (bar.baz = {}));
4949
})(bar = foo.bar || (foo.bar = {}));
5050
})(foo || (foo = {}));
51+
var provide = foo;
52+
var beez = foo.bar;
5153
5;
5254
"s";
5355
null;

testdata/baselines/reference/submodule/compiler/aliasErrors.js.diff

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
--- old.aliasErrors.js
22
+++ new.aliasErrors.js
3-
@@= skipped -47, +47 lines =@@
4-
})(baz = bar.baz || (bar.baz = {}));
3+
@@= skipped -48, +48 lines =@@
54
})(bar = foo.bar || (foo.bar = {}));
65
})(foo || (foo = {}));
7-
-var provide = foo;
6+
var provide = foo;
87
-var booz = foo.bar.baz;
9-
-var beez = foo.bar;
8+
var beez = foo.bar;
109
-var m = no;
1110
-var m2 = no.mod;
1211
5;

testdata/baselines/reference/submodule/compiler/chainedImportAlias.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ var m;
2424
"use strict";
2525
Object.defineProperty(exports, "__esModule", { value: true });
2626
const x = require("./chainedImportAlias_file0");
27+
var y = x;
2728
y.m.foo();

testdata/baselines/reference/submodule/compiler/chainedImportAlias.js.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"use strict";
66
Object.defineProperty(exports, "__esModule", { value: true });
77
-var x = require("./chainedImportAlias_file0");
8-
-var y = x;
98
+const x = require("./chainedImportAlias_file0");
9+
var y = x;
1010
y.m.foo();

testdata/baselines/reference/submodule/compiler/collisionExportsRequireAndInternalModuleAliasInGlobalFile.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ var mOfGloalFile;
3131
}
3232
mOfGloalFile.c = c;
3333
})(mOfGloalFile || (mOfGloalFile = {}));
34+
var exports = mOfGloalFile.c;
35+
var require = mOfGloalFile.c;
3436
new exports();
3537
new require();
3638
var m1;

testdata/baselines/reference/submodule/compiler/collisionExportsRequireAndInternalModuleAliasInGlobalFile.js.diff

Lines changed: 0 additions & 11 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/constEnums.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ var A2;
192192
})(C = B.C || (B.C = {}));
193193
})(B = A2.B || (A2.B = {}));
194194
})(A2 || (A2 = {}));
195+
var I1 = A1.B;
196+
var I2 = A2.B;
195197
function foo0(e) {
196198
if (e === 1 /* I.V1 */) {
197199
}

0 commit comments

Comments
 (0)