Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ impl<'a> Traverse<'a> for ExplicitResourceManagement<'a, '_> {
let variable_declarator = decl.declarations.first_mut().unwrap();
variable_declarator.kind = VariableDeclarationKind::Const;

let variable_declarator_binding_ident =
variable_declarator.id.get_binding_identifier().unwrap();

let for_of_init_symbol_id = variable_declarator_binding_ident.symbol_id();
let for_of_init_name = variable_declarator_binding_ident.name;

let temp_id = ctx.generate_uid_based_on_node(
variable_declarator.id.get_binding_identifier().unwrap(),
for_of_stmt_scope_id,
Expand All @@ -107,6 +113,13 @@ impl<'a> Traverse<'a> for ExplicitResourceManagement<'a, '_> {
false,
));

let scope_id = match &mut for_of_stmt.body {
Statement::BlockStatement(block) => block.scope_id(),
_ => ctx.create_child_scope(for_of_stmt_scope_id, ScopeFlags::empty()),
};
ctx.scoping_mut().set_symbol_scope_id(for_of_init_symbol_id, scope_id);
ctx.scoping_mut().move_binding(for_of_stmt_scope_id, scope_id, &for_of_init_name);

if let Statement::BlockStatement(body) = &mut for_of_stmt.body {
// `for (const _x of y) { x(); }` -> `for (const _x of y) { using x = _x; x(); }`
body.body.insert(0, using_stmt);
Expand All @@ -115,11 +128,7 @@ impl<'a> Traverse<'a> for ExplicitResourceManagement<'a, '_> {
let old_body = ctx.ast.move_statement(&mut for_of_stmt.body);

let new_body = ctx.ast.vec_from_array([using_stmt, old_body]);
for_of_stmt.body = ctx.ast.statement_block_with_scope_id(
SPAN,
new_body,
ctx.create_child_scope(for_of_stmt_scope_id, ScopeFlags::empty()),
);
for_of_stmt.body = ctx.ast.statement_block_with_scope_id(SPAN, new_body, scope_id);
};
}

Expand Down
37 changes: 2 additions & 35 deletions tasks/transform_conformance/snapshots/babel.snap.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
commit: 578ac4df

Passed: 710/1191
Passed: 713/1191

# All Passed:
* babel-plugin-transform-logical-assignment-operators
Expand Down Expand Up @@ -2752,40 +2752,7 @@ transform-react-jsx: unknown field `autoImport`, expected one of `runtime`, `dev
x Output mismatch


# babel-plugin-proposal-explicit-resource-management (17/24)
* source-maps/for-of/input.js
Bindings mismatch:
after transform: ScopeId(1): ["_x", "x"]
rebuilt : ScopeId(1): ["_x"]
Bindings mismatch:
after transform: ScopeId(2): []
rebuilt : ScopeId(2): ["x"]
Symbol scope ID mismatch for "x":
after transform: SymbolId(0): ScopeId(1)
rebuilt : SymbolId(2): ScopeId(2)

* transform-sync/for-await-head/input.js
Bindings mismatch:
after transform: ScopeId(1): ["_x", "x"]
rebuilt : ScopeId(1): ["_x"]
Bindings mismatch:
after transform: ScopeId(2): []
rebuilt : ScopeId(2): ["x"]
Symbol scope ID mismatch for "x":
after transform: SymbolId(0): ScopeId(1)
rebuilt : SymbolId(2): ScopeId(2)

* transform-sync/for-head/input.js
Bindings mismatch:
after transform: ScopeId(1): ["_x", "x"]
rebuilt : ScopeId(1): ["_x"]
Bindings mismatch:
after transform: ScopeId(2): []
rebuilt : ScopeId(2): ["x"]
Symbol scope ID mismatch for "x":
after transform: SymbolId(0): ScopeId(1)
rebuilt : SymbolId(2): ScopeId(2)

# babel-plugin-proposal-explicit-resource-management (20/24)
* transform-sync/function-body/input.js
Bindings mismatch:
after transform: ScopeId(1): ["_usingCtx", "x"]
Expand Down
9 changes: 0 additions & 9 deletions tasks/transform_conformance/snapshots/oxc.snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,24 +325,15 @@ x Output mismatch
x Output mismatch

* for-of-no-block/input.js
Bindings mismatch:
after transform: ScopeId(1): ["_x", "x"]
rebuilt : ScopeId(1): ["_x"]
Scope children mismatch:
after transform: ScopeId(1): [ScopeId(2), ScopeId(3), ScopeId(4), ScopeId(5), ScopeId(7)]
rebuilt : ScopeId(1): [ScopeId(2), ScopeId(3), ScopeId(5), ScopeId(7)]
Bindings mismatch:
after transform: ScopeId(4): []
rebuilt : ScopeId(3): ["x"]
Scope children mismatch:
after transform: ScopeId(4): []
rebuilt : ScopeId(3): [ScopeId(4)]
Scope parent mismatch:
after transform: ScopeId(3): Some(ScopeId(1))
rebuilt : ScopeId(4): Some(ScopeId(3))
Symbol scope ID mismatch for "x":
after transform: SymbolId(0): ScopeId(1)
rebuilt : SymbolId(2): ScopeId(3)

* function-with-scopes-in-params/input.js
Bindings mismatch:
Expand Down
Loading