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
20 changes: 10 additions & 10 deletions crates/oxc_parser/src/ts/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,16 +1064,11 @@ impl<'a> ParserImpl<'a> {

fn parse_type_or_type_predicate(&mut self) -> Result<TSType<'a>> {
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,
Expand All @@ -1084,12 +1079,17 @@ impl<'a> ParserImpl<'a> {
Ok(ty)
}

fn parse_type_predicate_prefix(&mut self) -> Result<IdentifierName<'a>> {
let id = self.parse_identifier_name()?;
fn parse_type_predicate_prefix(&mut self) -> Result<TSTypePredicateName<'a>> {
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())
}
Expand Down
14 changes: 1 addition & 13 deletions tasks/coverage/snapshots/estree_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1734,18 +1730,13 @@ 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
Mismatch: tasks/coverage/typescript/tests/cases/conformance/controlFlow/typeGuardsTypeParameters.ts
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading