aboutsummaryrefslogtreecommitdiff
path: root/tools/node_modules/eslint/node_modules/acorn/dist/acorn.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/node_modules/eslint/node_modules/acorn/dist/acorn.js')
-rw-r--r--tools/node_modules/eslint/node_modules/acorn/dist/acorn.js112
1 files changed, 85 insertions, 27 deletions
diff --git a/tools/node_modules/eslint/node_modules/acorn/dist/acorn.js b/tools/node_modules/eslint/node_modules/acorn/dist/acorn.js
index df8576ac4e..e4a0fe3a3b 100644
--- a/tools/node_modules/eslint/node_modules/acorn/dist/acorn.js
+++ b/tools/node_modules/eslint/node_modules/acorn/dist/acorn.js
@@ -542,7 +542,7 @@ var Parser = function Parser(options, input, startPos) {
this.regexpState = null;
};
-var prototypeAccessors = { inFunction: { configurable: true },inGenerator: { configurable: true },inAsync: { configurable: true },allowSuper: { configurable: true },allowDirectSuper: { configurable: true } };
+var prototypeAccessors = { inFunction: { configurable: true },inGenerator: { configurable: true },inAsync: { configurable: true },allowSuper: { configurable: true },allowDirectSuper: { configurable: true },treatFunctionsAsVar: { configurable: true } };
Parser.prototype.parse = function parse () {
var node = this.options.program || this.startNode();
@@ -555,6 +555,7 @@ prototypeAccessors.inGenerator.get = function () { return (this.currentVarScope(
prototypeAccessors.inAsync.get = function () { return (this.currentVarScope().flags & SCOPE_ASYNC) > 0 };
prototypeAccessors.allowSuper.get = function () { return (this.currentThisScope().flags & SCOPE_SUPER) > 0 };
prototypeAccessors.allowDirectSuper.get = function () { return (this.currentThisScope().flags & SCOPE_DIRECT_SUPER) > 0 };
+prototypeAccessors.treatFunctionsAsVar.get = function () { return this.treatFunctionsAsVarInScope(this.currentScope()) };
// Switch to a getter for 7.0.0.
Parser.prototype.inNonArrowFunction = function inNonArrowFunction () { return (this.currentThisScope().flags & SCOPE_FUNCTION) > 0 };
@@ -588,17 +589,24 @@ var pp = Parser.prototype;
// ## Parser utilities
-var literal = /^(?:'((?:\\.|[^'])*?)'|"((?:\\.|[^"])*?)"|;)/;
+var literal = /^(?:'((?:\\.|[^'])*?)'|"((?:\\.|[^"])*?)")/;
pp.strictDirective = function(start) {
var this$1 = this;
for (;;) {
+ // Try to find string literal.
skipWhiteSpace.lastIndex = start;
start += skipWhiteSpace.exec(this$1.input)[0].length;
var match = literal.exec(this$1.input.slice(start));
if (!match) { return false }
if ((match[1] || match[2]) === "use strict") { return true }
start += match[0].length;
+
+ // Skip semicolon, if any.
+ skipWhiteSpace.lastIndex = start;
+ start += skipWhiteSpace.exec(this$1.input)[0].length;
+ if (this$1.input[start] === ';')
+ { start++; }
}
};
@@ -750,13 +758,19 @@ pp$1.parseTopLevel = function(node) {
var loopLabel = {kind: "loop"};
var switchLabel = {kind: "switch"};
-pp$1.isLet = function() {
+pp$1.isLet = function(context) {
if (this.options.ecmaVersion < 6 || !this.isContextual("let")) { return false }
skipWhiteSpace.lastIndex = this.pos;
var skip = skipWhiteSpace.exec(this.input);
var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
- if (nextCh === 123 && !lineBreak.test(this.input.slice(this.end, next)) // '{'
- || nextCh === 91) { return true } // '['
+ // For ambiguous cases, determine if a LexicalDeclaration (or only a
+ // Statement) is allowed here. If context is not empty then only a Statement
+ // is allowed. However, `let [` is an explicit negative lookahead for
+ // ExpressionStatement, so special-case it first.
+ if (nextCh === 91) { return true } // '['
+ if (context) { return false }
+
+ if (nextCh === 123) { return true } // '{'
if (isIdentifierStart(nextCh, true)) {
var pos = next + 1;
while (isIdentifierChar(this.input.charCodeAt(pos), true)) { ++pos; }
@@ -791,7 +805,7 @@ pp$1.isAsyncFunction = function() {
pp$1.parseStatement = function(context, topLevel, exports) {
var starttype = this.type, node = this.startNode(), kind;
- if (this.isLet()) {
+ if (this.isLet(context)) {
starttype = types._var;
kind = "let";
}
@@ -806,7 +820,10 @@ pp$1.parseStatement = function(context, topLevel, exports) {
case types._do: return this.parseDoStatement(node)
case types._for: return this.parseForStatement(node)
case types._function:
- if ((context && (this.strict || context !== "if")) && this.options.ecmaVersion >= 6) { this.unexpected(); }
+ // Function as sole body of either an if statement or a labeled statement
+ // works, but not when it is part of a labeled statement that is the sole
+ // body of an if statement.
+ if ((context && (this.strict || context !== "if" && context !== "label")) && this.options.ecmaVersion >= 6) { this.unexpected(); }
return this.parseFunctionStatement(node, false, !context)
case types._class:
if (context) { this.unexpected(); }
@@ -1113,11 +1130,7 @@ pp$1.parseLabeledStatement = function(node, maybeName, expr, context) {
} else { break }
}
this.labels.push({name: maybeName, kind: kind, statementStart: this.start});
- node.body = this.parseStatement(context);
- if (node.body.type === "ClassDeclaration" ||
- node.body.type === "VariableDeclaration" && node.body.kind !== "var" ||
- node.body.type === "FunctionDeclaration" && (this.strict || node.body.generator || node.body.async))
- { this.raiseRecoverable(node.body.start, "Invalid labeled declaration"); }
+ node.body = this.parseStatement(context ? context.indexOf("label") === -1 ? context + "label" : context : "label");
this.labels.pop();
node.label = expr;
return this.finishNode(node, "LabeledStatement")
@@ -1160,8 +1173,8 @@ pp$1.parseFor = function(node, init) {
this.expect(types.semi);
node.update = this.type === types.parenR ? null : this.parseExpression();
this.expect(types.parenR);
- this.exitScope();
node.body = this.parseStatement("for");
+ this.exitScope();
this.labels.pop();
return this.finishNode(node, "ForStatement")
};
@@ -1181,8 +1194,8 @@ pp$1.parseForIn = function(node, init) {
node.left = init;
node.right = type === "ForInStatement" ? this.parseExpression() : this.parseMaybeAssign();
this.expect(types.parenR);
- this.exitScope();
node.body = this.parseStatement("for");
+ this.exitScope();
this.labels.pop();
return this.finishNode(node, type)
};
@@ -1213,7 +1226,10 @@ pp$1.parseVar = function(node, isFor, kind) {
};
pp$1.parseVarId = function(decl, kind) {
- decl.id = this.parseBindingAtom(kind);
+ if ((kind === "const" || kind === "let") && this.isContextual("let")) {
+ this.raiseRecoverable(this.start, "let is disallowed as a lexically bound name");
+ }
+ decl.id = this.parseBindingAtom();
this.checkLVal(decl.id, kind === "var" ? BIND_VAR : BIND_LEXICAL, false);
};
@@ -1226,15 +1242,22 @@ var FUNC_NULLABLE_ID = 4;
pp$1.parseFunction = function(node, statement, allowExpressionBody, isAsync) {
this.initFunction(node);
- if (this.options.ecmaVersion >= 9 || this.options.ecmaVersion >= 6 && !isAsync)
- { node.generator = this.eat(types.star); }
+ if (this.options.ecmaVersion >= 9 || this.options.ecmaVersion >= 6 && !isAsync) {
+ if (this.type === types.star && (statement & FUNC_HANGING_STATEMENT))
+ { this.unexpected(); }
+ node.generator = this.eat(types.star);
+ }
if (this.options.ecmaVersion >= 8)
{ node.async = !!isAsync; }
if (statement & FUNC_STATEMENT) {
node.id = (statement & FUNC_NULLABLE_ID) && this.type !== types.name ? null : this.parseIdent();
if (node.id && !(statement & FUNC_HANGING_STATEMENT))
- { this.checkLVal(node.id, this.inModule && !this.inFunction ? BIND_LEXICAL : BIND_FUNCTION); }
+ // If it is a regular function declaration in sloppy mode, then it is
+ // subject to Annex B semantics (BIND_FUNCTION). Otherwise, the binding
+ // mode depends on properties of the current scope (see
+ // treatFunctionsAsVar).
+ { this.checkLVal(node.id, (this.strict || node.generator || node.async) ? this.treatFunctionsAsVar ? BIND_VAR : BIND_LEXICAL : BIND_FUNCTION); }
}
var oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos;
@@ -1267,6 +1290,11 @@ pp$1.parseClass = function(node, isStatement) {
this.next();
+ // ecma-262 14.6 Class Definitions
+ // A class definition is always strict mode code.
+ var oldStrict = this.strict;
+ this.strict = true;
+
this.parseClassId(node, isStatement);
this.parseClassSuper(node);
var classBody = this.startNode();
@@ -1284,6 +1312,7 @@ pp$1.parseClass = function(node, isStatement) {
}
}
node.body = this.finishNode(classBody, "ClassBody");
+ this.strict = oldStrict;
return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
};
@@ -1350,7 +1379,15 @@ pp$1.parseClassMethod = function(method, isGenerator, isAsync, allowsDirectSuper
};
pp$1.parseClassId = function(node, isStatement) {
- node.id = this.type === types.name ? this.parseIdent() : isStatement === true ? this.unexpected() : null;
+ if (this.type === types.name) {
+ node.id = this.parseIdent();
+ if (isStatement === true)
+ { this.checkLVal(node.id, BIND_LEXICAL, false); }
+ } else {
+ if (isStatement === true)
+ { this.unexpected(); }
+ node.id = null;
+ }
};
pp$1.parseClassSuper = function(node) {
@@ -1929,7 +1966,7 @@ pp$3.parseExpression = function(noIn, refDestructuringErrors) {
pp$3.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
if (this.isContextual("yield")) {
- if (this.inGenerator) { return this.parseYield() }
+ if (this.inGenerator) { return this.parseYield(noIn) }
// The tokenizer will assume an expression is allowed after
// `yield`, but this isn't that kind of yield
else { this.exprAllowed = false; }
@@ -2732,7 +2769,7 @@ pp$3.parseIdent = function(liberal, isBinding) {
// Parses yield expression inside generator.
-pp$3.parseYield = function() {
+pp$3.parseYield = function(noIn) {
if (!this.yieldPos) { this.yieldPos = this.start; }
var node = this.startNode();
@@ -2742,7 +2779,7 @@ pp$3.parseYield = function() {
node.argument = null;
} else {
node.delegate = this.eat(types.star);
- node.argument = this.parseMaybeAssign();
+ node.argument = this.parseMaybeAssign(noIn);
}
return this.finishNode(node, "YieldExpression")
};
@@ -2788,6 +2825,8 @@ var Scope = function Scope(flags) {
this.var = [];
// A list of lexically-declared names in the current lexical scope
this.lexical = [];
+ // A list of lexically-declared FunctionDeclaration names in the current lexical scope
+ this.functions = [];
};
// The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names.
@@ -2800,25 +2839,39 @@ pp$5.exitScope = function() {
this.scopeStack.pop();
};
+// The spec says:
+// > At the top level of a function, or script, function declarations are
+// > treated like var declarations rather than like lexical declarations.
+pp$5.treatFunctionsAsVarInScope = function(scope) {
+ return (scope.flags & SCOPE_FUNCTION) || !this.inModule && (scope.flags & SCOPE_TOP);
+};
+
pp$5.declareName = function(name, bindingType, pos) {
var this$1 = this;
var redeclared = false;
if (bindingType === BIND_LEXICAL) {
var scope = this.currentScope();
- redeclared = scope.lexical.indexOf(name) > -1 || scope.var.indexOf(name) > -1;
+ redeclared = scope.lexical.indexOf(name) > -1 || scope.functions.indexOf(name) > -1 || scope.var.indexOf(name) > -1;
scope.lexical.push(name);
} else if (bindingType === BIND_SIMPLE_CATCH) {
var scope$1 = this.currentScope();
scope$1.lexical.push(name);
} else if (bindingType === BIND_FUNCTION) {
var scope$2 = this.currentScope();
- redeclared = scope$2.lexical.indexOf(name) > -1;
- scope$2.var.push(name);
+ if (this.treatFunctionsAsVar)
+ { redeclared = scope$2.lexical.indexOf(name) > -1; }
+ else
+ { redeclared = scope$2.lexical.indexOf(name) > -1 || scope$2.var.indexOf(name) > -1; }
+ scope$2.functions.push(name);
} else {
for (var i = this.scopeStack.length - 1; i >= 0; --i) {
var scope$3 = this$1.scopeStack[i];
- if (scope$3.lexical.indexOf(name) > -1 && !(scope$3.flags & SCOPE_SIMPLE_CATCH) && scope$3.lexical[0] === name) { redeclared = true; }
+ if (scope$3.lexical.indexOf(name) > -1 && !(scope$3.flags & SCOPE_SIMPLE_CATCH) && scope$3.lexical[0] === name ||
+ !this$1.treatFunctionsAsVarInScope(scope$3) && scope$3.functions.indexOf(name) > -1) {
+ redeclared = true;
+ break
+ }
scope$3.var.push(name);
if (scope$3.flags & SCOPE_VAR) { break }
}
@@ -5198,6 +5251,11 @@ pp$8.readEscapedChar = function(inTemplate) {
}
return String.fromCharCode(octal)
}
+ if (isNewLine(ch)) {
+ // Unicode new line characters after \ get removed from output in both
+ // template literals and strings
+ return ""
+ }
return String.fromCharCode(ch)
}
};
@@ -5276,7 +5334,7 @@ pp$8.readWord = function() {
//
// [walk]: util/walk.js
-var version = "6.0.5";
+var version = "6.0.6";
// The main exported interface (under `self.acorn` when in the
// browser) is a `parse` function that takes a code string and