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

Transformed all remaining occurences of for..of to forEach() #426

Conversation

rhettlivingston
Copy link
Contributor

No description provided.

@benmosher
Copy link
Member

fixes #415?

if (name !== 'default') {
for (let dep of this.dependencies.values()) {
let innerMap = dep()
this.dependencies.forEach((dep) => {
Copy link
Member

Choose a reason for hiding this comment

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

this would ideally be a some so that it short-circuits. not sure how to achieve with a 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.

I learned while doing this that Maps and Sets are very fundamentally not Arrays. So, no some and not even a clear way to utilize the basic for statement and break out of it (i.e. you can't access them in an indexed fashion).

I suspect the overhead of converting to an array just to use some would be greater than the gain.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After thinking about this some,,, I may experiment with directly accessing the iterator in a for loop. This is essentially what is going on with for..of, but I might be able to get away with it if I don't involve the underlying Symbol type and go directly to the Map / Set.

I've also realized I might have changed more than I had too. The instances that definitely caused problems involved using for..of to iterate Maps. In response, I changed all occurrences of for..of. It is possible that using for..of to iterate a Set causes no issue.

@rhettlivingston
Copy link
Contributor Author

rhettlivingston commented Jul 7, 2016

Yes. Didn't put that in the comment because I was merging into the branch
that fixes it.

I have to apologize for what it does to your code. I really wish I knew how
to just make the for..of implementation play well with others. forEach is
very inferior in this case because you can neither 'continue' within it nor
'return' from it.

On Thu, Jul 7, 2016 at 1:15 PM, Ben Mosher notifications@github.com wrote:

fixes #415 #415?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#426 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AH5TYs2rKotZaL09yo00Yrz6DpjeAPWvks5qTTRDgaJpZM4JHTZ0
.

if (innerValue.found) {
innerValue.path.unshift(this)
return innerValue
this.dependencies.forEach((dep) => {
Copy link
Member

Choose a reason for hiding this comment

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

same here, ideally would short-circuit

@benmosher
Copy link
Member

On short-circuits: I think you're probably right, best to leave it be.

Though notably, this.dependencies only ever deals with its values after parse time, so the only use it gets being a Map is one-per-path export * from x behavior, which could be easily achieved with an ephemeral Set of paths during parse and just if (!exportAllPaths.has(remoteMap)) m.dependencies.push(() => ExportMap.for(remoteMap, context) on line ~163 of getExports.js.

FWIW, I'll probably revert to the for ... of syntax in v2 anyway since 0.10 will no longer be supported. so no sweat either way. 😁 Best to just get it correct for the short term and not worry too much about the ideal case.

I'm just over-thinking it.

@benmosher
Copy link
Member

I'll go ahead and merge as-is if it fixes #415, no need to sweat the style stuff ATM.

@benmosher benmosher merged commit 9a8f821 into import-js:issue-415-no-symbols Jul 7, 2016
@rhettlivingston
Copy link
Contributor Author

Thank you very much for accepting this. And I'd absolutely agree with reverting to for..of later. It is unquestionably the proper way to traverse Maps and Sets.

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

Successfully merging this pull request may close these issues.

2 participants