Parenthesized expressions (#8025)
* Add parser createParenthesizedExpressions option … When set to `true` we create `ParenthesizedExpression` nodes instead of setting `extra.parenthesized`. * Also update babel-parser.d.ts
This commit is contained in:
committed by
Nicolò Ribaudo
parent
28c71e88e2
commit
fba5655a44
@@ -453,6 +453,13 @@ 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);
|
||||
@@ -469,7 +476,7 @@ export default class StatementParser extends ExpressionParser {
|
||||
this.state.labels.pop();
|
||||
|
||||
this.expect(tt._while);
|
||||
node.test = this.parseParenExpression();
|
||||
node.test = this.parseHeaderExpression();
|
||||
this.eat(tt.semi);
|
||||
return this.finishNode(node, "DoWhileStatement");
|
||||
}
|
||||
@@ -567,7 +574,7 @@ export default class StatementParser extends ExpressionParser {
|
||||
|
||||
parseIfStatement(node: N.IfStatement): N.IfStatement {
|
||||
this.next();
|
||||
node.test = this.parseParenExpression();
|
||||
node.test = this.parseHeaderExpression();
|
||||
node.consequent = this.parseStatement("if");
|
||||
node.alternate = this.eat(tt._else) ? this.parseStatement("if") : null;
|
||||
return this.finishNode(node, "IfStatement");
|
||||
@@ -596,7 +603,7 @@ export default class StatementParser extends ExpressionParser {
|
||||
|
||||
parseSwitchStatement(node: N.SwitchStatement): N.SwitchStatement {
|
||||
this.next();
|
||||
node.discriminant = this.parseParenExpression();
|
||||
node.discriminant = this.parseHeaderExpression();
|
||||
const cases = (node.cases = []);
|
||||
this.expect(tt.braceL);
|
||||
this.state.labels.push(switchLabel);
|
||||
@@ -715,7 +722,7 @@ export default class StatementParser extends ExpressionParser {
|
||||
|
||||
parseWhileStatement(node: N.WhileStatement): N.WhileStatement {
|
||||
this.next();
|
||||
node.test = this.parseParenExpression();
|
||||
node.test = this.parseHeaderExpression();
|
||||
this.state.labels.push(loopLabel);
|
||||
|
||||
node.body =
|
||||
@@ -737,7 +744,7 @@ export default class StatementParser extends ExpressionParser {
|
||||
this.raise(this.state.start, "'with' in strict mode");
|
||||
}
|
||||
this.next();
|
||||
node.object = this.parseParenExpression();
|
||||
node.object = this.parseHeaderExpression();
|
||||
|
||||
node.body =
|
||||
// For the smartPipelines plugin:
|
||||
|
||||
Reference in New Issue
Block a user