Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 13.8k
Using lookahead to detect generic JSX elements? #6395
Copy link
Copy link
Closed
Labels
Domain: JSX/TSXRelates to the JSX parser and emitterRelates to the JSX parser and emitterEffort: DifficultGood luck.Good luck.FixedA PR has been merged for this issueA PR has been merged for this issueHelp WantedYou can do thisYou can do thisSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
Description
Activity
Metadata
Metadata
Assignees
Labels
Domain: JSX/TSXRelates to the JSX parser and emitterRelates to the JSX parser and emitterEffort: DifficultGood luck.Good luck.FixedA PR has been merged for this issueA PR has been merged for this issueHelp WantedYou can do thisYou can do thisSuggestionAn idea for TypeScriptAn idea for TypeScript
Initially from a coupledifferent comments, but elaborated here.
Currently, in order to use a generic JSX element, you must alias both the type and interface to a non-generic specialization.
It would be a lot more convenient and consistent to use something like this:
In order to differentiate the latter, you can use a single token of lookahead in the parser to know if it's a generic JSX element:
<, like in< Select <, then consume the rest of the type as a generic type. After consuming that:>, then finish the type as a generic type cast.{(for spread attributes, when they get implemented), then parse the rest as a JSX element.>, like in< Select >, then finish the type as a simple type cast.{, then parse the rest as a JSX element.I don't know of any reason that wouldn't be feasible to do, considering async arrow functions, which are already implemented, require potentially a whole call expression of parsing to differentiate between
let f = async (x, y), which is a call expression, andlet f = async (x, y) => x, which is an async arrow function. (I feel sorry for whoever ends up implementing that in V8, which doesn't support any backtracking or much lookahead for memory reasons.)/cc Ryan Cavanaugh (@RyanCavanaugh)