Skip to content

Commit

Permalink
fix(compile): preserve granular unstable features (#21827)
Browse files Browse the repository at this point in the history
Fix #21814
  • Loading branch information
bartlomieju committed Jan 12, 2024
1 parent 28e4f3d commit f5c1a8f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cli/standalone/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ pub enum NodeModules {
pub struct Metadata {
pub argv: Vec<String>,
pub unstable: bool,
pub unstable_features: Vec<String>,
pub seed: Option<u64>,
pub permissions: PermissionsOptions,
pub location: Option<Url>,
Expand Down Expand Up @@ -542,6 +543,7 @@ impl<'a> DenoCompileBinaryWriter<'a> {
let metadata = Metadata {
argv: compile_flags.args.clone(),
unstable: cli_options.unstable(),
unstable_features: cli_options.unstable_features(),
seed: cli_options.seed(),
location: cli_options.location_flag().clone(),
permissions: cli_options.permissions_options(),
Expand Down
5 changes: 5 additions & 0 deletions cli/standalone/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,11 @@ pub async fn run(
if metadata.unstable {
checker.enable_legacy_unstable();
}
for feature in metadata.unstable_features {
// `metadata` is valid for the whole lifetime of the program, so we
// can leak the string here.
checker.enable_feature(feature.leak());
}
checker
});
let worker_factory = CliMainWorkerFactory::new(
Expand Down
26 changes: 26 additions & 0 deletions cli/tests/integration/compile_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1123,3 +1123,29 @@ fn dynamic_imports_tmp_lit() {
let output = context.new_command().name(&exe).run();
output.assert_matches_text("a\nb\n{ data: 5 }\n{ data: 1 }\n");
}

#[test]
fn granular_unstable_features() {
let context = TestContextBuilder::new().build();
let dir = context.temp_dir();
let exe = if cfg!(windows) {
dir.path().join("app.exe")
} else {
dir.path().join("app")
};
let output = context
.new_command()
.args_vec([
"compile",
"--output",
&exe.to_string_lossy(),
"--unstable-kv",
"./compile/unstable_features.ts",
])
.run();
output.assert_exit_code(0);
output.skip_output_check();
let output = context.new_command().name(&exe).run();
output.assert_exit_code(0);
output.assert_matches_text("Kv {}\n");
}
2 changes: 2 additions & 0 deletions cli/tests/testdata/compile/unstable_features.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const db = await Deno.openKv();
console.log(db);

0 comments on commit f5c1a8f

Please sign in to comment.