Skip to content

Commit

Permalink
JS-305 Support TSNonNullExpression nodes (#4792)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilia-kebets-sonarsource authored Aug 30, 2024
1 parent 67657ff commit ff9dfca
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 @@ -287,6 +287,9 @@ function getProtobufShapeForNode(node: TSESTree.Node) {
case 'TSAsExpression':
// skipping node
return visitNode(node.expression);
case 'TSNonNullExpression':
// skipping node
return visitNode(node.expression);
case 'AccessorProperty':
case 'Decorator':
case 'ImportAttribute':
Expand Down Expand Up @@ -347,7 +350,6 @@ function getProtobufShapeForNode(node: TSESTree.Node) {
case 'TSNamedTupleMember':
case 'TSNamespaceExportDeclaration':
case 'TSNeverKeyword':
case 'TSNonNullExpression':
case 'TSNullKeyword':
case 'TSNumberKeyword':
case 'TSObjectKeyword':
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 @@ -104,6 +104,16 @@ describe('ast', () => {
.type,
).toEqual(NODE_TYPE_ENUM.values['LiteralType']); // Literal
});

test('should support TSNonNullExpression 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');
});
});

/**
Expand Down

0 comments on commit ff9dfca

Please sign in to comment.