Add option for representing parenthesized expressions in the AST.
This commit is contained in:
committed by
Marijn Haverbeke
parent
e9c7209f8b
commit
d525c45644
@@ -15391,3 +15391,25 @@ test('function normal(x, y = 10) {}', {
|
||||
}, {ecmaVersion: 6});
|
||||
|
||||
test("'use strict'; function f([x,,z]) {}", {}, {ecmaVersion: 6});
|
||||
|
||||
// test preserveParens option with arrow functions
|
||||
test("() => 42", {
|
||||
type: "Program",
|
||||
body: [{
|
||||
type: "ExpressionStatement",
|
||||
expression: {
|
||||
type: "ArrowFunctionExpression"
|
||||
}
|
||||
}]
|
||||
}, {ecmaVersion: 6, preserveParens: true});
|
||||
|
||||
// test preserveParens with generators
|
||||
test("(for (x of array) for (y of array2) if (x === test) x)", {
|
||||
type: "Program",
|
||||
body: [{
|
||||
type: "ExpressionStatement",
|
||||
expression: {
|
||||
type: "ComprehensionExpression"
|
||||
}
|
||||
}]
|
||||
}, {ecmaVersion: 6, preserveParens: true});
|
||||
|
||||
117
test/tests.js
117
test/tests.js
@@ -234,6 +234,123 @@ test("(1 + 2 ) * 3", {
|
||||
}
|
||||
});
|
||||
|
||||
test("(1 + 2 ) * 3", {
|
||||
type: "Program",
|
||||
body: [
|
||||
{
|
||||
type: "ExpressionStatement",
|
||||
expression: {
|
||||
type: "BinaryExpression",
|
||||
left: {
|
||||
type: "ParenthesizedExpression",
|
||||
expression: {
|
||||
type: "BinaryExpression",
|
||||
left: {
|
||||
type: "Literal",
|
||||
value: 1,
|
||||
loc: {
|
||||
start: {
|
||||
line: 1,
|
||||
column: 1
|
||||
},
|
||||
end: {
|
||||
line: 1,
|
||||
column: 2
|
||||
}
|
||||
}
|
||||
},
|
||||
operator: "+",
|
||||
right: {
|
||||
type: "Literal",
|
||||
value: 2,
|
||||
loc: {
|
||||
start: {
|
||||
line: 1,
|
||||
column: 5
|
||||
},
|
||||
end: {
|
||||
line: 1,
|
||||
column: 6
|
||||
}
|
||||
}
|
||||
},
|
||||
loc: {
|
||||
start: {
|
||||
line: 1,
|
||||
column: 1
|
||||
},
|
||||
end: {
|
||||
line: 1,
|
||||
column: 6
|
||||
}
|
||||
}
|
||||
},
|
||||
loc: {
|
||||
start: {
|
||||
line: 1,
|
||||
column: 0
|
||||
},
|
||||
end: {
|
||||
line: 1,
|
||||
column: 8
|
||||
}
|
||||
}
|
||||
},
|
||||
operator: "*",
|
||||
right: {
|
||||
type: "Literal",
|
||||
value: 3,
|
||||
loc: {
|
||||
start: {
|
||||
line: 1,
|
||||
column: 11
|
||||
},
|
||||
end: {
|
||||
line: 1,
|
||||
column: 12
|
||||
}
|
||||
}
|
||||
},
|
||||
loc: {
|
||||
start: {
|
||||
line: 1,
|
||||
column: 0
|
||||
},
|
||||
end: {
|
||||
line: 1,
|
||||
column: 12
|
||||
}
|
||||
}
|
||||
},
|
||||
loc: {
|
||||
start: {
|
||||
line: 1,
|
||||
column: 0
|
||||
},
|
||||
end: {
|
||||
line: 1,
|
||||
column: 12
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
loc: {
|
||||
start: {
|
||||
line: 1,
|
||||
column: 0
|
||||
},
|
||||
end: {
|
||||
line: 1,
|
||||
column: 12
|
||||
}
|
||||
}
|
||||
}, {
|
||||
locations: true,
|
||||
preserveParens: true
|
||||
});
|
||||
|
||||
test("(x) = 23", {}, { preserveParens: true });
|
||||
|
||||
test("x = []", {
|
||||
type: "Program",
|
||||
body: [
|
||||
|
||||
Reference in New Issue
Block a user