Skip to content

Commit ea4e944

Browse files
authored
Fix moduleDetection for node18, fix __esModule in detect=force (#2045)
1 parent f5c70b2 commit ea4e944

18 files changed

+14
-78
lines changed

internal/core/compileroptions.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,11 @@ func (options *CompilerOptions) GetEmitModuleDetectionKind() ModuleDetectionKind
232232
if options.ModuleDetection != ModuleDetectionKindNone {
233233
return options.ModuleDetection
234234
}
235-
switch options.GetEmitModuleKind() {
236-
case ModuleKindNode16, ModuleKindNode20, ModuleKindNodeNext:
235+
moduleKind := options.GetEmitModuleKind()
236+
if ModuleKindNode16 <= moduleKind && moduleKind <= ModuleKindNodeNext {
237237
return ModuleDetectionKindForce
238-
default:
239-
return ModuleDetectionKindAuto
240238
}
239+
return ModuleDetectionKindAuto
241240
}
242241

243242
func (options *CompilerOptions) GetResolvePackageJsonExports() bool {

internal/transformers/moduletransforms/commonjsmodule.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ func (tx *CommonJSModuleTransformer) visitSourceFile(node *ast.SourceFile) *ast.
247247
func (tx *CommonJSModuleTransformer) shouldEmitUnderscoreUnderscoreESModule() bool {
248248
if tspath.FileExtensionIsOneOf(tx.currentSourceFile.FileName(), tspath.SupportedJSExtensionsFlat) &&
249249
tx.currentSourceFile.CommonJSModuleIndicator != nil &&
250-
(tx.currentSourceFile.ExternalModuleIndicator == nil /*|| tx.currentSourceFile.ExternalModuleIndicator == true*/) { // !!!
250+
(tx.currentSourceFile.ExternalModuleIndicator == nil || tx.currentSourceFile.ExternalModuleIndicator.Kind == ast.KindSourceFile) {
251251
return false
252252
}
253253
if tx.currentModuleInfo.exportEquals == nil && ast.IsExternalModule(tx.currentSourceFile) {

testdata/baselines/reference/submodule/compiler/tripleSlashTypesReferenceWithMissingExports(module=node18).js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ interface GlobalThing { a: number }
1414
const a: GlobalThing = { a: 0 };
1515

1616
//// [usage.js]
17+
"use strict";
1718
/// <reference types="pkg" />
19+
Object.defineProperty(exports, "__esModule", { value: true });
1820
const a = { a: 0 };

testdata/baselines/reference/submodule/compiler/tripleSlashTypesReferenceWithMissingExports(module=node18).js.diff

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

testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsExportAssignment(module=node16).js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const a = {};
3535
module.exports = a;
3636
//// [file.js]
3737
"use strict";
38-
Object.defineProperty(exports, "__esModule", { value: true });
3938
// cjs format file
4039
const a = {};
4140
module.exports = a;

testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsExportAssignment(module=node16).js.diff

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
--- old.nodeModulesAllowJsExportAssignment(module=node16).js
22
+++ new.nodeModulesAllowJsExportAssignment(module=node16).js
3-
@@= skipped -34, +34 lines =@@
4-
module.exports = a;
5-
//// [file.js]
6-
"use strict";
7-
+Object.defineProperty(exports, "__esModule", { value: true });
8-
// cjs format file
9-
const a = {};
10-
module.exports = a;
11-
@@= skipped -15, +16 lines =@@
3+
@@= skipped -49, +49 lines =@@
124

135

146
//// [index.d.ts]

testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsExportAssignment(module=node18).js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module.exports = a;
3434
const a = {};
3535
module.exports = a;
3636
//// [file.js]
37+
"use strict";
3738
// cjs format file
3839
const a = {};
3940
module.exports = a;

testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsExportAssignment(module=node18).js.diff

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
--- old.nodeModulesAllowJsExportAssignment(module=node18).js
22
+++ new.nodeModulesAllowJsExportAssignment(module=node18).js
3-
@@= skipped -33, +33 lines =@@
4-
const a = {};
5-
module.exports = a;
6-
//// [file.js]
7-
-"use strict";
8-
// cjs format file
9-
const a = {};
10-
module.exports = a;
11-
@@= skipped -16, +15 lines =@@
3+
@@= skipped -49, +49 lines =@@
124

135

146
//// [index.d.ts]

testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsExportAssignment(module=node20).js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const a = {};
3535
module.exports = a;
3636
//// [file.js]
3737
"use strict";
38-
Object.defineProperty(exports, "__esModule", { value: true });
3938
// cjs format file
4039
const a = {};
4140
module.exports = a;

testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsExportAssignment(module=node20).js.diff

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
--- old.nodeModulesAllowJsExportAssignment(module=node20).js
22
+++ new.nodeModulesAllowJsExportAssignment(module=node20).js
3-
@@= skipped -34, +34 lines =@@
4-
module.exports = a;
5-
//// [file.js]
6-
"use strict";
7-
+Object.defineProperty(exports, "__esModule", { value: true });
8-
// cjs format file
9-
const a = {};
10-
module.exports = a;
11-
@@= skipped -15, +16 lines =@@
3+
@@= skipped -49, +49 lines =@@
124

135

146
//// [index.d.ts]

0 commit comments

Comments
 (0)