more estree updates - finish flow parsing
This commit is contained in:
@@ -460,27 +460,19 @@ pp.flow_parsePrimaryType = function () {
|
||||
case tt.parenL:
|
||||
this.next();
|
||||
|
||||
var tmpId;
|
||||
|
||||
// Check to see if this is actually a grouped type
|
||||
if (this.type !== tt.parenR && this.type !== tt.ellipsis) {
|
||||
if (this.type === tt.name) {
|
||||
//raise(tokStart, "Grouped types are currently the only flow feature not supported, request it?");
|
||||
//tmpId = identToTypeAnnotation(start, node, parseIdent());
|
||||
//next();
|
||||
//isGroupedType = this.type !== tt.question && this.type !== tt.colon;
|
||||
var token = this.lookahead().type;
|
||||
isGroupedType = token !== tt.question && token !== tt.colon;
|
||||
} else {
|
||||
isGroupedType = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isGroupedType) {
|
||||
if (tmpId && tt.parenR) {
|
||||
type = tmpId;
|
||||
} else {
|
||||
type = this.flow_parseType();
|
||||
this.expect(tt.parenR);
|
||||
}
|
||||
type = this.flow_parseType();
|
||||
this.expect(tt.parenR);
|
||||
|
||||
// If we see a => next then someone was probably confused about
|
||||
// function types, so we can provide a better error message
|
||||
@@ -627,6 +619,19 @@ acorn.plugins.flow = function (instance) {
|
||||
};
|
||||
});
|
||||
|
||||
instance.extend("parseStatement", function (inner) {
|
||||
return function(declaration, topLevel) {
|
||||
// strict mode handling of `interface` since it's a reserved word
|
||||
if (this.strict && this.type === tt.name && this.value === "interface") {
|
||||
var node = this.startNode();
|
||||
this.next();
|
||||
return this.flow_parseInterface(node);
|
||||
} else {
|
||||
return inner.call(this, declaration, topLevel);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
instance.extend("parseExpressionStatement", function (inner) {
|
||||
return function (node, expr) {
|
||||
if (expr.type === "Identifier") {
|
||||
@@ -647,6 +652,12 @@ acorn.plugins.flow = function (instance) {
|
||||
};
|
||||
});
|
||||
|
||||
instance.extend("shouldParseExportDeclaration", function (inner) {
|
||||
return function () {
|
||||
return this.isContextual("type") || inner.call(this);
|
||||
};
|
||||
});
|
||||
|
||||
instance.extend("parseParenItem", function (inner) {
|
||||
return function (node, start) {
|
||||
if (this.type === tt.colon) {
|
||||
@@ -669,7 +680,7 @@ acorn.plugins.flow = function (instance) {
|
||||
};
|
||||
});
|
||||
|
||||
instance.extend("readToken", function(inner) {
|
||||
instance.extend("readToken", function (inner) {
|
||||
return function(code) {
|
||||
if (this.inType && (code === 62 || code === 60)) {
|
||||
return this.finishOp(tt.relational, 1);
|
||||
@@ -679,6 +690,12 @@ acorn.plugins.flow = function (instance) {
|
||||
};
|
||||
});
|
||||
|
||||
instance.extend("jsx_readToken", function (inner) {
|
||||
return function () {
|
||||
if (!this.inType) return inner.call(this);
|
||||
};
|
||||
});
|
||||
|
||||
instance.extend("parseParenArrowList", function (inner) {
|
||||
return function (start, exprList, isAsync) {
|
||||
for (var i = 0; i < exprList.length; i++) {
|
||||
|
||||
@@ -614,27 +614,25 @@ acorn.plugins.jsx = function(instance) {
|
||||
|
||||
instance.extend("readToken", function(inner) {
|
||||
return function(code) {
|
||||
if (!this.inType) {
|
||||
var context = this.curContext();
|
||||
var context = this.curContext();
|
||||
|
||||
if (context === tc.j_expr) return this.jsx_readToken();
|
||||
if (context === tc.j_expr) return this.jsx_readToken();
|
||||
|
||||
if (context === tc.j_oTag || context === tc.j_cTag) {
|
||||
if (acorn.isIdentifierStart(code)) return this.jsx_readWord();
|
||||
if (context === tc.j_oTag || context === tc.j_cTag) {
|
||||
if (acorn.isIdentifierStart(code)) return this.jsx_readWord();
|
||||
|
||||
if (code == 62) {
|
||||
++this.pos;
|
||||
return this.finishToken(tt.jsxTagEnd);
|
||||
}
|
||||
|
||||
if ((code === 34 || code === 39) && context == tc.j_oTag)
|
||||
return this.jsx_readString(code);
|
||||
}
|
||||
|
||||
if (code === 60 && this.exprAllowed) {
|
||||
if (code == 62) {
|
||||
++this.pos;
|
||||
return this.finishToken(tt.jsxTagStart);
|
||||
return this.finishToken(tt.jsxTagEnd);
|
||||
}
|
||||
|
||||
if ((code === 34 || code === 39) && context == tc.j_oTag)
|
||||
return this.jsx_readString(code);
|
||||
}
|
||||
|
||||
if (code === 60 && this.exprAllowed) {
|
||||
++this.pos;
|
||||
return this.finishToken(tt.jsxTagStart);
|
||||
}
|
||||
|
||||
return inner.call(this, code);
|
||||
|
||||
Reference in New Issue
Block a user