-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Request: different instances of core-js/library should return the same Symbol.iterator #51
Comments
In own methods, I'll think about it. |
I thought about both solutions before.
Ideas? |
I hadn't thought of the symbol registry. That puts me heavily in favor of the second solution since even more than Symbol.iterator benefits. No big downsides of the global way jump out at me besides a little bit of pollution, but on the plus side that pollution only happens for environments that don't yet have Symbol present natively (and don't have a global polyfill loaded). |
update core-js to get Symbol fix: zloirock/core-js#51
Background: Babel with the "runtime" transformation essentially translates code using
Symbol
to userequire('core-js/library').Symbol
. The "runtime" transformation seems to be necessary for well-behaved libraries that need ES6 polyfills without polluting the global context or requiring the application to do so.A problem occurs when a babel-transpiled library (using the runtime transformation) wants to be able to interoperate with iterable objects created by other babel-transpiled code (and they don't happen to share the same instance of
babel-runtime/core-js
, which will be the case if they weren't compiled with the same exact version of babel, or if neither babel-transpiled-library depends directly on the other andnpm prune
was not used). If a global Symbol.iterator is present, then it works fine because core-js returns that global one if it's present. If a global Symbol.iterator is not available (node 0.10.x, or most non-Chrome and non-Firefox browsers), then the library and the application / other libraries will each have different values for Symbol.iterator, and won't ever recognize objects created by each other as iterable.Here's an example of an issue with a babel-transpiled library: webmodules/node-iterator#1 . I brainstormed a few ways that the library itself could work around the issue, but they didn't strike me as very good. I think core-js or babel would be better positioned to solve this, though I'm not sure on the specifics, and I'm interested in any discussions.
Possible core-js solutions:
require('core-js/library').Symbol.iterator
could always evaluate to a specific hard-coded string. Relevant: Facebook's regenerator library falls back to using the string "@@iterator" for Symbol.iterator if Symbol isn't available.The text was updated successfully, but these errors were encountered: