react / wstein / node_modules / browserify / node_modules / syntax-error / node_modules / acorn / dist / acorn_loose.js
80551 views(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}(g.acorn || (g.acorn = {})).loose = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){1"use strict";23var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { "default": obj }; };45exports.parse_dammit = parse_dammit;6exports.__esModule = true;7// Acorn: Loose parser8//9// This module provides an alternative parser (`parse_dammit`) that10// exposes that same interface as `parse`, but will try to parse11// anything as JavaScript, repairing syntax error the best it can.12// There are circumstances in which it will raise an error and give13// up, but they are very rare. The resulting AST will be a mostly14// valid JavaScript AST (as per the [Mozilla parser API][api], except15// that:16//17// - Return outside functions is allowed18//19// - Label consistency (no conflicts, break only to existing labels)20// is not enforced.21//22// - Bogus Identifier nodes with a name of `"✖"` are inserted whenever23// the parser got too confused to return anything meaningful.24//25// [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API26//27// The expected use for this is to *first* try `acorn.parse`, and only28// if that fails switch to `parse_dammit`. The loose parser might29// parse badly indented code incorrectly, so **don't** use it as30// your default parser.31//32// Quite a lot of acorn.js is duplicated here. The alternative was to33// add a *lot* of extra cruft to that file, making it less readable34// and slower. Copying and editing the code allowed me to make35// invasive changes and simplifications without creating a complicated36// tangle.3738var acorn = _interopRequireWildcard(_dereq_(".."));3940var _state = _dereq_("./state");4142var LooseParser = _state.LooseParser;4344_dereq_("./tokenize");4546_dereq_("./parseutil");4748_dereq_("./statement");4950_dereq_("./expression");5152exports.LooseParser = _state.LooseParser;5354acorn.defaultOptions.tabSize = 4;5556function parse_dammit(input, options) {57var p = new LooseParser(input, options);58p.next();59return p.parseTopLevel();60}6162acorn.parse_dammit = parse_dammit;63acorn.LooseParser = LooseParser;6465},{"..":2,"./expression":3,"./parseutil":4,"./state":5,"./statement":6,"./tokenize":7}],2:[function(_dereq_,module,exports){66"use strict";6768module.exports = typeof acorn != "undefined" ? acorn : _dereq_("./acorn");6970},{}],3:[function(_dereq_,module,exports){71"use strict";7273var LooseParser = _dereq_("./state").LooseParser;7475var isDummy = _dereq_("./parseutil").isDummy;7677var tt = _dereq_("..").tokTypes;7879var lp = LooseParser.prototype;8081lp.checkLVal = function (expr, binding) {82if (!expr) return expr;83switch (expr.type) {84case "Identifier":85return expr;8687case "MemberExpression":88return binding ? this.dummyIdent() : expr;8990case "ParenthesizedExpression":91expr.expression = this.checkLVal(expr.expression, binding);92return expr;9394// FIXME recursively check contents95case "ObjectPattern":96case "ArrayPattern":97case "RestElement":98case "AssignmentPattern":99if (this.options.ecmaVersion >= 6) return expr;100101default:102return this.dummyIdent();103}104};105106lp.parseExpression = function (noIn) {107var start = this.storeCurrentPos();108var expr = this.parseMaybeAssign(noIn);109if (this.tok.type === tt.comma) {110var node = this.startNodeAt(start);111node.expressions = [expr];112while (this.eat(tt.comma)) node.expressions.push(this.parseMaybeAssign(noIn));113return this.finishNode(node, "SequenceExpression");114}115return expr;116};117118lp.parseParenExpression = function () {119this.pushCx();120this.expect(tt.parenL);121var val = this.parseExpression();122this.popCx();123this.expect(tt.parenR);124return val;125};126127lp.parseMaybeAssign = function (noIn) {128var start = this.storeCurrentPos();129var left = this.parseMaybeConditional(noIn);130if (this.tok.type.isAssign) {131var node = this.startNodeAt(start);132node.operator = this.tok.value;133node.left = this.tok.type === tt.eq ? this.toAssignable(left) : this.checkLVal(left);134this.next();135node.right = this.parseMaybeAssign(noIn);136return this.finishNode(node, "AssignmentExpression");137}138return left;139};140141lp.parseMaybeConditional = function (noIn) {142var start = this.storeCurrentPos();143var expr = this.parseExprOps(noIn);144if (this.eat(tt.question)) {145var node = this.startNodeAt(start);146node.test = expr;147node.consequent = this.parseMaybeAssign();148node.alternate = this.expect(tt.colon) ? this.parseMaybeAssign(noIn) : this.dummyIdent();149return this.finishNode(node, "ConditionalExpression");150}151return expr;152};153154lp.parseExprOps = function (noIn) {155var start = this.storeCurrentPos();156var indent = this.curIndent,157line = this.curLineStart;158return this.parseExprOp(this.parseMaybeUnary(noIn), start, -1, noIn, indent, line);159};160161lp.parseExprOp = function (left, start, minPrec, noIn, indent, line) {162if (this.curLineStart != line && this.curIndent < indent && this.tokenStartsLine()) return left;163var prec = this.tok.type.binop;164if (prec != null && (!noIn || this.tok.type !== tt._in)) {165if (prec > minPrec) {166var node = this.startNodeAt(start);167node.left = left;168node.operator = this.tok.value;169this.next();170if (this.curLineStart != line && this.curIndent < indent && this.tokenStartsLine()) {171node.right = this.dummyIdent();172} else {173var rightStart = this.storeCurrentPos();174node.right = this.parseExprOp(this.parseMaybeUnary(noIn), rightStart, prec, noIn, indent, line);175}176this.finishNode(node, /&&|\|\|/.test(node.operator) ? "LogicalExpression" : "BinaryExpression");177return this.parseExprOp(node, start, minPrec, noIn, indent, line);178}179}180return left;181};182183lp.parseMaybeUnary = function (noIn) {184if (this.tok.type.prefix) {185var node = this.startNode(),186update = this.tok.type === tt.incDec;187node.operator = this.tok.value;188node.prefix = true;189this.next();190node.argument = this.parseMaybeUnary(noIn);191if (update) node.argument = this.checkLVal(node.argument);192return this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");193} else if (this.tok.type === tt.ellipsis) {194var node = this.startNode();195this.next();196node.argument = this.parseMaybeUnary(noIn);197return this.finishNode(node, "SpreadElement");198}199var start = this.storeCurrentPos();200var expr = this.parseExprSubscripts();201while (this.tok.type.postfix && !this.canInsertSemicolon()) {202var node = this.startNodeAt(start);203node.operator = this.tok.value;204node.prefix = false;205node.argument = this.checkLVal(expr);206this.next();207expr = this.finishNode(node, "UpdateExpression");208}209return expr;210};211212lp.parseExprSubscripts = function () {213var start = this.storeCurrentPos();214return this.parseSubscripts(this.parseExprAtom(), start, false, this.curIndent, this.curLineStart);215};216217lp.parseSubscripts = function (base, start, noCalls, startIndent, line) {218for (;;) {219if (this.curLineStart != line && this.curIndent <= startIndent && this.tokenStartsLine()) {220if (this.tok.type == tt.dot && this.curIndent == startIndent) --startIndent;else return base;221}222223if (this.eat(tt.dot)) {224var node = this.startNodeAt(start);225node.object = base;226if (this.curLineStart != line && this.curIndent <= startIndent && this.tokenStartsLine()) node.property = this.dummyIdent();else node.property = this.parsePropertyAccessor() || this.dummyIdent();227node.computed = false;228base = this.finishNode(node, "MemberExpression");229} else if (this.tok.type == tt.bracketL) {230this.pushCx();231this.next();232var node = this.startNodeAt(start);233node.object = base;234node.property = this.parseExpression();235node.computed = true;236this.popCx();237this.expect(tt.bracketR);238base = this.finishNode(node, "MemberExpression");239} else if (!noCalls && this.tok.type == tt.parenL) {240var node = this.startNodeAt(start);241node.callee = base;242node.arguments = this.parseExprList(tt.parenR);243base = this.finishNode(node, "CallExpression");244} else if (this.tok.type == tt.backQuote) {245var node = this.startNodeAt(start);246node.tag = base;247node.quasi = this.parseTemplate();248base = this.finishNode(node, "TaggedTemplateExpression");249} else {250return base;251}252}253};254255lp.parseExprAtom = function () {256var node = undefined;257switch (this.tok.type) {258case tt._this:259case tt._super:260var type = this.tok.type === tt._this ? "ThisExpression" : "Super";261node = this.startNode();262this.next();263return this.finishNode(node, type);264265case tt.name:266var start = this.storeCurrentPos();267var id = this.parseIdent();268return this.eat(tt.arrow) ? this.parseArrowExpression(this.startNodeAt(start), [id]) : id;269270case tt.regexp:271node = this.startNode();272var val = this.tok.value;273node.regex = { pattern: val.pattern, flags: val.flags };274node.value = val.value;275node.raw = this.input.slice(this.tok.start, this.tok.end);276this.next();277return this.finishNode(node, "Literal");278279case tt.num:case tt.string:280node = this.startNode();281node.value = this.tok.value;282node.raw = this.input.slice(this.tok.start, this.tok.end);283this.next();284return this.finishNode(node, "Literal");285286case tt._null:case tt._true:case tt._false:287node = this.startNode();288node.value = this.tok.type === tt._null ? null : this.tok.type === tt._true;289node.raw = this.tok.type.keyword;290this.next();291return this.finishNode(node, "Literal");292293case tt.parenL:294var parenStart = this.storeCurrentPos();295this.next();296var inner = this.parseExpression();297this.expect(tt.parenR);298if (this.eat(tt.arrow)) {299return this.parseArrowExpression(this.startNodeAt(parenStart), inner.expressions || (isDummy(inner) ? [] : [inner]));300}301if (this.options.preserveParens) {302var par = this.startNodeAt(parenStart);303par.expression = inner;304inner = this.finishNode(par, "ParenthesizedExpression");305}306return inner;307308case tt.bracketL:309node = this.startNode();310node.elements = this.parseExprList(tt.bracketR, true);311return this.finishNode(node, "ArrayExpression");312313case tt.braceL:314return this.parseObj();315316case tt._class:317return this.parseClass();318319case tt._function:320node = this.startNode();321this.next();322return this.parseFunction(node, false);323324case tt._new:325return this.parseNew();326327case tt._yield:328node = this.startNode();329this.next();330if (this.semicolon() || this.canInsertSemicolon() || this.tok.type != tt.star && !this.tok.type.startsExpr) {331node.delegate = false;332node.argument = null;333} else {334node.delegate = this.eat(tt.star);335node.argument = this.parseMaybeAssign();336}337return this.finishNode(node, "YieldExpression");338339case tt.backQuote:340return this.parseTemplate();341342default:343return this.dummyIdent();344}345};346347lp.parseNew = function () {348var node = this.startNode(),349startIndent = this.curIndent,350line = this.curLineStart;351var meta = this.parseIdent(true);352if (this.options.ecmaVersion >= 6 && this.eat(tt.dot)) {353node.meta = meta;354node.property = this.parseIdent(true);355return this.finishNode(node, "MetaProperty");356}357var start = this.storeCurrentPos();358node.callee = this.parseSubscripts(this.parseExprAtom(), start, true, startIndent, line);359if (this.tok.type == tt.parenL) {360node.arguments = this.parseExprList(tt.parenR);361} else {362node.arguments = [];363}364return this.finishNode(node, "NewExpression");365};366367lp.parseTemplateElement = function () {368var elem = this.startNode();369elem.value = {370raw: this.input.slice(this.tok.start, this.tok.end),371cooked: this.tok.value372};373this.next();374elem.tail = this.tok.type === tt.backQuote;375return this.finishNode(elem, "TemplateElement");376};377378lp.parseTemplate = function () {379var node = this.startNode();380this.next();381node.expressions = [];382var curElt = this.parseTemplateElement();383node.quasis = [curElt];384while (!curElt.tail) {385this.next();386node.expressions.push(this.parseExpression());387if (this.expect(tt.braceR)) {388curElt = this.parseTemplateElement();389} else {390curElt = this.startNode();391curElt.value = { cooked: "", raw: "" };392curElt.tail = true;393}394node.quasis.push(curElt);395}396this.expect(tt.backQuote);397return this.finishNode(node, "TemplateLiteral");398};399400lp.parseObj = function () {401var node = this.startNode();402node.properties = [];403this.pushCx();404var indent = this.curIndent + 1,405line = this.curLineStart;406this.eat(tt.braceL);407if (this.curIndent + 1 < indent) {408indent = this.curIndent;line = this.curLineStart;409}410while (!this.closes(tt.braceR, indent, line)) {411var prop = this.startNode(),412isGenerator = undefined,413start = undefined;414if (this.options.ecmaVersion >= 6) {415start = this.storeCurrentPos();416prop.method = false;417prop.shorthand = false;418isGenerator = this.eat(tt.star);419}420this.parsePropertyName(prop);421if (isDummy(prop.key)) {422if (isDummy(this.parseMaybeAssign())) this.next();this.eat(tt.comma);continue;423}424if (this.eat(tt.colon)) {425prop.kind = "init";426prop.value = this.parseMaybeAssign();427} else if (this.options.ecmaVersion >= 6 && (this.tok.type === tt.parenL || this.tok.type === tt.braceL)) {428prop.kind = "init";429prop.method = true;430prop.value = this.parseMethod(isGenerator);431} else if (this.options.ecmaVersion >= 5 && prop.key.type === "Identifier" && !prop.computed && (prop.key.name === "get" || prop.key.name === "set") && (this.tok.type != tt.comma && this.tok.type != tt.braceR)) {432prop.kind = prop.key.name;433this.parsePropertyName(prop);434prop.value = this.parseMethod(false);435} else {436prop.kind = "init";437if (this.options.ecmaVersion >= 6) {438if (this.eat(tt.eq)) {439var assign = this.startNodeAt(start);440assign.operator = "=";441assign.left = prop.key;442assign.right = this.parseMaybeAssign();443prop.value = this.finishNode(assign, "AssignmentExpression");444} else {445prop.value = prop.key;446}447} else {448prop.value = this.dummyIdent();449}450prop.shorthand = true;451}452node.properties.push(this.finishNode(prop, "Property"));453this.eat(tt.comma);454}455this.popCx();456if (!this.eat(tt.braceR)) {457// If there is no closing brace, make the node span to the start458// of the next token (this is useful for Tern)459this.last.end = this.tok.start;460if (this.options.locations) this.last.loc.end = this.tok.loc.start;461}462return this.finishNode(node, "ObjectExpression");463};464465lp.parsePropertyName = function (prop) {466if (this.options.ecmaVersion >= 6) {467if (this.eat(tt.bracketL)) {468prop.computed = true;469prop.key = this.parseExpression();470this.expect(tt.bracketR);471return;472} else {473prop.computed = false;474}475}476var key = this.tok.type === tt.num || this.tok.type === tt.string ? this.parseExprAtom() : this.parseIdent();477prop.key = key || this.dummyIdent();478};479480lp.parsePropertyAccessor = function () {481if (this.tok.type === tt.name || this.tok.type.keyword) return this.parseIdent();482};483484lp.parseIdent = function () {485var name = this.tok.type === tt.name ? this.tok.value : this.tok.type.keyword;486if (!name) return this.dummyIdent();487var node = this.startNode();488this.next();489node.name = name;490return this.finishNode(node, "Identifier");491};492493lp.initFunction = function (node) {494node.id = null;495node.params = [];496if (this.options.ecmaVersion >= 6) {497node.generator = false;498node.expression = false;499}500};501502// Convert existing expression atom to assignable pattern503// if possible.504505lp.toAssignable = function (node, binding) {506if (this.options.ecmaVersion >= 6 && node) {507switch (node.type) {508case "ObjectExpression":509node.type = "ObjectPattern";510var props = node.properties;511for (var i = 0; i < props.length; i++) {512this.toAssignable(props[i].value, binding);513}break;514515case "ArrayExpression":516node.type = "ArrayPattern";517this.toAssignableList(node.elements, binding);518break;519520case "SpreadElement":521node.type = "RestElement";522node.argument = this.toAssignable(node.argument, binding);523break;524525case "AssignmentExpression":526node.type = "AssignmentPattern";527break;528}529}530return this.checkLVal(node, binding);531};532533lp.toAssignableList = function (exprList, binding) {534for (var i = 0; i < exprList.length; i++) {535exprList[i] = this.toAssignable(exprList[i], binding);536}return exprList;537};538539lp.parseFunctionParams = function (params) {540params = this.parseExprList(tt.parenR);541return this.toAssignableList(params, true);542};543544lp.parseMethod = function (isGenerator) {545var node = this.startNode();546this.initFunction(node);547node.params = this.parseFunctionParams();548node.generator = isGenerator || false;549node.expression = this.options.ecmaVersion >= 6 && this.tok.type !== tt.braceL;550node.body = node.expression ? this.parseMaybeAssign() : this.parseBlock();551return this.finishNode(node, "FunctionExpression");552};553554lp.parseArrowExpression = function (node, params) {555this.initFunction(node);556node.params = this.toAssignableList(params, true);557node.expression = this.tok.type !== tt.braceL;558node.body = node.expression ? this.parseMaybeAssign() : this.parseBlock();559return this.finishNode(node, "ArrowFunctionExpression");560};561562lp.parseExprList = function (close, allowEmpty) {563this.pushCx();564var indent = this.curIndent,565line = this.curLineStart,566elts = [];567this.next(); // Opening bracket568while (!this.closes(close, indent + 1, line)) {569if (this.eat(tt.comma)) {570elts.push(allowEmpty ? null : this.dummyIdent());571continue;572}573var elt = this.parseMaybeAssign();574if (isDummy(elt)) {575if (this.closes(close, indent, line)) break;576this.next();577} else {578elts.push(elt);579}580this.eat(tt.comma);581}582this.popCx();583if (!this.eat(close)) {584// If there is no closing brace, make the node span to the start585// of the next token (this is useful for Tern)586this.last.end = this.tok.start;587if (this.options.locations) this.last.loc.end = this.tok.loc.start;588}589return elts;590};591592},{"..":2,"./parseutil":4,"./state":5}],4:[function(_dereq_,module,exports){593"use strict";594595exports.isDummy = isDummy;596exports.__esModule = true;597598var LooseParser = _dereq_("./state").LooseParser;599600var _ = _dereq_("..");601602var Node = _.Node;603var SourceLocation = _.SourceLocation;604var lineBreak = _.lineBreak;605var isNewLine = _.isNewLine;606var tt = _.tokTypes;607608var lp = LooseParser.prototype;609610lp.startNode = function () {611var node = new Node();612node.start = this.tok.start;613if (this.options.locations) node.loc = new SourceLocation(this.toks, this.tok.loc.start);614if (this.options.directSourceFile) node.sourceFile = this.options.directSourceFile;615if (this.options.ranges) node.range = [this.tok.start, 0];616return node;617};618619lp.storeCurrentPos = function () {620return this.options.locations ? [this.tok.start, this.tok.loc.start] : this.tok.start;621};622623lp.startNodeAt = function (pos) {624var node = new Node();625if (this.options.locations) {626node.start = pos[0];627node.loc = new SourceLocation(this.toks, pos[1]);628pos = pos[0];629} else {630node.start = pos;631}632if (this.options.directSourceFile) node.sourceFile = this.options.directSourceFile;633if (this.options.ranges) node.range = [pos, 0];634return node;635};636637lp.finishNode = function (node, type) {638node.type = type;639node.end = this.last.end;640if (this.options.locations) node.loc.end = this.last.loc.end;641if (this.options.ranges) node.range[1] = this.last.end;642return node;643};644645lp.dummyIdent = function () {646var dummy = this.startNode();647dummy.name = "✖";648return this.finishNode(dummy, "Identifier");649};650651function isDummy(node) {652return node.name == "✖";653}654655lp.eat = function (type) {656if (this.tok.type === type) {657this.next();658return true;659} else {660return false;661}662};663664lp.isContextual = function (name) {665return this.tok.type === tt.name && this.tok.value === name;666};667668lp.eatContextual = function (name) {669return this.tok.value === name && this.eat(tt.name);670};671672lp.canInsertSemicolon = function () {673return this.tok.type === tt.eof || this.tok.type === tt.braceR || lineBreak.test(this.input.slice(this.last.end, this.tok.start));674};675676lp.semicolon = function () {677return this.eat(tt.semi);678};679680lp.expect = function (type) {681if (this.eat(type)) return true;682for (var i = 1; i <= 2; i++) {683if (this.lookAhead(i).type == type) {684for (var j = 0; j < i; j++) {685this.next();686}return true;687}688}689};690691lp.pushCx = function () {692this.context.push(this.curIndent);693};694lp.popCx = function () {695this.curIndent = this.context.pop();696};697698lp.lineEnd = function (pos) {699while (pos < this.input.length && !isNewLine(this.input.charCodeAt(pos))) ++pos;700return pos;701};702703lp.indentationAfter = function (pos) {704for (var count = 0;; ++pos) {705var ch = this.input.charCodeAt(pos);706if (ch === 32) ++count;else if (ch === 9) count += this.options.tabSize;else return count;707}708};709710lp.closes = function (closeTok, indent, line, blockHeuristic) {711if (this.tok.type === closeTok || this.tok.type === tt.eof) return true;712return line != this.curLineStart && this.curIndent < indent && this.tokenStartsLine() && (!blockHeuristic || this.nextLineStart >= this.input.length || this.indentationAfter(this.nextLineStart) < indent);713};714715lp.tokenStartsLine = function () {716for (var p = this.tok.start - 1; p >= this.curLineStart; --p) {717var ch = this.input.charCodeAt(p);718if (ch !== 9 && ch !== 32) return false;719}720return true;721};722723},{"..":2,"./state":5}],5:[function(_dereq_,module,exports){724"use strict";725726exports.LooseParser = LooseParser;727exports.__esModule = true;728729var _ = _dereq_("..");730731var tokenizer = _.tokenizer;732var SourceLocation = _.SourceLocation;733var tt = _.tokTypes;734735function LooseParser(input, options) {736this.toks = tokenizer(input, options);737this.options = this.toks.options;738this.input = this.toks.input;739this.tok = this.last = { type: tt.eof, start: 0, end: 0 };740if (this.options.locations) {741var here = this.toks.curPosition();742this.tok.loc = new SourceLocation(this.toks, here, here);743}744this.ahead = []; // Tokens ahead745this.context = []; // Indentation contexted746this.curIndent = 0;747this.curLineStart = 0;748this.nextLineStart = this.lineEnd(this.curLineStart) + 1;749}750751},{"..":2}],6:[function(_dereq_,module,exports){752"use strict";753754var LooseParser = _dereq_("./state").LooseParser;755756var isDummy = _dereq_("./parseutil").isDummy;757758var _ = _dereq_("..");759760var getLineInfo = _.getLineInfo;761var tt = _.tokTypes;762763var lp = LooseParser.prototype;764765lp.parseTopLevel = function () {766var node = this.startNodeAt(this.options.locations ? [0, getLineInfo(this.input, 0)] : 0);767node.body = [];768while (this.tok.type !== tt.eof) node.body.push(this.parseStatement());769this.last = this.tok;770if (this.options.ecmaVersion >= 6) {771node.sourceType = this.options.sourceType;772}773return this.finishNode(node, "Program");774};775776lp.parseStatement = function () {777var starttype = this.tok.type,778node = this.startNode();779780switch (starttype) {781case tt._break:case tt._continue:782this.next();783var isBreak = starttype === tt._break;784if (this.semicolon() || this.canInsertSemicolon()) {785node.label = null;786} else {787node.label = this.tok.type === tt.name ? this.parseIdent() : null;788this.semicolon();789}790return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");791792case tt._debugger:793this.next();794this.semicolon();795return this.finishNode(node, "DebuggerStatement");796797case tt._do:798this.next();799node.body = this.parseStatement();800node.test = this.eat(tt._while) ? this.parseParenExpression() : this.dummyIdent();801this.semicolon();802return this.finishNode(node, "DoWhileStatement");803804case tt._for:805this.next();806this.pushCx();807this.expect(tt.parenL);808if (this.tok.type === tt.semi) return this.parseFor(node, null);809if (this.tok.type === tt._var || this.tok.type === tt._let || this.tok.type === tt._const) {810var _init = this.parseVar(true);811if (_init.declarations.length === 1 && (this.tok.type === tt._in || this.isContextual("of"))) {812return this.parseForIn(node, _init);813}814return this.parseFor(node, _init);815}816var init = this.parseExpression(true);817if (this.tok.type === tt._in || this.isContextual("of")) return this.parseForIn(node, this.toAssignable(init));818return this.parseFor(node, init);819820case tt._function:821this.next();822return this.parseFunction(node, true);823824case tt._if:825this.next();826node.test = this.parseParenExpression();827node.consequent = this.parseStatement();828node.alternate = this.eat(tt._else) ? this.parseStatement() : null;829return this.finishNode(node, "IfStatement");830831case tt._return:832this.next();833if (this.eat(tt.semi) || this.canInsertSemicolon()) node.argument = null;else {834node.argument = this.parseExpression();this.semicolon();835}836return this.finishNode(node, "ReturnStatement");837838case tt._switch:839var blockIndent = this.curIndent,840line = this.curLineStart;841this.next();842node.discriminant = this.parseParenExpression();843node.cases = [];844this.pushCx();845this.expect(tt.braceL);846847var cur = undefined;848while (!this.closes(tt.braceR, blockIndent, line, true)) {849if (this.tok.type === tt._case || this.tok.type === tt._default) {850var isCase = this.tok.type === tt._case;851if (cur) this.finishNode(cur, "SwitchCase");852node.cases.push(cur = this.startNode());853cur.consequent = [];854this.next();855if (isCase) cur.test = this.parseExpression();else cur.test = null;856this.expect(tt.colon);857} else {858if (!cur) {859node.cases.push(cur = this.startNode());860cur.consequent = [];861cur.test = null;862}863cur.consequent.push(this.parseStatement());864}865}866if (cur) this.finishNode(cur, "SwitchCase");867this.popCx();868this.eat(tt.braceR);869return this.finishNode(node, "SwitchStatement");870871case tt._throw:872this.next();873node.argument = this.parseExpression();874this.semicolon();875return this.finishNode(node, "ThrowStatement");876877case tt._try:878this.next();879node.block = this.parseBlock();880node.handler = null;881if (this.tok.type === tt._catch) {882var clause = this.startNode();883this.next();884this.expect(tt.parenL);885clause.param = this.toAssignable(this.parseExprAtom(), true);886this.expect(tt.parenR);887clause.guard = null;888clause.body = this.parseBlock();889node.handler = this.finishNode(clause, "CatchClause");890}891node.finalizer = this.eat(tt._finally) ? this.parseBlock() : null;892if (!node.handler && !node.finalizer) return node.block;893return this.finishNode(node, "TryStatement");894895case tt._var:896case tt._let:897case tt._const:898return this.parseVar();899900case tt._while:901this.next();902node.test = this.parseParenExpression();903node.body = this.parseStatement();904return this.finishNode(node, "WhileStatement");905906case tt._with:907this.next();908node.object = this.parseParenExpression();909node.body = this.parseStatement();910return this.finishNode(node, "WithStatement");911912case tt.braceL:913return this.parseBlock();914915case tt.semi:916this.next();917return this.finishNode(node, "EmptyStatement");918919case tt._class:920return this.parseClass(true);921922case tt._import:923return this.parseImport();924925case tt._export:926return this.parseExport();927928default:929var expr = this.parseExpression();930if (isDummy(expr)) {931this.next();932if (this.tok.type === tt.eof) return this.finishNode(node, "EmptyStatement");933return this.parseStatement();934} else if (starttype === tt.name && expr.type === "Identifier" && this.eat(tt.colon)) {935node.body = this.parseStatement();936node.label = expr;937return this.finishNode(node, "LabeledStatement");938} else {939node.expression = expr;940this.semicolon();941return this.finishNode(node, "ExpressionStatement");942}943}944};945946lp.parseBlock = function () {947var node = this.startNode();948this.pushCx();949this.expect(tt.braceL);950var blockIndent = this.curIndent,951line = this.curLineStart;952node.body = [];953while (!this.closes(tt.braceR, blockIndent, line, true)) node.body.push(this.parseStatement());954this.popCx();955this.eat(tt.braceR);956return this.finishNode(node, "BlockStatement");957};958959lp.parseFor = function (node, init) {960node.init = init;961node.test = node.update = null;962if (this.eat(tt.semi) && this.tok.type !== tt.semi) node.test = this.parseExpression();963if (this.eat(tt.semi) && this.tok.type !== tt.parenR) node.update = this.parseExpression();964this.popCx();965this.expect(tt.parenR);966node.body = this.parseStatement();967return this.finishNode(node, "ForStatement");968};969970lp.parseForIn = function (node, init) {971var type = this.tok.type === tt._in ? "ForInStatement" : "ForOfStatement";972this.next();973node.left = init;974node.right = this.parseExpression();975this.popCx();976this.expect(tt.parenR);977node.body = this.parseStatement();978return this.finishNode(node, type);979};980981lp.parseVar = function (noIn) {982var node = this.startNode();983node.kind = this.tok.type.keyword;984this.next();985node.declarations = [];986do {987var decl = this.startNode();988decl.id = this.options.ecmaVersion >= 6 ? this.toAssignable(this.parseExprAtom(), true) : this.parseIdent();989decl.init = this.eat(tt.eq) ? this.parseMaybeAssign(noIn) : null;990node.declarations.push(this.finishNode(decl, "VariableDeclarator"));991} while (this.eat(tt.comma));992if (!node.declarations.length) {993var decl = this.startNode();994decl.id = this.dummyIdent();995node.declarations.push(this.finishNode(decl, "VariableDeclarator"));996}997if (!noIn) this.semicolon();998return this.finishNode(node, "VariableDeclaration");999};10001001lp.parseClass = function (isStatement) {1002var node = this.startNode();1003this.next();1004if (this.tok.type === tt.name) node.id = this.parseIdent();else if (isStatement) node.id = this.dummyIdent();else node.id = null;1005node.superClass = this.eat(tt._extends) ? this.parseExpression() : null;1006node.body = this.startNode();1007node.body.body = [];1008this.pushCx();1009var indent = this.curIndent + 1,1010line = this.curLineStart;1011this.eat(tt.braceL);1012if (this.curIndent + 1 < indent) {1013indent = this.curIndent;line = this.curLineStart;1014}1015while (!this.closes(tt.braceR, indent, line)) {1016if (this.semicolon()) continue;1017var method = this.startNode(),1018isGenerator = undefined;1019if (this.options.ecmaVersion >= 6) {1020method["static"] = false;1021isGenerator = this.eat(tt.star);1022}1023this.parsePropertyName(method);1024if (isDummy(method.key)) {1025if (isDummy(this.parseMaybeAssign())) this.next();this.eat(tt.comma);continue;1026}1027if (method.key.type === "Identifier" && !method.computed && method.key.name === "static" && (this.tok.type != tt.parenL && this.tok.type != tt.braceL)) {1028method["static"] = true;1029isGenerator = this.eat(tt.star);1030this.parsePropertyName(method);1031} else {1032method["static"] = false;1033}1034if (this.options.ecmaVersion >= 5 && method.key.type === "Identifier" && !method.computed && (method.key.name === "get" || method.key.name === "set") && this.tok.type !== tt.parenL && this.tok.type !== tt.braceL) {1035method.kind = method.key.name;1036this.parsePropertyName(method);1037method.value = this.parseMethod(false);1038} else {1039if (!method.computed && !method["static"] && !isGenerator && (method.key.type === "Identifier" && method.key.name === "constructor" || method.key.type === "Literal" && method.key.value === "constructor")) {1040method.kind = "constructor";1041} else {1042method.kind = "method";1043}1044method.value = this.parseMethod(isGenerator);1045}1046node.body.body.push(this.finishNode(method, "MethodDefinition"));1047}1048this.popCx();1049if (!this.eat(tt.braceR)) {1050// If there is no closing brace, make the node span to the start1051// of the next token (this is useful for Tern)1052this.last.end = this.tok.start;1053if (this.options.locations) this.last.loc.end = this.tok.loc.start;1054}1055this.semicolon();1056this.finishNode(node.body, "ClassBody");1057return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");1058};10591060lp.parseFunction = function (node, isStatement) {1061this.initFunction(node);1062if (this.options.ecmaVersion >= 6) {1063node.generator = this.eat(tt.star);1064}1065if (this.tok.type === tt.name) node.id = this.parseIdent();else if (isStatement) node.id = this.dummyIdent();1066node.params = this.parseFunctionParams();1067node.body = this.parseBlock();1068return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression");1069};10701071lp.parseExport = function () {1072var node = this.startNode();1073this.next();1074if (this.eat(tt.star)) {1075node.source = this.eatContextual("from") ? this.parseExprAtom() : null;1076return this.finishNode(node, "ExportAllDeclaration");1077}1078if (this.eat(tt._default)) {1079var expr = this.parseMaybeAssign();1080if (expr.id) {1081switch (expr.type) {1082case "FunctionExpression":1083expr.type = "FunctionDeclaration";break;1084case "ClassExpression":1085expr.type = "ClassDeclaration";break;1086}1087}1088node.declaration = expr;1089this.semicolon();1090return this.finishNode(node, "ExportDefaultDeclaration");1091}1092if (this.tok.type.keyword) {1093node.declaration = this.parseStatement();1094node.specifiers = [];1095node.source = null;1096} else {1097node.declaration = null;1098node.specifiers = this.parseExportSpecifierList();1099node.source = this.eatContextual("from") ? this.parseExprAtom() : null;1100this.semicolon();1101}1102return this.finishNode(node, "ExportNamedDeclaration");1103};11041105lp.parseImport = function () {1106var node = this.startNode();1107this.next();1108if (this.tok.type === tt.string) {1109node.specifiers = [];1110node.source = this.parseExprAtom();1111node.kind = "";1112} else {1113var elt = undefined;1114if (this.tok.type === tt.name && this.tok.value !== "from") {1115elt = this.startNode();1116elt.local = this.parseIdent();1117this.finishNode(elt, "ImportDefaultSpecifier");1118this.eat(tt.comma);1119}1120node.specifiers = this.parseImportSpecifierList();1121node.source = this.eatContextual("from") ? this.parseExprAtom() : null;1122if (elt) node.specifiers.unshift(elt);1123}1124this.semicolon();1125return this.finishNode(node, "ImportDeclaration");1126};11271128lp.parseImportSpecifierList = function () {1129var elts = [];1130if (this.tok.type === tt.star) {1131var elt = this.startNode();1132this.next();1133if (this.eatContextual("as")) elt.local = this.parseIdent();1134elts.push(this.finishNode(elt, "ImportNamespaceSpecifier"));1135} else {1136var indent = this.curIndent,1137line = this.curLineStart,1138continuedLine = this.nextLineStart;1139this.pushCx();1140this.eat(tt.braceL);1141if (this.curLineStart > continuedLine) continuedLine = this.curLineStart;1142while (!this.closes(tt.braceR, indent + (this.curLineStart <= continuedLine ? 1 : 0), line)) {1143var elt = this.startNode();1144if (this.eat(tt.star)) {1145if (this.eatContextual("as")) elt.local = this.parseIdent();1146this.finishNode(elt, "ImportNamespaceSpecifier");1147} else {1148if (this.isContextual("from")) break;1149elt.imported = this.parseIdent();1150elt.local = this.eatContextual("as") ? this.parseIdent() : elt.imported;1151this.finishNode(elt, "ImportSpecifier");1152}1153elts.push(elt);1154this.eat(tt.comma);1155}1156this.eat(tt.braceR);1157this.popCx();1158}1159return elts;1160};11611162lp.parseExportSpecifierList = function () {1163var elts = [];1164var indent = this.curIndent,1165line = this.curLineStart,1166continuedLine = this.nextLineStart;1167this.pushCx();1168this.eat(tt.braceL);1169if (this.curLineStart > continuedLine) continuedLine = this.curLineStart;1170while (!this.closes(tt.braceR, indent + (this.curLineStart <= continuedLine ? 1 : 0), line)) {1171if (this.isContextual("from")) break;1172var elt = this.startNode();1173elt.local = this.parseIdent();1174elt.exported = this.eatContextual("as") ? this.parseIdent() : elt.local;1175this.finishNode(elt, "ExportSpecifier");1176elts.push(elt);1177this.eat(tt.comma);1178}1179this.eat(tt.braceR);1180this.popCx();1181return elts;1182};11831184},{"..":2,"./parseutil":4,"./state":5}],7:[function(_dereq_,module,exports){1185"use strict";11861187var _ = _dereq_("..");11881189var tt = _.tokTypes;1190var Token = _.Token;1191var isNewLine = _.isNewLine;1192var SourceLocation = _.SourceLocation;1193var getLineInfo = _.getLineInfo;1194var lineBreakG = _.lineBreakG;11951196var LooseParser = _dereq_("./state").LooseParser;11971198var lp = LooseParser.prototype;11991200function isSpace(ch) {1201return ch < 14 && ch > 8 || ch === 32 || ch === 160 || isNewLine(ch);1202}12031204lp.next = function () {1205this.last = this.tok;1206if (this.ahead.length) this.tok = this.ahead.shift();else this.tok = this.readToken();12071208if (this.tok.start >= this.nextLineStart) {1209while (this.tok.start >= this.nextLineStart) {1210this.curLineStart = this.nextLineStart;1211this.nextLineStart = this.lineEnd(this.curLineStart) + 1;1212}1213this.curIndent = this.indentationAfter(this.curLineStart);1214}1215};12161217lp.readToken = function () {1218for (;;) {1219try {1220this.toks.next();1221if (this.toks.type === tt.dot && this.input.substr(this.toks.end, 1) === "." && this.options.ecmaVersion >= 6) {1222this.toks.end++;1223this.toks.type = tt.ellipsis;1224}1225return new Token(this.toks);1226} catch (e) {1227if (!(e instanceof SyntaxError)) throw e;12281229// Try to skip some text, based on the error message, and then continue1230var msg = e.message,1231pos = e.raisedAt,1232replace = true;1233if (/unterminated/i.test(msg)) {1234pos = this.lineEnd(e.pos + 1);1235if (/string/.test(msg)) {1236replace = { start: e.pos, end: pos, type: tt.string, value: this.input.slice(e.pos + 1, pos) };1237} else if (/regular expr/i.test(msg)) {1238var re = this.input.slice(e.pos, pos);1239try {1240re = new RegExp(re);1241} catch (e) {}1242replace = { start: e.pos, end: pos, type: tt.regexp, value: re };1243} else if (/template/.test(msg)) {1244replace = { start: e.pos, end: pos,1245type: tt.template,1246value: this.input.slice(e.pos, pos) };1247} else {1248replace = false;1249}1250} else if (/invalid (unicode|regexp|number)|expecting unicode|octal literal|is reserved|directly after number|expected number in radix/i.test(msg)) {1251while (pos < this.input.length && !isSpace(this.input.charCodeAt(pos))) ++pos;1252} else if (/character escape|expected hexadecimal/i.test(msg)) {1253while (pos < this.input.length) {1254var ch = this.input.charCodeAt(pos++);1255if (ch === 34 || ch === 39 || isNewLine(ch)) break;1256}1257} else if (/unexpected character/i.test(msg)) {1258pos++;1259replace = false;1260} else if (/regular expression/i.test(msg)) {1261replace = true;1262} else {1263throw e;1264}1265this.resetTo(pos);1266if (replace === true) replace = { start: pos, end: pos, type: tt.name, value: "✖" };1267if (replace) {1268if (this.options.locations) replace.loc = new SourceLocation(this.toks, getLineInfo(this.input, replace.start), getLineInfo(this.input, replace.end));1269return replace;1270}1271}1272}1273};12741275lp.resetTo = function (pos) {1276this.toks.pos = pos;1277var ch = this.input.charAt(pos - 1);1278this.toks.exprAllowed = !ch || /[\[\{\(,;:?\/*=+\-~!|&%^<>]/.test(ch) || /[enwfd]/.test(ch) && /\b(keywords|case|else|return|throw|new|in|(instance|type)of|delete|void)$/.test(this.input.slice(pos - 10, pos));12791280if (this.options.locations) {1281this.toks.curLine = 1;1282this.toks.lineStart = lineBreakG.lastIndex = 0;1283var match = undefined;1284while ((match = lineBreakG.exec(this.input)) && match.index < pos) {1285++this.toks.curLine;1286this.toks.lineStart = match.index + match[0].length;1287}1288}1289};12901291lp.lookAhead = function (n) {1292while (n > this.ahead.length) this.ahead.push(this.readToken());1293return this.ahead[n - 1];1294};12951296},{"..":2,"./state":5}]},{},[1])(1)1297});12981299