Skip to content

Commit

Permalink
fix(compile): prevent setting unstable feature twice (#24381)
Browse files Browse the repository at this point in the history
Prevent panic when enabling a feature that is already enabled by
removing duplicate features.

Closes #22015

---------

Co-authored-by: Bartek Iwańczuk <[email protected]>
  • Loading branch information
HasanAlrimawi and bartlomieju committed Jul 2, 2024
1 parent 7d919f6 commit 3324d72
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 3 deletions.
20 changes: 17 additions & 3 deletions cli/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/specs/compile/repetitive_unstable_flag/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 1,2 @@
out.exe
out
13 changes: 13 additions & 0 deletions tests/specs/compile/repetitive_unstable_flag/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 1,13 @@
{
"steps": [
{
"args": "compile --unstable-kv -A --output out main.ts",
"output": "compile.out"
},
{
"commandName": "./out",
"args": [],
"output": "main.out"
}
]
}
2 changes: 2 additions & 0 deletions tests/specs/compile/repetitive_unstable_flag/compile.out
Original file line number Diff line number Diff line change
@@ -0,0 1,2 @@
Check [WILDCARD]main.ts
Compile [WILDCARD]main.ts to out[WILDCARD]
3 changes: 3 additions & 0 deletions tests/specs/compile/repetitive_unstable_flag/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 1,3 @@
{
"unstable": ["kv"]
}
1 change: 1 addition & 0 deletions tests/specs/compile/repetitive_unstable_flag/main.out
Original file line number Diff line number Diff line change
@@ -0,0 1 @@
Duplicate unstable feature issue is resolved as you can see
1 change: 1 addition & 0 deletions tests/specs/compile/repetitive_unstable_flag/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 1 @@
console.log("Duplicate unstable feature issue is resolved as you can see");

0 comments on commit 3324d72

Please sign in to comment.