-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
regression: array.includes no longer working. #263
Comments
So it looks like the last time this passed, was on So maybe the |
Babel can't resolve instance methods on references to polyfills. Think about it this way, how can a compiler know what keys.includes() There is the potential in this particular case to do something about it because we can infer that the result of function includesName(keys) {
return keys.includes('name');
} This inability to do things consistently is why Babel will never auto-polyfill like this. |
Couldn't you transform it to something like this: var x = arr.includes('foo');
// =>
var x = includesHelper(arr, 'name');
function includesHelper(maybeArray, ...args) {
if (Array.isArray(maybeArray) && !maybeArray.includes) {
// use polyfill
} else {
return maybeArray.includes.apply(maybeArray, args);
}
} Obviously there is a performance hit for this way (especially when expanded to accommodate String.includes) . Is that the only reason it is considered unacceptable, or are there other reasons? |
If you're going to include the code to polyfill it, why not just polyfill it? Also, I don't think we'd ever be interested in going down that route in core, you're welcome to try your hand at in in your own plugin. |
AVA is trying to provide as much ES2015+ support inside tests, while not polluting the production environment at all. ES2015 convenience in the tests, while still allowing you to write really tiny, dependency-less modules that do not require a build step. I thought the goals of the optional runtime plugin were similar. |
Wonder if the |
Interesting. Looking back at the The list of prototype polyfills is not that long. A plugin might be easier. @thejameskyle - Does the |
Babel can actually do that through These are aliases to core-js functions: Array.includes; import _Array$includes from "babel-runtime/core-js/array/includes";
_Array$includes; |
That's what I thought. So, if I were to write a plugin to fill in the gaps for AVA, I would only need to tackle instance methods. |
@jamestalmage: I really don't think it would be that big of a deal to have the polyfill... I can't think of any possible reason (if I knew that the tests ran in ES2015), that the polyfill would confuse me. |
@ariporad The problem with such polyfill is that it mutates the global Array prototype, so it would influence not just your test code, but the code being tested. |
Is this really a bug? I agree it's a gotcha but even if we did an optimistic transform like @jamestalmage suggested in #263 (comment) that wouldn't work for test helpers. |
Closing, this is not something we can fix when transpiling test files. Users could add a |
@novemberborn Maybe we should document it somewhere? It can be surprising behavior. |
Yes. Opened #727. |
Late to this party but I just wanted to affirm the decision to have AVA not add polyfills by default (global polluting or no). Jest took a different route (and includes |
Reference: sindresorhus/serialize-error#3 (comment)
The following no longer works:
I get the following error:
We are using the
runtime
plugin, to avoid any polyfills, so it makes sense that Array.prototype.includes does not actually exist. I would have thought the runtime plugin would have picked this up and provided it via some helper function.We are still on Babel 5, so I am punting until we land Babel 6 support before digging in.
// @sebmck @thejameskyle
The text was updated successfully, but these errors were encountered: