From 3324d7203e8d00bb39cfae104e0aec61ba954e9b Mon Sep 17 00:00:00 2001 From: HasanAlrimawi <141642411+HasanAlrimawi@users.noreply.github.com> Date: Wed, 3 Jul 2024 02:15:10 +0300 Subject: [PATCH] fix(compile): prevent setting unstable feature twice (#24381) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prevent panic when enabling a feature that is already enabled by removing duplicate features. Closes #22015 --------- Co-authored-by: Bartek IwaƄczuk --- cli/args/mod.rs | 20 ++++++++++++++++--- .../repetitive_unstable_flag/.gitignore | 2 ++ .../repetitive_unstable_flag/__test__.jsonc | 13 ++++++++++++ .../repetitive_unstable_flag/compile.out | 2 ++ .../repetitive_unstable_flag/deno.json | 3 +++ .../compile/repetitive_unstable_flag/main.out | 1 + .../compile/repetitive_unstable_flag/main.ts | 1 + 7 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 tests/specs/compile/repetitive_unstable_flag/.gitignore create mode 100644 tests/specs/compile/repetitive_unstable_flag/__test__.jsonc create mode 100644 tests/specs/compile/repetitive_unstable_flag/compile.out create mode 100644 tests/specs/compile/repetitive_unstable_flag/deno.json create mode 100644 tests/specs/compile/repetitive_unstable_flag/main.out create mode 100644 tests/specs/compile/repetitive_unstable_flag/main.ts diff --git a/cli/args/mod.rs b/cli/args/mod.rs index e1e6f9510f..bf52c460f7 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -1773,14 +1773,28 @@ impl CliOptions { .map(|c| c.json.unstable.clone()) .unwrap_or_default(); - from_config_file.extend_from_slice(&self.flags.unstable_config.features); + self + .flags + .unstable_config + .features + .iter() + .for_each(|feature| { + if !from_config_file.contains(feature) { + from_config_file.push(feature.to_string()); + } + }); if *DENO_FUTURE { - from_config_file.extend_from_slice(&[ + let future_features = [ deno_runtime::deno_ffi::UNSTABLE_FEATURE_NAME.to_string(), deno_runtime::deno_fs::UNSTABLE_FEATURE_NAME.to_string(), deno_runtime::deno_webgpu::UNSTABLE_FEATURE_NAME.to_string(), - ]); + ]; + future_features.iter().for_each(|future_feature| { + if !from_config_file.contains(future_feature) { + from_config_file.push(future_feature.to_string()); + } + }); } from_config_file diff --git a/tests/specs/compile/repetitive_unstable_flag/.gitignore b/tests/specs/compile/repetitive_unstable_flag/.gitignore new file mode 100644 index 0000000000..ed6b0677d0 --- /dev/null +++ b/tests/specs/compile/repetitive_unstable_flag/.gitignore @@ -0,0 +1,2 @@ +out.exe +out diff --git a/tests/specs/compile/repetitive_unstable_flag/__test__.jsonc b/tests/specs/compile/repetitive_unstable_flag/__test__.jsonc new file mode 100644 index 0000000000..00d38bee6e --- /dev/null +++ b/tests/specs/compile/repetitive_unstable_flag/__test__.jsonc @@ -0,0 +1,13 @@ +{ + "steps": [ + { + "args": "compile --unstable-kv -A --output out main.ts", + "output": "compile.out" + }, + { + "commandName": "./out", + "args": [], + "output": "main.out" + } + ] +} diff --git a/tests/specs/compile/repetitive_unstable_flag/compile.out b/tests/specs/compile/repetitive_unstable_flag/compile.out new file mode 100644 index 0000000000..022f2c5802 --- /dev/null +++ b/tests/specs/compile/repetitive_unstable_flag/compile.out @@ -0,0 +1,2 @@ +Check [WILDCARD]main.ts +Compile [WILDCARD]main.ts to out[WILDCARD] diff --git a/tests/specs/compile/repetitive_unstable_flag/deno.json b/tests/specs/compile/repetitive_unstable_flag/deno.json new file mode 100644 index 0000000000..c0401f75f5 --- /dev/null +++ b/tests/specs/compile/repetitive_unstable_flag/deno.json @@ -0,0 +1,3 @@ +{ + "unstable": ["kv"] +} diff --git a/tests/specs/compile/repetitive_unstable_flag/main.out b/tests/specs/compile/repetitive_unstable_flag/main.out new file mode 100644 index 0000000000..2170a5a7df --- /dev/null +++ b/tests/specs/compile/repetitive_unstable_flag/main.out @@ -0,0 +1 @@ +Duplicate unstable feature issue is resolved as you can see diff --git a/tests/specs/compile/repetitive_unstable_flag/main.ts b/tests/specs/compile/repetitive_unstable_flag/main.ts new file mode 100644 index 0000000000..c45100cfd4 --- /dev/null +++ b/tests/specs/compile/repetitive_unstable_flag/main.ts @@ -0,0 +1 @@ +console.log("Duplicate unstable feature issue is resolved as you can see");