Created
October 26, 2016 13:56
-
-
Save jacobp100/d6ebdaf7eca93ca867c8fbf8c11b5495 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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