RFC: Replace `language-javascript` with Tree Sitter · Issue #3669 · purescript/purescript · GitHub
Skip to content

RFC: Replace language-javascript with Tree Sitter #3669

Closed

Description

@gasi

PureScript relies on language-javascript package to parse FFI modules. This information is used to check whether FFI module contents match all foreign import declarations.

Unfortunately, moving to ES modules (#3613) requires extensive additions to language-javascript and even more to support all of the ES2015+ syntax. Instead of investing that time, we could leverage the excellent work that GitHub has done with Tree Sitter, an incremental parsing library with support for JavaScript, JSX, and even TypeScript.

Pros / Cons / Unknowns: Tree Sitter

Details: https://github.com/github/semantic/blob/master/docs/why-tree-sitter.md


Early POC: gasi#2

If there is interest to more easily enable features such as ES Modules (#3613) and allow more ES2015+ syntax in FFI files, e.g. arrow syntax, I’d be happy to take this task on.

Let me know if this change would be considered for merge 😄

Activity

  1. hdgarrood commented on Jun 4, 2019

    @hdgarrood
    Contributor

    I’m not super keen, for a few reasons:

    • language-javascript is already very close to complete support for ES module import and export. The changes needed for full support are definitely not extensive.
    • support for recent ES features might be nice but is not particularly compelling to me, as we don’t really need features other than import/export. I think it might even be a good thing that people are discouraged from modern ES features because that way we are less likely to get libraries which downstream users find they need to set up Babel or something if they want to make use of them.
    • it’s not just for checking ffi imports match up: we also need to do quite a bit of spelunking in the JS AST in purs bundle, and tree-sitter seems to provide a much lower level API to the AST than language-javascript does. We’d essentially need to rewrite the entirety of purs bundle. It’s not a huge amount of code, admittedly, but it’s not fantastically well tested, so I’d be a bit nervous.
  2. gasi commented on Jun 6, 2019

    @gasi
    Author

    That’s fair. Thanks for responding. I’ll see if I can continue adding support to language-javascript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions