Skip to content
Closed
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
1 change: 1 addition & 0 deletions crates/oxc_ast/src/ast/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,7 @@ pub struct TSTypePredicate<'a> {
/// declare function isString(x: any): asserts x is string; // true
/// ```
pub asserts: bool,
#[estree(via = TSTypePredicateTypeAnnotation)]
pub type_annotation: Option<Box<'a, TSTypeAnnotation<'a>>>,
}

Expand Down
5 changes: 4 additions & 1 deletion crates/oxc_ast/src/generated/derive_estree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3020,7 +3020,10 @@ impl ESTree for TSTypePredicate<'_> {
state.serialize_field("end", &self.span.end);
state.serialize_field("parameterName", &self.parameter_name);
state.serialize_field("asserts", &self.asserts);
state.serialize_field("typeAnnotation", &self.type_annotation);
state.serialize_field(
"typeAnnotation",
&crate::serialize::TSTypePredicateTypeAnnotation(self),
);
state.end();
}
}
Expand Down
32 changes: 32 additions & 0 deletions crates/oxc_ast/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1586,6 +1586,38 @@ fn serialize_formal_params_with_this_param<'a, S: Serializer>(
seq.end();
}

/// Serializer for `type_annotation` field of `TSTypePredicate`.
///
/// TODO: More description
#[ast_meta]
#[estree(
ts_type = "TSTypeAnnotation | null",
raw_deser = "
const typeAnnotation = DESER[Option<Box<TSTypeAnnotation>>](POS_OFFSET.type_annotation);
// TODO: raw_deser
typeAnnotation
"
)]
pub struct TSTypePredicateTypeAnnotation<'a, 'b>(pub &'b TSTypePredicate<'a>);

impl ESTree for TSTypePredicateTypeAnnotation<'_, '_> {
fn serialize<S: Serializer>(&self, serializer: S) {
let Some(type_predicate_type_annotation) = &self.0.type_annotation else {
Null(()).serialize(serializer);
return;
};

let inner_type_annotation = &type_predicate_type_annotation.type_annotation;
let inner_type_annotation_span = inner_type_annotation.span();
let mut state = serializer.serialize_struct();
state.serialize_field("type", &JsonSafeString("TSTypeAnnotation"));
state.serialize_field("start", &inner_type_annotation_span.start);
state.serialize_field("end", &inner_type_annotation_span.end);
state.serialize_field("typeAnnotation", &inner_type_annotation);
state.end();
}
}

// --------------------
// Comments
// --------------------
Expand Down
4 changes: 3 additions & 1 deletion napi/parser/generated/deserialize/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -1775,13 +1775,15 @@ function deserializeTSInterfaceHeritage(pos) {
}

function deserializeTSTypePredicate(pos) {
const typeAnnotation = deserializeOptionBoxTSTypeAnnotation(pos + 32);
// TODO: raw_deser
return {
type: 'TSTypePredicate',
start: deserializeU32(pos),
end: deserializeU32(pos + 4),
parameterName: deserializeTSTypePredicateName(pos + 8),
asserts: deserializeBool(pos + 24),
typeAnnotation: deserializeOptionBoxTSTypeAnnotation(pos + 32),
typeAnnotation,
};
}

Expand Down
4 changes: 3 additions & 1 deletion napi/parser/generated/deserialize/ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -1927,13 +1927,15 @@ function deserializeTSInterfaceHeritage(pos) {
}

function deserializeTSTypePredicate(pos) {
const typeAnnotation = deserializeOptionBoxTSTypeAnnotation(pos + 32);
// TODO: raw_deser
return {
type: 'TSTypePredicate',
start: deserializeU32(pos),
end: deserializeU32(pos + 4),
parameterName: deserializeTSTypePredicateName(pos + 8),
asserts: deserializeBool(pos + 24),
typeAnnotation: deserializeOptionBoxTSTypeAnnotation(pos + 32),
typeAnnotation,
};
}

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,23 +2,11 @@ commit: 15392346

estree_typescript Summary:
AST Parsed : 6480/6481 (99.98%)
Positive Passed: 6472/6481 (99.86%)
Mismatch: tasks/coverage/typescript/tests/cases/compiler/controlFlowInstanceofWithSymbolHasInstance.ts

Mismatch: tasks/coverage/typescript/tests/cases/compiler/narrowingUnionToUnion.ts

Mismatch: tasks/coverage/typescript/tests/cases/conformance/expressions/binaryOperators/instanceofOperator/instanceofOperatorWithRHSHasSymbolHasInstance.ts

Mismatch: tasks/coverage/typescript/tests/cases/conformance/expressions/typeGuards/typeGuardNarrowsPrimitiveIntersection.ts

Mismatch: tasks/coverage/typescript/tests/cases/conformance/expressions/typeGuards/typeGuardNarrowsToLiteralTypeUnion.ts

Positive Passed: 6478/6481 (99.95%)
Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/jsx/jsxReactTestSuite.tsx
JSX expressions may not use the comma operator

Mismatch: tasks/coverage/typescript/tests/cases/conformance/jsx/tsxReactEmitEntities.tsx

Mismatch: tasks/coverage/typescript/tests/cases/conformance/jsx/tsxReactEmitNesting.tsx

Mismatch: tasks/coverage/typescript/tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags02.ts

Loading