-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
JSX - ts.findNextToken() does not account for "JsxText" case #7471
Comments
Seems like a bug to me. |
As a note, this is actually not part of the public API and is an internal implementation detail. For the record, we've special cased handling of JSX Text in other places in the language service, so ideally any changes here would be leveraged by the rest of the language service. |
Should we be marking these |
We are relying on these methods in |
@RyanCavanaugh it is marked |
I appreciate that it is has been marked as internal, but hopefully you guys can appreciate the challenge of transforming the tsc AST means we really need the help of these utilities functions. We have made some great progress on the project already, and it would be so awesome to be able release this parser to unlock the power of ESLint for TypeScript users. I am not sure how familiar you guys are with ESLint and its community, but for me it is one of the finest open source projects out there, and one of the most useful tools I have ever used. The configurability and plugin architecture is immense! Perhaps in the medium term, we could work with you guys to align on some "public" utility methods which the As I say, I am happy to submit the a PR for this issue. P.S. Mine is the merely the voice of the passionate TS and ESLint user, whereas ESLint is very much @nzakas project, so his opinion on any of the above trumps mine 100x :) |
@JamesHenry eslint is a terrific project, but committing to a public API should not be done flippantly. What exactly do you need |
@DanielRosenwasser the purpose of Plus, the docs seem to indicate that anything on I started from this page and, by inspecting that object, found the other methods. Undoubtedly I'm not the only one who went through this process and didn't even look at the annotated source code. I think relying on I'm happy to use something else if you want. These language utilities are fantastic and it's what makes ESLint support for TypeScript even remotely possible. What you have works great for our purposes, aside from this bug. :) |
Hmm, @mhegazy, we should discuss this. We should probably make it more explicit what is and isn't supported. I'm actually noticing portions of our API that we'd previously reviewed which are not marked as internal to begin with. @nzakas |
@DanielRosenwasser thanks, we can try using that. Just for completeness, these are the things we currently rely on:
Aside from the first, are these all "public"? |
I think the last two are fair game, but I don't believe the others actually are. One rule of thumb is that if it's in either |
Unfortunately, we can't stop using these methods because there is no easy way to emulate them. Out of curiosity, why would you consider these methods internal-only? They seem like fairly standard operations (we expose similar to ESLint rules) that many people would need if they want to work with the TypeScript AST at all. Since they are already public and we are probably not the only project using them, wouldn't a better option be to "bless" these APIs or else provide an equivalent that you can commit to maintaining? |
So this issue is quite old, but we need the Would you consider making them official, and adding them to your type definitions? |
I don't feel right representing this issue any more, it has been too long since I reported it or it was relevant for me. As Daniel mentions above, I believe the public Node#getChildren() got us what we needed in the end. You can follow the linked issues etc to see what fixes/changes were applied. |
TypeScript Version:
1.8.2
Background:
I have been working on trying to get https://github.com/eslint/typescript-eslint-parser, a TypeScript parser plugin for ESLint, off the ground, and the current job is adding JSX support.
ESLint uses espree and so the aim of the project is to convert the output of the tsc to an AST which espree expects. We already have a solid suite of JSX tests to develop against (taken from the espree project itself).
We do make use of some helper TypeScript helper methods when converting the AST, such as
ts.findNextToken()
and I believe I may have found an issue with the way it handles JsxTextGiven this JSX code:
...the TSC produces the AST we expect - with
@test content
represented as a single JsxText node:However, when iterating through the AST using
ts.findNextToken()
, rather than a single JsxText node, we get a node for@
,test
andcontent
separately.Upon quick inspection of the source I noticed that the related function,
ts.findPrecedingToken()
, was doing an early check for a JsxText node type, whereasts.findNextToken()
wasn't.(See https://github.com/Microsoft/TypeScript/blob/master/src/services/utilities.ts#L338 vs https://github.com/Microsoft/TypeScript/blob/master/src/services/utilities.ts#L364)
Sure enough when I monkey patched the relevant bit of typescript.js to exit early if n.kind was JsxText, a single JsxText token was recognised for
@test content
, and my test passed.If you agree that this is a bug, then I would be very happy submit a PR, otherwise any tips on how I might have arrived at this false positive would be very much appreciated!
The text was updated successfully, but these errors were encountered: