Skip to content

Commit f0ff976

Browse files
authored
isolatedModules does not imply every file is a module (#54218)
1 parent 08285ab commit f0ff976

16 files changed

+50
-40
lines changed

src/compiler/utilities.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1857,7 +1857,7 @@ function isCommonJSContainingModuleKind(kind: ModuleKind) {
18571857

18581858
/** @internal */
18591859
export function isEffectiveExternalModule(node: SourceFile, compilerOptions: CompilerOptions) {
1860-
return isExternalModule(node) || getIsolatedModules(compilerOptions) || (isCommonJSContainingModuleKind(getEmitModuleKind(compilerOptions)) && !!node.commonJsModuleIndicator);
1860+
return isExternalModule(node) || (isCommonJSContainingModuleKind(getEmitModuleKind(compilerOptions)) && !!node.commonJsModuleIndicator);
18611861
}
18621862

18631863
/**

src/testRunner/unittests/services/transpile.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ var x = 0;`, {
130130
testVerbatimModuleSyntax: true
131131
});
132132

133-
transpilesCorrectly("Generates module output", `var x = 0;`, {
133+
transpilesCorrectly("Generates module output", `var x = 0; export {};`, {
134134
options: { compilerOptions: { module: ts.ModuleKind.AMD } }
135135
});
136136

@@ -139,7 +139,7 @@ var x = 0;`, {
139139
testVerbatimModuleSyntax: true
140140
});
141141

142-
transpilesCorrectly("Sets module name", "var x = 1;", {
142+
transpilesCorrectly("Sets module name", "var x = 1; export {};", {
143143
options: { compilerOptions: { module: ts.ModuleKind.System, newLine: ts.NewLineKind.LineFeed }, moduleName: "NamedModule" }
144144
});
145145

src/testRunner/unittests/transform.ts

+1
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ describe("unittests:: TransformAPI", () => {
304304
target: ts.ScriptTarget.ES5,
305305
module: ts.ModuleKind.System,
306306
newLine: ts.NewLineKind.CarriageReturnLineFeed,
307+
moduleDetection: ts.ModuleDetectionKind.Force,
307308
}
308309
}).outputText;
309310

tests/baselines/reference/importHelpersInIsolatedModules.js

+34-8
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,40 @@ var C = /** @class */ (function () {
6969
return C;
7070
}());
7171
//// [script.js]
72-
var tslib_1 = require("tslib");
72+
var __extends = (this && this.__extends) || (function () {
73+
var extendStatics = function (d, b) {
74+
extendStatics = Object.setPrototypeOf ||
75+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
76+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
77+
return extendStatics(d, b);
78+
};
79+
return function (d, b) {
80+
if (typeof b !== "function" && b !== null)
81+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
82+
extendStatics(d, b);
83+
function __() { this.constructor = d; }
84+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
85+
};
86+
})();
87+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
88+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
89+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
90+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
91+
return c > 3 && r && Object.defineProperty(target, key, r), r;
92+
};
93+
var __metadata = (this && this.__metadata) || function (k, v) {
94+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
95+
};
96+
var __param = (this && this.__param) || function (paramIndex, decorator) {
97+
return function (target, key) { decorator(target, key, paramIndex); }
98+
};
7399
var A = /** @class */ (function () {
74100
function A() {
75101
}
76102
return A;
77103
}());
78104
var B = /** @class */ (function (_super) {
79-
tslib_1.__extends(B, _super);
105+
__extends(B, _super);
80106
function B() {
81107
return _super !== null && _super.apply(this, arguments) || this;
82108
}
@@ -87,13 +113,13 @@ var C = /** @class */ (function () {
87113
}
88114
C.prototype.method = function (x) {
89115
};
90-
tslib_1.__decorate([
91-
tslib_1.__param(0, dec),
92-
tslib_1.__metadata("design:type", Function),
93-
tslib_1.__metadata("design:paramtypes", [Number]),
94-
tslib_1.__metadata("design:returntype", void 0)
116+
__decorate([
117+
__param(0, dec),
118+
__metadata("design:type", Function),
119+
__metadata("design:paramtypes", [Number]),
120+
__metadata("design:returntype", void 0)
95121
], C.prototype, "method", null);
96-
C = tslib_1.__decorate([
122+
C = __decorate([
97123
dec
98124
], C);
99125
return C;

tests/baselines/reference/isolatedModulesPlainFile-AMD.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,4 @@ run(1);
44

55

66
//// [isolatedModulesPlainFile-AMD.js]
7-
define(["require", "exports"], function (require, exports) {
8-
"use strict";
9-
run(1);
10-
});
7+
run(1);

tests/baselines/reference/isolatedModulesPlainFile-System.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,4 @@ run(1);
44

55

66
//// [isolatedModulesPlainFile-System.js]
7-
System.register([], function (exports_1, context_1) {
8-
var __moduleName = context_1 && context_1.id;
9-
return {
10-
setters: [],
11-
execute: function () {
12-
run(1);
13-
}
14-
};
15-
});
7+
run(1);

tests/baselines/reference/isolatedModulesPlainFile-UMD.js

+1-12
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,4 @@ run(1);
44

55

66
//// [isolatedModulesPlainFile-UMD.js]
7-
(function (factory) {
8-
if (typeof module === "object" && typeof module.exports === "object") {
9-
var v = factory(require, exports);
10-
if (v !== undefined) module.exports = v;
11-
}
12-
else if (typeof define === "function" && define.amd) {
13-
define(["require", "exports"], factory);
14-
}
15-
})(function (require, exports) {
16-
"use strict";
17-
run(1);
18-
});
7+
run(1);

tests/baselines/reference/transformApi/transformsCorrectly.transformAddImportStar.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
System.register(["./comp1"], function (exports_1, context_1) {
2+
"use strict";
23
var i0;
34
var __moduleName = context_1 && context_1.id;
45
return {

tests/baselines/reference/transpile/Generates module output.errors.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ error TS5107: Option 'target=ES3' is deprecated and will stop functioning in Typ
33

44
!!! error TS5107: Option 'target=ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify compilerOption '"ignoreDeprecations": "5.0"' to silence this error.
55
==== file.ts (0 errors) ====
6-
var x = 0;
6+
var x = 0; export {};

tests/baselines/reference/transpile/Generates module output.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/transpile/Generates module output.oldTranspile.errors.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ error TS5107: Option 'target=ES3' is deprecated and will stop functioning in Typ
33

44
!!! error TS5107: Option 'target=ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify compilerOption '"ignoreDeprecations": "5.0"' to silence this error.
55
==== file.ts (0 errors) ====
6-
var x = 0;
6+
var x = 0; export {};

tests/baselines/reference/transpile/Generates module output.oldTranspile.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/transpile/Sets module name.errors.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ error TS5107: Option 'target=ES3' is deprecated and will stop functioning in Typ
33

44
!!! error TS5107: Option 'target=ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify compilerOption '"ignoreDeprecations": "5.0"' to silence this error.
55
==== file.ts (0 errors) ====
6-
var x = 1;
6+
var x = 1; export {};

tests/baselines/reference/transpile/Sets module name.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/transpile/Sets module name.oldTranspile.errors.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ error TS5107: Option 'target=ES3' is deprecated and will stop functioning in Typ
33

44
!!! error TS5107: Option 'target=ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify compilerOption '"ignoreDeprecations": "5.0"' to silence this error.
55
==== file.ts (0 errors) ====
6-
var x = 1;
6+
var x = 1; export {};

tests/baselines/reference/transpile/Sets module name.oldTranspile.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)