diff --git a/unsupported/juno/src/ast/dump.rs b/unsupported/juno/src/ast/dump.rs index e08651ab81f..04e735c2b64 100644 --- a/unsupported/juno/src/ast/dump.rs +++ b/unsupported/juno/src/ast/dump.rs @@ -7,9 +7,8 @@ use super::{ AssignmentExpressionOperator, BinaryExpressionOperator, Context, ExportKind, ImportKind, - LogicalExpressionOperator, MethodDefinitionKind, NodeKind, NodeLabel, NodeList, NodePtr, - NodeString, PropertyKind, UnaryExpressionOperator, UpdateExpressionOperator, - VariableDeclarationKind, + LogicalExpressionOperator, MethodDefinitionKind, NodeLabel, NodeList, NodePtr, NodeString, + PropertyKind, UnaryExpressionOperator, UpdateExpressionOperator, VariableDeclarationKind, }; use std::io::{self, Write}; use support::{case::ascii_snake_to_camel, json::*}; @@ -31,12 +30,13 @@ macro_rules! gen_dumper { $(,)? }) => { fn dump_node(ctx: &Context, node: NodePtr, emitter: &mut JSONEmitter) { + use crate::ast::*; emitter.open_dict(); emitter.emit_key("type"); emitter.emit_string(node.get(ctx).kind.name()); match &node.get(ctx).kind { $( - NodeKind::$kind $({$($field),*})? => { + NodeKind::$kind($kind {$($($field),*)?}) => { $($( emitter.emit_key(&ascii_snake_to_camel(stringify!($field))); $field.dump(ctx, emitter); diff --git a/unsupported/juno/src/ast/kind.rs b/unsupported/juno/src/ast/kind.rs index 7ccbd1f6d46..98bf557b03c 100644 --- a/unsupported/juno/src/ast/kind.rs +++ b/unsupported/juno/src/ast/kind.rs @@ -34,12 +34,18 @@ macro_rules! gen_nodekind_enum { #[derive(Debug)] pub enum NodeKind { // Create each field in the enum. + $($kind($kind),)* + } + + $( + #[derive(Debug)] + pub struct $kind { + // Create each field in the struct. $( - $kind $({ - $($field : $type),* - })? - ),* + $(pub $field : $type),* + )? } + )* impl NodeKind { /// Visit the child fields of this kind. @@ -47,7 +53,7 @@ macro_rules! gen_nodekind_enum { pub fn visit_children< V: Visitor>(&self, ctx: &Context, visitor: &mut V, node: NodePtr) { match self { $( - Self::$kind $({$($field),*})? => { + Self::$kind($kind {$($($field),*)?}) => { $($( $field.visit(ctx, visitor, node); )*)? diff --git a/unsupported/juno/src/ast/mod.rs b/unsupported/juno/src/ast/mod.rs index e4d3706dac4..d206d03fc3a 100644 --- a/unsupported/juno/src/ast/mod.rs +++ b/unsupported/juno/src/ast/mod.rs @@ -15,10 +15,10 @@ mod dump; mod kind; mod validate; -pub use kind::NodeKind; use kind::NodeVariant; pub use dump::{dump_json, Pretty}; +pub use kind::*; pub use validate::{validate_tree, ValidationError}; /// The storage for AST nodes. diff --git a/unsupported/juno/src/ast/validate.rs b/unsupported/juno/src/ast/validate.rs index c87a5b67011..5feeb67d378 100644 --- a/unsupported/juno/src/ast/validate.rs +++ b/unsupported/juno/src/ast/validate.rs @@ -6,10 +6,10 @@ */ use super::{ - AssignmentExpressionOperator, BinaryExpressionOperator, Context, ExportKind, ImportKind, - LogicalExpressionOperator, MethodDefinitionKind, NodeKind, NodeLabel, NodeList, NodePtr, - NodeString, NodeVariant, PropertyKind, UnaryExpressionOperator, UpdateExpressionOperator, - VariableDeclarationKind, Visitor, + kind::*, AssignmentExpressionOperator, BinaryExpressionOperator, Context, ExportKind, + ImportKind, LogicalExpressionOperator, MethodDefinitionKind, NodeKind, NodeLabel, NodeList, + NodePtr, NodeString, NodeVariant, PropertyKind, UnaryExpressionOperator, + UpdateExpressionOperator, VariableDeclarationKind, Visitor, }; macro_rules! gen_validate_fn { @@ -29,7 +29,7 @@ macro_rules! gen_validate_fn { fn validate_node(ctx: &Context, node: NodePtr) -> Result<(), ValidationError> { match &node.get(ctx).kind { $( - NodeKind::$kind $({$($field),*})? => { + NodeKind::$kind($kind {$($($field),*)?}) => { // Run the validation for each child. // Use `true &&` to make it work when there's no children. $($( @@ -153,19 +153,18 @@ fn instanceof(subtype: NodeVariant, supertype: NodeVariant) -> bool { /// Custom validation function for constraints which can't be expressed /// using just the inheritance structure in NodeKind. fn validate_custom(ctx: &Context, node: NodePtr) -> Result<(), ValidationError> { - use NodeKind::*; match &node.get(ctx).kind { - MemberExpression { + NodeKind::MemberExpression(MemberExpression { property, object: _, computed, - } - | OptionalMemberExpression { + }) + | NodeKind::OptionalMemberExpression(OptionalMemberExpression { property, object: _, computed, optional: _, - } => { + }) => { if *computed { property.validate_child(ctx, node, &[NodeVariant::Expression])?; } else { @@ -173,14 +172,14 @@ fn validate_custom(ctx: &Context, node: NodePtr) -> Result<(), ValidationError> } } - Property { + NodeKind::Property(Property { key, value, kind, computed, method, shorthand, - } => { + }) => { if *computed && *shorthand { return Err(ValidationError { node, diff --git a/unsupported/juno/src/gen_js.rs b/unsupported/juno/src/gen_js.rs index 8b289dfbfb5..f6a3deb6e90 100644 --- a/unsupported/juno/src/gen_js.rs +++ b/unsupported/juno/src/gen_js.rs @@ -259,17 +259,15 @@ impl GenJS { /// Generate the JS for each node kind. fn gen_node(&mut self, ctx: &Context, node: NodePtr, parent: Option) { - use NodeKind::*; - match &node.get(ctx).kind { - Empty => {} - Metadata => {} + NodeKind::Empty(_) => {} + NodeKind::Metadata(_) => {} - Program { body } => { + NodeKind::Program(Program { body }) => { self.visit_stmt_list(ctx, body, node); } - FunctionExpression { + NodeKind::FunctionExpression(FunctionExpression { id, params, body, @@ -278,8 +276,8 @@ impl GenJS { predicate, generator, is_async, - } - | FunctionDeclaration { + }) + | NodeKind::FunctionDeclaration(FunctionDeclaration { id, params, body, @@ -288,7 +286,7 @@ impl GenJS { predicate, generator, is_async, - } => { + }) => { if *is_async { out!(self, "async "); } @@ -310,7 +308,7 @@ impl GenJS { self.visit_func_params_body(ctx, params, *return_type, *predicate, *body, node); } - ArrowFunctionExpression { + NodeKind::ArrowFunctionExpression(ArrowFunctionExpression { id: _, params, body, @@ -319,7 +317,7 @@ impl GenJS { predicate, expression, is_async, - } => { + }) => { let mut need_sep = false; if *is_async { out!(self, "async"); @@ -364,7 +362,7 @@ impl GenJS { out!(self, "=>"); self.space(ForceSpace::No); match &body.get(ctx).kind { - BlockStatement { .. } => { + NodeKind::BlockStatement(_) => { body.visit(ctx, self, Some(node)); } _ => { @@ -373,7 +371,7 @@ impl GenJS { } } - WhileStatement { body, test } => { + NodeKind::WhileStatement(WhileStatement { body, test }) => { out!(self, "while"); self.space(ForceSpace::No); out!(self, "("); @@ -381,7 +379,7 @@ impl GenJS { out!(self, ")"); self.visit_stmt_or_block(ctx, *body, ForceBlock::No, node); } - DoWhileStatement { body, test } => { + NodeKind::DoWhileStatement(DoWhileStatement { body, test }) => { out!(self, "do"); let block = self.visit_stmt_or_block(ctx, *body, ForceBlock::No, node); if block { @@ -397,7 +395,7 @@ impl GenJS { out!(self, ")"); } - ForInStatement { left, right, body } => { + NodeKind::ForInStatement(ForInStatement { left, right, body }) => { out!(self, "for("); left.visit(ctx, self, Some(node)); out!(self, " in "); @@ -405,12 +403,12 @@ impl GenJS { out!(self, ")"); self.visit_stmt_or_block(ctx, *body, ForceBlock::No, node); } - ForOfStatement { + NodeKind::ForOfStatement(ForOfStatement { left, right, body, is_await, - } => { + }) => { out!(self, "for{}(", if *is_await { " await" } else { "" }); left.visit(ctx, self, Some(node)); out!(self, " of "); @@ -418,12 +416,12 @@ impl GenJS { out!(self, ")"); self.visit_stmt_or_block(ctx, *body, ForceBlock::No, node); } - ForStatement { + NodeKind::ForStatement(ForStatement { init, test, update, body, - } => { + }) => { out!(self, "for("); self.print_child(ctx, *init, node, ChildPos::Left); out!(self, ";"); @@ -440,12 +438,12 @@ impl GenJS { self.visit_stmt_or_block(ctx, *body, ForceBlock::No, node); } - DebuggerStatement => { + NodeKind::DebuggerStatement(_) => { out!(self, "debugger"); } - EmptyStatement => {} + NodeKind::EmptyStatement(_) => {} - BlockStatement { body } => { + NodeKind::BlockStatement(BlockStatement { body }) => { if body.is_empty() { out!(self, "{{}}"); } else { @@ -459,14 +457,14 @@ impl GenJS { } } - BreakStatement { label } => { + NodeKind::BreakStatement(BreakStatement { label }) => { out!(self, "break"); if let Some(label) = label { self.space(ForceSpace::Yes); label.visit(ctx, self, Some(node)); } } - ContinueStatement { label } => { + NodeKind::ContinueStatement(ContinueStatement { label }) => { out!(self, "continue"); if let Some(label) = label { self.space(ForceSpace::Yes); @@ -474,18 +472,18 @@ impl GenJS { } } - ThrowStatement { argument } => { + NodeKind::ThrowStatement(ThrowStatement { argument }) => { out!(self, "throw "); argument.visit(ctx, self, Some(node)); } - ReturnStatement { argument } => { + NodeKind::ReturnStatement(ReturnStatement { argument }) => { out!(self, "return"); if let Some(argument) = argument { out!(self, " "); argument.visit(ctx, self, Some(node)); } } - WithStatement { object, body } => { + NodeKind::WithStatement(WithStatement { object, body }) => { out!(self, "with"); self.space(ForceSpace::No); out!(self, "("); @@ -494,10 +492,10 @@ impl GenJS { self.visit_stmt_or_block(ctx, *body, ForceBlock::No, node); } - SwitchStatement { + NodeKind::SwitchStatement(SwitchStatement { discriminant, cases, - } => { + }) => { out!(self, "switch"); self.space(ForceSpace::No); out!(self, "("); @@ -512,7 +510,7 @@ impl GenJS { } out!(self, "}}"); } - SwitchCase { test, consequent } => { + NodeKind::SwitchCase(SwitchCase { test, consequent }) => { match test { Some(test) => { out!(self, "case "); @@ -531,25 +529,25 @@ impl GenJS { } } - LabeledStatement { label, body } => { + NodeKind::LabeledStatement(LabeledStatement { label, body }) => { label.visit(ctx, self, Some(node)); out!(self, ":"); self.newline(); body.visit(ctx, self, Some(node)); } - ExpressionStatement { + NodeKind::ExpressionStatement(ExpressionStatement { expression, directive: _, - } => { + }) => { self.print_child(ctx, Some(*expression), node, ChildPos::Anywhere); } - TryStatement { + NodeKind::TryStatement(TryStatement { block, handler, finalizer, - } => { + }) => { out!(self, "try"); self.visit_stmt_or_block(ctx, *block, ForceBlock::Yes, node); if let Some(handler) = handler { @@ -562,11 +560,11 @@ impl GenJS { } } - IfStatement { + NodeKind::IfStatement(IfStatement { test, consequent, alternate, - } => { + }) => { out!(self, "if"); self.space(ForceSpace::No); out!(self, "("); @@ -588,7 +586,7 @@ impl GenJS { } out!(self, "else"); self.space( - if matches!(&alternate.get(ctx).kind, BlockStatement { .. }) { + if matches!(&alternate.get(ctx).kind, NodeKind::BlockStatement(_)) { ForceSpace::No } else { ForceSpace::Yes @@ -598,21 +596,21 @@ impl GenJS { } } - BooleanLiteral { value } => { + NodeKind::BooleanLiteral(BooleanLiteral { value }) => { out!(self, "{}", if *value { "true" } else { "false" }); } - NullLiteral => { + NodeKind::NullLiteral(_) => { out!(self, "null"); } - StringLiteral { value } => { + NodeKind::StringLiteral(StringLiteral { value }) => { out!(self, "\""); self.print_escaped_string_literal(value, '"'); out!(self, "\""); } - NumericLiteral { value } => { + NodeKind::NumericLiteral(NumericLiteral { value }) => { out!(self, "{}", convert::number_to_string(*value)); } - RegExpLiteral { pattern, flags } => { + NodeKind::RegExpLiteral(RegExpLiteral { pattern, flags }) => { out!(self, "/"); // Parser doesn't handle escapes when lexing RegExp, // so we don't need to do any manual escaping here. @@ -620,14 +618,14 @@ impl GenJS { out!(self, "/"); self.write_utf8(&flags.str); } - ThisExpression => { + NodeKind::ThisExpression(_) => { out!(self, "this"); } - Super => { + NodeKind::Super(_) => { out!(self, "super"); } - SequenceExpression { expressions } => { + NodeKind::SequenceExpression(SequenceExpression { expressions }) => { out!(self, "("); for (i, expr) in expressions.iter().enumerate() { if i > 0 { @@ -647,19 +645,19 @@ impl GenJS { out!(self, ")"); } - ObjectExpression { properties } => { + NodeKind::ObjectExpression(ObjectExpression { properties }) => { self.visit_props(ctx, properties, node); } - ArrayExpression { + NodeKind::ArrayExpression(ArrayExpression { elements, trailing_comma, - } => { + }) => { out!(self, "["); for (i, elem) in elements.iter().enumerate() { if i > 0 { self.comma(); } - if let SpreadElement { .. } = &elem.get(ctx).kind { + if let NodeKind::SpreadElement(_) = &elem.get(ctx).kind { elem.visit(ctx, self, Some(node)); } else { self.print_comma_expression(ctx, *elem, node); @@ -671,16 +669,16 @@ impl GenJS { out!(self, "]"); } - SpreadElement { argument } => { + NodeKind::SpreadElement(SpreadElement { argument }) => { out!(self, "..."); argument.visit(ctx, self, Some(node)); } - NewExpression { + NodeKind::NewExpression(NewExpression { callee, type_arguments, arguments, - } => { + }) => { out!(self, "new "); self.print_child(ctx, Some(*callee), node, ChildPos::Left); if let Some(type_arguments) = type_arguments { @@ -695,7 +693,7 @@ impl GenJS { } out!(self, ")"); } - YieldExpression { argument, delegate } => { + NodeKind::YieldExpression(YieldExpression { argument, delegate }) => { out!(self, "yield"); if *delegate { out!(self, "*"); @@ -707,12 +705,12 @@ impl GenJS { argument.visit(ctx, self, Some(node)); } } - AwaitExpression { argument } => { + NodeKind::AwaitExpression(AwaitExpression { argument }) => { out!(self, "await "); argument.visit(ctx, self, Some(node)); } - ImportExpression { source, attributes } => { + NodeKind::ImportExpression(ImportExpression { source, attributes }) => { out!(self, "import("); source.visit(ctx, self, Some(node)); if let Some(attributes) = attributes { @@ -723,11 +721,11 @@ impl GenJS { out!(self, ")"); } - CallExpression { + NodeKind::CallExpression(CallExpression { callee, type_arguments, arguments, - } => { + }) => { self.print_child(ctx, Some(*callee), node, ChildPos::Left); if let Some(type_arguments) = type_arguments { type_arguments.visit(ctx, self, Some(node)); @@ -741,12 +739,12 @@ impl GenJS { } out!(self, ")"); } - OptionalCallExpression { + NodeKind::OptionalCallExpression(OptionalCallExpression { callee, type_arguments, arguments, optional, - } => { + }) => { self.print_child(ctx, Some(*callee), node, ChildPos::Left); if let Some(type_arguments) = type_arguments { type_arguments.visit(ctx, self, Some(node)); @@ -761,22 +759,22 @@ impl GenJS { out!(self, ")"); } - AssignmentExpression { + NodeKind::AssignmentExpression(AssignmentExpression { operator, left, right, - } => { + }) => { self.print_child(ctx, Some(*left), node, ChildPos::Left); self.space(ForceSpace::No); out!(self, "{}", operator.as_str()); self.space(ForceSpace::No); self.print_child(ctx, Some(*right), node, ChildPos::Right); } - UnaryExpression { + NodeKind::UnaryExpression(UnaryExpression { operator, argument, prefix, - } => { + }) => { let ident = operator.as_str().chars().next().unwrap().is_alphabetic(); if *prefix { out!(self, "{}", operator.as_str()); @@ -792,11 +790,11 @@ impl GenJS { out!(self, "{}", operator.as_str()); } } - UpdateExpression { + NodeKind::UpdateExpression(UpdateExpression { operator, argument, prefix, - } => { + }) => { if *prefix { out!(self, "{}", operator.as_str()); self.print_child(ctx, Some(*argument), node, ChildPos::Right); @@ -805,11 +803,11 @@ impl GenJS { out!(self, "{}", operator.as_str()); } } - MemberExpression { + NodeKind::MemberExpression(MemberExpression { object, property, computed, - } => { + }) => { self.print_child(ctx, Some(*object), node, ChildPos::Left); if *computed { out!(self, "["); @@ -821,12 +819,12 @@ impl GenJS { out!(self, "]"); } } - OptionalMemberExpression { + NodeKind::OptionalMemberExpression(OptionalMemberExpression { object, property, computed, optional, - } => { + }) => { self.print_child(ctx, Some(*object), node, ChildPos::Left); if *computed { out!(self, "{}[", if *optional { "?." } else { "" }); @@ -839,11 +837,11 @@ impl GenJS { } } - BinaryExpression { + NodeKind::BinaryExpression(BinaryExpression { left, right, operator, - } => { + }) => { let ident = operator.as_str().chars().next().unwrap().is_alphabetic(); self.print_child(ctx, Some(*left), node, ChildPos::Left); self.space(if ident { @@ -860,18 +858,18 @@ impl GenJS { self.print_child(ctx, Some(*right), node, ChildPos::Right); } - Directive { value } => { + NodeKind::Directive(Directive { value }) => { value.visit(ctx, self, Some(node)); } - DirectiveLiteral { .. } => { + NodeKind::DirectiveLiteral(DirectiveLiteral { .. }) => { unimplemented!("No escaping for directive literals"); } - ConditionalExpression { + NodeKind::ConditionalExpression(ConditionalExpression { test, consequent, alternate, - } => { + }) => { self.print_child(ctx, Some(*test), node, ChildPos::Left); self.space(ForceSpace::No); out!(self, "?"); @@ -883,11 +881,11 @@ impl GenJS { self.print_child(ctx, Some(*alternate), node, ChildPos::Right); } - Identifier { + NodeKind::Identifier(Identifier { name, type_annotation, optional, - } => { + }) => { self.write_utf8(name.str.as_ref()); if *optional { out!(self, "?"); @@ -898,17 +896,17 @@ impl GenJS { type_annotation.visit(ctx, self, Some(node)); } } - PrivateName { id } => { + NodeKind::PrivateName(PrivateName { id }) => { out!(self, "#"); id.visit(ctx, self, Some(node)); } - MetaProperty { meta, property } => { + NodeKind::MetaProperty(MetaProperty { meta, property }) => { meta.visit(ctx, self, Some(node)); out!(self, "."); property.visit(ctx, self, Some(node)); } - CatchClause { param, body } => { + NodeKind::CatchClause(CatchClause { param, body }) => { self.space(ForceSpace::No); out!(self, "catch"); if let Some(param) = param { @@ -920,7 +918,7 @@ impl GenJS { self.visit_stmt_or_block(ctx, *body, ForceBlock::Yes, node); } - VariableDeclaration { kind, declarations } => { + NodeKind::VariableDeclaration(VariableDeclaration { kind, declarations }) => { out!(self, "{} ", kind.as_str()); for (i, decl) in declarations.iter().enumerate() { if i > 0 { @@ -929,7 +927,7 @@ impl GenJS { decl.visit(ctx, self, Some(node)); } } - VariableDeclarator { init, id } => { + NodeKind::VariableDeclarator(VariableDeclarator { init, id }) => { id.visit(ctx, self, Some(node)); if let Some(init) = init { out!( @@ -944,18 +942,18 @@ impl GenJS { } } - TemplateLiteral { + NodeKind::TemplateLiteral(TemplateLiteral { quasis, expressions, - } => { + }) => { out!(self, "`"); let mut it_expr = expressions.iter(); for quasi in quasis { - if let TemplateElement { + if let NodeKind::TemplateElement(TemplateElement { raw, tail: _, cooked: _, - } = &quasi.get(ctx).kind + }) = &quasi.get(ctx).kind { let mut buf = [0u8; 4]; for char in raw.str.chars() { @@ -974,33 +972,33 @@ impl GenJS { } out!(self, "`"); } - TaggedTemplateExpression { tag, quasi } => { + NodeKind::TaggedTemplateExpression(TaggedTemplateExpression { tag, quasi }) => { self.print_child(ctx, Some(*tag), node, ChildPos::Left); self.print_child(ctx, Some(*quasi), node, ChildPos::Right); } - TemplateElement { .. } => { + NodeKind::TemplateElement(_) => { unreachable!("TemplateElement is handled in TemplateLiteral case"); } - Property { + NodeKind::Property(Property { key, value, kind, computed, method, shorthand, - } => { + }) => { let mut need_sep = false; if *kind != PropertyKind::Init { out!(self, "{}", kind.as_str()); need_sep = true; } else if *method { match &value.get(ctx).kind { - FunctionExpression { + NodeKind::FunctionExpression(FunctionExpression { generator, is_async, .. - } => { + }) => { if *is_async { out!(self, "async"); need_sep = true; @@ -1033,13 +1031,13 @@ impl GenJS { } if *kind != PropertyKind::Init || *method { match &value.get(ctx).kind { - FunctionExpression { + NodeKind::FunctionExpression(FunctionExpression { params, body, return_type, predicate, .. - } => { + }) => { self.visit_func_params_body( ctx, params, @@ -1058,11 +1056,11 @@ impl GenJS { } } - LogicalExpression { + NodeKind::LogicalExpression(LogicalExpression { left, right, operator, - } => { + }) => { self.print_child(ctx, Some(*left), node, ChildPos::Left); self.space(ForceSpace::No); out!(self, "{}", operator.as_str()); @@ -1070,7 +1068,7 @@ impl GenJS { self.print_child(ctx, Some(*right), node, ChildPos::Right); } - ClassExpression { + NodeKind::ClassExpression(ClassExpression { id, type_parameters, super_class, @@ -1078,8 +1076,8 @@ impl GenJS { implements, decorators, body, - } - | ClassDeclaration { + }) + | NodeKind::ClassDeclaration(ClassDeclaration { id, type_parameters, super_class, @@ -1087,7 +1085,7 @@ impl GenJS { implements, decorators, body, - } => { + }) => { for decorator in decorators { decorator.visit(ctx, self, Some(node)); self.force_newline(); @@ -1121,7 +1119,7 @@ impl GenJS { body.visit(ctx, self, Some(node)); } - ClassBody { body } => { + NodeKind::ClassBody(ClassBody { body }) => { if body.is_empty() { out!(self, "{{}}"); } else { @@ -1137,7 +1135,7 @@ impl GenJS { self.newline(); } } - ClassProperty { + NodeKind::ClassProperty(ClassProperty { key, value, computed, @@ -1146,7 +1144,7 @@ impl GenJS { optional: _, variance: _, type_annotation: _, - } => { + }) => { if *is_static { out!(self, "static "); } @@ -1165,7 +1163,7 @@ impl GenJS { } out!(self, ";"); } - ClassPrivateProperty { + NodeKind::ClassPrivateProperty(ClassPrivateProperty { key, value, is_static, @@ -1173,7 +1171,7 @@ impl GenJS { optional: _, variance: _, type_annotation: _, - } => { + }) => { if *is_static { out!(self, "static "); } @@ -1187,16 +1185,16 @@ impl GenJS { } out!(self, ";"); } - MethodDefinition { + NodeKind::MethodDefinition(MethodDefinition { key, value, kind, computed, is_static, - } => { + }) => { let (is_async, generator, params, body, return_type, predicate) = match &value.get(ctx).kind { - FunctionExpression { + NodeKind::FunctionExpression(FunctionExpression { generator, is_async, params, @@ -1204,7 +1202,7 @@ impl GenJS { return_type, predicate, .. - } => (*is_async, *generator, params, body, return_type, predicate), + }) => (*is_async, *generator, params, body, return_type, predicate), _ => { unreachable!("Invalid method value"); } @@ -1240,12 +1238,12 @@ impl GenJS { self.visit_func_params_body(ctx, params, *return_type, *predicate, *body, node); } - ImportDeclaration { + NodeKind::ImportDeclaration(ImportDeclaration { specifiers, source, attributes, import_kind, - } => { + }) => { out!(self, "import "); if *import_kind != ImportKind::Value { out!(self, "{} ", import_kind.as_str()); @@ -1255,7 +1253,7 @@ impl GenJS { if i > 0 { self.comma(); } - if let ImportSpecifier { .. } = &spec.get(ctx).kind { + if let NodeKind::ImportSpecifier(_) = &spec.get(ctx).kind { if !has_named_specs { has_named_specs = true; out!(self, "{{"); @@ -1287,11 +1285,11 @@ impl GenJS { } self.newline(); } - ImportSpecifier { + NodeKind::ImportSpecifier(ImportSpecifier { imported, local, import_kind, - } => { + }) => { if *import_kind != ImportKind::Value { out!(self, "{} ", import_kind.as_str()); } @@ -1299,26 +1297,26 @@ impl GenJS { out!(self, " as "); local.visit(ctx, self, Some(node)); } - ImportDefaultSpecifier { local } => { + NodeKind::ImportDefaultSpecifier(ImportDefaultSpecifier { local }) => { local.visit(ctx, self, Some(node)); } - ImportNamespaceSpecifier { local } => { + NodeKind::ImportNamespaceSpecifier(ImportNamespaceSpecifier { local }) => { out!(self, "* as "); local.visit(ctx, self, Some(node)); } - ImportAttribute { key, value } => { + NodeKind::ImportAttribute(ImportAttribute { key, value }) => { key.visit(ctx, self, Some(node)); out!(self, ":"); self.space(ForceSpace::No); value.visit(ctx, self, Some(node)); } - ExportNamedDeclaration { + NodeKind::ExportNamedDeclaration(ExportNamedDeclaration { declaration, specifiers, source, export_kind, - } => { + }) => { out!(self, "export "); if *export_kind != ExportKind::Value { out!(self, "{} ", export_kind.as_str()); @@ -1341,24 +1339,24 @@ impl GenJS { } self.newline(); } - ExportSpecifier { exported, local } => { + NodeKind::ExportSpecifier(ExportSpecifier { exported, local }) => { local.visit(ctx, self, Some(node)); out!(self, " as "); exported.visit(ctx, self, Some(node)); } - ExportNamespaceSpecifier { exported } => { + NodeKind::ExportNamespaceSpecifier(ExportNamespaceSpecifier { exported }) => { out!(self, "* as "); exported.visit(ctx, self, Some(node)); } - ExportDefaultDeclaration { declaration } => { + NodeKind::ExportDefaultDeclaration(ExportDefaultDeclaration { declaration }) => { out!(self, "export default "); declaration.visit(ctx, self, Some(node)); self.newline(); } - ExportAllDeclaration { + NodeKind::ExportAllDeclaration(ExportAllDeclaration { source, export_kind, - } => { + }) => { out!(self, "export "); if *export_kind != ExportKind::Value { out!(self, "{} ", export_kind.as_str()); @@ -1367,10 +1365,10 @@ impl GenJS { source.visit(ctx, self, Some(node)); } - ObjectPattern { + NodeKind::ObjectPattern(ObjectPattern { properties, type_annotation, - } => { + }) => { self.visit_props(ctx, properties, node); if let Some(type_annotation) = type_annotation { out!(self, ":"); @@ -1378,10 +1376,10 @@ impl GenJS { type_annotation.visit(ctx, self, Some(node)); } } - ArrayPattern { + NodeKind::ArrayPattern(ArrayPattern { elements, type_annotation, - } => { + }) => { out!(self, "["); for (i, elem) in elements.iter().enumerate() { if i > 0 { @@ -1396,11 +1394,11 @@ impl GenJS { type_annotation.visit(ctx, self, Some(node)); } } - RestElement { argument } => { + NodeKind::RestElement(RestElement { argument }) => { out!(self, "..."); argument.visit(ctx, self, Some(node)); } - AssignmentPattern { left, right } => { + NodeKind::AssignmentPattern(AssignmentPattern { left, right }) => { left.visit(ctx, self, Some(node)); self.space(ForceSpace::No); out!(self, "="); @@ -1408,35 +1406,35 @@ impl GenJS { right.visit(ctx, self, Some(node)); } - JSXIdentifier { name } => { + NodeKind::JSXIdentifier(JSXIdentifier { name }) => { out!(self, "{}", name.str); } - JSXMemberExpression { object, property } => { + NodeKind::JSXMemberExpression(JSXMemberExpression { object, property }) => { object.visit(ctx, self, Some(node)); out!(self, "."); property.visit(ctx, self, Some(node)); } - JSXNamespacedName { namespace, name } => { + NodeKind::JSXNamespacedName(JSXNamespacedName { namespace, name }) => { namespace.visit(ctx, self, Some(node)); out!(self, ":"); name.visit(ctx, self, Some(node)); } - JSXEmptyExpression => {} - JSXExpressionContainer { expression } => { + NodeKind::JSXEmptyExpression(_) => {} + NodeKind::JSXExpressionContainer(JSXExpressionContainer { expression }) => { out!(self, "{{"); expression.visit(ctx, self, Some(node)); out!(self, "}}"); } - JSXSpreadChild { expression } => { + NodeKind::JSXSpreadChild(JSXSpreadChild { expression }) => { out!(self, "{{..."); expression.visit(ctx, self, Some(node)); out!(self, "}}"); } - JSXOpeningElement { + NodeKind::JSXOpeningElement(JSXOpeningElement { name, attributes, self_closing, - } => { + }) => { out!(self, "<"); name.visit(ctx, self, Some(node)); for attr in attributes { @@ -1449,33 +1447,33 @@ impl GenJS { out!(self, ">"); } } - JSXClosingElement { name } => { + NodeKind::JSXClosingElement(JSXClosingElement { name }) => { out!(self, ""); } - JSXAttribute { name, value } => { + NodeKind::JSXAttribute(JSXAttribute { name, value }) => { name.visit(ctx, self, Some(node)); if let Some(value) = value { out!(self, "="); value.visit(ctx, self, Some(node)); } } - JSXSpreadAttribute { argument } => { + NodeKind::JSXSpreadAttribute(JSXSpreadAttribute { argument }) => { out!(self, "{{..."); argument.visit(ctx, self, Some(node)); out!(self, "}}"); } - JSXText { value: _, .. } => { + NodeKind::JSXText(JSXText { value: _, raw: _ }) => { unimplemented!("JSXText"); // FIXME: Ensure escaping here works properly. // out!(self, "{}", value.str); } - JSXElement { + NodeKind::JSXElement(JSXElement { opening_element, children, closing_element, - } => { + }) => { opening_element.visit(ctx, self, Some(node)); if let Some(closing_element) = closing_element { self.inc_indent(); @@ -1488,11 +1486,11 @@ impl GenJS { closing_element.visit(ctx, self, Some(node)); } } - JSXFragment { + NodeKind::JSXFragment(JSXFragment { opening_fragment, children, closing_fragment, - } => { + }) => { opening_fragment.visit(ctx, self, Some(node)); self.inc_indent(); self.newline(); @@ -1503,61 +1501,65 @@ impl GenJS { self.dec_indent(); closing_fragment.visit(ctx, self, Some(node)); } - JSXOpeningFragment => { + NodeKind::JSXOpeningFragment(_) => { out!(self, "<>"); } - JSXClosingFragment => { + NodeKind::JSXClosingFragment(_) => { out!(self, ""); } - ExistsTypeAnnotation => { + NodeKind::ExistsTypeAnnotation(_) => { out!(self, "*"); } - EmptyTypeAnnotation => { + NodeKind::EmptyTypeAnnotation(_) => { out!(self, "empty"); } - StringTypeAnnotation => { + NodeKind::StringTypeAnnotation(_) => { out!(self, "string"); } - NumberTypeAnnotation => { + NodeKind::NumberTypeAnnotation(_) => { out!(self, "number"); } - StringLiteralTypeAnnotation { value } => { + NodeKind::StringLiteralTypeAnnotation(StringLiteralTypeAnnotation { value }) => { out!(self, "\""); self.print_escaped_string_literal(value, '"'); out!(self, "\""); } - NumberLiteralTypeAnnotation { value, .. } => { + NodeKind::NumberLiteralTypeAnnotation(NumberLiteralTypeAnnotation { + value, .. + }) => { out!(self, "{}", convert::number_to_string(*value)); } - BooleanTypeAnnotation => { + NodeKind::BooleanTypeAnnotation(_) => { out!(self, "boolean"); } - BooleanLiteralTypeAnnotation { value, .. } => { + NodeKind::BooleanLiteralTypeAnnotation(BooleanLiteralTypeAnnotation { + value, .. + }) => { out!(self, "{}", if *value { "true" } else { "false" }); } - NullLiteralTypeAnnotation => { + NodeKind::NullLiteralTypeAnnotation(_) => { out!(self, "null"); } - SymbolTypeAnnotation => { + NodeKind::SymbolTypeAnnotation(_) => { out!(self, "symbol"); } - AnyTypeAnnotation => { + NodeKind::AnyTypeAnnotation(_) => { out!(self, "any"); } - MixedTypeAnnotation => { + NodeKind::MixedTypeAnnotation(_) => { out!(self, "mixed"); } - VoidTypeAnnotation => { + NodeKind::VoidTypeAnnotation(_) => { out!(self, "void"); } - FunctionTypeAnnotation { + NodeKind::FunctionTypeAnnotation(FunctionTypeAnnotation { params, this, return_type, rest, type_parameters, - } => { + }) => { if let Some(type_parameters) = type_parameters { type_parameters.visit(ctx, self, Some(node)); } @@ -1568,9 +1570,9 @@ impl GenJS { let mut need_comma = false; if let Some(this) = this { match &this.get(ctx).kind { - FunctionTypeParam { + NodeKind::FunctionTypeParam(FunctionTypeParam { type_annotation, .. - } => { + }) => { out!(self, "this:"); self.space(ForceSpace::No); type_annotation.visit(ctx, self, Some(node)); @@ -1606,11 +1608,11 @@ impl GenJS { } return_type.visit(ctx, self, Some(node)); } - FunctionTypeParam { + NodeKind::FunctionTypeParam(FunctionTypeParam { name, type_annotation, optional, - } => { + }) => { if let Some(name) = name { name.visit(ctx, self, Some(node)); if *optional { @@ -1621,20 +1623,20 @@ impl GenJS { } type_annotation.visit(ctx, self, Some(node)); } - NullableTypeAnnotation { type_annotation } => { + NodeKind::NullableTypeAnnotation(NullableTypeAnnotation { type_annotation }) => { out!(self, "?"); type_annotation.visit(ctx, self, Some(node)); } - QualifiedTypeIdentifier { qualification, id } => { + NodeKind::QualifiedTypeIdentifier(QualifiedTypeIdentifier { qualification, id }) => { qualification.visit(ctx, self, Some(node)); out!(self, "."); id.visit(ctx, self, Some(node)); } - TypeofTypeAnnotation { argument } => { + NodeKind::TypeofTypeAnnotation(TypeofTypeAnnotation { argument }) => { out!(self, "typeof "); argument.visit(ctx, self, Some(node)); } - TupleTypeAnnotation { types } => { + NodeKind::TupleTypeAnnotation(TupleTypeAnnotation { types }) => { out!(self, "["); for (i, ty) in types.iter().enumerate() { if i > 0 { @@ -1644,11 +1646,11 @@ impl GenJS { } out!(self, "]"); } - ArrayTypeAnnotation { element_type } => { + NodeKind::ArrayTypeAnnotation(ArrayTypeAnnotation { element_type }) => { element_type.visit(ctx, self, Some(node)); out!(self, "[]"); } - UnionTypeAnnotation { types } => { + NodeKind::UnionTypeAnnotation(UnionTypeAnnotation { types }) => { for (i, ty) in types.iter().enumerate() { if i > 0 { self.space(ForceSpace::No); @@ -1658,7 +1660,7 @@ impl GenJS { self.print_child(ctx, Some(*ty), node, ChildPos::Anywhere); } } - IntersectionTypeAnnotation { types } => { + NodeKind::IntersectionTypeAnnotation(IntersectionTypeAnnotation { types }) => { for (i, ty) in types.iter().enumerate() { if i > 0 { self.space(ForceSpace::No); @@ -1668,35 +1670,35 @@ impl GenJS { self.print_child(ctx, Some(*ty), node, ChildPos::Anywhere); } } - GenericTypeAnnotation { + NodeKind::GenericTypeAnnotation(GenericTypeAnnotation { id, type_parameters, - } => { + }) => { id.visit(ctx, self, Some(node)); if let Some(type_parameters) = type_parameters { type_parameters.visit(ctx, self, Some(node)); } } - IndexedAccessType { + NodeKind::IndexedAccessType(IndexedAccessType { object_type, index_type, - } => { + }) => { object_type.visit(ctx, self, Some(node)); out!(self, "["); index_type.visit(ctx, self, Some(node)); out!(self, "]"); } - OptionalIndexedAccessType { + NodeKind::OptionalIndexedAccessType(OptionalIndexedAccessType { object_type, index_type, optional, - } => { + }) => { object_type.visit(ctx, self, Some(node)); out!(self, "{}[", if *optional { "?." } else { "" }); index_type.visit(ctx, self, Some(node)); out!(self, "]"); } - InterfaceTypeAnnotation { extends, body } => { + NodeKind::InterfaceTypeAnnotation(InterfaceTypeAnnotation { extends, body }) => { out!(self, "interface"); if !extends.is_empty() { out!(self, " extends "); @@ -1714,17 +1716,17 @@ impl GenJS { } } - TypeAlias { + NodeKind::TypeAlias(TypeAlias { id, type_parameters, right, - } - | DeclareTypeAlias { + }) + | NodeKind::DeclareTypeAlias(DeclareTypeAlias { id, type_parameters, right, - } => { - if matches!(&node.get(ctx).kind, DeclareTypeAlias { .. }) { + }) => { + if matches!(&node.get(ctx).kind, NodeKind::DeclareTypeAlias(_)) { out!(self, "declare "); } out!(self, "type "); @@ -1739,12 +1741,12 @@ impl GenJS { } right.visit(ctx, self, Some(node)); } - OpaqueType { + NodeKind::OpaqueType(OpaqueType { id, type_parameters, impltype, supertype, - } => { + }) => { out!(self, "opaque type "); id.visit(ctx, self, Some(node)); if let Some(type_parameters) = type_parameters { @@ -1762,21 +1764,21 @@ impl GenJS { } impltype.visit(ctx, self, Some(node)); } - InterfaceDeclaration { + NodeKind::InterfaceDeclaration(InterfaceDeclaration { id, type_parameters, extends, body, - } - | DeclareInterface { + }) + | NodeKind::DeclareInterface(DeclareInterface { id, type_parameters, extends, body, - } => { + }) => { self.visit_interface( ctx, - if matches!(node.get(ctx).kind, InterfaceDeclaration { .. }) { + if matches!(node.get(ctx).kind, NodeKind::InterfaceDeclaration(_)) { "interface" } else { "declare interface" @@ -1788,12 +1790,12 @@ impl GenJS { node, ); } - DeclareOpaqueType { + NodeKind::DeclareOpaqueType(DeclareOpaqueType { id, type_parameters, impltype, supertype, - } => { + }) => { out!(self, "opaque type "); id.visit(ctx, self, Some(node)); if let Some(type_parameters) = type_parameters { @@ -1813,14 +1815,14 @@ impl GenJS { impltype.visit(ctx, self, Some(node)); } } - DeclareClass { + NodeKind::DeclareClass(DeclareClass { id, type_parameters, extends, implements, mixins, body, - } => { + }) => { out!(self, "declare class "); id.visit(ctx, self, Some(node)); if let Some(type_parameters) = type_parameters { @@ -1856,32 +1858,34 @@ impl GenJS { self.space(ForceSpace::No); body.visit(ctx, self, Some(node)); } - DeclareFunction { id, predicate } => { + NodeKind::DeclareFunction(DeclareFunction { id, predicate }) => { // This AST type uses the Identifier/TypeAnnotation // pairing to put a name on a function header-looking construct, // so we have to do some deep matching to get it to come out right. out!(self, "declare function "); match &id.get(ctx).kind { - Identifier { + NodeKind::Identifier(Identifier { name, type_annotation, .. - } => { + }) => { out!(self, "{}", &name.str); match type_annotation { None => { unimplemented!("Malformed AST: Need to handle error"); } Some(type_annotation) => match &type_annotation.get(ctx).kind { - TypeAnnotation { type_annotation } => { + NodeKind::TypeAnnotation(TypeAnnotation { type_annotation }) => { match &type_annotation.get(ctx).kind { - FunctionTypeAnnotation { - params, - this, - return_type, - rest, - type_parameters, - } => { + NodeKind::FunctionTypeAnnotation( + FunctionTypeAnnotation { + params, + this, + return_type, + rest, + type_parameters, + }, + ) => { self.visit_func_type_params( ctx, params, @@ -1914,20 +1918,20 @@ impl GenJS { } } } - DeclareVariable { id } => { + NodeKind::DeclareVariable(DeclareVariable { id }) => { if let Some(parent) = parent { - if !matches!(parent.get(ctx).kind, DeclareExportDeclaration { .. }) { + if !matches!(parent.get(ctx).kind, NodeKind::DeclareExportDeclaration(_)) { out!(self, "declare "); } } id.visit(ctx, self, Some(node)); } - DeclareExportDeclaration { + NodeKind::DeclareExportDeclaration(DeclareExportDeclaration { declaration, specifiers, source, default, - } => { + }) => { out!(self, "declare export "); if *default { out!(self, "default "); @@ -1949,47 +1953,47 @@ impl GenJS { } } } - DeclareExportAllDeclaration { source } => { + NodeKind::DeclareExportAllDeclaration(DeclareExportAllDeclaration { source }) => { out!(self, "declare export * from "); source.visit(ctx, self, Some(node)); } - DeclareModule { id, body, .. } => { + NodeKind::DeclareModule(DeclareModule { id, body, .. }) => { out!(self, "declare module "); id.visit(ctx, self, Some(node)); self.space(ForceSpace::No); body.visit(ctx, self, Some(node)); } - DeclareModuleExports { type_annotation } => { + NodeKind::DeclareModuleExports(DeclareModuleExports { type_annotation }) => { out!(self, "declare module.exports:"); self.space(ForceSpace::No); type_annotation.visit(ctx, self, Some(node)); } - InterfaceExtends { + NodeKind::InterfaceExtends(InterfaceExtends { id, type_parameters, - } - | ClassImplements { + }) + | NodeKind::ClassImplements(ClassImplements { id, type_parameters, - } => { + }) => { id.visit(ctx, self, Some(node)); if let Some(type_parameters) = type_parameters { type_parameters.visit(ctx, self, Some(node)); } } - TypeAnnotation { type_annotation } => { + NodeKind::TypeAnnotation(TypeAnnotation { type_annotation }) => { type_annotation.visit(ctx, self, Some(node)); } - ObjectTypeAnnotation { + NodeKind::ObjectTypeAnnotation(ObjectTypeAnnotation { properties, indexers, call_properties, internal_slots, inexact, exact, - } => { + }) => { out!(self, "{}", if *exact { "{|" } else { "{" }); self.inc_indent(); self.newline(); @@ -2040,7 +2044,7 @@ impl GenJS { self.newline(); out!(self, "{}", if *exact { "|}" } else { "}" }); } - ObjectTypeProperty { + NodeKind::ObjectTypeProperty(ObjectTypeProperty { key, value, method, @@ -2049,7 +2053,7 @@ impl GenJS { proto, variance, .. - } => { + }) => { if let Some(variance) = variance { variance.visit(ctx, self, Some(node)); } @@ -2065,13 +2069,13 @@ impl GenJS { } if *method { match &value.get(ctx).kind { - FunctionTypeAnnotation { + NodeKind::FunctionTypeAnnotation(FunctionTypeAnnotation { params, this, return_type, rest, type_parameters, - } => { + }) => { self.visit_func_type_params( ctx, params, @@ -2094,17 +2098,17 @@ impl GenJS { value.visit(ctx, self, Some(node)); } } - ObjectTypeSpreadProperty { argument } => { + NodeKind::ObjectTypeSpreadProperty(ObjectTypeSpreadProperty { argument }) => { out!(self, "..."); argument.visit(ctx, self, Some(node)); } - ObjectTypeInternalSlot { + NodeKind::ObjectTypeInternalSlot(ObjectTypeInternalSlot { id, value, optional, is_static, method, - } => { + }) => { if *is_static { out!(self, "static "); } @@ -2116,13 +2120,13 @@ impl GenJS { out!(self, "]]"); if *method { match &value.get(ctx).kind { - FunctionTypeAnnotation { + NodeKind::FunctionTypeAnnotation(FunctionTypeAnnotation { params, this, return_type, rest, type_parameters, - } => { + }) => { self.visit_func_type_params( ctx, params, @@ -2145,18 +2149,18 @@ impl GenJS { value.visit(ctx, self, Some(node)); } } - ObjectTypeCallProperty { value, is_static } => { + NodeKind::ObjectTypeCallProperty(ObjectTypeCallProperty { value, is_static }) => { if *is_static { out!(self, "static "); } match &value.get(ctx).kind { - FunctionTypeAnnotation { + NodeKind::FunctionTypeAnnotation(FunctionTypeAnnotation { params, this, return_type, rest, type_parameters, - } => { + }) => { self.visit_func_type_params( ctx, params, @@ -2174,13 +2178,13 @@ impl GenJS { } } } - ObjectTypeIndexer { + NodeKind::ObjectTypeIndexer(ObjectTypeIndexer { id, key, value, is_static, variance, - } => { + }) => { if *is_static { out!(self, "static "); } @@ -2199,7 +2203,7 @@ impl GenJS { self.space(ForceSpace::No); value.visit(ctx, self, Some(node)); } - Variance { kind } => { + NodeKind::Variance(Variance { kind }) => { out!( self, "{}", @@ -2211,7 +2215,8 @@ impl GenJS { ) } - TypeParameterDeclaration { params } | TypeParameterInstantiation { params } => { + NodeKind::TypeParameterDeclaration(TypeParameterDeclaration { params }) + | NodeKind::TypeParameterInstantiation(TypeParameterInstantiation { params }) => { out!(self, "<"); for (i, param) in params.iter().enumerate() { if i > 0 { @@ -2221,12 +2226,12 @@ impl GenJS { } out!(self, ">"); } - TypeParameter { + NodeKind::TypeParameter(TypeParameter { name, bound, variance, default, - } => { + }) => { if let Some(variance) = variance { variance.visit(ctx, self, Some(node)); } @@ -2242,10 +2247,10 @@ impl GenJS { default.visit(ctx, self, Some(node)); } } - TypeCastExpression { + NodeKind::TypeCastExpression(TypeCastExpression { expression, type_annotation, - } => { + }) => { // Type casts are required to have parentheses. out!(self, "("); self.print_child(ctx, Some(*expression), node, ChildPos::Left); @@ -2253,25 +2258,25 @@ impl GenJS { self.space(ForceSpace::No); self.print_child(ctx, Some(*type_annotation), node, ChildPos::Right); } - InferredPredicate => { + NodeKind::InferredPredicate(_) => { out!(self, "%checks"); } - DeclaredPredicate { value } => { + NodeKind::DeclaredPredicate(DeclaredPredicate { value }) => { out!(self, "%checks("); value.visit(ctx, self, Some(node)); out!(self, ")"); } - EnumDeclaration { id, body } => { + NodeKind::EnumDeclaration(EnumDeclaration { id, body }) => { out!(self, "enum "); id.visit(ctx, self, Some(node)); body.visit(ctx, self, Some(node)); } - EnumStringBody { + NodeKind::EnumStringBody(EnumStringBody { members, explicit_type, has_unknown_members, - } => { + }) => { self.visit_enum_body( ctx, "string", @@ -2281,11 +2286,11 @@ impl GenJS { node, ); } - EnumNumberBody { + NodeKind::EnumNumberBody(EnumNumberBody { members, explicit_type, has_unknown_members, - } => { + }) => { self.visit_enum_body( ctx, "number", @@ -2295,11 +2300,11 @@ impl GenJS { node, ); } - EnumBooleanBody { + NodeKind::EnumBooleanBody(EnumBooleanBody { members, explicit_type, has_unknown_members, - } => { + }) => { self.visit_enum_body( ctx, "boolean", @@ -2309,18 +2314,18 @@ impl GenJS { node, ); } - EnumSymbolBody { + NodeKind::EnumSymbolBody(EnumSymbolBody { members, has_unknown_members, - } => { + }) => { self.visit_enum_body(ctx, "symbol", members, true, *has_unknown_members, node); } - EnumDefaultedMember { id } => { + NodeKind::EnumDefaultedMember(EnumDefaultedMember { id }) => { id.visit(ctx, self, Some(node)); } - EnumStringMember { id, init } - | EnumNumberMember { id, init } - | EnumBooleanMember { id, init } => { + NodeKind::EnumStringMember(EnumStringMember { id, init }) + | NodeKind::EnumNumberMember(EnumNumberMember { id, init }) + | NodeKind::EnumBooleanMember(EnumBooleanMember { id, init }) => { id.visit(ctx, self, Some(node)); out!( self, @@ -2535,7 +2540,6 @@ impl GenJS { type_parameters: Option, node: NodePtr, ) { - use NodeKind::*; if let Some(type_parameters) = type_parameters { type_parameters.visit(ctx, self, Some(node)); } @@ -2543,9 +2547,9 @@ impl GenJS { let mut need_comma = false; if let Some(this) = this { match &this.get(ctx).kind { - FunctionTypeParam { + NodeKind::FunctionTypeParam(FunctionTypeParam { type_annotation, .. - } => { + }) => { out!(self, "this:"); self.space(ForceSpace::No); type_annotation.visit(ctx, self, Some(node)); @@ -2654,8 +2658,7 @@ impl GenJS { force_block: ForceBlock, parent: NodePtr, ) -> bool { - use NodeKind::*; - if let BlockStatement { body } = &node.get(ctx).kind { + if let NodeKind::BlockStatement(BlockStatement { body }) = &node.get(ctx).kind { if body.is_empty() { self.space(ForceSpace::No); out!(self, "{{}}"); @@ -2712,28 +2715,27 @@ impl GenJS { // Precedence order taken from // https://github.com/facebook/flow/blob/master/src/parser_utils/output/js_layout_generator.ml use precedence::*; - use NodeKind::*; match &node.kind { - Identifier { .. } - | NullLiteral { .. } - | BooleanLiteral { .. } - | StringLiteral { .. } - | NumericLiteral { .. } - | RegExpLiteral { .. } - | ThisExpression { .. } - | Super { .. } - | ArrayExpression { .. } - | ObjectExpression { .. } - | ObjectPattern { .. } - | FunctionExpression { .. } - | ClassExpression { .. } - | TemplateLiteral { .. } => (PRIMARY, Assoc::Ltr), - MemberExpression { .. } - | OptionalMemberExpression { .. } - | MetaProperty { .. } - | CallExpression { .. } - | OptionalCallExpression { .. } => (MEMBER, Assoc::Ltr), - NewExpression { arguments, .. } => { + NodeKind::Identifier(_) + | NodeKind::NullLiteral(_) + | NodeKind::BooleanLiteral(_) + | NodeKind::StringLiteral(_) + | NodeKind::NumericLiteral(_) + | NodeKind::RegExpLiteral(_) + | NodeKind::ThisExpression(_) + | NodeKind::Super(_) + | NodeKind::ArrayExpression(_) + | NodeKind::ObjectExpression(_) + | NodeKind::ObjectPattern(_) + | NodeKind::FunctionExpression(_) + | NodeKind::ClassExpression(_) + | NodeKind::TemplateLiteral(_) => (PRIMARY, Assoc::Ltr), + NodeKind::MemberExpression(_) + | NodeKind::OptionalMemberExpression(_) + | NodeKind::MetaProperty(_) + | NodeKind::CallExpression(_) + | NodeKind::OptionalCallExpression(_) => (MEMBER, Assoc::Ltr), + NodeKind::NewExpression(NewExpression { arguments, .. }) => { // `new foo()` has higher precedence than `new foo`. In pretty mode we // always append the `()`, but otherwise we must check the number of args. if self.pretty == Pretty::Yes || !arguments.is_empty() { @@ -2742,39 +2744,45 @@ impl GenJS { (NEW_NO_ARGS, Assoc::Ltr) } } - TaggedTemplateExpression { .. } | ImportExpression { .. } => { + NodeKind::TaggedTemplateExpression(_) | NodeKind::ImportExpression(_) => { (TAGGED_TEMPLATE, Assoc::Ltr) } - UpdateExpression { prefix, .. } => { + NodeKind::UpdateExpression(UpdateExpression { prefix, .. }) => { if *prefix { (POST_UPDATE, Assoc::Ltr) } else { (UNARY, Assoc::Rtl) } } - UnaryExpression { .. } => (UNARY, Assoc::Rtl), - BinaryExpression { operator, .. } => (get_binary_precedence(*operator), Assoc::Ltr), - LogicalExpression { operator, .. } => (get_logical_precedence(*operator), Assoc::Ltr), - ConditionalExpression { .. } => (COND, Assoc::Rtl), - AssignmentExpression { .. } => (ASSIGN, Assoc::Rtl), - YieldExpression { .. } | ArrowFunctionExpression { .. } => (YIELD, Assoc::Ltr), - SequenceExpression { .. } => (SEQ, Assoc::Rtl), - - ExistsTypeAnnotation - | EmptyTypeAnnotation - | StringTypeAnnotation - | NumberTypeAnnotation - | StringLiteralTypeAnnotation { .. } - | NumberLiteralTypeAnnotation { .. } - | BooleanTypeAnnotation - | BooleanLiteralTypeAnnotation { .. } - | NullLiteralTypeAnnotation - | SymbolTypeAnnotation - | AnyTypeAnnotation - | MixedTypeAnnotation - | VoidTypeAnnotation => (PRIMARY, Assoc::Ltr), - UnionTypeAnnotation { .. } => (UNION_TYPE, Assoc::Ltr), - IntersectionTypeAnnotation { .. } => (INTERSECTION_TYPE, Assoc::Ltr), + NodeKind::UnaryExpression(_) => (UNARY, Assoc::Rtl), + NodeKind::BinaryExpression(BinaryExpression { operator, .. }) => { + (get_binary_precedence(*operator), Assoc::Ltr) + } + NodeKind::LogicalExpression(LogicalExpression { operator, .. }) => { + (get_logical_precedence(*operator), Assoc::Ltr) + } + NodeKind::ConditionalExpression(_) => (COND, Assoc::Rtl), + NodeKind::AssignmentExpression(_) => (ASSIGN, Assoc::Rtl), + NodeKind::YieldExpression(_) | NodeKind::ArrowFunctionExpression(_) => { + (YIELD, Assoc::Ltr) + } + NodeKind::SequenceExpression(_) => (SEQ, Assoc::Rtl), + + NodeKind::ExistsTypeAnnotation(_) + | NodeKind::EmptyTypeAnnotation(_) + | NodeKind::StringTypeAnnotation(_) + | NodeKind::NumberTypeAnnotation(_) + | NodeKind::StringLiteralTypeAnnotation(_) + | NodeKind::NumberLiteralTypeAnnotation(_) + | NodeKind::BooleanTypeAnnotation(_) + | NodeKind::BooleanLiteralTypeAnnotation(_) + | NodeKind::NullLiteralTypeAnnotation(_) + | NodeKind::SymbolTypeAnnotation(_) + | NodeKind::AnyTypeAnnotation(_) + | NodeKind::MixedTypeAnnotation(_) + | NodeKind::VoidTypeAnnotation(_) => (PRIMARY, Assoc::Ltr), + NodeKind::UnionTypeAnnotation(_) => (UNION_TYPE, Assoc::Ltr), + NodeKind::IntersectionTypeAnnotation(_) => (INTERSECTION_TYPE, Assoc::Ltr), _ => (ALWAYS_PAREN, Assoc::Ltr), } @@ -2789,33 +2797,35 @@ impl GenJS { child: NodePtr, child_pos: ChildPos, ) -> NeedParens { - use NodeKind::*; - let parent_node = parent.get(ctx); let child_node = child.get(ctx); #[allow(clippy::if_same_then_else)] - if matches!(parent_node.kind, ArrowFunctionExpression { .. }) { + if matches!(parent_node.kind, NodeKind::ArrowFunctionExpression(_)) { // (x) => ({x: 10}) needs parens to avoid confusing it with a block and a // labelled statement. - if child_pos == ChildPos::Right && matches!(child_node.kind, ObjectExpression { .. }) { + if child_pos == ChildPos::Right + && matches!(child_node.kind, NodeKind::ObjectExpression(_)) + { return NeedParens::Yes; } - } else if matches!(parent_node.kind, ForStatement { .. }) { + } else if matches!(parent_node.kind, NodeKind::ForStatement(_)) { // for((a in b);..;..) needs parens to avoid confusing it with for(a in b). return NeedParens::from(match &child_node.kind { - BinaryExpression { operator, .. } => *operator == BinaryExpressionOperator::In, + NodeKind::BinaryExpression(BinaryExpression { operator, .. }) => { + *operator == BinaryExpressionOperator::In + } _ => false, }); - } else if matches!(parent_node.kind, ExpressionStatement { .. }) { + } else if matches!(parent_node.kind, NodeKind::ExpressionStatement(_)) { // Expression statement like (function () {} + 1) needs parens. return NeedParens::from(self.root_starts_with(ctx, child, |kind| -> bool { matches!( kind, - FunctionExpression { .. } - | ClassExpression { .. } - | ObjectExpression { .. } - | ObjectPattern { .. } + NodeKind::FunctionExpression(_) + | NodeKind::ClassExpression(_) + | NodeKind::ObjectExpression(_) + | NodeKind::ObjectPattern(_) ) })); } else if (parent_node.kind.is_unary_op(UnaryExpressionOperator::Minus) @@ -2844,10 +2854,10 @@ impl GenJS { }; } else if matches!( parent_node.kind, - MemberExpression { .. } | CallExpression { .. } + NodeKind::MemberExpression(_) | NodeKind::CallExpression(_) ) && matches!( child_node.kind, - OptionalMemberExpression { .. } | OptionalCallExpression { .. } + NodeKind::OptionalMemberExpression(_) | NodeKind::OptionalCallExpression(_) ) && child_pos == ChildPos::Left { // When optional chains are terminated by non-optional member/calls, @@ -2910,8 +2920,6 @@ impl GenJS { parent: Option, pred: F, ) -> bool { - use NodeKind::*; - if let Some(parent) = parent { if self.need_parens(ctx, parent, expr, ChildPos::Left) == NeedParens::Yes { return false; @@ -2925,28 +2933,35 @@ impl GenJS { // Ensure the recursive calls are the last things to run, // hopefully the compiler makes this into a loop. match &expr.get(ctx).kind { - CallExpression { callee, .. } => self.expr_starts_with(ctx, *callee, Some(expr), pred), - OptionalCallExpression { callee, .. } => { + NodeKind::CallExpression(CallExpression { callee, .. }) => { self.expr_starts_with(ctx, *callee, Some(expr), pred) } - BinaryExpression { left, .. } => self.expr_starts_with(ctx, *left, Some(expr), pred), - LogicalExpression { left, .. } => self.expr_starts_with(ctx, *left, Some(expr), pred), - ConditionalExpression { test, .. } => { + NodeKind::OptionalCallExpression(OptionalCallExpression { callee, .. }) => { + self.expr_starts_with(ctx, *callee, Some(expr), pred) + } + NodeKind::BinaryExpression(BinaryExpression { left, .. }) => { + self.expr_starts_with(ctx, *left, Some(expr), pred) + } + NodeKind::LogicalExpression(LogicalExpression { left, .. }) => { + self.expr_starts_with(ctx, *left, Some(expr), pred) + } + NodeKind::ConditionalExpression(ConditionalExpression { test, .. }) => { self.expr_starts_with(ctx, *test, Some(expr), pred) } - AssignmentExpression { left, .. } => { + NodeKind::AssignmentExpression(AssignmentExpression { left, .. }) => { self.expr_starts_with(ctx, *left, Some(expr), pred) } - UpdateExpression { + NodeKind::UpdateExpression(UpdateExpression { prefix, argument, .. - } => !*prefix && self.expr_starts_with(ctx, *argument, Some(expr), pred), - UnaryExpression { + }) => !*prefix && self.expr_starts_with(ctx, *argument, Some(expr), pred), + NodeKind::UnaryExpression(UnaryExpression { prefix, argument, .. - } => !*prefix && self.expr_starts_with(ctx, *argument, Some(expr), pred), - MemberExpression { object, .. } | OptionalMemberExpression { object, .. } => { + }) => !*prefix && self.expr_starts_with(ctx, *argument, Some(expr), pred), + NodeKind::MemberExpression(MemberExpression { object, .. }) + | NodeKind::OptionalMemberExpression(OptionalMemberExpression { object, .. }) => { self.expr_starts_with(ctx, *object, Some(expr), pred) } - TaggedTemplateExpression { tag, .. } => { + NodeKind::TaggedTemplateExpression(TaggedTemplateExpression { tag, .. }) => { self.expr_starts_with(ctx, *tag, Some(expr), pred) } _ => false, @@ -3001,37 +3016,37 @@ impl Visitor for GenJS { impl NodeKind { fn is_unary_op(&self, op: UnaryExpressionOperator) -> bool { match self { - NodeKind::UnaryExpression { operator, .. } => *operator == op, + NodeKind::UnaryExpression(UnaryExpression { operator, .. }) => *operator == op, _ => false, } } fn is_update_prefix(&self, op: UpdateExpressionOperator) -> bool { match self { - NodeKind::UpdateExpression { + NodeKind::UpdateExpression(UpdateExpression { prefix, operator, .. - } => *prefix && *operator == op, + }) => *prefix && *operator == op, _ => false, } } fn is_negative_number(&self) -> bool { match self { - NodeKind::NumericLiteral { value, .. } => *value < 0f64, + NodeKind::NumericLiteral(NumericLiteral { value, .. }) => *value < 0f64, _ => false, } } fn is_binary_op(&self, op: BinaryExpressionOperator) -> bool { match self { - NodeKind::BinaryExpression { operator, .. } => *operator == op, + NodeKind::BinaryExpression(BinaryExpression { operator, .. }) => *operator == op, _ => false, } } fn is_if_without_else(&self) -> bool { match self { - NodeKind::IfStatement { alternate, .. } => alternate.is_none(), + NodeKind::IfStatement(IfStatement { alternate, .. }) => alternate.is_none(), _ => false, } } @@ -3049,48 +3064,61 @@ impl NodeKind { fn check_and_or(&self) -> bool { matches!( self, - NodeKind::LogicalExpression { + NodeKind::LogicalExpression(LogicalExpression { operator: LogicalExpressionOperator::And | LogicalExpressionOperator::Or, .. - } + }) ) } fn check_nullish(&self) -> bool { matches!( self, - NodeKind::LogicalExpression { + NodeKind::LogicalExpression(LogicalExpression { operator: LogicalExpressionOperator::NullishCoalesce, .. - } + }) ) } } fn ends_with_block(ctx: &Context, node: Option) -> bool { - use NodeKind::*; match node { Some(node) => match &node.get(ctx).kind { - BlockStatement { .. } | FunctionDeclaration { .. } => true, - WhileStatement { body, .. } => ends_with_block(ctx, Some(*body)), - ForStatement { body, .. } => ends_with_block(ctx, Some(*body)), - ForInStatement { body, .. } => ends_with_block(ctx, Some(*body)), - ForOfStatement { body, .. } => ends_with_block(ctx, Some(*body)), - WithStatement { body, .. } => ends_with_block(ctx, Some(*body)), - SwitchStatement { .. } => true, - LabeledStatement { body, .. } => ends_with_block(ctx, Some(*body)), - TryStatement { + NodeKind::BlockStatement(_) | NodeKind::FunctionDeclaration(_) => true, + NodeKind::WhileStatement(WhileStatement { body, .. }) => { + ends_with_block(ctx, Some(*body)) + } + NodeKind::ForStatement(ForStatement { body, .. }) => ends_with_block(ctx, Some(*body)), + NodeKind::ForInStatement(ForInStatement { body, .. }) => { + ends_with_block(ctx, Some(*body)) + } + NodeKind::ForOfStatement(ForOfStatement { body, .. }) => { + ends_with_block(ctx, Some(*body)) + } + NodeKind::WithStatement(WithStatement { body, .. }) => { + ends_with_block(ctx, Some(*body)) + } + NodeKind::SwitchStatement(_) => true, + NodeKind::LabeledStatement(LabeledStatement { body, .. }) => { + ends_with_block(ctx, Some(*body)) + } + NodeKind::TryStatement(TryStatement { finalizer, handler, .. - } => ends_with_block(ctx, finalizer.or(*handler)), - CatchClause { body, .. } => ends_with_block(ctx, Some(*body)), - IfStatement { + }) => ends_with_block(ctx, finalizer.or(*handler)), + NodeKind::CatchClause(CatchClause { body, .. }) => ends_with_block(ctx, Some(*body)), + NodeKind::IfStatement(IfStatement { alternate, consequent, .. - } => ends_with_block(ctx, alternate.or(Some(*consequent))), - ClassDeclaration { .. } => true, - ExportDefaultDeclaration { declaration } => ends_with_block(ctx, Some(*declaration)), - ExportNamedDeclaration { declaration, .. } => ends_with_block(ctx, *declaration), + }) => ends_with_block(ctx, alternate.or(Some(*consequent))), + NodeKind::ClassDeclaration(_) => true, + NodeKind::ExportDefaultDeclaration(ExportDefaultDeclaration { declaration }) => { + ends_with_block(ctx, Some(*declaration)) + } + NodeKind::ExportNamedDeclaration(ExportNamedDeclaration { declaration, .. }) => { + ends_with_block(ctx, *declaration) + } _ => false, }, None => false, diff --git a/unsupported/juno/src/hparser/generated_cvt.rs b/unsupported/juno/src/hparser/generated_cvt.rs index b73c58923c7..8d2e7492caa 100644 --- a/unsupported/juno/src/hparser/generated_cvt.rs +++ b/unsupported/juno/src/hparser/generated_cvt.rs @@ -25,8 +25,8 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::Empty { - }, + kind: ast::NodeKind::Empty(ast::Empty { + }), } ) } @@ -34,8 +34,8 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::Metadata { - }, + kind: ast::NodeKind::Metadata(ast::Metadata { + }), } ) } @@ -44,9 +44,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::Program { + kind: ast::NodeKind::Program(ast::Program { body, - }, + }), } ) } @@ -62,7 +62,7 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::FunctionExpression { + kind: ast::NodeKind::FunctionExpression(ast::FunctionExpression { id, params, body, @@ -71,7 +71,7 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { predicate, generator, is_async, - }, + }), } ) } @@ -87,7 +87,7 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ArrowFunctionExpression { + kind: ast::NodeKind::ArrowFunctionExpression(ast::ArrowFunctionExpression { id, params, body, @@ -96,7 +96,7 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { predicate, expression, is_async, - }, + }), } ) } @@ -112,7 +112,7 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::FunctionDeclaration { + kind: ast::NodeKind::FunctionDeclaration(ast::FunctionDeclaration { id, params, body, @@ -121,7 +121,7 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { predicate, generator, is_async, - }, + }), } ) } @@ -131,10 +131,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::WhileStatement { + kind: ast::NodeKind::WhileStatement(ast::WhileStatement { body, test, - }, + }), } ) } @@ -144,10 +144,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::DoWhileStatement { + kind: ast::NodeKind::DoWhileStatement(ast::DoWhileStatement { body, test, - }, + }), } ) } @@ -158,11 +158,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ForInStatement { + kind: ast::NodeKind::ForInStatement(ast::ForInStatement { left, right, body, - }, + }), } ) } @@ -174,12 +174,12 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ForOfStatement { + kind: ast::NodeKind::ForOfStatement(ast::ForOfStatement { left, right, body, is_await, - }, + }), } ) } @@ -191,12 +191,12 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ForStatement { + kind: ast::NodeKind::ForStatement(ast::ForStatement { init, test, update, body, - }, + }), } ) } @@ -204,8 +204,8 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::DebuggerStatement { - }, + kind: ast::NodeKind::DebuggerStatement(ast::DebuggerStatement { + }), } ) } @@ -213,8 +213,8 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::EmptyStatement { - }, + kind: ast::NodeKind::EmptyStatement(ast::EmptyStatement { + }), } ) } @@ -223,9 +223,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::BlockStatement { + kind: ast::NodeKind::BlockStatement(ast::BlockStatement { body, - }, + }), } ) } @@ -234,9 +234,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::BreakStatement { + kind: ast::NodeKind::BreakStatement(ast::BreakStatement { label, - }, + }), } ) } @@ -245,9 +245,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ContinueStatement { + kind: ast::NodeKind::ContinueStatement(ast::ContinueStatement { label, - }, + }), } ) } @@ -256,9 +256,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ThrowStatement { + kind: ast::NodeKind::ThrowStatement(ast::ThrowStatement { argument, - }, + }), } ) } @@ -267,9 +267,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ReturnStatement { + kind: ast::NodeKind::ReturnStatement(ast::ReturnStatement { argument, - }, + }), } ) } @@ -279,10 +279,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::WithStatement { + kind: ast::NodeKind::WithStatement(ast::WithStatement { object, body, - }, + }), } ) } @@ -292,10 +292,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::SwitchStatement { + kind: ast::NodeKind::SwitchStatement(ast::SwitchStatement { discriminant, cases, - }, + }), } ) } @@ -305,10 +305,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::LabeledStatement { + kind: ast::NodeKind::LabeledStatement(ast::LabeledStatement { label, body, - }, + }), } ) } @@ -318,10 +318,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ExpressionStatement { + kind: ast::NodeKind::ExpressionStatement(ast::ExpressionStatement { expression, directive, - }, + }), } ) } @@ -332,11 +332,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TryStatement { + kind: ast::NodeKind::TryStatement(ast::TryStatement { block, handler, finalizer, - }, + }), } ) } @@ -347,11 +347,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::IfStatement { + kind: ast::NodeKind::IfStatement(ast::IfStatement { test, consequent, alternate, - }, + }), } ) } @@ -359,8 +359,8 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::NullLiteral { - }, + kind: ast::NodeKind::NullLiteral(ast::NullLiteral { + }), } ) } @@ -369,9 +369,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::BooleanLiteral { + kind: ast::NodeKind::BooleanLiteral(ast::BooleanLiteral { value, - }, + }), } ) } @@ -380,9 +380,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::StringLiteral { + kind: ast::NodeKind::StringLiteral(ast::StringLiteral { value, - }, + }), } ) } @@ -391,9 +391,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::NumericLiteral { + kind: ast::NodeKind::NumericLiteral(ast::NumericLiteral { value, - }, + }), } ) } @@ -403,10 +403,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::RegExpLiteral { + kind: ast::NodeKind::RegExpLiteral(ast::RegExpLiteral { pattern, flags, - }, + }), } ) } @@ -414,8 +414,8 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ThisExpression { - }, + kind: ast::NodeKind::ThisExpression(ast::ThisExpression { + }), } ) } @@ -423,8 +423,8 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::Super { - }, + kind: ast::NodeKind::Super(ast::Super { + }), } ) } @@ -433,9 +433,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::SequenceExpression { + kind: ast::NodeKind::SequenceExpression(ast::SequenceExpression { expressions, - }, + }), } ) } @@ -444,9 +444,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ObjectExpression { + kind: ast::NodeKind::ObjectExpression(ast::ObjectExpression { properties, - }, + }), } ) } @@ -456,10 +456,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ArrayExpression { + kind: ast::NodeKind::ArrayExpression(ast::ArrayExpression { elements, trailing_comma, - }, + }), } ) } @@ -468,9 +468,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::SpreadElement { + kind: ast::NodeKind::SpreadElement(ast::SpreadElement { argument, - }, + }), } ) } @@ -481,11 +481,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::NewExpression { + kind: ast::NodeKind::NewExpression(ast::NewExpression { callee, type_arguments, arguments, - }, + }), } ) } @@ -495,10 +495,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::YieldExpression { + kind: ast::NodeKind::YieldExpression(ast::YieldExpression { argument, delegate, - }, + }), } ) } @@ -507,9 +507,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::AwaitExpression { + kind: ast::NodeKind::AwaitExpression(ast::AwaitExpression { argument, - }, + }), } ) } @@ -519,10 +519,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ImportExpression { + kind: ast::NodeKind::ImportExpression(ast::ImportExpression { source, attributes, - }, + }), } ) } @@ -533,11 +533,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::CallExpression { + kind: ast::NodeKind::CallExpression(ast::CallExpression { callee, type_arguments, arguments, - }, + }), } ) } @@ -549,12 +549,12 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::OptionalCallExpression { + kind: ast::NodeKind::OptionalCallExpression(ast::OptionalCallExpression { callee, type_arguments, arguments, optional, - }, + }), } ) } @@ -565,11 +565,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::AssignmentExpression { + kind: ast::NodeKind::AssignmentExpression(ast::AssignmentExpression { operator, left, right, - }, + }), } ) } @@ -580,11 +580,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::UnaryExpression { + kind: ast::NodeKind::UnaryExpression(ast::UnaryExpression { operator, argument, prefix, - }, + }), } ) } @@ -595,11 +595,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::UpdateExpression { + kind: ast::NodeKind::UpdateExpression(ast::UpdateExpression { operator, argument, prefix, - }, + }), } ) } @@ -610,11 +610,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::MemberExpression { + kind: ast::NodeKind::MemberExpression(ast::MemberExpression { object, property, computed, - }, + }), } ) } @@ -626,12 +626,12 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::OptionalMemberExpression { + kind: ast::NodeKind::OptionalMemberExpression(ast::OptionalMemberExpression { object, property, computed, optional, - }, + }), } ) } @@ -642,11 +642,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::LogicalExpression { + kind: ast::NodeKind::LogicalExpression(ast::LogicalExpression { left, right, operator, - }, + }), } ) } @@ -657,11 +657,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ConditionalExpression { + kind: ast::NodeKind::ConditionalExpression(ast::ConditionalExpression { test, alternate, consequent, - }, + }), } ) } @@ -672,11 +672,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::BinaryExpression { + kind: ast::NodeKind::BinaryExpression(ast::BinaryExpression { left, right, operator, - }, + }), } ) } @@ -685,9 +685,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::Directive { + kind: ast::NodeKind::Directive(ast::Directive { value, - }, + }), } ) } @@ -696,9 +696,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::DirectiveLiteral { + kind: ast::NodeKind::DirectiveLiteral(ast::DirectiveLiteral { value, - }, + }), } ) } @@ -709,11 +709,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::Identifier { + kind: ast::NodeKind::Identifier(ast::Identifier { name, type_annotation, optional, - }, + }), } ) } @@ -722,9 +722,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::PrivateName { + kind: ast::NodeKind::PrivateName(ast::PrivateName { id, - }, + }), } ) } @@ -734,10 +734,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::MetaProperty { + kind: ast::NodeKind::MetaProperty(ast::MetaProperty { meta, property, - }, + }), } ) } @@ -747,10 +747,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::SwitchCase { + kind: ast::NodeKind::SwitchCase(ast::SwitchCase { test, consequent, - }, + }), } ) } @@ -760,10 +760,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::CatchClause { + kind: ast::NodeKind::CatchClause(ast::CatchClause { param, body, - }, + }), } ) } @@ -773,10 +773,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::VariableDeclarator { + kind: ast::NodeKind::VariableDeclarator(ast::VariableDeclarator { init, id, - }, + }), } ) } @@ -786,10 +786,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::VariableDeclaration { + kind: ast::NodeKind::VariableDeclaration(ast::VariableDeclaration { kind, declarations, - }, + }), } ) } @@ -799,10 +799,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TemplateLiteral { + kind: ast::NodeKind::TemplateLiteral(ast::TemplateLiteral { quasis, expressions, - }, + }), } ) } @@ -812,10 +812,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TaggedTemplateExpression { + kind: ast::NodeKind::TaggedTemplateExpression(ast::TaggedTemplateExpression { tag, quasi, - }, + }), } ) } @@ -826,11 +826,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TemplateElement { + kind: ast::NodeKind::TemplateElement(ast::TemplateElement { tail, cooked, raw, - }, + }), } ) } @@ -844,14 +844,14 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::Property { + kind: ast::NodeKind::Property(ast::Property { key, value, kind, computed, method, shorthand, - }, + }), } ) } @@ -866,7 +866,7 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ClassDeclaration { + kind: ast::NodeKind::ClassDeclaration(ast::ClassDeclaration { id, type_parameters, super_class, @@ -874,7 +874,7 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { implements, decorators, body, - }, + }), } ) } @@ -889,7 +889,7 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ClassExpression { + kind: ast::NodeKind::ClassExpression(ast::ClassExpression { id, type_parameters, super_class, @@ -897,7 +897,7 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { implements, decorators, body, - }, + }), } ) } @@ -906,9 +906,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ClassBody { + kind: ast::NodeKind::ClassBody(ast::ClassBody { body, - }, + }), } ) } @@ -924,7 +924,7 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ClassProperty { + kind: ast::NodeKind::ClassProperty(ast::ClassProperty { key, value, computed, @@ -933,7 +933,7 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { optional, variance, type_annotation, - }, + }), } ) } @@ -948,7 +948,7 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ClassPrivateProperty { + kind: ast::NodeKind::ClassPrivateProperty(ast::ClassPrivateProperty { key, value, is_static, @@ -956,7 +956,7 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { optional, variance, type_annotation, - }, + }), } ) } @@ -969,13 +969,13 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::MethodDefinition { + kind: ast::NodeKind::MethodDefinition(ast::MethodDefinition { key, value, kind, computed, is_static, - }, + }), } ) } @@ -987,12 +987,12 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ImportDeclaration { + kind: ast::NodeKind::ImportDeclaration(ast::ImportDeclaration { specifiers, source, attributes, import_kind, - }, + }), } ) } @@ -1003,11 +1003,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ImportSpecifier { + kind: ast::NodeKind::ImportSpecifier(ast::ImportSpecifier { imported, local, import_kind, - }, + }), } ) } @@ -1016,9 +1016,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ImportDefaultSpecifier { + kind: ast::NodeKind::ImportDefaultSpecifier(ast::ImportDefaultSpecifier { local, - }, + }), } ) } @@ -1027,9 +1027,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ImportNamespaceSpecifier { + kind: ast::NodeKind::ImportNamespaceSpecifier(ast::ImportNamespaceSpecifier { local, - }, + }), } ) } @@ -1039,10 +1039,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ImportAttribute { + kind: ast::NodeKind::ImportAttribute(ast::ImportAttribute { key, value, - }, + }), } ) } @@ -1054,12 +1054,12 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ExportNamedDeclaration { + kind: ast::NodeKind::ExportNamedDeclaration(ast::ExportNamedDeclaration { declaration, specifiers, source, export_kind, - }, + }), } ) } @@ -1069,10 +1069,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ExportSpecifier { + kind: ast::NodeKind::ExportSpecifier(ast::ExportSpecifier { exported, local, - }, + }), } ) } @@ -1081,9 +1081,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ExportNamespaceSpecifier { + kind: ast::NodeKind::ExportNamespaceSpecifier(ast::ExportNamespaceSpecifier { exported, - }, + }), } ) } @@ -1092,9 +1092,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ExportDefaultDeclaration { + kind: ast::NodeKind::ExportDefaultDeclaration(ast::ExportDefaultDeclaration { declaration, - }, + }), } ) } @@ -1104,10 +1104,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ExportAllDeclaration { + kind: ast::NodeKind::ExportAllDeclaration(ast::ExportAllDeclaration { source, export_kind, - }, + }), } ) } @@ -1117,10 +1117,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ObjectPattern { + kind: ast::NodeKind::ObjectPattern(ast::ObjectPattern { properties, type_annotation, - }, + }), } ) } @@ -1130,10 +1130,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ArrayPattern { + kind: ast::NodeKind::ArrayPattern(ast::ArrayPattern { elements, type_annotation, - }, + }), } ) } @@ -1142,9 +1142,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::RestElement { + kind: ast::NodeKind::RestElement(ast::RestElement { argument, - }, + }), } ) } @@ -1154,10 +1154,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::AssignmentPattern { + kind: ast::NodeKind::AssignmentPattern(ast::AssignmentPattern { left, right, - }, + }), } ) } @@ -1166,9 +1166,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::JSXIdentifier { + kind: ast::NodeKind::JSXIdentifier(ast::JSXIdentifier { name, - }, + }), } ) } @@ -1178,10 +1178,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::JSXMemberExpression { + kind: ast::NodeKind::JSXMemberExpression(ast::JSXMemberExpression { object, property, - }, + }), } ) } @@ -1191,10 +1191,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::JSXNamespacedName { + kind: ast::NodeKind::JSXNamespacedName(ast::JSXNamespacedName { namespace, name, - }, + }), } ) } @@ -1202,8 +1202,8 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::JSXEmptyExpression { - }, + kind: ast::NodeKind::JSXEmptyExpression(ast::JSXEmptyExpression { + }), } ) } @@ -1212,9 +1212,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::JSXExpressionContainer { + kind: ast::NodeKind::JSXExpressionContainer(ast::JSXExpressionContainer { expression, - }, + }), } ) } @@ -1223,9 +1223,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::JSXSpreadChild { + kind: ast::NodeKind::JSXSpreadChild(ast::JSXSpreadChild { expression, - }, + }), } ) } @@ -1236,11 +1236,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::JSXOpeningElement { + kind: ast::NodeKind::JSXOpeningElement(ast::JSXOpeningElement { name, attributes, self_closing, - }, + }), } ) } @@ -1249,9 +1249,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::JSXClosingElement { + kind: ast::NodeKind::JSXClosingElement(ast::JSXClosingElement { name, - }, + }), } ) } @@ -1261,10 +1261,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::JSXAttribute { + kind: ast::NodeKind::JSXAttribute(ast::JSXAttribute { name, value, - }, + }), } ) } @@ -1273,9 +1273,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::JSXSpreadAttribute { + kind: ast::NodeKind::JSXSpreadAttribute(ast::JSXSpreadAttribute { argument, - }, + }), } ) } @@ -1285,10 +1285,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::JSXText { + kind: ast::NodeKind::JSXText(ast::JSXText { value, raw, - }, + }), } ) } @@ -1299,11 +1299,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::JSXElement { + kind: ast::NodeKind::JSXElement(ast::JSXElement { opening_element, children, closing_element, - }, + }), } ) } @@ -1314,11 +1314,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::JSXFragment { + kind: ast::NodeKind::JSXFragment(ast::JSXFragment { opening_fragment, children, closing_fragment, - }, + }), } ) } @@ -1326,8 +1326,8 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::JSXOpeningFragment { - }, + kind: ast::NodeKind::JSXOpeningFragment(ast::JSXOpeningFragment { + }), } ) } @@ -1335,8 +1335,8 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::JSXClosingFragment { - }, + kind: ast::NodeKind::JSXClosingFragment(ast::JSXClosingFragment { + }), } ) } @@ -1344,8 +1344,8 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ExistsTypeAnnotation { - }, + kind: ast::NodeKind::ExistsTypeAnnotation(ast::ExistsTypeAnnotation { + }), } ) } @@ -1353,8 +1353,8 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::EmptyTypeAnnotation { - }, + kind: ast::NodeKind::EmptyTypeAnnotation(ast::EmptyTypeAnnotation { + }), } ) } @@ -1362,8 +1362,8 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::StringTypeAnnotation { - }, + kind: ast::NodeKind::StringTypeAnnotation(ast::StringTypeAnnotation { + }), } ) } @@ -1371,8 +1371,8 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::NumberTypeAnnotation { - }, + kind: ast::NodeKind::NumberTypeAnnotation(ast::NumberTypeAnnotation { + }), } ) } @@ -1381,9 +1381,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::StringLiteralTypeAnnotation { + kind: ast::NodeKind::StringLiteralTypeAnnotation(ast::StringLiteralTypeAnnotation { value, - }, + }), } ) } @@ -1393,10 +1393,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::NumberLiteralTypeAnnotation { + kind: ast::NodeKind::NumberLiteralTypeAnnotation(ast::NumberLiteralTypeAnnotation { value, raw, - }, + }), } ) } @@ -1404,8 +1404,8 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::BooleanTypeAnnotation { - }, + kind: ast::NodeKind::BooleanTypeAnnotation(ast::BooleanTypeAnnotation { + }), } ) } @@ -1415,10 +1415,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::BooleanLiteralTypeAnnotation { + kind: ast::NodeKind::BooleanLiteralTypeAnnotation(ast::BooleanLiteralTypeAnnotation { value, raw, - }, + }), } ) } @@ -1426,8 +1426,8 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::NullLiteralTypeAnnotation { - }, + kind: ast::NodeKind::NullLiteralTypeAnnotation(ast::NullLiteralTypeAnnotation { + }), } ) } @@ -1435,8 +1435,8 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::SymbolTypeAnnotation { - }, + kind: ast::NodeKind::SymbolTypeAnnotation(ast::SymbolTypeAnnotation { + }), } ) } @@ -1444,8 +1444,8 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::AnyTypeAnnotation { - }, + kind: ast::NodeKind::AnyTypeAnnotation(ast::AnyTypeAnnotation { + }), } ) } @@ -1453,8 +1453,8 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::MixedTypeAnnotation { - }, + kind: ast::NodeKind::MixedTypeAnnotation(ast::MixedTypeAnnotation { + }), } ) } @@ -1462,8 +1462,8 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::VoidTypeAnnotation { - }, + kind: ast::NodeKind::VoidTypeAnnotation(ast::VoidTypeAnnotation { + }), } ) } @@ -1476,13 +1476,13 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::FunctionTypeAnnotation { + kind: ast::NodeKind::FunctionTypeAnnotation(ast::FunctionTypeAnnotation { params, this, return_type, rest, type_parameters, - }, + }), } ) } @@ -1493,11 +1493,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::FunctionTypeParam { + kind: ast::NodeKind::FunctionTypeParam(ast::FunctionTypeParam { name, type_annotation, optional, - }, + }), } ) } @@ -1506,9 +1506,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::NullableTypeAnnotation { + kind: ast::NodeKind::NullableTypeAnnotation(ast::NullableTypeAnnotation { type_annotation, - }, + }), } ) } @@ -1518,10 +1518,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::QualifiedTypeIdentifier { + kind: ast::NodeKind::QualifiedTypeIdentifier(ast::QualifiedTypeIdentifier { qualification, id, - }, + }), } ) } @@ -1530,9 +1530,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TypeofTypeAnnotation { + kind: ast::NodeKind::TypeofTypeAnnotation(ast::TypeofTypeAnnotation { argument, - }, + }), } ) } @@ -1541,9 +1541,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TupleTypeAnnotation { + kind: ast::NodeKind::TupleTypeAnnotation(ast::TupleTypeAnnotation { types, - }, + }), } ) } @@ -1552,9 +1552,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ArrayTypeAnnotation { + kind: ast::NodeKind::ArrayTypeAnnotation(ast::ArrayTypeAnnotation { element_type, - }, + }), } ) } @@ -1563,9 +1563,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::UnionTypeAnnotation { + kind: ast::NodeKind::UnionTypeAnnotation(ast::UnionTypeAnnotation { types, - }, + }), } ) } @@ -1574,9 +1574,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::IntersectionTypeAnnotation { + kind: ast::NodeKind::IntersectionTypeAnnotation(ast::IntersectionTypeAnnotation { types, - }, + }), } ) } @@ -1586,10 +1586,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::GenericTypeAnnotation { + kind: ast::NodeKind::GenericTypeAnnotation(ast::GenericTypeAnnotation { id, type_parameters, - }, + }), } ) } @@ -1599,10 +1599,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::IndexedAccessType { + kind: ast::NodeKind::IndexedAccessType(ast::IndexedAccessType { object_type, index_type, - }, + }), } ) } @@ -1613,11 +1613,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::OptionalIndexedAccessType { + kind: ast::NodeKind::OptionalIndexedAccessType(ast::OptionalIndexedAccessType { object_type, index_type, optional, - }, + }), } ) } @@ -1627,10 +1627,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::InterfaceTypeAnnotation { + kind: ast::NodeKind::InterfaceTypeAnnotation(ast::InterfaceTypeAnnotation { extends, body, - }, + }), } ) } @@ -1641,11 +1641,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TypeAlias { + kind: ast::NodeKind::TypeAlias(ast::TypeAlias { id, type_parameters, right, - }, + }), } ) } @@ -1657,12 +1657,12 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::OpaqueType { + kind: ast::NodeKind::OpaqueType(ast::OpaqueType { id, type_parameters, impltype, supertype, - }, + }), } ) } @@ -1674,12 +1674,12 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::InterfaceDeclaration { + kind: ast::NodeKind::InterfaceDeclaration(ast::InterfaceDeclaration { id, type_parameters, extends, body, - }, + }), } ) } @@ -1690,11 +1690,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::DeclareTypeAlias { + kind: ast::NodeKind::DeclareTypeAlias(ast::DeclareTypeAlias { id, type_parameters, right, - }, + }), } ) } @@ -1706,12 +1706,12 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::DeclareOpaqueType { + kind: ast::NodeKind::DeclareOpaqueType(ast::DeclareOpaqueType { id, type_parameters, impltype, supertype, - }, + }), } ) } @@ -1723,12 +1723,12 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::DeclareInterface { + kind: ast::NodeKind::DeclareInterface(ast::DeclareInterface { id, type_parameters, extends, body, - }, + }), } ) } @@ -1742,14 +1742,14 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::DeclareClass { + kind: ast::NodeKind::DeclareClass(ast::DeclareClass { id, type_parameters, extends, implements, mixins, body, - }, + }), } ) } @@ -1759,10 +1759,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::DeclareFunction { + kind: ast::NodeKind::DeclareFunction(ast::DeclareFunction { id, predicate, - }, + }), } ) } @@ -1771,9 +1771,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::DeclareVariable { + kind: ast::NodeKind::DeclareVariable(ast::DeclareVariable { id, - }, + }), } ) } @@ -1785,12 +1785,12 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::DeclareExportDeclaration { + kind: ast::NodeKind::DeclareExportDeclaration(ast::DeclareExportDeclaration { declaration, specifiers, source, default, - }, + }), } ) } @@ -1799,9 +1799,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::DeclareExportAllDeclaration { + kind: ast::NodeKind::DeclareExportAllDeclaration(ast::DeclareExportAllDeclaration { source, - }, + }), } ) } @@ -1812,11 +1812,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::DeclareModule { + kind: ast::NodeKind::DeclareModule(ast::DeclareModule { id, body, kind, - }, + }), } ) } @@ -1825,9 +1825,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::DeclareModuleExports { + kind: ast::NodeKind::DeclareModuleExports(ast::DeclareModuleExports { type_annotation, - }, + }), } ) } @@ -1837,10 +1837,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::InterfaceExtends { + kind: ast::NodeKind::InterfaceExtends(ast::InterfaceExtends { id, type_parameters, - }, + }), } ) } @@ -1850,10 +1850,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ClassImplements { + kind: ast::NodeKind::ClassImplements(ast::ClassImplements { id, type_parameters, - }, + }), } ) } @@ -1862,9 +1862,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TypeAnnotation { + kind: ast::NodeKind::TypeAnnotation(ast::TypeAnnotation { type_annotation, - }, + }), } ) } @@ -1878,14 +1878,14 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ObjectTypeAnnotation { + kind: ast::NodeKind::ObjectTypeAnnotation(ast::ObjectTypeAnnotation { properties, indexers, call_properties, internal_slots, inexact, exact, - }, + }), } ) } @@ -1901,7 +1901,7 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ObjectTypeProperty { + kind: ast::NodeKind::ObjectTypeProperty(ast::ObjectTypeProperty { key, value, method, @@ -1910,7 +1910,7 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { proto, variance, kind, - }, + }), } ) } @@ -1919,9 +1919,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ObjectTypeSpreadProperty { + kind: ast::NodeKind::ObjectTypeSpreadProperty(ast::ObjectTypeSpreadProperty { argument, - }, + }), } ) } @@ -1934,13 +1934,13 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ObjectTypeInternalSlot { + kind: ast::NodeKind::ObjectTypeInternalSlot(ast::ObjectTypeInternalSlot { id, value, optional, is_static, method, - }, + }), } ) } @@ -1950,10 +1950,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ObjectTypeCallProperty { + kind: ast::NodeKind::ObjectTypeCallProperty(ast::ObjectTypeCallProperty { value, is_static, - }, + }), } ) } @@ -1966,13 +1966,13 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::ObjectTypeIndexer { + kind: ast::NodeKind::ObjectTypeIndexer(ast::ObjectTypeIndexer { id, key, value, is_static, variance, - }, + }), } ) } @@ -1981,9 +1981,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::Variance { + kind: ast::NodeKind::Variance(ast::Variance { kind, - }, + }), } ) } @@ -1992,9 +1992,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TypeParameterDeclaration { + kind: ast::NodeKind::TypeParameterDeclaration(ast::TypeParameterDeclaration { params, - }, + }), } ) } @@ -2006,12 +2006,12 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TypeParameter { + kind: ast::NodeKind::TypeParameter(ast::TypeParameter { name, bound, variance, default, - }, + }), } ) } @@ -2020,9 +2020,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TypeParameterInstantiation { + kind: ast::NodeKind::TypeParameterInstantiation(ast::TypeParameterInstantiation { params, - }, + }), } ) } @@ -2032,10 +2032,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TypeCastExpression { + kind: ast::NodeKind::TypeCastExpression(ast::TypeCastExpression { expression, type_annotation, - }, + }), } ) } @@ -2043,8 +2043,8 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::InferredPredicate { - }, + kind: ast::NodeKind::InferredPredicate(ast::InferredPredicate { + }), } ) } @@ -2053,9 +2053,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::DeclaredPredicate { + kind: ast::NodeKind::DeclaredPredicate(ast::DeclaredPredicate { value, - }, + }), } ) } @@ -2065,10 +2065,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::EnumDeclaration { + kind: ast::NodeKind::EnumDeclaration(ast::EnumDeclaration { id, body, - }, + }), } ) } @@ -2079,11 +2079,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::EnumStringBody { + kind: ast::NodeKind::EnumStringBody(ast::EnumStringBody { members, explicit_type, has_unknown_members, - }, + }), } ) } @@ -2094,11 +2094,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::EnumNumberBody { + kind: ast::NodeKind::EnumNumberBody(ast::EnumNumberBody { members, explicit_type, has_unknown_members, - }, + }), } ) } @@ -2109,11 +2109,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::EnumBooleanBody { + kind: ast::NodeKind::EnumBooleanBody(ast::EnumBooleanBody { members, explicit_type, has_unknown_members, - }, + }), } ) } @@ -2123,10 +2123,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::EnumSymbolBody { + kind: ast::NodeKind::EnumSymbolBody(ast::EnumSymbolBody { members, has_unknown_members, - }, + }), } ) } @@ -2135,9 +2135,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::EnumDefaultedMember { + kind: ast::NodeKind::EnumDefaultedMember(ast::EnumDefaultedMember { id, - }, + }), } ) } @@ -2147,10 +2147,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::EnumStringMember { + kind: ast::NodeKind::EnumStringMember(ast::EnumStringMember { id, init, - }, + }), } ) } @@ -2160,10 +2160,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::EnumNumberMember { + kind: ast::NodeKind::EnumNumberMember(ast::EnumNumberMember { id, init, - }, + }), } ) } @@ -2173,10 +2173,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::EnumBooleanMember { + kind: ast::NodeKind::EnumBooleanMember(ast::EnumBooleanMember { id, init, - }, + }), } ) } @@ -2185,9 +2185,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSTypeAnnotation { + kind: ast::NodeKind::TSTypeAnnotation(ast::TSTypeAnnotation { type_annotation, - }, + }), } ) } @@ -2195,8 +2195,8 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSAnyKeyword { - }, + kind: ast::NodeKind::TSAnyKeyword(ast::TSAnyKeyword { + }), } ) } @@ -2204,8 +2204,8 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSNumberKeyword { - }, + kind: ast::NodeKind::TSNumberKeyword(ast::TSNumberKeyword { + }), } ) } @@ -2213,8 +2213,8 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSBooleanKeyword { - }, + kind: ast::NodeKind::TSBooleanKeyword(ast::TSBooleanKeyword { + }), } ) } @@ -2222,8 +2222,8 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSStringKeyword { - }, + kind: ast::NodeKind::TSStringKeyword(ast::TSStringKeyword { + }), } ) } @@ -2231,8 +2231,8 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSSymbolKeyword { - }, + kind: ast::NodeKind::TSSymbolKeyword(ast::TSSymbolKeyword { + }), } ) } @@ -2240,8 +2240,8 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSVoidKeyword { - }, + kind: ast::NodeKind::TSVoidKeyword(ast::TSVoidKeyword { + }), } ) } @@ -2249,8 +2249,8 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSThisType { - }, + kind: ast::NodeKind::TSThisType(ast::TSThisType { + }), } ) } @@ -2259,9 +2259,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSLiteralType { + kind: ast::NodeKind::TSLiteralType(ast::TSLiteralType { literal, - }, + }), } ) } @@ -2271,10 +2271,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSIndexedAccessType { + kind: ast::NodeKind::TSIndexedAccessType(ast::TSIndexedAccessType { object_type, index_type, - }, + }), } ) } @@ -2283,9 +2283,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSArrayType { + kind: ast::NodeKind::TSArrayType(ast::TSArrayType { element_type, - }, + }), } ) } @@ -2295,10 +2295,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSTypeReference { + kind: ast::NodeKind::TSTypeReference(ast::TSTypeReference { type_name, type_parameters, - }, + }), } ) } @@ -2308,10 +2308,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSQualifiedName { + kind: ast::NodeKind::TSQualifiedName(ast::TSQualifiedName { left, right, - }, + }), } ) } @@ -2322,11 +2322,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSFunctionType { + kind: ast::NodeKind::TSFunctionType(ast::TSFunctionType { params, return_type, type_parameters, - }, + }), } ) } @@ -2337,11 +2337,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSConstructorType { + kind: ast::NodeKind::TSConstructorType(ast::TSConstructorType { params, return_type, type_parameters, - }, + }), } ) } @@ -2351,10 +2351,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSTypePredicate { + kind: ast::NodeKind::TSTypePredicate(ast::TSTypePredicate { parameter_name, type_annotation, - }, + }), } ) } @@ -2363,9 +2363,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSTupleType { + kind: ast::NodeKind::TSTupleType(ast::TSTupleType { element_types, - }, + }), } ) } @@ -2375,10 +2375,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSTypeAssertion { + kind: ast::NodeKind::TSTypeAssertion(ast::TSTypeAssertion { type_annotation, expression, - }, + }), } ) } @@ -2388,10 +2388,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSAsExpression { + kind: ast::NodeKind::TSAsExpression(ast::TSAsExpression { expression, type_annotation, - }, + }), } ) } @@ -2404,13 +2404,13 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSParameterProperty { + kind: ast::NodeKind::TSParameterProperty(ast::TSParameterProperty { parameter, accessibility, readonly, is_static, export, - }, + }), } ) } @@ -2421,11 +2421,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSTypeAliasDeclaration { + kind: ast::NodeKind::TSTypeAliasDeclaration(ast::TSTypeAliasDeclaration { id, type_parameters, type_annotation, - }, + }), } ) } @@ -2437,12 +2437,12 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSInterfaceDeclaration { + kind: ast::NodeKind::TSInterfaceDeclaration(ast::TSInterfaceDeclaration { id, body, extends, type_parameters, - }, + }), } ) } @@ -2452,10 +2452,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSInterfaceHeritage { + kind: ast::NodeKind::TSInterfaceHeritage(ast::TSInterfaceHeritage { expression, type_parameters, - }, + }), } ) } @@ -2464,9 +2464,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSInterfaceBody { + kind: ast::NodeKind::TSInterfaceBody(ast::TSInterfaceBody { body, - }, + }), } ) } @@ -2476,10 +2476,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSEnumDeclaration { + kind: ast::NodeKind::TSEnumDeclaration(ast::TSEnumDeclaration { id, members, - }, + }), } ) } @@ -2489,10 +2489,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSEnumMember { + kind: ast::NodeKind::TSEnumMember(ast::TSEnumMember { id, initializer, - }, + }), } ) } @@ -2502,10 +2502,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSModuleDeclaration { + kind: ast::NodeKind::TSModuleDeclaration(ast::TSModuleDeclaration { id, body, - }, + }), } ) } @@ -2514,9 +2514,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSModuleBlock { + kind: ast::NodeKind::TSModuleBlock(ast::TSModuleBlock { body, - }, + }), } ) } @@ -2526,10 +2526,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSModuleMember { + kind: ast::NodeKind::TSModuleMember(ast::TSModuleMember { id, initializer, - }, + }), } ) } @@ -2538,9 +2538,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSTypeParameterDeclaration { + kind: ast::NodeKind::TSTypeParameterDeclaration(ast::TSTypeParameterDeclaration { params, - }, + }), } ) } @@ -2551,11 +2551,11 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSTypeParameter { + kind: ast::NodeKind::TSTypeParameter(ast::TSTypeParameter { name, constraint, default, - }, + }), } ) } @@ -2564,9 +2564,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSTypeParameterInstantiation { + kind: ast::NodeKind::TSTypeParameterInstantiation(ast::TSTypeParameterInstantiation { params, - }, + }), } ) } @@ -2575,9 +2575,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSUnionType { + kind: ast::NodeKind::TSUnionType(ast::TSUnionType { types, - }, + }), } ) } @@ -2586,9 +2586,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSIntersectionType { + kind: ast::NodeKind::TSIntersectionType(ast::TSIntersectionType { types, - }, + }), } ) } @@ -2597,9 +2597,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSTypeQuery { + kind: ast::NodeKind::TSTypeQuery(ast::TSTypeQuery { expr_name, - }, + }), } ) } @@ -2611,12 +2611,12 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSConditionalType { + kind: ast::NodeKind::TSConditionalType(ast::TSConditionalType { extends_type, check_type, true_type, false_t_ype, - }, + }), } ) } @@ -2625,9 +2625,9 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSTypeLiteral { + kind: ast::NodeKind::TSTypeLiteral(ast::TSTypeLiteral { members, - }, + }), } ) } @@ -2643,7 +2643,7 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSPropertySignature { + kind: ast::NodeKind::TSPropertySignature(ast::TSPropertySignature { key, type_annotation, initializer, @@ -2652,7 +2652,7 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { readonly, is_static, export, - }, + }), } ) } @@ -2664,12 +2664,12 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSMethodSignature { + kind: ast::NodeKind::TSMethodSignature(ast::TSMethodSignature { key, params, return_type, computed, - }, + }), } ) } @@ -2679,10 +2679,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSIndexSignature { + kind: ast::NodeKind::TSIndexSignature(ast::TSIndexSignature { parameters, type_annotation, - }, + }), } ) } @@ -2692,10 +2692,10 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr { cvt.ast_context.alloc( ast::Node { range, - kind: ast::NodeKind::TSCallSignatureDeclaration { + kind: ast::NodeKind::TSCallSignatureDeclaration(ast::TSCallSignatureDeclaration { params, return_type, - }, + }), } ) } diff --git a/unsupported/juno/tests/ast/mod.rs b/unsupported/juno/tests/ast/mod.rs index 40a36097304..5636ddb766e 100644 --- a/unsupported/juno/tests/ast/mod.rs +++ b/unsupported/juno/tests/ast/mod.rs @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -use juno::ast::{Context, Node, NodeKind, NodePtr, Visitor}; +use juno::ast::*; /// Create a node with a default source range for testing. /// Use a macro to make it easier to construct nested macros @@ -31,29 +31,34 @@ mod validate; #[test] #[allow(clippy::float_cmp)] fn test_visit() { - use NodeKind::*; let mut ctx = Context::new(); // Dummy range, we don't care about ranges in this test. let ast = make_node!( ctx, - BlockStatement { + NodeKind::BlockStatement(BlockStatement { body: vec![ make_node!( ctx, - ExpressionStatement { - expression: make_node!(ctx, NumericLiteral { value: 1.0 },), + NodeKind::ExpressionStatement(ExpressionStatement { + expression: make_node!( + ctx, + NodeKind::NumericLiteral(NumericLiteral { value: 1.0 }), + ), directive: None, - }, + }), ), make_node!( ctx, - ExpressionStatement { - expression: make_node!(ctx, NumericLiteral { value: 2.0 },), + NodeKind::ExpressionStatement(ExpressionStatement { + expression: make_node!( + ctx, + NodeKind::NumericLiteral(NumericLiteral { value: 2.0 }), + ), directive: None, - }, + }), ), ], - }, + }), ); // Accumulates the numbers found in the AST. @@ -63,10 +68,10 @@ fn test_visit() { impl Visitor for NumberFinder { fn call(&mut self, ctx: &Context, node: NodePtr, parent: Option) { - if let NumericLiteral { value } = &node.get(ctx).kind { + if let NodeKind::NumericLiteral(NumericLiteral { value }) = &node.get(ctx).kind { assert!(matches!( parent.unwrap().get(ctx).kind, - ExpressionStatement { .. } + NodeKind::ExpressionStatement(ExpressionStatement { .. }) )); self.acc.push(*value); } diff --git a/unsupported/juno/tests/ast/validate.rs b/unsupported/juno/tests/ast/validate.rs index 120bd713109..441953a9098 100644 --- a/unsupported/juno/tests/ast/validate.rs +++ b/unsupported/juno/tests/ast/validate.rs @@ -5,49 +5,59 @@ * LICENSE file in the root directory of this source tree. */ -use juno::ast::{validate_tree, Context, Node, NodeKind, NodePtr}; +use juno::ast::*; #[test] fn test_valid() { - use NodeKind::*; let mut ctx = Context::new(); - let return_stmt = make_node!(ctx, ReturnStatement { argument: None }); + let return_stmt = make_node!( + ctx, + NodeKind::ReturnStatement(ReturnStatement { argument: None }) + ); assert!(validate_tree(&ctx, return_stmt).is_ok()); let return_stmt = make_node!( ctx, - ReturnStatement { - argument: Some(make_node!(ctx, NumericLiteral { value: 1.0 })) - } + NodeKind::ReturnStatement(ReturnStatement { + argument: Some(make_node!( + ctx, + NodeKind::NumericLiteral(NumericLiteral { value: 1.0 }) + )) + }) ); assert!(validate_tree(&ctx, return_stmt).is_ok()); let return_stmt = make_node!( ctx, - ReturnStatement { - argument: Some(make_node!(ctx, ReturnStatement { argument: None })), - } + NodeKind::ReturnStatement(ReturnStatement { + argument: Some(make_node!( + ctx, + NodeKind::ReturnStatement(ReturnStatement { argument: None }) + )), + }) ); assert!(validate_tree(&ctx, return_stmt).is_err()); } #[test] fn test_error() { - use NodeKind::*; let mut ctx = Context::new(); let ast = make_node!( ctx, - BlockStatement { + NodeKind::BlockStatement(BlockStatement { body: vec![make_node!( ctx, - ReturnStatement { - argument: Some(make_node!(ctx, ReturnStatement { argument: None })), - } + NodeKind::ReturnStatement(ReturnStatement { + argument: Some(make_node!( + ctx, + NodeKind::ReturnStatement(ReturnStatement { argument: None }) + )), + }) )], - } + }) ); let bad_ret: NodePtr = match &ast.get(&ctx).kind { - BlockStatement { body } => body[0], + NodeKind::BlockStatement(BlockStatement { body }) => body[0], _ => { unreachable!("bad match"); } diff --git a/unsupported/juno/tests/gen_js/mod.rs b/unsupported/juno/tests/gen_js/mod.rs index 66c54da5acf..cadc1f75c4a 100644 --- a/unsupported/juno/tests/gen_js/mod.rs +++ b/unsupported/juno/tests/gen_js/mod.rs @@ -64,23 +64,22 @@ fn test_roundtrip_flow(src1: &str) { #[test] fn test_literals() { - use NodeKind::*; let mut ctx = Context::new(); - let null = make_node!(ctx, NullLiteral); + let null = make_node!(ctx, NodeKind::NullLiteral(NullLiteral {})); assert_eq!(do_gen(&ctx, null, gen_js::Pretty::Yes).trim(), "null"); let string = make_node!( ctx, - StringLiteral { + NodeKind::StringLiteral(StringLiteral { value: juno::ast::NodeString { str: vec!['A' as u16, 0x1234u16, '\t' as u16], } - }, + }), ); assert_eq!( do_gen(&ctx, string, gen_js::Pretty::Yes).trim(), r#""A\u1234\t""#, ); - let number = make_node!(ctx, NumericLiteral { value: 1.0 }); + let number = make_node!(ctx, NodeKind::NumericLiteral(NumericLiteral { value: 1.0 })); assert_eq!(do_gen(&ctx, number, gen_js::Pretty::Yes).trim(), "1"); test_roundtrip("1"); @@ -117,17 +116,16 @@ fn test_identifier() { #[test] fn test_binop() { - use NodeKind::*; let mut ctx = Context::new(); - let left = make_node!(ctx, NullLiteral); - let right = make_node!(ctx, NullLiteral); + let left = make_node!(ctx, NodeKind::NullLiteral(NullLiteral {})); + let right = make_node!(ctx, NodeKind::NullLiteral(NullLiteral {})); let binary = make_node!( ctx, - BinaryExpression { + NodeKind::BinaryExpression(BinaryExpression { left, operator: BinaryExpressionOperator::Plus, right, - }, + }), ); assert_eq!( do_gen(&ctx, binary, gen_js::Pretty::Yes).trim(), @@ -408,24 +406,29 @@ fn test_export() { #[test] fn test_types() { - use NodeKind::*; let mut ctx = Context::new(); let union_ty = make_node!( ctx, - UnionTypeAnnotation { + NodeKind::UnionTypeAnnotation(UnionTypeAnnotation { types: vec![ - make_node!(ctx, NumberTypeAnnotation), + make_node!(ctx, NodeKind::NumberTypeAnnotation(NumberTypeAnnotation {})), make_node!( ctx, - IntersectionTypeAnnotation { + NodeKind::IntersectionTypeAnnotation(IntersectionTypeAnnotation { types: vec![ - make_node!(ctx, BooleanTypeAnnotation), - make_node!(ctx, StringTypeAnnotation) + make_node!( + ctx, + NodeKind::BooleanTypeAnnotation(BooleanTypeAnnotation {}) + ), + make_node!( + ctx, + NodeKind::StringTypeAnnotation(StringTypeAnnotation {}) + ) ], - }, + }), ) ], - }, + }), ); assert_eq!( do_gen(&ctx, union_ty, gen_js::Pretty::Yes).trim(), diff --git a/unsupported/tools/rustgen/rustgen.cpp b/unsupported/tools/rustgen/rustgen.cpp index 216bdaf6d0c..9d75d576cb7 100644 --- a/unsupported/tools/rustgen/rustgen.cpp +++ b/unsupported/tools/rustgen/rustgen.cpp @@ -444,14 +444,14 @@ static void genConvert() { " ast::Node {\n" " range,\n" " kind: ast::NodeKind::" - << cls.name << " {\n"; + << cls.name << "(ast::" << cls.name << " {\n"; for (const auto &fld : cls.fields) { // Shorthand initialization of each field. llvh::outs() << " " << fld.rustName() << ",\n"; } - llvh::outs() << " },\n" // kind + llvh::outs() << " }),\n" // kind " }\n" // Node " )\n" // NodePtr " }\n"; // match block