Skip to content

Ensure harness doesn't force or eagerly computes target, stop using raw target elsewhere #57526

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 1 commit into from
Feb 26, 2024
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
5 changes: 3 additions & 2 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ import {
getEmitFlags,
getEmitHelpers,
getEmitModuleKind,
getEmitScriptTarget,
getExternalHelpersModuleName,
getExternalModuleName,
getIdentifierTypeArguments,
Expand Down Expand Up @@ -856,8 +857,8 @@ export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFi
removeComments: compilerOptions.removeComments,
newLine: compilerOptions.newLine,
noEmitHelpers: compilerOptions.noEmitHelpers,
module: compilerOptions.module,
target: compilerOptions.target,
module: getEmitModuleKind(compilerOptions),
target: getEmitScriptTarget(compilerOptions),
sourceMap: compilerOptions.sourceMap,
inlineSourceMap: compilerOptions.inlineSourceMap,
inlineSources: compilerOptions.inlineSources,
Expand Down
1 change: 0 additions & 1 deletion src/harness/compilerImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ export function compileFiles(host: fakes.CompilerHost, rootFiles: string[] | und
}

// establish defaults (aligns with old harness)
if (compilerOptions.target === undefined && compilerOptions.module !== ts.ModuleKind.Node16 && compilerOptions.module !== ts.ModuleKind.NodeNext) compilerOptions.target = ts.ScriptTarget.ES3;
if (compilerOptions.newLine === undefined) compilerOptions.newLine = ts.NewLineKind.CarriageReturnLineFeed;
if (compilerOptions.skipDefaultLibCheck === undefined) compilerOptions.skipDefaultLibCheck = true;
if (compilerOptions.noErrorTruncation === undefined) compilerOptions.noErrorTruncation = true;
Comment on lines 260 to 262
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 want to say that we should drop these too, but:

  • If we change the default newLine, all baselines will change from CRLF to LF and lose git history.
  • skipDefaultLibCheck is a perf optimization.
  • noErrorTruncation gives us better baselines.

Expand Down
1 change: 0 additions & 1 deletion src/harness/harnessIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ export namespace Compiler {
symlinks?: vfs.FileSet,
): compiler.CompilationResult {
const options: ts.CompilerOptions & HarnessOptions = compilerOptions ? ts.cloneCompilerOptions(compilerOptions) : { noResolve: false };
options.target = ts.getEmitScriptTarget(options);
options.newLine = options.newLine || ts.NewLineKind.CarriageReturnLineFeed;
options.noErrorTruncation = true;
options.skipDefaultLibCheck = typeof options.skipDefaultLibCheck === "undefined" ? true : options.skipDefaultLibCheck;
Expand Down
3 changes: 2 additions & 1 deletion src/services/inlayHints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
GetAccessorDeclaration,
getEffectiveReturnTypeNode,
getEffectiveTypeAnnotationNode,
getEmitScriptTarget,
getLanguageVariant,
getLeadingCommentRanges,
getNameOfDeclaration,
Expand Down Expand Up @@ -350,7 +351,7 @@ export function provideInlayHints(context: InlayHintsContext): InlayHint[] {
}

function leadingCommentsContainsParameterName(node: Node, name: string) {
if (!isIdentifierText(name, compilerOptions.target, getLanguageVariant(file.scriptKind))) {
if (!isIdentifierText(name, getEmitScriptTarget(compilerOptions), getLanguageVariant(file.scriptKind))) {
Copy link
Member Author

Choose a reason for hiding this comment

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

It seems quite easy to make this kind of error; I am tempted to write an eslint rule which disallows the use of any CompilerOption property that we know to be computed, but that is non-trivial.

return false;
}

Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function CustomSelect2<Option,>(x: Props<Option> & {}) {}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CustomSelect2 = exports.CustomSelect1 = void 0;
var CustomSelect1 = function (x) { };
const CustomSelect1 = (x) => { };
exports.CustomSelect1 = CustomSelect1;
function CustomSelect2(x) { }
exports.CustomSelect2 = CustomSelect2;
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/declarationEmitUsingTypeAlias1.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ export const bar = (thing: SomeType) => {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.bar = exports.foo = void 0;
var foo = function (thing) {
const foo = (thing) => {
return thing;
};
exports.foo = foo;
var bar = function (thing) {
const bar = (thing) => {
return thing.arg;
};
exports.bar = bar;
Expand Down
9 changes: 3 additions & 6 deletions tests/baselines/reference/jsxClassAttributeResolution.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ import './';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.a = void 0;
var jsx_runtime_1 = require("react/jsx-runtime");
var App = /** @class */ (function () {
function App() {
}
return App;
}());
const jsx_runtime_1 = require("react/jsx-runtime");
class App {
}
exports.a = (0, jsx_runtime_1.jsx)(App, {});
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var p = __importStar(require("pkg"));
const p = __importStar(require("pkg"));
p.thing();
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var p = __importStar(require("pkg"));
const p = __importStar(require("pkg"));
p.thing();
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var p = __importStar(require("pkg"));
const p = __importStar(require("pkg"));
p.thing();
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var p = __importStar(require("pkg"));
const p = __importStar(require("pkg"));
p.thing();
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
error TS2468: Cannot find global value 'Promise'.
/src/buzz.mts(2,1): error TS2712: A dynamic import call in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.
/src/buzz.mts(2,8): error TS2834: Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Consider adding an extension to the import path.


!!! error TS2468: Cannot find global value 'Promise'.
==== /src/buzz.mts (2 errors) ====
==== /src/buzz.mts (1 errors) ====
// Extensionless relative path dynamic import in an ES module
import("./foo").then(x => x); // should error, ask for extension
~~~~~~~~~~~~~~~
!!! error TS2712: A dynamic import call in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.
~~~~~~~
!!! error TS2834: Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Consider adding an extension to the import path.
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import("./foo").then(x => x); // should error, ask for extension

//// [buzz.mjs]
// Extensionless relative path dynamic import in an ES module
import("./foo").then(function (x) { return x; }); // should error, ask for extension
import("./foo").then(x => x); // should error, ask for extension
export {};
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
error TS2468: Cannot find global value 'Promise'.
/src/bar.cts(2,1): error TS2712: A dynamic import call in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.
Copy link
Member Author

Choose a reason for hiding this comment

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

Another example of the implicit module setting now being reflected in tests; this was defaulted to ES5, but now it's esnext.

/src/bar.cts(2,8): error TS2834: Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Consider adding an extension to the import path.


!!! error TS2468: Cannot find global value 'Promise'.
==== /src/bar.cts (2 errors) ====
==== /src/bar.cts (1 errors) ====
// Extensionless relative path dynamic import in a cjs module
import("./foo").then(x => x); // should error, ask for extension
~~~~~~~~~~~~~~~
!!! error TS2712: A dynamic import call in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.
~~~~~~~
!!! error TS2834: Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Consider adding an extension to the import path.
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ import("./foo").then(x => x); // should error, ask for extension
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Extensionless relative path dynamic import in a cjs module
import("./foo").then(function (x) { return x; }); // should error, ask for extension
import("./foo").then(x => x); // should error, ask for extension
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
// esm format file
var self = __importStar(require("package"));
const self = __importStar(require("package"));
self;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
// esm format file
var self = __importStar(require("package"));
const self = __importStar(require("package"));
self;


Expand Down
Loading