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

Symbol.iterator should not load full Symbol polyfill #80

Closed
zloirock opened this issue Mar 24, 2021 · 8 comments · Fixed by #201
Closed

Symbol.iterator should not load full Symbol polyfill #80

zloirock opened this issue Mar 24, 2021 · 8 comments · Fixed by #201
Labels
bug Something isn't working

Comments

@zloirock
Copy link
Member

// Now:
arr[Symbol.iterator]();
// =>
import "core-js/modules/es.symbol.iterator.js";
import "core-js/modules/es.array.iterator.js";
import "core-js/modules/es.object.to-string.js";
import "core-js/modules/es.string.iterator.js";
import "core-js/modules/web.dom-collections.iterator.js";
import "core-js/modules/es.symbol.js";
import "core-js/modules/es.symbol.description.js";
arr[Symbol.iterator]();

es.symbol and es.symbol.description should not be loaded only on Symbol.iterator - it's too expensive. core-js architecture should allow to use es.symbol.iterator and iterators without those modules.

@nicolo-ribaudo nicolo-ribaudo added the bug Something isn't working label Mar 24, 2021
@zloirock
Copy link
Member Author

BTW looking at this output - seems after #78 modules sorted in the scope of a feature, but not a file how it should be and if Symbol.iterator would depend on Symbol - it will not work, es.symbol.js should be before the rest modules - it still could cause problems like #77.

@nicolo-ribaudo
Copy link
Member

Ok so:

  • We should only inject es.symbol if it's used not as part of Symbol.iterator
  • If es.symbol is injected, it should always come before es.symbol.iterator.

Is this correct?

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Mar 26, 2021

Btw, I don't think we can always fix the "implicit optional dependency" between those two polyfills:

// main.js

import "./dep1.js";
import "./dep2.js";
// dep1.js

Symbol.iterator;
// dep2.js

Symbol();

Either we always inject an import to es.symbol in dep1.js, or es.symbol.iterator will be imported before es.symbol.

@zloirock
Copy link
Member Author

zloirock commented Mar 26, 2021

@nicolo-ribaudo I mean that es.symbol before es.symbol.iterator in the recommended modules order. It's not related to this issue, it's related #77 and #78. It should work at least on the file's layer - different files are another problem.

@nyngwang

This comment was marked as off-topic.

@zloirock
Copy link
Member Author

It's another issue.

@nicolo-ribaudo
Copy link
Member

Working on this

@zloirock
Copy link
Member Author

zloirock commented Feb 8, 2024

@nicolo-ribaudo note that it also requires some other changes, for example, take a look at

  export default function _createForOfIteratorHelper(o, allowArrayLike) {
    var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];

that on typeof Symbol !== "undefined" will also load full symbol polyfill, or regeneratorRuntime:

var $Symbol = typeof Symbol === "function" ? Symbol : {};
var iteratorSymbol = $Symbol.iterator || "@@iterator";
var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";

It's an extended version of something like #199 and changes of some helpers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants