reimplement async function type parameters backfix - fixes #2028
This commit is contained in:
parent
0ca73d2474
commit
7f34827a72
@ -68,6 +68,7 @@ pp.parseExpression = function (noIn, refShorthandDefaultPos) {
|
|||||||
while (this.eat(tt.comma)) {
|
while (this.eat(tt.comma)) {
|
||||||
node.expressions.push(this.parseMaybeAssign(noIn, refShorthandDefaultPos));
|
node.expressions.push(this.parseMaybeAssign(noIn, refShorthandDefaultPos));
|
||||||
}
|
}
|
||||||
|
this.toReferencedList(node.expressions);
|
||||||
return this.finishNode(node, "SequenceExpression");
|
return this.finishNode(node, "SequenceExpression");
|
||||||
}
|
}
|
||||||
return expr;
|
return expr;
|
||||||
@ -89,8 +90,9 @@ pp.parseMaybeAssign = function (noIn, refShorthandDefaultPos, afterLeftParse) {
|
|||||||
failOnShorthandAssign = false;
|
failOnShorthandAssign = false;
|
||||||
}
|
}
|
||||||
let startPos = this.start, startLoc = this.startLoc;
|
let startPos = this.start, startLoc = this.startLoc;
|
||||||
if (this.type === tt.parenL || this.type === tt.name)
|
if (this.type === tt.parenL || this.type === tt.name) {
|
||||||
this.potentialArrowAt = this.start;
|
this.potentialArrowAt = this.start;
|
||||||
|
}
|
||||||
let left = this.parseMaybeConditional(noIn, refShorthandDefaultPos);
|
let left = this.parseMaybeConditional(noIn, refShorthandDefaultPos);
|
||||||
if (afterLeftParse) left = afterLeftParse.call(this, left, startPos, startLoc);
|
if (afterLeftParse) left = afterLeftParse.call(this, left, startPos, startLoc);
|
||||||
if (this.type.isAssign) {
|
if (this.type.isAssign) {
|
||||||
@ -245,6 +247,8 @@ pp.parseSubscripts = function(base, startPos, startLoc, noCalls) {
|
|||||||
|
|
||||||
if (possibleAsync && (this.type === tt.colon || this.type === tt.arrow)) {
|
if (possibleAsync && (this.type === tt.colon || this.type === tt.arrow)) {
|
||||||
base = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startPos, startLoc), node);
|
base = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startPos, startLoc), node);
|
||||||
|
} else {
|
||||||
|
this.toReferencedList(node.arguments);
|
||||||
}
|
}
|
||||||
} else if (this.type === tt.backQuote) {
|
} else if (this.type === tt.backQuote) {
|
||||||
let node = this.startNodeAt(startPos, startLoc);
|
let node = this.startNodeAt(startPos, startLoc);
|
||||||
@ -323,8 +327,9 @@ pp.parseExprAtom = function (refShorthandDefaultPos) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow))
|
if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow)) {
|
||||||
return this.parseArrowExpression(node, [id]);
|
return this.parseArrowExpression(node, [id]);
|
||||||
|
}
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
|
|
||||||
@ -339,7 +344,7 @@ pp.parseExprAtom = function (refShorthandDefaultPos) {
|
|||||||
|
|
||||||
case tt._null: case tt._true: case tt._false:
|
case tt._null: case tt._true: case tt._false:
|
||||||
node = this.startNode();
|
node = this.startNode();
|
||||||
node.value = this.type === tt._null ? null : this.type === tt._true;
|
node.rawValue = node.value = this.type === tt._null ? null : this.type === tt._true;
|
||||||
node.raw = this.type.keyword;
|
node.raw = this.type.keyword;
|
||||||
this.next();
|
this.next();
|
||||||
return this.finishNode(node, "Literal");
|
return this.finishNode(node, "Literal");
|
||||||
@ -355,6 +360,7 @@ pp.parseExprAtom = function (refShorthandDefaultPos) {
|
|||||||
return this.parseComprehension(node, false);
|
return this.parseComprehension(node, false);
|
||||||
}
|
}
|
||||||
node.elements = this.parseExprList(tt.bracketR, true, true, refShorthandDefaultPos);
|
node.elements = this.parseExprList(tt.bracketR, true, true, refShorthandDefaultPos);
|
||||||
|
this.toReferencedList(node.elements);
|
||||||
return this.finishNode(node, "ArrayExpression");
|
return this.finishNode(node, "ArrayExpression");
|
||||||
|
|
||||||
case tt.braceL:
|
case tt.braceL:
|
||||||
@ -446,12 +452,13 @@ pp.parseParenAndDistinguishExpression = function (startPos, startLoc, canBeArrow
|
|||||||
exprList.push(this.parseMaybeAssign(false, refShorthandDefaultPos, this.parseParenItem));
|
exprList.push(this.parseMaybeAssign(false, refShorthandDefaultPos, this.parseParenItem));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let innerEndPos = this.start, innerEndLoc = this.startLoc;
|
let innerEndPos = this.start;
|
||||||
|
let innerEndLoc = this.startLoc;
|
||||||
this.expect(tt.parenR);
|
this.expect(tt.parenR);
|
||||||
|
|
||||||
if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow)) {
|
if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow)) {
|
||||||
if (innerParenStart) this.unexpected(innerParenStart);
|
if (innerParenStart) this.unexpected(innerParenStart);
|
||||||
return this.parseParenArrowList(startPos, startLoc, exprList, isAsync);
|
return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList, isAsync);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!exprList.length) {
|
if (!exprList.length) {
|
||||||
@ -468,6 +475,7 @@ pp.parseParenAndDistinguishExpression = function (startPos, startLoc, canBeArrow
|
|||||||
if (exprList.length > 1) {
|
if (exprList.length > 1) {
|
||||||
val = this.startNodeAt(innerStartPos, innerStartLoc);
|
val = this.startNodeAt(innerStartPos, innerStartLoc);
|
||||||
val.expressions = exprList;
|
val.expressions = exprList;
|
||||||
|
this.toReferencedList(val.expressions);
|
||||||
this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
|
this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
|
||||||
} else {
|
} else {
|
||||||
val = exprList[0];
|
val = exprList[0];
|
||||||
@ -477,10 +485,6 @@ pp.parseParenAndDistinguishExpression = function (startPos, startLoc, canBeArrow
|
|||||||
return val;
|
return val;
|
||||||
};
|
};
|
||||||
|
|
||||||
pp.parseParenArrowList = function (startPos, startLoc, exprList, isAsync) {
|
|
||||||
return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList, isAsync);
|
|
||||||
};
|
|
||||||
|
|
||||||
pp.parseParenItem = function (node) {
|
pp.parseParenItem = function (node) {
|
||||||
return node;
|
return node;
|
||||||
};
|
};
|
||||||
@ -508,6 +512,7 @@ pp.parseNew = function () {
|
|||||||
|
|
||||||
if (this.eat(tt.parenL)) {
|
if (this.eat(tt.parenL)) {
|
||||||
node.arguments = this.parseExprList(tt.parenR, this.options.features["es7.trailingFunctionCommas"]);
|
node.arguments = this.parseExprList(tt.parenR, this.options.features["es7.trailingFunctionCommas"]);
|
||||||
|
this.toReferencedList(node.arguments);
|
||||||
} else {
|
} else {
|
||||||
node.arguments = [];
|
node.arguments = [];
|
||||||
}
|
}
|
||||||
@ -742,6 +747,12 @@ pp.parseExprList = function (close, allowTrailingComma, allowEmpty, refShorthand
|
|||||||
if (allowTrailingComma && this.afterTrailingComma(close)) break;
|
if (allowTrailingComma && this.afterTrailingComma(close)) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
elts.push(this.parseExprListItem(allowEmpty, refShorthandDefaultPos));
|
||||||
|
}
|
||||||
|
return elts;
|
||||||
|
};
|
||||||
|
|
||||||
|
pp.parseExprListItem = function (allowEmpty, refShorthandDefaultPos) {
|
||||||
let elt;
|
let elt;
|
||||||
if (allowEmpty && this.type === tt.comma) {
|
if (allowEmpty && this.type === tt.comma) {
|
||||||
elt = null;
|
elt = null;
|
||||||
@ -750,9 +761,7 @@ pp.parseExprList = function (close, allowTrailingComma, allowEmpty, refShorthand
|
|||||||
} else {
|
} else {
|
||||||
elt = this.parseMaybeAssign(false, refShorthandDefaultPos);
|
elt = this.parseMaybeAssign(false, refShorthandDefaultPos);
|
||||||
}
|
}
|
||||||
elts.push(elt);
|
return elt;
|
||||||
}
|
|
||||||
return elts;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse the next token as an identifier. If `liberal` is true (used
|
// Parse the next token as an identifier. If `liberal` is true (used
|
||||||
@ -761,7 +770,6 @@ pp.parseExprList = function (close, allowTrailingComma, allowEmpty, refShorthand
|
|||||||
|
|
||||||
pp.parseIdent = function (liberal) {
|
pp.parseIdent = function (liberal) {
|
||||||
let node = this.startNode();
|
let node = this.startNode();
|
||||||
if (liberal && this.options.allowReserved === "never") liberal = false;
|
|
||||||
if (this.type === tt.name) {
|
if (this.type === tt.name) {
|
||||||
if (!liberal &&
|
if (!liberal &&
|
||||||
((!this.options.allowReserved && this.isReservedWord(this.value)) ||
|
((!this.options.allowReserved && this.isReservedWord(this.value)) ||
|
||||||
|
|||||||
@ -75,6 +75,12 @@ pp.toAssignableList = function (exprList, isBinding) {
|
|||||||
return exprList;
|
return exprList;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Convert list of expression atoms to a list of
|
||||||
|
|
||||||
|
pp.toReferencedList = function (exprList) {
|
||||||
|
return exprList;
|
||||||
|
};
|
||||||
|
|
||||||
// Parses spread element.
|
// Parses spread element.
|
||||||
|
|
||||||
pp.parseSpread = function (refShorthandDefaultPos) {
|
pp.parseSpread = function (refShorthandDefaultPos) {
|
||||||
|
|||||||
@ -3,18 +3,6 @@ import { Parser } from "../state";
|
|||||||
|
|
||||||
var pp = Parser.prototype;
|
var pp = Parser.prototype;
|
||||||
|
|
||||||
pp.isRelational = function (op) {
|
|
||||||
return this.type === tt.relational && this.value === op;
|
|
||||||
};
|
|
||||||
|
|
||||||
pp.expectRelational = function (op) {
|
|
||||||
if (this.isRelational(op)) {
|
|
||||||
this.next();
|
|
||||||
} else {
|
|
||||||
this.unexpected();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
pp.flowParseTypeInitialiser = function (tok) {
|
pp.flowParseTypeInitialiser = function (tok) {
|
||||||
var oldInType = this.inType;
|
var oldInType = this.inType;
|
||||||
this.inType = true;
|
this.inType = true;
|
||||||
@ -707,17 +695,55 @@ export default function (instance) {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
instance.extend("parseParenArrowList", function (inner) {
|
function typeCastToParameter(node) {
|
||||||
return function (startPos, startLoc, exprList, isAsync) {
|
node.expression.typeAnnotation = node.typeAnnotation;
|
||||||
|
return node.expression;
|
||||||
|
}
|
||||||
|
|
||||||
|
instance.extend("toAssignableList", function (inner) {
|
||||||
|
return function (exprList, isBinding) {
|
||||||
for (var i = 0; i < exprList.length; i++) {
|
for (var i = 0; i < exprList.length; i++) {
|
||||||
var listItem = exprList[i];
|
var expr = exprList[i];
|
||||||
if (listItem.type === "TypeCastExpression") {
|
if (expr && expr.type === "TypeCastExpression") {
|
||||||
var expr = listItem.expression;
|
exprList[i] = typeCastToParameter(expr);
|
||||||
expr.typeAnnotation = listItem.typeAnnotation;
|
|
||||||
exprList[i] = expr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return inner.call(this, startPos, startLoc, exprList, isAsync);
|
return inner.call(this, exprList, isBinding);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
instance.extend("toReferencedList", function () {
|
||||||
|
return function (exprList) {
|
||||||
|
var foundTypeCast = false;
|
||||||
|
|
||||||
|
for (var i = 0; i < exprList.length; i++) {
|
||||||
|
var expr = exprList[i];
|
||||||
|
if (expr && expr._exprListItem && expr.type === "TypeCastExpression") {
|
||||||
|
if (foundTypeCast) {
|
||||||
|
this.unexpected(expr.start, "Unexpected type cast");
|
||||||
|
} else {
|
||||||
|
foundTypeCast = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return exprList;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
instance.extend("parseExprListItem", function (inner) {
|
||||||
|
return function (allowEmpty, refShorthandDefaultPos) {
|
||||||
|
var node = inner.call(this, allowEmpty, refShorthandDefaultPos);
|
||||||
|
if (this.type === tt.colon) {
|
||||||
|
return {
|
||||||
|
type: "TypeCastExpression",
|
||||||
|
_exprListItem: true,
|
||||||
|
expression: node,
|
||||||
|
typeAnnotation: this.flowParseTypeAnnotation()
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return node;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -5971,6 +5971,86 @@ var fbTestFixture = {
|
|||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
|
"var foo = async (foo: bar, bar: foo) => {}": {
|
||||||
|
type: "VariableDeclaration",
|
||||||
|
kind: "var",
|
||||||
|
start: 0,
|
||||||
|
end: 42,
|
||||||
|
declarations: [{
|
||||||
|
type: "VariableDeclarator",
|
||||||
|
start: 4,
|
||||||
|
end: 42,
|
||||||
|
id: {
|
||||||
|
type: "Identifier",
|
||||||
|
start: 4,
|
||||||
|
end: 7,
|
||||||
|
name: "foo"
|
||||||
|
},
|
||||||
|
init: {
|
||||||
|
type: "ArrowFunctionExpression",
|
||||||
|
start: 10,
|
||||||
|
end: 42,
|
||||||
|
id: null,
|
||||||
|
generator: false,
|
||||||
|
expression: false,
|
||||||
|
async: true,
|
||||||
|
params: [
|
||||||
|
{
|
||||||
|
type: "Identifier",
|
||||||
|
start: 17,
|
||||||
|
end: 20,
|
||||||
|
name: "foo",
|
||||||
|
typeAnnotation: {
|
||||||
|
type: "TypeAnnotation",
|
||||||
|
start: 20,
|
||||||
|
end: 25,
|
||||||
|
typeAnnotation: {
|
||||||
|
type: "GenericTypeAnnotation",
|
||||||
|
start: 22,
|
||||||
|
end: 25,
|
||||||
|
typeParameters: null,
|
||||||
|
id: {
|
||||||
|
type: "Identifier",
|
||||||
|
start: 22,
|
||||||
|
end: 25,
|
||||||
|
name: "bar"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "Identifier",
|
||||||
|
start: 27,
|
||||||
|
end: 30,
|
||||||
|
name: "bar",
|
||||||
|
typeAnnotation: {
|
||||||
|
type: "TypeAnnotation",
|
||||||
|
start: 30,
|
||||||
|
end: 35,
|
||||||
|
typeAnnotation: {
|
||||||
|
type: "GenericTypeAnnotation",
|
||||||
|
start: 32,
|
||||||
|
end: 35,
|
||||||
|
typeParameters: null,
|
||||||
|
id: {
|
||||||
|
type: "Identifier",
|
||||||
|
start: 32,
|
||||||
|
end: 35,
|
||||||
|
name: "foo"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
body: {
|
||||||
|
type: "BlockStatement",
|
||||||
|
start: 40,
|
||||||
|
end: 42,
|
||||||
|
body: []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
},
|
||||||
"var foo = async (): number => bar;": {
|
"var foo = async (): number => bar;": {
|
||||||
type: "VariableDeclaration",
|
type: "VariableDeclaration",
|
||||||
kind: "var",
|
kind: "var",
|
||||||
@ -11978,6 +12058,7 @@ var fbTestFixture = {
|
|||||||
|
|
||||||
if (typeof exports !== "undefined") {
|
if (typeof exports !== "undefined") {
|
||||||
var test = require("./driver.js").test;
|
var test = require("./driver.js").test;
|
||||||
|
var testFail = require("./driver.js").testFail;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var ns in fbTestFixture) {
|
for (var ns in fbTestFixture) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user