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

Allow subclassing of RegExps #18

Merged
merged 6 commits into from
Oct 24, 2015
Merged

Allow subclassing of RegExps #18

merged 6 commits into from
Oct 24, 2015

Conversation

mikesamuel
Copy link
Owner

No description provided.

@ljharb
Copy link
Collaborator

ljharb commented Aug 12, 2015

👍

// 2. RegExp.make('gi')`....` to specify flags
// 3. RegExp.make.bind(RegExpSubClass)`...` with a this value that specifies
// a different constructor.
const xType = typeof x;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just use typeof x twice. Should be shorter and easier to read; also engines optimise this better when typeof is a direct operand of ==/===.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Done

@mikesamuel
Copy link
Owner Author

@bergus, are you ok with patch as it stands?

@@ -306,7 +306,7 @@ RegExp.make = (function () {
* a start context, and RegExp source, and returns an end context.
*/
function parseRegExpSource(eventHandler) {
const {
var {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is this changed to var?

Copy link
Collaborator

Choose a reason for hiding this comment

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

still not sure why this is changed to var

Copy link
Owner Author

Choose a reason for hiding this comment

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

This is the same limitation of closure compiler. It types consts in a separate pass from vars.

mikesamuel added a commit that referenced this pull request Oct 24, 2015
Allow subclassing of RegExps
@mikesamuel mikesamuel merged commit a4d5e4e into master Oct 24, 2015
@@ -1065,12 +1076,25 @@ RegExp.make = (function () {
pattern += rawLiteralPart;
addTemplateGroups(i+1);
}
const output = new RegExp(pattern, flags);
var output = new ctor(pattern, flags);
Copy link
Collaborator

Choose a reason for hiding this comment

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

or this one

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.

4 participants