Skip to content

Commit 86e46c5

Browse files
committed
feat: gate using declarations behind experimental feature flag
Signed-off-by: Abhinav Sharma <abhinavs1920bpl@gmail.com>
1 parent af80f7a commit 86e46c5

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

core/engine/src/bytecompiler/mod.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2260,8 +2260,14 @@ impl<'ctx> ByteCompiler<'ctx> {
22602260
}
22612261

22622262
// Add resource to disposal stack
2263+
#[cfg(feature = "experimental")]
22632264
self.bytecode.emit_add_disposable_resource(value.variable());
22642265

2266+
#[cfg(not(feature = "experimental"))]
2267+
self.emit_type_error(
2268+
"using declarations require the 'experimental' feature",
2269+
);
2270+
22652271
self.emit_binding(BindingOpcode::InitLexical, ident, &value);
22662272
self.register_allocator.dealloc(value);
22672273
}
@@ -2275,8 +2281,14 @@ impl<'ctx> ByteCompiler<'ctx> {
22752281
}
22762282

22772283
// Add resource to disposal stack
2284+
#[cfg(feature = "experimental")]
22782285
self.bytecode.emit_add_disposable_resource(value.variable());
22792286

2287+
#[cfg(not(feature = "experimental"))]
2288+
self.emit_type_error(
2289+
"using declarations require the 'experimental' feature",
2290+
);
2291+
22802292
self.compile_declaration_pattern(
22812293
pattern,
22822294
BindingOpcode::InitLexical,
@@ -2300,9 +2312,11 @@ impl<'ctx> ByteCompiler<'ctx> {
23002312
self.bytecode.emit_store_undefined(value.variable());
23012313
}
23022314

2303-
// TODO: Add resource to async disposal stack
2304-
// For now, we just bind the variable like a let declaration
2305-
// Full implementation will add: AddAsyncDisposableResource opcode
2315+
// await using is not yet implemented even under experimental
2316+
#[cfg(not(feature = "experimental"))]
2317+
self.emit_type_error(
2318+
"await using declarations require the 'experimental' feature",
2319+
);
23062320

23072321
self.emit_binding(BindingOpcode::InitLexical, ident, &value);
23082322
self.register_allocator.dealloc(value);
@@ -2316,7 +2330,12 @@ impl<'ctx> ByteCompiler<'ctx> {
23162330
self.bytecode.emit_store_undefined(value.variable());
23172331
}
23182332

2319-
// TODO: SAME
2333+
// await using is not yet implemented even under experimental
2334+
#[cfg(not(feature = "experimental"))]
2335+
self.emit_type_error(
2336+
"await using declarations require the 'experimental' feature",
2337+
);
2338+
23202339
self.compile_declaration_pattern(
23212340
pattern,
23222341
BindingOpcode::InitLexical,

core/engine/src/bytecompiler/statement/block.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use crate::bytecompiler::ByteCompiler;
2+
#[cfg(feature = "experimental")]
23
use boa_ast::{
34
declaration::LexicalDeclaration,
45
operations::{LexicallyScopedDeclaration, lexically_scoped_declarations},
5-
statement::Block,
66
};
7+
use boa_ast::statement::Block;
78

89
impl ByteCompiler<'_> {
910
/// Compile a [`Block`] `boa_ast` node
@@ -12,6 +13,7 @@ impl ByteCompiler<'_> {
1213
self.block_declaration_instantiation(block);
1314

1415
// Count how many `using` bindings are in this block (statically known at compile time)
16+
#[cfg(feature = "experimental")]
1517
let using_count: u32 = lexically_scoped_declarations(block)
1618
.iter()
1719
.filter_map(|decl| {
@@ -29,6 +31,7 @@ impl ByteCompiler<'_> {
2931
self.compile_statement_list(block.statement_list(), use_expr, true);
3032

3133
// Emit DisposeResources with the static count if there are any using declarations
34+
#[cfg(feature = "experimental")]
3235
if using_count > 0 {
3336
self.bytecode.emit_dispose_resources(using_count.into());
3437
}

0 commit comments

Comments
 (0)