diff --git a/node_modules/espree/espree.js b/node_modules/espree/espree.js index 97e11b58..44c222f7 100644 --- a/node_modules/espree/espree.js +++ b/node_modules/espree/espree.js @@ -427,27 +427,43 @@ function scanPunctuator() { case 41: // ) close bracket case 59: // ; semicolon case 44: // , comma - case 123: // { open curly brace - case 125: // } close curly brace case 91: // [ case 93: // ] case 58: // : case 63: // ? case 126: // ~ ++index; - if (extra.tokenize) { - if (code === 40) { - extra.openParenToken = extra.tokens.length; - } else if (code === 123) { - extra.openCurlyToken = extra.tokens.length; - } + + if (extra.tokenize && code === 40) { + extra.openParenToken = extra.tokens.length; } - // 123 is {, 125 is } - if (code === 123) { - state.curlyStack.push("{"); - } else if (code === 125) { - state.curlyStack.pop(); + return { + type: Token.Punctuator, + value: String.fromCharCode(code), + lineNumber: lineNumber, + lineStart: lineStart, + range: [start, index] + }; + + case 123: // { open curly brace + case 125: // } close curly brace + ++index; + + if (extra.tokenize && code === 123) { + extra.openCurlyToken = extra.tokens.length; + } + + // lookahead2 function can cause tokens to be scanned twice and in doing so + // would wreck the curly stack by pushing the same token onto the stack twice. + // curlyLastIndex ensures each token is pushed or popped exactly once + if (index > state.curlyLastIndex) { + state.curlyLastIndex = index; + if (code === 123) { + state.curlyStack.push("{"); + } else { + state.curlyStack.pop(); + } } return { @@ -958,7 +974,6 @@ function scanTemplate() { var cooked = "", ch, escapedSequence, - octal = false, start = index, terminated = false, tail = false, @@ -983,8 +998,13 @@ function scanTemplate() { } else if (ch === "\\") { ch = source[index++]; escapedSequence = scanEscapeSequence(ch); + + if (escapedSequence.octal) { + throwError({}, Messages.TemplateOctalLiteral); + } + cooked += escapedSequence.ch; - octal = escapedSequence.octal || octal; + } else if (syntax.isLineTerminator(ch.charCodeAt(0))) { ++lineNumber; if (ch === "\r" && source[index] === "\n") { @@ -1001,12 +1021,16 @@ function scanTemplate() { throwError({}, Messages.UnexpectedToken, "ILLEGAL"); } - if (!tail) { - state.curlyStack.push("template"); - } + if (index > state.curlyLastIndex) { + state.curlyLastIndex = index; - if (!head) { - state.curlyStack.pop(); + if (!tail) { + state.curlyStack.push("template"); + } + + if (!head) { + state.curlyStack.pop(); + } } return { @@ -1017,40 +1041,12 @@ function scanTemplate() { }, head: head, tail: tail, - octal: octal, lineNumber: lineNumber, lineStart: lineStart, range: [start, index] }; } -/** - * Scan a template string element and return a ASTNode representation - * @param {Object} options Scan options - * @param {Object} options.head True if this element is the first in the - * template string, false otherwise. - * @returns {ASTNode} The template element node - * @private - */ -function scanTemplateElement(options) { - var startsWith, template; - - lookahead = null; - skipComment(); - - startsWith = (options.head) ? "`" : "}"; - - if (source[index] !== startsWith) { - throwError({}, Messages.UnexpectedToken, "ILLEGAL"); - } - - template = scanTemplate(); - - peek(); - - return template; -} - function testRegExp(pattern, flags) { var tmp = pattern, validFlags = "gmsi"; @@ -1484,22 +1480,6 @@ function lex() { lineNumber = token.lineNumber; lineStart = token.lineStart; - if (token.type === Token.Template) { - if (token.tail) { - state.curlyStack.pop(); - } else { - state.curlyStack.push("template"); - } - } - - if (token.value === "{") { - state.curlyStack.push("{"); - } - - if (token.value === "}") { - state.curlyStack.pop(); - } - return token; } @@ -2435,7 +2415,7 @@ function tryParseMethodDefinition(token, key, computed, marker) { rest: null }; if (match(")")) { - throwErrorTolerant(lookahead, Messages.UnexpectedToken); + throwErrorTolerant(lookahead, Messages.UnexpectedToken, lookahead.value); } else { parseParam(options); if (options.defaultCount === 0) { @@ -2506,7 +2486,8 @@ function parseObjectProperty() { * Check for getters and setters. Be careful! "get" and "set" are legal * method names. It's only a getter or setter if followed by a space. */ - if (token.value === "get" && !(match(":") || match("("))) { + if (token.value === "get" && + !(match(":") || match("(") || match(",") || match("}"))) { computed = (lookahead.value === "["); key = parseObjectPropertyKey(); methodMarker = markerCreate(); @@ -2530,7 +2511,8 @@ function parseObjectProperty() { ); } - if (token.value === "set" && !(match(":") || match("("))) { + if (token.value === "set" && + !(match(":") || match("(") || match(",") || match("}"))) { computed = (lookahead.value === "["); key = parseObjectPropertyKey(); methodMarker = markerCreate(); @@ -2775,19 +2757,32 @@ function parseObjectInitialiser() { /** * Parse a template string element and return its ASTNode representation - * @param {Object} options Parsing & scanning options - * @param {Object} options.head True if this element is the first in the + * @param {Object} option Parsing & scanning options + * @param {Object} option.head True if this element is the first in the * template string, false otherwise. * @returns {ASTNode} The template element node with marker info applied * @private */ -function parseTemplateElement(options) { - var marker = markerCreate(), - token = scanTemplateElement(options); - if (strict && token.octal) { - throwError(token, Messages.StrictOctalLiteral); +function parseTemplateElement(option) { + var marker, token; + + if (lookahead.type !== Token.Template || (option.head && !lookahead.head)) { + throwError({}, Messages.UnexpectedToken, "ILLEGAL"); } - return markerApply(marker, astNodeFactory.createTemplateElement({ raw: token.value.raw, cooked: token.value.cooked }, token.tail)); + + marker = markerCreate(); + token = lex(); + + return markerApply( + marker, + astNodeFactory.createTemplateElement( + { + raw: token.value.raw, + cooked: token.value.cooked + }, + token.tail + ) + ); } /** @@ -3003,7 +2998,7 @@ function parseLeftHandSideExpressionAllowCall() { expr = markerApply(marker, astNodeFactory.createMemberExpression("[", expr, parseComputedMember())); } else if (match(".")) { expr = markerApply(marker, astNodeFactory.createMemberExpression(".", expr, parseNonComputedMember())); - } else if (!lookahead.tail) { + } else { expr = markerApply(marker, astNodeFactory.createTaggedTemplateExpression(expr, parseTemplateLiteral())); } } @@ -4137,7 +4132,11 @@ function parseThrowStatement() { function parseCatchClause() { var param, body, - marker = markerCreate(); + marker = markerCreate(), + allowDestructuring = extra.ecmaFeatures.destructuring, + options = { + paramSet: new StringMap() + }; expectKeyword("catch"); @@ -4146,9 +4145,25 @@ function parseCatchClause() { throwUnexpected(lookahead); } - param = parseVariableIdentifier(); + if (match("[")) { + if (!allowDestructuring) { + throwUnexpected(lookahead); + } + param = parseArrayInitialiser(); + reinterpretAsDestructuredParameter(options, param); + } else if (match("{")) { + + if (!allowDestructuring) { + throwUnexpected(lookahead); + } + param = parseObjectInitialiser(); + reinterpretAsDestructuredParameter(options, param); + } else { + param = parseVariableIdentifier(); + } + // 12.14.1 - if (strict && syntax.isRestrictedWord(param.name)) { + if (strict && param.name && syntax.isRestrictedWord(param.name)) { throwErrorTolerant({}, Messages.StrictCatchVariable); } @@ -5219,6 +5234,8 @@ function tokenize(code, options) { inSwitch: false, lastCommentStart: -1, yieldAllowed: false, + curlyStack: [], + curlyLastIndex: 0, inJSXSpreadAttribute: false, inJSXChild: false, inJSXTag: false @@ -5240,9 +5257,6 @@ function tokenize(code, options) { extra.openParenToken = -1; extra.openCurlyToken = -1; - // Needed when using template string tokenization - state.curlyStack = []; - extra.range = (typeof options.range === "boolean") && options.range; extra.loc = (typeof options.loc === "boolean") && options.loc; @@ -5324,6 +5338,8 @@ function parse(code, options) { inSwitch: false, lastCommentStart: -1, yieldAllowed: false, + curlyStack: [], + curlyLastIndex: 0, inJSXSpreadAttribute: false, inJSXChild: false, inJSXTag: false diff --git a/node_modules/espree/lib/messages.js b/node_modules/espree/lib/messages.js index 2618f993..a7780b64 100644 --- a/node_modules/espree/lib/messages.js +++ b/node_modules/espree/lib/messages.js @@ -68,6 +68,7 @@ module.exports = { StrictVarName: "Variable name may not be eval or arguments in strict mode", StrictParamName: "Parameter name eval or arguments is not allowed in strict mode", StrictParamDupe: "Strict mode function may not have duplicate parameter names", + TemplateOctalLiteral: "Octal literals are not allowed in template strings.", ParameterAfterRestParameter: "Rest parameter must be final parameter of an argument list", DefaultRestParameter: "Rest parameter can not have a default value", ElementAfterSpreadElement: "Spread must be the final element of an element list", diff --git a/node_modules/espree/package.json b/node_modules/espree/package.json index fe4557f1..b3306b0d 100644 --- a/node_modules/espree/package.json +++ b/node_modules/espree/package.json @@ -11,7 +11,7 @@ "esparse": "./bin/esparse.js", "esvalidate": "./bin/esvalidate.js" }, - "version": "1.12.0", + "version": "1.12.3", "files": [ "bin", "lib", @@ -85,8 +85,8 @@ "dependencies": {}, "readme": "# Espree\n\nEspree is an actively-maintained fork Esprima, a high performance,\nstandard-compliant [ECMAScript](http://www.ecma-international.org/publications/standards/Ecma-262.htm)\nparser written in ECMAScript (also popularly known as\n[JavaScript](http://en.wikipedia.org/wiki/JavaScript)).\n\n## Features\n\n- Full support for ECMAScript 5.1 ([ECMA-262](http://www.ecma-international.org/publications/standards/Ecma-262.htm))\n- Sensible syntax tree format compatible with Mozilla\n[Parser AST](https://developer.mozilla.org/en/SpiderMonkey/Parser_API)\n- Optional tracking of syntax node location (index-based and line-column)\n- Heavily tested (> 650 unit tests) with full code coverage\n\n## Usage\n\nInstall:\n\n```\nnpm i espree --save\n```\n\nAnd in your Node.js code:\n\n```javascript\nvar espree = require(\"espree\");\n\nvar ast = espree.parse(code);\n```\n\nThere is a second argument to `parse()` that allows you to specify various options:\n\n```javascript\nvar espree = require(\"espree\");\n\nvar ast = espree.parse(code, {\n\n // attach range information to each node\n range: true,\n\n // attach line/column location information to each node\n loc: true,\n\n // create a top-level comments array containing all comments\n comments: true,\n\n // attach comments to the closest relevant node as leadingComments and\n // trailingComments\n attachComment: true,\n\n // create a top-level tokens array containing all tokens\n tokens: true,\n\n // try to continue parsing if an error is encountered, store errors in a\n // top-level errors array\n tolerant: true,\n\n // specify parsing features (default only has blockBindings: true)\n ecmaFeatures: {\n\n // enable parsing of arrow functions\n arrowFunctions: true,\n\n // enable parsing of let/const\n blockBindings: true,\n\n // enable parsing of destructured arrays and objects\n destructuring: true,\n\n // enable parsing of regular expression y flag\n regexYFlag: true,\n\n // enable parsing of regular expression u flag\n regexUFlag: true,\n\n // enable parsing of template strings\n templateStrings: true,\n\n // enable parsing of binary literals\n binaryLiterals: true,\n\n // enable parsing of ES6 octal literals\n octalLiterals: true,\n\n // enable parsing unicode code point escape sequences\n unicodeCodePointEscapes: true,\n\n // enable parsing of default parameters\n defaultParams: true,\n\n // enable parsing of rest parameters\n restParams: true,\n\n // enable parsing of for-of statement\n forOf: true,\n\n // enable parsing computed object literal properties\n objectLiteralComputedProperties: true,\n\n // enable parsing of shorthand object literal methods\n objectLiteralShorthandMethods: true,\n\n // enable parsing of shorthand object literal properties\n objectLiteralShorthandProperties: true,\n\n // Allow duplicate object literal properties (except '__proto__')\n objectLiteralDuplicateProperties: true,\n\n // enable parsing of generators/yield\n generators: true,\n\n // enable parsing spread operator\n spread: true,\n\n // enable parsing classes\n classes: true,\n\n // enable parsing of modules\n modules: true,\n\n // enable React JSX parsing\n jsx: true,\n\n // enable return in global scope\n globalReturn: true\n }\n});\n```\n\n## Plans\n\nEspree starts as a fork of Esprima v1.2.2, the last stable published released of Esprima before work on ECMAScript 6 began. Espree's first version is therefore v1.2.2 and is 100% compatible with Esprima v1.2.2 as a drop-in replacement. The version number will be incremented based on [semantic versioning](http://semver.org/) as features and bug fixes are added.\n\nThe immediate plans are:\n\n1. Move away from giant files and move towards small, modular files that are easier to manage.\n1. Move towards CommonJS for all files and use browserify to create browser bundles.\n1. Support ECMAScript version filtering, allowing users to specify which version the parser should work in (similar to Acorn's `ecmaVersion` property).\n1. Add tests to track comment attachment.\n1. Add well-thought-out features that are useful for tools developers.\n1. Add full support for ECMAScript 6.\n1. Add optional parsing of JSX.\n\n## Esprima Compatibility Going Forward\n\nThe primary goal is to produce the exact same AST structure as Esprima and Acorn, and that takes precedence over anything else. (The AST structure being the SpiderMonkey Parser API with JSX extensions.) Separate from that, Espree may deviate from what Esprima outputs in terms of where and how comments are attached, as well as what additional information is available on AST nodes. That is to say, Espree may add more things to the AST nodes than Esprima does but the overall AST structure produced will be the same.\n\nEspree may also deviate from Esprima in the interface it exposes.\n\n## Frequent and Incremental Releases\n\nEspree will not do giant releases. Releases will happen periodically as changes are made and incremental releases will be made towards larger goals. For instance, we will not have one big release for ECMAScript 6 support. Instead, we will implement ECMAScript 6, piece-by-piece, hiding those pieces behind an `ecmaFeatures` property that allows you to opt-in to use those features.\n\n## Contributing\n\nIssues and pull requests will be triaged and responded to as quickly as possible. We operate under the [ESLint Contributor Guidelines](http://eslint.org/docs/developer-guide/contributing.html), so please be sure to read them before contributing. If you're not sure where to dig in, check out the [issues](https://github.com/eslint/espree/issues).\n\nEspree is licensed under a permissive BSD 3-clause license.\n\n## Build Commands\n\n* `npm test` - run all linting and tests\n* `npm run lint` - run all linting\n* `npm run browserify` - creates a version of Espree that is usable in a browser\n\n## Known Incompatibilities\n\nIn an effort to help those wanting to transition from other parsers to Espree, the following is a list of noteworthy incompatibilities with other parsers. These are known differences that we do not intend to change.\n\n### Esprima 1.2.2\n\n* None.\n\n### Esprima/Harmony Branch\n\n* Esprima/Harmony uses a different comment attachment algorithm that results in some comments being added in different places than Espree. The algorithm Espree uses is the same one used in Esprima 1.2.2.\n* Template tokens have a `head` property in addition to `tail`. Esprima has only `tail`.\n\n### Esprima-FB\n\n* All Esprima/Harmony incompatibilities.\n\n## Frequently Asked Questions\n\n### Why are you forking Esprima?\n\n[ESLint](http://eslint.org) has been relying on Esprima as its parser from the beginning. While that was fine when the JavaScript language was evolving slowly, the pace of development has increased dramatically and Esprima has fallen behind. ESLint, like many other tools reliant on Esprima, has been stuck in using new JavaScript language features until Esprima updates, and that has caused our users frustration.\n\nWe decided the only way for us to move forward was to create our own parser, bringing us inline with JSHint and JSLint, and allowing us to keep implementing new features as we need them. We chose to fork Esprima instead of starting from scratch in order to move as quickly as possible with a compatible API.\n\n### Have you tried working with Esprima?\n\nYes. Since the start of ESLint, we've regularly filed bugs and feature requests with Esprima. Unfortunately, we've been unable to make much progress towards getting our needs addressed.\n\n### Why don't you just use Facebook's Esprima fork?\n\n`esprima-fb` is Facebook's Esprima fork that features JSX and Flow type annotations. We tried working with `esprima-fb` in our evaluation of how to support ECMAScript 6 and JSX in ESLint. Unfortunately, we were hampered by bugs that were part of Esprima (not necessarily Facebook's code). Since `esprima-fb` tracks the Esprima Harmony branch, that means we still were unable to get fixes or features we needed in a timely manner.\n\n### Why don't you just use Acorn?\n\nAcorn is a great JavaScript parser that produces an AST that is compatible with Esprima. Unfortunately, ESLint relies on more than just the AST to do its job. It relies on Esprima's tokens and comment attachment features to get a complete picture of the source code. We investigated switching to Acorn, but the inconsistencies between Esprima and Acorn created too much work for a project like ESLint.\n\nWe expect there are other tools like ESLint that rely on more than just the AST produced by Esprima, and so a drop-in replacement will help those projects as well as ESLint.\n\n### What ECMAScript 6 features do you support?\n\nPlease see the [tracking issue](https://github.com/eslint/espree/issues/10) for the most up-to-date information.\n\n### Why use Espree instead of Esprima?\n\n* Faster turnaround time on bug fixes\n* More frequent releases\n* Better communication and responsiveness to issues\n* Ongoing development\n\n### Why use Espree instead of Esprima-FB?\n\n* Opt-in to just the ECMAScript 6 features you want\n* JSX support is off by default, so you're not forced to use it to use ECMAScript 6\n* Stricter ECMAScript 6 support\n", "readmeFilename": "README.md", - "_id": "espree@1.12.0", - "_shasum": "18980ba9121d325a626d9e732e2e47f524278383", + "_id": "espree@1.12.3", + "_shasum": "04ceeada91bda077a38c040c125ba186b13bb3cc", "_from": "espree@~1.12.0", - "_resolved": "https://registry.npmjs.org/espree/-/espree-1.12.0.tgz" + "_resolved": "https://registry.npmjs.org/espree/-/espree-1.12.3.tgz" } diff --git a/package.json b/package.json index 825220cc..c3fcbd40 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "bluebird": "~2.9.14", "catharsis": "~0.8.6", "escape-string-regexp": "~1.0.2", - "espree": "~1.12.0", + "espree": "~1.12.3", "js2xmlparser": "~0.1.7", "marked": "~0.3.2", "requizzle": "~0.2.0",