From bedb65f35b35feda7b9511f45739ea4b8c9a1c5e Mon Sep 17 00:00:00 2001 From: Samantha Nguyen Date: Wed, 5 Jun 2024 11:39:01 -0500 Subject: [PATCH] feat: add support for `compilerOptions.moduleDetection` Introduced in TypeScript 4.7: - https://www.typescriptlang.org/tsconfig/#moduleDetection - https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-7.html#control-over-module-detection --- src/lib.rs | 17 +++++++++++++++++ test/tsconfig.complete.json | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 7ccae0a..99ed354 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -360,6 +360,7 @@ pub struct CompilerOptions { pub jsx: Option, pub lib: Option>, pub module: Option, + pub module_detection: Option, pub no_emit: Option, pub out_dir: Option, pub out_file: Option, @@ -453,6 +454,22 @@ pub struct CompilerOptions { pub watch_file: Option, } +/// Module detection mode +/// +/// This setting controls how TypeScript determines whether a file is a script or a module. +/// These choices include: +/// - "auto" (default) - TypeScript will not only look for import and export statements, but it will also check whether the "type" field in a package.json is set to "module" when running with module: nodenext or node16, and check whether the current file is a JSX file when running under jsx: react-jsx. +/// - "legacy" - The same behavior as 4.6 and prior, usings import and export statements to determine whether a file is a module. +/// - "force" - Ensures that every non-declaration file is treated as a module. +#[derive(Deserialize, Debug, PartialEq, Copy, Clone, Default)] +#[serde(rename_all = "lowercase")] +pub enum ModuleDetectionMode { + #[default] + Auto, + Legacy, + Force, +} + /// Module resolution mode /// /// Specify the module resolution strategy: 'node' (Node.js) or 'classic' (used in TypeScript before the release of 1.6). You probably won’t need to use classic in modern code. diff --git a/test/tsconfig.complete.json b/test/tsconfig.complete.json index 1d64282..2324676 100644 --- a/test/tsconfig.complete.json +++ b/test/tsconfig.complete.json @@ -82,6 +82,7 @@ "removeComments": false, // Remove all comments except copy-right header comments beginning with //! "experimentalDecorators": true, // Enables experimental support for ES7 decorators. "emitDecoratorMetadata": true, // Enables experimental support for emitting type metadata for decorators. + "moduleDetection": "auto", // Controls how TypeScript determines whether a file is a script or a module. // Source map options "sourceMap": false, // Generates corresponding '.map' file. @@ -103,4 +104,4 @@ "noLib": false, // Do not include the default library file (lib.d.ts). "pretty": true, // Stylize errors and messages using color and context. } -} \ No newline at end of file +}