Skip to content

Commit 891e0b4

Browse files
committed
docs(parser): add note about falling back to parse TSType in TSImportType (#16119)
1 parent 5233d73 commit 891e0b4

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

crates/oxc_parser/src/ts/types.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,9 @@ impl<'a> ParserImpl<'a> {
10281028
let source = if self.at(Kind::Str) {
10291029
self.parse_literal_string()
10301030
} else {
1031+
// `StringLiteral` is the only valid type for `TSImportType`'s `source` field. So this is an error.
1032+
// Fallback to parsing a `TSType`, to obtain a good span for the diagnostic.
1033+
// It's possible for `parse_ts_type` to produce an invalid span. Fallback to the current token span if so.
10311034
let mut span = self.parse_ts_type().span();
10321035
if span.end <= span.start {
10331036
span = self.cur_token().span();

0 commit comments

Comments
 (0)