-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Reverse SyntaxKind query shows misleading result #18062
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
Labels
Design Limitation
Constraints of the existing architecture prevent this from being fixed
Comments
koczkatamas
added a commit
to koczkatamas/astexplorer
that referenced
this issue
Aug 26, 2017
Reverse SyntaxKind lookup does not give correct results (as described here: microsoft/TypeScript#18062) . This commit workarounds that issue (until it'll be resolved in TS compiler - if it will be ever...)
See #3103. |
We probably (?) should have had "first in wins" semantics for the reverse map, but it'd be a runtime breaking change (extreme risk) to change it now. |
Maybe moving |
fkling
pushed a commit
to fkling/astexplorer
that referenced
this issue
Sep 1, 2017
* Fix typescript parser's node name Reverse SyntaxKind lookup does not give correct results (as described here: microsoft/TypeScript#18062) . This commit workarounds that issue (until it'll be resolved in TS compiler - if it will be ever...) * Fix linting errors of commit 46cec82 * Improve workaround introduced in 46cec82 Replaces previous implementation with a (hopefully) more future-proof one in the case of TS compiler changes internal indices of SyntaxKind enum * Move SyntaxKind workaround from parse to loadParser
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
TypeScript Version: 2.4.2
Code
Expected behavior:
NumericLiteral
Actual behavior:
FirstLiteralToken
Description:
Maybe this is a duplicate of a more broad issue (which I did not find), and I am not sure if there is a workaround for this specific case, but currently I would presume that I can use
SyntaxKind
enum for reverse lookups of values I got from TS ast node'skind
property.As this enum describes not just unique values but also ranges (with
FirstSomething
andLastSomething
elements), reversing the enum values is not unambiguous, and currently it gives back the less expected result (FirstLiteralToken
) and not the expected one (NumericLiteral
).I think changing the order of the enum items or putting these range items to outside of the enum could solve this issue, but this would break compatibility of course.
Footnote: other tools (for example https://astexplorer.net/) also ran into this mistake and it makes harder to beginners to understand without reading TS's source code what's actually happening here. (I thought for a while that
FirstLiteralToken
is some kind of special token, but then I empirically found out it only shows this token type for numeric values and just then I looked into TS's source code...)((I'll report this issue to AstExplorer too.))
The text was updated successfully, but these errors were encountered: