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
Justin Ridgewell
parent
417e72ebfd
commit
dd8b700a2c
@@ -426,6 +426,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);
|
||||
@@ -442,7 +449,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");
|
||||
}
|
||||
@@ -531,7 +538,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");
|
||||
@@ -560,7 +567,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);
|
||||
@@ -669,7 +676,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 =
|
||||
@@ -691,7 +698,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