From f5c5b465924387f493a00eedad2a496612bc043d Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Tue, 16 Nov 2021 19:34:01 +0000 Subject: [PATCH 01/13] feat: pass error kind via parameter (#1788) --- crates/rslint_parser/src/parser.rs | 27 ++++++++++++++++--- crates/rslint_parser/src/syntax/decl.rs | 1 + crates/rslint_parser/src/syntax/expr.rs | 6 ++--- crates/rslint_parser/src/syntax/object.rs | 4 +-- crates/rslint_parser/src/syntax/pat.rs | 4 ++- crates/rslint_parser/src/syntax/stmt.rs | 9 +++++-- crates/rslint_parser/src/syntax/typescript.rs | 5 +++- 7 files changed, 44 insertions(+), 12 deletions(-) diff --git a/crates/rslint_parser/src/parser.rs b/crates/rslint_parser/src/parser.rs index c7cdb5d32c6..8bb410c7b22 100644 --- a/crates/rslint_parser/src/parser.rs +++ b/crates/rslint_parser/src/parser.rs @@ -180,11 +180,20 @@ impl<'t> Parser<'t> { } /// Recover from an error with a recovery set or by using a `{` or `}`. + /// + /// # Arguments + /// + /// * `error` - the [Diagnostic] to emit + /// * `recovery` - it recovers the parser position is inside a set [tokens](TokenSet) + /// * `include_braces` - it recovers the parser if the current token is a curly brace + /// * `unknown_node` - The kind of the unknown node the parser inserts if it isn't able to recover because + /// the current token is neither in the recovery set nor any of `{` or `}`. pub fn err_recover( &mut self, error: impl Into, recovery: TokenSet, include_braces: bool, + unknown_node: SyntaxKind, ) -> Option<()> { if self.state.no_recovery { return None; @@ -206,12 +215,24 @@ impl<'t> Parser<'t> { let m = self.start(); self.error(error); self.bump_any(); - m.complete(self, SyntaxKind::ERROR); + m.complete(self, unknown_node); Some(()) } /// Recover from an error but don't add an error to the events - pub fn err_recover_no_err(&mut self, recovery: TokenSet, include_braces: bool) { + /// + /// # Arguments + /// + /// * `recovery` - it recovers the parser position is inside a set [tokens](TokenSet) + /// * `include_braces` - it recovers the parser if the current token is a curly brace + /// * `unknown_node` - The kind of the unknown node the parser inserts if it isn't able to recover because + /// the current token is neither in the recovery set nor any of `{` or `}`. + pub fn err_recover_no_err( + &mut self, + recovery: TokenSet, + include_braces: bool, + unknown_node: SyntaxKind, + ) { match self.cur() { T!['{'] | T!['}'] if include_braces => { return; @@ -225,7 +246,7 @@ impl<'t> Parser<'t> { let m = self.start(); self.bump_any(); - m.complete(self, SyntaxKind::ERROR); + m.complete(self, unknown_node); } /// Starts a new node in the syntax tree. All nodes and tokens diff --git a/crates/rslint_parser/src/syntax/decl.rs b/crates/rslint_parser/src/syntax/decl.rs index 071b53b7649..c87c84afe9d 100644 --- a/crates/rslint_parser/src/syntax/decl.rs +++ b/crates/rslint_parser/src/syntax/decl.rs @@ -214,6 +214,7 @@ pub(super) fn parameters_list( T![')'], ], true, + ERROR, ); None } diff --git a/crates/rslint_parser/src/syntax/expr.rs b/crates/rslint_parser/src/syntax/expr.rs index 6da095d7f1c..43ca2c0a828 100644 --- a/crates/rslint_parser/src/syntax/expr.rs +++ b/crates/rslint_parser/src/syntax/expr.rs @@ -716,7 +716,7 @@ pub fn paren_or_arrow_expr(p: &mut Parser, can_be_arrow: bool) -> CompletedMarke let err = temp.err_builder(&format!("expect a closing parenthesis after a spread element, but instead found `{}`", temp.cur_src())) .primary(temp.cur_tok().range, ""); - temp.err_recover(err, EXPR_RECOVERY_SET, false); + temp.err_recover(err, EXPR_RECOVERY_SET, false, ERROR); } } break; @@ -1046,7 +1046,7 @@ pub fn primary_expr(p: &mut Parser) -> Option { let err = p .err_builder("Expected an expression, but found none") .primary(p.cur_tok().range, "Expected an expression here"); - p.err_recover(err, p.state.expr_recovery_set, true); + p.err_recover(err, p.state.expr_recovery_set, true, ERROR); return None; } }; @@ -1066,7 +1066,7 @@ pub fn identifier_reference(p: &mut Parser) -> Option { .err_builder("Expected an identifier, but found none") .primary(p.cur_tok().range, ""); - p.err_recover(err, p.state.expr_recovery_set, true); + p.err_recover(err, p.state.expr_recovery_set, true, ERROR); None } } diff --git a/crates/rslint_parser/src/syntax/object.rs b/crates/rslint_parser/src/syntax/object.rs index 4b19f7a9601..cb5c4178147 100644 --- a/crates/rslint_parser/src/syntax/object.rs +++ b/crates/rslint_parser/src/syntax/object.rs @@ -139,7 +139,7 @@ fn object_member(p: &mut Parser) -> Option { // test_err object_expr_non_ident_literal_prop // let b = {5} - p.err_recover_no_err(token_set![T![:], T![,]], false); + p.err_recover_no_err(token_set![T![:], T![,]], false, ERROR); if p.eat(T![:]) { assign_expr(p); @@ -302,7 +302,7 @@ fn method_object_member_body(p: &mut Parser) -> Result<(), ()> { .err_builder("expected a method definition, but found none") .primary(p.cur_tok().range, ""); - p.err_recover(err, BASE_METHOD_RECOVERY_SET, false); + p.err_recover(err, BASE_METHOD_RECOVERY_SET, false, ERROR); Err(()) }; diff --git a/crates/rslint_parser/src/syntax/pat.rs b/crates/rslint_parser/src/syntax/pat.rs index d490a862daf..a4cc0fff26e 100644 --- a/crates/rslint_parser/src/syntax/pat.rs +++ b/crates/rslint_parser/src/syntax/pat.rs @@ -71,7 +71,7 @@ pub fn pattern(p: &mut Parser, parameters: bool, assignment: bool) -> Option Option>) -> Option return None; } - p.err_recover(err, recovery_set.into().unwrap_or(STMT_RECOVERY_SET), false); + p.err_recover( + err, + recovery_set.into().unwrap_or(STMT_RECOVERY_SET), + false, + ERROR, + ); return None; } }; @@ -989,7 +994,7 @@ fn switch_clause(p: &mut Parser) -> Option> { "Expected the start to a case or default clause here", ); - p.err_recover(err, STMT_RECOVERY_SET, true); + p.err_recover(err, STMT_RECOVERY_SET, true, ERROR); } } None diff --git a/crates/rslint_parser/src/syntax/typescript.rs b/crates/rslint_parser/src/syntax/typescript.rs index 81904ec902d..63ff2b8a12f 100644 --- a/crates/rslint_parser/src/syntax/typescript.rs +++ b/crates/rslint_parser/src/syntax/typescript.rs @@ -592,6 +592,7 @@ pub fn ts_enum(p: &mut Parser) -> CompletedMarker { err, token_set![T!['}'], T![ident], T![yield], T![await], T![=], T![,]], false, + ERROR, ); true } else { @@ -1029,6 +1030,7 @@ pub fn ts_non_array_type(p: &mut Parser) -> Option { T![|] ]), false, + ERROR, ); None } @@ -1126,6 +1128,7 @@ fn type_param(p: &mut Parser) -> Option { err, token_set![T![ident], T![yield], T![await], T![>], T![=]], false, + ERROR, ); None } @@ -1361,6 +1364,6 @@ pub fn ts_type_name( )) .primary(p.cur_tok().range, ""); - p.err_recover(err, set, false)?; + p.err_recover(err, set, false, ERROR)?; None } From f43dfcc3a879b79af174256e25ff48bea204a395 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Fri, 19 Nov 2021 12:59:32 +0000 Subject: [PATCH 02/13] feat: unknown statements (#1794) --- .github/workflows/test262.yml | 2 + crates/rslint_parser/src/lib.rs | 1 + .../rslint_parser/src/lossless_tree_sink.rs | 2 +- crates/rslint_parser/src/parse_recoverer.rs | 94 +++++++++++++++++++ crates/rslint_parser/src/parser.rs | 69 -------------- crates/rslint_parser/src/syntax/decl.rs | 8 +- crates/rslint_parser/src/syntax/expr.rs | 12 ++- crates/rslint_parser/src/syntax/object.rs | 5 +- crates/rslint_parser/src/syntax/pat.rs | 16 ++-- crates/rslint_parser/src/syntax/stmt.rs | 24 ++--- crates/rslint_parser/src/syntax/typescript.rs | 27 +++--- .../inline/err/do_while_stmt_err.rast | 2 +- .../test_data/inline/err/function_broken.js | 1 + .../test_data/inline/err/function_broken.rast | 93 ++++++++++++++++++ .../test_data/inline/err/if_broken.js | 1 + .../test_data/inline/err/if_broken.rast | 54 +++++++++++ .../err/object_expr_error_prop_name.rast | 2 +- .../paren_or_arrow_expr_invalid_params.rast | 8 +- .../inline/err/switch_stmt_double_default.js | 4 + .../err/switch_stmt_double_default.rast | 50 ++++++++++ .../test_data/inline/err/while_stmt_err.rast | 2 +- 21 files changed, 360 insertions(+), 117 deletions(-) create mode 100644 crates/rslint_parser/src/parse_recoverer.rs create mode 100644 crates/rslint_parser/test_data/inline/err/function_broken.js create mode 100644 crates/rslint_parser/test_data/inline/err/function_broken.rast create mode 100644 crates/rslint_parser/test_data/inline/err/if_broken.js create mode 100644 crates/rslint_parser/test_data/inline/err/if_broken.rast create mode 100644 crates/rslint_parser/test_data/inline/err/switch_stmt_double_default.js create mode 100644 crates/rslint_parser/test_data/inline/err/switch_stmt_double_default.rast diff --git a/.github/workflows/test262.yml b/.github/workflows/test262.yml index 38b5635ac73..fd1ea696ddd 100644 --- a/.github/workflows/test262.yml +++ b/.github/workflows/test262.yml @@ -6,6 +6,8 @@ on: pull_request: branches: - main + # enable this job on this temporary branch + - feature/unknown-nodes-errors env: RUST_LOG: info diff --git a/crates/rslint_parser/src/lib.rs b/crates/rslint_parser/src/lib.rs index f52bc35f776..15432522d1f 100644 --- a/crates/rslint_parser/src/lib.rs +++ b/crates/rslint_parser/src/lib.rs @@ -64,6 +64,7 @@ mod lossless_tree_sink; mod lossy_tree_sink; mod numbers; mod parse; +pub(crate) mod parse_recoverer; mod state; mod syntax_node; mod token_source; diff --git a/crates/rslint_parser/src/lossless_tree_sink.rs b/crates/rslint_parser/src/lossless_tree_sink.rs index 55d1a1fb95f..2c8f8b160e0 100644 --- a/crates/rslint_parser/src/lossless_tree_sink.rs +++ b/crates/rslint_parser/src/lossless_tree_sink.rs @@ -108,7 +108,7 @@ impl<'a> TreeSink for LosslessTreeSink<'a> { it.kind, self.text .get(start..end) - .unwrap_or_else(|| self.text.get(start - 1..end).unwrap()), + .unwrap_or_else(|| self.text.get(start - 1..end).unwrap_or("")), ) }); n_attached_trivias(kind, leading_trivias.rev()) diff --git a/crates/rslint_parser/src/parse_recoverer.rs b/crates/rslint_parser/src/parse_recoverer.rs new file mode 100644 index 00000000000..c7959fcf9b4 --- /dev/null +++ b/crates/rslint_parser/src/parse_recoverer.rs @@ -0,0 +1,94 @@ +use crate::{Parser, ParserError, TokenSet}; +use rslint_errors::Diagnostic; +use rslint_lexer::{SyntaxKind, T}; + +/// This struct contains the information needed to the parser to recover from a certain error +/// +/// By default it doesn't check curly braces, use [with_braces_included] to turn opt-in the check +#[derive(Debug)] +pub struct ParseRecoverer { + /// The [Diagnostic] to emit + error: Option, + /// It tells the parser to recover if the position is inside a set of [tokens](TokenSet) + recovery: TokenSet, + /// It tells the parser to recover if the current token is a curly brace + include_braces: bool, + /// The kind of the unknown node the parser inserts if it isn't able to recover because + /// the current token is neither in the recovery set nor any of `{` or `}`. + unknown_node_kind: SyntaxKind, +} + +impl ParseRecoverer { + pub fn new(recovery: TokenSet, unknown_node_kind: SyntaxKind) -> Self { + Self { + error: None, + recovery, + include_braces: false, + unknown_node_kind, + } + } + + pub fn with_error>( + recovery: TokenSet, + unknown_node_kind: SyntaxKind, + error: Err, + ) -> Self { + Self { + error: Some(error.into()), + recovery, + include_braces: false, + unknown_node_kind, + } + } + + /// Enable check of curly braces as recovery tokens + pub fn enabled_braces_check(mut self) -> Self { + self.include_braces = true; + self + } + + /// The main function that tells to the parser how to recover itself. + /// + /// Recover from an error with a [recovery set](TokenSet) or by using a `{` or `}`. + /// + /// If [ParserRecoverer] has an error, it gets tracked in the events. + pub fn recover(&self, p: &mut Parser) { + let error = self.get_error(); + if let Some(error) = error { + p.error(error); + } else { + // the check on state should be done only when there's no error + if p.state.no_recovery { + return; + } + } + if !self.parsing_is_recoverable(p) { + let m = p.start(); + p.bump_any(); + m.complete(p, self.get_unknown_node_kind()); + } + } + + /// Checks if the parsing phase is recoverable by checking curly braces and [tokens set](TokenSet) + fn parsing_is_recoverable(&self, parser: &Parser) -> bool { + self.is_at_token_set(parser) || self.is_at_braces(parser) + } + + /// It returns the diagnostic + fn get_error(&self) -> Option { + self.error.to_owned() + } + + /// It returns the unknown node kind that will be used to complete the parsing + fn get_unknown_node_kind(&self) -> SyntaxKind { + self.unknown_node_kind + } + + fn is_at_braces(&self, parser: &Parser) -> bool { + matches!(parser.cur(), T!['{'] | T!['}'] if self.include_braces) + } + + fn is_at_token_set(&self, parser: &Parser) -> bool { + parser.at_ts(self.recovery) + } +} diff --git a/crates/rslint_parser/src/parser.rs b/crates/rslint_parser/src/parser.rs index 8bb410c7b22..743147eb967 100644 --- a/crates/rslint_parser/src/parser.rs +++ b/crates/rslint_parser/src/parser.rs @@ -179,75 +179,6 @@ impl<'t> Parser<'t> { true } - /// Recover from an error with a recovery set or by using a `{` or `}`. - /// - /// # Arguments - /// - /// * `error` - the [Diagnostic] to emit - /// * `recovery` - it recovers the parser position is inside a set [tokens](TokenSet) - /// * `include_braces` - it recovers the parser if the current token is a curly brace - /// * `unknown_node` - The kind of the unknown node the parser inserts if it isn't able to recover because - /// the current token is neither in the recovery set nor any of `{` or `}`. - pub fn err_recover( - &mut self, - error: impl Into, - recovery: TokenSet, - include_braces: bool, - unknown_node: SyntaxKind, - ) -> Option<()> { - if self.state.no_recovery { - return None; - } - - match self.cur() { - T!['{'] | T!['}'] if include_braces => { - self.error(error); - return Some(()); - } - _ => (), - } - - if self.at_ts(recovery) { - self.error(error); - return Some(()); - } - - let m = self.start(); - self.error(error); - self.bump_any(); - m.complete(self, unknown_node); - Some(()) - } - - /// Recover from an error but don't add an error to the events - /// - /// # Arguments - /// - /// * `recovery` - it recovers the parser position is inside a set [tokens](TokenSet) - /// * `include_braces` - it recovers the parser if the current token is a curly brace - /// * `unknown_node` - The kind of the unknown node the parser inserts if it isn't able to recover because - /// the current token is neither in the recovery set nor any of `{` or `}`. - pub fn err_recover_no_err( - &mut self, - recovery: TokenSet, - include_braces: bool, - unknown_node: SyntaxKind, - ) { - match self.cur() { - T!['{'] | T!['}'] if include_braces => { - return; - } - _ => (), - } - - if self.at_ts(recovery) { - return; - } - - let m = self.start(); - self.bump_any(); - m.complete(self, unknown_node); - } /// Starts a new node in the syntax tree. All nodes and tokens /// consumed between the `start` and the corresponding `Marker::complete` diff --git a/crates/rslint_parser/src/syntax/decl.rs b/crates/rslint_parser/src/syntax/decl.rs index c87c84afe9d..48c2662fcff 100644 --- a/crates/rslint_parser/src/syntax/decl.rs +++ b/crates/rslint_parser/src/syntax/decl.rs @@ -3,6 +3,7 @@ use super::expr::{assign_expr, identifier_name}; use super::pat::pattern; use super::typescript::*; +use crate::parse_recoverer::ParseRecoverer; use crate::syntax::function::function_body; use crate::{SyntaxKind::*, *}; @@ -203,7 +204,7 @@ pub(super) fn parameters_list( } Some(res) } else { - p.err_recover_no_err( + ParseRecoverer::new( token_set![ T![ident], T![await], @@ -213,9 +214,10 @@ pub(super) fn parameters_list( T![...], T![')'], ], - true, ERROR, - ); + ) + .enabled_braces_check() + .recover(p); None } }; diff --git a/crates/rslint_parser/src/syntax/expr.rs b/crates/rslint_parser/src/syntax/expr.rs index 43ca2c0a828..063f2c01da3 100644 --- a/crates/rslint_parser/src/syntax/expr.rs +++ b/crates/rslint_parser/src/syntax/expr.rs @@ -7,6 +7,7 @@ use super::decl::{arrow_body, maybe_private_name, parameter_list}; use super::pat::pattern; use super::typescript::*; use super::util::*; +use crate::parse_recoverer::ParseRecoverer; use crate::syntax::class::class_expression; use crate::syntax::function::function_expression; use crate::syntax::object::object_expr; @@ -716,7 +717,8 @@ pub fn paren_or_arrow_expr(p: &mut Parser, can_be_arrow: bool) -> CompletedMarke let err = temp.err_builder(&format!("expect a closing parenthesis after a spread element, but instead found `{}`", temp.cur_src())) .primary(temp.cur_tok().range, ""); - temp.err_recover(err, EXPR_RECOVERY_SET, false, ERROR); + ParseRecoverer::with_error(EXPR_RECOVERY_SET, ERROR, err) + .recover(&mut temp); } } break; @@ -1046,7 +1048,9 @@ pub fn primary_expr(p: &mut Parser) -> Option { let err = p .err_builder("Expected an expression, but found none") .primary(p.cur_tok().range, "Expected an expression here"); - p.err_recover(err, p.state.expr_recovery_set, true, ERROR); + ParseRecoverer::with_error(p.state.expr_recovery_set, ERROR, err) + .enabled_braces_check() + .recover(p); return None; } }; @@ -1066,7 +1070,9 @@ pub fn identifier_reference(p: &mut Parser) -> Option { .err_builder("Expected an identifier, but found none") .primary(p.cur_tok().range, ""); - p.err_recover(err, p.state.expr_recovery_set, true, ERROR); + ParseRecoverer::with_error(p.state.expr_recovery_set, ERROR, err) + .enabled_braces_check() + .recover(p); None } } diff --git a/crates/rslint_parser/src/syntax/object.rs b/crates/rslint_parser/src/syntax/object.rs index cb5c4178147..c52a2431c74 100644 --- a/crates/rslint_parser/src/syntax/object.rs +++ b/crates/rslint_parser/src/syntax/object.rs @@ -1,3 +1,4 @@ +use crate::parse_recoverer::ParseRecoverer; use crate::syntax::decl::{formal_param_pat, parameter_list, BASE_METHOD_RECOVERY_SET}; use crate::syntax::expr::{assign_expr, expr, identifier_name, literal}; use crate::syntax::function::{function_body, ts_parameter_types, ts_return_type}; @@ -139,7 +140,7 @@ fn object_member(p: &mut Parser) -> Option { // test_err object_expr_non_ident_literal_prop // let b = {5} - p.err_recover_no_err(token_set![T![:], T![,]], false, ERROR); + ParseRecoverer::new(token_set![T![:], T![,]], ERROR).recover(p); if p.eat(T![:]) { assign_expr(p); @@ -302,7 +303,7 @@ fn method_object_member_body(p: &mut Parser) -> Result<(), ()> { .err_builder("expected a method definition, but found none") .primary(p.cur_tok().range, ""); - p.err_recover(err, BASE_METHOD_RECOVERY_SET, false, ERROR); + ParseRecoverer::with_error(BASE_METHOD_RECOVERY_SET, ERROR, err).recover(p); Err(()) }; diff --git a/crates/rslint_parser/src/syntax/pat.rs b/crates/rslint_parser/src/syntax/pat.rs index a4cc0fff26e..e8e7c4a484e 100644 --- a/crates/rslint_parser/src/syntax/pat.rs +++ b/crates/rslint_parser/src/syntax/pat.rs @@ -1,6 +1,6 @@ use super::expr::{assign_expr, identifier_name, identifier_reference, lhs_expr}; use crate::syntax::object::object_prop_name; -use crate::{SyntaxKind::*, *}; +use crate::{parse_recoverer::ParseRecoverer, SyntaxKind::*, *}; pub fn pattern(p: &mut Parser, parameters: bool, assignment: bool) -> Option { Some(match p.cur() { @@ -71,7 +71,7 @@ pub fn pattern(p: &mut Parser, parameters: bool, assignment: bool) -> Option Option>) -> Option // We must explicitly handle this case or else infinite recursion can happen if p.at_ts(token_set![T!['}'], T![import], T![export]]) { - p.err_and_bump(err, ERROR); + p.err_and_bump(err, JS_UNKNOWN_STATEMENT); return None; } - - p.err_recover( - err, + ParseRecoverer::with_error( recovery_set.into().unwrap_or(STMT_RECOVERY_SET), - false, - ERROR, - ); + JS_UNKNOWN_STATEMENT, + err, + ) + .recover(p); return None; } }; @@ -994,7 +994,9 @@ fn switch_clause(p: &mut Parser) -> Option> { "Expected the start to a case or default clause here", ); - p.err_recover(err, STMT_RECOVERY_SET, true, ERROR); + ParseRecoverer::with_error(STMT_RECOVERY_SET, JS_UNKNOWN_STATEMENT, err) + .enabled_braces_check() + .recover(p); } } None @@ -1029,7 +1031,7 @@ pub fn switch_stmt(p: &mut Parser) -> CompletedMarker { break_allowed: true, ..p.state.clone() }); - if let Some(range) = switch_clause(&mut *temp) { + if let Some(default_range) = switch_clause(&mut *temp) { if let Some(ref err_range) = first_default { let err = temp .err_builder( @@ -1039,11 +1041,11 @@ pub fn switch_stmt(p: &mut Parser) -> CompletedMarker { err_range.to_owned(), "the first default clause is defined here", ) - .primary(range, "a second clause here is not allowed"); + .primary(default_range, "a second clause here is not allowed"); temp.error(err); } else { - first_default = Some(range); + first_default = Some(default_range); } } } diff --git a/crates/rslint_parser/src/syntax/typescript.rs b/crates/rslint_parser/src/syntax/typescript.rs index 63ff2b8a12f..2f43b4f0431 100644 --- a/crates/rslint_parser/src/syntax/typescript.rs +++ b/crates/rslint_parser/src/syntax/typescript.rs @@ -3,6 +3,7 @@ use super::decl::*; use super::expr::{assign_expr, identifier_name, lhs_expr, literal}; use super::stmt::{semi, statements, variable_declaration_statement}; +use crate::parse_recoverer::ParseRecoverer; use crate::syntax::class::class_declaration; use crate::syntax::function::function_declaration; use crate::{SyntaxKind::*, *}; @@ -588,12 +589,12 @@ pub fn ts_enum(p: &mut Parser) -> CompletedMarker { .err_builder("expected an identifier or string for an enum variant, but found none") .primary(p.cur_tok().range, ""); - p.err_recover( - err, + ParseRecoverer::with_error( token_set![T!['}'], T![ident], T![yield], T![await], T![=], T![,]], - false, ERROR, - ); + err, + ) + .recover(p); true } else { if !p.eat(JS_STRING_LITERAL_TOKEN) { @@ -1010,8 +1011,7 @@ pub fn ts_non_array_type(p: &mut Parser) -> Option { .err_builder("expected a type") .primary(p.cur_tok().range, ""); - p.err_recover( - err, + ParseRecoverer::with_error( BASE_TS_RECOVERY_SET.union(token_set![ T![typeof], T!['{'], @@ -1029,9 +1029,10 @@ pub fn ts_non_array_type(p: &mut Parser) -> Option { T![&], T![|] ]), - false, ERROR, - ); + err, + ) + .recover(p); None } } @@ -1124,12 +1125,12 @@ fn type_param(p: &mut Parser) -> Option { .err_builder("expected a type parameter, but found none") .primary(p.cur_tok().range, ""); - p.err_recover( - err, + ParseRecoverer::with_error( token_set![T![ident], T![yield], T![await], T![>], T![=]], - false, ERROR, - ); + err, + ) + .recover(p); None } } @@ -1364,6 +1365,6 @@ pub fn ts_type_name( )) .primary(p.cur_tok().range, ""); - p.err_recover(err, set, false, ERROR)?; + ParseRecoverer::with_error(set, ERROR, err).recover(p); None } diff --git a/crates/rslint_parser/test_data/inline/err/do_while_stmt_err.rast b/crates/rslint_parser/test_data/inline/err/do_while_stmt_err.rast index 48490b109b0..2ffa492e548 100644 --- a/crates/rslint_parser/test_data/inline/err/do_while_stmt_err.rast +++ b/crates/rslint_parser/test_data/inline/err/do_while_stmt_err.rast @@ -30,7 +30,7 @@ JS_ROOT@0..42 JS_BOOLEAN_LITERAL@37..41 TRUE_KW@37..41 "true" WHITESPACE@41..42 "\n" - ERROR@42..42 + JS_UNKNOWN_STATEMENT@42..42 ERROR@42..42 ERROR@42..42 ERROR@42..42 diff --git a/crates/rslint_parser/test_data/inline/err/function_broken.js b/crates/rslint_parser/test_data/inline/err/function_broken.js new file mode 100644 index 00000000000..046ecf3ecb7 --- /dev/null +++ b/crates/rslint_parser/test_data/inline/err/function_broken.js @@ -0,0 +1 @@ +function foo())})}{{{ {} diff --git a/crates/rslint_parser/test_data/inline/err/function_broken.rast b/crates/rslint_parser/test_data/inline/err/function_broken.rast new file mode 100644 index 00000000000..9b3785e120a --- /dev/null +++ b/crates/rslint_parser/test_data/inline/err/function_broken.rast @@ -0,0 +1,93 @@ +JS_ROOT@0..26 + LIST@0..0 + LIST@0..25 + JS_FUNCTION_DECLARATION@0..14 + FUNCTION_KW@0..8 "function" + WHITESPACE@8..9 " " + JS_IDENTIFIER_BINDING@9..12 + IDENT@9..12 "foo" + JS_PARAMETER_LIST@12..14 + L_PAREN@12..13 "(" + LIST@13..13 + R_PAREN@13..14 ")" + JS_UNKNOWN_STATEMENT@14..15 + R_PAREN@14..15 ")" + JS_UNKNOWN_STATEMENT@15..16 + R_CURLY@15..16 "}" + JS_UNKNOWN_STATEMENT@16..17 + R_PAREN@16..17 ")" + JS_UNKNOWN_STATEMENT@17..18 + R_CURLY@17..18 "}" + JS_BLOCK_STATEMENT@18..25 + L_CURLY@18..19 "{" + LIST@19..25 + JS_BLOCK_STATEMENT@19..25 + L_CURLY@19..20 "{" + LIST@20..25 + JS_BLOCK_STATEMENT@20..25 + L_CURLY@20..21 "{" + WHITESPACE@21..23 " " + LIST@23..25 + JS_BLOCK_STATEMENT@23..25 + L_CURLY@23..24 "{" + LIST@24..24 + R_CURLY@24..25 "}" + WHITESPACE@25..26 "\n" +-- +error[SyntaxError]: expected a block statement but instead found `)` + ┌─ function_broken.js:1:15 + │ +1 │ function foo())})}{{{ {} + │ ^ + +-- +error[SyntaxError]: Expected a statement or declaration, but found none + ┌─ function_broken.js:1:15 + │ +1 │ function foo())})}{{{ {} + │ ^ Expected a statement or declaration here + +-- +error[SyntaxError]: Expected a statement or declaration, but found none + ┌─ function_broken.js:1:16 + │ +1 │ function foo())})}{{{ {} + │ ^ Expected a statement or declaration here + +-- +error[SyntaxError]: Expected a statement or declaration, but found none + ┌─ function_broken.js:1:17 + │ +1 │ function foo())})}{{{ {} + │ ^ Expected a statement or declaration here + +-- +error[SyntaxError]: Expected a statement or declaration, but found none + ┌─ function_broken.js:1:18 + │ +1 │ function foo())})}{{{ {} + │ ^ Expected a statement or declaration here + +-- +error[SyntaxError]: expected `'}'` but instead the file ends + ┌─ function_broken.js:2:1 + │ +2 │ + │ ^ the file ends here + +-- +error[SyntaxError]: expected `'}'` but instead the file ends + ┌─ function_broken.js:2:1 + │ +2 │ + │ ^ the file ends here + +-- +error[SyntaxError]: expected `'}'` but instead the file ends + ┌─ function_broken.js:2:1 + │ +2 │ + │ ^ the file ends here + +-- +function foo())})}{{{ {} diff --git a/crates/rslint_parser/test_data/inline/err/if_broken.js b/crates/rslint_parser/test_data/inline/err/if_broken.js new file mode 100644 index 00000000000..a571f99a0cb --- /dev/null +++ b/crates/rslint_parser/test_data/inline/err/if_broken.js @@ -0,0 +1 @@ +if (true)}}}} {} diff --git a/crates/rslint_parser/test_data/inline/err/if_broken.rast b/crates/rslint_parser/test_data/inline/err/if_broken.rast new file mode 100644 index 00000000000..da39eceba34 --- /dev/null +++ b/crates/rslint_parser/test_data/inline/err/if_broken.rast @@ -0,0 +1,54 @@ +JS_ROOT@0..17 + LIST@0..0 + LIST@0..16 + JS_IF_STATEMENT@0..10 + IF_KW@0..2 "if" + WHITESPACE@2..3 " " + L_PAREN@3..4 "(" + JS_BOOLEAN_LITERAL@4..8 + TRUE_KW@4..8 "true" + R_PAREN@8..9 ")" + JS_UNKNOWN_STATEMENT@9..10 + R_CURLY@9..10 "}" + JS_UNKNOWN_STATEMENT@10..11 + R_CURLY@10..11 "}" + JS_UNKNOWN_STATEMENT@11..12 + R_CURLY@11..12 "}" + JS_UNKNOWN_STATEMENT@12..13 + R_CURLY@12..13 "}" + WHITESPACE@13..14 " " + JS_BLOCK_STATEMENT@14..16 + L_CURLY@14..15 "{" + LIST@15..15 + R_CURLY@15..16 "}" + WHITESPACE@16..17 "\n" +-- +error[SyntaxError]: Expected a statement or declaration, but found none + ┌─ if_broken.js:1:10 + │ +1 │ if (true)}}}} {} + │ ^ Expected a statement or declaration here + +-- +error[SyntaxError]: Expected a statement or declaration, but found none + ┌─ if_broken.js:1:11 + │ +1 │ if (true)}}}} {} + │ ^ Expected a statement or declaration here + +-- +error[SyntaxError]: Expected a statement or declaration, but found none + ┌─ if_broken.js:1:12 + │ +1 │ if (true)}}}} {} + │ ^ Expected a statement or declaration here + +-- +error[SyntaxError]: Expected a statement or declaration, but found none + ┌─ if_broken.js:1:13 + │ +1 │ if (true)}}}} {} + │ ^ Expected a statement or declaration here + +-- +if (true)}}}} {} 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 67cc86acc50..1c51f7613d2 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 @@ -47,7 +47,7 @@ JS_ROOT@0..40 ERROR@36..37 L_CURLY@36..37 "{" R_CURLY@37..38 "}" - ERROR@38..39 + JS_UNKNOWN_STATEMENT@38..39 R_CURLY@38..39 "}" WHITESPACE@39..40 "\n" -- diff --git a/crates/rslint_parser/test_data/inline/err/paren_or_arrow_expr_invalid_params.rast b/crates/rslint_parser/test_data/inline/err/paren_or_arrow_expr_invalid_params.rast index 33d83171fee..fed2ec8c521 100644 --- a/crates/rslint_parser/test_data/inline/err/paren_or_arrow_expr_invalid_params.rast +++ b/crates/rslint_parser/test_data/inline/err/paren_or_arrow_expr_invalid_params.rast @@ -13,10 +13,10 @@ JS_ROOT@0..28 PLUS@3..4 "+" WHITESPACE@4..5 " " JS_NUMBER_LITERAL_TOKEN@5..6 "5" - ERROR@6..7 + JS_UNKNOWN_STATEMENT@6..7 R_PAREN@6..7 ")" WHITESPACE@7..8 " " - ERROR@8..10 + JS_UNKNOWN_STATEMENT@8..10 FAT_ARROW@8..10 "=>" WHITESPACE@10..11 " " JS_BLOCK_STATEMENT@11..13 @@ -37,10 +37,10 @@ JS_ROOT@0..28 JS_EXPRESSION_STATEMENT@19..20 JS_REFERENCE_IDENTIFIER_EXPRESSION@19..20 IDENT@19..20 "b" - ERROR@20..21 + JS_UNKNOWN_STATEMENT@20..21 R_PAREN@20..21 ")" WHITESPACE@21..22 " " - ERROR@22..24 + JS_UNKNOWN_STATEMENT@22..24 FAT_ARROW@22..24 "=>" WHITESPACE@24..25 " " JS_BLOCK_STATEMENT@25..27 diff --git a/crates/rslint_parser/test_data/inline/err/switch_stmt_double_default.js b/crates/rslint_parser/test_data/inline/err/switch_stmt_double_default.js new file mode 100644 index 00000000000..c193c56e2cc --- /dev/null +++ b/crates/rslint_parser/test_data/inline/err/switch_stmt_double_default.js @@ -0,0 +1,4 @@ +switch (foo) { + default: {} + default: {} +} diff --git a/crates/rslint_parser/test_data/inline/err/switch_stmt_double_default.rast b/crates/rslint_parser/test_data/inline/err/switch_stmt_double_default.rast new file mode 100644 index 00000000000..56051b63cef --- /dev/null +++ b/crates/rslint_parser/test_data/inline/err/switch_stmt_double_default.rast @@ -0,0 +1,50 @@ +JS_ROOT@0..43 + LIST@0..0 + LIST@0..42 + JS_SWITCH_STATEMENT@0..42 + SWITCH_KW@0..6 "switch" + WHITESPACE@6..7 " " + L_PAREN@7..8 "(" + JS_REFERENCE_IDENTIFIER_EXPRESSION@8..11 + IDENT@8..11 "foo" + R_PAREN@11..12 ")" + WHITESPACE@12..13 " " + L_CURLY@13..14 "{" + WHITESPACE@14..16 "\n\t" + LIST@16..40 + JS_DEFAULT_CLAUSE@16..27 + DEFAULT_KW@16..23 "default" + COLON@23..24 ":" + WHITESPACE@24..25 " " + LIST@25..27 + JS_BLOCK_STATEMENT@25..27 + L_CURLY@25..26 "{" + LIST@26..26 + R_CURLY@26..27 "}" + WHITESPACE@27..29 "\n\t" + JS_DEFAULT_CLAUSE@29..40 + DEFAULT_KW@29..36 "default" + COLON@36..37 ":" + WHITESPACE@37..38 " " + LIST@38..40 + JS_BLOCK_STATEMENT@38..40 + L_CURLY@38..39 "{" + LIST@39..39 + R_CURLY@39..40 "}" + WHITESPACE@40..41 "\n" + R_CURLY@41..42 "}" + WHITESPACE@42..43 "\n" +-- +error[SyntaxError]: Multiple default clauses inside of a switch statement are not allowed + ┌─ switch_stmt_double_default.js:3:2 + │ +2 │ default: {} + │ ---------- the first default clause is defined here +3 │ default: {} + │ ^^^^^^^^^^ a second clause here is not allowed + +-- +switch (foo) { + default: {} + default: {} +} diff --git a/crates/rslint_parser/test_data/inline/err/while_stmt_err.rast b/crates/rslint_parser/test_data/inline/err/while_stmt_err.rast index 9113dac46b0..c1ffb76583f 100644 --- a/crates/rslint_parser/test_data/inline/err/while_stmt_err.rast +++ b/crates/rslint_parser/test_data/inline/err/while_stmt_err.rast @@ -39,7 +39,7 @@ JS_ROOT@0..52 TRUE_KW@44..48 "true" R_PAREN@48..49 ")" WHITESPACE@49..50 " " - ERROR@50..51 + JS_UNKNOWN_STATEMENT@50..51 R_CURLY@50..51 "}" WHITESPACE@51..52 "\n" -- From 397e567fda2e5f65499edf60ee54a2a1785e6bc0 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Fri, 19 Nov 2021 10:04:53 -0300 Subject: [PATCH 03/13] chore: rebase --- crates/rslint_parser/src/syntax/class.rs | 10 ++++++---- .../test_data/inline/err/block_stmt_in_class.rast | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/rslint_parser/src/syntax/class.rs b/crates/rslint_parser/src/syntax/class.rs index 1c3994e693f..6f83042758b 100644 --- a/crates/rslint_parser/src/syntax/class.rs +++ b/crates/rslint_parser/src/syntax/class.rs @@ -1,3 +1,4 @@ +use crate::parse_recoverer::ParseRecoverer; use crate::syntax::decl::{formal_param_pat, parameter_list, parameters_list}; use crate::syntax::expr::assign_expr; use crate::syntax::function::{function_body, ts_parameter_types, ts_return_type}; @@ -527,11 +528,12 @@ fn class_member(p: &mut Parser) -> Option { let err = p .err_builder("expected `;`, a property, or a method for a class body, but found none") .primary(p.cur_tok().range, ""); - p.err_recover( - err, + ParseRecoverer::with_error( token_set![T![;], T![ident], T![async], T![yield], T!['}'], T![#]], - false, - ); + ERROR, + err, + ) + .recover(p); None } diff --git a/crates/rslint_parser/test_data/inline/err/block_stmt_in_class.rast b/crates/rslint_parser/test_data/inline/err/block_stmt_in_class.rast index f3fc3fde4d9..841e793c9e4 100644 --- a/crates/rslint_parser/test_data/inline/err/block_stmt_in_class.rast +++ b/crates/rslint_parser/test_data/inline/err/block_stmt_in_class.rast @@ -11,7 +11,7 @@ JS_ROOT@0..12 ERROR@8..9 L_CURLY@8..9 "{" R_CURLY@9..10 "}" - ERROR@10..11 + JS_UNKNOWN_STATEMENT@10..11 R_CURLY@10..11 "}" WHITESPACE@11..12 "\n" -- From e53bcd59347044fe42b46ed881dd8b96654c3054 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Fri, 19 Nov 2021 10:36:36 -0300 Subject: [PATCH 04/13] fix: test and format --- crates/rome_formatter/src/ts/statements/statement.rs | 6 ++++-- crates/rslint_parser/src/parser.rs | 1 - 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/rome_formatter/src/ts/statements/statement.rs b/crates/rome_formatter/src/ts/statements/statement.rs index 8e28405f4d2..810b892e3f4 100644 --- a/crates/rome_formatter/src/ts/statements/statement.rs +++ b/crates/rome_formatter/src/ts/statements/statement.rs @@ -1,5 +1,5 @@ use crate::{FormatElement, FormatResult, Formatter, ToFormatElement}; -use rslint_parser::ast::JsAnyStatement; +use rslint_parser::{ast::JsAnyStatement, AstNode}; impl ToFormatElement for JsAnyStatement { fn to_format_element(&self, formatter: &Formatter) -> FormatResult { @@ -54,7 +54,9 @@ impl ToFormatElement for JsAnyStatement { JsAnyStatement::JsVariableDeclarationStatement(decl) => { decl.to_format_element(formatter) } - JsAnyStatement::JsUnknownStatement(_) => todo!(), + JsAnyStatement::JsUnknownStatement(unknown_statement) => { + Ok(formatter.format_raw(unknown_statement.syntax())) + } JsAnyStatement::ImportDecl(_) => todo!(), JsAnyStatement::ExportNamed(_) => todo!(), JsAnyStatement::ExportDefaultDecl(_) => todo!(), diff --git a/crates/rslint_parser/src/parser.rs b/crates/rslint_parser/src/parser.rs index 743147eb967..87ca106f001 100644 --- a/crates/rslint_parser/src/parser.rs +++ b/crates/rslint_parser/src/parser.rs @@ -179,7 +179,6 @@ impl<'t> Parser<'t> { true } - /// Starts a new node in the syntax tree. All nodes and tokens /// consumed between the `start` and the corresponding `Marker::complete` /// belong to the same node. From 79d644f3b8cf0e639e3d01dab6861505cdafc17a Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Thu, 18 Nov 2021 16:38:31 -0300 Subject: [PATCH 05/13] chore: new error test cases --- .../test_data/inline/err/debugger.js | 5 ++ .../test_data/inline/err/debugger.rast | 61 +++++++++++++++++++ .../test_data/inline/err/double_label.js | 5 ++ .../test_data/inline/err/double_label.rast | 48 +++++++++++++++ 4 files changed, 119 insertions(+) create mode 100644 crates/rslint_parser/test_data/inline/err/debugger.js create mode 100644 crates/rslint_parser/test_data/inline/err/debugger.rast create mode 100644 crates/rslint_parser/test_data/inline/err/double_label.js create mode 100644 crates/rslint_parser/test_data/inline/err/double_label.rast diff --git a/crates/rslint_parser/test_data/inline/err/debugger.js b/crates/rslint_parser/test_data/inline/err/debugger.js new file mode 100644 index 00000000000..1ffa5855857 --- /dev/null +++ b/crates/rslint_parser/test_data/inline/err/debugger.js @@ -0,0 +1,5 @@ +function foo() { + debugger { + var something = "lorem"; + } +} diff --git a/crates/rslint_parser/test_data/inline/err/debugger.rast b/crates/rslint_parser/test_data/inline/err/debugger.rast new file mode 100644 index 00000000000..f694deca20b --- /dev/null +++ b/crates/rslint_parser/test_data/inline/err/debugger.rast @@ -0,0 +1,61 @@ +JS_ROOT@0..61 + LIST@0..0 + LIST@0..60 + JS_FUNCTION_DECLARATION@0..60 + FUNCTION_KW@0..8 "function" + WHITESPACE@8..9 " " + JS_IDENTIFIER_BINDING@9..12 + IDENT@9..12 "foo" + JS_PARAMETER_LIST@12..14 + L_PAREN@12..13 "(" + LIST@13..13 + R_PAREN@13..14 ")" + WHITESPACE@14..15 " " + JS_FUNCTION_BODY@15..60 + L_CURLY@15..16 "{" + WHITESPACE@16..18 "\n\t" + LIST@18..18 + LIST@18..58 + JS_DEBUGGER_STATEMENT@18..26 + DEBUGGER_KW@18..26 "debugger" + WHITESPACE@26..27 " " + JS_BLOCK_STATEMENT@27..58 + L_CURLY@27..28 "{" + WHITESPACE@28..31 "\n\t\t" + LIST@31..55 + JS_VARIABLE_DECLARATION_STATEMENT@31..55 + JS_VARIABLE_DECLARATION@31..54 + VAR_KW@31..34 "var" + WHITESPACE@34..35 " " + LIST@35..54 + JS_VARIABLE_DECLARATOR@35..54 + SINGLE_PATTERN@35..44 + NAME@35..44 + IDENT@35..44 "something" + WHITESPACE@44..45 " " + JS_EQUAL_VALUE_CLAUSE@45..54 + EQ@45..46 "=" + WHITESPACE@46..47 " " + JS_STRING_LITERAL@47..54 + JS_STRING_LITERAL_TOKEN@47..54 "\"lorem\"" + SEMICOLON@54..55 ";" + WHITESPACE@55..57 "\n\t" + R_CURLY@57..58 "}" + WHITESPACE@58..59 "\n" + R_CURLY@59..60 "}" + WHITESPACE@60..61 "\n" +-- +error[SyntaxError]: Expected a semicolon or an implicit semicolon after a statement, but found none + ┌─ debugger.js:2:11 + │ +2 │ debugger { + │ -------- ^ An explicit or implicit semicolon is expected here... + │ │ + │ ...Which is required to end this statement + +-- +function foo() { + debugger { + var something = "lorem"; + } +} diff --git a/crates/rslint_parser/test_data/inline/err/double_label.js b/crates/rslint_parser/test_data/inline/err/double_label.js new file mode 100644 index 00000000000..153e974c4b0 --- /dev/null +++ b/crates/rslint_parser/test_data/inline/err/double_label.js @@ -0,0 +1,5 @@ +label1: { + label2: { + label1: {} + } +} diff --git a/crates/rslint_parser/test_data/inline/err/double_label.rast b/crates/rslint_parser/test_data/inline/err/double_label.rast new file mode 100644 index 00000000000..716e312743f --- /dev/null +++ b/crates/rslint_parser/test_data/inline/err/double_label.rast @@ -0,0 +1,48 @@ +JS_ROOT@0..39 + LIST@0..0 + LIST@0..38 + JS_LABELED_STATEMENT@0..38 + IDENT@0..6 "label1" + COLON@6..7 ":" + WHITESPACE@7..8 " " + JS_BLOCK_STATEMENT@8..38 + L_CURLY@8..9 "{" + WHITESPACE@9..11 "\n\t" + LIST@11..36 + JS_LABELED_STATEMENT@11..36 + IDENT@11..17 "label2" + COLON@17..18 ":" + WHITESPACE@18..19 " " + JS_BLOCK_STATEMENT@19..36 + L_CURLY@19..20 "{" + WHITESPACE@20..23 "\n\t\t" + LIST@23..33 + JS_LABELED_STATEMENT@23..33 + IDENT@23..29 "label1" + COLON@29..30 ":" + WHITESPACE@30..31 " " + JS_BLOCK_STATEMENT@31..33 + L_CURLY@31..32 "{" + LIST@32..32 + R_CURLY@32..33 "}" + WHITESPACE@33..35 "\n\t" + R_CURLY@35..36 "}" + WHITESPACE@36..37 "\n" + R_CURLY@37..38 "}" + WHITESPACE@38..39 "\n" +-- +error[SyntaxError]: Duplicate statement labels are not allowed + ┌─ double_label.js:3:3 + │ +1 │ label1: { + │ ------ `label1` is first used as a label here +2 │ label2: { +3 │ label1: {} + │ ^^^^^^ a second use of `label1` here is not allowed + +-- +label1: { + label2: { + label1: {} + } +} From 6792b6957aea6fe962485d180909622574d01244 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Thu, 18 Nov 2021 16:39:25 -0300 Subject: [PATCH 06/13] feat: unknown binding --- crates/rslint_parser/src/syntax/pat.rs | 8 +++++--- crates/rslint_parser/src/syntax/stmt.rs | 3 ++- .../test_data/inline/err/binding_identifier_invalid.rast | 6 +++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/crates/rslint_parser/src/syntax/pat.rs b/crates/rslint_parser/src/syntax/pat.rs index e8e7c4a484e..241b6ec7703 100644 --- a/crates/rslint_parser/src/syntax/pat.rs +++ b/crates/rslint_parser/src/syntax/pat.rs @@ -94,11 +94,13 @@ pub fn opt_binding_identifier(p: &mut Parser) -> Option { // } // let eval = 5; pub fn binding_identifier(p: &mut Parser) -> Option { + let mut kind_to_change = NAME; if p.at(T![yield]) && p.state.in_generator { let err = p .err_builder("Illegal use of `yield` as an identifier in generator function") .primary(p.cur_tok().range, ""); + kind_to_change = JS_UNKNOWN_BINDING; p.error(err); } @@ -106,7 +108,7 @@ pub fn binding_identifier(p: &mut Parser) -> Option { let err = p .err_builder("Illegal use of `await` as an identifier in an async context") .primary(p.cur_tok().range, ""); - + kind_to_change = JS_UNKNOWN_BINDING; p.error(err); } @@ -119,12 +121,12 @@ pub fn binding_identifier(p: &mut Parser) -> Option { p.cur_src() )) .primary(p.cur_tok().range, ""); - + kind_to_change = JS_UNKNOWN_BINDING; p.error(err); } let mut m = identifier_reference(p)?; - m.change_kind(p, NAME); + m.change_kind(p, kind_to_change); Some(m) } diff --git a/crates/rslint_parser/src/syntax/stmt.rs b/crates/rslint_parser/src/syntax/stmt.rs index 62a5640565f..63d6bce7f00 100644 --- a/crates/rslint_parser/src/syntax/stmt.rs +++ b/crates/rslint_parser/src/syntax/stmt.rs @@ -60,6 +60,7 @@ pub fn semi(p: &mut Parser, err_range: Range) { ) .secondary(err_range, "...Which is required to end this statement"); + p.error(err); } } @@ -222,7 +223,7 @@ fn expr_stmt(p: &mut Parser) -> Option { &format!("`{}` is first used as a label here", text), ) .primary( - p.cur_tok().range, + text_range, &format!("a second use of `{}` here is not allowed", text), ); 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 2a8348eeff9..93c57ad0336 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 @@ -24,7 +24,7 @@ JS_ROOT@0..83 LIST@18..27 JS_VARIABLE_DECLARATOR@18..27 SINGLE_PATTERN@18..23 - NAME@18..23 + JS_UNKNOWN_BINDING@18..23 IDENT@18..23 "await" WHITESPACE@23..24 " " JS_EQUAL_VALUE_CLAUSE@24..27 @@ -59,7 +59,7 @@ JS_ROOT@0..83 LIST@56..65 JS_VARIABLE_DECLARATOR@56..65 SINGLE_PATTERN@56..61 - NAME@56..61 + JS_UNKNOWN_BINDING@56..61 IDENT@56..61 "yield" WHITESPACE@61..62 " " JS_EQUAL_VALUE_CLAUSE@62..65 @@ -78,7 +78,7 @@ JS_ROOT@0..83 LIST@73..81 JS_VARIABLE_DECLARATOR@73..81 SINGLE_PATTERN@73..77 - NAME@73..77 + JS_UNKNOWN_BINDING@73..77 IDENT@73..77 "eval" WHITESPACE@77..78 " " JS_EQUAL_VALUE_CLAUSE@78..81 From ab356188f3971d9c12ba6cc3773e192b979279c2 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Fri, 19 Nov 2021 11:24:24 -0300 Subject: [PATCH 07/13] feat: correctly flag unknown binding inside patterns --- crates/rslint_parser/src/syntax/pat.rs | 14 +- .../inline/err/bad_object_pattern.js | 1 + .../inline/err/bad_object_pattern.rast | 71 ++++++++ .../err/formal_params_no_binding_element.rast | 2 +- .../inline/err/function_decl_err.rast | 6 +- .../inline/err/illigal_object_pattern.js | 3 + .../inline/err/illigal_object_pattern.rast | 155 ++++++++++++++++++ .../inline/err/invalid_arg_list.rast | 2 +- .../paren_or_arrow_expr_invalid_params.rast | 2 +- 9 files changed, 244 insertions(+), 12 deletions(-) create mode 100644 crates/rslint_parser/test_data/inline/err/bad_object_pattern.js create mode 100644 crates/rslint_parser/test_data/inline/err/bad_object_pattern.rast create mode 100644 crates/rslint_parser/test_data/inline/err/illigal_object_pattern.js create mode 100644 crates/rslint_parser/test_data/inline/err/illigal_object_pattern.rast diff --git a/crates/rslint_parser/src/syntax/pat.rs b/crates/rslint_parser/src/syntax/pat.rs index 241b6ec7703..55d71b72b74 100644 --- a/crates/rslint_parser/src/syntax/pat.rs +++ b/crates/rslint_parser/src/syntax/pat.rs @@ -64,14 +64,16 @@ pub fn pattern(p: &mut Parser, parameters: bool, assignment: bool) -> Option { + let mut unknown_node_kind = JS_UNKNOWN_BINDING; let err = p .err_builder("Expected an identifier or pattern, but found none") .primary(p.cur_tok().range, ""); let mut ts = token_set![T![ident], T![yield], T![await], T!['['],]; if p.state.allow_object_expr { + unknown_node_kind = JS_UNKNOWN_PATTERN; ts = ts.union(token_set![T!['{']]); } - ParseRecoverer::with_error(ts, ERROR, err).recover(p); + ParseRecoverer::with_error(ts, unknown_node_kind, err).recover(p); return None; } }) @@ -100,7 +102,7 @@ pub fn binding_identifier(p: &mut Parser) -> Option { .err_builder("Illegal use of `yield` as an identifier in generator function") .primary(p.cur_tok().range, ""); - kind_to_change = JS_UNKNOWN_BINDING; + kind_to_change = JS_UNKNOWN_BINDING; p.error(err); } @@ -108,7 +110,7 @@ pub fn binding_identifier(p: &mut Parser) -> Option { let err = p .err_builder("Illegal use of `await` as an identifier in an async context") .primary(p.cur_tok().range, ""); - kind_to_change = JS_UNKNOWN_BINDING; + kind_to_change = JS_UNKNOWN_BINDING; p.error(err); } @@ -121,7 +123,7 @@ pub fn binding_identifier(p: &mut Parser) -> Option { p.cur_src() )) .primary(p.cur_tok().range, ""); - kind_to_change = JS_UNKNOWN_BINDING; + kind_to_change = JS_UNKNOWN_BINDING; p.error(err); } @@ -242,7 +244,7 @@ fn object_binding_prop(p: &mut Parser, parameters: bool) -> Option Option Date: Fri, 19 Nov 2021 11:34:25 -0300 Subject: [PATCH 08/13] feat: correct unknown pattern --- crates/rslint_parser/src/syntax/object.rs | 4 ++-- crates/rslint_parser/src/syntax/pat.rs | 7 ++++++- .../test_data/inline/err/bad_object_pattern.rast | 2 +- .../test_data/inline/err/illigal_object_pattern.rast | 6 +++--- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/crates/rslint_parser/src/syntax/object.rs b/crates/rslint_parser/src/syntax/object.rs index c52a2431c74..10bfa935afa 100644 --- a/crates/rslint_parser/src/syntax/object.rs +++ b/crates/rslint_parser/src/syntax/object.rs @@ -233,7 +233,7 @@ pub(crate) fn computed_member_name(p: &mut Parser) -> CompletedMarker { pub(super) fn literal_member_name(p: &mut Parser) -> Option { let m = p.start(); - + let mut complete_with_this_kind = JS_LITERAL_MEMBER_NAME; match p.cur() { JS_STRING_LITERAL_TOKEN | JS_NUMBER_LITERAL_TOKEN | T![ident] => { p.bump_any(); @@ -252,7 +252,7 @@ pub(super) fn literal_member_name(p: &mut Parser) -> Option { return None; } } - Some(m.complete(p, JS_LITERAL_MEMBER_NAME)) + Some(m.complete(p, complete_with_this_kind)) } /// Parses a method object member diff --git a/crates/rslint_parser/src/syntax/pat.rs b/crates/rslint_parser/src/syntax/pat.rs index 55d71b72b74..2235f96dddc 100644 --- a/crates/rslint_parser/src/syntax/pat.rs +++ b/crates/rslint_parser/src/syntax/pat.rs @@ -251,12 +251,17 @@ fn object_binding_prop(p: &mut Parser, parameters: bool) -> Option Date: Fri, 19 Nov 2021 14:25:32 -0300 Subject: [PATCH 09/13] chore: format --- crates/rslint_parser/src/syntax/object.rs | 3 +-- crates/rslint_parser/src/syntax/stmt.rs | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/rslint_parser/src/syntax/object.rs b/crates/rslint_parser/src/syntax/object.rs index 10bfa935afa..fabcf406c2e 100644 --- a/crates/rslint_parser/src/syntax/object.rs +++ b/crates/rslint_parser/src/syntax/object.rs @@ -233,7 +233,6 @@ pub(crate) fn computed_member_name(p: &mut Parser) -> CompletedMarker { pub(super) fn literal_member_name(p: &mut Parser) -> Option { let m = p.start(); - let mut complete_with_this_kind = JS_LITERAL_MEMBER_NAME; match p.cur() { JS_STRING_LITERAL_TOKEN | JS_NUMBER_LITERAL_TOKEN | T![ident] => { p.bump_any(); @@ -252,7 +251,7 @@ pub(super) fn literal_member_name(p: &mut Parser) -> Option { return None; } } - Some(m.complete(p, complete_with_this_kind)) + Some(m.complete(p, JS_LITERAL_MEMBER_NAME)) } /// Parses a method object member diff --git a/crates/rslint_parser/src/syntax/stmt.rs b/crates/rslint_parser/src/syntax/stmt.rs index 63d6bce7f00..b0aff10dbe1 100644 --- a/crates/rslint_parser/src/syntax/stmt.rs +++ b/crates/rslint_parser/src/syntax/stmt.rs @@ -60,7 +60,6 @@ pub fn semi(p: &mut Parser, err_range: Range) { ) .secondary(err_range, "...Which is required to end this statement"); - p.error(err); } } From a3f1fd21782d24532fab4d3aedbb5bfcf80974ed Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Fri, 19 Nov 2021 15:32:39 -0300 Subject: [PATCH 10/13] feat: better pattern coverage --- crates/rslint_parser/src/syntax/pat.rs | 3 +- .../inline/err/illigal_array_pattern.js | 1 + .../inline/err/illigal_array_pattern.rast | 67 +++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 crates/rslint_parser/test_data/inline/err/illigal_array_pattern.js create mode 100644 crates/rslint_parser/test_data/inline/err/illigal_array_pattern.rast diff --git a/crates/rslint_parser/src/syntax/pat.rs b/crates/rslint_parser/src/syntax/pat.rs index 2235f96dddc..a15cc7c0f12 100644 --- a/crates/rslint_parser/src/syntax/pat.rs +++ b/crates/rslint_parser/src/syntax/pat.rs @@ -173,9 +173,10 @@ pub fn array_binding_pattern( m.complete(p, REST_PATTERN); break; } else if binding_element(p, parameters, assignment).is_none() { + // TODO: find a away to land ParseRecoverer::new( token_set![T![await], T![ident], T![yield], T![:], T![=], T![']']], - ERROR, + JS_UNKNOWN_PATTERN, ) .recover(p); } diff --git a/crates/rslint_parser/test_data/inline/err/illigal_array_pattern.js b/crates/rslint_parser/test_data/inline/err/illigal_array_pattern.js new file mode 100644 index 00000000000..7f50e8a570f --- /dev/null +++ b/crates/rslint_parser/test_data/inline/err/illigal_array_pattern.js @@ -0,0 +1 @@ +let [ default: , hey , ] = [] diff --git a/crates/rslint_parser/test_data/inline/err/illigal_array_pattern.rast b/crates/rslint_parser/test_data/inline/err/illigal_array_pattern.rast new file mode 100644 index 00000000000..83034f161c3 --- /dev/null +++ b/crates/rslint_parser/test_data/inline/err/illigal_array_pattern.rast @@ -0,0 +1,67 @@ +JS_ROOT@0..30 + LIST@0..0 + LIST@0..29 + JS_VARIABLE_DECLARATION_STATEMENT@0..29 + JS_VARIABLE_DECLARATION@0..29 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..29 + JS_VARIABLE_DECLARATOR@4..29 + ARRAY_PATTERN@4..24 + L_BRACK@4..5 "[" + WHITESPACE@5..6 " " + LIST@6..22 + JS_UNKNOWN_PATTERN@6..13 + DEFAULT_KW@6..13 "default" + JS_UNKNOWN_PATTERN@13..14 + COLON@13..14 ":" + WHITESPACE@14..15 " " + JS_UNKNOWN_PATTERN@15..16 + COMMA@15..16 "," + WHITESPACE@16..17 " " + SINGLE_PATTERN@17..20 + NAME@17..20 + IDENT@17..20 "hey" + WHITESPACE@20..21 " " + COMMA@21..22 "," + WHITESPACE@22..23 " " + R_BRACK@23..24 "]" + WHITESPACE@24..25 " " + JS_EQUAL_VALUE_CLAUSE@25..29 + EQ@25..26 "=" + WHITESPACE@26..27 " " + JS_ARRAY_EXPRESSION@27..29 + L_BRACK@27..28 "[" + LIST@28..28 + R_BRACK@28..29 "]" + WHITESPACE@29..30 "\n" +-- +error[SyntaxError]: Expected an identifier or pattern, but found none + ┌─ illigal_array_pattern.js:1:7 + │ +1 │ let [ default: , hey , ] = [] + │ ^^^^^^^ + +-- +error[SyntaxError]: expected `,` but instead found `:` + ┌─ illigal_array_pattern.js:1:14 + │ +1 │ let [ default: , hey , ] = [] + │ ^ unexpected + +-- +error[SyntaxError]: Expected an identifier or pattern, but found none + ┌─ illigal_array_pattern.js:1:14 + │ +1 │ let [ default: , hey , ] = [] + │ ^ + +-- +error[SyntaxError]: expected `,` but instead found `hey` + ┌─ illigal_array_pattern.js:1:18 + │ +1 │ let [ default: , hey , ] = [] + │ ^^^ unexpected + +-- +let [ default: , hey , ] = [] From 8c62e9a2fbd3d80aed54717861d3d5d8a4a21f79 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Fri, 19 Nov 2021 16:36:08 -0300 Subject: [PATCH 11/13] chore: code gen tests --- crates/rslint_parser/src/syntax/object.rs | 4 +- crates/rslint_parser/src/syntax/pat.rs | 8 + crates/rslint_parser/src/syntax/stmt.rs | 16 ++ .../inline/err/bad_object_pattern.js | 1 - .../inline/err/bad_object_pattern.rast | 71 ------ .../test_data/inline/err/class_decl_err.js | 2 - .../test_data/inline/err/class_decl_err.rast | 66 +----- .../err/{debugger.js => debugger_stmt.js} | 0 .../err/{debugger.rast => debugger_stmt.rast} | 2 +- .../test_data/inline/err/for_stmt_err.js | 2 +- .../test_data/inline/err/for_stmt_err.rast | 16 +- .../test_data/inline/err/if_broken.js | 1 - .../test_data/inline/err/if_broken.rast | 54 ----- .../test_data/inline/err/if_stmt_err.js | 1 + .../test_data/inline/err/if_stmt_err.rast | 56 ++++- .../inline/err/illigal_array_pattern.js | 1 - .../inline/err/illigal_array_pattern.rast | 67 ------ .../inline/err/illigal_object_pattern.rast | 155 ------------ ...t_pattern.js => object_binding_pattern.js} | 1 + .../inline/err/object_binding_pattern.rast | 222 ++++++++++++++++++ .../inline/err/object_expr_error_prop_name.js | 2 + .../err/object_expr_error_prop_name.rast | 61 ++++- .../err/paren_or_arrow_expr_invalid_params.js | 1 - .../paren_or_arrow_expr_invalid_params.rast | 79 +------ .../test_data/inline/ok/binary_expressions.js | 1 + .../inline/ok/binary_expressions.rast | 124 +++++----- .../test_data/inline/ok/class_decl.js | 3 + .../test_data/inline/ok/class_decl.rast | 49 ++++ .../test_data/inline/ok/grouping_expr.js | 2 + .../test_data/inline/ok/grouping_expr.rast | 21 ++ .../inline/ok/object_expr_getter_getter.js | 5 + .../inline/ok/object_expr_getter_getter.rast | 44 ++++ .../inline/ok/object_expr_getter_setter.js | 5 + .../inline/ok/object_expr_getter_setter.rast | 50 ++++ .../test_data/inline/ok/object_expr_method.js | 5 +- .../inline/ok/object_expr_method.rast | 128 +++------- .../test_data/inline/ok/object_member_name.js | 1 + .../inline/ok/object_member_name.rast | 64 +++++ .../test_data/inline/ok/postfix_expr.js | 2 + .../test_data/inline/ok/postfix_expr.rast | 15 ++ .../test_data/inline/ok/try_stmt.js | 3 - .../test_data/inline/ok/try_stmt.rast | 133 +++-------- .../test_data/inline/ok/var_decl.js | 1 - .../test_data/inline/ok/var_decl.rast | 59 +---- .../test_data/inline/ok/yield_expr.js | 1 - .../test_data/inline/ok/yield_expr.rast | 21 +- 46 files changed, 782 insertions(+), 844 deletions(-) delete mode 100644 crates/rslint_parser/test_data/inline/err/bad_object_pattern.js delete mode 100644 crates/rslint_parser/test_data/inline/err/bad_object_pattern.rast rename crates/rslint_parser/test_data/inline/err/{debugger.js => debugger_stmt.js} (100%) rename crates/rslint_parser/test_data/inline/err/{debugger.rast => debugger_stmt.rast} (98%) delete mode 100644 crates/rslint_parser/test_data/inline/err/if_broken.js delete mode 100644 crates/rslint_parser/test_data/inline/err/if_broken.rast delete mode 100644 crates/rslint_parser/test_data/inline/err/illigal_array_pattern.js delete mode 100644 crates/rslint_parser/test_data/inline/err/illigal_array_pattern.rast delete mode 100644 crates/rslint_parser/test_data/inline/err/illigal_object_pattern.rast rename crates/rslint_parser/test_data/inline/err/{illigal_object_pattern.js => object_binding_pattern.js} (75%) create mode 100644 crates/rslint_parser/test_data/inline/err/object_binding_pattern.rast create mode 100644 crates/rslint_parser/test_data/inline/ok/class_decl.js create mode 100644 crates/rslint_parser/test_data/inline/ok/class_decl.rast create mode 100644 crates/rslint_parser/test_data/inline/ok/grouping_expr.js create mode 100644 crates/rslint_parser/test_data/inline/ok/grouping_expr.rast create mode 100644 crates/rslint_parser/test_data/inline/ok/object_expr_getter_getter.js create mode 100644 crates/rslint_parser/test_data/inline/ok/object_expr_getter_getter.rast create mode 100644 crates/rslint_parser/test_data/inline/ok/object_expr_getter_setter.js create mode 100644 crates/rslint_parser/test_data/inline/ok/object_expr_getter_setter.rast create mode 100644 crates/rslint_parser/test_data/inline/ok/object_member_name.js create mode 100644 crates/rslint_parser/test_data/inline/ok/object_member_name.rast create mode 100644 crates/rslint_parser/test_data/inline/ok/postfix_expr.js create mode 100644 crates/rslint_parser/test_data/inline/ok/postfix_expr.rast diff --git a/crates/rslint_parser/src/syntax/object.rs b/crates/rslint_parser/src/syntax/object.rs index fabcf406c2e..6350b86a5b4 100644 --- a/crates/rslint_parser/src/syntax/object.rs +++ b/crates/rslint_parser/src/syntax/object.rs @@ -48,7 +48,7 @@ pub(super) fn object_expr(p: &mut Parser) -> CompletedMarker { /// An individual object property such as `"a": b` or `5: 6 + 6`. fn object_member(p: &mut Parser) -> Option { match p.cur() { - // test object_expr_getter_setter + // test object_expr_getter_getter // let a = { // get foo() { // return foo; @@ -212,7 +212,7 @@ pub fn object_prop_name(p: &mut Parser, binding: bool) -> Option Option { diff --git a/crates/rslint_parser/src/syntax/pat.rs b/crates/rslint_parser/src/syntax/pat.rs index a15cc7c0f12..f51c0849dc4 100644 --- a/crates/rslint_parser/src/syntax/pat.rs +++ b/crates/rslint_parser/src/syntax/pat.rs @@ -150,6 +150,8 @@ pub fn binding_element( left } +// test_err +// let [ default: , hey , ] = [] pub fn array_binding_pattern( p: &mut Parser, parameters: bool, @@ -191,6 +193,12 @@ pub fn array_binding_pattern( m.complete(p, ARRAY_PATTERN) } + +// test_err object_binding_pattern +// let { 5 } } = { eval: "foo" }; +// let { eval } = { eval: "foo" }; +// let { 5, 6 } = { eval: "foo" }; +// let { default: , bar } = {}; pub fn object_binding_pattern(p: &mut Parser, parameters: bool) -> CompletedMarker { let m = p.start(); p.expect(T!['{']); diff --git a/crates/rslint_parser/src/syntax/stmt.rs b/crates/rslint_parser/src/syntax/stmt.rs index b0aff10dbe1..c0c0c82b1b4 100644 --- a/crates/rslint_parser/src/syntax/stmt.rs +++ b/crates/rslint_parser/src/syntax/stmt.rs @@ -148,6 +148,13 @@ pub fn stmt(p: &mut Parser, recovery_set: impl Into>) -> Option Some(res) } +// test_err double_label +// label1: { +// label2: { +// label1: {} +// } +// } + fn expr_stmt(p: &mut Parser) -> Option { let start = p.cur_tok().range.start; // this is *technically* wrong because it would be an expr stmt in js but for our purposes @@ -246,6 +253,14 @@ fn expr_stmt(p: &mut Parser) -> Option { /// A debugger statement such as `debugger;` // test debugger_stmt // debugger; + +// test_err debugger_stmt +// function foo() { +// debugger { +// var something = "lorem"; +// } +// } + pub fn debugger_stmt(p: &mut Parser) -> CompletedMarker { let m = p.start(); let range = p.cur_tok().range; @@ -595,6 +610,7 @@ pub fn if_stmt(p: &mut Parser) -> CompletedMarker { // if (true) else // if else {} // if () {} else {} + // if (true)}}}} {} let m = p.start(); p.expect(T![if]); diff --git a/crates/rslint_parser/test_data/inline/err/bad_object_pattern.js b/crates/rslint_parser/test_data/inline/err/bad_object_pattern.js deleted file mode 100644 index 656a6a65fb2..00000000000 --- a/crates/rslint_parser/test_data/inline/err/bad_object_pattern.js +++ /dev/null @@ -1 +0,0 @@ -let { 5 } } = { eval: "foo" }; diff --git a/crates/rslint_parser/test_data/inline/err/bad_object_pattern.rast b/crates/rslint_parser/test_data/inline/err/bad_object_pattern.rast deleted file mode 100644 index 873b0ce0d17..00000000000 --- a/crates/rslint_parser/test_data/inline/err/bad_object_pattern.rast +++ /dev/null @@ -1,71 +0,0 @@ -JS_ROOT@0..31 - LIST@0..0 - LIST@0..30 - JS_VARIABLE_DECLARATION_STATEMENT@0..9 - JS_VARIABLE_DECLARATION@0..9 - LET_KW@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..9 - JS_VARIABLE_DECLARATOR@4..9 - OBJECT_PATTERN@4..9 - L_CURLY@4..5 "{" - WHITESPACE@5..6 " " - LIST@6..7 - JS_UNKNOWN_PATTERN@6..7 - JS_NUMBER_LITERAL@6..7 - JS_NUMBER_LITERAL_TOKEN@6..7 "5" - WHITESPACE@7..8 " " - R_CURLY@8..9 "}" - WHITESPACE@9..10 " " - JS_UNKNOWN_STATEMENT@10..11 - R_CURLY@10..11 "}" - WHITESPACE@11..12 " " - JS_UNKNOWN_STATEMENT@12..13 - EQ@12..13 "=" - WHITESPACE@13..14 " " - JS_BLOCK_STATEMENT@14..29 - L_CURLY@14..15 "{" - WHITESPACE@15..16 " " - LIST@16..27 - JS_LABELED_STATEMENT@16..27 - IDENT@16..20 "eval" - COLON@20..21 ":" - WHITESPACE@21..22 " " - JS_EXPRESSION_STATEMENT@22..27 - JS_STRING_LITERAL@22..27 - JS_STRING_LITERAL_TOKEN@22..27 "\"foo\"" - WHITESPACE@27..28 " " - R_CURLY@28..29 "}" - JS_EMPTY_STATEMENT@29..30 - SEMICOLON@29..30 ";" - WHITESPACE@30..31 "\n" --- -error[SyntaxError]: Expected an identifier for a pattern, but found none - ┌─ bad_object_pattern.js:1:7 - │ -1 │ let { 5 } } = { eval: "foo" }; - │ ^ - --- -error[SyntaxError]: Object and Array patterns require initializers - ┌─ bad_object_pattern.js:1:5 - │ -1 │ let { 5 } } = { eval: "foo" }; - │ ^^^^^ this pattern is declared, but it is not given an initialized value - --- -error[SyntaxError]: Expected a statement or declaration, but found none - ┌─ bad_object_pattern.js:1:11 - │ -1 │ let { 5 } } = { eval: "foo" }; - │ ^ Expected a statement or declaration here - --- -error[SyntaxError]: Expected a statement or declaration, but found none - ┌─ bad_object_pattern.js:1:13 - │ -1 │ let { 5 } } = { eval: "foo" }; - │ ^ Expected a statement or declaration here - --- -let { 5 } } = { eval: "foo" }; diff --git a/crates/rslint_parser/test_data/inline/err/class_decl_err.js b/crates/rslint_parser/test_data/inline/err/class_decl_err.js index c774c80df95..4f57464d9c7 100644 --- a/crates/rslint_parser/test_data/inline/err/class_decl_err.js +++ b/crates/rslint_parser/test_data/inline/err/class_decl_err.js @@ -3,5 +3,3 @@ class extends bar {} class extends {} class class foo { set {} } -class A extends bar extends foo {} -class A extends bar, foo {} diff --git a/crates/rslint_parser/test_data/inline/err/class_decl_err.rast b/crates/rslint_parser/test_data/inline/err/class_decl_err.rast index a3865f0dbaa..bafd9f4c96e 100644 --- a/crates/rslint_parser/test_data/inline/err/class_decl_err.rast +++ b/crates/rslint_parser/test_data/inline/err/class_decl_err.rast @@ -1,6 +1,6 @@ -JS_ROOT@0..137 +JS_ROOT@0..74 LIST@0..0 - LIST@0..136 + LIST@0..73 JS_CLASS_DECLARATION@0..8 CLASS_KW@0..5 "class" WHITESPACE@5..6 " " @@ -57,51 +57,7 @@ JS_ROOT@0..137 R_CURLY@70..71 "}" WHITESPACE@71..72 " " R_CURLY@72..73 "}" - WHITESPACE@73..74 "\n" - JS_CLASS_DECLARATION@74..108 - CLASS_KW@74..79 "class" - WHITESPACE@79..80 " " - JS_IDENTIFIER_BINDING@80..81 - IDENT@80..81 "A" - WHITESPACE@81..82 " " - JS_EXTENDS_CLAUSE@82..105 - EXTENDS_KW@82..89 "extends" - WHITESPACE@89..90 " " - JS_REFERENCE_IDENTIFIER_EXPRESSION@90..93 - IDENT@90..93 "bar" - WHITESPACE@93..94 " " - ERROR@94..105 - EXTENDS_KW@94..101 "extends" - WHITESPACE@101..102 " " - TS_EXPR_WITH_TYPE_ARGS@102..105 - JS_REFERENCE_IDENTIFIER_EXPRESSION@102..105 - IDENT@102..105 "foo" - WHITESPACE@105..106 " " - L_CURLY@106..107 "{" - LIST@107..107 - R_CURLY@107..108 "}" - WHITESPACE@108..109 "\n" - JS_CLASS_DECLARATION@109..136 - CLASS_KW@109..114 "class" - WHITESPACE@114..115 " " - JS_IDENTIFIER_BINDING@115..116 - IDENT@115..116 "A" - WHITESPACE@116..117 " " - JS_EXTENDS_CLAUSE@117..133 - EXTENDS_KW@117..124 "extends" - WHITESPACE@124..125 " " - JS_REFERENCE_IDENTIFIER_EXPRESSION@125..128 - IDENT@125..128 "bar" - COMMA@128..129 "," - WHITESPACE@129..130 " " - TS_EXPR_WITH_TYPE_ARGS@130..133 - JS_REFERENCE_IDENTIFIER_EXPRESSION@130..133 - IDENT@130..133 "foo" - WHITESPACE@133..134 " " - L_CURLY@134..135 "{" - LIST@135..135 - R_CURLY@135..136 "}" - WHITESPACE@136..137 "\n" + WHITESPACE@73..74 "\n" -- error[SyntaxError]: class declarations must have a name ┌─ class_decl_err.js:1:7 @@ -172,25 +128,9 @@ error[SyntaxError]: expected a block statement but instead found `}` 5 │ class foo { set {} } │ ^ --- -error[SyntaxError]: classes cannot extend multiple classes - ┌─ class_decl_err.js:6:29 - │ -6 │ class A extends bar extends foo {} - │ ^^^ - --- -error[SyntaxError]: classes cannot extend multiple classes - ┌─ class_decl_err.js:7:22 - │ -7 │ class A extends bar, foo {} - │ ^^^ - -- class {} class extends bar {} class extends {} class class foo { set {} } -class A extends bar extends foo {} -class A extends bar, foo {} diff --git a/crates/rslint_parser/test_data/inline/err/debugger.js b/crates/rslint_parser/test_data/inline/err/debugger_stmt.js similarity index 100% rename from crates/rslint_parser/test_data/inline/err/debugger.js rename to crates/rslint_parser/test_data/inline/err/debugger_stmt.js diff --git a/crates/rslint_parser/test_data/inline/err/debugger.rast b/crates/rslint_parser/test_data/inline/err/debugger_stmt.rast similarity index 98% rename from crates/rslint_parser/test_data/inline/err/debugger.rast rename to crates/rslint_parser/test_data/inline/err/debugger_stmt.rast index f694deca20b..ae7f8a1fd47 100644 --- a/crates/rslint_parser/test_data/inline/err/debugger.rast +++ b/crates/rslint_parser/test_data/inline/err/debugger_stmt.rast @@ -46,7 +46,7 @@ JS_ROOT@0..61 WHITESPACE@60..61 "\n" -- error[SyntaxError]: Expected a semicolon or an implicit semicolon after a statement, but found none - ┌─ debugger.js:2:11 + ┌─ debugger_stmt.js:2:11 │ 2 │ debugger { │ -------- ^ An explicit or implicit semicolon is expected here... diff --git a/crates/rslint_parser/test_data/inline/err/for_stmt_err.js b/crates/rslint_parser/test_data/inline/err/for_stmt_err.js index 79642a08382..80426b1f7a0 100644 --- a/crates/rslint_parser/test_data/inline/err/for_stmt_err.js +++ b/crates/rslint_parser/test_data/inline/err/for_stmt_err.js @@ -1,2 +1,2 @@ for ;; {} -for let i = 5; i < 10; ++i {} +for let i = 5; i < 10; i++ {} 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 98a1f987be7..0317dfe161b 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 @@ -45,10 +45,10 @@ JS_ROOT@0..40 SEMICOLON@31..32 ";" WHITESPACE@32..33 " " FOR_STMT_UPDATE@33..36 - JS_PRE_UPDATE_EXPRESSION@33..36 - PLUS2@33..35 "++" - JS_REFERENCE_IDENTIFIER_EXPRESSION@35..36 - IDENT@35..36 "i" + JS_POST_UPDATE_EXPRESSION@33..36 + JS_REFERENCE_IDENTIFIER_EXPRESSION@33..34 + IDENT@33..34 "i" + PLUS2@34..36 "++" WHITESPACE@36..37 " " JS_BLOCK_STATEMENT@37..39 L_CURLY@37..38 "{" @@ -66,23 +66,23 @@ error[SyntaxError]: expected `'('` but instead found `;` error[SyntaxError]: expected `')'` but instead found `for` ┌─ for_stmt_err.js:2:1 │ -2 │ for let i = 5; i < 10; ++i {} +2 │ for let i = 5; i < 10; i++ {} │ ^^^ unexpected -- error[SyntaxError]: expected `'('` but instead found `let` ┌─ for_stmt_err.js:2:5 │ -2 │ for let i = 5; i < 10; ++i {} +2 │ for let i = 5; i < 10; i++ {} │ ^^^ unexpected -- error[SyntaxError]: expected `')'` but instead found `{` ┌─ for_stmt_err.js:2:28 │ -2 │ for let i = 5; i < 10; ++i {} +2 │ for let i = 5; i < 10; i++ {} │ ^ unexpected -- for ;; {} -for let i = 5; i < 10; ++i {} +for let i = 5; i < 10; i++ {} diff --git a/crates/rslint_parser/test_data/inline/err/if_broken.js b/crates/rslint_parser/test_data/inline/err/if_broken.js deleted file mode 100644 index a571f99a0cb..00000000000 --- a/crates/rslint_parser/test_data/inline/err/if_broken.js +++ /dev/null @@ -1 +0,0 @@ -if (true)}}}} {} diff --git a/crates/rslint_parser/test_data/inline/err/if_broken.rast b/crates/rslint_parser/test_data/inline/err/if_broken.rast deleted file mode 100644 index da39eceba34..00000000000 --- a/crates/rslint_parser/test_data/inline/err/if_broken.rast +++ /dev/null @@ -1,54 +0,0 @@ -JS_ROOT@0..17 - LIST@0..0 - LIST@0..16 - JS_IF_STATEMENT@0..10 - IF_KW@0..2 "if" - WHITESPACE@2..3 " " - L_PAREN@3..4 "(" - JS_BOOLEAN_LITERAL@4..8 - TRUE_KW@4..8 "true" - R_PAREN@8..9 ")" - JS_UNKNOWN_STATEMENT@9..10 - R_CURLY@9..10 "}" - JS_UNKNOWN_STATEMENT@10..11 - R_CURLY@10..11 "}" - JS_UNKNOWN_STATEMENT@11..12 - R_CURLY@11..12 "}" - JS_UNKNOWN_STATEMENT@12..13 - R_CURLY@12..13 "}" - WHITESPACE@13..14 " " - JS_BLOCK_STATEMENT@14..16 - L_CURLY@14..15 "{" - LIST@15..15 - R_CURLY@15..16 "}" - WHITESPACE@16..17 "\n" --- -error[SyntaxError]: Expected a statement or declaration, but found none - ┌─ if_broken.js:1:10 - │ -1 │ if (true)}}}} {} - │ ^ Expected a statement or declaration here - --- -error[SyntaxError]: Expected a statement or declaration, but found none - ┌─ if_broken.js:1:11 - │ -1 │ if (true)}}}} {} - │ ^ Expected a statement or declaration here - --- -error[SyntaxError]: Expected a statement or declaration, but found none - ┌─ if_broken.js:1:12 - │ -1 │ if (true)}}}} {} - │ ^ Expected a statement or declaration here - --- -error[SyntaxError]: Expected a statement or declaration, but found none - ┌─ if_broken.js:1:13 - │ -1 │ if (true)}}}} {} - │ ^ Expected a statement or declaration here - --- -if (true)}}}} {} diff --git a/crates/rslint_parser/test_data/inline/err/if_stmt_err.js b/crates/rslint_parser/test_data/inline/err/if_stmt_err.js index 2a953332092..544717864aa 100644 --- a/crates/rslint_parser/test_data/inline/err/if_stmt_err.js +++ b/crates/rslint_parser/test_data/inline/err/if_stmt_err.js @@ -2,3 +2,4 @@ if (true) else {} if (true) else if else {} if () {} else {} +if (true)}}}} {} diff --git a/crates/rslint_parser/test_data/inline/err/if_stmt_err.rast b/crates/rslint_parser/test_data/inline/err/if_stmt_err.rast index b7283574d6a..b0562da32db 100644 --- a/crates/rslint_parser/test_data/inline/err/if_stmt_err.rast +++ b/crates/rslint_parser/test_data/inline/err/if_stmt_err.rast @@ -1,6 +1,6 @@ -JS_ROOT@0..61 +JS_ROOT@0..78 LIST@0..0 - LIST@0..60 + LIST@0..77 JS_IF_STATEMENT@0..17 IF_KW@0..2 "if" WHITESPACE@2..3 " " @@ -57,7 +57,28 @@ JS_ROOT@0..61 L_CURLY@58..59 "{" LIST@59..59 R_CURLY@59..60 "}" - WHITESPACE@60..61 "\n" + WHITESPACE@60..61 "\n" + JS_IF_STATEMENT@61..71 + IF_KW@61..63 "if" + WHITESPACE@63..64 " " + L_PAREN@64..65 "(" + JS_BOOLEAN_LITERAL@65..69 + TRUE_KW@65..69 "true" + R_PAREN@69..70 ")" + JS_UNKNOWN_STATEMENT@70..71 + R_CURLY@70..71 "}" + JS_UNKNOWN_STATEMENT@71..72 + R_CURLY@71..72 "}" + JS_UNKNOWN_STATEMENT@72..73 + R_CURLY@72..73 "}" + JS_UNKNOWN_STATEMENT@73..74 + R_CURLY@73..74 "}" + WHITESPACE@74..75 " " + JS_BLOCK_STATEMENT@75..77 + L_CURLY@75..76 "{" + LIST@76..76 + R_CURLY@76..77 "}" + WHITESPACE@77..78 "\n" -- error[SyntaxError]: Expected a statement or declaration, but found none ┌─ if_stmt_err.js:1:11 @@ -107,8 +128,37 @@ error[SyntaxError]: Expected an expression, but found none 4 │ if () {} else {} │ ^ Expected an expression here +-- +error[SyntaxError]: Expected a statement or declaration, but found none + ┌─ if_stmt_err.js:5:10 + │ +5 │ if (true)}}}} {} + │ ^ Expected a statement or declaration here + +-- +error[SyntaxError]: Expected a statement or declaration, but found none + ┌─ if_stmt_err.js:5:11 + │ +5 │ if (true)}}}} {} + │ ^ Expected a statement or declaration here + +-- +error[SyntaxError]: Expected a statement or declaration, but found none + ┌─ if_stmt_err.js:5:12 + │ +5 │ if (true)}}}} {} + │ ^ Expected a statement or declaration here + +-- +error[SyntaxError]: Expected a statement or declaration, but found none + ┌─ if_stmt_err.js:5:13 + │ +5 │ if (true)}}}} {} + │ ^ Expected a statement or declaration here + -- if (true) else {} if (true) else if else {} if () {} else {} +if (true)}}}} {} diff --git a/crates/rslint_parser/test_data/inline/err/illigal_array_pattern.js b/crates/rslint_parser/test_data/inline/err/illigal_array_pattern.js deleted file mode 100644 index 7f50e8a570f..00000000000 --- a/crates/rslint_parser/test_data/inline/err/illigal_array_pattern.js +++ /dev/null @@ -1 +0,0 @@ -let [ default: , hey , ] = [] diff --git a/crates/rslint_parser/test_data/inline/err/illigal_array_pattern.rast b/crates/rslint_parser/test_data/inline/err/illigal_array_pattern.rast deleted file mode 100644 index 83034f161c3..00000000000 --- a/crates/rslint_parser/test_data/inline/err/illigal_array_pattern.rast +++ /dev/null @@ -1,67 +0,0 @@ -JS_ROOT@0..30 - LIST@0..0 - LIST@0..29 - JS_VARIABLE_DECLARATION_STATEMENT@0..29 - JS_VARIABLE_DECLARATION@0..29 - LET_KW@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..29 - JS_VARIABLE_DECLARATOR@4..29 - ARRAY_PATTERN@4..24 - L_BRACK@4..5 "[" - WHITESPACE@5..6 " " - LIST@6..22 - JS_UNKNOWN_PATTERN@6..13 - DEFAULT_KW@6..13 "default" - JS_UNKNOWN_PATTERN@13..14 - COLON@13..14 ":" - WHITESPACE@14..15 " " - JS_UNKNOWN_PATTERN@15..16 - COMMA@15..16 "," - WHITESPACE@16..17 " " - SINGLE_PATTERN@17..20 - NAME@17..20 - IDENT@17..20 "hey" - WHITESPACE@20..21 " " - COMMA@21..22 "," - WHITESPACE@22..23 " " - R_BRACK@23..24 "]" - WHITESPACE@24..25 " " - JS_EQUAL_VALUE_CLAUSE@25..29 - EQ@25..26 "=" - WHITESPACE@26..27 " " - JS_ARRAY_EXPRESSION@27..29 - L_BRACK@27..28 "[" - LIST@28..28 - R_BRACK@28..29 "]" - WHITESPACE@29..30 "\n" --- -error[SyntaxError]: Expected an identifier or pattern, but found none - ┌─ illigal_array_pattern.js:1:7 - │ -1 │ let [ default: , hey , ] = [] - │ ^^^^^^^ - --- -error[SyntaxError]: expected `,` but instead found `:` - ┌─ illigal_array_pattern.js:1:14 - │ -1 │ let [ default: , hey , ] = [] - │ ^ unexpected - --- -error[SyntaxError]: Expected an identifier or pattern, but found none - ┌─ illigal_array_pattern.js:1:14 - │ -1 │ let [ default: , hey , ] = [] - │ ^ - --- -error[SyntaxError]: expected `,` but instead found `hey` - ┌─ illigal_array_pattern.js:1:18 - │ -1 │ let [ default: , hey , ] = [] - │ ^^^ unexpected - --- -let [ default: , hey , ] = [] diff --git a/crates/rslint_parser/test_data/inline/err/illigal_object_pattern.rast b/crates/rslint_parser/test_data/inline/err/illigal_object_pattern.rast deleted file mode 100644 index af921c93e92..00000000000 --- a/crates/rslint_parser/test_data/inline/err/illigal_object_pattern.rast +++ /dev/null @@ -1,155 +0,0 @@ -JS_ROOT@0..93 - LIST@0..0 - LIST@0..92 - JS_VARIABLE_DECLARATION_STATEMENT@0..31 - JS_VARIABLE_DECLARATION@0..30 - LET_KW@0..3 "let" - WHITESPACE@3..4 " " - LIST@4..30 - JS_VARIABLE_DECLARATOR@4..30 - OBJECT_PATTERN@4..12 - L_CURLY@4..5 "{" - WHITESPACE@5..6 " " - LIST@6..10 - JS_UNKNOWN_PATTERN@6..10 - JS_UNKNOWN_BINDING@6..10 - IDENT@6..10 "eval" - WHITESPACE@10..11 " " - R_CURLY@11..12 "}" - WHITESPACE@12..13 " " - JS_EQUAL_VALUE_CLAUSE@13..30 - EQ@13..14 "=" - WHITESPACE@14..15 " " - JS_OBJECT_EXPRESSION@15..30 - L_CURLY@15..16 "{" - WHITESPACE@16..17 " " - LIST@17..28 - JS_PROPERTY_OBJECT_MEMBER@17..28 - JS_LITERAL_MEMBER_NAME@17..21 - IDENT@17..21 "eval" - COLON@21..22 ":" - WHITESPACE@22..23 " " - JS_STRING_LITERAL@23..28 - JS_STRING_LITERAL_TOKEN@23..28 "\"foo\"" - WHITESPACE@28..29 " " - R_CURLY@29..30 "}" - SEMICOLON@30..31 ";" - WHITESPACE@31..32 "\n" - JS_VARIABLE_DECLARATION_STATEMENT@32..63 - JS_VARIABLE_DECLARATION@32..62 - LET_KW@32..35 "let" - WHITESPACE@35..36 " " - LIST@36..62 - JS_VARIABLE_DECLARATOR@36..62 - OBJECT_PATTERN@36..44 - L_CURLY@36..37 "{" - WHITESPACE@37..38 " " - LIST@38..42 - JS_UNKNOWN_PATTERN@38..39 - JS_NUMBER_LITERAL@38..39 - JS_NUMBER_LITERAL_TOKEN@38..39 "5" - COMMA@39..40 "," - WHITESPACE@40..41 " " - JS_UNKNOWN_PATTERN@41..42 - JS_NUMBER_LITERAL@41..42 - JS_NUMBER_LITERAL_TOKEN@41..42 "6" - WHITESPACE@42..43 " " - R_CURLY@43..44 "}" - WHITESPACE@44..45 " " - JS_EQUAL_VALUE_CLAUSE@45..62 - EQ@45..46 "=" - WHITESPACE@46..47 " " - JS_OBJECT_EXPRESSION@47..62 - L_CURLY@47..48 "{" - WHITESPACE@48..49 " " - LIST@49..60 - JS_PROPERTY_OBJECT_MEMBER@49..60 - JS_LITERAL_MEMBER_NAME@49..53 - IDENT@49..53 "eval" - COLON@53..54 ":" - WHITESPACE@54..55 " " - JS_STRING_LITERAL@55..60 - JS_STRING_LITERAL_TOKEN@55..60 "\"foo\"" - WHITESPACE@60..61 " " - R_CURLY@61..62 "}" - SEMICOLON@62..63 ";" - WHITESPACE@63..64 "\n" - JS_VARIABLE_DECLARATION_STATEMENT@64..92 - JS_VARIABLE_DECLARATION@64..91 - LET_KW@64..67 "let" - WHITESPACE@67..68 " " - LIST@68..91 - JS_VARIABLE_DECLARATOR@68..91 - OBJECT_PATTERN@68..86 - L_CURLY@68..69 "{" - WHITESPACE@69..70 " " - LIST@70..84 - KEY_VALUE_PATTERN@70..80 - NAME@70..77 - IDENT@70..77 "default" - COLON@77..78 ":" - WHITESPACE@78..79 " " - JS_UNKNOWN_PATTERN@79..80 - COMMA@79..80 "," - WHITESPACE@80..81 " " - SINGLE_PATTERN@81..84 - NAME@81..84 - IDENT@81..84 "bar" - WHITESPACE@84..85 " " - R_CURLY@85..86 "}" - WHITESPACE@86..87 " " - JS_EQUAL_VALUE_CLAUSE@87..91 - EQ@87..88 "=" - WHITESPACE@88..89 " " - JS_OBJECT_EXPRESSION@89..91 - L_CURLY@89..90 "{" - LIST@90..90 - R_CURLY@90..91 "}" - SEMICOLON@91..92 ";" - WHITESPACE@92..93 "\n" --- -error[SyntaxError]: Illegal use of `eval` as an identifier in strict mode - ┌─ illigal_object_pattern.js:1:7 - │ -1 │ let { eval } = { eval: "foo" }; - │ ^^^^ - --- -error[SyntaxError]: Expected an identifier for a pattern, but found none - ┌─ illigal_object_pattern.js:1:7 - │ -1 │ let { eval } = { eval: "foo" }; - │ ^^^^ - --- -error[SyntaxError]: Expected an identifier for a pattern, but found none - ┌─ illigal_object_pattern.js:2:7 - │ -2 │ let { 5, 6 } = { eval: "foo" }; - │ ^ - --- -error[SyntaxError]: Expected an identifier for a pattern, but found none - ┌─ illigal_object_pattern.js:2:10 - │ -2 │ let { 5, 6 } = { eval: "foo" }; - │ ^ - --- -error[SyntaxError]: Expected an identifier or pattern, but found none - ┌─ illigal_object_pattern.js:3:16 - │ -3 │ let { default: , bar } = {}; - │ ^ - --- -error[SyntaxError]: expected `,` but instead found `bar` - ┌─ illigal_object_pattern.js:3:18 - │ -3 │ let { default: , bar } = {}; - │ ^^^ unexpected - --- -let { eval } = { eval: "foo" }; -let { 5, 6 } = { eval: "foo" }; -let { default: , bar } = {}; diff --git a/crates/rslint_parser/test_data/inline/err/illigal_object_pattern.js b/crates/rslint_parser/test_data/inline/err/object_binding_pattern.js similarity index 75% rename from crates/rslint_parser/test_data/inline/err/illigal_object_pattern.js rename to crates/rslint_parser/test_data/inline/err/object_binding_pattern.js index 42c685a2e46..552ae54eaa5 100644 --- a/crates/rslint_parser/test_data/inline/err/illigal_object_pattern.js +++ b/crates/rslint_parser/test_data/inline/err/object_binding_pattern.js @@ -1,3 +1,4 @@ +let { 5 } } = { eval: "foo" }; let { eval } = { eval: "foo" }; let { 5, 6 } = { eval: "foo" }; let { default: , bar } = {}; diff --git a/crates/rslint_parser/test_data/inline/err/object_binding_pattern.rast b/crates/rslint_parser/test_data/inline/err/object_binding_pattern.rast new file mode 100644 index 00000000000..9c791e5a0d0 --- /dev/null +++ b/crates/rslint_parser/test_data/inline/err/object_binding_pattern.rast @@ -0,0 +1,222 @@ +JS_ROOT@0..124 + LIST@0..0 + LIST@0..123 + JS_VARIABLE_DECLARATION_STATEMENT@0..9 + JS_VARIABLE_DECLARATION@0..9 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..9 + JS_VARIABLE_DECLARATOR@4..9 + OBJECT_PATTERN@4..9 + L_CURLY@4..5 "{" + WHITESPACE@5..6 " " + LIST@6..7 + JS_UNKNOWN_PATTERN@6..7 + JS_NUMBER_LITERAL@6..7 + JS_NUMBER_LITERAL_TOKEN@6..7 "5" + WHITESPACE@7..8 " " + R_CURLY@8..9 "}" + WHITESPACE@9..10 " " + JS_UNKNOWN_STATEMENT@10..11 + R_CURLY@10..11 "}" + WHITESPACE@11..12 " " + JS_UNKNOWN_STATEMENT@12..13 + EQ@12..13 "=" + WHITESPACE@13..14 " " + JS_BLOCK_STATEMENT@14..29 + L_CURLY@14..15 "{" + WHITESPACE@15..16 " " + LIST@16..27 + JS_LABELED_STATEMENT@16..27 + IDENT@16..20 "eval" + COLON@20..21 ":" + WHITESPACE@21..22 " " + JS_EXPRESSION_STATEMENT@22..27 + JS_STRING_LITERAL@22..27 + JS_STRING_LITERAL_TOKEN@22..27 "\"foo\"" + WHITESPACE@27..28 " " + R_CURLY@28..29 "}" + JS_EMPTY_STATEMENT@29..30 + SEMICOLON@29..30 ";" + WHITESPACE@30..31 "\n" + JS_VARIABLE_DECLARATION_STATEMENT@31..62 + JS_VARIABLE_DECLARATION@31..61 + LET_KW@31..34 "let" + WHITESPACE@34..35 " " + LIST@35..61 + JS_VARIABLE_DECLARATOR@35..61 + OBJECT_PATTERN@35..43 + L_CURLY@35..36 "{" + WHITESPACE@36..37 " " + LIST@37..41 + JS_UNKNOWN_PATTERN@37..41 + JS_UNKNOWN_BINDING@37..41 + IDENT@37..41 "eval" + WHITESPACE@41..42 " " + R_CURLY@42..43 "}" + WHITESPACE@43..44 " " + JS_EQUAL_VALUE_CLAUSE@44..61 + EQ@44..45 "=" + WHITESPACE@45..46 " " + JS_OBJECT_EXPRESSION@46..61 + L_CURLY@46..47 "{" + WHITESPACE@47..48 " " + LIST@48..59 + JS_PROPERTY_OBJECT_MEMBER@48..59 + JS_LITERAL_MEMBER_NAME@48..52 + IDENT@48..52 "eval" + COLON@52..53 ":" + WHITESPACE@53..54 " " + JS_STRING_LITERAL@54..59 + JS_STRING_LITERAL_TOKEN@54..59 "\"foo\"" + WHITESPACE@59..60 " " + R_CURLY@60..61 "}" + SEMICOLON@61..62 ";" + WHITESPACE@62..63 "\n" + JS_VARIABLE_DECLARATION_STATEMENT@63..94 + JS_VARIABLE_DECLARATION@63..93 + LET_KW@63..66 "let" + WHITESPACE@66..67 " " + LIST@67..93 + JS_VARIABLE_DECLARATOR@67..93 + OBJECT_PATTERN@67..75 + L_CURLY@67..68 "{" + WHITESPACE@68..69 " " + LIST@69..73 + JS_UNKNOWN_PATTERN@69..70 + JS_NUMBER_LITERAL@69..70 + JS_NUMBER_LITERAL_TOKEN@69..70 "5" + COMMA@70..71 "," + WHITESPACE@71..72 " " + JS_UNKNOWN_PATTERN@72..73 + JS_NUMBER_LITERAL@72..73 + JS_NUMBER_LITERAL_TOKEN@72..73 "6" + WHITESPACE@73..74 " " + R_CURLY@74..75 "}" + WHITESPACE@75..76 " " + JS_EQUAL_VALUE_CLAUSE@76..93 + EQ@76..77 "=" + WHITESPACE@77..78 " " + JS_OBJECT_EXPRESSION@78..93 + L_CURLY@78..79 "{" + WHITESPACE@79..80 " " + LIST@80..91 + JS_PROPERTY_OBJECT_MEMBER@80..91 + JS_LITERAL_MEMBER_NAME@80..84 + IDENT@80..84 "eval" + COLON@84..85 ":" + WHITESPACE@85..86 " " + JS_STRING_LITERAL@86..91 + JS_STRING_LITERAL_TOKEN@86..91 "\"foo\"" + WHITESPACE@91..92 " " + R_CURLY@92..93 "}" + SEMICOLON@93..94 ";" + WHITESPACE@94..95 "\n" + JS_VARIABLE_DECLARATION_STATEMENT@95..123 + JS_VARIABLE_DECLARATION@95..122 + LET_KW@95..98 "let" + WHITESPACE@98..99 " " + LIST@99..122 + JS_VARIABLE_DECLARATOR@99..122 + OBJECT_PATTERN@99..117 + L_CURLY@99..100 "{" + WHITESPACE@100..101 " " + LIST@101..115 + KEY_VALUE_PATTERN@101..111 + NAME@101..108 + IDENT@101..108 "default" + COLON@108..109 ":" + WHITESPACE@109..110 " " + JS_UNKNOWN_PATTERN@110..111 + COMMA@110..111 "," + WHITESPACE@111..112 " " + SINGLE_PATTERN@112..115 + NAME@112..115 + IDENT@112..115 "bar" + WHITESPACE@115..116 " " + R_CURLY@116..117 "}" + WHITESPACE@117..118 " " + JS_EQUAL_VALUE_CLAUSE@118..122 + EQ@118..119 "=" + WHITESPACE@119..120 " " + JS_OBJECT_EXPRESSION@120..122 + L_CURLY@120..121 "{" + LIST@121..121 + R_CURLY@121..122 "}" + SEMICOLON@122..123 ";" + WHITESPACE@123..124 "\n" +-- +error[SyntaxError]: Expected an identifier for a pattern, but found none + ┌─ object_binding_pattern.js:1:7 + │ +1 │ let { 5 } } = { eval: "foo" }; + │ ^ + +-- +error[SyntaxError]: Object and Array patterns require initializers + ┌─ object_binding_pattern.js:1:5 + │ +1 │ let { 5 } } = { eval: "foo" }; + │ ^^^^^ this pattern is declared, but it is not given an initialized value + +-- +error[SyntaxError]: Expected a statement or declaration, but found none + ┌─ object_binding_pattern.js:1:11 + │ +1 │ let { 5 } } = { eval: "foo" }; + │ ^ Expected a statement or declaration here + +-- +error[SyntaxError]: Expected a statement or declaration, but found none + ┌─ object_binding_pattern.js:1:13 + │ +1 │ let { 5 } } = { eval: "foo" }; + │ ^ Expected a statement or declaration here + +-- +error[SyntaxError]: Illegal use of `eval` as an identifier in strict mode + ┌─ object_binding_pattern.js:2:7 + │ +2 │ let { eval } = { eval: "foo" }; + │ ^^^^ + +-- +error[SyntaxError]: Expected an identifier for a pattern, but found none + ┌─ object_binding_pattern.js:2:7 + │ +2 │ let { eval } = { eval: "foo" }; + │ ^^^^ + +-- +error[SyntaxError]: Expected an identifier for a pattern, but found none + ┌─ object_binding_pattern.js:3:7 + │ +3 │ let { 5, 6 } = { eval: "foo" }; + │ ^ + +-- +error[SyntaxError]: Expected an identifier for a pattern, but found none + ┌─ object_binding_pattern.js:3:10 + │ +3 │ let { 5, 6 } = { eval: "foo" }; + │ ^ + +-- +error[SyntaxError]: Expected an identifier or pattern, but found none + ┌─ object_binding_pattern.js:4:16 + │ +4 │ let { default: , bar } = {}; + │ ^ + +-- +error[SyntaxError]: expected `,` but instead found `bar` + ┌─ object_binding_pattern.js:4:18 + │ +4 │ let { default: , bar } = {}; + │ ^^^ unexpected + +-- +let { 5 } } = { eval: "foo" }; +let { eval } = { eval: "foo" }; +let { 5, 6 } = { eval: "foo" }; +let { default: , bar } = {}; diff --git a/crates/rslint_parser/test_data/inline/err/object_expr_error_prop_name.js b/crates/rslint_parser/test_data/inline/err/object_expr_error_prop_name.js index 8c9013724c8..7170c447e6d 100644 --- a/crates/rslint_parser/test_data/inline/err/object_expr_error_prop_name.js +++ b/crates/rslint_parser/test_data/inline/err/object_expr_error_prop_name.js @@ -1,2 +1,4 @@ let a = { /: 6, /: /foo/ } let a = {{}} +test_err object_expr_non_ident_literal_prop +let b = {5} 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 1c51f7613d2..e12e037f07b 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,6 +1,6 @@ -JS_ROOT@0..40 +JS_ROOT@0..96 LIST@0..0 - LIST@0..39 + LIST@0..95 JS_VARIABLE_DECLARATION_STATEMENT@0..26 JS_VARIABLE_DECLARATION@0..26 LET_KW@0..3 "let" @@ -49,7 +49,36 @@ JS_ROOT@0..40 R_CURLY@37..38 "}" JS_UNKNOWN_STATEMENT@38..39 R_CURLY@38..39 "}" - WHITESPACE@39..40 "\n" + WHITESPACE@39..40 "\n" + JS_EXPRESSION_STATEMENT@40..48 + JS_REFERENCE_IDENTIFIER_EXPRESSION@40..48 + IDENT@40..48 "test_err" + WHITESPACE@48..49 " " + JS_EXPRESSION_STATEMENT@49..83 + JS_REFERENCE_IDENTIFIER_EXPRESSION@49..83 + IDENT@49..83 "object_expr_non_ident ..." + WHITESPACE@83..84 "\n" + JS_VARIABLE_DECLARATION_STATEMENT@84..95 + JS_VARIABLE_DECLARATION@84..95 + LET_KW@84..87 "let" + WHITESPACE@87..88 " " + LIST@88..95 + JS_VARIABLE_DECLARATOR@88..95 + SINGLE_PATTERN@88..89 + NAME@88..89 + IDENT@88..89 "b" + WHITESPACE@89..90 " " + JS_EQUAL_VALUE_CLAUSE@90..95 + EQ@90..91 "=" + WHITESPACE@91..92 " " + JS_OBJECT_EXPRESSION@92..95 + L_CURLY@92..93 "{" + LIST@93..94 + JS_PROPERTY_OBJECT_MEMBER@93..94 + JS_LITERAL_MEMBER_NAME@93..94 + JS_NUMBER_LITERAL_TOKEN@93..94 "5" + R_CURLY@94..95 "}" + WHITESPACE@95..96 "\n" -- error[SyntaxError]: Expected an identifier, a keyword, or a string or number literal ┌─ object_expr_error_prop_name.js:1:11 @@ -71,6 +100,32 @@ error[SyntaxError]: Expected a statement or declaration, but found none 2 │ let a = {{}} │ ^ Expected a statement or declaration here +-- +error[SyntaxError]: Expected a semicolon or an implicit semicolon after a statement, but found none + ┌─ object_expr_error_prop_name.js:3:10 + │ +3 │ test_err object_expr_non_ident_literal_prop + │ ---------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + │ │ │ + │ │ An explicit or implicit semicolon is expected here... + │ ...Which is required to end this statement + +-- +error[SyntaxError]: expected `:` but instead found `}` + ┌─ object_expr_error_prop_name.js:4:11 + │ +4 │ let b = {5} + │ ^ unexpected + +-- +error[SyntaxError]: Expected an expression, but found none + ┌─ object_expr_error_prop_name.js:4:11 + │ +4 │ let b = {5} + │ ^ Expected an expression here + -- let a = { /: 6, /: /foo/ } let a = {{}} +test_err object_expr_non_ident_literal_prop +let b = {5} diff --git a/crates/rslint_parser/test_data/inline/err/paren_or_arrow_expr_invalid_params.js b/crates/rslint_parser/test_data/inline/err/paren_or_arrow_expr_invalid_params.js index 6d568ef5134..5c81884588e 100644 --- a/crates/rslint_parser/test_data/inline/err/paren_or_arrow_expr_invalid_params.js +++ b/crates/rslint_parser/test_data/inline/err/paren_or_arrow_expr_invalid_params.js @@ -1,2 +1 @@ (5 + 5) => {} -(a, ,b) => {} diff --git a/crates/rslint_parser/test_data/inline/err/paren_or_arrow_expr_invalid_params.rast b/crates/rslint_parser/test_data/inline/err/paren_or_arrow_expr_invalid_params.rast index 086fd2727f1..fcc08cedeee 100644 --- a/crates/rslint_parser/test_data/inline/err/paren_or_arrow_expr_invalid_params.rast +++ b/crates/rslint_parser/test_data/inline/err/paren_or_arrow_expr_invalid_params.rast @@ -1,6 +1,6 @@ -JS_ROOT@0..28 +JS_ROOT@0..14 LIST@0..0 - LIST@0..27 + LIST@0..13 JS_EXPRESSION_STATEMENT@0..6 JS_ARROW_FUNCTION_EXPRESSION@0..6 JS_PARAMETER_LIST@0..4 @@ -23,31 +23,7 @@ JS_ROOT@0..28 L_CURLY@11..12 "{" LIST@12..12 R_CURLY@12..13 "}" - WHITESPACE@13..14 "\n" - JS_EXPRESSION_STATEMENT@14..19 - JS_PARENTHESIZED_EXPRESSION@14..19 - L_PAREN@14..15 "(" - JS_SEQUENCE_EXPRESSION@15..19 - JS_REFERENCE_IDENTIFIER_EXPRESSION@15..16 - IDENT@15..16 "a" - COMMA@16..17 "," - WHITESPACE@17..18 " " - ERROR@18..19 - COMMA@18..19 "," - JS_EXPRESSION_STATEMENT@19..20 - JS_REFERENCE_IDENTIFIER_EXPRESSION@19..20 - IDENT@19..20 "b" - JS_UNKNOWN_STATEMENT@20..21 - R_PAREN@20..21 ")" - WHITESPACE@21..22 " " - JS_UNKNOWN_STATEMENT@22..24 - FAT_ARROW@22..24 "=>" - WHITESPACE@24..25 " " - JS_BLOCK_STATEMENT@25..27 - L_CURLY@25..26 "{" - LIST@26..26 - R_CURLY@26..27 "}" - WHITESPACE@27..28 "\n" + WHITESPACE@13..14 "\n" -- error[SyntaxError]: Expected an identifier or pattern, but found none ┌─ paren_or_arrow_expr_invalid_params.js:1:2 @@ -93,54 +69,5 @@ error[SyntaxError]: Expected a statement or declaration, but found none 1 │ (5 + 5) => {} │ ^^ Expected a statement or declaration here --- -error[SyntaxError]: Expected an expression, but found none - ┌─ paren_or_arrow_expr_invalid_params.js:2:5 - │ -2 │ (a, ,b) => {} - │ ^ Expected an expression here - --- -error[SyntaxError]: expected `')'` but instead found `b` - ┌─ paren_or_arrow_expr_invalid_params.js:2:6 - │ -2 │ (a, ,b) => {} - │ ^ unexpected - --- -error[SyntaxError]: Expected a semicolon or an implicit semicolon after a statement, but found none - ┌─ paren_or_arrow_expr_invalid_params.js:2:6 - │ -2 │ (a, ,b) => {} - │ -----^ - │ │ │ - │ │ An explicit or implicit semicolon is expected here... - │ ...Which is required to end this statement - --- -error[SyntaxError]: Expected a semicolon or an implicit semicolon after a statement, but found none - ┌─ paren_or_arrow_expr_invalid_params.js:2:7 - │ -2 │ (a, ,b) => {} - │ -^ - │ ││ - │ │An explicit or implicit semicolon is expected here... - │ ...Which is required to end this statement - --- -error[SyntaxError]: Expected a statement or declaration, but found none - ┌─ paren_or_arrow_expr_invalid_params.js:2:7 - │ -2 │ (a, ,b) => {} - │ ^ Expected a statement or declaration here - --- -error[SyntaxError]: Expected a statement or declaration, but found none - ┌─ paren_or_arrow_expr_invalid_params.js:2:9 - │ -2 │ (a, ,b) => {} - │ ^^ Expected a statement or declaration here - -- (5 + 5) => {} -(a, ,b) => {} diff --git a/crates/rslint_parser/test_data/inline/ok/binary_expressions.js b/crates/rslint_parser/test_data/inline/ok/binary_expressions.js index 1ab7f7fa2a6..b8d9a2e68ec 100644 --- a/crates/rslint_parser/test_data/inline/ok/binary_expressions.js +++ b/crates/rslint_parser/test_data/inline/ok/binary_expressions.js @@ -5,5 +5,6 @@ 1 / 2 74 in foo foo instanceof Array +foo ?? bar 1 + 1 + 1 + 1 5 + 6 - 1 * 2 / 1 ** 6 diff --git a/crates/rslint_parser/test_data/inline/ok/binary_expressions.rast b/crates/rslint_parser/test_data/inline/ok/binary_expressions.rast index 22951212f6d..decca056f98 100644 --- a/crates/rslint_parser/test_data/inline/ok/binary_expressions.rast +++ b/crates/rslint_parser/test_data/inline/ok/binary_expressions.rast @@ -1,6 +1,6 @@ -JS_ROOT@0..114 +JS_ROOT@0..125 LIST@0..0 - LIST@0..113 + LIST@0..124 JS_EXPRESSION_STATEMENT@0..5 JS_BINARY_EXPRESSION@0..5 JS_NUMBER_LITERAL@0..1 @@ -93,59 +93,69 @@ JS_ROOT@0..114 JS_REFERENCE_IDENTIFIER_EXPRESSION@71..76 IDENT@71..76 "Array" WHITESPACE@76..77 "\n" - JS_EXPRESSION_STATEMENT@77..90 - JS_BINARY_EXPRESSION@77..90 - JS_BINARY_EXPRESSION@77..86 - JS_BINARY_EXPRESSION@77..82 - JS_NUMBER_LITERAL@77..78 - JS_NUMBER_LITERAL_TOKEN@77..78 "1" - WHITESPACE@78..79 " " - PLUS@79..80 "+" - WHITESPACE@80..81 " " - JS_NUMBER_LITERAL@81..82 - JS_NUMBER_LITERAL_TOKEN@81..82 "1" - WHITESPACE@82..83 " " - PLUS@83..84 "+" - WHITESPACE@84..85 " " - JS_NUMBER_LITERAL@85..86 - JS_NUMBER_LITERAL_TOKEN@85..86 "1" - WHITESPACE@86..87 " " - PLUS@87..88 "+" - WHITESPACE@88..89 " " - JS_NUMBER_LITERAL@89..90 - JS_NUMBER_LITERAL_TOKEN@89..90 "1" - WHITESPACE@90..91 "\n" - JS_EXPRESSION_STATEMENT@91..113 - JS_BINARY_EXPRESSION@91..113 - JS_BINARY_EXPRESSION@91..96 - JS_NUMBER_LITERAL@91..92 - JS_NUMBER_LITERAL_TOKEN@91..92 "5" - WHITESPACE@92..93 " " - PLUS@93..94 "+" - WHITESPACE@94..95 " " - JS_NUMBER_LITERAL@95..96 - JS_NUMBER_LITERAL_TOKEN@95..96 "6" - WHITESPACE@96..97 " " - MINUS@97..98 "-" - WHITESPACE@98..99 " " - JS_BINARY_EXPRESSION@99..113 - JS_BINARY_EXPRESSION@99..104 - JS_NUMBER_LITERAL@99..100 - JS_NUMBER_LITERAL_TOKEN@99..100 "1" - WHITESPACE@100..101 " " - STAR@101..102 "*" - WHITESPACE@102..103 " " - JS_NUMBER_LITERAL@103..104 - JS_NUMBER_LITERAL_TOKEN@103..104 "2" - WHITESPACE@104..105 " " - SLASH@105..106 "/" - WHITESPACE@106..107 " " - JS_BINARY_EXPRESSION@107..113 - JS_NUMBER_LITERAL@107..108 - JS_NUMBER_LITERAL_TOKEN@107..108 "1" - WHITESPACE@108..109 " " - STAR2@109..111 "**" + JS_EXPRESSION_STATEMENT@77..87 + JS_LOGICAL_EXPRESSION@77..87 + JS_REFERENCE_IDENTIFIER_EXPRESSION@77..80 + IDENT@77..80 "foo" + WHITESPACE@80..81 " " + QUESTION2@81..83 "??" + WHITESPACE@83..84 " " + JS_REFERENCE_IDENTIFIER_EXPRESSION@84..87 + IDENT@84..87 "bar" + WHITESPACE@87..88 "\n" + JS_EXPRESSION_STATEMENT@88..101 + JS_BINARY_EXPRESSION@88..101 + JS_BINARY_EXPRESSION@88..97 + JS_BINARY_EXPRESSION@88..93 + JS_NUMBER_LITERAL@88..89 + JS_NUMBER_LITERAL_TOKEN@88..89 "1" + WHITESPACE@89..90 " " + PLUS@90..91 "+" + WHITESPACE@91..92 " " + JS_NUMBER_LITERAL@92..93 + JS_NUMBER_LITERAL_TOKEN@92..93 "1" + WHITESPACE@93..94 " " + PLUS@94..95 "+" + WHITESPACE@95..96 " " + JS_NUMBER_LITERAL@96..97 + JS_NUMBER_LITERAL_TOKEN@96..97 "1" + WHITESPACE@97..98 " " + PLUS@98..99 "+" + WHITESPACE@99..100 " " + JS_NUMBER_LITERAL@100..101 + JS_NUMBER_LITERAL_TOKEN@100..101 "1" + WHITESPACE@101..102 "\n" + JS_EXPRESSION_STATEMENT@102..124 + JS_BINARY_EXPRESSION@102..124 + JS_BINARY_EXPRESSION@102..107 + JS_NUMBER_LITERAL@102..103 + JS_NUMBER_LITERAL_TOKEN@102..103 "5" + WHITESPACE@103..104 " " + PLUS@104..105 "+" + WHITESPACE@105..106 " " + JS_NUMBER_LITERAL@106..107 + JS_NUMBER_LITERAL_TOKEN@106..107 "6" + WHITESPACE@107..108 " " + MINUS@108..109 "-" + WHITESPACE@109..110 " " + JS_BINARY_EXPRESSION@110..124 + JS_BINARY_EXPRESSION@110..115 + JS_NUMBER_LITERAL@110..111 + JS_NUMBER_LITERAL_TOKEN@110..111 "1" WHITESPACE@111..112 " " - JS_NUMBER_LITERAL@112..113 - JS_NUMBER_LITERAL_TOKEN@112..113 "6" - WHITESPACE@113..114 "\n" + STAR@112..113 "*" + WHITESPACE@113..114 " " + JS_NUMBER_LITERAL@114..115 + JS_NUMBER_LITERAL_TOKEN@114..115 "2" + WHITESPACE@115..116 " " + SLASH@116..117 "/" + WHITESPACE@117..118 " " + JS_BINARY_EXPRESSION@118..124 + JS_NUMBER_LITERAL@118..119 + JS_NUMBER_LITERAL_TOKEN@118..119 "1" + WHITESPACE@119..120 " " + STAR2@120..122 "**" + WHITESPACE@122..123 " " + JS_NUMBER_LITERAL@123..124 + JS_NUMBER_LITERAL_TOKEN@123..124 "6" + WHITESPACE@124..125 "\n" diff --git a/crates/rslint_parser/test_data/inline/ok/class_decl.js b/crates/rslint_parser/test_data/inline/ok/class_decl.js new file mode 100644 index 00000000000..4a2383ca5b0 --- /dev/null +++ b/crates/rslint_parser/test_data/inline/ok/class_decl.js @@ -0,0 +1,3 @@ +class foo {} +class foo extends bar {} +class foo extends foo.bar {} diff --git a/crates/rslint_parser/test_data/inline/ok/class_decl.rast b/crates/rslint_parser/test_data/inline/ok/class_decl.rast new file mode 100644 index 00000000000..34aa40b7b65 --- /dev/null +++ b/crates/rslint_parser/test_data/inline/ok/class_decl.rast @@ -0,0 +1,49 @@ +JS_ROOT@0..67 + LIST@0..0 + LIST@0..66 + JS_CLASS_DECLARATION@0..12 + CLASS_KW@0..5 "class" + WHITESPACE@5..6 " " + JS_IDENTIFIER_BINDING@6..9 + IDENT@6..9 "foo" + WHITESPACE@9..10 " " + L_CURLY@10..11 "{" + LIST@11..11 + R_CURLY@11..12 "}" + WHITESPACE@12..13 "\n" + JS_CLASS_DECLARATION@13..37 + CLASS_KW@13..18 "class" + WHITESPACE@18..19 " " + JS_IDENTIFIER_BINDING@19..22 + IDENT@19..22 "foo" + WHITESPACE@22..23 " " + JS_EXTENDS_CLAUSE@23..34 + EXTENDS_KW@23..30 "extends" + WHITESPACE@30..31 " " + JS_REFERENCE_IDENTIFIER_EXPRESSION@31..34 + IDENT@31..34 "bar" + WHITESPACE@34..35 " " + L_CURLY@35..36 "{" + LIST@36..36 + R_CURLY@36..37 "}" + WHITESPACE@37..38 "\n" + JS_CLASS_DECLARATION@38..66 + CLASS_KW@38..43 "class" + WHITESPACE@43..44 " " + JS_IDENTIFIER_BINDING@44..47 + IDENT@44..47 "foo" + WHITESPACE@47..48 " " + JS_EXTENDS_CLAUSE@48..63 + EXTENDS_KW@48..55 "extends" + WHITESPACE@55..56 " " + DOT_EXPR@56..63 + JS_REFERENCE_IDENTIFIER_EXPRESSION@56..59 + IDENT@56..59 "foo" + DOT@59..60 "." + NAME@60..63 + IDENT@60..63 "bar" + WHITESPACE@63..64 " " + L_CURLY@64..65 "{" + LIST@65..65 + R_CURLY@65..66 "}" + WHITESPACE@66..67 "\n" diff --git a/crates/rslint_parser/test_data/inline/ok/grouping_expr.js b/crates/rslint_parser/test_data/inline/ok/grouping_expr.js new file mode 100644 index 00000000000..0b56526bc61 --- /dev/null +++ b/crates/rslint_parser/test_data/inline/ok/grouping_expr.js @@ -0,0 +1,2 @@ +((foo)) +(foo) diff --git a/crates/rslint_parser/test_data/inline/ok/grouping_expr.rast b/crates/rslint_parser/test_data/inline/ok/grouping_expr.rast new file mode 100644 index 00000000000..b5365d1d631 --- /dev/null +++ b/crates/rslint_parser/test_data/inline/ok/grouping_expr.rast @@ -0,0 +1,21 @@ +JS_ROOT@0..14 + LIST@0..0 + LIST@0..13 + JS_EXPRESSION_STATEMENT@0..13 + CALL_EXPR@0..13 + JS_PARENTHESIZED_EXPRESSION@0..7 + L_PAREN@0..1 "(" + JS_PARENTHESIZED_EXPRESSION@1..6 + L_PAREN@1..2 "(" + JS_REFERENCE_IDENTIFIER_EXPRESSION@2..5 + IDENT@2..5 "foo" + R_PAREN@5..6 ")" + R_PAREN@6..7 ")" + WHITESPACE@7..8 "\n" + ARG_LIST@8..13 + L_PAREN@8..9 "(" + LIST@9..12 + JS_REFERENCE_IDENTIFIER_EXPRESSION@9..12 + IDENT@9..12 "foo" + R_PAREN@12..13 ")" + WHITESPACE@13..14 "\n" diff --git a/crates/rslint_parser/test_data/inline/ok/object_expr_getter_getter.js b/crates/rslint_parser/test_data/inline/ok/object_expr_getter_getter.js new file mode 100644 index 00000000000..962c788d77f --- /dev/null +++ b/crates/rslint_parser/test_data/inline/ok/object_expr_getter_getter.js @@ -0,0 +1,5 @@ +let a = { + get foo() { + return foo; + } +} diff --git a/crates/rslint_parser/test_data/inline/ok/object_expr_getter_getter.rast b/crates/rslint_parser/test_data/inline/ok/object_expr_getter_getter.rast new file mode 100644 index 00000000000..2b014d02a9a --- /dev/null +++ b/crates/rslint_parser/test_data/inline/ok/object_expr_getter_getter.rast @@ -0,0 +1,44 @@ +JS_ROOT@0..43 + LIST@0..0 + LIST@0..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 " " + JS_OBJECT_EXPRESSION@8..42 + L_CURLY@8..9 "{" + WHITESPACE@9..11 "\n " + LIST@11..40 + JS_GETTER_OBJECT_MEMBER@11..40 + GET_KW@11..14 "get" + WHITESPACE@14..15 " " + JS_LITERAL_MEMBER_NAME@15..18 + IDENT@15..18 "foo" + L_PAREN@18..19 "(" + R_PAREN@19..20 ")" + WHITESPACE@20..21 " " + JS_FUNCTION_BODY@21..40 + L_CURLY@21..22 "{" + WHITESPACE@22..26 "\n " + LIST@26..26 + LIST@26..37 + JS_RETURN_STATEMENT@26..37 + RETURN_KW@26..32 "return" + WHITESPACE@32..33 " " + JS_REFERENCE_IDENTIFIER_EXPRESSION@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.js b/crates/rslint_parser/test_data/inline/ok/object_expr_getter_setter.js new file mode 100644 index 00000000000..326052c01da --- /dev/null +++ b/crates/rslint_parser/test_data/inline/ok/object_expr_getter_setter.js @@ -0,0 +1,5 @@ +let b = { + set [foo](bar) { + return 5; + } +} 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 new file mode 100644 index 00000000000..f1d64733f91 --- /dev/null +++ b/crates/rslint_parser/test_data/inline/ok/object_expr_getter_setter.rast @@ -0,0 +1,50 @@ +JS_ROOT@0..47 + LIST@0..0 + LIST@0..46 + JS_VARIABLE_DECLARATION_STATEMENT@0..46 + JS_VARIABLE_DECLARATION@0..46 + LET_KW@0..3 "let" + WHITESPACE@3..4 " " + LIST@4..46 + JS_VARIABLE_DECLARATOR@4..46 + SINGLE_PATTERN@4..5 + NAME@4..5 + IDENT@4..5 "b" + WHITESPACE@5..6 " " + JS_EQUAL_VALUE_CLAUSE@6..46 + EQ@6..7 "=" + WHITESPACE@7..8 " " + JS_OBJECT_EXPRESSION@8..46 + L_CURLY@8..9 "{" + WHITESPACE@9..11 "\n " + LIST@11..44 + JS_SETTER_OBJECT_MEMBER@11..44 + SET_KW@11..14 "set" + WHITESPACE@14..15 " " + JS_COMPUTED_MEMBER_NAME@15..20 + L_BRACK@15..16 "[" + JS_REFERENCE_IDENTIFIER_EXPRESSION@16..19 + IDENT@16..19 "foo" + R_BRACK@19..20 "]" + L_PAREN@20..21 "(" + SINGLE_PATTERN@21..24 + NAME@21..24 + IDENT@21..24 "bar" + R_PAREN@24..25 ")" + WHITESPACE@25..26 " " + JS_FUNCTION_BODY@26..44 + L_CURLY@26..27 "{" + WHITESPACE@27..32 "\n " + LIST@32..32 + LIST@32..41 + JS_RETURN_STATEMENT@32..41 + RETURN_KW@32..38 "return" + WHITESPACE@38..39 " " + JS_NUMBER_LITERAL@39..40 + JS_NUMBER_LITERAL_TOKEN@39..40 "5" + SEMICOLON@40..41 ";" + WHITESPACE@41..43 "\n " + R_CURLY@43..44 "}" + WHITESPACE@44..45 "\n" + R_CURLY@45..46 "}" + WHITESPACE@46..47 "\n" diff --git a/crates/rslint_parser/test_data/inline/ok/object_expr_method.js b/crates/rslint_parser/test_data/inline/ok/object_expr_method.js index d7c0ef23dd5..be9b39fd567 100644 --- a/crates/rslint_parser/test_data/inline/ok/object_expr_method.js +++ b/crates/rslint_parser/test_data/inline/ok/object_expr_method.js @@ -1,6 +1,3 @@ let b = { - foo() {}, - "bar"(a, b, c) {}, - ["foo" + "bar"](a) {}, - 5(...rest) {} + foo() {}, } 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 ff6d2fee9f5..fe568747581 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,111 +1,37 @@ -JS_ROOT@0..83 +JS_ROOT@0..23 LIST@0..0 - LIST@0..82 - JS_VARIABLE_DECLARATION_STATEMENT@0..82 - JS_VARIABLE_DECLARATION@0..82 + LIST@0..22 + JS_VARIABLE_DECLARATION_STATEMENT@0..22 + JS_VARIABLE_DECLARATION@0..22 LET_KW@0..3 "let" WHITESPACE@3..4 " " - LIST@4..82 - JS_VARIABLE_DECLARATOR@4..82 + 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..82 + JS_EQUAL_VALUE_CLAUSE@6..22 EQ@6..7 "=" WHITESPACE@7..8 " " - JS_OBJECT_EXPRESSION@8..82 + JS_OBJECT_EXPRESSION@8..22 L_CURLY@8..9 "{" - WHITESPACE@9..12 "\n \t" - LIST@12..80 - JS_METHOD_OBJECT_MEMBER@12..20 - JS_LITERAL_MEMBER_NAME@12..15 - IDENT@12..15 "foo" - JS_PARAMETER_LIST@15..17 - L_PAREN@15..16 "(" - LIST@16..16 - R_PAREN@16..17 ")" - WHITESPACE@17..18 " " - JS_FUNCTION_BODY@18..20 - L_CURLY@18..19 "{" - LIST@19..19 - LIST@19..19 - R_CURLY@19..20 "}" - COMMA@20..21 "," - WHITESPACE@21..23 "\n\t" - JS_METHOD_OBJECT_MEMBER@23..40 - JS_LITERAL_MEMBER_NAME@23..28 - JS_STRING_LITERAL_TOKEN@23..28 "\"bar\"" - JS_PARAMETER_LIST@28..37 - L_PAREN@28..29 "(" - LIST@29..36 - SINGLE_PATTERN@29..30 - NAME@29..30 - IDENT@29..30 "a" - COMMA@30..31 "," - WHITESPACE@31..32 " " - SINGLE_PATTERN@32..33 - NAME@32..33 - IDENT@32..33 "b" - COMMA@33..34 "," - WHITESPACE@34..35 " " - SINGLE_PATTERN@35..36 - NAME@35..36 - IDENT@35..36 "c" - R_PAREN@36..37 ")" - WHITESPACE@37..38 " " - JS_FUNCTION_BODY@38..40 - L_CURLY@38..39 "{" - LIST@39..39 - LIST@39..39 - R_CURLY@39..40 "}" - COMMA@40..41 "," - WHITESPACE@41..43 "\n\t" - JS_METHOD_OBJECT_MEMBER@43..64 - JS_COMPUTED_MEMBER_NAME@43..58 - L_BRACK@43..44 "[" - JS_BINARY_EXPRESSION@44..57 - JS_STRING_LITERAL@44..49 - JS_STRING_LITERAL_TOKEN@44..49 "\"foo\"" - WHITESPACE@49..50 " " - PLUS@50..51 "+" - WHITESPACE@51..52 " " - JS_STRING_LITERAL@52..57 - JS_STRING_LITERAL_TOKEN@52..57 "\"bar\"" - R_BRACK@57..58 "]" - JS_PARAMETER_LIST@58..61 - L_PAREN@58..59 "(" - LIST@59..60 - SINGLE_PATTERN@59..60 - NAME@59..60 - IDENT@59..60 "a" - R_PAREN@60..61 ")" - WHITESPACE@61..62 " " - JS_FUNCTION_BODY@62..64 - L_CURLY@62..63 "{" - LIST@63..63 - LIST@63..63 - R_CURLY@63..64 "}" - COMMA@64..65 "," - WHITESPACE@65..67 "\n\t" - JS_METHOD_OBJECT_MEMBER@67..80 - JS_LITERAL_MEMBER_NAME@67..68 - JS_NUMBER_LITERAL_TOKEN@67..68 "5" - JS_PARAMETER_LIST@68..77 - L_PAREN@68..69 "(" - LIST@69..76 - JS_REST_PARAMETER@69..76 - DOT2@69..72 "..." - SINGLE_PATTERN@72..76 - NAME@72..76 - IDENT@72..76 "rest" - R_PAREN@76..77 ")" - WHITESPACE@77..78 " " - JS_FUNCTION_BODY@78..80 - L_CURLY@78..79 "{" - LIST@79..79 - LIST@79..79 - R_CURLY@79..80 "}" - WHITESPACE@80..81 "\n" - R_CURLY@81..82 "}" - WHITESPACE@82..83 "\n" + WHITESPACE@9..11 "\n " + LIST@11..20 + JS_METHOD_OBJECT_MEMBER@11..19 + JS_LITERAL_MEMBER_NAME@11..14 + IDENT@11..14 "foo" + JS_PARAMETER_LIST@14..16 + L_PAREN@14..15 "(" + LIST@15..15 + R_PAREN@15..16 ")" + WHITESPACE@16..17 " " + JS_FUNCTION_BODY@17..19 + L_CURLY@17..18 "{" + LIST@18..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_member_name.js b/crates/rslint_parser/test_data/inline/ok/object_member_name.js new file mode 100644 index 00000000000..c5dcdbad15d --- /dev/null +++ b/crates/rslint_parser/test_data/inline/ok/object_member_name.js @@ -0,0 +1 @@ +let a = {"foo": foo, [6 + 6]: foo, bar: foo, 7: foo} diff --git a/crates/rslint_parser/test_data/inline/ok/object_member_name.rast b/crates/rslint_parser/test_data/inline/ok/object_member_name.rast new file mode 100644 index 00000000000..747486e33ec --- /dev/null +++ b/crates/rslint_parser/test_data/inline/ok/object_member_name.rast @@ -0,0 +1,64 @@ +JS_ROOT@0..53 + LIST@0..0 + LIST@0..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 " " + JS_OBJECT_EXPRESSION@8..52 + L_CURLY@8..9 "{" + LIST@9..51 + JS_PROPERTY_OBJECT_MEMBER@9..19 + JS_LITERAL_MEMBER_NAME@9..14 + JS_STRING_LITERAL_TOKEN@9..14 "\"foo\"" + COLON@14..15 ":" + WHITESPACE@15..16 " " + JS_REFERENCE_IDENTIFIER_EXPRESSION@16..19 + IDENT@16..19 "foo" + COMMA@19..20 "," + WHITESPACE@20..21 " " + JS_PROPERTY_OBJECT_MEMBER@21..33 + JS_COMPUTED_MEMBER_NAME@21..28 + L_BRACK@21..22 "[" + JS_BINARY_EXPRESSION@22..27 + JS_NUMBER_LITERAL@22..23 + JS_NUMBER_LITERAL_TOKEN@22..23 "6" + WHITESPACE@23..24 " " + PLUS@24..25 "+" + WHITESPACE@25..26 " " + JS_NUMBER_LITERAL@26..27 + JS_NUMBER_LITERAL_TOKEN@26..27 "6" + R_BRACK@27..28 "]" + COLON@28..29 ":" + WHITESPACE@29..30 " " + JS_REFERENCE_IDENTIFIER_EXPRESSION@30..33 + IDENT@30..33 "foo" + COMMA@33..34 "," + WHITESPACE@34..35 " " + JS_PROPERTY_OBJECT_MEMBER@35..43 + JS_LITERAL_MEMBER_NAME@35..38 + IDENT@35..38 "bar" + COLON@38..39 ":" + WHITESPACE@39..40 " " + JS_REFERENCE_IDENTIFIER_EXPRESSION@40..43 + IDENT@40..43 "foo" + COMMA@43..44 "," + WHITESPACE@44..45 " " + JS_PROPERTY_OBJECT_MEMBER@45..51 + JS_LITERAL_MEMBER_NAME@45..46 + JS_NUMBER_LITERAL_TOKEN@45..46 "7" + COLON@46..47 ":" + WHITESPACE@47..48 " " + JS_REFERENCE_IDENTIFIER_EXPRESSION@48..51 + IDENT@48..51 "foo" + R_CURLY@51..52 "}" + WHITESPACE@52..53 "\n" diff --git a/crates/rslint_parser/test_data/inline/ok/postfix_expr.js b/crates/rslint_parser/test_data/inline/ok/postfix_expr.js new file mode 100644 index 00000000000..0ff56e1688a --- /dev/null +++ b/crates/rslint_parser/test_data/inline/ok/postfix_expr.js @@ -0,0 +1,2 @@ +foo++ +foo-- diff --git a/crates/rslint_parser/test_data/inline/ok/postfix_expr.rast b/crates/rslint_parser/test_data/inline/ok/postfix_expr.rast new file mode 100644 index 00000000000..9e8b4f38a3d --- /dev/null +++ b/crates/rslint_parser/test_data/inline/ok/postfix_expr.rast @@ -0,0 +1,15 @@ +JS_ROOT@0..12 + LIST@0..0 + LIST@0..11 + JS_EXPRESSION_STATEMENT@0..5 + JS_POST_UPDATE_EXPRESSION@0..5 + JS_REFERENCE_IDENTIFIER_EXPRESSION@0..3 + IDENT@0..3 "foo" + PLUS2@3..5 "++" + WHITESPACE@5..6 "\n" + JS_EXPRESSION_STATEMENT@6..11 + JS_POST_UPDATE_EXPRESSION@6..11 + JS_REFERENCE_IDENTIFIER_EXPRESSION@6..9 + IDENT@6..9 "foo" + MINUS2@9..11 "--" + WHITESPACE@11..12 "\n" diff --git a/crates/rslint_parser/test_data/inline/ok/try_stmt.js b/crates/rslint_parser/test_data/inline/ok/try_stmt.js index d7467eb2619..352228f2c7b 100644 --- a/crates/rslint_parser/test_data/inline/ok/try_stmt.js +++ b/crates/rslint_parser/test_data/inline/ok/try_stmt.js @@ -1,5 +1,2 @@ -try {} catch {} try {} catch (e) {} try {} catch {} finally {} -try {} catch (e) {} finally {} -try {} finally {} diff --git a/crates/rslint_parser/test_data/inline/ok/try_stmt.rast b/crates/rslint_parser/test_data/inline/ok/try_stmt.rast index b7351a05d76..4593ff996db 100644 --- a/crates/rslint_parser/test_data/inline/ok/try_stmt.rast +++ b/crates/rslint_parser/test_data/inline/ok/try_stmt.rast @@ -1,7 +1,7 @@ -JS_ROOT@0..112 +JS_ROOT@0..47 LIST@0..0 - LIST@0..111 - JS_TRY_STATEMENT@0..15 + LIST@0..46 + JS_TRY_STATEMENT@0..19 TRY_KW@0..3 "try" WHITESPACE@3..4 " " JS_BLOCK_STATEMENT@4..6 @@ -9,105 +9,42 @@ JS_ROOT@0..112 LIST@5..5 R_CURLY@5..6 "}" WHITESPACE@6..7 " " - JS_CATCH_CLAUSE@7..15 + JS_CATCH_CLAUSE@7..19 CATCH_KW@7..12 "catch" WHITESPACE@12..13 " " - JS_BLOCK_STATEMENT@13..15 - L_CURLY@13..14 "{" - LIST@14..14 - R_CURLY@14..15 "}" - WHITESPACE@15..16 "\n" - JS_TRY_STATEMENT@16..35 - TRY_KW@16..19 "try" - WHITESPACE@19..20 " " - JS_BLOCK_STATEMENT@20..22 - L_CURLY@20..21 "{" - LIST@21..21 - R_CURLY@21..22 "}" - WHITESPACE@22..23 " " - JS_CATCH_CLAUSE@23..35 - CATCH_KW@23..28 "catch" - WHITESPACE@28..29 " " - JS_CATCH_DECLARATION@29..32 - L_PAREN@29..30 "(" - SINGLE_PATTERN@30..31 - NAME@30..31 - IDENT@30..31 "e" - R_PAREN@31..32 ")" + JS_CATCH_DECLARATION@13..16 + L_PAREN@13..14 "(" + SINGLE_PATTERN@14..15 + NAME@14..15 + IDENT@14..15 "e" + 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 "\n" + JS_TRY_FINALLY_STATEMENT@20..46 + TRY_KW@20..23 "try" + WHITESPACE@23..24 " " + JS_BLOCK_STATEMENT@24..26 + L_CURLY@24..25 "{" + LIST@25..25 + R_CURLY@25..26 "}" + WHITESPACE@26..27 " " + JS_CATCH_CLAUSE@27..35 + CATCH_KW@27..32 "catch" WHITESPACE@32..33 " " JS_BLOCK_STATEMENT@33..35 L_CURLY@33..34 "{" LIST@34..34 R_CURLY@34..35 "}" - WHITESPACE@35..36 "\n" - JS_TRY_FINALLY_STATEMENT@36..62 - TRY_KW@36..39 "try" - WHITESPACE@39..40 " " - JS_BLOCK_STATEMENT@40..42 - L_CURLY@40..41 "{" - LIST@41..41 - R_CURLY@41..42 "}" - WHITESPACE@42..43 " " - JS_CATCH_CLAUSE@43..51 - CATCH_KW@43..48 "catch" - WHITESPACE@48..49 " " - JS_BLOCK_STATEMENT@49..51 - L_CURLY@49..50 "{" - LIST@50..50 - R_CURLY@50..51 "}" - WHITESPACE@51..52 " " - JS_FINALLY_CLAUSE@52..62 - FINALLY_KW@52..59 "finally" - WHITESPACE@59..60 " " - JS_BLOCK_STATEMENT@60..62 - L_CURLY@60..61 "{" - LIST@61..61 - R_CURLY@61..62 "}" - WHITESPACE@62..63 "\n" - JS_TRY_FINALLY_STATEMENT@63..93 - TRY_KW@63..66 "try" - WHITESPACE@66..67 " " - JS_BLOCK_STATEMENT@67..69 - L_CURLY@67..68 "{" - LIST@68..68 - R_CURLY@68..69 "}" - WHITESPACE@69..70 " " - JS_CATCH_CLAUSE@70..82 - CATCH_KW@70..75 "catch" - WHITESPACE@75..76 " " - JS_CATCH_DECLARATION@76..79 - L_PAREN@76..77 "(" - SINGLE_PATTERN@77..78 - NAME@77..78 - IDENT@77..78 "e" - R_PAREN@78..79 ")" - WHITESPACE@79..80 " " - JS_BLOCK_STATEMENT@80..82 - L_CURLY@80..81 "{" - LIST@81..81 - R_CURLY@81..82 "}" - WHITESPACE@82..83 " " - JS_FINALLY_CLAUSE@83..93 - FINALLY_KW@83..90 "finally" - WHITESPACE@90..91 " " - JS_BLOCK_STATEMENT@91..93 - L_CURLY@91..92 "{" - LIST@92..92 - R_CURLY@92..93 "}" - WHITESPACE@93..94 "\n" - JS_TRY_FINALLY_STATEMENT@94..111 - TRY_KW@94..97 "try" - WHITESPACE@97..98 " " - JS_BLOCK_STATEMENT@98..100 - L_CURLY@98..99 "{" - LIST@99..99 - R_CURLY@99..100 "}" - WHITESPACE@100..101 " " - JS_FINALLY_CLAUSE@101..111 - FINALLY_KW@101..108 "finally" - WHITESPACE@108..109 " " - JS_BLOCK_STATEMENT@109..111 - L_CURLY@109..110 "{" - LIST@110..110 - R_CURLY@110..111 "}" - WHITESPACE@111..112 "\n" + WHITESPACE@35..36 " " + JS_FINALLY_CLAUSE@36..46 + FINALLY_KW@36..43 "finally" + WHITESPACE@43..44 " " + JS_BLOCK_STATEMENT@44..46 + L_CURLY@44..45 "{" + LIST@45..45 + R_CURLY@45..46 "}" + WHITESPACE@46..47 "\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 b480d7c9815..d7c04afe472 100644 --- a/crates/rslint_parser/test_data/inline/ok/var_decl.js +++ b/crates/rslint_parser/test_data/inline/ok/var_decl.js @@ -3,4 +3,3 @@ 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 c05d234f86e..d91b48b65cf 100644 --- a/crates/rslint_parser/test_data/inline/ok/var_decl.rast +++ b/crates/rslint_parser/test_data/inline/ok/var_decl.rast @@ -1,6 +1,6 @@ -JS_ROOT@0..155 +JS_ROOT@0..92 LIST@0..0 - LIST@0..154 + LIST@0..91 JS_VARIABLE_DECLARATION_STATEMENT@0..10 JS_VARIABLE_DECLARATION@0..9 VAR_KW@0..3 "var" @@ -118,57 +118,4 @@ JS_ROOT@0..155 LIST@89..89 R_CURLY@89..90 "}" SEMICOLON@90..91 ";" - 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 " " - JS_STRING_LITERAL@102..109 - JS_STRING_LITERAL_TOKEN@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 " " - JS_STRING_LITERAL@117..124 - JS_STRING_LITERAL_TOKEN@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 " " - JS_STRING_LITERAL@134..141 - JS_STRING_LITERAL_TOKEN@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 " " - JS_NUMBER_LITERAL@152..153 - JS_NUMBER_LITERAL_TOKEN@152..153 "6" - SEMICOLON@153..154 ";" - WHITESPACE@154..155 "\n" + WHITESPACE@91..92 "\n" diff --git a/crates/rslint_parser/test_data/inline/ok/yield_expr.js b/crates/rslint_parser/test_data/inline/ok/yield_expr.js index f2874a011b9..bde6bc509a8 100644 --- a/crates/rslint_parser/test_data/inline/ok/yield_expr.js +++ b/crates/rslint_parser/test_data/inline/ok/yield_expr.js @@ -1,5 +1,4 @@ function *foo() { yield foo; yield* foo; - yield; } diff --git a/crates/rslint_parser/test_data/inline/ok/yield_expr.rast b/crates/rslint_parser/test_data/inline/ok/yield_expr.rast index 761d8627fe2..65c196dde2c 100644 --- a/crates/rslint_parser/test_data/inline/ok/yield_expr.rast +++ b/crates/rslint_parser/test_data/inline/ok/yield_expr.rast @@ -1,7 +1,7 @@ -JS_ROOT@0..53 +JS_ROOT@0..45 LIST@0..0 - LIST@0..52 - JS_FUNCTION_DECLARATION@0..52 + LIST@0..44 + JS_FUNCTION_DECLARATION@0..44 FUNCTION_KW@0..8 "function" WHITESPACE@8..9 " " STAR@9..10 "*" @@ -12,11 +12,11 @@ JS_ROOT@0..53 LIST@14..14 R_PAREN@14..15 ")" WHITESPACE@15..16 " " - JS_FUNCTION_BODY@16..52 + JS_FUNCTION_BODY@16..44 L_CURLY@16..17 "{" WHITESPACE@17..19 "\n " LIST@19..19 - LIST@19..50 + LIST@19..42 JS_EXPRESSION_STATEMENT@19..29 JS_YIELD_EXPRESSION@19..28 YIELD_KW@19..24 "yield" @@ -33,11 +33,6 @@ JS_ROOT@0..53 JS_REFERENCE_IDENTIFIER_EXPRESSION@38..41 IDENT@38..41 "foo" SEMICOLON@41..42 ";" - WHITESPACE@42..44 "\n " - JS_EXPRESSION_STATEMENT@44..50 - JS_YIELD_EXPRESSION@44..49 - YIELD_KW@44..49 "yield" - SEMICOLON@49..50 ";" - WHITESPACE@50..51 "\n" - R_CURLY@51..52 "}" - WHITESPACE@52..53 "\n" + WHITESPACE@42..43 "\n" + R_CURLY@43..44 "}" + WHITESPACE@44..45 "\n" From 33fa14f3fba4d76af280e6bc1d4c8b5d6bcfd3b5 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Fri, 19 Nov 2021 16:45:35 -0300 Subject: [PATCH 12/13] chore: restored tests --- crates/rslint_parser/src/syntax/class.rs | 35 +++ crates/rslint_parser/src/syntax/expr.rs | 2 + crates/rslint_parser/src/syntax/object.rs | 4 + crates/rslint_parser/src/syntax/stmt.rs | 5 + .../test_data/inline/err/class_decl_err.js | 2 + .../test_data/inline/err/class_decl_err.rast | 66 ++++- .../test_data/inline/err/for_stmt_err.js | 1 + .../test_data/inline/err/for_stmt_err.rast | 63 ++++- .../err/paren_or_arrow_expr_invalid_params.js | 1 + .../paren_or_arrow_expr_invalid_params.rast | 79 +++++- .../inline/ok/getter_class_member.js | 6 - .../inline/ok/getter_class_member.rast | 258 +++++++++--------- .../test_data/inline/ok/object_expr_method.js | 4 + .../inline/ok/object_expr_method.rast | 113 +++++++- .../inline/ok/setter_class_number.js | 14 + .../inline/ok/setter_class_number.rast | 211 ++++++++++++++ .../test_data/inline/ok/try_stmt.js | 3 + .../test_data/inline/ok/try_stmt.rast | 133 ++++++--- .../test_data/inline/ok/var_decl.js | 1 + .../test_data/inline/ok/var_decl.rast | 59 +++- .../test_data/inline/ok/yield_expr.js | 1 + .../test_data/inline/ok/yield_expr.rast | 21 +- 22 files changed, 880 insertions(+), 202 deletions(-) create mode 100644 crates/rslint_parser/test_data/inline/ok/setter_class_number.js create mode 100644 crates/rslint_parser/test_data/inline/ok/setter_class_number.rast diff --git a/crates/rslint_parser/src/syntax/class.rs b/crates/rslint_parser/src/syntax/class.rs index 6f83042758b..9fd97f9570b 100644 --- a/crates/rslint_parser/src/syntax/class.rs +++ b/crates/rslint_parser/src/syntax/class.rs @@ -30,6 +30,8 @@ pub(super) fn class_expression(p: &mut Parser) -> CompletedMarker { // class extends {} // class // class foo { set {} } +// class A extends bar extends foo {} +// class A extends bar, foo {} /// Parses a class declaration pub(super) fn class_declaration(p: &mut Parser) -> CompletedMarker { class(p, ClassKind::Declaration) @@ -479,6 +481,39 @@ fn class_member(p: &mut Parser) -> Option { if matches!(member_name, "get" | "set") && !is_at_line_break_or_generator { let is_getter = member_name == "get"; + // test getter_class_member + // class Getters { + // get foo() {} + // get static() {} + // static get bar() {} + // get "baz"() {} + // get ["a" + "b"]() {} + // get 5() {} + // get #private() {} + // } + // class NotGetters { + // get() {} + // async get() {} + // static get() {} + // } + + // test setter_class_number + // class Setters { + // set foo(a) {} + // set static(a) {} + // static set bar(a) {} + // set "baz"(a) {} + // set ["a" + "b"](a) {} + // set 5(a) {} + // set #private(a) {} + // } + // class NotSetters { + // set(a) {} + // async set(a) {} + // static set(a) {} + // } + + // The tree currently holds a STATIC_MEMBER_NAME node that wraps a ident token but we now found // out that the 'get' or 'set' isn't a member name in this context but instead are the // 'get'/'set' keywords for getters/setters. That's why we need to undo the member name node, diff --git a/crates/rslint_parser/src/syntax/expr.rs b/crates/rslint_parser/src/syntax/expr.rs index 063f2c01da3..40377cddda3 100644 --- a/crates/rslint_parser/src/syntax/expr.rs +++ b/crates/rslint_parser/src/syntax/expr.rs @@ -246,6 +246,7 @@ fn assign_expr_recursive( // function *foo() { // yield foo; // yield* foo; +// yield; // } pub fn yield_expr(p: &mut Parser) -> CompletedMarker { let m = p.start(); @@ -673,6 +674,7 @@ pub fn args(p: &mut Parser) -> CompletedMarker { // test_err paren_or_arrow_expr_invalid_params // (5 + 5) => {} +// (a, ,b) => {} pub fn paren_or_arrow_expr(p: &mut Parser, can_be_arrow: bool) -> CompletedMarker { let m = p.start(); let checkpoint = p.checkpoint(); diff --git a/crates/rslint_parser/src/syntax/object.rs b/crates/rslint_parser/src/syntax/object.rs index 6350b86a5b4..df47507e7bf 100644 --- a/crates/rslint_parser/src/syntax/object.rs +++ b/crates/rslint_parser/src/syntax/object.rs @@ -106,6 +106,10 @@ fn object_member(p: &mut Parser) -> Option { // test object_expr_method // let b = { // foo() {}, + // foo() {}, + // "bar"(a, b, c) {}, + // ["foo" + "bar"](a) {}, + // 5(...rest) {} // } if p.at(T!['(']) || p.at(T![<]) { method_object_member_body(p).ok()?; diff --git a/crates/rslint_parser/src/syntax/stmt.rs b/crates/rslint_parser/src/syntax/stmt.rs index c0c0c82b1b4..1aa2790226f 100644 --- a/crates/rslint_parser/src/syntax/stmt.rs +++ b/crates/rslint_parser/src/syntax/stmt.rs @@ -687,6 +687,7 @@ pub fn while_stmt(p: &mut Parser) -> CompletedMarker { // let bar, foo; // const a = 5; // const { foo: [bar], baz } = {}; +// let foo = "lorem", bar = "ipsum", third = "value", fourth = 6; pub fn variable_declaration_statement(p: &mut Parser) -> CompletedMarker { // test_err var_decl_err // var a =; @@ -951,6 +952,7 @@ pub fn for_stmt(p: &mut Parser) -> CompletedMarker { // test_err for_stmt_err // for ;; {} // for let i = 5; i < 10; i++ {} + // for let i = 5; i < 10; ++i {} let m = p.start(); p.expect(T![for]); // FIXME: This should emit an error for non-for-of @@ -1136,8 +1138,11 @@ fn catch_declaration(p: &mut Parser) { /// } /// ``` // test try_stmt +// try {} catch {} // try {} catch (e) {} // try {} catch {} finally {} +// try {} catch (e) {} finally {} +// try {} finally {} pub fn try_stmt(p: &mut Parser) -> CompletedMarker { // TODO: recover from `try catch` and `try finally`. The issue is block_items // will cause infinite recursion because parsing a stmt would not consume the catch token diff --git a/crates/rslint_parser/test_data/inline/err/class_decl_err.js b/crates/rslint_parser/test_data/inline/err/class_decl_err.js index 4f57464d9c7..c774c80df95 100644 --- a/crates/rslint_parser/test_data/inline/err/class_decl_err.js +++ b/crates/rslint_parser/test_data/inline/err/class_decl_err.js @@ -3,3 +3,5 @@ class extends bar {} class extends {} class class foo { set {} } +class A extends bar extends foo {} +class A extends bar, foo {} diff --git a/crates/rslint_parser/test_data/inline/err/class_decl_err.rast b/crates/rslint_parser/test_data/inline/err/class_decl_err.rast index bafd9f4c96e..a3865f0dbaa 100644 --- a/crates/rslint_parser/test_data/inline/err/class_decl_err.rast +++ b/crates/rslint_parser/test_data/inline/err/class_decl_err.rast @@ -1,6 +1,6 @@ -JS_ROOT@0..74 +JS_ROOT@0..137 LIST@0..0 - LIST@0..73 + LIST@0..136 JS_CLASS_DECLARATION@0..8 CLASS_KW@0..5 "class" WHITESPACE@5..6 " " @@ -57,7 +57,51 @@ JS_ROOT@0..74 R_CURLY@70..71 "}" WHITESPACE@71..72 " " R_CURLY@72..73 "}" - WHITESPACE@73..74 "\n" + WHITESPACE@73..74 "\n" + JS_CLASS_DECLARATION@74..108 + CLASS_KW@74..79 "class" + WHITESPACE@79..80 " " + JS_IDENTIFIER_BINDING@80..81 + IDENT@80..81 "A" + WHITESPACE@81..82 " " + JS_EXTENDS_CLAUSE@82..105 + EXTENDS_KW@82..89 "extends" + WHITESPACE@89..90 " " + JS_REFERENCE_IDENTIFIER_EXPRESSION@90..93 + IDENT@90..93 "bar" + WHITESPACE@93..94 " " + ERROR@94..105 + EXTENDS_KW@94..101 "extends" + WHITESPACE@101..102 " " + TS_EXPR_WITH_TYPE_ARGS@102..105 + JS_REFERENCE_IDENTIFIER_EXPRESSION@102..105 + IDENT@102..105 "foo" + WHITESPACE@105..106 " " + L_CURLY@106..107 "{" + LIST@107..107 + R_CURLY@107..108 "}" + WHITESPACE@108..109 "\n" + JS_CLASS_DECLARATION@109..136 + CLASS_KW@109..114 "class" + WHITESPACE@114..115 " " + JS_IDENTIFIER_BINDING@115..116 + IDENT@115..116 "A" + WHITESPACE@116..117 " " + JS_EXTENDS_CLAUSE@117..133 + EXTENDS_KW@117..124 "extends" + WHITESPACE@124..125 " " + JS_REFERENCE_IDENTIFIER_EXPRESSION@125..128 + IDENT@125..128 "bar" + COMMA@128..129 "," + WHITESPACE@129..130 " " + TS_EXPR_WITH_TYPE_ARGS@130..133 + JS_REFERENCE_IDENTIFIER_EXPRESSION@130..133 + IDENT@130..133 "foo" + WHITESPACE@133..134 " " + L_CURLY@134..135 "{" + LIST@135..135 + R_CURLY@135..136 "}" + WHITESPACE@136..137 "\n" -- error[SyntaxError]: class declarations must have a name ┌─ class_decl_err.js:1:7 @@ -128,9 +172,25 @@ error[SyntaxError]: expected a block statement but instead found `}` 5 │ class foo { set {} } │ ^ +-- +error[SyntaxError]: classes cannot extend multiple classes + ┌─ class_decl_err.js:6:29 + │ +6 │ class A extends bar extends foo {} + │ ^^^ + +-- +error[SyntaxError]: classes cannot extend multiple classes + ┌─ class_decl_err.js:7:22 + │ +7 │ class A extends bar, foo {} + │ ^^^ + -- class {} class extends bar {} class extends {} class class foo { set {} } +class A extends bar extends foo {} +class A extends bar, foo {} diff --git a/crates/rslint_parser/test_data/inline/err/for_stmt_err.js b/crates/rslint_parser/test_data/inline/err/for_stmt_err.js index 80426b1f7a0..8077c930c6a 100644 --- a/crates/rslint_parser/test_data/inline/err/for_stmt_err.js +++ b/crates/rslint_parser/test_data/inline/err/for_stmt_err.js @@ -1,2 +1,3 @@ for ;; {} for let i = 5; i < 10; i++ {} +for let i = 5; i < 10; ++i {} 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 0317dfe161b..50e04562f80 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 @@ -1,6 +1,6 @@ -JS_ROOT@0..40 +JS_ROOT@0..70 LIST@0..0 - LIST@0..39 + LIST@0..69 FOR_STMT@0..39 FOR_KW@0..3 "for" WHITESPACE@3..4 " " @@ -54,7 +54,49 @@ JS_ROOT@0..40 L_CURLY@37..38 "{" LIST@38..38 R_CURLY@38..39 "}" - WHITESPACE@39..40 "\n" + WHITESPACE@39..40 "\n" + FOR_STMT@40..69 + FOR_KW@40..43 "for" + WHITESPACE@43..44 " " + FOR_STMT_INIT@44..53 + JS_VARIABLE_DECLARATION@44..53 + LET_KW@44..47 "let" + WHITESPACE@47..48 " " + LIST@48..53 + JS_VARIABLE_DECLARATOR@48..53 + SINGLE_PATTERN@48..49 + NAME@48..49 + IDENT@48..49 "i" + WHITESPACE@49..50 " " + JS_EQUAL_VALUE_CLAUSE@50..53 + EQ@50..51 "=" + WHITESPACE@51..52 " " + JS_NUMBER_LITERAL@52..53 + JS_NUMBER_LITERAL_TOKEN@52..53 "5" + SEMICOLON@53..54 ";" + WHITESPACE@54..55 " " + FOR_STMT_TEST@55..61 + JS_BINARY_EXPRESSION@55..61 + JS_REFERENCE_IDENTIFIER_EXPRESSION@55..56 + IDENT@55..56 "i" + WHITESPACE@56..57 " " + L_ANGLE@57..58 "<" + WHITESPACE@58..59 " " + JS_NUMBER_LITERAL@59..61 + JS_NUMBER_LITERAL_TOKEN@59..61 "10" + SEMICOLON@61..62 ";" + WHITESPACE@62..63 " " + FOR_STMT_UPDATE@63..66 + JS_PRE_UPDATE_EXPRESSION@63..66 + PLUS2@63..65 "++" + JS_REFERENCE_IDENTIFIER_EXPRESSION@65..66 + IDENT@65..66 "i" + WHITESPACE@66..67 " " + JS_BLOCK_STATEMENT@67..69 + L_CURLY@67..68 "{" + LIST@68..68 + R_CURLY@68..69 "}" + WHITESPACE@69..70 "\n" -- error[SyntaxError]: expected `'('` but instead found `;` ┌─ for_stmt_err.js:1:5 @@ -83,6 +125,21 @@ error[SyntaxError]: expected `')'` but instead found `{` 2 │ for let i = 5; i < 10; i++ {} │ ^ unexpected +-- +error[SyntaxError]: expected `'('` but instead found `let` + ┌─ for_stmt_err.js:3:5 + │ +3 │ for let i = 5; i < 10; ++i {} + │ ^^^ unexpected + +-- +error[SyntaxError]: expected `')'` but instead found `{` + ┌─ for_stmt_err.js:3:28 + │ +3 │ for let i = 5; i < 10; ++i {} + │ ^ unexpected + -- for ;; {} for let i = 5; i < 10; i++ {} +for let i = 5; i < 10; ++i {} diff --git a/crates/rslint_parser/test_data/inline/err/paren_or_arrow_expr_invalid_params.js b/crates/rslint_parser/test_data/inline/err/paren_or_arrow_expr_invalid_params.js index 5c81884588e..6d568ef5134 100644 --- a/crates/rslint_parser/test_data/inline/err/paren_or_arrow_expr_invalid_params.js +++ b/crates/rslint_parser/test_data/inline/err/paren_or_arrow_expr_invalid_params.js @@ -1 +1,2 @@ (5 + 5) => {} +(a, ,b) => {} diff --git a/crates/rslint_parser/test_data/inline/err/paren_or_arrow_expr_invalid_params.rast b/crates/rslint_parser/test_data/inline/err/paren_or_arrow_expr_invalid_params.rast index fcc08cedeee..086fd2727f1 100644 --- a/crates/rslint_parser/test_data/inline/err/paren_or_arrow_expr_invalid_params.rast +++ b/crates/rslint_parser/test_data/inline/err/paren_or_arrow_expr_invalid_params.rast @@ -1,6 +1,6 @@ -JS_ROOT@0..14 +JS_ROOT@0..28 LIST@0..0 - LIST@0..13 + LIST@0..27 JS_EXPRESSION_STATEMENT@0..6 JS_ARROW_FUNCTION_EXPRESSION@0..6 JS_PARAMETER_LIST@0..4 @@ -23,7 +23,31 @@ JS_ROOT@0..14 L_CURLY@11..12 "{" LIST@12..12 R_CURLY@12..13 "}" - WHITESPACE@13..14 "\n" + WHITESPACE@13..14 "\n" + JS_EXPRESSION_STATEMENT@14..19 + JS_PARENTHESIZED_EXPRESSION@14..19 + L_PAREN@14..15 "(" + JS_SEQUENCE_EXPRESSION@15..19 + JS_REFERENCE_IDENTIFIER_EXPRESSION@15..16 + IDENT@15..16 "a" + COMMA@16..17 "," + WHITESPACE@17..18 " " + ERROR@18..19 + COMMA@18..19 "," + JS_EXPRESSION_STATEMENT@19..20 + JS_REFERENCE_IDENTIFIER_EXPRESSION@19..20 + IDENT@19..20 "b" + JS_UNKNOWN_STATEMENT@20..21 + R_PAREN@20..21 ")" + WHITESPACE@21..22 " " + JS_UNKNOWN_STATEMENT@22..24 + FAT_ARROW@22..24 "=>" + WHITESPACE@24..25 " " + JS_BLOCK_STATEMENT@25..27 + L_CURLY@25..26 "{" + LIST@26..26 + R_CURLY@26..27 "}" + WHITESPACE@27..28 "\n" -- error[SyntaxError]: Expected an identifier or pattern, but found none ┌─ paren_or_arrow_expr_invalid_params.js:1:2 @@ -69,5 +93,54 @@ error[SyntaxError]: Expected a statement or declaration, but found none 1 │ (5 + 5) => {} │ ^^ Expected a statement or declaration here +-- +error[SyntaxError]: Expected an expression, but found none + ┌─ paren_or_arrow_expr_invalid_params.js:2:5 + │ +2 │ (a, ,b) => {} + │ ^ Expected an expression here + +-- +error[SyntaxError]: expected `')'` but instead found `b` + ┌─ paren_or_arrow_expr_invalid_params.js:2:6 + │ +2 │ (a, ,b) => {} + │ ^ unexpected + +-- +error[SyntaxError]: Expected a semicolon or an implicit semicolon after a statement, but found none + ┌─ paren_or_arrow_expr_invalid_params.js:2:6 + │ +2 │ (a, ,b) => {} + │ -----^ + │ │ │ + │ │ An explicit or implicit semicolon is expected here... + │ ...Which is required to end this statement + +-- +error[SyntaxError]: Expected a semicolon or an implicit semicolon after a statement, but found none + ┌─ paren_or_arrow_expr_invalid_params.js:2:7 + │ +2 │ (a, ,b) => {} + │ -^ + │ ││ + │ │An explicit or implicit semicolon is expected here... + │ ...Which is required to end this statement + +-- +error[SyntaxError]: Expected a statement or declaration, but found none + ┌─ paren_or_arrow_expr_invalid_params.js:2:7 + │ +2 │ (a, ,b) => {} + │ ^ Expected a statement or declaration here + +-- +error[SyntaxError]: Expected a statement or declaration, but found none + ┌─ paren_or_arrow_expr_invalid_params.js:2:9 + │ +2 │ (a, ,b) => {} + │ ^^ Expected a statement or declaration here + -- (5 + 5) => {} +(a, ,b) => {} diff --git a/crates/rslint_parser/test_data/inline/ok/getter_class_member.js b/crates/rslint_parser/test_data/inline/ok/getter_class_member.js index a308da7fd74..bbe3aaf1e5f 100644 --- a/crates/rslint_parser/test_data/inline/ok/getter_class_member.js +++ b/crates/rslint_parser/test_data/inline/ok/getter_class_member.js @@ -2,19 +2,13 @@ class Getters { get foo() {} get static() {} static get bar() {} - get "baz"() {} - get ["a" + "b"]() {} - get 5() {} - get #private() {} } - class NotGetters { get() {} async get() {} static get() {} } - diff --git a/crates/rslint_parser/test_data/inline/ok/getter_class_member.rast b/crates/rslint_parser/test_data/inline/ok/getter_class_member.rast index a3f211e2df2..42e7b83808c 100644 --- a/crates/rslint_parser/test_data/inline/ok/getter_class_member.rast +++ b/crates/rslint_parser/test_data/inline/ok/getter_class_member.rast @@ -1,7 +1,7 @@ -JS_ROOT@0..209 +JS_ROOT@0..203 LIST@0..0 - LIST@0..207 - JS_CLASS_DECLARATION@0..142 + LIST@0..202 + JS_CLASS_DECLARATION@0..138 CLASS_KW@0..5 "class" WHITESPACE@5..6 " " JS_IDENTIFIER_BINDING@6..13 @@ -9,7 +9,7 @@ JS_ROOT@0..209 WHITESPACE@13..14 " " L_CURLY@14..15 "{" WHITESPACE@15..17 "\n\t" - LIST@17..140 + LIST@17..136 JS_GETTER_CLASS_MEMBER@17..29 GET_KW@17..20 "get" WHITESPACE@20..21 " " @@ -53,129 +53,129 @@ JS_ROOT@0..209 LIST@66..66 LIST@66..66 R_CURLY@66..67 "}" - WHITESPACE@67..70 "\n\n\t" - JS_GETTER_CLASS_MEMBER@70..84 - GET_KW@70..73 "get" - WHITESPACE@73..74 " " - JS_LITERAL_MEMBER_NAME@74..79 - JS_STRING_LITERAL_TOKEN@74..79 "\"baz\"" - L_PAREN@79..80 "(" - R_PAREN@80..81 ")" - WHITESPACE@81..82 " " - JS_FUNCTION_BODY@82..84 - L_CURLY@82..83 "{" - LIST@83..83 - LIST@83..83 - R_CURLY@83..84 "}" - WHITESPACE@84..87 "\n\n\t" - JS_GETTER_CLASS_MEMBER@87..107 - GET_KW@87..90 "get" - WHITESPACE@90..91 " " - JS_COMPUTED_MEMBER_NAME@91..102 - L_BRACK@91..92 "[" - JS_BINARY_EXPRESSION@92..101 - JS_STRING_LITERAL@92..95 - JS_STRING_LITERAL_TOKEN@92..95 "\"a\"" + WHITESPACE@67..69 "\n\t" + JS_GETTER_CLASS_MEMBER@69..83 + GET_KW@69..72 "get" + WHITESPACE@72..73 " " + JS_LITERAL_MEMBER_NAME@73..78 + JS_STRING_LITERAL_TOKEN@73..78 "\"baz\"" + L_PAREN@78..79 "(" + R_PAREN@79..80 ")" + WHITESPACE@80..81 " " + JS_FUNCTION_BODY@81..83 + L_CURLY@81..82 "{" + LIST@82..82 + LIST@82..82 + R_CURLY@82..83 "}" + WHITESPACE@83..85 "\n\t" + JS_GETTER_CLASS_MEMBER@85..105 + GET_KW@85..88 "get" + WHITESPACE@88..89 " " + JS_COMPUTED_MEMBER_NAME@89..100 + L_BRACK@89..90 "[" + JS_BINARY_EXPRESSION@90..99 + JS_STRING_LITERAL@90..93 + JS_STRING_LITERAL_TOKEN@90..93 "\"a\"" + WHITESPACE@93..94 " " + PLUS@94..95 "+" WHITESPACE@95..96 " " - PLUS@96..97 "+" - WHITESPACE@97..98 " " - JS_STRING_LITERAL@98..101 - JS_STRING_LITERAL_TOKEN@98..101 "\"b\"" - R_BRACK@101..102 "]" - L_PAREN@102..103 "(" - R_PAREN@103..104 ")" - WHITESPACE@104..105 " " - JS_FUNCTION_BODY@105..107 - L_CURLY@105..106 "{" - LIST@106..106 - LIST@106..106 - R_CURLY@106..107 "}" - WHITESPACE@107..110 "\n\n\t" - JS_GETTER_CLASS_MEMBER@110..120 - GET_KW@110..113 "get" - WHITESPACE@113..114 " " - JS_LITERAL_MEMBER_NAME@114..115 - JS_NUMBER_LITERAL_TOKEN@114..115 "5" - L_PAREN@115..116 "(" - R_PAREN@116..117 ")" - WHITESPACE@117..118 " " - JS_FUNCTION_BODY@118..120 - L_CURLY@118..119 "{" - LIST@119..119 - LIST@119..119 - R_CURLY@119..120 "}" - WHITESPACE@120..123 "\n\n\t" - JS_GETTER_CLASS_MEMBER@123..140 - GET_KW@123..126 "get" - WHITESPACE@126..127 " " - JS_PRIVATE_CLASS_MEMBER_NAME@127..135 - HASH@127..128 "#" - IDENT@128..135 "private" - L_PAREN@135..136 "(" - R_PAREN@136..137 ")" - WHITESPACE@137..138 " " - JS_FUNCTION_BODY@138..140 - L_CURLY@138..139 "{" - LIST@139..139 - LIST@139..139 - R_CURLY@139..140 "}" - WHITESPACE@140..141 "\n" - R_CURLY@141..142 "}" - WHITESPACE@142..144 "\n\n" - JS_CLASS_DECLARATION@144..207 - CLASS_KW@144..149 "class" - WHITESPACE@149..150 " " - JS_IDENTIFIER_BINDING@150..160 - IDENT@150..160 "NotGetters" - WHITESPACE@160..161 " " - L_CURLY@161..162 "{" - WHITESPACE@162..164 "\n\t" - LIST@164..205 - JS_METHOD_CLASS_MEMBER@164..172 - JS_LITERAL_MEMBER_NAME@164..167 - IDENT@164..167 "get" - JS_PARAMETER_LIST@167..169 - L_PAREN@167..168 "(" - LIST@168..168 - R_PAREN@168..169 ")" - WHITESPACE@169..170 " " - JS_FUNCTION_BODY@170..172 - L_CURLY@170..171 "{" - LIST@171..171 - LIST@171..171 - R_CURLY@171..172 "}" - WHITESPACE@172..174 "\n\t" - JS_METHOD_CLASS_MEMBER@174..188 - ASYNC_KW@174..179 "async" - WHITESPACE@179..180 " " - JS_LITERAL_MEMBER_NAME@180..183 - IDENT@180..183 "get" - JS_PARAMETER_LIST@183..185 - L_PAREN@183..184 "(" - LIST@184..184 - R_PAREN@184..185 ")" - WHITESPACE@185..186 " " - JS_FUNCTION_BODY@186..188 - L_CURLY@186..187 "{" - LIST@187..187 - LIST@187..187 - R_CURLY@187..188 "}" - WHITESPACE@188..190 "\n\t" - JS_METHOD_CLASS_MEMBER@190..205 - STATIC_KW@190..196 "static" - WHITESPACE@196..197 " " - JS_LITERAL_MEMBER_NAME@197..200 - IDENT@197..200 "get" - JS_PARAMETER_LIST@200..202 - L_PAREN@200..201 "(" - LIST@201..201 - R_PAREN@201..202 ")" - WHITESPACE@202..203 " " - JS_FUNCTION_BODY@203..205 - L_CURLY@203..204 "{" - LIST@204..204 - LIST@204..204 - R_CURLY@204..205 "}" - WHITESPACE@205..206 "\n" - R_CURLY@206..207 "}" - WHITESPACE@207..209 "\n\n" + JS_STRING_LITERAL@96..99 + JS_STRING_LITERAL_TOKEN@96..99 "\"b\"" + R_BRACK@99..100 "]" + L_PAREN@100..101 "(" + R_PAREN@101..102 ")" + WHITESPACE@102..103 " " + JS_FUNCTION_BODY@103..105 + L_CURLY@103..104 "{" + LIST@104..104 + LIST@104..104 + R_CURLY@104..105 "}" + WHITESPACE@105..107 "\n\t" + JS_GETTER_CLASS_MEMBER@107..117 + GET_KW@107..110 "get" + WHITESPACE@110..111 " " + JS_LITERAL_MEMBER_NAME@111..112 + JS_NUMBER_LITERAL_TOKEN@111..112 "5" + L_PAREN@112..113 "(" + R_PAREN@113..114 ")" + WHITESPACE@114..115 " " + JS_FUNCTION_BODY@115..117 + L_CURLY@115..116 "{" + LIST@116..116 + LIST@116..116 + R_CURLY@116..117 "}" + WHITESPACE@117..119 "\n\t" + JS_GETTER_CLASS_MEMBER@119..136 + GET_KW@119..122 "get" + WHITESPACE@122..123 " " + JS_PRIVATE_CLASS_MEMBER_NAME@123..131 + HASH@123..124 "#" + IDENT@124..131 "private" + L_PAREN@131..132 "(" + R_PAREN@132..133 ")" + WHITESPACE@133..134 " " + JS_FUNCTION_BODY@134..136 + L_CURLY@134..135 "{" + LIST@135..135 + LIST@135..135 + R_CURLY@135..136 "}" + WHITESPACE@136..137 "\n" + R_CURLY@137..138 "}" + WHITESPACE@138..139 "\n" + JS_CLASS_DECLARATION@139..202 + CLASS_KW@139..144 "class" + WHITESPACE@144..145 " " + JS_IDENTIFIER_BINDING@145..155 + IDENT@145..155 "NotGetters" + WHITESPACE@155..156 " " + L_CURLY@156..157 "{" + WHITESPACE@157..159 "\n\t" + LIST@159..200 + JS_METHOD_CLASS_MEMBER@159..167 + JS_LITERAL_MEMBER_NAME@159..162 + IDENT@159..162 "get" + JS_PARAMETER_LIST@162..164 + L_PAREN@162..163 "(" + LIST@163..163 + R_PAREN@163..164 ")" + WHITESPACE@164..165 " " + JS_FUNCTION_BODY@165..167 + L_CURLY@165..166 "{" + LIST@166..166 + LIST@166..166 + R_CURLY@166..167 "}" + WHITESPACE@167..169 "\n\t" + JS_METHOD_CLASS_MEMBER@169..183 + ASYNC_KW@169..174 "async" + WHITESPACE@174..175 " " + JS_LITERAL_MEMBER_NAME@175..178 + IDENT@175..178 "get" + JS_PARAMETER_LIST@178..180 + L_PAREN@178..179 "(" + LIST@179..179 + R_PAREN@179..180 ")" + WHITESPACE@180..181 " " + JS_FUNCTION_BODY@181..183 + L_CURLY@181..182 "{" + LIST@182..182 + LIST@182..182 + R_CURLY@182..183 "}" + WHITESPACE@183..185 "\n\t" + JS_METHOD_CLASS_MEMBER@185..200 + STATIC_KW@185..191 "static" + WHITESPACE@191..192 " " + JS_LITERAL_MEMBER_NAME@192..195 + IDENT@192..195 "get" + JS_PARAMETER_LIST@195..197 + L_PAREN@195..196 "(" + LIST@196..196 + R_PAREN@196..197 ")" + WHITESPACE@197..198 " " + JS_FUNCTION_BODY@198..200 + L_CURLY@198..199 "{" + LIST@199..199 + LIST@199..199 + R_CURLY@199..200 "}" + WHITESPACE@200..201 "\n" + R_CURLY@201..202 "}" + WHITESPACE@202..203 "\n" diff --git a/crates/rslint_parser/test_data/inline/ok/object_expr_method.js b/crates/rslint_parser/test_data/inline/ok/object_expr_method.js index be9b39fd567..5f04d01db7e 100644 --- a/crates/rslint_parser/test_data/inline/ok/object_expr_method.js +++ b/crates/rslint_parser/test_data/inline/ok/object_expr_method.js @@ -1,3 +1,7 @@ let b = { foo() {}, +foo() {}, +"bar"(a, b, c) {}, +["foo" + "bar"](a) {}, +5(...rest) {} } 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 fe568747581..5500089669e 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,23 +1,23 @@ -JS_ROOT@0..23 +JS_ROOT@0..89 LIST@0..0 - LIST@0..22 - JS_VARIABLE_DECLARATION_STATEMENT@0..22 - JS_VARIABLE_DECLARATION@0..22 + LIST@0..88 + JS_VARIABLE_DECLARATION_STATEMENT@0..88 + JS_VARIABLE_DECLARATION@0..88 LET_KW@0..3 "let" WHITESPACE@3..4 " " - LIST@4..22 - JS_VARIABLE_DECLARATOR@4..22 + LIST@4..88 + JS_VARIABLE_DECLARATOR@4..88 SINGLE_PATTERN@4..5 NAME@4..5 IDENT@4..5 "b" WHITESPACE@5..6 " " - JS_EQUAL_VALUE_CLAUSE@6..22 + JS_EQUAL_VALUE_CLAUSE@6..88 EQ@6..7 "=" WHITESPACE@7..8 " " - JS_OBJECT_EXPRESSION@8..22 + JS_OBJECT_EXPRESSION@8..88 L_CURLY@8..9 "{" WHITESPACE@9..11 "\n " - LIST@11..20 + LIST@11..86 JS_METHOD_OBJECT_MEMBER@11..19 JS_LITERAL_MEMBER_NAME@11..14 IDENT@11..14 "foo" @@ -32,6 +32,95 @@ JS_ROOT@0..23 LIST@18..18 R_CURLY@18..19 "}" COMMA@19..20 "," - WHITESPACE@20..21 "\n" - R_CURLY@21..22 "}" - WHITESPACE@22..23 "\n" + WHITESPACE@20..21 "\n" + JS_METHOD_OBJECT_MEMBER@21..29 + JS_LITERAL_MEMBER_NAME@21..24 + IDENT@21..24 "foo" + JS_PARAMETER_LIST@24..26 + L_PAREN@24..25 "(" + LIST@25..25 + R_PAREN@25..26 ")" + WHITESPACE@26..27 " " + JS_FUNCTION_BODY@27..29 + L_CURLY@27..28 "{" + LIST@28..28 + LIST@28..28 + R_CURLY@28..29 "}" + COMMA@29..30 "," + WHITESPACE@30..31 "\n" + JS_METHOD_OBJECT_MEMBER@31..48 + JS_LITERAL_MEMBER_NAME@31..36 + JS_STRING_LITERAL_TOKEN@31..36 "\"bar\"" + JS_PARAMETER_LIST@36..45 + L_PAREN@36..37 "(" + LIST@37..44 + SINGLE_PATTERN@37..38 + NAME@37..38 + IDENT@37..38 "a" + COMMA@38..39 "," + WHITESPACE@39..40 " " + SINGLE_PATTERN@40..41 + NAME@40..41 + IDENT@40..41 "b" + COMMA@41..42 "," + WHITESPACE@42..43 " " + SINGLE_PATTERN@43..44 + NAME@43..44 + IDENT@43..44 "c" + R_PAREN@44..45 ")" + WHITESPACE@45..46 " " + JS_FUNCTION_BODY@46..48 + L_CURLY@46..47 "{" + LIST@47..47 + LIST@47..47 + R_CURLY@47..48 "}" + COMMA@48..49 "," + WHITESPACE@49..50 "\n" + JS_METHOD_OBJECT_MEMBER@50..71 + JS_COMPUTED_MEMBER_NAME@50..65 + L_BRACK@50..51 "[" + JS_BINARY_EXPRESSION@51..64 + JS_STRING_LITERAL@51..56 + JS_STRING_LITERAL_TOKEN@51..56 "\"foo\"" + WHITESPACE@56..57 " " + PLUS@57..58 "+" + WHITESPACE@58..59 " " + JS_STRING_LITERAL@59..64 + JS_STRING_LITERAL_TOKEN@59..64 "\"bar\"" + R_BRACK@64..65 "]" + JS_PARAMETER_LIST@65..68 + L_PAREN@65..66 "(" + LIST@66..67 + SINGLE_PATTERN@66..67 + NAME@66..67 + IDENT@66..67 "a" + R_PAREN@67..68 ")" + WHITESPACE@68..69 " " + JS_FUNCTION_BODY@69..71 + L_CURLY@69..70 "{" + LIST@70..70 + LIST@70..70 + R_CURLY@70..71 "}" + COMMA@71..72 "," + WHITESPACE@72..73 "\n" + JS_METHOD_OBJECT_MEMBER@73..86 + JS_LITERAL_MEMBER_NAME@73..74 + JS_NUMBER_LITERAL_TOKEN@73..74 "5" + JS_PARAMETER_LIST@74..83 + L_PAREN@74..75 "(" + LIST@75..82 + JS_REST_PARAMETER@75..82 + DOT2@75..78 "..." + SINGLE_PATTERN@78..82 + NAME@78..82 + IDENT@78..82 "rest" + R_PAREN@82..83 ")" + WHITESPACE@83..84 " " + JS_FUNCTION_BODY@84..86 + L_CURLY@84..85 "{" + LIST@85..85 + LIST@85..85 + R_CURLY@85..86 "}" + WHITESPACE@86..87 "\n" + R_CURLY@87..88 "}" + WHITESPACE@88..89 "\n" diff --git a/crates/rslint_parser/test_data/inline/ok/setter_class_number.js b/crates/rslint_parser/test_data/inline/ok/setter_class_number.js new file mode 100644 index 00000000000..4ee19e9f0a9 --- /dev/null +++ b/crates/rslint_parser/test_data/inline/ok/setter_class_number.js @@ -0,0 +1,14 @@ +class Setters { + set foo(a) {} + set static(a) {} + static set bar(a) {} + set "baz"(a) {} + set ["a" + "b"](a) {} + set 5(a) {} + set #private(a) {} +} +class NotSetters { + set(a) {} + async set(a) {} + static set(a) {} +} diff --git a/crates/rslint_parser/test_data/inline/ok/setter_class_number.rast b/crates/rslint_parser/test_data/inline/ok/setter_class_number.rast new file mode 100644 index 00000000000..66604b9fda4 --- /dev/null +++ b/crates/rslint_parser/test_data/inline/ok/setter_class_number.rast @@ -0,0 +1,211 @@ +JS_ROOT@0..213 + LIST@0..0 + LIST@0..212 + JS_CLASS_DECLARATION@0..145 + CLASS_KW@0..5 "class" + WHITESPACE@5..6 " " + JS_IDENTIFIER_BINDING@6..13 + IDENT@6..13 "Setters" + WHITESPACE@13..14 " " + L_CURLY@14..15 "{" + WHITESPACE@15..17 "\n\t" + LIST@17..143 + JS_SETTER_CLASS_MEMBER@17..30 + SET_KW@17..20 "set" + WHITESPACE@20..21 " " + JS_LITERAL_MEMBER_NAME@21..24 + IDENT@21..24 "foo" + L_PAREN@24..25 "(" + SINGLE_PATTERN@25..26 + NAME@25..26 + IDENT@25..26 "a" + R_PAREN@26..27 ")" + WHITESPACE@27..28 " " + JS_FUNCTION_BODY@28..30 + L_CURLY@28..29 "{" + LIST@29..29 + LIST@29..29 + R_CURLY@29..30 "}" + WHITESPACE@30..32 "\n\t" + JS_SETTER_CLASS_MEMBER@32..48 + SET_KW@32..35 "set" + WHITESPACE@35..36 " " + JS_LITERAL_MEMBER_NAME@36..42 + IDENT@36..42 "static" + L_PAREN@42..43 "(" + SINGLE_PATTERN@43..44 + NAME@43..44 + IDENT@43..44 "a" + R_PAREN@44..45 ")" + WHITESPACE@45..46 " " + JS_FUNCTION_BODY@46..48 + L_CURLY@46..47 "{" + LIST@47..47 + LIST@47..47 + R_CURLY@47..48 "}" + WHITESPACE@48..50 "\n\t" + JS_SETTER_CLASS_MEMBER@50..70 + STATIC_KW@50..56 "static" + WHITESPACE@56..57 " " + SET_KW@57..60 "set" + WHITESPACE@60..61 " " + JS_LITERAL_MEMBER_NAME@61..64 + IDENT@61..64 "bar" + L_PAREN@64..65 "(" + SINGLE_PATTERN@65..66 + NAME@65..66 + IDENT@65..66 "a" + R_PAREN@66..67 ")" + WHITESPACE@67..68 " " + JS_FUNCTION_BODY@68..70 + L_CURLY@68..69 "{" + LIST@69..69 + LIST@69..69 + R_CURLY@69..70 "}" + WHITESPACE@70..72 "\n\t" + JS_SETTER_CLASS_MEMBER@72..87 + SET_KW@72..75 "set" + WHITESPACE@75..76 " " + JS_LITERAL_MEMBER_NAME@76..81 + JS_STRING_LITERAL_TOKEN@76..81 "\"baz\"" + L_PAREN@81..82 "(" + SINGLE_PATTERN@82..83 + NAME@82..83 + IDENT@82..83 "a" + R_PAREN@83..84 ")" + WHITESPACE@84..85 " " + JS_FUNCTION_BODY@85..87 + L_CURLY@85..86 "{" + LIST@86..86 + LIST@86..86 + R_CURLY@86..87 "}" + WHITESPACE@87..89 "\n\t" + JS_SETTER_CLASS_MEMBER@89..110 + SET_KW@89..92 "set" + WHITESPACE@92..93 " " + JS_COMPUTED_MEMBER_NAME@93..104 + L_BRACK@93..94 "[" + JS_BINARY_EXPRESSION@94..103 + JS_STRING_LITERAL@94..97 + JS_STRING_LITERAL_TOKEN@94..97 "\"a\"" + WHITESPACE@97..98 " " + PLUS@98..99 "+" + WHITESPACE@99..100 " " + JS_STRING_LITERAL@100..103 + JS_STRING_LITERAL_TOKEN@100..103 "\"b\"" + R_BRACK@103..104 "]" + L_PAREN@104..105 "(" + SINGLE_PATTERN@105..106 + NAME@105..106 + IDENT@105..106 "a" + R_PAREN@106..107 ")" + WHITESPACE@107..108 " " + JS_FUNCTION_BODY@108..110 + L_CURLY@108..109 "{" + LIST@109..109 + LIST@109..109 + R_CURLY@109..110 "}" + WHITESPACE@110..112 "\n\t" + JS_SETTER_CLASS_MEMBER@112..123 + SET_KW@112..115 "set" + WHITESPACE@115..116 " " + JS_LITERAL_MEMBER_NAME@116..117 + JS_NUMBER_LITERAL_TOKEN@116..117 "5" + L_PAREN@117..118 "(" + SINGLE_PATTERN@118..119 + NAME@118..119 + IDENT@118..119 "a" + R_PAREN@119..120 ")" + WHITESPACE@120..121 " " + JS_FUNCTION_BODY@121..123 + L_CURLY@121..122 "{" + LIST@122..122 + LIST@122..122 + R_CURLY@122..123 "}" + WHITESPACE@123..125 "\n\t" + JS_SETTER_CLASS_MEMBER@125..143 + SET_KW@125..128 "set" + WHITESPACE@128..129 " " + JS_PRIVATE_CLASS_MEMBER_NAME@129..137 + HASH@129..130 "#" + IDENT@130..137 "private" + L_PAREN@137..138 "(" + SINGLE_PATTERN@138..139 + NAME@138..139 + IDENT@138..139 "a" + R_PAREN@139..140 ")" + WHITESPACE@140..141 " " + JS_FUNCTION_BODY@141..143 + L_CURLY@141..142 "{" + LIST@142..142 + LIST@142..142 + R_CURLY@142..143 "}" + WHITESPACE@143..144 "\n" + R_CURLY@144..145 "}" + WHITESPACE@145..146 "\n" + JS_CLASS_DECLARATION@146..212 + CLASS_KW@146..151 "class" + WHITESPACE@151..152 " " + JS_IDENTIFIER_BINDING@152..162 + IDENT@152..162 "NotSetters" + WHITESPACE@162..163 " " + L_CURLY@163..164 "{" + WHITESPACE@164..166 "\n\t" + LIST@166..210 + JS_METHOD_CLASS_MEMBER@166..175 + JS_LITERAL_MEMBER_NAME@166..169 + IDENT@166..169 "set" + JS_PARAMETER_LIST@169..172 + L_PAREN@169..170 "(" + LIST@170..171 + SINGLE_PATTERN@170..171 + NAME@170..171 + IDENT@170..171 "a" + R_PAREN@171..172 ")" + WHITESPACE@172..173 " " + JS_FUNCTION_BODY@173..175 + L_CURLY@173..174 "{" + LIST@174..174 + LIST@174..174 + R_CURLY@174..175 "}" + WHITESPACE@175..177 "\n\t" + JS_METHOD_CLASS_MEMBER@177..192 + ASYNC_KW@177..182 "async" + WHITESPACE@182..183 " " + JS_LITERAL_MEMBER_NAME@183..186 + IDENT@183..186 "set" + JS_PARAMETER_LIST@186..189 + L_PAREN@186..187 "(" + LIST@187..188 + SINGLE_PATTERN@187..188 + NAME@187..188 + IDENT@187..188 "a" + R_PAREN@188..189 ")" + WHITESPACE@189..190 " " + JS_FUNCTION_BODY@190..192 + L_CURLY@190..191 "{" + LIST@191..191 + LIST@191..191 + R_CURLY@191..192 "}" + WHITESPACE@192..194 "\n\t" + JS_METHOD_CLASS_MEMBER@194..210 + STATIC_KW@194..200 "static" + WHITESPACE@200..201 " " + JS_LITERAL_MEMBER_NAME@201..204 + IDENT@201..204 "set" + JS_PARAMETER_LIST@204..207 + L_PAREN@204..205 "(" + LIST@205..206 + SINGLE_PATTERN@205..206 + NAME@205..206 + IDENT@205..206 "a" + R_PAREN@206..207 ")" + WHITESPACE@207..208 " " + JS_FUNCTION_BODY@208..210 + L_CURLY@208..209 "{" + LIST@209..209 + LIST@209..209 + R_CURLY@209..210 "}" + WHITESPACE@210..211 "\n" + R_CURLY@211..212 "}" + WHITESPACE@212..213 "\n" diff --git a/crates/rslint_parser/test_data/inline/ok/try_stmt.js b/crates/rslint_parser/test_data/inline/ok/try_stmt.js index 352228f2c7b..d7467eb2619 100644 --- a/crates/rslint_parser/test_data/inline/ok/try_stmt.js +++ b/crates/rslint_parser/test_data/inline/ok/try_stmt.js @@ -1,2 +1,5 @@ +try {} catch {} try {} catch (e) {} try {} catch {} finally {} +try {} catch (e) {} finally {} +try {} finally {} diff --git a/crates/rslint_parser/test_data/inline/ok/try_stmt.rast b/crates/rslint_parser/test_data/inline/ok/try_stmt.rast index 4593ff996db..b7351a05d76 100644 --- a/crates/rslint_parser/test_data/inline/ok/try_stmt.rast +++ b/crates/rslint_parser/test_data/inline/ok/try_stmt.rast @@ -1,7 +1,7 @@ -JS_ROOT@0..47 +JS_ROOT@0..112 LIST@0..0 - LIST@0..46 - JS_TRY_STATEMENT@0..19 + LIST@0..111 + JS_TRY_STATEMENT@0..15 TRY_KW@0..3 "try" WHITESPACE@3..4 " " JS_BLOCK_STATEMENT@4..6 @@ -9,42 +9,105 @@ JS_ROOT@0..47 LIST@5..5 R_CURLY@5..6 "}" WHITESPACE@6..7 " " - JS_CATCH_CLAUSE@7..19 + JS_CATCH_CLAUSE@7..15 CATCH_KW@7..12 "catch" WHITESPACE@12..13 " " - JS_CATCH_DECLARATION@13..16 - L_PAREN@13..14 "(" - SINGLE_PATTERN@14..15 - NAME@14..15 - IDENT@14..15 "e" - 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 "\n" - JS_TRY_FINALLY_STATEMENT@20..46 - TRY_KW@20..23 "try" - WHITESPACE@23..24 " " - JS_BLOCK_STATEMENT@24..26 - L_CURLY@24..25 "{" - LIST@25..25 - R_CURLY@25..26 "}" - WHITESPACE@26..27 " " - JS_CATCH_CLAUSE@27..35 - CATCH_KW@27..32 "catch" + JS_BLOCK_STATEMENT@13..15 + L_CURLY@13..14 "{" + LIST@14..14 + R_CURLY@14..15 "}" + WHITESPACE@15..16 "\n" + JS_TRY_STATEMENT@16..35 + TRY_KW@16..19 "try" + WHITESPACE@19..20 " " + JS_BLOCK_STATEMENT@20..22 + L_CURLY@20..21 "{" + LIST@21..21 + R_CURLY@21..22 "}" + WHITESPACE@22..23 " " + JS_CATCH_CLAUSE@23..35 + CATCH_KW@23..28 "catch" + WHITESPACE@28..29 " " + JS_CATCH_DECLARATION@29..32 + L_PAREN@29..30 "(" + SINGLE_PATTERN@30..31 + NAME@30..31 + IDENT@30..31 "e" + R_PAREN@31..32 ")" WHITESPACE@32..33 " " JS_BLOCK_STATEMENT@33..35 L_CURLY@33..34 "{" LIST@34..34 R_CURLY@34..35 "}" - WHITESPACE@35..36 " " - JS_FINALLY_CLAUSE@36..46 - FINALLY_KW@36..43 "finally" - WHITESPACE@43..44 " " - JS_BLOCK_STATEMENT@44..46 - L_CURLY@44..45 "{" - LIST@45..45 - R_CURLY@45..46 "}" - WHITESPACE@46..47 "\n" + WHITESPACE@35..36 "\n" + JS_TRY_FINALLY_STATEMENT@36..62 + TRY_KW@36..39 "try" + WHITESPACE@39..40 " " + JS_BLOCK_STATEMENT@40..42 + L_CURLY@40..41 "{" + LIST@41..41 + R_CURLY@41..42 "}" + WHITESPACE@42..43 " " + JS_CATCH_CLAUSE@43..51 + CATCH_KW@43..48 "catch" + WHITESPACE@48..49 " " + JS_BLOCK_STATEMENT@49..51 + L_CURLY@49..50 "{" + LIST@50..50 + R_CURLY@50..51 "}" + WHITESPACE@51..52 " " + JS_FINALLY_CLAUSE@52..62 + FINALLY_KW@52..59 "finally" + WHITESPACE@59..60 " " + JS_BLOCK_STATEMENT@60..62 + L_CURLY@60..61 "{" + LIST@61..61 + R_CURLY@61..62 "}" + WHITESPACE@62..63 "\n" + JS_TRY_FINALLY_STATEMENT@63..93 + TRY_KW@63..66 "try" + WHITESPACE@66..67 " " + JS_BLOCK_STATEMENT@67..69 + L_CURLY@67..68 "{" + LIST@68..68 + R_CURLY@68..69 "}" + WHITESPACE@69..70 " " + JS_CATCH_CLAUSE@70..82 + CATCH_KW@70..75 "catch" + WHITESPACE@75..76 " " + JS_CATCH_DECLARATION@76..79 + L_PAREN@76..77 "(" + SINGLE_PATTERN@77..78 + NAME@77..78 + IDENT@77..78 "e" + R_PAREN@78..79 ")" + WHITESPACE@79..80 " " + JS_BLOCK_STATEMENT@80..82 + L_CURLY@80..81 "{" + LIST@81..81 + R_CURLY@81..82 "}" + WHITESPACE@82..83 " " + JS_FINALLY_CLAUSE@83..93 + FINALLY_KW@83..90 "finally" + WHITESPACE@90..91 " " + JS_BLOCK_STATEMENT@91..93 + L_CURLY@91..92 "{" + LIST@92..92 + R_CURLY@92..93 "}" + WHITESPACE@93..94 "\n" + JS_TRY_FINALLY_STATEMENT@94..111 + TRY_KW@94..97 "try" + WHITESPACE@97..98 " " + JS_BLOCK_STATEMENT@98..100 + L_CURLY@98..99 "{" + LIST@99..99 + R_CURLY@99..100 "}" + WHITESPACE@100..101 " " + JS_FINALLY_CLAUSE@101..111 + FINALLY_KW@101..108 "finally" + WHITESPACE@108..109 " " + JS_BLOCK_STATEMENT@109..111 + L_CURLY@109..110 "{" + LIST@110..110 + R_CURLY@110..111 "}" + WHITESPACE@111..112 "\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 d91b48b65cf..c05d234f86e 100644 --- a/crates/rslint_parser/test_data/inline/ok/var_decl.rast +++ b/crates/rslint_parser/test_data/inline/ok/var_decl.rast @@ -1,6 +1,6 @@ -JS_ROOT@0..92 +JS_ROOT@0..155 LIST@0..0 - LIST@0..91 + LIST@0..154 JS_VARIABLE_DECLARATION_STATEMENT@0..10 JS_VARIABLE_DECLARATION@0..9 VAR_KW@0..3 "var" @@ -118,4 +118,57 @@ JS_ROOT@0..92 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 " " + JS_STRING_LITERAL@102..109 + JS_STRING_LITERAL_TOKEN@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 " " + JS_STRING_LITERAL@117..124 + JS_STRING_LITERAL_TOKEN@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 " " + JS_STRING_LITERAL@134..141 + JS_STRING_LITERAL_TOKEN@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 " " + JS_NUMBER_LITERAL@152..153 + JS_NUMBER_LITERAL_TOKEN@152..153 "6" + SEMICOLON@153..154 ";" + WHITESPACE@154..155 "\n" diff --git a/crates/rslint_parser/test_data/inline/ok/yield_expr.js b/crates/rslint_parser/test_data/inline/ok/yield_expr.js index bde6bc509a8..f2874a011b9 100644 --- a/crates/rslint_parser/test_data/inline/ok/yield_expr.js +++ b/crates/rslint_parser/test_data/inline/ok/yield_expr.js @@ -1,4 +1,5 @@ function *foo() { yield foo; yield* foo; + yield; } diff --git a/crates/rslint_parser/test_data/inline/ok/yield_expr.rast b/crates/rslint_parser/test_data/inline/ok/yield_expr.rast index 65c196dde2c..761d8627fe2 100644 --- a/crates/rslint_parser/test_data/inline/ok/yield_expr.rast +++ b/crates/rslint_parser/test_data/inline/ok/yield_expr.rast @@ -1,7 +1,7 @@ -JS_ROOT@0..45 +JS_ROOT@0..53 LIST@0..0 - LIST@0..44 - JS_FUNCTION_DECLARATION@0..44 + LIST@0..52 + JS_FUNCTION_DECLARATION@0..52 FUNCTION_KW@0..8 "function" WHITESPACE@8..9 " " STAR@9..10 "*" @@ -12,11 +12,11 @@ JS_ROOT@0..45 LIST@14..14 R_PAREN@14..15 ")" WHITESPACE@15..16 " " - JS_FUNCTION_BODY@16..44 + JS_FUNCTION_BODY@16..52 L_CURLY@16..17 "{" WHITESPACE@17..19 "\n " LIST@19..19 - LIST@19..42 + LIST@19..50 JS_EXPRESSION_STATEMENT@19..29 JS_YIELD_EXPRESSION@19..28 YIELD_KW@19..24 "yield" @@ -33,6 +33,11 @@ JS_ROOT@0..45 JS_REFERENCE_IDENTIFIER_EXPRESSION@38..41 IDENT@38..41 "foo" SEMICOLON@41..42 ";" - WHITESPACE@42..43 "\n" - R_CURLY@43..44 "}" - WHITESPACE@44..45 "\n" + WHITESPACE@42..44 "\n " + JS_EXPRESSION_STATEMENT@44..50 + JS_YIELD_EXPRESSION@44..49 + YIELD_KW@44..49 "yield" + SEMICOLON@49..50 ";" + WHITESPACE@50..51 "\n" + R_CURLY@51..52 "}" + WHITESPACE@52..53 "\n" From 053b5fc095397a41217057d4127de978ed57809a Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Tue, 23 Nov 2021 12:16:36 +0000 Subject: [PATCH 13/13] chore: code review --- crates/rslint_parser/src/syntax/object.rs | 13 +- crates/rslint_parser/src/syntax/pat.rs | 5 +- .../inline/err/function_decl_err.rast | 6 +- ...getter_getter.js => object_expr_getter.js} | 0 ...er_getter.rast => object_expr_getter.rast} | 0 .../test_data/inline/ok/object_expr_method.js | 1 - .../inline/ok/object_expr_method.rast | 189 ++++++++---------- ...getter_setter.js => object_expr_setter.js} | 0 ...er_setter.rast => object_expr_setter.rast} | 0 9 files changed, 98 insertions(+), 116 deletions(-) rename crates/rslint_parser/test_data/inline/ok/{object_expr_getter_getter.js => object_expr_getter.js} (100%) rename crates/rslint_parser/test_data/inline/ok/{object_expr_getter_getter.rast => object_expr_getter.rast} (100%) rename crates/rslint_parser/test_data/inline/ok/{object_expr_getter_setter.js => object_expr_setter.js} (100%) rename crates/rslint_parser/test_data/inline/ok/{object_expr_getter_setter.rast => object_expr_setter.rast} (100%) diff --git a/crates/rslint_parser/src/syntax/object.rs b/crates/rslint_parser/src/syntax/object.rs index 0dd5d2037d3..ecace5529fc 100644 --- a/crates/rslint_parser/src/syntax/object.rs +++ b/crates/rslint_parser/src/syntax/object.rs @@ -48,7 +48,7 @@ pub(super) fn object_expr(p: &mut Parser) -> CompletedMarker { /// An individual object property such as `"a": b` or `5: 6 + 6`. fn object_member(p: &mut Parser) -> Option { match p.cur() { - // test object_expr_getter_getter + // test object_expr_getter // let a = { // get foo() { // return foo; @@ -62,7 +62,7 @@ fn object_member(p: &mut Parser) -> Option { Some(getter_object_member(p)) } - // test object_expr_getter_setter + // test object_expr_setter // let b = { // set [foo](bar) { // return 5; @@ -105,11 +105,10 @@ fn object_member(p: &mut Parser) -> Option { // test object_expr_method // let b = { - // foo() {}, - // foo() {}, - // "bar"(a, b, c) {}, - // ["foo" + "bar"](a) {}, - // 5(...rest) {} + // foo() {}, + // "bar"(a, b, c) {}, + // ["foo" + "bar"](a) {}, + // 5(...rest) {} // } if p.at(T!['(']) || p.at(T![<]) { method_object_member_body(p).ok()?; diff --git a/crates/rslint_parser/src/syntax/pat.rs b/crates/rslint_parser/src/syntax/pat.rs index 1097e8b7f97..13e615197e4 100644 --- a/crates/rslint_parser/src/syntax/pat.rs +++ b/crates/rslint_parser/src/syntax/pat.rs @@ -70,16 +70,14 @@ pub fn pattern(p: &mut Parser, parameters: bool, assignment: bool) -> Option { - let mut unknown_node_kind = JS_UNKNOWN_BINDING; let err = p .err_builder("Expected an identifier or pattern, but found none") .primary(p.cur_tok().range, ""); let mut ts = token_set![T![ident], T![yield], T![await], T!['['],]; if p.state.allow_object_expr { - unknown_node_kind = JS_UNKNOWN_PATTERN; ts = ts.union(token_set![T!['{']]); } - ParseRecoverer::with_error(ts, unknown_node_kind, err).recover(p); + ParseRecoverer::with_error(ts, JS_UNKNOWN_PATTERN, err).recover(p); return None; } }) @@ -181,7 +179,6 @@ pub fn array_binding_pattern( m.complete(p, REST_PATTERN); break; } else if binding_element(p, parameters, assignment).is_none() { - // TODO: find a away to land ParseRecoverer::new( token_set![T![await], T![ident], T![yield], T![:], T![=], T![']']], JS_UNKNOWN_PATTERN, diff --git a/crates/rslint_parser/test_data/inline/err/function_decl_err.rast b/crates/rslint_parser/test_data/inline/err/function_decl_err.rast index 445914a4675..6691425e1a1 100644 --- a/crates/rslint_parser/test_data/inline/err/function_decl_err.rast +++ b/crates/rslint_parser/test_data/inline/err/function_decl_err.rast @@ -18,15 +18,15 @@ 1: JS_PARAMETER_LIST@23..39 0: (empty) 1: LIST@23..37 - 0: JS_UNKNOWN_BINDING@23..24 + 0: JS_UNKNOWN_PATTERN@23..24 0: L_CURLY@23..24 "{" [] [] 1: (empty) - 2: JS_UNKNOWN_BINDING@24..25 + 2: JS_UNKNOWN_PATTERN@24..25 0: R_CURLY@24..25 "}" [] [] 3: ERROR@25..35 0: FUNCTION_KW@25..35 "function" [Whitespace("\n")] [Whitespace(" ")] 4: (empty) - 5: JS_UNKNOWN_BINDING@35..36 + 5: JS_UNKNOWN_PATTERN@35..36 0: STAR@35..36 "*" [] [] 6: ERROR@36..37 0: L_PAREN@36..37 "(" [] [] diff --git a/crates/rslint_parser/test_data/inline/ok/object_expr_getter_getter.js b/crates/rslint_parser/test_data/inline/ok/object_expr_getter.js similarity index 100% rename from crates/rslint_parser/test_data/inline/ok/object_expr_getter_getter.js rename to crates/rslint_parser/test_data/inline/ok/object_expr_getter.js diff --git a/crates/rslint_parser/test_data/inline/ok/object_expr_getter_getter.rast b/crates/rslint_parser/test_data/inline/ok/object_expr_getter.rast similarity index 100% rename from crates/rslint_parser/test_data/inline/ok/object_expr_getter_getter.rast rename to crates/rslint_parser/test_data/inline/ok/object_expr_getter.rast diff --git a/crates/rslint_parser/test_data/inline/ok/object_expr_method.js b/crates/rslint_parser/test_data/inline/ok/object_expr_method.js index 5f04d01db7e..791956320aa 100644 --- a/crates/rslint_parser/test_data/inline/ok/object_expr_method.js +++ b/crates/rslint_parser/test_data/inline/ok/object_expr_method.js @@ -1,5 +1,4 @@ let b = { - foo() {}, foo() {}, "bar"(a, b, c) {}, ["foo" + "bar"](a) {}, 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 5df7f8d3eff..e4329240dab 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,110 +1,97 @@ -0: JS_ROOT@0..89 +0: JS_ROOT@0..78 0: (empty) 1: LIST@0..0 - 2: LIST@0..88 - 0: JS_VARIABLE_DECLARATION_STATEMENT@0..88 - 0: JS_VARIABLE_DECLARATION@0..88 + 2: LIST@0..77 + 0: JS_VARIABLE_DECLARATION_STATEMENT@0..77 + 0: JS_VARIABLE_DECLARATION@0..77 0: LET_KW@0..4 "let" [] [Whitespace(" ")] - 1: LIST@4..88 - 0: JS_VARIABLE_DECLARATOR@4..88 + 1: LIST@4..77 + 0: JS_VARIABLE_DECLARATOR@4..77 0: SINGLE_PATTERN@4..6 0: NAME@4..6 0: IDENT@4..6 "b" [] [Whitespace(" ")] - 1: JS_EQUAL_VALUE_CLAUSE@6..88 + 1: JS_EQUAL_VALUE_CLAUSE@6..77 0: EQ@6..8 "=" [] [Whitespace(" ")] - 1: JS_OBJECT_EXPRESSION@8..88 + 1: JS_OBJECT_EXPRESSION@8..77 0: L_CURLY@8..9 "{" [] [] - 1: LIST@9..86 - 0: JS_METHOD_OBJECT_MEMBER@9..19 - 0: JS_LITERAL_MEMBER_NAME@9..14 - 0: IDENT@9..14 "foo" [Whitespace("\n ")] [] - 1: JS_PARAMETER_LIST@14..17 - 0: L_PAREN@14..15 "(" [] [] - 1: LIST@15..15 - 2: R_PAREN@15..17 ")" [] [Whitespace(" ")] - 2: JS_FUNCTION_BODY@17..19 - 0: L_CURLY@17..18 "{" [] [] - 1: LIST@18..18 - 2: LIST@18..18 - 3: R_CURLY@18..19 "}" [] [] - 1: COMMA@19..20 "," [] [] - 2: JS_METHOD_OBJECT_MEMBER@20..29 - 0: JS_LITERAL_MEMBER_NAME@20..24 - 0: IDENT@20..24 "foo" [Whitespace("\n")] [] - 1: JS_PARAMETER_LIST@24..27 - 0: L_PAREN@24..25 "(" [] [] - 1: LIST@25..25 - 2: R_PAREN@25..27 ")" [] [Whitespace(" ")] - 2: JS_FUNCTION_BODY@27..29 - 0: L_CURLY@27..28 "{" [] [] - 1: LIST@28..28 - 2: LIST@28..28 - 3: R_CURLY@28..29 "}" [] [] - 3: COMMA@29..30 "," [] [] - 4: JS_METHOD_OBJECT_MEMBER@30..48 - 0: JS_LITERAL_MEMBER_NAME@30..36 - 0: JS_STRING_LITERAL_TOKEN@30..36 "\"bar\"" [Whitespace("\n")] [] - 1: JS_PARAMETER_LIST@36..46 - 0: L_PAREN@36..37 "(" [] [] - 1: LIST@37..44 - 0: SINGLE_PATTERN@37..38 - 0: NAME@37..38 - 0: IDENT@37..38 "a" [] [] - 1: COMMA@38..40 "," [] [Whitespace(" ")] - 2: SINGLE_PATTERN@40..41 - 0: NAME@40..41 - 0: IDENT@40..41 "b" [] [] - 3: COMMA@41..43 "," [] [Whitespace(" ")] - 4: SINGLE_PATTERN@43..44 - 0: NAME@43..44 - 0: IDENT@43..44 "c" [] [] - 2: R_PAREN@44..46 ")" [] [Whitespace(" ")] - 2: JS_FUNCTION_BODY@46..48 - 0: L_CURLY@46..47 "{" [] [] - 1: LIST@47..47 - 2: LIST@47..47 - 3: R_CURLY@47..48 "}" [] [] - 5: COMMA@48..49 "," [] [] - 6: JS_METHOD_OBJECT_MEMBER@49..71 - 0: JS_COMPUTED_MEMBER_NAME@49..65 - 0: L_BRACK@49..51 "[" [Whitespace("\n")] [] - 1: JS_BINARY_EXPRESSION@51..64 - 0: JS_STRING_LITERAL@51..57 - 0: JS_STRING_LITERAL_TOKEN@51..57 "\"foo\"" [] [Whitespace(" ")] - 1: PLUS@57..59 "+" [] [Whitespace(" ")] - 2: JS_STRING_LITERAL@59..64 - 0: JS_STRING_LITERAL_TOKEN@59..64 "\"bar\"" [] [] - 2: R_BRACK@64..65 "]" [] [] - 1: JS_PARAMETER_LIST@65..69 - 0: L_PAREN@65..66 "(" [] [] - 1: LIST@66..67 - 0: SINGLE_PATTERN@66..67 - 0: NAME@66..67 - 0: IDENT@66..67 "a" [] [] - 2: R_PAREN@67..69 ")" [] [Whitespace(" ")] - 2: JS_FUNCTION_BODY@69..71 - 0: L_CURLY@69..70 "{" [] [] - 1: LIST@70..70 - 2: LIST@70..70 - 3: R_CURLY@70..71 "}" [] [] - 7: COMMA@71..72 "," [] [] - 8: JS_METHOD_OBJECT_MEMBER@72..86 - 0: JS_LITERAL_MEMBER_NAME@72..74 - 0: JS_NUMBER_LITERAL_TOKEN@72..74 "5" [Whitespace("\n")] [] - 1: JS_PARAMETER_LIST@74..84 - 0: L_PAREN@74..75 "(" [] [] - 1: LIST@75..82 - 0: JS_REST_PARAMETER@75..82 - 0: DOT2@75..78 "..." [] [] - 1: SINGLE_PATTERN@78..82 - 0: NAME@78..82 - 0: IDENT@78..82 "rest" [] [] - 2: R_PAREN@82..84 ")" [] [Whitespace(" ")] - 2: JS_FUNCTION_BODY@84..86 - 0: L_CURLY@84..85 "{" [] [] - 1: LIST@85..85 - 2: LIST@85..85 - 3: R_CURLY@85..86 "}" [] [] - 2: R_CURLY@86..88 "}" [Whitespace("\n")] [] + 1: LIST@9..75 + 0: JS_METHOD_OBJECT_MEMBER@9..18 + 0: JS_LITERAL_MEMBER_NAME@9..13 + 0: IDENT@9..13 "foo" [Whitespace("\n")] [] + 1: JS_PARAMETER_LIST@13..16 + 0: L_PAREN@13..14 "(" [] [] + 1: LIST@14..14 + 2: R_PAREN@14..16 ")" [] [Whitespace(" ")] + 2: JS_FUNCTION_BODY@16..18 + 0: L_CURLY@16..17 "{" [] [] + 1: LIST@17..17 + 2: LIST@17..17 + 3: R_CURLY@17..18 "}" [] [] + 1: COMMA@18..19 "," [] [] + 2: JS_METHOD_OBJECT_MEMBER@19..37 + 0: JS_LITERAL_MEMBER_NAME@19..25 + 0: JS_STRING_LITERAL_TOKEN@19..25 "\"bar\"" [Whitespace("\n")] [] + 1: JS_PARAMETER_LIST@25..35 + 0: L_PAREN@25..26 "(" [] [] + 1: LIST@26..33 + 0: SINGLE_PATTERN@26..27 + 0: NAME@26..27 + 0: IDENT@26..27 "a" [] [] + 1: COMMA@27..29 "," [] [Whitespace(" ")] + 2: SINGLE_PATTERN@29..30 + 0: NAME@29..30 + 0: IDENT@29..30 "b" [] [] + 3: COMMA@30..32 "," [] [Whitespace(" ")] + 4: SINGLE_PATTERN@32..33 + 0: NAME@32..33 + 0: IDENT@32..33 "c" [] [] + 2: R_PAREN@33..35 ")" [] [Whitespace(" ")] + 2: JS_FUNCTION_BODY@35..37 + 0: L_CURLY@35..36 "{" [] [] + 1: LIST@36..36 + 2: LIST@36..36 + 3: R_CURLY@36..37 "}" [] [] + 3: COMMA@37..38 "," [] [] + 4: JS_METHOD_OBJECT_MEMBER@38..60 + 0: JS_COMPUTED_MEMBER_NAME@38..54 + 0: L_BRACK@38..40 "[" [Whitespace("\n")] [] + 1: JS_BINARY_EXPRESSION@40..53 + 0: JS_STRING_LITERAL@40..46 + 0: JS_STRING_LITERAL_TOKEN@40..46 "\"foo\"" [] [Whitespace(" ")] + 1: PLUS@46..48 "+" [] [Whitespace(" ")] + 2: JS_STRING_LITERAL@48..53 + 0: JS_STRING_LITERAL_TOKEN@48..53 "\"bar\"" [] [] + 2: R_BRACK@53..54 "]" [] [] + 1: JS_PARAMETER_LIST@54..58 + 0: L_PAREN@54..55 "(" [] [] + 1: LIST@55..56 + 0: SINGLE_PATTERN@55..56 + 0: NAME@55..56 + 0: IDENT@55..56 "a" [] [] + 2: R_PAREN@56..58 ")" [] [Whitespace(" ")] + 2: JS_FUNCTION_BODY@58..60 + 0: L_CURLY@58..59 "{" [] [] + 1: LIST@59..59 + 2: LIST@59..59 + 3: R_CURLY@59..60 "}" [] [] + 5: COMMA@60..61 "," [] [] + 6: JS_METHOD_OBJECT_MEMBER@61..75 + 0: JS_LITERAL_MEMBER_NAME@61..63 + 0: JS_NUMBER_LITERAL_TOKEN@61..63 "5" [Whitespace("\n")] [] + 1: JS_PARAMETER_LIST@63..73 + 0: L_PAREN@63..64 "(" [] [] + 1: LIST@64..71 + 0: JS_REST_PARAMETER@64..71 + 0: DOT2@64..67 "..." [] [] + 1: SINGLE_PATTERN@67..71 + 0: NAME@67..71 + 0: IDENT@67..71 "rest" [] [] + 2: R_PAREN@71..73 ")" [] [Whitespace(" ")] + 2: JS_FUNCTION_BODY@73..75 + 0: L_CURLY@73..74 "{" [] [] + 1: LIST@74..74 + 2: LIST@74..74 + 3: R_CURLY@74..75 "}" [] [] + 2: R_CURLY@75..77 "}" [Whitespace("\n")] [] 1: (empty) - 3: EOF@88..89 "" [Whitespace("\n")] [] + 3: EOF@77..78 "" [Whitespace("\n")] [] diff --git a/crates/rslint_parser/test_data/inline/ok/object_expr_getter_setter.js b/crates/rslint_parser/test_data/inline/ok/object_expr_setter.js similarity index 100% rename from crates/rslint_parser/test_data/inline/ok/object_expr_getter_setter.js rename to crates/rslint_parser/test_data/inline/ok/object_expr_setter.js 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_setter.rast similarity index 100% rename from crates/rslint_parser/test_data/inline/ok/object_expr_getter_setter.rast rename to crates/rslint_parser/test_data/inline/ok/object_expr_setter.rast