Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions crates/oxc_parser/src/ts/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1318,20 +1318,18 @@ impl<'a> ParserImpl<'a> {
fn parse_js_doc_unknown_or_nullable_type(&mut self) -> Result<TSType<'a>> {
let span = self.start_span();
self.bump_any(); // bump `?`
let type_annotation = self.parse_ts_type()?;
let span = self.end_span(span);
if matches!(
self.cur_kind(),
Kind::Comma | Kind::RCurly | Kind::RParen | Kind::RAngle | Kind::Eq | Kind::Pipe
) {
Ok(self.ast.ts_type_js_doc_unknown_type(span))
} else {
Ok(self.ast.ts_type_js_doc_nullable_type(
span,
type_annotation,
/* postfix */ false,
))
return Ok(self.ast.ts_type_js_doc_unknown_type(self.end_span(span)));
}
let type_annotation = self.parse_ts_type()?;
Ok(self.ast.ts_type_js_doc_nullable_type(
self.end_span(span),
type_annotation,
/* postfix */ false,
))
}

fn parse_js_doc_non_nullable_type(&mut self) -> Result<TSType<'a>> {
Expand Down
5 changes: 2 additions & 3 deletions tasks/coverage/snapshots/estree_typescript.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
commit: 15392346

estree_typescript Summary:
AST Parsed : 10618/10725 (99.00%)
AST Parsed : 10619/10725 (99.01%)
Positive Passed: 8456/10725 (78.84%)
Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/ClassDeclarationWithInvalidConstOnPropertyDeclaration.ts
A class member cannot have the 'const' keyword.
Expand Down Expand Up @@ -495,8 +495,7 @@ Mismatch: tasks/coverage/typescript/tests/cases/compiler/exportSpecifierReferenc
Mismatch: tasks/coverage/typescript/tests/cases/compiler/exportSpecifierReferencingOuterDeclaration4.ts
Mismatch: tasks/coverage/typescript/tests/cases/compiler/exportStarFromEmptyModule.ts
Mismatch: tasks/coverage/typescript/tests/cases/compiler/exportedInterfaceInaccessibleInCallbackInModule.ts
Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/expressionWithJSDocTypeArguments.ts
Unexpected token
Mismatch: tasks/coverage/typescript/tests/cases/compiler/expressionWithJSDocTypeArguments.ts
Mismatch: tasks/coverage/typescript/tests/cases/compiler/extendBaseClassBeforeItsDeclared.ts
tasks/coverage/typescript/tests/cases/compiler/extendsUntypedModule.ts
Unexpected estree file content error: 1 != 3
Expand Down
38 changes: 29 additions & 9 deletions tasks/coverage/snapshots/parser_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ commit: 15392346
parser_typescript Summary:
AST Parsed : 6522/6531 (99.86%)
Positive Passed: 6511/6531 (99.69%)
Negative Passed: 1298/5754 (22.56%)
Negative Passed: 1297/5754 (22.54%)
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/ClassDeclaration24.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/ExportAssignment7.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/ExportAssignment8.ts
Expand Down Expand Up @@ -815,6 +815,7 @@ Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/exportSpecif
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/exportStarFromEmptyModule.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/exportedBlockScopedDeclarations.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/expr.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/expressionWithJSDocTypeArguments.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/extBaseClass2.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/extendAndImplementTheSameBaseType2.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/extendArray.ts
Expand Down Expand Up @@ -8107,14 +8108,6 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/salsa/private
╰────
help: Try insert a semicolon here

× Unexpected token
╭─[typescript/tests/cases/compiler/expressionWithJSDocTypeArguments.ts:9:21]
8 │
9 │ const WhatFoo = foo<?>;
· ─
10 │ const HuhFoo = foo<string?>;
╰────

× await expression not allowed in formal parameter
╭─[typescript/tests/cases/compiler/expressionsForbiddenInParameterInitializers.ts:1:35]
1 │ export async function foo({ foo = await import("./bar") }) {
Expand Down Expand Up @@ -10851,6 +10844,24 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/salsa/private
╰────
help: Did you mean to write 'number | null | undefined'?

× TS(17020): '?' at the start of a type is not valid TypeScript syntax.
╭─[typescript/tests/cases/compiler/parseInvalidNullableTypes.ts:8:16]
7 │
8 │ function f4(a: ?string) {}
· ───────
9 │ function f5(a: ?number) {}
╰────
help: Did you mean to write 'string | null | undefined'?

× TS(17020): '?' at the start of a type is not valid TypeScript syntax.
╭─[typescript/tests/cases/compiler/parseInvalidNullableTypes.ts:9:16]
8 │ function f4(a: ?string) {}
9 │ function f5(a: ?number) {}
· ───────
10 │
╰────
help: Did you mean to write 'number | null | undefined'?

× TS(17020): '?' at the start of a type is not valid TypeScript syntax.
╭─[typescript/tests/cases/compiler/parseInvalidNullableTypes.ts:11:25]
10 │
Expand All @@ -10869,6 +10880,15 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/salsa/private
╰────
help: Did you mean to write 'number | null | undefined'?

× TS(17020): '?' at the start of a type is not valid TypeScript syntax.
╭─[typescript/tests/cases/compiler/parseInvalidNullableTypes.ts:19:10]
18 │ const c = 1 as ?any;
19 │ const d: ?number = 1;
· ───────
20 │
╰────
help: Did you mean to write 'number | null | undefined'?

× TS(17019): '?' at the end of a type is not valid TypeScript syntax.
╭─[typescript/tests/cases/compiler/parseInvalidNullableTypes.ts:21:8]
20 │
Expand Down
Loading