1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-03 04:48:52 -05:00

chore(cli): remove dead code related to previous tsc emit (#15196)

This commit is contained in:
Nayeem Rahman 2022-07-13 20:38:36 +01:00 committed by GitHub
parent 667812a297
commit c2770c70b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 126 deletions

View file

@ -90,68 +90,62 @@ impl Serialize for IgnoredCompilerOptions {
pub const IGNORED_COMPILER_OPTIONS: &[&str] = &[ pub const IGNORED_COMPILER_OPTIONS: &[&str] = &[
"allowSyntheticDefaultImports", "allowSyntheticDefaultImports",
"allowUmdGlobalAccess", "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", "assumeChangesOnlyAffectDirectDependencies",
"baseUrl",
"build", "build",
"charset", "charset",
"composite", "composite",
"declaration",
"declarationMap",
"diagnostics", "diagnostics",
"disableSizeLimit", "disableSizeLimit",
"downlevelIteration",
"emitBOM", "emitBOM",
"emitDeclarationOnly",
"esModuleInterop",
"extendedDiagnostics", "extendedDiagnostics",
"forceConsistentCasingInFileNames", "forceConsistentCasingInFileNames",
"generateCpuProfile", "generateCpuProfile",
"help", "help",
"importHelpers",
"incremental", "incremental",
"init", "init",
"inlineSourceMap",
"inlineSources",
"isolatedModules", "isolatedModules",
"listEmittedFiles", "listEmittedFiles",
"listFiles", "listFiles",
"mapRoot", "mapRoot",
"maxNodeModuleJsDepth", "maxNodeModuleJsDepth",
"module",
"moduleResolution", "moduleResolution",
"newLine", "newLine",
"noEmit", "noEmit",
"noEmitHelpers",
"noEmitOnError", "noEmitOnError",
"noErrorTruncation",
"noLib",
"noResolve",
"out", "out",
"outDir", "outDir",
"outFile", "outFile",
"paths",
"preserveConstEnums",
"preserveSymlinks", "preserveSymlinks",
"preserveWatchOutput", "preserveWatchOutput",
"pretty", "pretty",
"project", "project",
"reactNamespace",
"resolveJsonModule", "resolveJsonModule",
"rootDir",
"rootDirs",
"showConfig", "showConfig",
"skipDefaultLibCheck", "skipDefaultLibCheck",
"skipLibCheck",
"sourceMap",
"sourceRoot",
"stripInternal", "stripInternal",
"target",
"traceResolution", "traceResolution",
"tsBuildInfoFile", "tsBuildInfoFile",
"typeRoots", "typeRoots",
@ -177,16 +171,13 @@ pub fn json_merge(a: &mut Value, b: &Value) {
fn parse_compiler_options( fn parse_compiler_options(
compiler_options: &HashMap<String, Value>, compiler_options: &HashMap<String, Value>,
maybe_specifier: Option<ModuleSpecifier>, maybe_specifier: Option<ModuleSpecifier>,
is_runtime: bool,
) -> Result<(Value, Option<IgnoredCompilerOptions>), AnyError> { ) -> Result<(Value, Option<IgnoredCompilerOptions>), AnyError> {
let mut filtered: HashMap<String, Value> = HashMap::new(); let mut filtered: HashMap<String, Value> = HashMap::new();
let mut items: Vec<String> = Vec::new(); let mut items: Vec<String> = Vec::new();
for (key, value) in compiler_options.iter() { for (key, value) in compiler_options.iter() {
let key = key.as_str(); let key = key.as_str();
if (!is_runtime && IGNORED_COMPILER_OPTIONS.contains(&key)) if IGNORED_COMPILER_OPTIONS.contains(&key) {
|| IGNORED_RUNTIME_COMPILER_OPTIONS.contains(&key)
{
items.push(key.to_string()); items.push(key.to_string());
} else { } else {
filtered.insert(key.to_string(), value.to_owned()); filtered.insert(key.to_string(), value.to_owned());
@ -261,19 +252,6 @@ impl TsConfig {
Ok(None) 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 { impl Serialize for TsConfig {
@ -585,7 +563,7 @@ impl ConfigFile {
let options: HashMap<String, Value> = let options: HashMap<String, Value> =
serde_json::from_value(compiler_options) serde_json::from_value(compiler_options)
.context("compilerOptions should be an object")?; .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 { } else {
Ok((json!({}), None)) Ok((json!({}), None))
} }
@ -910,38 +888,6 @@ mod tests {
assert!(ConfigFile::new(config_text, &config_specifier).is_err()); 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] #[test]
fn test_tsconfig_as_bytes() { fn test_tsconfig_as_bytes() {
let mut tsconfig1 = TsConfig::new(json!({ let mut tsconfig1 = TsConfig::new(json!({

View file

@ -119,7 +119,7 @@ pub enum TsConfigType {
Bundle, Bundle,
/// Return a configuration to use tsc to type check and optionally emit. This /// Return a configuration to use tsc to type check and optionally emit. This
/// is independent of either bundling or just emitting via swc /// 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. /// Return a configuration to use swc to emit single module files.
Emit, Emit,
} }
@ -148,19 +148,24 @@ pub fn get_ts_config_for_emit(
"jsxFactory": "React.createElement", "jsxFactory": "React.createElement",
"jsxFragmentFactory": "React.Fragment", "jsxFragmentFactory": "React.Fragment",
})), })),
TsConfigType::Check { tsc_emit, lib } => { TsConfigType::Check { lib } => TsConfig::new(json!({
let mut ts_config = TsConfig::new(json!({
"allowJs": true, "allowJs": true,
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
"checkJs": false, "checkJs": false,
"emitDecoratorMetadata": false,
"experimentalDecorators": true, "experimentalDecorators": true,
"incremental": true, "incremental": true,
"jsx": "react", "jsx": "react",
"jsxFactory": "React.createElement", "jsxFactory": "React.createElement",
"jsxFragmentFactory": "React.Fragment", "jsxFragmentFactory": "React.Fragment",
"importsNotUsedAsValues": "remove",
"inlineSourceMap": true,
"inlineSources": true,
"isolatedModules": true, "isolatedModules": true,
"lib": lib, "lib": lib,
"module": "esnext", "module": "esnext",
"moduleDetection": "force",
"noEmit": true,
"resolveJsonModule": true, "resolveJsonModule": true,
"sourceMap": false, "sourceMap": false,
"strict": true, "strict": true,
@ -169,23 +174,7 @@ pub fn get_ts_config_for_emit(
"useDefineForClassFields": true, "useDefineForClassFields": true,
// TODO(@kitsonk) remove for Deno 2.0 // TODO(@kitsonk) remove for Deno 2.0
"useUnknownInCatchVariables": false, "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::Emit => TsConfig::new(json!({ TsConfigType::Emit => TsConfig::new(json!({
"checkJs": false, "checkJs": false,
"emitDecoratorMetadata": false, "emitDecoratorMetadata": false,
@ -201,9 +190,6 @@ pub fn get_ts_config_for_emit(
}; };
let maybe_ignored_options = let maybe_ignored_options =
ts_config.merge_tsconfig_from_config_file(maybe_config_file)?; ts_config.merge_tsconfig_from_config_file(maybe_config_file)?;
ts_config.merge(&json!({
"moduleDetection": "force",
}));
Ok(TsConfigWithIgnoredOptions { Ok(TsConfigWithIgnoredOptions {
ts_config, ts_config,
maybe_ignored_options, maybe_ignored_options,

View file

@ -654,7 +654,6 @@ async fn create_graph_and_maybe_check(
if ps.options.type_check_mode() != TypeCheckMode::None { if ps.options.type_check_mode() != TypeCheckMode::None {
let ts_config_result = let ts_config_result =
ps.options.resolve_ts_config_for_emit(TsConfigType::Check { ps.options.resolve_ts_config_for_emit(TsConfigType::Check {
tsc_emit: false,
lib: ps.options.ts_type_lib_window(), lib: ps.options.ts_type_lib_window(),
})?; })?;
if let Some(ignored_options) = ts_config_result.maybe_ignored_options { if let Some(ignored_options) = ts_config_result.maybe_ignored_options {

View file

@ -414,10 +414,7 @@ impl ProcState {
let config_type = if self.options.type_check_mode() == TypeCheckMode::None { let config_type = if self.options.type_check_mode() == TypeCheckMode::None {
TsConfigType::Emit TsConfigType::Emit
} else { } else {
TsConfigType::Check { TsConfigType::Check { lib }
tsc_emit: true,
lib,
}
}; };
let ts_config_result = let ts_config_result =