Skip to content

Commit

Permalink
fix(js_parser): correctly parse type arguments in expression (biomejs…
Browse files Browse the repository at this point in the history
ah-yu authored and ematipico committed Jan 24, 2024
1 parent 4176bde commit 997df23
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
@@ -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:

@@ -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)
@@ -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
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
@@ -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))
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: JS_NUMBER_LITERAL@0..2 "0" [] [Whitespace(" ")],
},
operator_token: L_ANGLE@2..4 "<" [] [Whitespace(" ")],
right: JsParenthesizedExpression {
l_paren_token: L_PAREN@4..5 "(" [] [],
expression: JsBinaryExpression {
left: JsNumberLiteralExpression {
value_token: JS_NUMBER_LITERAL@5..7 "0" [] [Whitespace(" ")],
},
operator_token: GTEQ@7..10 ">=" [] [Whitespace(" ")],
right: JsNumberLiteralExpression {
value_token: JS_NUMBER_LITERAL@10..11 "1" [] [],
},
},
r_paren_token: R_PAREN@11..12 ")" [] [],
},
},
semicolon_token: SEMICOLON@12..13 ";" [] [],
},
],
eof_token: EOF@13..14 "" [Newline("\n")] [],
}

0: JS_MODULE@0..14
0: (empty)
1: (empty)
2: JS_DIRECTIVE_LIST@0..0
3: JS_MODULE_ITEM_LIST@0..13
0: JS_EXPRESSION_STATEMENT@0..13
0: JS_BINARY_EXPRESSION@0..12
0: JS_NUMBER_LITERAL_EXPRESSION@0..2
0: JS_NUMBER_LITERAL@0..2 "0" [] [Whitespace(" ")]
1: L_ANGLE@2..4 "<" [] [Whitespace(" ")]
2: JS_PARENTHESIZED_EXPRESSION@4..12
0: L_PAREN@4..5 "(" [] []
1: JS_BINARY_EXPRESSION@5..11
0: JS_NUMBER_LITERAL_EXPRESSION@5..7
0: JS_NUMBER_LITERAL@5..7 "0" [] [Whitespace(" ")]
1: GTEQ@7..10 ">=" [] [Whitespace(" ")]
2: JS_NUMBER_LITERAL_EXPRESSION@10..11
0: JS_NUMBER_LITERAL@10..11 "1" [] []
2: R_PAREN@11..12 ")" [] []
1: SEMICOLON@12..13 ";" [] []
4: EOF@13..14 "" [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
@@ -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:

@@ -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)
@@ -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

0 comments on commit 997df23

Please sign in to comment.