From c2770c70b72e5d5121be936ee32e249a21e4ea92 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Wed, 13 Jul 2022 20:38:36 +0100 Subject: [PATCH] chore(cli): remove dead code related to previous tsc emit (#15196) --- cli/args/config_file.rs | 104 ++++++++++------------------------------ cli/emit.rs | 70 +++++++++++---------------- cli/main.rs | 1 - cli/proc_state.rs | 5 +- 4 files changed, 54 insertions(+), 126 deletions(-) diff --git a/cli/args/config_file.rs b/cli/args/config_file.rs index 570aeba0d7..a0a5837fb3 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, maybe_specifier: Option, - is_runtime: bool, ) -> Result<(Value, Option), AnyError> { let mut filtered: HashMap = HashMap::new(); let mut items: Vec = 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, - ) -> Result, 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 = 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)) } @@ -910,38 +888,6 @@ mod tests { assert!(ConfigFile::new(config_text, &config_specifier).is_err()); } - #[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!({ diff --git a/cli/emit.rs b/cli/emit.rs index a530dbcb91..924af49c4d 100644 --- a/cli/emit.rs +++ b/cli/emit.rs @@ -119,7 +119,7 @@ pub enum TsConfigType { Bundle, /// Return a configuration to use tsc to type check and optionally emit. This /// is independent of either bundling or just emitting via swc - Check { lib: TsTypeLib, tsc_emit: bool }, + Check { lib: TsTypeLib }, /// Return a configuration to use swc to emit single module files. Emit, } @@ -148,44 +148,33 @@ pub fn get_ts_config_for_emit( "jsxFactory": "React.createElement", "jsxFragmentFactory": "React.Fragment", })), - TsConfigType::Check { tsc_emit, lib } => { - let mut ts_config = TsConfig::new(json!({ - "allowJs": true, - "allowSyntheticDefaultImports": true, - "checkJs": false, - "experimentalDecorators": true, - "incremental": true, - "jsx": "react", - "jsxFactory": "React.createElement", - "jsxFragmentFactory": "React.Fragment", - "isolatedModules": true, - "lib": lib, - "module": "esnext", - "resolveJsonModule": true, - "sourceMap": false, - "strict": true, - "target": "esnext", - "tsBuildInfoFile": "deno:///.tsbuildinfo", - "useDefineForClassFields": true, - // TODO(@kitsonk) remove for Deno 2.0 - "useUnknownInCatchVariables": false, - })); - if tsc_emit { - ts_config.merge(&json!({ - "emitDecoratorMetadata": false, - "importsNotUsedAsValues": "remove", - "inlineSourceMap": true, - "inlineSources": true, - "outDir": "deno://", - "removeComments": true, - })); - } else { - ts_config.merge(&json!({ - "noEmit": true, - })); - } - ts_config - } + TsConfigType::Check { lib } => TsConfig::new(json!({ + "allowJs": true, + "allowSyntheticDefaultImports": true, + "checkJs": false, + "emitDecoratorMetadata": false, + "experimentalDecorators": true, + "incremental": true, + "jsx": "react", + "jsxFactory": "React.createElement", + "jsxFragmentFactory": "React.Fragment", + "importsNotUsedAsValues": "remove", + "inlineSourceMap": true, + "inlineSources": true, + "isolatedModules": true, + "lib": lib, + "module": "esnext", + "moduleDetection": "force", + "noEmit": true, + "resolveJsonModule": true, + "sourceMap": false, + "strict": true, + "target": "esnext", + "tsBuildInfoFile": "deno:///.tsbuildinfo", + "useDefineForClassFields": true, + // TODO(@kitsonk) remove for Deno 2.0 + "useUnknownInCatchVariables": false, + })), TsConfigType::Emit => TsConfig::new(json!({ "checkJs": false, "emitDecoratorMetadata": false, @@ -201,9 +190,6 @@ pub fn get_ts_config_for_emit( }; let maybe_ignored_options = ts_config.merge_tsconfig_from_config_file(maybe_config_file)?; - ts_config.merge(&json!({ - "moduleDetection": "force", - })); Ok(TsConfigWithIgnoredOptions { ts_config, maybe_ignored_options, diff --git a/cli/main.rs b/cli/main.rs index fbbfc77d24..2cdd65ed21 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -654,7 +654,6 @@ async fn create_graph_and_maybe_check( if ps.options.type_check_mode() != TypeCheckMode::None { let ts_config_result = ps.options.resolve_ts_config_for_emit(TsConfigType::Check { - tsc_emit: false, lib: ps.options.ts_type_lib_window(), })?; if let Some(ignored_options) = ts_config_result.maybe_ignored_options { diff --git a/cli/proc_state.rs b/cli/proc_state.rs index fac2b2418c..ae0290b2c7 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -414,10 +414,7 @@ impl ProcState { let config_type = if self.options.type_check_mode() == TypeCheckMode::None { TsConfigType::Emit } else { - TsConfigType::Check { - tsc_emit: true, - lib, - } + TsConfigType::Check { lib } }; let ts_config_result =