Array destructuring transpiles into code that is incompatible with IE11
See original GitHub issueBug Report
- I would like to work on a fix!
Current Behavior
Transpiling the code below generates code that uses Symbol, which does not run on IE11, even though I have @babel/env
set to ie: 11
.
Input Code
const oneTwoTree = () => [1, 2, 3];
const [a, b, c] = oneTwoTree();
Output Code
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
var oneTwoTree = function oneTwoTree() {
return [1, 2, 3];
};
var _oneTwoTree = oneTwoTree(),
_oneTwoTree2 = _slicedToArray(_oneTwoTree, 3),
a = _oneTwoTree2[0],
b = _oneTwoTree2[1],
c = _oneTwoTree2[2];
Expected behavior/code Transpiled code that runs on IE11.
Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)
- Filename:
babel.config.js
module.exports = function(api) {
return {
presets: [
[
'@babel/env',
{
modules: 'amd',
targets: {
ie: '11',
safari: '11'
}
}
],
['@babel/react']
],
sourceMaps: 'both',
sourceType: 'unambiguous'
};
};
Environment
- Babel version(s): v7.8.4
- How you are using Babel:
cli
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Destructuring assignment not working in IE 11 even after ...
I have a situation where I am adding a middleware which contain destructing params When opened in google chrome ,its working fine ....
Read more >IE11 and the Missing Polyfills - DEV Community
Our startup was in the stealth mode. We had no traffic, no customers, and, obviously, no worries. Everything was perfect - the code...
Read more >Polyfills, transpilation, and browser support | by Dominic Fraser
Array.includes unsupported on IE11 https://caniuse.com/array-. It's important to note that while we use IE11 is as the most common example, ...
Read more >ECMAScript 6 compatibility table
Feature name▻ Current browser 98% ES6 Trans‑ piler 25% Trace...
Optimisation Optimisation Optimisation Optimi...
§proper tail calls (tail call optimisation)▻ 0/2 0/2 0/2
§direct recursionc No...
Read more >Destructuring assignment - JavaScript - MDN Web Docs
The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Leaving this snippet here for anyone getting an error in IE11, hope it can help anyone. It took pretty long for me to debug…
The problem was that
document.body.childNodes
is not iterable in old IE versions.You can now enable the
allowArrayLike
option of the destructuring transform, or the newarrayLikeIsIterable
assumption that will be released in Babel 7.13.0 (https://github.com/babel/rfcs/pull/5).