Skip to content

Commit

Permalink
fix(js_parser): correctly parse type arguments in expression (#1645)
Browse files Browse the repository at this point in the history
  • Loading branch information
ah-yu authored Jan 24, 2024
1 parent c3fee4e commit 71163ef
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 7 deletions.
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

0 comments on commit 71163ef

Please sign in to comment.