Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
chore: restored tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Nov 19, 2021
1 parent 8c62e9a commit 33fa14f
Show file tree
Hide file tree
Showing 22 changed files with 880 additions and 202 deletions.
35 changes: 35 additions & 0 deletions crates/rslint_parser/src/syntax/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -479,6 +481,39 @@ fn class_member(p: &mut Parser) -> Option<CompletedMarker> {
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,
Expand Down
2 changes: 2 additions & 0 deletions crates/rslint_parser/src/syntax/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions crates/rslint_parser/src/syntax/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ fn object_member(p: &mut Parser) -> Option<CompletedMarker> {
// 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()?;
Expand Down
5 changes: 5 additions & 0 deletions crates/rslint_parser/src/syntax/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions crates/rslint_parser/test_data/inline/err/class_decl_err.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ class extends bar {}
class extends {}
class
class foo { set {} }
class A extends bar extends foo {}
class A extends bar, foo {}
66 changes: 63 additions & 3 deletions crates/rslint_parser/test_data/inline/err/class_decl_err.rast
Original file line number Diff line number Diff line change
@@ -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 " "
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {}
1 change: 1 addition & 0 deletions crates/rslint_parser/test_data/inline/err/for_stmt_err.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
for ;; {}
for let i = 5; i < 10; i++ {}
for let i = 5; i < 10; ++i {}
63 changes: 60 additions & 3 deletions crates/rslint_parser/test_data/inline/err/for_stmt_err.rast
Original file line number Diff line number Diff line change
@@ -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 " "
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
(5 + 5) => {}
(a, ,b) => {}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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) => {}
Loading

0 comments on commit 33fa14f

Please sign in to comment.