Skip to content

Commit

Permalink
refactor(transformer/async-generator-functions): move handling of `Me…
Browse files Browse the repository at this point in the history
…thodDefinition`'s value to `exit_function` (#7106)

Part of #7074

I have mentioned the reason why I need to move this in #7105
  • Loading branch information
Dunqing committed Nov 4, 2024
1 parent ae692d7 commit e04ee97
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 24 deletions.
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

0 comments on commit e04ee97

Please sign in to comment.