Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(transformer/async-generator-functions): move handling of MethodDefinition's value to exit_function #7106

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
20 changes: 8 additions & 12 deletions crates/oxc_transformer/src/es2018/async_generator_functions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,22 +164,18 @@ impl<'a, 'ctx> Traverse<'a> for AsyncGeneratorFunctions<'a, 'ctx> {
}
}

fn exit_method_definition(
&mut self,
node: &mut MethodDefinition<'a>,
ctx: &mut TraverseCtx<'a>,
) {
let function = &mut node.value;
if function.r#async && function.generator && !function.is_typescript_syntax() {
self.executor.transform_function_for_method_definition(function, ctx);
}
}

fn enter_function(&mut self, func: &mut Function<'a>, _ctx: &mut TraverseCtx<'a>) {
self.stack.push(func.r#async && func.generator);
}

fn exit_function(&mut self, _func: &mut Function<'a>, _ctx: &mut TraverseCtx<'a>) {
fn exit_function(&mut self, func: &mut Function<'a>, ctx: &mut TraverseCtx<'a>) {
if func.r#async
&& func.generator
&& !func.is_typescript_syntax()
&& matches!(ctx.parent(), Ancestor::MethodDefinitionValue(_))
{
self.executor.transform_function_for_method_definition(func, ctx);
}
self.stack.pop();
}
}
Expand Down
12 changes: 1 addition & 11 deletions crates/oxc_transformer/src/es2018/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod async_generator_functions;
mod object_rest_spread;
mod options;

use oxc_ast::ast::{Expression, ForOfStatement, Function, MethodDefinition, Statement};
use oxc_ast::ast::{Expression, ForOfStatement, Function, Statement};
use oxc_traverse::{Traverse, TraverseCtx};

use crate::context::TransformCtx;
Expand Down Expand Up @@ -56,16 +56,6 @@ impl<'a, 'ctx> Traverse<'a> for ES2018<'a, 'ctx> {
}
}

fn exit_method_definition(
&mut self,
node: &mut MethodDefinition<'a>,
ctx: &mut TraverseCtx<'a>,
) {
if self.options.async_generator_functions {
self.async_generator_functions.exit_method_definition(node, ctx);
}
}

fn enter_for_of_statement(&mut self, node: &mut ForOfStatement<'a>, ctx: &mut TraverseCtx<'a>) {
if self.options.async_generator_functions {
self.async_generator_functions.enter_for_of_statement(node, ctx);
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_transformer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ impl<'a, 'ctx> Traverse<'a> for TransformerImpl<'a, 'ctx> {
if let Some(typescript) = self.x0_typescript.as_mut() {
typescript.exit_method_definition(def, ctx);
}
self.x2_es2018.exit_method_definition(def, ctx);
}

fn enter_new_expression(&mut self, expr: &mut NewExpression<'a>, ctx: &mut TraverseCtx<'a>) {
Expand Down
Loading