Skip to content

Commit

Permalink
fix(parser): parse intrinsic TS keyword (#8627)
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz authored Jan 21, 2025
1 parent 48717ab commit 178c232
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
8 changes: 7 additions & 1 deletion crates/oxc_parser/src/ts/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions crates/oxc_parser/src/ts/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
11 changes: 9 additions & 2 deletions tasks/coverage/snapshots/parser_babel.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}`;
Expand Down
6 changes: 0 additions & 6 deletions tasks/coverage/snapshots/semantic_babel.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 178c232

Please sign in to comment.