@tdb/web
Version:
Common condiguration for serving a web-site and testing web-based UI components.
1,349 lines (1,140 loc) • 342 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function _AwaitValue(value) {
this.wrapped = value;
}
function _AsyncGenerator(gen) {
var front, back;
function send(key, arg) {
return new Promise(function (resolve, reject) {
var request = {
key: key,
arg: arg,
resolve: resolve,
reject: reject,
next: null
};
if (back) {
back = back.next = request;
} else {
front = back = request;
resume(key, arg);
}
});
}
function resume(key, arg) {
try {
var result = gen[key](arg);
var value = result.value;
var wrappedAwait = value instanceof _AwaitValue;
Promise.resolve(wrappedAwait ? value.wrapped : value).then(function (arg) {
if (wrappedAwait) {
resume("next", arg);
return;
}
settle(result.done ? "return" : "normal", arg);
}, function (err) {
resume("throw", err);
});
} catch (err) {
settle("throw", err);
}
}
function settle(type, value) {
switch (type) {
case "return":
front.resolve({
value: value,
done: true
});
break;
case "throw":
front.reject(value);
break;
default:
front.resolve({
value: value,
done: false
});
break;
}
front = front.next;
if (front) {
resume(front.key, front.arg);
} else {
back = null;
}
}
this._invoke = send;
if (typeof gen.return !== "function") {
this.return = undefined;
}
}
if (typeof Symbol === "function" && Symbol.asyncIterator) {
_AsyncGenerator.prototype[Symbol.asyncIterator] = function () {
return this;
};
}
_AsyncGenerator.prototype.next = function (arg) {
return this._invoke("next", arg);
};
_AsyncGenerator.prototype.throw = function (arg) {
return this._invoke("throw", arg);
};
_AsyncGenerator.prototype.return = function (arg) {
return this._invoke("return", arg);
};
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
var beforeExpr = true;
var startsExpr = true;
var isLoop = true;
var isAssign = true;
var prefix = true;
var postfix = true;
var TokenType = function TokenType(label, conf) {
if (conf === void 0) {
conf = {};
}
this.label = label;
this.keyword = conf.keyword;
this.beforeExpr = !!conf.beforeExpr;
this.startsExpr = !!conf.startsExpr;
this.rightAssociative = !!conf.rightAssociative;
this.isLoop = !!conf.isLoop;
this.isAssign = !!conf.isAssign;
this.prefix = !!conf.prefix;
this.postfix = !!conf.postfix;
this.binop = conf.binop === 0 ? 0 : conf.binop || null;
this.updateContext = null;
};
function KeywordTokenType(keyword, options) {
if (options === void 0) {
options = {};
}
return new TokenType(keyword, Object.assign({}, options, {
keyword: keyword
}));
}
function BinopTokenType(name, binop) {
return new TokenType(name, {
beforeExpr: beforeExpr,
binop: binop
});
}
var types = {
num: new TokenType("num", {
startsExpr: startsExpr
}),
bigint: new TokenType("bigint", {
startsExpr: startsExpr
}),
regexp: new TokenType("regexp", {
startsExpr: startsExpr
}),
string: new TokenType("string", {
startsExpr: startsExpr
}),
name: new TokenType("name", {
startsExpr: startsExpr
}),
eof: new TokenType("eof"),
bracketL: new TokenType("[", {
beforeExpr: beforeExpr,
startsExpr: startsExpr
}),
bracketR: new TokenType("]"),
braceL: new TokenType("{", {
beforeExpr: beforeExpr,
startsExpr: startsExpr
}),
braceBarL: new TokenType("{|", {
beforeExpr: beforeExpr,
startsExpr: startsExpr
}),
braceR: new TokenType("}"),
braceBarR: new TokenType("|}"),
parenL: new TokenType("(", {
beforeExpr: beforeExpr,
startsExpr: startsExpr
}),
parenR: new TokenType(")"),
comma: new TokenType(",", {
beforeExpr: beforeExpr
}),
semi: new TokenType(";", {
beforeExpr: beforeExpr
}),
colon: new TokenType(":", {
beforeExpr: beforeExpr
}),
doubleColon: new TokenType("::", {
beforeExpr: beforeExpr
}),
dot: new TokenType("."),
question: new TokenType("?", {
beforeExpr: beforeExpr
}),
questionDot: new TokenType("?."),
arrow: new TokenType("=>", {
beforeExpr: beforeExpr
}),
template: new TokenType("template"),
ellipsis: new TokenType("...", {
beforeExpr: beforeExpr
}),
backQuote: new TokenType("`", {
startsExpr: startsExpr
}),
dollarBraceL: new TokenType("${", {
beforeExpr: beforeExpr,
startsExpr: startsExpr
}),
at: new TokenType("@"),
hash: new TokenType("#"),
interpreterDirective: new TokenType("#!..."),
eq: new TokenType("=", {
beforeExpr: beforeExpr,
isAssign: isAssign
}),
assign: new TokenType("_=", {
beforeExpr: beforeExpr,
isAssign: isAssign
}),
incDec: new TokenType("++/--", {
prefix: prefix,
postfix: postfix,
startsExpr: startsExpr
}),
bang: new TokenType("!", {
beforeExpr: beforeExpr,
prefix: prefix,
startsExpr: startsExpr
}),
tilde: new TokenType("~", {
beforeExpr: beforeExpr,
prefix: prefix,
startsExpr: startsExpr
}),
pipeline: new BinopTokenType("|>", 0),
nullishCoalescing: new BinopTokenType("??", 1),
logicalOR: new BinopTokenType("||", 1),
logicalAND: new BinopTokenType("&&", 2),
bitwiseOR: new BinopTokenType("|", 3),
bitwiseXOR: new BinopTokenType("^", 4),
bitwiseAND: new BinopTokenType("&", 5),
equality: new BinopTokenType("==/!=", 6),
relational: new BinopTokenType("</>", 7),
bitShift: new BinopTokenType("<</>>", 8),
plusMin: new TokenType("+/-", {
beforeExpr: beforeExpr,
binop: 9,
prefix: prefix,
startsExpr: startsExpr
}),
modulo: new BinopTokenType("%", 10),
star: new BinopTokenType("*", 10),
slash: new BinopTokenType("/", 10),
exponent: new TokenType("**", {
beforeExpr: beforeExpr,
binop: 11,
rightAssociative: true
})
};
var keywords = {
break: new KeywordTokenType("break"),
case: new KeywordTokenType("case", {
beforeExpr: beforeExpr
}),
catch: new KeywordTokenType("catch"),
continue: new KeywordTokenType("continue"),
debugger: new KeywordTokenType("debugger"),
default: new KeywordTokenType("default", {
beforeExpr: beforeExpr
}),
do: new KeywordTokenType("do", {
isLoop: isLoop,
beforeExpr: beforeExpr
}),
else: new KeywordTokenType("else", {
beforeExpr: beforeExpr
}),
finally: new KeywordTokenType("finally"),
for: new KeywordTokenType("for", {
isLoop: isLoop
}),
function: new KeywordTokenType("function", {
startsExpr: startsExpr
}),
if: new KeywordTokenType("if"),
return: new KeywordTokenType("return", {
beforeExpr: beforeExpr
}),
switch: new KeywordTokenType("switch"),
throw: new KeywordTokenType("throw", {
beforeExpr: beforeExpr,
prefix: prefix,
startsExpr: startsExpr
}),
try: new KeywordTokenType("try"),
var: new KeywordTokenType("var"),
let: new KeywordTokenType("let"),
const: new KeywordTokenType("const"),
while: new KeywordTokenType("while", {
isLoop: isLoop
}),
with: new KeywordTokenType("with"),
new: new KeywordTokenType("new", {
beforeExpr: beforeExpr,
startsExpr: startsExpr
}),
this: new KeywordTokenType("this", {
startsExpr: startsExpr
}),
super: new KeywordTokenType("super", {
startsExpr: startsExpr
}),
class: new KeywordTokenType("class", {
startsExpr: startsExpr
}),
extends: new KeywordTokenType("extends", {
beforeExpr: beforeExpr
}),
export: new KeywordTokenType("export"),
import: new KeywordTokenType("import", {
startsExpr: startsExpr
}),
yield: new KeywordTokenType("yield", {
beforeExpr: beforeExpr,
startsExpr: startsExpr
}),
null: new KeywordTokenType("null", {
startsExpr: startsExpr
}),
true: new KeywordTokenType("true", {
startsExpr: startsExpr
}),
false: new KeywordTokenType("false", {
startsExpr: startsExpr
}),
in: new KeywordTokenType("in", {
beforeExpr: beforeExpr,
binop: 7
}),
instanceof: new KeywordTokenType("instanceof", {
beforeExpr: beforeExpr,
binop: 7
}),
typeof: new KeywordTokenType("typeof", {
beforeExpr: beforeExpr,
prefix: prefix,
startsExpr: startsExpr
}),
void: new KeywordTokenType("void", {
beforeExpr: beforeExpr,
prefix: prefix,
startsExpr: startsExpr
}),
delete: new KeywordTokenType("delete", {
beforeExpr: beforeExpr,
prefix: prefix,
startsExpr: startsExpr
})
};
Object.keys(keywords).forEach(function (name) {
types["_" + name] = keywords[name];
});
function isSimpleProperty(node) {
return node != null && node.type === "Property" && node.kind === "init" && node.method === false;
}
var estree = (function (superClass) {
return function (_superClass) {
_inheritsLoose(_class, _superClass);
function _class() {
return _superClass.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.estreeParseRegExpLiteral = function estreeParseRegExpLiteral(_ref) {
var pattern = _ref.pattern,
flags = _ref.flags;
var regex = null;
try {
regex = new RegExp(pattern, flags);
} catch (e) {}
var node = this.estreeParseLiteral(regex);
node.regex = {
pattern: pattern,
flags: flags
};
return node;
};
_proto.estreeParseLiteral = function estreeParseLiteral(value) {
return this.parseLiteral(value, "Literal");
};
_proto.directiveToStmt = function directiveToStmt(directive) {
var directiveLiteral = directive.value;
var stmt = this.startNodeAt(directive.start, directive.loc.start);
var expression = this.startNodeAt(directiveLiteral.start, directiveLiteral.loc.start);
expression.value = directiveLiteral.value;
expression.raw = directiveLiteral.extra.raw;
stmt.expression = this.finishNodeAt(expression, "Literal", directiveLiteral.end, directiveLiteral.loc.end);
stmt.directive = directiveLiteral.extra.raw.slice(1, -1);
return this.finishNodeAt(stmt, "ExpressionStatement", directive.end, directive.loc.end);
};
_proto.initFunction = function initFunction(node, isAsync) {
_superClass.prototype.initFunction.call(this, node, isAsync);
node.expression = false;
};
_proto.checkDeclaration = function checkDeclaration(node) {
if (isSimpleProperty(node)) {
this.checkDeclaration(node.value);
} else {
_superClass.prototype.checkDeclaration.call(this, node);
}
};
_proto.checkGetterSetterParams = function checkGetterSetterParams(method) {
var prop = method;
var paramCount = prop.kind === "get" ? 0 : 1;
var start = prop.start;
if (prop.value.params.length !== paramCount) {
if (prop.kind === "get") {
this.raise(start, "getter must not have any formal parameters");
} else {
this.raise(start, "setter must have exactly one formal parameter");
}
}
if (prop.kind === "set" && prop.value.params[0].type === "RestElement") {
this.raise(start, "setter function argument must not be a rest parameter");
}
};
_proto.checkLVal = function checkLVal(expr, isBinding, checkClashes, contextDescription) {
var _this = this;
switch (expr.type) {
case "ObjectPattern":
expr.properties.forEach(function (prop) {
_this.checkLVal(prop.type === "Property" ? prop.value : prop, isBinding, checkClashes, "object destructuring pattern");
});
break;
default:
_superClass.prototype.checkLVal.call(this, expr, isBinding, checkClashes, contextDescription);
}
};
_proto.checkPropClash = function checkPropClash(prop, propHash) {
if (prop.computed || !isSimpleProperty(prop)) return;
var key = prop.key;
var name = key.type === "Identifier" ? key.name : String(key.value);
if (name === "__proto__") {
if (propHash.proto) {
this.raise(key.start, "Redefinition of __proto__ property");
}
propHash.proto = true;
}
};
_proto.isStrictBody = function isStrictBody(node) {
var isBlockStatement = node.body.type === "BlockStatement";
if (isBlockStatement && node.body.body.length > 0) {
for (var _i2 = 0, _node$body$body2 = node.body.body; _i2 < _node$body$body2.length; _i2++) {
var directive = _node$body$body2[_i2];
if (directive.type === "ExpressionStatement" && directive.expression.type === "Literal") {
if (directive.expression.value === "use strict") return true;
} else {
break;
}
}
}
return false;
};
_proto.isValidDirective = function isValidDirective(stmt) {
return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && (!stmt.expression.extra || !stmt.expression.extra.parenthesized);
};
_proto.stmtToDirective = function stmtToDirective(stmt) {
var directive = _superClass.prototype.stmtToDirective.call(this, stmt);
var value = stmt.expression.value;
directive.value.value = value;
return directive;
};
_proto.parseBlockBody = function parseBlockBody(node, allowDirectives, topLevel, end) {
var _this2 = this;
_superClass.prototype.parseBlockBody.call(this, node, allowDirectives, topLevel, end);
var directiveStatements = node.directives.map(function (d) {
return _this2.directiveToStmt(d);
});
node.body = directiveStatements.concat(node.body);
delete node.directives;
};
_proto.pushClassMethod = function pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor) {
this.parseMethod(method, isGenerator, isAsync, isConstructor, "MethodDefinition");
if (method.typeParameters) {
method.value.typeParameters = method.typeParameters;
delete method.typeParameters;
}
classBody.body.push(method);
};
_proto.parseExprAtom = function parseExprAtom(refShorthandDefaultPos) {
switch (this.state.type) {
case types.regexp:
return this.estreeParseRegExpLiteral(this.state.value);
case types.num:
case types.string:
return this.estreeParseLiteral(this.state.value);
case types._null:
return this.estreeParseLiteral(null);
case types._true:
return this.estreeParseLiteral(true);
case types._false:
return this.estreeParseLiteral(false);
default:
return _superClass.prototype.parseExprAtom.call(this, refShorthandDefaultPos);
}
};
_proto.parseLiteral = function parseLiteral(value, type, startPos, startLoc) {
var node = _superClass.prototype.parseLiteral.call(this, value, type, startPos, startLoc);
node.raw = node.extra.raw;
delete node.extra;
return node;
};
_proto.parseFunctionBody = function parseFunctionBody(node, allowExpression) {
_superClass.prototype.parseFunctionBody.call(this, node, allowExpression);
node.expression = node.body.type !== "BlockStatement";
};
_proto.parseMethod = function parseMethod(node, isGenerator, isAsync, isConstructor, type) {
var funcNode = this.startNode();
funcNode.kind = node.kind;
funcNode = _superClass.prototype.parseMethod.call(this, funcNode, isGenerator, isAsync, isConstructor, "FunctionExpression");
delete funcNode.kind;
node.value = funcNode;
return this.finishNode(node, type);
};
_proto.parseObjectMethod = function parseObjectMethod(prop, isGenerator, isAsync, isPattern, containsEsc) {
var node = _superClass.prototype.parseObjectMethod.call(this, prop, isGenerator, isAsync, isPattern, containsEsc);
if (node) {
node.type = "Property";
if (node.kind === "method") node.kind = "init";
node.shorthand = false;
}
return node;
};
_proto.parseObjectProperty = function parseObjectProperty(prop, startPos, startLoc, isPattern, refShorthandDefaultPos) {
var node = _superClass.prototype.parseObjectProperty.call(this, prop, startPos, startLoc, isPattern, refShorthandDefaultPos);
if (node) {
node.kind = "init";
node.type = "Property";
}
return node;
};
_proto.toAssignable = function toAssignable(node, isBinding, contextDescription) {
if (isSimpleProperty(node)) {
this.toAssignable(node.value, isBinding, contextDescription);
return node;
}
return _superClass.prototype.toAssignable.call(this, node, isBinding, contextDescription);
};
_proto.toAssignableObjectExpressionProp = function toAssignableObjectExpressionProp(prop, isBinding, isLast) {
if (prop.kind === "get" || prop.kind === "set") {
this.raise(prop.key.start, "Object pattern can't contain getter or setter");
} else if (prop.method) {
this.raise(prop.key.start, "Object pattern can't contain methods");
} else {
_superClass.prototype.toAssignableObjectExpressionProp.call(this, prop, isBinding, isLast);
}
};
return _class;
}(superClass);
});
var lineBreak = /\r\n?|\n|\u2028|\u2029/;
var lineBreakG = new RegExp(lineBreak.source, "g");
function isNewLine(code) {
switch (code) {
case 10:
case 13:
case 8232:
case 8233:
return true;
default:
return false;
}
}
var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
function isWhitespace(code) {
switch (code) {
case 0x0009:
case 0x000b:
case 0x000c:
case 32:
case 160:
case 5760:
case 0x2000:
case 0x2001:
case 0x2002:
case 0x2003:
case 0x2004:
case 0x2005:
case 0x2006:
case 0x2007:
case 0x2008:
case 0x2009:
case 0x200a:
case 0x202f:
case 0x205f:
case 0x3000:
case 0xfeff:
return true;
default:
return false;
}
}
var TokContext = function TokContext(token, isExpr, preserveSpace, override) {
this.token = token;
this.isExpr = !!isExpr;
this.preserveSpace = !!preserveSpace;
this.override = override;
};
var types$1 = {
braceStatement: new TokContext("{", false),
braceExpression: new TokContext("{", true),
templateQuasi: new TokContext("${", false),
parenStatement: new TokContext("(", false),
parenExpression: new TokContext("(", true),
template: new TokContext("`", true, true, function (p) {
return p.readTmplToken();
}),
functionExpression: new TokContext("function", true),
functionStatement: new TokContext("function", false)
};
types.parenR.updateContext = types.braceR.updateContext = function () {
if (this.state.context.length === 1) {
this.state.exprAllowed = true;
return;
}
var out = this.state.context.pop();
if (out === types$1.braceStatement && this.curContext().token === "function") {
out = this.state.context.pop();
}
this.state.exprAllowed = !out.isExpr;
};
types.name.updateContext = function (prevType) {
var allowed = false;
if (prevType !== types.dot) {
if (this.state.value === "of" && !this.state.exprAllowed || this.state.value === "yield" && this.state.inGenerator) {
allowed = true;
}
}
this.state.exprAllowed = allowed;
if (this.state.isIterator) {
this.state.isIterator = false;
}
};
types.braceL.updateContext = function (prevType) {
this.state.context.push(this.braceIsBlock(prevType) ? types$1.braceStatement : types$1.braceExpression);
this.state.exprAllowed = true;
};
types.dollarBraceL.updateContext = function () {
this.state.context.push(types$1.templateQuasi);
this.state.exprAllowed = true;
};
types.parenL.updateContext = function (prevType) {
var statementParens = prevType === types._if || prevType === types._for || prevType === types._with || prevType === types._while;
this.state.context.push(statementParens ? types$1.parenStatement : types$1.parenExpression);
this.state.exprAllowed = true;
};
types.incDec.updateContext = function () {};
types._function.updateContext = types._class.updateContext = function (prevType) {
if (prevType.beforeExpr && prevType !== types.semi && prevType !== types._else && !(prevType === types._return && lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.start))) && !((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat)) {
this.state.context.push(types$1.functionExpression);
} else {
this.state.context.push(types$1.functionStatement);
}
this.state.exprAllowed = false;
};
types.backQuote.updateContext = function () {
if (this.curContext() === types$1.template) {
this.state.context.pop();
} else {
this.state.context.push(types$1.template);
}
this.state.exprAllowed = false;
};
function makePredicate(words) {
var wordsArr = words.split(" ");
return function (str) {
return wordsArr.indexOf(str) >= 0;
};
}
var reservedWords = {
"6": makePredicate("enum await"),
strict: makePredicate("implements interface let package private protected public static yield"),
strictBind: makePredicate("eval arguments")
};
var isKeyword = makePredicate("break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this let const class extends export import yield super");
var nonASCIIidentifierStartChars = "\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1878\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309B-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEF\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7B9\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC";
var nonASCIIidentifierChars = "\u200C\u200D\xB7\u0300-\u036F\u0387\u0483-\u0487\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u0669\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u06F0-\u06F9\u0711\u0730-\u074A\u07A6-\u07B0\u07C0-\u07C9\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0966-\u096F\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09E6-\u09EF\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A66-\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AE6-\u0AEF\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B66-\u0B6F\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0BE6-\u0BEF\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C66-\u0C6F\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0CE6-\u0CEF\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D66-\u0D6F\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0E50-\u0E59\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0ED0-\u0ED9\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1040-\u1049\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F-\u109D\u135D-\u135F\u1369-\u1371\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u18A9\u1920-\u192B\u1930-\u193B\u1946-\u194F\u19D0-\u19DA\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AB0-\u1ABD\u1B00-\u1B04\u1B34-\u1B44\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BB0-\u1BB9\u1BE6-\u1BF3\u1C24-\u1C37\u1C40-\u1C49\u1C50-\u1C59\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u203F\u2040\u2054\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA620-\uA629\uA66F\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F1\uA8FF-\uA909\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9D0-\uA9D9\uA9E5\uA9F0-\uA9F9\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA50-\uAA59\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uABF0-\uABF9\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFF10-\uFF19\uFF3F";
var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
var astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 157, 310, 10, 21, 11, 7, 153, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 477, 28, 11, 0, 9, 21, 190, 52, 76, 44, 33, 24, 27, 35, 30, 0, 12, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 85, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 159, 52, 19, 3, 54, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 86, 26, 230, 43, 117, 63, 32, 0, 257, 0, 11, 39, 8, 0, 22, 0, 12, 39, 3, 3, 20, 0, 35, 56, 264, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 328, 18, 270, 921, 103, 110, 18, 195, 2749, 1070, 4050, 582, 8634, 568, 8, 30, 114, 29, 19, 47, 17, 3, 32, 20, 6, 18, 689, 63, 129, 68, 12, 0, 67, 12, 65, 1, 31, 6129, 15, 754, 9486, 286, 82, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 4149, 196, 60, 67, 1213, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42710, 42, 4148, 12, 221, 3, 5761, 15, 7472, 3104, 541];
var astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 525, 10, 176, 2, 54, 14, 32, 9, 16, 3, 46, 10, 54, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 4, 9, 83, 11, 7, 0, 161, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 193, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 84, 14, 5, 9, 243, 14, 166, 9, 280, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 406, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 330, 3, 19306, 9, 135, 4, 60, 6, 26, 9, 1016, 45, 17, 3, 19723, 1, 5319, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 2214, 6, 110, 6, 6, 9, 792487, 239];
function isInAstralSet(code, set) {
var pos = 0x10000;
for (var i = 0; i < set.length; i += 2) {
pos += set[i];
if (pos > code) return false;
pos += set[i + 1];
if (pos >= code) return true;
}
return false;
}
function isIdentifierStart(code) {
if (code < 65) return code === 36;
if (code <= 90) return true;
if (code < 97) return code === 95;
if (code <= 122) return true;
if (code <= 0xffff) {
return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
}
return isInAstralSet(code, astralIdentifierStartCodes);
}
function isIteratorStart(current, next) {
return current === 64 && next === 64;
}
function isIdentifierChar(code) {
if (code < 48) return code === 36;
if (code < 58) return true;
if (code < 65) return false;
if (code <= 90) return true;
if (code < 97) return code === 95;
if (code <= 122) return true;
if (code <= 0xffff) {
return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
}
return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
}
var reservedTypes = ["any", "bool", "boolean", "empty", "false", "mixed", "null", "number", "static", "string", "true", "typeof", "void", "interface", "extends", "_"];
function isEsModuleType(bodyElement) {
return bodyElement.type === "DeclareExportAllDeclaration" || bodyElement.type === "DeclareExportDeclaration" && (!bodyElement.declaration || bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration");
}
function hasTypeImportKind(node) {
return node.importKind === "type" || node.importKind === "typeof";
}
function isMaybeDefaultImport(state) {
return (state.type === types.name || !!state.type.keyword) && state.value !== "from";
}
var exportSuggestions = {
const: "declare export var",
let: "declare export var",
type: "export type",
interface: "export interface"
};
function partition(list, test) {
var list1 = [];
var list2 = [];
for (var i = 0; i < list.length; i++) {
(test(list[i], i, list) ? list1 : list2).push(list[i]);
}
return [list1, list2];
}
var FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
var flow = (function (superClass) {
return function (_superClass) {
_inheritsLoose(_class, _superClass);
function _class(options, input) {
var _this;
_this = _superClass.call(this, options, input) || this;
_this.flowPragma = undefined;
return _this;
}
var _proto = _class.prototype;
_proto.shouldParseTypes = function shouldParseTypes() {
return this.getPluginOption("flow", "all") || this.flowPragma === "flow";
};
_proto.addComment = function addComment(comment) {
if (this.flowPragma === undefined) {
var matches = FLOW_PRAGMA_REGEX.exec(comment.value);
if (!matches) {
this.flowPragma = null;
} else if (matches[1] === "flow") {
this.flowPragma = "flow";
} else if (matches[1] === "noflow") {
this.flowPragma = "noflow";
} else {
throw new Error("Unexpected flow pragma");
}
}
return _superClass.prototype.addComment.call(this, comment);
};
_proto.flowParseTypeInitialiser = function flowParseTypeInitialiser(tok) {
var oldInType = this.state.inType;
this.state.inType = true;
this.expect(tok || types.colon);
var type = this.flowParseType();
this.state.inType = oldInType;
return type;
};
_proto.flowParsePredicate = function flowParsePredicate() {
var node = this.startNode();
var moduloLoc = this.state.startLoc;
var moduloPos = this.state.start;
this.expect(types.modulo);
var checksLoc = this.state.startLoc;
this.expectContextual("checks");
if (moduloLoc.line !== checksLoc.line || moduloLoc.column !== checksLoc.column - 1) {
this.raise(moduloPos, "Spaces between ´%´ and ´checks´ are not allowed here.");
}
if (this.eat(types.parenL)) {
node.value = this.parseExpression();
this.expect(types.parenR);
return this.finishNode(node, "DeclaredPredicate");
} else {
return this.finishNode(node, "InferredPredicate");
}
};
_proto.flowParseTypeAndPredicateInitialiser = function flowParseTypeAndPredicateInitialiser() {
var oldInType = this.state.inType;
this.state.inType = true;
this.expect(types.colon);
var type = null;
var predicate = null;
if (this.match(types.modulo)) {
this.state.inType = oldInType;
predicate = this.flowParsePredicate();
} else {
type = this.flowParseType();
this.state.inType = oldInType;
if (this.match(types.modulo)) {
predicate = this.flowParsePredicate();
}
}
return [type, predicate];
};
_proto.flowParseDeclareClass = function flowParseDeclareClass(node) {
this.next();
this.flowParseInterfaceish(node, true);
return this.finishNode(node, "DeclareClass");
};
_proto.flowParseDeclareFunction = function flowParseDeclareFunction(node) {
this.next();
var id = node.id = this.parseIdentifier();
var typeNode = this.startNode();
var typeContainer = this.startNode();
if (this.isRelational("<")) {
typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
} else {
typeNode.typeParameters = null;
}
this.expect(types.parenL);
var tmp = this.flowParseFunctionTypeParams();
typeNode.params = tmp.params;
typeNode.rest = tmp.rest;
this.expect(types.parenR);
var _this$flowParseTypeAn = this.flowParseTypeAndPredicateInitialiser();
typeNode.returnType = _this$flowParseTypeAn[0];
node.predicate = _this$flowParseTypeAn[1];
typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation");
id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation");
this.finishNode(id, id.type);
this.semicolon();
return this.finishNode(node, "DeclareFunction");
};
_proto.flowParseDeclare = function flowParseDeclare(node, insideModule) {
if (this.match(types._class)) {
return this.flowParseDeclareClass(node);
} else if (this.match(types._function)) {
return this.flowParseDeclareFunction(node);
} else if (this.match(types._var)) {
return this.flowParseDeclareVariable(node);
} else if (this.isContextual("module")) {
if (this.lookahead().type === types.dot) {
return this.flowParseDeclareModuleExports(node);
} else {
if (insideModule) {
this.unexpected(null, "`declare module` cannot be used inside another `declare module`");
}
return this.flowParseDeclareModule(node);
}
} else if (this.isContextual("type")) {
return this.flowParseDeclareTypeAlias(node);
} else if (this.isContextual("opaque")) {
return this.flowParseDeclareOpaqueType(node);
} else if (this.isContextual("interface")) {
return this.flowParseDeclareInterface(node);
} else if (this.match(types._export)) {
return this.flowParseDeclareExportDeclaration(node, insideModule);
} else {
throw this.unexpected();
}
};
_proto.flowParseDeclareVariable = function flowParseDeclareVariable(node) {
this.next();
node.id = this.flowParseTypeAnnotatableIdentifier(true);
this.semicolon();
return this.finishNode(node, "DeclareVariable");
};
_proto.flowParseDeclareModule = function flowParseDeclareModule(node) {
var _this2 = this;
this.next();
if (this.match(types.string)) {
node.id = this.parseExprAtom();
} else {
node.id = this.parseIdentifier();
}
var bodyNode = node.body = this.startNode();
var body = bodyNode.body = [];
this.expect(types.braceL);
while (!this.match(types.braceR)) {
var _bodyNode = this.startNode();
if (this.match(types._import)) {
var lookahead = this.lookahead();
if (lookahead.value !== "type" && lookahead.value !== "typeof") {
this.unexpected(null, "Imports within a `declare module` body must always be `import type` or `import typeof`");
}
this.next();
this.parseImport(_bodyNode);
} else {
this.expectContextual("declare", "Only declares and type imports are allowed inside declare module");
_bodyNode = this.flowParseDeclare(_bodyNode, true);
}
body.push(_bodyNode);
}
this.expect(types.braceR);
this.finishNode(bodyNode, "BlockStatement");
var kind = null;
var hasModuleExport = false;
var errorMessage = "Found both `declare module.exports` and `declare export` in the same module. " + "Modules can only have 1 since they are either an ES module or they are a CommonJS module";
body.forEach(function (bodyElement) {
if (isEsModuleType(bodyElement)) {
if (kind === "CommonJS") {
_this2.unexpected(bodyElement.start, errorMessage);
}
kind = "ES";
} else if (bodyElement.type === "DeclareModuleExports") {
if (hasModuleExport) {
_this2.unexpected(bodyElement.start, "Duplicate `declare module.exports` statement");
}
if (kind === "ES") _this2.unexpected(bodyElement.start, errorMessage);
kind = "CommonJS";
hasModuleExport = true;
}
});
node.kind = kind || "CommonJS";
return this.finishNode(node, "DeclareModule");
};
_proto.flowParseDeclareExportDeclaration = function flowParseDeclareExportDeclaration(node, insideModule) {
this.expect(types._export);
if (this.eat(types._default)) {
if (this.match(types._function) || this.match(types._class)) {
node.declaration = this.flowParseDeclare(this.startNode());
} else {
node.declaration = this.flowParseType();
this.semicolon();
}
node.default = true;
return this.finishNode(node, "DeclareExportDeclaration");
} else {
if (this.match(types._const) || this.match(types._let) || (this.isContextual("type") || this.isContextual("interface")) && !insideModule) {
var label = this.state.value;
var suggestion = exportSuggestions[label];
this.unexpected(this.state.start, "`declare export " + label + "` is not supported. Use `" + suggestion + "` instead");
}
if (this.match(types._var) || this.match(types._function) || this.match(types._class) || this.isContextual("opaque")) {
node.declaration = this.flowParseDeclare(this.startNode());
node.default = false;
return this.finishNode(node, "DeclareExportDeclaration");
} else if (this.match(types.star) || this.match(types.braceL) || this.isContextual("interface") || this.isContextual("type") || this.isContextual("opaque")) {
node = this.parseExport(node);
if (node.type === "ExportNamedDeclaration") {
node.type = "ExportDeclaration";
node.default = false;
delete node.exportKind;
}
node.type = "Declare" + node.type;
return node;
}
}
throw this.unexpected();
};
_proto.flowParseDeclareModuleExports = function flowParseDeclareModuleExports(node) {
this.expectContextual("module");
this.expect(types.dot);
this.expectContextual("exports");
node.typeAnnotation = this.flowParseTypeAnnotation();
this.semicolon();
return this.finishNode(node, "DeclareModuleExports");
};
_proto.flowParseDeclareTypeAlias = function flowParseDeclareTypeAlias(node) {
this.next();
this.flowParseTypeAlias(node);
return this.finishNode(node, "DeclareTypeAlias");
};
_proto.flowParseDeclareOpaqueType = function flowParseDeclareOpaqueType(node) {
this.next();
this.flowParseOpaqueType(node, true);
return this.finishNode(node, "DeclareOpaqueType");
};
_proto.flowParseDeclareInterface = function flowParseDeclareInterface(node) {
this.next();
this.flowParseInterfaceish(node);
return this.finishNode(node, "DeclareInterface");
};
_proto.flowParseInterfaceish = function flowParseInterfaceish(node, isClass) {
if (isClass === void 0) {
isClass = false;
}
node.id = this.flowParseRestrictedIdentifier(!isClass);
if (this.isRelational("<")) {
node.typeParameters = this.flowParseTypeParameterDeclaration();
} else {
node.typeParameters = null;
}
node.extends = [];
node.implements = [];
node.mixins = [];
if (this.eat(types._extends)) {
do {
node.extends.push(this.flowParseInterfaceExtends());
} while (!isClass && this.eat(types.comma));
}
if (this.isContextual("mixins")) {
this.next();
do {
node.mixins.push(this.flowParseInterfaceExtends());
} while (this.eat(types.comma));
}
if (this.isContextual("implements")) {
this.next();
do {
node.implements.push(this.flowParseInterfaceExtends());
} while (this.eat(types.comma));
}
node.body = this.flowParseObjectType({
allowStatic: isClass,
allowExact: false,
allowSpread: false,
allowProto: isClass,
allowInexact: false
});
};
_proto.flowParseInterfaceExtends = function flowParseInterfaceExtends() {
var node = this.startNode();
node.id = this.flowParseQualifiedTypeIdentifier();
if (this.isRelational("<")) {
node.typeParameters = this.flowParseTypeParameterInstantiation();
} else {
node.typeParameters = null;
}
return this.finishNode(node, "InterfaceExtends");
};
_proto.flowParseInterface = function flowParseInterface(node) {
this.flowParseInterfaceish(node);
return this.finishNode(node, "InterfaceDeclaration");
};
_proto.checkNotUnderscore = function checkNotUnderscore(word) {
if (word === "_") {
throw this.unexpected(null, "`_` is only allowed as a type argument to call or new");
}
};
_proto.checkReservedType = function checkReservedType(word, startLoc) {
if (reservedTypes.indexOf(word) > -1) {
this.raise(startLoc, "Cannot overwrite reserved type " + word);
}
};
_proto.flowParseRestrictedIdentifier = function flowParseRestrictedIdentifier(liberal) {
this.checkReservedType(this.state.value, this.state.start);
return this.parseIdentifier(liberal);
};
_proto.flowParseTypeAlias = function flowParseTypeAlias(node) {
node.id = this.flowParseRestrictedIdentifier();
if (this.isRelational("<")) {
node.typeParameters = this.flowParseTypeParameterDeclaration();
} else {
node.typeParameters = null;
}
node.right = this.flowParseTypeInitialiser(types.eq);
this.semicolon();
return this.finishNode(node, "TypeAlias");
};
_proto.flowParseOpaqueType = function flowParseOpaqueType(node, declare) {
this.expectContextual("type");
node.id = this.flowParseRestrictedIdentifier(true);
if (this.isRelational("<")) {
node.typeParameters = this.flowParseTypeParameterDeclaration();
} else {
node.typeParameters = null;
}
node.supertype = null;
if (this.match(types.colon)) {
node.supertype = this.flowParseTypeInitialiser(types.colon);
}
node.impltype = null;
if (!declare) {
node.impltype = this.flowParseTypeInitialiser(types.eq);
}
this.semicolon();
return this.finishNode(node, "OpaqueType");
};
_proto.flowParseTypeParameter = function flowParseTypeParameter(allowDefault, requireDefault) {
if (allowDefault === void 0) {
allowDefault = true;
}
if (requireDefault === void 0) {
requireDefault = false;
}
if (!allowDefault && requireDefault) {
throw new Error("Cannot disallow a default value (`allowDefault`) while also requiring it (`requireDefault`).");
}
var nodeStart = this.state.start;
var node = this.startNode();
var variance = this.flowParseVariance();
var ident = this.flowParseTypeAnnotatableIdentifier();
node.name = ident.name;
node.variance = variance;
node.bound = ident.typeAnnotation;
if (this.match(types.eq)) {
if (allowDefault) {
this.eat(types.eq);
node.default = this.flowParseType();
} else {
this.unexpected();
}
} else {
if (requireDefault) {
this.unexpected(nodeStart, "Type parameter declaration needs a default, since a preceding type parameter declaration has a default.");
}
}
return this.finishNode(node, "TypeParameter");
};
_proto.flowParseTypeParameterDeclaration = function flowParseTypeParameterDeclaration(allowDefault) {
if (allowDefault === void 0) {
allowDefault = true;
}
var oldInType = this.state.inType;
var node = this.startNode();
node.params = [];
this.state.inType = true;
if (this.isRelational("<") || this.match(types.jsxTagStart)) {
this.next();
} else {
this.unexpected();
}
var defaultRequired = false;
do {
var typeParameter = this.flowParseTypeParameter(allowDefault, defaultRequired);
node.params.push(typeParameter);
if (typeParameter.default) {
defaultRequired = true;
}
if (!this.isRelational(">")) {
this.expect(types.comma);
}
} while (!this.isRelational(">"));
this.expectRelational(">");
this.state.inType = oldInType;
return this.finishNode(node, "TypeParameterDeclaration");
};
_proto.flowParseTypeParameterInstantiation = function flowParseTypeParameterInstantiation() {
var node = this.startNode();
var oldInType = this.state.inType;
node.params = [];
this.state.inType = true;
this.expectRelation