Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS-306 Support TSParameterProperty nodes #4794

Merged
merged 2 commits into from
Aug 30, 2024
Merged
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
4 changes: 3 additions & 1 deletion packages/jsts/src/parsers/ast.ts
Original file line number Diff line number Diff line change
@@ -296,6 +296,9 @@ function getProtobufShapeForNode(node: TSESTree.Node) {
case 'TSTypeAssertion':
// skipping node
return visitNode(node.expression);
case 'TSParameterProperty':
// skipping node
return visitNode(node.parameter);
case 'AccessorProperty':
case 'Decorator':
case 'ImportAttribute':
@@ -360,7 +363,6 @@ function getProtobufShapeForNode(node: TSESTree.Node) {
case 'TSNumberKeyword':
case 'TSObjectKeyword':
case 'TSOptionalType':
case 'TSParameterProperty':
case 'TSPrivateKeyword':
case 'TSPropertySignature':
case 'TSProtectedKeyword':
16 changes: 16 additions & 0 deletions packages/jsts/tests/parsers/ast.test.ts
Original file line number Diff line number Diff line change
@@ -133,6 +133,22 @@ describe('ast', () => {
expect(identifier.type).toEqual(NODE_TYPE_ENUM.values['IdentifierType']);
expect(identifier.identifier.name).toEqual('foo');
});

test('should support TSParameterProperty nodes', async () => {
const code = `
class Point {
constructor(public foo: number) {}
}
`;
const ast = await parseSourceCode(code, parsers.typescript);
const serializedAST = visitNode(ast as TSESTree.Program);

const classDeclaration = serializedAST.program.body[0].classDeclaration;
const methodDefinition = classDeclaration.body.classBody.body[0].methodDefinition;
const functionParameter = methodDefinition.value.functionExpression.params[0];
expect(functionParameter.type).toEqual(NODE_TYPE_ENUM.values['IdentifierType']);
expect(functionParameter.identifier.name).toEqual('foo');
});
});

/**