Skip to content

Commit

Permalink
refactor: add parseDo method
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Jul 23, 2020
1 parent c21bee5 commit 10209b7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
21 changes: 13 additions & 8 deletions packages/babel-parser/src/parser/expression.js
Expand Up @@ -1023,14 +1023,7 @@ export default class ExpressionParser extends LValParser {
}

case tt._do: {
this.expectPlugin("doExpressions");
const node = this.startNode();
this.next();
const oldLabels = this.state.labels;
this.state.labels = [];
node.body = this.parseBlock();
this.state.labels = oldLabels;
return this.finishNode(node, "DoExpression");
return this.parseDo();
}

case tt.regexp: {
Expand Down Expand Up @@ -1237,6 +1230,18 @@ export default class ExpressionParser extends LValParser {
return node;
}

// https://github.com/tc39/proposal-do-expressions
parseDo(): N.DoExpression {
this.expectPlugin("doExpressions");
const node = this.startNode();
this.next(); // eat `do`
const oldLabels = this.state.labels;
this.state.labels = [];
node.body = this.parseBlock();
this.state.labels = oldLabels;
return this.finishNode(node, "DoExpression");
}

// Parse the `super` keyword
parseSuper(): N.Super {
const node = this.startNode();
Expand Down
5 changes: 5 additions & 0 deletions packages/babel-parser/src/types.js
Expand Up @@ -389,6 +389,11 @@ export type ArrayExpression = NodeBase & {
elements: $ReadOnlyArray<?(Expression | SpreadElement)>,
};

export type DoExpression = NodeBase & {
type: "DoExpression",
body: ?BlockStatement,
};

export type TupleExpression = NodeBase & {
type: "TupleExpression",
elements: $ReadOnlyArray<?(Expression | SpreadElement)>,
Expand Down

0 comments on commit 10209b7

Please sign in to comment.