remove ParenthesizedExpression
This commit is contained in:
@@ -156,7 +156,7 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
|
||||
|
||||
// only compute if this node needs parens if our parent has been changed
|
||||
// since acorn would've wrapped us in a ParanthesizedExpression
|
||||
var needsParens = parent !== node._parent && n.needsParens(node, parent);
|
||||
var needsParens = n.needsParens(node, parent);
|
||||
if (needsParens) this.push("(");
|
||||
|
||||
this[node.type](node, this.buildPrint(node), parent);
|
||||
|
||||
@@ -18,12 +18,6 @@ exports.UnaryExpression = function (node, print) {
|
||||
print(node.argument);
|
||||
};
|
||||
|
||||
exports.ParenthesizedExpression = function (node, print) {
|
||||
this.push("(");
|
||||
print(node.expression);
|
||||
this.push(")");
|
||||
};
|
||||
|
||||
exports.UpdateExpression = function (node, print) {
|
||||
if (node.prefix) {
|
||||
this.push(node.operator);
|
||||
@@ -98,8 +92,11 @@ exports.AssignmentExpression = function (node, print) {
|
||||
print(node.right);
|
||||
};
|
||||
|
||||
var SCIENTIFIC_NOTATION = /e/i;
|
||||
|
||||
exports.MemberExpression = function (node, print) {
|
||||
print(node.object);
|
||||
var obj = node.object;
|
||||
print(obj);
|
||||
|
||||
if (node.computed) {
|
||||
this.push("[");
|
||||
@@ -107,7 +104,7 @@ exports.MemberExpression = function (node, print) {
|
||||
this.push("]");
|
||||
} else {
|
||||
// 5..toFixed(2);
|
||||
if (t.isLiteral(node.object) && util.isInteger(node.object.value)) {
|
||||
if (t.isLiteral(obj) && util.isInteger(obj.value) && !SCIENTIFIC_NOTATION.test(obj.value.toString())) {
|
||||
this.push(".");
|
||||
}
|
||||
|
||||
|
||||
@@ -92,13 +92,6 @@ exports.YieldExpression = function (node, parent) {
|
||||
t.isYieldExpression(parent);
|
||||
};
|
||||
|
||||
exports.Literal = function (node, parent) {
|
||||
// (1).valueOf()
|
||||
if (_.isNumber(node.value) && t.isMemberExpression(parent) && parent.object === node) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ClassExpression = function (node, parent) {
|
||||
return t.isExpressionStatement(parent);
|
||||
};
|
||||
|
||||
@@ -25,7 +25,7 @@ exports.ObjectExpression = function (node, parent, file) {
|
||||
OBJECT: node
|
||||
});
|
||||
|
||||
var containerCallee = container.callee.expression;
|
||||
var containerCallee = container.callee;
|
||||
var containerBody = containerCallee.body.body;
|
||||
|
||||
containerCallee._aliasFunction = true;
|
||||
|
||||
@@ -36,10 +36,7 @@ exports.TemplateLiteral = function (node) {
|
||||
nodes.push(t.literal(elem.value.cooked));
|
||||
|
||||
var expr = node.expressions.shift();
|
||||
if (expr) {
|
||||
if (t.isBinary(expr)) expr = t.parenthesizedExpression(expr);
|
||||
nodes.push(expr);
|
||||
}
|
||||
if (expr) nodes.push(expr);
|
||||
}
|
||||
|
||||
if (nodes.length > 1) {
|
||||
|
||||
@@ -33,7 +33,7 @@ var multiple = function (node, file) {
|
||||
});
|
||||
container.callee.expression._aliasFunction = true;
|
||||
|
||||
var block = container.callee.expression.body;
|
||||
var block = container.callee.body;
|
||||
var body = block.body;
|
||||
|
||||
var returnStatement = body.pop();
|
||||
|
||||
@@ -96,7 +96,6 @@ traverse.removeProperties = function (tree) {
|
||||
delete node._declarations;
|
||||
delete node.extendedRange;
|
||||
delete node._scopeInfo;
|
||||
delete node._parent;
|
||||
delete node._scope;
|
||||
delete node.tokens;
|
||||
delete node.range;
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
"MemberExpression": ["object", "property", "computed"],
|
||||
"NewExpression": ["callee", "arguments"],
|
||||
"ObjectExpression": ["properties"],
|
||||
"ParenthesizedExpression": ["expression"],
|
||||
"Program": ["body"],
|
||||
"Property": ["kind", "key", "value", "computed"],
|
||||
"ReturnStatement": ["argument"],
|
||||
|
||||
@@ -116,7 +116,7 @@ t.shallowEqual = function (actual, expected) {
|
||||
//
|
||||
|
||||
t.isDynamic = function (node) {
|
||||
if (t.isParenthesizedExpression(node) || t.isExpressionStatement(node)) {
|
||||
if (t.isExpressionStatement(node)) {
|
||||
return t.isDynamic(node.expression);
|
||||
} else if (t.isIdentifier(node) || t.isLiteral(node) || t.isThisExpression(node)) {
|
||||
return false;
|
||||
@@ -262,7 +262,6 @@ t.getIds.nodes = {
|
||||
VariableDeclarator: "id",
|
||||
FunctionDeclaration: "id",
|
||||
ClassDeclaration: "id",
|
||||
ParenthesizedExpression: "expression",
|
||||
MemeberExpression: "object",
|
||||
SpreadElement: "argument",
|
||||
Property: "value"
|
||||
|
||||
@@ -45,7 +45,6 @@
|
||||
"NewExpression": ["callee", "arguments"],
|
||||
"ObjectExpression": ["properties"],
|
||||
"ObjectPattern": ["properties"],
|
||||
"ParenthesizedExpression": ["expression"],
|
||||
"PrivateDeclaration": ["declarations"],
|
||||
"Program": ["body"],
|
||||
"Property": ["key", "value"],
|
||||
|
||||
@@ -161,8 +161,6 @@ exports.template = function (name, nodes, keepExpression) {
|
||||
|
||||
if (!keepExpression && t.isExpressionStatement(node)) {
|
||||
node = node.expression;
|
||||
|
||||
if (t.isParenthesizedExpression(node)) node = node.expression;
|
||||
}
|
||||
|
||||
return node;
|
||||
@@ -209,13 +207,7 @@ exports.repeat = function (width, cha) {
|
||||
|
||||
exports.normaliseAst = function (ast, comments, tokens) {
|
||||
if (ast && ast.type === "Program") {
|
||||
ast = t.file(ast, comments || [], tokens || []);
|
||||
|
||||
traverse(ast, function (node, parent) {
|
||||
node._parent = parent;
|
||||
});
|
||||
|
||||
return ast;
|
||||
return t.file(ast, comments || [], tokens || []);
|
||||
} else {
|
||||
throw new Error("Not a valid ast?");
|
||||
}
|
||||
@@ -228,7 +220,6 @@ exports.parse = function (opts, code, callback) {
|
||||
|
||||
var ast = acorn.parse(code, {
|
||||
allowReturnOutsideFunction: true,
|
||||
preserveParens: true,
|
||||
ecmaVersion: opts.experimental ? 7 : 6,
|
||||
playground: opts.playground,
|
||||
strictMode: true,
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
(function () {
|
||||
return; // comment
|
||||
}());
|
||||
})();
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
x | y ^ z;
|
||||
x | (y ^ z);
|
||||
x | y ^ z;
|
||||
(x | y) ^ z;
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
1.1.valueOf();
|
||||
(1e+300).valueOf();
|
||||
1e+300.valueOf();
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
for (var i = (1 in []) in []);
|
||||
for (var i = 1 in [] in []);
|
||||
for (var i = 1 in ([] in []));
|
||||
for (var i = (10 * 10 in []) in []);
|
||||
for (var i = (10 + 10 in []) in []);
|
||||
for (var i = 10 + (10 in []) in []);
|
||||
for (var i = 10 + 10 in [] in []);
|
||||
for (var i = 10 + 10 in ([] in []));
|
||||
for (var i = (1 in []);;);
|
||||
for ((1 in []);;);
|
||||
for (1 * (1 in []);;);
|
||||
for (1 * (1 + 1 in []);;);
|
||||
for (1 * ((1 + 1) in []);;);
|
||||
for (1 * (1 + 1 in []);;);
|
||||
for (1 * (1 + (1 in []));;);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
new (a().b)();
|
||||
new a().b();
|
||||
new (a()).b();
|
||||
new (a());
|
||||
new new a(a);
|
||||
new (new a)(a);
|
||||
new (a())();
|
||||
new new a(a)();
|
||||
new (new a())(a);
|
||||
(new a()).test;
|
||||
(new a().test);
|
||||
(new (a().test));
|
||||
(new (a().test)());
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
new (a().b)();
|
||||
new a().b();
|
||||
new (a()).b();
|
||||
new (a().b)();
|
||||
new (a())();
|
||||
new new a(a)();
|
||||
new (new a())(a);
|
||||
(new a()).test;
|
||||
(new a().test);
|
||||
(new (a().test)());
|
||||
new new a()(a);
|
||||
new a().test;
|
||||
new a().test;
|
||||
new (a().test)();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var fact5 = function fact(n) {
|
||||
var fact5 = (function fact(n) {
|
||||
if (n <= 1) return 1;
|
||||
return n * fact(n - 1);
|
||||
}(5);
|
||||
})(5);
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
(foo());
|
||||
(5 * 6);
|
||||
@@ -1,2 +0,0 @@
|
||||
(foo());
|
||||
(5 * 6);
|
||||
@@ -1,3 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
(Object.assign({ x: x }, y, { a: a }, b, { c: c }));
|
||||
Object.assign({ x: x }, y, { a: a }, b, { c: c });
|
||||
|
||||
Reference in New Issue
Block a user