diff --git a/packages/jsts/src/parsers/ast.ts b/packages/jsts/src/parsers/ast.ts index bab31862bf4..19e9a81f235 100644 --- a/packages/jsts/src/parsers/ast.ts +++ b/packages/jsts/src/parsers/ast.ts @@ -293,6 +293,9 @@ function getProtobufShapeForNode(node: TSESTree.Node) { case 'TSNonNullExpression': // skipping node return visitNode(node.expression); + case 'TSTypeAssertion': + // skipping node + return visitNode(node.expression); case 'AccessorProperty': case 'Decorator': case 'ImportAttribute': @@ -373,7 +376,6 @@ function getProtobufShapeForNode(node: TSESTree.Node) { case 'TSTupleType': case 'TSTypeAliasDeclaration': case 'TSTypeAnnotation': - case 'TSTypeAssertion': case 'TSTypeLiteral': case 'TSTypeOperator': case 'TSTypeParameter': diff --git a/packages/jsts/tests/parsers/ast.test.ts b/packages/jsts/tests/parsers/ast.test.ts index e8ea8666cfe..faf03c9b655 100644 --- a/packages/jsts/tests/parsers/ast.test.ts +++ b/packages/jsts/tests/parsers/ast.test.ts @@ -123,6 +123,16 @@ describe('ast', () => { expect(identifier.type).toEqual(NODE_TYPE_ENUM.values['IdentifierType']); expect(identifier.identifier.name).toEqual('foo'); }); + + test('should support TSTypeAssertion nodes', async () => { + const code = `foo;`; + const ast = await parseSourceCode(code, parsers.typescript); + const serializedAST = visitNode(ast as TSESTree.Program); + + const identifier = serializedAST.program.body[0].expressionStatement.expression; + expect(identifier.type).toEqual(NODE_TYPE_ENUM.values['IdentifierType']); + expect(identifier.identifier.name).toEqual('foo'); + }); }); /**