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

Support ECMAScript 2015 Set in for block #759 #760

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

Support ECMAScript 2015 Set in for block #759 #760

wants to merge 1 commit into from

Conversation

ricordisamoa
Copy link
Contributor

Synchronous only.

@@ -106,6 +106,10 @@ exports.isArray = Array.isArray || function(obj) {
return ObjProto.toString.call(obj) === '[object Array]';
};

exports.isSet = function(obj) {
return ObjProto.toString.call(obj) === '[object Set]';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What about polyfills? [object Object]...

Copy link
Contributor

Choose a reason for hiding this comment

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

What about obj && obj[Symbol.toStringTag] == 'Set'? Does not require shims to patch Object#toString (I would argue that they should, and most of them do), but requires Symbol polyfill.

@ricordisamoa
Copy link
Contributor Author

I don't like it, it turned out unreadable, duplication and bad tests

}

this.emitLine('} else if(runtime.isSet(' + arr + ')) {'); {
v = this.tmpid();
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need a different tmpid here? why not use the same one? the is-array and is-set clauses are mutually exclusive.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cargo cult programming

@carljm
Copy link
Contributor

carljm commented May 13, 2016

I think you're being too hard on yourself :-) The for loop code was already hard to read (code-generation code in general is hard to read, and nunjucks generally is too). Your PR follows the same patterns as the existing code (don't worry about some duplication, prioritize speed over size) and makes sense to me. What's wrong with the tests?

@carljm
Copy link
Contributor

carljm commented May 13, 2016

Looks like it's failing on Node 0.10, probably because it doesn't support for...of?

@ricordisamoa
Copy link
Contributor Author

probably because it doesn't support for...of

yes

@maxnordlund
Copy link
Contributor

Actually the code supports anything that happens to support the iterator protocol. But to be pragmatic, and support old browsers, why not use Array.from directly.

The only caveat I can think of is providing a string, which would iterate over the individual characters. But then again, by then your in la la land anyways.

The code could be simplified as arr = (typeof Array.from === "function") ? Array.from(arr) : arr. Then just reuse the old flow. If you don't have time @ricordisamoa I can make a PR with that change, but I don't want to steal this PR from you.

@ricordisamoa
Copy link
Contributor Author

@maxnordlund steal it, please 😀

@maxnordlund maxnordlund mentioned this pull request Jan 26, 2018
4 tasks
@maxnordlund
Copy link
Contributor

So Christmas happened, but I finally got around to doing this. Check it out and give me some feedback, pretty please?

@maxnordlund
Copy link
Contributor

This is done I think, ping @fdintino

@fdintino
Copy link
Collaborator

It is. I'll wait until I merge in the develop branch and put out a release before I close out this issue though.

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.

5 participants