mirror of
https://github.com/denoland/deno.git
synced 2024-12-21 23:04:45 -05:00
chore(cli): remove dead code related to previous tsc emit (#15196)
This commit is contained in:
parent
667812a297
commit
c2770c70b7
4 changed files with 54 additions and 126 deletions
|
@ -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))
|
||||
}
|
||||
|
@ -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!({
|
||||
|
|
70
cli/emit.rs
70
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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 =
|
||||
|
|
Loading…
Reference in a new issue