Update implied default for module based on target (#63076)

This commit is contained in:
Jake Bailey 2026-02-02 09:11:49 -08:00 committed by GitHub
parent 1fd0c5389d
commit 97d51a7448
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 11 deletions

View File

@ -9000,9 +9000,23 @@ const _computedOptions = createComputedCompilerOptions({
module: {
dependencies: ["target"],
computeValue: (compilerOptions): ModuleKind => {
return typeof compilerOptions.module === "number" ?
compilerOptions.module :
_computedOptions.target.computeValue(compilerOptions) >= ScriptTarget.ES2015 ? ModuleKind.ES2015 : ModuleKind.CommonJS;
if (typeof compilerOptions.module === "number") {
return compilerOptions.module;
}
const target = _computedOptions.target.computeValue(compilerOptions);
if (target === ScriptTarget.ESNext) {
return ModuleKind.ESNext;
}
if (target >= ScriptTarget.ES2022) {
return ModuleKind.ES2022;
}
if (target >= ScriptTarget.ES2020) {
return ModuleKind.ES2020;
}
if (target >= ScriptTarget.ES2015) {
return ModuleKind.ES2015;
}
return ModuleKind.CommonJS;
},
},
moduleResolution: {

View File

@ -12,11 +12,9 @@ awaitInNonAsyncFunction.ts(30,9): error TS1103: 'for await' loops are only allow
awaitInNonAsyncFunction.ts(31,5): error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules.
awaitInNonAsyncFunction.ts(34,7): error TS1103: 'for await' loops are only allowed within async functions and at the top levels of modules.
awaitInNonAsyncFunction.ts(35,5): error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules.
awaitInNonAsyncFunction.ts(39,5): error TS1432: Top-level 'for await' loops are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
awaitInNonAsyncFunction.ts(40,1): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
==== awaitInNonAsyncFunction.ts (16 errors) ====
==== awaitInNonAsyncFunction.ts (14 errors) ====
// https://github.com/Microsoft/TypeScript/issues/26586
function normalFunc(p: Promise<number>) {
@ -96,8 +94,4 @@ awaitInNonAsyncFunction.ts(40,1): error TS1378: Top-level 'await' expressions ar
}
for await (const _ of []);
~~~~~
!!! error TS1432: Top-level 'for await' loops are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
await null;
~~~~~
!!! error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
await null;