diff --git a/crates/oxc_parser/src/ts/types.rs b/crates/oxc_parser/src/ts/types.rs index 2a27da705a058..98281b1d52a7a 100644 --- a/crates/oxc_parser/src/ts/types.rs +++ b/crates/oxc_parser/src/ts/types.rs @@ -1064,16 +1064,11 @@ impl<'a> ParserImpl<'a> { fn parse_type_or_type_predicate(&mut self) -> Result> { let span = self.start_span(); - let type_predicate_variable = if self.cur_kind().is_identifier_name() { - self.try_parse(Self::parse_type_predicate_prefix) - } else { - None - }; + let type_predicate_variable = self.try_parse(Self::parse_type_predicate_prefix); let type_span = self.start_span(); let ty = self.parse_ts_type()?; - if let Some(id) = type_predicate_variable { + if let Some(parameter_name) = type_predicate_variable { let type_annotation = Some(self.ast.ts_type_annotation(self.end_span(type_span), ty)); - let parameter_name = TSTypePredicateName::Identifier(self.alloc(id)); return Ok(self.ast.ts_type_type_predicate( self.end_span(span), parameter_name, @@ -1084,12 +1079,17 @@ impl<'a> ParserImpl<'a> { Ok(ty) } - fn parse_type_predicate_prefix(&mut self) -> Result> { - let id = self.parse_identifier_name()?; + fn parse_type_predicate_prefix(&mut self) -> Result> { + let parameter_name = if self.at(Kind::This) { + TSTypePredicateName::This(self.parse_this_type_node()) + } else { + let ident_name = self.parse_identifier_name()?; + TSTypePredicateName::Identifier(self.alloc(ident_name)) + }; let token = self.cur_token(); if token.kind == Kind::Is && !token.is_on_new_line { self.bump_any(); - return Ok(id); + return Ok(parameter_name); } Err(self.unexpected()) } diff --git a/tasks/coverage/snapshots/estree_typescript.snap b/tasks/coverage/snapshots/estree_typescript.snap index 569a274ad6466..3ee85eccb914e 100644 --- a/tasks/coverage/snapshots/estree_typescript.snap +++ b/tasks/coverage/snapshots/estree_typescript.snap @@ -2,7 +2,7 @@ commit: 15392346 estree_typescript Summary: AST Parsed : 10618/10725 (99.00%) -Positive Passed: 8047/10725 (75.03%) +Positive Passed: 8059/10725 (75.14%) Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/ClassDeclarationWithInvalidConstOnPropertyDeclaration.ts A class member cannot have the 'const' keyword. Mismatch: tasks/coverage/typescript/tests/cases/compiler/abstractPropertyInConstructor.ts @@ -703,7 +703,6 @@ Mismatch: tasks/coverage/typescript/tests/cases/compiler/homomorphicMappedTypeWi Mismatch: tasks/coverage/typescript/tests/cases/compiler/hugeDeclarationOutputGetsTruncatedWithError.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/identicalTypesNoDifferByCheckOrder.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/identityAndDivergentNormalizedTypes.ts -Mismatch: tasks/coverage/typescript/tests/cases/compiler/identityRelationNeverTypes.ts Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/illegalModifiersOnClassElements.ts Expected a semicolon or an implicit semicolon after a statement, but found none Mismatch: tasks/coverage/typescript/tests/cases/compiler/implicitIndexSignatures.ts @@ -1507,7 +1506,6 @@ Mismatch: tasks/coverage/typescript/tests/cases/compiler/thisInGenericStaticMemb Mismatch: tasks/coverage/typescript/tests/cases/compiler/thisInSuperCall.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/thisInSuperCall1.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/thisInTypeQuery.ts -Mismatch: tasks/coverage/typescript/tests/cases/compiler/thisPredicateInObjectLiteral.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/this_inside-enum-should-not-be-allowed.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/topLevel.ts tasks/coverage/typescript/tests/cases/compiler/topLevelBlockExpando.ts @@ -1541,8 +1539,6 @@ Mismatch: tasks/coverage/typescript/tests/cases/compiler/typeGuardNarrowsIndexed Mismatch: tasks/coverage/typescript/tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/typeParameterExtendsPrimitive.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/typePredicateFreshLiteralWidening.ts -Mismatch: tasks/coverage/typescript/tests/cases/compiler/typePredicateInherit.ts -Mismatch: tasks/coverage/typescript/tests/cases/compiler/typePredicatesInUnion3.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/typeVariableConstraintIntersections.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/typeVariableTypeGuards.ts Mismatch: tasks/coverage/typescript/tests/cases/compiler/typedArrays.ts @@ -1734,7 +1730,6 @@ Expected `,` but found `is` Mismatch: tasks/coverage/typescript/tests/cases/conformance/controlFlow/controlFlowAliasing.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/controlFlow/controlFlowAssignmentPatternOrder.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/controlFlow/controlFlowGenericTypes.ts -Mismatch: tasks/coverage/typescript/tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/controlFlow/dependentDestructuredVariablesFromNestedPatterns.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/controlFlow/exhaustiveSwitchStatements1.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/controlFlow/neverReturningFunctions1.ts @@ -1742,10 +1737,6 @@ Mismatch: tasks/coverage/typescript/tests/cases/conformance/controlFlow/typeGuar Mismatch: tasks/coverage/typescript/tests/cases/conformance/declarationEmit/declarationEmitWorkWithInlineComments.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/declarationEmit/libReferenceDeclarationEmit.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/declarationEmit/libReferenceDeclarationEmitBundle.ts -Mismatch: tasks/coverage/typescript/tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicates01.ts -Mismatch: tasks/coverage/typescript/tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicates02.ts -Mismatch: tasks/coverage/typescript/tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName01.ts -Mismatch: tasks/coverage/typescript/tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName02.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/declarationEmit/typeReferenceRelatedFiles.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/decorators/class/constructor/decoratorOnClassConstructor2.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/decorators/class/constructor/decoratorOnClassConstructor3.ts @@ -2429,8 +2420,6 @@ Mismatch: tasks/coverage/typescript/tests/cases/conformance/expressions/thisKeyw Mismatch: tasks/coverage/typescript/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/expressions/typeAssertions/constAssertionOnEnum.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/expressions/typeGuards/TypeGuardWithEnumUnion.ts -Mismatch: tasks/coverage/typescript/tests/cases/conformance/expressions/typeGuards/typeGuardFunctionOfFormThis.ts -Mismatch: tasks/coverage/typescript/tests/cases/conformance/expressions/typeGuards/typeGuardFunctionOfFormThisErrors.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/expressions/typeGuards/typeGuardNarrowsPrimitiveIntersection.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/expressions/typeGuards/typeGuardNarrowsToLiteralTypeUnion.ts Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/expressions/typeGuards/typeGuardOfFormThisMember.ts @@ -3399,7 +3388,6 @@ Mismatch: tasks/coverage/typescript/tests/cases/conformance/types/specifyingType Mismatch: tasks/coverage/typescript/tests/cases/conformance/types/specifyingTypes/typeQueries/typeofThis.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/types/specifyingTypes/typeQueries/typeofThisWithImplicitThis.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/types/spread/objectSpreadNoTransform.ts -Mismatch: tasks/coverage/typescript/tests/cases/conformance/types/spread/spreadObjectOrFalsy.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/types/stringLiteral/stringLiteralCheckedInIf01.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/types/stringLiteral/stringLiteralCheckedInIf02.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/types/stringLiteral/stringLiteralMatchedInSwitch01.ts