mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Remove dependence on module compiler option to consider mts/cts files always modules (#49815)
This commit is contained in:
parent
eb430f27ea
commit
9872184483
@ -6319,7 +6319,7 @@ namespace ts {
|
||||
// Excludes declaration files - they still require an explicit `export {}` or the like
|
||||
// for back compat purposes. The only non-declaration files _not_ forced to be a module are `.js` files
|
||||
// that aren't esm-mode (meaning not in a `type: module` scope).
|
||||
return (file.impliedNodeFormat === ModuleKind.ESNext || (fileExtensionIsOneOf(file.fileName, [Extension.Cjs, Extension.Cts]))) && !file.isDeclarationFile ? true : undefined;
|
||||
return (file.impliedNodeFormat === ModuleKind.ESNext || (fileExtensionIsOneOf(file.fileName, [Extension.Cjs, Extension.Cts, Extension.Mjs, Extension.Mts]))) && !file.isDeclarationFile ? true : undefined;
|
||||
}
|
||||
|
||||
export function getSetExternalModuleIndicator(options: CompilerOptions): (file: SourceFile) => void {
|
||||
@ -6343,10 +6343,7 @@ namespace ts {
|
||||
if (options.jsx === JsxEmit.ReactJSX || options.jsx === JsxEmit.ReactJSXDev) {
|
||||
checks.push(isFileModuleFromUsingJSXTag);
|
||||
}
|
||||
const moduleKind = getEmitModuleKind(options);
|
||||
if (moduleKind === ModuleKind.Node16 || moduleKind === ModuleKind.NodeNext) {
|
||||
checks.push(isFileForcedToBeModuleByFormat);
|
||||
}
|
||||
checks.push(isFileForcedToBeModuleByFormat);
|
||||
const combined = or(...checks);
|
||||
const callback = (file: SourceFile) => void (file.externalModuleIndicator = combined(file));
|
||||
return callback;
|
||||
|
||||
@ -0,0 +1,19 @@
|
||||
//// [tests/cases/compiler/moduleDetectionIsolatedModulesCjsFileScope.ts] ////
|
||||
|
||||
//// [filename.cts]
|
||||
const a = 2;
|
||||
//// [filename.mts]
|
||||
const a = 2;
|
||||
|
||||
//// [filename.cjs]
|
||||
const a = 2;
|
||||
export {};
|
||||
//// [filename.mjs]
|
||||
const a = 2;
|
||||
export {};
|
||||
|
||||
|
||||
//// [filename.d.cts]
|
||||
export {};
|
||||
//// [filename.d.mts]
|
||||
export {};
|
||||
@ -0,0 +1,8 @@
|
||||
=== tests/cases/compiler/filename.cts ===
|
||||
const a = 2;
|
||||
>a : Symbol(a, Decl(filename.cts, 0, 5))
|
||||
|
||||
=== tests/cases/compiler/filename.mts ===
|
||||
const a = 2;
|
||||
>a : Symbol(a, Decl(filename.mts, 0, 5))
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
=== tests/cases/compiler/filename.cts ===
|
||||
const a = 2;
|
||||
>a : 2
|
||||
>2 : 2
|
||||
|
||||
=== tests/cases/compiler/filename.mts ===
|
||||
const a = 2;
|
||||
>a : 2
|
||||
>2 : 2
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
// @target: esnext
|
||||
// @module: esnext
|
||||
// @declaration: true
|
||||
// @moduleResolution: node
|
||||
// @isolatedModules: true
|
||||
// @filename: filename.cts
|
||||
const a = 2;
|
||||
// @filename: filename.mts
|
||||
const a = 2;
|
||||
Loading…
x
Reference in New Issue
Block a user