Skip to content

SyntaxTree and SyntaxWalker in new compiler #254

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

Closed
ashwinr opened this issue Jul 25, 2014 · 11 comments
Closed

SyntaxTree and SyntaxWalker in new compiler #254

ashwinr opened this issue Jul 25, 2014 · 11 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@ashwinr
Copy link

ashwinr commented Jul 25, 2014

Hi: tslint uses SyntaxTree and tree walkers extensively for implementing linter rules on top of the compiler (e.g. https://github.com/palantir/tslint/blob/master/src/rules/classNameRule.ts). It looks like the visitor pattern is not present in the new compiler (at least I couldn't find it in the master branch). But languageService-v2 still has it. Can someone please explain if the syntax tree will be present in the new compiler? Because otherwise tslint needs to completely rethink its existing rule implementations for the new compiler. Thanks!

@CyrusNajmabadi
Copy link
Contributor

Hi ashwinr. We're currently coming up with a plan for how things will work in the new compiler. We don't have an ETA when this information will be ready.

@ashwinr
Copy link
Author

ashwinr commented Jul 26, 2014

Thanks @CyrusNajmabadi Can you please give us a heads-up when there is a plan on how the new compiler will be structured? As you're well aware, there's an open-source ecosystem already built up around language services, and we'd very much appreciate it if there was sufficient communication made for breaking changes 😄

@vvakame
Copy link
Contributor

vvakame commented Jul 27, 2014

We know TypeScript compiler API (aka LanguageService) is not documented.
It mean unstable API.
but community has a interested into it. 😺

@ghost
Copy link

ghost commented Jul 31, 2014

Can you confirm that generation of the syntax tree of .ts source will be exposed publicly?

@mhegazy
Copy link
Contributor

mhegazy commented Jul 31, 2014

As @CyrusNajmabadi mentioned, we are still in the planning phase. We would like to have a public interface that allows access to compiler internal structures like nodes, symbols and types. There is no ETA on when this is going to happen though.

@RReverser RReverser mentioned this issue Aug 8, 2014
@RReverser
Copy link
Contributor

Just exposing ts from built compiler as exported variable would be great.

@ashwinr
Copy link
Author

ashwinr commented Aug 9, 2014

This is not the same issue as exposing a `ts`` API from the compiler. That issue is #372. This is making sure we have access to the compiler's internal data structures so that the community can keep building (just like it has with the older compiler) better third-party support on top of the core compiler.

@lptr
Copy link
Contributor

lptr commented Jan 5, 2015

Is there any news about this? Will we be able to walk an AST with a visitor? Thanks.

@DanielRosenwasser
Copy link
Member

We no longer use the SyntaxTree type from the ≤1.0 compiler. Instead we use Node and all types derived from it (see src/compiler/types.ts). The language service augments Node.

Instead of visitors/walkers, we use forEachChild in a mutually recursive fashion.

function getAllBinaryExpressions(root: ts.Node) {
    var result: ts.BinaryExpression[] = [];
    aggregate(root);

    return result;

    function aggregate(node: ts.Node): void {
        if (node.kind === ts.SyntaxKind.BinaryExpression) {
            result.push(<BinaryExpression>node);
        }

        ts.forEachChild(node, aggregate);
    }
}

If you need tokens, use the getChildren method defined in the language service.

We are planning to expose a preview of our API as mentioned in #372.

@ctaggart
Copy link
Contributor

ctaggart commented Jan 7, 2015

How do we get a ts.Node from a String? I'm looking something similar to this in the old api.

@basarat
Copy link
Contributor

basarat commented Jan 7, 2015

Great idea guys, feels much nicer ❤️

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

9 participants