From 124d5a5a09f22841307ca6adc04081586aca08eb Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Fri, 12 Nov 2021 17:37:02 +0100 Subject: [PATCH] refactor(rsliint_parser): Refine variable declaration AST Tree Changes the js grammar of the variable declaration to match our new AST facade as defined in #1725 (and proposed in #1719) * Split `VarDecl` into `JsVariableDeclarationStatement` and `JsVariableDeclaration` to correctly account for variable declarations inside for loops (that aren't statements). * Change the parser to emit a `let` token instead of an ident if let is used inside a variable declaration (let is a valid identifier which is why the lexer returns an `ident` token) * Rename `Declarator` to `JsVariableDeclarator` * Split out the `init` into a `JsEqualValueClause` that holds the `=` token and the initializer expression. --- crates/rome_formatter/src/cst.rs | 22 +- .../equal_value_clause.rs} | 8 +- crates/rome_formatter/src/ts/auxiliary/mod.rs | 1 + .../rome_formatter/src/ts/declarators/decl.rs | 2 +- .../rome_formatter/src/ts/declarators/mod.rs | 3 +- .../src/ts/declarators/var_decl.rs | 36 - .../variable_declaration_statement.rs | 47 + crates/rome_formatter/src/ts/mod.rs | 1 + .../src/ts/statements/for_stmt.rs | 2 +- crates/rslint_parser/src/ast.rs | 40 +- crates/rslint_parser/src/ast/expr_ext.rs | 8 +- .../rslint_parser/src/ast/generated/nodes.rs | 1402 +++++++---------- crates/rslint_parser/src/ast/stmt_ext.rs | 33 +- crates/rslint_parser/src/syntax/program.rs | 4 +- crates/rslint_parser/src/syntax/stmt.rs | 64 +- crates/rslint_parser/src/syntax/typescript.rs | 14 +- crates/rslint_parser/src/syntax/util.rs | 120 +- crates/rslint_parser/src/tests.rs | 25 +- .../err/async_arrow_expr_await_parameter.rast | 28 +- .../err/binding_identifier_invalid.rast | 84 +- .../test_data/inline/err/for_stmt_err.rast | 15 +- .../inline/err/import_call_no_arg.rast | 32 +- .../inline/err/invalid_arg_list.rast | 11 +- .../inline/err/invalid_method_recover.rast | 24 +- .../err/object_expr_error_prop_name.rast | 86 +- .../object_expr_non_ident_literal_prop.rast | 38 +- .../err/primary_expr_invalid_recovery.rast | 28 +- .../test_data/inline/err/semicolons_err.rast | 28 +- .../err/template_literal_unterminated.rast | 42 +- .../err/unterminated_unicode_codepoint.rast | 28 +- .../test_data/inline/err/var_decl_err.rast | 82 +- .../test_data/inline/ok/async_arrow_expr.rast | 106 +- .../inline/ok/async_function_expr.rast | 106 +- .../test_data/inline/ok/async_ident.rast | 28 +- .../test_data/inline/ok/class_expr.rast | 110 +- .../inline/ok/do_while_statement.rast | 28 +- .../test_data/inline/ok/for_stmt.rast | 21 +- .../test_data/inline/ok/function_expr.rast | 98 +- .../inline/ok/object_binding_prop.rast | 130 +- .../test_data/inline/ok/object_expr.rast | 72 +- .../inline/ok/object_expr_assign_prop.rast | 72 +- .../inline/ok/object_expr_async_method.rast | 98 +- .../ok/object_expr_generator_method.rast | 62 +- .../inline/ok/object_expr_getter_setter.rast | 80 +- .../ok/object_expr_getter_setter_as_prop.rast | 52 +- .../object_expr_getter_setter_computed.rast | 86 +- .../ok/object_expr_ident_literal_prop.rast | 50 +- .../inline/ok/object_expr_ident_prop.rast | 38 +- .../inline/ok/object_expr_method.rast | 62 +- .../inline/ok/object_expr_spread_prop.rast | 40 +- .../test_data/inline/ok/object_prop_name.rast | 118 +- .../test_data/inline/ok/semicolons.rast | 107 +- .../test_data/inline/ok/template_literal.rast | 152 +- .../test_data/inline/ok/var_decl.js | 1 + .../test_data/inline/ok/var_decl.rast | 266 ++-- crates/rslint_syntax/src/generated.rs | 6 +- xtask/js.ungram | 38 +- xtask/src/codegen/generate_nodes.rs | 23 +- xtask/src/codegen/kinds_src.rs | 6 +- 59 files changed, 2175 insertions(+), 2239 deletions(-) rename crates/rome_formatter/src/ts/{declarators/declarator.rs => auxiliary/equal_value_clause.rs} (61%) create mode 100644 crates/rome_formatter/src/ts/auxiliary/mod.rs delete mode 100644 crates/rome_formatter/src/ts/declarators/var_decl.rs create mode 100644 crates/rome_formatter/src/ts/declarators/variable_declaration_statement.rs diff --git a/crates/rome_formatter/src/cst.rs b/crates/rome_formatter/src/cst.rs index 3fa355068d4..7197586b35f 100644 --- a/crates/rome_formatter/src/cst.rs +++ b/crates/rome_formatter/src/cst.rs @@ -1,13 +1,13 @@ use crate::{token, FormatElement, FormatResult, Formatter, ToFormatElement}; use rslint_parser::ast::{ ArgList, ArrayExpr, ArrayPattern, ArrowExpr, AssignPattern, CallExpr, ClassBody, ClassDecl, - ClassProp, Condition, ConstructorParameters, Declarator, FnDecl, ForInStmt, ForStmt, - ForStmtInit, ForStmtTest, ForStmtUpdate, Getter, IdentProp, JsBlockStatement, JsCaseClause, - JsCatchClause, JsContinueStatement, JsDebuggerStatement, JsDefaultClause, JsDoWhileStatement, + ClassProp, Condition, ConstructorParameters, FnDecl, ForInStmt, ForStmt, ForStmtInit, + ForStmtTest, ForStmtUpdate, Getter, IdentProp, JsBlockStatement, JsCaseClause, JsCatchClause, + JsContinueStatement, JsDebuggerStatement, JsDefaultClause, JsDoWhileStatement, JsEmptyStatement, JsExpressionStatement, JsFinallyClause, JsIfStatement, JsLabeledStatement, - JsReturnStatement, JsScript, JsSwitchStatement, JsTryStatement, JsWhileStatement, - JsWithStatement, Literal, LiteralProp, Name, NameRef, ObjectExpr, ParameterList, SequenceExpr, - Setter, SinglePattern, VarDecl, + JsReturnStatement, JsScript, JsSwitchStatement, JsTryStatement, JsVariableDeclarationStatement, + JsVariableDeclarator, JsWhileStatement, JsWithStatement, Literal, LiteralProp, Name, NameRef, + ObjectExpr, ParameterList, SequenceExpr, Setter, SinglePattern, }; use rslint_parser::{AstNode, AstToken, SyntaxKind, SyntaxNode, SyntaxToken}; @@ -44,10 +44,12 @@ impl ToFormatElement for SyntaxNode { SyntaxKind::SPREAD_ELEMENT => SinglePattern::cast(self.clone()) .unwrap() .to_format_element(formatter), - SyntaxKind::VAR_DECL => VarDecl::cast(self.clone()) - .unwrap() - .to_format_element(formatter), - SyntaxKind::DECLARATOR => Declarator::cast(self.clone()) + SyntaxKind::JS_VARIABLE_DECLARATION_STATEMENT => { + JsVariableDeclarationStatement::cast(self.clone()) + .unwrap() + .to_format_element(formatter) + } + SyntaxKind::JS_VARIABLE_DECLARATOR => JsVariableDeclarator::cast(self.clone()) .unwrap() .to_format_element(formatter), SyntaxKind::FN_DECL => FnDecl::cast(self.clone()) diff --git a/crates/rome_formatter/src/ts/declarators/declarator.rs b/crates/rome_formatter/src/ts/auxiliary/equal_value_clause.rs similarity index 61% rename from crates/rome_formatter/src/ts/declarators/declarator.rs rename to crates/rome_formatter/src/ts/auxiliary/equal_value_clause.rs index 993f26ce521..1dd66b696dc 100644 --- a/crates/rome_formatter/src/ts/declarators/declarator.rs +++ b/crates/rome_formatter/src/ts/auxiliary/equal_value_clause.rs @@ -1,16 +1,14 @@ use crate::{ format_elements, space_token, FormatElement, FormatResult, Formatter, ToFormatElement, }; -use rslint_parser::ast::Declarator; +use rslint_parser::ast::JsEqualValueClause; -impl ToFormatElement for Declarator { +impl ToFormatElement for JsEqualValueClause { fn to_format_element(&self, formatter: &Formatter) -> FormatResult { Ok(format_elements![ - formatter.format_node(self.pattern()?)?, - space_token(), formatter.format_token(&self.eq_token()?)?, space_token(), - formatter.format_node(self.value()?)?, + formatter.format_node(self.expression()?)? ]) } } diff --git a/crates/rome_formatter/src/ts/auxiliary/mod.rs b/crates/rome_formatter/src/ts/auxiliary/mod.rs new file mode 100644 index 00000000000..79f5ffdc306 --- /dev/null +++ b/crates/rome_formatter/src/ts/auxiliary/mod.rs @@ -0,0 +1 @@ +mod equal_value_clause; diff --git a/crates/rome_formatter/src/ts/declarators/decl.rs b/crates/rome_formatter/src/ts/declarators/decl.rs index 53a309ee4d3..760b4ef381c 100644 --- a/crates/rome_formatter/src/ts/declarators/decl.rs +++ b/crates/rome_formatter/src/ts/declarators/decl.rs @@ -6,7 +6,7 @@ impl ToFormatElement for Decl { match self { Decl::FnDecl(fn_decl) => fn_decl.to_format_element(formatter), Decl::ClassDecl(class_declarator) => class_declarator.to_format_element(formatter), - Decl::VarDecl(var_decl) => var_decl.to_format_element(formatter), + Decl::JsVariableDeclarationStatement(var_decl) => var_decl.to_format_element(formatter), Decl::TsEnum(_) => todo!(), Decl::TsTypeAliasDecl(_) => todo!(), Decl::TsNamespaceDecl(_) => todo!(), diff --git a/crates/rome_formatter/src/ts/declarators/mod.rs b/crates/rome_formatter/src/ts/declarators/mod.rs index 21ee90fac3e..210c19e9d47 100644 --- a/crates/rome_formatter/src/ts/declarators/mod.rs +++ b/crates/rome_formatter/src/ts/declarators/mod.rs @@ -1,4 +1,3 @@ mod decl; -mod declarator; mod fn_decl; -mod var_decl; +mod variable_declaration_statement; diff --git a/crates/rome_formatter/src/ts/declarators/var_decl.rs b/crates/rome_formatter/src/ts/declarators/var_decl.rs deleted file mode 100644 index 7832d375cc1..00000000000 --- a/crates/rome_formatter/src/ts/declarators/var_decl.rs +++ /dev/null @@ -1,36 +0,0 @@ -use crate::{ - concat_elements, space_token, token, FormatElement, FormatError, FormatResult, Formatter, - ToFormatElement, -}; -use rslint_parser::ast::{AstNode, ForStmtInit, VarDecl}; - -impl ToFormatElement for VarDecl { - fn to_format_element(&self, formatter: &Formatter) -> FormatResult { - let mut tokens = vec![]; - - if self.is_const() { - tokens.push(formatter.format_token(&self.const_token()?)?); - } else if self.is_var() { - tokens.push(formatter.format_token(&self.var_token()?)?); - } else if self.is_let() { - // TODO: #1725 remove this custom code once #1745 is merged - tokens.push(formatter.format_token(&self.let_token().unwrap())?); - } else { - return Err(FormatError::MissingRequiredChild); - } - - tokens.push(space_token()); - - for declarator in self.declared() { - tokens.push(formatter.format_node(declarator)?); - } - - // don't add a semicolon if the var decl is in the init section of a for statement to avoid - // terminating the `init` with two semicolons. - if self.syntax().parent().and_then(ForStmtInit::cast).is_none() { - tokens.push(token(";")); - } - - Ok(concat_elements(tokens)) - } -} diff --git a/crates/rome_formatter/src/ts/declarators/variable_declaration_statement.rs b/crates/rome_formatter/src/ts/declarators/variable_declaration_statement.rs new file mode 100644 index 00000000000..5e4d5d7ad93 --- /dev/null +++ b/crates/rome_formatter/src/ts/declarators/variable_declaration_statement.rs @@ -0,0 +1,47 @@ +use crate::{ + empty_element, format_elements, join_elements, space_token, token, FormatElement, FormatResult, + Formatter, ToFormatElement, +}; +use rslint_parser::ast::{ + JsVariableDeclaration, JsVariableDeclarationStatement, JsVariableDeclarator, +}; + +impl ToFormatElement for JsVariableDeclarationStatement { + fn to_format_element(&self, formatter: &Formatter) -> FormatResult { + Ok(format_elements![ + formatter.format_node(self.declaration()?)?, + token(";"), + ]) + } +} + +impl ToFormatElement for JsVariableDeclaration { + fn to_format_element(&self, formatter: &Formatter) -> FormatResult { + let mut declarators = Vec::with_capacity(self.declarators().len()); + + for declarator in self.declarators().iter() { + declarators.push(formatter.format_node(declarator)?); + } + + Ok(format_elements![ + formatter.format_token(&self.kind_token()?)?, + space_token(), + join_elements(format_elements![token(","), space_token()], declarators), + ]) + } +} + +impl ToFormatElement for JsVariableDeclarator { + fn to_format_element(&self, formatter: &Formatter) -> FormatResult { + let initializer = if let Some(initializer) = self.init() { + format_elements![space_token(), formatter.format_node(initializer)?] + } else { + empty_element() + }; + + Ok(format_elements![ + formatter.format_node(self.id()?)?, + initializer + ]) + } +} diff --git a/crates/rome_formatter/src/ts/mod.rs b/crates/rome_formatter/src/ts/mod.rs index 6190963757a..ad3a3aa77aa 100644 --- a/crates/rome_formatter/src/ts/mod.rs +++ b/crates/rome_formatter/src/ts/mod.rs @@ -1,4 +1,5 @@ mod arg_list; +mod auxiliary; mod class; mod condition; mod declarators; diff --git a/crates/rome_formatter/src/ts/statements/for_stmt.rs b/crates/rome_formatter/src/ts/statements/for_stmt.rs index 785e5052178..2bba0dff3f8 100644 --- a/crates/rome_formatter/src/ts/statements/for_stmt.rs +++ b/crates/rome_formatter/src/ts/statements/for_stmt.rs @@ -52,7 +52,7 @@ impl ToFormatElement for ForStmtInit { impl ToFormatElement for ForHead { fn to_format_element(&self, formatter: &Formatter) -> FormatResult { match self { - ForHead::VarDecl(decl) => decl.to_format_element(formatter), + ForHead::JsVariableDeclaration(decl) => decl.to_format_element(formatter), ForHead::JsAnyExpression(expr) => expr.to_format_element(formatter), } } diff --git a/crates/rslint_parser/src/ast.rs b/crates/rslint_parser/src/ast.rs index b13d3e335e0..62dbe4ba041 100644 --- a/crates/rslint_parser/src/ast.rs +++ b/crates/rslint_parser/src/ast.rs @@ -349,7 +349,7 @@ impl IntoIterator for &AstSeparatedList { /// Specific result used when navigating nodes using AST APIs pub type SyntaxResult = Result; -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq, Clone)] pub enum SyntaxError { /// Error thrown when a mandatory node is not found MissingRequiredChild(SyntaxNode), @@ -364,14 +364,12 @@ mod support { use crate::SyntaxList; use crate::{SyntaxError, SyntaxResult}; - // TODO: #1725 remove once API are set in stone - #[allow(dead_code)] - pub(super) fn child(parent: &SyntaxNode) -> Option { + pub(super) fn node(parent: &SyntaxNode) -> Option { parent.children().find_map(N::cast) } - pub(super) fn as_optional_node(parent: &SyntaxNode) -> Option { - parent.children().find_map(N::cast) + pub(super) fn required_node(parent: &SyntaxNode) -> SyntaxResult { + node(parent).ok_or_else(|| SyntaxError::MissingRequiredChild(parent.clone())) } pub(super) fn elements(parent: &SyntaxNode) -> SyntaxElementChildren { @@ -409,29 +407,11 @@ mod support { .find(|it| it.kind() == kind) } - pub(super) fn as_optional_token(parent: &SyntaxNode, kind: SyntaxKind) -> Option { - parent - .children_with_tokens() - .filter_map(|it| it.into_token()) - .find(|it| it.kind() == kind) - } - - pub(super) fn as_mandatory_node(parent: &SyntaxNode) -> SyntaxResult { - parent - .children() - .find_map(N::cast) - .ok_or_else(|| SyntaxError::MissingRequiredChild(parent.clone())) - } - - pub(super) fn as_mandatory_token( + pub(super) fn required_token( parent: &SyntaxNode, kind: SyntaxKind, ) -> SyntaxResult { - parent - .children_with_tokens() - .filter_map(|it| it.into_token()) - .find(|it| it.kind() == kind) - .ok_or_else(|| SyntaxError::MissingRequiredChild(parent.clone())) + token(parent, kind).ok_or_else(|| SyntaxError::MissingRequiredChild(parent.clone())) } pub(super) fn find_token( @@ -447,6 +427,14 @@ mod support { .any(|possible_kind| *possible_kind == it.kind()) }) } + + pub(super) fn find_required_token( + parent: &SyntaxNode, + possible_kinds: &[SyntaxKind], + ) -> SyntaxResult { + find_token(parent, possible_kinds) + .ok_or_else(|| SyntaxError::MissingRequiredChild(parent.clone())) + } } #[cfg(test)] diff --git a/crates/rslint_parser/src/ast/expr_ext.rs b/crates/rslint_parser/src/ast/expr_ext.rs index c98ecb95e9d..38a97b62c69 100644 --- a/crates/rslint_parser/src/ast/expr_ext.rs +++ b/crates/rslint_parser/src/ast/expr_ext.rs @@ -5,7 +5,7 @@ use SyntaxKind::*; impl BracketExpr { pub fn object(&self) -> Option { - support::child(self.syntax()) + support::node(self.syntax()) } pub fn prop(&self) -> Option { @@ -15,7 +15,7 @@ impl BracketExpr { impl CondExpr { pub fn test(&self) -> Option { - support::child(self.syntax()) + support::node(self.syntax()) } pub fn cons(&self) -> Option { @@ -29,7 +29,7 @@ impl CondExpr { impl LiteralProp { pub fn key(&self) -> SyntaxResult { - support::as_mandatory_node::(self.syntax()) + support::required_node::(self.syntax()) } pub fn value(&self) -> SyntaxResult { @@ -144,7 +144,7 @@ impl BinExpr { } pub fn lhs(&self) -> Option { - support::child(self.syntax()) + support::node(self.syntax()) } pub fn rhs(&self) -> Option { diff --git a/crates/rslint_parser/src/ast/generated/nodes.rs b/crates/rslint_parser/src/ast/generated/nodes.rs index aa849c9889d..857d7430b9b 100644 --- a/crates/rslint_parser/src/ast/generated/nodes.rs +++ b/crates/rslint_parser/src/ast/generated/nodes.rs @@ -55,7 +55,7 @@ pub struct Ident { } impl Ident { pub fn ident_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![ident]) + support::required_token(&self.syntax, T![ident]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -64,7 +64,7 @@ pub struct JsScript { } impl JsScript { pub fn interpreter_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![js_shebang]) + support::token(&self.syntax, T![js_shebang]) } pub fn statements(&self) -> AstNodeList { support::node_list(&self.syntax, 0usize) @@ -76,7 +76,7 @@ pub struct JsModule { } impl JsModule { pub fn interpreter_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![js_shebang]) + support::token(&self.syntax, T![js_shebang]) } pub fn statements(&self) -> AstNodeList { support::node_list(&self.syntax, 0usize) @@ -88,13 +88,13 @@ pub struct JsBlockStatement { } impl JsBlockStatement { pub fn l_curly_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['{']) + support::required_token(&self.syntax, T!['{']) } pub fn statements(&self) -> AstNodeList { support::node_list(&self.syntax, 0usize) } pub fn r_curly_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['}']) + support::required_token(&self.syntax, T!['}']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -103,7 +103,7 @@ pub struct JsEmptyStatement { } impl JsEmptyStatement { pub fn semicolon_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [;]) + support::required_token(&self.syntax, T ! [;]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -112,11 +112,9 @@ pub struct JsExpressionStatement { } impl JsExpressionStatement { pub fn expression(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) - } - pub fn semicolon_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [;]) + support::required_node(&self.syntax) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T ! [;]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct JsIfStatement { @@ -124,19 +122,19 @@ pub struct JsIfStatement { } impl JsIfStatement { pub fn if_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![if]) + support::required_token(&self.syntax, T![if]) } pub fn l_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['(']) + support::required_token(&self.syntax, T!['(']) } - pub fn test(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn test(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn r_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![')']) + support::required_token(&self.syntax, T![')']) } pub fn consequence(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_node(&self.syntax) } - pub fn else_clause(&self) -> Option { support::as_optional_node(&self.syntax) } + pub fn else_clause(&self) -> Option { support::node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct JsDoWhileStatement { @@ -144,22 +142,20 @@ pub struct JsDoWhileStatement { } impl JsDoWhileStatement { pub fn do_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![do]) + support::required_token(&self.syntax, T![do]) } - pub fn body(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn body(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn while_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![while]) + support::required_token(&self.syntax, T![while]) } pub fn l_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['(']) + support::required_token(&self.syntax, T!['(']) } - pub fn test(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn test(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn r_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![')']) - } - pub fn semicolon_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [;]) + support::required_token(&self.syntax, T![')']) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T ! [;]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct JsWhileStatement { @@ -167,16 +163,16 @@ pub struct JsWhileStatement { } impl JsWhileStatement { pub fn while_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![while]) + support::required_token(&self.syntax, T![while]) } pub fn l_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['(']) + support::required_token(&self.syntax, T!['(']) } - pub fn test(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn test(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn r_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![')']) + support::required_token(&self.syntax, T![')']) } - pub fn body(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn body(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ForStmt { @@ -184,18 +180,18 @@ pub struct ForStmt { } impl ForStmt { pub fn for_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![for]) + support::required_token(&self.syntax, T![for]) } pub fn l_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['(']) + support::required_token(&self.syntax, T!['(']) } - pub fn init(&self) -> Option { support::as_optional_node(&self.syntax) } - pub fn test(&self) -> Option { support::as_optional_node(&self.syntax) } - pub fn update(&self) -> Option { support::as_optional_node(&self.syntax) } + pub fn init(&self) -> Option { support::node(&self.syntax) } + pub fn test(&self) -> Option { support::node(&self.syntax) } + pub fn update(&self) -> Option { support::node(&self.syntax) } pub fn r_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![')']) + support::required_token(&self.syntax, T![')']) } - pub fn cons(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn cons(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ForInStmt { @@ -203,22 +199,20 @@ pub struct ForInStmt { } impl ForInStmt { pub fn for_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![for]) + support::required_token(&self.syntax, T![for]) } pub fn l_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['(']) + support::required_token(&self.syntax, T!['(']) } - pub fn left(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn left(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn in_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![in]) - } - pub fn right(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_token(&self.syntax, T![in]) } + pub fn right(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn r_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![')']) + support::required_token(&self.syntax, T![')']) } - pub fn cons(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn cons(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ForOfStmt { @@ -226,22 +220,20 @@ pub struct ForOfStmt { } impl ForOfStmt { pub fn for_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![for]) + support::required_token(&self.syntax, T![for]) } pub fn l_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['(']) + support::required_token(&self.syntax, T!['(']) } - pub fn left(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn left(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn of_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![of]) - } - pub fn right(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_token(&self.syntax, T![of]) } + pub fn right(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn r_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![')']) + support::required_token(&self.syntax, T![')']) } - pub fn cons(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn cons(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct JsContinueStatement { @@ -249,14 +241,10 @@ pub struct JsContinueStatement { } impl JsContinueStatement { pub fn continue_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![continue]) - } - pub fn label_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![ident]) - } - pub fn semicolon_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [;]) + support::required_token(&self.syntax, T![continue]) } + pub fn label_token(&self) -> Option { support::token(&self.syntax, T![ident]) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T ! [;]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct JsBreakStatement { @@ -264,14 +252,10 @@ pub struct JsBreakStatement { } impl JsBreakStatement { pub fn break_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![break]) - } - pub fn label_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![ident]) - } - pub fn semicolon_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [;]) + support::required_token(&self.syntax, T![break]) } + pub fn label_token(&self) -> Option { support::token(&self.syntax, T![ident]) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T ! [;]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct JsReturnStatement { @@ -279,12 +263,10 @@ pub struct JsReturnStatement { } impl JsReturnStatement { pub fn return_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![return]) - } - pub fn argument(&self) -> Option { support::as_optional_node(&self.syntax) } - pub fn semicolon_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [;]) + support::required_token(&self.syntax, T![return]) } + pub fn argument(&self) -> Option { support::node(&self.syntax) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T ! [;]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct JsWithStatement { @@ -292,18 +274,16 @@ pub struct JsWithStatement { } impl JsWithStatement { pub fn with_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![with]) + support::required_token(&self.syntax, T![with]) } pub fn l_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['(']) - } - pub fn object(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_token(&self.syntax, T!['(']) } + pub fn object(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn r_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![')']) + support::required_token(&self.syntax, T![')']) } - pub fn body(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn body(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct JsLabeledStatement { @@ -311,12 +291,12 @@ pub struct JsLabeledStatement { } impl JsLabeledStatement { pub fn label_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![ident]) + support::required_token(&self.syntax, T![ident]) } pub fn colon_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [:]) + support::required_token(&self.syntax, T ! [:]) } - pub fn body(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn body(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct JsSwitchStatement { @@ -324,25 +304,25 @@ pub struct JsSwitchStatement { } impl JsSwitchStatement { pub fn switch_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![switch]) + support::required_token(&self.syntax, T![switch]) } pub fn l_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['(']) + support::required_token(&self.syntax, T!['(']) } pub fn discriminant(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_node(&self.syntax) } pub fn r_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![')']) + support::required_token(&self.syntax, T![')']) } pub fn l_curly_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['{']) + support::required_token(&self.syntax, T!['{']) } pub fn cases(&self) -> AstNodeList { support::node_list(&self.syntax, 0usize) } pub fn r_curly_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['}']) + support::required_token(&self.syntax, T!['}']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -351,14 +331,10 @@ pub struct JsThrowStatement { } impl JsThrowStatement { pub fn throw_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![throw]) - } - pub fn argument(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) - } - pub fn semicolon_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [;]) + support::required_token(&self.syntax, T![throw]) } + pub fn argument(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T ! [;]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct JsTryStatement { @@ -366,13 +342,11 @@ pub struct JsTryStatement { } impl JsTryStatement { pub fn try_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![try]) - } - pub fn body(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_token(&self.syntax, T![try]) } + pub fn body(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn catch_clause(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -381,14 +355,12 @@ pub struct JsTryFinallyStatement { } impl JsTryFinallyStatement { pub fn try_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![try]) - } - pub fn body(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_token(&self.syntax, T![try]) } - pub fn catch_clause(&self) -> Option { support::as_optional_node(&self.syntax) } + pub fn body(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn catch_clause(&self) -> Option { support::node(&self.syntax) } pub fn finally_clause(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -397,11 +369,9 @@ pub struct JsDebuggerStatement { } impl JsDebuggerStatement { pub fn debugger_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![debugger]) - } - pub fn semicolon_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [;]) + support::required_token(&self.syntax, T![debugger]) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T ! [;]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ImportDecl { @@ -409,24 +379,18 @@ pub struct ImportDecl { } impl ImportDecl { pub fn import_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![import]) + support::required_token(&self.syntax, T![import]) } pub fn imports(&self) -> AstNodeList { support::node_list(&self.syntax, 0usize) } - pub fn type_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![type]) - } + pub fn type_token(&self) -> Option { support::token(&self.syntax, T![type]) } pub fn from_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![from]) + support::required_token(&self.syntax, T![from]) } pub fn asserted_object(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) - } - pub fn assert_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![assert]) - } - pub fn semicolon_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [;]) + support::required_node(&self.syntax) } + pub fn assert_token(&self) -> Option { support::token(&self.syntax, T![assert]) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T ! [;]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ExportNamed { @@ -434,22 +398,18 @@ pub struct ExportNamed { } impl ExportNamed { pub fn export_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![export]) - } - pub fn type_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![type]) - } - pub fn from_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![from]) + support::required_token(&self.syntax, T![export]) } + pub fn type_token(&self) -> Option { support::token(&self.syntax, T![type]) } + pub fn from_token(&self) -> Option { support::token(&self.syntax, T![from]) } pub fn l_curly_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['{']) + support::required_token(&self.syntax, T!['{']) } pub fn specifiers(&self) -> AstSeparatedList { support::separated_list(&self.syntax, 0usize) } pub fn r_curly_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['}']) + support::required_token(&self.syntax, T!['}']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -458,15 +418,11 @@ pub struct ExportDefaultDecl { } impl ExportDefaultDecl { pub fn export_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![export]) - } - pub fn default_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![default]) + support::required_token(&self.syntax, T![export]) } - pub fn type_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![type]) - } - pub fn decl(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn default_token(&self) -> Option { support::token(&self.syntax, T![default]) } + pub fn type_token(&self) -> Option { support::token(&self.syntax, T![type]) } + pub fn decl(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ExportDefaultExpr { @@ -474,15 +430,11 @@ pub struct ExportDefaultExpr { } impl ExportDefaultExpr { pub fn export_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![export]) - } - pub fn type_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![type]) - } - pub fn default_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![default]) + support::required_token(&self.syntax, T![export]) } - pub fn expr(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn type_token(&self) -> Option { support::token(&self.syntax, T![type]) } + pub fn default_token(&self) -> Option { support::token(&self.syntax, T![default]) } + pub fn expr(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ExportWildcard { @@ -490,20 +442,16 @@ pub struct ExportWildcard { } impl ExportWildcard { pub fn export_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![export]) - } - pub fn type_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![type]) + support::required_token(&self.syntax, T![export]) } + pub fn type_token(&self) -> Option { support::token(&self.syntax, T![type]) } pub fn star_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [*]) - } - pub fn as_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![as]) + support::required_token(&self.syntax, T ! [*]) } - pub fn ident(&self) -> Option { support::as_optional_node(&self.syntax) } + pub fn as_token(&self) -> Option { support::token(&self.syntax, T![as]) } + pub fn ident(&self) -> Option { support::node(&self.syntax) } pub fn from_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![from]) + support::required_token(&self.syntax, T![from]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -512,12 +460,10 @@ pub struct ExportDecl { } impl ExportDecl { pub fn export_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![export]) - } - pub fn type_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![type]) + support::required_token(&self.syntax, T![export]) } - pub fn decl(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn type_token(&self) -> Option { support::token(&self.syntax, T![type]) } + pub fn decl(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsImportEqualsDecl { @@ -525,19 +471,17 @@ pub struct TsImportEqualsDecl { } impl TsImportEqualsDecl { pub fn import_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![import]) + support::required_token(&self.syntax, T![import]) } pub fn export_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![export]) + support::required_token(&self.syntax, T![export]) } - pub fn ident(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ident(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn eq_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [=]) - } - pub fn module(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } - pub fn semicolon_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [;]) + support::required_token(&self.syntax, T ! [=]) } + pub fn module(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T ! [;]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsExportAssignment { @@ -545,15 +489,13 @@ pub struct TsExportAssignment { } impl TsExportAssignment { pub fn export_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![export]) + support::required_token(&self.syntax, T![export]) } pub fn eq_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [=]) - } - pub fn expr(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } - pub fn semicolon_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [;]) + support::required_token(&self.syntax, T ! [=]) } + pub fn expr(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T ! [;]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsNamespaceExportDecl { @@ -561,18 +503,16 @@ pub struct TsNamespaceExportDecl { } impl TsNamespaceExportDecl { pub fn export_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![export]) + support::required_token(&self.syntax, T![export]) } pub fn as_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![as]) + support::required_token(&self.syntax, T![as]) } pub fn namespace_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![namespace]) - } - pub fn ident(&self) -> Option { support::as_optional_node(&self.syntax) } - pub fn semicolon_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [;]) + support::required_token(&self.syntax, T![namespace]) } + pub fn ident(&self) -> Option { support::node(&self.syntax) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T ! [;]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct JsElseClause { @@ -580,20 +520,18 @@ pub struct JsElseClause { } impl JsElseClause { pub fn else_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![else]) - } - pub fn alternate(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_token(&self.syntax, T![else]) } + pub fn alternate(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ForStmtInit { pub(crate) syntax: SyntaxNode, } impl ForStmtInit { - pub fn inner(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn inner(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn semicolon_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [;]) + support::required_token(&self.syntax, T ! [;]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -601,9 +539,9 @@ pub struct ForStmtTest { pub(crate) syntax: SyntaxNode, } impl ForStmtTest { - pub fn expr(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn expr(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn semicolon_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [;]) + support::required_token(&self.syntax, T ! [;]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -611,25 +549,19 @@ pub struct ForStmtUpdate { pub(crate) syntax: SyntaxNode, } impl ForStmtUpdate { - pub fn expr(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn expr(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct VarDecl { +pub struct JsVariableDeclaration { pub(crate) syntax: SyntaxNode, } -impl VarDecl { - pub fn var_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![var]) +impl JsVariableDeclaration { + pub fn kind_token(&self) -> SyntaxResult { + support::find_required_token(&self.syntax, &[T![var], T![const], T![let]]) } - pub fn const_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![const]) - } - pub fn declared(&self) -> AstSeparatedList { + pub fn declarators(&self) -> AstSeparatedList { support::separated_list(&self.syntax, 0usize) } - pub fn semicolon_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [;]) - } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct JsCaseClause { @@ -637,11 +569,11 @@ pub struct JsCaseClause { } impl JsCaseClause { pub fn case_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![case]) + support::required_token(&self.syntax, T![case]) } - pub fn test(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn test(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn colon_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [:]) + support::required_token(&self.syntax, T ! [:]) } pub fn consequence(&self) -> AstNodeList { support::node_list(&self.syntax, 0usize) @@ -653,10 +585,10 @@ pub struct JsDefaultClause { } impl JsDefaultClause { pub fn default_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![default]) + support::required_token(&self.syntax, T![default]) } pub fn colon_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [:]) + support::required_token(&self.syntax, T ! [:]) } pub fn consequence(&self) -> AstNodeList { support::node_list(&self.syntax, 0usize) @@ -668,14 +600,10 @@ pub struct JsCatchClause { } impl JsCatchClause { pub fn catch_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![catch]) - } - pub fn declaration(&self) -> Option { - support::as_optional_node(&self.syntax) - } - pub fn body(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_token(&self.syntax, T![catch]) } + pub fn declaration(&self) -> Option { support::node(&self.syntax) } + pub fn body(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct JsFinallyClause { @@ -683,11 +611,9 @@ pub struct JsFinallyClause { } impl JsFinallyClause { pub fn finally_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![finally]) - } - pub fn body(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_token(&self.syntax, T![finally]) } + pub fn body(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct JsCatchDeclaration { @@ -695,11 +621,11 @@ pub struct JsCatchDeclaration { } impl JsCatchDeclaration { pub fn l_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['(']) + support::required_token(&self.syntax, T!['(']) } - pub fn binding(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn binding(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn r_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![')']) + support::required_token(&self.syntax, T![')']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -707,18 +633,14 @@ pub struct ArrowExpr { pub(crate) syntax: SyntaxNode, } impl ArrowExpr { - pub fn async_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![async]) - } - pub fn type_params(&self) -> Option { support::as_optional_node(&self.syntax) } - pub fn params(&self) -> Option { support::as_optional_node(&self.syntax) } + pub fn async_token(&self) -> Option { support::token(&self.syntax, T![async]) } + pub fn type_params(&self) -> Option { support::node(&self.syntax) } + pub fn params(&self) -> Option { support::node(&self.syntax) } pub fn fat_arrow_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [=>]) - } - pub fn colon_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [:]) + support::required_token(&self.syntax, T ! [=>]) } - pub fn return_type(&self) -> Option { support::as_optional_node(&self.syntax) } + pub fn colon_token(&self) -> Option { support::token(&self.syntax, T ! [:]) } + pub fn return_type(&self) -> Option { support::node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Literal { @@ -726,22 +648,22 @@ pub struct Literal { } impl Literal { pub fn true_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![true]) + support::required_token(&self.syntax, T![true]) } pub fn false_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![false]) + support::required_token(&self.syntax, T![false]) } pub fn number_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![number]) + support::required_token(&self.syntax, T![number]) } pub fn regex_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![regex]) + support::required_token(&self.syntax, T![regex]) } pub fn float_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![float]) + support::required_token(&self.syntax, T![float]) } pub fn big_int_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![big_int]) + support::required_token(&self.syntax, T![big_int]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -750,7 +672,7 @@ pub struct Template { } impl Template { pub fn backtick_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['`']) + support::required_token(&self.syntax, T!['`']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -759,7 +681,7 @@ pub struct NameRef { } impl NameRef { pub fn ident_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![ident]) + support::required_token(&self.syntax, T![ident]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -768,7 +690,7 @@ pub struct ThisExpr { } impl ThisExpr { pub fn this_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![this]) + support::required_token(&self.syntax, T![this]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -777,11 +699,11 @@ pub struct ArrayExpr { } impl ArrayExpr { pub fn l_brack_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['[']) + support::required_token(&self.syntax, T!['[']) } pub fn elements(&self) -> AstNodeList { support::node_list(&self.syntax, 0usize) } pub fn r_brack_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![']']) + support::required_token(&self.syntax, T![']']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -790,13 +712,13 @@ pub struct ObjectExpr { } impl ObjectExpr { pub fn l_curly_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['{']) + support::required_token(&self.syntax, T!['{']) } pub fn props(&self) -> AstSeparatedList { support::separated_list(&self.syntax, 0usize) } pub fn r_curly_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['}']) + support::required_token(&self.syntax, T!['}']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -805,13 +727,11 @@ pub struct GroupingExpr { } impl GroupingExpr { pub fn l_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['(']) - } - pub fn inner(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_token(&self.syntax, T!['(']) } + pub fn inner(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn r_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![')']) + support::required_token(&self.syntax, T![')']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -819,14 +739,12 @@ pub struct BracketExpr { pub(crate) syntax: SyntaxNode, } impl BracketExpr { - pub fn super_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![super]) - } + pub fn super_token(&self) -> Option { support::token(&self.syntax, T![super]) } pub fn l_brack_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['[']) + support::required_token(&self.syntax, T!['[']) } pub fn r_brack_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![']']) + support::required_token(&self.syntax, T![']']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -834,16 +752,12 @@ pub struct DotExpr { pub(crate) syntax: SyntaxNode, } impl DotExpr { - pub fn super_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![super]) - } - pub fn object(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) - } + pub fn super_token(&self) -> Option { support::token(&self.syntax, T![super]) } + pub fn object(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn dot_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [.]) + support::required_token(&self.syntax, T ! [.]) } - pub fn prop(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn prop(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct NewExpr { @@ -851,32 +765,28 @@ pub struct NewExpr { } impl NewExpr { pub fn new_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![new]) - } - pub fn type_args(&self) -> Option { support::as_optional_node(&self.syntax) } - pub fn object(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_token(&self.syntax, T![new]) } - pub fn arguments(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn type_args(&self) -> Option { support::node(&self.syntax) } + pub fn object(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn arguments(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct CallExpr { pub(crate) syntax: SyntaxNode, } impl CallExpr { - pub fn type_args(&self) -> Option { support::as_optional_node(&self.syntax) } - pub fn callee(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) - } - pub fn arguments(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn type_args(&self) -> Option { support::node(&self.syntax) } + pub fn callee(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn arguments(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct UnaryExpr { pub(crate) syntax: SyntaxNode, } impl UnaryExpr { - pub fn operator(&self) -> Option { - support::find_token( + pub fn operator(&self) -> SyntaxResult { + support::find_required_token( &self.syntax, &[ T![delete], @@ -890,32 +800,26 @@ impl UnaryExpr { ], ) } - pub fn argument(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) - } + pub fn argument(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct PreUpdateExpression { pub(crate) syntax: SyntaxNode, } impl PreUpdateExpression { - pub fn operator(&self) -> Option { - support::find_token(&self.syntax, &[T ! [++], T ! [--]]) - } - pub fn operand(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + pub fn operator(&self) -> SyntaxResult { + support::find_required_token(&self.syntax, &[T ! [++], T ! [--]]) } + pub fn operand(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct PostUpdateExpression { pub(crate) syntax: SyntaxNode, } impl PostUpdateExpression { - pub fn operand(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) - } - pub fn operator(&self) -> Option { - support::find_token(&self.syntax, &[T ! [++], T ! [--]]) + pub fn operand(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn operator(&self) -> SyntaxResult { + support::find_required_token(&self.syntax, &[T ! [++], T ! [--]]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -923,8 +827,8 @@ pub struct BinExpr { pub(crate) syntax: SyntaxNode, } impl BinExpr { - pub fn operator(&self) -> Option { - support::find_token( + pub fn operator(&self) -> SyntaxResult { + support::find_required_token( &self.syntax, &[ T ! [<], @@ -962,10 +866,10 @@ pub struct CondExpr { } impl CondExpr { pub fn question_mark_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [?]) + support::required_token(&self.syntax, T ! [?]) } pub fn colon_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [:]) + support::required_token(&self.syntax, T ! [:]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -973,8 +877,8 @@ pub struct AssignExpr { pub(crate) syntax: SyntaxNode, } impl AssignExpr { - pub fn operator(&self) -> Option { - support::find_token( + pub fn operator(&self) -> SyntaxResult { + support::find_required_token( &self.syntax, &[ T ! [=], @@ -1004,32 +908,24 @@ impl SequenceExpr { pub fn exprs(&self) -> AstSeparatedList { support::separated_list(&self.syntax, 0usize) } - pub fn bin_expr(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn bin_expr(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct FnExpr { pub(crate) syntax: SyntaxNode, } impl FnExpr { - pub fn async_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![async]) - } + pub fn async_token(&self) -> Option { support::token(&self.syntax, T![async]) } pub fn function_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![function]) - } - pub fn star_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [*]) - } - pub fn name(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } - pub fn type_params(&self) -> Option { support::as_optional_node(&self.syntax) } - pub fn parameters(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } - pub fn colon_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [:]) - } - pub fn return_type(&self) -> Option { support::as_optional_node(&self.syntax) } - pub fn body(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_token(&self.syntax, T![function]) } + pub fn star_token(&self) -> Option { support::token(&self.syntax, T ! [*]) } + pub fn name(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn type_params(&self) -> Option { support::node(&self.syntax) } + pub fn parameters(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn colon_token(&self) -> Option { support::token(&self.syntax, T ! [:]) } + pub fn return_type(&self) -> Option { support::node(&self.syntax) } + pub fn body(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ClassExpr { @@ -1037,18 +933,16 @@ pub struct ClassExpr { } impl ClassExpr { pub fn class_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![class]) + support::required_token(&self.syntax, T![class]) } - pub fn name(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } - pub fn type_params(&self) -> Option { support::as_optional_node(&self.syntax) } - pub fn parent(&self) -> Option { support::as_optional_node(&self.syntax) } + pub fn name(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn type_params(&self) -> Option { support::node(&self.syntax) } + pub fn parent(&self) -> Option { support::node(&self.syntax) } pub fn implements_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![implements]) - } - pub fn implements(&self) -> Option { - support::as_optional_node(&self.syntax) + support::token(&self.syntax, T![implements]) } - pub fn body(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn implements(&self) -> Option { support::node(&self.syntax) } + pub fn body(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct NewTarget { @@ -1056,13 +950,13 @@ pub struct NewTarget { } impl NewTarget { pub fn new_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![new]) + support::required_token(&self.syntax, T![new]) } pub fn dot_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [.]) + support::required_token(&self.syntax, T ! [.]) } pub fn target_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![target]) + support::required_token(&self.syntax, T![target]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1071,10 +965,10 @@ pub struct ImportMeta { } impl ImportMeta { pub fn import_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![import]) + support::required_token(&self.syntax, T![import]) } pub fn dot_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [.]) + support::required_token(&self.syntax, T ! [.]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1083,9 +977,9 @@ pub struct SuperCall { } impl SuperCall { pub fn super_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![super]) + support::required_token(&self.syntax, T![super]) } - pub fn arguments(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn arguments(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ImportCall { @@ -1093,16 +987,14 @@ pub struct ImportCall { } impl ImportCall { pub fn import_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![import]) + support::required_token(&self.syntax, T![import]) } pub fn l_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['(']) - } - pub fn argument(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_token(&self.syntax, T!['(']) } + pub fn argument(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn r_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![')']) + support::required_token(&self.syntax, T![')']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1111,14 +1003,10 @@ pub struct YieldExpr { } impl YieldExpr { pub fn yield_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![yield]) - } - pub fn star_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [*]) - } - pub fn value(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_token(&self.syntax, T![yield]) } + pub fn star_token(&self) -> Option { support::token(&self.syntax, T ! [*]) } + pub fn value(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct AwaitExpr { @@ -1126,29 +1014,29 @@ pub struct AwaitExpr { } impl AwaitExpr { pub fn await_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![await]) + support::required_token(&self.syntax, T![await]) } - pub fn expr(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn expr(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct PrivatePropAccess { pub(crate) syntax: SyntaxNode, } impl PrivatePropAccess { - pub fn lhs(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn lhs(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn dot_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [.]) + support::required_token(&self.syntax, T ! [.]) } - pub fn rhs(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn rhs(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsNonNull { pub(crate) syntax: SyntaxNode, } impl TsNonNull { - pub fn expr(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn expr(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn excl_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![!]) + support::required_token(&self.syntax, T![!]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1156,14 +1044,14 @@ pub struct TsAssertion { pub(crate) syntax: SyntaxNode, } impl TsAssertion { - pub fn expr(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } - pub fn ident(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn expr(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn ident(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn l_angle_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [<]) + support::required_token(&self.syntax, T ! [<]) } - pub fn ty(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ty(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn r_angle_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [>]) + support::required_token(&self.syntax, T ! [>]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1171,16 +1059,16 @@ pub struct TsConstAssertion { pub(crate) syntax: SyntaxNode, } impl TsConstAssertion { - pub fn expr(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } - pub fn ident(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn expr(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn ident(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn l_angle_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [<]) + support::required_token(&self.syntax, T ! [<]) } pub fn const_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![const]) + support::required_token(&self.syntax, T![const]) } pub fn r_angle_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [>]) + support::required_token(&self.syntax, T ! [>]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1189,7 +1077,7 @@ pub struct Name { } impl Name { pub fn ident_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![ident]) + support::required_token(&self.syntax, T![ident]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1198,11 +1086,11 @@ pub struct TsTypeArgs { } impl TsTypeArgs { pub fn l_angle_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [<]) + support::required_token(&self.syntax, T ! [<]) } - pub fn args(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn args(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn r_angle_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [>]) + support::required_token(&self.syntax, T ! [>]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1211,13 +1099,13 @@ pub struct ArgList { } impl ArgList { pub fn l_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['(']) + support::required_token(&self.syntax, T!['(']) } pub fn args(&self) -> AstSeparatedList { support::separated_list(&self.syntax, 0usize) } pub fn r_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![')']) + support::required_token(&self.syntax, T![')']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1225,13 +1113,9 @@ pub struct TsTypeParams { pub(crate) syntax: SyntaxNode, } impl TsTypeParams { - pub fn l_angle_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [<]) - } - pub fn params(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } - pub fn r_angle_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [>]) - } + pub fn l_angle_token(&self) -> Option { support::token(&self.syntax, T ! [<]) } + pub fn params(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn r_angle_token(&self) -> Option { support::token(&self.syntax, T ! [>]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ParameterList { @@ -1239,13 +1123,13 @@ pub struct ParameterList { } impl ParameterList { pub fn l_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['(']) + support::required_token(&self.syntax, T!['(']) } pub fn parameters(&self) -> AstSeparatedList { support::separated_list(&self.syntax, 0usize) } pub fn r_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![')']) + support::required_token(&self.syntax, T![')']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1253,10 +1137,8 @@ pub struct TsExprWithTypeArgs { pub(crate) syntax: SyntaxNode, } impl TsExprWithTypeArgs { - pub fn item(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } - pub fn type_params(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) - } + pub fn item(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn type_params(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ClassBody { @@ -1264,11 +1146,11 @@ pub struct ClassBody { } impl ClassBody { pub fn l_curly_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['{']) + support::required_token(&self.syntax, T!['{']) } pub fn elements(&self) -> AstNodeList { support::node_list(&self.syntax, 0usize) } pub fn r_curly_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['}']) + support::required_token(&self.syntax, T!['}']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1276,87 +1158,55 @@ pub struct Method { pub(crate) syntax: SyntaxNode, } impl Method { - pub fn static_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![static]) - } - pub fn async_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![async]) - } - pub fn star_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [*]) - } - pub fn name(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } - pub fn type_params(&self) -> Option { support::as_optional_node(&self.syntax) } - pub fn parameters(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) - } - pub fn colon_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [:]) - } - pub fn return_type(&self) -> Option { support::as_optional_node(&self.syntax) } - pub fn body(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) - } + pub fn static_token(&self) -> Option { support::token(&self.syntax, T![static]) } + pub fn async_token(&self) -> Option { support::token(&self.syntax, T![async]) } + pub fn star_token(&self) -> Option { support::token(&self.syntax, T ! [*]) } + pub fn name(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn type_params(&self) -> Option { support::node(&self.syntax) } + pub fn parameters(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn colon_token(&self) -> Option { support::token(&self.syntax, T ! [:]) } + pub fn return_type(&self) -> Option { support::node(&self.syntax) } + pub fn body(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct PrivateProp { pub(crate) syntax: SyntaxNode, } impl PrivateProp { - pub fn class_prop(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn class_prop(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ClassProp { pub(crate) syntax: SyntaxNode, } impl ClassProp { - pub fn declare_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![declare]) - } + pub fn declare_token(&self) -> Option { support::token(&self.syntax, T![declare]) } pub fn abstract_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![abstract]) - } - pub fn static_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![static]) - } - pub fn accessibility(&self) -> Option { - support::as_optional_node(&self.syntax) + support::token(&self.syntax, T![abstract]) } - pub fn hash_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [#]) - } - pub fn key(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn static_token(&self) -> Option { support::token(&self.syntax, T![static]) } + pub fn accessibility(&self) -> Option { support::node(&self.syntax) } + pub fn hash_token(&self) -> Option { support::token(&self.syntax, T ! [#]) } + pub fn key(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn question_mark_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [?]) - } - pub fn excl_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![!]) - } - pub fn ty(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } - pub fn eq_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [=]) - } - pub fn value(&self) -> Option { support::as_optional_node(&self.syntax) } - pub fn semicolon_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [;]) + support::token(&self.syntax, T ! [?]) } + pub fn excl_token(&self) -> Option { support::token(&self.syntax, T![!]) } + pub fn ty(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn eq_token(&self) -> Option { support::token(&self.syntax, T ! [=]) } + pub fn value(&self) -> Option { support::node(&self.syntax) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T ! [;]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Constructor { pub(crate) syntax: SyntaxNode, } impl Constructor { - pub fn accessibility(&self) -> Option { - support::as_optional_node(&self.syntax) - } - pub fn name(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } - pub fn type_params(&self) -> Option { support::as_optional_node(&self.syntax) } - pub fn parameters(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) - } - pub fn body(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) - } + pub fn accessibility(&self) -> Option { support::node(&self.syntax) } + pub fn name(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn type_params(&self) -> Option { support::node(&self.syntax) } + pub fn parameters(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn body(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsIndexSignature { @@ -1364,18 +1214,18 @@ pub struct TsIndexSignature { } impl TsIndexSignature { pub fn readonly_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![readonly]) + support::token(&self.syntax, T![readonly]) } pub fn l_brack_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['[']) + support::required_token(&self.syntax, T!['[']) } - pub fn pat(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn pat(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn colon_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [:]) + support::required_token(&self.syntax, T ! [:]) } - pub fn ty(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ty(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn r_brack_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![']']) + support::required_token(&self.syntax, T![']']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1384,15 +1234,11 @@ pub struct Getter { } impl Getter { pub fn get_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![get]) - } - pub fn key(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } - pub fn parameters(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) - } - pub fn body(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_token(&self.syntax, T![get]) } + pub fn key(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn parameters(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn body(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Setter { @@ -1400,15 +1246,11 @@ pub struct Setter { } impl Setter { pub fn set_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![set]) - } - pub fn key(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } - pub fn parameters(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) - } - pub fn body(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_token(&self.syntax, T![set]) } + pub fn key(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn parameters(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn body(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsAccessibility { @@ -1416,10 +1258,10 @@ pub struct TsAccessibility { } impl TsAccessibility { pub fn private_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![private]) + support::required_token(&self.syntax, T![private]) } pub fn readonly_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![readonly]) + support::required_token(&self.syntax, T![readonly]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1428,13 +1270,13 @@ pub struct ConstructorParameters { } impl ConstructorParameters { pub fn l_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['(']) + support::required_token(&self.syntax, T!['(']) } pub fn parameters(&self) -> AstSeparatedList { support::separated_list(&self.syntax, 0usize) } pub fn r_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![')']) + support::required_token(&self.syntax, T![')']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1443,9 +1285,9 @@ pub struct TsConstructorParam { } impl TsConstructorParam { pub fn readonly_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![readonly]) + support::required_token(&self.syntax, T![readonly]) } - pub fn pat(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn pat(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct SpreadElement { @@ -1453,11 +1295,9 @@ pub struct SpreadElement { } impl SpreadElement { pub fn dotdotdot_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [...]) - } - pub fn element(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_token(&self.syntax, T ! [...]) } + pub fn element(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Null { @@ -1465,7 +1305,7 @@ pub struct Null { } impl Null { pub fn null_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![null]) + support::required_token(&self.syntax, T![null]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1474,7 +1314,7 @@ pub struct Undefined { } impl Undefined { pub fn undefined_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![undefined]) + support::required_token(&self.syntax, T![undefined]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1482,17 +1322,13 @@ pub struct SinglePattern { pub(crate) syntax: SyntaxNode, } impl SinglePattern { - pub fn name(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn name(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn question_mark_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [?]) - } - pub fn excl_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![!]) + support::token(&self.syntax, T ! [?]) } - pub fn colon_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [:]) - } - pub fn ty(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn excl_token(&self) -> Option { support::token(&self.syntax, T![!]) } + pub fn colon_token(&self) -> Option { support::token(&self.syntax, T ! [:]) } + pub fn ty(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct RestPattern { @@ -1500,26 +1336,22 @@ pub struct RestPattern { } impl RestPattern { pub fn dotdotdot_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [...]) + support::required_token(&self.syntax, T ! [...]) } - pub fn pat(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn pat(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct AssignPattern { pub(crate) syntax: SyntaxNode, } impl AssignPattern { - pub fn key(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } - pub fn colon_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [:]) - } - pub fn ty(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn key(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn colon_token(&self) -> Option { support::token(&self.syntax, T ! [:]) } + pub fn ty(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn eq_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [=]) - } - pub fn value(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_token(&self.syntax, T ! [=]) } + pub fn value(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ObjectPattern { @@ -1527,13 +1359,13 @@ pub struct ObjectPattern { } impl ObjectPattern { pub fn l_curly_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['{']) + support::required_token(&self.syntax, T!['{']) } pub fn elements(&self) -> AstSeparatedList { support::separated_list(&self.syntax, 0usize) } pub fn r_curly_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['}']) + support::required_token(&self.syntax, T!['}']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1542,35 +1374,35 @@ pub struct ArrayPattern { } impl ArrayPattern { pub fn l_brack_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['[']) + support::required_token(&self.syntax, T!['[']) } pub fn elements(&self) -> AstNodeList { support::node_list(&self.syntax, 0usize) } pub fn r_brack_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![']']) + support::required_token(&self.syntax, T![']']) } pub fn excl_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![!]) + support::required_token(&self.syntax, T![!]) } pub fn colon_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [:]) + support::required_token(&self.syntax, T ! [:]) } - pub fn ty(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ty(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ExprPattern { pub(crate) syntax: SyntaxNode, } impl ExprPattern { - pub fn expr(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn expr(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct KeyValuePattern { pub(crate) syntax: SyntaxNode, } impl KeyValuePattern { - pub fn key(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn key(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn colon_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [:]) + support::required_token(&self.syntax, T ! [:]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1579,7 +1411,7 @@ pub struct LiteralProp { } impl LiteralProp { pub fn colon_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [:]) + support::required_token(&self.syntax, T ! [:]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1588,31 +1420,27 @@ pub struct SpreadProp { } impl SpreadProp { pub fn dotdotdot_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [...]) - } - pub fn value(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_token(&self.syntax, T ! [...]) } + pub fn value(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct InitializedProp { pub(crate) syntax: SyntaxNode, } impl InitializedProp { - pub fn key(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn key(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn eq_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [=]) - } - pub fn value(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_token(&self.syntax, T ! [=]) } + pub fn value(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct IdentProp { pub(crate) syntax: SyntaxNode, } impl IdentProp { - pub fn name(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn name(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ComputedPropertyName { @@ -1620,11 +1448,11 @@ pub struct ComputedPropertyName { } impl ComputedPropertyName { pub fn l_brack_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['[']) + support::required_token(&self.syntax, T!['[']) } - pub fn expr(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn expr(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn r_brack_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![']']) + support::required_token(&self.syntax, T![']']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1633,9 +1461,9 @@ pub struct PrivateName { } impl PrivateName { pub fn hash_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [#]) + support::required_token(&self.syntax, T ! [#]) } - pub fn name(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn name(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Condition { @@ -1643,13 +1471,13 @@ pub struct Condition { } impl Condition { pub fn l_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['(']) + support::required_token(&self.syntax, T!['(']) } pub fn condition(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_node(&self.syntax) } pub fn r_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![')']) + support::required_token(&self.syntax, T![')']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1657,29 +1485,17 @@ pub struct FnDecl { pub(crate) syntax: SyntaxNode, } impl FnDecl { - pub fn async_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![async]) - } + pub fn async_token(&self) -> Option { support::token(&self.syntax, T![async]) } pub fn function_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![function]) - } - pub fn star_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [*]) - } - pub fn name(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } - pub fn type_parameters(&self) -> Option { - support::as_optional_node(&self.syntax) - } - pub fn parameters(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) - } - pub fn colon_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [:]) - } - pub fn return_type(&self) -> Option { support::as_optional_node(&self.syntax) } - pub fn body(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_token(&self.syntax, T![function]) } + pub fn star_token(&self) -> Option { support::token(&self.syntax, T ! [*]) } + pub fn name(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn type_parameters(&self) -> Option { support::node(&self.syntax) } + pub fn parameters(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn colon_token(&self) -> Option { support::token(&self.syntax, T ! [:]) } + pub fn return_type(&self) -> Option { support::node(&self.syntax) } + pub fn body(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ClassDecl { @@ -1687,33 +1503,41 @@ pub struct ClassDecl { } impl ClassDecl { pub fn class_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![class]) + support::required_token(&self.syntax, T![class]) } - pub fn name(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn name(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn extends_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![extends]) + support::required_token(&self.syntax, T![extends]) } - pub fn parent(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } - pub fn body(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn parent(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn body(&self) -> SyntaxResult { support::required_node(&self.syntax) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct JsVariableDeclarationStatement { + pub(crate) syntax: SyntaxNode, +} +impl JsVariableDeclarationStatement { + pub fn declaration(&self) -> SyntaxResult { + support::required_node(&self.syntax) + } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T ! [;]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsEnum { pub(crate) syntax: SyntaxNode, } impl TsEnum { - pub fn const_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![const]) - } + pub fn const_token(&self) -> Option { support::token(&self.syntax, T![const]) } pub fn enum_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![enum]) + support::required_token(&self.syntax, T![enum]) } - pub fn ident(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ident(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn l_curly_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['{']) + support::required_token(&self.syntax, T!['{']) } pub fn members(&self) -> AstNodeList { support::node_list(&self.syntax, 0usize) } pub fn r_curly_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['}']) + support::required_token(&self.syntax, T!['}']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1722,15 +1546,13 @@ pub struct TsTypeAliasDecl { } impl TsTypeAliasDecl { pub fn type_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![type]) - } - pub fn type_params(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_token(&self.syntax, T![type]) } + pub fn type_params(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn eq_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [=]) + support::required_token(&self.syntax, T ! [=]) } - pub fn ty(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ty(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsNamespaceDecl { @@ -1738,13 +1560,11 @@ pub struct TsNamespaceDecl { } impl TsNamespaceDecl { pub fn declare_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![declare]) + support::required_token(&self.syntax, T![declare]) } - pub fn ident(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } - pub fn dot_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [.]) - } - pub fn body(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ident(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn dot_token(&self) -> Option { support::token(&self.syntax, T ! [.]) } + pub fn body(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsModuleDecl { @@ -1752,62 +1572,54 @@ pub struct TsModuleDecl { } impl TsModuleDecl { pub fn declare_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![declare]) - } - pub fn global_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![global]) + support::required_token(&self.syntax, T![declare]) } + pub fn global_token(&self) -> Option { support::token(&self.syntax, T![global]) } pub fn module_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![module]) - } - pub fn dot_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [.]) + support::required_token(&self.syntax, T![module]) } - pub fn ident(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } - pub fn body(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn dot_token(&self) -> Option { support::token(&self.syntax, T ! [.]) } + pub fn ident(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn body(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsInterfaceDecl { pub(crate) syntax: SyntaxNode, } impl TsInterfaceDecl { - pub fn declare_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![declare]) - } + pub fn declare_token(&self) -> Option { support::token(&self.syntax, T![declare]) } pub fn interface_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![interface]) - } - pub fn type_params(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_token(&self.syntax, T![interface]) } - pub fn extends_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![extends]) - } - pub fn extends(&self) -> Option { support::as_optional_node(&self.syntax) } + pub fn type_params(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn extends_token(&self) -> Option { support::token(&self.syntax, T![extends]) } + pub fn extends(&self) -> Option { support::node(&self.syntax) } pub fn l_curly_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['{']) - } - pub fn members(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_token(&self.syntax, T!['{']) } + pub fn members(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn r_curly_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['}']) + support::required_token(&self.syntax, T!['}']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Declarator { +pub struct JsVariableDeclarator { pub(crate) syntax: SyntaxNode, } -impl Declarator { - pub fn pattern(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } - pub fn excl_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![!]) - } +impl JsVariableDeclarator { + pub fn id(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn init(&self) -> Option { support::node(&self.syntax) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct JsEqualValueClause { + pub(crate) syntax: SyntaxNode, +} +impl JsEqualValueClause { pub fn eq_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [=]) + support::required_token(&self.syntax, T ! [=]) } - pub fn value(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + pub fn expression(&self) -> SyntaxResult { + support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1816,12 +1628,10 @@ pub struct WildcardImport { } impl WildcardImport { pub fn star_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [*]) - } - pub fn as_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![as]) + support::required_token(&self.syntax, T ! [*]) } - pub fn ident(&self) -> Option { support::as_optional_node(&self.syntax) } + pub fn as_token(&self) -> Option { support::token(&self.syntax, T![as]) } + pub fn ident(&self) -> Option { support::node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct NamedImports { @@ -1829,13 +1639,13 @@ pub struct NamedImports { } impl NamedImports { pub fn l_curly_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['{']) + support::required_token(&self.syntax, T!['{']) } pub fn specifiers(&self) -> AstSeparatedList { support::separated_list(&self.syntax, 0usize) } pub fn r_curly_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['}']) + support::required_token(&self.syntax, T!['}']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1848,7 +1658,7 @@ pub struct Specifier { pub(crate) syntax: SyntaxNode, } impl Specifier { - pub fn name(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn name(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsExternalModuleRef { @@ -1856,13 +1666,13 @@ pub struct TsExternalModuleRef { } impl TsExternalModuleRef { pub fn require_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![require]) + support::required_token(&self.syntax, T![require]) } pub fn l_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['(']) + support::required_token(&self.syntax, T!['(']) } pub fn r_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![')']) + support::required_token(&self.syntax, T![')']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1871,7 +1681,7 @@ pub struct TsAny { } impl TsAny { pub fn any_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![any]) + support::required_token(&self.syntax, T![any]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1880,7 +1690,7 @@ pub struct TsUnknown { } impl TsUnknown { pub fn unknown_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![unknown]) + support::required_token(&self.syntax, T![unknown]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1888,42 +1698,42 @@ pub struct TsNumber { pub(crate) syntax: SyntaxNode, } impl TsNumber { - pub fn ident(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ident(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsObject { pub(crate) syntax: SyntaxNode, } impl TsObject { - pub fn ident(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ident(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsBoolean { pub(crate) syntax: SyntaxNode, } impl TsBoolean { - pub fn ident(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ident(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsBigint { pub(crate) syntax: SyntaxNode, } impl TsBigint { - pub fn ident(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ident(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsString { pub(crate) syntax: SyntaxNode, } impl TsString { - pub fn ident(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ident(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsSymbol { pub(crate) syntax: SyntaxNode, } impl TsSymbol { - pub fn ident(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ident(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsVoid { @@ -1931,7 +1741,7 @@ pub struct TsVoid { } impl TsVoid { pub fn void_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![void]) + support::required_token(&self.syntax, T![void]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1940,7 +1750,7 @@ pub struct TsUndefined { } impl TsUndefined { pub fn undefined_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![undefined]) + support::required_token(&self.syntax, T![undefined]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1949,7 +1759,7 @@ pub struct TsNull { } impl TsNull { pub fn null_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![null]) + support::required_token(&self.syntax, T![null]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1958,7 +1768,7 @@ pub struct TsNever { } impl TsNever { pub fn never_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![never]) + support::required_token(&self.syntax, T![never]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1967,7 +1777,7 @@ pub struct TsThis { } impl TsThis { pub fn this_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![this]) + support::required_token(&self.syntax, T![this]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1975,15 +1785,15 @@ pub struct TsLiteral { pub(crate) syntax: SyntaxNode, } impl TsLiteral { - pub fn ident(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ident(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsPredicate { pub(crate) syntax: SyntaxNode, } impl TsPredicate { - pub fn lhs(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } - pub fn rhs(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn lhs(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn rhs(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsTuple { @@ -1991,13 +1801,11 @@ pub struct TsTuple { } impl TsTuple { pub fn l_brack_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['[']) - } - pub fn elements(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_token(&self.syntax, T!['[']) } + pub fn elements(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn r_brack_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![']']) + support::required_token(&self.syntax, T![']']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -2006,11 +1814,11 @@ pub struct TsParen { } impl TsParen { pub fn l_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['(']) + support::required_token(&self.syntax, T!['(']) } - pub fn ty(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ty(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn r_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![')']) + support::required_token(&self.syntax, T![')']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -2018,8 +1826,8 @@ pub struct TsTypeRef { pub(crate) syntax: SyntaxNode, } impl TsTypeRef { - pub fn name(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } - pub fn type_args(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn name(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn type_args(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsTemplate { @@ -2027,7 +1835,7 @@ pub struct TsTemplate { } impl TsTemplate { pub fn elements(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -2036,33 +1844,23 @@ pub struct TsMappedType { } impl TsMappedType { pub fn l_curly_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['{']) - } - pub fn readonly_modifier(&self) -> Option { - support::as_optional_node(&self.syntax) - } - pub fn minus_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [-]) - } - pub fn plus_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [+]) + support::required_token(&self.syntax, T!['{']) } + pub fn readonly_modifier(&self) -> Option { support::node(&self.syntax) } + pub fn minus_token(&self) -> Option { support::token(&self.syntax, T ! [-]) } + pub fn plus_token(&self) -> Option { support::token(&self.syntax, T ! [+]) } pub fn question_mark_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [?]) - } - pub fn param(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::token(&self.syntax, T ! [?]) } + pub fn param(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn colon_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [:]) + support::required_token(&self.syntax, T ! [:]) } - pub fn ty(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ty(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn r_curly_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['}']) - } - pub fn semicolon_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [;]) + support::required_token(&self.syntax, T!['}']) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T ! [;]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsImport { @@ -2070,20 +1868,16 @@ pub struct TsImport { } impl TsImport { pub fn import_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![import]) - } - pub fn type_args(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } - pub fn dot_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [.]) + support::required_token(&self.syntax, T![import]) } + pub fn type_args(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn dot_token(&self) -> Option { support::token(&self.syntax, T ! [.]) } pub fn l_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['(']) - } - pub fn qualifier(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_token(&self.syntax, T!['(']) } + pub fn qualifier(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn r_paren_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![')']) + support::required_token(&self.syntax, T![')']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -2092,11 +1886,11 @@ pub struct TsArray { } impl TsArray { pub fn l_brack_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['[']) + support::required_token(&self.syntax, T!['[']) } - pub fn ty(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ty(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn r_brack_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![']']) + support::required_token(&self.syntax, T![']']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -2105,11 +1899,11 @@ pub struct TsIndexedArray { } impl TsIndexedArray { pub fn l_brack_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['[']) + support::required_token(&self.syntax, T!['[']) } - pub fn ty(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ty(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn r_brack_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![']']) + support::required_token(&self.syntax, T![']']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -2117,7 +1911,7 @@ pub struct TsTypeOperator { pub(crate) syntax: SyntaxNode, } impl TsTypeOperator { - pub fn ty(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ty(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsIntersection { @@ -2138,11 +1932,11 @@ pub struct TsFnType { pub(crate) syntax: SyntaxNode, } impl TsFnType { - pub fn params(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn params(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn fat_arrow_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [=>]) + support::required_token(&self.syntax, T ! [=>]) } - pub fn return_type(&self) -> Option { support::as_optional_node(&self.syntax) } + pub fn return_type(&self) -> Option { support::node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsConstructorType { @@ -2150,27 +1944,27 @@ pub struct TsConstructorType { } impl TsConstructorType { pub fn new_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![new]) + support::required_token(&self.syntax, T![new]) } - pub fn params(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn params(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn colon_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [:]) + support::required_token(&self.syntax, T ! [:]) } - pub fn return_type(&self) -> Option { support::as_optional_node(&self.syntax) } + pub fn return_type(&self) -> Option { support::node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsConditionalType { pub(crate) syntax: SyntaxNode, } impl TsConditionalType { - pub fn ty(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ty(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn question_mark_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [?]) + support::required_token(&self.syntax, T ! [?]) } pub fn colon_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [:]) + support::required_token(&self.syntax, T ! [:]) } - pub fn extends(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn extends(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsObjectType { @@ -2178,11 +1972,11 @@ pub struct TsObjectType { } impl TsObjectType { pub fn l_curly_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['{']) + support::required_token(&self.syntax, T!['{']) } pub fn members(&self) -> AstNodeList { support::node_list(&self.syntax, 0usize) } pub fn r_curly_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['}']) + support::required_token(&self.syntax, T!['}']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -2191,48 +1985,44 @@ pub struct TsInfer { } impl TsInfer { pub fn infer_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![infer]) + support::required_token(&self.syntax, T![infer]) } - pub fn ident(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ident(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsTupleElement { pub(crate) syntax: SyntaxNode, } impl TsTupleElement { - pub fn ident(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ident(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn colon_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [:]) + support::required_token(&self.syntax, T ! [:]) } pub fn question_mark_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [?]) + support::required_token(&self.syntax, T ! [?]) } - pub fn dotdotdot_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [...]) - } - pub fn ty(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn dotdotdot_token(&self) -> Option { support::token(&self.syntax, T ! [...]) } + pub fn ty(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsEnumMember { pub(crate) syntax: SyntaxNode, } impl TsEnumMember { - pub fn ident(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ident(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn eq_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [=]) - } - pub fn value(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_token(&self.syntax, T ! [=]) } + pub fn value(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsTemplateElement { pub(crate) syntax: SyntaxNode, } impl TsTemplateElement { - pub fn ty(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ty(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn r_curly_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['}']) + support::required_token(&self.syntax, T!['}']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -2240,14 +2030,10 @@ pub struct TsMappedTypeReadonly { pub(crate) syntax: SyntaxNode, } impl TsMappedTypeReadonly { - pub fn minus_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [-]) - } - pub fn plus_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [+]) - } + pub fn minus_token(&self) -> Option { support::token(&self.syntax, T ! [-]) } + pub fn plus_token(&self) -> Option { support::token(&self.syntax, T ! [+]) } pub fn readonly_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![readonly]) + support::token(&self.syntax, T![readonly]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -2255,22 +2041,18 @@ pub struct TsMappedTypeParam { pub(crate) syntax: SyntaxNode, } impl TsMappedTypeParam { - pub fn l_brack_token(&self) -> Option { - support::as_optional_token(&self.syntax, T!['[']) - } - pub fn name(&self) -> Option { support::as_optional_node(&self.syntax) } - pub fn r_brack_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![']']) - } - pub fn ident(&self) -> Option { support::as_optional_node(&self.syntax) } - pub fn ty(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn l_brack_token(&self) -> Option { support::token(&self.syntax, T!['[']) } + pub fn name(&self) -> Option { support::node(&self.syntax) } + pub fn r_brack_token(&self) -> Option { support::token(&self.syntax, T![']']) } + pub fn ident(&self) -> Option { support::node(&self.syntax) } + pub fn ty(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsTypeName { pub(crate) syntax: SyntaxNode, } impl TsTypeName { - pub fn ident(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ident(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsExtends { @@ -2278,9 +2060,9 @@ pub struct TsExtends { } impl TsExtends { pub fn extends_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![extends]) + support::required_token(&self.syntax, T![extends]) } - pub fn ty(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ty(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsModuleBlock { @@ -2288,11 +2070,11 @@ pub struct TsModuleBlock { } impl TsModuleBlock { pub fn l_curly_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['{']) + support::required_token(&self.syntax, T!['{']) } - pub fn items(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn items(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn r_curly_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T!['}']) + support::required_token(&self.syntax, T!['}']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -2300,11 +2082,9 @@ pub struct TsTypeParam { pub(crate) syntax: SyntaxNode, } impl TsTypeParam { - pub fn ident(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } - pub fn constraint(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) - } - pub fn default(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ident(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn constraint(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn default(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsConstraint { @@ -2312,9 +2092,9 @@ pub struct TsConstraint { } impl TsConstraint { pub fn extends_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![extends]) + support::required_token(&self.syntax, T![extends]) } - pub fn ty(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ty(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsDefault { @@ -2322,25 +2102,21 @@ pub struct TsDefault { } impl TsDefault { pub fn eq_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [=]) + support::required_token(&self.syntax, T ! [=]) } - pub fn ty(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ty(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsCallSignatureDecl { pub(crate) syntax: SyntaxNode, } impl TsCallSignatureDecl { - pub fn type_params(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) - } - pub fn parameters(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) - } + pub fn type_params(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn parameters(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn colon_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [:]) + support::required_token(&self.syntax, T ! [:]) } - pub fn return_type(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn return_type(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsConstructSignatureDecl { @@ -2348,18 +2124,12 @@ pub struct TsConstructSignatureDecl { } impl TsConstructSignatureDecl { pub fn new_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T![new]) - } - pub fn type_params(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) - } - pub fn parameters(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::required_token(&self.syntax, T![new]) } - pub fn colon_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [:]) - } - pub fn return_type(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn type_params(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn parameters(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn colon_token(&self) -> Option { support::token(&self.syntax, T ! [:]) } + pub fn return_type(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsPropertySignature { @@ -2367,16 +2137,16 @@ pub struct TsPropertySignature { } impl TsPropertySignature { pub fn readonly_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![readonly]) + support::token(&self.syntax, T![readonly]) } - pub fn prop(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn prop(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn question_mark_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [?]) + support::required_token(&self.syntax, T ! [?]) } pub fn colon_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [:]) + support::required_token(&self.syntax, T ! [:]) } - pub fn ty(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn ty(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsMethodSignature { @@ -2384,33 +2154,29 @@ pub struct TsMethodSignature { } impl TsMethodSignature { pub fn readonly_token(&self) -> Option { - support::as_optional_token(&self.syntax, T![readonly]) - } - pub fn key(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } - pub fn type_params(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) - } - pub fn parameters(&self) -> SyntaxResult { - support::as_mandatory_node(&self.syntax) + support::token(&self.syntax, T![readonly]) } + pub fn key(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn type_params(&self) -> SyntaxResult { support::required_node(&self.syntax) } + pub fn parameters(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn question_mark_token(&self) -> Option { - support::as_optional_token(&self.syntax, T ! [?]) + support::token(&self.syntax, T ! [?]) } pub fn colon_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [:]) + support::required_token(&self.syntax, T ! [:]) } - pub fn return_type(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn return_type(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TsQualifiedPath { pub(crate) syntax: SyntaxNode, } impl TsQualifiedPath { - pub fn lhs(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn lhs(&self) -> SyntaxResult { support::required_node(&self.syntax) } pub fn dot_token(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, T ! [.]) + support::required_token(&self.syntax, T ! [.]) } - pub fn rhs(&self) -> SyntaxResult { support::as_mandatory_node(&self.syntax) } + pub fn rhs(&self) -> SyntaxResult { support::required_node(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum JsAnyStatement { @@ -2449,7 +2215,7 @@ pub enum JsAnyStatement { pub enum Decl { FnDecl(FnDecl), ClassDecl(ClassDecl), - VarDecl(VarDecl), + JsVariableDeclarationStatement(JsVariableDeclarationStatement), TsEnum(TsEnum), TsTypeAliasDecl(TsTypeAliasDecl), TsNamespaceDecl(TsNamespaceDecl), @@ -2493,7 +2259,7 @@ pub enum JsAnyExpression { } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum ForHead { - VarDecl(VarDecl), + JsVariableDeclaration(JsVariableDeclaration), JsAnyExpression(JsAnyExpression), } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -3101,8 +2867,8 @@ impl AstNode for ForStmtUpdate { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for VarDecl { - fn can_cast(kind: SyntaxKind) -> bool { kind == VAR_DECL } +impl AstNode for JsVariableDeclaration { + fn can_cast(kind: SyntaxKind) -> bool { kind == JS_VARIABLE_DECLARATION } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -3904,6 +3670,17 @@ impl AstNode for ClassDecl { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } +impl AstNode for JsVariableDeclarationStatement { + fn can_cast(kind: SyntaxKind) -> bool { kind == JS_VARIABLE_DECLARATION_STATEMENT } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} impl AstNode for TsEnum { fn can_cast(kind: SyntaxKind) -> bool { kind == TS_ENUM } fn cast(syntax: SyntaxNode) -> Option { @@ -3959,8 +3736,19 @@ impl AstNode for TsInterfaceDecl { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for Declarator { - fn can_cast(kind: SyntaxKind) -> bool { kind == DECLARATOR } +impl AstNode for JsVariableDeclarator { + fn can_cast(kind: SyntaxKind) -> bool { kind == JS_VARIABLE_DECLARATOR } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} +impl AstNode for JsEqualValueClause { + fn can_cast(kind: SyntaxKind) -> bool { kind == JS_EQUAL_VALUE_CLAUSE } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -4776,8 +4564,10 @@ impl From for Decl { impl From for Decl { fn from(node: ClassDecl) -> Decl { Decl::ClassDecl(node) } } -impl From for Decl { - fn from(node: VarDecl) -> Decl { Decl::VarDecl(node) } +impl From for Decl { + fn from(node: JsVariableDeclarationStatement) -> Decl { + Decl::JsVariableDeclarationStatement(node) + } } impl From for Decl { fn from(node: TsEnum) -> Decl { Decl::TsEnum(node) } @@ -4797,8 +4587,14 @@ impl From for Decl { impl AstNode for Decl { fn can_cast(kind: SyntaxKind) -> bool { match kind { - FN_DECL | CLASS_DECL | VAR_DECL | TS_ENUM | TS_TYPE_ALIAS_DECL | TS_NAMESPACE_DECL - | TS_MODULE_DECL | TS_INTERFACE_DECL => true, + FN_DECL + | CLASS_DECL + | JS_VARIABLE_DECLARATION_STATEMENT + | TS_ENUM + | TS_TYPE_ALIAS_DECL + | TS_NAMESPACE_DECL + | TS_MODULE_DECL + | TS_INTERFACE_DECL => true, _ => false, } } @@ -4806,7 +4602,9 @@ impl AstNode for Decl { let res = match syntax.kind() { FN_DECL => Decl::FnDecl(FnDecl { syntax }), CLASS_DECL => Decl::ClassDecl(ClassDecl { syntax }), - VAR_DECL => Decl::VarDecl(VarDecl { syntax }), + JS_VARIABLE_DECLARATION_STATEMENT => { + Decl::JsVariableDeclarationStatement(JsVariableDeclarationStatement { syntax }) + } TS_ENUM => Decl::TsEnum(TsEnum { syntax }), TS_TYPE_ALIAS_DECL => Decl::TsTypeAliasDecl(TsTypeAliasDecl { syntax }), TS_NAMESPACE_DECL => Decl::TsNamespaceDecl(TsNamespaceDecl { syntax }), @@ -4820,7 +4618,7 @@ impl AstNode for Decl { match self { Decl::FnDecl(it) => &it.syntax, Decl::ClassDecl(it) => &it.syntax, - Decl::VarDecl(it) => &it.syntax, + Decl::JsVariableDeclarationStatement(it) => &it.syntax, Decl::TsEnum(it) => &it.syntax, Decl::TsTypeAliasDecl(it) => &it.syntax, Decl::TsNamespaceDecl(it) => &it.syntax, @@ -5050,20 +4848,22 @@ impl AstNode for JsAnyExpression { } } } -impl From for ForHead { - fn from(node: VarDecl) -> ForHead { ForHead::VarDecl(node) } +impl From for ForHead { + fn from(node: JsVariableDeclaration) -> ForHead { ForHead::JsVariableDeclaration(node) } } impl AstNode for ForHead { fn can_cast(kind: SyntaxKind) -> bool { match kind { - VAR_DECL => true, + JS_VARIABLE_DECLARATION => true, k if JsAnyExpression::can_cast(k) => true, _ => false, } } fn cast(syntax: SyntaxNode) -> Option { let res = match syntax.kind() { - VAR_DECL => ForHead::VarDecl(VarDecl { syntax }), + JS_VARIABLE_DECLARATION => { + ForHead::JsVariableDeclaration(JsVariableDeclaration { syntax }) + } _ => { if let Some(js_any_expression) = JsAnyExpression::cast(syntax) { return Some(ForHead::JsAnyExpression(js_any_expression)); @@ -5075,7 +4875,7 @@ impl AstNode for ForHead { } fn syntax(&self) -> &SyntaxNode { match self { - ForHead::VarDecl(it) => &it.syntax, + ForHead::JsVariableDeclaration(it) => &it.syntax, ForHead::JsAnyExpression(it) => it.syntax(), } } @@ -6266,7 +6066,7 @@ impl std::fmt::Display for ForStmtUpdate { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for VarDecl { +impl std::fmt::Display for JsVariableDeclaration { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -6631,6 +6431,11 @@ impl std::fmt::Display for ClassDecl { std::fmt::Display::fmt(self.syntax(), f) } } +impl std::fmt::Display for JsVariableDeclarationStatement { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} impl std::fmt::Display for TsEnum { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -6656,7 +6461,12 @@ impl std::fmt::Display for TsInterfaceDecl { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for Declarator { +impl std::fmt::Display for JsVariableDeclarator { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for JsEqualValueClause { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } diff --git a/crates/rslint_parser/src/ast/stmt_ext.rs b/crates/rslint_parser/src/ast/stmt_ext.rs index b5d4219ad8d..f6824b62701 100644 --- a/crates/rslint_parser/src/ast/stmt_ext.rs +++ b/crates/rslint_parser/src/ast/stmt_ext.rs @@ -30,27 +30,38 @@ impl AstNode for StmtListItem { } } -impl VarDecl { - // TODO: switch this to a contextual keyword once the typescript pr lands - pub fn let_token(&self) -> Option { - self.syntax() - .first_lossy_token() - .filter(|t| t.kind() == T![ident] && t.text() == "let") - } +#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] +pub enum JsVariableKind { + Const, + Let, + Var, +} +impl JsVariableDeclaration { /// Whether the declaration is a const declaration pub fn is_const(&self) -> bool { - self.const_token().is_ok() + self.variable_kind() == Ok(JsVariableKind::Const) } /// Whether the declaration is a let declaration pub fn is_let(&self) -> bool { - self.let_token().is_some() + self.variable_kind() == Ok(JsVariableKind::Let) } /// Whether the declaration is a let declaration pub fn is_var(&self) -> bool { - self.var_token().is_ok() + self.variable_kind() == Ok(JsVariableKind::Const) + } + + pub fn variable_kind(&self) -> SyntaxResult { + let token_kind = self.kind_token().map(|t| t.kind())?; + + Ok(match token_kind { + T![const] => JsVariableKind::Const, + T![let] => JsVariableKind::Let, + T![var] => JsVariableKind::Var, + _ => unreachable!(), + }) } } @@ -112,7 +123,7 @@ mod tests { let var_decl = parsed .statements() .iter() - .find_map(|stmt| ast::VarDecl::cast(stmt.syntax().clone())); + .find_map(|stmt| ast::JsVariableDeclarationStatement::cast(stmt.syntax().clone())); assert!(var_decl.is_some()); } diff --git a/crates/rslint_parser/src/syntax/program.rs b/crates/rslint_parser/src/syntax/program.rs index a1483870e1c..b708fa662e7 100644 --- a/crates/rslint_parser/src/syntax/program.rs +++ b/crates/rslint_parser/src/syntax/program.rs @@ -5,7 +5,7 @@ use syntax::stmt::FOLLOWS_LET; use super::decl::{class_decl, function_decl}; use super::expr::{assign_expr, expr, identifier_name, literal, object_expr, primary_expr}; use super::pat::binding_identifier; -use super::stmt::{block_items, semi, var_decl}; +use super::stmt::{block_items, semi, variable_declaration_statement}; use super::typescript::*; use crate::{SyntaxKind::*, *}; @@ -455,7 +455,7 @@ pub fn export_decl(p: &mut Parser) -> CompletedMarker { || p.at(T![const]) || (p.cur_src() == "let" && FOLLOWS_LET.contains(p.nth(1)))) { - var_decl(p, false); + variable_declaration_statement(p); } else { let m = p.start(); diff --git a/crates/rslint_parser/src/syntax/stmt.rs b/crates/rslint_parser/src/syntax/stmt.rs index 3cd296f602a..3a5e55e3953 100644 --- a/crates/rslint_parser/src/syntax/stmt.rs +++ b/crates/rslint_parser/src/syntax/stmt.rs @@ -7,7 +7,7 @@ use super::expr::{assign_expr, expr, EXPR_RECOVERY_SET, STARTS_EXPR}; use super::pat::*; use super::program::{export_decl, import_decl}; use super::typescript::*; -use super::util::{check_for_stmt_declarators, check_label_use, check_lhs}; +use super::util::{check_for_stmt_declaration, check_label_use, check_lhs}; use crate::{SyntaxKind::*, *}; pub const STMT_RECOVERY_SET: TokenSet = token_set![ @@ -86,7 +86,7 @@ pub fn stmt( res.err_if_not_ts(p, "enums can only be declared in TypeScript files"); res } - T![var] | T![const] => var_decl(p, false), + T![var] | T![const] => variable_declaration_statement(p), T![for] => for_stmt(p), T![do] => do_stmt(p), T![switch] => switch_stmt(p), @@ -131,7 +131,9 @@ pub fn stmt( ) } - T![ident] if p.cur_src() == "let" && FOLLOWS_LET.contains(p.nth(1)) => var_decl(p, false), + T![ident] if p.cur_src() == "let" && FOLLOWS_LET.contains(p.nth(1)) => { + variable_declaration_statement(p) + } // TODO: handle `() => {};` with less of a hack _ if p.at_ts(STARTS_EXPR) || p.at(T![<]) => { let complete = expr_stmt(p, decorator); @@ -712,19 +714,29 @@ pub fn while_stmt(p: &mut Parser) -> CompletedMarker { m.complete(p, JS_WHILE_STATEMENT) } -/// A var, const, or let declaration such as `var a = 5, b;` or `let {a, b} = foo;` +/// A var, const, or let declaration statement such as `var a = 5, b;` or `let {a, b} = foo;` // test var_decl // var a = 5; // let { foo, bar } = 5; // let bar, foo; // const a = 5; // const { foo: [bar], baz } = {}; -pub fn var_decl(p: &mut Parser, no_semi: bool) -> CompletedMarker { +pub fn variable_declaration_statement(p: &mut Parser) -> CompletedMarker { // test_err var_decl_err // var a =; // const a = 5 let b = 5; let m = p.start(); let start = p.cur_tok().range.start; + + variable_declaration(p, false); + + semi(p, start..p.cur_tok().range.start); + + m.complete(p, JS_VARIABLE_DECLARATION_STATEMENT) +} + +fn variable_declaration(p: &mut Parser, no_semi: bool) -> CompletedMarker { + let m = p.start(); let mut is_const = None; let mut is_let = false; @@ -735,7 +747,9 @@ pub fn var_decl(p: &mut Parser, no_semi: bool) -> CompletedMarker { p.bump_any() } T![ident] if p.cur_src() == "let" => { - p.bump_any(); + // let is a valid identifier name that's why the returns an ident for let. + // remap it here because we know from the context that this is the let keyword. + p.bump_remap(T![let]); is_let = true; } _ => { @@ -751,28 +765,19 @@ pub fn var_decl(p: &mut Parser, no_semi: bool) -> CompletedMarker { let declared_list = p.start(); - declarator(p, &is_const, no_semi, is_let); + variable_declarator(p, &is_const, no_semi, is_let); - if p.eat(T![,]) { - declarator(p, &is_const, no_semi, is_let); - while p.eat(T![,]) { - declarator(p, &is_const, no_semi, is_let); - } + while p.eat(T![,]) { + variable_declarator(p, &is_const, no_semi, is_let); } declared_list.complete(p, LIST); - - if !no_semi { - semi(p, start..p.cur_tok().range.start); - } - let complete = m.complete(p, VAR_DECL); p.state.name_map.clear(); - - complete + m.complete(p, JS_VARIABLE_DECLARATION) } // A single declarator, either `ident` or `ident = assign_expr` -fn declarator( +pub(crate) fn variable_declarator( p: &mut Parser, is_const: &Option>, for_stmt: bool, @@ -820,8 +825,8 @@ fn declarator( let marker = pat_m.complete(p, kind); - if p.eat(T![=]) { - p.expr_with_semi_recovery(true); + if p.at(T![=]) { + variable_initializer(p); } else if marker.kind() != SINGLE_PATTERN && !for_stmt && !p.state.in_declare { let err = p .err_builder("Object and Array patterns require initializers") @@ -840,7 +845,16 @@ fn declarator( p.error(err); } - Some(m.complete(p, DECLARATOR)) + Some(m.complete(p, JS_VARIABLE_DECLARATOR)) +} + +fn variable_initializer(p: &mut Parser) { + let m = p.start(); + + p.expect(T![=]); + p.expr_with_semi_recovery(true); + + m.complete(p, SyntaxKind::JS_EQUAL_VALUE_CLAUSE); } // A do.. while statement, such as `do {} while (true)` @@ -878,7 +892,7 @@ fn for_head(p: &mut Parser) -> SyntaxKind { include_in: false, ..p.state.clone() }); - let decl = var_decl(&mut *guard, true); + let decl = variable_declaration(&mut *guard, true); drop(guard); m.complete(p, FOR_STMT_INIT); @@ -889,7 +903,7 @@ fn for_head(p: &mut Parser) -> SyntaxKind { let is_in = p.at(T![in]); p.bump_any(); - check_for_stmt_declarators(p, &decl); + check_for_stmt_declaration(p, &decl); for_each_head(p, is_in) } else { diff --git a/crates/rslint_parser/src/syntax/typescript.rs b/crates/rslint_parser/src/syntax/typescript.rs index 52eceaff083..aec84c4d2af 100644 --- a/crates/rslint_parser/src/syntax/typescript.rs +++ b/crates/rslint_parser/src/syntax/typescript.rs @@ -2,7 +2,7 @@ use super::decl::*; use super::expr::{assign_expr, identifier_name, lhs_expr, literal}; -use super::stmt::{block_items, semi, var_decl}; +use super::stmt::{block_items, semi, variable_declaration_statement}; use crate::{SyntaxKind::*, *}; pub const BASE_TS_RECOVERY_SET: TokenSet = token_set![ @@ -156,14 +156,18 @@ pub(crate) fn ts_declare(p: &mut Parser) -> Option { let m = p.start(); p.bump_remap(T![declare]); // unwrap the marker so its children go to `m` - var_decl(p, false).undo_completion(p).abandon(p); - m.complete(p, VAR_DECL) + variable_declaration_statement(p) + .undo_completion(p) + .abandon(p); + m.complete(p, JS_VARIABLE_DECLARATION_STATEMENT) } _ if p.nth_src(1) == "let" => { let m = p.start(); p.bump_remap(T![declare]); - var_decl(p, false).undo_completion(p).abandon(p); - m.complete(p, VAR_DECL) + variable_declaration_statement(p) + .undo_completion(p) + .abandon(p); + m.complete(p, JS_VARIABLE_DECLARATION_STATEMENT) } _ if p.nth_src(1) == "global" => { let m = p.start(); diff --git a/crates/rslint_parser/src/syntax/util.rs b/crates/rslint_parser/src/syntax/util.rs index 4818cbfeb3f..b23056c90b2 100644 --- a/crates/rslint_parser/src/syntax/util.rs +++ b/crates/rslint_parser/src/syntax/util.rs @@ -6,8 +6,6 @@ use crate::{ *, }; -use std::collections::HashMap; - /// Check if assignment to an expression is invalid and report an error if so. /// /// For example: `++true` is invalid. @@ -118,118 +116,6 @@ pub fn get_precedence(tok: SyntaxKind) -> Option { }) } -/// Check the bound names of a variable declaration and issue errors according to `13.3.1.1` -/// -/// # Panics -/// Panics if the marker does not represent a [`VarDecl`](ast::VarDecl). -pub fn check_var_decl_bound_names(p: &mut Parser, marker: &CompletedMarker) { - let mut map = HashMap::with_capacity(3); - - let decl = p.parse_marker::(marker); - if decl.is_let() || decl.is_const() { - for declarator in decl.declared() { - if let Ok(pattern) = declarator.pattern() { - check_pat(p, pattern, &mut map, marker) - } - } - } -} - -fn check_pat( - p: &mut Parser, - pattern: ast::Pattern, - map: &mut HashMap>, - marker: &CompletedMarker, -) { - match pattern { - ast::Pattern::SinglePattern(name) => { - if let Some(ident) = name.name().map_or_else(|_| None, |x| x.ident_token().ok()) { - check_name_pat(p, &ident, map, marker); - } - } - ast::Pattern::AssignPattern(pat) => { - if let Ok(subpat) = pat.value() { - // This should always be a pattern - if ast::Pattern::can_cast(subpat.syntax().kind()) { - check_pat( - p, - ast::Pattern::cast(subpat.syntax().to_owned()).unwrap(), - map, - marker, - ) - } - } - } - ast::Pattern::ObjectPattern(obj) => { - for subpat in obj.elements() { - let pat = match subpat { - ast::ObjectPatternProp::AssignPattern(pat) => pat.into(), - ast::ObjectPatternProp::KeyValuePattern(pat) => { - if let Some(val) = pat.value() { - val - } else { - return; - } - } - ast::ObjectPatternProp::RestPattern(pat) => pat.into(), - ast::ObjectPatternProp::SinglePattern(pat) => pat.into(), - ast::ObjectPatternProp::JsUnknownPattern(_) => todo!(), - }; - check_pat(p, pat, map, marker); - } - } - ast::Pattern::ArrayPattern(pat) => { - for subpat in pat.elements() { - check_pat(p, subpat, map, marker); - } - } - ast::Pattern::RestPattern(pat) => { - if let Ok(subpat) = pat.pat() { - check_pat(p, subpat, map, marker); - } - } - ast::Pattern::ExprPattern(_) => unreachable!(), - ast::Pattern::JsUnknownPattern(_) => todo!(), - } -} - -fn check_name_pat( - p: &mut Parser, - token: &SyntaxToken, - map: &mut HashMap>, - marker: &CompletedMarker, -) { - let range = marker.offset_range(p, token.text_range()); - let token_src = p.source(range).to_owned(); - - if token_src == "let" { - let err = p - .err_builder("`let` cannot be declared as a variable name inside of a declaration") - .primary(range, ""); - - p.error(err); - } - - if let Some(entry) = map.get(&token_src) { - let err = p - .err_builder( - "Declarations inside of a `let` or `const` declaration may not have duplicates", - ) - .secondary( - entry.to_owned(), - &format!("{} is first declared here", token_src), - ) - .primary( - range, - &format!("a second declaration of {} is not allowed", token_src), - ); - - p.error(err); - } else { - map.insert(token_src.to_owned(), range.into()); - } -} - /// Check the LHS expression inside of a for...in or for...of statement according to pub fn check_for_stmt_lhs(p: &mut Parser, expr: JsAnyExpression, marker: &CompletedMarker) { match expr { @@ -333,9 +219,9 @@ pub fn check_lhs(p: &mut Parser, expr: JsAnyExpression, marker: &CompletedMarker } /// Check if the var declaration in a for statement has multiple declarators, which is invalid -pub fn check_for_stmt_declarators(p: &mut Parser, marker: &CompletedMarker) { - let parsed = p.parse_marker::(marker); - let excess = parsed.declared().iter().skip(1).collect::>(); +pub fn check_for_stmt_declaration(p: &mut Parser, marker: &CompletedMarker) { + let parsed = p.parse_marker::(marker); + let excess = parsed.declarators().iter().skip(1).collect::>(); if !excess.is_empty() { let start = marker diff --git a/crates/rslint_parser/src/tests.rs b/crates/rslint_parser/src/tests.rs index fae0982ca58..06a876b655f 100644 --- a/crates/rslint_parser/src/tests.rs +++ b/crates/rslint_parser/src/tests.rs @@ -1,6 +1,8 @@ use crate::ast::ArgList; use crate::{parse_module, parse_text, AstNode, ParserError, SyntaxNode}; use expect_test::expect_file; +use rslint_errors::file::SimpleFile; +use rslint_errors::termcolor::Buffer; use rslint_errors::{file::SimpleFiles, Emitter}; use rslint_syntax::SyntaxKind; use std::fs; @@ -79,7 +81,7 @@ fn parser_tests() { dir_tests(&test_data_dir(), &["inline/ok"], "rast", |text, path| { let parse = try_parse(path.to_str().unwrap(), text); let errors = parse.errors.as_slice(); - assert_errors_are_absent(errors, path); + assert_errors_are_absent(errors, path, &parse.root); format!("{:#?}", parse.root) }); @@ -163,11 +165,22 @@ fn assert_errors_are_present(errors: &[ParserError], path: &Path) { ); } -fn assert_errors_are_absent(errors: &[ParserError], path: &Path) { - assert!( - errors.is_empty(), - "There should be no errors in the file {:?} but the following errors were present: {:?}", +fn assert_errors_are_absent(errors: &[ParserError], path: &Path, syntax: &SyntaxNode) { + if errors.is_empty() { + return; + } + + let file = SimpleFile::new(path.to_str().unwrap().to_string(), syntax.to_string()); + let mut emitter = Emitter::new(&file); + let mut buffer = Buffer::no_color(); + + for diagnostic in errors { + emitter.emit_with_writer(diagnostic, &mut buffer).unwrap(); + } + + panic!("There should be no errors in the file {:?} but the following errors where present:\n{}\n\nParsed tree:\n{:#?}", path.display(), - errors + std::str::from_utf8(buffer.as_slice()).unwrap(), + syntax ); } diff --git a/crates/rslint_parser/test_data/inline/err/async_arrow_expr_await_parameter.rast b/crates/rslint_parser/test_data/inline/err/async_arrow_expr_await_parameter.rast index 188518f3d45..f83f19fb424 100644 --- a/crates/rslint_parser/test_data/inline/err/async_arrow_expr_await_parameter.rast +++ b/crates/rslint_parser/test_data/inline/err/async_arrow_expr_await_parameter.rast @@ -1,18 +1,20 @@ JS_MODULE@0..26 LIST@0..25 - VAR_DECL@0..13 - IDENT@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..13 - DECLARATOR@4..13 - SINGLE_PATTERN@4..5 - NAME@4..5 - IDENT@4..5 "a" - WHITESPACE@5..6 " " - EQ@6..7 "=" - WHITESPACE@7..8 " " - NAME_REF@8..13 - IDENT@8..13 "async" + JS_VARIABLE_DECLARATION_STATEMENT@0..13 + JS_VARIABLE_DECLARATION@0..13 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..13 + JS_VARIABLE_DECLARATOR@4..13 + SINGLE_PATTERN@4..5 + NAME@4..5 + IDENT@4..5 "a" + WHITESPACE@5..6 " " + JS_EQUAL_VALUE_CLAUSE@6..13 + EQ@6..7 "=" + WHITESPACE@7..8 " " + NAME_REF@8..13 + IDENT@8..13 "async" WHITESPACE@13..14 " " JS_EXPRESSION_STATEMENT@14..25 ARROW_EXPR@14..25 diff --git a/crates/rslint_parser/test_data/inline/err/binding_identifier_invalid.rast b/crates/rslint_parser/test_data/inline/err/binding_identifier_invalid.rast index 368b21a4e2e..1e6df889022 100644 --- a/crates/rslint_parser/test_data/inline/err/binding_identifier_invalid.rast +++ b/crates/rslint_parser/test_data/inline/err/binding_identifier_invalid.rast @@ -15,19 +15,21 @@ JS_MODULE@0..83 L_CURLY@12..13 "{" WHITESPACE@13..14 " " LIST@14..28 - VAR_DECL@14..28 - IDENT@14..17 "let" - WHITESPACE@17..18 " " - LIST@18..27 - DECLARATOR@18..27 - SINGLE_PATTERN@18..23 - NAME@18..23 - IDENT@18..23 "await" - WHITESPACE@23..24 " " - EQ@24..25 "=" - WHITESPACE@25..26 " " - LITERAL@26..27 - NUMBER@26..27 "5" + JS_VARIABLE_DECLARATION_STATEMENT@14..28 + JS_VARIABLE_DECLARATION@14..27 + LET_KW@14..17 "let" + WHITESPACE@17..18 " " + LIST@18..27 + JS_VARIABLE_DECLARATOR@18..27 + SINGLE_PATTERN@18..23 + NAME@18..23 + IDENT@18..23 "await" + WHITESPACE@23..24 " " + JS_EQUAL_VALUE_CLAUSE@24..27 + EQ@24..25 "=" + WHITESPACE@25..26 " " + LITERAL@26..27 + NUMBER@26..27 "5" SEMICOLON@27..28 ";" WHITESPACE@28..29 " " R_CURLY@29..30 "}" @@ -47,36 +49,40 @@ JS_MODULE@0..83 L_CURLY@47..48 "{" WHITESPACE@48..52 "\n " LIST@52..66 - VAR_DECL@52..66 - IDENT@52..55 "let" - WHITESPACE@55..56 " " - LIST@56..65 - DECLARATOR@56..65 - SINGLE_PATTERN@56..61 - NAME@56..61 - IDENT@56..61 "yield" - WHITESPACE@61..62 " " - EQ@62..63 "=" - WHITESPACE@63..64 " " - LITERAL@64..65 - NUMBER@64..65 "5" + JS_VARIABLE_DECLARATION_STATEMENT@52..66 + JS_VARIABLE_DECLARATION@52..65 + LET_KW@52..55 "let" + WHITESPACE@55..56 " " + LIST@56..65 + JS_VARIABLE_DECLARATOR@56..65 + SINGLE_PATTERN@56..61 + NAME@56..61 + IDENT@56..61 "yield" + WHITESPACE@61..62 " " + JS_EQUAL_VALUE_CLAUSE@62..65 + EQ@62..63 "=" + WHITESPACE@63..64 " " + LITERAL@64..65 + NUMBER@64..65 "5" SEMICOLON@65..66 ";" WHITESPACE@66..67 "\n" R_CURLY@67..68 "}" WHITESPACE@68..69 "\n" - VAR_DECL@69..82 - IDENT@69..72 "let" - WHITESPACE@72..73 " " - LIST@73..81 - DECLARATOR@73..81 - SINGLE_PATTERN@73..77 - NAME@73..77 - IDENT@73..77 "eval" - WHITESPACE@77..78 " " - EQ@78..79 "=" - WHITESPACE@79..80 " " - LITERAL@80..81 - NUMBER@80..81 "5" + JS_VARIABLE_DECLARATION_STATEMENT@69..82 + JS_VARIABLE_DECLARATION@69..81 + LET_KW@69..72 "let" + WHITESPACE@72..73 " " + LIST@73..81 + JS_VARIABLE_DECLARATOR@73..81 + SINGLE_PATTERN@73..77 + NAME@73..77 + IDENT@73..77 "eval" + WHITESPACE@77..78 " " + JS_EQUAL_VALUE_CLAUSE@78..81 + EQ@78..79 "=" + WHITESPACE@79..80 " " + LITERAL@80..81 + NUMBER@80..81 "5" SEMICOLON@81..82 ";" WHITESPACE@82..83 "\n" -- diff --git a/crates/rslint_parser/test_data/inline/err/for_stmt_err.rast b/crates/rslint_parser/test_data/inline/err/for_stmt_err.rast index d22393f6d35..4f63a9e05af 100644 --- a/crates/rslint_parser/test_data/inline/err/for_stmt_err.rast +++ b/crates/rslint_parser/test_data/inline/err/for_stmt_err.rast @@ -16,19 +16,20 @@ JS_MODULE@0..40 FOR_KW@10..13 "for" WHITESPACE@13..14 " " FOR_STMT_INIT@14..23 - VAR_DECL@14..23 - IDENT@14..17 "let" + JS_VARIABLE_DECLARATION@14..23 + LET_KW@14..17 "let" WHITESPACE@17..18 " " LIST@18..23 - DECLARATOR@18..23 + JS_VARIABLE_DECLARATOR@18..23 SINGLE_PATTERN@18..19 NAME@18..19 IDENT@18..19 "i" WHITESPACE@19..20 " " - EQ@20..21 "=" - WHITESPACE@21..22 " " - LITERAL@22..23 - NUMBER@22..23 "5" + JS_EQUAL_VALUE_CLAUSE@20..23 + EQ@20..21 "=" + WHITESPACE@21..22 " " + LITERAL@22..23 + NUMBER@22..23 "5" SEMICOLON@23..24 ";" WHITESPACE@24..25 " " FOR_STMT_TEST@25..31 diff --git a/crates/rslint_parser/test_data/inline/err/import_call_no_arg.rast b/crates/rslint_parser/test_data/inline/err/import_call_no_arg.rast index 244e3fff044..8a73c68686f 100644 --- a/crates/rslint_parser/test_data/inline/err/import_call_no_arg.rast +++ b/crates/rslint_parser/test_data/inline/err/import_call_no_arg.rast @@ -1,20 +1,22 @@ JS_MODULE@0..25 LIST@0..24 - VAR_DECL@0..17 - IDENT@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..16 - DECLARATOR@4..16 - SINGLE_PATTERN@4..5 - NAME@4..5 - IDENT@4..5 "a" - WHITESPACE@5..6 " " - EQ@6..7 "=" - WHITESPACE@7..8 " " - IMPORT_CALL@8..16 - IMPORT_KW@8..14 "import" - L_PAREN@14..15 "(" - R_PAREN@15..16 ")" + JS_VARIABLE_DECLARATION_STATEMENT@0..17 + JS_VARIABLE_DECLARATION@0..16 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..16 + JS_VARIABLE_DECLARATOR@4..16 + SINGLE_PATTERN@4..5 + NAME@4..5 + IDENT@4..5 "a" + WHITESPACE@5..6 " " + JS_EQUAL_VALUE_CLAUSE@6..16 + EQ@6..7 "=" + WHITESPACE@7..8 " " + IMPORT_CALL@8..16 + IMPORT_KW@8..14 "import" + L_PAREN@14..15 "(" + R_PAREN@15..16 ")" SEMICOLON@16..17 ";" WHITESPACE@17..18 "\n" JS_EXPRESSION_STATEMENT@18..24 diff --git a/crates/rslint_parser/test_data/inline/err/invalid_arg_list.rast b/crates/rslint_parser/test_data/inline/err/invalid_arg_list.rast index d2dcd11c18a..8a1b63286e7 100644 --- a/crates/rslint_parser/test_data/inline/err/invalid_arg_list.rast +++ b/crates/rslint_parser/test_data/inline/err/invalid_arg_list.rast @@ -27,11 +27,12 @@ JS_MODULE@0..21 NAME_REF@15..16 IDENT@15..16 "b" WHITESPACE@16..17 " " - VAR_DECL@17..21 - VAR_KW@17..20 "var" - WHITESPACE@20..21 "\n" - LIST@21..21 - ERROR@21..21 + JS_VARIABLE_DECLARATION_STATEMENT@17..21 + JS_VARIABLE_DECLARATION@17..21 + VAR_KW@17..20 "var" + WHITESPACE@20..21 "\n" + LIST@21..21 + ERROR@21..21 -- error[SyntaxError]: expected `')'` but instead found `;` ┌─ invalid_arg_list.js:1:8 diff --git a/crates/rslint_parser/test_data/inline/err/invalid_method_recover.rast b/crates/rslint_parser/test_data/inline/err/invalid_method_recover.rast index 71c50706280..3557b452b8a 100644 --- a/crates/rslint_parser/test_data/inline/err/invalid_method_recover.rast +++ b/crates/rslint_parser/test_data/inline/err/invalid_method_recover.rast @@ -34,17 +34,19 @@ JS_MODULE@0..48 L_CURLY@26..27 "{" WHITESPACE@27..32 "\n " LIST@32..39 - VAR_DECL@32..39 - IDENT@32..35 "let" - WHITESPACE@35..36 " " - LIST@36..39 - DECLARATOR@36..39 - SINGLE_PATTERN@36..37 - NAME@36..37 - IDENT@36..37 "a" - EQ@37..38 "=" - ERROR@38..39 - SEMICOLON@38..39 ";" + JS_VARIABLE_DECLARATION_STATEMENT@32..39 + JS_VARIABLE_DECLARATION@32..39 + LET_KW@32..35 "let" + WHITESPACE@35..36 " " + LIST@36..39 + JS_VARIABLE_DECLARATOR@36..39 + SINGLE_PATTERN@36..37 + NAME@36..37 + IDENT@36..37 "a" + JS_EQUAL_VALUE_CLAUSE@37..39 + EQ@37..38 "=" + ERROR@38..39 + SEMICOLON@38..39 ";" WHITESPACE@39..42 "\n " R_CURLY@42..43 "}" SEMICOLON@43..44 ";" diff --git a/crates/rslint_parser/test_data/inline/err/object_expr_error_prop_name.rast b/crates/rslint_parser/test_data/inline/err/object_expr_error_prop_name.rast index d3fb45b6d9b..1a4e3364f62 100644 --- a/crates/rslint_parser/test_data/inline/err/object_expr_error_prop_name.rast +++ b/crates/rslint_parser/test_data/inline/err/object_expr_error_prop_name.rast @@ -1,47 +1,51 @@ JS_MODULE@0..40 LIST@0..39 - VAR_DECL@0..26 - IDENT@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..26 - DECLARATOR@4..26 - SINGLE_PATTERN@4..5 - NAME@4..5 - IDENT@4..5 "a" - WHITESPACE@5..6 " " - EQ@6..7 "=" - WHITESPACE@7..8 " " - OBJECT_EXPR@8..26 - L_CURLY@8..9 "{" - WHITESPACE@9..10 " " - LIST@10..24 - LITERAL_PROP@10..24 - ERROR@10..17 - REGEX@10..17 "/: 6, /" - COLON@17..18 ":" - WHITESPACE@18..19 " " - LITERAL@19..24 - REGEX@19..24 "/foo/" - WHITESPACE@24..25 " " - R_CURLY@25..26 "}" + JS_VARIABLE_DECLARATION_STATEMENT@0..26 + JS_VARIABLE_DECLARATION@0..26 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..26 + JS_VARIABLE_DECLARATOR@4..26 + SINGLE_PATTERN@4..5 + NAME@4..5 + IDENT@4..5 "a" + WHITESPACE@5..6 " " + JS_EQUAL_VALUE_CLAUSE@6..26 + EQ@6..7 "=" + WHITESPACE@7..8 " " + OBJECT_EXPR@8..26 + L_CURLY@8..9 "{" + WHITESPACE@9..10 " " + LIST@10..24 + LITERAL_PROP@10..24 + ERROR@10..17 + REGEX@10..17 "/: 6, /" + COLON@17..18 ":" + WHITESPACE@18..19 " " + LITERAL@19..24 + REGEX@19..24 "/foo/" + WHITESPACE@24..25 " " + R_CURLY@25..26 "}" WHITESPACE@26..27 "\n" - VAR_DECL@27..38 - IDENT@27..30 "let" - WHITESPACE@30..31 " " - LIST@31..38 - DECLARATOR@31..38 - SINGLE_PATTERN@31..32 - NAME@31..32 - IDENT@31..32 "a" - WHITESPACE@32..33 " " - EQ@33..34 "=" - WHITESPACE@34..35 " " - OBJECT_EXPR@35..38 - L_CURLY@35..36 "{" - LIST@36..37 - ERROR@36..37 - L_CURLY@36..37 "{" - R_CURLY@37..38 "}" + JS_VARIABLE_DECLARATION_STATEMENT@27..38 + JS_VARIABLE_DECLARATION@27..38 + LET_KW@27..30 "let" + WHITESPACE@30..31 " " + LIST@31..38 + JS_VARIABLE_DECLARATOR@31..38 + SINGLE_PATTERN@31..32 + NAME@31..32 + IDENT@31..32 "a" + WHITESPACE@32..33 " " + JS_EQUAL_VALUE_CLAUSE@33..38 + EQ@33..34 "=" + WHITESPACE@34..35 " " + OBJECT_EXPR@35..38 + L_CURLY@35..36 "{" + LIST@36..37 + ERROR@36..37 + L_CURLY@36..37 "{" + R_CURLY@37..38 "}" ERROR@38..39 R_CURLY@38..39 "}" WHITESPACE@39..40 "\n" diff --git a/crates/rslint_parser/test_data/inline/err/object_expr_non_ident_literal_prop.rast b/crates/rslint_parser/test_data/inline/err/object_expr_non_ident_literal_prop.rast index e86ae7a8ab1..8be2bc12065 100644 --- a/crates/rslint_parser/test_data/inline/err/object_expr_non_ident_literal_prop.rast +++ b/crates/rslint_parser/test_data/inline/err/object_expr_non_ident_literal_prop.rast @@ -1,23 +1,25 @@ JS_MODULE@0..12 LIST@0..11 - VAR_DECL@0..11 - IDENT@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..11 - DECLARATOR@4..11 - SINGLE_PATTERN@4..5 - NAME@4..5 - IDENT@4..5 "b" - WHITESPACE@5..6 " " - EQ@6..7 "=" - WHITESPACE@7..8 " " - OBJECT_EXPR@8..11 - L_CURLY@8..9 "{" - LIST@9..10 - LITERAL_PROP@9..10 - LITERAL@9..10 - NUMBER@9..10 "5" - R_CURLY@10..11 "}" + JS_VARIABLE_DECLARATION_STATEMENT@0..11 + JS_VARIABLE_DECLARATION@0..11 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..11 + JS_VARIABLE_DECLARATOR@4..11 + SINGLE_PATTERN@4..5 + NAME@4..5 + IDENT@4..5 "b" + WHITESPACE@5..6 " " + JS_EQUAL_VALUE_CLAUSE@6..11 + EQ@6..7 "=" + WHITESPACE@7..8 " " + OBJECT_EXPR@8..11 + L_CURLY@8..9 "{" + LIST@9..10 + LITERAL_PROP@9..10 + LITERAL@9..10 + NUMBER@9..10 "5" + R_CURLY@10..11 "}" WHITESPACE@11..12 "\n" -- error[SyntaxError]: expected `:` but instead found `}` diff --git a/crates/rslint_parser/test_data/inline/err/primary_expr_invalid_recovery.rast b/crates/rslint_parser/test_data/inline/err/primary_expr_invalid_recovery.rast index 706933fe718..0f85fa8a45d 100644 --- a/crates/rslint_parser/test_data/inline/err/primary_expr_invalid_recovery.rast +++ b/crates/rslint_parser/test_data/inline/err/primary_expr_invalid_recovery.rast @@ -1,18 +1,20 @@ JS_MODULE@0..18 LIST@0..17 - VAR_DECL@0..10 - IDENT@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..9 - DECLARATOR@4..9 - SINGLE_PATTERN@4..5 - NAME@4..5 - IDENT@4..5 "a" - WHITESPACE@5..6 " " - EQ@6..7 "=" - WHITESPACE@7..8 " " - ERROR@8..9 - ERROR_TOKEN@8..9 "\\" + JS_VARIABLE_DECLARATION_STATEMENT@0..10 + JS_VARIABLE_DECLARATION@0..9 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..9 + JS_VARIABLE_DECLARATOR@4..9 + SINGLE_PATTERN@4..5 + NAME@4..5 + IDENT@4..5 "a" + WHITESPACE@5..6 " " + JS_EQUAL_VALUE_CLAUSE@6..9 + EQ@6..7 "=" + WHITESPACE@7..8 " " + ERROR@8..9 + ERROR_TOKEN@8..9 "\\" SEMICOLON@9..10 ";" WHITESPACE@10..11 " " JS_EXPRESSION_STATEMENT@11..17 diff --git a/crates/rslint_parser/test_data/inline/err/semicolons_err.rast b/crates/rslint_parser/test_data/inline/err/semicolons_err.rast index e476484188b..431d15dfd0d 100644 --- a/crates/rslint_parser/test_data/inline/err/semicolons_err.rast +++ b/crates/rslint_parser/test_data/inline/err/semicolons_err.rast @@ -1,18 +1,20 @@ JS_MODULE@0..24 LIST@0..23 - VAR_DECL@0..13 - IDENT@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..13 - DECLARATOR@4..13 - SINGLE_PATTERN@4..7 - NAME@4..7 - IDENT@4..7 "foo" - WHITESPACE@7..8 " " - EQ@8..9 "=" - WHITESPACE@9..10 " " - NAME_REF@10..13 - IDENT@10..13 "bar" + JS_VARIABLE_DECLARATION_STATEMENT@0..13 + JS_VARIABLE_DECLARATION@0..13 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..13 + JS_VARIABLE_DECLARATOR@4..13 + SINGLE_PATTERN@4..7 + NAME@4..7 + IDENT@4..7 "foo" + WHITESPACE@7..8 " " + JS_EQUAL_VALUE_CLAUSE@8..13 + EQ@8..9 "=" + WHITESPACE@9..10 " " + NAME_REF@10..13 + IDENT@10..13 "bar" WHITESPACE@13..14 " " JS_THROW_STATEMENT@14..23 THROW_KW@14..19 "throw" diff --git a/crates/rslint_parser/test_data/inline/err/template_literal_unterminated.rast b/crates/rslint_parser/test_data/inline/err/template_literal_unterminated.rast index d1caf47db70..f4581620e84 100644 --- a/crates/rslint_parser/test_data/inline/err/template_literal_unterminated.rast +++ b/crates/rslint_parser/test_data/inline/err/template_literal_unterminated.rast @@ -1,25 +1,27 @@ JS_MODULE@0..20 LIST@0..20 - VAR_DECL@0..20 - IDENT@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..20 - DECLARATOR@4..20 - SINGLE_PATTERN@4..5 - NAME@4..5 - IDENT@4..5 "a" - WHITESPACE@5..6 " " - EQ@6..7 "=" - WHITESPACE@7..8 " " - TEMPLATE@8..20 - BACKTICK@8..9 "`" - LIST@9..20 - TEMPLATE_ELEMENT@9..15 - DOLLARCURLY@9..11 "${" - NAME_REF@11..14 - IDENT@11..14 "foo" - R_CURLY@14..15 "}" - TEMPLATE_CHUNK@15..20 " bar\n" + JS_VARIABLE_DECLARATION_STATEMENT@0..20 + JS_VARIABLE_DECLARATION@0..20 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..20 + JS_VARIABLE_DECLARATOR@4..20 + SINGLE_PATTERN@4..5 + NAME@4..5 + IDENT@4..5 "a" + WHITESPACE@5..6 " " + JS_EQUAL_VALUE_CLAUSE@6..20 + EQ@6..7 "=" + WHITESPACE@7..8 " " + TEMPLATE@8..20 + BACKTICK@8..9 "`" + LIST@9..20 + TEMPLATE_ELEMENT@9..15 + DOLLARCURLY@9..11 "${" + NAME_REF@11..14 + IDENT@11..14 "foo" + R_CURLY@14..15 "}" + TEMPLATE_CHUNK@15..20 " bar\n" -- error: unterminated template literal ┌─ template_literal_unterminated.js:2:1 diff --git a/crates/rslint_parser/test_data/inline/err/unterminated_unicode_codepoint.rast b/crates/rslint_parser/test_data/inline/err/unterminated_unicode_codepoint.rast index 764be11f5a6..0750794cf43 100644 --- a/crates/rslint_parser/test_data/inline/err/unterminated_unicode_codepoint.rast +++ b/crates/rslint_parser/test_data/inline/err/unterminated_unicode_codepoint.rast @@ -1,18 +1,20 @@ JS_MODULE@0..18 LIST@0..17 - VAR_DECL@0..17 - IDENT@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..16 - DECLARATOR@4..16 - SINGLE_PATTERN@4..5 - NAME@4..5 - IDENT@4..5 "s" - WHITESPACE@5..6 " " - EQ@6..7 "=" - WHITESPACE@7..8 " " - ERROR@8..16 - ERROR_TOKEN@8..16 "\"\\u{200\"" + JS_VARIABLE_DECLARATION_STATEMENT@0..17 + JS_VARIABLE_DECLARATION@0..16 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..16 + JS_VARIABLE_DECLARATOR@4..16 + SINGLE_PATTERN@4..5 + NAME@4..5 + IDENT@4..5 "s" + WHITESPACE@5..6 " " + JS_EQUAL_VALUE_CLAUSE@6..16 + EQ@6..7 "=" + WHITESPACE@7..8 " " + ERROR@8..16 + ERROR_TOKEN@8..16 "\"\\u{200\"" SEMICOLON@16..17 ";" WHITESPACE@17..18 "\n" -- diff --git a/crates/rslint_parser/test_data/inline/err/var_decl_err.rast b/crates/rslint_parser/test_data/inline/err/var_decl_err.rast index d2da2acea09..69ba22969a7 100644 --- a/crates/rslint_parser/test_data/inline/err/var_decl_err.rast +++ b/crates/rslint_parser/test_data/inline/err/var_decl_err.rast @@ -1,45 +1,51 @@ JS_MODULE@0..32 LIST@0..31 - VAR_DECL@0..8 - VAR_KW@0..3 "var" - WHITESPACE@3..4 " " - LIST@4..8 - DECLARATOR@4..8 - SINGLE_PATTERN@4..5 - NAME@4..5 - IDENT@4..5 "a" - WHITESPACE@5..6 " " - EQ@6..7 "=" - ERROR@7..8 - SEMICOLON@7..8 ";" + JS_VARIABLE_DECLARATION_STATEMENT@0..8 + JS_VARIABLE_DECLARATION@0..8 + VAR_KW@0..3 "var" + WHITESPACE@3..4 " " + LIST@4..8 + JS_VARIABLE_DECLARATOR@4..8 + SINGLE_PATTERN@4..5 + NAME@4..5 + IDENT@4..5 "a" + WHITESPACE@5..6 " " + JS_EQUAL_VALUE_CLAUSE@6..8 + EQ@6..7 "=" + ERROR@7..8 + SEMICOLON@7..8 ";" WHITESPACE@8..9 "\n" - VAR_DECL@9..20 - CONST_KW@9..14 "const" - WHITESPACE@14..15 " " - LIST@15..20 - DECLARATOR@15..20 - SINGLE_PATTERN@15..16 - NAME@15..16 - IDENT@15..16 "a" - WHITESPACE@16..17 " " - EQ@17..18 "=" - WHITESPACE@18..19 " " - LITERAL@19..20 - NUMBER@19..20 "5" + JS_VARIABLE_DECLARATION_STATEMENT@9..20 + JS_VARIABLE_DECLARATION@9..20 + CONST_KW@9..14 "const" + WHITESPACE@14..15 " " + LIST@15..20 + JS_VARIABLE_DECLARATOR@15..20 + SINGLE_PATTERN@15..16 + NAME@15..16 + IDENT@15..16 "a" + WHITESPACE@16..17 " " + JS_EQUAL_VALUE_CLAUSE@17..20 + EQ@17..18 "=" + WHITESPACE@18..19 " " + LITERAL@19..20 + NUMBER@19..20 "5" WHITESPACE@20..21 " " - VAR_DECL@21..31 - IDENT@21..24 "let" - WHITESPACE@24..25 " " - LIST@25..30 - DECLARATOR@25..30 - SINGLE_PATTERN@25..26 - NAME@25..26 - IDENT@25..26 "b" - WHITESPACE@26..27 " " - EQ@27..28 "=" - WHITESPACE@28..29 " " - LITERAL@29..30 - NUMBER@29..30 "5" + JS_VARIABLE_DECLARATION_STATEMENT@21..31 + JS_VARIABLE_DECLARATION@21..30 + LET_KW@21..24 "let" + WHITESPACE@24..25 " " + LIST@25..30 + JS_VARIABLE_DECLARATOR@25..30 + SINGLE_PATTERN@25..26 + NAME@25..26 + IDENT@25..26 "b" + WHITESPACE@26..27 " " + JS_EQUAL_VALUE_CLAUSE@27..30 + EQ@27..28 "=" + WHITESPACE@28..29 " " + LITERAL@29..30 + NUMBER@29..30 "5" SEMICOLON@30..31 ";" WHITESPACE@31..32 "\n" -- diff --git a/crates/rslint_parser/test_data/inline/ok/async_arrow_expr.rast b/crates/rslint_parser/test_data/inline/ok/async_arrow_expr.rast index 6f049a57348..a2cc1b81a0a 100644 --- a/crates/rslint_parser/test_data/inline/ok/async_arrow_expr.rast +++ b/crates/rslint_parser/test_data/inline/ok/async_arrow_expr.rast @@ -1,57 +1,61 @@ JS_MODULE@0..82 LIST@0..81 - VAR_DECL@0..23 - IDENT@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..23 - DECLARATOR@4..23 - SINGLE_PATTERN@4..5 - NAME@4..5 - IDENT@4..5 "a" - WHITESPACE@5..6 " " - EQ@6..7 "=" - WHITESPACE@7..8 " " - ARROW_EXPR@8..23 - ASYNC_KW@8..13 "async" - WHITESPACE@13..14 " " - NAME@14..17 - IDENT@14..17 "foo" - WHITESPACE@17..18 " " - FAT_ARROW@18..20 "=>" - WHITESPACE@20..21 " " - JS_BLOCK_STATEMENT@21..23 - L_CURLY@21..22 "{" - LIST@22..22 - R_CURLY@22..23 "}" + JS_VARIABLE_DECLARATION_STATEMENT@0..23 + JS_VARIABLE_DECLARATION@0..23 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..23 + JS_VARIABLE_DECLARATOR@4..23 + SINGLE_PATTERN@4..5 + NAME@4..5 + IDENT@4..5 "a" + WHITESPACE@5..6 " " + JS_EQUAL_VALUE_CLAUSE@6..23 + EQ@6..7 "=" + WHITESPACE@7..8 " " + ARROW_EXPR@8..23 + ASYNC_KW@8..13 "async" + WHITESPACE@13..14 " " + NAME@14..17 + IDENT@14..17 "foo" + WHITESPACE@17..18 " " + FAT_ARROW@18..20 "=>" + WHITESPACE@20..21 " " + JS_BLOCK_STATEMENT@21..23 + L_CURLY@21..22 "{" + LIST@22..22 + R_CURLY@22..23 "}" WHITESPACE@23..24 "\n" - VAR_DECL@24..49 - IDENT@24..27 "let" - WHITESPACE@27..28 " " - LIST@28..49 - DECLARATOR@28..49 - SINGLE_PATTERN@28..29 - NAME@28..29 - IDENT@28..29 "b" - WHITESPACE@29..30 " " - EQ@30..31 "=" - WHITESPACE@31..32 " " - ARROW_EXPR@32..49 - ASYNC_KW@32..37 "async" - WHITESPACE@37..38 " " - PARAMETER_LIST@38..43 - L_PAREN@38..39 "(" - LIST@39..42 - SINGLE_PATTERN@39..42 - NAME@39..42 - IDENT@39..42 "bar" - R_PAREN@42..43 ")" - WHITESPACE@43..44 " " - FAT_ARROW@44..46 "=>" - WHITESPACE@46..47 " " - JS_BLOCK_STATEMENT@47..49 - L_CURLY@47..48 "{" - LIST@48..48 - R_CURLY@48..49 "}" + JS_VARIABLE_DECLARATION_STATEMENT@24..49 + JS_VARIABLE_DECLARATION@24..49 + LET_KW@24..27 "let" + WHITESPACE@27..28 " " + LIST@28..49 + JS_VARIABLE_DECLARATOR@28..49 + SINGLE_PATTERN@28..29 + NAME@28..29 + IDENT@28..29 "b" + WHITESPACE@29..30 " " + JS_EQUAL_VALUE_CLAUSE@30..49 + EQ@30..31 "=" + WHITESPACE@31..32 " " + ARROW_EXPR@32..49 + ASYNC_KW@32..37 "async" + WHITESPACE@37..38 " " + PARAMETER_LIST@38..43 + L_PAREN@38..39 "(" + LIST@39..42 + SINGLE_PATTERN@39..42 + NAME@39..42 + IDENT@39..42 "bar" + R_PAREN@42..43 ")" + WHITESPACE@43..44 " " + FAT_ARROW@44..46 "=>" + WHITESPACE@46..47 " " + JS_BLOCK_STATEMENT@47..49 + L_CURLY@47..48 "{" + LIST@48..48 + R_CURLY@48..49 "}" WHITESPACE@49..50 "\n" JS_EXPRESSION_STATEMENT@50..81 ARROW_EXPR@50..81 diff --git a/crates/rslint_parser/test_data/inline/ok/async_function_expr.rast b/crates/rslint_parser/test_data/inline/ok/async_function_expr.rast index 3f788aefc67..c1dc71aecf3 100644 --- a/crates/rslint_parser/test_data/inline/ok/async_function_expr.rast +++ b/crates/rslint_parser/test_data/inline/ok/async_function_expr.rast @@ -1,57 +1,61 @@ JS_MODULE@0..62 LIST@0..61 - VAR_DECL@0..28 - IDENT@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..27 - DECLARATOR@4..27 - SINGLE_PATTERN@4..5 - NAME@4..5 - IDENT@4..5 "a" - WHITESPACE@5..6 " " - EQ@6..7 "=" - WHITESPACE@7..8 " " - FN_EXPR@8..27 - ASYNC_KW@8..13 "async" - WHITESPACE@13..14 " " - FUNCTION_KW@14..22 "function" - PARAMETER_LIST@22..24 - L_PAREN@22..23 "(" - LIST@23..23 - R_PAREN@23..24 ")" - WHITESPACE@24..25 " " - JS_BLOCK_STATEMENT@25..27 - L_CURLY@25..26 "{" - LIST@26..26 - R_CURLY@26..27 "}" + JS_VARIABLE_DECLARATION_STATEMENT@0..28 + JS_VARIABLE_DECLARATION@0..27 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..27 + JS_VARIABLE_DECLARATOR@4..27 + SINGLE_PATTERN@4..5 + NAME@4..5 + IDENT@4..5 "a" + WHITESPACE@5..6 " " + JS_EQUAL_VALUE_CLAUSE@6..27 + EQ@6..7 "=" + WHITESPACE@7..8 " " + FN_EXPR@8..27 + ASYNC_KW@8..13 "async" + WHITESPACE@13..14 " " + FUNCTION_KW@14..22 "function" + PARAMETER_LIST@22..24 + L_PAREN@22..23 "(" + LIST@23..23 + R_PAREN@23..24 ")" + WHITESPACE@24..25 " " + JS_BLOCK_STATEMENT@25..27 + L_CURLY@25..26 "{" + LIST@26..26 + R_CURLY@26..27 "}" SEMICOLON@27..28 ";" WHITESPACE@28..29 "\n" - VAR_DECL@29..61 - IDENT@29..32 "let" - WHITESPACE@32..33 " " - LIST@33..60 - DECLARATOR@33..60 - SINGLE_PATTERN@33..34 - NAME@33..34 - IDENT@33..34 "b" - WHITESPACE@34..35 " " - EQ@35..36 "=" - WHITESPACE@36..37 " " - FN_EXPR@37..60 - ASYNC_KW@37..42 "async" - WHITESPACE@42..43 " " - FUNCTION_KW@43..51 "function" - WHITESPACE@51..52 " " - NAME@52..55 - IDENT@52..55 "foo" - PARAMETER_LIST@55..57 - L_PAREN@55..56 "(" - LIST@56..56 - R_PAREN@56..57 ")" - WHITESPACE@57..58 " " - JS_BLOCK_STATEMENT@58..60 - L_CURLY@58..59 "{" - LIST@59..59 - R_CURLY@59..60 "}" + JS_VARIABLE_DECLARATION_STATEMENT@29..61 + JS_VARIABLE_DECLARATION@29..60 + LET_KW@29..32 "let" + WHITESPACE@32..33 " " + LIST@33..60 + JS_VARIABLE_DECLARATOR@33..60 + SINGLE_PATTERN@33..34 + NAME@33..34 + IDENT@33..34 "b" + WHITESPACE@34..35 " " + JS_EQUAL_VALUE_CLAUSE@35..60 + EQ@35..36 "=" + WHITESPACE@36..37 " " + FN_EXPR@37..60 + ASYNC_KW@37..42 "async" + WHITESPACE@42..43 " " + FUNCTION_KW@43..51 "function" + WHITESPACE@51..52 " " + NAME@52..55 + IDENT@52..55 "foo" + PARAMETER_LIST@55..57 + L_PAREN@55..56 "(" + LIST@56..56 + R_PAREN@56..57 ")" + WHITESPACE@57..58 " " + JS_BLOCK_STATEMENT@58..60 + L_CURLY@58..59 "{" + LIST@59..59 + R_CURLY@59..60 "}" SEMICOLON@60..61 ";" WHITESPACE@61..62 "\n" diff --git a/crates/rslint_parser/test_data/inline/ok/async_ident.rast b/crates/rslint_parser/test_data/inline/ok/async_ident.rast index 872cf8f1959..a6ea7af4df2 100644 --- a/crates/rslint_parser/test_data/inline/ok/async_ident.rast +++ b/crates/rslint_parser/test_data/inline/ok/async_ident.rast @@ -1,17 +1,19 @@ JS_MODULE@0..15 LIST@0..14 - VAR_DECL@0..14 - IDENT@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..13 - DECLARATOR@4..13 - SINGLE_PATTERN@4..5 - NAME@4..5 - IDENT@4..5 "a" - WHITESPACE@5..6 " " - EQ@6..7 "=" - WHITESPACE@7..8 " " - NAME_REF@8..13 - IDENT@8..13 "async" + JS_VARIABLE_DECLARATION_STATEMENT@0..14 + JS_VARIABLE_DECLARATION@0..13 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..13 + JS_VARIABLE_DECLARATOR@4..13 + SINGLE_PATTERN@4..5 + NAME@4..5 + IDENT@4..5 "a" + WHITESPACE@5..6 " " + JS_EQUAL_VALUE_CLAUSE@6..13 + EQ@6..7 "=" + WHITESPACE@7..8 " " + NAME_REF@8..13 + IDENT@8..13 "async" SEMICOLON@13..14 ";" WHITESPACE@14..15 "\n" diff --git a/crates/rslint_parser/test_data/inline/ok/class_expr.rast b/crates/rslint_parser/test_data/inline/ok/class_expr.rast index bdf3b802df2..4126526f068 100644 --- a/crates/rslint_parser/test_data/inline/ok/class_expr.rast +++ b/crates/rslint_parser/test_data/inline/ok/class_expr.rast @@ -1,60 +1,64 @@ JS_MODULE@0..72 LIST@0..71 - VAR_DECL@0..17 - IDENT@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..16 - DECLARATOR@4..16 - SINGLE_PATTERN@4..5 - NAME@4..5 - IDENT@4..5 "a" - WHITESPACE@5..6 " " - EQ@6..7 "=" - WHITESPACE@7..8 " " - CLASS_EXPR@8..16 - CLASS_KW@8..13 "class" - WHITESPACE@13..14 " " - CLASS_BODY@14..16 - L_CURLY@14..15 "{" - LIST@15..15 - R_CURLY@15..16 "}" + JS_VARIABLE_DECLARATION_STATEMENT@0..17 + JS_VARIABLE_DECLARATION@0..16 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..16 + JS_VARIABLE_DECLARATOR@4..16 + SINGLE_PATTERN@4..5 + NAME@4..5 + IDENT@4..5 "a" + WHITESPACE@5..6 " " + JS_EQUAL_VALUE_CLAUSE@6..16 + EQ@6..7 "=" + WHITESPACE@7..8 " " + CLASS_EXPR@8..16 + CLASS_KW@8..13 "class" + WHITESPACE@13..14 " " + CLASS_BODY@14..16 + L_CURLY@14..15 "{" + LIST@15..15 + R_CURLY@15..16 "}" SEMICOLON@16..17 ";" WHITESPACE@17..18 "\n" - VAR_DECL@18..57 - IDENT@18..21 "let" - WHITESPACE@21..22 " " - LIST@22..57 - DECLARATOR@22..57 - SINGLE_PATTERN@22..23 - NAME@22..23 - IDENT@22..23 "a" - WHITESPACE@23..24 " " - EQ@24..25 "=" - WHITESPACE@25..26 " " - CLASS_EXPR@26..57 - CLASS_KW@26..31 "class" - WHITESPACE@31..32 " " - NAME@32..35 - IDENT@32..35 "foo" - WHITESPACE@35..36 " " - CLASS_BODY@36..57 - L_CURLY@36..37 "{" - WHITESPACE@37..39 "\n " - LIST@39..55 - CONSTRUCTOR@39..55 - NAME@39..50 - IDENT@39..50 "constructor" - PARAMETER_LIST@50..52 - L_PAREN@50..51 "(" - LIST@51..51 - R_PAREN@51..52 ")" - WHITESPACE@52..53 " " - JS_BLOCK_STATEMENT@53..55 - L_CURLY@53..54 "{" - LIST@54..54 - R_CURLY@54..55 "}" - WHITESPACE@55..56 "\n" - R_CURLY@56..57 "}" + JS_VARIABLE_DECLARATION_STATEMENT@18..57 + JS_VARIABLE_DECLARATION@18..57 + LET_KW@18..21 "let" + WHITESPACE@21..22 " " + LIST@22..57 + JS_VARIABLE_DECLARATOR@22..57 + SINGLE_PATTERN@22..23 + NAME@22..23 + IDENT@22..23 "a" + WHITESPACE@23..24 " " + JS_EQUAL_VALUE_CLAUSE@24..57 + EQ@24..25 "=" + WHITESPACE@25..26 " " + CLASS_EXPR@26..57 + CLASS_KW@26..31 "class" + WHITESPACE@31..32 " " + NAME@32..35 + IDENT@32..35 "foo" + WHITESPACE@35..36 " " + CLASS_BODY@36..57 + L_CURLY@36..37 "{" + WHITESPACE@37..39 "\n " + LIST@39..55 + CONSTRUCTOR@39..55 + NAME@39..50 + IDENT@39..50 "constructor" + PARAMETER_LIST@50..52 + L_PAREN@50..51 "(" + LIST@51..51 + R_PAREN@51..52 ")" + WHITESPACE@52..53 " " + JS_BLOCK_STATEMENT@53..55 + L_CURLY@53..54 "{" + LIST@54..54 + R_CURLY@54..55 "}" + WHITESPACE@55..56 "\n" + R_CURLY@56..57 "}" WHITESPACE@57..58 "\n" JS_EXPRESSION_STATEMENT@58..71 BRACKET_EXPR@58..71 diff --git a/crates/rslint_parser/test_data/inline/ok/do_while_statement.rast b/crates/rslint_parser/test_data/inline/ok/do_while_statement.rast index 6458c44ad1a..0a4e3b02e07 100644 --- a/crates/rslint_parser/test_data/inline/ok/do_while_statement.rast +++ b/crates/rslint_parser/test_data/inline/ok/do_while_statement.rast @@ -57,19 +57,21 @@ JS_MODULE@0..144 R_PAREN@76..77 ")" SEMICOLON@77..78 ";" WHITESPACE@78..80 "\n\n" - VAR_DECL@80..90 - IDENT@80..83 "let" - WHITESPACE@83..84 " " - LIST@84..89 - DECLARATOR@84..89 - SINGLE_PATTERN@84..85 - NAME@84..85 - IDENT@84..85 "a" - WHITESPACE@85..86 " " - EQ@86..87 "=" - WHITESPACE@87..88 " " - LITERAL@88..89 - NUMBER@88..89 "1" + JS_VARIABLE_DECLARATION_STATEMENT@80..90 + JS_VARIABLE_DECLARATION@80..89 + LET_KW@80..83 "let" + WHITESPACE@83..84 " " + LIST@84..89 + JS_VARIABLE_DECLARATOR@84..89 + SINGLE_PATTERN@84..85 + NAME@84..85 + IDENT@84..85 "a" + WHITESPACE@85..86 " " + JS_EQUAL_VALUE_CLAUSE@86..89 + EQ@86..87 "=" + WHITESPACE@87..88 " " + LITERAL@88..89 + NUMBER@88..89 "1" SEMICOLON@89..90 ";" WHITESPACE@90..91 "\n" JS_DO_WHILE_STATEMENT@91..143 diff --git a/crates/rslint_parser/test_data/inline/ok/for_stmt.rast b/crates/rslint_parser/test_data/inline/ok/for_stmt.rast index 33d96ba6f8f..3450e7e81ae 100644 --- a/crates/rslint_parser/test_data/inline/ok/for_stmt.rast +++ b/crates/rslint_parser/test_data/inline/ok/for_stmt.rast @@ -5,19 +5,20 @@ JS_MODULE@0..95 WHITESPACE@3..4 " " L_PAREN@4..5 "(" FOR_STMT_INIT@5..14 - VAR_DECL@5..14 - IDENT@5..8 "let" + JS_VARIABLE_DECLARATION@5..14 + LET_KW@5..8 "let" WHITESPACE@8..9 " " LIST@9..14 - DECLARATOR@9..14 + JS_VARIABLE_DECLARATOR@9..14 SINGLE_PATTERN@9..10 NAME@9..10 IDENT@9..10 "i" WHITESPACE@10..11 " " - EQ@11..12 "=" - WHITESPACE@12..13 " " - LITERAL@13..14 - NUMBER@13..14 "5" + JS_EQUAL_VALUE_CLAUSE@11..14 + EQ@11..12 "=" + WHITESPACE@12..13 " " + LITERAL@13..14 + NUMBER@13..14 "5" SEMICOLON@14..15 ";" WHITESPACE@15..16 " " FOR_STMT_TEST@16..22 @@ -48,11 +49,11 @@ JS_MODULE@0..95 WHITESPACE@35..36 " " L_PAREN@36..37 "(" FOR_STMT_INIT@37..53 - VAR_DECL@37..53 - IDENT@37..40 "let" + JS_VARIABLE_DECLARATION@37..53 + LET_KW@37..40 "let" WHITESPACE@40..41 " " LIST@41..53 - DECLARATOR@41..53 + JS_VARIABLE_DECLARATOR@41..53 OBJECT_PATTERN@41..53 L_CURLY@41..42 "{" WHITESPACE@42..43 " " diff --git a/crates/rslint_parser/test_data/inline/ok/function_expr.rast b/crates/rslint_parser/test_data/inline/ok/function_expr.rast index 7be8b3eaf35..6033d85b6c2 100644 --- a/crates/rslint_parser/test_data/inline/ok/function_expr.rast +++ b/crates/rslint_parser/test_data/inline/ok/function_expr.rast @@ -1,51 +1,55 @@ JS_MODULE@0..48 LIST@0..47 - VAR_DECL@0..21 - IDENT@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..21 - DECLARATOR@4..21 - SINGLE_PATTERN@4..5 - NAME@4..5 - IDENT@4..5 "a" - WHITESPACE@5..6 " " - EQ@6..7 "=" - WHITESPACE@7..8 " " - FN_EXPR@8..21 - FUNCTION_KW@8..16 "function" - PARAMETER_LIST@16..18 - L_PAREN@16..17 "(" - LIST@17..17 - R_PAREN@17..18 ")" - WHITESPACE@18..19 " " - JS_BLOCK_STATEMENT@19..21 - L_CURLY@19..20 "{" - LIST@20..20 - R_CURLY@20..21 "}" + JS_VARIABLE_DECLARATION_STATEMENT@0..21 + JS_VARIABLE_DECLARATION@0..21 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..21 + JS_VARIABLE_DECLARATOR@4..21 + SINGLE_PATTERN@4..5 + NAME@4..5 + IDENT@4..5 "a" + WHITESPACE@5..6 " " + JS_EQUAL_VALUE_CLAUSE@6..21 + EQ@6..7 "=" + WHITESPACE@7..8 " " + FN_EXPR@8..21 + FUNCTION_KW@8..16 "function" + PARAMETER_LIST@16..18 + L_PAREN@16..17 "(" + LIST@17..17 + R_PAREN@17..18 ")" + WHITESPACE@18..19 " " + JS_BLOCK_STATEMENT@19..21 + L_CURLY@19..20 "{" + LIST@20..20 + R_CURLY@20..21 "}" WHITESPACE@21..22 "\n" - VAR_DECL@22..47 - IDENT@22..25 "let" - WHITESPACE@25..26 " " - LIST@26..47 - DECLARATOR@26..47 - SINGLE_PATTERN@26..27 - NAME@26..27 - IDENT@26..27 "b" - WHITESPACE@27..28 " " - EQ@28..29 "=" - WHITESPACE@29..30 " " - FN_EXPR@30..47 - FUNCTION_KW@30..38 "function" - WHITESPACE@38..39 " " - NAME@39..42 - IDENT@39..42 "foo" - PARAMETER_LIST@42..44 - L_PAREN@42..43 "(" - LIST@43..43 - R_PAREN@43..44 ")" - WHITESPACE@44..45 " " - JS_BLOCK_STATEMENT@45..47 - L_CURLY@45..46 "{" - LIST@46..46 - R_CURLY@46..47 "}" + JS_VARIABLE_DECLARATION_STATEMENT@22..47 + JS_VARIABLE_DECLARATION@22..47 + LET_KW@22..25 "let" + WHITESPACE@25..26 " " + LIST@26..47 + JS_VARIABLE_DECLARATOR@26..47 + SINGLE_PATTERN@26..27 + NAME@26..27 + IDENT@26..27 "b" + WHITESPACE@27..28 " " + JS_EQUAL_VALUE_CLAUSE@28..47 + EQ@28..29 "=" + WHITESPACE@29..30 " " + FN_EXPR@30..47 + FUNCTION_KW@30..38 "function" + WHITESPACE@38..39 " " + NAME@39..42 + IDENT@39..42 "foo" + PARAMETER_LIST@42..44 + L_PAREN@42..43 "(" + LIST@43..43 + R_PAREN@43..44 ")" + WHITESPACE@44..45 " " + JS_BLOCK_STATEMENT@45..47 + L_CURLY@45..46 "{" + LIST@46..46 + R_CURLY@46..47 "}" WHITESPACE@47..48 "\n" diff --git a/crates/rslint_parser/test_data/inline/ok/object_binding_prop.rast b/crates/rslint_parser/test_data/inline/ok/object_binding_prop.rast index 7d4d95afd6c..9ec77bc844e 100644 --- a/crates/rslint_parser/test_data/inline/ok/object_binding_prop.rast +++ b/crates/rslint_parser/test_data/inline/ok/object_binding_prop.rast @@ -1,67 +1,71 @@ JS_MODULE@0..59 LIST@0..58 - VAR_DECL@0..30 - IDENT@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..30 - DECLARATOR@4..30 - OBJECT_PATTERN@4..25 - L_CURLY@4..5 "{" - WHITESPACE@5..6 " " - LIST@6..23 - KEY_VALUE_PATTERN@6..18 - NAME@6..13 - IDENT@6..13 "default" - COLON@13..14 ":" - WHITESPACE@14..15 " " - SINGLE_PATTERN@15..18 - NAME@15..18 - IDENT@15..18 "foo" - COMMA@18..19 "," - WHITESPACE@19..20 " " - SINGLE_PATTERN@20..23 - NAME@20..23 - IDENT@20..23 "bar" - WHITESPACE@23..24 " " - R_CURLY@24..25 "}" - WHITESPACE@25..26 " " - EQ@26..27 "=" - WHITESPACE@27..28 " " - OBJECT_EXPR@28..30 - L_CURLY@28..29 "{" - LIST@29..29 - R_CURLY@29..30 "}" + JS_VARIABLE_DECLARATION_STATEMENT@0..30 + JS_VARIABLE_DECLARATION@0..30 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..30 + JS_VARIABLE_DECLARATOR@4..30 + OBJECT_PATTERN@4..25 + L_CURLY@4..5 "{" + WHITESPACE@5..6 " " + LIST@6..23 + KEY_VALUE_PATTERN@6..18 + NAME@6..13 + IDENT@6..13 "default" + COLON@13..14 ":" + WHITESPACE@14..15 " " + SINGLE_PATTERN@15..18 + NAME@15..18 + IDENT@15..18 "foo" + COMMA@18..19 "," + WHITESPACE@19..20 " " + SINGLE_PATTERN@20..23 + NAME@20..23 + IDENT@20..23 "bar" + WHITESPACE@23..24 " " + R_CURLY@24..25 "}" + WHITESPACE@25..26 " " + JS_EQUAL_VALUE_CLAUSE@26..30 + EQ@26..27 "=" + WHITESPACE@27..28 " " + OBJECT_EXPR@28..30 + L_CURLY@28..29 "{" + LIST@29..29 + R_CURLY@29..30 "}" WHITESPACE@30..31 "\n" - VAR_DECL@31..58 - IDENT@31..34 "let" - WHITESPACE@34..35 " " - LIST@35..58 - DECLARATOR@35..58 - OBJECT_PATTERN@35..53 - L_CURLY@35..36 "{" - WHITESPACE@36..37 " " - LIST@37..51 - ASSIGN_PATTERN@37..46 - SINGLE_PATTERN@37..40 - NAME@37..40 - IDENT@37..40 "foo" - WHITESPACE@40..41 " " - EQ@41..42 "=" - WHITESPACE@42..43 " " - NAME_REF@43..46 - IDENT@43..46 "bar" - COMMA@46..47 "," - WHITESPACE@47..48 " " - SINGLE_PATTERN@48..51 - NAME@48..51 - IDENT@48..51 "baz" - WHITESPACE@51..52 " " - R_CURLY@52..53 "}" - WHITESPACE@53..54 " " - EQ@54..55 "=" - WHITESPACE@55..56 " " - OBJECT_EXPR@56..58 - L_CURLY@56..57 "{" - LIST@57..57 - R_CURLY@57..58 "}" + JS_VARIABLE_DECLARATION_STATEMENT@31..58 + JS_VARIABLE_DECLARATION@31..58 + LET_KW@31..34 "let" + WHITESPACE@34..35 " " + LIST@35..58 + JS_VARIABLE_DECLARATOR@35..58 + OBJECT_PATTERN@35..53 + L_CURLY@35..36 "{" + WHITESPACE@36..37 " " + LIST@37..51 + ASSIGN_PATTERN@37..46 + SINGLE_PATTERN@37..40 + NAME@37..40 + IDENT@37..40 "foo" + WHITESPACE@40..41 " " + EQ@41..42 "=" + WHITESPACE@42..43 " " + NAME_REF@43..46 + IDENT@43..46 "bar" + COMMA@46..47 "," + WHITESPACE@47..48 " " + SINGLE_PATTERN@48..51 + NAME@48..51 + IDENT@48..51 "baz" + WHITESPACE@51..52 " " + R_CURLY@52..53 "}" + WHITESPACE@53..54 " " + JS_EQUAL_VALUE_CLAUSE@54..58 + EQ@54..55 "=" + WHITESPACE@55..56 " " + OBJECT_EXPR@56..58 + L_CURLY@56..57 "{" + LIST@57..57 + R_CURLY@57..58 "}" WHITESPACE@58..59 "\n" diff --git a/crates/rslint_parser/test_data/inline/ok/object_expr.rast b/crates/rslint_parser/test_data/inline/ok/object_expr.rast index a609fbad490..b9ee30c3f38 100644 --- a/crates/rslint_parser/test_data/inline/ok/object_expr.rast +++ b/crates/rslint_parser/test_data/inline/ok/object_expr.rast @@ -1,39 +1,43 @@ JS_MODULE@0..27 LIST@0..26 - VAR_DECL@0..11 - IDENT@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..10 - DECLARATOR@4..10 - SINGLE_PATTERN@4..5 - NAME@4..5 - IDENT@4..5 "a" - WHITESPACE@5..6 " " - EQ@6..7 "=" - WHITESPACE@7..8 " " - OBJECT_EXPR@8..10 - L_CURLY@8..9 "{" - LIST@9..9 - R_CURLY@9..10 "}" + JS_VARIABLE_DECLARATION_STATEMENT@0..11 + JS_VARIABLE_DECLARATION@0..10 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..10 + JS_VARIABLE_DECLARATOR@4..10 + SINGLE_PATTERN@4..5 + NAME@4..5 + IDENT@4..5 "a" + WHITESPACE@5..6 " " + JS_EQUAL_VALUE_CLAUSE@6..10 + EQ@6..7 "=" + WHITESPACE@7..8 " " + OBJECT_EXPR@8..10 + L_CURLY@8..9 "{" + LIST@9..9 + R_CURLY@9..10 "}" SEMICOLON@10..11 ";" WHITESPACE@11..12 "\n" - VAR_DECL@12..26 - IDENT@12..15 "let" - WHITESPACE@15..16 " " - LIST@16..26 - DECLARATOR@16..26 - SINGLE_PATTERN@16..17 - NAME@16..17 - IDENT@16..17 "b" - WHITESPACE@17..18 " " - EQ@18..19 "=" - WHITESPACE@19..20 " " - OBJECT_EXPR@20..26 - L_CURLY@20..21 "{" - LIST@21..25 - IDENT_PROP@21..24 - NAME@21..24 - IDENT@21..24 "foo" - COMMA@24..25 "," - R_CURLY@25..26 "}" + JS_VARIABLE_DECLARATION_STATEMENT@12..26 + JS_VARIABLE_DECLARATION@12..26 + LET_KW@12..15 "let" + WHITESPACE@15..16 " " + LIST@16..26 + JS_VARIABLE_DECLARATOR@16..26 + SINGLE_PATTERN@16..17 + NAME@16..17 + IDENT@16..17 "b" + WHITESPACE@17..18 " " + JS_EQUAL_VALUE_CLAUSE@18..26 + EQ@18..19 "=" + WHITESPACE@19..20 " " + OBJECT_EXPR@20..26 + L_CURLY@20..21 "{" + LIST@21..25 + IDENT_PROP@21..24 + NAME@21..24 + IDENT@21..24 "foo" + COMMA@24..25 "," + R_CURLY@25..26 "}" WHITESPACE@26..27 "\n" diff --git a/crates/rslint_parser/test_data/inline/ok/object_expr_assign_prop.rast b/crates/rslint_parser/test_data/inline/ok/object_expr_assign_prop.rast index 3ba52d24940..2bb243ea7bc 100644 --- a/crates/rslint_parser/test_data/inline/ok/object_expr_assign_prop.rast +++ b/crates/rslint_parser/test_data/inline/ok/object_expr_assign_prop.rast @@ -1,38 +1,40 @@ JS_MODULE@0..31 LIST@0..30 - VAR_DECL@0..30 - IDENT@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..30 - DECLARATOR@4..30 - SINGLE_PATTERN@4..5 - NAME@4..5 - IDENT@4..5 "b" - WHITESPACE@5..6 " " - EQ@6..7 "=" - WHITESPACE@7..8 " " - OBJECT_EXPR@8..30 - L_CURLY@8..9 "{" - WHITESPACE@9..10 " " - LIST@10..28 - INITIALIZED_PROP@10..17 - NAME@10..13 - IDENT@10..13 "foo" - WHITESPACE@13..14 " " - EQ@14..15 "=" - WHITESPACE@15..16 " " - LITERAL@16..17 - NUMBER@16..17 "4" - COMMA@17..18 "," - WHITESPACE@18..19 " " - INITIALIZED_PROP@19..28 - NAME@19..22 - IDENT@19..22 "foo" - WHITESPACE@22..23 " " - EQ@23..24 "=" - WHITESPACE@24..25 " " - NAME_REF@25..28 - IDENT@25..28 "bar" - WHITESPACE@28..29 " " - R_CURLY@29..30 "}" + JS_VARIABLE_DECLARATION_STATEMENT@0..30 + JS_VARIABLE_DECLARATION@0..30 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..30 + JS_VARIABLE_DECLARATOR@4..30 + SINGLE_PATTERN@4..5 + NAME@4..5 + IDENT@4..5 "b" + WHITESPACE@5..6 " " + JS_EQUAL_VALUE_CLAUSE@6..30 + EQ@6..7 "=" + WHITESPACE@7..8 " " + OBJECT_EXPR@8..30 + L_CURLY@8..9 "{" + WHITESPACE@9..10 " " + LIST@10..28 + INITIALIZED_PROP@10..17 + NAME@10..13 + IDENT@10..13 "foo" + WHITESPACE@13..14 " " + EQ@14..15 "=" + WHITESPACE@15..16 " " + LITERAL@16..17 + NUMBER@16..17 "4" + COMMA@17..18 "," + WHITESPACE@18..19 " " + INITIALIZED_PROP@19..28 + NAME@19..22 + IDENT@19..22 "foo" + WHITESPACE@22..23 " " + EQ@23..24 "=" + WHITESPACE@24..25 " " + NAME_REF@25..28 + IDENT@25..28 "bar" + WHITESPACE@28..29 " " + R_CURLY@29..30 "}" WHITESPACE@30..31 "\n" diff --git a/crates/rslint_parser/test_data/inline/ok/object_expr_async_method.rast b/crates/rslint_parser/test_data/inline/ok/object_expr_async_method.rast index 158b7e5d49e..59cf98eb68d 100644 --- a/crates/rslint_parser/test_data/inline/ok/object_expr_async_method.rast +++ b/crates/rslint_parser/test_data/inline/ok/object_expr_async_method.rast @@ -1,51 +1,53 @@ JS_MODULE@0..48 LIST@0..47 - VAR_DECL@0..47 - IDENT@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..47 - DECLARATOR@4..47 - SINGLE_PATTERN@4..5 - NAME@4..5 - IDENT@4..5 "a" - WHITESPACE@5..6 " " - EQ@6..7 "=" - WHITESPACE@7..8 " " - OBJECT_EXPR@8..47 - L_CURLY@8..9 "{" - WHITESPACE@9..12 "\n " - LIST@12..45 - METHOD@12..26 - ASYNC_KW@12..17 "async" - WHITESPACE@17..18 " " - NAME@18..21 - IDENT@18..21 "foo" - PARAMETER_LIST@21..23 - L_PAREN@21..22 "(" - LIST@22..22 - R_PAREN@22..23 ")" - WHITESPACE@23..24 " " - JS_BLOCK_STATEMENT@24..26 - L_CURLY@24..25 "{" - LIST@25..25 - R_CURLY@25..26 "}" - COMMA@26..27 "," - WHITESPACE@27..30 "\n " - METHOD@30..45 - ASYNC_KW@30..35 "async" - WHITESPACE@35..36 " " - STAR@36..37 "*" - NAME@37..40 - IDENT@37..40 "foo" - PARAMETER_LIST@40..42 - L_PAREN@40..41 "(" - LIST@41..41 - R_PAREN@41..42 ")" - WHITESPACE@42..43 " " - JS_BLOCK_STATEMENT@43..45 - L_CURLY@43..44 "{" - LIST@44..44 - R_CURLY@44..45 "}" - WHITESPACE@45..46 "\n" - R_CURLY@46..47 "}" + JS_VARIABLE_DECLARATION_STATEMENT@0..47 + JS_VARIABLE_DECLARATION@0..47 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..47 + JS_VARIABLE_DECLARATOR@4..47 + SINGLE_PATTERN@4..5 + NAME@4..5 + IDENT@4..5 "a" + WHITESPACE@5..6 " " + JS_EQUAL_VALUE_CLAUSE@6..47 + EQ@6..7 "=" + WHITESPACE@7..8 " " + OBJECT_EXPR@8..47 + L_CURLY@8..9 "{" + WHITESPACE@9..12 "\n " + LIST@12..45 + METHOD@12..26 + ASYNC_KW@12..17 "async" + WHITESPACE@17..18 " " + NAME@18..21 + IDENT@18..21 "foo" + PARAMETER_LIST@21..23 + L_PAREN@21..22 "(" + LIST@22..22 + R_PAREN@22..23 ")" + WHITESPACE@23..24 " " + JS_BLOCK_STATEMENT@24..26 + L_CURLY@24..25 "{" + LIST@25..25 + R_CURLY@25..26 "}" + COMMA@26..27 "," + WHITESPACE@27..30 "\n " + METHOD@30..45 + ASYNC_KW@30..35 "async" + WHITESPACE@35..36 " " + STAR@36..37 "*" + NAME@37..40 + IDENT@37..40 "foo" + PARAMETER_LIST@40..42 + L_PAREN@40..41 "(" + LIST@41..41 + R_PAREN@41..42 ")" + WHITESPACE@42..43 " " + JS_BLOCK_STATEMENT@43..45 + L_CURLY@43..44 "{" + LIST@44..44 + R_CURLY@44..45 "}" + WHITESPACE@45..46 "\n" + R_CURLY@46..47 "}" WHITESPACE@47..48 "\n" diff --git a/crates/rslint_parser/test_data/inline/ok/object_expr_generator_method.rast b/crates/rslint_parser/test_data/inline/ok/object_expr_generator_method.rast index 5d07870dfcd..2f065f61ba3 100644 --- a/crates/rslint_parser/test_data/inline/ok/object_expr_generator_method.rast +++ b/crates/rslint_parser/test_data/inline/ok/object_expr_generator_method.rast @@ -1,33 +1,35 @@ JS_MODULE@0..22 LIST@0..21 - VAR_DECL@0..21 - IDENT@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..21 - DECLARATOR@4..21 - SINGLE_PATTERN@4..5 - NAME@4..5 - IDENT@4..5 "b" - WHITESPACE@5..6 " " - EQ@6..7 "=" - WHITESPACE@7..8 " " - OBJECT_EXPR@8..21 - L_CURLY@8..9 "{" - WHITESPACE@9..10 " " - LIST@10..19 - METHOD@10..19 - STAR@10..11 "*" - NAME@11..14 - IDENT@11..14 "foo" - PARAMETER_LIST@14..16 - L_PAREN@14..15 "(" - LIST@15..15 - R_PAREN@15..16 ")" - WHITESPACE@16..17 " " - JS_BLOCK_STATEMENT@17..19 - L_CURLY@17..18 "{" - LIST@18..18 - R_CURLY@18..19 "}" - WHITESPACE@19..20 " " - R_CURLY@20..21 "}" + JS_VARIABLE_DECLARATION_STATEMENT@0..21 + JS_VARIABLE_DECLARATION@0..21 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..21 + JS_VARIABLE_DECLARATOR@4..21 + SINGLE_PATTERN@4..5 + NAME@4..5 + IDENT@4..5 "b" + WHITESPACE@5..6 " " + JS_EQUAL_VALUE_CLAUSE@6..21 + EQ@6..7 "=" + WHITESPACE@7..8 " " + OBJECT_EXPR@8..21 + L_CURLY@8..9 "{" + WHITESPACE@9..10 " " + LIST@10..19 + METHOD@10..19 + STAR@10..11 "*" + NAME@11..14 + IDENT@11..14 "foo" + PARAMETER_LIST@14..16 + L_PAREN@14..15 "(" + LIST@15..15 + R_PAREN@15..16 ")" + WHITESPACE@16..17 " " + JS_BLOCK_STATEMENT@17..19 + L_CURLY@17..18 "{" + LIST@18..18 + R_CURLY@18..19 "}" + WHITESPACE@19..20 " " + R_CURLY@20..21 "}" WHITESPACE@21..22 "\n" diff --git a/crates/rslint_parser/test_data/inline/ok/object_expr_getter_setter.rast b/crates/rslint_parser/test_data/inline/ok/object_expr_getter_setter.rast index e42a0e23fa4..b60cb72e700 100644 --- a/crates/rslint_parser/test_data/inline/ok/object_expr_getter_setter.rast +++ b/crates/rslint_parser/test_data/inline/ok/object_expr_getter_setter.rast @@ -1,42 +1,44 @@ JS_MODULE@0..43 LIST@0..42 - VAR_DECL@0..42 - IDENT@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..42 - DECLARATOR@4..42 - SINGLE_PATTERN@4..5 - NAME@4..5 - IDENT@4..5 "a" - WHITESPACE@5..6 " " - EQ@6..7 "=" - WHITESPACE@7..8 " " - OBJECT_EXPR@8..42 - L_CURLY@8..9 "{" - WHITESPACE@9..11 "\n " - LIST@11..40 - GETTER@11..40 - GET_KW@11..14 "get" - WHITESPACE@14..15 " " - NAME@15..18 - IDENT@15..18 "foo" - PARAMETER_LIST@18..20 - L_PAREN@18..19 "(" - LIST@19..19 - R_PAREN@19..20 ")" - WHITESPACE@20..21 " " - JS_BLOCK_STATEMENT@21..40 - L_CURLY@21..22 "{" - WHITESPACE@22..26 "\n " - LIST@26..37 - JS_RETURN_STATEMENT@26..37 - RETURN_KW@26..32 "return" - WHITESPACE@32..33 " " - NAME_REF@33..36 - IDENT@33..36 "foo" - SEMICOLON@36..37 ";" - WHITESPACE@37..39 "\n " - R_CURLY@39..40 "}" - WHITESPACE@40..41 "\n" - R_CURLY@41..42 "}" + JS_VARIABLE_DECLARATION_STATEMENT@0..42 + JS_VARIABLE_DECLARATION@0..42 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..42 + JS_VARIABLE_DECLARATOR@4..42 + SINGLE_PATTERN@4..5 + NAME@4..5 + IDENT@4..5 "a" + WHITESPACE@5..6 " " + JS_EQUAL_VALUE_CLAUSE@6..42 + EQ@6..7 "=" + WHITESPACE@7..8 " " + OBJECT_EXPR@8..42 + L_CURLY@8..9 "{" + WHITESPACE@9..11 "\n " + LIST@11..40 + GETTER@11..40 + GET_KW@11..14 "get" + WHITESPACE@14..15 " " + NAME@15..18 + IDENT@15..18 "foo" + PARAMETER_LIST@18..20 + L_PAREN@18..19 "(" + LIST@19..19 + R_PAREN@19..20 ")" + WHITESPACE@20..21 " " + JS_BLOCK_STATEMENT@21..40 + L_CURLY@21..22 "{" + WHITESPACE@22..26 "\n " + LIST@26..37 + JS_RETURN_STATEMENT@26..37 + RETURN_KW@26..32 "return" + WHITESPACE@32..33 " " + NAME_REF@33..36 + IDENT@33..36 "foo" + SEMICOLON@36..37 ";" + WHITESPACE@37..39 "\n " + R_CURLY@39..40 "}" + WHITESPACE@40..41 "\n" + R_CURLY@41..42 "}" WHITESPACE@42..43 "\n" diff --git a/crates/rslint_parser/test_data/inline/ok/object_expr_getter_setter_as_prop.rast b/crates/rslint_parser/test_data/inline/ok/object_expr_getter_setter_as_prop.rast index a2acf1df192..58b78fb0c7c 100644 --- a/crates/rslint_parser/test_data/inline/ok/object_expr_getter_setter_as_prop.rast +++ b/crates/rslint_parser/test_data/inline/ok/object_expr_getter_setter_as_prop.rast @@ -1,29 +1,31 @@ JS_MODULE@0..26 LIST@0..25 - VAR_DECL@0..25 - CONST_KW@0..5 "const" - WHITESPACE@5..6 " " - LIST@6..24 - DECLARATOR@6..24 - SINGLE_PATTERN@6..9 - NAME@6..9 - IDENT@6..9 "foo" - WHITESPACE@9..10 " " - EQ@10..11 "=" - WHITESPACE@11..12 " " - OBJECT_EXPR@12..24 - L_CURLY@12..13 "{" - WHITESPACE@13..14 " " - LIST@14..22 - IDENT_PROP@14..17 - NAME@14..17 - IDENT@14..17 "set" - COMMA@17..18 "," - WHITESPACE@18..19 " " - IDENT_PROP@19..22 - NAME@19..22 - IDENT@19..22 "get" - WHITESPACE@22..23 " " - R_CURLY@23..24 "}" + JS_VARIABLE_DECLARATION_STATEMENT@0..25 + JS_VARIABLE_DECLARATION@0..24 + CONST_KW@0..5 "const" + WHITESPACE@5..6 " " + LIST@6..24 + JS_VARIABLE_DECLARATOR@6..24 + SINGLE_PATTERN@6..9 + NAME@6..9 + IDENT@6..9 "foo" + WHITESPACE@9..10 " " + JS_EQUAL_VALUE_CLAUSE@10..24 + EQ@10..11 "=" + WHITESPACE@11..12 " " + OBJECT_EXPR@12..24 + L_CURLY@12..13 "{" + WHITESPACE@13..14 " " + LIST@14..22 + IDENT_PROP@14..17 + NAME@14..17 + IDENT@14..17 "set" + COMMA@17..18 "," + WHITESPACE@18..19 " " + IDENT_PROP@19..22 + NAME@19..22 + IDENT@19..22 "get" + WHITESPACE@22..23 " " + R_CURLY@23..24 "}" SEMICOLON@24..25 ";" WHITESPACE@25..26 "\n" diff --git a/crates/rslint_parser/test_data/inline/ok/object_expr_getter_setter_computed.rast b/crates/rslint_parser/test_data/inline/ok/object_expr_getter_setter_computed.rast index 07753a2b6f3..2d34fed0927 100644 --- a/crates/rslint_parser/test_data/inline/ok/object_expr_getter_setter_computed.rast +++ b/crates/rslint_parser/test_data/inline/ok/object_expr_getter_setter_computed.rast @@ -1,45 +1,47 @@ JS_MODULE@0..48 LIST@0..47 - VAR_DECL@0..47 - IDENT@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..47 - DECLARATOR@4..47 - SINGLE_PATTERN@4..5 - NAME@4..5 - IDENT@4..5 "a" - WHITESPACE@5..6 " " - EQ@6..7 "=" - WHITESPACE@7..8 " " - OBJECT_EXPR@8..47 - L_CURLY@8..9 "{" - WHITESPACE@9..12 "\n " - LIST@12..45 - GETTER@12..45 - GET_KW@12..15 "get" - WHITESPACE@15..16 " " - COMPUTED_PROPERTY_NAME@16..21 - L_BRACK@16..17 "[" - NAME_REF@17..20 - IDENT@17..20 "foo" - R_BRACK@20..21 "]" - PARAMETER_LIST@21..23 - L_PAREN@21..22 "(" - LIST@22..22 - R_PAREN@22..23 ")" - WHITESPACE@23..24 " " - JS_BLOCK_STATEMENT@24..45 - L_CURLY@24..25 "{" - WHITESPACE@25..30 "\n " - LIST@30..41 - JS_RETURN_STATEMENT@30..41 - RETURN_KW@30..36 "return" - WHITESPACE@36..37 " " - NAME_REF@37..40 - IDENT@37..40 "foo" - SEMICOLON@40..41 ";" - WHITESPACE@41..44 "\n " - R_CURLY@44..45 "}" - WHITESPACE@45..46 "\n" - R_CURLY@46..47 "}" + JS_VARIABLE_DECLARATION_STATEMENT@0..47 + JS_VARIABLE_DECLARATION@0..47 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..47 + JS_VARIABLE_DECLARATOR@4..47 + SINGLE_PATTERN@4..5 + NAME@4..5 + IDENT@4..5 "a" + WHITESPACE@5..6 " " + JS_EQUAL_VALUE_CLAUSE@6..47 + EQ@6..7 "=" + WHITESPACE@7..8 " " + OBJECT_EXPR@8..47 + L_CURLY@8..9 "{" + WHITESPACE@9..12 "\n " + LIST@12..45 + GETTER@12..45 + GET_KW@12..15 "get" + WHITESPACE@15..16 " " + COMPUTED_PROPERTY_NAME@16..21 + L_BRACK@16..17 "[" + NAME_REF@17..20 + IDENT@17..20 "foo" + R_BRACK@20..21 "]" + PARAMETER_LIST@21..23 + L_PAREN@21..22 "(" + LIST@22..22 + R_PAREN@22..23 ")" + WHITESPACE@23..24 " " + JS_BLOCK_STATEMENT@24..45 + L_CURLY@24..25 "{" + WHITESPACE@25..30 "\n " + LIST@30..41 + JS_RETURN_STATEMENT@30..41 + RETURN_KW@30..36 "return" + WHITESPACE@36..37 " " + NAME_REF@37..40 + IDENT@37..40 "foo" + SEMICOLON@40..41 ";" + WHITESPACE@41..44 "\n " + R_CURLY@44..45 "}" + WHITESPACE@45..46 "\n" + R_CURLY@46..47 "}" WHITESPACE@47..48 "\n" diff --git a/crates/rslint_parser/test_data/inline/ok/object_expr_ident_literal_prop.rast b/crates/rslint_parser/test_data/inline/ok/object_expr_ident_literal_prop.rast index d74ad946781..55eea4c6e68 100644 --- a/crates/rslint_parser/test_data/inline/ok/object_expr_ident_literal_prop.rast +++ b/crates/rslint_parser/test_data/inline/ok/object_expr_ident_literal_prop.rast @@ -1,27 +1,29 @@ JS_MODULE@0..20 LIST@0..19 - VAR_DECL@0..19 - IDENT@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..19 - DECLARATOR@4..19 - SINGLE_PATTERN@4..5 - NAME@4..5 - IDENT@4..5 "b" - WHITESPACE@5..6 " " - EQ@6..7 "=" - WHITESPACE@7..8 " " - OBJECT_EXPR@8..19 - L_CURLY@8..9 "{" - WHITESPACE@9..10 " " - LIST@10..17 - LITERAL_PROP@10..17 - NAME@10..11 - IDENT@10..11 "a" - COLON@11..12 ":" - WHITESPACE@12..13 " " - LITERAL@13..17 - TRUE_KW@13..17 "true" - WHITESPACE@17..18 " " - R_CURLY@18..19 "}" + JS_VARIABLE_DECLARATION_STATEMENT@0..19 + JS_VARIABLE_DECLARATION@0..19 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..19 + JS_VARIABLE_DECLARATOR@4..19 + SINGLE_PATTERN@4..5 + NAME@4..5 + IDENT@4..5 "b" + WHITESPACE@5..6 " " + JS_EQUAL_VALUE_CLAUSE@6..19 + EQ@6..7 "=" + WHITESPACE@7..8 " " + OBJECT_EXPR@8..19 + L_CURLY@8..9 "{" + WHITESPACE@9..10 " " + LIST@10..17 + LITERAL_PROP@10..17 + NAME@10..11 + IDENT@10..11 "a" + COLON@11..12 ":" + WHITESPACE@12..13 " " + LITERAL@13..17 + TRUE_KW@13..17 "true" + WHITESPACE@17..18 " " + R_CURLY@18..19 "}" WHITESPACE@19..20 "\n" diff --git a/crates/rslint_parser/test_data/inline/ok/object_expr_ident_prop.rast b/crates/rslint_parser/test_data/inline/ok/object_expr_ident_prop.rast index 023405ce721..229a4cbe2b2 100644 --- a/crates/rslint_parser/test_data/inline/ok/object_expr_ident_prop.rast +++ b/crates/rslint_parser/test_data/inline/ok/object_expr_ident_prop.rast @@ -1,21 +1,23 @@ JS_MODULE@0..14 LIST@0..13 - VAR_DECL@0..13 - IDENT@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..13 - DECLARATOR@4..13 - SINGLE_PATTERN@4..5 - NAME@4..5 - IDENT@4..5 "b" - WHITESPACE@5..6 " " - EQ@6..7 "=" - WHITESPACE@7..8 " " - OBJECT_EXPR@8..13 - L_CURLY@8..9 "{" - LIST@9..12 - IDENT_PROP@9..12 - NAME@9..12 - IDENT@9..12 "foo" - R_CURLY@12..13 "}" + JS_VARIABLE_DECLARATION_STATEMENT@0..13 + JS_VARIABLE_DECLARATION@0..13 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..13 + JS_VARIABLE_DECLARATOR@4..13 + SINGLE_PATTERN@4..5 + NAME@4..5 + IDENT@4..5 "b" + WHITESPACE@5..6 " " + JS_EQUAL_VALUE_CLAUSE@6..13 + EQ@6..7 "=" + WHITESPACE@7..8 " " + OBJECT_EXPR@8..13 + L_CURLY@8..9 "{" + LIST@9..12 + IDENT_PROP@9..12 + NAME@9..12 + IDENT@9..12 "foo" + R_CURLY@12..13 "}" WHITESPACE@13..14 "\n" diff --git a/crates/rslint_parser/test_data/inline/ok/object_expr_method.rast b/crates/rslint_parser/test_data/inline/ok/object_expr_method.rast index d14abc22250..67ea65ebcbf 100644 --- a/crates/rslint_parser/test_data/inline/ok/object_expr_method.rast +++ b/crates/rslint_parser/test_data/inline/ok/object_expr_method.rast @@ -1,33 +1,35 @@ JS_MODULE@0..23 LIST@0..22 - VAR_DECL@0..22 - IDENT@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..22 - DECLARATOR@4..22 - SINGLE_PATTERN@4..5 - NAME@4..5 - IDENT@4..5 "b" - WHITESPACE@5..6 " " - EQ@6..7 "=" - WHITESPACE@7..8 " " - OBJECT_EXPR@8..22 - L_CURLY@8..9 "{" - WHITESPACE@9..11 "\n " - LIST@11..20 - METHOD@11..19 - NAME@11..14 - IDENT@11..14 "foo" - PARAMETER_LIST@14..16 - L_PAREN@14..15 "(" - LIST@15..15 - R_PAREN@15..16 ")" - WHITESPACE@16..17 " " - JS_BLOCK_STATEMENT@17..19 - L_CURLY@17..18 "{" - LIST@18..18 - R_CURLY@18..19 "}" - COMMA@19..20 "," - WHITESPACE@20..21 "\n" - R_CURLY@21..22 "}" + JS_VARIABLE_DECLARATION_STATEMENT@0..22 + JS_VARIABLE_DECLARATION@0..22 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..22 + JS_VARIABLE_DECLARATOR@4..22 + SINGLE_PATTERN@4..5 + NAME@4..5 + IDENT@4..5 "b" + WHITESPACE@5..6 " " + JS_EQUAL_VALUE_CLAUSE@6..22 + EQ@6..7 "=" + WHITESPACE@7..8 " " + OBJECT_EXPR@8..22 + L_CURLY@8..9 "{" + WHITESPACE@9..11 "\n " + LIST@11..20 + METHOD@11..19 + NAME@11..14 + IDENT@11..14 "foo" + PARAMETER_LIST@14..16 + L_PAREN@14..15 "(" + LIST@15..15 + R_PAREN@15..16 ")" + WHITESPACE@16..17 " " + JS_BLOCK_STATEMENT@17..19 + L_CURLY@17..18 "{" + LIST@18..18 + R_CURLY@18..19 "}" + COMMA@19..20 "," + WHITESPACE@20..21 "\n" + R_CURLY@21..22 "}" WHITESPACE@22..23 "\n" diff --git a/crates/rslint_parser/test_data/inline/ok/object_expr_spread_prop.rast b/crates/rslint_parser/test_data/inline/ok/object_expr_spread_prop.rast index 1c74f8ae7a6..e9474feda52 100644 --- a/crates/rslint_parser/test_data/inline/ok/object_expr_spread_prop.rast +++ b/crates/rslint_parser/test_data/inline/ok/object_expr_spread_prop.rast @@ -1,22 +1,24 @@ JS_MODULE@0..17 LIST@0..16 - VAR_DECL@0..16 - IDENT@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..16 - DECLARATOR@4..16 - SINGLE_PATTERN@4..5 - NAME@4..5 - IDENT@4..5 "a" - WHITESPACE@5..6 " " - EQ@6..7 "=" - WHITESPACE@7..8 " " - OBJECT_EXPR@8..16 - L_CURLY@8..9 "{" - LIST@9..15 - SPREAD_PROP@9..15 - DOT2@9..12 "..." - NAME_REF@12..15 - IDENT@12..15 "foo" - R_CURLY@15..16 "}" + JS_VARIABLE_DECLARATION_STATEMENT@0..16 + JS_VARIABLE_DECLARATION@0..16 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..16 + JS_VARIABLE_DECLARATOR@4..16 + SINGLE_PATTERN@4..5 + NAME@4..5 + IDENT@4..5 "a" + WHITESPACE@5..6 " " + JS_EQUAL_VALUE_CLAUSE@6..16 + EQ@6..7 "=" + WHITESPACE@7..8 " " + OBJECT_EXPR@8..16 + L_CURLY@8..9 "{" + LIST@9..15 + SPREAD_PROP@9..15 + DOT2@9..12 "..." + NAME_REF@12..15 + IDENT@12..15 "foo" + R_CURLY@15..16 "}" WHITESPACE@16..17 "\n" diff --git a/crates/rslint_parser/test_data/inline/ok/object_prop_name.rast b/crates/rslint_parser/test_data/inline/ok/object_prop_name.rast index caade487b12..224d20a548c 100644 --- a/crates/rslint_parser/test_data/inline/ok/object_prop_name.rast +++ b/crates/rslint_parser/test_data/inline/ok/object_prop_name.rast @@ -1,61 +1,63 @@ JS_MODULE@0..53 LIST@0..52 - VAR_DECL@0..52 - IDENT@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..52 - DECLARATOR@4..52 - SINGLE_PATTERN@4..5 - NAME@4..5 - IDENT@4..5 "a" - WHITESPACE@5..6 " " - EQ@6..7 "=" - WHITESPACE@7..8 " " - OBJECT_EXPR@8..52 - L_CURLY@8..9 "{" - LIST@9..51 - LITERAL_PROP@9..19 - LITERAL@9..14 - STRING@9..14 "\"foo\"" - COLON@14..15 ":" - WHITESPACE@15..16 " " - NAME_REF@16..19 - IDENT@16..19 "foo" - COMMA@19..20 "," - WHITESPACE@20..21 " " - LITERAL_PROP@21..33 - COMPUTED_PROPERTY_NAME@21..28 - L_BRACK@21..22 "[" - BIN_EXPR@22..27 - LITERAL@22..23 - NUMBER@22..23 "6" - WHITESPACE@23..24 " " - PLUS@24..25 "+" - WHITESPACE@25..26 " " - LITERAL@26..27 - NUMBER@26..27 "6" - R_BRACK@27..28 "]" - COLON@28..29 ":" - WHITESPACE@29..30 " " - NAME_REF@30..33 - IDENT@30..33 "foo" - COMMA@33..34 "," - WHITESPACE@34..35 " " - LITERAL_PROP@35..43 - NAME@35..38 - IDENT@35..38 "bar" - COLON@38..39 ":" - WHITESPACE@39..40 " " - NAME_REF@40..43 - IDENT@40..43 "foo" - COMMA@43..44 "," - WHITESPACE@44..45 " " - LITERAL_PROP@45..51 - LITERAL@45..46 - NUMBER@45..46 "7" - COLON@46..47 ":" - WHITESPACE@47..48 " " - NAME_REF@48..51 - IDENT@48..51 "foo" - R_CURLY@51..52 "}" + JS_VARIABLE_DECLARATION_STATEMENT@0..52 + JS_VARIABLE_DECLARATION@0..52 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..52 + JS_VARIABLE_DECLARATOR@4..52 + SINGLE_PATTERN@4..5 + NAME@4..5 + IDENT@4..5 "a" + WHITESPACE@5..6 " " + JS_EQUAL_VALUE_CLAUSE@6..52 + EQ@6..7 "=" + WHITESPACE@7..8 " " + OBJECT_EXPR@8..52 + L_CURLY@8..9 "{" + LIST@9..51 + LITERAL_PROP@9..19 + LITERAL@9..14 + STRING@9..14 "\"foo\"" + COLON@14..15 ":" + WHITESPACE@15..16 " " + NAME_REF@16..19 + IDENT@16..19 "foo" + COMMA@19..20 "," + WHITESPACE@20..21 " " + LITERAL_PROP@21..33 + COMPUTED_PROPERTY_NAME@21..28 + L_BRACK@21..22 "[" + BIN_EXPR@22..27 + LITERAL@22..23 + NUMBER@22..23 "6" + WHITESPACE@23..24 " " + PLUS@24..25 "+" + WHITESPACE@25..26 " " + LITERAL@26..27 + NUMBER@26..27 "6" + R_BRACK@27..28 "]" + COLON@28..29 ":" + WHITESPACE@29..30 " " + NAME_REF@30..33 + IDENT@30..33 "foo" + COMMA@33..34 "," + WHITESPACE@34..35 " " + LITERAL_PROP@35..43 + NAME@35..38 + IDENT@35..38 "bar" + COLON@38..39 ":" + WHITESPACE@39..40 " " + NAME_REF@40..43 + IDENT@40..43 "foo" + COMMA@43..44 "," + WHITESPACE@44..45 " " + LITERAL_PROP@45..51 + LITERAL@45..46 + NUMBER@45..46 "7" + COLON@46..47 ":" + WHITESPACE@47..48 " " + NAME_REF@48..51 + IDENT@48..51 "foo" + R_CURLY@51..52 "}" WHITESPACE@52..53 "\n" diff --git a/crates/rslint_parser/test_data/inline/ok/semicolons.rast b/crates/rslint_parser/test_data/inline/ok/semicolons.rast index 558fcc7635f..570ba0d9b21 100644 --- a/crates/rslint_parser/test_data/inline/ok/semicolons.rast +++ b/crates/rslint_parser/test_data/inline/ok/semicolons.rast @@ -1,62 +1,69 @@ JS_MODULE@0..84 LIST@0..83 - VAR_DECL@0..14 - IDENT@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..13 - DECLARATOR@4..13 - SINGLE_PATTERN@4..7 - NAME@4..7 - IDENT@4..7 "foo" - WHITESPACE@7..8 " " - EQ@8..9 "=" - WHITESPACE@9..10 " " - NAME_REF@10..13 - IDENT@10..13 "bar" + JS_VARIABLE_DECLARATION_STATEMENT@0..14 + JS_VARIABLE_DECLARATION@0..13 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..13 + JS_VARIABLE_DECLARATOR@4..13 + SINGLE_PATTERN@4..7 + NAME@4..7 + IDENT@4..7 "foo" + WHITESPACE@7..8 " " + JS_EQUAL_VALUE_CLAUSE@8..13 + EQ@8..9 "=" + WHITESPACE@9..10 " " + NAME_REF@10..13 + IDENT@10..13 "bar" SEMICOLON@13..14 ";" WHITESPACE@14..15 "\n" - VAR_DECL@15..27 - IDENT@15..18 "let" - WHITESPACE@18..19 " " - LIST@19..26 - DECLARATOR@19..26 - SINGLE_PATTERN@19..22 - NAME@19..22 - IDENT@19..22 "foo" - WHITESPACE@22..23 " " - EQ@23..24 "=" - WHITESPACE@24..25 " " - NAME_REF@25..26 - IDENT@25..26 "b" + JS_VARIABLE_DECLARATION_STATEMENT@15..27 + JS_VARIABLE_DECLARATION@15..26 + LET_KW@15..18 "let" + WHITESPACE@18..19 " " + LIST@19..26 + JS_VARIABLE_DECLARATOR@19..26 + SINGLE_PATTERN@19..22 + NAME@19..22 + IDENT@19..22 "foo" + WHITESPACE@22..23 " " + JS_EQUAL_VALUE_CLAUSE@23..26 + EQ@23..24 "=" + WHITESPACE@24..25 " " + NAME_REF@25..26 + IDENT@25..26 "b" SEMICOLON@26..27 ";" WHITESPACE@27..28 "\n" - VAR_DECL@28..36 - IDENT@28..31 "let" - WHITESPACE@31..32 " " - LIST@32..35 - DECLARATOR@32..35 - SINGLE_PATTERN@32..35 - NAME@32..35 - IDENT@32..35 "foo" + JS_VARIABLE_DECLARATION_STATEMENT@28..36 + JS_VARIABLE_DECLARATION@28..35 + LET_KW@28..31 "let" + WHITESPACE@31..32 " " + LIST@32..35 + JS_VARIABLE_DECLARATOR@32..35 + SINGLE_PATTERN@32..35 + NAME@32..35 + IDENT@32..35 "foo" SEMICOLON@35..36 ";" WHITESPACE@36..37 "\n" - VAR_DECL@37..44 - IDENT@37..40 "let" - WHITESPACE@40..41 " " - LIST@41..44 - DECLARATOR@41..44 - SINGLE_PATTERN@41..44 - NAME@41..44 - IDENT@41..44 "foo" + JS_VARIABLE_DECLARATION_STATEMENT@37..44 + JS_VARIABLE_DECLARATION@37..44 + LET_KW@37..40 "let" + WHITESPACE@40..41 " " + LIST@41..44 + JS_VARIABLE_DECLARATOR@41..44 + SINGLE_PATTERN@41..44 + NAME@41..44 + IDENT@41..44 "foo" WHITESPACE@44..45 "\n" - VAR_DECL@45..52 - IDENT@45..48 "let" - WHITESPACE@48..49 " " - LIST@49..52 - DECLARATOR@49..52 - SINGLE_PATTERN@49..52 - NAME@49..52 - IDENT@49..52 "foo" + JS_VARIABLE_DECLARATION_STATEMENT@45..52 + JS_VARIABLE_DECLARATION@45..52 + LET_KW@45..48 "let" + WHITESPACE@48..49 " " + LIST@49..52 + JS_VARIABLE_DECLARATOR@49..52 + SINGLE_PATTERN@49..52 + NAME@49..52 + IDENT@49..52 "foo" WHITESPACE@52..53 "\n" FN_DECL@53..83 FUNCTION_KW@53..61 "function" diff --git a/crates/rslint_parser/test_data/inline/ok/template_literal.rast b/crates/rslint_parser/test_data/inline/ok/template_literal.rast index 4e98171012d..3f70c0cbc18 100644 --- a/crates/rslint_parser/test_data/inline/ok/template_literal.rast +++ b/crates/rslint_parser/test_data/inline/ok/template_literal.rast @@ -1,82 +1,90 @@ JS_MODULE@0..67 LIST@0..66 - VAR_DECL@0..21 - IDENT@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..20 - DECLARATOR@4..20 - SINGLE_PATTERN@4..5 - NAME@4..5 - IDENT@4..5 "a" - WHITESPACE@5..6 " " - EQ@6..7 "=" - WHITESPACE@7..8 " " - TEMPLATE@8..20 - BACKTICK@8..9 "`" - LIST@9..19 - TEMPLATE_CHUNK@9..13 "foo " - TEMPLATE_ELEMENT@13..19 - DOLLARCURLY@13..15 "${" - NAME_REF@15..18 - IDENT@15..18 "bar" - R_CURLY@18..19 "}" - BACKTICK@19..20 "`" + JS_VARIABLE_DECLARATION_STATEMENT@0..21 + JS_VARIABLE_DECLARATION@0..20 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..20 + JS_VARIABLE_DECLARATOR@4..20 + SINGLE_PATTERN@4..5 + NAME@4..5 + IDENT@4..5 "a" + WHITESPACE@5..6 " " + JS_EQUAL_VALUE_CLAUSE@6..20 + EQ@6..7 "=" + WHITESPACE@7..8 " " + TEMPLATE@8..20 + BACKTICK@8..9 "`" + LIST@9..19 + TEMPLATE_CHUNK@9..13 "foo " + TEMPLATE_ELEMENT@13..19 + DOLLARCURLY@13..15 "${" + NAME_REF@15..18 + IDENT@15..18 "bar" + R_CURLY@18..19 "}" + BACKTICK@19..20 "`" SEMICOLON@20..21 ";" WHITESPACE@21..22 "\n" - VAR_DECL@22..33 - IDENT@22..25 "let" - WHITESPACE@25..26 " " - LIST@26..32 - DECLARATOR@26..32 - SINGLE_PATTERN@26..27 - NAME@26..27 - IDENT@26..27 "a" - WHITESPACE@27..28 " " - EQ@28..29 "=" - WHITESPACE@29..30 " " - TEMPLATE@30..32 - BACKTICK@30..31 "`" - LIST@31..31 - BACKTICK@31..32 "`" + JS_VARIABLE_DECLARATION_STATEMENT@22..33 + JS_VARIABLE_DECLARATION@22..32 + LET_KW@22..25 "let" + WHITESPACE@25..26 " " + LIST@26..32 + JS_VARIABLE_DECLARATOR@26..32 + SINGLE_PATTERN@26..27 + NAME@26..27 + IDENT@26..27 "a" + WHITESPACE@27..28 " " + JS_EQUAL_VALUE_CLAUSE@28..32 + EQ@28..29 "=" + WHITESPACE@29..30 " " + TEMPLATE@30..32 + BACKTICK@30..31 "`" + LIST@31..31 + BACKTICK@31..32 "`" SEMICOLON@32..33 ";" WHITESPACE@33..34 "\n" - VAR_DECL@34..51 - IDENT@34..37 "let" - WHITESPACE@37..38 " " - LIST@38..50 - DECLARATOR@38..50 - SINGLE_PATTERN@38..39 - NAME@38..39 - IDENT@38..39 "a" - WHITESPACE@39..40 " " - EQ@40..41 "=" - WHITESPACE@41..42 " " - TEMPLATE@42..50 - BACKTICK@42..43 "`" - LIST@43..49 - TEMPLATE_ELEMENT@43..49 - DOLLARCURLY@43..45 "${" - NAME_REF@45..48 - IDENT@45..48 "foo" - R_CURLY@48..49 "}" - BACKTICK@49..50 "`" + JS_VARIABLE_DECLARATION_STATEMENT@34..51 + JS_VARIABLE_DECLARATION@34..50 + LET_KW@34..37 "let" + WHITESPACE@37..38 " " + LIST@38..50 + JS_VARIABLE_DECLARATOR@38..50 + SINGLE_PATTERN@38..39 + NAME@38..39 + IDENT@38..39 "a" + WHITESPACE@39..40 " " + JS_EQUAL_VALUE_CLAUSE@40..50 + EQ@40..41 "=" + WHITESPACE@41..42 " " + TEMPLATE@42..50 + BACKTICK@42..43 "`" + LIST@43..49 + TEMPLATE_ELEMENT@43..49 + DOLLARCURLY@43..45 "${" + NAME_REF@45..48 + IDENT@45..48 "foo" + R_CURLY@48..49 "}" + BACKTICK@49..50 "`" SEMICOLON@50..51 ";" WHITESPACE@51..52 "\n" - VAR_DECL@52..66 - IDENT@52..55 "let" - WHITESPACE@55..56 " " - LIST@56..65 - DECLARATOR@56..65 - SINGLE_PATTERN@56..57 - NAME@56..57 - IDENT@56..57 "a" - WHITESPACE@57..58 " " - EQ@58..59 "=" - WHITESPACE@59..60 " " - TEMPLATE@60..65 - BACKTICK@60..61 "`" - LIST@61..64 - TEMPLATE_CHUNK@61..64 "foo" - BACKTICK@64..65 "`" + JS_VARIABLE_DECLARATION_STATEMENT@52..66 + JS_VARIABLE_DECLARATION@52..65 + LET_KW@52..55 "let" + WHITESPACE@55..56 " " + LIST@56..65 + JS_VARIABLE_DECLARATOR@56..65 + SINGLE_PATTERN@56..57 + NAME@56..57 + IDENT@56..57 "a" + WHITESPACE@57..58 " " + JS_EQUAL_VALUE_CLAUSE@58..65 + EQ@58..59 "=" + WHITESPACE@59..60 " " + TEMPLATE@60..65 + BACKTICK@60..61 "`" + LIST@61..64 + TEMPLATE_CHUNK@61..64 "foo" + BACKTICK@64..65 "`" SEMICOLON@65..66 ";" WHITESPACE@66..67 "\n" diff --git a/crates/rslint_parser/test_data/inline/ok/var_decl.js b/crates/rslint_parser/test_data/inline/ok/var_decl.js index d7c04afe472..b480d7c9815 100644 --- a/crates/rslint_parser/test_data/inline/ok/var_decl.js +++ b/crates/rslint_parser/test_data/inline/ok/var_decl.js @@ -3,3 +3,4 @@ let { foo, bar } = 5; let bar, foo; const a = 5; const { foo: [bar], baz } = {}; +let foo = "lorem", bar = "ipsum", third = "value", fourth = 6; diff --git a/crates/rslint_parser/test_data/inline/ok/var_decl.rast b/crates/rslint_parser/test_data/inline/ok/var_decl.rast index 2f65c84935f..23508cd3b91 100644 --- a/crates/rslint_parser/test_data/inline/ok/var_decl.rast +++ b/crates/rslint_parser/test_data/inline/ok/var_decl.rast @@ -1,111 +1,173 @@ -JS_MODULE@0..92 - LIST@0..91 - VAR_DECL@0..10 - VAR_KW@0..3 "var" - WHITESPACE@3..4 " " - LIST@4..9 - DECLARATOR@4..9 - SINGLE_PATTERN@4..5 - NAME@4..5 - IDENT@4..5 "a" - WHITESPACE@5..6 " " - EQ@6..7 "=" - WHITESPACE@7..8 " " - LITERAL@8..9 - NUMBER@8..9 "5" +JS_MODULE@0..155 + LIST@0..154 + JS_VARIABLE_DECLARATION_STATEMENT@0..10 + JS_VARIABLE_DECLARATION@0..9 + VAR_KW@0..3 "var" + WHITESPACE@3..4 " " + LIST@4..9 + JS_VARIABLE_DECLARATOR@4..9 + SINGLE_PATTERN@4..5 + NAME@4..5 + IDENT@4..5 "a" + WHITESPACE@5..6 " " + JS_EQUAL_VALUE_CLAUSE@6..9 + EQ@6..7 "=" + WHITESPACE@7..8 " " + LITERAL@8..9 + NUMBER@8..9 "5" SEMICOLON@9..10 ";" WHITESPACE@10..11 "\n" - VAR_DECL@11..32 - IDENT@11..14 "let" - WHITESPACE@14..15 " " - LIST@15..31 - DECLARATOR@15..31 - OBJECT_PATTERN@15..27 - L_CURLY@15..16 "{" - WHITESPACE@16..17 " " - LIST@17..25 - SINGLE_PATTERN@17..20 - NAME@17..20 - IDENT@17..20 "foo" - COMMA@20..21 "," - WHITESPACE@21..22 " " - SINGLE_PATTERN@22..25 - NAME@22..25 - IDENT@22..25 "bar" - WHITESPACE@25..26 " " - R_CURLY@26..27 "}" - WHITESPACE@27..28 " " - EQ@28..29 "=" - WHITESPACE@29..30 " " - LITERAL@30..31 - NUMBER@30..31 "5" + JS_VARIABLE_DECLARATION_STATEMENT@11..32 + JS_VARIABLE_DECLARATION@11..31 + LET_KW@11..14 "let" + WHITESPACE@14..15 " " + LIST@15..31 + JS_VARIABLE_DECLARATOR@15..31 + OBJECT_PATTERN@15..27 + L_CURLY@15..16 "{" + WHITESPACE@16..17 " " + LIST@17..25 + SINGLE_PATTERN@17..20 + NAME@17..20 + IDENT@17..20 "foo" + COMMA@20..21 "," + WHITESPACE@21..22 " " + SINGLE_PATTERN@22..25 + NAME@22..25 + IDENT@22..25 "bar" + WHITESPACE@25..26 " " + R_CURLY@26..27 "}" + WHITESPACE@27..28 " " + JS_EQUAL_VALUE_CLAUSE@28..31 + EQ@28..29 "=" + WHITESPACE@29..30 " " + LITERAL@30..31 + NUMBER@30..31 "5" SEMICOLON@31..32 ";" WHITESPACE@32..33 "\n" - VAR_DECL@33..46 - IDENT@33..36 "let" - WHITESPACE@36..37 " " - LIST@37..45 - DECLARATOR@37..40 - SINGLE_PATTERN@37..40 - NAME@37..40 - IDENT@37..40 "bar" - COMMA@40..41 "," - WHITESPACE@41..42 " " - DECLARATOR@42..45 - SINGLE_PATTERN@42..45 - NAME@42..45 - IDENT@42..45 "foo" + JS_VARIABLE_DECLARATION_STATEMENT@33..46 + JS_VARIABLE_DECLARATION@33..45 + LET_KW@33..36 "let" + WHITESPACE@36..37 " " + LIST@37..45 + JS_VARIABLE_DECLARATOR@37..40 + SINGLE_PATTERN@37..40 + NAME@37..40 + IDENT@37..40 "bar" + COMMA@40..41 "," + WHITESPACE@41..42 " " + JS_VARIABLE_DECLARATOR@42..45 + SINGLE_PATTERN@42..45 + NAME@42..45 + IDENT@42..45 "foo" SEMICOLON@45..46 ";" WHITESPACE@46..47 "\n" - VAR_DECL@47..59 - CONST_KW@47..52 "const" - WHITESPACE@52..53 " " - LIST@53..58 - DECLARATOR@53..58 - SINGLE_PATTERN@53..54 - NAME@53..54 - IDENT@53..54 "a" - WHITESPACE@54..55 " " - EQ@55..56 "=" - WHITESPACE@56..57 " " - LITERAL@57..58 - NUMBER@57..58 "5" + JS_VARIABLE_DECLARATION_STATEMENT@47..59 + JS_VARIABLE_DECLARATION@47..58 + CONST_KW@47..52 "const" + WHITESPACE@52..53 " " + LIST@53..58 + JS_VARIABLE_DECLARATOR@53..58 + SINGLE_PATTERN@53..54 + NAME@53..54 + IDENT@53..54 "a" + WHITESPACE@54..55 " " + JS_EQUAL_VALUE_CLAUSE@55..58 + EQ@55..56 "=" + WHITESPACE@56..57 " " + LITERAL@57..58 + NUMBER@57..58 "5" SEMICOLON@58..59 ";" WHITESPACE@59..60 "\n" - VAR_DECL@60..91 - CONST_KW@60..65 "const" - WHITESPACE@65..66 " " - LIST@66..90 - DECLARATOR@66..90 - OBJECT_PATTERN@66..85 - L_CURLY@66..67 "{" - WHITESPACE@67..68 " " - LIST@68..83 - KEY_VALUE_PATTERN@68..78 - NAME@68..71 - IDENT@68..71 "foo" - COLON@71..72 ":" - WHITESPACE@72..73 " " - ARRAY_PATTERN@73..78 - L_BRACK@73..74 "[" - LIST@74..77 - SINGLE_PATTERN@74..77 - NAME@74..77 - IDENT@74..77 "bar" - R_BRACK@77..78 "]" - COMMA@78..79 "," - WHITESPACE@79..80 " " - SINGLE_PATTERN@80..83 - NAME@80..83 - IDENT@80..83 "baz" - WHITESPACE@83..84 " " - R_CURLY@84..85 "}" - WHITESPACE@85..86 " " - EQ@86..87 "=" - WHITESPACE@87..88 " " - OBJECT_EXPR@88..90 - L_CURLY@88..89 "{" - LIST@89..89 - R_CURLY@89..90 "}" + JS_VARIABLE_DECLARATION_STATEMENT@60..91 + JS_VARIABLE_DECLARATION@60..90 + CONST_KW@60..65 "const" + WHITESPACE@65..66 " " + LIST@66..90 + JS_VARIABLE_DECLARATOR@66..90 + OBJECT_PATTERN@66..85 + L_CURLY@66..67 "{" + WHITESPACE@67..68 " " + LIST@68..83 + KEY_VALUE_PATTERN@68..78 + NAME@68..71 + IDENT@68..71 "foo" + COLON@71..72 ":" + WHITESPACE@72..73 " " + ARRAY_PATTERN@73..78 + L_BRACK@73..74 "[" + LIST@74..77 + SINGLE_PATTERN@74..77 + NAME@74..77 + IDENT@74..77 "bar" + R_BRACK@77..78 "]" + COMMA@78..79 "," + WHITESPACE@79..80 " " + SINGLE_PATTERN@80..83 + NAME@80..83 + IDENT@80..83 "baz" + WHITESPACE@83..84 " " + R_CURLY@84..85 "}" + WHITESPACE@85..86 " " + JS_EQUAL_VALUE_CLAUSE@86..90 + EQ@86..87 "=" + WHITESPACE@87..88 " " + OBJECT_EXPR@88..90 + L_CURLY@88..89 "{" + LIST@89..89 + R_CURLY@89..90 "}" SEMICOLON@90..91 ";" - WHITESPACE@91..92 "\n" + WHITESPACE@91..92 "\n" + JS_VARIABLE_DECLARATION_STATEMENT@92..154 + JS_VARIABLE_DECLARATION@92..153 + LET_KW@92..95 "let" + WHITESPACE@95..96 " " + LIST@96..153 + JS_VARIABLE_DECLARATOR@96..109 + SINGLE_PATTERN@96..99 + NAME@96..99 + IDENT@96..99 "foo" + WHITESPACE@99..100 " " + JS_EQUAL_VALUE_CLAUSE@100..109 + EQ@100..101 "=" + WHITESPACE@101..102 " " + LITERAL@102..109 + STRING@102..109 "\"lorem\"" + COMMA@109..110 "," + WHITESPACE@110..111 " " + JS_VARIABLE_DECLARATOR@111..124 + SINGLE_PATTERN@111..114 + NAME@111..114 + IDENT@111..114 "bar" + WHITESPACE@114..115 " " + JS_EQUAL_VALUE_CLAUSE@115..124 + EQ@115..116 "=" + WHITESPACE@116..117 " " + LITERAL@117..124 + STRING@117..124 "\"ipsum\"" + COMMA@124..125 "," + WHITESPACE@125..126 " " + JS_VARIABLE_DECLARATOR@126..141 + SINGLE_PATTERN@126..131 + NAME@126..131 + IDENT@126..131 "third" + WHITESPACE@131..132 " " + JS_EQUAL_VALUE_CLAUSE@132..141 + EQ@132..133 "=" + WHITESPACE@133..134 " " + LITERAL@134..141 + STRING@134..141 "\"value\"" + COMMA@141..142 "," + WHITESPACE@142..143 " " + JS_VARIABLE_DECLARATOR@143..153 + SINGLE_PATTERN@143..149 + NAME@143..149 + IDENT@143..149 "fourth" + WHITESPACE@149..150 " " + JS_EQUAL_VALUE_CLAUSE@150..153 + EQ@150..151 "=" + WHITESPACE@151..152 " " + LITERAL@152..153 + NUMBER@152..153 "6" + SEMICOLON@153..154 ";" + WHITESPACE@154..155 "\n" diff --git a/crates/rslint_syntax/src/generated.rs b/crates/rslint_syntax/src/generated.rs index 7d9d5885fcc..bdddef3cc3b 100644 --- a/crates/rslint_syntax/src/generated.rs +++ b/crates/rslint_syntax/src/generated.rs @@ -163,8 +163,10 @@ pub enum SyntaxKind { JS_DIRECTIVE, ERROR, JS_BLOCK_STATEMENT, - VAR_DECL, - DECLARATOR, + JS_VARIABLE_DECLARATION_STATEMENT, + JS_VARIABLE_DECLARATION, + JS_VARIABLE_DECLARATOR, + JS_EQUAL_VALUE_CLAUSE, JS_EMPTY_STATEMENT, EXPR, JS_EXPRESSION_STATEMENT, diff --git a/xtask/js.ungram b/xtask/js.ungram index b80612a80fc..f0e340d2ef3 100644 --- a/xtask/js.ungram +++ b/xtask/js.ungram @@ -142,7 +142,7 @@ ForStmt = cons:JsAnyStatement ForStmtInit = inner:ForHead ';' -ForHead = VarDecl | JsAnyExpression +ForHead = JsVariableDeclaration | JsAnyExpression ForStmtTest = expr:JsAnyExpression ';' @@ -275,7 +275,7 @@ Template = '`' // This Expression ThisExpr = 'this' -// Dot exprssion +// Dot expression // TODO: review the 'super' token // https://github.com/rome/tools/issues/1729 DotExpr = 'super'? object:JsAnyExpression '.' prop:Name @@ -289,13 +289,13 @@ CallExpr = type_args:TsTypeArgs? callee:JsAnyExpression arguments:ArgList // await expression AwaitExpr = 'await' expr: JsAnyExpression -// yield expressoin +// yield expression YieldExpr = 'yield' '*'? value:JsAnyExpression // super call expression SuperCall = 'super' arguments:ArgList -// import call exression +// import call expression ImportCall = 'import' '(' argument:JsAnyExpression ')' // new target expression @@ -601,7 +601,7 @@ NameRef = 'ident' Decl = FnDecl | ClassDecl - | VarDecl + | JsVariableDeclarationStatement | TsEnum | TsTypeAliasDecl | TsNamespaceDecl @@ -619,13 +619,22 @@ FnDecl = return_type:TsType? body:JsBlockStatement -VarDecl = ('var' | 'const' | manual__:'let') declared:(Declarator (',' Declarator)*) ';'? + +JsVariableDeclarationStatement = + declaration: JsVariableDeclaration ';'? + +JsVariableDeclaration = + kind_token: ('var' | 'const' | 'let') + declarators: (JsVariableDeclarator (',' JsVariableDeclarator)*) + +JsVariableDeclarator = + // TODO 1725 change to `JsAnyBinding` + id: Pattern + init: JsEqualValueClause? // @ematipico: should we consider ClassDecl = ClassExpr ? ClassDecl = 'class' name: Name ('extends' parent:NameRef)? body:ClassBody -Declarator = pattern:Pattern '!' '=' value:JsAnyExpression - /////////////// // MODULE SYNTAX @@ -687,6 +696,19 @@ WildcardImport = '*' 'as'? ident: Ident? // @ematipico this one is not entirely correct I think.. ExportNamed = 'export' 'type'? 'from'? '{' specifiers:(Specifier (',' Specifier)* ','?) * '}' +/////////////// +// AUXILIARY +/////////////// + + +// let a = 10; +// ^^^^ +// class { a = 10; } +// ^^^^ +JsEqualValueClause = + '=' + expression: JsAnyExpression + /////////////// // TYPESCRIPT /////////////// diff --git a/xtask/src/codegen/generate_nodes.rs b/xtask/src/codegen/generate_nodes.rs index c0a613d189f..204fae68a22 100644 --- a/xtask/src/codegen/generate_nodes.rs +++ b/xtask/src/codegen/generate_nodes.rs @@ -45,9 +45,18 @@ pub fn generate_nodes(ast: &AstSrc) -> Result { TokenKind::Many(kinds) => { let tokens = token_kinds_to_code(kinds.as_slice()); let method_name = format_ident!("{}", name); - quote! { - pub fn #method_name(&self) -> Option { - support::find_token(&self.syntax, #tokens) + + if is_optional { + quote! { + pub fn #method_name(&self) -> Option { + support::find_token(&self.syntax, #tokens) + } + } + } else { + quote! { + pub fn #method_name(&self) -> SyntaxResult { + support::find_required_token(&self.syntax, #tokens) + } } } } @@ -56,13 +65,13 @@ pub fn generate_nodes(ast: &AstSrc) -> Result { if is_optional { quote! { pub fn #method_name(&self) -> Option { - support::as_optional_token(&self.syntax, #token_kind_code) + support::token(&self.syntax, #token_kind_code) } } } else { quote! { pub fn #method_name(&self) -> SyntaxResult { - support::as_mandatory_token(&self.syntax, #token_kind_code) + support::required_token(&self.syntax, #token_kind_code) } } } @@ -92,7 +101,7 @@ pub fn generate_nodes(ast: &AstSrc) -> Result { } else if *optional { quote! { pub fn #method_name(&self) -> Option<#ty> { - support::as_optional_node(&self.syntax) + support::node(&self.syntax) } } } else if *has_many { @@ -115,7 +124,7 @@ pub fn generate_nodes(ast: &AstSrc) -> Result { } else { quote! { pub fn #method_name(&self) -> SyntaxResult<#ty> { - support::as_mandatory_node(&self.syntax) + support::required_node(&self.syntax) } } } diff --git a/xtask/src/codegen/kinds_src.rs b/xtask/src/codegen/kinds_src.rs index b06986278a9..47ca92a9995 100644 --- a/xtask/src/codegen/kinds_src.rs +++ b/xtask/src/codegen/kinds_src.rs @@ -171,8 +171,10 @@ pub const KINDS_SRC: KindsSrc = KindsSrc { "JS_DIRECTIVE", "ERROR", "JS_BLOCK_STATEMENT", - "VAR_DECL", - "DECLARATOR", + "JS_VARIABLE_DECLARATION_STATEMENT", + "JS_VARIABLE_DECLARATION", + "JS_VARIABLE_DECLARATOR", + "JS_EQUAL_VALUE_CLAUSE", "JS_EMPTY_STATEMENT", "EXPR", "JS_EXPRESSION_STATEMENT",