Skip to content

Commit

Permalink
JS-308 Support TSTypeAssertion nodes (#4793)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilia-kebets-sonarsource authored Aug 30, 2024
1 parent 20ae576 commit 5c2fb53
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/jsts/src/parsers/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -373,7 +376,6 @@ function getProtobufShapeForNode(node: TSESTree.Node) {
case 'TSTupleType':
case 'TSTypeAliasDeclaration':
case 'TSTypeAnnotation':
case 'TSTypeAssertion':
case 'TSTypeLiteral':
case 'TSTypeOperator':
case 'TSTypeParameter':
Expand Down
10 changes: 10 additions & 0 deletions packages/jsts/tests/parsers/ast.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>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');
});
});

/**
Expand Down

0 comments on commit 5c2fb53

Please sign in to comment.