Skip to content

Conversation

@josephfrazier
Copy link
Collaborator

This makes the "Constructor with x flag, whitespace, and comments" test
fast again. From
#164 (comment):

A couple ideas: avoid the string concatenation in isPatternNext
(possibly going back to regex literals and making the function specific
to quantifiers again even though the current code is more
readable/maintainable, since this isn't needed to handle simple cases
with whitespace followed by ))

Since babel-plugin-transform-xregexp automatically compiles the new RegExp() calls into literals, we get (most of) the performance back
without sacrificing the readability of having separate subpatterns.

This add [babel-plugin-transform-xregexp] to the build process, which
allows XRegExp to "self-host" in a sense. Note that `new Regexp()` is
compiled to `/(?:)/`.

[babel-plugin-transform-xregexp]: https://www.npmjs.com/package/babel-plugin-transform-xregexp
This makes the "Constructor with x flag, whitespace, and comments" test
fast again. From slevithan#164 (comment):

> A couple ideas: avoid the string concatenation in `isPatternNext`
> (possibly going back to regex literals and making the function specific
> to quantifiers again even though the current code is more
> readable/maintainable, since this isn't needed to handle simple cases
> with whitespace followed by `)`)

Since babel-plugin-transform-xregexp automatically compiles the `new
RegExp()` calls into literals, we get (most of) the performance back
without sacrificing the readability of having separate subpatterns.
@slevithan slevithan merged commit 0bbc43f into slevithan:master Apr 25, 2017
@slevithan
Copy link
Owner

Awesome

@josephfrazier josephfrazier deleted the self-host branch May 1, 2017 00:16
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.

2 participants