mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 04:42:10 +00:00
fix(transformer/async-generator-functions): correct all binding scope id (#7425)
Fixed a bunch of semantic errors by removing moving binding logic 😢. This plugin constructs a complex `for-await` replacement so that I wrongly move to an incorrect scope.
This commit is contained in:
parent
bb2c0c219b
commit
4d6bd07afe
4 changed files with 12 additions and 4497 deletions
|
|
@ -786,15 +786,6 @@ impl<'a, 'ctx> AsyncGeneratorExecutor<'a, 'ctx> {
|
||||||
) {
|
) {
|
||||||
BindingMover::new(target_scope_id, ctx).visit_binding_identifier(ident);
|
BindingMover::new(target_scope_id, ctx).visit_binding_identifier(ident);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn move_bindings_to_target_scope_for_statement(
|
|
||||||
target_scope_id: ScopeId,
|
|
||||||
stmt: &Statement<'a>,
|
|
||||||
ctx: &mut TraverseCtx<'a>,
|
|
||||||
) {
|
|
||||||
BindingMover::new(target_scope_id, ctx).visit_statement(stmt);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Moves the bindings from original scope to target scope.
|
/// Moves the bindings from original scope to target scope.
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use oxc_span::SPAN;
|
||||||
use oxc_traverse::{Ancestor, BoundIdentifier, TraverseCtx};
|
use oxc_traverse::{Ancestor, BoundIdentifier, TraverseCtx};
|
||||||
|
|
||||||
use super::AsyncGeneratorFunctions;
|
use super::AsyncGeneratorFunctions;
|
||||||
use crate::{common::helper_loader::Helper, es2017::AsyncGeneratorExecutor};
|
use crate::common::helper_loader::Helper;
|
||||||
|
|
||||||
impl<'a, 'ctx> AsyncGeneratorFunctions<'a, 'ctx> {
|
impl<'a, 'ctx> AsyncGeneratorFunctions<'a, 'ctx> {
|
||||||
/// Check the parent node to see if multiple statements are allowed.
|
/// Check the parent node to see if multiple statements are allowed.
|
||||||
|
|
@ -254,7 +254,6 @@ impl<'a, 'ctx> AsyncGeneratorFunctions<'a, 'ctx> {
|
||||||
let block_scope_id = ctx.create_child_scope(parent_scope_id, ScopeFlags::empty());
|
let block_scope_id = ctx.create_child_scope(parent_scope_id, ScopeFlags::empty());
|
||||||
let for_statement_scope_id =
|
let for_statement_scope_id =
|
||||||
ctx.create_child_scope(block_scope_id, ScopeFlags::empty());
|
ctx.create_child_scope(block_scope_id, ScopeFlags::empty());
|
||||||
ctx.scopes_mut().change_parent_id(for_of_scope_id, Some(block_scope_id));
|
|
||||||
|
|
||||||
let for_statement = Statement::ForStatement(ctx.ast.alloc_for_statement_with_scope_id(
|
let for_statement = Statement::ForStatement(ctx.ast.alloc_for_statement_with_scope_id(
|
||||||
SPAN,
|
SPAN,
|
||||||
|
|
@ -330,28 +329,17 @@ impl<'a, 'ctx> AsyncGeneratorFunctions<'a, 'ctx> {
|
||||||
for_statement_body_scope_id,
|
for_statement_body_scope_id,
|
||||||
Some(for_statement_scope_id),
|
Some(for_statement_scope_id),
|
||||||
);
|
);
|
||||||
let statement = body.first().unwrap();
|
|
||||||
AsyncGeneratorExecutor::move_bindings_to_target_scope_for_statement(
|
|
||||||
for_statement_body_scope_id,
|
|
||||||
statement,
|
|
||||||
ctx,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Statement::BlockStatement(ctx.ast.alloc_block_statement_with_scope_id(
|
Statement::BlockStatement(ctx.ast.alloc_block_statement_with_scope_id(
|
||||||
SPAN,
|
SPAN,
|
||||||
body,
|
body,
|
||||||
for_statement_body_scope_id,
|
for_of_scope_id,
|
||||||
))
|
))
|
||||||
},
|
},
|
||||||
for_statement_scope_id,
|
for_statement_scope_id,
|
||||||
));
|
));
|
||||||
|
|
||||||
// // If has a label, we need to wrap the for statement with a labeled statement.
|
|
||||||
// // e.g. `label: for await (let i of test) {}` to `label: { for (let i of test) {} }`
|
|
||||||
// if let Some(label) = label {
|
|
||||||
// statement = ctx.ast.statement_labeled(SPAN, label, statement);
|
|
||||||
// }
|
|
||||||
ctx.ast.block_statement_with_scope_id(SPAN, ctx.ast.vec1(for_statement), block_scope_id)
|
ctx.ast.block_statement_with_scope_id(SPAN, ctx.ast.vec1(for_statement), block_scope_id)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -53451,24 +53451,15 @@ after transform: SymbolId(6) "M"
|
||||||
rebuilt : SymbolId(4) "M"
|
rebuilt : SymbolId(4) "M"
|
||||||
|
|
||||||
tasks/coverage/typescript/tests/cases/conformance/statements/VariableStatements/usingDeclarations/awaitUsingDeclarationsInForAwaitOf.ts
|
tasks/coverage/typescript/tests/cases/conformance/statements/VariableStatements/usingDeclarations/awaitUsingDeclarationsInForAwaitOf.ts
|
||||||
semantic error: Bindings mismatch:
|
semantic error: Scope children mismatch:
|
||||||
after transform: ScopeId(1): ["_didIteratorError", "_iterator", "_iteratorAbruptCompletion", "_iteratorError", "_step"]
|
|
||||||
rebuilt : ScopeId(3): ["_didIteratorError", "_iterator", "_iteratorAbruptCompletion", "_iteratorError", "_step", "d1"]
|
|
||||||
Scope children mismatch:
|
|
||||||
after transform: ScopeId(7): [ScopeId(2), ScopeId(15)]
|
after transform: ScopeId(7): [ScopeId(2), ScopeId(15)]
|
||||||
rebuilt : ScopeId(5): [ScopeId(6), ScopeId(8), ScopeId(9)]
|
rebuilt : ScopeId(5): [ScopeId(6), ScopeId(8), ScopeId(9)]
|
||||||
Scope parent mismatch:
|
Scope parent mismatch:
|
||||||
after transform: ScopeId(4): Some(ScopeId(2))
|
after transform: ScopeId(4): Some(ScopeId(2))
|
||||||
rebuilt : ScopeId(8): Some(ScopeId(5))
|
rebuilt : ScopeId(8): Some(ScopeId(5))
|
||||||
Bindings mismatch:
|
|
||||||
after transform: ScopeId(2): ["d1"]
|
|
||||||
rebuilt : ScopeId(9): []
|
|
||||||
Scope children mismatch:
|
Scope children mismatch:
|
||||||
after transform: ScopeId(2): [ScopeId(4)]
|
after transform: ScopeId(2): [ScopeId(4)]
|
||||||
rebuilt : ScopeId(9): []
|
rebuilt : ScopeId(9): []
|
||||||
Symbol scope ID mismatch for "d1":
|
|
||||||
after transform: SymbolId(1): ScopeId(2)
|
|
||||||
rebuilt : SymbolId(9): ScopeId(3)
|
|
||||||
|
|
||||||
tasks/coverage/typescript/tests/cases/conformance/statements/VariableStatements/usingDeclarations/usingDeclarations.1.ts
|
tasks/coverage/typescript/tests/cases/conformance/statements/VariableStatements/usingDeclarations/usingDeclarations.1.ts
|
||||||
semantic error: Missing SymbolId: "N"
|
semantic error: Missing SymbolId: "N"
|
||||||
|
|
@ -53503,24 +53494,15 @@ after transform: SymbolId(2): [ReferenceId(3)]
|
||||||
rebuilt : SymbolId(2): []
|
rebuilt : SymbolId(2): []
|
||||||
|
|
||||||
tasks/coverage/typescript/tests/cases/conformance/statements/VariableStatements/usingDeclarations/usingDeclarationsInForAwaitOf.ts
|
tasks/coverage/typescript/tests/cases/conformance/statements/VariableStatements/usingDeclarations/usingDeclarationsInForAwaitOf.ts
|
||||||
semantic error: Bindings mismatch:
|
semantic error: Scope children mismatch:
|
||||||
after transform: ScopeId(1): ["_didIteratorError", "_iterator", "_iteratorAbruptCompletion", "_iteratorError", "_step"]
|
|
||||||
rebuilt : ScopeId(3): ["_didIteratorError", "_iterator", "_iteratorAbruptCompletion", "_iteratorError", "_step", "d1"]
|
|
||||||
Scope children mismatch:
|
|
||||||
after transform: ScopeId(6): [ScopeId(2)]
|
after transform: ScopeId(6): [ScopeId(2)]
|
||||||
rebuilt : ScopeId(5): [ScopeId(6), ScopeId(7)]
|
rebuilt : ScopeId(5): [ScopeId(6), ScopeId(7)]
|
||||||
Scope parent mismatch:
|
Scope parent mismatch:
|
||||||
after transform: ScopeId(3): Some(ScopeId(2))
|
after transform: ScopeId(3): Some(ScopeId(2))
|
||||||
rebuilt : ScopeId(6): Some(ScopeId(5))
|
rebuilt : ScopeId(6): Some(ScopeId(5))
|
||||||
Bindings mismatch:
|
|
||||||
after transform: ScopeId(2): ["d1"]
|
|
||||||
rebuilt : ScopeId(7): []
|
|
||||||
Scope children mismatch:
|
Scope children mismatch:
|
||||||
after transform: ScopeId(2): [ScopeId(3)]
|
after transform: ScopeId(2): [ScopeId(3)]
|
||||||
rebuilt : ScopeId(7): []
|
rebuilt : ScopeId(7): []
|
||||||
Symbol scope ID mismatch for "d1":
|
|
||||||
after transform: SymbolId(1): ScopeId(2)
|
|
||||||
rebuilt : SymbolId(9): ScopeId(3)
|
|
||||||
|
|
||||||
tasks/coverage/typescript/tests/cases/conformance/statements/VariableStatements/usingDeclarations/usingDeclarationsNamedEvaluationDecoratorsAndClassFields.ts
|
tasks/coverage/typescript/tests/cases/conformance/statements/VariableStatements/usingDeclarations/usingDeclarationsNamedEvaluationDecoratorsAndClassFields.ts
|
||||||
semantic error: Bindings mismatch:
|
semantic error: Bindings mismatch:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue