Skip to content

Commit

Permalink
Fix arguments in function param
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Nov 17, 2024
1 parent 5f4e91e commit f54762c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 36 deletions.
32 changes: 16 additions & 16 deletions crates/oxc_transformer/src/common/arrow_function_converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,9 @@ impl<'a> Traverse<'a> for ArrowFunctionConverter<'a> {

self.this_var_stack.push(None);
self.arguments_var_stack.push(None);
if self.is_async_only() {
let is_async_method = func.r#async && Self::is_class_method_like_ancestor(ctx.parent());
self.arguments_needs_transform_stack.push(is_async_method);
if is_async_method {
self.super_methods = Some(FxIndexMap::default());
}
if self.is_async_only() && func.r#async && Self::is_class_method_like_ancestor(ctx.parent())
{
self.super_methods = Some(FxIndexMap::default());
}
}

Expand All @@ -233,11 +230,6 @@ impl<'a> Traverse<'a> for ArrowFunctionConverter<'a> {
};
let this_var = self.this_var_stack.pop();
let arguments_var = self.arguments_var_stack.pop();

if self.is_async_only() {
self.arguments_needs_transform_stack.pop();
}

self.insert_variable_statement_at_the_top_of_statements(
scope_id,
&mut body.statements,
Expand All @@ -258,11 +250,19 @@ impl<'a> Traverse<'a> for ArrowFunctionConverter<'a> {
}
}

fn exit_arrow_function_expression(
&mut self,
_arrow: &mut ArrowFunctionExpression<'a>,
_ctx: &mut TraverseCtx<'a>,
) {
fn enter_function_body(&mut self, _body: &mut FunctionBody<'a>, ctx: &mut TraverseCtx<'a>) {
if self.is_async_only() {
// Ignore arrow functions
if let Ancestor::FunctionBody(func) = ctx.parent() {
let is_async_method =
*func.r#async() && Self::is_class_method_like_ancestor(ctx.ancestor(1));
self.arguments_needs_transform_stack.push(is_async_method);
}
}
}

fn exit_function_body(&mut self, _body: &mut FunctionBody<'a>, _ctx: &mut TraverseCtx<'a>) {
// This covers exiting either a `Function` or an `ArrowFunctionExpression`
if self.is_async_only() {
self.arguments_needs_transform_stack.pop();
}
Expand Down
12 changes: 6 additions & 6 deletions crates/oxc_transformer/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ impl<'a, 'ctx> Traverse<'a> for Common<'a, 'ctx> {
self.arrow_function_converter.enter_arrow_function_expression(arrow, ctx);
}

fn exit_arrow_function_expression(
&mut self,
arrow: &mut ArrowFunctionExpression<'a>,
ctx: &mut TraverseCtx<'a>,
) {
self.arrow_function_converter.exit_arrow_function_expression(arrow, ctx);
fn enter_function_body(&mut self, body: &mut FunctionBody<'a>, ctx: &mut TraverseCtx<'a>) {
self.arrow_function_converter.enter_function_body(body, ctx);
}

fn exit_function_body(&mut self, body: &mut FunctionBody<'a>, ctx: &mut TraverseCtx<'a>) {
self.arrow_function_converter.exit_function_body(body, ctx);
}

fn enter_static_block(&mut self, block: &mut StaticBlock<'a>, ctx: &mut TraverseCtx<'a>) {
Expand Down
10 changes: 8 additions & 2 deletions crates/oxc_transformer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,14 @@ impl<'a, 'ctx> Traverse<'a> for TransformerImpl<'a, 'ctx> {
self.common.exit_function(func, ctx);
}

fn enter_function_body(&mut self, body: &mut FunctionBody<'a>, ctx: &mut TraverseCtx<'a>) {
self.common.enter_function_body(body, ctx);
}

fn exit_function_body(&mut self, body: &mut FunctionBody<'a>, ctx: &mut TraverseCtx<'a>) {
self.common.exit_function_body(body, ctx);
}

fn enter_jsx_element(&mut self, node: &mut JSXElement<'a>, ctx: &mut TraverseCtx<'a>) {
if let Some(typescript) = self.x0_typescript.as_mut() {
typescript.enter_jsx_element(node, ctx);
Expand Down Expand Up @@ -429,8 +437,6 @@ impl<'a, 'ctx> Traverse<'a> for TransformerImpl<'a, 'ctx> {
.push(ctx.ast.statement_return(SPAN, Some(statement.unbox().expression)));
arrow.expression = false;
}

self.common.exit_arrow_function_expression(arrow, ctx);
}

fn exit_statements(
Expand Down
13 changes: 1 addition & 12 deletions tasks/coverage/snapshots/semantic_test262.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ commit: 06454619

semantic_test262 Summary:
AST Parsed : 43851/43851 (100.00%)
Positive Passed: 43039/43851 (98.15%)
Positive Passed: 43040/43851 (98.15%)
tasks/coverage/test262/test/annexB/language/function-code/if-decl-else-decl-a-func-block-scoping.js
semantic error: Symbol scope ID mismatch for "f":
after transform: SymbolId(3): ScopeId(4294967294)
Expand Down Expand Up @@ -6050,17 +6050,6 @@ Symbol scope ID mismatch for "x":
after transform: SymbolId(4): ScopeId(7)
rebuilt : SymbolId(5): ScopeId(4)

tasks/coverage/test262/test/language/statements/class/static-init-arguments-methods.js
semantic error: Symbol reference IDs mismatch for "_arguments":
after transform: SymbolId(15): [ReferenceId(16), ReferenceId(18)]
rebuilt : SymbolId(16): [ReferenceId(21)]
Reference symbol mismatch for "_arguments":
after transform: SymbolId(15) "_arguments"
rebuilt : <None>
Unresolved references mismatch:
after transform: ["arguments", "assert", "require"]
rebuilt : ["_arguments", "arguments", "assert", "require"]

tasks/coverage/test262/test/language/statements/for-await-of/async-from-sync-iterator-continuation-abrupt-completion-get-constructor.js
semantic error: Bindings mismatch:
after transform: ScopeId(1): ["_didIteratorError", "_iterator", "_iteratorAbruptCompletion", "_iteratorError", "_step", "p"]
Expand Down

0 comments on commit f54762c

Please sign in to comment.