diff --git a/src/babel/transformation/transformers/es6/destructuring.js b/src/babel/transformation/transformers/es6/destructuring.js index 8c11eca2d5..400716b8b8 100644 --- a/src/babel/transformation/transformers/es6/destructuring.js +++ b/src/babel/transformation/transformers/es6/destructuring.js @@ -434,7 +434,11 @@ class DestructuringTransformer { // return a locally bound identifier if it's been inferred to be an array, // otherwise it'll be a call to a helper that will ensure it's one - var toArray = this.scope.toArray(arrayRef, count); + var toArray = arrayRef; + + if (!this.file.isLoose("es6.destructuring")) { + toArray = this.scope.toArray(arrayRef, count); + } if (t.isIdentifier(toArray)) { // we've been given an identifier so it must have been inferred to be an @@ -457,7 +461,11 @@ class DestructuringTransformer { var elemRef; if (t.isRestElement(elem)) { - elemRef = this.scope.toArray(arrayRef); + elemRef = arrayRef; + + if (!this.file.isLoose("es6.destructuring")) { + elemRef = this.scope.toArray(arrayRef); + } if (i > 0) { elemRef = t.callExpression(t.memberExpression(elemRef, t.identifier("slice")), [t.literal(i)]); diff --git a/src/babel/transformation/transformers/es6/spread.js b/src/babel/transformation/transformers/es6/spread.js index b47e5b24b4..d56f9c9c66 100644 --- a/src/babel/transformation/transformers/es6/spread.js +++ b/src/babel/transformation/transformers/es6/spread.js @@ -2,7 +2,11 @@ import includes from "lodash/collection/includes"; import * as t from "../../../types"; function getSpreadLiteral(spread, scope) { - return scope.toArray(spread.argument, true); + if (scope.file.isLoose("es6.spread")) { + return spread.argument; + } else { + return scope.toArray(spread.argument, true); + } } function hasSpread(nodes) {