Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9989b89b92 | ||
|
|
361ef02a88 | ||
|
|
72369c90a2 | ||
|
|
fa26174d3f | ||
|
|
227d51a556 |
@@ -11,7 +11,7 @@ var buildVariableAssign = function (kind, id, init) {
|
||||
}
|
||||
};
|
||||
|
||||
var get = function (node) {
|
||||
var normalise = function (node) {
|
||||
if (t.isParenthesizedExpression(node)) {
|
||||
return node.expression;
|
||||
} else {
|
||||
@@ -19,8 +19,12 @@ var get = function (node) {
|
||||
}
|
||||
};
|
||||
|
||||
var isPattern = function (node) {
|
||||
return t.isPattern(normalise(node));
|
||||
};
|
||||
|
||||
var push = function (kind, nodes, elem, parentId) {
|
||||
elem = get(elem);
|
||||
elem = normalise(elem);
|
||||
|
||||
if (t.isObjectPattern(elem)) {
|
||||
pushObjectPattern(kind, nodes, elem, parentId);
|
||||
@@ -35,10 +39,10 @@ var push = function (kind, nodes, elem, parentId) {
|
||||
|
||||
var pushObjectPattern = function (kind, nodes, pattern, parentId) {
|
||||
_.each(pattern.properties, function (prop) {
|
||||
var pattern2 = get(prop.value);
|
||||
var pattern2 = prop.value;
|
||||
var patternId2 = t.memberExpression(parentId, prop.key);
|
||||
|
||||
if (t.isPattern(pattern2)) {
|
||||
if (isPattern(pattern2)) {
|
||||
push(kind, nodes, pattern2, patternId2);
|
||||
} else {
|
||||
nodes.push(buildVariableAssign(kind, pattern2, patternId2));
|
||||
@@ -89,8 +93,8 @@ exports.ForOfStatement = function (node, parent, file, scope) {
|
||||
var declar = node.left;
|
||||
if (!t.isVariableDeclaration(declar)) return;
|
||||
|
||||
var pattern = get(declar.declarations[0].id);
|
||||
if (!t.isPattern(pattern)) return;
|
||||
var pattern = declar.declarations[0].id;
|
||||
if (!isPattern(pattern)) return;
|
||||
|
||||
var key = t.identifier(file.generateUid("ref", scope));
|
||||
node.left = t.variableDeclaration(declar.kind, [
|
||||
@@ -113,7 +117,7 @@ exports.Function = function (node, parent, file, scope) {
|
||||
var hasDestructuring = false;
|
||||
|
||||
node.params = node.params.map(function (pattern) {
|
||||
if (!t.isPattern(get(pattern))) return pattern;
|
||||
if (!isPattern(pattern)) return pattern;
|
||||
|
||||
hasDestructuring = true;
|
||||
var parentId = t.identifier(file.generateUid("ref", scope));
|
||||
@@ -142,8 +146,7 @@ exports.ExpressionStatement = function (node, parent, file, scope) {
|
||||
var expr = node.expression;
|
||||
if (expr.type !== "AssignmentExpression") return;
|
||||
|
||||
var left = get(expr.left);
|
||||
if (!t.isPattern(left)) return;
|
||||
if (!isPattern(expr.left)) return;
|
||||
|
||||
var nodes = [];
|
||||
|
||||
@@ -152,7 +155,7 @@ exports.ExpressionStatement = function (node, parent, file, scope) {
|
||||
t.variableDeclarator(ref, expr.right)
|
||||
]));
|
||||
|
||||
push(false, nodes, left, ref);
|
||||
push(false, nodes, expr.left, ref);
|
||||
|
||||
return nodes;
|
||||
};
|
||||
@@ -164,7 +167,7 @@ exports.VariableDeclaration = function (node, parent, file, scope) {
|
||||
|
||||
var hasPattern = false;
|
||||
_.each(node.declarations, function (declar) {
|
||||
if (t.isPattern(get(declar.id))) {
|
||||
if (isPattern(declar.id)) {
|
||||
hasPattern = true;
|
||||
return false;
|
||||
}
|
||||
@@ -173,7 +176,7 @@ exports.VariableDeclaration = function (node, parent, file, scope) {
|
||||
|
||||
_.each(node.declarations, function (declar) {
|
||||
var patternId = declar.init;
|
||||
var pattern = get(declar.id);
|
||||
var pattern = declar.id;
|
||||
if (t.isPattern(pattern) && patternId) {
|
||||
pushPattern({
|
||||
kind: node.kind,
|
||||
|
||||
@@ -185,6 +185,8 @@ t.getIds = function (node, map) {
|
||||
search = search.concat(id.specifiers);
|
||||
} else if (t.isMemberExpression(id)) {
|
||||
search.push(id.object);
|
||||
} else if (t.isParenthesizedExpression(id)) {
|
||||
search.push(id.expression);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
16
package.json
16
package.json
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "1.11.1",
|
||||
"version": "1.11.2",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://github.com/6to5/6to5",
|
||||
"repository": {
|
||||
@@ -36,17 +36,17 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"ast-types": "~0.6.0",
|
||||
"commander": "2.4.0",
|
||||
"commander": "2.5.0",
|
||||
"fs-readdir-recursive": "0.0.2",
|
||||
"lodash": "2.4.1",
|
||||
"mkdirp": "0.5.0",
|
||||
"es6-shim": "0.18.0",
|
||||
"es6-shim": "0.20.2",
|
||||
"es6-symbol": "0.1.1",
|
||||
"regexpu": "0.3.0",
|
||||
"source-map": "0.1.40",
|
||||
"regenerator-6to5": "https://github.com/6to5/regenerator-6to5/archive/b7bc53e1a655879974aad53a8ceb93a70efaa08d.tar.gz",
|
||||
"chokidar": "0.10.0",
|
||||
"source-map-support": "0.2.7",
|
||||
"chokidar": "0.10.5",
|
||||
"source-map-support": "0.2.8",
|
||||
"esutils": "1.1.4",
|
||||
"acorn-6to5": "https://github.com/6to5/acorn-6to5/archive/f5110383517eef0bea78c2da2a1fb01fbed74e4e.tar.gz",
|
||||
"estraverse": "^1.7.0"
|
||||
@@ -54,11 +54,11 @@
|
||||
"devDependencies": {
|
||||
"istanbul": "0.3.2",
|
||||
"matcha": "0.5.0",
|
||||
"mocha": "1.21.5",
|
||||
"mocha": "2.0.1",
|
||||
"uglify-js": "2.4.15",
|
||||
"browserify": "6.1.0",
|
||||
"browserify": "6.2.0",
|
||||
"rimraf": "2.2.8",
|
||||
"jshint": "2.5.6",
|
||||
"jshint": "2.5.10",
|
||||
"chai": "^1.9.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
[a, b] = f();
|
||||
({ x }) = e();
|
||||
|
||||
@@ -4,3 +4,6 @@ var _ref = f();
|
||||
|
||||
a = _ref[0];
|
||||
b = _ref[1];
|
||||
var _ref2 = e();
|
||||
|
||||
x = _ref2.x;
|
||||
|
||||
Reference in New Issue
Block a user