Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(js_parser): correctly parse type arguments in expression #1645

Merged
merged 5 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom
describe.skip("test", () => {});
it.skip("test", () => {});
```
<<<<<<< HEAD
=======

- Add the rule [noFocusedTests](https://biomejs.dev/linter/rules/no-focused-tests), to disallow skipped tests:

Expand All @@ -52,7 +50,6 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom
it.only("test", () => {});
```

>>>>>>> fd3de977d1 (feat(linter): new rule noFocusedTests (#1641))
### Parser

## 1.5.3 (2024-01-22)
Expand Down Expand Up @@ -133,6 +130,16 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom

Contributed by @magic-akari

- Correctly parse type arguments in expression([#1184](https://github.com/biomejs/biome/issues/1184)).

The following code is now correctly parsed in typescript:

```ts
0 < (0 >= 1);
```

Contributed by @ah-yu

### Website

#### New
Expand Down
13 changes: 12 additions & 1 deletion crates/biome_js_parser/src/syntax/typescript/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2004,9 +2004,20 @@ pub(crate) fn parse_ts_type_arguments_in_expression(
return Absent;
}

// test ts ts_type_arguments_like_expression
// 0 < (0 >= 1);
try_parse(p, |p| {
p.re_lex(JsReLexContext::TypeArgumentLessThan);
let arguments = parse_ts_type_arguments_impl(p, TypeContext::default(), false);
let m = p.start();
p.bump(T![<]);

if p.at(T![>]) {
p.error(expected_ts_type_parameter(p, p.cur_range()));
}
TypeArgumentsList::new(TypeContext::default(), false).parse_list(p);
p.re_lex(JsReLexContext::BinaryOperator);
p.expect(T![>]);
let arguments = m.complete(p, TS_TYPE_ARGUMENTS);

if p.last() == Some(T![>]) && can_follow_type_arguments_in_expr(p, context) {
Ok(Present(arguments))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
JsModule {
bom_token: missing (optional),
interpreter_token: missing (optional),
directives: JsDirectiveList [],
items: JsModuleItemList [
JsExpressionStatement {
expression: JsBinaryExpression {
left: JsNumberLiteralExpression {
value_token: [email protected] "0" [] [Whitespace(" ")],
},
operator_token: [email protected] "<" [] [Whitespace(" ")],
right: JsParenthesizedExpression {
l_paren_token: [email protected] "(" [] [],
expression: JsBinaryExpression {
left: JsNumberLiteralExpression {
value_token: [email protected] "0" [] [Whitespace(" ")],
},
operator_token: [email protected] ">=" [] [Whitespace(" ")],
right: JsNumberLiteralExpression {
value_token: [email protected] "1" [] [],
},
},
r_paren_token: [email protected] ")" [] [],
},
},
semicolon_token: [email protected] ";" [] [],
},
],
eof_token: [email protected] "" [Newline("\n")] [],
}

0: [email protected]
0: (empty)
1: (empty)
2: [email protected]
3: [email protected]
0: [email protected]
0: [email protected]
0: [email protected]
0: [email protected] "0" [] [Whitespace(" ")]
1: [email protected] "<" [] [Whitespace(" ")]
2: [email protected]
0: [email protected] "(" [] []
1: [email protected]
0: [email protected]
0: [email protected] "0" [] [Whitespace(" ")]
1: [email protected] ">=" [] [Whitespace(" ")]
2: [email protected]
0: [email protected] "1" [] []
2: [email protected] ")" [] []
1: [email protected] ";" [] []
4: [email protected] "" [Newline("\n")] []
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 < (0 >= 1);
13 changes: 10 additions & 3 deletions website/src/content/docs/internals/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom
describe.skip("test", () => {});
it.skip("test", () => {});
```
<<<<<<< HEAD
=======

- Add the rule [noFocusedTests](https://biomejs.dev/linter/rules/no-focused-tests), to disallow skipped tests:

Expand All @@ -58,7 +56,6 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom
it.only("test", () => {});
```

>>>>>>> fd3de977d1 (feat(linter): new rule noFocusedTests (#1641))
### Parser

## 1.5.3 (2024-01-22)
Expand Down Expand Up @@ -139,6 +136,16 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom

Contributed by @magic-akari

- Correctly parse type arguments in expression([#1184](https://github.com/biomejs/biome/issues/1184)).

The following code is now correctly parsed in typescript:

```ts
0 < (0 >= 1);
```

Contributed by @ah-yu

### Website

#### New
Expand Down
Loading