add loose mode to spread and destructuring
This commit is contained in:
@@ -7,7 +7,7 @@ var buildVariableAssign = function (opts, id, init) {
|
||||
if (t.isMemberExpression(id)) op = "=";
|
||||
|
||||
if (op) {
|
||||
return t.expressionStatement(t.assignmentExpression("=", id, init));
|
||||
return t.expressionStatement(t.assignmentExpression(op, id, init));
|
||||
} else {
|
||||
return t.variableDeclaration(opts.kind, [
|
||||
t.variableDeclarator(id, init)
|
||||
@@ -95,7 +95,12 @@ var pushArrayPattern = function (opts, nodes, pattern, parentId) {
|
||||
}
|
||||
}
|
||||
|
||||
var toArray = opts.file.toArray(parentId, !hasSpreadElement && pattern.elements.length);
|
||||
var isLoose = opts.file.isLoose("destructuring");
|
||||
var toArray = parentId;
|
||||
|
||||
if (!isLoose) {
|
||||
toArray = opts.file.toArray(parentId, !hasSpreadElement && pattern.elements.length);
|
||||
}
|
||||
|
||||
var _parentId = opts.scope.generateUidBasedOnNode(parentId, opts.file);
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
@@ -107,12 +112,14 @@ var pushArrayPattern = function (opts, nodes, pattern, parentId) {
|
||||
var elem = pattern.elements[i];
|
||||
if (!elem) continue;
|
||||
|
||||
i = +i;
|
||||
|
||||
var newPatternId;
|
||||
|
||||
if (t.isSpreadElement(elem)) {
|
||||
newPatternId = opts.file.toArray(parentId);
|
||||
newPatternId = parentId;
|
||||
|
||||
if (!isLoose) {
|
||||
newPatternId = opts.file.toArray(parentId);
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
newPatternId = t.callExpression(t.memberExpression(newPatternId, t.identifier("slice")), [t.literal(i)]);
|
||||
|
||||
@@ -2,7 +2,11 @@ var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
var getSpreadLiteral = function (spread, file) {
|
||||
return file.toArray(spread.argument);
|
||||
if (file.isLoose("spread")) {
|
||||
return spread.argument;
|
||||
} else {
|
||||
return file.toArray(spread.argument);
|
||||
}
|
||||
};
|
||||
|
||||
var hasSpread = function (nodes) {
|
||||
@@ -64,7 +68,7 @@ exports.CallExpression = function (node, parent, scope, context, file) {
|
||||
node.arguments = [];
|
||||
|
||||
var nodes;
|
||||
if (args.length === 1 && args[0].argument.name === 'arguments') {
|
||||
if (args.length === 1 && args[0].argument.name === "arguments") {
|
||||
nodes = [args[0].argument];
|
||||
} else {
|
||||
nodes = build(args, file);
|
||||
|
||||
Reference in New Issue
Block a user