Skip to content
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

Fix test generation placeholders inside and adjacent to RegExp literals #3817

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ptomato
Copy link
Contributor

@ptomato ptomato commented Apr 14, 2023

Several improvements to the test generation tool. The first commit is based on @guijemont's work and fixes the case where a placeholder comment is immediately adjacent to the end of a RegExp literal.

The second commit adds a feature to test template files which can be used as an escape hatch in case the /* and */ delimiters of placeholder comments would be misparsed. (This is one way that it could work, I'm not attached to it.)

Closes: #3808

@ptomato ptomato requested a review from a team as a code owner April 14, 2023 23:16
ptomato and others added 2 commits April 14, 2023 16:27
This fixes cases such as `/foo//*{ subst }*/` where previously the `//`
would be interpreted as a single-line comment. We now keep track in
find_comments() of when we are inside a RegExp literal.

However, this breaks cases that used to work (but not tested; maybe this
worked unintentionally?) of `/regexp /*{ subst }*//`.

See: tc39#3808

Co-authored-by: Guillaume Emont <[email protected]>
For places where /* or */ would be misparsed (e.g. in RegExp literals) we
add an escape hatch in the form of placeholder-prefix and
placeholder-suffix keys that can be placed in the front matter of a test
template file.

These strings delimit placeholder comments, regardless of where they
appear in the template file.

Unlike /* */ placeholder comments, a placeholder comment delimited by
these strings _must_ contain an identifier wrapped in curly braces. If it
contains anything else, the file is invalid. This is to prevent
accidentally using some valid JS syntax as the delimiters.
@ptomato ptomato force-pushed the 3808-fix-test-generation-regexp branch from bd4c562 to a38d3cd Compare April 14, 2023 23:27
Copy link
Contributor

@jugglinmike jugglinmike left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first commit looks like it unblocks gh-3807, so I'm all for it!

I'm less enthusiastic about the second commit, though. Addressing needs through configuration certainly makes the tool more powerful, but it also makes things more daunting for new contributors--even for those who have no need for it (presumably the majority of potential users). This implementation's distinct edge case (the restriction on interpolated values), if documented, will steepen the learning curve a little further still.

I'd be more inclined to collaborate on the design if there was a motivating use case. Without that, its hard for me to justify the complexity and to envision the scenarios where test authors would need this ability.

@ptomato
Copy link
Contributor Author

ptomato commented Apr 17, 2023

@jugglinmike I see your point, in fact I shared your skepticism about the configurable delimiters feature when Richard suggested it. This comment explains why I changed my mind. But like I said in the description, I'm not attached to the design of this feature, so I'd be happy to go with something completely different.

But more immediately: the first commit actually doesn't unblock #3807 unless I add some more processing for comments inside regexp literals. (The first commit fixes /foo//*{ bar }*/ but breaks /foo/*{ bar }*/baz/. Fixing the latter made me come around to Richard's suggestion of configurable delimiters.) I'd be happy to make a separate PR with 83614a1 and a second commit that fixes comments inside regexp literals, while we iterate on the configurable delimiters, or decide not to do them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[generation] Support comments directly following regular expression litterals
2 participants