diff options
author | HasanAlrimawi <141642411+HasanAlrimawi@users.noreply.github.com> | 2024-07-03 02:15:10 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-02 23:15:10 +0000 |
commit | 3324d7203e8d00bb39cfae104e0aec61ba954e9b (patch) | |
tree | d5d2b612bca91fd8d5045ca4326c5ff12fcb51dd | |
parent | 7d919f6fd980ed54785e86892a518f0bdf68f475 (diff) |
fix(compile): prevent setting unstable feature twice (#24381)
Prevent panic when enabling a feature that is already enabled by
removing duplicate features.
Closes #22015
---------
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
7 files changed, 39 insertions, 3 deletions
diff --git a/cli/args/mod.rs b/cli/args/mod.rs index e1e6f9510..bf52c460f 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 000000000..ed6b0677d --- /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 000000000..00d38bee6 --- /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 000000000..022f2c580 --- /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 000000000..c0401f75f --- /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 000000000..2170a5a7d --- /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 000000000..c45100cfd --- /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"); |