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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user