Fix bug in preset-env usage plugin with destructure in for-of (#6662)

This commit is contained in:
Brian Ng 2017-11-15 09:45:54 -06:00 committed by GitHub
parent 9ae23639ad
commit 287b485d0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 4 deletions

View File

@ -217,14 +217,12 @@ export default function({ types: t }: { types: Object }): Plugin {
const obj = node.init;
if (!t.isObjectPattern(node.id)) return;
const props = node.id.properties;
if (!t.isReferenced(obj, node)) return;
// doesn't reference the global
if (path.scope.getBindingIdentifier(obj.name)) return;
if (obj && path.scope.getBindingIdentifier(obj.name)) return;
for (let prop of props) {
for (let prop of node.id.properties) {
prop = prop.key;
if (
!node.computed &&

View File

@ -0,0 +1,3 @@
for (const { padStart } of foo) {
console.log('b'.padEnd(5));
}

View File

@ -0,0 +1,8 @@
import "@babel/polyfill/lib/core-js/modules/es7.string.pad-end";
import "@babel/polyfill/lib/core-js/modules/es7.string.pad-start";
for (const {
padStart
} of foo) {
console.log('b'.padEnd(5));
}

View File

@ -0,0 +1,11 @@
{
"presets": [
["../../../../lib", {
"targets": {
"node": "7"
},
"useBuiltIns": "usage",
"modules": false
}]
]
}

View File

@ -0,0 +1,3 @@
for (const { a } of foo) {
console.log(a);
}

View File

@ -0,0 +1,5 @@
for (const {
a
} of foo) {
console.log(a);
}

View File

@ -0,0 +1,11 @@
{
"presets": [
["../../../../lib", {
"targets": {
"node": "8"
},
"useBuiltIns": "usage",
"modules": false
}]
]
}