From 20ae576ae2651925e61e202f0ae59b1839554184 Mon Sep 17 00:00:00 2001 From: Ilia Kebets <104737176+ilia-kebets-sonarsource@users.noreply.github.com> Date: Fri, 30 Aug 2024 15:03:17 +0200 Subject: [PATCH] JS-307 Support TSSatisfiesExpression nodes (#4791) --- packages/jsts/src/parsers/ast.ts | 4 +++- packages/jsts/tests/parsers/ast.test.ts | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/jsts/src/parsers/ast.ts b/packages/jsts/src/parsers/ast.ts index 1a96b6b99d9..bab31862bf4 100644 --- a/packages/jsts/src/parsers/ast.ts +++ b/packages/jsts/src/parsers/ast.ts @@ -287,6 +287,9 @@ function getProtobufShapeForNode(node: TSESTree.Node) { case 'TSAsExpression': // skipping node return visitNode(node.expression); + case 'TSSatisfiesExpression': + // skipping node + return visitNode(node.expression); case 'TSNonNullExpression': // skipping node return visitNode(node.expression); @@ -362,7 +365,6 @@ function getProtobufShapeForNode(node: TSESTree.Node) { case 'TSQualifiedName': case 'TSReadonlyKeyword': case 'TSRestType': - case 'TSSatisfiesExpression': case 'TSStaticKeyword': case 'TSStringKeyword': case 'TSSymbolKeyword': diff --git a/packages/jsts/tests/parsers/ast.test.ts b/packages/jsts/tests/parsers/ast.test.ts index dc686886ced..e8ea8666cfe 100644 --- a/packages/jsts/tests/parsers/ast.test.ts +++ b/packages/jsts/tests/parsers/ast.test.ts @@ -105,6 +105,15 @@ describe('ast', () => { ).toEqual(NODE_TYPE_ENUM.values['LiteralType']); // Literal }); + test('should support TSSatisfiesExpression nodes', async () => { + const code = `42 satisfies Bar;`; + const ast = await parseSourceCode(code, parsers.typescript); + const serializedAST = visitNode(ast as TSESTree.Program); + const literalNode = serializedAST.program.body[0].expressionStatement.expression.literal; + expect(literalNode.type).toEqual(NODE_TYPE_ENUM.values['Literal']); + expect(literalNode.valueNumber).toEqual(42); + }); + test('should support TSNonNullExpression nodes', async () => { const code = `foo!;`; const ast = await parseSourceCode(code, parsers.typescript);