From 710a7f882d62c38de48601a06506748c7fc51bd9 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sat, 28 Mar 2015 00:21:37 +1100 Subject: [PATCH] add loose mode for es6.spread and es6.destructuring that assumes all values are arrays - emberjs/ember.js#10730 --- .../transformation/transformers/es6/destructuring.js | 12 ++++++++++-- src/babel/transformation/transformers/es6/spread.js | 6 +++++- 2 files changed, 15 insertions(+), 3 deletions(-) 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) {