Revert "Parenthesized expressions (#8025)"

This reverts commit dd8b700a2c4c975584c7b2ea43023aa275c16167.
This commit is contained in:
Justin Ridgewell 2019-02-23 04:48:05 -05:00 committed by Nicolò Ribaudo
parent 9f3457797f
commit fc1ea7f496
43 changed files with 65 additions and 1186 deletions

View File

@ -1,12 +0,0 @@
// One
(1);
/* Two */
(2);
(
// Three
3
);
(/* Four */ 4);

View File

@ -1,3 +0,0 @@
{
"parserOpts": {"createParenthesizedExpressions": true}
}

View File

@ -1,10 +0,0 @@
// One
(1);
/* Two */
(2);
( // Three
3);
(
/* Four */
4);

View File

@ -492,7 +492,6 @@ suites.forEach(function(testSuite) {
strictMode: false,
sourceType: "module",
sourceMaps: !!task.sourceMap,
...task.options.parserOpts,
});
const options = {
sourceFileName: path.relative(__dirname, actual.loc),

View File

@ -78,7 +78,6 @@ These are the core @babel/parser (babylon) AST node types.
- [CallExpression](#callexpression)
- [NewExpression](#newexpression)
- [SequenceExpression](#sequenceexpression)
- [ParenthesizedExpression](#parenthesizedexpression)
- [DoExpression](#doexpression)
- [Template Literals](#template-literals)
- [TemplateLiteral](#templateliteral)
@ -937,17 +936,6 @@ interface SequenceExpression <: Expression {
A sequence expression, i.e., a comma-separated sequence of expressions.
## ParenthesizedExpression
```js
interface ParenthesizedExpression <: Expression {
type "ParenthesizedExpression";
expression: Expression;
}
```
An expression wrapped by parentheses.
## DoExpression
```js

View File

@ -19,7 +19,6 @@ export type Options = {
strictMode: ?boolean,
ranges: boolean,
tokens: boolean,
createParenthesizedExpressions: boolean,
};
export const defaultOptions: Options = {
@ -56,9 +55,6 @@ export const defaultOptions: Options = {
ranges: false,
// Adds all parsed tokens to a `tokens` property on the `File` node
tokens: false,
// Whether to create ParenthesizedExpression AST nodes (if false
// the parser sets extra.parenthesized on the expression nodes instead).
createParenthesizedExpressions: false,
};
// Interpret and default an options object

View File

@ -185,28 +185,17 @@ export default class ExpressionParser extends LValParser {
let patternErrorMsg;
let elementName;
const unwrap = node => {
return node.type === "ParenthesizedExpression"
? unwrap(node.expression)
: node;
};
const maybePattern = unwrap(left);
if (maybePattern.type === "ObjectPattern") {
if (left.type === "ObjectPattern") {
patternErrorMsg = "`({a}) = 0` use `({a} = 0)`";
elementName = "property";
} else if (maybePattern.type === "ArrayPattern") {
} else if (left.type === "ArrayPattern") {
patternErrorMsg = "`([a]) = 0` use `([a] = 0)`";
elementName = "element";
}
if (
patternErrorMsg &&
((left.extra && left.extra.parenthesized) ||
left.type === "ParenthesizedExpression")
) {
if (patternErrorMsg && left.extra && left.extra.parenthesized) {
this.raise(
maybePattern.start,
left.start,
`You're trying to assign to a parenthesized expression, eg. instead of ${patternErrorMsg}`,
);
}
@ -320,8 +309,7 @@ export default class ExpressionParser extends LValParser {
if (
operator === "**" &&
left.type === "UnaryExpression" &&
(this.options.createParenthesizedExpressions ||
!(left.extra && left.extra.parenthesized))
!(left.extra && left.extra.parenthesized)
) {
this.raise(
left.argument.start,
@ -1167,6 +1155,13 @@ export default class ExpressionParser extends LValParser {
return this.finishNode(node, type);
}
parseParenExpression(): N.Expression {
this.expect(tt.parenL);
const val = this.parseExpression();
this.expect(tt.parenR);
return val;
}
parseParenAndDistinguishExpression(canBeArrow: boolean): N.Expression {
const startPos = this.state.start;
const startLoc = this.state.startLoc;
@ -1277,16 +1272,10 @@ export default class ExpressionParser extends LValParser {
val = exprList[0];
}
if (!this.options.createParenthesizedExpressions) {
this.addExtra(val, "parenthesized", true);
this.addExtra(val, "parenStart", startPos);
return val;
}
this.addExtra(val, "parenthesized", true);
this.addExtra(val, "parenStart", startPos);
const parenExpression = this.startNodeAt(startPos, startLoc);
parenExpression.expression = val;
this.finishNode(parenExpression, "ParenthesizedExpression");
return parenExpression;
return val;
}
shouldParseArrow(): boolean {

View File

@ -92,14 +92,6 @@ export default class LValParser extends NodeUtils {
}
break;
case "ParenthesizedExpression":
node.expression = this.toAssignable(
node.expression,
isBinding,
contextDescription,
);
break;
case "MemberExpression":
if (!isBinding) break;
@ -415,15 +407,6 @@ export default class LValParser extends NodeUtils {
this.checkLVal(expr.argument, isBinding, checkClashes, "rest element");
break;
case "ParenthesizedExpression":
this.checkLVal(
expr.expression,
isBinding,
checkClashes,
"parenthesized expression",
);
break;
default: {
const message =
(isBinding

View File

@ -426,13 +426,6 @@ export default class StatementParser extends ExpressionParser {
return this.finishNode(node, "DebuggerStatement");
}
parseHeaderExpression(): N.Expression {
this.expect(tt.parenL);
const val = this.parseExpression();
this.expect(tt.parenR);
return val;
}
parseDoStatement(node: N.DoWhileStatement): N.DoWhileStatement {
this.next();
this.state.labels.push(loopLabel);
@ -449,7 +442,7 @@ export default class StatementParser extends ExpressionParser {
this.state.labels.pop();
this.expect(tt._while);
node.test = this.parseHeaderExpression();
node.test = this.parseParenExpression();
this.eat(tt.semi);
return this.finishNode(node, "DoWhileStatement");
}
@ -538,7 +531,7 @@ export default class StatementParser extends ExpressionParser {
parseIfStatement(node: N.IfStatement): N.IfStatement {
this.next();
node.test = this.parseHeaderExpression();
node.test = this.parseParenExpression();
node.consequent = this.parseStatement("if");
node.alternate = this.eat(tt._else) ? this.parseStatement("if") : null;
return this.finishNode(node, "IfStatement");
@ -567,7 +560,7 @@ export default class StatementParser extends ExpressionParser {
parseSwitchStatement(node: N.SwitchStatement): N.SwitchStatement {
this.next();
node.discriminant = this.parseHeaderExpression();
node.discriminant = this.parseParenExpression();
const cases = (node.cases = []);
this.expect(tt.braceL);
this.state.labels.push(switchLabel);
@ -676,7 +669,7 @@ export default class StatementParser extends ExpressionParser {
parseWhileStatement(node: N.WhileStatement): N.WhileStatement {
this.next();
node.test = this.parseHeaderExpression();
node.test = this.parseParenExpression();
this.state.labels.push(loopLabel);
node.body =
@ -698,7 +691,7 @@ export default class StatementParser extends ExpressionParser {
this.raise(this.state.start, "'with' in strict mode");
}
this.next();
node.object = this.parseHeaderExpression();
node.object = this.parseParenExpression();
node.body =
// For the smartPipelines plugin:

View File

@ -566,11 +566,6 @@ export type SequenceExpression = NodeBase & {
expressions: $ReadOnlyArray<Expression>,
};
export type ParenthesizedExpression = NodeBase & {
type: "ParenthesizedExpression",
expression: Expression,
};
// Pipelines
export type PipelineBody = NodeBase & {

View File

@ -1,12 +0,0 @@
// One
(1);
/* Two */
(2);
(
// Three
3
);
(/* Four */ 4);

View File

@ -1,3 +0,0 @@
{
"createParenthesizedExpressions": true
}

View File

@ -1,391 +0,0 @@
{
"type": "File",
"start": 0,
"end": 65,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 12,
"column": 15
}
},
"program": {
"type": "Program",
"start": 0,
"end": 65,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 12,
"column": 15
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start": 7,
"end": 11,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 4
}
},
"expression": {
"type": "ParenthesizedExpression",
"start": 7,
"end": 10,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 3
}
},
"expression": {
"type": "NumericLiteral",
"start": 8,
"end": 9,
"loc": {
"start": {
"line": 2,
"column": 1
},
"end": {
"line": 2,
"column": 2
}
},
"extra": {
"rawValue": 1,
"raw": "1"
},
"value": 1
}
},
"leadingComments": [
{
"type": "CommentLine",
"value": " One",
"start": 0,
"end": 6,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 6
}
}
}
],
"trailingComments": [
{
"type": "CommentBlock",
"value": " Two ",
"start": 13,
"end": 22,
"loc": {
"start": {
"line": 4,
"column": 0
},
"end": {
"line": 4,
"column": 9
}
}
}
]
},
{
"type": "ExpressionStatement",
"start": 23,
"end": 27,
"loc": {
"start": {
"line": 5,
"column": 0
},
"end": {
"line": 5,
"column": 4
}
},
"expression": {
"type": "ParenthesizedExpression",
"start": 23,
"end": 26,
"loc": {
"start": {
"line": 5,
"column": 0
},
"end": {
"line": 5,
"column": 3
}
},
"expression": {
"type": "NumericLiteral",
"start": 24,
"end": 25,
"loc": {
"start": {
"line": 5,
"column": 1
},
"end": {
"line": 5,
"column": 2
}
},
"extra": {
"rawValue": 2,
"raw": "2"
},
"value": 2
}
},
"leadingComments": [
{
"type": "CommentBlock",
"value": " Two ",
"start": 13,
"end": 22,
"loc": {
"start": {
"line": 4,
"column": 0
},
"end": {
"line": 4,
"column": 9
}
}
}
]
},
{
"type": "ExpressionStatement",
"start": 29,
"end": 48,
"loc": {
"start": {
"line": 7,
"column": 0
},
"end": {
"line": 10,
"column": 2
}
},
"expression": {
"type": "ParenthesizedExpression",
"start": 29,
"end": 47,
"loc": {
"start": {
"line": 7,
"column": 0
},
"end": {
"line": 10,
"column": 1
}
},
"expression": {
"type": "NumericLiteral",
"start": 44,
"end": 45,
"loc": {
"start": {
"line": 9,
"column": 2
},
"end": {
"line": 9,
"column": 3
}
},
"extra": {
"rawValue": 3,
"raw": "3"
},
"value": 3,
"leadingComments": [
{
"type": "CommentLine",
"value": " Three",
"start": 33,
"end": 41,
"loc": {
"start": {
"line": 8,
"column": 2
},
"end": {
"line": 8,
"column": 10
}
}
}
]
}
}
},
{
"type": "ExpressionStatement",
"start": 50,
"end": 65,
"loc": {
"start": {
"line": 12,
"column": 0
},
"end": {
"line": 12,
"column": 15
}
},
"expression": {
"type": "ParenthesizedExpression",
"start": 50,
"end": 64,
"loc": {
"start": {
"line": 12,
"column": 0
},
"end": {
"line": 12,
"column": 14
}
},
"expression": {
"type": "NumericLiteral",
"start": 62,
"end": 63,
"loc": {
"start": {
"line": 12,
"column": 12
},
"end": {
"line": 12,
"column": 13
}
},
"extra": {
"rawValue": 4,
"raw": "4"
},
"value": 4,
"leadingComments": [
{
"type": "CommentBlock",
"value": " Four ",
"start": 51,
"end": 61,
"loc": {
"start": {
"line": 12,
"column": 1
},
"end": {
"line": 12,
"column": 11
}
}
}
]
}
}
}
],
"directives": []
},
"comments": [
{
"type": "CommentLine",
"value": " One",
"start": 0,
"end": 6,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 6
}
}
},
{
"type": "CommentBlock",
"value": " Two ",
"start": 13,
"end": 22,
"loc": {
"start": {
"line": 4,
"column": 0
},
"end": {
"line": 4,
"column": 9
}
}
},
{
"type": "CommentLine",
"value": " Three",
"start": 33,
"end": 41,
"loc": {
"start": {
"line": 8,
"column": 2
},
"end": {
"line": 8,
"column": 10
}
}
},
{
"type": "CommentBlock",
"value": " Four ",
"start": 51,
"end": 61,
"loc": {
"start": {
"line": 12,
"column": 1
},
"end": {
"line": 12,
"column": 11
}
}
}
]
}

View File

@ -1 +0,0 @@
({x}) = {x: 1};

View File

@ -1,4 +0,0 @@
{
"createParenthesizedExpressions": true,
"throws": "You're trying to assign to a parenthesized expression, eg. instead of `({a}) = 0` use `({a} = 0)` (1:1)"
}

View File

@ -1 +0,0 @@
("hello");

View File

@ -1,3 +0,0 @@
{
"createParenthesizedExpressions": true
}

View File

@ -1,85 +0,0 @@
{
"type": "File",
"start": 0,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 10
}
},
"program": {
"type": "Program",
"start": 0,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 10
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 10
}
},
"expression": {
"type": "ParenthesizedExpression",
"start": 0,
"end": 9,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 9
}
},
"expression": {
"type": "StringLiteral",
"start": 1,
"end": 8,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 8
}
},
"extra": {
"rawValue": "hello",
"raw": "\"hello\""
},
"value": "hello"
}
}
}
],
"directives": []
}
}

View File

@ -1 +0,0 @@
([a]) = []

View File

@ -1,4 +0,0 @@
{
"createParenthesizedExpressions": true,
"throws": "You're trying to assign to a parenthesized expression, eg. instead of `([a]) = 0` use `([a] = 0)` (1:1)"
}

View File

@ -1,3 +0,0 @@
{
"createParenthesizedExpressions": true
}

View File

@ -1,104 +0,0 @@
{
"type": "File",
"start": 0,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 11
}
},
"program": {
"type": "Program",
"start": 0,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 11
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 11
}
},
"expression": {
"type": "ArrowFunctionExpression",
"start": 0,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 11
}
},
"id": null,
"generator": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 1,
"end": 4,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 4
},
"identifierName": "foo"
},
"name": "foo"
}
],
"body": {
"type": "BlockStatement",
"start": 9,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 11
}
},
"body": [],
"directives": []
}
}
}
],
"directives": []
}
}

View File

@ -1,4 +0,0 @@
var a;
(a) = {};
(a.b) = {};
(a['c']) = {};

View File

@ -1,3 +0,0 @@
{
"createParenthesizedExpressions": true
}

View File

@ -1,392 +0,0 @@
{
"type": "File",
"start": 0,
"end": 43,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 14
}
},
"program": {
"type": "Program",
"start": 0,
"end": 43,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 14
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "VariableDeclaration",
"start": 0,
"end": 6,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 6
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 4,
"end": 5,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 5
}
},
"id": {
"type": "Identifier",
"start": 4,
"end": 5,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 5
},
"identifierName": "a"
},
"name": "a"
},
"init": null
}
],
"kind": "var"
},
{
"type": "ExpressionStatement",
"start": 7,
"end": 16,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 9
}
},
"expression": {
"type": "AssignmentExpression",
"start": 7,
"end": 15,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 8
}
},
"operator": "=",
"left": {
"type": "ParenthesizedExpression",
"start": 7,
"end": 10,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 3
}
},
"expression": {
"type": "Identifier",
"start": 8,
"end": 9,
"loc": {
"start": {
"line": 2,
"column": 1
},
"end": {
"line": 2,
"column": 2
},
"identifierName": "a"
},
"name": "a"
}
},
"right": {
"type": "ObjectExpression",
"start": 13,
"end": 15,
"loc": {
"start": {
"line": 2,
"column": 6
},
"end": {
"line": 2,
"column": 8
}
},
"properties": []
}
}
},
{
"type": "ExpressionStatement",
"start": 17,
"end": 28,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 11
}
},
"expression": {
"type": "AssignmentExpression",
"start": 17,
"end": 27,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 10
}
},
"operator": "=",
"left": {
"type": "ParenthesizedExpression",
"start": 17,
"end": 22,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 5
}
},
"expression": {
"type": "MemberExpression",
"start": 18,
"end": 21,
"loc": {
"start": {
"line": 3,
"column": 1
},
"end": {
"line": 3,
"column": 4
}
},
"object": {
"type": "Identifier",
"start": 18,
"end": 19,
"loc": {
"start": {
"line": 3,
"column": 1
},
"end": {
"line": 3,
"column": 2
},
"identifierName": "a"
},
"name": "a"
},
"property": {
"type": "Identifier",
"start": 20,
"end": 21,
"loc": {
"start": {
"line": 3,
"column": 3
},
"end": {
"line": 3,
"column": 4
},
"identifierName": "b"
},
"name": "b"
},
"computed": false
}
},
"right": {
"type": "ObjectExpression",
"start": 25,
"end": 27,
"loc": {
"start": {
"line": 3,
"column": 8
},
"end": {
"line": 3,
"column": 10
}
},
"properties": []
}
}
},
{
"type": "ExpressionStatement",
"start": 29,
"end": 43,
"loc": {
"start": {
"line": 4,
"column": 0
},
"end": {
"line": 4,
"column": 14
}
},
"expression": {
"type": "AssignmentExpression",
"start": 29,
"end": 42,
"loc": {
"start": {
"line": 4,
"column": 0
},
"end": {
"line": 4,
"column": 13
}
},
"operator": "=",
"left": {
"type": "ParenthesizedExpression",
"start": 29,
"end": 37,
"loc": {
"start": {
"line": 4,
"column": 0
},
"end": {
"line": 4,
"column": 8
}
},
"expression": {
"type": "MemberExpression",
"start": 30,
"end": 36,
"loc": {
"start": {
"line": 4,
"column": 1
},
"end": {
"line": 4,
"column": 7
}
},
"object": {
"type": "Identifier",
"start": 30,
"end": 31,
"loc": {
"start": {
"line": 4,
"column": 1
},
"end": {
"line": 4,
"column": 2
},
"identifierName": "a"
},
"name": "a"
},
"property": {
"type": "StringLiteral",
"start": 32,
"end": 35,
"loc": {
"start": {
"line": 4,
"column": 3
},
"end": {
"line": 4,
"column": 6
}
},
"extra": {
"rawValue": "c",
"raw": "'c'"
},
"value": "c"
},
"computed": true
}
},
"right": {
"type": "ObjectExpression",
"start": 40,
"end": 42,
"loc": {
"start": {
"line": 4,
"column": 11
},
"end": {
"line": 4,
"column": 13
}
},
"properties": []
}
}
}
],
"directives": []
}
}

View File

@ -1 +0,0 @@
([a.a]) => 42

View File

@ -1,4 +0,0 @@
{
"createParenthesizedExpressions": true,
"throws": "Invalid left-hand side in arrow function parameters (1:2)"
}

View File

@ -1,4 +0,0 @@
{
"createParenthesizedExpressions": true,
"throws": "Illegal expression. Wrap left hand side or entire exponentiation in parentheses. (1:1)"
}

View File

@ -1,4 +0,0 @@
{
"createParenthesizedExpressions": true,
"throws": "Illegal expression. Wrap left hand side or entire exponentiation in parentheses. (1:2)"
}

View File

@ -124,4 +124,4 @@
],
"directives": []
}
}
}

View File

@ -160,4 +160,4 @@
],
"directives": []
}
}
}

View File

@ -156,4 +156,4 @@
],
"directives": []
}
}
}

View File

@ -124,4 +124,4 @@
],
"directives": []
}
}
}

View File

@ -78,14 +78,6 @@ export interface ParserOptions {
* Adds all parsed tokens to a tokens property on the File node.
*/
tokens?: boolean;
/**
* By default, the parser adds information about parentheses by setting
* `extra.parenthesized` to `true` as needed.
* When this option is `true` the parser creates `ParenthesizedExpression`
* AST nodes instead of using the `extra` property.
*/
createParenthesizedExpressions?: boolean;
}
export type ParserPlugin =

View File

@ -102,10 +102,6 @@ export function SequenceExpression() {
.getTypeAnnotation();
}
export function ParenthesizedExpression() {
return this.get("expression").getTypeAnnotation();
}
export function AssignmentExpression() {
return this.get("right").getTypeAnnotation();
}

View File

@ -162,12 +162,6 @@ export function assertSequenceExpression(
): void {
assert("SequenceExpression", node, opts);
}
export function assertParenthesizedExpression(
node: Object,
opts?: Object = {},
): void {
assert("ParenthesizedExpression", node, opts);
}
export function assertSwitchCase(node: Object, opts?: Object = {}): void {
assert("SwitchCase", node, opts);
}
@ -660,6 +654,12 @@ export function assertJSXClosingFragment(
export function assertNoop(node: Object, opts?: Object = {}): void {
assert("Noop", node, opts);
}
export function assertParenthesizedExpression(
node: Object,
opts?: Object = {},
): void {
assert("ParenthesizedExpression", node, opts);
}
export function assertAwaitExpression(node: Object, opts?: Object = {}): void {
assert("AwaitExpression", node, opts);
}

View File

@ -161,10 +161,6 @@ export function SequenceExpression(...args: Array<any>): Object {
return builder("SequenceExpression", ...args);
}
export { SequenceExpression as sequenceExpression };
export function ParenthesizedExpression(...args: Array<any>): Object {
return builder("ParenthesizedExpression", ...args);
}
export { ParenthesizedExpression as parenthesizedExpression };
export function SwitchCase(...args: Array<any>): Object {
return builder("SwitchCase", ...args);
}
@ -596,6 +592,10 @@ export function Noop(...args: Array<any>): Object {
return builder("Noop", ...args);
}
export { Noop as noop };
export function ParenthesizedExpression(...args: Array<any>): Object {
return builder("ParenthesizedExpression", ...args);
}
export { ParenthesizedExpression as parenthesizedExpression };
export function AwaitExpression(...args: Array<any>): Object {
return builder("AwaitExpression", ...args);
}

View File

@ -731,16 +731,6 @@ defineType("SequenceExpression", {
aliases: ["Expression"],
});
defineType("ParenthesizedExpression", {
visitor: ["expression"],
aliases: ["Expression", "ExpressionWrapper"],
fields: {
expression: {
validate: assertNodeType("Expression"),
},
},
});
defineType("SwitchCase", {
visitor: ["test", "consequent"],
fields: {

View File

@ -1,6 +1,16 @@
// @flow
import defineType from "./utils";
import defineType, { assertNodeType } from "./utils";
defineType("Noop", {
visitor: [],
});
defineType("ParenthesizedExpression", {
visitor: ["expression"],
aliases: ["Expression", "ExpressionWrapper"],
fields: {
expression: {
validate: assertNodeType("Expression"),
},
},
});

View File

@ -551,23 +551,6 @@ export function isSequenceExpression(node: ?Object, opts?: Object): boolean {
return false;
}
export function isParenthesizedExpression(
node: ?Object,
opts?: Object,
): boolean {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "ParenthesizedExpression") {
if (typeof opts === "undefined") {
return true;
} else {
return shallowEqual(node, opts);
}
}
return false;
}
export function isSwitchCase(node: ?Object, opts?: Object): boolean {
if (!node) return false;
@ -2093,6 +2076,23 @@ export function isNoop(node: ?Object, opts?: Object): boolean {
return false;
}
export function isParenthesizedExpression(
node: ?Object,
opts?: Object,
): boolean {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "ParenthesizedExpression") {
if (typeof opts === "undefined") {
return true;
} else {
return shallowEqual(node, opts);
}
}
return false;
}
export function isAwaitExpression(node: ?Object, opts?: Object): boolean {
if (!node) return false;
@ -3242,7 +3242,6 @@ export function isExpression(node: ?Object, opts?: Object): boolean {
"NewExpression" === nodeType ||
"ObjectExpression" === nodeType ||
"SequenceExpression" === nodeType ||
"ParenthesizedExpression" === nodeType ||
"ThisExpression" === nodeType ||
"UnaryExpression" === nodeType ||
"UpdateExpression" === nodeType ||
@ -3256,6 +3255,7 @@ export function isExpression(node: ?Object, opts?: Object): boolean {
"TypeCastExpression" === nodeType ||
"JSXElement" === nodeType ||
"JSXFragment" === nodeType ||
"ParenthesizedExpression" === nodeType ||
"AwaitExpression" === nodeType ||
"BindExpression" === nodeType ||
"OptionalMemberExpression" === nodeType ||
@ -3545,8 +3545,8 @@ export function isExpressionWrapper(node: ?Object, opts?: Object): boolean {
if (
nodeType === "ExpressionWrapper" ||
"ExpressionStatement" === nodeType ||
"ParenthesizedExpression" === nodeType ||
"TypeCastExpression" === nodeType
"TypeCastExpression" === nodeType ||
"ParenthesizedExpression" === nodeType
) {
if (typeof opts === "undefined") {
return true;