From 178c2322f52f9a4fe9e33d27fb2719aa4b38d209 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Deng=20=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90?= Date: Tue, 21 Jan 2025 09:54:10 +0800 Subject: [PATCH] fix(parser): parse `intrinsic` TS keyword (#8627) --- crates/oxc_parser/src/ts/statement.rs | 8 +++++++- crates/oxc_parser/src/ts/types.rs | 4 ---- tasks/coverage/snapshots/parser_babel.snap | 11 +++++++++-- tasks/coverage/snapshots/semantic_babel.snap | 6 ------ 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/crates/oxc_parser/src/ts/statement.rs b/crates/oxc_parser/src/ts/statement.rs index 1e0d5b8e9b9e0..37af36f119a18 100644 --- a/crates/oxc_parser/src/ts/statement.rs +++ b/crates/oxc_parser/src/ts/statement.rs @@ -124,7 +124,13 @@ impl<'a> ParserImpl<'a> { let params = self.parse_ts_type_parameters()?; self.expect(Kind::Eq)?; - let annotation = self.parse_ts_type()?; + let annotation = if self.at(Kind::Intrinsic) && !self.peek_at(Kind::Dot) { + let span = self.start_span(); + self.bump_any(); + self.ast.ts_type_intrinsic_keyword(self.end_span(span)) + } else { + self.parse_ts_type()? + }; self.asi()?; let span = self.end_span(span); diff --git a/crates/oxc_parser/src/ts/types.rs b/crates/oxc_parser/src/ts/types.rs index f92f565fcc686..ec323ac8bac29 100644 --- a/crates/oxc_parser/src/ts/types.rs +++ b/crates/oxc_parser/src/ts/types.rs @@ -433,10 +433,6 @@ impl<'a> ParserImpl<'a> { self.bump_any(); self.ast.ts_type_boolean_keyword(self.end_span(span)) } - Kind::Intrinsic => { - self.bump_any(); - self.ast.ts_type_intrinsic_keyword(self.end_span(span)) - } Kind::Never => { self.bump_any(); self.ast.ts_type_never_keyword(self.end_span(span)) diff --git a/tasks/coverage/snapshots/parser_babel.snap b/tasks/coverage/snapshots/parser_babel.snap index dea097fa0d867..0849a397dd3a3 100644 --- a/tasks/coverage/snapshots/parser_babel.snap +++ b/tasks/coverage/snapshots/parser_babel.snap @@ -3,7 +3,7 @@ commit: acbc09a8 parser_babel Summary: AST Parsed : 2277/2292 (99.35%) Positive Passed: 2256/2292 (98.43%) -Negative Passed: 1541/1662 (92.72%) +Negative Passed: 1542/1662 (92.78%) Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/annex-b/enabled/3.1-sloppy-labeled-functions-if-body/input.js Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/core/categorized/invalid-fn-decl-labeled-inside-if/input.js Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/core/categorized/invalid-fn-decl-labeled-inside-loop/input.js @@ -121,7 +121,6 @@ Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/ty Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/types/import-type-declaration-error/input.ts Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/types/import-type-dynamic-errors/input.ts Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/types/import-type-dynamic-errors-babel-7/input.ts -Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/types/intrinsic-keyword-error/input.ts Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/types/tuple-labeled-invalid-optional/input.ts Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/types/tuple-optional-invalid/input.ts Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/types/tuple-required-after-labeled-optional/input.ts @@ -12756,6 +12755,14 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc · ───────── ╰──── + × Expected a semicolon or an implicit semicolon after a statement, but found none + ╭─[babel/packages/babel-parser/test/fixtures/typescript/types/intrinsic-keyword-error/input.ts:1:21] + 1 │ type Foo = intrinsic["foo"]; + · ▲ + 2 │ + ╰──── + help: Try insert a semicolon here + × Unexpected token ╭─[babel/packages/babel-parser/test/fixtures/typescript/types/literal-string-3/input.ts:1:19] 1 │ let x: `foo-${bar + baz}`; diff --git a/tasks/coverage/snapshots/semantic_babel.snap b/tasks/coverage/snapshots/semantic_babel.snap index fda5a1305ab6e..0acee792d6e0f 100644 --- a/tasks/coverage/snapshots/semantic_babel.snap +++ b/tasks/coverage/snapshots/semantic_babel.snap @@ -2531,17 +2531,11 @@ tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/types/intrin semantic error: Scope children mismatch: after transform: ScopeId(0): [ScopeId(1), ScopeId(2)] rebuilt : ScopeId(0): [] -Unresolved references mismatch: -after transform: ["intrinsic"] -rebuilt : [] tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/types/intrinsic-keyword-babel-7/input.ts semantic error: Scope children mismatch: after transform: ScopeId(0): [ScopeId(1), ScopeId(2)] rebuilt : ScopeId(0): [] -Unresolved references mismatch: -after transform: ["intrinsic"] -rebuilt : [] tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/types/literal-string-2/input.ts semantic error: Unresolved references mismatch: