Merge branch 'fix-flow-optional-type' of https://github.com/danez/babylon into danez-fix-flow-optional-type

# Conflicts:
#	src/plugins/flow.js
This commit is contained in:
Sebastian McKenzie
2016-06-22 12:52:42 +01:00
8 changed files with 408 additions and 4 deletions

View File

@@ -726,9 +726,29 @@ export default function (instance) {
};
});
instance.extend("parseConditional", function (inner) {
return function (expr, noIn, startPos, startLoc, refNeedsArrowPos) {
const state = this.state.clone();
try {
return inner.call(this, expr, noIn, startPos, startLoc);
} catch (err) {
if (refNeedsArrowPos && err instanceof SyntaxError) {
this.state = state;
refNeedsArrowPos.start = this.state.start;
return expr;
} else {
throw err;
}
}
};
});
instance.extend("parseParenItem", function (inner) {
return function (node, startLoc, startPos) {
node = inner.call(this, node, startLoc, startPos);
if (this.eat(tt.question)) {
node.optional = true;
}
if (this.match(tt.colon)) {
let typeCastNode = this.startNodeAt(startLoc, startPos);