Skip to content

Instantly share code, notes, and snippets.

@jacobp100
Last active October 26, 2016 13:50
Show Gist options
  • Save jacobp100/2a41b68fa9f7eec2afc98226496f7ed1 to your computer and use it in GitHub Desktop.
Save jacobp100/2a41b68fa9f7eec2afc98226496f7ed1 to your computer and use it in GitHub Desktop.
const plugin = (instance) => {
instance.extend('parseIfStatement', inner => function (node) {
this.next();
const isParenFree = this.match(tokenTypes.parenL);
node.test = isParenFree
? this.parseExpression()
: this.parseParenExpression();
node.consequent = isParenFree
? this.parseBlock(false)
: this.parseStatement(false);
node.alternate = this.eat(tt._else) ? this.parseStatement(false) : null;
return this.finishNode(node, "IfStatement");
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment