Skip to content

Instantly share code, notes, and snippets.

@jacobp100
Created October 26, 2016 13:56
Show Gist options
  • Save jacobp100/d6ebdaf7eca93ca867c8fbf8c11b5495 to your computer and use it in GitHub Desktop.
Save jacobp100/d6ebdaf7eca93ca867c8fbf8c11b5495 to your computer and use it in GitHub Desktop.
const plugin = (instance) => {
instance.extend('parseParenFreeIfStatement', () => function parseParenFreeIfStatement(node) {
this.next();
node.test = this.parseExpression();
node.consequent = this.parseBlock(false);
node.alternate = this.eat(tt._else) ? this.parseParenFreeElseStatement() : null;
return this.finishNode(node, 'IfStatement');
});
instance.extend('parseParenFreeElseStatement', () => function parseParenFreeElseStatement() {
const node = this.startNode();
return (this.match(tt._if))
? this.parseParenFreeIfStatement(node)
: this.parseBlock(false);
});
instance.extend('parseIfStatement', inner => function parseIfStatement(node) {
return (this.lookahead().type === tt.parenL)
? inner.call(this, node)
: this.parseParenFreeIfStatement(node);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment