diff --git a/crates/oxc_parser/src/ts/types.rs b/crates/oxc_parser/src/ts/types.rs index cf81efff67429..bc82d9c207434 100644 --- a/crates/oxc_parser/src/ts/types.rs +++ b/crates/oxc_parser/src/ts/types.rs @@ -1318,20 +1318,18 @@ impl<'a> ParserImpl<'a> { fn parse_js_doc_unknown_or_nullable_type(&mut self) -> Result> { 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> { diff --git a/tasks/coverage/snapshots/estree_typescript.snap b/tasks/coverage/snapshots/estree_typescript.snap index f7b0081bca5ea..56f70e6dabe24 100644 --- a/tasks/coverage/snapshots/estree_typescript.snap +++ b/tasks/coverage/snapshots/estree_typescript.snap @@ -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. @@ -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 diff --git a/tasks/coverage/snapshots/parser_typescript.snap b/tasks/coverage/snapshots/parser_typescript.snap index 990adc7b036f2..f425968e09331 100644 --- a/tasks/coverage/snapshots/parser_typescript.snap +++ b/tasks/coverage/snapshots/parser_typescript.snap @@ -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 @@ -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 @@ -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; - ╰──── - × await expression not allowed in formal parameter ╭─[typescript/tests/cases/compiler/expressionsForbiddenInParameterInitializers.ts:1:35] 1 │ export async function foo({ foo = await import("./bar") }) { @@ -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 │ @@ -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 │