Skip to content

Commit

Permalink
only check if the last property is rest
Browse files Browse the repository at this point in the history
- due to spec changes requiring RestProperty to have to be last and have only 1 of them
  • Loading branch information
hzoo authored Nov 11, 2016
1 parent f2b4030 commit b81e978
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions packages/babel-plugin-transform-es2015-destructuring/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,12 @@ export default function ({ types: t }) {
// are extracted into temporary vars so they are only evaluated
// once

let hasRestProperty = false;
for (let i = 0; i < pattern.properties.length; i++) {
const prop = pattern.properties[i];
if (t.isRestProperty(prop)) {
hasRestProperty = true;
break;
}
}

//
let lastProp = pattern.properties.length - 1;
let hasRestProperty = t.isRestProperty(pattern.properties[lastProp]);

for (let i = 0; i < pattern.properties.length; i++) {
let prop = pattern.properties[i];
if (t.isRestProperty(prop)) {
if (i === lastProp && t.isRestProperty(prop)) {
this.pushObjectRest(pattern, objRef, prop, i);
} else {
// extract key to temp var to avoid multiple evaluation
Expand Down

0 comments on commit b81e978

Please sign in to comment.