fix(parser): parse const extends in arrow functions correctly (#3450)

close: #3443
This commit is contained in:
Dunqing 2024-05-28 21:34:52 +08:00 committed by GitHub
parent 085f91761c
commit cf41513d28
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 18 additions and 20 deletions

View file

@ -156,10 +156,13 @@ impl<'a> ParserImpl<'a> {
// JSX overrides
if self.source_type.is_jsx() {
return match self.nth_kind(offset + 2) {
// <const Ident extends Ident>
// ^^^^^ Optional
offset += if second == Kind::Const { 3 } else { 2 };
return match self.nth_kind(offset) {
Kind::Extends => {
let third = self.nth_kind(offset + 3);
if matches!(third, Kind::Eq | Kind::RAngle) {
let third = self.nth_kind(offset + 1);
if matches!(third, Kind::Eq | Kind::RAngle | Kind::Slash) {
Tristate::False
} else if third.is_binding_identifier() {
Tristate::Maybe

View file

@ -1,3 +1,3 @@
codegen_misc Summary:
AST Parsed : 17/17 (100.00%)
Positive Passed: 17/17 (100.00%)
AST Parsed : 18/18 (100.00%)
Positive Passed: 18/18 (100.00%)

View file

@ -0,0 +1,2 @@
const A = <const T extends F>() => {};
const B = <const T extends keyof F>() => {};

View file

@ -1,6 +1,6 @@
parser_misc Summary:
AST Parsed : 17/17 (100.00%)
Positive Passed: 17/17 (100.00%)
AST Parsed : 18/18 (100.00%)
Positive Passed: 18/18 (100.00%)
Negative Passed: 9/9 (100.00%)
× Unexpected token

View file

@ -3,7 +3,7 @@ commit: 64d2eeea
parser_typescript Summary:
AST Parsed : 5240/5243 (99.94%)
Positive Passed: 5233/5243 (99.81%)
Negative Passed: 1065/4879 (21.83%)
Negative Passed: 1064/4879 (21.81%)
Expect Syntax Error: "compiler/ClassDeclaration10.ts"
Expect Syntax Error: "compiler/ClassDeclaration11.ts"
Expect Syntax Error: "compiler/ClassDeclaration13.ts"
@ -1388,6 +1388,7 @@ Expect Syntax Error: "compiler/paramterDestrcuturingDeclaration.ts"
Expect Syntax Error: "compiler/parenthesizedJSDocCastDoesNotNarrow.ts"
Expect Syntax Error: "compiler/parseCommaSeparatedNewlineNumber.ts"
Expect Syntax Error: "compiler/parseCommaSeparatedNewlineString.ts"
Expect Syntax Error: "compiler/parseJsxExtends2.ts"
Expect Syntax Error: "compiler/parseTypes.ts"
Expect Syntax Error: "compiler/parseUnaryExpressionNoTypeAssertionInJsx1.ts"
Expect Syntax Error: "compiler/parseUnaryExpressionNoTypeAssertionInJsx3.ts"
@ -8517,14 +8518,6 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts"
5 │
╰────
× Unexpected token
╭─[compiler/parseJsxExtends2.ts:8:22]
7 │ // Error: T is not declared.
8 │ return <T extends/>
· ─
9 │ }
╰────
× Unexpected token
╭─[compiler/parseUnaryExpressionNoTypeAssertionInJsx2.ts:7:14]
6 │ const x = "oops";

View file

@ -1,6 +1,6 @@
prettier_misc Summary:
AST Parsed : 17/17 (100.00%)
Positive Passed: 10/17 (58.82%)
AST Parsed : 18/18 (100.00%)
Positive Passed: 11/18 (61.11%)
Expect to Parse: "pass/oxc-1740.tsx"
Expect to Parse: "pass/oxc-2087.ts"
Expect to Parse: "pass/oxc-2394.ts"

View file

@ -1,3 +1,3 @@
transformer_misc Summary:
AST Parsed : 17/17 (100.00%)
Positive Passed: 17/17 (100.00%)
AST Parsed : 18/18 (100.00%)
Positive Passed: 18/18 (100.00%)