Skip to content

Commit

Permalink
Merge pull request #6 from neoncitylights/master
Browse files Browse the repository at this point in the history
feat: add support for `compilerOptions.moduleDetection`
  • Loading branch information
drivasperez authored Jun 11, 2024
2 parents b77c1d7 + bedb65f commit daab509
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
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.
}
}
}

0 comments on commit daab509

Please sign in to comment.