Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Separate TypeScript and TSX grammars to avoid ambiguity and support type arguments in TSX #68
TSX and TypeScript are actually two slightly different languages. TypeScript includes syntax for type assertions that conflicts with JSX elements, so in TSX the type assertion syntax is not used. Previously, we handled this by just allowing the grammar to be ambiguous with respect to type assertions versus JSX expressions, but adding support for type arguments led to complications with that approach.
This PR splits the previous grammar into two separate grammars, one for Typescript and one for TSX. Now, when using this module, you need to specify the dialect when requiring as follows:
const ts = require("tree-sitter-typescript/typescript"); const tsx = require("tree-sitter-typescript/tsx");
In order to avoid ambiguity around the special
Duplication between grammars is minimized by a JS helper function at the root of the repo called
To avoid duplication of the custom scanner code, we use a simple
Our biggest concern is duplication in the tests. They are slightly different due to the differences in grammars explained above, but largely duplicated. I could see potentially cutting down the TSX tests to the bare minimum since we define both grammars via a shared function anyways. Let me know if that makes sense and I'll do it.
maxbrunsfeld left a comment •
This looks like a great improvement.
Yeah that's right; unused
Reusing the C code via an
With this setup, the
So maybe you should have a third
@maxbrunsfeld I named the common file
May 24, 2019
Hey @maxbrunsfeld! Got this green and addressed your concerns. My last concern is that I don't want to interfere with any other infrastructure that depends on this grammar. I moved the