Skip to content

Ensure isolatedModules does not make scripts emit as modules #54218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,7 @@ function isCommonJSContainingModuleKind(kind: ModuleKind) {

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

/**
Expand Down
4 changes: 2 additions & 2 deletions src/testRunner/unittests/services/transpile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ var x = 0;`, {
testVerbatimModuleSyntax: true
});

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

Expand All @@ -139,7 +139,7 @@ var x = 0;`, {
testVerbatimModuleSyntax: true
});

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

Expand Down
1 change: 1 addition & 0 deletions src/testRunner/unittests/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ describe("unittests:: TransformAPI", () => {
target: ts.ScriptTarget.ES5,
module: ts.ModuleKind.System,
newLine: ts.NewLineKind.CarriageReturnLineFeed,
moduleDetection: ts.ModuleDetectionKind.Force,
}
}).outputText;

Expand Down
42 changes: 34 additions & 8 deletions tests/baselines/reference/importHelpersInIsolatedModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,40 @@ var C = /** @class */ (function () {
return C;
}());
//// [script.js]
var tslib_1 = require("tslib");
var __extends = (this && this.__extends) || (function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what I meant by this change affecting --importHelpers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a correct change. The file is written as a script and checks as a script, so the output definitely can’t import the helpers, since that would make it lose its scriptiness.

var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
var A = /** @class */ (function () {
function A() {
}
return A;
}());
var B = /** @class */ (function (_super) {
tslib_1.__extends(B, _super);
__extends(B, _super);
function B() {
return _super !== null && _super.apply(this, arguments) || this;
}
Expand All @@ -87,13 +113,13 @@ var C = /** @class */ (function () {
}
C.prototype.method = function (x) {
};
tslib_1.__decorate([
tslib_1.__param(0, dec),
tslib_1.__metadata("design:type", Function),
tslib_1.__metadata("design:paramtypes", [Number]),
tslib_1.__metadata("design:returntype", void 0)
__decorate([
__param(0, dec),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Number]),
__metadata("design:returntype", void 0)
], C.prototype, "method", null);
C = tslib_1.__decorate([
C = __decorate([
dec
], C);
return C;
Expand Down
5 changes: 1 addition & 4 deletions tests/baselines/reference/isolatedModulesPlainFile-AMD.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@ run(1);


//// [isolatedModulesPlainFile-AMD.js]
define(["require", "exports"], function (require, exports) {
"use strict";
run(1);
});
run(1);
10 changes: 1 addition & 9 deletions tests/baselines/reference/isolatedModulesPlainFile-System.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,4 @@ run(1);


//// [isolatedModulesPlainFile-System.js]
System.register([], function (exports_1, context_1) {
var __moduleName = context_1 && context_1.id;
return {
setters: [],
execute: function () {
run(1);
}
};
});
run(1);
13 changes: 1 addition & 12 deletions tests/baselines/reference/isolatedModulesPlainFile-UMD.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,4 @@ run(1);


//// [isolatedModulesPlainFile-UMD.js]
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
run(1);
});
run(1);
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
System.register(["./comp1"], function (exports_1, context_1) {
"use strict";
var i0;
var __moduleName = context_1 && context_1.id;
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ error TS5107: Option 'target=ES3' is deprecated and will stop functioning in Typ

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ error TS5107: Option 'target=ES3' is deprecated and will stop functioning in Typ

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ error TS5107: Option 'target=ES3' is deprecated and will stop functioning in Typ

!!! error TS5107: Option 'target=ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify compilerOption '"ignoreDeprecations": "5.0"' to silence this error.
==== file.ts (0 errors) ====
var x = 1;
var x = 1; export {};
1 change: 1 addition & 0 deletions tests/baselines/reference/transpile/Sets module name.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ error TS5107: Option 'target=ES3' is deprecated and will stop functioning in Typ

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.