Repository: microsoft/TypeScript
File: src/compiler/utilities.ts (TypeScript)

Code before:

const _computedOptions = createComputedCompilerOptions({
    allowImportingTsExtensions: {
        dependencies: ["rewriteRelativeImportExtensions"],
        computeValue: compilerOptions => {
            return !!(compilerOptions.allowImportingTsExtensions || compilerOptions.rewriteRelativeImportExtensions);
        },
    },
    target: {
        dependencies: [],
        computeValue: compilerOptions => {
            const target = compilerOptions.target === ScriptTarget.ES3 ? undefined : compilerOptions.target;
            return target ?? ScriptTarget.LatestStandard;
        },
    },
    module: {
        dependencies: ["target"],
        computeValue: (compilerOptions): ModuleKind => {
            return typeof compilerOptions.module === "number" ?
                compilerOptions.module :
                _computedOptions.target.computeValue(compilerOptions) >= ScriptTarget.ES2015 ? ModuleKind.ES2015 : ModuleKind.CommonJS;
        },
    },
    moduleResolution: {
        dependencies: ["module", "target"],
        computeValue: (compilerOptions): ModuleResolutionKind => {
            if (compilerOptions.moduleResolution !== undefined) {
                return compilerOptions.moduleResolution;
            }
            const moduleKind = _computedOptions.module.computeValue(compilerOptions);
            switch (moduleKind) {
                case ModuleKind.None:
                case ModuleKind.AMD:
                case ModuleKind.UMD:
                case ModuleKind.System:
                    return ModuleResolutionKind.Classic;
                case ModuleKind.NodeNext:
                    return ModuleResolutionKind.NodeNext;
            }
            if (ModuleKind.Node16 <= moduleKind && moduleKind < ModuleKind.NodeNext) {
                return ModuleResolutionKind.Node16;
            }
            return ModuleResolutionKind.Bundler;
        },
    },
    moduleDetection: {
        dependencies: ["module", "target"],
        computeValue: (compilerOptions): ModuleDetectionKind => {
            if (compilerOptions.moduleDetection !== undefined) {
                return compilerOptions.moduleDetection;
            }

Review comment (suggestion):
This change alters the implied `module` value based on `target` (including enabling top-level await for `@target: esnext` via the implicit `module: esnext`). It would be good to add a focused compiler test that explicitly asserts the new default mapping at the key boundaries (es2015/es2020/es2022/esnext), rather than relying on incidental baseline changes in unrelated tests.

Code after:

const _computedOptions = createComputedCompilerOptions({
    allowImportingTsExtensions: {
        dependencies: ["rewriteRelativeImportExtensions"],
        computeValue: compilerOptions => {
            return !!(compilerOptions.allowImportingTsExtensions || compilerOptions.rewriteRelativeImportExtensions);
        },
    },
    target: {
        dependencies: [],
        computeValue: compilerOptions => {
            const target = compilerOptions.target === ScriptTarget.ES3 ? undefined : compilerOptions.target;
            return target ?? ScriptTarget.LatestStandard;
        },
    },
    module: {
        dependencies: ["target"],
        computeValue: (compilerOptions): ModuleKind => {
            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: {
        dependencies: ["module", "target"],
        computeValue: (compilerOptions): ModuleResolutionKind => {
            if (compilerOptions.moduleResolution !== undefined) {
                return compilerOptions.moduleResolution;
            }
            const moduleKind = _computedOptions.module.computeValue(compilerOptions);
            switch (moduleKind) {
                case ModuleKind.None:
                case ModuleKind.AMD:
                case ModuleKind.UMD:
                case ModuleKind.System:
                    return ModuleResolutionKind.Classic;
                case ModuleKind.NodeNext: