question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Please add access to Abstract Syntax Tree

See original GitHub issue

Please 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:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
ortacommented, Jun 29, 2020

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 of ts and and the TypeScriptWorker this instance.

0reactions
ortacommented, Sep 4, 2020

https://github.com/microsoft/monaco-typescript/pull/65 would allow you to create your own webworker which can do AST stuff I the background

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found