Please add access to Abstract Syntax Tree
See original GitHub issuePlease expose Abstract Syntax Tree from Language service for TypeScript. It will be of great help to analyze code model rather then reparsing it again (as there is no way to access internal model), I want to access imported modules.
Update
Can you add a method that goes inside worker and can access the model and return the result?
function nodeVisitor(root) {
// .. ast related code without any closure...
return // ... some result...
}
// source of nodeVisitor is passed to
// typescript worker
const result = await worker.processAst( nodeVisitor.toString() );
The underlying code simply passed this function as source code, which is executed in worker’s context and result is returned either as string or or some JSON.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:6 (4 by maintainers)
Top Results From Across the Web
ast — Abstract Syntax Trees — Python 3.11.1 documentation
The ast module helps Python applications to process trees of the Python abstract syntax grammar. The abstract syntax itself might change with each...
Read more >Introduction to Abstract Syntax Trees - Twilio
Abstract Syntax Trees or ASTs are tree representations of code. They are a fundamental part of the way a compiler works. When a...
Read more >Abstract Syntax Tree - powershell.one
The Abstract Syntax Tree (AST) groups tokens into meaningful structures and is the most sophisticated way of analyzing PowerShell code.
Read more >Modern way of accessing AST in Java - Stack Overflow
I think tree walking is the same as it is for the Eclipse AST. ... JastAdd offers access to name resolution as well...
Read more >How to Modify Nodes in an Abstract Syntax Tree | CSS-Tricks
log(contents);. This code takes advantage of Node's built-in fs module, which allows us to access and manipulate the filesystem. For more ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
A worker is async background code which you don’t really have access to in a general sense from your user-land code.
@luminaxster’s idea of being able to add your own dynamic import is probably the best option here - perhaps a new function in here: https://github.com/microsoft/monaco-typescript/blob/master/src/tsWorker.ts#L235 which calls
importScripts
with your own URL which has a default export as a function which receives a copy ofts
and and theTypeScriptWorker
this
instance.https://github.com/microsoft/monaco-typescript/pull/65 would allow you to create your own webworker which can do AST stuff I the background