From 9f003bb839c3e1120877106854fbc988f6660f98 Mon Sep 17 00:00:00 2001 From: Ethan Goh <7086cmd@gmail.com> Date: Sun, 8 Sep 2024 00:17:37 +0800 Subject: [PATCH 01/25] feat: to async generator. --- .../src/es2017/async_to_generator.rs | 316 +++++++++ crates/oxc_transformer/src/es2017/mod.rs | 61 ++ crates/oxc_transformer/src/es2017/options.rs | 27 + .../oxc_transformer/src/es2017/utils/mod.rs | 608 ++++++++++++++++++ .../src/options/transformer.rs | 10 + tasks/transform_conformance/src/constants.rs | 2 +- 6 files changed, 1023 insertions(+), 1 deletion(-) create mode 100644 crates/oxc_transformer/src/es2017/async_to_generator.rs create mode 100644 crates/oxc_transformer/src/es2017/mod.rs create mode 100644 crates/oxc_transformer/src/es2017/options.rs create mode 100644 crates/oxc_transformer/src/es2017/utils/mod.rs diff --git a/crates/oxc_transformer/src/es2017/async_to_generator.rs b/crates/oxc_transformer/src/es2017/async_to_generator.rs new file mode 100644 index 0000000000000..0458f170ac90f --- /dev/null +++ b/crates/oxc_transformer/src/es2017/async_to_generator.rs @@ -0,0 +1,316 @@ +use crate::context::Ctx; +use crate::es2017::utils::{ + async_generator_step, async_to_generator, function_apply, generate_caller_from_arrow, + generate_caller_from_function, +}; +use oxc_allocator::{Box, CloneIn}; +use oxc_ast::ast::{ + ArrowFunctionExpression, AwaitExpression, BindingRestElement, Expression, + FormalParameterKind, Function, FunctionType, Program, Statement, TSThisParameter, + TSTypeAnnotation, TSTypeParameterDeclaration, TSTypeParameterInstantiation, + VariableDeclarationKind, +}; +use oxc_span::SPAN; +use oxc_syntax::operator::AssignmentOperator; +use oxc_traverse::{Ancestor, Traverse, TraverseCtx}; + +/// ES2017: Async / Await +/// +/// This plugin transforms async functions to generator functions. +/// +/// Reference: +/// * +/// * +/// * +pub struct AsyncToGenerator<'a> { + ctx: Ctx<'a>, + + inject_helpers: bool, +} + +impl<'a> AsyncToGenerator<'a> { + pub fn new(ctx: Ctx<'a>) -> Self { + Self { ctx, inject_helpers: false } + } +} + +impl<'a> AsyncToGenerator<'a> { + pub fn transform_await_to_yield(&mut self, decl: &Box) -> Expression<'a> { + self.ctx.ast.expression_yield( + SPAN, + false, + Some(decl.argument.clone_in(self.ctx.ast.allocator)), + ) + } +} + +impl<'a> Traverse<'a> for AsyncToGenerator<'a> { + fn exit_program(&mut self, program: &mut Program<'a>, _ctx: &mut TraverseCtx<'a>) { + let mut stmts = self.ctx.ast.vec(); + + if self.inject_helpers { + stmts.push(async_generator_step(&self.ctx.ast).clone_in(self.ctx.ast.allocator)); + stmts.push(async_to_generator(&self.ctx.ast).clone_in(self.ctx.ast.allocator)); + } + + for stmt in self.ctx.ast.move_vec(&mut program.body) { + match stmt { + Statement::FunctionDeclaration(mut decl) => { + if !decl.r#async || decl.generator { + stmts.push( + self.ctx.ast.statement_declaration( + self.ctx.ast.declaration_from_function( + decl.clone_in(self.ctx.ast.allocator), + ), + ), + ); + } else { + let mut result = self.ctx.ast.vec(); + decl.r#async = false; + decl.generator = true; + // TODO do not clone_in + let fn_name = decl + .id + .clone_in(self.ctx.ast.allocator) + .map_or("ref".to_owned(), |id| id.name.to_string()); + let alias_name = "_".to_owned() + fn_name.as_str(); + // generates the following code: + // function fn_name() { + // return alias_name.apply(this, arguments); + // } + result.push( + self.ctx + .ast + .statement_declaration(self.ctx.ast.declaration_function( + FunctionType::FunctionDeclaration, + SPAN, + Some(self.ctx.ast.binding_identifier(SPAN, fn_name.as_str())), + false, + false, + false, + decl.type_parameters.clone_in(self.ctx.ast.allocator), + decl.this_param.clone_in(self.ctx.ast.allocator), + decl.params.clone_in(self.ctx.ast.allocator), + decl.return_type.clone_in(self.ctx.ast.allocator), + Some(self.ctx.ast.function_body( + SPAN, + self.ctx.ast.vec(), + self.ctx.ast.vec1(function_apply( + alias_name.as_str(), + &self.ctx.ast, + )), + )), + )) + .clone_in(self.ctx.ast.allocator), + ); + result.push(self.ctx.ast.statement_declaration(self.ctx.ast.declaration_function( + FunctionType::FunctionDeclaration, + SPAN, + Some(self.ctx.ast.binding_identifier(SPAN, alias_name.as_str())), + false, + false, + false, + decl.type_parameters.clone_in(self.ctx.ast.allocator), + decl.this_param.clone_in(self.ctx.ast.allocator), + decl.params.clone_in(self.ctx.ast.allocator), + decl.return_type.clone_in(self.ctx.ast.allocator), + Some(self.ctx.ast.function_body(SPAN, self.ctx.ast.vec(), { + let mut result = self.ctx.ast.vec(); + result.push( + self.ctx.ast.statement_expression( + SPAN, + self.ctx.ast.expression_assignment( + SPAN, + AssignmentOperator::Assign, + self.ctx.ast.assignment_target_simple( + self.ctx.ast.simple_assignment_target_identifier_reference( + SPAN, + alias_name.as_str(), + ), + ), + self.ctx.ast.expression_call( + SPAN, + self.ctx + .ast + .expression_identifier_reference(SPAN, "_asyncToGenerator"), + None::, + self.ctx.ast.vec1(self.ctx.ast.argument_expression( + self.ctx.ast.expression_from_function( + decl.clone_in(self.ctx.ast.allocator), + ), + )), + false, + ), + ), + ), + ); + result.push( + function_apply(fn_name.as_str(), &self.ctx.ast) + .clone_in(self.ctx.ast.allocator), + ); + result + })), + ))); + stmts.extend(result); + } + } + _ => stmts.push(stmt), + } + } + program.body = stmts; + } + + fn exit_expression(&mut self, expr: &mut Expression<'a>, ctx: &mut TraverseCtx<'a>) { + match expr { + Expression::AwaitExpression(decl) => { + // Do not transform await in top-level + let in_function = ctx.ancestry.ancestors().any(|ancestor| { + matches!( + ancestor, + Ancestor::FunctionBody(_) | Ancestor::ArrowFunctionExpressionBody(_) + ) + }); + if in_function { + *expr = self.transform_await_to_yield(decl).clone_in(self.ctx.ast.allocator); + } + } + Expression::ArrowFunctionExpression(func) if func.r#async => { + let func = func.clone_in(self.ctx.ast.allocator); + if func.params.items.is_empty() { + *expr = generate_caller_from_arrow(func, &self.ctx.ast) + .clone_in(self.ctx.ast.allocator); + } else { + let mut statements = self.ctx.ast.vec(); + statements.push( + self.ctx.ast.statement_declaration( + self.ctx.ast.declaration_variable( + SPAN, + VariableDeclarationKind::Var, + self.ctx.ast.vec1( + self.ctx.ast.variable_declarator( + SPAN, + VariableDeclarationKind::Var, + self.ctx.ast.binding_pattern( + self.ctx.ast.binding_pattern_kind_binding_identifier( + SPAN, "_ref", + ), + None::, + false, + ), + Some( + generate_caller_from_arrow(func, &self.ctx.ast) + .clone_in(self.ctx.ast.allocator), + ), + false, + ), + ), + false, + ), + ), + ); + statements.push( + function_apply("_ref", &self.ctx.ast).clone_in(self.ctx.ast.allocator), + ); + *expr = self.ctx.ast.expression_parenthesized( + SPAN, + self.ctx.ast.expression_function( + FunctionType::FunctionExpression, + SPAN, + None, + false, + false, + false, + None::, + None::, + self.ctx.ast.formal_parameters( + SPAN, + FormalParameterKind::FormalParameter, + self.ctx.ast.vec(), + None::, + ), + None::, + Some(self.ctx.ast.function_body(SPAN, self.ctx.ast.vec(), statements)), + ), + ); + } + } + Expression::FunctionExpression(func) if func.r#async => { + let func = func.clone_in(self.ctx.ast.allocator); + if func.params.items.is_empty() { + *expr = generate_caller_from_function(&func, &self.ctx.ast) + .clone_in(self.ctx.ast.allocator); + } else { + let mut statements = self.ctx.ast.vec(); + statements.push( + self.ctx.ast.statement_declaration( + self.ctx.ast.declaration_variable( + SPAN, + VariableDeclarationKind::Var, + self.ctx.ast.vec1( + self.ctx.ast.variable_declarator( + SPAN, + VariableDeclarationKind::Var, + self.ctx.ast.binding_pattern( + self.ctx.ast.binding_pattern_kind_binding_identifier( + SPAN, "_ref", + ), + None::, + false, + ), + Some( + generate_caller_from_function(&func, &self.ctx.ast) + .clone_in(self.ctx.ast.allocator), + ), + false, + ), + ), + false, + ), + ), + ); + statements.push( + function_apply("_ref", &self.ctx.ast).clone_in(self.ctx.ast.allocator), + ); + *expr = self.ctx.ast.expression_parenthesized( + SPAN, + self.ctx.ast.expression_function( + FunctionType::FunctionExpression, + SPAN, + None, + false, + false, + false, + None::, + None::, + self.ctx.ast.formal_parameters( + SPAN, + FormalParameterKind::FormalParameter, + self.ctx.ast.vec(), + None::, + ), + None::, + Some(self.ctx.ast.function_body(SPAN, self.ctx.ast.vec(), statements)), + ), + ); + } + } + _ => {} + } + } + + fn enter_function(&mut self, function: &mut Function<'a>, _ctx: &mut TraverseCtx<'a>) { + if function.r#async && !function.generator { + self.inject_helpers = true; + } + } + + fn enter_arrow_function_expression( + &mut self, + function: &mut ArrowFunctionExpression<'a>, + _ctx: &mut TraverseCtx<'a>, + ) { + if function.r#async { + self.inject_helpers = true; + } + } +} diff --git a/crates/oxc_transformer/src/es2017/mod.rs b/crates/oxc_transformer/src/es2017/mod.rs new file mode 100644 index 0000000000000..5da579188b9a8 --- /dev/null +++ b/crates/oxc_transformer/src/es2017/mod.rs @@ -0,0 +1,61 @@ +mod async_to_generator; +pub mod options; +pub mod utils; + +use crate::context::Ctx; +use crate::es2017::async_to_generator::AsyncToGenerator; +use crate::es2017::options::ES2017Options; +use oxc_ast::ast::{ArrowFunctionExpression, CallExpression, Expression, Function, Program}; +use oxc_traverse::{Traverse, TraverseCtx}; +use std::rc::Rc; + +#[allow(dead_code)] +pub struct ES2017<'a> { + ctx: Ctx<'a>, + options: ES2017Options, + + // Plugins + async_to_generator: AsyncToGenerator<'a>, +} + +impl ES2017<'_> { + pub fn new(options: ES2017Options, ctx: Ctx) -> ES2017 { + ES2017 { async_to_generator: AsyncToGenerator::new(Rc::clone(&ctx)), ctx, options } + } +} + +impl<'a> Traverse<'a> for ES2017<'a> { + fn exit_program(&mut self, node: &mut Program<'a>, ctx: &mut TraverseCtx<'a>) { + if self.options.async_to_generator { + self.async_to_generator.exit_program(node, ctx); + } + } + + fn exit_expression(&mut self, node: &mut Expression<'a>, ctx: &mut TraverseCtx<'a>) { + if self.options.async_to_generator { + self.async_to_generator.exit_expression(node, ctx); + } + } + + fn exit_call_expression(&mut self, node: &mut CallExpression<'a>, ctx: &mut TraverseCtx<'a>) { + if self.options.async_to_generator { + self.async_to_generator.exit_call_expression(node, ctx); + } + } + + fn enter_function(&mut self, node: &mut Function<'a>, ctx: &mut TraverseCtx<'a>) { + if self.options.async_to_generator { + self.async_to_generator.enter_function(node, ctx); + } + } + + fn enter_arrow_function_expression( + &mut self, + node: &mut ArrowFunctionExpression<'a>, + ctx: &mut TraverseCtx<'a>, + ) { + if self.options.async_to_generator { + self.async_to_generator.enter_arrow_function_expression(node, ctx); + } + } +} diff --git a/crates/oxc_transformer/src/es2017/options.rs b/crates/oxc_transformer/src/es2017/options.rs new file mode 100644 index 0000000000000..16abf9d1afebc --- /dev/null +++ b/crates/oxc_transformer/src/es2017/options.rs @@ -0,0 +1,27 @@ +use crate::env::{can_enable_plugin, Versions}; +use serde::Deserialize; + +#[derive(Debug, Default, Clone, Deserialize)] +#[serde(default, rename_all = "camelCase", deny_unknown_fields)] +pub struct ES2017Options { + #[serde(skip)] + pub async_to_generator: bool, +} + +impl ES2017Options { + pub fn with_async_to_generator(&mut self, enable: bool) -> &mut Self { + self.async_to_generator = enable; + self + } + + #[must_use] + pub fn from_targets_and_bugfixes(targets: Option<&Versions>, bugfixes: bool) -> Self { + Self { + async_to_generator: can_enable_plugin( + "transform-async-to-generator", + targets, + bugfixes, + ), + } + } +} diff --git a/crates/oxc_transformer/src/es2017/utils/mod.rs b/crates/oxc_transformer/src/es2017/utils/mod.rs new file mode 100644 index 0000000000000..1d11e99febea6 --- /dev/null +++ b/crates/oxc_transformer/src/es2017/utils/mod.rs @@ -0,0 +1,608 @@ +use oxc_allocator::{Box, CloneIn}; +use oxc_ast::ast::{ + ArrowFunctionExpression, BindingRestElement, BlockStatement, Expression, FormalParameterKind, + Function, FunctionType, Statement, TSAccessibility, TSThisParameter, TSTypeAnnotation, + TSTypeParameterDeclaration, TSTypeParameterInstantiation, VariableDeclarationKind, +}; +use oxc_ast::AstBuilder; +use oxc_span::SPAN; +use oxc_syntax::operator::UnaryOperator; + +pub fn async_generator_step<'a>(builder: &'a AstBuilder) -> Statement<'a> { + builder.statement_declaration(builder.declaration_function( + FunctionType::FunctionDeclaration, + SPAN, + Some(builder.binding_identifier(SPAN, "asyncGeneratorStep")), + false, + false, + false, + None::, + None::, + builder.formal_parameters( + SPAN, + FormalParameterKind::FormalParameter, + { + let mut items = builder.vec(); + items.push(builder.formal_parameter( + SPAN, + builder.vec(), + builder.binding_pattern( + builder.binding_pattern_kind_binding_identifier(SPAN, "gen"), + None::, + false, + ), + None::, + false, + false, + )); + items.push(builder.formal_parameter( + SPAN, + builder.vec(), + builder.binding_pattern( + builder.binding_pattern_kind_binding_identifier(SPAN, "resolve"), + None::, + false, + ), + None::, + false, + false, + )); + items.push(builder.formal_parameter( + SPAN, + builder.vec(), + builder.binding_pattern( + builder.binding_pattern_kind_binding_identifier(SPAN, "reject"), + None::, + false, + ), + None::, + false, + false, + )); + items.push(builder.formal_parameter( + SPAN, + builder.vec(), + builder.binding_pattern( + builder.binding_pattern_kind_binding_identifier(SPAN, "_next"), + None::, + false, + ), + None::, + false, + false, + )); + items.push(builder.formal_parameter( + SPAN, + builder.vec(), + builder.binding_pattern( + builder.binding_pattern_kind_binding_identifier(SPAN, "_throw"), + None::, + false, + ), + None::, + false, + false, + )); + items.push(builder.formal_parameter( + SPAN, + builder.vec(), + builder.binding_pattern( + builder.binding_pattern_kind_binding_identifier(SPAN, "key"), + None::, + false, + ), + None::, + false, + false, + )); + items.push(builder.formal_parameter( + SPAN, + builder.vec(), + builder.binding_pattern( + builder.binding_pattern_kind_binding_identifier(SPAN, "arg"), + None::, + false, + ), + None::, + false, + false, + )); + items + }, + None::, + ), + None::, + Some(builder.function_body(SPAN, builder.vec(), { + let mut items = builder.vec(); + items.push(builder.statement_try( + SPAN, + builder.block_statement( + SPAN, + builder.vec1(builder.statement_declaration(builder.declaration_variable( + SPAN, + VariableDeclarationKind::Var, + { + let mut items = builder.vec(); + items.push(builder.variable_declarator( + SPAN, + VariableDeclarationKind::Var, + builder.binding_pattern( + builder.binding_pattern_kind_binding_identifier(SPAN, "i"), + None::, + false, + ), + Some(builder.expression_call( + SPAN, + builder.expression_member(builder.member_expression_computed( + SPAN, + builder.expression_identifier_reference(SPAN, "gen"), + builder.expression_identifier_reference(SPAN, "key"), + false, + )), + None::, + builder.vec1(builder.argument_expression( + builder.expression_identifier_reference(SPAN, "arg"), + )), + false, + )), + false, + )); + items.push(builder.variable_declarator( + SPAN, + VariableDeclarationKind::Var, + builder.binding_pattern( + builder.binding_pattern_kind_binding_identifier(SPAN, "u"), + None::, + false, + ), + Some(builder.expression_member(builder.member_expression_static( + SPAN, + builder.expression_identifier_reference(SPAN, "i"), + builder.identifier_name(SPAN, "value"), + false, + ))), + false, + )); + items + }, + false, + ))), + ), + Some(builder.catch_clause( + SPAN, + Some(builder.catch_parameter( + SPAN, + builder.binding_pattern( + builder.binding_pattern_kind_binding_identifier(SPAN, "gen"), + None::, + false, + ), + )), + builder.block_statement( + SPAN, + builder.vec1(builder.statement_return( + SPAN, + Some(builder.expression_unary( + SPAN, + UnaryOperator::Void, + builder.expression_call( + SPAN, + builder.expression_identifier_reference(SPAN, "reject"), + None::, + builder.vec1(builder.argument_expression( + builder.expression_identifier_reference(SPAN, "gen"), + )), + false, + ), + )), + )), + ), + )), + None::, + )); + items.push(builder.statement_expression( + SPAN, + builder.expression_conditional( + SPAN, + builder.expression_member(builder.member_expression_static( + SPAN, + builder.expression_identifier_reference(SPAN, "i"), + builder.identifier_name(SPAN, "done"), + false, + )), + builder.expression_call( + SPAN, + builder.expression_identifier_reference(SPAN, "resolve"), + None::, + builder.vec1(builder.argument_expression( + builder.expression_identifier_reference(SPAN, "u"), + )), + false, + ), + builder.expression_call( + SPAN, + builder.expression_member(builder.member_expression_static( + SPAN, + builder.expression_call( + SPAN, + builder.expression_member(builder.member_expression_static( + SPAN, + builder.expression_identifier_reference(SPAN, "Promise"), + builder.identifier_name(SPAN, "resolve"), + false, + )), + None::, + builder.vec1(builder.argument_expression( + builder.expression_identifier_reference(SPAN, "u"), + )), + false, + ), + builder.identifier_name(SPAN, "then"), + false, + )), + None::, + { + let mut items = builder.vec(); + items.push(builder.argument_expression( + builder.expression_identifier_reference(SPAN, "_next"), + )); + items.push(builder.argument_expression( + builder.expression_identifier_reference(SPAN, "_throw"), + )); + items + }, + false, + ), + ), + )); + items + })), + )) +} + +fn async_generator_step_caller<'a>(parameter: &'a str, builder: &'a AstBuilder) -> Statement<'a> { + builder.statement_declaration(builder.declaration_function( + FunctionType::FunctionDeclaration, + SPAN, + Some(builder.binding_identifier(SPAN, "_".to_owned() + parameter)), + false, + false, + false, + None::, + None::, + builder.formal_parameters( + SPAN, + FormalParameterKind::FormalParameter, + builder.vec1(builder.formal_parameter( + SPAN, + builder.vec(), + builder.binding_pattern( + builder.binding_pattern_kind_binding_identifier(SPAN, "gen"), + None::, + false, + ), + None::, + false, + false, + )), + None::, + ), + None::, + Some(builder.function_body( + SPAN, + builder.vec(), + builder.vec1(builder.statement_expression( + SPAN, + builder.expression_call( + SPAN, + builder.expression_identifier_reference(SPAN, "asyncGeneratorStep"), + None::, + { + let mut items = builder.vec(); + items.push(builder.argument_expression( + builder.expression_identifier_reference(SPAN, "key"), + )); + items.push(builder.argument_expression( + builder.expression_identifier_reference(SPAN, "_next"), + )); + items.push(builder.argument_expression( + builder.expression_identifier_reference(SPAN, "_throw"), + )); + items.push(builder.argument_expression( + builder.expression_identifier_reference(SPAN, "_next"), + )); + items.push(builder.argument_expression( + builder.expression_identifier_reference(SPAN, "_throw"), + )); + items.push(builder.argument_expression( + builder.expression_string_literal(SPAN, parameter), + )); + items.push(builder.argument_expression( + builder.expression_identifier_reference(SPAN, "gen"), + )); + items + }, + false, + ), + )), + )), + )) +} + +fn caller_promise<'a>(builder: &'a AstBuilder) -> Expression<'a> { + builder.expression_new( + SPAN, + builder.expression_identifier_reference(SPAN, "Promise"), + builder.vec1(builder.argument_expression(builder.expression_function( + FunctionType::FunctionExpression, + SPAN, + None, + false, + false, + false, + None::, + None::, + builder.formal_parameters( + SPAN, + FormalParameterKind::FormalParameter, + { + let mut items = builder.vec(); + items.push(builder.formal_parameter( + SPAN, + builder.vec(), + builder.binding_pattern( + builder.binding_pattern_kind_binding_identifier(SPAN, "_next"), + None::, + false, + ), + None::, + false, + false, + )); + items.push(builder.formal_parameter( + SPAN, + builder.vec(), + builder.binding_pattern( + builder.binding_pattern_kind_binding_identifier(SPAN, "_throw"), + None::, + false, + ), + None::, + false, + false, + )); + items + }, + None::, + ), + None::, + Some(builder.function_body(SPAN, builder.vec(), { + let mut items = builder.vec(); + items.push(builder.statement_declaration(builder.declaration_variable( + SPAN, + VariableDeclarationKind::Var, + builder.vec1(builder.variable_declarator( + SPAN, + VariableDeclarationKind::Var, + builder.binding_pattern( + builder.binding_pattern_kind_binding_identifier(SPAN, "key"), + None::, + false, + ), + Some(builder.expression_call( + SPAN, + builder.expression_member(builder.member_expression_static( + SPAN, + builder.expression_identifier_reference(SPAN, "fn"), + builder.identifier_name(SPAN, "apply"), + false, + )), + None::, + { + let mut items = builder.vec(); + items.push(builder.argument_expression( + builder.expression_identifier_reference(SPAN, "resolve"), + )); + items.push(builder.argument_expression( + builder.expression_identifier_reference(SPAN, "reject"), + )); + items + }, + false, + )), + false, + )), + false, + ))); + items.push(async_generator_step_caller("next", builder)); + items.push(async_generator_step_caller("throw", builder)); + items.push(builder.statement_expression( + SPAN, + builder.expression_call( + SPAN, + builder.expression_identifier_reference(SPAN, "_next"), + None::, + builder.vec1(builder.argument_expression(builder.void_0())), + false, + ), + )); + items + })), + ))), + None::, + ) +} + +pub fn async_to_generator<'a>(builder: &'a AstBuilder) -> Statement<'a> { + builder.statement_declaration(builder.declaration_function( + FunctionType::FunctionDeclaration, + SPAN, + Some(builder.binding_identifier(SPAN, "_asyncToGenerator")), + false, + false, + false, + None::, + None::, + builder.formal_parameters( + SPAN, + FormalParameterKind::FormalParameter, + builder.vec1(builder.formal_parameter( + SPAN, + builder.vec(), + builder.binding_pattern( + builder.binding_pattern_kind_binding_identifier(SPAN, "fn"), + None::, + false, + ), + None::, + false, + false, + )), + None::, + ), + None::, + Some(builder.function_body( + SPAN, + builder.vec(), + builder.vec1(builder.statement_return( + SPAN, + Some(builder.expression_function( + FunctionType::FunctionExpression, + SPAN, + None, + false, + false, + false, + None::, + None::, + builder.formal_parameters( + SPAN, + FormalParameterKind::FormalParameter, + builder.vec(), + None::, + ), + None::, + Some(builder.function_body(SPAN, builder.vec(), { + let mut items = builder.vec(); + items.push(builder.statement_declaration(builder.declaration_variable( + SPAN, + VariableDeclarationKind::Var, + { + let mut items = builder.vec(); + items.push(builder.variable_declarator( + SPAN, + VariableDeclarationKind::Var, + builder.binding_pattern( + builder.binding_pattern_kind_binding_identifier( + SPAN, "resolve", + ), + None::, + false, + ), + Some(builder.expression_this(SPAN)), + false, + )); + items.push(builder.variable_declarator( + SPAN, + VariableDeclarationKind::Var, + builder.binding_pattern( + builder.binding_pattern_kind_binding_identifier( + SPAN, "reject", + ), + None::, + false, + ), + Some( + builder.expression_identifier_reference(SPAN, "arguments"), + ), + false, + )); + items + }, + false, + ))); + items.push(builder.statement_return(SPAN, Some(caller_promise(builder)))); + items + })), + )), + )), + )), + )) +} + +pub fn function_apply<'a>(name: &'a str, builder: &'a AstBuilder) -> Statement<'a> { + builder.statement_return( + SPAN, + Some(builder.expression_call( + SPAN, + builder.expression_member(builder.member_expression_static( + SPAN, + builder.expression_identifier_reference(SPAN, name), + builder.identifier_name(SPAN, "apply"), + false, + )), + None::, + { + let mut items = builder.vec(); + items.push(builder.argument_expression(builder.expression_this(SPAN))); + items.push(builder.argument_expression( + builder.expression_identifier_reference(SPAN, "arguments"), + )); + items + }, + false, + )), + ) +} + +pub fn generate_caller_from_arrow<'a>( + func: Box, + builder: &'a AstBuilder, +) -> Expression<'a> { + let result = builder.function( + FunctionType::FunctionExpression, + func.span, + None, + true, + false, + false, + func.type_parameters.clone_in(builder.allocator), + None::, + func.params.clone_in(builder.allocator), + func.return_type.clone_in(builder.allocator), + Some(func.body.clone_in(builder.allocator)), + ); + builder.expression_call( + SPAN, + builder.expression_identifier_reference(SPAN, "_asyncToGenerator"), + None::, + builder.vec1(builder.argument_expression(builder.expression_from_function(result))), + false, + ) +} + +pub fn generate_caller_from_function<'a>( + func: &Box>, + builder: &'a AstBuilder, +) -> Expression<'a> { + let result = builder.function( + FunctionType::FunctionExpression, + func.span, + None, + true, + false, + false, + func.type_parameters.clone_in(builder.allocator), + None::, + func.params.clone_in(builder.allocator), + func.return_type.clone_in(builder.allocator), + func.body.clone_in(builder.allocator), + ); + builder.expression_call( + SPAN, + builder.expression_identifier_reference(SPAN, "_asyncToGenerator"), + None::, + builder.vec1(builder.argument_expression(builder.expression_from_function(result))), + false, + ) +} diff --git a/crates/oxc_transformer/src/options/transformer.rs b/crates/oxc_transformer/src/options/transformer.rs index 233db466627f6..4b6714fee1925 100644 --- a/crates/oxc_transformer/src/options/transformer.rs +++ b/crates/oxc_transformer/src/options/transformer.rs @@ -8,6 +8,7 @@ use crate::{ env::{can_enable_plugin, EnvOptions, Versions}, es2015::{ArrowFunctionsOptions, ES2015Options}, es2016::ES2016Options, + es2017::options::ES2017Options, es2018::{ES2018Options, ObjectRestSpreadOptions}, es2019::ES2019Options, es2020::ES2020Options, @@ -46,6 +47,8 @@ pub struct TransformOptions { pub es2016: ES2016Options, + pub es2017: ES2017Options, + pub es2018: ES2018Options, pub es2019: ES2019Options, @@ -83,6 +86,7 @@ impl TransformOptions { }, es2016: ES2016Options { exponentiation_operator: true }, es2018: ES2018Options { object_rest_spread: Some(ObjectRestSpreadOptions::default()) }, + es2017: ES2017Options { async_to_generator: true }, es2019: ES2019Options { optional_catch_binding: true }, es2020: ES2020Options { nullish_coalescing_operator: true }, es2021: ES2021Options { logical_assignment_operators: true }, @@ -93,6 +97,7 @@ impl TransformOptions { Self { es2015: ES2015Options::from_targets_and_bugfixes(targets, bugfixes), es2016: ES2016Options::from_targets_and_bugfixes(targets, bugfixes), + es2017: ES2017Options::from_targets_and_bugfixes(targets, bugfixes), es2018: ES2018Options::from_targets_and_bugfixes(targets, bugfixes), es2019: ES2019Options::from_targets_and_bugfixes(targets, bugfixes), es2020: ES2020Options::from_targets_and_bugfixes(targets, bugfixes), @@ -206,6 +211,11 @@ impl TransformOptions { get_enabled_plugin_options(plugin_name, options, targets.as_ref(), bugfixes).is_some() }); + transformer_options.es2017.with_async_to_generator({ + let plugin_name = "transform-async-to-generator"; + get_enabled_plugin_options(plugin_name, options, targets.as_ref(), bugfixes).is_some() + }); + transformer_options.es2018.with_object_rest_spread({ let plugin_name = "transform-object-rest-spread"; get_enabled_plugin_options(plugin_name, options, targets.as_ref(), bugfixes).map( diff --git a/tasks/transform_conformance/src/constants.rs b/tasks/transform_conformance/src/constants.rs index 01e619b1c4bb7..a22718f51b63b 100644 --- a/tasks/transform_conformance/src/constants.rs +++ b/tasks/transform_conformance/src/constants.rs @@ -29,7 +29,7 @@ pub(crate) const PLUGINS: &[&str] = &[ // "babel-plugin-transform-dotall-regex", // // [Regex] "babel-plugin-transform-named-capturing-groups-regex", // // ES2017 - // "babel-plugin-transform-async-to-generator", + "babel-plugin-transform-async-to-generator", // ES2016 "babel-plugin-transform-exponentiation-operator", // ES2015 From 1b82340e8fc3a6a2f0389acfd578fdc6d77c171f Mon Sep 17 00:00:00 2001 From: Ethan Goh <7086cmd@gmail.com> Date: Sun, 8 Sep 2024 00:18:34 +0800 Subject: [PATCH 02/25] chore: lint. --- .../oxc_transformer/src/es2017/async_to_generator.rs | 11 +++++------ crates/oxc_transformer/src/es2017/utils/mod.rs | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/crates/oxc_transformer/src/es2017/async_to_generator.rs b/crates/oxc_transformer/src/es2017/async_to_generator.rs index 0458f170ac90f..af8c645011851 100644 --- a/crates/oxc_transformer/src/es2017/async_to_generator.rs +++ b/crates/oxc_transformer/src/es2017/async_to_generator.rs @@ -5,10 +5,9 @@ use crate::es2017::utils::{ }; use oxc_allocator::{Box, CloneIn}; use oxc_ast::ast::{ - ArrowFunctionExpression, AwaitExpression, BindingRestElement, Expression, - FormalParameterKind, Function, FunctionType, Program, Statement, TSThisParameter, - TSTypeAnnotation, TSTypeParameterDeclaration, TSTypeParameterInstantiation, - VariableDeclarationKind, + ArrowFunctionExpression, AwaitExpression, BindingRestElement, Expression, FormalParameterKind, + Function, FunctionType, Program, Statement, TSThisParameter, TSTypeAnnotation, + TSTypeParameterDeclaration, TSTypeParameterInstantiation, VariableDeclarationKind, }; use oxc_span::SPAN; use oxc_syntax::operator::AssignmentOperator; @@ -177,7 +176,7 @@ impl<'a> Traverse<'a> for AsyncToGenerator<'a> { Expression::ArrowFunctionExpression(func) if func.r#async => { let func = func.clone_in(self.ctx.ast.allocator); if func.params.items.is_empty() { - *expr = generate_caller_from_arrow(func, &self.ctx.ast) + *expr = generate_caller_from_arrow(&func, &self.ctx.ast) .clone_in(self.ctx.ast.allocator); } else { let mut statements = self.ctx.ast.vec(); @@ -198,7 +197,7 @@ impl<'a> Traverse<'a> for AsyncToGenerator<'a> { false, ), Some( - generate_caller_from_arrow(func, &self.ctx.ast) + generate_caller_from_arrow(&func, &self.ctx.ast) .clone_in(self.ctx.ast.allocator), ), false, diff --git a/crates/oxc_transformer/src/es2017/utils/mod.rs b/crates/oxc_transformer/src/es2017/utils/mod.rs index 1d11e99febea6..1dbb3dc007563 100644 --- a/crates/oxc_transformer/src/es2017/utils/mod.rs +++ b/crates/oxc_transformer/src/es2017/utils/mod.rs @@ -556,7 +556,7 @@ pub fn function_apply<'a>(name: &'a str, builder: &'a AstBuilder) -> Statement<' } pub fn generate_caller_from_arrow<'a>( - func: Box, + func: &Box, builder: &'a AstBuilder, ) -> Expression<'a> { let result = builder.function( From 53c57cf061dde254d6961e126e4accd3c21830ec Mon Sep 17 00:00:00 2001 From: Ethan Goh <7086cmd@gmail.com> Date: Sun, 8 Sep 2024 07:05:27 +0800 Subject: [PATCH 03/25] fix: avoid iteration. --- .../src/es2017/async_to_generator.rs | 203 +++-- crates/oxc_transformer/src/es2017/mod.rs | 6 + crates/oxc_transformer/src/lib.rs | 1 + tasks/transform_conformance/oxc.snap.md | 795 ++++++++++++++++++ .../snapshots/babel.snap.md | 354 +++++++- .../snapshots/babel_exec.snap.md | 24 +- 6 files changed, 1230 insertions(+), 153 deletions(-) create mode 100644 tasks/transform_conformance/oxc.snap.md diff --git a/crates/oxc_transformer/src/es2017/async_to_generator.rs b/crates/oxc_transformer/src/es2017/async_to_generator.rs index af8c645011851..031ef210d6d67 100644 --- a/crates/oxc_transformer/src/es2017/async_to_generator.rs +++ b/crates/oxc_transformer/src/es2017/async_to_generator.rs @@ -51,111 +51,7 @@ impl<'a> Traverse<'a> for AsyncToGenerator<'a> { stmts.push(async_generator_step(&self.ctx.ast).clone_in(self.ctx.ast.allocator)); stmts.push(async_to_generator(&self.ctx.ast).clone_in(self.ctx.ast.allocator)); } - - for stmt in self.ctx.ast.move_vec(&mut program.body) { - match stmt { - Statement::FunctionDeclaration(mut decl) => { - if !decl.r#async || decl.generator { - stmts.push( - self.ctx.ast.statement_declaration( - self.ctx.ast.declaration_from_function( - decl.clone_in(self.ctx.ast.allocator), - ), - ), - ); - } else { - let mut result = self.ctx.ast.vec(); - decl.r#async = false; - decl.generator = true; - // TODO do not clone_in - let fn_name = decl - .id - .clone_in(self.ctx.ast.allocator) - .map_or("ref".to_owned(), |id| id.name.to_string()); - let alias_name = "_".to_owned() + fn_name.as_str(); - // generates the following code: - // function fn_name() { - // return alias_name.apply(this, arguments); - // } - result.push( - self.ctx - .ast - .statement_declaration(self.ctx.ast.declaration_function( - FunctionType::FunctionDeclaration, - SPAN, - Some(self.ctx.ast.binding_identifier(SPAN, fn_name.as_str())), - false, - false, - false, - decl.type_parameters.clone_in(self.ctx.ast.allocator), - decl.this_param.clone_in(self.ctx.ast.allocator), - decl.params.clone_in(self.ctx.ast.allocator), - decl.return_type.clone_in(self.ctx.ast.allocator), - Some(self.ctx.ast.function_body( - SPAN, - self.ctx.ast.vec(), - self.ctx.ast.vec1(function_apply( - alias_name.as_str(), - &self.ctx.ast, - )), - )), - )) - .clone_in(self.ctx.ast.allocator), - ); - result.push(self.ctx.ast.statement_declaration(self.ctx.ast.declaration_function( - FunctionType::FunctionDeclaration, - SPAN, - Some(self.ctx.ast.binding_identifier(SPAN, alias_name.as_str())), - false, - false, - false, - decl.type_parameters.clone_in(self.ctx.ast.allocator), - decl.this_param.clone_in(self.ctx.ast.allocator), - decl.params.clone_in(self.ctx.ast.allocator), - decl.return_type.clone_in(self.ctx.ast.allocator), - Some(self.ctx.ast.function_body(SPAN, self.ctx.ast.vec(), { - let mut result = self.ctx.ast.vec(); - result.push( - self.ctx.ast.statement_expression( - SPAN, - self.ctx.ast.expression_assignment( - SPAN, - AssignmentOperator::Assign, - self.ctx.ast.assignment_target_simple( - self.ctx.ast.simple_assignment_target_identifier_reference( - SPAN, - alias_name.as_str(), - ), - ), - self.ctx.ast.expression_call( - SPAN, - self.ctx - .ast - .expression_identifier_reference(SPAN, "_asyncToGenerator"), - None::, - self.ctx.ast.vec1(self.ctx.ast.argument_expression( - self.ctx.ast.expression_from_function( - decl.clone_in(self.ctx.ast.allocator), - ), - )), - false, - ), - ), - ), - ); - result.push( - function_apply(fn_name.as_str(), &self.ctx.ast) - .clone_in(self.ctx.ast.allocator), - ); - result - })), - ))); - stmts.extend(result); - } - } - _ => stmts.push(stmt), - } - } + stmts.extend(program.body.clone_in(self.ctx.ast.allocator)); program.body = stmts; } @@ -303,6 +199,103 @@ impl<'a> Traverse<'a> for AsyncToGenerator<'a> { } } + fn exit_function(&mut self, decl: &mut Function<'a>, ctx: &mut TraverseCtx<'a>) { + let fn_name = decl + .id + .clone_in(self.ctx.ast.allocator) + .map_or("ref".to_owned(), |id| id.name.to_string()); + let alias_name = "_".to_owned() + fn_name.as_str(); + let inner_function = self.ctx.ast.function( + decl.r#type.clone_in(self.ctx.ast.allocator), + SPAN, + Some(self.ctx.ast.binding_identifier(SPAN, alias_name.as_str())), + false, + false, + false, + decl.type_parameters.clone_in(self.ctx.ast.allocator), + decl.this_param.clone_in(self.ctx.ast.allocator), + decl.params.clone_in(self.ctx.ast.allocator), + decl.return_type.clone_in(self.ctx.ast.allocator), + Some(self.ctx.ast.function_body(SPAN, self.ctx.ast.vec(), { + let mut result = self.ctx.ast.vec(); + result.push(self.ctx.ast.statement_expression( + SPAN, + self.ctx.ast.expression_assignment( + SPAN, + AssignmentOperator::Assign, + self.ctx.ast.assignment_target_simple( + self.ctx.ast.simple_assignment_target_identifier_reference( + SPAN, + alias_name.as_str(), + ), + ), + self.ctx.ast.expression_call( + SPAN, + self.ctx.ast.expression_identifier_reference(SPAN, "_asyncToGenerator"), + None::, + self.ctx.ast.vec1(self.ctx.ast.argument_expression( + self.ctx.ast.expression_from_function( + decl.clone_in(self.ctx.ast.allocator), + ), + )), + false, + ), + ), + )); + result.push( + function_apply(fn_name.as_str(), &self.ctx.ast) + .clone_in(self.ctx.ast.allocator), + ); + result + })), + ); + *decl = self.ctx.ast.function( + decl.r#type.clone_in(self.ctx.ast.allocator), + SPAN, + Some(self.ctx.ast.binding_identifier(SPAN, "b")), + false, + false, + false, + decl.type_parameters.clone_in(self.ctx.ast.allocator), + decl.this_param.clone_in(self.ctx.ast.allocator), + decl.params.clone_in(self.ctx.ast.allocator), + decl.return_type.clone_in(self.ctx.ast.allocator), + Some(self.ctx.ast.function_body( + SPAN, + self.ctx.ast.vec(), + self.ctx.ast.vec1(self.ctx.ast.statement_return( + SPAN, + Some(self.ctx.ast.expression_call( + SPAN, + self.ctx.ast.expression_member(self.ctx.ast.member_expression_static( + SPAN, + self.ctx.ast.expression_parenthesized( + SPAN, + self.ctx.ast.expression_from_function(inner_function), + ), + self.ctx.ast.identifier_name(SPAN, "apply"), + false, + )), + None::, + { + let mut items = self.ctx.ast.vec(); + items.push( + self.ctx + .ast + .argument_expression(self.ctx.ast.expression_this(SPAN)), + ); + items.push(self.ctx.ast.argument_expression( + self.ctx.ast.expression_identifier_reference(SPAN, "arguments"), + )); + items + }, + false, + )), + )), + )), + ); + } + fn enter_arrow_function_expression( &mut self, function: &mut ArrowFunctionExpression<'a>, diff --git a/crates/oxc_transformer/src/es2017/mod.rs b/crates/oxc_transformer/src/es2017/mod.rs index 5da579188b9a8..8ed221ada31b4 100644 --- a/crates/oxc_transformer/src/es2017/mod.rs +++ b/crates/oxc_transformer/src/es2017/mod.rs @@ -49,6 +49,12 @@ impl<'a> Traverse<'a> for ES2017<'a> { } } + fn exit_function(&mut self, node: &mut Function<'a>, ctx: &mut TraverseCtx<'a>) { + if self.options.async_to_generator { + self.async_to_generator.exit_function(node, ctx); + } + } + fn enter_arrow_function_expression( &mut self, node: &mut ArrowFunctionExpression<'a>, diff --git a/crates/oxc_transformer/src/lib.rs b/crates/oxc_transformer/src/lib.rs index 159017bb92b6f..f5f4ad64abf6e 100644 --- a/crates/oxc_transformer/src/lib.rs +++ b/crates/oxc_transformer/src/lib.rs @@ -233,6 +233,7 @@ impl<'a, 'ctx> Traverse<'a> for TransformerImpl<'a, 'ctx> { fn exit_function(&mut self, func: &mut Function<'a>, ctx: &mut TraverseCtx<'a>) { self.x0_typescript.exit_function(func, ctx); self.x1_react.exit_function(func, ctx); + self.x2_es2017.exit_function(func, ctx); self.x3_es2015.exit_function(func, ctx); } diff --git a/tasks/transform_conformance/oxc.snap.md b/tasks/transform_conformance/oxc.snap.md new file mode 100644 index 0000000000000..333f08f7c005a --- /dev/null +++ b/tasks/transform_conformance/oxc.snap.md @@ -0,0 +1,795 @@ +commit: 3bcfee23 + +Passed: 18/49 + +# All Passed: +* babel-plugin-transform-nullish-coalescing-operator +* babel-plugin-transform-optional-catch-binding +* babel-preset-typescript + + +# babel-plugin-transform-arrow-functions (1/2) +* with-this-member-expression/input.jsx +x Output mismatch + + +# babel-plugin-transform-typescript (1/8) +* class-property-definition/input.ts +Unresolved references mismatch: +after transform: ["const"] +rebuilt : [] + +* computed-constant-value/input.ts +Missing ReferenceId: Infinity +Missing ReferenceId: Infinity +Missing ReferenceId: Infinity +Missing ReferenceId: Infinity +Bindings mismatch: +after transform: ScopeId(1): ["A", "a", "b", "c", "d", "e"] +rebuilt : ScopeId(1): ["A"] +Scope flags mismatch: +after transform: ScopeId(1): ScopeFlags(StrictMode) +rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) +Bindings mismatch: +after transform: ScopeId(2): ["B", "a", "b", "c", "d", "e"] +rebuilt : ScopeId(2): ["B"] +Scope flags mismatch: +after transform: ScopeId(2): ScopeFlags(StrictMode) +rebuilt : ScopeId(2): ScopeFlags(StrictMode | Function) +Bindings mismatch: +after transform: ScopeId(3): ["C", "a", "b", "c"] +rebuilt : ScopeId(3): ["C"] +Scope flags mismatch: +after transform: ScopeId(3): ScopeFlags(StrictMode) +rebuilt : ScopeId(3): ScopeFlags(StrictMode | Function) +Bindings mismatch: +after transform: ScopeId(4): ["D", "a", "b", "c"] +rebuilt : ScopeId(4): ["D"] +Scope flags mismatch: +after transform: ScopeId(4): ScopeFlags(StrictMode) +rebuilt : ScopeId(4): ScopeFlags(StrictMode | Function) +Symbol flags mismatch: +after transform: SymbolId(0): SymbolFlags(RegularEnum) +rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable) +Symbol flags mismatch: +after transform: SymbolId(6): SymbolFlags(RegularEnum) +rebuilt : SymbolId(2): SymbolFlags(FunctionScopedVariable) +Symbol flags mismatch: +after transform: SymbolId(12): SymbolFlags(RegularEnum) +rebuilt : SymbolId(4): SymbolFlags(FunctionScopedVariable) +Symbol flags mismatch: +after transform: SymbolId(16): SymbolFlags(RegularEnum) +rebuilt : SymbolId(6): SymbolFlags(FunctionScopedVariable) +Unresolved references mismatch: +after transform: ["Infinity", "NaN"] +rebuilt : ["Infinity"] +Unresolved reference IDs mismatch for "Infinity": +after transform: [ReferenceId(0), ReferenceId(1), ReferenceId(2), ReferenceId(3)] +rebuilt : [ReferenceId(2), ReferenceId(5), ReferenceId(8), ReferenceId(12)] + +* elimination-declare/input.ts +Bindings mismatch: +after transform: ScopeId(0): ["A", "ReactiveMarkerSymbol"] +rebuilt : ScopeId(0): [] +Scope children mismatch: +after transform: ScopeId(0): [ScopeId(1)] +rebuilt : ScopeId(0): [] + +* enum-member-reference/input.ts +Missing ReferenceId: Foo +Bindings mismatch: +after transform: ScopeId(1): ["Foo", "a", "b", "c"] +rebuilt : ScopeId(1): ["Foo"] +Scope flags mismatch: +after transform: ScopeId(1): ScopeFlags(StrictMode) +rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) +Symbol flags mismatch: +after transform: SymbolId(1): SymbolFlags(RegularEnum) +rebuilt : SymbolId(1): SymbolFlags(FunctionScopedVariable) +Symbol reference IDs mismatch: +after transform: SymbolId(5): [ReferenceId(3), ReferenceId(4), ReferenceId(5), ReferenceId(6), ReferenceId(7), ReferenceId(8), ReferenceId(9)] +rebuilt : SymbolId(2): [ReferenceId(0), ReferenceId(1), ReferenceId(2), ReferenceId(3), ReferenceId(4), ReferenceId(5), ReferenceId(6), ReferenceId(8)] + +* export-elimination/input.ts +Missing SymbolId: Name +Missing SymbolId: _Name +Missing ReferenceId: _Name +Missing ReferenceId: Name +Missing ReferenceId: Name +Bindings mismatch: +after transform: ScopeId(0): ["Baq", "Bar", "Baz", "Foo", "Func", "Im", "Name", "Ok", "T"] +rebuilt : ScopeId(0): ["Bar", "Foo", "Func", "Im", "Name", "Ok", "T"] +Scope children mismatch: +after transform: ScopeId(0): [ScopeId(1), ScopeId(2), ScopeId(3), ScopeId(4), ScopeId(5), ScopeId(6), ScopeId(7)] +rebuilt : ScopeId(0): [ScopeId(1), ScopeId(2), ScopeId(3), ScopeId(4)] +Binding symbols mismatch: +after transform: ScopeId(5): [SymbolId(8), SymbolId(10)] +rebuilt : ScopeId(3): [SymbolId(6), SymbolId(7)] +Symbol flags mismatch: +after transform: SymbolId(8): SymbolFlags(BlockScopedVariable | ConstVariable | Export) +rebuilt : SymbolId(7): SymbolFlags(BlockScopedVariable | ConstVariable) +Symbol flags mismatch: +after transform: SymbolId(9): SymbolFlags(BlockScopedVariable | Export | Function | TypeAlias) +rebuilt : SymbolId(8): SymbolFlags(BlockScopedVariable | Export | Function) +Symbol span mismatch: +after transform: SymbolId(9): Span { start: 205, end: 206 } +rebuilt : SymbolId(8): Span { start: 226, end: 227 } +Symbol reference IDs mismatch: +after transform: SymbolId(9): [ReferenceId(8), ReferenceId(9)] +rebuilt : SymbolId(8): [ReferenceId(9)] +Symbol redeclarations mismatch: +after transform: SymbolId(9): [Span { start: 226, end: 227 }] +rebuilt : SymbolId(8): [] +Reference symbol mismatch: +after transform: ReferenceId(7): Some("Name") +rebuilt : ReferenceId(8): Some("Name") + +* redeclarations/input.ts +Scope children mismatch: +after transform: ScopeId(0): [ScopeId(1), ScopeId(2)] +rebuilt : ScopeId(0): [] +Symbol flags mismatch: +after transform: SymbolId(0): SymbolFlags(BlockScopedVariable | ConstVariable | Export | Import) +rebuilt : SymbolId(0): SymbolFlags(BlockScopedVariable | ConstVariable | Export) +Symbol span mismatch: +after transform: SymbolId(0): Span { start: 57, end: 58 } +rebuilt : SymbolId(0): Span { start: 79, end: 83 } +Symbol reference IDs mismatch: +after transform: SymbolId(0): [ReferenceId(0), ReferenceId(1)] +rebuilt : SymbolId(0): [ReferenceId(0)] +Symbol redeclarations mismatch: +after transform: SymbolId(0): [Span { start: 79, end: 83 }] +rebuilt : SymbolId(0): [] +Symbol flags mismatch: +after transform: SymbolId(1): SymbolFlags(Export | Import | TypeAlias) +rebuilt : SymbolId(1): SymbolFlags(Export | Import) +Symbol redeclarations mismatch: +after transform: SymbolId(1): [Span { start: 170, end: 171 }] +rebuilt : SymbolId(1): [] +Symbol flags mismatch: +after transform: SymbolId(2): SymbolFlags(BlockScopedVariable | ConstVariable | Export | Import | TypeAlias) +rebuilt : SymbolId(2): SymbolFlags(BlockScopedVariable | ConstVariable | Export) +Symbol span mismatch: +after transform: SymbolId(2): Span { start: 267, end: 268 } +rebuilt : SymbolId(2): Span { start: 289, end: 293 } +Symbol reference IDs mismatch: +after transform: SymbolId(2): [ReferenceId(3), ReferenceId(4)] +rebuilt : SymbolId(2): [ReferenceId(2)] +Symbol redeclarations mismatch: +after transform: SymbolId(2): [Span { start: 289, end: 293 }, Span { start: 304, end: 305 }] +rebuilt : SymbolId(2): [] + +* ts-declaration-empty-output/input.d.ts +x Output mismatch + + +# babel-plugin-transform-react-jsx (6/27) +* refresh/can-handle-implicit-arrow-returns/input.jsx +Symbol reference IDs mismatch: +after transform: SymbolId(9): [ReferenceId(23), ReferenceId(24), ReferenceId(25)] +rebuilt : SymbolId(0): [ReferenceId(6), ReferenceId(7)] +Symbol reference IDs mismatch: +after transform: SymbolId(10): [ReferenceId(26), ReferenceId(27), ReferenceId(29)] +rebuilt : SymbolId(1): [ReferenceId(10), ReferenceId(13)] +Symbol reference IDs mismatch: +after transform: SymbolId(11): [ReferenceId(30), ReferenceId(31), ReferenceId(32)] +rebuilt : SymbolId(2): [ReferenceId(18), ReferenceId(19)] +Symbol reference IDs mismatch: +after transform: SymbolId(12): [ReferenceId(33), ReferenceId(34), ReferenceId(36)] +rebuilt : SymbolId(3): [ReferenceId(22), ReferenceId(25)] +Symbol reference IDs mismatch: +after transform: SymbolId(13): [ReferenceId(37), ReferenceId(38), ReferenceId(39), ReferenceId(40)] +rebuilt : SymbolId(4): [ReferenceId(29), ReferenceId(32), ReferenceId(33)] +Symbol reference IDs mismatch: +after transform: SymbolId(14): [ReferenceId(41), ReferenceId(42), ReferenceId(44)] +rebuilt : SymbolId(5): [ReferenceId(38), ReferenceId(41)] +Symbol reference IDs mismatch: +after transform: SymbolId(4): [ReferenceId(14), ReferenceId(45), ReferenceId(46)] +rebuilt : SymbolId(10): [ReferenceId(15), ReferenceId(46)] +Symbol reference IDs mismatch: +after transform: SymbolId(5): [ReferenceId(16), ReferenceId(47), ReferenceId(48)] +rebuilt : SymbolId(11): [ReferenceId(27), ReferenceId(48)] +Symbol reference IDs mismatch: +after transform: SymbolId(6): [ReferenceId(18), ReferenceId(49), ReferenceId(50)] +rebuilt : SymbolId(12): [ReferenceId(31), ReferenceId(50)] +Symbol reference IDs mismatch: +after transform: SymbolId(7): [ReferenceId(19), ReferenceId(51), ReferenceId(52)] +rebuilt : SymbolId(13): [ReferenceId(36), ReferenceId(52)] +Symbol reference IDs mismatch: +after transform: SymbolId(8): [ReferenceId(21), ReferenceId(53), ReferenceId(54)] +rebuilt : SymbolId(14): [ReferenceId(43), ReferenceId(54)] +Reference symbol mismatch: +after transform: ReferenceId(23): Some("_s") +rebuilt : ReferenceId(0): None +Reference symbol mismatch: +after transform: ReferenceId(26): Some("_s2") +rebuilt : ReferenceId(1): None +Reference symbol mismatch: +after transform: ReferenceId(30): Some("_s3") +rebuilt : ReferenceId(2): None +Reference symbol mismatch: +after transform: ReferenceId(33): Some("_s4") +rebuilt : ReferenceId(3): None +Reference symbol mismatch: +after transform: ReferenceId(37): Some("_s5") +rebuilt : ReferenceId(4): None +Reference symbol mismatch: +after transform: ReferenceId(41): Some("_s6") +rebuilt : ReferenceId(5): None +Reference flags mismatch: +after transform: ReferenceId(18): ReferenceFlags(Write) +rebuilt : ReferenceId(31): ReferenceFlags(Read | Write) +Reference symbol mismatch: +after transform: ReferenceId(45): Some("_c") +rebuilt : ReferenceId(45): None +Reference symbol mismatch: +after transform: ReferenceId(47): Some("_c2") +rebuilt : ReferenceId(47): None +Reference symbol mismatch: +after transform: ReferenceId(49): Some("_c3") +rebuilt : ReferenceId(49): None +Reference symbol mismatch: +after transform: ReferenceId(51): Some("_c4") +rebuilt : ReferenceId(51): None +Reference symbol mismatch: +after transform: ReferenceId(53): Some("_c5") +rebuilt : ReferenceId(53): None +Unresolved references mismatch: +after transform: ["X", "memo", "module", "useContext"] +rebuilt : ["$RefreshReg$", "$RefreshSig$", "X", "memo", "module", "useContext"] + +* refresh/does-not-consider-require-like-methods-to-be-hocs/input.jsx +Symbol reference IDs mismatch: +after transform: SymbolId(5): [ReferenceId(10), ReferenceId(17), ReferenceId(18)] +rebuilt : SymbolId(7): [ReferenceId(15), ReferenceId(18)] +Reference symbol mismatch: +after transform: ReferenceId(17): Some("_c") +rebuilt : ReferenceId(17): None +Unresolved references mismatch: +after transform: ["foo", "gk", "require", "requireCond"] +rebuilt : ["$RefreshReg$", "foo", "gk", "require", "requireCond"] + +* refresh/does-not-get-tripped-by-iifes/input.jsx +Bindings mismatch: +after transform: ScopeId(0): [] +rebuilt : ScopeId(0): ["_s"] +Bindings mismatch: +after transform: ScopeId(1): ["_s"] +rebuilt : ScopeId(1): [] +Symbol scope ID mismatch: +after transform: SymbolId(1): ScopeId(1) +rebuilt : SymbolId(0): ScopeId(0) +Symbol reference IDs mismatch: +after transform: SymbolId(1): [ReferenceId(3), ReferenceId(4), ReferenceId(5)] +rebuilt : SymbolId(0): [ReferenceId(2), ReferenceId(3)] +Reference symbol mismatch: +after transform: ReferenceId(3): Some("_s") +rebuilt : ReferenceId(1): None +Unresolved references mismatch: +after transform: ["item", "useFoo"] +rebuilt : ["$RefreshSig$", "item", "useFoo"] + +* refresh/generates-signatures-for-function-declarations-calling-hooks/input.jsx +Symbol reference IDs mismatch: +after transform: SymbolId(5): [ReferenceId(6), ReferenceId(7), ReferenceId(9)] +rebuilt : SymbolId(1): [ReferenceId(1), ReferenceId(6)] +Symbol reference IDs mismatch: +after transform: SymbolId(3): [ReferenceId(3), ReferenceId(10), ReferenceId(11)] +rebuilt : SymbolId(5): [ReferenceId(8), ReferenceId(11)] +Reference symbol mismatch: +after transform: ReferenceId(6): Some("_s") +rebuilt : ReferenceId(0): None +Reference symbol mismatch: +after transform: ReferenceId(10): Some("_c") +rebuilt : ReferenceId(10): None +Unresolved references mismatch: +after transform: ["React", "useState"] +rebuilt : ["$RefreshReg$", "$RefreshSig$", "React", "useState"] + +* refresh/generates-signatures-for-function-expressions-calling-hooks/input.jsx +Symbol reference IDs mismatch: +after transform: SymbolId(22): [ReferenceId(26), ReferenceId(27), ReferenceId(28), ReferenceId(29), ReferenceId(30)] +rebuilt : SymbolId(1): [ReferenceId(2), ReferenceId(5), ReferenceId(8), ReferenceId(9)] +Symbol reference IDs mismatch: +after transform: SymbolId(23): [ReferenceId(32), ReferenceId(33), ReferenceId(34), ReferenceId(35), ReferenceId(36)] +rebuilt : SymbolId(2): [ReferenceId(17), ReferenceId(20), ReferenceId(23), ReferenceId(24)] +Symbol reference IDs mismatch: +after transform: SymbolId(24): [ReferenceId(38), ReferenceId(39), ReferenceId(40)] +rebuilt : SymbolId(14): [ReferenceId(33), ReferenceId(34)] +Symbol reference IDs mismatch: +after transform: SymbolId(15): [ReferenceId(17), ReferenceId(41), ReferenceId(42)] +rebuilt : SymbolId(19): [ReferenceId(7), ReferenceId(42)] +Symbol reference IDs mismatch: +after transform: SymbolId(16): [ReferenceId(18), ReferenceId(43), ReferenceId(44)] +rebuilt : SymbolId(20): [ReferenceId(4), ReferenceId(44)] +Symbol reference IDs mismatch: +after transform: SymbolId(17): [ReferenceId(19), ReferenceId(45), ReferenceId(46)] +rebuilt : SymbolId(21): [ReferenceId(15), ReferenceId(46)] +Symbol reference IDs mismatch: +after transform: SymbolId(18): [ReferenceId(21), ReferenceId(47), ReferenceId(48)] +rebuilt : SymbolId(22): [ReferenceId(22), ReferenceId(48)] +Symbol reference IDs mismatch: +after transform: SymbolId(19): [ReferenceId(22), ReferenceId(49), ReferenceId(50)] +rebuilt : SymbolId(23): [ReferenceId(19), ReferenceId(50)] +Symbol reference IDs mismatch: +after transform: SymbolId(20): [ReferenceId(23), ReferenceId(51), ReferenceId(52)] +rebuilt : SymbolId(24): [ReferenceId(30), ReferenceId(52)] +Reference symbol mismatch: +after transform: ReferenceId(26): Some("_s") +rebuilt : ReferenceId(0): None +Reference symbol mismatch: +after transform: ReferenceId(32): Some("_s2") +rebuilt : ReferenceId(1): None +Reference flags mismatch: +after transform: ReferenceId(18): ReferenceFlags(Write) +rebuilt : ReferenceId(4): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(17): ReferenceFlags(Write) +rebuilt : ReferenceId(7): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(22): ReferenceFlags(Write) +rebuilt : ReferenceId(19): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(21): ReferenceFlags(Write) +rebuilt : ReferenceId(22): ReferenceFlags(Read | Write) +Reference symbol mismatch: +after transform: ReferenceId(38): Some("_s3") +rebuilt : ReferenceId(32): None +Reference symbol mismatch: +after transform: ReferenceId(41): Some("_c") +rebuilt : ReferenceId(41): None +Reference symbol mismatch: +after transform: ReferenceId(43): Some("_c2") +rebuilt : ReferenceId(43): None +Reference symbol mismatch: +after transform: ReferenceId(45): Some("_c3") +rebuilt : ReferenceId(45): None +Reference symbol mismatch: +after transform: ReferenceId(47): Some("_c4") +rebuilt : ReferenceId(47): None +Reference symbol mismatch: +after transform: ReferenceId(49): Some("_c5") +rebuilt : ReferenceId(49): None +Reference symbol mismatch: +after transform: ReferenceId(51): Some("_c6") +rebuilt : ReferenceId(51): None +Unresolved references mismatch: +after transform: ["React", "ref", "useState"] +rebuilt : ["$RefreshReg$", "$RefreshSig$", "React", "ref", "useState"] + +* refresh/generates-valid-signature-for-exotic-ways-to-call-hooks/input.jsx +Missing ScopeId +Scope children mismatch: +after transform: ScopeId(0): [ScopeId(1)] +rebuilt : ScopeId(0): [ScopeId(1), ScopeId(3)] +Symbol reference IDs mismatch: +after transform: SymbolId(10): [ReferenceId(17), ReferenceId(18), ReferenceId(20)] +rebuilt : SymbolId(0): [ReferenceId(1), ReferenceId(16)] +Symbol reference IDs mismatch: +after transform: SymbolId(8): [ReferenceId(11), ReferenceId(12), ReferenceId(14)] +rebuilt : SymbolId(4): [ReferenceId(3), ReferenceId(7)] +Symbol reference IDs mismatch: +after transform: SymbolId(7): [ReferenceId(9), ReferenceId(21), ReferenceId(22)] +rebuilt : SymbolId(10): [ReferenceId(19), ReferenceId(22)] +Reference symbol mismatch: +after transform: ReferenceId(17): Some("_s2") +rebuilt : ReferenceId(0): None +Reference symbol mismatch: +after transform: ReferenceId(11): Some("_s") +rebuilt : ReferenceId(2): None +Reference symbol mismatch: +after transform: ReferenceId(21): Some("_c") +rebuilt : ReferenceId(21): None +Unresolved references mismatch: +after transform: ["React", "useFancyEffect", "useThePlatform"] +rebuilt : ["$RefreshReg$", "$RefreshSig$", "React", "useFancyEffect", "useThePlatform"] + +* refresh/includes-custom-hooks-into-the-signatures/input.jsx +Missing ScopeId +Missing ScopeId +Scope children mismatch: +after transform: ScopeId(0): [ScopeId(1), ScopeId(2), ScopeId(4)] +rebuilt : ScopeId(0): [ScopeId(1), ScopeId(2), ScopeId(3), ScopeId(5), ScopeId(6)] +Symbol reference IDs mismatch: +after transform: SymbolId(7): [ReferenceId(9), ReferenceId(10), ReferenceId(12)] +rebuilt : SymbolId(1): [ReferenceId(3), ReferenceId(7)] +Symbol reference IDs mismatch: +after transform: SymbolId(8): [ReferenceId(13), ReferenceId(14), ReferenceId(16)] +rebuilt : SymbolId(2): [ReferenceId(10), ReferenceId(12)] +Symbol reference IDs mismatch: +after transform: SymbolId(10): [ReferenceId(19), ReferenceId(20), ReferenceId(22)] +rebuilt : SymbolId(3): [ReferenceId(14), ReferenceId(18)] +Symbol reference IDs mismatch: +after transform: SymbolId(6): [ReferenceId(6), ReferenceId(23), ReferenceId(24)] +rebuilt : SymbolId(10): [ReferenceId(21), ReferenceId(24)] +Reference symbol mismatch: +after transform: ReferenceId(9): Some("_s") +rebuilt : ReferenceId(0): None +Reference symbol mismatch: +after transform: ReferenceId(13): Some("_s2") +rebuilt : ReferenceId(1): None +Reference symbol mismatch: +after transform: ReferenceId(19): Some("_s3") +rebuilt : ReferenceId(2): None +Reference symbol mismatch: +after transform: ReferenceId(23): Some("_c") +rebuilt : ReferenceId(23): None +Unresolved references mismatch: +after transform: ["React"] +rebuilt : ["$RefreshReg$", "$RefreshSig$", "React"] + +* refresh/registers-capitalized-identifiers-in-hoc-calls/input.jsx +Symbol reference IDs mismatch: +after transform: SymbolId(3): [ReferenceId(6), ReferenceId(14), ReferenceId(15)] +rebuilt : SymbolId(4): [ReferenceId(1), ReferenceId(15)] +Symbol reference IDs mismatch: +after transform: SymbolId(4): [ReferenceId(8), ReferenceId(16), ReferenceId(17)] +rebuilt : SymbolId(5): [ReferenceId(3), ReferenceId(17)] +Symbol reference IDs mismatch: +after transform: SymbolId(5): [ReferenceId(9), ReferenceId(18), ReferenceId(19)] +rebuilt : SymbolId(6): [ReferenceId(8), ReferenceId(19)] +Symbol reference IDs mismatch: +after transform: SymbolId(6): [ReferenceId(11), ReferenceId(20), ReferenceId(21)] +rebuilt : SymbolId(7): [ReferenceId(12), ReferenceId(21)] +Reference flags mismatch: +after transform: ReferenceId(8): ReferenceFlags(Write) +rebuilt : ReferenceId(3): ReferenceFlags(Read | Write) +Reference symbol mismatch: +after transform: ReferenceId(14): Some("_c") +rebuilt : ReferenceId(14): None +Reference symbol mismatch: +after transform: ReferenceId(16): Some("_c2") +rebuilt : ReferenceId(16): None +Reference symbol mismatch: +after transform: ReferenceId(18): Some("_c3") +rebuilt : ReferenceId(18): None +Reference symbol mismatch: +after transform: ReferenceId(20): Some("_c4") +rebuilt : ReferenceId(20): None +Unresolved references mismatch: +after transform: ["hoc"] +rebuilt : ["$RefreshReg$", "hoc"] + +* refresh/registers-identifiers-used-in-jsx-at-definition-site/input.jsx +x Output mismatch + +* refresh/registers-identifiers-used-in-react-create-element-at-definition-site/input.jsx +x Output mismatch + +* refresh/registers-likely-hocs-with-inline-functions-1/input.jsx +Symbol reference IDs mismatch: +after transform: SymbolId(4): [ReferenceId(5), ReferenceId(18), ReferenceId(19)] +rebuilt : SymbolId(5): [ReferenceId(1), ReferenceId(19)] +Symbol reference IDs mismatch: +after transform: SymbolId(5): [ReferenceId(6), ReferenceId(20), ReferenceId(21)] +rebuilt : SymbolId(6): [ReferenceId(3), ReferenceId(21)] +Symbol reference IDs mismatch: +after transform: SymbolId(6): [ReferenceId(8), ReferenceId(22), ReferenceId(23)] +rebuilt : SymbolId(7): [ReferenceId(8), ReferenceId(23)] +Symbol reference IDs mismatch: +after transform: SymbolId(7): [ReferenceId(9), ReferenceId(24), ReferenceId(25)] +rebuilt : SymbolId(8): [ReferenceId(6), ReferenceId(25)] +Symbol reference IDs mismatch: +after transform: SymbolId(8): [ReferenceId(10), ReferenceId(26), ReferenceId(27)] +rebuilt : SymbolId(9): [ReferenceId(10), ReferenceId(27)] +Symbol reference IDs mismatch: +after transform: SymbolId(9): [ReferenceId(12), ReferenceId(28), ReferenceId(29)] +rebuilt : SymbolId(10): [ReferenceId(16), ReferenceId(29)] +Symbol reference IDs mismatch: +after transform: SymbolId(10): [ReferenceId(13), ReferenceId(30), ReferenceId(31)] +rebuilt : SymbolId(11): [ReferenceId(14), ReferenceId(31)] +Symbol reference IDs mismatch: +after transform: SymbolId(11): [ReferenceId(14), ReferenceId(32), ReferenceId(33)] +rebuilt : SymbolId(12): [ReferenceId(12), ReferenceId(33)] +Reference flags mismatch: +after transform: ReferenceId(5): ReferenceFlags(Write) +rebuilt : ReferenceId(1): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(9): ReferenceFlags(Write) +rebuilt : ReferenceId(6): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(8): ReferenceFlags(Write) +rebuilt : ReferenceId(8): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(14): ReferenceFlags(Write) +rebuilt : ReferenceId(12): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(13): ReferenceFlags(Write) +rebuilt : ReferenceId(14): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(12): ReferenceFlags(Write) +rebuilt : ReferenceId(16): ReferenceFlags(Read | Write) +Reference symbol mismatch: +after transform: ReferenceId(18): Some("_c") +rebuilt : ReferenceId(18): None +Reference symbol mismatch: +after transform: ReferenceId(20): Some("_c2") +rebuilt : ReferenceId(20): None +Reference symbol mismatch: +after transform: ReferenceId(22): Some("_c3") +rebuilt : ReferenceId(22): None +Reference symbol mismatch: +after transform: ReferenceId(24): Some("_c4") +rebuilt : ReferenceId(24): None +Reference symbol mismatch: +after transform: ReferenceId(26): Some("_c5") +rebuilt : ReferenceId(26): None +Reference symbol mismatch: +after transform: ReferenceId(28): Some("_c6") +rebuilt : ReferenceId(28): None +Reference symbol mismatch: +after transform: ReferenceId(30): Some("_c7") +rebuilt : ReferenceId(30): None +Reference symbol mismatch: +after transform: ReferenceId(32): Some("_c8") +rebuilt : ReferenceId(32): None +Unresolved references mismatch: +after transform: ["React", "forwardRef", "memo"] +rebuilt : ["$RefreshReg$", "React", "forwardRef", "memo"] + +* refresh/registers-likely-hocs-with-inline-functions-2/input.jsx +Symbol reference IDs mismatch: +after transform: SymbolId(2): [ReferenceId(2), ReferenceId(6), ReferenceId(7)] +rebuilt : SymbolId(3): [ReferenceId(4), ReferenceId(7)] +Symbol reference IDs mismatch: +after transform: SymbolId(3): [ReferenceId(3), ReferenceId(8), ReferenceId(9)] +rebuilt : SymbolId(4): [ReferenceId(2), ReferenceId(9)] +Symbol reference IDs mismatch: +after transform: SymbolId(4): [ReferenceId(4), ReferenceId(10), ReferenceId(11)] +rebuilt : SymbolId(5): [ReferenceId(0), ReferenceId(11)] +Reference flags mismatch: +after transform: ReferenceId(4): ReferenceFlags(Write) +rebuilt : ReferenceId(0): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(3): ReferenceFlags(Write) +rebuilt : ReferenceId(2): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(2): ReferenceFlags(Write) +rebuilt : ReferenceId(4): ReferenceFlags(Read | Write) +Reference symbol mismatch: +after transform: ReferenceId(6): Some("_c") +rebuilt : ReferenceId(6): None +Reference symbol mismatch: +after transform: ReferenceId(8): Some("_c2") +rebuilt : ReferenceId(8): None +Reference symbol mismatch: +after transform: ReferenceId(10): Some("_c3") +rebuilt : ReferenceId(10): None +Unresolved references mismatch: +after transform: ["React", "forwardRef"] +rebuilt : ["$RefreshReg$", "React", "forwardRef"] + +* refresh/registers-likely-hocs-with-inline-functions-3/input.jsx +Symbol reference IDs mismatch: +after transform: SymbolId(3): [ReferenceId(2), ReferenceId(6), ReferenceId(7)] +rebuilt : SymbolId(4): [ReferenceId(4), ReferenceId(7)] +Symbol reference IDs mismatch: +after transform: SymbolId(4): [ReferenceId(3), ReferenceId(8), ReferenceId(9)] +rebuilt : SymbolId(5): [ReferenceId(2), ReferenceId(9)] +Symbol reference IDs mismatch: +after transform: SymbolId(5): [ReferenceId(4), ReferenceId(10), ReferenceId(11)] +rebuilt : SymbolId(6): [ReferenceId(0), ReferenceId(11)] +Reference flags mismatch: +after transform: ReferenceId(4): ReferenceFlags(Write) +rebuilt : ReferenceId(0): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(3): ReferenceFlags(Write) +rebuilt : ReferenceId(2): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(2): ReferenceFlags(Write) +rebuilt : ReferenceId(4): ReferenceFlags(Read | Write) +Reference symbol mismatch: +after transform: ReferenceId(6): Some("_c") +rebuilt : ReferenceId(6): None +Reference symbol mismatch: +after transform: ReferenceId(8): Some("_c2") +rebuilt : ReferenceId(8): None +Reference symbol mismatch: +after transform: ReferenceId(10): Some("_c3") +rebuilt : ReferenceId(10): None +Unresolved references mismatch: +after transform: ["React", "forwardRef"] +rebuilt : ["$RefreshReg$", "React", "forwardRef"] + +* refresh/registers-top-level-exported-function-declarations/input.jsx +Symbol reference IDs mismatch: +after transform: SymbolId(7): [ReferenceId(4), ReferenceId(13), ReferenceId(14)] +rebuilt : SymbolId(8): [ReferenceId(2), ReferenceId(14)] +Symbol reference IDs mismatch: +after transform: SymbolId(8): [ReferenceId(6), ReferenceId(15), ReferenceId(16)] +rebuilt : SymbolId(9): [ReferenceId(6), ReferenceId(16)] +Symbol reference IDs mismatch: +after transform: SymbolId(9): [ReferenceId(8), ReferenceId(17), ReferenceId(18)] +rebuilt : SymbolId(10): [ReferenceId(9), ReferenceId(18)] +Reference symbol mismatch: +after transform: ReferenceId(13): Some("_c") +rebuilt : ReferenceId(13): None +Reference symbol mismatch: +after transform: ReferenceId(15): Some("_c2") +rebuilt : ReferenceId(15): None +Reference symbol mismatch: +after transform: ReferenceId(17): Some("_c3") +rebuilt : ReferenceId(17): None +Unresolved references mismatch: +after transform: [] +rebuilt : ["$RefreshReg$"] + +* refresh/registers-top-level-exported-named-arrow-functions/input.jsx +Symbol reference IDs mismatch: +after transform: SymbolId(4): [ReferenceId(3), ReferenceId(10), ReferenceId(11)] +rebuilt : SymbolId(5): [ReferenceId(2), ReferenceId(11)] +Symbol reference IDs mismatch: +after transform: SymbolId(5): [ReferenceId(5), ReferenceId(12), ReferenceId(13)] +rebuilt : SymbolId(6): [ReferenceId(6), ReferenceId(13)] +Reference symbol mismatch: +after transform: ReferenceId(10): Some("_c") +rebuilt : ReferenceId(10): None +Reference symbol mismatch: +after transform: ReferenceId(12): Some("_c2") +rebuilt : ReferenceId(12): None +Unresolved references mismatch: +after transform: [] +rebuilt : ["$RefreshReg$"] + +* refresh/registers-top-level-function-declarations/input.jsx +Symbol reference IDs mismatch: +after transform: SymbolId(3): [ReferenceId(2), ReferenceId(8), ReferenceId(9)] +rebuilt : SymbolId(4): [ReferenceId(2), ReferenceId(9)] +Symbol reference IDs mismatch: +after transform: SymbolId(4): [ReferenceId(4), ReferenceId(10), ReferenceId(11)] +rebuilt : SymbolId(5): [ReferenceId(6), ReferenceId(11)] +Reference symbol mismatch: +after transform: ReferenceId(8): Some("_c") +rebuilt : ReferenceId(8): None +Reference symbol mismatch: +after transform: ReferenceId(10): Some("_c2") +rebuilt : ReferenceId(10): None +Unresolved references mismatch: +after transform: [] +rebuilt : ["$RefreshReg$"] + +* refresh/registers-top-level-variable-declarations-with-arrow-functions/input.jsx +Symbol reference IDs mismatch: +after transform: SymbolId(5): [ReferenceId(2), ReferenceId(11), ReferenceId(12)] +rebuilt : SymbolId(6): [ReferenceId(2), ReferenceId(12)] +Symbol reference IDs mismatch: +after transform: SymbolId(6): [ReferenceId(4), ReferenceId(13), ReferenceId(14)] +rebuilt : SymbolId(7): [ReferenceId(6), ReferenceId(14)] +Symbol reference IDs mismatch: +after transform: SymbolId(7): [ReferenceId(6), ReferenceId(15), ReferenceId(16)] +rebuilt : SymbolId(8): [ReferenceId(9), ReferenceId(16)] +Reference symbol mismatch: +after transform: ReferenceId(11): Some("_c") +rebuilt : ReferenceId(11): None +Reference symbol mismatch: +after transform: ReferenceId(13): Some("_c2") +rebuilt : ReferenceId(13): None +Reference symbol mismatch: +after transform: ReferenceId(15): Some("_c3") +rebuilt : ReferenceId(15): None +Unresolved references mismatch: +after transform: [] +rebuilt : ["$RefreshReg$"] + +* refresh/registers-top-level-variable-declarations-with-function-expressions/input.jsx +Symbol reference IDs mismatch: +after transform: SymbolId(7): [ReferenceId(2), ReferenceId(8), ReferenceId(9)] +rebuilt : SymbolId(8): [ReferenceId(2), ReferenceId(9)] +Symbol reference IDs mismatch: +after transform: SymbolId(8): [ReferenceId(4), ReferenceId(10), ReferenceId(11)] +rebuilt : SymbolId(9): [ReferenceId(6), ReferenceId(11)] +Reference symbol mismatch: +after transform: ReferenceId(8): Some("_c") +rebuilt : ReferenceId(8): None +Reference symbol mismatch: +after transform: ReferenceId(10): Some("_c2") +rebuilt : ReferenceId(10): None +Unresolved references mismatch: +after transform: [] +rebuilt : ["$RefreshReg$"] + +* refresh/supports-typescript-namespace-syntax/input.tsx +x Output mismatch + +* refresh/uses-custom-identifiers-for-refresh-reg-and-refresh-sig/input.jsx +Symbol reference IDs mismatch: +after transform: SymbolId(3): [ReferenceId(6), ReferenceId(7), ReferenceId(9)] +rebuilt : SymbolId(1): [ReferenceId(1), ReferenceId(6)] +Symbol reference IDs mismatch: +after transform: SymbolId(1): [ReferenceId(3), ReferenceId(10), ReferenceId(11)] +rebuilt : SymbolId(3): [ReferenceId(8), ReferenceId(11)] +Reference symbol mismatch: +after transform: ReferenceId(6): Some("_s") +rebuilt : ReferenceId(0): None +Reference symbol mismatch: +after transform: ReferenceId(10): Some("_c") +rebuilt : ReferenceId(10): None +Unresolved references mismatch: +after transform: ["Foo", "X", "useContext"] +rebuilt : ["Foo", "X", "import.meta.refreshReg", "import.meta.refreshSig", "useContext"] + +* refresh/uses-original-function-declaration-if-it-get-reassigned/input.jsx +Symbol reference IDs mismatch: +after transform: SymbolId(1): [ReferenceId(3), ReferenceId(6), ReferenceId(7)] +rebuilt : SymbolId(2): [ReferenceId(1), ReferenceId(7)] +Reference symbol mismatch: +after transform: ReferenceId(6): Some("_c") +rebuilt : ReferenceId(6): None +Unresolved references mismatch: +after transform: ["connect"] +rebuilt : ["$RefreshReg$", "connect"] + + +# regexp (6/8) +* all-regex-plugins-enabled-by-targets/input.js +Missing ReferenceId: x1 +Missing ReferenceId: RegExp +Missing ReferenceId: x2 +Missing ReferenceId: RegExp +Missing ReferenceId: a1 +Missing ReferenceId: RegExp +Missing ReferenceId: b1 +Missing ReferenceId: RegExp +Missing ReferenceId: b2 +Missing ReferenceId: RegExp +Missing ReferenceId: b3 +Missing ReferenceId: RegExp +Missing ReferenceId: b4 +Missing ReferenceId: RegExp +Missing ReferenceId: c1 +Missing ReferenceId: RegExp +Missing ReferenceId: c2 +Missing ReferenceId: RegExp +Missing ReferenceId: d1 +Missing ReferenceId: RegExp +Missing ReferenceId: f1 +Missing ReferenceId: RegExp +Missing ReferenceId: g1 +Missing ReferenceId: RegExp +Unresolved reference IDs mismatch for "c1": +after transform: [ReferenceId(7)] +rebuilt : [ReferenceId(14)] +Unresolved reference IDs mismatch for "b4": +after transform: [ReferenceId(6)] +rebuilt : [ReferenceId(12)] +Unresolved reference IDs mismatch for "b1": +after transform: [ReferenceId(3)] +rebuilt : [ReferenceId(6)] +Unresolved reference IDs mismatch for "b3": +after transform: [ReferenceId(5)] +rebuilt : [ReferenceId(10)] +Unresolved reference IDs mismatch for "c2": +after transform: [ReferenceId(8)] +rebuilt : [ReferenceId(16)] +Unresolved reference IDs mismatch for "g1": +after transform: [ReferenceId(11)] +rebuilt : [ReferenceId(22)] +Unresolved reference IDs mismatch for "b2": +after transform: [ReferenceId(4)] +rebuilt : [ReferenceId(8)] +Unresolved reference IDs mismatch for "RegExp": +after transform: [ReferenceId(12), ReferenceId(13), ReferenceId(14), ReferenceId(15), ReferenceId(16), ReferenceId(17), ReferenceId(18), ReferenceId(19), ReferenceId(20), ReferenceId(21), ReferenceId(22), ReferenceId(23)] +rebuilt : [ReferenceId(1), ReferenceId(3), ReferenceId(5), ReferenceId(7), ReferenceId(9), ReferenceId(11), ReferenceId(13), ReferenceId(15), ReferenceId(17), ReferenceId(19), ReferenceId(21), ReferenceId(23)] +Unresolved reference IDs mismatch for "f1": +after transform: [ReferenceId(10)] +rebuilt : [ReferenceId(20)] +Unresolved reference IDs mismatch for "a1": +after transform: [ReferenceId(2)] +rebuilt : [ReferenceId(4)] +Unresolved reference IDs mismatch for "d1": +after transform: [ReferenceId(9)] +rebuilt : [ReferenceId(18)] +Unresolved reference IDs mismatch for "x1": +after transform: [ReferenceId(0)] +rebuilt : [ReferenceId(0)] +Unresolved reference IDs mismatch for "x2": +after transform: [ReferenceId(1)] +rebuilt : [ReferenceId(2)] + +* igm/input.js +Missing ReferenceId: a1 +Unresolved reference IDs mismatch for "a1": +after transform: [ReferenceId(0)] +rebuilt : [ReferenceId(0)] + + diff --git a/tasks/transform_conformance/snapshots/babel.snap.md b/tasks/transform_conformance/snapshots/babel.snap.md index 58d136f047f08..8167a326b453b 100644 --- a/tasks/transform_conformance/snapshots/babel.snap.md +++ b/tasks/transform_conformance/snapshots/babel.snap.md @@ -1,16 +1,15 @@ commit: 3bcfee23 -Passed: 333/1022 +Passed: 312/1038 # All Passed: * babel-plugin-transform-optional-catch-binding -* babel-preset-react * babel-plugin-transform-react-display-name * babel-plugin-transform-react-jsx-self * babel-plugin-transform-react-jsx-source -# babel-preset-env (109/585) +# babel-preset-env (104/585) * .plugins-overlapping/chrome-49/input.js x Output mismatch @@ -230,6 +229,9 @@ x Output mismatch * corejs2-babel-7/usage-regenerator-used-generator/input.mjs x Output mismatch +* corejs2-babel-7/usage-regenerator-used-generator-native-support/input.mjs +x Output mismatch + * corejs2-babel-7/usage-remove-babel-polyfill-import/input.mjs x Output mismatch @@ -254,6 +256,12 @@ x Output mismatch * corejs2-babel-7/usage-typed-array/input.mjs x Output mismatch +* corejs2-babel-7/usage-typed-array-edge-13/input.mjs +Missing ReferenceId: Int8Array +Unresolved reference IDs mismatch for "Int8Array": +after transform: [ReferenceId(0)] +rebuilt : [ReferenceId(0)] + * corejs2-babel-7/usage-typed-array-static/input.mjs x Output mismatch @@ -437,6 +445,9 @@ x Output mismatch * corejs3/usage-regenerator-used-async-native-support/input.mjs x Output mismatch +* corejs3/usage-regenerator-used-generator-native-support/input.mjs +x Output mismatch + * corejs3/usage-shippedProposals/input.mjs x Output mismatch @@ -695,6 +706,9 @@ x Output mismatch * corejs3-babel-7/usage-regenerator-used-generator/input.mjs x Output mismatch +* corejs3-babel-7/usage-regenerator-used-generator-native-support/input.mjs +x Output mismatch + * corejs3-babel-7/usage-shippedProposals/input.mjs x Output mismatch @@ -1307,6 +1321,16 @@ x Output mismatch * preset-options/include-scoped/input.mjs x Output mismatch +* preset-options/ios-10/input.mjs +Missing SymbolId: a +Missing ScopeId +Binding symbols mismatch: +after transform: ScopeId(0): [SymbolId(0)] +rebuilt : ScopeId(0): [SymbolId(0)] +Scope children mismatch: +after transform: ScopeId(0): [ScopeId(1)] +rebuilt : ScopeId(0): [ScopeId(1)] + * preset-options/ios-6/input.mjs x Output mismatch @@ -1440,7 +1464,35 @@ x Output mismatch x Output mismatch -# babel-plugin-transform-logical-assignment-operators (3/6) +# babel-plugin-transform-logical-assignment-operators (0/6) +* logical-assignment/anonymous-functions-transform/input.js +Symbol reference IDs mismatch: +after transform: SymbolId(0): [ReferenceId(0), ReferenceId(1), ReferenceId(2), ReferenceId(3), ReferenceId(4), ReferenceId(5), ReferenceId(6), ReferenceId(7), ReferenceId(8)] +rebuilt : SymbolId(0): [ReferenceId(0), ReferenceId(1), ReferenceId(2), ReferenceId(3), ReferenceId(4), ReferenceId(5)] +Reference flags mismatch: +after transform: ReferenceId(4): ReferenceFlags(Write) +rebuilt : ReferenceId(1): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(6): ReferenceFlags(Write) +rebuilt : ReferenceId(3): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(8): ReferenceFlags(Write) +rebuilt : ReferenceId(5): ReferenceFlags(Read | Write) + +* logical-assignment/arrow-functions-transform/input.js +Symbol reference IDs mismatch: +after transform: SymbolId(0): [ReferenceId(0), ReferenceId(1), ReferenceId(2), ReferenceId(3), ReferenceId(4), ReferenceId(5), ReferenceId(6), ReferenceId(7), ReferenceId(8)] +rebuilt : SymbolId(0): [ReferenceId(0), ReferenceId(1), ReferenceId(2), ReferenceId(3), ReferenceId(4), ReferenceId(5)] +Reference flags mismatch: +after transform: ReferenceId(4): ReferenceFlags(Write) +rebuilt : ReferenceId(1): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(6): ReferenceFlags(Write) +rebuilt : ReferenceId(3): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(8): ReferenceFlags(Write) +rebuilt : ReferenceId(5): ReferenceFlags(Read | Write) + * logical-assignment/general-semantics/input.js Symbol reference IDs mismatch: after transform: SymbolId(15): [ReferenceId(117), ReferenceId(118), ReferenceId(121)] @@ -1454,6 +1506,104 @@ rebuilt : SymbolId(12): [ReferenceId(111), ReferenceId(115)] Symbol reference IDs mismatch: after transform: SymbolId(21): [ReferenceId(132), ReferenceId(133), ReferenceId(136)] rebuilt : SymbolId(14): [ReferenceId(123), ReferenceId(127)] +Reference flags mismatch: +after transform: ReferenceId(98): ReferenceFlags(Write) +rebuilt : ReferenceId(27): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(97): ReferenceFlags(Write) +rebuilt : ReferenceId(29): ReferenceFlags(Read) +Reference flags mismatch: +after transform: ReferenceId(100): ReferenceFlags(Write) +rebuilt : ReferenceId(33): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(99): ReferenceFlags(Write) +rebuilt : ReferenceId(35): ReferenceFlags(Read) +Reference flags mismatch: +after transform: ReferenceId(102): ReferenceFlags(Write) +rebuilt : ReferenceId(39): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(101): ReferenceFlags(Write) +rebuilt : ReferenceId(41): ReferenceFlags(Read) +Reference flags mismatch: +after transform: ReferenceId(104): ReferenceFlags(Write) +rebuilt : ReferenceId(45): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(103): ReferenceFlags(Write) +rebuilt : ReferenceId(47): ReferenceFlags(Read) +Reference flags mismatch: +after transform: ReferenceId(107): ReferenceFlags(Write) +rebuilt : ReferenceId(52): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(105): ReferenceFlags(Write) +rebuilt : ReferenceId(55): ReferenceFlags(Read) +Reference flags mismatch: +after transform: ReferenceId(110): ReferenceFlags(Write) +rebuilt : ReferenceId(61): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(108): ReferenceFlags(Write) +rebuilt : ReferenceId(64): ReferenceFlags(Read) +Reference flags mismatch: +after transform: ReferenceId(113): ReferenceFlags(Write) +rebuilt : ReferenceId(70): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(111): ReferenceFlags(Write) +rebuilt : ReferenceId(73): ReferenceFlags(Read) +Reference flags mismatch: +after transform: ReferenceId(116): ReferenceFlags(Write) +rebuilt : ReferenceId(79): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(114): ReferenceFlags(Write) +rebuilt : ReferenceId(82): ReferenceFlags(Read) +Reference flags mismatch: +after transform: ReferenceId(118): ReferenceFlags(Write) +rebuilt : ReferenceId(87): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(120): ReferenceFlags(Write) +rebuilt : ReferenceId(89): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(119): ReferenceFlags(Write) +rebuilt : ReferenceId(92): ReferenceFlags(Read) +Reference flags mismatch: +after transform: ReferenceId(123): ReferenceFlags(Write) +rebuilt : ReferenceId(99): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(125): ReferenceFlags(Write) +rebuilt : ReferenceId(101): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(124): ReferenceFlags(Write) +rebuilt : ReferenceId(104): ReferenceFlags(Read) +Reference flags mismatch: +after transform: ReferenceId(128): ReferenceFlags(Write) +rebuilt : ReferenceId(111): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(130): ReferenceFlags(Write) +rebuilt : ReferenceId(113): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(129): ReferenceFlags(Write) +rebuilt : ReferenceId(116): ReferenceFlags(Read) +Reference flags mismatch: +after transform: ReferenceId(133): ReferenceFlags(Write) +rebuilt : ReferenceId(123): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(135): ReferenceFlags(Write) +rebuilt : ReferenceId(125): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(134): ReferenceFlags(Write) +rebuilt : ReferenceId(128): ReferenceFlags(Read) + +* logical-assignment/named-functions-transform/input.js +Symbol reference IDs mismatch: +after transform: SymbolId(0): [ReferenceId(0), ReferenceId(1), ReferenceId(2), ReferenceId(3), ReferenceId(4), ReferenceId(5), ReferenceId(6), ReferenceId(7), ReferenceId(8)] +rebuilt : SymbolId(0): [ReferenceId(0), ReferenceId(1), ReferenceId(2), ReferenceId(3), ReferenceId(4), ReferenceId(5)] +Reference flags mismatch: +after transform: ReferenceId(4): ReferenceFlags(Write) +rebuilt : ReferenceId(1): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(6): ReferenceFlags(Write) +rebuilt : ReferenceId(3): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(8): ReferenceFlags(Write) +rebuilt : ReferenceId(5): ReferenceFlags(Read | Write) * logical-assignment/null-coalescing/input.js Symbol reference IDs mismatch: @@ -1465,8 +1615,29 @@ rebuilt : SymbolId(13): [ReferenceId(88), ReferenceId(94)] * logical-assignment/null-coalescing-without-other/input.js Symbol reference IDs mismatch: -after transform: SymbolId(2): [ReferenceId(6), ReferenceId(7), ReferenceId(10)] +after transform: SymbolId(2): [ReferenceId(7), ReferenceId(8), ReferenceId(11)] rebuilt : SymbolId(1): [ReferenceId(5), ReferenceId(8)] +Symbol reference IDs mismatch: +after transform: SymbolId(0): [ReferenceId(0), ReferenceId(1), ReferenceId(2), ReferenceId(3), ReferenceId(4)] +rebuilt : SymbolId(3): [ReferenceId(0), ReferenceId(1), ReferenceId(3), ReferenceId(6)] +Reference flags mismatch: +after transform: ReferenceId(4): ReferenceFlags(Write) +rebuilt : ReferenceId(1): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(6): ReferenceFlags(Write) +rebuilt : ReferenceId(2): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(5): ReferenceFlags(Write) +rebuilt : ReferenceId(4): ReferenceFlags(Read) +Reference flags mismatch: +after transform: ReferenceId(8): ReferenceFlags(Write) +rebuilt : ReferenceId(5): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(10): ReferenceFlags(Write) +rebuilt : ReferenceId(7): ReferenceFlags(Read | Write) +Reference flags mismatch: +after transform: ReferenceId(9): ReferenceFlags(Write) +rebuilt : ReferenceId(9): ReferenceFlags(Read) # babel-plugin-transform-nullish-coalescing-operator (5/12) @@ -1656,6 +1827,56 @@ x Output mismatch x Output mismatch +# babel-plugin-transform-async-to-generator (1/17) +* assumption-ignoreFunctionLength-true/basic/input.mjs +x Output mismatch + +* assumption-ignoreFunctionLength-true/export-default-function/input.mjs +x Output mismatch + +* assumption-noNewArrows-false/basic/input.js +x Output mismatch + +* bluebird-coroutines/arrow-function/input.js +x Output mismatch + +* bluebird-coroutines/class/input.js +x Output mismatch + +* bluebird-coroutines/expression/input.js +x Output mismatch + +* bluebird-coroutines/named-expression/input.js +x Output mismatch + +* bluebird-coroutines/statement/input.js +x Output mismatch + +* regression/15978/input.js +x Output mismatch + +* regression/4599/input.js +x Output mismatch + +* regression/8783/input.js +x Output mismatch + +* regression/T7108/input.js +x Output mismatch + +* regression/T7194/input.js +x Output mismatch + +* regression/gh-6923/input.js +x Output mismatch + +* regression/in-uncompiled-class-fields/input.js +x Output mismatch + +* regression/regression-2765/input.js +x Output mismatch + + # babel-plugin-transform-exponentiation-operator (1/4) * exponentiation-operator/assignment/input.js Symbol reference IDs mismatch: @@ -1811,16 +2032,16 @@ Bindings mismatch: after transform: ScopeId(1): ["A", "E"] rebuilt : ScopeId(1): ["E"] Scope flags mismatch: -after transform: ScopeId(1): ScopeFlags(0x0) -rebuilt : ScopeId(1): ScopeFlags(Function) +after transform: ScopeId(1): ScopeFlags(StrictMode) +rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) Symbol flags mismatch: after transform: SymbolId(0): SymbolFlags(RegularEnum) rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable) * enum/const/input.ts Scope flags mismatch: -after transform: ScopeId(1): ScopeFlags(0x0) -rebuilt : ScopeId(1): ScopeFlags(Function) +after transform: ScopeId(1): ScopeFlags(StrictMode) +rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) Symbol flags mismatch: after transform: SymbolId(0): SymbolFlags(ConstEnum) rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable) @@ -1830,8 +2051,8 @@ Bindings mismatch: after transform: ScopeId(1): ["E", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r"] rebuilt : ScopeId(1): ["E"] Scope flags mismatch: -after transform: ScopeId(1): ScopeFlags(0x0) -rebuilt : ScopeId(1): ScopeFlags(Function) +after transform: ScopeId(1): ScopeFlags(StrictMode) +rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) Symbol flags mismatch: after transform: SymbolId(0): SymbolFlags(RegularEnum) rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable) @@ -1841,14 +2062,14 @@ Bindings mismatch: after transform: ScopeId(1): ["Animals", "Cat", "Dog"] rebuilt : ScopeId(1): ["Animals"] Scope flags mismatch: -after transform: ScopeId(1): ScopeFlags(0x0) -rebuilt : ScopeId(1): ScopeFlags(Function) +after transform: ScopeId(1): ScopeFlags(StrictMode) +rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) Bindings mismatch: after transform: ScopeId(2): ["Animals", "CatDog"] rebuilt : ScopeId(2): ["Animals"] Scope flags mismatch: -after transform: ScopeId(2): ScopeFlags(0x0) -rebuilt : ScopeId(2): ScopeFlags(Function) +after transform: ScopeId(2): ScopeFlags(StrictMode) +rebuilt : ScopeId(2): ScopeFlags(StrictMode | Function) Symbol flags mismatch: after transform: SymbolId(0): SymbolFlags(RegularEnum) rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable) @@ -1864,20 +2085,20 @@ Bindings mismatch: after transform: ScopeId(1): ["Animals", "Cat"] rebuilt : ScopeId(1): ["Animals"] Scope flags mismatch: -after transform: ScopeId(1): ScopeFlags(0x0) -rebuilt : ScopeId(1): ScopeFlags(Function) +after transform: ScopeId(1): ScopeFlags(StrictMode) +rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) Bindings mismatch: after transform: ScopeId(2): ["Animals", "Dog"] rebuilt : ScopeId(2): ["Animals"] Scope flags mismatch: -after transform: ScopeId(2): ScopeFlags(0x0) -rebuilt : ScopeId(2): ScopeFlags(Function) +after transform: ScopeId(2): ScopeFlags(StrictMode) +rebuilt : ScopeId(2): ScopeFlags(StrictMode | Function) Bindings mismatch: after transform: ScopeId(3): ["Animals", "CatDog"] rebuilt : ScopeId(3): ["Animals"] Scope flags mismatch: -after transform: ScopeId(3): ScopeFlags(0x0) -rebuilt : ScopeId(3): ScopeFlags(Function) +after transform: ScopeId(3): ScopeFlags(StrictMode) +rebuilt : ScopeId(3): ScopeFlags(StrictMode | Function) Symbol reference IDs mismatch: after transform: SymbolId(0): [ReferenceId(0)] rebuilt : SymbolId(0): [] @@ -1916,8 +2137,8 @@ Bindings mismatch: after transform: ScopeId(1): ["E", "x", "y"] rebuilt : ScopeId(1): ["E"] Scope flags mismatch: -after transform: ScopeId(1): ScopeFlags(0x0) -rebuilt : ScopeId(1): ScopeFlags(Function) +after transform: ScopeId(1): ScopeFlags(StrictMode) +rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) Symbol flags mismatch: after transform: SymbolId(0): SymbolFlags(RegularEnum) rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable) @@ -1927,8 +2148,8 @@ Bindings mismatch: after transform: ScopeId(1): ["E", "a", "b"] rebuilt : ScopeId(1): ["E"] Scope flags mismatch: -after transform: ScopeId(1): ScopeFlags(0x0) -rebuilt : ScopeId(1): ScopeFlags(Function) +after transform: ScopeId(1): ScopeFlags(StrictMode) +rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) Symbol flags mismatch: after transform: SymbolId(0): SymbolFlags(RegularEnum) rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable) @@ -1941,8 +2162,8 @@ Bindings mismatch: after transform: ScopeId(1): ["E", "a", "b"] rebuilt : ScopeId(1): ["E"] Scope flags mismatch: -after transform: ScopeId(1): ScopeFlags(0x0) -rebuilt : ScopeId(1): ScopeFlags(Function) +after transform: ScopeId(1): ScopeFlags(StrictMode) +rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) Symbol flags mismatch: after transform: SymbolId(0): SymbolFlags(RegularEnum) rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable) @@ -1952,14 +2173,14 @@ Bindings mismatch: after transform: ScopeId(1): ["E", "x", "y"] rebuilt : ScopeId(1): ["E"] Scope flags mismatch: -after transform: ScopeId(1): ScopeFlags(0x0) -rebuilt : ScopeId(1): ScopeFlags(Function) +after transform: ScopeId(1): ScopeFlags(StrictMode) +rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) Bindings mismatch: after transform: ScopeId(2): ["E", "z"] rebuilt : ScopeId(2): ["E"] Scope flags mismatch: -after transform: ScopeId(2): ScopeFlags(0x0) -rebuilt : ScopeId(2): ScopeFlags(Function) +after transform: ScopeId(2): ScopeFlags(StrictMode) +rebuilt : ScopeId(2): ScopeFlags(StrictMode | Function) Symbol flags mismatch: after transform: SymbolId(0): SymbolFlags(RegularEnum) rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable) @@ -1972,14 +2193,14 @@ Bindings mismatch: after transform: ScopeId(1): ["IPC", "SERVER", "SOCKET", "socketType"] rebuilt : ScopeId(1): ["socketType"] Scope flags mismatch: -after transform: ScopeId(1): ScopeFlags(0x0) -rebuilt : ScopeId(1): ScopeFlags(Function) +after transform: ScopeId(1): ScopeFlags(StrictMode) +rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) Bindings mismatch: after transform: ScopeId(2): ["IPC", "SERVER", "SOCKET", "UV_READABLE", "UV_WRITABLE", "constants"] rebuilt : ScopeId(2): ["constants"] Scope flags mismatch: -after transform: ScopeId(2): ScopeFlags(0x0) -rebuilt : ScopeId(2): ScopeFlags(Function) +after transform: ScopeId(2): ScopeFlags(StrictMode) +rebuilt : ScopeId(2): ScopeFlags(StrictMode | Function) Symbol flags mismatch: after transform: SymbolId(0): SymbolFlags(RegularEnum) rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable) @@ -1995,8 +2216,8 @@ x Output mismatch * enum/scoped/input.ts Scope flags mismatch: -after transform: ScopeId(2): ScopeFlags(0x0) -rebuilt : ScopeId(2): ScopeFlags(Function) +after transform: ScopeId(2): ScopeFlags(StrictMode) +rebuilt : ScopeId(2): ScopeFlags(StrictMode | Function) Symbol flags mismatch: after transform: SymbolId(0): SymbolFlags(RegularEnum) rebuilt : SymbolId(0): SymbolFlags(BlockScopedVariable) @@ -2006,8 +2227,8 @@ Bindings mismatch: after transform: ScopeId(1): ["A", "A2", "B", "B2", "E"] rebuilt : ScopeId(1): ["E"] Scope flags mismatch: -after transform: ScopeId(1): ScopeFlags(0x0) -rebuilt : ScopeId(1): ScopeFlags(Function) +after transform: ScopeId(1): ScopeFlags(StrictMode) +rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) Symbol flags mismatch: after transform: SymbolId(0): SymbolFlags(RegularEnum) rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable) @@ -2017,8 +2238,8 @@ Bindings mismatch: after transform: ScopeId(1): ["A", "E"] rebuilt : ScopeId(1): ["E"] Scope flags mismatch: -after transform: ScopeId(1): ScopeFlags(0x0) -rebuilt : ScopeId(1): ScopeFlags(Function) +after transform: ScopeId(1): ScopeFlags(StrictMode) +rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) Symbol flags mismatch: after transform: SymbolId(0): SymbolFlags(RegularEnum) rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable) @@ -2028,8 +2249,8 @@ Bindings mismatch: after transform: ScopeId(1): ["A", "E"] rebuilt : ScopeId(1): ["E"] Scope flags mismatch: -after transform: ScopeId(1): ScopeFlags(0x0) -rebuilt : ScopeId(1): ScopeFlags(Function) +after transform: ScopeId(1): ScopeFlags(StrictMode) +rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) Symbol flags mismatch: after transform: SymbolId(0): SymbolFlags(RegularEnum) rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable) @@ -3324,19 +3545,39 @@ after transform: ["T", "f"] rebuilt : ["f"] -# babel-plugin-transform-react-jsx (124/144) +# babel-preset-react (6/9) +* preset-options/development-runtime-automatic/input.js +x Output mismatch + +* preset-options/empty-options/input.js +x Output mismatch + +* preset-options/runtime-automatic/input.js +x Output mismatch + + +# babel-plugin-transform-react-jsx (119/144) +* pure/false-default-pragma-automatic-runtime/input.js +x Output mismatch + * pure/false-pragma-comment-automatic-runtime/input.js pragma and pragmaFrag cannot be set when runtime is automatic. * pure/false-pragma-option-automatic-runtime/input.js pragma and pragmaFrag cannot be set when runtime is automatic. +* pure/true-default-pragma-automatic-runtime/input.js +x Output mismatch + * pure/true-pragma-comment-automatic-runtime/input.js pragma and pragmaFrag cannot be set when runtime is automatic. * pure/true-pragma-option-automatic-runtime/input.js pragma and pragmaFrag cannot be set when runtime is automatic. +* pure/unset-default-pragma-automatic-runtime/input.js +x Output mismatch + * pure/unset-pragma-comment-automatic-runtime/input.js pragma and pragmaFrag cannot be set when runtime is automatic. @@ -3421,6 +3662,12 @@ Spread children are not supported in React. * react-automatic/should-warn-when-pragma-or-pragmaFrag-is-set/input.js pragma and pragmaFrag cannot be set when runtime is automatic. +* runtime/defaults-to-automatic/input.js +x Output mismatch + +* runtime/runtime-automatic/input.js +x Output mismatch + * spread-transform/transform-to-babel-extend/input.js x Output mismatch @@ -3428,7 +3675,7 @@ x Output mismatch x Output mismatch -# babel-plugin-transform-react-jsx-development (8/11) +# babel-plugin-transform-react-jsx-development (2/10) * cross-platform/disallow-__self-as-jsx-attribute/input.js ! Duplicate __self prop found. ,-[tasks/coverage/babel/packages/babel-plugin-transform-react-jsx-development/test/fixtures/cross-platform/disallow-__self-as-jsx-attribute/input.js:1:14] @@ -3445,7 +3692,22 @@ x Output mismatch `---- -* cross-platform/within-ts-module-block/input.ts +* cross-platform/fragments/input.js +x Output mismatch + +* cross-platform/handle-fragments-with-key/input.js +x Output mismatch + +* cross-platform/handle-nonstatic-children/input.js +x Output mismatch + +* cross-platform/handle-static-children/input.js +x Output mismatch + +* cross-platform/within-derived-classes-constructor/input.js +x Output mismatch + +* cross-platform/within-ts-module-block/input.tsx x Output mismatch diff --git a/tasks/transform_conformance/snapshots/babel_exec.snap.md b/tasks/transform_conformance/snapshots/babel_exec.snap.md index 0eaa0432a6553..589af4ed43752 100644 --- a/tasks/transform_conformance/snapshots/babel_exec.snap.md +++ b/tasks/transform_conformance/snapshots/babel_exec.snap.md @@ -1,6 +1,6 @@ commit: 3bcfee23 -Passed: 33/54 +Passed: 33/60 # All Passed: * babel-plugin-transform-logical-assignment-operators @@ -10,13 +10,16 @@ Passed: 33/54 * babel-plugin-transform-arrow-functions -# babel-preset-env (8/11) +# babel-preset-env (7/11) * plugins-integration/class-arrow-super-tagged-expr/exec.js exec failed * plugins-integration/issue-15170/exec.js exec failed +* plugins-integration/regression-7064/exec.js +exec failed + * sanity/check-es2015-constants/exec.js exec failed @@ -71,6 +74,23 @@ exec failed exec failed +# babel-plugin-transform-async-to-generator (1/6) +* regression/15978/exec.js +exec failed + +* regression/8783/exec.js +exec failed + +* regression/T6882/exec.js +exec failed + +* regression/fn-name/exec.js +exec failed + +* regression/test262-fn-length/exec.js +exec failed + + # babel-plugin-transform-react-jsx-source (0/2) * react-source/basic-sample/exec.js exec failed From 2629c3a0ffabea2c2d048ce1daf7f0cee3367538 Mon Sep 17 00:00:00 2001 From: Ethan Goh <7086cmd@gmail.com> Date: Sun, 8 Sep 2024 07:07:39 +0800 Subject: [PATCH 04/25] chore: lint. --- crates/oxc_transformer/src/es2017/async_to_generator.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/oxc_transformer/src/es2017/async_to_generator.rs b/crates/oxc_transformer/src/es2017/async_to_generator.rs index 031ef210d6d67..9f16941bcaa95 100644 --- a/crates/oxc_transformer/src/es2017/async_to_generator.rs +++ b/crates/oxc_transformer/src/es2017/async_to_generator.rs @@ -6,7 +6,7 @@ use crate::es2017::utils::{ use oxc_allocator::{Box, CloneIn}; use oxc_ast::ast::{ ArrowFunctionExpression, AwaitExpression, BindingRestElement, Expression, FormalParameterKind, - Function, FunctionType, Program, Statement, TSThisParameter, TSTypeAnnotation, + Function, FunctionType, Program, TSThisParameter, TSTypeAnnotation, TSTypeParameterDeclaration, TSTypeParameterInstantiation, VariableDeclarationKind, }; use oxc_span::SPAN; @@ -199,7 +199,7 @@ impl<'a> Traverse<'a> for AsyncToGenerator<'a> { } } - fn exit_function(&mut self, decl: &mut Function<'a>, ctx: &mut TraverseCtx<'a>) { + fn exit_function(&mut self, decl: &mut Function<'a>, _ctx: &mut TraverseCtx<'a>) { let fn_name = decl .id .clone_in(self.ctx.ast.allocator) From 524b20ac2e3ecb2e0adafca6f9c7a3b4c6d19a74 Mon Sep 17 00:00:00 2001 From: Ethan Goh <7086cmd@gmail.com> Date: Sun, 8 Sep 2024 07:07:53 +0800 Subject: [PATCH 05/25] chore: lint. --- crates/oxc_transformer/src/es2017/async_to_generator.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/oxc_transformer/src/es2017/async_to_generator.rs b/crates/oxc_transformer/src/es2017/async_to_generator.rs index 9f16941bcaa95..c5818c2a6a729 100644 --- a/crates/oxc_transformer/src/es2017/async_to_generator.rs +++ b/crates/oxc_transformer/src/es2017/async_to_generator.rs @@ -6,8 +6,8 @@ use crate::es2017::utils::{ use oxc_allocator::{Box, CloneIn}; use oxc_ast::ast::{ ArrowFunctionExpression, AwaitExpression, BindingRestElement, Expression, FormalParameterKind, - Function, FunctionType, Program, TSThisParameter, TSTypeAnnotation, - TSTypeParameterDeclaration, TSTypeParameterInstantiation, VariableDeclarationKind, + Function, FunctionType, Program, TSThisParameter, TSTypeAnnotation, TSTypeParameterDeclaration, + TSTypeParameterInstantiation, VariableDeclarationKind, }; use oxc_span::SPAN; use oxc_syntax::operator::AssignmentOperator; From 9188d296c23676ced0eb41e9be9ff5bffaa7de28 Mon Sep 17 00:00:00 2001 From: Ethan Goh <7086cmd@gmail.com> Date: Sun, 22 Sep 2024 12:32:44 +0800 Subject: [PATCH 06/25] refactor: align esbuild does. --- .../src/es2017/async_to_generator.rs | 401 ++++-------- crates/oxc_transformer/src/es2017/mod.rs | 29 +- .../oxc_transformer/src/es2017/utils/mod.rs | 608 ------------------ 3 files changed, 125 insertions(+), 913 deletions(-) delete mode 100644 crates/oxc_transformer/src/es2017/utils/mod.rs diff --git a/crates/oxc_transformer/src/es2017/async_to_generator.rs b/crates/oxc_transformer/src/es2017/async_to_generator.rs index c5818c2a6a729..a4ff6955db531 100644 --- a/crates/oxc_transformer/src/es2017/async_to_generator.rs +++ b/crates/oxc_transformer/src/es2017/async_to_generator.rs @@ -1,308 +1,151 @@ +//! ES2017: Async / Await +//! +//! This plugin transforms async functions to generator functions. +//! +//! ## Example +//! +//! Input: +//! ```js +//! async function foo() { +//! await bar(); +//! } +//! const foo2 = async () => { +//! await bar(); +//! }; +//! ``` +//! +//! Output: +//! ```js +//! function foo() { +//! return _asyncToGenerator(this, null, function* () { +//! yield bar(); +//! }) +//! } +//! const foo2 = () => _asyncToGenerator(this, null, function* () { +//! yield bar(); +//! } +//! ``` +//! +//! ## Implementation +//! +//! Implementation based on [@babel/plugin-transform-async-to-generator](https://babel.dev/docs/babel-plugin-transform-async-to-generator) and [esbuild](https://github.com/evanw/esbuild/blob/main/internal/js_parser/js_parser_lower.go#L392). +//! +//! +//! Reference: +//! * Babel docs: +//! * Esbuild implementation: +//! * Babel implementation: +//! * Babel helper implementation: +//! * Async / Await TC39 proposal: +//! + use crate::context::Ctx; -use crate::es2017::utils::{ - async_generator_step, async_to_generator, function_apply, generate_caller_from_arrow, - generate_caller_from_function, -}; -use oxc_allocator::{Box, CloneIn}; +use oxc_allocator::CloneIn; use oxc_ast::ast::{ - ArrowFunctionExpression, AwaitExpression, BindingRestElement, Expression, FormalParameterKind, - Function, FunctionType, Program, TSThisParameter, TSTypeAnnotation, TSTypeParameterDeclaration, - TSTypeParameterInstantiation, VariableDeclarationKind, + ArrowFunctionExpression, Expression, FormalParameterKind, Function, Statement, YieldExpression, }; -use oxc_span::SPAN; -use oxc_syntax::operator::AssignmentOperator; +use oxc_ast::NONE; +use oxc_span::{Atom, SPAN}; +use oxc_syntax::reference::ReferenceFlags; +use oxc_syntax::symbol::SymbolId; use oxc_traverse::{Ancestor, Traverse, TraverseCtx}; -/// ES2017: Async / Await -/// -/// This plugin transforms async functions to generator functions. -/// -/// Reference: -/// * -/// * -/// * pub struct AsyncToGenerator<'a> { - ctx: Ctx<'a>, - - inject_helpers: bool, + _ctx: Ctx<'a>, } impl<'a> AsyncToGenerator<'a> { pub fn new(ctx: Ctx<'a>) -> Self { - Self { ctx, inject_helpers: false } + Self { _ctx: ctx } } -} -impl<'a> AsyncToGenerator<'a> { - pub fn transform_await_to_yield(&mut self, decl: &Box) -> Expression<'a> { - self.ctx.ast.expression_yield( + fn get_helper_callee(symbol_id: Option, ctx: &mut TraverseCtx<'a>) -> Expression<'a> { + let ident = ctx.create_reference_id( SPAN, - false, - Some(decl.argument.clone_in(self.ctx.ast.allocator)), - ) + Atom::from("babelHelpers"), + symbol_id, + ReferenceFlags::Read, + ); + let object = ctx.ast.expression_from_identifier_reference(ident); + let property = ctx.ast.identifier_name(SPAN, Atom::from("asyncToGenerator")); + Expression::from(ctx.ast.member_expression_static(SPAN, object, property, false)) } } impl<'a> Traverse<'a> for AsyncToGenerator<'a> { - fn exit_program(&mut self, program: &mut Program<'a>, _ctx: &mut TraverseCtx<'a>) { - let mut stmts = self.ctx.ast.vec(); - - if self.inject_helpers { - stmts.push(async_generator_step(&self.ctx.ast).clone_in(self.ctx.ast.allocator)); - stmts.push(async_to_generator(&self.ctx.ast).clone_in(self.ctx.ast.allocator)); - } - stmts.extend(program.body.clone_in(self.ctx.ast.allocator)); - program.body = stmts; - } - fn exit_expression(&mut self, expr: &mut Expression<'a>, ctx: &mut TraverseCtx<'a>) { - match expr { - Expression::AwaitExpression(decl) => { - // Do not transform await in top-level - let in_function = ctx.ancestry.ancestors().any(|ancestor| { - matches!( - ancestor, - Ancestor::FunctionBody(_) | Ancestor::ArrowFunctionExpressionBody(_) - ) - }); - if in_function { - *expr = self.transform_await_to_yield(decl).clone_in(self.ctx.ast.allocator); - } + if let Expression::AwaitExpression(await_expr) = expr { + // Do not transform top-level await + if ctx.ancestry.ancestors().any(|ancestor| { + matches!( + ancestor, + Ancestor::FunctionBody(_) | Ancestor::ArrowFunctionExpressionBody(_) + ) + }) { + let yield_expression = YieldExpression { + span: SPAN, + delegate: false, + argument: Some(await_expr.argument.clone_in(ctx.ast.allocator)), + }; + let expression = ctx.ast.alloc(yield_expression); + *expr = Expression::YieldExpression(expression); } - Expression::ArrowFunctionExpression(func) if func.r#async => { - let func = func.clone_in(self.ctx.ast.allocator); - if func.params.items.is_empty() { - *expr = generate_caller_from_arrow(&func, &self.ctx.ast) - .clone_in(self.ctx.ast.allocator); - } else { - let mut statements = self.ctx.ast.vec(); - statements.push( - self.ctx.ast.statement_declaration( - self.ctx.ast.declaration_variable( - SPAN, - VariableDeclarationKind::Var, - self.ctx.ast.vec1( - self.ctx.ast.variable_declarator( - SPAN, - VariableDeclarationKind::Var, - self.ctx.ast.binding_pattern( - self.ctx.ast.binding_pattern_kind_binding_identifier( - SPAN, "_ref", - ), - None::, - false, - ), - Some( - generate_caller_from_arrow(&func, &self.ctx.ast) - .clone_in(self.ctx.ast.allocator), - ), - false, - ), - ), - false, - ), - ), - ); - statements.push( - function_apply("_ref", &self.ctx.ast).clone_in(self.ctx.ast.allocator), - ); - *expr = self.ctx.ast.expression_parenthesized( - SPAN, - self.ctx.ast.expression_function( - FunctionType::FunctionExpression, - SPAN, - None, - false, - false, - false, - None::, - None::, - self.ctx.ast.formal_parameters( - SPAN, - FormalParameterKind::FormalParameter, - self.ctx.ast.vec(), - None::, - ), - None::, - Some(self.ctx.ast.function_body(SPAN, self.ctx.ast.vec(), statements)), - ), - ); - } - } - Expression::FunctionExpression(func) if func.r#async => { - let func = func.clone_in(self.ctx.ast.allocator); - if func.params.items.is_empty() { - *expr = generate_caller_from_function(&func, &self.ctx.ast) - .clone_in(self.ctx.ast.allocator); - } else { - let mut statements = self.ctx.ast.vec(); - statements.push( - self.ctx.ast.statement_declaration( - self.ctx.ast.declaration_variable( - SPAN, - VariableDeclarationKind::Var, - self.ctx.ast.vec1( - self.ctx.ast.variable_declarator( - SPAN, - VariableDeclarationKind::Var, - self.ctx.ast.binding_pattern( - self.ctx.ast.binding_pattern_kind_binding_identifier( - SPAN, "_ref", - ), - None::, - false, - ), - Some( - generate_caller_from_function(&func, &self.ctx.ast) - .clone_in(self.ctx.ast.allocator), - ), - false, - ), - ), - false, - ), - ), - ); - statements.push( - function_apply("_ref", &self.ctx.ast).clone_in(self.ctx.ast.allocator), - ); - *expr = self.ctx.ast.expression_parenthesized( - SPAN, - self.ctx.ast.expression_function( - FunctionType::FunctionExpression, - SPAN, - None, - false, - false, - false, - None::, - None::, - self.ctx.ast.formal_parameters( - SPAN, - FormalParameterKind::FormalParameter, - self.ctx.ast.vec(), - None::, - ), - None::, - Some(self.ctx.ast.function_body(SPAN, self.ctx.ast.vec(), statements)), - ), - ); - } - } - _ => {} - } - } - - fn enter_function(&mut self, function: &mut Function<'a>, _ctx: &mut TraverseCtx<'a>) { - if function.r#async && !function.generator { - self.inject_helpers = true; } } - fn exit_function(&mut self, decl: &mut Function<'a>, _ctx: &mut TraverseCtx<'a>) { - let fn_name = decl - .id - .clone_in(self.ctx.ast.allocator) - .map_or("ref".to_owned(), |id| id.name.to_string()); - let alias_name = "_".to_owned() + fn_name.as_str(); - let inner_function = self.ctx.ast.function( - decl.r#type.clone_in(self.ctx.ast.allocator), + fn exit_function(&mut self, func: &mut Function<'a>, ctx: &mut TraverseCtx<'a>) { + let babel_helpers_id = ctx.scopes().find_binding(ctx.current_scope_id(), "babelHelpers"); + let callee = Self::get_helper_callee(babel_helpers_id, ctx); + let mut target = func.clone_in(ctx.ast.allocator); + target.r#async = false; + target.generator = true; + target.params = ctx.ast.alloc(ctx.ast.formal_parameters( SPAN, - Some(self.ctx.ast.binding_identifier(SPAN, alias_name.as_str())), - false, - false, - false, - decl.type_parameters.clone_in(self.ctx.ast.allocator), - decl.this_param.clone_in(self.ctx.ast.allocator), - decl.params.clone_in(self.ctx.ast.allocator), - decl.return_type.clone_in(self.ctx.ast.allocator), - Some(self.ctx.ast.function_body(SPAN, self.ctx.ast.vec(), { - let mut result = self.ctx.ast.vec(); - result.push(self.ctx.ast.statement_expression( - SPAN, - self.ctx.ast.expression_assignment( - SPAN, - AssignmentOperator::Assign, - self.ctx.ast.assignment_target_simple( - self.ctx.ast.simple_assignment_target_identifier_reference( - SPAN, - alias_name.as_str(), - ), - ), - self.ctx.ast.expression_call( - SPAN, - self.ctx.ast.expression_identifier_reference(SPAN, "_asyncToGenerator"), - None::, - self.ctx.ast.vec1(self.ctx.ast.argument_expression( - self.ctx.ast.expression_from_function( - decl.clone_in(self.ctx.ast.allocator), - ), - )), - false, - ), - ), - )); - result.push( - function_apply(fn_name.as_str(), &self.ctx.ast) - .clone_in(self.ctx.ast.allocator), - ); - result - })), - ); - *decl = self.ctx.ast.function( - decl.r#type.clone_in(self.ctx.ast.allocator), - SPAN, - Some(self.ctx.ast.binding_identifier(SPAN, "b")), - false, - false, - false, - decl.type_parameters.clone_in(self.ctx.ast.allocator), - decl.this_param.clone_in(self.ctx.ast.allocator), - decl.params.clone_in(self.ctx.ast.allocator), - decl.return_type.clone_in(self.ctx.ast.allocator), - Some(self.ctx.ast.function_body( - SPAN, - self.ctx.ast.vec(), - self.ctx.ast.vec1(self.ctx.ast.statement_return( - SPAN, - Some(self.ctx.ast.expression_call( - SPAN, - self.ctx.ast.expression_member(self.ctx.ast.member_expression_static( - SPAN, - self.ctx.ast.expression_parenthesized( - SPAN, - self.ctx.ast.expression_from_function(inner_function), - ), - self.ctx.ast.identifier_name(SPAN, "apply"), - false, - )), - None::, - { - let mut items = self.ctx.ast.vec(); - items.push( - self.ctx - .ast - .argument_expression(self.ctx.ast.expression_this(SPAN)), - ); - items.push(self.ctx.ast.argument_expression( - self.ctx.ast.expression_identifier_reference(SPAN, "arguments"), - )); - items - }, - false, - )), - )), - )), - ); + FormalParameterKind::FormalParameter, + ctx.ast.vec(), + NONE, + )); + let parameters = { + let mut items = ctx.ast.vec(); + items.push(ctx.ast.argument_expression(ctx.ast.expression_this(SPAN))); + items.push(ctx.ast.argument_expression(ctx.ast.expression_null_literal(SPAN))); + items.push(ctx.ast.argument_expression(ctx.ast.expression_from_function(target))); + items + }; + let call = ctx.ast.expression_call(SPAN, callee, NONE, parameters, false); + let returns = ctx.ast.return_statement(SPAN, Some(call)); + let body = Statement::ReturnStatement(ctx.ast.alloc(returns)); + let body = ctx.ast.function_body(SPAN, ctx.ast.vec(), ctx.ast.vec1(body)); + let body = ctx.ast.alloc(body); + func.body = Some(body); } - fn enter_arrow_function_expression( + fn exit_arrow_function_expression( &mut self, - function: &mut ArrowFunctionExpression<'a>, - _ctx: &mut TraverseCtx<'a>, + arrow: &mut ArrowFunctionExpression<'a>, + ctx: &mut TraverseCtx<'a>, ) { - if function.r#async { - self.inject_helpers = true; - } + let babel_helpers_id = ctx.scopes().find_binding(ctx.current_scope_id(), "babelHelpers"); + let callee = Self::get_helper_callee(babel_helpers_id, ctx); + let mut target = arrow.clone_in(ctx.ast.allocator); + target.r#async = false; + target.params = ctx.ast.alloc(ctx.ast.formal_parameters( + SPAN, + FormalParameterKind::FormalParameter, + ctx.ast.vec(), + NONE, + )); + let parameters = { + let mut items = ctx.ast.vec(); + items.push(ctx.ast.argument_expression(ctx.ast.expression_this(SPAN))); + items.push(ctx.ast.argument_expression(ctx.ast.expression_null_literal(SPAN))); + items.push(ctx.ast.argument_expression(ctx.ast.expression_from_arrow_function(target))); + items + }; + let call = ctx.ast.expression_call(SPAN, callee, NONE, parameters, false); + let returns = ctx.ast.return_statement(SPAN, Some(call)); + let body = Statement::ReturnStatement(ctx.ast.alloc(returns)); + let body = ctx.ast.function_body(SPAN, ctx.ast.vec(), ctx.ast.vec1(body)); + arrow.body = ctx.ast.alloc(body); } } diff --git a/crates/oxc_transformer/src/es2017/mod.rs b/crates/oxc_transformer/src/es2017/mod.rs index 8ed221ada31b4..7e2adc30b89f1 100644 --- a/crates/oxc_transformer/src/es2017/mod.rs +++ b/crates/oxc_transformer/src/es2017/mod.rs @@ -1,11 +1,10 @@ mod async_to_generator; pub mod options; -pub mod utils; use crate::context::Ctx; use crate::es2017::async_to_generator::AsyncToGenerator; use crate::es2017::options::ES2017Options; -use oxc_ast::ast::{ArrowFunctionExpression, CallExpression, Expression, Function, Program}; +use oxc_ast::ast::{ArrowFunctionExpression, Expression, Function}; use oxc_traverse::{Traverse, TraverseCtx}; use std::rc::Rc; @@ -25,43 +24,21 @@ impl ES2017<'_> { } impl<'a> Traverse<'a> for ES2017<'a> { - fn exit_program(&mut self, node: &mut Program<'a>, ctx: &mut TraverseCtx<'a>) { - if self.options.async_to_generator { - self.async_to_generator.exit_program(node, ctx); - } - } - fn exit_expression(&mut self, node: &mut Expression<'a>, ctx: &mut TraverseCtx<'a>) { if self.options.async_to_generator { self.async_to_generator.exit_expression(node, ctx); } } - fn exit_call_expression(&mut self, node: &mut CallExpression<'a>, ctx: &mut TraverseCtx<'a>) { - if self.options.async_to_generator { - self.async_to_generator.exit_call_expression(node, ctx); - } - } - - fn enter_function(&mut self, node: &mut Function<'a>, ctx: &mut TraverseCtx<'a>) { - if self.options.async_to_generator { - self.async_to_generator.enter_function(node, ctx); - } - } - fn exit_function(&mut self, node: &mut Function<'a>, ctx: &mut TraverseCtx<'a>) { if self.options.async_to_generator { self.async_to_generator.exit_function(node, ctx); } } - fn enter_arrow_function_expression( - &mut self, - node: &mut ArrowFunctionExpression<'a>, - ctx: &mut TraverseCtx<'a>, - ) { + fn exit_arrow_function_expression(&mut self, node: &mut ArrowFunctionExpression<'a>, ctx: &mut TraverseCtx<'a>) { if self.options.async_to_generator { - self.async_to_generator.enter_arrow_function_expression(node, ctx); + self.async_to_generator.exit_arrow_function_expression(node, ctx); } } } diff --git a/crates/oxc_transformer/src/es2017/utils/mod.rs b/crates/oxc_transformer/src/es2017/utils/mod.rs deleted file mode 100644 index 1dbb3dc007563..0000000000000 --- a/crates/oxc_transformer/src/es2017/utils/mod.rs +++ /dev/null @@ -1,608 +0,0 @@ -use oxc_allocator::{Box, CloneIn}; -use oxc_ast::ast::{ - ArrowFunctionExpression, BindingRestElement, BlockStatement, Expression, FormalParameterKind, - Function, FunctionType, Statement, TSAccessibility, TSThisParameter, TSTypeAnnotation, - TSTypeParameterDeclaration, TSTypeParameterInstantiation, VariableDeclarationKind, -}; -use oxc_ast::AstBuilder; -use oxc_span::SPAN; -use oxc_syntax::operator::UnaryOperator; - -pub fn async_generator_step<'a>(builder: &'a AstBuilder) -> Statement<'a> { - builder.statement_declaration(builder.declaration_function( - FunctionType::FunctionDeclaration, - SPAN, - Some(builder.binding_identifier(SPAN, "asyncGeneratorStep")), - false, - false, - false, - None::, - None::, - builder.formal_parameters( - SPAN, - FormalParameterKind::FormalParameter, - { - let mut items = builder.vec(); - items.push(builder.formal_parameter( - SPAN, - builder.vec(), - builder.binding_pattern( - builder.binding_pattern_kind_binding_identifier(SPAN, "gen"), - None::, - false, - ), - None::, - false, - false, - )); - items.push(builder.formal_parameter( - SPAN, - builder.vec(), - builder.binding_pattern( - builder.binding_pattern_kind_binding_identifier(SPAN, "resolve"), - None::, - false, - ), - None::, - false, - false, - )); - items.push(builder.formal_parameter( - SPAN, - builder.vec(), - builder.binding_pattern( - builder.binding_pattern_kind_binding_identifier(SPAN, "reject"), - None::, - false, - ), - None::, - false, - false, - )); - items.push(builder.formal_parameter( - SPAN, - builder.vec(), - builder.binding_pattern( - builder.binding_pattern_kind_binding_identifier(SPAN, "_next"), - None::, - false, - ), - None::, - false, - false, - )); - items.push(builder.formal_parameter( - SPAN, - builder.vec(), - builder.binding_pattern( - builder.binding_pattern_kind_binding_identifier(SPAN, "_throw"), - None::, - false, - ), - None::, - false, - false, - )); - items.push(builder.formal_parameter( - SPAN, - builder.vec(), - builder.binding_pattern( - builder.binding_pattern_kind_binding_identifier(SPAN, "key"), - None::, - false, - ), - None::, - false, - false, - )); - items.push(builder.formal_parameter( - SPAN, - builder.vec(), - builder.binding_pattern( - builder.binding_pattern_kind_binding_identifier(SPAN, "arg"), - None::, - false, - ), - None::, - false, - false, - )); - items - }, - None::, - ), - None::, - Some(builder.function_body(SPAN, builder.vec(), { - let mut items = builder.vec(); - items.push(builder.statement_try( - SPAN, - builder.block_statement( - SPAN, - builder.vec1(builder.statement_declaration(builder.declaration_variable( - SPAN, - VariableDeclarationKind::Var, - { - let mut items = builder.vec(); - items.push(builder.variable_declarator( - SPAN, - VariableDeclarationKind::Var, - builder.binding_pattern( - builder.binding_pattern_kind_binding_identifier(SPAN, "i"), - None::, - false, - ), - Some(builder.expression_call( - SPAN, - builder.expression_member(builder.member_expression_computed( - SPAN, - builder.expression_identifier_reference(SPAN, "gen"), - builder.expression_identifier_reference(SPAN, "key"), - false, - )), - None::, - builder.vec1(builder.argument_expression( - builder.expression_identifier_reference(SPAN, "arg"), - )), - false, - )), - false, - )); - items.push(builder.variable_declarator( - SPAN, - VariableDeclarationKind::Var, - builder.binding_pattern( - builder.binding_pattern_kind_binding_identifier(SPAN, "u"), - None::, - false, - ), - Some(builder.expression_member(builder.member_expression_static( - SPAN, - builder.expression_identifier_reference(SPAN, "i"), - builder.identifier_name(SPAN, "value"), - false, - ))), - false, - )); - items - }, - false, - ))), - ), - Some(builder.catch_clause( - SPAN, - Some(builder.catch_parameter( - SPAN, - builder.binding_pattern( - builder.binding_pattern_kind_binding_identifier(SPAN, "gen"), - None::, - false, - ), - )), - builder.block_statement( - SPAN, - builder.vec1(builder.statement_return( - SPAN, - Some(builder.expression_unary( - SPAN, - UnaryOperator::Void, - builder.expression_call( - SPAN, - builder.expression_identifier_reference(SPAN, "reject"), - None::, - builder.vec1(builder.argument_expression( - builder.expression_identifier_reference(SPAN, "gen"), - )), - false, - ), - )), - )), - ), - )), - None::, - )); - items.push(builder.statement_expression( - SPAN, - builder.expression_conditional( - SPAN, - builder.expression_member(builder.member_expression_static( - SPAN, - builder.expression_identifier_reference(SPAN, "i"), - builder.identifier_name(SPAN, "done"), - false, - )), - builder.expression_call( - SPAN, - builder.expression_identifier_reference(SPAN, "resolve"), - None::, - builder.vec1(builder.argument_expression( - builder.expression_identifier_reference(SPAN, "u"), - )), - false, - ), - builder.expression_call( - SPAN, - builder.expression_member(builder.member_expression_static( - SPAN, - builder.expression_call( - SPAN, - builder.expression_member(builder.member_expression_static( - SPAN, - builder.expression_identifier_reference(SPAN, "Promise"), - builder.identifier_name(SPAN, "resolve"), - false, - )), - None::, - builder.vec1(builder.argument_expression( - builder.expression_identifier_reference(SPAN, "u"), - )), - false, - ), - builder.identifier_name(SPAN, "then"), - false, - )), - None::, - { - let mut items = builder.vec(); - items.push(builder.argument_expression( - builder.expression_identifier_reference(SPAN, "_next"), - )); - items.push(builder.argument_expression( - builder.expression_identifier_reference(SPAN, "_throw"), - )); - items - }, - false, - ), - ), - )); - items - })), - )) -} - -fn async_generator_step_caller<'a>(parameter: &'a str, builder: &'a AstBuilder) -> Statement<'a> { - builder.statement_declaration(builder.declaration_function( - FunctionType::FunctionDeclaration, - SPAN, - Some(builder.binding_identifier(SPAN, "_".to_owned() + parameter)), - false, - false, - false, - None::, - None::, - builder.formal_parameters( - SPAN, - FormalParameterKind::FormalParameter, - builder.vec1(builder.formal_parameter( - SPAN, - builder.vec(), - builder.binding_pattern( - builder.binding_pattern_kind_binding_identifier(SPAN, "gen"), - None::, - false, - ), - None::, - false, - false, - )), - None::, - ), - None::, - Some(builder.function_body( - SPAN, - builder.vec(), - builder.vec1(builder.statement_expression( - SPAN, - builder.expression_call( - SPAN, - builder.expression_identifier_reference(SPAN, "asyncGeneratorStep"), - None::, - { - let mut items = builder.vec(); - items.push(builder.argument_expression( - builder.expression_identifier_reference(SPAN, "key"), - )); - items.push(builder.argument_expression( - builder.expression_identifier_reference(SPAN, "_next"), - )); - items.push(builder.argument_expression( - builder.expression_identifier_reference(SPAN, "_throw"), - )); - items.push(builder.argument_expression( - builder.expression_identifier_reference(SPAN, "_next"), - )); - items.push(builder.argument_expression( - builder.expression_identifier_reference(SPAN, "_throw"), - )); - items.push(builder.argument_expression( - builder.expression_string_literal(SPAN, parameter), - )); - items.push(builder.argument_expression( - builder.expression_identifier_reference(SPAN, "gen"), - )); - items - }, - false, - ), - )), - )), - )) -} - -fn caller_promise<'a>(builder: &'a AstBuilder) -> Expression<'a> { - builder.expression_new( - SPAN, - builder.expression_identifier_reference(SPAN, "Promise"), - builder.vec1(builder.argument_expression(builder.expression_function( - FunctionType::FunctionExpression, - SPAN, - None, - false, - false, - false, - None::, - None::, - builder.formal_parameters( - SPAN, - FormalParameterKind::FormalParameter, - { - let mut items = builder.vec(); - items.push(builder.formal_parameter( - SPAN, - builder.vec(), - builder.binding_pattern( - builder.binding_pattern_kind_binding_identifier(SPAN, "_next"), - None::, - false, - ), - None::, - false, - false, - )); - items.push(builder.formal_parameter( - SPAN, - builder.vec(), - builder.binding_pattern( - builder.binding_pattern_kind_binding_identifier(SPAN, "_throw"), - None::, - false, - ), - None::, - false, - false, - )); - items - }, - None::, - ), - None::, - Some(builder.function_body(SPAN, builder.vec(), { - let mut items = builder.vec(); - items.push(builder.statement_declaration(builder.declaration_variable( - SPAN, - VariableDeclarationKind::Var, - builder.vec1(builder.variable_declarator( - SPAN, - VariableDeclarationKind::Var, - builder.binding_pattern( - builder.binding_pattern_kind_binding_identifier(SPAN, "key"), - None::, - false, - ), - Some(builder.expression_call( - SPAN, - builder.expression_member(builder.member_expression_static( - SPAN, - builder.expression_identifier_reference(SPAN, "fn"), - builder.identifier_name(SPAN, "apply"), - false, - )), - None::, - { - let mut items = builder.vec(); - items.push(builder.argument_expression( - builder.expression_identifier_reference(SPAN, "resolve"), - )); - items.push(builder.argument_expression( - builder.expression_identifier_reference(SPAN, "reject"), - )); - items - }, - false, - )), - false, - )), - false, - ))); - items.push(async_generator_step_caller("next", builder)); - items.push(async_generator_step_caller("throw", builder)); - items.push(builder.statement_expression( - SPAN, - builder.expression_call( - SPAN, - builder.expression_identifier_reference(SPAN, "_next"), - None::, - builder.vec1(builder.argument_expression(builder.void_0())), - false, - ), - )); - items - })), - ))), - None::, - ) -} - -pub fn async_to_generator<'a>(builder: &'a AstBuilder) -> Statement<'a> { - builder.statement_declaration(builder.declaration_function( - FunctionType::FunctionDeclaration, - SPAN, - Some(builder.binding_identifier(SPAN, "_asyncToGenerator")), - false, - false, - false, - None::, - None::, - builder.formal_parameters( - SPAN, - FormalParameterKind::FormalParameter, - builder.vec1(builder.formal_parameter( - SPAN, - builder.vec(), - builder.binding_pattern( - builder.binding_pattern_kind_binding_identifier(SPAN, "fn"), - None::, - false, - ), - None::, - false, - false, - )), - None::, - ), - None::, - Some(builder.function_body( - SPAN, - builder.vec(), - builder.vec1(builder.statement_return( - SPAN, - Some(builder.expression_function( - FunctionType::FunctionExpression, - SPAN, - None, - false, - false, - false, - None::, - None::, - builder.formal_parameters( - SPAN, - FormalParameterKind::FormalParameter, - builder.vec(), - None::, - ), - None::, - Some(builder.function_body(SPAN, builder.vec(), { - let mut items = builder.vec(); - items.push(builder.statement_declaration(builder.declaration_variable( - SPAN, - VariableDeclarationKind::Var, - { - let mut items = builder.vec(); - items.push(builder.variable_declarator( - SPAN, - VariableDeclarationKind::Var, - builder.binding_pattern( - builder.binding_pattern_kind_binding_identifier( - SPAN, "resolve", - ), - None::, - false, - ), - Some(builder.expression_this(SPAN)), - false, - )); - items.push(builder.variable_declarator( - SPAN, - VariableDeclarationKind::Var, - builder.binding_pattern( - builder.binding_pattern_kind_binding_identifier( - SPAN, "reject", - ), - None::, - false, - ), - Some( - builder.expression_identifier_reference(SPAN, "arguments"), - ), - false, - )); - items - }, - false, - ))); - items.push(builder.statement_return(SPAN, Some(caller_promise(builder)))); - items - })), - )), - )), - )), - )) -} - -pub fn function_apply<'a>(name: &'a str, builder: &'a AstBuilder) -> Statement<'a> { - builder.statement_return( - SPAN, - Some(builder.expression_call( - SPAN, - builder.expression_member(builder.member_expression_static( - SPAN, - builder.expression_identifier_reference(SPAN, name), - builder.identifier_name(SPAN, "apply"), - false, - )), - None::, - { - let mut items = builder.vec(); - items.push(builder.argument_expression(builder.expression_this(SPAN))); - items.push(builder.argument_expression( - builder.expression_identifier_reference(SPAN, "arguments"), - )); - items - }, - false, - )), - ) -} - -pub fn generate_caller_from_arrow<'a>( - func: &Box, - builder: &'a AstBuilder, -) -> Expression<'a> { - let result = builder.function( - FunctionType::FunctionExpression, - func.span, - None, - true, - false, - false, - func.type_parameters.clone_in(builder.allocator), - None::, - func.params.clone_in(builder.allocator), - func.return_type.clone_in(builder.allocator), - Some(func.body.clone_in(builder.allocator)), - ); - builder.expression_call( - SPAN, - builder.expression_identifier_reference(SPAN, "_asyncToGenerator"), - None::, - builder.vec1(builder.argument_expression(builder.expression_from_function(result))), - false, - ) -} - -pub fn generate_caller_from_function<'a>( - func: &Box>, - builder: &'a AstBuilder, -) -> Expression<'a> { - let result = builder.function( - FunctionType::FunctionExpression, - func.span, - None, - true, - false, - false, - func.type_parameters.clone_in(builder.allocator), - None::, - func.params.clone_in(builder.allocator), - func.return_type.clone_in(builder.allocator), - func.body.clone_in(builder.allocator), - ); - builder.expression_call( - SPAN, - builder.expression_identifier_reference(SPAN, "_asyncToGenerator"), - None::, - builder.vec1(builder.argument_expression(builder.expression_from_function(result))), - false, - ) -} From 6a8aebcb7d11d4bf51fa9e08d20583ed40b42407 Mon Sep 17 00:00:00 2001 From: Ethan Goh <7086cmd@gmail.com> Date: Sun, 22 Sep 2024 12:33:15 +0800 Subject: [PATCH 07/25] chore: format. --- crates/oxc_transformer/src/es2017/mod.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/oxc_transformer/src/es2017/mod.rs b/crates/oxc_transformer/src/es2017/mod.rs index 7e2adc30b89f1..b0f67638b9a58 100644 --- a/crates/oxc_transformer/src/es2017/mod.rs +++ b/crates/oxc_transformer/src/es2017/mod.rs @@ -36,7 +36,11 @@ impl<'a> Traverse<'a> for ES2017<'a> { } } - fn exit_arrow_function_expression(&mut self, node: &mut ArrowFunctionExpression<'a>, ctx: &mut TraverseCtx<'a>) { + fn exit_arrow_function_expression( + &mut self, + node: &mut ArrowFunctionExpression<'a>, + ctx: &mut TraverseCtx<'a>, + ) { if self.options.async_to_generator { self.async_to_generator.exit_arrow_function_expression(node, ctx); } From d6572fd7ec0ee1be47767c67810a61a44c893ae2 Mon Sep 17 00:00:00 2001 From: Ethan Goh <7086cmd@gmail.com> Date: Sun, 22 Sep 2024 12:43:40 +0800 Subject: [PATCH 08/25] chore: resolve tests. --- .../snapshots/babel.snap.md | 337 +++--------------- 1 file changed, 46 insertions(+), 291 deletions(-) diff --git a/tasks/transform_conformance/snapshots/babel.snap.md b/tasks/transform_conformance/snapshots/babel.snap.md index 8167a326b453b..843426f546a41 100644 --- a/tasks/transform_conformance/snapshots/babel.snap.md +++ b/tasks/transform_conformance/snapshots/babel.snap.md @@ -1,15 +1,16 @@ commit: 3bcfee23 -Passed: 312/1038 +Passed: 330/1024 # All Passed: * babel-plugin-transform-optional-catch-binding +* babel-preset-react * babel-plugin-transform-react-display-name * babel-plugin-transform-react-jsx-self * babel-plugin-transform-react-jsx-source -# babel-preset-env (104/585) +# babel-preset-env (106/585) * .plugins-overlapping/chrome-49/input.js x Output mismatch @@ -256,12 +257,6 @@ x Output mismatch * corejs2-babel-7/usage-typed-array/input.mjs x Output mismatch -* corejs2-babel-7/usage-typed-array-edge-13/input.mjs -Missing ReferenceId: Int8Array -Unresolved reference IDs mismatch for "Int8Array": -after transform: [ReferenceId(0)] -rebuilt : [ReferenceId(0)] - * corejs2-babel-7/usage-typed-array-static/input.mjs x Output mismatch @@ -1321,16 +1316,6 @@ x Output mismatch * preset-options/include-scoped/input.mjs x Output mismatch -* preset-options/ios-10/input.mjs -Missing SymbolId: a -Missing ScopeId -Binding symbols mismatch: -after transform: ScopeId(0): [SymbolId(0)] -rebuilt : ScopeId(0): [SymbolId(0)] -Scope children mismatch: -after transform: ScopeId(0): [ScopeId(1)] -rebuilt : ScopeId(0): [ScopeId(1)] - * preset-options/ios-6/input.mjs x Output mismatch @@ -1464,35 +1449,7 @@ x Output mismatch x Output mismatch -# babel-plugin-transform-logical-assignment-operators (0/6) -* logical-assignment/anonymous-functions-transform/input.js -Symbol reference IDs mismatch: -after transform: SymbolId(0): [ReferenceId(0), ReferenceId(1), ReferenceId(2), ReferenceId(3), ReferenceId(4), ReferenceId(5), ReferenceId(6), ReferenceId(7), ReferenceId(8)] -rebuilt : SymbolId(0): [ReferenceId(0), ReferenceId(1), ReferenceId(2), ReferenceId(3), ReferenceId(4), ReferenceId(5)] -Reference flags mismatch: -after transform: ReferenceId(4): ReferenceFlags(Write) -rebuilt : ReferenceId(1): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(6): ReferenceFlags(Write) -rebuilt : ReferenceId(3): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(8): ReferenceFlags(Write) -rebuilt : ReferenceId(5): ReferenceFlags(Read | Write) - -* logical-assignment/arrow-functions-transform/input.js -Symbol reference IDs mismatch: -after transform: SymbolId(0): [ReferenceId(0), ReferenceId(1), ReferenceId(2), ReferenceId(3), ReferenceId(4), ReferenceId(5), ReferenceId(6), ReferenceId(7), ReferenceId(8)] -rebuilt : SymbolId(0): [ReferenceId(0), ReferenceId(1), ReferenceId(2), ReferenceId(3), ReferenceId(4), ReferenceId(5)] -Reference flags mismatch: -after transform: ReferenceId(4): ReferenceFlags(Write) -rebuilt : ReferenceId(1): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(6): ReferenceFlags(Write) -rebuilt : ReferenceId(3): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(8): ReferenceFlags(Write) -rebuilt : ReferenceId(5): ReferenceFlags(Read | Write) - +# babel-plugin-transform-logical-assignment-operators (3/6) * logical-assignment/general-semantics/input.js Symbol reference IDs mismatch: after transform: SymbolId(15): [ReferenceId(117), ReferenceId(118), ReferenceId(121)] @@ -1506,104 +1463,6 @@ rebuilt : SymbolId(12): [ReferenceId(111), ReferenceId(115)] Symbol reference IDs mismatch: after transform: SymbolId(21): [ReferenceId(132), ReferenceId(133), ReferenceId(136)] rebuilt : SymbolId(14): [ReferenceId(123), ReferenceId(127)] -Reference flags mismatch: -after transform: ReferenceId(98): ReferenceFlags(Write) -rebuilt : ReferenceId(27): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(97): ReferenceFlags(Write) -rebuilt : ReferenceId(29): ReferenceFlags(Read) -Reference flags mismatch: -after transform: ReferenceId(100): ReferenceFlags(Write) -rebuilt : ReferenceId(33): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(99): ReferenceFlags(Write) -rebuilt : ReferenceId(35): ReferenceFlags(Read) -Reference flags mismatch: -after transform: ReferenceId(102): ReferenceFlags(Write) -rebuilt : ReferenceId(39): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(101): ReferenceFlags(Write) -rebuilt : ReferenceId(41): ReferenceFlags(Read) -Reference flags mismatch: -after transform: ReferenceId(104): ReferenceFlags(Write) -rebuilt : ReferenceId(45): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(103): ReferenceFlags(Write) -rebuilt : ReferenceId(47): ReferenceFlags(Read) -Reference flags mismatch: -after transform: ReferenceId(107): ReferenceFlags(Write) -rebuilt : ReferenceId(52): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(105): ReferenceFlags(Write) -rebuilt : ReferenceId(55): ReferenceFlags(Read) -Reference flags mismatch: -after transform: ReferenceId(110): ReferenceFlags(Write) -rebuilt : ReferenceId(61): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(108): ReferenceFlags(Write) -rebuilt : ReferenceId(64): ReferenceFlags(Read) -Reference flags mismatch: -after transform: ReferenceId(113): ReferenceFlags(Write) -rebuilt : ReferenceId(70): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(111): ReferenceFlags(Write) -rebuilt : ReferenceId(73): ReferenceFlags(Read) -Reference flags mismatch: -after transform: ReferenceId(116): ReferenceFlags(Write) -rebuilt : ReferenceId(79): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(114): ReferenceFlags(Write) -rebuilt : ReferenceId(82): ReferenceFlags(Read) -Reference flags mismatch: -after transform: ReferenceId(118): ReferenceFlags(Write) -rebuilt : ReferenceId(87): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(120): ReferenceFlags(Write) -rebuilt : ReferenceId(89): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(119): ReferenceFlags(Write) -rebuilt : ReferenceId(92): ReferenceFlags(Read) -Reference flags mismatch: -after transform: ReferenceId(123): ReferenceFlags(Write) -rebuilt : ReferenceId(99): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(125): ReferenceFlags(Write) -rebuilt : ReferenceId(101): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(124): ReferenceFlags(Write) -rebuilt : ReferenceId(104): ReferenceFlags(Read) -Reference flags mismatch: -after transform: ReferenceId(128): ReferenceFlags(Write) -rebuilt : ReferenceId(111): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(130): ReferenceFlags(Write) -rebuilt : ReferenceId(113): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(129): ReferenceFlags(Write) -rebuilt : ReferenceId(116): ReferenceFlags(Read) -Reference flags mismatch: -after transform: ReferenceId(133): ReferenceFlags(Write) -rebuilt : ReferenceId(123): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(135): ReferenceFlags(Write) -rebuilt : ReferenceId(125): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(134): ReferenceFlags(Write) -rebuilt : ReferenceId(128): ReferenceFlags(Read) - -* logical-assignment/named-functions-transform/input.js -Symbol reference IDs mismatch: -after transform: SymbolId(0): [ReferenceId(0), ReferenceId(1), ReferenceId(2), ReferenceId(3), ReferenceId(4), ReferenceId(5), ReferenceId(6), ReferenceId(7), ReferenceId(8)] -rebuilt : SymbolId(0): [ReferenceId(0), ReferenceId(1), ReferenceId(2), ReferenceId(3), ReferenceId(4), ReferenceId(5)] -Reference flags mismatch: -after transform: ReferenceId(4): ReferenceFlags(Write) -rebuilt : ReferenceId(1): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(6): ReferenceFlags(Write) -rebuilt : ReferenceId(3): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(8): ReferenceFlags(Write) -rebuilt : ReferenceId(5): ReferenceFlags(Read | Write) * logical-assignment/null-coalescing/input.js Symbol reference IDs mismatch: @@ -1615,29 +1474,8 @@ rebuilt : SymbolId(13): [ReferenceId(88), ReferenceId(94)] * logical-assignment/null-coalescing-without-other/input.js Symbol reference IDs mismatch: -after transform: SymbolId(2): [ReferenceId(7), ReferenceId(8), ReferenceId(11)] +after transform: SymbolId(2): [ReferenceId(6), ReferenceId(7), ReferenceId(10)] rebuilt : SymbolId(1): [ReferenceId(5), ReferenceId(8)] -Symbol reference IDs mismatch: -after transform: SymbolId(0): [ReferenceId(0), ReferenceId(1), ReferenceId(2), ReferenceId(3), ReferenceId(4)] -rebuilt : SymbolId(3): [ReferenceId(0), ReferenceId(1), ReferenceId(3), ReferenceId(6)] -Reference flags mismatch: -after transform: ReferenceId(4): ReferenceFlags(Write) -rebuilt : ReferenceId(1): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(6): ReferenceFlags(Write) -rebuilt : ReferenceId(2): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(5): ReferenceFlags(Write) -rebuilt : ReferenceId(4): ReferenceFlags(Read) -Reference flags mismatch: -after transform: ReferenceId(8): ReferenceFlags(Write) -rebuilt : ReferenceId(5): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(10): ReferenceFlags(Write) -rebuilt : ReferenceId(7): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(9): ReferenceFlags(Write) -rebuilt : ReferenceId(9): ReferenceFlags(Read) # babel-plugin-transform-nullish-coalescing-operator (5/12) @@ -1827,55 +1665,13 @@ x Output mismatch x Output mismatch -# babel-plugin-transform-async-to-generator (1/17) +# babel-plugin-transform-async-to-generator (0/2) * assumption-ignoreFunctionLength-true/basic/input.mjs x Output mismatch * assumption-ignoreFunctionLength-true/export-default-function/input.mjs x Output mismatch -* assumption-noNewArrows-false/basic/input.js -x Output mismatch - -* bluebird-coroutines/arrow-function/input.js -x Output mismatch - -* bluebird-coroutines/class/input.js -x Output mismatch - -* bluebird-coroutines/expression/input.js -x Output mismatch - -* bluebird-coroutines/named-expression/input.js -x Output mismatch - -* bluebird-coroutines/statement/input.js -x Output mismatch - -* regression/15978/input.js -x Output mismatch - -* regression/4599/input.js -x Output mismatch - -* regression/8783/input.js -x Output mismatch - -* regression/T7108/input.js -x Output mismatch - -* regression/T7194/input.js -x Output mismatch - -* regression/gh-6923/input.js -x Output mismatch - -* regression/in-uncompiled-class-fields/input.js -x Output mismatch - -* regression/regression-2765/input.js -x Output mismatch - # babel-plugin-transform-exponentiation-operator (1/4) * exponentiation-operator/assignment/input.js @@ -2032,16 +1828,16 @@ Bindings mismatch: after transform: ScopeId(1): ["A", "E"] rebuilt : ScopeId(1): ["E"] Scope flags mismatch: -after transform: ScopeId(1): ScopeFlags(StrictMode) -rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) +after transform: ScopeId(1): ScopeFlags(0x0) +rebuilt : ScopeId(1): ScopeFlags(Function) Symbol flags mismatch: after transform: SymbolId(0): SymbolFlags(RegularEnum) rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable) * enum/const/input.ts Scope flags mismatch: -after transform: ScopeId(1): ScopeFlags(StrictMode) -rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) +after transform: ScopeId(1): ScopeFlags(0x0) +rebuilt : ScopeId(1): ScopeFlags(Function) Symbol flags mismatch: after transform: SymbolId(0): SymbolFlags(ConstEnum) rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable) @@ -2051,8 +1847,8 @@ Bindings mismatch: after transform: ScopeId(1): ["E", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r"] rebuilt : ScopeId(1): ["E"] Scope flags mismatch: -after transform: ScopeId(1): ScopeFlags(StrictMode) -rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) +after transform: ScopeId(1): ScopeFlags(0x0) +rebuilt : ScopeId(1): ScopeFlags(Function) Symbol flags mismatch: after transform: SymbolId(0): SymbolFlags(RegularEnum) rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable) @@ -2062,14 +1858,14 @@ Bindings mismatch: after transform: ScopeId(1): ["Animals", "Cat", "Dog"] rebuilt : ScopeId(1): ["Animals"] Scope flags mismatch: -after transform: ScopeId(1): ScopeFlags(StrictMode) -rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) +after transform: ScopeId(1): ScopeFlags(0x0) +rebuilt : ScopeId(1): ScopeFlags(Function) Bindings mismatch: after transform: ScopeId(2): ["Animals", "CatDog"] rebuilt : ScopeId(2): ["Animals"] Scope flags mismatch: -after transform: ScopeId(2): ScopeFlags(StrictMode) -rebuilt : ScopeId(2): ScopeFlags(StrictMode | Function) +after transform: ScopeId(2): ScopeFlags(0x0) +rebuilt : ScopeId(2): ScopeFlags(Function) Symbol flags mismatch: after transform: SymbolId(0): SymbolFlags(RegularEnum) rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable) @@ -2085,20 +1881,20 @@ Bindings mismatch: after transform: ScopeId(1): ["Animals", "Cat"] rebuilt : ScopeId(1): ["Animals"] Scope flags mismatch: -after transform: ScopeId(1): ScopeFlags(StrictMode) -rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) +after transform: ScopeId(1): ScopeFlags(0x0) +rebuilt : ScopeId(1): ScopeFlags(Function) Bindings mismatch: after transform: ScopeId(2): ["Animals", "Dog"] rebuilt : ScopeId(2): ["Animals"] Scope flags mismatch: -after transform: ScopeId(2): ScopeFlags(StrictMode) -rebuilt : ScopeId(2): ScopeFlags(StrictMode | Function) +after transform: ScopeId(2): ScopeFlags(0x0) +rebuilt : ScopeId(2): ScopeFlags(Function) Bindings mismatch: after transform: ScopeId(3): ["Animals", "CatDog"] rebuilt : ScopeId(3): ["Animals"] Scope flags mismatch: -after transform: ScopeId(3): ScopeFlags(StrictMode) -rebuilt : ScopeId(3): ScopeFlags(StrictMode | Function) +after transform: ScopeId(3): ScopeFlags(0x0) +rebuilt : ScopeId(3): ScopeFlags(Function) Symbol reference IDs mismatch: after transform: SymbolId(0): [ReferenceId(0)] rebuilt : SymbolId(0): [] @@ -2137,8 +1933,8 @@ Bindings mismatch: after transform: ScopeId(1): ["E", "x", "y"] rebuilt : ScopeId(1): ["E"] Scope flags mismatch: -after transform: ScopeId(1): ScopeFlags(StrictMode) -rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) +after transform: ScopeId(1): ScopeFlags(0x0) +rebuilt : ScopeId(1): ScopeFlags(Function) Symbol flags mismatch: after transform: SymbolId(0): SymbolFlags(RegularEnum) rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable) @@ -2148,8 +1944,8 @@ Bindings mismatch: after transform: ScopeId(1): ["E", "a", "b"] rebuilt : ScopeId(1): ["E"] Scope flags mismatch: -after transform: ScopeId(1): ScopeFlags(StrictMode) -rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) +after transform: ScopeId(1): ScopeFlags(0x0) +rebuilt : ScopeId(1): ScopeFlags(Function) Symbol flags mismatch: after transform: SymbolId(0): SymbolFlags(RegularEnum) rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable) @@ -2162,8 +1958,8 @@ Bindings mismatch: after transform: ScopeId(1): ["E", "a", "b"] rebuilt : ScopeId(1): ["E"] Scope flags mismatch: -after transform: ScopeId(1): ScopeFlags(StrictMode) -rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) +after transform: ScopeId(1): ScopeFlags(0x0) +rebuilt : ScopeId(1): ScopeFlags(Function) Symbol flags mismatch: after transform: SymbolId(0): SymbolFlags(RegularEnum) rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable) @@ -2173,14 +1969,14 @@ Bindings mismatch: after transform: ScopeId(1): ["E", "x", "y"] rebuilt : ScopeId(1): ["E"] Scope flags mismatch: -after transform: ScopeId(1): ScopeFlags(StrictMode) -rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) +after transform: ScopeId(1): ScopeFlags(0x0) +rebuilt : ScopeId(1): ScopeFlags(Function) Bindings mismatch: after transform: ScopeId(2): ["E", "z"] rebuilt : ScopeId(2): ["E"] Scope flags mismatch: -after transform: ScopeId(2): ScopeFlags(StrictMode) -rebuilt : ScopeId(2): ScopeFlags(StrictMode | Function) +after transform: ScopeId(2): ScopeFlags(0x0) +rebuilt : ScopeId(2): ScopeFlags(Function) Symbol flags mismatch: after transform: SymbolId(0): SymbolFlags(RegularEnum) rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable) @@ -2193,14 +1989,14 @@ Bindings mismatch: after transform: ScopeId(1): ["IPC", "SERVER", "SOCKET", "socketType"] rebuilt : ScopeId(1): ["socketType"] Scope flags mismatch: -after transform: ScopeId(1): ScopeFlags(StrictMode) -rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) +after transform: ScopeId(1): ScopeFlags(0x0) +rebuilt : ScopeId(1): ScopeFlags(Function) Bindings mismatch: after transform: ScopeId(2): ["IPC", "SERVER", "SOCKET", "UV_READABLE", "UV_WRITABLE", "constants"] rebuilt : ScopeId(2): ["constants"] Scope flags mismatch: -after transform: ScopeId(2): ScopeFlags(StrictMode) -rebuilt : ScopeId(2): ScopeFlags(StrictMode | Function) +after transform: ScopeId(2): ScopeFlags(0x0) +rebuilt : ScopeId(2): ScopeFlags(Function) Symbol flags mismatch: after transform: SymbolId(0): SymbolFlags(RegularEnum) rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable) @@ -2216,8 +2012,8 @@ x Output mismatch * enum/scoped/input.ts Scope flags mismatch: -after transform: ScopeId(2): ScopeFlags(StrictMode) -rebuilt : ScopeId(2): ScopeFlags(StrictMode | Function) +after transform: ScopeId(2): ScopeFlags(0x0) +rebuilt : ScopeId(2): ScopeFlags(Function) Symbol flags mismatch: after transform: SymbolId(0): SymbolFlags(RegularEnum) rebuilt : SymbolId(0): SymbolFlags(BlockScopedVariable) @@ -2227,8 +2023,8 @@ Bindings mismatch: after transform: ScopeId(1): ["A", "A2", "B", "B2", "E"] rebuilt : ScopeId(1): ["E"] Scope flags mismatch: -after transform: ScopeId(1): ScopeFlags(StrictMode) -rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) +after transform: ScopeId(1): ScopeFlags(0x0) +rebuilt : ScopeId(1): ScopeFlags(Function) Symbol flags mismatch: after transform: SymbolId(0): SymbolFlags(RegularEnum) rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable) @@ -2238,8 +2034,8 @@ Bindings mismatch: after transform: ScopeId(1): ["A", "E"] rebuilt : ScopeId(1): ["E"] Scope flags mismatch: -after transform: ScopeId(1): ScopeFlags(StrictMode) -rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) +after transform: ScopeId(1): ScopeFlags(0x0) +rebuilt : ScopeId(1): ScopeFlags(Function) Symbol flags mismatch: after transform: SymbolId(0): SymbolFlags(RegularEnum) rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable) @@ -2249,8 +2045,8 @@ Bindings mismatch: after transform: ScopeId(1): ["A", "E"] rebuilt : ScopeId(1): ["E"] Scope flags mismatch: -after transform: ScopeId(1): ScopeFlags(StrictMode) -rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) +after transform: ScopeId(1): ScopeFlags(0x0) +rebuilt : ScopeId(1): ScopeFlags(Function) Symbol flags mismatch: after transform: SymbolId(0): SymbolFlags(RegularEnum) rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable) @@ -3545,39 +3341,19 @@ after transform: ["T", "f"] rebuilt : ["f"] -# babel-preset-react (6/9) -* preset-options/development-runtime-automatic/input.js -x Output mismatch - -* preset-options/empty-options/input.js -x Output mismatch - -* preset-options/runtime-automatic/input.js -x Output mismatch - - -# babel-plugin-transform-react-jsx (119/144) -* pure/false-default-pragma-automatic-runtime/input.js -x Output mismatch - +# babel-plugin-transform-react-jsx (124/144) * pure/false-pragma-comment-automatic-runtime/input.js pragma and pragmaFrag cannot be set when runtime is automatic. * pure/false-pragma-option-automatic-runtime/input.js pragma and pragmaFrag cannot be set when runtime is automatic. -* pure/true-default-pragma-automatic-runtime/input.js -x Output mismatch - * pure/true-pragma-comment-automatic-runtime/input.js pragma and pragmaFrag cannot be set when runtime is automatic. * pure/true-pragma-option-automatic-runtime/input.js pragma and pragmaFrag cannot be set when runtime is automatic. -* pure/unset-default-pragma-automatic-runtime/input.js -x Output mismatch - * pure/unset-pragma-comment-automatic-runtime/input.js pragma and pragmaFrag cannot be set when runtime is automatic. @@ -3662,12 +3438,6 @@ Spread children are not supported in React. * react-automatic/should-warn-when-pragma-or-pragmaFrag-is-set/input.js pragma and pragmaFrag cannot be set when runtime is automatic. -* runtime/defaults-to-automatic/input.js -x Output mismatch - -* runtime/runtime-automatic/input.js -x Output mismatch - * spread-transform/transform-to-babel-extend/input.js x Output mismatch @@ -3675,7 +3445,7 @@ x Output mismatch x Output mismatch -# babel-plugin-transform-react-jsx-development (2/10) +# babel-plugin-transform-react-jsx-development (8/11) * cross-platform/disallow-__self-as-jsx-attribute/input.js ! Duplicate __self prop found. ,-[tasks/coverage/babel/packages/babel-plugin-transform-react-jsx-development/test/fixtures/cross-platform/disallow-__self-as-jsx-attribute/input.js:1:14] @@ -3692,21 +3462,6 @@ x Output mismatch `---- -* cross-platform/fragments/input.js -x Output mismatch - -* cross-platform/handle-fragments-with-key/input.js -x Output mismatch - -* cross-platform/handle-nonstatic-children/input.js -x Output mismatch - -* cross-platform/handle-static-children/input.js -x Output mismatch - -* cross-platform/within-derived-classes-constructor/input.js -x Output mismatch - * cross-platform/within-ts-module-block/input.tsx x Output mismatch From 8a827ccefc55afacf88f5f08cc1044540c652a77 Mon Sep 17 00:00:00 2001 From: Ethan Goh <7086cmd@gmail.com> Date: Sun, 22 Sep 2024 12:45:10 +0800 Subject: [PATCH 09/25] chore: remove file [ci skip] --- tasks/transform_conformance/oxc.snap.md | 795 ------------------------ 1 file changed, 795 deletions(-) delete mode 100644 tasks/transform_conformance/oxc.snap.md diff --git a/tasks/transform_conformance/oxc.snap.md b/tasks/transform_conformance/oxc.snap.md deleted file mode 100644 index 333f08f7c005a..0000000000000 --- a/tasks/transform_conformance/oxc.snap.md +++ /dev/null @@ -1,795 +0,0 @@ -commit: 3bcfee23 - -Passed: 18/49 - -# All Passed: -* babel-plugin-transform-nullish-coalescing-operator -* babel-plugin-transform-optional-catch-binding -* babel-preset-typescript - - -# babel-plugin-transform-arrow-functions (1/2) -* with-this-member-expression/input.jsx -x Output mismatch - - -# babel-plugin-transform-typescript (1/8) -* class-property-definition/input.ts -Unresolved references mismatch: -after transform: ["const"] -rebuilt : [] - -* computed-constant-value/input.ts -Missing ReferenceId: Infinity -Missing ReferenceId: Infinity -Missing ReferenceId: Infinity -Missing ReferenceId: Infinity -Bindings mismatch: -after transform: ScopeId(1): ["A", "a", "b", "c", "d", "e"] -rebuilt : ScopeId(1): ["A"] -Scope flags mismatch: -after transform: ScopeId(1): ScopeFlags(StrictMode) -rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) -Bindings mismatch: -after transform: ScopeId(2): ["B", "a", "b", "c", "d", "e"] -rebuilt : ScopeId(2): ["B"] -Scope flags mismatch: -after transform: ScopeId(2): ScopeFlags(StrictMode) -rebuilt : ScopeId(2): ScopeFlags(StrictMode | Function) -Bindings mismatch: -after transform: ScopeId(3): ["C", "a", "b", "c"] -rebuilt : ScopeId(3): ["C"] -Scope flags mismatch: -after transform: ScopeId(3): ScopeFlags(StrictMode) -rebuilt : ScopeId(3): ScopeFlags(StrictMode | Function) -Bindings mismatch: -after transform: ScopeId(4): ["D", "a", "b", "c"] -rebuilt : ScopeId(4): ["D"] -Scope flags mismatch: -after transform: ScopeId(4): ScopeFlags(StrictMode) -rebuilt : ScopeId(4): ScopeFlags(StrictMode | Function) -Symbol flags mismatch: -after transform: SymbolId(0): SymbolFlags(RegularEnum) -rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable) -Symbol flags mismatch: -after transform: SymbolId(6): SymbolFlags(RegularEnum) -rebuilt : SymbolId(2): SymbolFlags(FunctionScopedVariable) -Symbol flags mismatch: -after transform: SymbolId(12): SymbolFlags(RegularEnum) -rebuilt : SymbolId(4): SymbolFlags(FunctionScopedVariable) -Symbol flags mismatch: -after transform: SymbolId(16): SymbolFlags(RegularEnum) -rebuilt : SymbolId(6): SymbolFlags(FunctionScopedVariable) -Unresolved references mismatch: -after transform: ["Infinity", "NaN"] -rebuilt : ["Infinity"] -Unresolved reference IDs mismatch for "Infinity": -after transform: [ReferenceId(0), ReferenceId(1), ReferenceId(2), ReferenceId(3)] -rebuilt : [ReferenceId(2), ReferenceId(5), ReferenceId(8), ReferenceId(12)] - -* elimination-declare/input.ts -Bindings mismatch: -after transform: ScopeId(0): ["A", "ReactiveMarkerSymbol"] -rebuilt : ScopeId(0): [] -Scope children mismatch: -after transform: ScopeId(0): [ScopeId(1)] -rebuilt : ScopeId(0): [] - -* enum-member-reference/input.ts -Missing ReferenceId: Foo -Bindings mismatch: -after transform: ScopeId(1): ["Foo", "a", "b", "c"] -rebuilt : ScopeId(1): ["Foo"] -Scope flags mismatch: -after transform: ScopeId(1): ScopeFlags(StrictMode) -rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function) -Symbol flags mismatch: -after transform: SymbolId(1): SymbolFlags(RegularEnum) -rebuilt : SymbolId(1): SymbolFlags(FunctionScopedVariable) -Symbol reference IDs mismatch: -after transform: SymbolId(5): [ReferenceId(3), ReferenceId(4), ReferenceId(5), ReferenceId(6), ReferenceId(7), ReferenceId(8), ReferenceId(9)] -rebuilt : SymbolId(2): [ReferenceId(0), ReferenceId(1), ReferenceId(2), ReferenceId(3), ReferenceId(4), ReferenceId(5), ReferenceId(6), ReferenceId(8)] - -* export-elimination/input.ts -Missing SymbolId: Name -Missing SymbolId: _Name -Missing ReferenceId: _Name -Missing ReferenceId: Name -Missing ReferenceId: Name -Bindings mismatch: -after transform: ScopeId(0): ["Baq", "Bar", "Baz", "Foo", "Func", "Im", "Name", "Ok", "T"] -rebuilt : ScopeId(0): ["Bar", "Foo", "Func", "Im", "Name", "Ok", "T"] -Scope children mismatch: -after transform: ScopeId(0): [ScopeId(1), ScopeId(2), ScopeId(3), ScopeId(4), ScopeId(5), ScopeId(6), ScopeId(7)] -rebuilt : ScopeId(0): [ScopeId(1), ScopeId(2), ScopeId(3), ScopeId(4)] -Binding symbols mismatch: -after transform: ScopeId(5): [SymbolId(8), SymbolId(10)] -rebuilt : ScopeId(3): [SymbolId(6), SymbolId(7)] -Symbol flags mismatch: -after transform: SymbolId(8): SymbolFlags(BlockScopedVariable | ConstVariable | Export) -rebuilt : SymbolId(7): SymbolFlags(BlockScopedVariable | ConstVariable) -Symbol flags mismatch: -after transform: SymbolId(9): SymbolFlags(BlockScopedVariable | Export | Function | TypeAlias) -rebuilt : SymbolId(8): SymbolFlags(BlockScopedVariable | Export | Function) -Symbol span mismatch: -after transform: SymbolId(9): Span { start: 205, end: 206 } -rebuilt : SymbolId(8): Span { start: 226, end: 227 } -Symbol reference IDs mismatch: -after transform: SymbolId(9): [ReferenceId(8), ReferenceId(9)] -rebuilt : SymbolId(8): [ReferenceId(9)] -Symbol redeclarations mismatch: -after transform: SymbolId(9): [Span { start: 226, end: 227 }] -rebuilt : SymbolId(8): [] -Reference symbol mismatch: -after transform: ReferenceId(7): Some("Name") -rebuilt : ReferenceId(8): Some("Name") - -* redeclarations/input.ts -Scope children mismatch: -after transform: ScopeId(0): [ScopeId(1), ScopeId(2)] -rebuilt : ScopeId(0): [] -Symbol flags mismatch: -after transform: SymbolId(0): SymbolFlags(BlockScopedVariable | ConstVariable | Export | Import) -rebuilt : SymbolId(0): SymbolFlags(BlockScopedVariable | ConstVariable | Export) -Symbol span mismatch: -after transform: SymbolId(0): Span { start: 57, end: 58 } -rebuilt : SymbolId(0): Span { start: 79, end: 83 } -Symbol reference IDs mismatch: -after transform: SymbolId(0): [ReferenceId(0), ReferenceId(1)] -rebuilt : SymbolId(0): [ReferenceId(0)] -Symbol redeclarations mismatch: -after transform: SymbolId(0): [Span { start: 79, end: 83 }] -rebuilt : SymbolId(0): [] -Symbol flags mismatch: -after transform: SymbolId(1): SymbolFlags(Export | Import | TypeAlias) -rebuilt : SymbolId(1): SymbolFlags(Export | Import) -Symbol redeclarations mismatch: -after transform: SymbolId(1): [Span { start: 170, end: 171 }] -rebuilt : SymbolId(1): [] -Symbol flags mismatch: -after transform: SymbolId(2): SymbolFlags(BlockScopedVariable | ConstVariable | Export | Import | TypeAlias) -rebuilt : SymbolId(2): SymbolFlags(BlockScopedVariable | ConstVariable | Export) -Symbol span mismatch: -after transform: SymbolId(2): Span { start: 267, end: 268 } -rebuilt : SymbolId(2): Span { start: 289, end: 293 } -Symbol reference IDs mismatch: -after transform: SymbolId(2): [ReferenceId(3), ReferenceId(4)] -rebuilt : SymbolId(2): [ReferenceId(2)] -Symbol redeclarations mismatch: -after transform: SymbolId(2): [Span { start: 289, end: 293 }, Span { start: 304, end: 305 }] -rebuilt : SymbolId(2): [] - -* ts-declaration-empty-output/input.d.ts -x Output mismatch - - -# babel-plugin-transform-react-jsx (6/27) -* refresh/can-handle-implicit-arrow-returns/input.jsx -Symbol reference IDs mismatch: -after transform: SymbolId(9): [ReferenceId(23), ReferenceId(24), ReferenceId(25)] -rebuilt : SymbolId(0): [ReferenceId(6), ReferenceId(7)] -Symbol reference IDs mismatch: -after transform: SymbolId(10): [ReferenceId(26), ReferenceId(27), ReferenceId(29)] -rebuilt : SymbolId(1): [ReferenceId(10), ReferenceId(13)] -Symbol reference IDs mismatch: -after transform: SymbolId(11): [ReferenceId(30), ReferenceId(31), ReferenceId(32)] -rebuilt : SymbolId(2): [ReferenceId(18), ReferenceId(19)] -Symbol reference IDs mismatch: -after transform: SymbolId(12): [ReferenceId(33), ReferenceId(34), ReferenceId(36)] -rebuilt : SymbolId(3): [ReferenceId(22), ReferenceId(25)] -Symbol reference IDs mismatch: -after transform: SymbolId(13): [ReferenceId(37), ReferenceId(38), ReferenceId(39), ReferenceId(40)] -rebuilt : SymbolId(4): [ReferenceId(29), ReferenceId(32), ReferenceId(33)] -Symbol reference IDs mismatch: -after transform: SymbolId(14): [ReferenceId(41), ReferenceId(42), ReferenceId(44)] -rebuilt : SymbolId(5): [ReferenceId(38), ReferenceId(41)] -Symbol reference IDs mismatch: -after transform: SymbolId(4): [ReferenceId(14), ReferenceId(45), ReferenceId(46)] -rebuilt : SymbolId(10): [ReferenceId(15), ReferenceId(46)] -Symbol reference IDs mismatch: -after transform: SymbolId(5): [ReferenceId(16), ReferenceId(47), ReferenceId(48)] -rebuilt : SymbolId(11): [ReferenceId(27), ReferenceId(48)] -Symbol reference IDs mismatch: -after transform: SymbolId(6): [ReferenceId(18), ReferenceId(49), ReferenceId(50)] -rebuilt : SymbolId(12): [ReferenceId(31), ReferenceId(50)] -Symbol reference IDs mismatch: -after transform: SymbolId(7): [ReferenceId(19), ReferenceId(51), ReferenceId(52)] -rebuilt : SymbolId(13): [ReferenceId(36), ReferenceId(52)] -Symbol reference IDs mismatch: -after transform: SymbolId(8): [ReferenceId(21), ReferenceId(53), ReferenceId(54)] -rebuilt : SymbolId(14): [ReferenceId(43), ReferenceId(54)] -Reference symbol mismatch: -after transform: ReferenceId(23): Some("_s") -rebuilt : ReferenceId(0): None -Reference symbol mismatch: -after transform: ReferenceId(26): Some("_s2") -rebuilt : ReferenceId(1): None -Reference symbol mismatch: -after transform: ReferenceId(30): Some("_s3") -rebuilt : ReferenceId(2): None -Reference symbol mismatch: -after transform: ReferenceId(33): Some("_s4") -rebuilt : ReferenceId(3): None -Reference symbol mismatch: -after transform: ReferenceId(37): Some("_s5") -rebuilt : ReferenceId(4): None -Reference symbol mismatch: -after transform: ReferenceId(41): Some("_s6") -rebuilt : ReferenceId(5): None -Reference flags mismatch: -after transform: ReferenceId(18): ReferenceFlags(Write) -rebuilt : ReferenceId(31): ReferenceFlags(Read | Write) -Reference symbol mismatch: -after transform: ReferenceId(45): Some("_c") -rebuilt : ReferenceId(45): None -Reference symbol mismatch: -after transform: ReferenceId(47): Some("_c2") -rebuilt : ReferenceId(47): None -Reference symbol mismatch: -after transform: ReferenceId(49): Some("_c3") -rebuilt : ReferenceId(49): None -Reference symbol mismatch: -after transform: ReferenceId(51): Some("_c4") -rebuilt : ReferenceId(51): None -Reference symbol mismatch: -after transform: ReferenceId(53): Some("_c5") -rebuilt : ReferenceId(53): None -Unresolved references mismatch: -after transform: ["X", "memo", "module", "useContext"] -rebuilt : ["$RefreshReg$", "$RefreshSig$", "X", "memo", "module", "useContext"] - -* refresh/does-not-consider-require-like-methods-to-be-hocs/input.jsx -Symbol reference IDs mismatch: -after transform: SymbolId(5): [ReferenceId(10), ReferenceId(17), ReferenceId(18)] -rebuilt : SymbolId(7): [ReferenceId(15), ReferenceId(18)] -Reference symbol mismatch: -after transform: ReferenceId(17): Some("_c") -rebuilt : ReferenceId(17): None -Unresolved references mismatch: -after transform: ["foo", "gk", "require", "requireCond"] -rebuilt : ["$RefreshReg$", "foo", "gk", "require", "requireCond"] - -* refresh/does-not-get-tripped-by-iifes/input.jsx -Bindings mismatch: -after transform: ScopeId(0): [] -rebuilt : ScopeId(0): ["_s"] -Bindings mismatch: -after transform: ScopeId(1): ["_s"] -rebuilt : ScopeId(1): [] -Symbol scope ID mismatch: -after transform: SymbolId(1): ScopeId(1) -rebuilt : SymbolId(0): ScopeId(0) -Symbol reference IDs mismatch: -after transform: SymbolId(1): [ReferenceId(3), ReferenceId(4), ReferenceId(5)] -rebuilt : SymbolId(0): [ReferenceId(2), ReferenceId(3)] -Reference symbol mismatch: -after transform: ReferenceId(3): Some("_s") -rebuilt : ReferenceId(1): None -Unresolved references mismatch: -after transform: ["item", "useFoo"] -rebuilt : ["$RefreshSig$", "item", "useFoo"] - -* refresh/generates-signatures-for-function-declarations-calling-hooks/input.jsx -Symbol reference IDs mismatch: -after transform: SymbolId(5): [ReferenceId(6), ReferenceId(7), ReferenceId(9)] -rebuilt : SymbolId(1): [ReferenceId(1), ReferenceId(6)] -Symbol reference IDs mismatch: -after transform: SymbolId(3): [ReferenceId(3), ReferenceId(10), ReferenceId(11)] -rebuilt : SymbolId(5): [ReferenceId(8), ReferenceId(11)] -Reference symbol mismatch: -after transform: ReferenceId(6): Some("_s") -rebuilt : ReferenceId(0): None -Reference symbol mismatch: -after transform: ReferenceId(10): Some("_c") -rebuilt : ReferenceId(10): None -Unresolved references mismatch: -after transform: ["React", "useState"] -rebuilt : ["$RefreshReg$", "$RefreshSig$", "React", "useState"] - -* refresh/generates-signatures-for-function-expressions-calling-hooks/input.jsx -Symbol reference IDs mismatch: -after transform: SymbolId(22): [ReferenceId(26), ReferenceId(27), ReferenceId(28), ReferenceId(29), ReferenceId(30)] -rebuilt : SymbolId(1): [ReferenceId(2), ReferenceId(5), ReferenceId(8), ReferenceId(9)] -Symbol reference IDs mismatch: -after transform: SymbolId(23): [ReferenceId(32), ReferenceId(33), ReferenceId(34), ReferenceId(35), ReferenceId(36)] -rebuilt : SymbolId(2): [ReferenceId(17), ReferenceId(20), ReferenceId(23), ReferenceId(24)] -Symbol reference IDs mismatch: -after transform: SymbolId(24): [ReferenceId(38), ReferenceId(39), ReferenceId(40)] -rebuilt : SymbolId(14): [ReferenceId(33), ReferenceId(34)] -Symbol reference IDs mismatch: -after transform: SymbolId(15): [ReferenceId(17), ReferenceId(41), ReferenceId(42)] -rebuilt : SymbolId(19): [ReferenceId(7), ReferenceId(42)] -Symbol reference IDs mismatch: -after transform: SymbolId(16): [ReferenceId(18), ReferenceId(43), ReferenceId(44)] -rebuilt : SymbolId(20): [ReferenceId(4), ReferenceId(44)] -Symbol reference IDs mismatch: -after transform: SymbolId(17): [ReferenceId(19), ReferenceId(45), ReferenceId(46)] -rebuilt : SymbolId(21): [ReferenceId(15), ReferenceId(46)] -Symbol reference IDs mismatch: -after transform: SymbolId(18): [ReferenceId(21), ReferenceId(47), ReferenceId(48)] -rebuilt : SymbolId(22): [ReferenceId(22), ReferenceId(48)] -Symbol reference IDs mismatch: -after transform: SymbolId(19): [ReferenceId(22), ReferenceId(49), ReferenceId(50)] -rebuilt : SymbolId(23): [ReferenceId(19), ReferenceId(50)] -Symbol reference IDs mismatch: -after transform: SymbolId(20): [ReferenceId(23), ReferenceId(51), ReferenceId(52)] -rebuilt : SymbolId(24): [ReferenceId(30), ReferenceId(52)] -Reference symbol mismatch: -after transform: ReferenceId(26): Some("_s") -rebuilt : ReferenceId(0): None -Reference symbol mismatch: -after transform: ReferenceId(32): Some("_s2") -rebuilt : ReferenceId(1): None -Reference flags mismatch: -after transform: ReferenceId(18): ReferenceFlags(Write) -rebuilt : ReferenceId(4): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(17): ReferenceFlags(Write) -rebuilt : ReferenceId(7): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(22): ReferenceFlags(Write) -rebuilt : ReferenceId(19): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(21): ReferenceFlags(Write) -rebuilt : ReferenceId(22): ReferenceFlags(Read | Write) -Reference symbol mismatch: -after transform: ReferenceId(38): Some("_s3") -rebuilt : ReferenceId(32): None -Reference symbol mismatch: -after transform: ReferenceId(41): Some("_c") -rebuilt : ReferenceId(41): None -Reference symbol mismatch: -after transform: ReferenceId(43): Some("_c2") -rebuilt : ReferenceId(43): None -Reference symbol mismatch: -after transform: ReferenceId(45): Some("_c3") -rebuilt : ReferenceId(45): None -Reference symbol mismatch: -after transform: ReferenceId(47): Some("_c4") -rebuilt : ReferenceId(47): None -Reference symbol mismatch: -after transform: ReferenceId(49): Some("_c5") -rebuilt : ReferenceId(49): None -Reference symbol mismatch: -after transform: ReferenceId(51): Some("_c6") -rebuilt : ReferenceId(51): None -Unresolved references mismatch: -after transform: ["React", "ref", "useState"] -rebuilt : ["$RefreshReg$", "$RefreshSig$", "React", "ref", "useState"] - -* refresh/generates-valid-signature-for-exotic-ways-to-call-hooks/input.jsx -Missing ScopeId -Scope children mismatch: -after transform: ScopeId(0): [ScopeId(1)] -rebuilt : ScopeId(0): [ScopeId(1), ScopeId(3)] -Symbol reference IDs mismatch: -after transform: SymbolId(10): [ReferenceId(17), ReferenceId(18), ReferenceId(20)] -rebuilt : SymbolId(0): [ReferenceId(1), ReferenceId(16)] -Symbol reference IDs mismatch: -after transform: SymbolId(8): [ReferenceId(11), ReferenceId(12), ReferenceId(14)] -rebuilt : SymbolId(4): [ReferenceId(3), ReferenceId(7)] -Symbol reference IDs mismatch: -after transform: SymbolId(7): [ReferenceId(9), ReferenceId(21), ReferenceId(22)] -rebuilt : SymbolId(10): [ReferenceId(19), ReferenceId(22)] -Reference symbol mismatch: -after transform: ReferenceId(17): Some("_s2") -rebuilt : ReferenceId(0): None -Reference symbol mismatch: -after transform: ReferenceId(11): Some("_s") -rebuilt : ReferenceId(2): None -Reference symbol mismatch: -after transform: ReferenceId(21): Some("_c") -rebuilt : ReferenceId(21): None -Unresolved references mismatch: -after transform: ["React", "useFancyEffect", "useThePlatform"] -rebuilt : ["$RefreshReg$", "$RefreshSig$", "React", "useFancyEffect", "useThePlatform"] - -* refresh/includes-custom-hooks-into-the-signatures/input.jsx -Missing ScopeId -Missing ScopeId -Scope children mismatch: -after transform: ScopeId(0): [ScopeId(1), ScopeId(2), ScopeId(4)] -rebuilt : ScopeId(0): [ScopeId(1), ScopeId(2), ScopeId(3), ScopeId(5), ScopeId(6)] -Symbol reference IDs mismatch: -after transform: SymbolId(7): [ReferenceId(9), ReferenceId(10), ReferenceId(12)] -rebuilt : SymbolId(1): [ReferenceId(3), ReferenceId(7)] -Symbol reference IDs mismatch: -after transform: SymbolId(8): [ReferenceId(13), ReferenceId(14), ReferenceId(16)] -rebuilt : SymbolId(2): [ReferenceId(10), ReferenceId(12)] -Symbol reference IDs mismatch: -after transform: SymbolId(10): [ReferenceId(19), ReferenceId(20), ReferenceId(22)] -rebuilt : SymbolId(3): [ReferenceId(14), ReferenceId(18)] -Symbol reference IDs mismatch: -after transform: SymbolId(6): [ReferenceId(6), ReferenceId(23), ReferenceId(24)] -rebuilt : SymbolId(10): [ReferenceId(21), ReferenceId(24)] -Reference symbol mismatch: -after transform: ReferenceId(9): Some("_s") -rebuilt : ReferenceId(0): None -Reference symbol mismatch: -after transform: ReferenceId(13): Some("_s2") -rebuilt : ReferenceId(1): None -Reference symbol mismatch: -after transform: ReferenceId(19): Some("_s3") -rebuilt : ReferenceId(2): None -Reference symbol mismatch: -after transform: ReferenceId(23): Some("_c") -rebuilt : ReferenceId(23): None -Unresolved references mismatch: -after transform: ["React"] -rebuilt : ["$RefreshReg$", "$RefreshSig$", "React"] - -* refresh/registers-capitalized-identifiers-in-hoc-calls/input.jsx -Symbol reference IDs mismatch: -after transform: SymbolId(3): [ReferenceId(6), ReferenceId(14), ReferenceId(15)] -rebuilt : SymbolId(4): [ReferenceId(1), ReferenceId(15)] -Symbol reference IDs mismatch: -after transform: SymbolId(4): [ReferenceId(8), ReferenceId(16), ReferenceId(17)] -rebuilt : SymbolId(5): [ReferenceId(3), ReferenceId(17)] -Symbol reference IDs mismatch: -after transform: SymbolId(5): [ReferenceId(9), ReferenceId(18), ReferenceId(19)] -rebuilt : SymbolId(6): [ReferenceId(8), ReferenceId(19)] -Symbol reference IDs mismatch: -after transform: SymbolId(6): [ReferenceId(11), ReferenceId(20), ReferenceId(21)] -rebuilt : SymbolId(7): [ReferenceId(12), ReferenceId(21)] -Reference flags mismatch: -after transform: ReferenceId(8): ReferenceFlags(Write) -rebuilt : ReferenceId(3): ReferenceFlags(Read | Write) -Reference symbol mismatch: -after transform: ReferenceId(14): Some("_c") -rebuilt : ReferenceId(14): None -Reference symbol mismatch: -after transform: ReferenceId(16): Some("_c2") -rebuilt : ReferenceId(16): None -Reference symbol mismatch: -after transform: ReferenceId(18): Some("_c3") -rebuilt : ReferenceId(18): None -Reference symbol mismatch: -after transform: ReferenceId(20): Some("_c4") -rebuilt : ReferenceId(20): None -Unresolved references mismatch: -after transform: ["hoc"] -rebuilt : ["$RefreshReg$", "hoc"] - -* refresh/registers-identifiers-used-in-jsx-at-definition-site/input.jsx -x Output mismatch - -* refresh/registers-identifiers-used-in-react-create-element-at-definition-site/input.jsx -x Output mismatch - -* refresh/registers-likely-hocs-with-inline-functions-1/input.jsx -Symbol reference IDs mismatch: -after transform: SymbolId(4): [ReferenceId(5), ReferenceId(18), ReferenceId(19)] -rebuilt : SymbolId(5): [ReferenceId(1), ReferenceId(19)] -Symbol reference IDs mismatch: -after transform: SymbolId(5): [ReferenceId(6), ReferenceId(20), ReferenceId(21)] -rebuilt : SymbolId(6): [ReferenceId(3), ReferenceId(21)] -Symbol reference IDs mismatch: -after transform: SymbolId(6): [ReferenceId(8), ReferenceId(22), ReferenceId(23)] -rebuilt : SymbolId(7): [ReferenceId(8), ReferenceId(23)] -Symbol reference IDs mismatch: -after transform: SymbolId(7): [ReferenceId(9), ReferenceId(24), ReferenceId(25)] -rebuilt : SymbolId(8): [ReferenceId(6), ReferenceId(25)] -Symbol reference IDs mismatch: -after transform: SymbolId(8): [ReferenceId(10), ReferenceId(26), ReferenceId(27)] -rebuilt : SymbolId(9): [ReferenceId(10), ReferenceId(27)] -Symbol reference IDs mismatch: -after transform: SymbolId(9): [ReferenceId(12), ReferenceId(28), ReferenceId(29)] -rebuilt : SymbolId(10): [ReferenceId(16), ReferenceId(29)] -Symbol reference IDs mismatch: -after transform: SymbolId(10): [ReferenceId(13), ReferenceId(30), ReferenceId(31)] -rebuilt : SymbolId(11): [ReferenceId(14), ReferenceId(31)] -Symbol reference IDs mismatch: -after transform: SymbolId(11): [ReferenceId(14), ReferenceId(32), ReferenceId(33)] -rebuilt : SymbolId(12): [ReferenceId(12), ReferenceId(33)] -Reference flags mismatch: -after transform: ReferenceId(5): ReferenceFlags(Write) -rebuilt : ReferenceId(1): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(9): ReferenceFlags(Write) -rebuilt : ReferenceId(6): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(8): ReferenceFlags(Write) -rebuilt : ReferenceId(8): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(14): ReferenceFlags(Write) -rebuilt : ReferenceId(12): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(13): ReferenceFlags(Write) -rebuilt : ReferenceId(14): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(12): ReferenceFlags(Write) -rebuilt : ReferenceId(16): ReferenceFlags(Read | Write) -Reference symbol mismatch: -after transform: ReferenceId(18): Some("_c") -rebuilt : ReferenceId(18): None -Reference symbol mismatch: -after transform: ReferenceId(20): Some("_c2") -rebuilt : ReferenceId(20): None -Reference symbol mismatch: -after transform: ReferenceId(22): Some("_c3") -rebuilt : ReferenceId(22): None -Reference symbol mismatch: -after transform: ReferenceId(24): Some("_c4") -rebuilt : ReferenceId(24): None -Reference symbol mismatch: -after transform: ReferenceId(26): Some("_c5") -rebuilt : ReferenceId(26): None -Reference symbol mismatch: -after transform: ReferenceId(28): Some("_c6") -rebuilt : ReferenceId(28): None -Reference symbol mismatch: -after transform: ReferenceId(30): Some("_c7") -rebuilt : ReferenceId(30): None -Reference symbol mismatch: -after transform: ReferenceId(32): Some("_c8") -rebuilt : ReferenceId(32): None -Unresolved references mismatch: -after transform: ["React", "forwardRef", "memo"] -rebuilt : ["$RefreshReg$", "React", "forwardRef", "memo"] - -* refresh/registers-likely-hocs-with-inline-functions-2/input.jsx -Symbol reference IDs mismatch: -after transform: SymbolId(2): [ReferenceId(2), ReferenceId(6), ReferenceId(7)] -rebuilt : SymbolId(3): [ReferenceId(4), ReferenceId(7)] -Symbol reference IDs mismatch: -after transform: SymbolId(3): [ReferenceId(3), ReferenceId(8), ReferenceId(9)] -rebuilt : SymbolId(4): [ReferenceId(2), ReferenceId(9)] -Symbol reference IDs mismatch: -after transform: SymbolId(4): [ReferenceId(4), ReferenceId(10), ReferenceId(11)] -rebuilt : SymbolId(5): [ReferenceId(0), ReferenceId(11)] -Reference flags mismatch: -after transform: ReferenceId(4): ReferenceFlags(Write) -rebuilt : ReferenceId(0): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(3): ReferenceFlags(Write) -rebuilt : ReferenceId(2): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(2): ReferenceFlags(Write) -rebuilt : ReferenceId(4): ReferenceFlags(Read | Write) -Reference symbol mismatch: -after transform: ReferenceId(6): Some("_c") -rebuilt : ReferenceId(6): None -Reference symbol mismatch: -after transform: ReferenceId(8): Some("_c2") -rebuilt : ReferenceId(8): None -Reference symbol mismatch: -after transform: ReferenceId(10): Some("_c3") -rebuilt : ReferenceId(10): None -Unresolved references mismatch: -after transform: ["React", "forwardRef"] -rebuilt : ["$RefreshReg$", "React", "forwardRef"] - -* refresh/registers-likely-hocs-with-inline-functions-3/input.jsx -Symbol reference IDs mismatch: -after transform: SymbolId(3): [ReferenceId(2), ReferenceId(6), ReferenceId(7)] -rebuilt : SymbolId(4): [ReferenceId(4), ReferenceId(7)] -Symbol reference IDs mismatch: -after transform: SymbolId(4): [ReferenceId(3), ReferenceId(8), ReferenceId(9)] -rebuilt : SymbolId(5): [ReferenceId(2), ReferenceId(9)] -Symbol reference IDs mismatch: -after transform: SymbolId(5): [ReferenceId(4), ReferenceId(10), ReferenceId(11)] -rebuilt : SymbolId(6): [ReferenceId(0), ReferenceId(11)] -Reference flags mismatch: -after transform: ReferenceId(4): ReferenceFlags(Write) -rebuilt : ReferenceId(0): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(3): ReferenceFlags(Write) -rebuilt : ReferenceId(2): ReferenceFlags(Read | Write) -Reference flags mismatch: -after transform: ReferenceId(2): ReferenceFlags(Write) -rebuilt : ReferenceId(4): ReferenceFlags(Read | Write) -Reference symbol mismatch: -after transform: ReferenceId(6): Some("_c") -rebuilt : ReferenceId(6): None -Reference symbol mismatch: -after transform: ReferenceId(8): Some("_c2") -rebuilt : ReferenceId(8): None -Reference symbol mismatch: -after transform: ReferenceId(10): Some("_c3") -rebuilt : ReferenceId(10): None -Unresolved references mismatch: -after transform: ["React", "forwardRef"] -rebuilt : ["$RefreshReg$", "React", "forwardRef"] - -* refresh/registers-top-level-exported-function-declarations/input.jsx -Symbol reference IDs mismatch: -after transform: SymbolId(7): [ReferenceId(4), ReferenceId(13), ReferenceId(14)] -rebuilt : SymbolId(8): [ReferenceId(2), ReferenceId(14)] -Symbol reference IDs mismatch: -after transform: SymbolId(8): [ReferenceId(6), ReferenceId(15), ReferenceId(16)] -rebuilt : SymbolId(9): [ReferenceId(6), ReferenceId(16)] -Symbol reference IDs mismatch: -after transform: SymbolId(9): [ReferenceId(8), ReferenceId(17), ReferenceId(18)] -rebuilt : SymbolId(10): [ReferenceId(9), ReferenceId(18)] -Reference symbol mismatch: -after transform: ReferenceId(13): Some("_c") -rebuilt : ReferenceId(13): None -Reference symbol mismatch: -after transform: ReferenceId(15): Some("_c2") -rebuilt : ReferenceId(15): None -Reference symbol mismatch: -after transform: ReferenceId(17): Some("_c3") -rebuilt : ReferenceId(17): None -Unresolved references mismatch: -after transform: [] -rebuilt : ["$RefreshReg$"] - -* refresh/registers-top-level-exported-named-arrow-functions/input.jsx -Symbol reference IDs mismatch: -after transform: SymbolId(4): [ReferenceId(3), ReferenceId(10), ReferenceId(11)] -rebuilt : SymbolId(5): [ReferenceId(2), ReferenceId(11)] -Symbol reference IDs mismatch: -after transform: SymbolId(5): [ReferenceId(5), ReferenceId(12), ReferenceId(13)] -rebuilt : SymbolId(6): [ReferenceId(6), ReferenceId(13)] -Reference symbol mismatch: -after transform: ReferenceId(10): Some("_c") -rebuilt : ReferenceId(10): None -Reference symbol mismatch: -after transform: ReferenceId(12): Some("_c2") -rebuilt : ReferenceId(12): None -Unresolved references mismatch: -after transform: [] -rebuilt : ["$RefreshReg$"] - -* refresh/registers-top-level-function-declarations/input.jsx -Symbol reference IDs mismatch: -after transform: SymbolId(3): [ReferenceId(2), ReferenceId(8), ReferenceId(9)] -rebuilt : SymbolId(4): [ReferenceId(2), ReferenceId(9)] -Symbol reference IDs mismatch: -after transform: SymbolId(4): [ReferenceId(4), ReferenceId(10), ReferenceId(11)] -rebuilt : SymbolId(5): [ReferenceId(6), ReferenceId(11)] -Reference symbol mismatch: -after transform: ReferenceId(8): Some("_c") -rebuilt : ReferenceId(8): None -Reference symbol mismatch: -after transform: ReferenceId(10): Some("_c2") -rebuilt : ReferenceId(10): None -Unresolved references mismatch: -after transform: [] -rebuilt : ["$RefreshReg$"] - -* refresh/registers-top-level-variable-declarations-with-arrow-functions/input.jsx -Symbol reference IDs mismatch: -after transform: SymbolId(5): [ReferenceId(2), ReferenceId(11), ReferenceId(12)] -rebuilt : SymbolId(6): [ReferenceId(2), ReferenceId(12)] -Symbol reference IDs mismatch: -after transform: SymbolId(6): [ReferenceId(4), ReferenceId(13), ReferenceId(14)] -rebuilt : SymbolId(7): [ReferenceId(6), ReferenceId(14)] -Symbol reference IDs mismatch: -after transform: SymbolId(7): [ReferenceId(6), ReferenceId(15), ReferenceId(16)] -rebuilt : SymbolId(8): [ReferenceId(9), ReferenceId(16)] -Reference symbol mismatch: -after transform: ReferenceId(11): Some("_c") -rebuilt : ReferenceId(11): None -Reference symbol mismatch: -after transform: ReferenceId(13): Some("_c2") -rebuilt : ReferenceId(13): None -Reference symbol mismatch: -after transform: ReferenceId(15): Some("_c3") -rebuilt : ReferenceId(15): None -Unresolved references mismatch: -after transform: [] -rebuilt : ["$RefreshReg$"] - -* refresh/registers-top-level-variable-declarations-with-function-expressions/input.jsx -Symbol reference IDs mismatch: -after transform: SymbolId(7): [ReferenceId(2), ReferenceId(8), ReferenceId(9)] -rebuilt : SymbolId(8): [ReferenceId(2), ReferenceId(9)] -Symbol reference IDs mismatch: -after transform: SymbolId(8): [ReferenceId(4), ReferenceId(10), ReferenceId(11)] -rebuilt : SymbolId(9): [ReferenceId(6), ReferenceId(11)] -Reference symbol mismatch: -after transform: ReferenceId(8): Some("_c") -rebuilt : ReferenceId(8): None -Reference symbol mismatch: -after transform: ReferenceId(10): Some("_c2") -rebuilt : ReferenceId(10): None -Unresolved references mismatch: -after transform: [] -rebuilt : ["$RefreshReg$"] - -* refresh/supports-typescript-namespace-syntax/input.tsx -x Output mismatch - -* refresh/uses-custom-identifiers-for-refresh-reg-and-refresh-sig/input.jsx -Symbol reference IDs mismatch: -after transform: SymbolId(3): [ReferenceId(6), ReferenceId(7), ReferenceId(9)] -rebuilt : SymbolId(1): [ReferenceId(1), ReferenceId(6)] -Symbol reference IDs mismatch: -after transform: SymbolId(1): [ReferenceId(3), ReferenceId(10), ReferenceId(11)] -rebuilt : SymbolId(3): [ReferenceId(8), ReferenceId(11)] -Reference symbol mismatch: -after transform: ReferenceId(6): Some("_s") -rebuilt : ReferenceId(0): None -Reference symbol mismatch: -after transform: ReferenceId(10): Some("_c") -rebuilt : ReferenceId(10): None -Unresolved references mismatch: -after transform: ["Foo", "X", "useContext"] -rebuilt : ["Foo", "X", "import.meta.refreshReg", "import.meta.refreshSig", "useContext"] - -* refresh/uses-original-function-declaration-if-it-get-reassigned/input.jsx -Symbol reference IDs mismatch: -after transform: SymbolId(1): [ReferenceId(3), ReferenceId(6), ReferenceId(7)] -rebuilt : SymbolId(2): [ReferenceId(1), ReferenceId(7)] -Reference symbol mismatch: -after transform: ReferenceId(6): Some("_c") -rebuilt : ReferenceId(6): None -Unresolved references mismatch: -after transform: ["connect"] -rebuilt : ["$RefreshReg$", "connect"] - - -# regexp (6/8) -* all-regex-plugins-enabled-by-targets/input.js -Missing ReferenceId: x1 -Missing ReferenceId: RegExp -Missing ReferenceId: x2 -Missing ReferenceId: RegExp -Missing ReferenceId: a1 -Missing ReferenceId: RegExp -Missing ReferenceId: b1 -Missing ReferenceId: RegExp -Missing ReferenceId: b2 -Missing ReferenceId: RegExp -Missing ReferenceId: b3 -Missing ReferenceId: RegExp -Missing ReferenceId: b4 -Missing ReferenceId: RegExp -Missing ReferenceId: c1 -Missing ReferenceId: RegExp -Missing ReferenceId: c2 -Missing ReferenceId: RegExp -Missing ReferenceId: d1 -Missing ReferenceId: RegExp -Missing ReferenceId: f1 -Missing ReferenceId: RegExp -Missing ReferenceId: g1 -Missing ReferenceId: RegExp -Unresolved reference IDs mismatch for "c1": -after transform: [ReferenceId(7)] -rebuilt : [ReferenceId(14)] -Unresolved reference IDs mismatch for "b4": -after transform: [ReferenceId(6)] -rebuilt : [ReferenceId(12)] -Unresolved reference IDs mismatch for "b1": -after transform: [ReferenceId(3)] -rebuilt : [ReferenceId(6)] -Unresolved reference IDs mismatch for "b3": -after transform: [ReferenceId(5)] -rebuilt : [ReferenceId(10)] -Unresolved reference IDs mismatch for "c2": -after transform: [ReferenceId(8)] -rebuilt : [ReferenceId(16)] -Unresolved reference IDs mismatch for "g1": -after transform: [ReferenceId(11)] -rebuilt : [ReferenceId(22)] -Unresolved reference IDs mismatch for "b2": -after transform: [ReferenceId(4)] -rebuilt : [ReferenceId(8)] -Unresolved reference IDs mismatch for "RegExp": -after transform: [ReferenceId(12), ReferenceId(13), ReferenceId(14), ReferenceId(15), ReferenceId(16), ReferenceId(17), ReferenceId(18), ReferenceId(19), ReferenceId(20), ReferenceId(21), ReferenceId(22), ReferenceId(23)] -rebuilt : [ReferenceId(1), ReferenceId(3), ReferenceId(5), ReferenceId(7), ReferenceId(9), ReferenceId(11), ReferenceId(13), ReferenceId(15), ReferenceId(17), ReferenceId(19), ReferenceId(21), ReferenceId(23)] -Unresolved reference IDs mismatch for "f1": -after transform: [ReferenceId(10)] -rebuilt : [ReferenceId(20)] -Unresolved reference IDs mismatch for "a1": -after transform: [ReferenceId(2)] -rebuilt : [ReferenceId(4)] -Unresolved reference IDs mismatch for "d1": -after transform: [ReferenceId(9)] -rebuilt : [ReferenceId(18)] -Unresolved reference IDs mismatch for "x1": -after transform: [ReferenceId(0)] -rebuilt : [ReferenceId(0)] -Unresolved reference IDs mismatch for "x2": -after transform: [ReferenceId(1)] -rebuilt : [ReferenceId(2)] - -* igm/input.js -Missing ReferenceId: a1 -Unresolved reference IDs mismatch for "a1": -after transform: [ReferenceId(0)] -rebuilt : [ReferenceId(0)] - - From 8dbf73b73254e4f3c0b1fc83392c581ff3b1ab50 Mon Sep 17 00:00:00 2001 From: Ethan Goh <7086cmd@gmail.com> Date: Mon, 23 Sep 2024 16:08:04 +0800 Subject: [PATCH 10/25] perf: avoid cloning. --- .../src/es2017/async_to_generator.rs | 56 +++++++++++++------ crates/oxc_transformer/src/lib.rs | 1 + 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/crates/oxc_transformer/src/es2017/async_to_generator.rs b/crates/oxc_transformer/src/es2017/async_to_generator.rs index a4ff6955db531..601dc7e015b52 100644 --- a/crates/oxc_transformer/src/es2017/async_to_generator.rs +++ b/crates/oxc_transformer/src/es2017/async_to_generator.rs @@ -41,9 +41,7 @@ use crate::context::Ctx; use oxc_allocator::CloneIn; -use oxc_ast::ast::{ - ArrowFunctionExpression, Expression, FormalParameterKind, Function, Statement, YieldExpression, -}; +use oxc_ast::ast::{ArrowFunctionExpression, Expression, FormalParameterKind, Function, FunctionType, Statement, YieldExpression}; use oxc_ast::NONE; use oxc_span::{Atom, SPAN}; use oxc_syntax::reference::ReferenceFlags; @@ -96,15 +94,24 @@ impl<'a> Traverse<'a> for AsyncToGenerator<'a> { fn exit_function(&mut self, func: &mut Function<'a>, ctx: &mut TraverseCtx<'a>) { let babel_helpers_id = ctx.scopes().find_binding(ctx.current_scope_id(), "babelHelpers"); let callee = Self::get_helper_callee(babel_helpers_id, ctx); - let mut target = func.clone_in(ctx.ast.allocator); - target.r#async = false; - target.generator = true; - target.params = ctx.ast.alloc(ctx.ast.formal_parameters( + let target = ctx.ast.function( + func.r#type.clone(), SPAN, - FormalParameterKind::FormalParameter, - ctx.ast.vec(), - NONE, - )); + func.id.clone(), + true, + false, + false, + func.type_parameters.take(), + func.this_param.take(), + ctx.ast.alloc(ctx.ast.formal_parameters( + SPAN, + FormalParameterKind::FormalParameter, + ctx.ast.vec(), + NONE, + )), + func.return_type.take(), + func.body.take() + ); let parameters = { let mut items = ctx.ast.vec(); items.push(ctx.ast.argument_expression(ctx.ast.expression_this(SPAN))); @@ -117,6 +124,7 @@ impl<'a> Traverse<'a> for AsyncToGenerator<'a> { let body = Statement::ReturnStatement(ctx.ast.alloc(returns)); let body = ctx.ast.function_body(SPAN, ctx.ast.vec(), ctx.ast.vec1(body)); let body = ctx.ast.alloc(body); + func.r#async = false; func.body = Some(body); } @@ -127,19 +135,30 @@ impl<'a> Traverse<'a> for AsyncToGenerator<'a> { ) { let babel_helpers_id = ctx.scopes().find_binding(ctx.current_scope_id(), "babelHelpers"); let callee = Self::get_helper_callee(babel_helpers_id, ctx); - let mut target = arrow.clone_in(ctx.ast.allocator); - target.r#async = false; - target.params = ctx.ast.alloc(ctx.ast.formal_parameters( + let body = ctx.ast.function_body(SPAN, ctx.ast.move_vec(&mut arrow.body.directives), ctx.ast.move_vec(&mut arrow.body.statements)); + let target = ctx.ast.function( + FunctionType::FunctionExpression, SPAN, - FormalParameterKind::FormalParameter, - ctx.ast.vec(), + None, + true, + false, + false, + arrow.type_parameters.take(), NONE, - )); + ctx.ast.alloc(ctx.ast.formal_parameters( + SPAN, + FormalParameterKind::FormalParameter, + ctx.ast.vec(), + NONE, + )), + arrow.return_type.take(), + Some(body) + ); let parameters = { let mut items = ctx.ast.vec(); items.push(ctx.ast.argument_expression(ctx.ast.expression_this(SPAN))); items.push(ctx.ast.argument_expression(ctx.ast.expression_null_literal(SPAN))); - items.push(ctx.ast.argument_expression(ctx.ast.expression_from_arrow_function(target))); + items.push(ctx.ast.argument_expression(ctx.ast.expression_from_function(target))); items }; let call = ctx.ast.expression_call(SPAN, callee, NONE, parameters, false); @@ -147,5 +166,6 @@ impl<'a> Traverse<'a> for AsyncToGenerator<'a> { let body = Statement::ReturnStatement(ctx.ast.alloc(returns)); let body = ctx.ast.function_body(SPAN, ctx.ast.vec(), ctx.ast.vec1(body)); arrow.body = ctx.ast.alloc(body); + arrow.r#async = false; } } diff --git a/crates/oxc_transformer/src/lib.rs b/crates/oxc_transformer/src/lib.rs index f5f4ad64abf6e..4b9c1e3c89b12 100644 --- a/crates/oxc_transformer/src/lib.rs +++ b/crates/oxc_transformer/src/lib.rs @@ -330,6 +330,7 @@ impl<'a, 'ctx> Traverse<'a> for TransformerImpl<'a, 'ctx> { .push(ctx.ast.statement_return(SPAN, Some(statement.unbox().expression))); arrow.expression = false; } + self.x2_es2017.exit_arrow_function_expression(arrow, ctx); } fn exit_statements(&mut self, stmts: &mut Vec<'a, Statement<'a>>, ctx: &mut TraverseCtx<'a>) { From 11a401356d113deb7d3830102875124ce541198a Mon Sep 17 00:00:00 2001 From: Ethan Goh <7086cmd@gmail.com> Date: Tue, 24 Sep 2024 12:53:33 +0800 Subject: [PATCH 11/25] perf: avoid cloning in expression. --- .../src/es2017/async_to_generator.rs | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/crates/oxc_transformer/src/es2017/async_to_generator.rs b/crates/oxc_transformer/src/es2017/async_to_generator.rs index 601dc7e015b52..745270685c156 100644 --- a/crates/oxc_transformer/src/es2017/async_to_generator.rs +++ b/crates/oxc_transformer/src/es2017/async_to_generator.rs @@ -73,17 +73,21 @@ impl<'a> AsyncToGenerator<'a> { impl<'a> Traverse<'a> for AsyncToGenerator<'a> { fn exit_expression(&mut self, expr: &mut Expression<'a>, ctx: &mut TraverseCtx<'a>) { if let Expression::AwaitExpression(await_expr) = expr { - // Do not transform top-level await - if ctx.ancestry.ancestors().any(|ancestor| { - matches!( - ancestor, - Ancestor::FunctionBody(_) | Ancestor::ArrowFunctionExpressionBody(_) - ) - }) { + // Do not transform top-level await, or in async generator functions. + let in_async_function = ctx.ancestry.ancestors().find_map(|ance| { + if let Ancestor::FunctionBody(body) = ance { + if *body.r#async() { + Some(!body.generator()) + } else { None } + } else if let Ancestor::ArrowFunctionExpressionBody(body) = ance { + Some(true) + } else { None } + }).unwrap_or(false); + if in_async_function { let yield_expression = YieldExpression { span: SPAN, delegate: false, - argument: Some(await_expr.argument.clone_in(ctx.ast.allocator)), + argument: Some(ctx.ast.move_expression(&mut await_expr.argument)), }; let expression = ctx.ast.alloc(yield_expression); *expr = Expression::YieldExpression(expression); From e39f2c62c0f36e528168e71eb23c1f0744597fc4 Mon Sep 17 00:00:00 2001 From: Ethan Goh <7086cmd@gmail.com> Date: Tue, 24 Sep 2024 12:53:41 +0800 Subject: [PATCH 12/25] chore: format. --- .../src/es2017/async_to_generator.rs | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/crates/oxc_transformer/src/es2017/async_to_generator.rs b/crates/oxc_transformer/src/es2017/async_to_generator.rs index 745270685c156..2fde6d802897f 100644 --- a/crates/oxc_transformer/src/es2017/async_to_generator.rs +++ b/crates/oxc_transformer/src/es2017/async_to_generator.rs @@ -74,15 +74,23 @@ impl<'a> Traverse<'a> for AsyncToGenerator<'a> { fn exit_expression(&mut self, expr: &mut Expression<'a>, ctx: &mut TraverseCtx<'a>) { if let Expression::AwaitExpression(await_expr) = expr { // Do not transform top-level await, or in async generator functions. - let in_async_function = ctx.ancestry.ancestors().find_map(|ance| { - if let Ancestor::FunctionBody(body) = ance { - if *body.r#async() { - Some(!body.generator()) - } else { None } - } else if let Ancestor::ArrowFunctionExpressionBody(body) = ance { - Some(true) - } else { None } - }).unwrap_or(false); + let in_async_function = ctx + .ancestry + .ancestors() + .find_map(|ance| { + if let Ancestor::FunctionBody(body) = ance { + if *body.r#async() { + Some(!body.generator()) + } else { + None + } + } else if let Ancestor::ArrowFunctionExpressionBody(body) = ance { + Some(true) + } else { + None + } + }) + .unwrap_or(false); if in_async_function { let yield_expression = YieldExpression { span: SPAN, From facd2e271e99cb4d7cbc566e0514d34533450b28 Mon Sep 17 00:00:00 2001 From: Ethan Goh <7086cmd@gmail.com> Date: Tue, 24 Sep 2024 13:26:56 +0800 Subject: [PATCH 13/25] refactor: align with babel without cloning. --- .../src/es2017/async_to_generator.rs | 161 +++++++++++++----- crates/oxc_transformer/src/es2017/mod.rs | 6 +- crates/oxc_transformer/src/lib.rs | 4 + .../snapshots/babel.snap.md | 23 +-- .../snapshots/babel_exec.snap.md | 19 +-- tasks/transform_conformance/src/constants.rs | 2 +- 6 files changed, 128 insertions(+), 87 deletions(-) diff --git a/crates/oxc_transformer/src/es2017/async_to_generator.rs b/crates/oxc_transformer/src/es2017/async_to_generator.rs index 2fde6d802897f..5f4266c128559 100644 --- a/crates/oxc_transformer/src/es2017/async_to_generator.rs +++ b/crates/oxc_transformer/src/es2017/async_to_generator.rs @@ -40,8 +40,10 @@ //! use crate::context::Ctx; -use oxc_allocator::CloneIn; -use oxc_ast::ast::{ArrowFunctionExpression, Expression, FormalParameterKind, Function, FunctionType, Statement, YieldExpression}; +use oxc_ast::ast::{ + ArrowFunctionExpression, Expression, FormalParameterKind, Function, FunctionType, Statement, + VariableDeclarationKind, YieldExpression, +}; use oxc_ast::NONE; use oxc_span::{Atom, SPAN}; use oxc_syntax::reference::ReferenceFlags; @@ -68,6 +70,65 @@ impl<'a> AsyncToGenerator<'a> { let property = ctx.ast.identifier_name(SPAN, Atom::from("asyncToGenerator")); Expression::from(ctx.ast.member_expression_static(SPAN, object, property, false)) } + + fn transform_function(func: &mut Function<'a>, ctx: &mut TraverseCtx<'a>) -> Function<'a> { + let babel_helpers_id = + ctx.scopes().find_binding(ctx.current_scope_id(), "babelHelpers"); + let callee = Self::get_helper_callee(babel_helpers_id, ctx); + let target = ctx.ast.function( + func.r#type, + SPAN, + None, + true, + false, + false, + func.type_parameters.take(), + func.this_param.take(), + ctx.ast.alloc(ctx.ast.formal_parameters( + SPAN, + FormalParameterKind::FormalParameter, + ctx.ast.vec(), + NONE, + )), + func.return_type.take(), + func.body.take(), + ); + let parameters = + ctx.ast.vec1(ctx.ast.argument_expression(ctx.ast.expression_from_function(target))); + let call = ctx.ast.expression_call(SPAN, callee, NONE, parameters, false); + let call = ctx.ast.expression_member(ctx.ast.member_expression_static( + SPAN, + call, + ctx.ast.identifier_name(SPAN, "apply"), + false + )); + let call = ctx.ast.expression_call(SPAN, call, NONE, { + let mut items = ctx.ast.vec(); + items.push(ctx.ast.argument_expression(ctx.ast.expression_this(SPAN))); + items.push(ctx.ast.argument_expression( + ctx.ast.expression_identifier_reference(SPAN, "arguments"), + )); + items + }, false); + let returns = ctx.ast.return_statement(SPAN, Some(call)); + let body = Statement::ReturnStatement(ctx.ast.alloc(returns)); + let body = ctx.ast.function_body(SPAN, ctx.ast.vec(), ctx.ast.vec1(body)); + let body = ctx.ast.alloc(body); + let params = ctx.ast.formal_parameters(SPAN, func.params.kind, ctx.ast.move_vec(&mut func.params.items), func.params.rest.take()); + ctx.ast.function( + FunctionType::FunctionExpression, + SPAN, + None, + false, + false, + false, + func.type_parameters.take(), + func.this_param.take(), + params, + func.return_type.take(), + Some(body) + ) + } } impl<'a> Traverse<'a> for AsyncToGenerator<'a> { @@ -84,7 +145,7 @@ impl<'a> Traverse<'a> for AsyncToGenerator<'a> { } else { None } - } else if let Ancestor::ArrowFunctionExpressionBody(body) = ance { + } else if let Ancestor::ArrowFunctionExpressionBody(_) = ance { Some(true) } else { None @@ -100,44 +161,38 @@ impl<'a> Traverse<'a> for AsyncToGenerator<'a> { let expression = ctx.ast.alloc(yield_expression); *expr = Expression::YieldExpression(expression); } + } else if let Expression::FunctionExpression(func) = expr { + if !func.r#async || func.generator { return } + let new_function = Self::transform_function(func, ctx); + *expr = ctx.ast.expression_from_function(new_function); } } - fn exit_function(&mut self, func: &mut Function<'a>, ctx: &mut TraverseCtx<'a>) { - let babel_helpers_id = ctx.scopes().find_binding(ctx.current_scope_id(), "babelHelpers"); - let callee = Self::get_helper_callee(babel_helpers_id, ctx); - let target = ctx.ast.function( - func.r#type.clone(), - SPAN, - func.id.clone(), - true, - false, - false, - func.type_parameters.take(), - func.this_param.take(), - ctx.ast.alloc(ctx.ast.formal_parameters( - SPAN, - FormalParameterKind::FormalParameter, - ctx.ast.vec(), - NONE, - )), - func.return_type.take(), - func.body.take() - ); - let parameters = { - let mut items = ctx.ast.vec(); - items.push(ctx.ast.argument_expression(ctx.ast.expression_this(SPAN))); - items.push(ctx.ast.argument_expression(ctx.ast.expression_null_literal(SPAN))); - items.push(ctx.ast.argument_expression(ctx.ast.expression_from_function(target))); - items - }; - let call = ctx.ast.expression_call(SPAN, callee, NONE, parameters, false); - let returns = ctx.ast.return_statement(SPAN, Some(call)); - let body = Statement::ReturnStatement(ctx.ast.alloc(returns)); - let body = ctx.ast.function_body(SPAN, ctx.ast.vec(), ctx.ast.vec1(body)); - let body = ctx.ast.alloc(body); - func.r#async = false; - func.body = Some(body); + fn exit_statement(&mut self, stmt: &mut Statement<'a>, ctx: &mut TraverseCtx<'a>) { + if let Statement::FunctionDeclaration(func) = stmt { + if !func.r#async || func.generator { return } + let new_function = Self::transform_function(func, ctx); + if let Some(id) = func.id.take() { + *stmt = ctx.ast.statement_declaration(ctx.ast.declaration_variable( + SPAN, + VariableDeclarationKind::Const, + ctx.ast.vec1(ctx.ast.variable_declarator( + SPAN, + VariableDeclarationKind::Const, + ctx.ast.binding_pattern( + ctx.ast.binding_pattern_kind_from_binding_identifier(id), + NONE, + false, + ), + Some(ctx.ast.expression_from_function(new_function)), + false, + )), + false, + )); + } else { + *stmt = ctx.ast.statement_declaration(ctx.ast.declaration_from_function(new_function)); + } + } } fn exit_arrow_function_expression( @@ -145,9 +200,16 @@ impl<'a> Traverse<'a> for AsyncToGenerator<'a> { arrow: &mut ArrowFunctionExpression<'a>, ctx: &mut TraverseCtx<'a>, ) { + if !arrow.r#async { + return; + } let babel_helpers_id = ctx.scopes().find_binding(ctx.current_scope_id(), "babelHelpers"); let callee = Self::get_helper_callee(babel_helpers_id, ctx); - let body = ctx.ast.function_body(SPAN, ctx.ast.move_vec(&mut arrow.body.directives), ctx.ast.move_vec(&mut arrow.body.statements)); + let body = ctx.ast.function_body( + SPAN, + ctx.ast.move_vec(&mut arrow.body.directives), + ctx.ast.move_vec(&mut arrow.body.statements), + ); let target = ctx.ast.function( FunctionType::FunctionExpression, SPAN, @@ -164,16 +226,25 @@ impl<'a> Traverse<'a> for AsyncToGenerator<'a> { NONE, )), arrow.return_type.take(), - Some(body) + Some(body), ); - let parameters = { + let parameters = + ctx.ast.vec1(ctx.ast.argument_expression(ctx.ast.expression_from_function(target))); + let call = ctx.ast.expression_call(SPAN, callee, NONE, parameters, false); + let call = ctx.ast.expression_member(ctx.ast.member_expression_static( + SPAN, + call, + ctx.ast.identifier_name(SPAN, "apply"), + false + )); + let call = ctx.ast.expression_call(SPAN, call, NONE, { let mut items = ctx.ast.vec(); items.push(ctx.ast.argument_expression(ctx.ast.expression_this(SPAN))); - items.push(ctx.ast.argument_expression(ctx.ast.expression_null_literal(SPAN))); - items.push(ctx.ast.argument_expression(ctx.ast.expression_from_function(target))); + items.push(ctx.ast.argument_expression( + ctx.ast.expression_identifier_reference(SPAN, "arguments"), + )); items - }; - let call = ctx.ast.expression_call(SPAN, callee, NONE, parameters, false); + }, false); let returns = ctx.ast.return_statement(SPAN, Some(call)); let body = Statement::ReturnStatement(ctx.ast.alloc(returns)); let body = ctx.ast.function_body(SPAN, ctx.ast.vec(), ctx.ast.vec1(body)); diff --git a/crates/oxc_transformer/src/es2017/mod.rs b/crates/oxc_transformer/src/es2017/mod.rs index b0f67638b9a58..d90efc0fd50e2 100644 --- a/crates/oxc_transformer/src/es2017/mod.rs +++ b/crates/oxc_transformer/src/es2017/mod.rs @@ -4,7 +4,7 @@ pub mod options; use crate::context::Ctx; use crate::es2017::async_to_generator::AsyncToGenerator; use crate::es2017::options::ES2017Options; -use oxc_ast::ast::{ArrowFunctionExpression, Expression, Function}; +use oxc_ast::ast::{ArrowFunctionExpression, Expression, Statement}; use oxc_traverse::{Traverse, TraverseCtx}; use std::rc::Rc; @@ -30,9 +30,9 @@ impl<'a> Traverse<'a> for ES2017<'a> { } } - fn exit_function(&mut self, node: &mut Function<'a>, ctx: &mut TraverseCtx<'a>) { + fn exit_statement(&mut self, stmt: &mut Statement<'a>, ctx: &mut TraverseCtx<'a>) { if self.options.async_to_generator { - self.async_to_generator.exit_function(node, ctx); + self.async_to_generator.exit_statement(stmt, ctx); } } diff --git a/crates/oxc_transformer/src/lib.rs b/crates/oxc_transformer/src/lib.rs index 4b9c1e3c89b12..bf19592a38b97 100644 --- a/crates/oxc_transformer/src/lib.rs +++ b/crates/oxc_transformer/src/lib.rs @@ -339,6 +339,10 @@ impl<'a, 'ctx> Traverse<'a> for TransformerImpl<'a, 'ctx> { self.common.exit_statements(stmts, ctx); } + fn exit_statement(&mut self, stmt: &mut Statement<'a>, ctx: &mut TraverseCtx<'a>) { + self.x2_es2017.exit_statement(stmt, ctx); + } + fn enter_tagged_template_expression( &mut self, expr: &mut TaggedTemplateExpression<'a>, diff --git a/tasks/transform_conformance/snapshots/babel.snap.md b/tasks/transform_conformance/snapshots/babel.snap.md index 843426f546a41..58d136f047f08 100644 --- a/tasks/transform_conformance/snapshots/babel.snap.md +++ b/tasks/transform_conformance/snapshots/babel.snap.md @@ -1,6 +1,6 @@ commit: 3bcfee23 -Passed: 330/1024 +Passed: 333/1022 # All Passed: * babel-plugin-transform-optional-catch-binding @@ -10,7 +10,7 @@ Passed: 330/1024 * babel-plugin-transform-react-jsx-source -# babel-preset-env (106/585) +# babel-preset-env (109/585) * .plugins-overlapping/chrome-49/input.js x Output mismatch @@ -230,9 +230,6 @@ x Output mismatch * corejs2-babel-7/usage-regenerator-used-generator/input.mjs x Output mismatch -* corejs2-babel-7/usage-regenerator-used-generator-native-support/input.mjs -x Output mismatch - * corejs2-babel-7/usage-remove-babel-polyfill-import/input.mjs x Output mismatch @@ -440,9 +437,6 @@ x Output mismatch * corejs3/usage-regenerator-used-async-native-support/input.mjs x Output mismatch -* corejs3/usage-regenerator-used-generator-native-support/input.mjs -x Output mismatch - * corejs3/usage-shippedProposals/input.mjs x Output mismatch @@ -701,9 +695,6 @@ x Output mismatch * corejs3-babel-7/usage-regenerator-used-generator/input.mjs x Output mismatch -* corejs3-babel-7/usage-regenerator-used-generator-native-support/input.mjs -x Output mismatch - * corejs3-babel-7/usage-shippedProposals/input.mjs x Output mismatch @@ -1665,14 +1656,6 @@ x Output mismatch x Output mismatch -# babel-plugin-transform-async-to-generator (0/2) -* assumption-ignoreFunctionLength-true/basic/input.mjs -x Output mismatch - -* assumption-ignoreFunctionLength-true/export-default-function/input.mjs -x Output mismatch - - # babel-plugin-transform-exponentiation-operator (1/4) * exponentiation-operator/assignment/input.js Symbol reference IDs mismatch: @@ -3462,7 +3445,7 @@ x Output mismatch `---- -* cross-platform/within-ts-module-block/input.tsx +* cross-platform/within-ts-module-block/input.ts x Output mismatch diff --git a/tasks/transform_conformance/snapshots/babel_exec.snap.md b/tasks/transform_conformance/snapshots/babel_exec.snap.md index 589af4ed43752..8520c53d043df 100644 --- a/tasks/transform_conformance/snapshots/babel_exec.snap.md +++ b/tasks/transform_conformance/snapshots/babel_exec.snap.md @@ -1,6 +1,6 @@ commit: 3bcfee23 -Passed: 33/60 +Passed: 32/54 # All Passed: * babel-plugin-transform-logical-assignment-operators @@ -74,23 +74,6 @@ exec failed exec failed -# babel-plugin-transform-async-to-generator (1/6) -* regression/15978/exec.js -exec failed - -* regression/8783/exec.js -exec failed - -* regression/T6882/exec.js -exec failed - -* regression/fn-name/exec.js -exec failed - -* regression/test262-fn-length/exec.js -exec failed - - # babel-plugin-transform-react-jsx-source (0/2) * react-source/basic-sample/exec.js exec failed diff --git a/tasks/transform_conformance/src/constants.rs b/tasks/transform_conformance/src/constants.rs index a22718f51b63b..01e619b1c4bb7 100644 --- a/tasks/transform_conformance/src/constants.rs +++ b/tasks/transform_conformance/src/constants.rs @@ -29,7 +29,7 @@ pub(crate) const PLUGINS: &[&str] = &[ // "babel-plugin-transform-dotall-regex", // // [Regex] "babel-plugin-transform-named-capturing-groups-regex", // // ES2017 - "babel-plugin-transform-async-to-generator", + // "babel-plugin-transform-async-to-generator", // ES2016 "babel-plugin-transform-exponentiation-operator", // ES2015 From 2f736a4c085c762a2149a0530a46e5e32dfa1081 Mon Sep 17 00:00:00 2001 From: Ethan Goh <7086cmd@gmail.com> Date: Tue, 24 Sep 2024 13:27:02 +0800 Subject: [PATCH 14/25] chore: format. --- .../src/es2017/async_to_generator.rs | 71 ++++++++++++------- 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/crates/oxc_transformer/src/es2017/async_to_generator.rs b/crates/oxc_transformer/src/es2017/async_to_generator.rs index 5f4266c128559..7b8dc8d48aed9 100644 --- a/crates/oxc_transformer/src/es2017/async_to_generator.rs +++ b/crates/oxc_transformer/src/es2017/async_to_generator.rs @@ -72,8 +72,7 @@ impl<'a> AsyncToGenerator<'a> { } fn transform_function(func: &mut Function<'a>, ctx: &mut TraverseCtx<'a>) -> Function<'a> { - let babel_helpers_id = - ctx.scopes().find_binding(ctx.current_scope_id(), "babelHelpers"); + let babel_helpers_id = ctx.scopes().find_binding(ctx.current_scope_id(), "babelHelpers"); let callee = Self::get_helper_callee(babel_helpers_id, ctx); let target = ctx.ast.function( func.r#type, @@ -100,21 +99,32 @@ impl<'a> AsyncToGenerator<'a> { SPAN, call, ctx.ast.identifier_name(SPAN, "apply"), - false + false, )); - let call = ctx.ast.expression_call(SPAN, call, NONE, { - let mut items = ctx.ast.vec(); - items.push(ctx.ast.argument_expression(ctx.ast.expression_this(SPAN))); - items.push(ctx.ast.argument_expression( - ctx.ast.expression_identifier_reference(SPAN, "arguments"), - )); - items - }, false); + let call = ctx.ast.expression_call( + SPAN, + call, + NONE, + { + let mut items = ctx.ast.vec(); + items.push(ctx.ast.argument_expression(ctx.ast.expression_this(SPAN))); + items.push(ctx.ast.argument_expression( + ctx.ast.expression_identifier_reference(SPAN, "arguments"), + )); + items + }, + false, + ); let returns = ctx.ast.return_statement(SPAN, Some(call)); let body = Statement::ReturnStatement(ctx.ast.alloc(returns)); let body = ctx.ast.function_body(SPAN, ctx.ast.vec(), ctx.ast.vec1(body)); let body = ctx.ast.alloc(body); - let params = ctx.ast.formal_parameters(SPAN, func.params.kind, ctx.ast.move_vec(&mut func.params.items), func.params.rest.take()); + let params = ctx.ast.formal_parameters( + SPAN, + func.params.kind, + ctx.ast.move_vec(&mut func.params.items), + func.params.rest.take(), + ); ctx.ast.function( FunctionType::FunctionExpression, SPAN, @@ -126,7 +136,7 @@ impl<'a> AsyncToGenerator<'a> { func.this_param.take(), params, func.return_type.take(), - Some(body) + Some(body), ) } } @@ -162,7 +172,9 @@ impl<'a> Traverse<'a> for AsyncToGenerator<'a> { *expr = Expression::YieldExpression(expression); } } else if let Expression::FunctionExpression(func) = expr { - if !func.r#async || func.generator { return } + if !func.r#async || func.generator { + return; + } let new_function = Self::transform_function(func, ctx); *expr = ctx.ast.expression_from_function(new_function); } @@ -170,7 +182,9 @@ impl<'a> Traverse<'a> for AsyncToGenerator<'a> { fn exit_statement(&mut self, stmt: &mut Statement<'a>, ctx: &mut TraverseCtx<'a>) { if let Statement::FunctionDeclaration(func) = stmt { - if !func.r#async || func.generator { return } + if !func.r#async || func.generator { + return; + } let new_function = Self::transform_function(func, ctx); if let Some(id) = func.id.take() { *stmt = ctx.ast.statement_declaration(ctx.ast.declaration_variable( @@ -190,7 +204,8 @@ impl<'a> Traverse<'a> for AsyncToGenerator<'a> { false, )); } else { - *stmt = ctx.ast.statement_declaration(ctx.ast.declaration_from_function(new_function)); + *stmt = + ctx.ast.statement_declaration(ctx.ast.declaration_from_function(new_function)); } } } @@ -235,16 +250,22 @@ impl<'a> Traverse<'a> for AsyncToGenerator<'a> { SPAN, call, ctx.ast.identifier_name(SPAN, "apply"), - false + false, )); - let call = ctx.ast.expression_call(SPAN, call, NONE, { - let mut items = ctx.ast.vec(); - items.push(ctx.ast.argument_expression(ctx.ast.expression_this(SPAN))); - items.push(ctx.ast.argument_expression( - ctx.ast.expression_identifier_reference(SPAN, "arguments"), - )); - items - }, false); + let call = ctx.ast.expression_call( + SPAN, + call, + NONE, + { + let mut items = ctx.ast.vec(); + items.push(ctx.ast.argument_expression(ctx.ast.expression_this(SPAN))); + items.push(ctx.ast.argument_expression( + ctx.ast.expression_identifier_reference(SPAN, "arguments"), + )); + items + }, + false, + ); let returns = ctx.ast.return_statement(SPAN, Some(call)); let body = Statement::ReturnStatement(ctx.ast.alloc(returns)); let body = ctx.ast.function_body(SPAN, ctx.ast.vec(), ctx.ast.vec1(body)); From 08ddcc4c15ef3d9898b5ea6924cf6f0cc02e7865 Mon Sep 17 00:00:00 2001 From: Ethan Goh <7086cmd@gmail.com> Date: Tue, 24 Sep 2024 13:36:33 +0800 Subject: [PATCH 15/25] fix --- crates/oxc_transformer/src/es2017/async_to_generator.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/oxc_transformer/src/es2017/async_to_generator.rs b/crates/oxc_transformer/src/es2017/async_to_generator.rs index 7b8dc8d48aed9..a60f91ac7ab4f 100644 --- a/crates/oxc_transformer/src/es2017/async_to_generator.rs +++ b/crates/oxc_transformer/src/es2017/async_to_generator.rs @@ -266,9 +266,11 @@ impl<'a> Traverse<'a> for AsyncToGenerator<'a> { }, false, ); - let returns = ctx.ast.return_statement(SPAN, Some(call)); - let body = Statement::ReturnStatement(ctx.ast.alloc(returns)); - let body = ctx.ast.function_body(SPAN, ctx.ast.vec(), ctx.ast.vec1(body)); + let body = ctx.ast.function_body( + SPAN, + ctx.ast.vec(), + ctx.ast.vec1(ctx.ast.statement_expression(SPAN, call)), + ); arrow.body = ctx.ast.alloc(body); arrow.r#async = false; } From c3f85dc0a463cee2d0eb51414e5809e509367336 Mon Sep 17 00:00:00 2001 From: Ethan Goh <7086cmd@gmail.com> Date: Tue, 24 Sep 2024 18:18:17 +0800 Subject: [PATCH 16/25] chore: add tests, fix: arrow expression. --- .../src/es2017/async_to_generator.rs | 1 + .../snapshots/babel.snap.md | 52 ++++++++++++++++++- .../snapshots/babel_exec.snap.md | 13 ++++- tasks/transform_conformance/src/constants.rs | 2 +- tasks/transform_conformance/src/test_case.rs | 10 +++- 5 files changed, 74 insertions(+), 4 deletions(-) diff --git a/crates/oxc_transformer/src/es2017/async_to_generator.rs b/crates/oxc_transformer/src/es2017/async_to_generator.rs index a60f91ac7ab4f..c5f01abb02801 100644 --- a/crates/oxc_transformer/src/es2017/async_to_generator.rs +++ b/crates/oxc_transformer/src/es2017/async_to_generator.rs @@ -273,5 +273,6 @@ impl<'a> Traverse<'a> for AsyncToGenerator<'a> { ); arrow.body = ctx.ast.alloc(body); arrow.r#async = false; + arrow.expression = true; } } diff --git a/tasks/transform_conformance/snapshots/babel.snap.md b/tasks/transform_conformance/snapshots/babel.snap.md index 58d136f047f08..671d5eee91e23 100644 --- a/tasks/transform_conformance/snapshots/babel.snap.md +++ b/tasks/transform_conformance/snapshots/babel.snap.md @@ -1,6 +1,6 @@ commit: 3bcfee23 -Passed: 333/1022 +Passed: 334/1039 # All Passed: * babel-plugin-transform-optional-catch-binding @@ -1656,6 +1656,56 @@ x Output mismatch x Output mismatch +# babel-plugin-transform-async-to-generator (1/17) +* assumption-ignoreFunctionLength-true/basic/input.mjs +x Output mismatch + +* assumption-ignoreFunctionLength-true/export-default-function/input.mjs +x Output mismatch + +* assumption-noNewArrows-false/basic/input.js +x Output mismatch + +* bluebird-coroutines/arrow-function/input.js +x Output mismatch + +* bluebird-coroutines/class/input.js +x Output mismatch + +* bluebird-coroutines/expression/input.js +x Output mismatch + +* bluebird-coroutines/named-expression/input.js +x Output mismatch + +* bluebird-coroutines/statement/input.js +x Output mismatch + +* regression/15978/input.js +x Output mismatch + +* regression/4599/input.js +x Output mismatch + +* regression/8783/input.js +x Output mismatch + +* regression/T7108/input.js +x Output mismatch + +* regression/T7194/input.js +x Output mismatch + +* regression/gh-6923/input.js +x Output mismatch + +* regression/in-uncompiled-class-fields/input.js +x Output mismatch + +* regression/regression-2765/input.js +x Output mismatch + + # babel-plugin-transform-exponentiation-operator (1/4) * exponentiation-operator/assignment/input.js Symbol reference IDs mismatch: diff --git a/tasks/transform_conformance/snapshots/babel_exec.snap.md b/tasks/transform_conformance/snapshots/babel_exec.snap.md index 8520c53d043df..b8a6a93d38ff6 100644 --- a/tasks/transform_conformance/snapshots/babel_exec.snap.md +++ b/tasks/transform_conformance/snapshots/babel_exec.snap.md @@ -1,6 +1,6 @@ commit: 3bcfee23 -Passed: 32/54 +Passed: 35/60 # All Passed: * babel-plugin-transform-logical-assignment-operators @@ -74,6 +74,17 @@ exec failed exec failed +# babel-plugin-transform-async-to-generator (3/6) +* regression/15978/exec.js +exec failed + +* regression/8783/exec.js +exec failed + +* regression/T6882/exec.js +exec failed + + # babel-plugin-transform-react-jsx-source (0/2) * react-source/basic-sample/exec.js exec failed diff --git a/tasks/transform_conformance/src/constants.rs b/tasks/transform_conformance/src/constants.rs index 01e619b1c4bb7..a22718f51b63b 100644 --- a/tasks/transform_conformance/src/constants.rs +++ b/tasks/transform_conformance/src/constants.rs @@ -29,7 +29,7 @@ pub(crate) const PLUGINS: &[&str] = &[ // "babel-plugin-transform-dotall-regex", // // [Regex] "babel-plugin-transform-named-capturing-groups-regex", // // ES2017 - // "babel-plugin-transform-async-to-generator", + "babel-plugin-transform-async-to-generator", // ES2016 "babel-plugin-transform-exponentiation-operator", // ES2015 diff --git a/tasks/transform_conformance/src/test_case.rs b/tasks/transform_conformance/src/test_case.rs index 35211c842366c..6834bb92169f2 100644 --- a/tasks/transform_conformance/src/test_case.rs +++ b/tasks/transform_conformance/src/test_case.rs @@ -4,6 +4,7 @@ use std::{ }; use cow_utils::CowUtils; +use oxc::parser::ParseOptions; use oxc::{ allocator::Allocator, codegen::CodeGenerator, @@ -298,7 +299,14 @@ impl TestCase for ConformanceTestCase { String::default, |output| { // Get expected code by parsing the source text, so we can get the same code generated result. - let ret = Parser::new(&allocator, &output, source_type).parse(); + let ret = Parser::new(&allocator, &output, source_type) + .with_options(ParseOptions { + // Related: async to generator, regression + allow_return_outside_function: true, + ..Default::default() + }) + .parse(); + CodeGenerator::new() // .enable_comment( // &output, From d29ea213b4251591eef0f78e18bc002914da079a Mon Sep 17 00:00:00 2001 From: Ethan Goh <7086cmd@gmail.com> Date: Tue, 24 Sep 2024 18:18:23 +0800 Subject: [PATCH 17/25] chore: format. --- tasks/transform_conformance/src/test_case.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/transform_conformance/src/test_case.rs b/tasks/transform_conformance/src/test_case.rs index 6834bb92169f2..a9724b2bdc890 100644 --- a/tasks/transform_conformance/src/test_case.rs +++ b/tasks/transform_conformance/src/test_case.rs @@ -306,7 +306,7 @@ impl TestCase for ConformanceTestCase { ..Default::default() }) .parse(); - + CodeGenerator::new() // .enable_comment( // &output, From 071c28f74e0d45364c42650cf2f229751842b24e Mon Sep 17 00:00:00 2001 From: Ethan Goh <7086cmd@gmail.com> Date: Tue, 24 Sep 2024 18:23:07 +0800 Subject: [PATCH 18/25] refactor: remove `ctx`. --- .../src/es2017/async_to_generator.rs | 20 ++++++++----------- crates/oxc_transformer/src/es2017/mod.rs | 15 ++++++-------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/crates/oxc_transformer/src/es2017/async_to_generator.rs b/crates/oxc_transformer/src/es2017/async_to_generator.rs index c5f01abb02801..466c4352dc8c9 100644 --- a/crates/oxc_transformer/src/es2017/async_to_generator.rs +++ b/crates/oxc_transformer/src/es2017/async_to_generator.rs @@ -39,7 +39,6 @@ //! * Async / Await TC39 proposal: //! -use crate::context::Ctx; use oxc_ast::ast::{ ArrowFunctionExpression, Expression, FormalParameterKind, Function, FunctionType, Statement, VariableDeclarationKind, YieldExpression, @@ -50,16 +49,13 @@ use oxc_syntax::reference::ReferenceFlags; use oxc_syntax::symbol::SymbolId; use oxc_traverse::{Ancestor, Traverse, TraverseCtx}; -pub struct AsyncToGenerator<'a> { - _ctx: Ctx<'a>, -} - -impl<'a> AsyncToGenerator<'a> { - pub fn new(ctx: Ctx<'a>) -> Self { - Self { _ctx: ctx } - } +pub struct AsyncToGenerator; - fn get_helper_callee(symbol_id: Option, ctx: &mut TraverseCtx<'a>) -> Expression<'a> { +impl AsyncToGenerator { + fn get_helper_callee<'a>( + symbol_id: Option, + ctx: &mut TraverseCtx<'a>, + ) -> Expression<'a> { let ident = ctx.create_reference_id( SPAN, Atom::from("babelHelpers"), @@ -71,7 +67,7 @@ impl<'a> AsyncToGenerator<'a> { Expression::from(ctx.ast.member_expression_static(SPAN, object, property, false)) } - fn transform_function(func: &mut Function<'a>, ctx: &mut TraverseCtx<'a>) -> Function<'a> { + fn transform_function<'a>(func: &mut Function<'a>, ctx: &mut TraverseCtx<'a>) -> Function<'a> { let babel_helpers_id = ctx.scopes().find_binding(ctx.current_scope_id(), "babelHelpers"); let callee = Self::get_helper_callee(babel_helpers_id, ctx); let target = ctx.ast.function( @@ -141,7 +137,7 @@ impl<'a> AsyncToGenerator<'a> { } } -impl<'a> Traverse<'a> for AsyncToGenerator<'a> { +impl<'a> Traverse<'a> for AsyncToGenerator { fn exit_expression(&mut self, expr: &mut Expression<'a>, ctx: &mut TraverseCtx<'a>) { if let Expression::AwaitExpression(await_expr) = expr { // Do not transform top-level await, or in async generator functions. diff --git a/crates/oxc_transformer/src/es2017/mod.rs b/crates/oxc_transformer/src/es2017/mod.rs index d90efc0fd50e2..68e2b5e39eeac 100644 --- a/crates/oxc_transformer/src/es2017/mod.rs +++ b/crates/oxc_transformer/src/es2017/mod.rs @@ -1,29 +1,26 @@ mod async_to_generator; pub mod options; -use crate::context::Ctx; use crate::es2017::async_to_generator::AsyncToGenerator; use crate::es2017::options::ES2017Options; use oxc_ast::ast::{ArrowFunctionExpression, Expression, Statement}; use oxc_traverse::{Traverse, TraverseCtx}; -use std::rc::Rc; #[allow(dead_code)] -pub struct ES2017<'a> { - ctx: Ctx<'a>, +pub struct ES2017 { options: ES2017Options, // Plugins - async_to_generator: AsyncToGenerator<'a>, + async_to_generator: AsyncToGenerator, } -impl ES2017<'_> { - pub fn new(options: ES2017Options, ctx: Ctx) -> ES2017 { - ES2017 { async_to_generator: AsyncToGenerator::new(Rc::clone(&ctx)), ctx, options } +impl ES2017 { + pub fn new(options: ES2017Options) -> ES2017 { + ES2017 { async_to_generator: AsyncToGenerator, options } } } -impl<'a> Traverse<'a> for ES2017<'a> { +impl<'a> Traverse<'a> for ES2017 { fn exit_expression(&mut self, node: &mut Expression<'a>, ctx: &mut TraverseCtx<'a>) { if self.options.async_to_generator { self.async_to_generator.exit_expression(node, ctx); From e7feb66db0779a215e55409fd5d5d2ff8daaa8eb Mon Sep 17 00:00:00 2001 From: Ethan Goh <7086cmd@gmail.com> Date: Sat, 28 Sep 2024 19:30:46 +0800 Subject: [PATCH 19/25] chore: align with latest. --- crates/oxc_transformer/src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/oxc_transformer/src/lib.rs b/crates/oxc_transformer/src/lib.rs index bf19592a38b97..f701d50baa66c 100644 --- a/crates/oxc_transformer/src/lib.rs +++ b/crates/oxc_transformer/src/lib.rs @@ -17,6 +17,7 @@ mod options; mod env; mod es2015; mod es2016; +mod es2017; mod es2018; mod es2019; mod es2020; @@ -36,6 +37,7 @@ use std::path::Path; use common::Common; use es2016::ES2016; use es2018::ES2018; +use es2017::ES2017; use es2019::ES2019; use es2020::ES2020; use es2021::ES2021; @@ -98,6 +100,7 @@ impl<'a> Transformer<'a> { x2_es2019: ES2019::new(self.options.es2019), x2_es2018: ES2018::new(self.options.es2018), x2_es2016: ES2016::new(self.options.es2016, &self.ctx), + x2_es2017: ES2017::new(self.options.es2017), x3_es2015: ES2015::new(self.options.es2015), x4_regexp: RegExp::new(self.options.regexp, &self.ctx), common: Common::new(&self.ctx), @@ -116,6 +119,7 @@ struct TransformerImpl<'a, 'ctx> { x2_es2020: ES2020<'a, 'ctx>, x2_es2019: ES2019, x2_es2018: ES2018, + x2_es2017: ES2017, x2_es2016: ES2016<'a, 'ctx>, x3_es2015: ES2015<'a>, x4_regexp: RegExp<'a, 'ctx>, @@ -199,6 +203,7 @@ impl<'a, 'ctx> Traverse<'a> for TransformerImpl<'a, 'ctx> { fn exit_expression(&mut self, expr: &mut Expression<'a>, ctx: &mut TraverseCtx<'a>) { self.x1_react.exit_expression(expr, ctx); + self.x2_es2017.exit_expression(expr, ctx); self.x3_es2015.exit_expression(expr, ctx); } From ca74e6a4ca90b8a10b6c6251da896b5fc5a39495 Mon Sep 17 00:00:00 2001 From: Ethan Goh <7086cmd@gmail.com> Date: Sat, 28 Sep 2024 19:30:54 +0800 Subject: [PATCH 20/25] chore: format. --- crates/oxc_transformer/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/oxc_transformer/src/lib.rs b/crates/oxc_transformer/src/lib.rs index f701d50baa66c..e146d358915e9 100644 --- a/crates/oxc_transformer/src/lib.rs +++ b/crates/oxc_transformer/src/lib.rs @@ -36,8 +36,8 @@ use std::path::Path; use common::Common; use es2016::ES2016; -use es2018::ES2018; use es2017::ES2017; +use es2018::ES2018; use es2019::ES2019; use es2020::ES2020; use es2021::ES2021; From e83cf6c716d376c891aed72ee6fc36a81d0b21cc Mon Sep 17 00:00:00 2001 From: Ethan Goh <7086cmd@gmail.com> Date: Sat, 28 Sep 2024 19:38:33 +0800 Subject: [PATCH 21/25] fix: should pass the arguments to generator function. --- .../src/es2017/async_to_generator.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/oxc_transformer/src/es2017/async_to_generator.rs b/crates/oxc_transformer/src/es2017/async_to_generator.rs index 466c4352dc8c9..91a410710714d 100644 --- a/crates/oxc_transformer/src/es2017/async_to_generator.rs +++ b/crates/oxc_transformer/src/es2017/async_to_generator.rs @@ -40,7 +40,7 @@ //! use oxc_ast::ast::{ - ArrowFunctionExpression, Expression, FormalParameterKind, Function, FunctionType, Statement, + ArrowFunctionExpression, Expression, Function, FunctionType, Statement, VariableDeclarationKind, YieldExpression, }; use oxc_ast::NONE; @@ -81,9 +81,9 @@ impl AsyncToGenerator { func.this_param.take(), ctx.ast.alloc(ctx.ast.formal_parameters( SPAN, - FormalParameterKind::FormalParameter, - ctx.ast.vec(), - NONE, + func.params.kind, + ctx.ast.move_vec(&mut func.params.items), + func.params.rest.take(), )), func.return_type.take(), func.body.take(), @@ -232,9 +232,9 @@ impl<'a> Traverse<'a> for AsyncToGenerator { NONE, ctx.ast.alloc(ctx.ast.formal_parameters( SPAN, - FormalParameterKind::FormalParameter, - ctx.ast.vec(), - NONE, + arrow.params.kind, + ctx.ast.move_vec(&mut arrow.params.items), + arrow.params.rest.take(), )), arrow.return_type.take(), Some(body), From f4d3fd2ff88f447960107e9133f039b99df7eed6 Mon Sep 17 00:00:00 2001 From: Ethan Goh <7086cmd@gmail.com> Date: Sat, 28 Sep 2024 19:52:20 +0800 Subject: [PATCH 22/25] chore: update snapshots. --- tasks/transform_conformance/snapshots/babel_exec.snap.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tasks/transform_conformance/snapshots/babel_exec.snap.md b/tasks/transform_conformance/snapshots/babel_exec.snap.md index b8a6a93d38ff6..34aceed67d863 100644 --- a/tasks/transform_conformance/snapshots/babel_exec.snap.md +++ b/tasks/transform_conformance/snapshots/babel_exec.snap.md @@ -1,6 +1,6 @@ commit: 3bcfee23 -Passed: 35/60 +Passed: 34/60 # All Passed: * babel-plugin-transform-logical-assignment-operators @@ -74,7 +74,7 @@ exec failed exec failed -# babel-plugin-transform-async-to-generator (3/6) +# babel-plugin-transform-async-to-generator (2/6) * regression/15978/exec.js exec failed @@ -84,6 +84,9 @@ exec failed * regression/T6882/exec.js exec failed +* regression/test262-fn-length/exec.js +exec failed + # babel-plugin-transform-react-jsx-source (0/2) * react-source/basic-sample/exec.js From b194592f4a2fd97bc0897f7730e90b607128355d Mon Sep 17 00:00:00 2001 From: Ethan Goh <7086cmd@gmail.com> Date: Sun, 29 Sep 2024 07:28:33 +0800 Subject: [PATCH 23/25] perf: reduce taking. --- .../src/es2017/async_to_generator.rs | 47 +------------------ 1 file changed, 1 insertion(+), 46 deletions(-) diff --git a/crates/oxc_transformer/src/es2017/async_to_generator.rs b/crates/oxc_transformer/src/es2017/async_to_generator.rs index 91a410710714d..15c4df4c3e710 100644 --- a/crates/oxc_transformer/src/es2017/async_to_generator.rs +++ b/crates/oxc_transformer/src/es2017/async_to_generator.rs @@ -91,36 +91,11 @@ impl AsyncToGenerator { let parameters = ctx.ast.vec1(ctx.ast.argument_expression(ctx.ast.expression_from_function(target))); let call = ctx.ast.expression_call(SPAN, callee, NONE, parameters, false); - let call = ctx.ast.expression_member(ctx.ast.member_expression_static( - SPAN, - call, - ctx.ast.identifier_name(SPAN, "apply"), - false, - )); - let call = ctx.ast.expression_call( - SPAN, - call, - NONE, - { - let mut items = ctx.ast.vec(); - items.push(ctx.ast.argument_expression(ctx.ast.expression_this(SPAN))); - items.push(ctx.ast.argument_expression( - ctx.ast.expression_identifier_reference(SPAN, "arguments"), - )); - items - }, - false, - ); let returns = ctx.ast.return_statement(SPAN, Some(call)); let body = Statement::ReturnStatement(ctx.ast.alloc(returns)); let body = ctx.ast.function_body(SPAN, ctx.ast.vec(), ctx.ast.vec1(body)); let body = ctx.ast.alloc(body); - let params = ctx.ast.formal_parameters( - SPAN, - func.params.kind, - ctx.ast.move_vec(&mut func.params.items), - func.params.rest.take(), - ); + let params = ctx.ast.formal_parameters(SPAN, func.params.kind, ctx.ast.vec(), NONE); ctx.ast.function( FunctionType::FunctionExpression, SPAN, @@ -242,26 +217,6 @@ impl<'a> Traverse<'a> for AsyncToGenerator { let parameters = ctx.ast.vec1(ctx.ast.argument_expression(ctx.ast.expression_from_function(target))); let call = ctx.ast.expression_call(SPAN, callee, NONE, parameters, false); - let call = ctx.ast.expression_member(ctx.ast.member_expression_static( - SPAN, - call, - ctx.ast.identifier_name(SPAN, "apply"), - false, - )); - let call = ctx.ast.expression_call( - SPAN, - call, - NONE, - { - let mut items = ctx.ast.vec(); - items.push(ctx.ast.argument_expression(ctx.ast.expression_this(SPAN))); - items.push(ctx.ast.argument_expression( - ctx.ast.expression_identifier_reference(SPAN, "arguments"), - )); - items - }, - false, - ); let body = ctx.ast.function_body( SPAN, ctx.ast.vec(), From 28b307412af76846889c0abfce64c7c7e4c5d522 Mon Sep 17 00:00:00 2001 From: Ethan Goh <7086cmd@gmail.com> Date: Mon, 30 Sep 2024 19:28:05 +0800 Subject: [PATCH 24/25] refactor: use ast builder. --- .../src/es2017/async_to_generator.rs | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/crates/oxc_transformer/src/es2017/async_to_generator.rs b/crates/oxc_transformer/src/es2017/async_to_generator.rs index 15c4df4c3e710..a158bf0e5b00f 100644 --- a/crates/oxc_transformer/src/es2017/async_to_generator.rs +++ b/crates/oxc_transformer/src/es2017/async_to_generator.rs @@ -1,4 +1,4 @@ -//! ES2017: Async / Await +//! ES2017: Async / Await [WIP] //! //! This plugin transforms async functions to generator functions. //! @@ -12,23 +12,26 @@ //! const foo2 = async () => { //! await bar(); //! }; +//! async () => { +//! await bar(); +//! } //! ``` //! -//! Output: +//! Output (Currently): //! ```js //! function foo() { -//! return _asyncToGenerator(this, null, function* () { +//! return _asyncToGenerator(function* () { //! yield bar(); //! }) //! } -//! const foo2 = () => _asyncToGenerator(this, null, function* () { +//! const foo2 = () => _asyncToGenerator(function* () { //! yield bar(); //! } //! ``` //! //! ## Implementation //! -//! Implementation based on [@babel/plugin-transform-async-to-generator](https://babel.dev/docs/babel-plugin-transform-async-to-generator) and [esbuild](https://github.com/evanw/esbuild/blob/main/internal/js_parser/js_parser_lower.go#L392). +//! Implementation based on [@babel/plugin-transform-async-to-generator](https://babel.dev/docs/babel-plugin-transform-async-to-generator). //! //! //! Reference: @@ -40,8 +43,7 @@ //! use oxc_ast::ast::{ - ArrowFunctionExpression, Expression, Function, FunctionType, Statement, - VariableDeclarationKind, YieldExpression, + ArrowFunctionExpression, Expression, Function, FunctionType, Statement, VariableDeclarationKind, }; use oxc_ast::NONE; use oxc_span::{Atom, SPAN}; @@ -120,6 +122,8 @@ impl<'a> Traverse<'a> for AsyncToGenerator { .ancestry .ancestors() .find_map(|ance| { + // We need to check if there's async generator or async function. + // If it is async generator, we should not transform the await expression here. if let Ancestor::FunctionBody(body) = ance { if *body.r#async() { Some(!body.generator()) @@ -127,6 +131,7 @@ impl<'a> Traverse<'a> for AsyncToGenerator { None } } else if let Ancestor::ArrowFunctionExpressionBody(_) = ance { + // Arrow function is never generator. Some(true) } else { None @@ -134,13 +139,12 @@ impl<'a> Traverse<'a> for AsyncToGenerator { }) .unwrap_or(false); if in_async_function { - let yield_expression = YieldExpression { - span: SPAN, - delegate: false, - argument: Some(ctx.ast.move_expression(&mut await_expr.argument)), - }; - let expression = ctx.ast.alloc(yield_expression); - *expr = Expression::YieldExpression(expression); + // Move the expression to yield. + *expr = ctx.ast.expression_yield( + SPAN, + false, + Some(ctx.ast.move_expression(&mut await_expr.argument)), + ); } } else if let Expression::FunctionExpression(func) = expr { if !func.r#async || func.generator { From 4ee2faf7f9e36f037750c95f9eceba7cfa1281b5 Mon Sep 17 00:00:00 2001 From: Ethan Goh <7086cmd@gmail.com> Date: Mon, 30 Sep 2024 21:43:05 +0800 Subject: [PATCH 25/25] chore: docs. --- crates/oxc_transformer/src/es2017/async_to_generator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/oxc_transformer/src/es2017/async_to_generator.rs b/crates/oxc_transformer/src/es2017/async_to_generator.rs index a158bf0e5b00f..6505a42fd3a53 100644 --- a/crates/oxc_transformer/src/es2017/async_to_generator.rs +++ b/crates/oxc_transformer/src/es2017/async_to_generator.rs @@ -1,4 +1,4 @@ -//! ES2017: Async / Await [WIP] +//! ES2017: Async / Await \[WIP\] //! //! This plugin transforms async functions to generator functions. //!