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

concat to flags #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

concat to flags #17

wants to merge 1 commit into from

Conversation

bergus
Copy link
Collaborator

@bergus bergus commented Aug 12, 2015

If we can do myMake = RegExp.make("")("g")("i")("")… anyway, let it be useful at least :-)

I wonder what TC39 will say to this pattern, though. There are no curried functions in ES6 yet, and no variadic ones for sure.

If we can do `RegExp.make("")("g")("i")("")…` anyway, let it be useful at least :-)
if ('string' === typeof template && values.length === 0) {
// Allow RegExp.make(i)`...` to specify flags.
// This calling convention is disjoint with use as a template tag
// since the typeof a template record is 'object'.
return make.bind(null, template /* use as flags instead */);
return make.bind(null, flags + template /* use as flags instead */);
Copy link
Collaborator

Choose a reason for hiding this comment

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

won't this cause a problem if i do make('g')('g')? or should we expect that to throw, much later, when it's invoked as a tagged template string?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, you're right, §21.2.3.2.2#7 says

if it contains the same code unit more than once, throw a SyntaxError exception.

I didn't consider that. Do you think we should throw immediately? Filter out duplicates?

The change just looked simple and possible useful. I don't want to add any complexity…

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer to throw immediately. If we know it will fail later, why defer the failure? The use case for currying here includes passing around the "maker" function for later use, so the exception could occur far away from the site of the double-flag.

Of course, another alternative is to uniquify the code units (perhaps [...new Set(flags + template)].join('')) in make.

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