-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement parser changes for the JSX automatic runtime (#739)
Progress toward #585 This change extends the parser to detect two JSX cases that are needed for the automatic runtime. The new code is run unconditionally, even in the old transform, since flagging it would have its own overhead and complexity. The new JSX transform needs to distinguish children being static or non-static, where static is equivalent to having at least two comma-separated children emitted by the old transform or any child being a spread child. The main challenge in getting this right is that JSX whitespace-trimming will sometimes completely remove all content from a text range, in which case it shouldn't count as a child for the purposes of counting the number of children. Fortunately, there is a relatively simple algorithm to detect if a text range is empty: it's empty if and only if it is entirely whitespace and has at least one newline. To identify these "empty text" regions, I added a new token type `jsxEmptyText` that is treated the same except for the purposes of counting children. In the future, it likely is reasonable to not treat such a region as a token in the first place. The new JSX transform also needs to detect the pattern of a key appearing after a prop spread. We don't do keyword detection on JSX prop names, so instead I manually detect the name "key", but only if we have already seen a prop spread.
- Loading branch information
1 parent
36b82ba
commit e9a1281
Showing
9 changed files
with
307 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.