diff --git a/crates/oxc_codegen/src/gen.rs b/crates/oxc_codegen/src/gen.rs index 453ec8f91b15b..47ed1c33ac0ba 100644 --- a/crates/oxc_codegen/src/gen.rs +++ b/crates/oxc_codegen/src/gen.rs @@ -19,22 +19,30 @@ use crate::{ pub trait Gen: GetSpan { fn gen(&self, p: &mut Codegen, ctx: Context); + + fn print(&self, p: &mut Codegen, ctx: Context) { + self.gen(p, ctx); + } } pub trait GenExpr: GetSpan { fn gen_expr(&self, p: &mut Codegen, precedence: Precedence, ctx: Context); + + fn print_expr(&self, p: &mut Codegen, precedence: Precedence, ctx: Context) { + self.gen_expr(p, precedence, ctx); + } } impl<'a> Gen for Program<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { if let Some(hashbang) = &self.hashbang { - hashbang.gen(p, ctx); + hashbang.print(p, ctx); } for directive in &self.directives { - directive.gen(p, ctx); + directive.print(p, ctx); } for stmt in &self.body { - stmt.gen(p, ctx); + stmt.print(p, ctx); p.print_semicolon_if_needed(); } } @@ -65,70 +73,70 @@ impl<'a> Gen for Directive<'a> { impl<'a> Gen for Statement<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match self { - Self::BlockStatement(stmt) => stmt.gen(p, ctx), - Self::BreakStatement(stmt) => stmt.gen(p, ctx), - Self::ContinueStatement(stmt) => stmt.gen(p, ctx), - Self::DebuggerStatement(stmt) => stmt.gen(p, ctx), - Self::DoWhileStatement(stmt) => stmt.gen(p, ctx), - Self::EmptyStatement(stmt) => stmt.gen(p, ctx), - Self::ExpressionStatement(stmt) => stmt.gen(p, ctx), - Self::ForInStatement(stmt) => stmt.gen(p, ctx), - Self::ForOfStatement(stmt) => stmt.gen(p, ctx), - Self::ForStatement(stmt) => stmt.gen(p, ctx), - Self::IfStatement(stmt) => stmt.gen(p, ctx), - Self::LabeledStatement(stmt) => stmt.gen(p, ctx), - Self::ReturnStatement(stmt) => stmt.gen(p, ctx), - Self::SwitchStatement(stmt) => stmt.gen(p, ctx), - Self::ThrowStatement(stmt) => stmt.gen(p, ctx), - Self::TryStatement(stmt) => stmt.gen(p, ctx), - Self::WhileStatement(stmt) => stmt.gen(p, ctx), - Self::WithStatement(stmt) => stmt.gen(p, ctx), - - Self::ImportDeclaration(decl) => decl.gen(p, ctx), - Self::ExportAllDeclaration(decl) => decl.gen(p, ctx), - Self::ExportDefaultDeclaration(decl) => decl.gen(p, ctx), - Self::ExportNamedDeclaration(decl) => decl.gen(p, ctx), - Self::TSExportAssignment(decl) => decl.gen(p, ctx), - Self::TSNamespaceExportDeclaration(decl) => decl.gen(p, ctx), + Self::BlockStatement(stmt) => stmt.print(p, ctx), + Self::BreakStatement(stmt) => stmt.print(p, ctx), + Self::ContinueStatement(stmt) => stmt.print(p, ctx), + Self::DebuggerStatement(stmt) => stmt.print(p, ctx), + Self::DoWhileStatement(stmt) => stmt.print(p, ctx), + Self::EmptyStatement(stmt) => stmt.print(p, ctx), + Self::ExpressionStatement(stmt) => stmt.print(p, ctx), + Self::ForInStatement(stmt) => stmt.print(p, ctx), + Self::ForOfStatement(stmt) => stmt.print(p, ctx), + Self::ForStatement(stmt) => stmt.print(p, ctx), + Self::IfStatement(stmt) => stmt.print(p, ctx), + Self::LabeledStatement(stmt) => stmt.print(p, ctx), + Self::ReturnStatement(stmt) => stmt.print(p, ctx), + Self::SwitchStatement(stmt) => stmt.print(p, ctx), + Self::ThrowStatement(stmt) => stmt.print(p, ctx), + Self::TryStatement(stmt) => stmt.print(p, ctx), + Self::WhileStatement(stmt) => stmt.print(p, ctx), + Self::WithStatement(stmt) => stmt.print(p, ctx), + + Self::ImportDeclaration(decl) => decl.print(p, ctx), + Self::ExportAllDeclaration(decl) => decl.print(p, ctx), + Self::ExportDefaultDeclaration(decl) => decl.print(p, ctx), + Self::ExportNamedDeclaration(decl) => decl.print(p, ctx), + Self::TSExportAssignment(decl) => decl.print(p, ctx), + Self::TSNamespaceExportDeclaration(decl) => decl.print(p, ctx), Self::VariableDeclaration(decl) => { p.print_indent(); - decl.gen(p, ctx); + decl.print(p, ctx); p.print_semicolon_after_statement(); } Self::FunctionDeclaration(decl) => { p.print_indent(); - decl.gen(p, ctx); + decl.print(p, ctx); p.print_soft_newline(); } Self::ClassDeclaration(decl) => { p.print_indent(); - decl.gen(p, ctx); + decl.print(p, ctx); p.print_soft_newline(); } Self::TSModuleDeclaration(decl) => { p.print_indent(); - decl.gen(p, ctx); + decl.print(p, ctx); p.print_soft_newline(); } Self::TSTypeAliasDeclaration(decl) => { p.print_indent(); - decl.gen(p, ctx); + decl.print(p, ctx); p.print_semicolon_after_statement(); } Self::TSInterfaceDeclaration(decl) => { p.print_indent(); - decl.gen(p, ctx); + decl.print(p, ctx); p.print_soft_newline(); } Self::TSEnumDeclaration(decl) => { p.print_indent(); - decl.gen(p, ctx); + decl.print(p, ctx); p.print_soft_newline(); } Self::TSImportEqualsDeclaration(decl) => { p.print_indent(); - decl.gen(p, ctx); + decl.print(p, ctx); p.print_semicolon_after_statement(); } } @@ -177,7 +185,7 @@ fn print_if(if_stmt: &IfStatement<'_>, p: &mut Codegen, ctx: Context) { stmt if wrap_to_avoid_ambiguous_else(stmt) => { p.print_soft_space(); p.print_block_start(stmt.span().start); - stmt.gen(p, ctx); + stmt.print(p, ctx); p.needs_semicolon = false; p.print_block_end(stmt.span().end); if if_stmt.alternate.is_some() { @@ -247,7 +255,7 @@ impl<'a> Gen for ForStatement<'a> { p.print_char(b'('); if let Some(init) = &self.init { - init.gen(p, Context::FORBID_IN); + init.print(p, Context::FORBID_IN); } p.print_semicolon(); @@ -276,7 +284,7 @@ impl<'a> Gen for ForInStatement<'a> { p.print_str("for"); p.print_soft_space(); p.print_char(b'('); - self.left.gen(p, Context::empty().and_forbid_in(false)); + self.left.print(p, Context::empty().and_forbid_in(false)); p.print_soft_space(); p.print_space_before_identifier(); p.print_str("in"); @@ -297,11 +305,11 @@ impl<'a> Gen for ForOfStatement<'a> { p.print_str(" await"); } p.print_char(b'('); - self.left.gen(p, ctx); + self.left.print(p, ctx); p.print_soft_space(); p.print_space_before_identifier(); p.print_str("of "); - self.right.gen_expr(p, Precedence::Comma, Context::empty()); + self.right.print_expr(p, Precedence::Comma, Context::empty()); p.print_char(b')'); p.print_body(&self.body, false, ctx); } @@ -311,9 +319,9 @@ impl<'a> Gen for ForStatementInit<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match self { match_expression!(ForStatementInit) => { - self.to_expression().gen_expr(p, Precedence::Lowest, ctx); + self.to_expression().print_expr(p, Precedence::Lowest, ctx); } - Self::VariableDeclaration(var) => var.gen(p, ctx), + Self::VariableDeclaration(var) => var.print(p, ctx), } } } @@ -321,13 +329,13 @@ impl<'a> Gen for ForStatementInit<'a> { impl<'a> Gen for ForStatementLeft<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match self { - ForStatementLeft::VariableDeclaration(var) => var.gen(p, ctx), + ForStatementLeft::VariableDeclaration(var) => var.print(p, ctx), ForStatementLeft::AssignmentTargetIdentifier(identifier) => { let wrap = identifier.name == "async"; - p.wrap(wrap, |p| self.to_assignment_target().gen(p, ctx)); + p.wrap(wrap, |p| self.to_assignment_target().print(p, ctx)); } match_assignment_target!(ForStatementLeft) => { - p.wrap(false, |p| self.to_assignment_target().gen(p, ctx)); + p.wrap(false, |p| self.to_assignment_target().print(p, ctx)); } } } @@ -357,7 +365,7 @@ impl<'a> Gen for DoWhileStatement<'a> { } else { p.print_soft_newline(); p.indent(); - self.body.gen(p, ctx); + self.body.print(p, ctx); p.print_semicolon_if_needed(); p.dedent(); p.print_indent(); @@ -387,7 +395,7 @@ impl<'a> Gen for ContinueStatement<'a> { p.print_str("continue"); if let Some(label) = &self.label { p.print_hard_space(); - label.gen(p, ctx); + label.print(p, ctx); } p.print_semicolon_after_statement(); } @@ -400,7 +408,7 @@ impl<'a> Gen for BreakStatement<'a> { p.print_str("break"); if let Some(label) = &self.label { p.print_hard_space(); - label.gen(p, ctx); + label.print(p, ctx); } p.print_semicolon_after_statement(); } @@ -419,7 +427,7 @@ impl<'a> Gen for SwitchStatement<'a> { p.print_curly_braces(self.span, self.cases.is_empty(), |p| { for case in &self.cases { p.add_source_mapping(case.span.start); - case.gen(p, ctx); + case.print(p, ctx); } }); p.print_soft_newline(); @@ -449,7 +457,7 @@ impl<'a> Gen for SwitchCase<'a> { p.indent(); for item in &self.consequent { p.print_semicolon_if_needed(); - item.gen(p, ctx); + item.print(p, ctx); } p.dedent(); } @@ -475,7 +483,7 @@ impl<'a> Gen for LabeledStatement<'a> { p.print_indent(); } p.print_space_before_identifier(); - self.label.gen(p, ctx); + self.label.print(p, ctx); p.print_colon(); p.print_body(&self.body, false, ctx); } @@ -495,7 +503,7 @@ impl<'a> Gen for TryStatement<'a> { if let Some(param) = &handler.param { p.print_soft_space(); p.print_str("("); - param.pattern.gen(p, ctx); + param.pattern.print(p, ctx); p.print_str(")"); } p.print_soft_space(); @@ -581,12 +589,12 @@ impl<'a> Gen for VariableDeclaration<'a> { impl<'a> Gen for VariableDeclarator<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { - self.id.gen(p, ctx); + self.id.print(p, ctx); if let Some(init) = &self.init { p.print_soft_space(); p.print_equal(); p.print_soft_space(); - init.gen_expr(p, Precedence::Comma, ctx); + init.print_expr(p, Precedence::Comma, ctx); } } } @@ -612,28 +620,28 @@ impl<'a> Gen for Function<'a> { } if let Some(id) = &self.id { p.print_space_before_identifier(); - id.gen(p, ctx); + id.print(p, ctx); } if let Some(type_parameters) = &self.type_parameters { - type_parameters.gen(p, ctx); + type_parameters.print(p, ctx); } p.print_char(b'('); if let Some(this_param) = &self.this_param { - this_param.gen(p, ctx); + this_param.print(p, ctx); if !self.params.is_empty() || self.params.rest.is_some() { p.print_str(","); } p.print_soft_space(); } - self.params.gen(p, ctx); + self.params.print(p, ctx); p.print_char(b')'); if let Some(return_type) = &self.return_type { p.print_str(": "); - return_type.gen(p, ctx); + return_type.print(p, ctx); } if let Some(body) = &self.body { p.print_soft_space(); - body.gen(p, ctx); + body.print(p, ctx); } else { p.print_semicolon(); } @@ -645,11 +653,11 @@ impl<'a> Gen for FunctionBody<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { p.print_curly_braces(self.span, self.is_empty(), |p| { for directive in &self.directives { - directive.gen(p, ctx); + directive.print(p, ctx); } for stmt in &self.statements { p.print_semicolon_if_needed(); - stmt.gen(p, ctx); + stmt.print(p, ctx); } }); p.needs_semicolon = false; @@ -659,7 +667,7 @@ impl<'a> Gen for FunctionBody<'a> { impl<'a> Gen for FormalParameter<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { for decorator in &self.decorators { - decorator.gen(p, ctx); + decorator.print(p, ctx); p.print_hard_space(); } if let Some(accessibility) = self.accessibility { @@ -669,7 +677,7 @@ impl<'a> Gen for FormalParameter<'a> { if self.readonly { p.print_str("readonly "); } - self.pattern.gen(p, ctx); + self.pattern.print(p, ctx); } } @@ -681,7 +689,7 @@ impl<'a> Gen for FormalParameters<'a> { p.print_comma(); p.print_soft_space(); } - rest.gen(p, ctx); + rest.print(p, ctx); } } } @@ -705,7 +713,7 @@ impl<'a> Gen for ImportDeclaration<'a> { p.print_char(b'"'); if let Some(with_clause) = &self.with_clause { p.print_hard_space(); - with_clause.gen(p, ctx); + with_clause.print(p, ctx); } p.print_semicolon_after_statement(); return; @@ -723,7 +731,7 @@ impl<'a> Gen for ImportDeclaration<'a> { p.print_comma(); p.print_soft_space(); } - spec.local.gen(p, ctx); + spec.local.print(p, ctx); } ImportDeclarationSpecifier::ImportNamespaceSpecifier(spec) => { if in_block { @@ -735,7 +743,7 @@ impl<'a> Gen for ImportDeclaration<'a> { p.print_soft_space(); } p.print_str("* as "); - spec.local.gen(p, ctx); + spec.local.print(p, ctx); } ImportDeclarationSpecifier::ImportSpecifier(spec) => { if in_block { @@ -757,15 +765,15 @@ impl<'a> Gen for ImportDeclaration<'a> { let imported_name = match &spec.imported { ModuleExportName::IdentifierName(identifier) => { - identifier.gen(p, ctx); + identifier.print(p, ctx); identifier.name.as_str() } ModuleExportName::IdentifierReference(identifier) => { - identifier.gen(p, ctx); + identifier.print(p, ctx); identifier.name.as_str() } ModuleExportName::StringLiteral(literal) => { - literal.gen(p, ctx); + literal.print(p, ctx); literal.value.as_str() } }; @@ -774,7 +782,7 @@ impl<'a> Gen for ImportDeclaration<'a> { if imported_name != local_name { p.print_str(" as "); - spec.local.gen(p, ctx); + spec.local.print(p, ctx); } } } @@ -785,10 +793,10 @@ impl<'a> Gen for ImportDeclaration<'a> { } p.print_str(" from "); } - self.source.gen(p, ctx); + self.source.print(p, ctx); if let Some(with_clause) = &self.with_clause { p.print_hard_space(); - with_clause.gen(p, ctx); + with_clause.print(p, ctx); } p.add_source_mapping(self.span.end); p.print_semicolon_after_statement(); @@ -798,7 +806,7 @@ impl<'a> Gen for ImportDeclaration<'a> { impl<'a> Gen for WithClause<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { p.add_source_mapping(self.span.start); - self.attributes_keyword.gen(p, ctx); + self.attributes_keyword.print(p, ctx); p.print_soft_space(); p.print_block_start(self.span.start); p.print_sequence(&self.with_entries, ctx); @@ -812,11 +820,11 @@ impl<'a> Gen for ImportAttribute<'a> { ImportAttributeKey::Identifier(identifier) => { p.print_str(identifier.name.as_str()); } - ImportAttributeKey::StringLiteral(literal) => literal.gen(p, ctx), + ImportAttributeKey::StringLiteral(literal) => literal.print(p, ctx), }; p.print_colon(); p.print_soft_space(); - self.value.gen(p, ctx); + self.value.print(p, ctx); } } @@ -853,14 +861,14 @@ impl<'a> Gen for ExportNamedDeclaration<'a> { match &self.declaration { Some(decl) => { match decl { - Declaration::VariableDeclaration(decl) => decl.gen(p, ctx), - Declaration::FunctionDeclaration(decl) => decl.gen(p, ctx), - Declaration::ClassDeclaration(decl) => decl.gen(p, ctx), - Declaration::TSModuleDeclaration(decl) => decl.gen(p, ctx), - Declaration::TSTypeAliasDeclaration(decl) => decl.gen(p, ctx), - Declaration::TSInterfaceDeclaration(decl) => decl.gen(p, ctx), - Declaration::TSEnumDeclaration(decl) => decl.gen(p, ctx), - Declaration::TSImportEqualsDeclaration(decl) => decl.gen(p, ctx), + Declaration::VariableDeclaration(decl) => decl.print(p, ctx), + Declaration::FunctionDeclaration(decl) => decl.print(p, ctx), + Declaration::ClassDeclaration(decl) => decl.print(p, ctx), + Declaration::TSModuleDeclaration(decl) => decl.print(p, ctx), + Declaration::TSTypeAliasDeclaration(decl) => decl.print(p, ctx), + Declaration::TSInterfaceDeclaration(decl) => decl.print(p, ctx), + Declaration::TSEnumDeclaration(decl) => decl.print(p, ctx), + Declaration::TSImportEqualsDeclaration(decl) => decl.print(p, ctx), } if matches!( decl, @@ -886,7 +894,7 @@ impl<'a> Gen for ExportNamedDeclaration<'a> { p.print_soft_space(); p.print_str("from"); p.print_soft_space(); - source.gen(p, ctx); + source.print(p, ctx); } p.print_semicolon_after_statement(); } @@ -898,7 +906,7 @@ impl<'a> Gen for TSExportAssignment<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { p.print_indent(); p.print_str("export = "); - self.expression.gen_expr(p, Precedence::Lowest, ctx); + self.expression.print_expr(p, Precedence::Lowest, ctx); p.print_semicolon_after_statement(); } } @@ -907,7 +915,7 @@ impl<'a> Gen for TSNamespaceExportDeclaration<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { p.print_indent(); p.print_str("export as namespace "); - self.id.gen(p, ctx); + self.id.print(p, ctx); p.print_semicolon_after_statement(); } } @@ -917,10 +925,10 @@ impl<'a> Gen for ExportSpecifier<'a> { if self.export_kind.is_type() { p.print_str("type "); } - self.local.gen(p, ctx); + self.local.print(p, ctx); if self.local.name() != self.exported.name() { p.print_str(" as "); - self.exported.gen(p, ctx); + self.exported.print(p, ctx); } } } @@ -929,8 +937,8 @@ impl<'a> Gen for ModuleExportName<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match self { Self::IdentifierName(identifier) => p.print_str(identifier.name.as_str()), - Self::IdentifierReference(identifier) => identifier.gen(p, ctx), - Self::StringLiteral(literal) => literal.gen(p, ctx), + Self::IdentifierReference(identifier) => identifier.print(p, ctx), + Self::StringLiteral(literal) => literal.print(p, ctx), }; } } @@ -947,14 +955,14 @@ impl<'a> Gen for ExportAllDeclaration<'a> { if let Some(exported) = &self.exported { p.print_str(" as "); - exported.gen(p, ctx); + exported.print(p, ctx); } p.print_str(" from "); - self.source.gen(p, ctx); + self.source.print(p, ctx); if let Some(with_clause) = &self.with_clause { p.print_hard_space(); - with_clause.gen(p, ctx); + with_clause.print(p, ctx); } p.print_semicolon_after_statement(); } @@ -965,7 +973,7 @@ impl<'a> Gen for ExportDefaultDeclaration<'a> { p.add_source_mapping(self.span.start); p.print_indent(); p.print_str("export default "); - self.declaration.gen(p, ctx); + self.declaration.print(p, ctx); } } impl<'a> Gen for ExportDefaultDeclarationKind<'a> { @@ -973,18 +981,18 @@ impl<'a> Gen for ExportDefaultDeclarationKind<'a> { match self { match_expression!(Self) => { p.start_of_default_export = p.code_len(); - self.to_expression().gen_expr(p, Precedence::Comma, Context::empty()); + self.to_expression().print_expr(p, Precedence::Comma, Context::empty()); p.print_semicolon_after_statement(); } Self::FunctionDeclaration(fun) => { - fun.gen(p, ctx); + fun.print(p, ctx); p.print_soft_newline(); } Self::ClassDeclaration(class) => { - class.gen(p, ctx); + class.print(p, ctx); p.print_soft_newline(); } - Self::TSInterfaceDeclaration(interface) => interface.gen(p, ctx), + Self::TSInterfaceDeclaration(interface) => interface.print(p, ctx), } } } @@ -992,55 +1000,55 @@ impl<'a> Gen for ExportDefaultDeclarationKind<'a> { impl<'a> GenExpr for Expression<'a> { fn gen_expr(&self, p: &mut Codegen, precedence: Precedence, ctx: Context) { match self { - Self::BooleanLiteral(lit) => lit.gen(p, ctx), - Self::NullLiteral(lit) => lit.gen(p, ctx), - Self::NumericLiteral(lit) => lit.gen(p, ctx), - Self::BigIntLiteral(lit) => lit.gen(p, ctx), - Self::RegExpLiteral(lit) => lit.gen(p, ctx), - Self::StringLiteral(lit) => lit.gen(p, ctx), - Self::Identifier(ident) => ident.gen(p, ctx), - Self::ThisExpression(expr) => expr.gen(p, ctx), + Self::BooleanLiteral(lit) => lit.print(p, ctx), + Self::NullLiteral(lit) => lit.print(p, ctx), + Self::NumericLiteral(lit) => lit.print(p, ctx), + Self::BigIntLiteral(lit) => lit.print(p, ctx), + Self::RegExpLiteral(lit) => lit.print(p, ctx), + Self::StringLiteral(lit) => lit.print(p, ctx), + Self::Identifier(ident) => ident.print(p, ctx), + Self::ThisExpression(expr) => expr.print(p, ctx), match_member_expression!(Self) => { - self.to_member_expression().gen_expr(p, precedence, ctx); - } - Self::CallExpression(expr) => expr.gen_expr(p, precedence, ctx), - Self::ArrayExpression(expr) => expr.gen(p, ctx), - Self::ObjectExpression(expr) => expr.gen_expr(p, precedence, ctx), - Self::FunctionExpression(expr) => expr.gen(p, ctx), - Self::ArrowFunctionExpression(expr) => expr.gen_expr(p, precedence, ctx), - Self::YieldExpression(expr) => expr.gen_expr(p, precedence, ctx), - Self::UpdateExpression(expr) => expr.gen_expr(p, precedence, ctx), - Self::UnaryExpression(expr) => expr.gen_expr(p, precedence, ctx), - Self::BinaryExpression(expr) => expr.gen_expr(p, precedence, ctx), - Self::PrivateInExpression(expr) => expr.gen_expr(p, precedence, ctx), - Self::LogicalExpression(expr) => expr.gen_expr(p, precedence, ctx), - Self::ConditionalExpression(expr) => expr.gen_expr(p, precedence, ctx), - Self::AssignmentExpression(expr) => expr.gen_expr(p, precedence, ctx), - Self::SequenceExpression(expr) => expr.gen_expr(p, precedence, ctx), - Self::ImportExpression(expr) => expr.gen_expr(p, precedence, ctx), - Self::TemplateLiteral(literal) => literal.gen(p, ctx), - Self::TaggedTemplateExpression(expr) => expr.gen(p, ctx), - Self::Super(sup) => sup.gen(p, ctx), - Self::AwaitExpression(expr) => expr.gen_expr(p, precedence, ctx), - Self::ChainExpression(expr) => expr.gen_expr(p, precedence, ctx), - Self::NewExpression(expr) => expr.gen_expr(p, precedence, ctx), - Self::MetaProperty(expr) => expr.gen(p, ctx), - Self::ClassExpression(expr) => expr.gen(p, ctx), - Self::JSXElement(el) => el.gen(p, ctx), - Self::JSXFragment(fragment) => fragment.gen(p, ctx), - Self::ParenthesizedExpression(e) => e.gen_expr(p, precedence, ctx), - Self::TSAsExpression(e) => e.gen_expr(p, precedence, ctx), - Self::TSSatisfiesExpression(e) => e.gen_expr(p, precedence, ctx), - Self::TSTypeAssertion(e) => e.gen_expr(p, precedence, ctx), - Self::TSNonNullExpression(e) => e.gen_expr(p, precedence, ctx), - Self::TSInstantiationExpression(e) => e.gen_expr(p, precedence, ctx), + self.to_member_expression().print_expr(p, precedence, ctx); + } + Self::CallExpression(expr) => expr.print_expr(p, precedence, ctx), + Self::ArrayExpression(expr) => expr.print(p, ctx), + Self::ObjectExpression(expr) => expr.print_expr(p, precedence, ctx), + Self::FunctionExpression(expr) => expr.print(p, ctx), + Self::ArrowFunctionExpression(expr) => expr.print_expr(p, precedence, ctx), + Self::YieldExpression(expr) => expr.print_expr(p, precedence, ctx), + Self::UpdateExpression(expr) => expr.print_expr(p, precedence, ctx), + Self::UnaryExpression(expr) => expr.print_expr(p, precedence, ctx), + Self::BinaryExpression(expr) => expr.print_expr(p, precedence, ctx), + Self::PrivateInExpression(expr) => expr.print_expr(p, precedence, ctx), + Self::LogicalExpression(expr) => expr.print_expr(p, precedence, ctx), + Self::ConditionalExpression(expr) => expr.print_expr(p, precedence, ctx), + Self::AssignmentExpression(expr) => expr.print_expr(p, precedence, ctx), + Self::SequenceExpression(expr) => expr.print_expr(p, precedence, ctx), + Self::ImportExpression(expr) => expr.print_expr(p, precedence, ctx), + Self::TemplateLiteral(literal) => literal.print(p, ctx), + Self::TaggedTemplateExpression(expr) => expr.print(p, ctx), + Self::Super(sup) => sup.print(p, ctx), + Self::AwaitExpression(expr) => expr.print_expr(p, precedence, ctx), + Self::ChainExpression(expr) => expr.print_expr(p, precedence, ctx), + Self::NewExpression(expr) => expr.print_expr(p, precedence, ctx), + Self::MetaProperty(expr) => expr.print(p, ctx), + Self::ClassExpression(expr) => expr.print(p, ctx), + Self::JSXElement(el) => el.print(p, ctx), + Self::JSXFragment(fragment) => fragment.print(p, ctx), + Self::ParenthesizedExpression(e) => e.print_expr(p, precedence, ctx), + Self::TSAsExpression(e) => e.print_expr(p, precedence, ctx), + Self::TSSatisfiesExpression(e) => e.print_expr(p, precedence, ctx), + Self::TSTypeAssertion(e) => e.print_expr(p, precedence, ctx), + Self::TSNonNullExpression(e) => e.print_expr(p, precedence, ctx), + Self::TSInstantiationExpression(e) => e.print_expr(p, precedence, ctx), } } } impl<'a> GenExpr for ParenthesizedExpression<'a> { fn gen_expr(&self, p: &mut Codegen, precedence: Precedence, ctx: Context) { - self.expression.gen_expr(p, precedence, ctx); + self.expression.print_expr(p, precedence, ctx); } } @@ -1331,28 +1339,28 @@ impl Gen for ThisExpression { impl<'a> GenExpr for MemberExpression<'a> { fn gen_expr(&self, p: &mut Codegen, precedence: Precedence, ctx: Context) { match self { - Self::ComputedMemberExpression(expr) => expr.gen_expr(p, precedence, ctx), - Self::StaticMemberExpression(expr) => expr.gen_expr(p, precedence, ctx), - Self::PrivateFieldExpression(expr) => expr.gen_expr(p, precedence, ctx), + Self::ComputedMemberExpression(expr) => expr.print_expr(p, precedence, ctx), + Self::StaticMemberExpression(expr) => expr.print_expr(p, precedence, ctx), + Self::PrivateFieldExpression(expr) => expr.print_expr(p, precedence, ctx), } } } impl<'a> GenExpr for ComputedMemberExpression<'a> { fn gen_expr(&self, p: &mut Codegen, _precedence: Precedence, ctx: Context) { - self.object.gen_expr(p, Precedence::Prefix, ctx.intersection(Context::FORBID_CALL)); + self.object.print_expr(p, Precedence::Prefix, ctx.intersection(Context::FORBID_CALL)); if self.optional { p.print_str("?."); } p.print_char(b'['); - self.expression.gen_expr(p, Precedence::Lowest, Context::empty()); + self.expression.print_expr(p, Precedence::Lowest, Context::empty()); p.print_char(b']'); } } impl<'a> GenExpr for StaticMemberExpression<'a> { fn gen_expr(&self, p: &mut Codegen, _precedence: Precedence, ctx: Context) { - self.object.gen_expr(p, Precedence::Postfix, ctx.intersection(Context::FORBID_CALL)); + self.object.print_expr(p, Precedence::Postfix, ctx.intersection(Context::FORBID_CALL)); if self.optional { p.print_char(b'?'); } else if p.need_space_before_dot == p.code_len() { @@ -1360,18 +1368,18 @@ impl<'a> GenExpr for StaticMemberExpression<'a> { p.print_hard_space(); } p.print_char(b'.'); - self.property.gen(p, ctx); + self.property.print(p, ctx); } } impl<'a> GenExpr for PrivateFieldExpression<'a> { fn gen_expr(&self, p: &mut Codegen, _precedence: Precedence, ctx: Context) { - self.object.gen_expr(p, Precedence::Prefix, ctx.intersection(Context::FORBID_CALL)); + self.object.print_expr(p, Precedence::Prefix, ctx.intersection(Context::FORBID_CALL)); if self.optional { p.print_str("?"); } p.print_char(b'.'); - self.field.gen(p, ctx); + self.field.print(p, ctx); } } @@ -1385,12 +1393,12 @@ impl<'a> GenExpr for CallExpression<'a> { p.wrap(wrap, |p| { p.print_comments(&annotate_comments, &mut AnnotationKind::empty()); p.add_source_mapping(self.span.start); - self.callee.gen_expr(p, Precedence::Postfix, Context::empty()); + self.callee.print_expr(p, Precedence::Postfix, Context::empty()); if self.optional { p.print_str("?."); } if let Some(type_parameters) = &self.type_parameters { - type_parameters.gen(p, ctx); + type_parameters.print(p, ctx); } p.print_char(b'('); p.print_list(&self.arguments, ctx); @@ -1403,9 +1411,9 @@ impl<'a> GenExpr for CallExpression<'a> { impl<'a> Gen for Argument<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match self { - Self::SpreadElement(elem) => elem.gen(p, ctx), + Self::SpreadElement(elem) => elem.print(p, ctx), match_expression!(Self) => { - self.to_expression().gen_expr(p, Precedence::Comma, Context::empty()); + self.to_expression().print_expr(p, Precedence::Comma, Context::empty()); } } } @@ -1415,9 +1423,9 @@ impl<'a> Gen for ArrayExpressionElement<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match self { match_expression!(Self) => { - self.to_expression().gen_expr(p, Precedence::Comma, Context::empty()); + self.to_expression().print_expr(p, Precedence::Comma, Context::empty()); } - Self::SpreadElement(elem) => elem.gen(p, ctx), + Self::SpreadElement(elem) => elem.print(p, ctx), Self::Elision(_span) => p.print_comma(), } } @@ -1427,7 +1435,7 @@ impl<'a> Gen for SpreadElement<'a> { fn gen(&self, p: &mut Codegen, _ctx: Context) { p.add_source_mapping(self.span.start); p.print_ellipsis(); - self.argument.gen_expr(p, Precedence::Comma, Context::empty()); + self.argument.print_expr(p, Precedence::Comma, Context::empty()); } } @@ -1436,7 +1444,7 @@ impl<'a> Gen for ArrayExpression<'a> { p.add_source_mapping(self.span.start); p.print_char(b'['); for (index, item) in self.elements.iter().enumerate() { - item.gen(p, ctx); + item.print(p, ctx); if index != self.elements.len() - 1 { if !matches!(item, ArrayExpressionElement::Elision(_)) { p.print_comma(); @@ -1471,7 +1479,7 @@ impl<'a> GenExpr for ObjectExpression<'a> { } else { p.print_soft_space(); } - item.gen(p, ctx); + item.print(p, ctx); } if is_multi_line { p.print_soft_newline(); @@ -1489,8 +1497,8 @@ impl<'a> GenExpr for ObjectExpression<'a> { impl<'a> Gen for ObjectPropertyKind<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match self { - Self::ObjectProperty(prop) => prop.gen(p, ctx), - Self::SpreadProperty(elem) => elem.gen(p, ctx), + Self::ObjectProperty(prop) => prop.print(p, ctx), + Self::SpreadProperty(elem) => elem.print(p, ctx), } } } @@ -1522,19 +1530,19 @@ impl<'a> Gen for ObjectProperty<'a> { if self.computed { p.print_char(b'['); } - self.key.gen(p, ctx); + self.key.print(p, ctx); if self.computed { p.print_char(b']'); } if let Some(type_parameters) = &func.type_parameters { - type_parameters.gen(p, ctx); + type_parameters.print(p, ctx); } p.print_char(b'('); - func.params.gen(p, ctx); + func.params.print(p, ctx); p.print_char(b')'); if let Some(body) = &func.body { p.print_soft_space(); - body.gen(p, ctx); + body.print(p, ctx); } return; } @@ -1553,7 +1561,7 @@ impl<'a> Gen for ObjectProperty<'a> { p.print_char(b'['); } if !shorthand { - self.key.gen(p, ctx); + self.key.print(p, ctx); } if self.computed { p.print_char(b']'); @@ -1562,17 +1570,17 @@ impl<'a> Gen for ObjectProperty<'a> { p.print_colon(); p.print_soft_space(); } - self.value.gen_expr(p, Precedence::Comma, Context::empty()); + self.value.print_expr(p, Precedence::Comma, Context::empty()); } } impl<'a> Gen for PropertyKey<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match self { - Self::StaticIdentifier(ident) => ident.gen(p, ctx), - Self::PrivateIdentifier(ident) => ident.gen(p, ctx), + Self::StaticIdentifier(ident) => ident.print(p, ctx), + Self::PrivateIdentifier(ident) => ident.print(p, ctx), match_expression!(Self) => { - self.to_expression().gen_expr(p, Precedence::Comma, Context::empty()); + self.to_expression().print_expr(p, Precedence::Comma, Context::empty()); } } } @@ -1592,16 +1600,16 @@ impl<'a> GenExpr for ArrowFunctionExpression<'a> { } if let Some(type_parameters) = &self.type_parameters { - type_parameters.gen(p, ctx); + type_parameters.print(p, ctx); } p.add_source_mapping(self.span.start); p.print_char(b'('); - self.params.gen(p, ctx); + self.params.print(p, ctx); p.print_char(b')'); if let Some(return_type) = &self.return_type { p.print_str(":"); p.print_soft_space(); - return_type.gen(p, ctx); + return_type.print(p, ctx); } p.print_soft_space(); p.print_str("=>"); @@ -1609,10 +1617,10 @@ impl<'a> GenExpr for ArrowFunctionExpression<'a> { if self.expression { if let Some(Statement::ExpressionStatement(stmt)) = &self.body.statements.first() { p.start_of_arrow_expr = p.code_len(); - stmt.expression.gen_expr(p, Precedence::Comma, ctx.and_forbid_in(true)); + stmt.expression.print_expr(p, Precedence::Comma, ctx.and_forbid_in(true)); } } else { - self.body.gen(p, ctx); + self.body.print(p, ctx); } }); } @@ -1632,7 +1640,7 @@ impl<'a> GenExpr for YieldExpression<'a> { if !self.delegate { p.print_hard_space(); } - argument.gen_expr(p, Precedence::Yield, Context::empty()); + argument.print_expr(p, Precedence::Yield, Context::empty()); } }); } @@ -1648,10 +1656,10 @@ impl<'a> GenExpr for UpdateExpression<'a> { p.print_str(operator); p.prev_op = Some(self.operator.into()); p.prev_op_end = p.code().len(); - self.argument.gen_expr(p, Precedence::Prefix, ctx); + self.argument.print_expr(p, Precedence::Prefix, ctx); } else { p.print_space_before_operator(self.operator.into()); - self.argument.gen_expr(p, Precedence::Postfix, ctx); + self.argument.print_expr(p, Precedence::Postfix, ctx); p.print_str(operator); p.prev_op = Some(self.operator.into()); p.prev_op_end = p.code().len(); @@ -1674,7 +1682,7 @@ impl<'a> GenExpr for UnaryExpression<'a> { p.prev_op = Some(self.operator.into()); p.prev_op_end = p.code().len(); } - self.argument.gen_expr(p, Precedence::Exponentiation, ctx); + self.argument.print_expr(p, Precedence::Exponentiation, ctx); }); } } @@ -1702,9 +1710,9 @@ impl<'a> GenExpr for BinaryExpression<'a> { impl<'a> GenExpr for PrivateInExpression<'a> { fn gen_expr(&self, p: &mut Codegen, precedence: Precedence, ctx: Context) { p.wrap(precedence >= Precedence::Compare, |p| { - self.left.gen(p, ctx); + self.left.print(p, ctx); p.print_str(" in "); - self.right.gen_expr(p, Precedence::Equals, Context::empty()); + self.right.print_expr(p, Precedence::Equals, Context::empty()); }); } } @@ -1737,15 +1745,15 @@ impl<'a> GenExpr for ConditionalExpression<'a> { ctx &= Context::FORBID_IN.not(); } p.wrap(wrap, |p| { - self.test.gen_expr(p, Precedence::Conditional, ctx & Context::FORBID_IN); + self.test.print_expr(p, Precedence::Conditional, ctx & Context::FORBID_IN); p.print_soft_space(); p.print_char(b'?'); p.print_soft_space(); - self.consequent.gen_expr(p, Precedence::Yield, Context::empty()); + self.consequent.print_expr(p, Precedence::Yield, Context::empty()); p.print_soft_space(); p.print_colon(); p.print_soft_space(); - self.alternate.gen_expr(p, Precedence::Yield, ctx & Context::FORBID_IN); + self.alternate.print_expr(p, Precedence::Yield, ctx & Context::FORBID_IN); }); } } @@ -1778,11 +1786,11 @@ impl<'a> GenExpr for AssignmentExpression<'a> { && matches!(self.left, AssignmentTarget::ObjectAssignmentTarget(_))) || identifier_is_keyword; p.wrap(wrap || precedence >= self.precedence(), |p| { - self.left.gen(p, ctx); + self.left.print(p, ctx); p.print_soft_space(); p.print_str(self.operator.as_str()); p.print_soft_space(); - self.right.gen_expr(p, Precedence::Comma, ctx); + self.right.print_expr(p, Precedence::Comma, ctx); }); } } @@ -1791,10 +1799,14 @@ impl<'a> Gen for AssignmentTarget<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match self { match_simple_assignment_target!(Self) => { - self.to_simple_assignment_target().gen_expr(p, Precedence::Comma, Context::empty()); + self.to_simple_assignment_target().print_expr( + p, + Precedence::Comma, + Context::empty(), + ); } match_assignment_target_pattern!(Self) => { - self.to_assignment_target_pattern().gen(p, ctx); + self.to_assignment_target_pattern().print(p, ctx); } } } @@ -1803,15 +1815,15 @@ impl<'a> Gen for AssignmentTarget<'a> { impl<'a> GenExpr for SimpleAssignmentTarget<'a> { fn gen_expr(&self, p: &mut Codegen, precedence: Precedence, ctx: Context) { match self { - Self::AssignmentTargetIdentifier(ident) => ident.gen(p, ctx), + Self::AssignmentTargetIdentifier(ident) => ident.print(p, ctx), match_member_expression!(Self) => { - self.to_member_expression().gen_expr(p, precedence, ctx); + self.to_member_expression().print_expr(p, precedence, ctx); } - Self::TSAsExpression(e) => e.gen_expr(p, precedence, ctx), - Self::TSSatisfiesExpression(e) => e.gen_expr(p, precedence, ctx), - Self::TSNonNullExpression(e) => e.gen_expr(p, precedence, ctx), - Self::TSTypeAssertion(e) => e.gen_expr(p, precedence, ctx), - Self::TSInstantiationExpression(e) => e.gen_expr(p, precedence, ctx), + Self::TSAsExpression(e) => e.print_expr(p, precedence, ctx), + Self::TSSatisfiesExpression(e) => e.print_expr(p, precedence, ctx), + Self::TSNonNullExpression(e) => e.print_expr(p, precedence, ctx), + Self::TSTypeAssertion(e) => e.print_expr(p, precedence, ctx), + Self::TSInstantiationExpression(e) => e.print_expr(p, precedence, ctx), } } } @@ -1819,8 +1831,8 @@ impl<'a> GenExpr for SimpleAssignmentTarget<'a> { impl<'a> Gen for AssignmentTargetPattern<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match self { - Self::ArrayAssignmentTarget(target) => target.gen(p, ctx), - Self::ObjectAssignmentTarget(target) => target.gen(p, ctx), + Self::ArrayAssignmentTarget(target) => target.print(p, ctx), + Self::ObjectAssignmentTarget(target) => target.print(p, ctx), } } } @@ -1835,7 +1847,7 @@ impl<'a> Gen for ArrayAssignmentTarget<'a> { p.print_soft_space(); } if let Some(item) = item { - item.gen(p, ctx); + item.print(p, ctx); } } if let Some(target) = &self.rest { @@ -1843,7 +1855,7 @@ impl<'a> Gen for ArrayAssignmentTarget<'a> { p.print_comma(); } p.add_source_mapping(self.span.start); - target.gen(p, ctx); + target.print(p, ctx); } if self.trailing_comma.is_some() { p.print_comma(); @@ -1863,7 +1875,7 @@ impl<'a> Gen for ObjectAssignmentTarget<'a> { p.print_comma(); } p.add_source_mapping(self.span.start); - target.gen(p, ctx); + target.print(p, ctx); } p.print_char(b'}'); p.add_source_mapping(self.span.end); @@ -1873,27 +1885,27 @@ impl<'a> Gen for ObjectAssignmentTarget<'a> { impl<'a> Gen for AssignmentTargetMaybeDefault<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match self { - match_assignment_target!(Self) => self.to_assignment_target().gen(p, ctx), - Self::AssignmentTargetWithDefault(target) => target.gen(p, ctx), + match_assignment_target!(Self) => self.to_assignment_target().print(p, ctx), + Self::AssignmentTargetWithDefault(target) => target.print(p, ctx), } } } impl<'a> Gen for AssignmentTargetWithDefault<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { - self.binding.gen(p, ctx); + self.binding.print(p, ctx); p.print_soft_space(); p.print_equal(); p.print_soft_space(); - self.init.gen_expr(p, Precedence::Comma, Context::empty()); + self.init.print_expr(p, Precedence::Comma, Context::empty()); } } impl<'a> Gen for AssignmentTargetProperty<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match self { - Self::AssignmentTargetPropertyIdentifier(ident) => ident.gen(p, ctx), - Self::AssignmentTargetPropertyProperty(prop) => prop.gen(p, ctx), + Self::AssignmentTargetPropertyIdentifier(ident) => ident.print(p, ctx), + Self::AssignmentTargetPropertyProperty(prop) => prop.print(p, ctx), } } } @@ -1902,7 +1914,7 @@ impl<'a> Gen for AssignmentTargetPropertyIdentifier<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { let ident_name = p.get_identifier_reference_name(&self.binding).to_owned(); if ident_name == self.binding.name.as_str() { - self.binding.gen(p, ctx); + self.binding.print(p, ctx); } else { // `({x: a} = y);` p.print_str(self.binding.name.as_str()); @@ -1914,7 +1926,7 @@ impl<'a> Gen for AssignmentTargetPropertyIdentifier<'a> { p.print_soft_space(); p.print_equal(); p.print_soft_space(); - expr.gen_expr(p, Precedence::Comma, Context::empty()); + expr.print_expr(p, Precedence::Comma, Context::empty()); } } } @@ -1923,27 +1935,27 @@ impl<'a> Gen for AssignmentTargetPropertyProperty<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match &self.name { PropertyKey::StaticIdentifier(ident) => { - ident.gen(p, ctx); + ident.print(p, ctx); } PropertyKey::PrivateIdentifier(ident) => { - ident.gen(p, ctx); + ident.print(p, ctx); } key @ match_expression!(PropertyKey) => { p.print_char(b'['); - key.to_expression().gen_expr(p, Precedence::Comma, Context::empty()); + key.to_expression().print_expr(p, Precedence::Comma, Context::empty()); p.print_char(b']'); } } p.print_colon(); p.print_soft_space(); - self.binding.gen(p, ctx); + self.binding.print(p, ctx); } } impl<'a> Gen for AssignmentTargetRest<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { p.print_ellipsis(); - self.target.gen(p, ctx); + self.target.print(p, ctx); } } @@ -1961,7 +1973,7 @@ impl<'a> GenExpr for ImportExpression<'a> { p.wrap(wrap, |p| { p.add_source_mapping(self.span.start); p.print_str("import("); - self.source.gen_expr(p, Precedence::Comma, Context::empty()); + self.source.print_expr(p, Precedence::Comma, Context::empty()); if !self.arguments.is_empty() { p.print_comma(); p.print_expressions(&self.arguments, Precedence::Comma, Context::empty()); @@ -1994,11 +2006,11 @@ impl<'a> Gen for TemplateLiteral<'a> { impl<'a> Gen for TaggedTemplateExpression<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { p.add_source_mapping(self.span.start); - self.tag.gen_expr(p, Precedence::Postfix, Context::empty()); + self.tag.print_expr(p, Precedence::Postfix, Context::empty()); if let Some(type_parameters) = &self.type_parameters { - type_parameters.gen(p, ctx); + type_parameters.print(p, ctx); } - self.quasi.gen(p, ctx); + self.quasi.print(p, ctx); } } @@ -2014,7 +2026,7 @@ impl<'a> GenExpr for AwaitExpression<'a> { p.wrap(precedence >= self.precedence(), |p| { p.add_source_mapping(self.span.start); p.print_str("await "); - self.argument.gen_expr(p, Precedence::Exponentiation, ctx); + self.argument.print_expr(p, Precedence::Exponentiation, ctx); }); } } @@ -2022,9 +2034,9 @@ impl<'a> GenExpr for AwaitExpression<'a> { impl<'a> GenExpr for ChainExpression<'a> { fn gen_expr(&self, p: &mut Codegen, precedence: Precedence, ctx: Context) { match &self.expression { - ChainElement::CallExpression(expr) => expr.gen_expr(p, precedence, ctx), + ChainElement::CallExpression(expr) => expr.print_expr(p, precedence, ctx), match_member_expression!(ChainElement) => { - self.expression.to_member_expression().gen_expr(p, precedence, ctx); + self.expression.to_member_expression().print_expr(p, precedence, ctx); } } } @@ -2042,7 +2054,7 @@ impl<'a> GenExpr for NewExpression<'a> { p.print_space_before_identifier(); p.add_source_mapping(self.span.start); p.print_str("new "); - self.callee.gen_expr(p, Precedence::New, Context::FORBID_CALL); + self.callee.print_expr(p, Precedence::New, Context::FORBID_CALL); p.print_char(b'('); p.print_list(&self.arguments, ctx); p.print_char(b')'); @@ -2054,10 +2066,10 @@ impl<'a> GenExpr for TSAsExpression<'a> { fn gen_expr(&self, p: &mut Codegen, precedence: Precedence, ctx: Context) { p.print_char(b'('); p.print_char(b'('); - self.expression.gen_expr(p, precedence, Context::default()); + self.expression.print_expr(p, precedence, Context::default()); p.print_char(b')'); p.print_str(" as "); - self.type_annotation.gen(p, ctx); + self.type_annotation.print(p, ctx); p.print_char(b')'); } } @@ -2066,10 +2078,10 @@ impl<'a> GenExpr for TSSatisfiesExpression<'a> { fn gen_expr(&self, p: &mut Codegen, precedence: Precedence, ctx: Context) { p.print_char(b'('); p.print_char(b'('); - self.expression.gen_expr(p, precedence, Context::default()); + self.expression.print_expr(p, precedence, Context::default()); p.print_char(b')'); p.print_str(" satisfies "); - self.type_annotation.gen(p, ctx); + self.type_annotation.print(p, ctx); p.print_char(b')'); } } @@ -2077,7 +2089,7 @@ impl<'a> GenExpr for TSSatisfiesExpression<'a> { impl<'a> GenExpr for TSNonNullExpression<'a> { fn gen_expr(&self, p: &mut Codegen, precedence: Precedence, ctx: Context) { p.wrap(matches!(self.expression, Expression::ParenthesizedExpression(_)), |p| { - self.expression.gen_expr(p, precedence, ctx); + self.expression.print_expr(p, precedence, ctx); }); p.print_char(b'!'); if p.options.minify { @@ -2088,8 +2100,8 @@ impl<'a> GenExpr for TSNonNullExpression<'a> { impl<'a> GenExpr for TSInstantiationExpression<'a> { fn gen_expr(&self, p: &mut Codegen, precedence: Precedence, ctx: Context) { - self.expression.gen_expr(p, precedence, ctx); - self.type_parameters.gen(p, ctx); + self.expression.print_expr(p, precedence, ctx); + self.type_parameters.print(p, ctx); if p.options.minify { p.print_hard_space(); } @@ -2105,9 +2117,9 @@ impl<'a> GenExpr for TSTypeAssertion<'a> { if matches!(self.type_annotation, TSType::TSFunctionType(_)) { p.print_hard_space(); } - self.type_annotation.gen(p, ctx); + self.type_annotation.print(p, ctx); p.print_str(">"); - self.expression.gen_expr(p, Precedence::Member, ctx); + self.expression.print_expr(p, Precedence::Member, ctx); }); } } @@ -2115,9 +2127,9 @@ impl<'a> GenExpr for TSTypeAssertion<'a> { impl<'a> Gen for MetaProperty<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { p.add_source_mapping(self.span.start); - self.meta.gen(p, ctx); + self.meta.print(p, ctx); p.print_char(b'.'); - self.property.gen(p, ctx); + self.property.print(p, ctx); } } @@ -2128,7 +2140,7 @@ impl<'a> Gen for Class<'a> { let wrap = self.is_expression() && (p.start_of_stmt == n || p.start_of_default_export == n); p.wrap(wrap, |p| { for decorator in &self.decorators { - decorator.gen(p, ctx); + decorator.print(p, ctx); p.print_hard_space(); } if self.declare { @@ -2140,16 +2152,16 @@ impl<'a> Gen for Class<'a> { p.print_str("class"); if let Some(id) = &self.id { p.print_hard_space(); - id.gen(p, ctx); + id.print(p, ctx); if let Some(type_parameters) = self.type_parameters.as_ref() { - type_parameters.gen(p, ctx); + type_parameters.print(p, ctx); } } if let Some(super_class) = self.super_class.as_ref() { p.print_str(" extends "); - super_class.gen_expr(p, Precedence::Call, Context::empty()); + super_class.print_expr(p, Precedence::Call, Context::empty()); if let Some(super_type_parameters) = &self.super_type_parameters { - super_type_parameters.gen(p, ctx); + super_type_parameters.print(p, ctx); } } if let Some(implements) = self.implements.as_ref() { @@ -2157,7 +2169,7 @@ impl<'a> Gen for Class<'a> { p.print_list(implements, ctx); } p.print_soft_space(); - self.body.gen(p, ctx); + self.body.print(p, ctx); p.needs_semicolon = false; }); } @@ -2169,7 +2181,7 @@ impl<'a> Gen for ClassBody<'a> { for item in &self.body { p.print_semicolon_if_needed(); p.print_indent(); - item.gen(p, ctx); + item.print(p, ctx); } }); } @@ -2179,23 +2191,23 @@ impl<'a> Gen for ClassElement<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match self { Self::StaticBlock(elem) => { - elem.gen(p, ctx); + elem.print(p, ctx); p.print_soft_newline(); } Self::MethodDefinition(elem) => { - elem.gen(p, ctx); + elem.print(p, ctx); p.print_soft_newline(); } Self::PropertyDefinition(elem) => { - elem.gen(p, ctx); + elem.print(p, ctx); p.print_semicolon_after_statement(); } Self::AccessorProperty(elem) => { - elem.gen(p, ctx); + elem.print(p, ctx); p.print_semicolon_after_statement(); } Self::TSIndexSignature(elem) => { - elem.gen(p, ctx); + elem.print(p, ctx); p.print_semicolon_after_statement(); } } @@ -2212,56 +2224,56 @@ impl<'a> Gen for JSXIdentifier<'a> { impl<'a> Gen for JSXMemberExpressionObject<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match self { - Self::IdentifierReference(ident) => ident.gen(p, ctx), - Self::MemberExpression(member_expr) => member_expr.gen(p, ctx), - Self::ThisExpression(expr) => expr.gen(p, ctx), + Self::IdentifierReference(ident) => ident.print(p, ctx), + Self::MemberExpression(member_expr) => member_expr.print(p, ctx), + Self::ThisExpression(expr) => expr.print(p, ctx), } } } impl<'a> Gen for JSXMemberExpression<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { - self.object.gen(p, ctx); + self.object.print(p, ctx); p.print_char(b'.'); - self.property.gen(p, ctx); + self.property.print(p, ctx); } } impl<'a> Gen for JSXElementName<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match self { - Self::Identifier(identifier) => identifier.gen(p, ctx), - Self::IdentifierReference(identifier) => identifier.gen(p, ctx), - Self::NamespacedName(namespaced_name) => namespaced_name.gen(p, ctx), - Self::MemberExpression(member_expr) => member_expr.gen(p, ctx), - Self::ThisExpression(expr) => expr.gen(p, ctx), + Self::Identifier(identifier) => identifier.print(p, ctx), + Self::IdentifierReference(identifier) => identifier.print(p, ctx), + Self::NamespacedName(namespaced_name) => namespaced_name.print(p, ctx), + Self::MemberExpression(member_expr) => member_expr.print(p, ctx), + Self::ThisExpression(expr) => expr.print(p, ctx), } } } impl<'a> Gen for JSXNamespacedName<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { - self.namespace.gen(p, ctx); + self.namespace.print(p, ctx); p.print_colon(); - self.property.gen(p, ctx); + self.property.print(p, ctx); } } impl<'a> Gen for JSXAttributeName<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match self { - Self::Identifier(ident) => ident.gen(p, ctx), - Self::NamespacedName(namespaced_name) => namespaced_name.gen(p, ctx), + Self::Identifier(ident) => ident.print(p, ctx), + Self::NamespacedName(namespaced_name) => namespaced_name.print(p, ctx), } } } impl<'a> Gen for JSXAttribute<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { - self.name.gen(p, ctx); + self.name.print(p, ctx); if let Some(value) = &self.value { p.print_equal(); - value.gen(p, ctx); + value.print(p, ctx); } } } @@ -2274,7 +2286,7 @@ impl<'a> Gen for JSXExpression<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match self { match_expression!(Self) => p.print_expression(self.to_expression()), - Self::EmptyExpression(expr) => expr.gen(p, ctx), + Self::EmptyExpression(expr) => expr.print(p, ctx), } } } @@ -2282,7 +2294,7 @@ impl<'a> Gen for JSXExpression<'a> { impl<'a> Gen for JSXExpressionContainer<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { p.print_char(b'{'); - self.expression.gen(p, ctx); + self.expression.print(p, ctx); p.print_char(b'}'); } } @@ -2290,15 +2302,15 @@ impl<'a> Gen for JSXExpressionContainer<'a> { impl<'a> Gen for JSXAttributeValue<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match self { - Self::Fragment(fragment) => fragment.gen(p, ctx), - Self::Element(el) => el.gen(p, ctx), + Self::Fragment(fragment) => fragment.print(p, ctx), + Self::Element(el) => el.print(p, ctx), Self::StringLiteral(lit) => { let quote = if lit.value.contains('"') { b'\'' } else { b'"' }; p.print_char(quote); p.print_str(&lit.value); p.print_char(quote); } - Self::ExpressionContainer(expr_container) => expr_container.gen(p, ctx), + Self::ExpressionContainer(expr_container) => expr_container.print(p, ctx), } } } @@ -2306,7 +2318,7 @@ impl<'a> Gen for JSXAttributeValue<'a> { impl<'a> Gen for JSXSpreadAttribute<'a> { fn gen(&self, p: &mut Codegen, _ctx: Context) { p.print_str("{..."); - self.argument.gen_expr(p, Precedence::Comma, Context::empty()); + self.argument.print_expr(p, Precedence::Comma, Context::empty()); p.print_char(b'}'); } } @@ -2314,8 +2326,8 @@ impl<'a> Gen for JSXSpreadAttribute<'a> { impl<'a> Gen for JSXAttributeItem<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match self { - Self::Attribute(attr) => attr.gen(p, ctx), - Self::SpreadAttribute(spread_attr) => spread_attr.gen(p, ctx), + Self::Attribute(attr) => attr.print(p, ctx), + Self::SpreadAttribute(spread_attr) => spread_attr.print(p, ctx), } } } @@ -2324,7 +2336,7 @@ impl<'a> Gen for JSXOpeningElement<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { p.add_source_mapping(self.span.start); p.print_char(b'<'); - self.name.gen(p, ctx); + self.name.print(p, ctx); for attr in &self.attributes { match attr { JSXAttributeItem::Attribute(_) => { @@ -2334,7 +2346,7 @@ impl<'a> Gen for JSXOpeningElement<'a> { p.print_soft_space(); } } - attr.gen(p, ctx); + attr.print(p, ctx); } if self.self_closing { p.print_soft_space(); @@ -2348,19 +2360,19 @@ impl<'a> Gen for JSXClosingElement<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { p.add_source_mapping(self.span.start); p.print_str("'); } } impl<'a> Gen for JSXElement<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { - self.opening_element.gen(p, ctx); + self.opening_element.print(p, ctx); for child in &self.children { - child.gen(p, ctx); + child.print(p, ctx); } if let Some(closing_element) = &self.closing_element { - closing_element.gen(p, ctx); + closing_element.print(p, ctx); } } } @@ -2396,22 +2408,22 @@ impl<'a> Gen for JSXSpreadChild<'a> { impl<'a> Gen for JSXChild<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match self { - Self::Fragment(fragment) => fragment.gen(p, ctx), - Self::Element(el) => el.gen(p, ctx), + Self::Fragment(fragment) => fragment.print(p, ctx), + Self::Element(el) => el.print(p, ctx), Self::Spread(spread) => p.print_expression(&spread.expression), - Self::ExpressionContainer(expr_container) => expr_container.gen(p, ctx), - Self::Text(text) => text.gen(p, ctx), + Self::ExpressionContainer(expr_container) => expr_container.print(p, ctx), + Self::Text(text) => text.print(p, ctx), } } } impl<'a> Gen for JSXFragment<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { - self.opening_fragment.gen(p, ctx); + self.opening_fragment.print(p, ctx); for child in &self.children { - child.gen(p, ctx); + child.print(p, ctx); } - self.closing_fragment.gen(p, ctx); + self.closing_fragment.print(p, ctx); } } @@ -2423,7 +2435,7 @@ impl<'a> Gen for StaticBlock<'a> { p.print_curly_braces(self.span, self.body.is_empty(), |p| { for stmt in &self.body { p.print_semicolon_if_needed(); - stmt.gen(p, ctx); + stmt.print(p, ctx); } }); p.needs_semicolon = false; @@ -2434,7 +2446,7 @@ impl<'a> Gen for MethodDefinition<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { p.add_source_mapping(self.span.start); for decorator in &self.decorators { - decorator.gen(p, ctx); + decorator.print(p, ctx); p.print_hard_space(); } @@ -2470,7 +2482,7 @@ impl<'a> Gen for MethodDefinition<'a> { if self.computed { p.print_char(b'['); } - self.key.gen(p, ctx); + self.key.print(p, ctx); if self.computed { p.print_char(b']'); } @@ -2478,19 +2490,19 @@ impl<'a> Gen for MethodDefinition<'a> { p.print_char(b'?'); } if let Some(type_parameters) = self.value.type_parameters.as_ref() { - type_parameters.gen(p, ctx); + type_parameters.print(p, ctx); } p.print_char(b'('); - self.value.params.gen(p, ctx); + self.value.params.print(p, ctx); p.print_char(b')'); if let Some(return_type) = &self.value.return_type { p.print_colon(); p.print_soft_space(); - return_type.gen(p, ctx); + return_type.print(p, ctx); } if let Some(body) = &self.value.body { p.print_soft_space(); - body.gen(p, ctx); + body.print(p, ctx); } else { p.print_semicolon(); } @@ -2501,7 +2513,7 @@ impl<'a> Gen for PropertyDefinition<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { p.add_source_mapping(self.span.start); for decorator in &self.decorators { - decorator.gen(p, ctx); + decorator.print(p, ctx); p.print_hard_space(); } if self.declare { @@ -2523,7 +2535,7 @@ impl<'a> Gen for PropertyDefinition<'a> { if self.computed { p.print_char(b'['); } - self.key.gen(p, ctx); + self.key.print(p, ctx); if self.computed { p.print_char(b']'); } @@ -2533,13 +2545,13 @@ impl<'a> Gen for PropertyDefinition<'a> { if let Some(type_annotation) = &self.type_annotation { p.print_colon(); p.print_soft_space(); - type_annotation.gen(p, ctx); + type_annotation.print(p, ctx); } if let Some(value) = &self.value { p.print_soft_space(); p.print_equal(); p.print_soft_space(); - value.gen_expr(p, Precedence::Comma, Context::empty()); + value.print_expr(p, Precedence::Comma, Context::empty()); } } } @@ -2548,7 +2560,7 @@ impl<'a> Gen for AccessorProperty<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { p.add_source_mapping(self.span.start); for decorator in &self.decorators { - decorator.gen(p, ctx); + decorator.print(p, ctx); p.print_hard_space(); } if self.r#type.is_abstract() { @@ -2568,20 +2580,20 @@ impl<'a> Gen for AccessorProperty<'a> { } else { p.print_hard_space(); } - self.key.gen(p, ctx); + self.key.print(p, ctx); if self.computed { p.print_char(b']'); } if let Some(type_annotation) = &self.type_annotation { p.print_colon(); p.print_soft_space(); - type_annotation.gen(p, ctx); + type_annotation.print(p, ctx); } if let Some(value) = &self.value { p.print_soft_space(); p.print_equal(); p.print_soft_space(); - value.gen_expr(p, Precedence::Comma, Context::empty()); + value.print_expr(p, Precedence::Comma, Context::empty()); } } } @@ -2597,10 +2609,10 @@ impl<'a> Gen for PrivateIdentifier<'a> { impl<'a> Gen for BindingPattern<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match &self.kind { - BindingPatternKind::BindingIdentifier(ident) => ident.gen(p, ctx), - BindingPatternKind::ObjectPattern(pattern) => pattern.gen(p, ctx), - BindingPatternKind::ArrayPattern(pattern) => pattern.gen(p, ctx), - BindingPatternKind::AssignmentPattern(pattern) => pattern.gen(p, ctx), + BindingPatternKind::BindingIdentifier(ident) => ident.print(p, ctx), + BindingPatternKind::ObjectPattern(pattern) => pattern.print(p, ctx), + BindingPatternKind::ArrayPattern(pattern) => pattern.print(p, ctx), + BindingPatternKind::AssignmentPattern(pattern) => pattern.print(p, ctx), } if self.optional { p.print_str("?"); @@ -2608,7 +2620,7 @@ impl<'a> Gen for BindingPattern<'a> { if let Some(type_annotation) = &self.type_annotation { p.print_colon(); p.print_soft_space(); - type_annotation.gen(p, ctx); + type_annotation.print(p, ctx); } } } @@ -2623,7 +2635,7 @@ impl<'a> Gen for ObjectPattern<'a> { if !self.properties.is_empty() { p.print_comma(); } - rest.gen(p, ctx); + rest.print(p, ctx); } p.print_soft_space(); p.print_char(b'}'); @@ -2660,7 +2672,7 @@ impl<'a> Gen for BindingProperty<'a> { } if !shorthand { - self.key.gen(p, ctx); + self.key.print(p, ctx); } if self.computed { p.print_char(b']'); @@ -2669,7 +2681,7 @@ impl<'a> Gen for BindingProperty<'a> { p.print_colon(); p.print_soft_space(); } - self.value.gen(p, ctx); + self.value.print(p, ctx); } } @@ -2677,7 +2689,7 @@ impl<'a> Gen for BindingRestElement<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { p.add_source_mapping(self.span.start); p.print_ellipsis(); - self.argument.gen(p, ctx); + self.argument.print(p, ctx); } } @@ -2691,7 +2703,7 @@ impl<'a> Gen for ArrayPattern<'a> { p.print_soft_space(); } if let Some(item) = item { - item.gen(p, ctx); + item.print(p, ctx); } if index == self.elements.len() - 1 && (item.is_none() || self.rest.is_some()) { p.print_comma(); @@ -2699,7 +2711,7 @@ impl<'a> Gen for ArrayPattern<'a> { } if let Some(rest) = &self.rest { p.print_soft_space(); - rest.gen(p, ctx); + rest.print(p, ctx); } p.print_char(b']'); p.add_source_mapping(self.span.end); @@ -2708,11 +2720,11 @@ impl<'a> Gen for ArrayPattern<'a> { impl<'a> Gen for AssignmentPattern<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { - self.left.gen(p, ctx); + self.left.print(p, ctx); p.print_soft_space(); p.print_equal(); p.print_soft_space(); - self.right.gen_expr(p, Precedence::Comma, Context::empty()); + self.right.print_expr(p, Precedence::Comma, Context::empty()); } } @@ -2738,16 +2750,16 @@ impl<'a> Gen for Decorator<'a> { p.print_char(b'@'); let wrap = need_wrap(&self.expression); p.wrap(wrap, |p| { - self.expression.gen_expr(p, Precedence::Lowest, Context::empty()); + self.expression.print_expr(p, Precedence::Lowest, Context::empty()); }); } } impl<'a> Gen for TSClassImplements<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { - self.expression.gen(p, ctx); + self.expression.print(p, ctx); if let Some(type_parameters) = self.type_parameters.as_ref() { - type_parameters.gen(p, ctx); + type_parameters.print(p, ctx); } } } @@ -2762,28 +2774,28 @@ impl<'a> Gen for TSTypeParameterDeclaration<'a> { impl<'a> Gen for TSTypeAnnotation<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { - self.type_annotation.gen(p, ctx); + self.type_annotation.print(p, ctx); } } impl<'a> Gen for TSType<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match self { - Self::TSFunctionType(ty) => ty.gen(p, ctx), - Self::TSConstructorType(ty) => ty.gen(p, ctx), - Self::TSArrayType(ty) => ty.gen(p, ctx), - Self::TSTupleType(ty) => ty.gen(p, ctx), - Self::TSUnionType(ty) => ty.gen(p, ctx), - Self::TSParenthesizedType(ty) => ty.gen(p, ctx), - Self::TSIntersectionType(ty) => ty.gen(p, ctx), - Self::TSConditionalType(ty) => ty.gen(p, ctx), - Self::TSInferType(ty) => ty.gen(p, ctx), - Self::TSIndexedAccessType(ty) => ty.gen(p, ctx), - Self::TSMappedType(ty) => ty.gen(p, ctx), - Self::TSNamedTupleMember(ty) => ty.gen(p, ctx), - Self::TSLiteralType(ty) => ty.literal.gen(p, ctx), - Self::TSImportType(ty) => ty.gen(p, ctx), - Self::TSQualifiedName(ty) => ty.gen(p, ctx), + Self::TSFunctionType(ty) => ty.print(p, ctx), + Self::TSConstructorType(ty) => ty.print(p, ctx), + Self::TSArrayType(ty) => ty.print(p, ctx), + Self::TSTupleType(ty) => ty.print(p, ctx), + Self::TSUnionType(ty) => ty.print(p, ctx), + Self::TSParenthesizedType(ty) => ty.print(p, ctx), + Self::TSIntersectionType(ty) => ty.print(p, ctx), + Self::TSConditionalType(ty) => ty.print(p, ctx), + Self::TSInferType(ty) => ty.print(p, ctx), + Self::TSIndexedAccessType(ty) => ty.print(p, ctx), + Self::TSMappedType(ty) => ty.print(p, ctx), + Self::TSNamedTupleMember(ty) => ty.print(p, ctx), + Self::TSLiteralType(ty) => ty.literal.print(p, ctx), + Self::TSImportType(ty) => ty.print(p, ctx), + Self::TSQualifiedName(ty) => ty.print(p, ctx), Self::TSAnyKeyword(_) => p.print_str("any"), Self::TSBigIntKeyword(_) => p.print_str("bigint"), Self::TSBooleanKeyword(_) => p.print_str("boolean"), @@ -2798,14 +2810,14 @@ impl<'a> Gen for TSType<'a> { Self::TSUndefinedKeyword(_) => p.print_str("undefined"), Self::TSUnknownKeyword(_) => p.print_str("unknown"), Self::TSVoidKeyword(_) => p.print_str("void"), - Self::TSTemplateLiteralType(ty) => ty.gen(p, ctx), - Self::TSTypeLiteral(ty) => ty.gen(p, ctx), - Self::TSTypeOperatorType(ty) => ty.gen(p, ctx), - Self::TSTypePredicate(ty) => ty.gen(p, ctx), - Self::TSTypeQuery(ty) => ty.gen(p, ctx), - Self::TSTypeReference(ty) => ty.gen(p, ctx), - Self::JSDocNullableType(ty) => ty.gen(p, ctx), - Self::JSDocNonNullableType(ty) => ty.gen(p, ctx), + Self::TSTemplateLiteralType(ty) => ty.print(p, ctx), + Self::TSTypeLiteral(ty) => ty.print(p, ctx), + Self::TSTypeOperatorType(ty) => ty.print(p, ctx), + Self::TSTypePredicate(ty) => ty.print(p, ctx), + Self::TSTypeQuery(ty) => ty.print(p, ctx), + Self::TSTypeReference(ty) => ty.print(p, ctx), + Self::JSDocNullableType(ty) => ty.print(p, ctx), + Self::JSDocNonNullableType(ty) => ty.print(p, ctx), Self::JSDocUnknownType(_ty) => p.print_str("unknown"), } } @@ -2813,7 +2825,7 @@ impl<'a> Gen for TSType<'a> { impl<'a> Gen for TSArrayType<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { - self.element_type.gen(p, ctx); + self.element_type.print(p, ctx); p.print_str("[]"); } } @@ -2829,7 +2841,7 @@ impl<'a> Gen for TSTupleType<'a> { impl<'a> Gen for TSUnionType<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { if self.types.len() == 1 { - self.types[0].gen(p, ctx); + self.types[0].print(p, ctx); return; } for (index, item) in self.types.iter().enumerate() { @@ -2838,7 +2850,7 @@ impl<'a> Gen for TSUnionType<'a> { p.print_str("|"); p.print_soft_space(); } - item.gen(p, ctx); + item.print(p, ctx); } } } @@ -2846,7 +2858,7 @@ impl<'a> Gen for TSUnionType<'a> { impl<'a> Gen for TSParenthesizedType<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { p.print_char(b'('); - self.type_annotation.gen(p, ctx); + self.type_annotation.print(p, ctx); p.print_char(b')'); } } @@ -2854,7 +2866,7 @@ impl<'a> Gen for TSParenthesizedType<'a> { impl<'a> Gen for TSIntersectionType<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { if self.types.len() == 1 { - self.types[0].gen(p, ctx); + self.types[0].print(p, ctx); return; } for (index, item) in self.types.iter().enumerate() { @@ -2863,35 +2875,35 @@ impl<'a> Gen for TSIntersectionType<'a> { p.print_str("&"); p.print_soft_space(); } - item.gen(p, ctx); + item.print(p, ctx); } } } impl<'a> Gen for TSConditionalType<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { - self.check_type.gen(p, ctx); + self.check_type.print(p, ctx); p.print_str(" extends "); - self.extends_type.gen(p, ctx); + self.extends_type.print(p, ctx); p.print_str(" ? "); - self.true_type.gen(p, ctx); + self.true_type.print(p, ctx); p.print_str(" : "); - self.false_type.gen(p, ctx); + self.false_type.print(p, ctx); } } impl<'a> Gen for TSInferType<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { p.print_str("infer "); - self.type_parameter.gen(p, ctx); + self.type_parameter.print(p, ctx); } } impl<'a> Gen for TSIndexedAccessType<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { - self.object_type.gen(p, ctx); + self.object_type.print(p, ctx); p.print_str("["); - self.index_type.gen(p, ctx); + self.index_type.print(p, ctx); p.print_str("]"); } } @@ -2913,18 +2925,18 @@ impl<'a> Gen for TSMappedType<'a> { } p.print_hard_space(); p.print_str("["); - self.type_parameter.name.gen(p, ctx); + self.type_parameter.name.print(p, ctx); if let Some(constraint) = &self.type_parameter.constraint { p.print_str(" in "); - constraint.gen(p, ctx); + constraint.print(p, ctx); } if let Some(default) = &self.type_parameter.default { p.print_str(" = "); - default.gen(p, ctx); + default.print(p, ctx); } if let Some(name_type) = &self.name_type { p.print_str(" as "); - name_type.gen(p, ctx); + name_type.print(p, ctx); } p.print_str("]"); match self.optional { @@ -2943,7 +2955,7 @@ impl<'a> Gen for TSMappedType<'a> { if let Some(type_annotation) = &self.type_annotation { p.print_str(":"); p.print_soft_space(); - type_annotation.gen(p, ctx); + type_annotation.print(p, ctx); } p.print_str("}"); } @@ -2951,9 +2963,9 @@ impl<'a> Gen for TSMappedType<'a> { impl<'a> Gen for TSQualifiedName<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { - self.left.gen(p, ctx); + self.left.print(p, ctx); p.print_str("."); - self.right.gen(p, ctx); + self.right.print(p, ctx); } } @@ -2970,7 +2982,7 @@ impl<'a> Gen for TSTypeOperator<'a> { p.print_str("readonly "); } } - self.type_annotation.gen(p, ctx); + self.type_annotation.print(p, ctx); } } @@ -2981,7 +2993,7 @@ impl<'a> Gen for TSTypePredicate<'a> { } match &self.parameter_name { TSTypePredicateName::Identifier(ident) => { - ident.gen(p, ctx); + ident.print(p, ctx); } TSTypePredicateName::This(_ident) => { p.print_str("this"); @@ -2989,16 +3001,16 @@ impl<'a> Gen for TSTypePredicate<'a> { } if let Some(type_annotation) = &self.type_annotation { p.print_str(" is "); - type_annotation.gen(p, ctx); + type_annotation.print(p, ctx); } } } impl<'a> Gen for TSTypeReference<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { - self.type_name.gen(p, ctx); + self.type_name.print(p, ctx); if let Some(type_parameters) = &self.type_parameters { - type_parameters.gen(p, ctx); + type_parameters.print(p, ctx); } } } @@ -3006,11 +3018,11 @@ impl<'a> Gen for TSTypeReference<'a> { impl<'a> Gen for JSDocNullableType<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { if self.postfix { - self.type_annotation.gen(p, ctx); + self.type_annotation.print(p, ctx); p.print_str("?"); } else { p.print_str("?"); - self.type_annotation.gen(p, ctx); + self.type_annotation.print(p, ctx); } } } @@ -3018,11 +3030,11 @@ impl<'a> Gen for JSDocNullableType<'a> { impl<'a> Gen for JSDocNonNullableType<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { if self.postfix { - self.type_annotation.gen(p, ctx); + self.type_annotation.print(p, ctx); p.print_str("!"); } else { p.print_str("!"); - self.type_annotation.gen(p, ctx); + self.type_annotation.print(p, ctx); } } } @@ -3034,7 +3046,7 @@ impl<'a> Gen for TSTemplateLiteralType<'a> { if index != 0 { if let Some(types) = self.types.get(index - 1) { p.print_str("${"); - types.gen(p, ctx); + types.print(p, ctx); p.print_str("}"); } } @@ -3050,7 +3062,7 @@ impl<'a> Gen for TSTypeLiteral<'a> { p.print_curly_braces(self.span, single_line, |p| { for item in &self.members { p.print_indent(); - item.gen(p, ctx); + item.print(p, ctx); if !single_line { p.print_semicolon(); p.print_soft_newline(); @@ -3064,12 +3076,12 @@ impl<'a> Gen for TSTypeName<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match self { Self::IdentifierReference(ident) => { - ident.gen(p, ctx); + ident.print(p, ctx); } Self::QualifiedName(decl) => { - decl.left.gen(p, ctx); + decl.left.print(p, ctx); p.print_str("."); - decl.right.gen(p, ctx); + decl.right.print(p, ctx); } } } @@ -3078,14 +3090,14 @@ impl<'a> Gen for TSTypeName<'a> { impl<'a> Gen for TSLiteral<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match self { - Self::BooleanLiteral(decl) => decl.gen(p, ctx), - Self::NullLiteral(decl) => decl.gen(p, ctx), - Self::NumericLiteral(decl) => decl.gen(p, ctx), - Self::BigIntLiteral(decl) => decl.gen(p, ctx), - Self::RegExpLiteral(decl) => decl.gen(p, ctx), - Self::StringLiteral(decl) => decl.gen(p, ctx), - Self::TemplateLiteral(decl) => decl.gen(p, ctx), - Self::UnaryExpression(decl) => decl.gen_expr(p, Precedence::Comma, ctx), + Self::BooleanLiteral(decl) => decl.print(p, ctx), + Self::NullLiteral(decl) => decl.print(p, ctx), + Self::NumericLiteral(decl) => decl.print(p, ctx), + Self::BigIntLiteral(decl) => decl.print(p, ctx), + Self::RegExpLiteral(decl) => decl.print(p, ctx), + Self::StringLiteral(decl) => decl.print(p, ctx), + Self::TemplateLiteral(decl) => decl.print(p, ctx), + Self::UnaryExpression(decl) => decl.print_expr(p, Precedence::Comma, ctx), } } } @@ -3095,14 +3107,14 @@ impl<'a> Gen for TSTypeParameter<'a> { if self.r#const { p.print_str("const "); } - self.name.gen(p, ctx); + self.name.print(p, ctx); if let Some(constraint) = &self.constraint { p.print_str(" extends "); - constraint.gen(p, ctx); + constraint.print(p, ctx); } if let Some(default) = &self.default { p.print_str(" = "); - default.gen(p, ctx); + default.print(p, ctx); } } } @@ -3110,22 +3122,22 @@ impl<'a> Gen for TSTypeParameter<'a> { impl<'a> Gen for TSFunctionType<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { if let Some(type_parameters) = &self.type_parameters { - type_parameters.gen(p, ctx); + type_parameters.print(p, ctx); } p.print_str("("); if let Some(this_param) = &self.this_param { - this_param.gen(p, ctx); + this_param.print(p, ctx); if !self.params.is_empty() || self.params.rest.is_some() { p.print_str(","); } p.print_soft_space(); } - self.params.gen(p, ctx); + self.params.print(p, ctx); p.print_str(")"); p.print_soft_space(); p.print_str("=>"); p.print_soft_space(); - self.return_type.gen(p, ctx); + self.return_type.print(p, ctx); } } @@ -3134,7 +3146,7 @@ impl<'a> Gen for TSThisParameter<'a> { p.print_str("this"); if let Some(type_annotation) = &self.type_annotation { p.print_str(": "); - type_annotation.gen(p, ctx); + type_annotation.print(p, ctx); } } } @@ -3142,25 +3154,25 @@ impl<'a> Gen for TSThisParameter<'a> { impl<'a> Gen for TSSignature<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match self { - Self::TSIndexSignature(signature) => signature.gen(p, ctx), + Self::TSIndexSignature(signature) => signature.print(p, ctx), Self::TSPropertySignature(signature) => { if signature.readonly { p.print_str("readonly "); } if signature.computed { p.print_char(b'['); - signature.key.gen(p, ctx); + signature.key.print(p, ctx); p.print_char(b']'); } else { match &signature.key { PropertyKey::StaticIdentifier(key) => { - key.gen(p, ctx); + key.print(p, ctx); } PropertyKey::PrivateIdentifier(key) => { p.print_str(key.name.as_str()); } key @ match_expression!(PropertyKey) => { - key.to_expression().gen_expr(p, Precedence::Comma, ctx); + key.to_expression().print_expr(p, Precedence::Comma, ctx); } } } @@ -3170,41 +3182,41 @@ impl<'a> Gen for TSSignature<'a> { if let Some(type_annotation) = &signature.type_annotation { p.print_colon(); p.print_soft_space(); - type_annotation.gen(p, ctx); + type_annotation.print(p, ctx); } } Self::TSCallSignatureDeclaration(signature) => { if let Some(type_parameters) = signature.type_parameters.as_ref() { - type_parameters.gen(p, ctx); + type_parameters.print(p, ctx); } p.print_str("("); if let Some(this_param) = &signature.this_param { - this_param.gen(p, ctx); + this_param.print(p, ctx); if !signature.params.is_empty() || signature.params.rest.is_some() { p.print_str(","); } p.print_soft_space(); } - signature.params.gen(p, ctx); + signature.params.print(p, ctx); p.print_str(")"); if let Some(return_type) = &signature.return_type { p.print_colon(); p.print_soft_space(); - return_type.gen(p, ctx); + return_type.print(p, ctx); } } Self::TSConstructSignatureDeclaration(signature) => { p.print_str("new "); if let Some(type_parameters) = signature.type_parameters.as_ref() { - type_parameters.gen(p, ctx); + type_parameters.print(p, ctx); } p.print_str("("); - signature.params.gen(p, ctx); + signature.params.print(p, ctx); p.print_str(")"); if let Some(return_type) = &signature.return_type { p.print_colon(); p.print_soft_space(); - return_type.gen(p, ctx); + return_type.print(p, ctx); } } Self::TSMethodSignature(signature) => { @@ -3215,18 +3227,18 @@ impl<'a> Gen for TSSignature<'a> { } if signature.computed { p.print_char(b'['); - signature.key.gen(p, ctx); + signature.key.print(p, ctx); p.print_char(b']'); } else { match &signature.key { PropertyKey::StaticIdentifier(key) => { - key.gen(p, ctx); + key.print(p, ctx); } PropertyKey::PrivateIdentifier(key) => { p.print_str(key.name.as_str()); } key @ match_expression!(PropertyKey) => { - key.to_expression().gen_expr(p, Precedence::Comma, ctx); + key.to_expression().print_expr(p, Precedence::Comma, ctx); } } } @@ -3234,22 +3246,22 @@ impl<'a> Gen for TSSignature<'a> { p.print_str("?"); } if let Some(type_parameters) = &signature.type_parameters { - type_parameters.gen(p, ctx); + type_parameters.print(p, ctx); } p.print_str("("); if let Some(this_param) = &signature.this_param { - this_param.gen(p, ctx); + this_param.print(p, ctx); if !signature.params.is_empty() || signature.params.rest.is_some() { p.print_str(","); } p.print_soft_space(); } - signature.params.gen(p, ctx); + signature.params.print(p, ctx); p.print_str(")"); if let Some(return_type) = &signature.return_type { p.print_colon(); p.print_soft_space(); - return_type.gen(p, ctx); + return_type.print(p, ctx); } } } @@ -3259,9 +3271,9 @@ impl<'a> Gen for TSSignature<'a> { impl<'a> Gen for TSTypeQuery<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { p.print_str("typeof "); - self.expr_name.gen(p, ctx); + self.expr_name.print(p, ctx); if let Some(type_params) = &self.type_parameters { - type_params.gen(p, ctx); + type_params.print(p, ctx); } } } @@ -3269,8 +3281,8 @@ impl<'a> Gen for TSTypeQuery<'a> { impl<'a> Gen for TSTypeQueryExprName<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match self { - match_ts_type_name!(Self) => self.to_ts_type_name().gen(p, ctx), - Self::TSImportType(decl) => decl.gen(p, ctx), + match_ts_type_name!(Self) => self.to_ts_type_name().print(p, ctx), + Self::TSImportType(decl) => decl.print(p, ctx), } } } @@ -3281,18 +3293,18 @@ impl<'a> Gen for TSImportType<'a> { p.print_str("typeof "); } p.print_str("import("); - self.parameter.gen(p, ctx); + self.parameter.print(p, ctx); if let Some(attributes) = &self.attributes { p.print_str(", "); - attributes.gen(p, ctx); + attributes.print(p, ctx); } p.print_str(")"); if let Some(qualifier) = &self.qualifier { p.print_char(b'.'); - qualifier.gen(p, ctx); + qualifier.print(p, ctx); } if let Some(type_parameters) = &self.type_parameters { - type_parameters.gen(p, ctx); + type_parameters.print(p, ctx); } } } @@ -3301,7 +3313,7 @@ impl<'a> Gen for TSImportAttributes<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { p.print_char(b'{'); p.print_soft_space(); - self.attributes_keyword.gen(p, ctx); + self.attributes_keyword.print(p, ctx); p.print_str(":"); p.print_soft_space(); p.print_char(b'{'); @@ -3316,17 +3328,17 @@ impl<'a> Gen for TSImportAttributes<'a> { impl<'a> Gen for TSImportAttribute<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { - self.name.gen(p, ctx); + self.name.print(p, ctx); p.print_str(": "); - self.value.gen_expr(p, Precedence::Member, ctx); + self.value.print_expr(p, Precedence::Member, ctx); } } impl<'a> Gen for TSImportAttributeName<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match self { - TSImportAttributeName::Identifier(ident) => ident.gen(p, ctx), - TSImportAttributeName::StringLiteral(literal) => literal.gen(p, ctx), + TSImportAttributeName::Identifier(ident) => ident.print(p, ctx), + TSImportAttributeName::StringLiteral(literal) => literal.print(p, ctx), } } } @@ -3352,26 +3364,26 @@ impl<'a> Gen for TSIndexSignature<'a> { p.print_str(parameter.name.as_str()); p.print_colon(); p.print_soft_space(); - parameter.type_annotation.gen(p, ctx); + parameter.type_annotation.print(p, ctx); } p.print_str("]"); p.print_colon(); p.print_soft_space(); - self.type_annotation.gen(p, ctx); + self.type_annotation.print(p, ctx); } } impl<'a> Gen for TSTupleElement<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match self { - match_ts_type!(TSTupleElement) => self.to_ts_type().gen(p, ctx), + match_ts_type!(TSTupleElement) => self.to_ts_type().print(p, ctx), TSTupleElement::TSOptionalType(ts_type) => { - ts_type.type_annotation.gen(p, ctx); + ts_type.type_annotation.print(p, ctx); p.print_str("?"); } TSTupleElement::TSRestType(ts_type) => { p.print_str("..."); - ts_type.type_annotation.gen(p, ctx); + ts_type.type_annotation.print(p, ctx); } } } @@ -3379,13 +3391,13 @@ impl<'a> Gen for TSTupleElement<'a> { impl<'a> Gen for TSNamedTupleMember<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { - self.label.gen(p, ctx); + self.label.print(p, ctx); if self.optional { p.print_str("?"); } p.print_str(":"); p.print_soft_space(); - self.element_type.gen(p, ctx); + self.element_type.print(p, ctx); } } @@ -3398,7 +3410,7 @@ impl<'a> Gen for TSModuleDeclaration<'a> { // If the kind is global, then the id is also `global`, so we don't need to print it if !self.kind.is_global() { p.print_space_before_identifier(); - self.id.gen(p, ctx); + self.id.print(p, ctx); } if let Some(body) = &self.body { @@ -3407,7 +3419,7 @@ impl<'a> Gen for TSModuleDeclaration<'a> { match body { TSModuleDeclarationBody::TSModuleDeclaration(b) => { p.print_char(b'.'); - b.id.gen(p, ctx); + b.id.print(p, ctx); if let Some(b) = &b.body { body = b; } else { @@ -3416,7 +3428,7 @@ impl<'a> Gen for TSModuleDeclaration<'a> { } TSModuleDeclarationBody::TSModuleBlock(body) => { p.print_soft_space(); - body.gen(p, ctx); + body.print(p, ctx); break; } } @@ -3429,8 +3441,8 @@ impl<'a> Gen for TSModuleDeclaration<'a> { impl<'a> Gen for TSModuleDeclarationName<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match self { - Self::Identifier(ident) => ident.gen(p, ctx), - Self::StringLiteral(s) => s.gen(p, ctx), + Self::Identifier(ident) => ident.print(p, ctx), + Self::StringLiteral(s) => s.print(p, ctx), } } } @@ -3440,11 +3452,11 @@ impl<'a> Gen for TSModuleBlock<'a> { let is_empty = self.directives.is_empty() && self.body.is_empty(); p.print_curly_braces(self.span, is_empty, |p| { for directive in &self.directives { - directive.gen(p, ctx); + directive.print(p, ctx); } for stmt in &self.body { p.print_semicolon_if_needed(); - stmt.gen(p, ctx); + stmt.print(p, ctx); } }); p.needs_semicolon = false; @@ -3458,14 +3470,14 @@ impl<'a> Gen for TSTypeAliasDeclaration<'a> { } p.print_str("type"); p.print_space_before_identifier(); - self.id.gen(p, ctx); + self.id.print(p, ctx); if let Some(type_parameters) = &self.type_parameters { - type_parameters.gen(p, ctx); + type_parameters.print(p, ctx); } p.print_soft_space(); p.print_str("="); p.print_soft_space(); - self.type_annotation.gen(p, ctx); + self.type_annotation.print(p, ctx); } } @@ -3473,9 +3485,9 @@ impl<'a> Gen for TSInterfaceDeclaration<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { p.print_str("interface"); p.print_hard_space(); - self.id.gen(p, ctx); + self.id.print(p, ctx); if let Some(type_parameters) = &self.type_parameters { - type_parameters.gen(p, ctx); + type_parameters.print(p, ctx); } if let Some(extends) = &self.extends { if !extends.is_empty() { @@ -3487,7 +3499,7 @@ impl<'a> Gen for TSInterfaceDeclaration<'a> { p.print_curly_braces(self.body.span, self.body.body.is_empty(), |p| { for item in &self.body.body { p.print_indent(); - item.gen(p, ctx); + item.print(p, ctx); p.print_semicolon(); p.print_soft_newline(); } @@ -3497,9 +3509,9 @@ impl<'a> Gen for TSInterfaceDeclaration<'a> { impl<'a> Gen for TSInterfaceHeritage<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { - self.expression.gen_expr(p, Precedence::Call, ctx); + self.expression.print_expr(p, Precedence::Call, ctx); if let Some(type_parameters) = &self.type_parameters { - type_parameters.gen(p, ctx); + type_parameters.print(p, ctx); } } } @@ -3515,12 +3527,12 @@ impl<'a> Gen for TSEnumDeclaration<'a> { } p.print_space_before_identifier(); p.print_str("enum "); - self.id.gen(p, ctx); + self.id.print(p, ctx); p.print_space_before_identifier(); p.print_curly_braces(self.span, self.members.is_empty(), |p| { for member in &self.members { p.print_indent(); - member.gen(p, ctx); + member.print(p, ctx); p.print_comma(); p.print_soft_newline(); } @@ -3531,13 +3543,13 @@ impl<'a> Gen for TSEnumDeclaration<'a> { impl<'a> Gen for TSEnumMember<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { match &self.id { - TSEnumMemberName::StaticIdentifier(decl) => decl.gen(p, ctx), - TSEnumMemberName::StaticStringLiteral(decl) => decl.gen(p, ctx), - TSEnumMemberName::StaticTemplateLiteral(decl) => decl.gen(p, ctx), - TSEnumMemberName::StaticNumericLiteral(decl) => decl.gen(p, ctx), + TSEnumMemberName::StaticIdentifier(decl) => decl.print(p, ctx), + TSEnumMemberName::StaticStringLiteral(decl) => decl.print(p, ctx), + TSEnumMemberName::StaticTemplateLiteral(decl) => decl.print(p, ctx), + TSEnumMemberName::StaticNumericLiteral(decl) => decl.print(p, ctx), decl @ match_expression!(TSEnumMemberName) => { p.print_str("["); - decl.to_expression().gen_expr(p, Precedence::Lowest, ctx); + decl.to_expression().print_expr(p, Precedence::Lowest, ctx); p.print_str("]"); } } @@ -3545,7 +3557,7 @@ impl<'a> Gen for TSEnumMember<'a> { p.print_soft_space(); p.print_equal(); p.print_soft_space(); - init.gen_expr(p, Precedence::Lowest, ctx); + init.print_expr(p, Precedence::Lowest, ctx); } } } @@ -3557,24 +3569,24 @@ impl<'a> Gen for TSConstructorType<'a> { } p.print_str("new "); if let Some(type_parameters) = &self.type_parameters { - type_parameters.gen(p, ctx); + type_parameters.print(p, ctx); } p.print_str("("); - self.params.gen(p, ctx); + self.params.print(p, ctx); p.print_str(")"); p.print_soft_space(); p.print_str("=>"); p.print_soft_space(); - self.return_type.gen(p, ctx); + self.return_type.print(p, ctx); } } impl<'a> Gen for TSImportEqualsDeclaration<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { p.print_str("import "); - self.id.gen(p, ctx); + self.id.print(p, ctx); p.print_str(" = "); - self.module_reference.gen(p, ctx); + self.module_reference.print(p, ctx); } } @@ -3583,10 +3595,10 @@ impl<'a> Gen for TSModuleReference<'a> { match self { Self::ExternalModuleReference(decl) => { p.print_str("require("); - decl.expression.gen(p, ctx); + decl.expression.print(p, ctx); p.print_str(")"); } - match_ts_type_name!(Self) => self.to_ts_type_name().gen(p, ctx), + match_ts_type_name!(Self) => self.to_ts_type_name().print(p, ctx), } } } diff --git a/crates/oxc_codegen/src/lib.rs b/crates/oxc_codegen/src/lib.rs index c2516e0a14d2c..8674b1ce886bb 100644 --- a/crates/oxc_codegen/src/lib.rs +++ b/crates/oxc_codegen/src/lib.rs @@ -206,7 +206,7 @@ impl<'a> Codegen<'a> { #[must_use] pub fn build(mut self, program: &Program<'_>) -> CodegenReturn { - program.gen(&mut self, Context::default()); + program.print(&mut self, Context::default()); let source_text = self.into_source_text(); let source_map = self.sourcemap_builder.map(SourcemapBuilder::into_sourcemap); CodegenReturn { source_text, source_map } @@ -233,7 +233,7 @@ impl<'a> Codegen<'a> { #[inline] pub fn print_expression(&mut self, expr: &Expression<'_>) { - expr.gen_expr(self, Precedence::Lowest, Context::empty()); + expr.print_expr(self, Precedence::Lowest, Context::empty()); } } @@ -353,7 +353,7 @@ impl<'a> Codegen<'a> { fn print_sequence(&mut self, items: &[T], ctx: Context) { for item in items { - item.gen(self, ctx); + item.print(self, ctx); self.print_comma(); } } @@ -404,7 +404,7 @@ impl<'a> Codegen<'a> { self.print_hard_space(); } self.print_next_indent_as_space = true; - stmt.gen(self, ctx); + stmt.print(self, ctx); } } } @@ -413,7 +413,7 @@ impl<'a> Codegen<'a> { self.print_curly_braces(stmt.span, stmt.body.is_empty(), |p| { for stmt in &stmt.body { p.print_semicolon_if_needed(); - stmt.gen(p, ctx); + stmt.print(p, ctx); } }); self.needs_semicolon = false; @@ -423,11 +423,11 @@ impl<'a> Codegen<'a> { // ``` // let mut iter = items.iter(); // let Some(item) = iter.next() else { return }; - // item.gen(self, ctx); + // item.print(self, ctx); // for item in iter { // self.print_comma(); // self.print_soft_space(); - // item.gen(self, ctx); + // item.print(self, ctx); // } // ``` // But it turned out this was actually a bit slower. @@ -438,7 +438,7 @@ impl<'a> Codegen<'a> { self.print_comma(); self.print_soft_space(); } - item.gen(self, ctx); + item.print(self, ctx); } } @@ -448,7 +448,7 @@ impl<'a> Codegen<'a> { self.print_comma(); self.print_soft_space(); } - item.gen_expr(self, precedence, ctx); + item.print_expr(self, precedence, ctx); } }