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

Commit

Permalink
fix(syntax): Remove quotes from tokens in JsSyntaxKind::to_string (#…
Browse files Browse the repository at this point in the history
…2665)

`JsSyntaxKind::to_string` should return the token's string representation without any additional quotes.
Quoting should happen at the call side if necessary.

This fixes some double-quoting of parentheses inside of parser diagnostic messages for different parentheses.
  • Loading branch information
MichaReiser authored Jun 7, 2022
1 parent 8c3a819 commit c173b0c
Show file tree
Hide file tree
Showing 40 changed files with 97 additions and 110 deletions.
14 changes: 7 additions & 7 deletions crates/rome_css_syntax/src/generated/kind.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
source: crates/rome_js_formatter/tests/prettier_tests.rs
assertion_line: 121
expression: arrows-bind.js

---
# Input
```js
Expand All @@ -25,7 +23,7 @@ a:

# Errors
```
error[SyntaxError]: expected `')'` but instead found `:`
error[SyntaxError]: expected `)` but instead found `:`
┌─ arrows-bind.js:1:9
1 │ a => ({}::b()``[''].c++ && 0 ? 0 : 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
source: crates/rome_js_formatter/tests/prettier_tests.rs
assertion_line: 125
expression: async-do-expressions.js

---
# Input
```js
Expand Down Expand Up @@ -88,7 +86,7 @@ error[SyntaxError]: expected `while` but instead found `;`
3};
│ ^ unexpected
error[SyntaxError]: expected `')'` but instead found `do`
error[SyntaxError]: expected `)` but instead found `do`
┌─ async-do-expressions.js:5:8
5 │ (async do {});
Expand Down Expand Up @@ -144,7 +142,7 @@ error[SyntaxError]: expected `while` but instead found `}`
21 │ };
^ unexpected
error[SyntaxError]: expected `')'` but instead found `;`
error[SyntaxError]: expected `)` but instead found `;`
┌─ async-do-expressions.js:21:2
21 │ };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rome_js_formatter/tests/prettier_tests.rs
assertion_line: 175
expression: decimal.js
---
# Input
Expand Down Expand Up @@ -127,7 +126,7 @@ error[SyntaxError]: expected a property, a shorthand property, a getter, a sette
9 │ ({ 0m: 0, .1m() {}, get 0.2m(){}, set 3m(_){}, async 4m() {}, *.5m() {} });
^^^^^^^ Expected a property, a shorthand property, a getter, a setter, or a method here
error[SyntaxError]: expected `')'` but instead found `0.2m`
error[SyntaxError]: expected `)` but instead found `0.2m`
┌─ decimal.js:9:25
9 │ ({ 0m: 0, .1m() {}, get 0.2m(){}, set 3m(_){}, async 4m() {}, *.5m() {} });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
source: crates/rome_js_formatter/tests/prettier_tests.rs
assertion_line: 144
expression: bind_parens.js

---
# Input
```js
Expand Down Expand Up @@ -125,7 +123,7 @@ error[SyntaxError]: Expected a semicolon or an implicit semicolon after a statem
│ │ An explicit or implicit semicolon is expected here...
│ ...Which is required to end this statement
error[SyntaxError]: expected `')'` but instead found `:`
error[SyntaxError]: expected `)` but instead found `:`
┌─ bind_parens.js:2:8
2 │ a || (b::c);
Expand Down Expand Up @@ -296,7 +294,7 @@ error[SyntaxError]: Expected a semicolon or an implicit semicolon after a statem
│ │ An explicit or implicit semicolon is expected here...
│ ...Which is required to end this statement
error[SyntaxError]: expected `')'` but instead found `:`
error[SyntaxError]: expected `)` but instead found `:`
┌─ bind_parens.js:29:5
29 │ (b.c::d).e;
Expand Down Expand Up @@ -344,7 +342,7 @@ error[SyntaxError]: expected `=>` but instead found `.`
30 │ (b::c::d).e;
│ ^ unexpected
error[SyntaxError]: expected `')'` but instead found `:`
error[SyntaxError]: expected `)` but instead found `:`
┌─ bind_parens.js:31:7
31 │ new (a::b)();
Expand All @@ -356,13 +354,13 @@ error[SyntaxError]: expected `,` but instead found `:`
32 │ new f(a::b);
│ ^ unexpected
error[SyntaxError]: expected `']'` but instead found `:`
error[SyntaxError]: expected `]` but instead found `:`
┌─ bind_parens.js:33:4
33 │ f[a::b];
│ ^ unexpected
error[SyntaxError]: expected `']'` but instead found `:`
error[SyntaxError]: expected `]` but instead found `:`
┌─ bind_parens.js:34:4
34 │ f[a::b()];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
source: crates/rome_js_formatter/tests/prettier_tests.rs
assertion_line: 83
expression: unary.js

---
# Input
```js
Expand Down Expand Up @@ -59,31 +57,31 @@ error[SyntaxError]: Expected a semicolon or an implicit semicolon after a statem
│ │ An explicit or implicit semicolon is expected here...
│ ...Which is required to end this statement
error[SyntaxError]: expected `')'` but instead found `:`
error[SyntaxError]: expected `)` but instead found `:`
┌─ unary.js:2:4
2 │ !(x::y /* foo */);
│ ^ unexpected
error[SyntaxError]: expected `')'` but instead found `:`
error[SyntaxError]: expected `)` but instead found `:`
┌─ unary.js:3:14
3 │ !(/* foo */ x::y);
│ ^ unexpected
error[SyntaxError]: expected `')'` but instead found `:`
error[SyntaxError]: expected `)` but instead found `:`
┌─ unary.js:6:4
6 │ x::y
│ ^ unexpected
error[SyntaxError]: expected `')'` but instead found `:`
error[SyntaxError]: expected `)` but instead found `:`
┌─ unary.js:9:4
9 │ x::y
│ ^ unexpected
error[SyntaxError]: expected `')'` but instead found `:`
error[SyntaxError]: expected `)` but instead found `:`
┌─ unary.js:13:4
13 │ x::y // foo
Expand Down
10 changes: 5 additions & 5 deletions crates/rome_js_formatter/tests/specs/prettier/js/do/do.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -201,19 +201,19 @@ error[SyntaxError]: expected `while` but instead found `;`
18};
│ ^ unexpected
error[SyntaxError]: expected `'}'` but instead found `do`
error[SyntaxError]: expected `}` but instead found `do`
┌─ do.js:25:9
25do {
│ ^^ unexpected
error[SyntaxError]: expected `'}'` but instead found `if`
error[SyntaxError]: expected `}` but instead found `if`
┌─ do.js:26:11
26if (loggedIn) {
│ ^^ unexpected
error[SyntaxError]: expected `')'` but instead found `do`
error[SyntaxError]: expected `)` but instead found `do`
┌─ do.js:37:2
37 │ (do {});
Expand All @@ -225,7 +225,7 @@ error[SyntaxError]: expected `while` but instead found `)`
37 │ (do {});
^ unexpected
error[SyntaxError]: expected `')'` but instead found `do`
error[SyntaxError]: expected `)` but instead found `do`
┌─ do.js:38:2
38 │ (do {} + 1);
Expand Down Expand Up @@ -261,7 +261,7 @@ error[SyntaxError]: expected `while` but instead found `;`
40 │ () => do {};
│ ^ unexpected
error[SyntaxError]: expected `')'` but instead found `do`
error[SyntaxError]: expected `)` but instead found `do`
┌─ do.js:42:2
42 │ (do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ const a3 = {

# Errors
```
error[SyntaxError]: expected `')'` but instead found `:`
error[SyntaxError]: expected `)` but instead found `:`
┌─ expression.js:5:4
5 │ ({}::b, 0);
│ ^ unexpected
error[SyntaxError]: expected `')'` but instead found `:`
error[SyntaxError]: expected `)` but instead found `:`
┌─ expression.js:6:4
6 │ ({}::b()``[''].c++ && 0 ? 0 : 0, 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
source: crates/rome_js_formatter/tests/prettier_tests.rs
assertion_line: 125
expression: fsharp_style_pipeline_operator.js

---
# Input
```js
Expand Down Expand Up @@ -228,7 +226,7 @@ error[SyntaxError]: Expected an expression for the left hand side of the `>` ope
28 │ const f = (x) => (x |> (y) => y + 1)
│ ^ This operator requires a left hand side value
error[SyntaxError]: expected `')'` but instead found `=>`
error[SyntaxError]: expected `)` but instead found `=>`
┌─ fsharp_style_pipeline_operator.js:28:28
28 │ const f = (x) => (x |> (y) => y + 1)
Expand Down Expand Up @@ -274,7 +272,7 @@ error[SyntaxError]: Expected an expression for the left hand side of the `>` ope
39 │ |> (y => (y + 1 |> (z) => z * y))
│ ^ This operator requires a left hand side value
error[SyntaxError]: expected `')'` but instead found `=>`
error[SyntaxError]: expected `)` but instead found `=>`
┌─ fsharp_style_pipeline_operator.js:39:26
39 │ |> (y => (y + 1 |> (z) => z * y))
Expand All @@ -292,7 +290,7 @@ error[SyntaxError]: Expected an expression for the left hand side of the `>` ope
44 │ return (y + 1 |> (z) => z * y);
│ ^ This operator requires a left hand side value
error[SyntaxError]: expected `')'` but instead found `=>`
error[SyntaxError]: expected `)` but instead found `=>`
┌─ fsharp_style_pipeline_operator.js:44:28
44 │ return (y + 1 |> (z) => z * y);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
source: crates/rome_js_formatter/tests/prettier_tests.rs
assertion_line: 125
expression: hack_pipeline_operator.js

---
# Input
```js
Expand Down Expand Up @@ -580,7 +578,7 @@ error[SyntaxError]: Expected an expression for the left hand side of the `>` ope
44|> (yield %)
^ This operator requires a left hand side value
error[SyntaxError]: expected `')'` but instead found `%`
error[SyntaxError]: expected `)` but instead found `%`
┌─ hack_pipeline_operator.js:44:15
44|> (yield %)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ error[SyntaxError]: An index signature must have a type annotation
1 │ type A = { [key: string] };
│ ^
error[SyntaxError]: expected `']'` but instead found `,`
error[SyntaxError]: expected `]` but instead found `,`
┌─ index-signature.ts:4:13
4 │ [a: string, b: string]: string;
Expand All @@ -84,7 +84,7 @@ error[SyntaxError]: expected a statement but instead found '}'
5 │ };
│ ^ Expected a statement here
error[SyntaxError]: expected `']'` but instead found `,`
error[SyntaxError]: expected `]` but instead found `,`
┌─ index-signature.ts:7:13
7 │ [a: string, b: string, c: string]: string;
Expand All @@ -108,7 +108,7 @@ error[SyntaxError]: expected a statement but instead found '}'
8 │ };
│ ^ Expected a statement here
error[SyntaxError]: expected `']'` but instead found `,`
error[SyntaxError]: expected `]` but instead found `,`
┌─ index-signature.ts:11:41
11 │ [loooooooooooooooooooooooooong: string, looooooooooooooooooooooooooooooooooooooong: string]: string;
Expand All @@ -132,7 +132,7 @@ error[SyntaxError]: expected a statement but instead found '}'
12 │ }
│ ^ Expected a statement here
error[SyntaxError]: expected `']'` but instead found `,`
error[SyntaxError]: expected `]` but instead found `,`
┌─ index-signature.ts:13:58
13 │ type TooLong81 = { [loooooooooooooooooooooooooong: string, loooooooooooooooooong: string]: string; }
Expand All @@ -156,7 +156,7 @@ error[SyntaxError]: expected a statement but instead found '}'
13 │ type TooLong81 = { [loooooooooooooooooooooooooong: string, loooooooooooooooooong: string]: string; }
│ ^ Expected a statement here
error[SyntaxError]: expected `']'` but instead found `,`
error[SyntaxError]: expected `]` but instead found `,`
┌─ index-signature.ts:14:58
14 │ type TooLong80 = { [loooooooooooooooooooooooooong: string, looooooooooooooooong: string]: string; }
Expand Down
2 changes: 1 addition & 1 deletion crates/rome_js_parser/src/syntax/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ fn validate_rest_pattern(
.primary(
rest.range(p),
&format!(
"Move the rest element to the end of the pattern, right before the closing {}",
"Move the rest element to the end of the pattern, right before the closing '{}'",
end_token.to_string().unwrap(),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ JsModule {
1: (empty)
3: [email protected] "" [Newline("\n")] []
--
error[SyntaxError]: expected `']'` but instead the file ends
error[SyntaxError]: expected `]` but instead the file ends
┌─ array_expr_incomplete.js:2:1
2 │
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ JsModule {
0: [email protected] ";" [] []
3: [email protected] "" [Newline("\n")] []
--
error[SyntaxError]: expected `')'` but instead found `=`
error[SyntaxError]: expected `)` but instead found `=`
┌─ assign_expr_left.js:1:3
1 │ ( = foo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ error[SyntaxError]: expected `,` but instead found `}`
│ ^ unexpected

--
error[SyntaxError]: expected `')'` but instead the file ends
error[SyntaxError]: expected `)` but instead the file ends
┌─ class_member_method_parameters.js:2:1
2 │
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ error[SyntaxError]: A `break` statement can only be used within an enclosing ite
│ ^^^^^

--
error[SyntaxError]: expected `')'` but instead found `continue`
error[SyntaxError]: expected `)` but instead found `continue`
┌─ do_while_no_continue_break.js:1:15
1 │ do { } break (continue)
Expand Down Expand Up @@ -209,7 +209,7 @@ error[SyntaxError]: A `continue` statement can only be used within an enclosing
│ ^^^^^^^^

--
error[SyntaxError]: expected `')'` but instead found `break`
error[SyntaxError]: expected `)` but instead found `break`
┌─ do_while_no_continue_break.js:2:18
2 │ do { } continue (break)
Expand Down
Loading

0 comments on commit c173b0c

Please sign in to comment.