diff options
Diffstat (limited to 'cli/args/config_file.rs')
-rw-r--r-- | cli/args/config_file.rs | 104 |
1 files changed, 25 insertions, 79 deletions
diff --git a/cli/args/config_file.rs b/cli/args/config_file.rs index 570aeba0d..a0a5837fb 100644 --- a/cli/args/config_file.rs +++ b/cli/args/config_file.rs @@ -90,68 +90,62 @@ impl Serialize for IgnoredCompilerOptions { pub const IGNORED_COMPILER_OPTIONS: &[&str] = &[ "allowSyntheticDefaultImports", "allowUmdGlobalAccess", - "baseUrl", - "declaration", - "declarationMap", - "downlevelIteration", - "esModuleInterop", - "emitDeclarationOnly", - "importHelpers", - "inlineSourceMap", - "inlineSources", - "module", - "noEmitHelpers", - "noErrorTruncation", - "noLib", - "noResolve", - "outDir", - "paths", - "preserveConstEnums", - "reactNamespace", - "resolveJsonModule", - "rootDir", - "rootDirs", - "skipLibCheck", - "sourceMap", - "sourceRoot", - "target", - "useDefineForClassFields", -]; - -pub const IGNORED_RUNTIME_COMPILER_OPTIONS: &[&str] = &[ "assumeChangesOnlyAffectDirectDependencies", + "baseUrl", "build", "charset", "composite", + "declaration", + "declarationMap", "diagnostics", "disableSizeLimit", + "downlevelIteration", "emitBOM", + "emitDeclarationOnly", + "esModuleInterop", "extendedDiagnostics", "forceConsistentCasingInFileNames", "generateCpuProfile", "help", + "importHelpers", "incremental", "init", + "inlineSourceMap", + "inlineSources", "isolatedModules", "listEmittedFiles", "listFiles", "mapRoot", "maxNodeModuleJsDepth", + "module", "moduleResolution", "newLine", "noEmit", + "noEmitHelpers", "noEmitOnError", + "noErrorTruncation", + "noLib", + "noResolve", "out", "outDir", "outFile", + "paths", + "preserveConstEnums", "preserveSymlinks", "preserveWatchOutput", "pretty", "project", + "reactNamespace", "resolveJsonModule", + "rootDir", + "rootDirs", "showConfig", "skipDefaultLibCheck", + "skipLibCheck", + "sourceMap", + "sourceRoot", "stripInternal", + "target", "traceResolution", "tsBuildInfoFile", "typeRoots", @@ -177,16 +171,13 @@ pub fn json_merge(a: &mut Value, b: &Value) { fn parse_compiler_options( compiler_options: &HashMap<String, Value>, maybe_specifier: Option<ModuleSpecifier>, - is_runtime: bool, ) -> Result<(Value, Option<IgnoredCompilerOptions>), AnyError> { let mut filtered: HashMap<String, Value> = HashMap::new(); let mut items: Vec<String> = Vec::new(); for (key, value) in compiler_options.iter() { let key = key.as_str(); - if (!is_runtime && IGNORED_COMPILER_OPTIONS.contains(&key)) - || IGNORED_RUNTIME_COMPILER_OPTIONS.contains(&key) - { + if IGNORED_COMPILER_OPTIONS.contains(&key) { items.push(key.to_string()); } else { filtered.insert(key.to_string(), value.to_owned()); @@ -261,19 +252,6 @@ impl TsConfig { Ok(None) } } - - /// Take a map of compiler options, filtering out any that are ignored, then - /// merge it with the current configuration, returning any options that might - /// have been ignored. - pub fn merge_user_config( - &mut self, - user_options: &HashMap<String, Value>, - ) -> Result<Option<IgnoredCompilerOptions>, AnyError> { - let (value, maybe_ignored_options) = - parse_compiler_options(user_options, None, true)?; - self.merge(&value); - Ok(maybe_ignored_options) - } } impl Serialize for TsConfig { @@ -585,7 +563,7 @@ impl ConfigFile { let options: HashMap<String, Value> = serde_json::from_value(compiler_options) .context("compilerOptions should be an object")?; - parse_compiler_options(&options, Some(self.specifier.to_owned()), false) + parse_compiler_options(&options, Some(self.specifier.to_owned())) } else { Ok((json!({}), None)) } @@ -911,38 +889,6 @@ mod tests { } #[test] - fn test_tsconfig_merge_user_options() { - let mut tsconfig = TsConfig::new(json!({ - "target": "esnext", - "module": "esnext", - })); - let user_options = serde_json::from_value(json!({ - "target": "es6", - "build": true, - "strict": false, - })) - .expect("could not convert to hashmap"); - let maybe_ignored_options = tsconfig - .merge_user_config(&user_options) - .expect("could not merge options"); - assert_eq!( - tsconfig.0, - json!({ - "module": "esnext", - "target": "es6", - "strict": false, - }) - ); - assert_eq!( - maybe_ignored_options, - Some(IgnoredCompilerOptions { - items: vec!["build".to_string()], - maybe_specifier: None - }) - ); - } - - #[test] fn test_tsconfig_as_bytes() { let mut tsconfig1 = TsConfig::new(json!({ "strict": true, |