You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How can I use esquery in conjunction with ts-morph to retrieve nodes from the Abstract Syntax Tree (AST) by query path similar to CSS? For instance, given the query path CallExpression > ObjectLiteralExpression > PropertyAssignment[name="arg1"], how can I retrieve the node of type PropertyAssignment with the name arg1?
Here's an example code I've been trying to use to accomplish this, but it doesn't seem to work:
Although I'm aware that ts-morph allows me to parse code into an AST, I'm specifically interested in using esquery to retrieve nodes by query path similar to CSS. Is there a way to combine the two approaches or is there an alternative solution that achieves a similar outcome?
The text was updated successfully, but these errors were encountered:
@jon9090 We could allow a function there, but it's kind of strange for that information to only be available via a method call. Why is ts-morph designed like that? Can you post-process the AST to eagerly pull out the node types and attach the result as a property? Do the AST nodes have a shared prototype where you could stick a getter?
I hesitate to just add support for a function, as it will slow the typical case to accommodate what I feel is a very unusual case.
How can I use esquery in conjunction with ts-morph to retrieve nodes from the Abstract Syntax Tree (AST) by query path similar to CSS? For instance, given the query path CallExpression > ObjectLiteralExpression > PropertyAssignment[name="arg1"], how can I retrieve the node of type PropertyAssignment with the name arg1?
Here's an example code I've been trying to use to accomplish this, but it doesn't seem to work:
codesandbox
Although I'm aware that ts-morph allows me to parse code into an AST, I'm specifically interested in using esquery to retrieve nodes by query path similar to CSS. Is there a way to combine the two approaches or is there an alternative solution that achieves a similar outcome?
The text was updated successfully, but these errors were encountered: