Skip to content
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

feat: add support for compilerOptions.moduleDetection #6

Merged
merged 1 commit into from
Jun 11, 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
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ pub struct CompilerOptions {
pub jsx: Option<Jsx>,
pub lib: Option<Vec<Lib>>,
pub module: Option<Module>,
pub module_detection: Option<ModuleDetectionMode>,
pub no_emit: Option<bool>,
pub out_dir: Option<String>,
pub out_file: Option<String>,
Expand Down Expand Up @@ -453,6 +454,22 @@ pub struct CompilerOptions {
pub watch_file: Option<String>,
}

/// 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.
Expand Down
3 changes: 2 additions & 1 deletion test/tsconfig.complete.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
}
}
}
Loading