From de16502f7d117edef0b122387229ff3d050640dc Mon Sep 17 00:00:00 2001 From: angelozerr Date: Tue, 26 Jan 2016 19:17:23 +0100 Subject: [PATCH] Hack to support start/end location of eslint by waiting for https://github.com/eslint/eslint/issues/3307 --- demos/issue4.html | 117 + demos/resources/eslint/eslint.js | 40418 +++++++++++++++++------------ eslint.js | 50 +- package.json | 4 +- test/validate_default.js | 2 +- 5 files changed, 23352 insertions(+), 17239 deletions(-) create mode 100644 demos/issue4.html diff --git a/demos/issue4.html b/demos/issue4.html new file mode 100644 index 0000000..eb5ee49 --- /dev/null +++ b/demos/issue4.html @@ -0,0 +1,117 @@ + + +CodeMirror: Tern Demo + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

Tern ESLint Demo

+

+ +

Demonstrates integration of Tern +and CodeMirror. The following keys are bound:

+ +
+
Ctrl-Space
Autocomplete
+
Ctrl-I
Find type at cursor
+
Alt-.
Jump to definition (Alt-, to jump back)
+
Ctrl-Q
Rename variable
+
+ +

Documentation is sparse for now. See the top of +the script for a rough API +overview.

+ + + +
diff --git a/demos/resources/eslint/eslint.js b/demos/resources/eslint/eslint.js index c6635f9..3df9e91 100644 --- a/demos/resources/eslint/eslint.js +++ b/demos/resources/eslint/eslint.js @@ -1,970 +1,4 @@ require=(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 - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -"use strict"; - -//------------------------------------------------------------------------------ -// Requirements -//------------------------------------------------------------------------------ - -var astNodeTypes = require("./ast-node-types"); - -//------------------------------------------------------------------------------ -// Public -//------------------------------------------------------------------------------ - -module.exports = { - - /** - * Create an Array Expression ASTNode out of an array of elements - * @param {ASTNode[]} elements An array of ASTNode elements - * @returns {ASTNode} An ASTNode representing the entire array expression - */ - createArrayExpression: function(elements) { - return { - type: astNodeTypes.ArrayExpression, - elements: elements - }; - }, - - /** - * Create an Arrow Function Expression ASTNode - * @param {ASTNode} params The function arguments - * @param {ASTNode} body The function body - * @param {boolean} expression True if the arrow function is created via an expression. - * Always false for declarations, but kept here to be in sync with - * FunctionExpression objects. - * @returns {ASTNode} An ASTNode representing the entire arrow function expression - */ - createArrowFunctionExpression: function (params, body, expression) { - return { - type: astNodeTypes.ArrowFunctionExpression, - id: null, - params: params, - body: body, - generator: false, - expression: expression - }; - }, - - /** - * Create an ASTNode representation of an assignment expression - * @param {ASTNode} operator The assignment operator - * @param {ASTNode} left The left operand - * @param {ASTNode} right The right operand - * @returns {ASTNode} An ASTNode representing the entire assignment expression - */ - createAssignmentExpression: function(operator, left, right) { - return { - type: astNodeTypes.AssignmentExpression, - operator: operator, - left: left, - right: right - }; - }, - - /** - * Create an ASTNode representation of an assignment pattern (default parameters) - * @param {ASTNode} left The left operand - * @param {ASTNode} right The right operand - * @returns {ASTNode} An ASTNode representing the entire assignment pattern - */ - createAssignmentPattern: function(left, right) { - return { - type: astNodeTypes.AssignmentPattern, - left: left, - right: right - }; - }, - - /** - * Create an ASTNode representation of a binary expression - * @param {ASTNode} operator The assignment operator - * @param {ASTNode} left The left operand - * @param {ASTNode} right The right operand - * @returns {ASTNode} An ASTNode representing the entire binary expression - */ - createBinaryExpression: function(operator, left, right) { - var type = (operator === "||" || operator === "&&") ? astNodeTypes.LogicalExpression : - astNodeTypes.BinaryExpression; - return { - type: type, - operator: operator, - left: left, - right: right - }; - }, - - /** - * Create an ASTNode representation of a block statement - * @param {ASTNode} body The block statement body - * @returns {ASTNode} An ASTNode representing the entire block statement - */ - createBlockStatement: function(body) { - return { - type: astNodeTypes.BlockStatement, - body: body - }; - }, - - /** - * Create an ASTNode representation of a break statement - * @param {ASTNode} label The break statement label - * @returns {ASTNode} An ASTNode representing the break statement - */ - createBreakStatement: function(label) { - return { - type: astNodeTypes.BreakStatement, - label: label - }; - }, - - /** - * Create an ASTNode representation of a call expression - * @param {ASTNode} callee The function being called - * @param {ASTNode[]} args An array of ASTNodes representing the function call arguments - * @returns {ASTNode} An ASTNode representing the entire call expression - */ - createCallExpression: function(callee, args) { - return { - type: astNodeTypes.CallExpression, - callee: callee, - "arguments": args - }; - }, - - /** - * Create an ASTNode representation of a catch clause/block - * @param {ASTNode} param Any catch clause exeption/conditional parameter information - * @param {ASTNode} body The catch block body - * @returns {ASTNode} An ASTNode representing the entire catch clause - */ - createCatchClause: function(param, body) { - return { - type: astNodeTypes.CatchClause, - param: param, - body: body - }; - }, - - /** - * Creates an ASTNode representation of a class body. - * @param {ASTNode} body The node representing the body of the class. - * @returns {ASTNode} An ASTNode representing the class body. - */ - createClassBody: function(body) { - return { - type: astNodeTypes.ClassBody, - body: body - }; - }, - - createClassExpression: function(id, superClass, body) { - return { - type: astNodeTypes.ClassExpression, - id: id, - superClass: superClass, - body: body - }; - }, - - createClassDeclaration: function(id, superClass, body) { - return { - type: astNodeTypes.ClassDeclaration, - id: id, - superClass: superClass, - body: body - }; - }, - - createMethodDefinition: function(propertyType, kind, key, value, computed) { - return { - type: astNodeTypes.MethodDefinition, - key: key, - value: value, - kind: kind, - "static": propertyType === "static", - computed: computed - }; - }, - - createMetaProperty: function(meta, property) { - return { - type: astNodeTypes.MetaProperty, - meta: meta, - property: property - }; - }, - - /** - * Create an ASTNode representation of a conditional expression - * @param {ASTNode} test The conditional to evaluate - * @param {ASTNode} consequent The code to be run if the test returns true - * @param {ASTNode} alternate The code to be run if the test returns false - * @returns {ASTNode} An ASTNode representing the entire conditional expression - */ - createConditionalExpression: function(test, consequent, alternate) { - return { - type: astNodeTypes.ConditionalExpression, - test: test, - consequent: consequent, - alternate: alternate - }; - }, - - /** - * Create an ASTNode representation of a continue statement - * @param {?ASTNode} label The optional continue label (null if not set) - * @returns {ASTNode} An ASTNode representing the continue statement - */ - createContinueStatement: function(label) { - return { - type: astNodeTypes.ContinueStatement, - label: label - }; - }, - - /** - * Create an ASTNode representation of a debugger statement - * @returns {ASTNode} An ASTNode representing the debugger statement - */ - createDebuggerStatement: function() { - return { - type: astNodeTypes.DebuggerStatement - }; - }, - - /** - * Create an ASTNode representation of an empty statement - * @returns {ASTNode} An ASTNode representing an empty statement - */ - createEmptyStatement: function() { - return { - type: astNodeTypes.EmptyStatement - }; - }, - - /** - * Create an ASTNode representation of an expression statement - * @param {ASTNode} expression The expression - * @returns {ASTNode} An ASTNode representing an expression statement - */ - createExpressionStatement: function(expression) { - return { - type: astNodeTypes.ExpressionStatement, - expression: expression - }; - }, - - /** - * Create an ASTNode representation of a while statement - * @param {ASTNode} test The while conditional - * @param {ASTNode} body The while loop body - * @returns {ASTNode} An ASTNode representing a while statement - */ - createWhileStatement: function(test, body) { - return { - type: astNodeTypes.WhileStatement, - test: test, - body: body - }; - }, - - /** - * Create an ASTNode representation of a do..while statement - * @param {ASTNode} test The do..while conditional - * @param {ASTNode} body The do..while loop body - * @returns {ASTNode} An ASTNode representing a do..while statement - */ - createDoWhileStatement: function(test, body) { - return { - type: astNodeTypes.DoWhileStatement, - body: body, - test: test - }; - }, - - /** - * Create an ASTNode representation of a for statement - * @param {ASTNode} init The initialization expression - * @param {ASTNode} test The conditional test expression - * @param {ASTNode} update The update expression - * @param {ASTNode} body The statement body - * @returns {ASTNode} An ASTNode representing a for statement - */ - createForStatement: function(init, test, update, body) { - return { - type: astNodeTypes.ForStatement, - init: init, - test: test, - update: update, - body: body - }; - }, - - /** - * Create an ASTNode representation of a for..in statement - * @param {ASTNode} left The left-side variable for the property name - * @param {ASTNode} right The right-side object - * @param {ASTNode} body The statement body - * @returns {ASTNode} An ASTNode representing a for..in statement - */ - createForInStatement: function(left, right, body) { - return { - type: astNodeTypes.ForInStatement, - left: left, - right: right, - body: body, - each: false - }; - }, - - /** - * Create an ASTNode representation of a for..of statement - * @param {ASTNode} left The left-side variable for the property value - * @param {ASTNode} right The right-side object - * @param {ASTNode} body The statement body - * @returns {ASTNode} An ASTNode representing a for..of statement - */ - createForOfStatement: function(left, right, body) { - return { - type: astNodeTypes.ForOfStatement, - left: left, - right: right, - body: body - }; - }, - - /** - * Create an ASTNode representation of a function declaration - * @param {ASTNode} id The function name - * @param {ASTNode} params The function arguments - * @param {ASTNode} body The function body - * @param {boolean} generator True if the function is a generator, false if not. - * @param {boolean} expression True if the function is created via an expression. - * Always false for declarations, but kept here to be in sync with - * FunctionExpression objects. - * @returns {ASTNode} An ASTNode representing a function declaration - */ - createFunctionDeclaration: function (id, params, body, generator, expression) { - return { - type: astNodeTypes.FunctionDeclaration, - id: id, - params: params || [], - body: body, - generator: !!generator, - expression: !!expression - }; - }, - - /** - * Create an ASTNode representation of a function expression - * @param {ASTNode} id The function name - * @param {ASTNode} params The function arguments - * @param {ASTNode} body The function body - * @param {boolean} generator True if the function is a generator, false if not. - * @param {boolean} expression True if the function is created via an expression. - * @returns {ASTNode} An ASTNode representing a function declaration - */ - createFunctionExpression: function (id, params, body, generator, expression) { - return { - type: astNodeTypes.FunctionExpression, - id: id, - params: params || [], - body: body, - generator: !!generator, - expression: !!expression - }; - }, - - /** - * Create an ASTNode representation of an identifier - * @param {ASTNode} name The identifier name - * @returns {ASTNode} An ASTNode representing an identifier - */ - createIdentifier: function(name) { - return { - type: astNodeTypes.Identifier, - name: name - }; - }, - - /** - * Create an ASTNode representation of an if statement - * @param {ASTNode} test The if conditional expression - * @param {ASTNode} consequent The consequent if statement to run - * @param {ASTNode} alternate the "else" alternate statement - * @returns {ASTNode} An ASTNode representing an if statement - */ - createIfStatement: function(test, consequent, alternate) { - return { - type: astNodeTypes.IfStatement, - test: test, - consequent: consequent, - alternate: alternate - }; - }, - - /** - * Create an ASTNode representation of a labeled statement - * @param {ASTNode} label The statement label - * @param {ASTNode} body The labeled statement body - * @returns {ASTNode} An ASTNode representing a labeled statement - */ - createLabeledStatement: function(label, body) { - return { - type: astNodeTypes.LabeledStatement, - label: label, - body: body - }; - }, - - /** - * Create an ASTNode literal from the source code - * @param {ASTNode} token The ASTNode token - * @param {string} source The source code to get the literal from - * @returns {ASTNode} An ASTNode representing the new literal - */ - createLiteralFromSource: function(token, source) { - var node = { - type: astNodeTypes.Literal, - value: token.value, - raw: source.slice(token.range[0], token.range[1]) - }; - - // regular expressions have regex properties - if (token.regex) { - node.regex = token.regex; - } - - return node; - }, - - /** - * Create an ASTNode template element - * @param {Object} value Data on the element value - * @param {string} value.raw The raw template string - * @param {string} value.cooked The processed template string - * @param {boolean} tail True if this is the final element in a template string - * @returns {ASTNode} An ASTNode representing the template string element - */ - createTemplateElement: function(value, tail) { - return { - type: astNodeTypes.TemplateElement, - value: value, - tail: tail - }; - }, - - /** - * Create an ASTNode template literal - * @param {ASTNode[]} quasis An array of the template string elements - * @param {ASTNode[]} expressions An array of the template string expressions - * @returns {ASTNode} An ASTNode representing the template string - */ - createTemplateLiteral: function(quasis, expressions) { - return { - type: astNodeTypes.TemplateLiteral, - quasis: quasis, - expressions: expressions - }; - }, - - /** - * Create an ASTNode representation of a spread element - * @param {ASTNode} argument The array being spread - * @returns {ASTNode} An ASTNode representing a spread element - */ - createSpreadElement: function(argument) { - return { - type: astNodeTypes.SpreadElement, - argument: argument - }; - }, - - /** - * Create an ASTNode representation of an experimental rest property - * @param {ASTNode} argument The identifier being rested - * @returns {ASTNode} An ASTNode representing a rest element - */ - createExperimentalRestProperty: function(argument) { - return { - type: astNodeTypes.ExperimentalRestProperty, - argument: argument - }; - }, - - /** - * Create an ASTNode representation of an experimental spread property - * @param {ASTNode} argument The identifier being spread - * @returns {ASTNode} An ASTNode representing a spread element - */ - createExperimentalSpreadProperty: function(argument) { - return { - type: astNodeTypes.ExperimentalSpreadProperty, - argument: argument - }; - }, - - /** - * Create an ASTNode tagged template expression - * @param {ASTNode} tag The tag expression - * @param {ASTNode} quasi A TemplateLiteral ASTNode representing - * the template string itself. - * @returns {ASTNode} An ASTNode representing the tagged template - */ - createTaggedTemplateExpression: function(tag, quasi) { - return { - type: astNodeTypes.TaggedTemplateExpression, - tag: tag, - quasi: quasi - }; - }, - - /** - * Create an ASTNode representation of a member expression - * @param {string} accessor The member access method (bracket or period) - * @param {ASTNode} object The object being referenced - * @param {ASTNode} property The object-property being referenced - * @returns {ASTNode} An ASTNode representing a member expression - */ - createMemberExpression: function(accessor, object, property) { - return { - type: astNodeTypes.MemberExpression, - computed: accessor === "[", - object: object, - property: property - }; - }, - - /** - * Create an ASTNode representation of a new expression - * @param {ASTNode} callee The constructor for the new object type - * @param {ASTNode} args The arguments passed to the constructor - * @returns {ASTNode} An ASTNode representing a new expression - */ - createNewExpression: function(callee, args) { - return { - type: astNodeTypes.NewExpression, - callee: callee, - "arguments": args - }; - }, - - /** - * Create an ASTNode representation of a new object expression - * @param {ASTNode[]} properties An array of ASTNodes that represent all object - * properties and associated values - * @returns {ASTNode} An ASTNode representing a new object expression - */ - createObjectExpression: function(properties) { - return { - type: astNodeTypes.ObjectExpression, - properties: properties - }; - }, - - /** - * Create an ASTNode representation of a postfix expression - * @param {string} operator The postfix operator ("++", "--", etc.) - * @param {ASTNode} argument The operator argument - * @returns {ASTNode} An ASTNode representing a postfix expression - */ - createPostfixExpression: function(operator, argument) { - return { - type: astNodeTypes.UpdateExpression, - operator: operator, - argument: argument, - prefix: false - }; - }, - - /** - * Create an ASTNode representation of an entire program - * @param {ASTNode} body The program body - * @param {string} sourceType Either "module" or "script". - * @returns {ASTNode} An ASTNode representing an entire program - */ - createProgram: function(body, sourceType) { - return { - type: astNodeTypes.Program, - body: body, - sourceType: sourceType - }; - }, - - /** - * Create an ASTNode representation of an object property - * @param {string} kind The type of property represented ("get", "set", etc.) - * @param {ASTNode} key The property key - * @param {ASTNode} value The new property value - * @param {boolean} method True if the property is also a method (value is a function) - * @param {boolean} shorthand True if the property is shorthand - * @param {boolean} computed True if the property value has been computed - * @returns {ASTNode} An ASTNode representing an object property - */ - createProperty: function(kind, key, value, method, shorthand, computed) { - return { - type: astNodeTypes.Property, - key: key, - value: value, - kind: kind, - method: method, - shorthand: shorthand, - computed: computed - }; - }, - - /** - * Create an ASTNode representation of a rest element - * @param {ASTNode} argument The rest argument - * @returns {ASTNode} An ASTNode representing a rest element - */ - createRestElement: function (argument) { - return { - type: astNodeTypes.RestElement, - argument: argument - }; - }, - - /** - * Create an ASTNode representation of a return statement - * @param {?ASTNode} argument The return argument, null if no argument is provided - * @returns {ASTNode} An ASTNode representing a return statement - */ - createReturnStatement: function(argument) { - return { - type: astNodeTypes.ReturnStatement, - argument: argument - }; - }, - - /** - * Create an ASTNode representation of a sequence of expressions - * @param {ASTNode[]} expressions An array containing each expression, in order - * @returns {ASTNode} An ASTNode representing a sequence of expressions - */ - createSequenceExpression: function(expressions) { - return { - type: astNodeTypes.SequenceExpression, - expressions: expressions - }; - }, - - /** - * Create an ASTNode representation of super - * @returns {ASTNode} An ASTNode representing super - */ - createSuper: function() { - return { - type: astNodeTypes.Super - }; - }, - - /** - * Create an ASTNode representation of a switch case statement - * @param {ASTNode} test The case value to test against the switch value - * @param {ASTNode} consequent The consequent case statement - * @returns {ASTNode} An ASTNode representing a switch case - */ - createSwitchCase: function(test, consequent) { - return { - type: astNodeTypes.SwitchCase, - test: test, - consequent: consequent - }; - }, - - /** - * Create an ASTNode representation of a switch statement - * @param {ASTNode} discriminant An expression to test against each case value - * @param {ASTNode[]} cases An array of switch case statements - * @returns {ASTNode} An ASTNode representing a switch statement - */ - createSwitchStatement: function(discriminant, cases) { - return { - type: astNodeTypes.SwitchStatement, - discriminant: discriminant, - cases: cases - }; - }, - - /** - * Create an ASTNode representation of a this statement - * @returns {ASTNode} An ASTNode representing a this statement - */ - createThisExpression: function() { - return { - type: astNodeTypes.ThisExpression - }; - }, - - /** - * Create an ASTNode representation of a throw statement - * @param {ASTNode} argument The argument to throw - * @returns {ASTNode} An ASTNode representing a throw statement - */ - createThrowStatement: function(argument) { - return { - type: astNodeTypes.ThrowStatement, - argument: argument - }; - }, - - /** - * Create an ASTNode representation of a try statement - * @param {ASTNode} block The try block - * @param {ASTNode} handler A catch handler - * @param {?ASTNode} finalizer The final code block to run after the try/catch has run - * @returns {ASTNode} An ASTNode representing a try statement - */ - createTryStatement: function(block, handler, finalizer) { - return { - type: astNodeTypes.TryStatement, - block: block, - handler: handler, - finalizer: finalizer - }; - }, - - /** - * Create an ASTNode representation of a unary expression - * @param {string} operator The unary operator - * @param {ASTNode} argument The unary operand - * @returns {ASTNode} An ASTNode representing a unary expression - */ - createUnaryExpression: function(operator, argument) { - if (operator === "++" || operator === "--") { - return { - type: astNodeTypes.UpdateExpression, - operator: operator, - argument: argument, - prefix: true - }; - } - return { - type: astNodeTypes.UnaryExpression, - operator: operator, - argument: argument, - prefix: true - }; - }, - - /** - * Create an ASTNode representation of a variable declaration - * @param {ASTNode[]} declarations An array of variable declarations - * @param {string} kind The kind of variable created ("var", "let", etc.) - * @returns {ASTNode} An ASTNode representing a variable declaration - */ - createVariableDeclaration: function(declarations, kind) { - return { - type: astNodeTypes.VariableDeclaration, - declarations: declarations, - kind: kind - }; - }, - - /** - * Create an ASTNode representation of a variable declarator - * @param {ASTNode} id The variable ID - * @param {ASTNode} init The variable's initial value - * @returns {ASTNode} An ASTNode representing a variable declarator - */ - createVariableDeclarator: function(id, init) { - return { - type: astNodeTypes.VariableDeclarator, - id: id, - init: init - }; - }, - - /** - * Create an ASTNode representation of a with statement - * @param {ASTNode} object The with statement object expression - * @param {ASTNode} body The with statement body - * @returns {ASTNode} An ASTNode representing a with statement - */ - createWithStatement: function(object, body) { - return { - type: astNodeTypes.WithStatement, - object: object, - body: body - }; - }, - - createYieldExpression: function(argument, delegate) { - return { - type: astNodeTypes.YieldExpression, - argument: argument || null, - delegate: delegate - }; - }, - - createJSXAttribute: function(name, value) { - return { - type: astNodeTypes.JSXAttribute, - name: name, - value: value || null - }; - }, - - createJSXSpreadAttribute: function(argument) { - return { - type: astNodeTypes.JSXSpreadAttribute, - argument: argument - }; - }, - - createJSXIdentifier: function(name) { - return { - type: astNodeTypes.JSXIdentifier, - name: name - }; - }, - - createJSXNamespacedName: function(namespace, name) { - return { - type: astNodeTypes.JSXNamespacedName, - namespace: namespace, - name: name - }; - }, - - createJSXMemberExpression: function(object, property) { - return { - type: astNodeTypes.JSXMemberExpression, - object: object, - property: property - }; - }, - - createJSXElement: function(openingElement, closingElement, children) { - return { - type: astNodeTypes.JSXElement, - openingElement: openingElement, - closingElement: closingElement, - children: children - }; - }, - - createJSXEmptyExpression: function() { - return { - type: astNodeTypes.JSXEmptyExpression - }; - }, - - createJSXExpressionContainer: function(expression) { - return { - type: astNodeTypes.JSXExpressionContainer, - expression: expression - }; - }, - - createJSXOpeningElement: function(name, attributes, selfClosing) { - return { - type: astNodeTypes.JSXOpeningElement, - name: name, - selfClosing: selfClosing, - attributes: attributes - }; - }, - - createJSXClosingElement: function(name) { - return { - type: astNodeTypes.JSXClosingElement, - name: name - }; - }, - - createExportSpecifier: function(local, exported) { - return { - type: astNodeTypes.ExportSpecifier, - exported: exported || local, - local: local - }; - }, - - createImportDefaultSpecifier: function(local) { - return { - type: astNodeTypes.ImportDefaultSpecifier, - local: local - }; - }, - - createImportNamespaceSpecifier: function(local) { - return { - type: astNodeTypes.ImportNamespaceSpecifier, - local: local - }; - }, - - createExportNamedDeclaration: function(declaration, specifiers, source) { - return { - type: astNodeTypes.ExportNamedDeclaration, - declaration: declaration, - specifiers: specifiers, - source: source - }; - }, - - createExportDefaultDeclaration: function(declaration) { - return { - type: astNodeTypes.ExportDefaultDeclaration, - declaration: declaration - }; - }, - - createExportAllDeclaration: function(source) { - return { - type: astNodeTypes.ExportAllDeclaration, - source: source - }; - }, - - createImportSpecifier: function(local, imported) { - return { - type: astNodeTypes.ImportSpecifier, - local: local || imported, - imported: imported - }; - }, - - createImportDeclaration: function(specifiers, source) { - return { - type: astNodeTypes.ImportDeclaration, - specifiers: specifiers, - source: source - }; - } - -}; - -},{"./ast-node-types":2}],2:[function(require,module,exports){ /** * @fileoverview The AST node types produced by the parser. * @author Nicholas C. Zakas @@ -1085,7 +119,7 @@ module.exports = { ImportNamespaceSpecifier: "ImportNamespaceSpecifier" }; -},{}],3:[function(require,module,exports){ +},{}],2:[function(require,module,exports){ /** * @fileoverview Attaches comments to the AST. * @author Nicholas C. Zakas @@ -1126,10 +160,10 @@ var astNodeTypes = require("./ast-node-types"); //------------------------------------------------------------------------------ var extra = { - trailingComments: [], - leadingComments: [], - bottomRightStack: [] - }; + trailingComments: [], + leadingComments: [], + bottomRightStack: [] +}; //------------------------------------------------------------------------------ // Public @@ -1270,13 +304,11 @@ module.exports = { }; -},{"./ast-node-types":2}],4:[function(require,module,exports){ +},{"./ast-node-types":1}],3:[function(require,module,exports){ /** - * @fileoverview The list of feature flags supported by the parser and their default - * settings. + * @fileoverview Translates tokens between Acorn format and Esprima format. * @author Nicholas C. Zakas - * @copyright 2015 Fred K. Schott. All rights reserved. - * @copyright 2014 Nicholas C. Zakas. All rights reserved. + * @copyright 2015 Nicholas C. Zakas. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -1298,6 +330,7 @@ module.exports = { * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/* eslint no-underscore-dangle: 0 */ "use strict"; @@ -1305,255 +338,245 @@ module.exports = { // Requirements //------------------------------------------------------------------------------ -// None! +// none! //------------------------------------------------------------------------------ -// Public +// Private //------------------------------------------------------------------------------ -module.exports = { - // enable parsing of arrow functions - arrowFunctions: false, +// Esprima Token Types +var Token = { + Boolean: "Boolean", + EOF: "", + Identifier: "Identifier", + Keyword: "Keyword", + Null: "Null", + Numeric: "Numeric", + Punctuator: "Punctuator", + String: "String", + RegularExpression: "RegularExpression", + Template: "Template", + JSXIdentifier: "JSXIdentifier", + JSXText: "JSXText" +}; - // enable parsing of let and const - blockBindings: true, +/** + * Converts part of a template into an Esprima token. + * @param {AcornToken[]} tokens The Acorn tokens representing the template. + * @param {string} code The source code. + * @returns {EsprimaToken} The Esprima equivalent of the template token. + * @private + */ +function convertTemplatePart(tokens, code) { + var firstToken = tokens[0], + lastTemplateToken = tokens[tokens.length - 1]; - // enable parsing of destructured arrays and objects - destructuring: false, + var token = { + type: Token.Template, + value: code.slice(firstToken.start, lastTemplateToken.end) + }; - // enable parsing of regex u flag - regexUFlag: false, + if (firstToken.loc) { + token.loc = { + start: firstToken.loc.start, + end: lastTemplateToken.loc.end + }; + } - // enable parsing of regex y flag - regexYFlag: false, + if (firstToken.range) { + token.range = [firstToken.range[0], lastTemplateToken.range[1]]; + } - // enable parsing of template strings - templateStrings: false, + return token; +} - // enable parsing binary literals - binaryLiterals: false, +/** + * Contains logic to translate Acorn tokens into Esprima tokens. + * @param {Object} acornTokTypes The Acorn token types. + * @param {string} code The source code Acorn is parsing. This is necessary + * to correct the "value" property of some tokens. + * @constructor + */ +function TokenTranslator(acornTokTypes, code) { - // enable parsing ES6 octal literals - octalLiterals: false, + // token types + this._acornTokTypes = acornTokTypes; - // enable parsing unicode code point escape sequences - unicodeCodePointEscapes: true, + // token buffer for templates + this._tokens = []; - // enable parsing of default parameters - defaultParams: false, + // track the last curly brace + this._curlyBrace = null; - // enable parsing of rest parameters - restParams: false, + // the source code + this._code = code; - // enable parsing of for-of statements - forOf: false, +} - // enable parsing computed object literal properties - objectLiteralComputedProperties: false, +TokenTranslator.prototype = { + constructor: TokenTranslator, - // enable parsing of shorthand object literal methods - objectLiteralShorthandMethods: false, + /** + * Translates a single Esprima token to a single Acorn token. This may be + * inaccurate due to how templates are handled differently in Esprima and + * Acorn, but should be accurate for all other tokens. + * @param {AcornToken} token The Acorn token to translate. + * @param {Object} extra Espree extra object. + * @returns {EsprimaToken} The Esprima version of the token. + */ + translate: function(token, extra) { - // enable parsing of shorthand object literal properties - objectLiteralShorthandProperties: false, + var type = token.type, + tt = this._acornTokTypes; - // Allow duplicate object literal properties (except '__proto__') - objectLiteralDuplicateProperties: false, + if (type === tt.name) { + token.type = Token.Identifier; - // enable parsing of generators/yield - generators: false, + // TODO: See if this is an Acorn bug + if (token.value === "static") { + token.type = Token.Keyword; + } - // support the spread operator - spread: false, + } else if (type === tt.semi || type === tt.comma || + type === tt.parenL || type === tt.parenR || + type === tt.braceL || type === tt.braceR || + type === tt.dot || type === tt.bracketL || + type === tt.colon || type === tt.question || + type === tt.bracketR || type === tt.ellipsis || + type === tt.arrow || type === tt.jsxTagStart || + type === tt.jsxTagEnd || (type.binop && !type.keyword) || + type.isAssign) { - // enable super in functions - superInFunctions: false, + token.type = Token.Punctuator; + token.value = this._code.slice(token.start, token.end); + } else if (type === tt.jsxName) { + token.type = Token.JSXIdentifier; + } else if (type.label === "jsxText" || type === tt.jsxAttrValueToken) { + token.type = Token.JSXText; + } else if (type.keyword) { + if (type.keyword === "true" || type.keyword === "false") { + token.type = Token.Boolean; + } else if (type.keyword === "null") { + token.type = Token.Null; + } else { + token.type = Token.Keyword; + } + } else if (type === tt.num) { + token.type = Token.Numeric; + token.value = this._code.slice(token.start, token.end); + } else if (type === tt.string) { - // enable parsing of classes - classes: false, + if (extra.jsxAttrValueToken) { + extra.jsxAttrValueToken = false; + token.type = Token.JSXText; + } else { + token.type = Token.String; + } - // enable parsing of new.target - newTarget: false, + token.value = this._code.slice(token.start, token.end); + } else if (type === tt.regexp) { + token.type = Token.RegularExpression; + var value = token.value; + token.regex = { + flags: value.flags, + pattern: value.pattern + }; + token.value = "/" + value.pattern + "/" + value.flags; + } - // enable parsing of modules - modules: false, + return token; + }, - // React JSX parsing - jsx: false, + /** + * Function to call during Acorn's onToken handler. + * @param {AcornToken} token The Acorn token. + * @param {Object} extra The Espree extra object. + * @returns {void} + */ + onToken: function(token, extra) { - // allow return statement in global scope - globalReturn: false, + var that = this, + tt = this._acornTokTypes, + tokens = extra.tokens, + templateTokens = this._tokens; - // allow experimental object rest/spread - experimentalObjectRestSpread: false -}; + /** + * Flushes the buffered template tokens and resets the template + * tracking. + * @returns {void} + * @private + */ + function translateTemplateTokens() { + tokens.push(convertTemplatePart(that._tokens, that._code)); + that._tokens = []; + } -},{}],5:[function(require,module,exports){ -/** - * @fileoverview Error messages returned by the parser. - * @author Nicholas C. Zakas - * @copyright 2014 Nicholas C. Zakas. All rights reserved. - * @copyright 2011-2013 Ariya Hidayat - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + if (token.type === tt.eof) { -"use strict"; + // might be one last curlyBrace + if (this._curlyBrace) { + tokens.push(this.translate(this._curlyBrace, extra)); + } -//------------------------------------------------------------------------------ -// Requirements -//------------------------------------------------------------------------------ + return; + } -// None! + if (token.type === tt.backQuote) { + templateTokens.push(token); -//------------------------------------------------------------------------------ -// Public -//------------------------------------------------------------------------------ + // it's the end + if (templateTokens.length > 1) { + translateTemplateTokens(); + } -// error messages should be identical to V8 where possible -module.exports = { - UnexpectedToken: "Unexpected token %0", - UnexpectedNumber: "Unexpected number", - UnexpectedString: "Unexpected string", - UnexpectedIdentifier: "Unexpected identifier", - UnexpectedReserved: "Unexpected reserved word", - UnexpectedTemplate: "Unexpected quasi %0", - UnexpectedEOS: "Unexpected end of input", - NewlineAfterThrow: "Illegal newline after throw", - InvalidRegExp: "Invalid regular expression", - InvalidRegExpFlag: "Invalid regular expression flag", - UnterminatedRegExp: "Invalid regular expression: missing /", - InvalidLHSInAssignment: "Invalid left-hand side in assignment", - InvalidLHSInFormalsList: "Invalid left-hand side in formals list", - InvalidLHSInForIn: "Invalid left-hand side in for-in", - MultipleDefaultsInSwitch: "More than one default clause in switch statement", - NoCatchOrFinally: "Missing catch or finally after try", - NoUnintializedConst: "Const must be initialized", - UnknownLabel: "Undefined label '%0'", - Redeclaration: "%0 '%1' has already been declared", - IllegalContinue: "Illegal continue statement", - IllegalBreak: "Illegal break statement", - IllegalReturn: "Illegal return statement", - IllegalYield: "Illegal yield expression", - IllegalSpread: "Illegal spread element", - StrictModeWith: "Strict mode code may not include a with statement", - StrictCatchVariable: "Catch variable may not be eval or arguments in strict mode", - 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 last formal parameter", - DefaultRestParameter: "Rest parameter can not have a default value", - ElementAfterSpreadElement: "Spread must be the final element of an element list", - ObjectPatternAsRestParameter: "Invalid rest parameter", - ObjectPatternAsSpread: "Invalid spread argument", - StrictFunctionName: "Function name may not be eval or arguments in strict mode", - StrictOctalLiteral: "Octal literals are not allowed in strict mode.", - StrictDelete: "Delete of an unqualified identifier in strict mode.", - StrictDuplicateProperty: "Duplicate data property in object literal not allowed in strict mode", - DuplicatePrototypeProperty: "Duplicate '__proto__' property in object literal are not allowed", - ConstructorSpecialMethod: "Class constructor may not be an accessor", - DuplicateConstructor: "A class may only have one constructor", - StaticPrototype: "Classes may not have static property named prototype", - AccessorDataProperty: "Object literal may not have data and accessor property with the same name", - AccessorGetSet: "Object literal may not have multiple get/set accessors with the same name", - StrictLHSAssignment: "Assignment to eval or arguments is not allowed in strict mode", - StrictLHSPostfix: "Postfix increment/decrement may not have eval or arguments operand in strict mode", - StrictLHSPrefix: "Prefix increment/decrement may not have eval or arguments operand in strict mode", - StrictReservedWord: "Use of future reserved word in strict mode", - InvalidJSXAttributeValue: "JSX value should be either an expression or a quoted JSX text", - ExpectedJSXClosingTag: "Expected corresponding JSX closing tag for %0", - AdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag", - MissingFromClause: "Missing from clause", - NoAsAfterImportNamespace: "Missing as after import *", - InvalidModuleSpecifier: "Invalid module specifier", - IllegalImportDeclaration: "Illegal import declaration", - IllegalExportDeclaration: "Illegal export declaration" -}; - -},{}],6:[function(require,module,exports){ -/** - * @fileoverview A simple map that helps avoid collisions on the Object prototype. - * @author Jamund Ferguson - * @copyright 2015 Jamund Ferguson. All rights reserved. - * @copyright 2011-2013 Ariya Hidayat - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + return; + } else if (token.type === tt.dollarBraceL) { + templateTokens.push(token); + translateTemplateTokens(); + return; + } else if (token.type === tt.braceR) { -"use strict"; + // if there's already a curly, it's not part of the template + if (this._curlyBrace) { -function StringMap() { - this.$data = {}; -} + tokens.push(this.translate(this._curlyBrace, extra)); + } -StringMap.prototype.get = function (key) { - key = "$" + key; - return this.$data[key]; -}; + // store new curly for later + this._curlyBrace = token; + return; + } else if (token.type === tt.template) { + if (this._curlyBrace) { + templateTokens.push(this._curlyBrace); + this._curlyBrace = null; + } -StringMap.prototype.set = function (key, value) { - key = "$" + key; - this.$data[key] = value; - return this; -}; + templateTokens.push(token); + return; + } -StringMap.prototype.has = function (key) { - key = "$" + key; - return Object.prototype.hasOwnProperty.call(this.$data, key); -}; + if (this._curlyBrace) { + tokens.push(this.translate(this._curlyBrace, extra)); + this._curlyBrace = null; + } -StringMap.prototype.delete = function (key) { - key = "$" + key; - return delete this.$data[key]; + tokens.push(this.translate(token, extra)); + } }; -module.exports = StringMap; +//------------------------------------------------------------------------------ +// Public +//------------------------------------------------------------------------------ + +module.exports = TokenTranslator; -},{}],7:[function(require,module,exports){ +},{}],4:[function(require,module,exports){ /** - * @fileoverview Various syntax/pattern checks for parsing. + * @fileoverview The visitor keys for the node types Espree supports * @author Nicholas C. Zakas - * @copyright 2014 Nicholas C. Zakas. All rights reserved. - * @copyright 2011-2013 Ariya Hidayat - * @copyright 2012-2013 Mathias Bynens + * @copyright 2015 Nicholas C. Zakas. All rights reserved. + * @copyright 2012-2013 Yusuke Suzuki (twitter: @Constellation) and other contributors. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -1574,6 +597,28 @@ module.exports = StringMap; * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Contains code from estraverse-fb. + * + * The MIT license. Copyright (c) 2014 Ingvar Stepanyan + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. */ "use strict"; @@ -1584,7873 +629,8078 @@ module.exports = StringMap; // None! -//------------------------------------------------------------------------------ -// Private -//------------------------------------------------------------------------------ - -// See also tools/generate-identifier-regex.js. -var Regex = { - NonAsciiIdentifierStart: new RegExp("[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\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\u08A0\u08A2-\u08AC\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097F\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\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\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-\u0C33\u0C35-\u0C39\u0C3D\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\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-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F0\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191C\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\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\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\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\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA697\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA793\uA7A0-\uA7AA\uA7F8-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA80-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uABC0-\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]"), - NonAsciiIdentifierPart: new RegExp("[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u0527\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u08A0\u08A2-\u08AC\u08E4-\u08FE\u0900-\u0963\u0966-\u096F\u0971-\u0977\u0979-\u097F\u0981-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C01-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58\u0C59\u0C60-\u0C63\u0C66-\u0C6F\u0C82\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D02\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D57\u0D60-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\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\u135D-\u135F\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F0\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191C\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19D9\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1CD0-\u1CD2\u1CD4-\u1CF6\u1D00-\u1DE6\u1DFC-\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\u200C\u200D\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA697\uA69F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA793\uA7A0-\uA7AA\uA7F8-\uA827\uA840-\uA873\uA880-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A\uAA7B\uAA80-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uABC0-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE26\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]"), - LeadingZeros: new RegExp("^0+(?!$)") -}; - //------------------------------------------------------------------------------ // Public //------------------------------------------------------------------------------ module.exports = { - Regex: Regex, - - isDecimalDigit: function(ch) { - return (ch >= 48 && ch <= 57); // 0..9 - }, + // ECMAScript + AssignmentExpression: ["left", "right"], + AssignmentPattern: ["left", "right"], + ArrayExpression: ["elements"], + ArrayPattern: ["elements"], + ArrowFunctionExpression: ["params", "body"], + BlockStatement: ["body"], + BinaryExpression: ["left", "right"], + BreakStatement: ["label"], + CallExpression: ["callee", "arguments"], + CatchClause: ["param", "body"], + ClassBody: ["body"], + ClassDeclaration: ["id", "superClass", "body"], + ClassExpression: ["id", "superClass", "body"], + ConditionalExpression: ["test", "consequent", "alternate"], + ContinueStatement: ["label"], + DebuggerStatement: [], + DirectiveStatement: [], + DoWhileStatement: ["body", "test"], + EmptyStatement: [], + ExportAllDeclaration: ["source"], + ExportDefaultDeclaration: ["declaration"], + ExportNamedDeclaration: ["declaration", "specifiers", "source"], + ExportSpecifier: ["exported", "local"], + ExpressionStatement: ["expression"], + ForStatement: ["init", "test", "update", "body"], + ForInStatement: ["left", "right", "body"], + ForOfStatement: ["left", "right", "body"], + FunctionDeclaration: ["id", "params", "body"], + FunctionExpression: ["id", "params", "body"], + Identifier: [], + IfStatement: ["test", "consequent", "alternate"], + ImportDeclaration: ["specifiers", "source"], + ImportDefaultSpecifier: ["local"], + ImportNamespaceSpecifier: ["local"], + ImportSpecifier: ["imported", "local"], + Literal: [], + LabeledStatement: ["label", "body"], + LogicalExpression: ["left", "right"], + MemberExpression: ["object", "property"], + MetaProperty: ["meta", "property"], + MethodDefinition: ["key", "value"], + ModuleSpecifier: [], + NewExpression: ["callee", "arguments"], + ObjectExpression: ["properties"], + ObjectPattern: ["properties"], + Program: ["body"], + Property: ["key", "value"], + RestElement: [ "argument" ], + ReturnStatement: ["argument"], + SequenceExpression: ["expressions"], + SpreadElement: ["argument"], + Super: [], + SwitchStatement: ["discriminant", "cases"], + SwitchCase: ["test", "consequent"], + TaggedTemplateExpression: ["tag", "quasi"], + TemplateElement: [], + TemplateLiteral: ["quasis", "expressions"], + ThisExpression: [], + ThrowStatement: ["argument"], + TryStatement: ["block", "handler", "finalizer"], + UnaryExpression: ["argument"], + UpdateExpression: ["argument"], + VariableDeclaration: ["declarations"], + VariableDeclarator: ["id", "init"], + WhileStatement: ["test", "body"], + WithStatement: ["object", "body"], + YieldExpression: ["argument"], + + // JSX + JSXIdentifier: [], + JSXNamespacedName: ["namespace", "name"], + JSXMemberExpression: ["object", "property"], + JSXEmptyExpression: [], + JSXExpressionContainer: ["expression"], + JSXElement: ["openingElement", "closingElement", "children"], + JSXClosingElement: ["name"], + JSXOpeningElement: ["name", "attributes"], + JSXAttribute: ["name", "value"], + JSXText: null, + JSXSpreadAttribute: ["argument"], + + // Experimental features + ExperimentalRestProperty: ["argument"], + ExperimentalSpreadProperty: ["argument"] +}; - isHexDigit: function(ch) { - return "0123456789abcdefABCDEF".indexOf(ch) >= 0; - }, +},{}],5:[function(require,module,exports){ +'use strict'; - isOctalDigit: function(ch) { - return "01234567".indexOf(ch) >= 0; - }, +var XHTMLEntities = require('./xhtml'); - // 7.2 White Space +var hexNumber = /^[\da-fA-F]+$/; +var decimalNumber = /^\d+$/; - isWhiteSpace: function(ch) { - return (ch === 0x20) || (ch === 0x09) || (ch === 0x0B) || (ch === 0x0C) || (ch === 0xA0) || - (ch >= 0x1680 && [0x1680, 0x180E, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202F, 0x205F, 0x3000, 0xFEFF].indexOf(ch) >= 0); - }, +module.exports = function(acorn) { + var tt = acorn.tokTypes; + var tc = acorn.tokContexts; - // 7.3 Line Terminators + tc.j_oTag = new acorn.TokContext('...', true, true); - isLineTerminator: function(ch) { - return (ch === 0x0A) || (ch === 0x0D) || (ch === 0x2028) || (ch === 0x2029); - }, + tt.jsxName = new acorn.TokenType('jsxName'); + tt.jsxText = new acorn.TokenType('jsxText', {beforeExpr: true}); + tt.jsxTagStart = new acorn.TokenType('jsxTagStart'); + tt.jsxTagEnd = new acorn.TokenType('jsxTagEnd'); - // 7.6 Identifier Names and Identifiers + tt.jsxTagStart.updateContext = function() { + this.context.push(tc.j_expr); // treat as beginning of JSX expression + this.context.push(tc.j_oTag); // start opening tag context + this.exprAllowed = false; + }; + tt.jsxTagEnd.updateContext = function(prevType) { + var out = this.context.pop(); + if (out === tc.j_oTag && prevType === tt.slash || out === tc.j_cTag) { + this.context.pop(); + this.exprAllowed = this.curContext() === tc.j_expr; + } else { + this.exprAllowed = true; + } + }; - isIdentifierStart: function(ch) { - return (ch === 0x24) || (ch === 0x5F) || // $ (dollar) and _ (underscore) - (ch >= 0x41 && ch <= 0x5A) || // A..Z - (ch >= 0x61 && ch <= 0x7A) || // a..z - (ch === 0x5C) || // \ (backslash) - ((ch >= 0x80) && Regex.NonAsciiIdentifierStart.test(String.fromCharCode(ch))); - }, + var pp = acorn.Parser.prototype; - isIdentifierPart: function(ch) { - return (ch === 0x24) || (ch === 0x5F) || // $ (dollar) and _ (underscore) - (ch >= 0x41 && ch <= 0x5A) || // A..Z - (ch >= 0x61 && ch <= 0x7A) || // a..z - (ch >= 0x30 && ch <= 0x39) || // 0..9 - (ch === 0x5C) || // \ (backslash) - ((ch >= 0x80) && Regex.NonAsciiIdentifierPart.test(String.fromCharCode(ch))); - }, + // Reads inline JSX contents token. - // 7.6.1.2 Future Reserved Words + pp.jsx_readToken = function() { + var out = '', chunkStart = this.pos; + for (;;) { + if (this.pos >= this.input.length) + this.raise(this.start, 'Unterminated JSX contents'); + var ch = this.input.charCodeAt(this.pos); - isFutureReservedWord: function(id) { - switch (id) { - case "class": - case "enum": - case "export": - case "extends": - case "import": - case "super": - return true; - default: - return false; + switch (ch) { + case 60: // '<' + case 123: // '{' + if (this.pos === this.start) { + if (ch === 60 && this.exprAllowed) { + ++this.pos; + return this.finishToken(tt.jsxTagStart); + } + return this.getTokenFromCode(ch); } - }, + out += this.input.slice(chunkStart, this.pos); + return this.finishToken(tt.jsxText, out); - isStrictModeReservedWord: function(id, ecmaFeatures) { - switch (id) { - case "implements": - case "interface": - case "package": - case "private": - case "protected": - case "public": - case "static": - case "yield": - case "let": - return true; - case "await": - return ecmaFeatures.modules; - default: - return false; + case 38: // '&' + out += this.input.slice(chunkStart, this.pos); + out += this.jsx_readEntity(); + chunkStart = this.pos; + break; + + default: + if (acorn.isNewLine(ch)) { + out += this.input.slice(chunkStart, this.pos); + out += this.jsx_readNewLine(true); + chunkStart = this.pos; + } else { + ++this.pos; } - }, + } + } + }; - isRestrictedWord: function(id) { - return id === "eval" || id === "arguments"; - }, + pp.jsx_readNewLine = function(normalizeCRLF) { + var ch = this.input.charCodeAt(this.pos); + var out; + ++this.pos; + if (ch === 13 && this.input.charCodeAt(this.pos) === 10) { + ++this.pos; + out = normalizeCRLF ? '\n' : '\r\n'; + } else { + out = String.fromCharCode(ch); + } + if (this.options.locations) { + ++this.curLine; + this.lineStart = this.pos; + } - // 7.6.1.1 Keywords + return out; + }; - isKeyword: function(id, strict, ecmaFeatures) { + pp.jsx_readString = function(quote) { + var out = '', chunkStart = ++this.pos; + for (;;) { + if (this.pos >= this.input.length) + this.raise(this.start, 'Unterminated string constant'); + var ch = this.input.charCodeAt(this.pos); + if (ch === quote) break; + if (ch === 38) { // '&' + out += this.input.slice(chunkStart, this.pos); + out += this.jsx_readEntity(); + chunkStart = this.pos; + } else if (acorn.isNewLine(ch)) { + out += this.input.slice(chunkStart, this.pos); + out += this.jsx_readNewLine(false); + chunkStart = this.pos; + } else { + ++this.pos; + } + } + out += this.input.slice(chunkStart, this.pos++); + return this.finishToken(tt.string, out); + }; - if (strict && this.isStrictModeReservedWord(id, ecmaFeatures)) { - return true; + pp.jsx_readEntity = function() { + var str = '', count = 0, entity; + var ch = this.input[this.pos]; + if (ch !== '&') + this.raise(this.pos, 'Entity must start with an ampersand'); + var startPos = ++this.pos; + while (this.pos < this.input.length && count++ < 10) { + ch = this.input[this.pos++]; + if (ch === ';') { + if (str[0] === '#') { + if (str[1] === 'x') { + str = str.substr(2); + if (hexNumber.test(str)) + entity = String.fromCharCode(parseInt(str, 16)); + } else { + str = str.substr(1); + if (decimalNumber.test(str)) + entity = String.fromCharCode(parseInt(str, 10)); + } + } else { + entity = XHTMLEntities[str]; } + break; + } + str += ch; + } + if (!entity) { + this.pos = startPos; + return '&'; + } + return entity; + }; - // "const" is specialized as Keyword in V8. - // "yield" and "let" are for compatiblity with SpiderMonkey and ES.next. - // Some others are from future reserved words. - switch (id.length) { - case 2: - return (id === "if") || (id === "in") || (id === "do"); - case 3: - return (id === "var") || (id === "for") || (id === "new") || - (id === "try") || (id === "let"); - case 4: - return (id === "this") || (id === "else") || (id === "case") || - (id === "void") || (id === "with") || (id === "enum"); - case 5: - return (id === "while") || (id === "break") || (id === "catch") || - (id === "throw") || (id === "const") || (!ecmaFeatures.generators && id === "yield") || - (id === "class") || (id === "super"); - case 6: - return (id === "return") || (id === "typeof") || (id === "delete") || - (id === "switch") || (id === "export") || (id === "import"); - case 7: - return (id === "default") || (id === "finally") || (id === "extends"); - case 8: - return (id === "function") || (id === "continue") || (id === "debugger"); - case 10: - return (id === "instanceof"); - default: - return false; - } - }, + // Read a JSX identifier (valid tag or attribute name). + // + // Optimized version since JSX identifiers can't contain + // escape characters and so can be read as single slice. + // Also assumes that first character was already checked + // by isIdentifierStart in readToken. - isJSXIdentifierStart: function(ch) { - // exclude backslash (\) - return (ch !== 92) && this.isIdentifierStart(ch); - }, + pp.jsx_readWord = function() { + var ch, start = this.pos; + do { + ch = this.input.charCodeAt(++this.pos); + } while (acorn.isIdentifierChar(ch) || ch === 45); // '-' + return this.finishToken(tt.jsxName, this.input.slice(start, this.pos)); + }; - isJSXIdentifierPart: function(ch) { - // exclude backslash (\) and add hyphen (-) - return (ch !== 92) && (ch === 45 || this.isIdentifierPart(ch)); - } + // Transforms JSX element name to string. + function getQualifiedJSXName(object) { + if (object.type === 'JSXIdentifier') + return object.name; -}; + if (object.type === 'JSXNamespacedName') + return object.namespace.name + ':' + object.name.name; -},{}],8:[function(require,module,exports){ -/** - * @fileoverview Contains token information. - * @author Nicholas C. Zakas - * @copyright 2014 Nicholas C. Zakas. All rights reserved. - * @copyright 2013 Thaddee Tyl - * @copyright 2011-2013 Ariya Hidayat - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + if (object.type === 'JSXMemberExpression') + return getQualifiedJSXName(object.object) + '.' + + getQualifiedJSXName(object.property); + } -"use strict"; + // Parse next token as JSX identifier + + pp.jsx_parseIdentifier = function() { + var node = this.startNode(); + if (this.type === tt.jsxName) + node.name = this.value; + else if (this.type.keyword) + node.name = this.type.keyword; + else + this.unexpected(); + this.next(); + return this.finishNode(node, 'JSXIdentifier'); + }; -//------------------------------------------------------------------------------ -// Requirements -//------------------------------------------------------------------------------ + // Parse namespaced identifier. -// None! + pp.jsx_parseNamespacedName = function() { + var startPos = this.start, startLoc = this.startLoc; + var name = this.jsx_parseIdentifier(); + if (!this.eat(tt.colon)) return name; + var node = this.startNodeAt(startPos, startLoc); + node.namespace = name; + node.name = this.jsx_parseIdentifier(); + return this.finishNode(node, 'JSXNamespacedName'); + }; -//------------------------------------------------------------------------------ -// Private -//------------------------------------------------------------------------------ + // Parses element name in any form - namespaced, member + // or single identifier. -var Token = { - BooleanLiteral: 1, - EOF: 2, - Identifier: 3, - Keyword: 4, - NullLiteral: 5, - NumericLiteral: 6, - Punctuator: 7, - StringLiteral: 8, - RegularExpression: 9, - Template: 10, - JSXIdentifier: 11, - JSXText: 12 -}; - -var TokenName = {}; -TokenName[Token.BooleanLiteral] = "Boolean"; -TokenName[Token.EOF] = ""; -TokenName[Token.Identifier] = "Identifier"; -TokenName[Token.Keyword] = "Keyword"; -TokenName[Token.NullLiteral] = "Null"; -TokenName[Token.NumericLiteral] = "Numeric"; -TokenName[Token.Punctuator] = "Punctuator"; -TokenName[Token.StringLiteral] = "String"; -TokenName[Token.RegularExpression] = "RegularExpression"; -TokenName[Token.Template] = "Template"; -TokenName[Token.JSXIdentifier] = "JSXIdentifier"; -TokenName[Token.JSXText] = "JSXText"; - -// A function following one of those tokens is an expression. -var FnExprTokens = ["(", "{", "[", "in", "typeof", "instanceof", "new", - "return", "case", "delete", "throw", "void", - // assignment operators - "=", "+=", "-=", "*=", "/=", "%=", "<<=", ">>=", ">>>=", - "&=", "|=", "^=", ",", - // binary/unary operators - "+", "-", "*", "/", "%", "++", "--", "<<", ">>", ">>>", "&", - "|", "^", "!", "~", "&&", "||", "?", ":", "===", "==", ">=", - "<=", "<", ">", "!=", "!=="]; + pp.jsx_parseElementName = function() { + var startPos = this.start, startLoc = this.startLoc; + var node = this.jsx_parseNamespacedName(); + while (this.eat(tt.dot)) { + var newNode = this.startNodeAt(startPos, startLoc); + newNode.object = node; + newNode.property = this.jsx_parseIdentifier(); + node = this.finishNode(newNode, 'JSXMemberExpression'); + } + return node; + }; + // Parses any type of JSX attribute value. -//------------------------------------------------------------------------------ -// Public -//------------------------------------------------------------------------------ + pp.jsx_parseAttributeValue = function() { + switch (this.type) { + case tt.braceL: + var node = this.jsx_parseExpressionContainer(); + if (node.expression.type === 'JSXEmptyExpression') + this.raise(node.start, 'JSX attributes must only be assigned a non-empty expression'); + return node; -module.exports = { - Token: Token, - TokenName: TokenName, - FnExprTokens: FnExprTokens -}; + case tt.jsxTagStart: + case tt.string: + return this.parseExprAtom(); -},{}],9:[function(require,module,exports){ -/** - * @fileoverview The list of XHTML entities that are valid in JSX. - * @author Nicholas C. Zakas - * @copyright 2014 Nicholas C. Zakas. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + default: + this.raise(this.start, 'JSX value should be either an expression or a quoted JSX text'); + } + }; -"use strict"; + // JSXEmptyExpression is unique type since it doesn't actually parse anything, + // and so it should start at the end of last read token (left brace) and finish + // at the beginning of the next one (right brace). -//------------------------------------------------------------------------------ -// Requirements -//------------------------------------------------------------------------------ + pp.jsx_parseEmptyExpression = function() { + var node = this.startNodeAt(this.lastTokEnd, this.lastTokEndLoc); + return this.finishNodeAt(node, 'JSXEmptyExpression', this.start, this.startLoc); + }; -// None! + // Parses JSX expression enclosed into curly brackets. -//------------------------------------------------------------------------------ -// Public -//------------------------------------------------------------------------------ -module.exports = { - quot: "\u0022", - amp: "&", - apos: "\u0027", - lt: "<", - gt: ">", - nbsp: "\u00A0", - iexcl: "\u00A1", - cent: "\u00A2", - pound: "\u00A3", - curren: "\u00A4", - yen: "\u00A5", - brvbar: "\u00A6", - sect: "\u00A7", - uml: "\u00A8", - copy: "\u00A9", - ordf: "\u00AA", - laquo: "\u00AB", - not: "\u00AC", - shy: "\u00AD", - reg: "\u00AE", - macr: "\u00AF", - deg: "\u00B0", - plusmn: "\u00B1", - sup2: "\u00B2", - sup3: "\u00B3", - acute: "\u00B4", - micro: "\u00B5", - para: "\u00B6", - middot: "\u00B7", - cedil: "\u00B8", - sup1: "\u00B9", - ordm: "\u00BA", - raquo: "\u00BB", - frac14: "\u00BC", - frac12: "\u00BD", - frac34: "\u00BE", - iquest: "\u00BF", - Agrave: "\u00C0", - Aacute: "\u00C1", - Acirc: "\u00C2", - Atilde: "\u00C3", - Auml: "\u00C4", - Aring: "\u00C5", - AElig: "\u00C6", - Ccedil: "\u00C7", - Egrave: "\u00C8", - Eacute: "\u00C9", - Ecirc: "\u00CA", - Euml: "\u00CB", - Igrave: "\u00CC", - Iacute: "\u00CD", - Icirc: "\u00CE", - Iuml: "\u00CF", - ETH: "\u00D0", - Ntilde: "\u00D1", - Ograve: "\u00D2", - Oacute: "\u00D3", - Ocirc: "\u00D4", - Otilde: "\u00D5", - Ouml: "\u00D6", - times: "\u00D7", - Oslash: "\u00D8", - Ugrave: "\u00D9", - Uacute: "\u00DA", - Ucirc: "\u00DB", - Uuml: "\u00DC", - Yacute: "\u00DD", - THORN: "\u00DE", - szlig: "\u00DF", - agrave: "\u00E0", - aacute: "\u00E1", - acirc: "\u00E2", - atilde: "\u00E3", - auml: "\u00E4", - aring: "\u00E5", - aelig: "\u00E6", - ccedil: "\u00E7", - egrave: "\u00E8", - eacute: "\u00E9", - ecirc: "\u00EA", - euml: "\u00EB", - igrave: "\u00EC", - iacute: "\u00ED", - icirc: "\u00EE", - iuml: "\u00EF", - eth: "\u00F0", - ntilde: "\u00F1", - ograve: "\u00F2", - oacute: "\u00F3", - ocirc: "\u00F4", - otilde: "\u00F5", - ouml: "\u00F6", - divide: "\u00F7", - oslash: "\u00F8", - ugrave: "\u00F9", - uacute: "\u00FA", - ucirc: "\u00FB", - uuml: "\u00FC", - yacute: "\u00FD", - thorn: "\u00FE", - yuml: "\u00FF", - OElig: "\u0152", - oelig: "\u0153", - Scaron: "\u0160", - scaron: "\u0161", - Yuml: "\u0178", - fnof: "\u0192", - circ: "\u02C6", - tilde: "\u02DC", - Alpha: "\u0391", - Beta: "\u0392", - Gamma: "\u0393", - Delta: "\u0394", - Epsilon: "\u0395", - Zeta: "\u0396", - Eta: "\u0397", - Theta: "\u0398", - Iota: "\u0399", - Kappa: "\u039A", - Lambda: "\u039B", - Mu: "\u039C", - Nu: "\u039D", - Xi: "\u039E", - Omicron: "\u039F", - Pi: "\u03A0", - Rho: "\u03A1", - Sigma: "\u03A3", - Tau: "\u03A4", - Upsilon: "\u03A5", - Phi: "\u03A6", - Chi: "\u03A7", - Psi: "\u03A8", - Omega: "\u03A9", - alpha: "\u03B1", - beta: "\u03B2", - gamma: "\u03B3", - delta: "\u03B4", - epsilon: "\u03B5", - zeta: "\u03B6", - eta: "\u03B7", - theta: "\u03B8", - iota: "\u03B9", - kappa: "\u03BA", - lambda: "\u03BB", - mu: "\u03BC", - nu: "\u03BD", - xi: "\u03BE", - omicron: "\u03BF", - pi: "\u03C0", - rho: "\u03C1", - sigmaf: "\u03C2", - sigma: "\u03C3", - tau: "\u03C4", - upsilon: "\u03C5", - phi: "\u03C6", - chi: "\u03C7", - psi: "\u03C8", - omega: "\u03C9", - thetasym: "\u03D1", - upsih: "\u03D2", - piv: "\u03D6", - ensp: "\u2002", - emsp: "\u2003", - thinsp: "\u2009", - zwnj: "\u200C", - zwj: "\u200D", - lrm: "\u200E", - rlm: "\u200F", - ndash: "\u2013", - mdash: "\u2014", - lsquo: "\u2018", - rsquo: "\u2019", - sbquo: "\u201A", - ldquo: "\u201C", - rdquo: "\u201D", - bdquo: "\u201E", - dagger: "\u2020", - Dagger: "\u2021", - bull: "\u2022", - hellip: "\u2026", - permil: "\u2030", - prime: "\u2032", - Prime: "\u2033", - lsaquo: "\u2039", - rsaquo: "\u203A", - oline: "\u203E", - frasl: "\u2044", - euro: "\u20AC", - image: "\u2111", - weierp: "\u2118", - real: "\u211C", - trade: "\u2122", - alefsym: "\u2135", - larr: "\u2190", - uarr: "\u2191", - rarr: "\u2192", - darr: "\u2193", - harr: "\u2194", - crarr: "\u21B5", - lArr: "\u21D0", - uArr: "\u21D1", - rArr: "\u21D2", - dArr: "\u21D3", - hArr: "\u21D4", - forall: "\u2200", - part: "\u2202", - exist: "\u2203", - empty: "\u2205", - nabla: "\u2207", - isin: "\u2208", - notin: "\u2209", - ni: "\u220B", - prod: "\u220F", - sum: "\u2211", - minus: "\u2212", - lowast: "\u2217", - radic: "\u221A", - prop: "\u221D", - infin: "\u221E", - ang: "\u2220", - and: "\u2227", - or: "\u2228", - cap: "\u2229", - cup: "\u222A", - "int": "\u222B", - there4: "\u2234", - sim: "\u223C", - cong: "\u2245", - asymp: "\u2248", - ne: "\u2260", - equiv: "\u2261", - le: "\u2264", - ge: "\u2265", - sub: "\u2282", - sup: "\u2283", - nsub: "\u2284", - sube: "\u2286", - supe: "\u2287", - oplus: "\u2295", - otimes: "\u2297", - perp: "\u22A5", - sdot: "\u22C5", - lceil: "\u2308", - rceil: "\u2309", - lfloor: "\u230A", - rfloor: "\u230B", - lang: "\u2329", - rang: "\u232A", - loz: "\u25CA", - spades: "\u2660", - clubs: "\u2663", - hearts: "\u2665", - diams: "\u2666" -}; + pp.jsx_parseExpressionContainer = function() { + var node = this.startNode(); + this.next(); + node.expression = this.type === tt.braceR + ? this.jsx_parseEmptyExpression() + : this.parseExpression(); + this.expect(tt.braceR); + return this.finishNode(node, 'JSXExpressionContainer'); + }; -},{}],10:[function(require,module,exports){ -module.exports={ - "name": "espree", - "description": "An actively-maintained fork of Esprima, the ECMAScript parsing infrastructure for multipurpose analysis", - "author": { - "name": "Nicholas C. Zakas", - "email": "nicholas+npm@nczconsulting.com" - }, - "homepage": "https://github.com/eslint/espree", - "main": "espree.js", - "bin": { - "esparse": "./bin/esparse.js", - "esvalidate": "./bin/esvalidate.js" - }, - "version": "2.2.5", - "files": [ - "bin", - "lib", - "test/run.js", - "test/runner.js", - "test/test.js", - "test/compat.js", - "test/reflect.js", - "espree.js" - ], - "engines": { - "node": ">=0.10.0" - }, - "repository": { - "type": "git", - "url": "http://github.com/eslint/espree.git" - }, - "bugs": { - "url": "http://github.com/eslint/espree.git" - }, - "licenses": [ - { - "type": "BSD", - "url": "http://github.com/nzakas/espree/raw/master/LICENSE" - } - ], - "devDependencies": { - "browserify": "^7.0.0", - "chai": "^1.10.0", - "complexity-report": "~0.6.1", - "dateformat": "^1.0.11", - "eslint": "^0.9.2", - "esprima": "git://github.com/jquery/esprima", - "esprima-fb": "^8001.2001.0-dev-harmony-fb", - "istanbul": "~0.2.6", - "json-diff": "~0.3.1", - "leche": "^1.0.1", - "mocha": "^2.0.1", - "npm-license": "^0.2.3", - "optimist": "~0.6.0", - "regenerate": "~0.5.4", - "semver": "^4.1.1", - "shelljs": "^0.3.0", - "shelljs-nodecli": "^0.1.1", - "unicode-6.3.0": "~0.1.0" - }, - "keywords": [ - "ast", - "ecmascript", - "javascript", - "parser", - "syntax" - ], - "scripts": { - "generate-regex": "node tools/generate-identifier-regex.js", - "test": "npm run-script lint && node Makefile.js test && node test/run.js", - "lint": "node Makefile.js lint", - "patch": "node Makefile.js patch", - "minor": "node Makefile.js minor", - "major": "node Makefile.js major", - "browserify": "node Makefile.js browserify", - "coverage": "npm run-script analyze-coverage && npm run-script check-coverage", - "analyze-coverage": "node node_modules/istanbul/lib/cli.js cover test/runner.js", - "check-coverage": "node node_modules/istanbul/lib/cli.js check-coverage --statement 99 --branch 99 --function 99", - "complexity": "npm run-script analyze-complexity && npm run-script check-complexity", - "analyze-complexity": "node tools/list-complexity.js", - "check-complexity": "node node_modules/complexity-report/src/cli.js --maxcc 14 --silent -l -w espree.js", - "benchmark": "node test/benchmarks.js", - "benchmark-quick": "node test/benchmarks.js quick" - }, - "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- Implements [ESTree](https://github.com/estree/estree) (both ES5 and ES6 specs) as the AST format.\n- Optional tracking of syntax node location (index-based and line-column)\n- Heavily tested and battle-hardened by inclusion in [ESLint](http://eslint.org)\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 // setting this option replaces the default values\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 super in functions\n superInFunctions: true,\n\n // enable parsing classes\n classes: true,\n\n // enable parsing of new.target\n newTarget: false,\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 // allow experimental object rest/spread\n experimentalObjectRestSpread: 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 ESTree 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 2-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* Espree uses ESTree format for the AST nodes whereas Esprima/Harmony uses a nonstandard format.\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\nWe are actively working with Esprima as part of its adoption by the jQuery Foundation. We are hoping to reconcile Espree with Esprima at some point in the future, but there are some different philosophies around how the projects work that need to be worked through. We're committed to a goal of merging Espree back into Esprima, or at the very least, to have Espree track Esprima as an upstream target so there's no duplication of effort. In the meantime, we will continue to update and maintain Espree.\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\nAll of them.\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@2.2.5", - "_shasum": "df691b9310889402aeb29cc066708c56690b854b", - "_from": "espree@^2.2.4", - "_resolved": "https://registry.npmjs.org/espree/-/espree-2.2.5.tgz" -} + // Parses following JSX attribute name-value pair. -},{}],"espree":[function(require,module,exports){ -/* -Copyright (C) 2015 Fred K. Schott -Copyright (C) 2013 Ariya Hidayat -Copyright (C) 2013 Thaddee Tyl -Copyright (C) 2013 Mathias Bynens -Copyright (C) 2012 Ariya Hidayat -Copyright (C) 2012 Mathias Bynens -Copyright (C) 2012 Joost-Wim Boekesteijn -Copyright (C) 2012 Kris Kowal -Copyright (C) 2012 Yusuke Suzuki -Copyright (C) 2012 Arpad Borsos -Copyright (C) 2011 Ariya Hidayat - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ -/*eslint no-undefined:0, no-use-before-define: 0*/ - -"use strict"; - -var syntax = require("./lib/syntax"), - tokenInfo = require("./lib/token-info"), - astNodeTypes = require("./lib/ast-node-types"), - astNodeFactory = require("./lib/ast-node-factory"), - defaultFeatures = require("./lib/features"), - Messages = require("./lib/messages"), - XHTMLEntities = require("./lib/xhtml-entities"), - StringMap = require("./lib/string-map"), - commentAttachment = require("./lib/comment-attachment"); - -var Token = tokenInfo.Token, - TokenName = tokenInfo.TokenName, - FnExprTokens = tokenInfo.FnExprTokens, - Regex = syntax.Regex, - PropertyKind, - source, - strict, - index, - lineNumber, - lineStart, - length, - lookahead, - state, - extra; - -PropertyKind = { - Data: 1, - Get: 2, - Set: 4 -}; - - -// Ensure the condition is true, otherwise throw an error. -// This is only to have a better contract semantic, i.e. another safety net -// to catch a logic error. The condition shall be fulfilled in normal case. -// Do NOT use this to enforce a certain condition on any user input. - -function assert(condition, message) { - /* istanbul ignore if */ - if (!condition) { - throw new Error("ASSERT: " + message); + pp.jsx_parseAttribute = function() { + var node = this.startNode(); + if (this.eat(tt.braceL)) { + this.expect(tt.ellipsis); + node.argument = this.parseMaybeAssign(); + this.expect(tt.braceR); + return this.finishNode(node, 'JSXSpreadAttribute'); } -} + node.name = this.jsx_parseNamespacedName(); + node.value = this.eat(tt.eq) ? this.jsx_parseAttributeValue() : null; + return this.finishNode(node, 'JSXAttribute'); + }; -// 7.4 Comments + // Parses JSX opening tag starting after '<'. + + pp.jsx_parseOpeningElementAt = function(startPos, startLoc) { + var node = this.startNodeAt(startPos, startLoc); + node.attributes = []; + node.name = this.jsx_parseElementName(); + while (this.type !== tt.slash && this.type !== tt.jsxTagEnd) + node.attributes.push(this.jsx_parseAttribute()); + node.selfClosing = this.eat(tt.slash); + this.expect(tt.jsxTagEnd); + return this.finishNode(node, 'JSXOpeningElement'); + }; -function addComment(type, value, start, end, loc) { - var comment; + // Parses JSX closing tag starting after '= start) { - return; - } - state.lastCommentStart = start; + // Parses entire JSX element, including it's opening tag + // (starting after '<'), attributes, contents and closing tag. - comment = { - type: type, - value: value - }; - if (extra.range) { - comment.range = [start, end]; - } - if (extra.loc) { - comment.loc = loc; - } - extra.comments.push(comment); + pp.jsx_parseElementAt = function(startPos, startLoc) { + var node = this.startNodeAt(startPos, startLoc); + var children = []; + var openingElement = this.jsx_parseOpeningElementAt(startPos, startLoc); + var closingElement = null; - if (extra.attachComment) { - commentAttachment.addComment(comment); - } -} + if (!openingElement.selfClosing) { + contents: for (;;) { + switch (this.type) { + case tt.jsxTagStart: + startPos = this.start; startLoc = this.startLoc; + this.next(); + if (this.eat(tt.slash)) { + closingElement = this.jsx_parseClosingElementAt(startPos, startLoc); + break contents; + } + children.push(this.jsx_parseElementAt(startPos, startLoc)); + break; -function skipSingleLineComment(offset) { - var start, loc, ch, comment; + case tt.jsxText: + children.push(this.parseExprAtom()); + break; - start = index - offset; - loc = { - start: { - line: lineNumber, - column: index - lineStart - offset - } - }; + case tt.braceL: + children.push(this.jsx_parseExpressionContainer()); + break; - while (index < length) { - ch = source.charCodeAt(index); - ++index; - if (syntax.isLineTerminator(ch)) { - if (extra.comments) { - comment = source.slice(start + offset, index - 1); - loc.end = { - line: lineNumber, - column: index - lineStart - 1 - }; - addComment("Line", comment, start, index - 1, loc); - } - if (ch === 13 && source.charCodeAt(index) === 10) { - ++index; - } - ++lineNumber; - lineStart = index; - return; + default: + this.unexpected(); } + } + if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) { + this.raise( + closingElement.start, + 'Expected corresponding JSX closing tag for <' + getQualifiedJSXName(openingElement.name) + '>'); + } } - if (extra.comments) { - comment = source.slice(start + offset, index); - loc.end = { - line: lineNumber, - column: index - lineStart - }; - addComment("Line", comment, start, index, loc); + node.openingElement = openingElement; + node.closingElement = closingElement; + node.children = children; + if (this.type === tt.relational && this.value === "<") { + this.raise(this.start, "Adjacent JSX elements must be wrapped in an enclosing tag"); } -} + return this.finishNode(node, 'JSXElement'); + }; -function skipMultiLineComment() { - var start, loc, ch, comment; + // Parses entire JSX element from current position. - if (extra.comments) { - start = index - 2; - loc = { - start: { - line: lineNumber, - column: index - lineStart - 2 - } - }; - } + pp.jsx_parseElement = function() { + var startPos = this.start, startLoc = this.startLoc; + this.next(); + return this.jsx_parseElementAt(startPos, startLoc); + }; - while (index < length) { - ch = source.charCodeAt(index); - if (syntax.isLineTerminator(ch)) { - if (ch === 0x0D && source.charCodeAt(index + 1) === 0x0A) { - ++index; - } - ++lineNumber; - ++index; - lineStart = index; - if (index >= length) { - throwError({}, Messages.UnexpectedToken, "ILLEGAL"); - } - } else if (ch === 0x2A) { - // Block comment ends with "*/". - if (source.charCodeAt(index + 1) === 0x2F) { - ++index; - ++index; - if (extra.comments) { - comment = source.slice(start + 2, index - 2); - loc.end = { - line: lineNumber, - column: index - lineStart - }; - addComment("Block", comment, start, index, loc); - } - return; - } - ++index; - } else { - ++index; - } - } + acorn.plugins.jsx = function(instance) { + instance.extend('parseExprAtom', function(inner) { + return function(refShortHandDefaultPos) { + if (this.type === tt.jsxText) + return this.parseLiteral(this.value); + else if (this.type === tt.jsxTagStart) + return this.jsx_parseElement(); + else + return inner.call(this, refShortHandDefaultPos); + }; + }); - throwError({}, Messages.UnexpectedToken, "ILLEGAL"); -} + instance.extend('readToken', function(inner) { + return function(code) { + var context = this.curContext(); -function skipComment() { - var ch, start; + if (context === tc.j_expr) return this.jsx_readToken(); - start = (index === 0); - while (index < length) { - ch = source.charCodeAt(index); + if (context === tc.j_oTag || context === tc.j_cTag) { + if (acorn.isIdentifierStart(code)) return this.jsx_readWord(); - if (syntax.isWhiteSpace(ch)) { - ++index; - } else if (syntax.isLineTerminator(ch)) { - ++index; - if (ch === 0x0D && source.charCodeAt(index) === 0x0A) { - ++index; - } - ++lineNumber; - lineStart = index; - start = true; - } else if (ch === 0x2F) { // U+002F is "/" - ch = source.charCodeAt(index + 1); - if (ch === 0x2F) { - ++index; - ++index; - skipSingleLineComment(2); - start = true; - } else if (ch === 0x2A) { // U+002A is "*" - ++index; - ++index; - skipMultiLineComment(); - } else { - break; - } - } else if (start && ch === 0x2D) { // U+002D is "-" - // U+003E is ">" - if ((source.charCodeAt(index + 1) === 0x2D) && (source.charCodeAt(index + 2) === 0x3E)) { - // "-->" is a single-line comment - index += 3; - skipSingleLineComment(3); - } else { - break; - } - } else if (ch === 0x3C) { // U+003C is "<" - if (source.slice(index + 1, index + 4) === "!--") { - ++index; // `<` - ++index; // `!` - ++index; // `-` - ++index; // `-` - skipSingleLineComment(4); - } else { - break; - } - } else { - break; + if (code == 62) { + ++this.pos; + return this.finishToken(tt.jsxTagEnd); + } + + if ((code === 34 || code === 39) && context == tc.j_oTag) + return this.jsx_readString(code); } - } -} -function scanHexEscape(prefix) { - var i, len, ch, code = 0; + if (code === 60 && this.exprAllowed) { + ++this.pos; + return this.finishToken(tt.jsxTagStart); + } + return inner.call(this, code); + }; + }); - len = (prefix === "u") ? 4 : 2; - for (i = 0; i < len; ++i) { - if (index < length && syntax.isHexDigit(source[index])) { - ch = source[index++]; - code = code * 16 + "0123456789abcdef".indexOf(ch.toLowerCase()); + instance.extend('updateContext', function(inner) { + return function(prevType) { + if (this.type == tt.braceL) { + var curContext = this.curContext(); + if (curContext == tc.j_oTag) this.context.push(tc.b_expr); + else if (curContext == tc.j_expr) this.context.push(tc.b_tmpl); + else inner.call(this, prevType); + this.exprAllowed = true; + } else if (this.type === tt.slash && prevType === tt.jsxTagStart) { + this.context.length -= 2; // do not consider JSX expr -> JSX open tag -> ... anymore + this.context.push(tc.j_cTag); // reconsider as closing tag context + this.exprAllowed = false; } else { - return ""; + return inner.call(this, prevType); } - } - return String.fromCharCode(code); -} + }; + }); + }; -/** - * Scans an extended unicode code point escape sequence from source. Throws an - * error if the sequence is empty or if the code point value is too large. - * @returns {string} The string created by the Unicode escape sequence. - * @private - */ -function scanUnicodeCodePointEscape() { - var ch, code, cu1, cu2; + return acorn; +}; + +},{"./xhtml":6}],6:[function(require,module,exports){ +module.exports = { + quot: '\u0022', + amp: '&', + apos: '\u0027', + lt: '<', + gt: '>', + nbsp: '\u00A0', + iexcl: '\u00A1', + cent: '\u00A2', + pound: '\u00A3', + curren: '\u00A4', + yen: '\u00A5', + brvbar: '\u00A6', + sect: '\u00A7', + uml: '\u00A8', + copy: '\u00A9', + ordf: '\u00AA', + laquo: '\u00AB', + not: '\u00AC', + shy: '\u00AD', + reg: '\u00AE', + macr: '\u00AF', + deg: '\u00B0', + plusmn: '\u00B1', + sup2: '\u00B2', + sup3: '\u00B3', + acute: '\u00B4', + micro: '\u00B5', + para: '\u00B6', + middot: '\u00B7', + cedil: '\u00B8', + sup1: '\u00B9', + ordm: '\u00BA', + raquo: '\u00BB', + frac14: '\u00BC', + frac12: '\u00BD', + frac34: '\u00BE', + iquest: '\u00BF', + Agrave: '\u00C0', + Aacute: '\u00C1', + Acirc: '\u00C2', + Atilde: '\u00C3', + Auml: '\u00C4', + Aring: '\u00C5', + AElig: '\u00C6', + Ccedil: '\u00C7', + Egrave: '\u00C8', + Eacute: '\u00C9', + Ecirc: '\u00CA', + Euml: '\u00CB', + Igrave: '\u00CC', + Iacute: '\u00CD', + Icirc: '\u00CE', + Iuml: '\u00CF', + ETH: '\u00D0', + Ntilde: '\u00D1', + Ograve: '\u00D2', + Oacute: '\u00D3', + Ocirc: '\u00D4', + Otilde: '\u00D5', + Ouml: '\u00D6', + times: '\u00D7', + Oslash: '\u00D8', + Ugrave: '\u00D9', + Uacute: '\u00DA', + Ucirc: '\u00DB', + Uuml: '\u00DC', + Yacute: '\u00DD', + THORN: '\u00DE', + szlig: '\u00DF', + agrave: '\u00E0', + aacute: '\u00E1', + acirc: '\u00E2', + atilde: '\u00E3', + auml: '\u00E4', + aring: '\u00E5', + aelig: '\u00E6', + ccedil: '\u00E7', + egrave: '\u00E8', + eacute: '\u00E9', + ecirc: '\u00EA', + euml: '\u00EB', + igrave: '\u00EC', + iacute: '\u00ED', + icirc: '\u00EE', + iuml: '\u00EF', + eth: '\u00F0', + ntilde: '\u00F1', + ograve: '\u00F2', + oacute: '\u00F3', + ocirc: '\u00F4', + otilde: '\u00F5', + ouml: '\u00F6', + divide: '\u00F7', + oslash: '\u00F8', + ugrave: '\u00F9', + uacute: '\u00FA', + ucirc: '\u00FB', + uuml: '\u00FC', + yacute: '\u00FD', + thorn: '\u00FE', + yuml: '\u00FF', + OElig: '\u0152', + oelig: '\u0153', + Scaron: '\u0160', + scaron: '\u0161', + Yuml: '\u0178', + fnof: '\u0192', + circ: '\u02C6', + tilde: '\u02DC', + Alpha: '\u0391', + Beta: '\u0392', + Gamma: '\u0393', + Delta: '\u0394', + Epsilon: '\u0395', + Zeta: '\u0396', + Eta: '\u0397', + Theta: '\u0398', + Iota: '\u0399', + Kappa: '\u039A', + Lambda: '\u039B', + Mu: '\u039C', + Nu: '\u039D', + Xi: '\u039E', + Omicron: '\u039F', + Pi: '\u03A0', + Rho: '\u03A1', + Sigma: '\u03A3', + Tau: '\u03A4', + Upsilon: '\u03A5', + Phi: '\u03A6', + Chi: '\u03A7', + Psi: '\u03A8', + Omega: '\u03A9', + alpha: '\u03B1', + beta: '\u03B2', + gamma: '\u03B3', + delta: '\u03B4', + epsilon: '\u03B5', + zeta: '\u03B6', + eta: '\u03B7', + theta: '\u03B8', + iota: '\u03B9', + kappa: '\u03BA', + lambda: '\u03BB', + mu: '\u03BC', + nu: '\u03BD', + xi: '\u03BE', + omicron: '\u03BF', + pi: '\u03C0', + rho: '\u03C1', + sigmaf: '\u03C2', + sigma: '\u03C3', + tau: '\u03C4', + upsilon: '\u03C5', + phi: '\u03C6', + chi: '\u03C7', + psi: '\u03C8', + omega: '\u03C9', + thetasym: '\u03D1', + upsih: '\u03D2', + piv: '\u03D6', + ensp: '\u2002', + emsp: '\u2003', + thinsp: '\u2009', + zwnj: '\u200C', + zwj: '\u200D', + lrm: '\u200E', + rlm: '\u200F', + ndash: '\u2013', + mdash: '\u2014', + lsquo: '\u2018', + rsquo: '\u2019', + sbquo: '\u201A', + ldquo: '\u201C', + rdquo: '\u201D', + bdquo: '\u201E', + dagger: '\u2020', + Dagger: '\u2021', + bull: '\u2022', + hellip: '\u2026', + permil: '\u2030', + prime: '\u2032', + Prime: '\u2033', + lsaquo: '\u2039', + rsaquo: '\u203A', + oline: '\u203E', + frasl: '\u2044', + euro: '\u20AC', + image: '\u2111', + weierp: '\u2118', + real: '\u211C', + trade: '\u2122', + alefsym: '\u2135', + larr: '\u2190', + uarr: '\u2191', + rarr: '\u2192', + darr: '\u2193', + harr: '\u2194', + crarr: '\u21B5', + lArr: '\u21D0', + uArr: '\u21D1', + rArr: '\u21D2', + dArr: '\u21D3', + hArr: '\u21D4', + forall: '\u2200', + part: '\u2202', + exist: '\u2203', + empty: '\u2205', + nabla: '\u2207', + isin: '\u2208', + notin: '\u2209', + ni: '\u220B', + prod: '\u220F', + sum: '\u2211', + minus: '\u2212', + lowast: '\u2217', + radic: '\u221A', + prop: '\u221D', + infin: '\u221E', + ang: '\u2220', + and: '\u2227', + or: '\u2228', + cap: '\u2229', + cup: '\u222A', + 'int': '\u222B', + there4: '\u2234', + sim: '\u223C', + cong: '\u2245', + asymp: '\u2248', + ne: '\u2260', + equiv: '\u2261', + le: '\u2264', + ge: '\u2265', + sub: '\u2282', + sup: '\u2283', + nsub: '\u2284', + sube: '\u2286', + supe: '\u2287', + oplus: '\u2295', + otimes: '\u2297', + perp: '\u22A5', + sdot: '\u22C5', + lceil: '\u2308', + rceil: '\u2309', + lfloor: '\u230A', + rfloor: '\u230B', + lang: '\u2329', + rang: '\u232A', + loz: '\u25CA', + spades: '\u2660', + clubs: '\u2663', + hearts: '\u2665', + diams: '\u2666' +}; - ch = source[index]; - code = 0; +},{}],7:[function(require,module,exports){ +(function (global){ +(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 = 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 0x10FFFF || ch !== "}") { - throwError({}, Messages.UnexpectedToken, "ILLEGAL"); - } +var _state = _dereq_("./state"); - // UTF-16 Encoding - if (code <= 0xFFFF) { - return String.fromCharCode(code); - } - cu1 = ((code - 0x10000) >> 10) + 0xD800; - cu2 = ((code - 0x10000) & 1023) + 0xDC00; - return String.fromCharCode(cu1, cu2); -} +var pp = _state.Parser.prototype; -function getEscapedIdentifier() { - var ch, id; +// Check if property name clashes with already added. +// Object/class getters and setters are not allowed to clash — +// either with each other or with an init property — and in +// strict mode, init properties are also not allowed to be repeated. - ch = source.charCodeAt(index++); - id = String.fromCharCode(ch); +pp.checkPropClash = function (prop, propHash) { + if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand)) return; + var key = prop.key;var name = undefined; + switch (key.type) { + case "Identifier": + name = key.name;break; + case "Literal": + name = String(key.value);break; + default: + return; + } + var kind = prop.kind; - // "\u" (U+005C, U+0075) denotes an escaped character. - if (ch === 0x5C) { - if (source.charCodeAt(index) !== 0x75) { - throwError({}, Messages.UnexpectedToken, "ILLEGAL"); - } - ++index; - ch = scanHexEscape("u"); - if (!ch || ch === "\\" || !syntax.isIdentifierStart(ch.charCodeAt(0))) { - throwError({}, Messages.UnexpectedToken, "ILLEGAL"); - } - id = ch; + if (this.options.ecmaVersion >= 6) { + if (name === "__proto__" && kind === "init") { + if (propHash.proto) this.raise(key.start, "Redefinition of __proto__ property"); + propHash.proto = true; } + return; + } + name = "$" + name; + var other = propHash[name]; + if (other) { + var isGetSet = kind !== "init"; + if ((this.strict || isGetSet) && other[kind] || !(isGetSet ^ other.init)) this.raise(key.start, "Redefinition of property"); + } else { + other = propHash[name] = { + init: false, + get: false, + set: false + }; + } + other[kind] = true; +}; + +// ### Expression parsing + +// These nest, from the most general expression type at the top to +// 'atomic', nondivisible expression types at the bottom. Most of +// the functions will simply let the function(s) below them parse, +// and, *if* the syntactic construct they handle is present, wrap +// the AST node that the inner parser gave them in another node. + +// Parse a full expression. The optional arguments are used to +// forbid the `in` operator (in for loops initalization expressions) +// and provide reference for storing '=' operator inside shorthand +// property assignment in contexts where both object expression +// and object pattern might appear (so it's possible to raise +// delayed syntax error at correct position). + +pp.parseExpression = function (noIn, refDestructuringErrors) { + var startPos = this.start, + startLoc = this.startLoc; + var expr = this.parseMaybeAssign(noIn, refDestructuringErrors); + if (this.type === _tokentype.types.comma) { + var node = this.startNodeAt(startPos, startLoc); + node.expressions = [expr]; + while (this.eat(_tokentype.types.comma)) node.expressions.push(this.parseMaybeAssign(noIn, refDestructuringErrors)); + return this.finishNode(node, "SequenceExpression"); + } + return expr; +}; - while (index < length) { - ch = source.charCodeAt(index); - if (!syntax.isIdentifierPart(ch)) { - break; - } - ++index; - id += String.fromCharCode(ch); +// Parse an assignment expression. This includes applications of +// operators like `+=`. - // "\u" (U+005C, U+0075) denotes an escaped character. - if (ch === 0x5C) { - id = id.substr(0, id.length - 1); - if (source.charCodeAt(index) !== 0x75) { - throwError({}, Messages.UnexpectedToken, "ILLEGAL"); - } - ++index; - ch = scanHexEscape("u"); - if (!ch || ch === "\\" || !syntax.isIdentifierPart(ch.charCodeAt(0))) { - throwError({}, Messages.UnexpectedToken, "ILLEGAL"); - } - id += ch; - } +pp.parseMaybeAssign = function (noIn, refDestructuringErrors, afterLeftParse) { + if (this.type == _tokentype.types._yield && this.inGenerator) return this.parseYield(); + + var validateDestructuring = false; + if (!refDestructuringErrors) { + refDestructuringErrors = { shorthandAssign: 0, trailingComma: 0 }; + validateDestructuring = true; + } + var startPos = this.start, + startLoc = this.startLoc; + if (this.type == _tokentype.types.parenL || this.type == _tokentype.types.name) this.potentialArrowAt = this.start; + var left = this.parseMaybeConditional(noIn, refDestructuringErrors); + if (afterLeftParse) left = afterLeftParse.call(this, left, startPos, startLoc); + if (this.type.isAssign) { + if (validateDestructuring) this.checkPatternErrors(refDestructuringErrors, true); + var node = this.startNodeAt(startPos, startLoc); + node.operator = this.value; + node.left = this.type === _tokentype.types.eq ? this.toAssignable(left) : left; + refDestructuringErrors.shorthandAssign = 0; // reset because shorthand default was used correctly + this.checkLVal(left); + this.next(); + node.right = this.parseMaybeAssign(noIn); + return this.finishNode(node, "AssignmentExpression"); + } else { + if (validateDestructuring) this.checkExpressionErrors(refDestructuringErrors, true); + } + return left; +}; + +// Parse a ternary conditional (`?:`) operator. + +pp.parseMaybeConditional = function (noIn, refDestructuringErrors) { + var startPos = this.start, + startLoc = this.startLoc; + var expr = this.parseExprOps(noIn, refDestructuringErrors); + if (this.checkExpressionErrors(refDestructuringErrors)) return expr; + if (this.eat(_tokentype.types.question)) { + var node = this.startNodeAt(startPos, startLoc); + node.test = expr; + node.consequent = this.parseMaybeAssign(); + this.expect(_tokentype.types.colon); + node.alternate = this.parseMaybeAssign(noIn); + return this.finishNode(node, "ConditionalExpression"); + } + return expr; +}; + +// Start the precedence parser. + +pp.parseExprOps = function (noIn, refDestructuringErrors) { + var startPos = this.start, + startLoc = this.startLoc; + var expr = this.parseMaybeUnary(refDestructuringErrors); + if (this.checkExpressionErrors(refDestructuringErrors)) return expr; + return this.parseExprOp(expr, startPos, startLoc, -1, noIn); +}; + +// Parse binary operators with the operator precedence parsing +// algorithm. `left` is the left-hand side of the operator. +// `minPrec` provides context that allows the function to stop and +// defer further parser to one of its callers when it encounters an +// operator that has a lower precedence than the set it is parsing. + +pp.parseExprOp = function (left, leftStartPos, leftStartLoc, minPrec, noIn) { + var prec = this.type.binop; + if (prec != null && (!noIn || this.type !== _tokentype.types._in)) { + if (prec > minPrec) { + var node = this.startNodeAt(leftStartPos, leftStartLoc); + node.left = left; + node.operator = this.value; + var op = this.type; + this.next(); + var startPos = this.start, + startLoc = this.startLoc; + node.right = this.parseExprOp(this.parseMaybeUnary(), startPos, startLoc, prec, noIn); + this.finishNode(node, op === _tokentype.types.logicalOR || op === _tokentype.types.logicalAND ? "LogicalExpression" : "BinaryExpression"); + return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn); + } + } + return left; +}; + +// Parse unary operators, both prefix and postfix. + +pp.parseMaybeUnary = function (refDestructuringErrors) { + if (this.type.prefix) { + var node = this.startNode(), + update = this.type === _tokentype.types.incDec; + node.operator = this.value; + node.prefix = true; + this.next(); + node.argument = this.parseMaybeUnary(); + this.checkExpressionErrors(refDestructuringErrors, true); + if (update) this.checkLVal(node.argument);else if (this.strict && node.operator === "delete" && node.argument.type === "Identifier") this.raise(node.start, "Deleting local variable in strict mode"); + return this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression"); + } + var startPos = this.start, + startLoc = this.startLoc; + var expr = this.parseExprSubscripts(refDestructuringErrors); + if (this.checkExpressionErrors(refDestructuringErrors)) return expr; + while (this.type.postfix && !this.canInsertSemicolon()) { + var node = this.startNodeAt(startPos, startLoc); + node.operator = this.value; + node.prefix = false; + node.argument = expr; + this.checkLVal(expr); + this.next(); + expr = this.finishNode(node, "UpdateExpression"); + } + return expr; +}; + +// Parse call, dot, and `[]`-subscript expressions. + +pp.parseExprSubscripts = function (refDestructuringErrors) { + var startPos = this.start, + startLoc = this.startLoc; + var expr = this.parseExprAtom(refDestructuringErrors); + var skipArrowSubscripts = expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")"; + if (this.checkExpressionErrors(refDestructuringErrors) || skipArrowSubscripts) return expr; + return this.parseSubscripts(expr, startPos, startLoc); +}; + +pp.parseSubscripts = function (base, startPos, startLoc, noCalls) { + for (;;) { + if (this.eat(_tokentype.types.dot)) { + var node = this.startNodeAt(startPos, startLoc); + node.object = base; + node.property = this.parseIdent(true); + node.computed = false; + base = this.finishNode(node, "MemberExpression"); + } else if (this.eat(_tokentype.types.bracketL)) { + var node = this.startNodeAt(startPos, startLoc); + node.object = base; + node.property = this.parseExpression(); + node.computed = true; + this.expect(_tokentype.types.bracketR); + base = this.finishNode(node, "MemberExpression"); + } else if (!noCalls && this.eat(_tokentype.types.parenL)) { + var node = this.startNodeAt(startPos, startLoc); + node.callee = base; + node.arguments = this.parseExprList(_tokentype.types.parenR, false); + base = this.finishNode(node, "CallExpression"); + } else if (this.type === _tokentype.types.backQuote) { + var node = this.startNodeAt(startPos, startLoc); + node.tag = base; + node.quasi = this.parseTemplate(); + base = this.finishNode(node, "TaggedTemplateExpression"); + } else { + return base; } + } +}; - return id; -} +// Parse an atomic expression — either a single token that is an +// expression, an expression started by a keyword like `function` or +// `new`, or an expression wrapped in punctuation like `()`, `[]`, +// or `{}`. + +pp.parseExprAtom = function (refDestructuringErrors) { + var node = undefined, + canBeArrow = this.potentialArrowAt == this.start; + switch (this.type) { + case _tokentype.types._super: + if (!this.inFunction) this.raise(this.start, "'super' outside of function or class"); + case _tokentype.types._this: + var type = this.type === _tokentype.types._this ? "ThisExpression" : "Super"; + node = this.startNode(); + this.next(); + return this.finishNode(node, type); + + case _tokentype.types._yield: + if (this.inGenerator) this.unexpected(); + + case _tokentype.types.name: + var startPos = this.start, + startLoc = this.startLoc; + var id = this.parseIdent(this.type !== _tokentype.types.name); + if (canBeArrow && !this.canInsertSemicolon() && this.eat(_tokentype.types.arrow)) return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id]); + return id; + + case _tokentype.types.regexp: + var value = this.value; + node = this.parseLiteral(value.value); + node.regex = { pattern: value.pattern, flags: value.flags }; + return node; + + case _tokentype.types.num:case _tokentype.types.string: + return this.parseLiteral(this.value); + + case _tokentype.types._null:case _tokentype.types._true:case _tokentype.types._false: + node = this.startNode(); + node.value = this.type === _tokentype.types._null ? null : this.type === _tokentype.types._true; + node.raw = this.type.keyword; + this.next(); + return this.finishNode(node, "Literal"); + + case _tokentype.types.parenL: + return this.parseParenAndDistinguishExpression(canBeArrow); + + case _tokentype.types.bracketL: + node = this.startNode(); + this.next(); + // check whether this is array comprehension or regular array + if (this.options.ecmaVersion >= 7 && this.type === _tokentype.types._for) { + return this.parseComprehension(node, false); + } + node.elements = this.parseExprList(_tokentype.types.bracketR, true, true, refDestructuringErrors); + return this.finishNode(node, "ArrayExpression"); -function getIdentifier() { - var start, ch; + case _tokentype.types.braceL: + return this.parseObj(false, refDestructuringErrors); - start = index++; - while (index < length) { - ch = source.charCodeAt(index); - if (ch === 0x5C) { - // Blackslash (U+005C) marks Unicode escape sequence. - index = start; - return getEscapedIdentifier(); - } - if (syntax.isIdentifierPart(ch)) { - ++index; - } else { - break; - } - } + case _tokentype.types._function: + node = this.startNode(); + this.next(); + return this.parseFunction(node, false); - return source.slice(start, index); -} + case _tokentype.types._class: + return this.parseClass(this.startNode(), false); -function scanIdentifier() { - var start, id, type; + case _tokentype.types._new: + return this.parseNew(); - start = index; + case _tokentype.types.backQuote: + return this.parseTemplate(); - // Backslash (U+005C) starts an escaped character. - id = (source.charCodeAt(index) === 0x5C) ? getEscapedIdentifier() : getIdentifier(); + default: + this.unexpected(); + } +}; - // There is no keyword or literal with only one character. - // Thus, it must be an identifier. - if (id.length === 1) { - type = Token.Identifier; - } else if (syntax.isKeyword(id, strict, extra.ecmaFeatures)) { - type = Token.Keyword; - } else if (id === "null") { - type = Token.NullLiteral; - } else if (id === "true" || id === "false") { - type = Token.BooleanLiteral; - } else { - type = Token.Identifier; +pp.parseLiteral = function (value) { + var node = this.startNode(); + node.value = value; + node.raw = this.input.slice(this.start, this.end); + this.next(); + return this.finishNode(node, "Literal"); +}; + +pp.parseParenExpression = function () { + this.expect(_tokentype.types.parenL); + var val = this.parseExpression(); + this.expect(_tokentype.types.parenR); + return val; +}; + +pp.parseParenAndDistinguishExpression = function (canBeArrow) { + var startPos = this.start, + startLoc = this.startLoc, + val = undefined; + if (this.options.ecmaVersion >= 6) { + this.next(); + + if (this.options.ecmaVersion >= 7 && this.type === _tokentype.types._for) { + return this.parseComprehension(this.startNodeAt(startPos, startLoc), true); + } + + var innerStartPos = this.start, + innerStartLoc = this.startLoc; + var exprList = [], + first = true; + var refDestructuringErrors = { shorthandAssign: 0, trailingComma: 0 }, + spreadStart = undefined, + innerParenStart = undefined; + while (this.type !== _tokentype.types.parenR) { + first ? first = false : this.expect(_tokentype.types.comma); + if (this.type === _tokentype.types.ellipsis) { + spreadStart = this.start; + exprList.push(this.parseParenItem(this.parseRest())); + break; + } else { + if (this.type === _tokentype.types.parenL && !innerParenStart) { + innerParenStart = this.start; + } + exprList.push(this.parseMaybeAssign(false, refDestructuringErrors, this.parseParenItem)); + } } + var innerEndPos = this.start, + innerEndLoc = this.startLoc; + this.expect(_tokentype.types.parenR); - return { - type: type, - value: id, - lineNumber: lineNumber, - lineStart: lineStart, - range: [start, index] - }; -} + if (canBeArrow && !this.canInsertSemicolon() && this.eat(_tokentype.types.arrow)) { + this.checkPatternErrors(refDestructuringErrors, true); + if (innerParenStart) this.unexpected(innerParenStart); + return this.parseParenArrowList(startPos, startLoc, exprList); + } + if (!exprList.length) this.unexpected(this.lastTokStart); + if (spreadStart) this.unexpected(spreadStart); + this.checkExpressionErrors(refDestructuringErrors, true); -// 7.7 Punctuators + if (exprList.length > 1) { + val = this.startNodeAt(innerStartPos, innerStartLoc); + val.expressions = exprList; + this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc); + } else { + val = exprList[0]; + } + } else { + val = this.parseParenExpression(); + } -function scanPunctuator() { - var start = index, - code = source.charCodeAt(index), - code2, - ch1 = source[index], - ch2, - ch3, - ch4; + if (this.options.preserveParens) { + var par = this.startNodeAt(startPos, startLoc); + par.expression = val; + return this.finishNode(par, "ParenthesizedExpression"); + } else { + return val; + } +}; - switch (code) { - // Check for most common single-character punctuators. - case 40: // ( open bracket - case 41: // ) close bracket - case 59: // ; semicolon - case 44: // , comma - case 91: // [ - case 93: // ] - case 58: // : - case 63: // ? - case 126: // ~ - ++index; +pp.parseParenItem = function (item) { + return item; +}; - if (extra.tokenize && code === 40) { - extra.openParenToken = extra.tokens.length; - } +pp.parseParenArrowList = function (startPos, startLoc, exprList) { + return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList); +}; - return { - type: Token.Punctuator, - value: String.fromCharCode(code), - lineNumber: lineNumber, - lineStart: lineStart, - range: [start, index] - }; +// New's precedence is slightly tricky. It must allow its argument to +// be a `[]` or dot subscript expression, but not a call — at least, +// not without wrapping it in parentheses. Thus, it uses the noCalls +// argument to parseSubscripts to prevent it from consuming the +// argument list. - case 123: // { open curly brace - case 125: // } close curly brace - ++index; +var empty = []; - if (extra.tokenize && code === 123) { - extra.openCurlyToken = extra.tokens.length; - } +pp.parseNew = function () { + var node = this.startNode(); + var meta = this.parseIdent(true); + if (this.options.ecmaVersion >= 6 && this.eat(_tokentype.types.dot)) { + node.meta = meta; + node.property = this.parseIdent(true); + if (node.property.name !== "target") this.raise(node.property.start, "The only valid meta property for new is new.target"); + if (!this.inFunction) this.raise(node.start, "new.target can only be used in functions"); + return this.finishNode(node, "MetaProperty"); + } + var startPos = this.start, + startLoc = this.startLoc; + node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true); + if (this.eat(_tokentype.types.parenL)) node.arguments = this.parseExprList(_tokentype.types.parenR, false);else node.arguments = empty; + return this.finishNode(node, "NewExpression"); +}; - // 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(); - } - } +// Parse template expression. - return { - type: Token.Punctuator, - value: String.fromCharCode(code), - lineNumber: lineNumber, - lineStart: lineStart, - range: [start, index] - }; +pp.parseTemplateElement = function () { + var elem = this.startNode(); + elem.value = { + raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, '\n'), + cooked: this.value + }; + this.next(); + elem.tail = this.type === _tokentype.types.backQuote; + return this.finishNode(elem, "TemplateElement"); +}; + +pp.parseTemplate = function () { + var node = this.startNode(); + this.next(); + node.expressions = []; + var curElt = this.parseTemplateElement(); + node.quasis = [curElt]; + while (!curElt.tail) { + this.expect(_tokentype.types.dollarBraceL); + node.expressions.push(this.parseExpression()); + this.expect(_tokentype.types.braceR); + node.quasis.push(curElt = this.parseTemplateElement()); + } + this.next(); + return this.finishNode(node, "TemplateLiteral"); +}; + +// Parse an object literal or binding pattern. + +pp.parseObj = function (isPattern, refDestructuringErrors) { + var node = this.startNode(), + first = true, + propHash = {}; + node.properties = []; + this.next(); + while (!this.eat(_tokentype.types.braceR)) { + if (!first) { + this.expect(_tokentype.types.comma); + if (this.afterTrailingComma(_tokentype.types.braceR)) break; + } else first = false; + + var prop = this.startNode(), + isGenerator = undefined, + startPos = undefined, + startLoc = undefined; + if (this.options.ecmaVersion >= 6) { + prop.method = false; + prop.shorthand = false; + if (isPattern || refDestructuringErrors) { + startPos = this.start; + startLoc = this.startLoc; + } + if (!isPattern) isGenerator = this.eat(_tokentype.types.star); + } + this.parsePropertyName(prop); + this.parsePropertyValue(prop, isPattern, isGenerator, startPos, startLoc, refDestructuringErrors); + this.checkPropClash(prop, propHash); + node.properties.push(this.finishNode(prop, "Property")); + } + return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression"); +}; + +pp.parsePropertyValue = function (prop, isPattern, isGenerator, startPos, startLoc, refDestructuringErrors) { + if (this.eat(_tokentype.types.colon)) { + prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors); + prop.kind = "init"; + } else if (this.options.ecmaVersion >= 6 && this.type === _tokentype.types.parenL) { + if (isPattern) this.unexpected(); + prop.kind = "init"; + prop.method = true; + prop.value = this.parseMethod(isGenerator); + } else if (this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" && (prop.key.name === "get" || prop.key.name === "set") && (this.type != _tokentype.types.comma && this.type != _tokentype.types.braceR)) { + if (isGenerator || isPattern) this.unexpected(); + prop.kind = prop.key.name; + this.parsePropertyName(prop); + prop.value = this.parseMethod(false); + var paramCount = prop.kind === "get" ? 0 : 1; + if (prop.value.params.length !== paramCount) { + var start = prop.value.start; + if (prop.kind === "get") this.raise(start, "getter should have no params");else this.raise(start, "setter should have exactly one param"); + } + if (prop.kind === "set" && prop.value.params[0].type === "RestElement") this.raise(prop.value.params[0].start, "Setter cannot use rest params"); + } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") { + prop.kind = "init"; + if (isPattern) { + if (this.keywords.test(prop.key.name) || (this.strict ? this.reservedWordsStrictBind : this.reservedWords).test(prop.key.name)) this.raise(prop.key.start, "Binding " + prop.key.name); + prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key); + } else if (this.type === _tokentype.types.eq && refDestructuringErrors) { + if (!refDestructuringErrors.shorthandAssign) refDestructuringErrors.shorthandAssign = this.start; + prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key); + } else { + prop.value = prop.key; + } + prop.shorthand = true; + } else this.unexpected(); +}; - default: - code2 = source.charCodeAt(index + 1); - - // "=" (char #61) marks an assignment or comparison operator. - if (code2 === 61) { - switch (code) { - case 37: // % - case 38: // & - case 42: // *: - case 43: // + - case 45: // - - case 47: // / - case 60: // < - case 62: // > - case 94: // ^ - case 124: // | - index += 2; - return { - type: Token.Punctuator, - value: String.fromCharCode(code) + String.fromCharCode(code2), - lineNumber: lineNumber, - lineStart: lineStart, - range: [start, index] - }; - - case 33: // ! - case 61: // = - index += 2; - - // !== and === - if (source.charCodeAt(index) === 61) { - ++index; - } - return { - type: Token.Punctuator, - value: source.slice(start, index), - lineNumber: lineNumber, - lineStart: lineStart, - range: [start, index] - }; - default: - break; - } - } - break; +pp.parsePropertyName = function (prop) { + if (this.options.ecmaVersion >= 6) { + if (this.eat(_tokentype.types.bracketL)) { + prop.computed = true; + prop.key = this.parseMaybeAssign(); + this.expect(_tokentype.types.bracketR); + return prop.key; + } else { + prop.computed = false; } + } + return prop.key = this.type === _tokentype.types.num || this.type === _tokentype.types.string ? this.parseExprAtom() : this.parseIdent(true); +}; - // Peek more characters. +// Initialize empty function node. - ch2 = source[index + 1]; - ch3 = source[index + 2]; - ch4 = source[index + 3]; +pp.initFunction = function (node) { + node.id = null; + if (this.options.ecmaVersion >= 6) { + node.generator = false; + node.expression = false; + } +}; - // 4-character punctuator: >>>= +// Parse object or class method. - if (ch1 === ">" && ch2 === ">" && ch3 === ">") { - if (ch4 === "=") { - index += 4; - return { - type: Token.Punctuator, - value: ">>>=", - lineNumber: lineNumber, - lineStart: lineStart, - range: [start, index] - }; - } - } +pp.parseMethod = function (isGenerator) { + var node = this.startNode(); + this.initFunction(node); + this.expect(_tokentype.types.parenL); + node.params = this.parseBindingList(_tokentype.types.parenR, false, false); + if (this.options.ecmaVersion >= 6) node.generator = isGenerator; + this.parseFunctionBody(node, false); + return this.finishNode(node, "FunctionExpression"); +}; - // 3-character punctuators: === !== >>> <<= >>= +// Parse arrow function expression with given parameters. - if (ch1 === ">" && ch2 === ">" && ch3 === ">") { - index += 3; - return { - type: Token.Punctuator, - value: ">>>", - lineNumber: lineNumber, - lineStart: lineStart, - range: [start, index] - }; - } +pp.parseArrowExpression = function (node, params) { + this.initFunction(node); + node.params = this.toAssignableList(params, true); + this.parseFunctionBody(node, true); + return this.finishNode(node, "ArrowFunctionExpression"); +}; - if (ch1 === "<" && ch2 === "<" && ch3 === "=") { - index += 3; - return { - type: Token.Punctuator, - value: "<<=", - lineNumber: lineNumber, - lineStart: lineStart, - range: [start, index] - }; - } +// Parse function body and check parameters. - if (ch1 === ">" && ch2 === ">" && ch3 === "=") { - index += 3; - return { - type: Token.Punctuator, - value: ">>=", - lineNumber: lineNumber, - lineStart: lineStart, - range: [start, index] - }; - } +pp.parseFunctionBody = function (node, isArrowFunction) { + var isExpression = isArrowFunction && this.type !== _tokentype.types.braceL; - // The ... operator (spread, restParams, JSX, etc.) - if (extra.ecmaFeatures.spread || - extra.ecmaFeatures.restParams || - extra.ecmaFeatures.experimentalObjectRestSpread || - (extra.ecmaFeatures.jsx && state.inJSXSpreadAttribute) - ) { - if (ch1 === "." && ch2 === "." && ch3 === ".") { - index += 3; - return { - type: Token.Punctuator, - value: "...", - lineNumber: lineNumber, - lineStart: lineStart, - range: [start, index] - }; - } - } + if (isExpression) { + node.body = this.parseMaybeAssign(); + node.expression = true; + } else { + // Start a new scope with regard to labels and the `inFunction` + // flag (restore them to their old value afterwards). + var oldInFunc = this.inFunction, + oldInGen = this.inGenerator, + oldLabels = this.labels; + this.inFunction = true;this.inGenerator = node.generator;this.labels = []; + node.body = this.parseBlock(true); + node.expression = false; + this.inFunction = oldInFunc;this.inGenerator = oldInGen;this.labels = oldLabels; + } - // Other 2-character punctuators: ++ -- << >> && || - if (ch1 === ch2 && ("+-<>&|".indexOf(ch1) >= 0)) { - index += 2; - return { - type: Token.Punctuator, - value: ch1 + ch2, - lineNumber: lineNumber, - lineStart: lineStart, - range: [start, index] - }; - } - - // the => for arrow functions - if (extra.ecmaFeatures.arrowFunctions) { - if (ch1 === "=" && ch2 === ">") { - index += 2; - return { - type: Token.Punctuator, - value: "=>", - lineNumber: lineNumber, - lineStart: lineStart, - range: [start, index] - }; - } - } + // If this is a strict mode function, verify that argument names + // are not repeated, and it does not try to bind the words `eval` + // or `arguments`. + if (this.strict || !isExpression && node.body.body.length && this.isUseStrict(node.body.body[0])) { + var oldStrict = this.strict; + this.strict = true; + if (node.id) this.checkLVal(node.id, true); + this.checkParams(node); + this.strict = oldStrict; + } else if (isArrowFunction) { + this.checkParams(node); + } +}; - if ("<>=!+-*%&|^/".indexOf(ch1) >= 0) { - ++index; - return { - type: Token.Punctuator, - value: ch1, - lineNumber: lineNumber, - lineStart: lineStart, - range: [start, index] - }; - } +// Checks function params for various disallowed patterns such as using "eval" +// or "arguments" and duplicate parameters. - if (ch1 === ".") { - ++index; - return { - type: Token.Punctuator, - value: ch1, - lineNumber: lineNumber, - lineStart: lineStart, - range: [start, index] - }; - } +pp.checkParams = function (node) { + var nameHash = {}; + for (var i = 0; i < node.params.length; i++) { + this.checkLVal(node.params[i], true, nameHash); + } +}; - throwError({}, Messages.UnexpectedToken, "ILLEGAL"); -} +// Parses a comma-separated list of expressions, and returns them as +// an array. `close` is the token type that ends the list, and +// `allowEmpty` can be turned on to allow subsequent commas with +// nothing in between them to be parsed as `null` (which is needed +// for array literals). + +pp.parseExprList = function (close, allowTrailingComma, allowEmpty, refDestructuringErrors) { + var elts = [], + first = true; + while (!this.eat(close)) { + if (!first) { + this.expect(_tokentype.types.comma); + if (this.type === close && refDestructuringErrors && !refDestructuringErrors.trailingComma) { + refDestructuringErrors.trailingComma = this.lastTokStart; + } + if (allowTrailingComma && this.afterTrailingComma(close)) break; + } else first = false; -// 7.8.3 Numeric Literals + var elt = undefined; + if (allowEmpty && this.type === _tokentype.types.comma) elt = null;else if (this.type === _tokentype.types.ellipsis) elt = this.parseSpread(refDestructuringErrors);else elt = this.parseMaybeAssign(false, refDestructuringErrors); + elts.push(elt); + } + return elts; +}; -function scanHexLiteral(start) { - var number = ""; +// Parse the next token as an identifier. If `liberal` is true (used +// when parsing properties), it will also convert keywords into +// identifiers. - while (index < length) { - if (!syntax.isHexDigit(source[index])) { - break; - } - number += source[index++]; - } +pp.parseIdent = function (liberal) { + var node = this.startNode(); + if (liberal && this.options.allowReserved == "never") liberal = false; + if (this.type === _tokentype.types.name) { + if (!liberal && (this.strict ? this.reservedWordsStrict : this.reservedWords).test(this.value) && (this.options.ecmaVersion >= 6 || this.input.slice(this.start, this.end).indexOf("\\") == -1)) this.raise(this.start, "The keyword '" + this.value + "' is reserved"); + node.name = this.value; + } else if (liberal && this.type.keyword) { + node.name = this.type.keyword; + } else { + this.unexpected(); + } + this.next(); + return this.finishNode(node, "Identifier"); +}; - if (number.length === 0) { - throwError({}, Messages.UnexpectedToken, "ILLEGAL"); - } +// Parses yield expression inside generator. - if (syntax.isIdentifierStart(source.charCodeAt(index))) { - throwError({}, Messages.UnexpectedToken, "ILLEGAL"); - } +pp.parseYield = function () { + var node = this.startNode(); + this.next(); + if (this.type == _tokentype.types.semi || this.canInsertSemicolon() || this.type != _tokentype.types.star && !this.type.startsExpr) { + node.delegate = false; + node.argument = null; + } else { + node.delegate = this.eat(_tokentype.types.star); + node.argument = this.parseMaybeAssign(); + } + return this.finishNode(node, "YieldExpression"); +}; + +// Parses array and generator comprehensions. + +pp.parseComprehension = function (node, isGenerator) { + node.blocks = []; + while (this.type === _tokentype.types._for) { + var block = this.startNode(); + this.next(); + this.expect(_tokentype.types.parenL); + block.left = this.parseBindingAtom(); + this.checkLVal(block.left, true); + this.expectContextual("of"); + block.right = this.parseExpression(); + this.expect(_tokentype.types.parenR); + node.blocks.push(this.finishNode(block, "ComprehensionBlock")); + } + node.filter = this.eat(_tokentype.types._if) ? this.parseParenExpression() : null; + node.body = this.parseExpression(); + this.expect(isGenerator ? _tokentype.types.parenR : _tokentype.types.bracketR); + node.generator = isGenerator; + return this.finishNode(node, "ComprehensionExpression"); +}; + +},{"./state":10,"./tokentype":14}],2:[function(_dereq_,module,exports){ +// This is a trick taken from Esprima. It turns out that, on +// non-Chrome browsers, to check whether a string is in a set, a +// predicate containing a big ugly `switch` statement is faster than +// a regular expression, and on Chrome the two are about on par. +// This function uses `eval` (non-lexical) to produce such a +// predicate from a space-separated string of words. +// +// It starts by sorting the words by length. - return { - type: Token.NumericLiteral, - value: parseInt("0x" + number, 16), - lineNumber: lineNumber, - lineStart: lineStart, - range: [start, index] - }; -} +// Reserved word lists for various dialects of the language -function scanBinaryLiteral(start) { - var ch, number = ""; +"use strict"; - while (index < length) { - ch = source[index]; - if (ch !== "0" && ch !== "1") { - break; - } - number += source[index++]; - } +exports.__esModule = true; +exports.isIdentifierStart = isIdentifierStart; +exports.isIdentifierChar = isIdentifierChar; +var reservedWords = { + 3: "abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile", + 5: "class enum extends super const export import", + 6: "enum", + strict: "implements interface let package private protected public static yield", + strictBind: "eval arguments" +}; + +exports.reservedWords = reservedWords; +// And the keywords + +var ecma5AndLessKeywords = "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"; + +var keywords = { + 5: ecma5AndLessKeywords, + 6: ecma5AndLessKeywords + " let const class extends export import yield super" +}; + +exports.keywords = keywords; +// ## Character categories + +// Big ugly regular expressions that match characters in the +// whitespace, identifier, and identifier-start categories. These +// are only applied when a character is found to actually have a +// code point above 128. +// Generated by `bin/generate-identifier-regex.js`. + +var nonASCIIidentifierStartChars = "ªµºÀ-ÖØ-öø-ˁˆ-ˑˠ-ˤˬˮͰ-ʹͶͷͺ-ͽͿΆΈ-ΊΌΎ-ΡΣ-ϵϷ-ҁҊ-ԯԱ-Ֆՙա-ևא-תװ-ײؠ-يٮٯٱ-ۓەۥۦۮۯۺ-ۼۿܐܒ-ܯݍ-ޥޱߊ-ߪߴߵߺࠀ-ࠕࠚࠤࠨࡀ-ࡘࢠ-ࢲऄ-हऽॐक़-ॡॱ-ঀঅ-ঌএঐও-নপ-রলশ-হঽৎড়ঢ়য়-ৡৰৱਅ-ਊਏਐਓ-ਨਪ-ਰਲਲ਼ਵਸ਼ਸਹਖ਼-ੜਫ਼ੲ-ੴઅ-ઍએ-ઑઓ-નપ-રલળવ-હઽૐૠૡଅ-ଌଏଐଓ-ନପ-ରଲଳଵ-ହଽଡ଼ଢ଼ୟ-ୡୱஃஅ-ஊஎ-ஐஒ-கஙசஜஞடணதந-பம-ஹௐఅ-ఌఎ-ఐఒ-నప-హఽౘౙౠౡಅ-ಌಎ-ಐಒ-ನಪ-ಳವ-ಹಽೞೠೡೱೲഅ-ഌഎ-ഐഒ-ഺഽൎൠൡൺ-ൿඅ-ඖක-නඳ-රලව-ෆก-ะาำเ-ๆກຂຄງຈຊຍດ-ທນ-ຟມ-ຣລວສຫອ-ະາຳຽເ-ໄໆໜ-ໟༀཀ-ཇཉ-ཬྈ-ྌက-ဪဿၐ-ၕၚ-ၝၡၥၦၮ-ၰၵ-ႁႎႠ-ჅჇჍა-ჺჼ-ቈቊ-ቍቐ-ቖቘቚ-ቝበ-ኈኊ-ኍነ-ኰኲ-ኵኸ-ኾዀዂ-ዅወ-ዖዘ-ጐጒ-ጕጘ-ፚᎀ-ᎏᎠ-Ᏼᐁ-ᙬᙯ-ᙿᚁ-ᚚᚠ-ᛪᛮ-ᛸᜀ-ᜌᜎ-ᜑᜠ-ᜱᝀ-ᝑᝠ-ᝬᝮ-ᝰក-ឳៗៜᠠ-ᡷᢀ-ᢨᢪᢰ-ᣵᤀ-ᤞᥐ-ᥭᥰ-ᥴᦀ-ᦫᧁ-ᧇᨀ-ᨖᨠ-ᩔᪧᬅ-ᬳᭅ-ᭋᮃ-ᮠᮮᮯᮺ-ᯥᰀ-ᰣᱍ-ᱏᱚ-ᱽᳩ-ᳬᳮ-ᳱᳵᳶᴀ-ᶿḀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼιῂ-ῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲ-ῴῶ-ῼⁱⁿₐ-ₜℂℇℊ-ℓℕ℘-ℝℤΩℨK-ℹℼ-ℿⅅ-ⅉⅎⅠ-ↈⰀ-Ⱞⰰ-ⱞⱠ-ⳤⳫ-ⳮⳲⳳⴀ-ⴥⴧⴭⴰ-ⵧⵯⶀ-ⶖⶠ-ⶦⶨ-ⶮⶰ-ⶶⶸ-ⶾⷀ-ⷆⷈ-ⷎⷐ-ⷖⷘ-ⷞ々-〇〡-〩〱-〵〸-〼ぁ-ゖ゛-ゟァ-ヺー-ヿㄅ-ㄭㄱ-ㆎㆠ-ㆺㇰ-ㇿ㐀-䶵一-鿌ꀀ-ꒌꓐ-ꓽꔀ-ꘌꘐ-ꘟꘪꘫꙀ-ꙮꙿ-ꚝꚠ-ꛯꜗ-ꜟꜢ-ꞈꞋ-ꞎꞐ-ꞭꞰꞱꟷ-ꠁꠃ-ꠅꠇ-ꠊꠌ-ꠢꡀ-ꡳꢂ-ꢳꣲ-ꣷꣻꤊ-ꤥꤰ-ꥆꥠ-ꥼꦄ-ꦲꧏꧠ-ꧤꧦ-ꧯꧺ-ꧾꨀ-ꨨꩀ-ꩂꩄ-ꩋꩠ-ꩶꩺꩾ-ꪯꪱꪵꪶꪹ-ꪽꫀꫂꫛ-ꫝꫠ-ꫪꫲ-ꫴꬁ-ꬆꬉ-ꬎꬑ-ꬖꬠ-ꬦꬨ-ꬮꬰ-ꭚꭜ-ꭟꭤꭥꯀ-ꯢ가-힣ힰ-ퟆퟋ-ퟻ豈-舘並-龎ff-stﬓ-ﬗיִײַ-ﬨשׁ-זּטּ-לּמּנּסּףּפּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼA-Za-zヲ-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ"; +var nonASCIIidentifierChars = "‌‍·̀-ͯ·҃-֑҇-ׇֽֿׁׂׅׄؐ-ًؚ-٩ٰۖ-ۜ۟-۪ۤۧۨ-ۭ۰-۹ܑܰ-݊ަ-ް߀-߉߫-߳ࠖ-࠙ࠛ-ࠣࠥ-ࠧࠩ-࡙࠭-࡛ࣤ-ःऺ-़ा-ॏ॑-ॗॢॣ०-९ঁ-ঃ়া-ৄেৈো-্ৗৢৣ০-৯ਁ-ਃ਼ਾ-ੂੇੈੋ-੍ੑ੦-ੱੵઁ-ઃ઼ા-ૅે-ૉો-્ૢૣ૦-૯ଁ-ଃ଼ା-ୄେୈୋ-୍ୖୗୢୣ୦-୯ஂா-ூெ-ைொ-்ௗ௦-௯ఀ-ఃా-ౄె-ైొ-్ౕౖౢౣ౦-౯ಁ-ಃ಼ಾ-ೄೆ-ೈೊ-್ೕೖೢೣ೦-೯ഁ-ഃാ-ൄെ-ൈൊ-്ൗൢൣ൦-൯ංඃ්ා-ුූෘ-ෟ෦-෯ෲෳัิ-ฺ็-๎๐-๙ັິ-ູົຼ່-ໍ໐-໙༘༙༠-༩༹༵༷༾༿ཱ-྄྆྇ྍ-ྗྙ-ྼ࿆ါ-ှ၀-၉ၖ-ၙၞ-ၠၢ-ၤၧ-ၭၱ-ၴႂ-ႍႏ-ႝ፝-፟፩-፱ᜒ-᜔ᜲ-᜴ᝒᝓᝲᝳ឴-៓៝០-៩᠋-᠍᠐-᠙ᢩᤠ-ᤫᤰ-᤻᥆-᥏ᦰ-ᧀᧈᧉ᧐-᧚ᨗ-ᨛᩕ-ᩞ᩠-᩿᩼-᪉᪐-᪙᪰-᪽ᬀ-ᬄ᬴-᭄᭐-᭙᭫-᭳ᮀ-ᮂᮡ-ᮭ᮰-᮹᯦-᯳ᰤ-᰷᱀-᱉᱐-᱙᳐-᳔᳒-᳨᳭ᳲ-᳴᳸᳹᷀-᷵᷼-᷿‿⁀⁔⃐-⃥⃜⃡-⃰⳯-⵿⳱ⷠ-〪ⷿ-゙゚〯꘠-꘩꙯ꙴ-꙽ꚟ꛰꛱ꠂ꠆ꠋꠣ-ꠧꢀꢁꢴ-꣄꣐-꣙꣠-꣱꤀-꤉ꤦ-꤭ꥇ-꥓ꦀ-ꦃ꦳-꧀꧐-꧙ꧥ꧰-꧹ꨩ-ꨶꩃꩌꩍ꩐-꩙ꩻ-ꩽꪰꪲ-ꪴꪷꪸꪾ꪿꫁ꫫ-ꫯꫵ꫶ꯣ-ꯪ꯬꯭꯰-꯹ﬞ︀-️︠-︭︳︴﹍-﹏0-9_"; + +var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]"); +var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]"); + +nonASCIIidentifierStartChars = nonASCIIidentifierChars = null; + +// These are a run-length and offset encoded representation of the +// >0xffff code points that are a valid part of identifiers. The +// offset starts at 0x10000, and each pair of numbers represents an +// offset to the next range, and then a size of the range. They were +// generated by tools/generate-identifier-regex.js +var astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 17, 26, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 99, 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, 98, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 26, 45, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 955, 52, 76, 44, 33, 24, 27, 35, 42, 34, 4, 0, 13, 47, 15, 3, 22, 0, 38, 17, 2, 24, 133, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 32, 4, 287, 47, 21, 1, 2, 0, 185, 46, 82, 47, 21, 0, 60, 42, 502, 63, 32, 0, 449, 56, 1288, 920, 104, 110, 2962, 1070, 13266, 568, 8, 30, 114, 29, 19, 47, 17, 3, 32, 20, 6, 18, 881, 68, 12, 0, 67, 12, 16481, 1, 3071, 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, 1340, 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, 16355, 541]; +var astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 1306, 2, 54, 14, 32, 9, 16, 3, 46, 10, 54, 9, 7, 2, 37, 13, 2, 9, 52, 0, 13, 2, 49, 13, 16, 9, 83, 11, 168, 11, 6, 9, 8, 2, 57, 0, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 316, 19, 13, 9, 214, 6, 3, 8, 112, 16, 16, 9, 82, 12, 9, 9, 535, 9, 20855, 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, 4305, 6, 792618, 239]; + +// This has a complexity linear to the value of the code. The +// assumption is that looking up astral identifier characters is +// rare. +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; + } +} - if (number.length === 0) { - // only 0b or 0B - throwError({}, Messages.UnexpectedToken, "ILLEGAL"); - } +// Test whether a given character code starts an identifier. +function isIdentifierStart(code, astral) { + if (code < 65) return code === 36; + if (code < 91) return true; + if (code < 97) return code === 95; + if (code < 123) return true; + if (code <= 0xffff) return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)); + if (astral === false) return false; + return isInAstralSet(code, astralIdentifierStartCodes); +} - if (index < length) { - ch = source.charCodeAt(index); - /* istanbul ignore else */ - if (syntax.isIdentifierStart(ch) || syntax.isDecimalDigit(ch)) { - throwError({}, Messages.UnexpectedToken, "ILLEGAL"); - } - } +// Test whether a given character is part of an identifier. - return { - type: Token.NumericLiteral, - value: parseInt(number, 2), - lineNumber: lineNumber, - lineStart: lineStart, - range: [start, index] - }; +function isIdentifierChar(code, astral) { + if (code < 48) return code === 36; + if (code < 58) return true; + if (code < 65) return false; + if (code < 91) return true; + if (code < 97) return code === 95; + if (code < 123) return true; + if (code <= 0xffff) return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)); + if (astral === false) return false; + return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes); } -function scanOctalLiteral(prefix, start) { - var number, octal; +},{}],3:[function(_dereq_,module,exports){ +// Acorn is a tiny, fast JavaScript parser written in JavaScript. +// +// Acorn was written by Marijn Haverbeke, Ingvar Stepanyan, and +// various contributors and released under an MIT license. +// +// Git repositories for Acorn are available at +// +// http://marijnhaverbeke.nl/git/acorn +// https://github.com/ternjs/acorn.git +// +// Please use the [github bug tracker][ghbt] to report issues. +// +// [ghbt]: https://github.com/ternjs/acorn/issues +// +// This file defines the main parser interface. The library also comes +// with a [error-tolerant parser][dammit] and an +// [abstract syntax tree walker][walk], defined in other files. +// +// [dammit]: acorn_loose.js +// [walk]: util/walk.js - if (syntax.isOctalDigit(prefix)) { - octal = true; - number = "0" + source[index++]; - } else { - octal = false; - ++index; - number = ""; - } +"use strict"; - while (index < length) { - if (!syntax.isOctalDigit(source[index])) { - break; - } - number += source[index++]; - } +exports.__esModule = true; +exports.parse = parse; +exports.parseExpressionAt = parseExpressionAt; +exports.tokenizer = tokenizer; - if (!octal && number.length === 0) { - // only 0o or 0O - throwError({}, Messages.UnexpectedToken, "ILLEGAL"); - } +var _state = _dereq_("./state"); - if (syntax.isIdentifierStart(source.charCodeAt(index)) || syntax.isDecimalDigit(source.charCodeAt(index))) { - throwError({}, Messages.UnexpectedToken, "ILLEGAL"); - } +_dereq_("./parseutil"); - return { - type: Token.NumericLiteral, - value: parseInt(number, 8), - octal: octal, - lineNumber: lineNumber, - lineStart: lineStart, - range: [start, index] - }; -} +_dereq_("./statement"); -function scanNumericLiteral() { - var number, start, ch; +_dereq_("./lval"); - ch = source[index]; - assert(syntax.isDecimalDigit(ch.charCodeAt(0)) || (ch === "."), - "Numeric literal must start with a decimal digit or a decimal point"); +_dereq_("./expression"); - start = index; - number = ""; - if (ch !== ".") { - number = source[index++]; - ch = source[index]; +_dereq_("./location"); - // Hex number starts with "0x". - // Octal number starts with "0". - if (number === "0") { - if (ch === "x" || ch === "X") { - ++index; - return scanHexLiteral(start); - } +exports.Parser = _state.Parser; +exports.plugins = _state.plugins; - // Binary number in ES6 starts with '0b' - if (extra.ecmaFeatures.binaryLiterals) { - if (ch === "b" || ch === "B") { - ++index; - return scanBinaryLiteral(start); - } - } +var _options = _dereq_("./options"); - if ((extra.ecmaFeatures.octalLiterals && (ch === "o" || ch === "O")) || syntax.isOctalDigit(ch)) { - return scanOctalLiteral(ch, start); - } +exports.defaultOptions = _options.defaultOptions; - // decimal number starts with "0" such as "09" is illegal. - if (ch && syntax.isDecimalDigit(ch.charCodeAt(0))) { - throwError({}, Messages.UnexpectedToken, "ILLEGAL"); - } - } +var _locutil = _dereq_("./locutil"); - while (syntax.isDecimalDigit(source.charCodeAt(index))) { - number += source[index++]; - } - ch = source[index]; - } +exports.Position = _locutil.Position; +exports.SourceLocation = _locutil.SourceLocation; +exports.getLineInfo = _locutil.getLineInfo; - if (ch === ".") { - number += source[index++]; - while (syntax.isDecimalDigit(source.charCodeAt(index))) { - number += source[index++]; - } - ch = source[index]; - } +var _node = _dereq_("./node"); - if (ch === "e" || ch === "E") { - number += source[index++]; +exports.Node = _node.Node; - ch = source[index]; - if (ch === "+" || ch === "-") { - number += source[index++]; - } - if (syntax.isDecimalDigit(source.charCodeAt(index))) { - while (syntax.isDecimalDigit(source.charCodeAt(index))) { - number += source[index++]; - } - } else { - throwError({}, Messages.UnexpectedToken, "ILLEGAL"); - } - } +var _tokentype = _dereq_("./tokentype"); - if (syntax.isIdentifierStart(source.charCodeAt(index))) { - throwError({}, Messages.UnexpectedToken, "ILLEGAL"); - } +exports.TokenType = _tokentype.TokenType; +exports.tokTypes = _tokentype.types; - return { - type: Token.NumericLiteral, - value: parseFloat(number), - lineNumber: lineNumber, - lineStart: lineStart, - range: [start, index] - }; -} +var _tokencontext = _dereq_("./tokencontext"); -/** - * Scan a string escape sequence and return its special character. - * @param {string} ch The starting character of the given sequence. - * @returns {Object} An object containing the character and a flag - * if the escape sequence was an octal. - * @private - */ -function scanEscapeSequence(ch) { - var code, - unescaped, - restore, - escapedCh, - octal = false; - - // An escape sequence cannot be empty - if (!ch) { - throwError({}, Messages.UnexpectedToken, "ILLEGAL"); - } - - if (syntax.isLineTerminator(ch.charCodeAt(0))) { - ++lineNumber; - if (ch === "\r" && source[index] === "\n") { - ++index; - } - lineStart = index; - escapedCh = ""; - } else if (ch === "u" && source[index] === "{") { - // Handle ES6 extended unicode code point escape sequences. - if (extra.ecmaFeatures.unicodeCodePointEscapes) { - ++index; - escapedCh = scanUnicodeCodePointEscape(); - } else { - throwError({}, Messages.UnexpectedToken, "ILLEGAL"); - } - } else if (ch === "u" || ch === "x") { - // Handle other unicode and hex codes normally - restore = index; - unescaped = scanHexEscape(ch); - if (unescaped) { - escapedCh = unescaped; - } else { - index = restore; - escapedCh = ch; - } - } else if (ch === "n") { - escapedCh = "\n"; - } else if (ch === "r") { - escapedCh = "\r"; - } else if (ch === "t") { - escapedCh = "\t"; - } else if (ch === "b") { - escapedCh = "\b"; - } else if (ch === "f") { - escapedCh = "\f"; - } else if (ch === "v") { - escapedCh = "\v"; - } else if (syntax.isOctalDigit(ch)) { - code = "01234567".indexOf(ch); - - // \0 is not octal escape sequence - if (code !== 0) { - octal = true; - } - - if (index < length && syntax.isOctalDigit(source[index])) { - octal = true; - code = code * 8 + "01234567".indexOf(source[index++]); - - // 3 digits are only allowed when string starts with 0, 1, 2, 3 - if ("0123".indexOf(ch) >= 0 && - index < length && - syntax.isOctalDigit(source[index])) { - code = code * 8 + "01234567".indexOf(source[index++]); - } - } - escapedCh = String.fromCharCode(code); - } else { - escapedCh = ch; - } +exports.TokContext = _tokencontext.TokContext; +exports.tokContexts = _tokencontext.types; - return { - ch: escapedCh, - octal: octal - }; -} +var _identifier = _dereq_("./identifier"); -function scanStringLiteral() { - var str = "", - ch, - escapedSequence, - octal = false, - start = index, - startLineNumber = lineNumber, - startLineStart = lineStart, - quote = source[index]; +exports.isIdentifierChar = _identifier.isIdentifierChar; +exports.isIdentifierStart = _identifier.isIdentifierStart; - assert((quote === "'" || quote === "\""), - "String literal must starts with a quote"); +var _tokenize = _dereq_("./tokenize"); - ++index; +exports.Token = _tokenize.Token; - while (index < length) { - ch = source[index++]; +var _whitespace = _dereq_("./whitespace"); - if (syntax.isLineTerminator(ch.charCodeAt(0))) { - break; - } else if (ch === quote) { - quote = ""; - break; - } else if (ch === "\\") { - ch = source[index++]; - escapedSequence = scanEscapeSequence(ch); - str += escapedSequence.ch; - octal = escapedSequence.octal || octal; - } else { - str += ch; - } - } +exports.isNewLine = _whitespace.isNewLine; +exports.lineBreak = _whitespace.lineBreak; +exports.lineBreakG = _whitespace.lineBreakG; +var version = "2.7.0"; - if (quote !== "") { - throwError({}, Messages.UnexpectedToken, "ILLEGAL"); - } +exports.version = version; +// The main exported interface (under `self.acorn` when in the +// browser) is a `parse` function that takes a code string and +// returns an abstract syntax tree as specified by [Mozilla parser +// API][api]. +// +// [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API - return { - type: Token.StringLiteral, - value: str, - octal: octal, - startLineNumber: startLineNumber, - startLineStart: startLineStart, - lineNumber: lineNumber, - lineStart: lineStart, - range: [start, index] - }; +function parse(input, options) { + return new _state.Parser(options, input).parse(); } -/** - * Scan a template string and return a token. This scans both the first and - * subsequent pieces of a template string and assumes that the first backtick - * or the closing } have already been scanned. - * @returns {Token} The template string token. - * @private - */ -function scanTemplate() { - var cooked = "", - ch, - escapedSequence, - start = index, - terminated = false, - tail = false, - head = (source[index] === "`"); - - ++index; +// This function tries to parse a single expression at a given +// offset in a string. Useful for parsing mixed-language formats +// that embed JavaScript expressions. - while (index < length) { - ch = source[index++]; - - if (ch === "`") { - tail = true; - terminated = true; - break; - } else if (ch === "$") { - if (source[index] === "{") { - ++index; - terminated = true; - break; - } - cooked += ch; - } else if (ch === "\\") { - ch = source[index++]; - escapedSequence = scanEscapeSequence(ch); +function parseExpressionAt(input, pos, options) { + var p = new _state.Parser(options, input, pos); + p.nextToken(); + return p.parseExpression(); +} - if (escapedSequence.octal) { - throwError({}, Messages.TemplateOctalLiteral); - } +// Acorn is organized as a tokenizer and a recursive-descent parser. +// The `tokenizer` export provides an interface to the tokenizer. - cooked += escapedSequence.ch; +function tokenizer(input, options) { + return new _state.Parser(options, input); +} - } else if (syntax.isLineTerminator(ch.charCodeAt(0))) { - ++lineNumber; - if (ch === "\r" && source[index] === "\n") { - ++index; - } - lineStart = index; - cooked += "\n"; - } else { - cooked += ch; - } - } +},{"./expression":1,"./identifier":2,"./location":4,"./locutil":5,"./lval":6,"./node":7,"./options":8,"./parseutil":9,"./state":10,"./statement":11,"./tokencontext":12,"./tokenize":13,"./tokentype":14,"./whitespace":16}],4:[function(_dereq_,module,exports){ +"use strict"; - if (!terminated) { - throwError({}, Messages.UnexpectedToken, "ILLEGAL"); - } +var _state = _dereq_("./state"); - if (index > state.curlyLastIndex) { - state.curlyLastIndex = index; +var _locutil = _dereq_("./locutil"); - if (!tail) { - state.curlyStack.push("template"); - } +var pp = _state.Parser.prototype; - if (!head) { - state.curlyStack.pop(); - } - } +// This function is used to raise exceptions on parse errors. It +// takes an offset integer (into the current `input`) to indicate +// the location of the error, attaches the position to the end +// of the error message, and then raises a `SyntaxError` with that +// message. - return { - type: Token.Template, - value: { - cooked: cooked, - raw: source.slice(start + 1, index - ((tail) ? 1 : 2)) - }, - head: head, - tail: tail, - lineNumber: lineNumber, - lineStart: lineStart, - range: [start, index] - }; -} +pp.raise = function (pos, message) { + var loc = _locutil.getLineInfo(this.input, pos); + message += " (" + loc.line + ":" + loc.column + ")"; + var err = new SyntaxError(message); + err.pos = pos;err.loc = loc;err.raisedAt = this.pos; + throw err; +}; -function testRegExp(pattern, flags) { - var tmp = pattern, - validFlags = "gmsi"; +pp.curPosition = function () { + if (this.options.locations) { + return new _locutil.Position(this.curLine, this.pos - this.lineStart); + } +}; - if (extra.ecmaFeatures.regexYFlag) { - validFlags += "y"; - } +},{"./locutil":5,"./state":10}],5:[function(_dereq_,module,exports){ +"use strict"; - if (extra.ecmaFeatures.regexUFlag) { - validFlags += "u"; - } +exports.__esModule = true; +exports.getLineInfo = getLineInfo; - if (!RegExp("^[" + validFlags + "]*$").test(flags)) { - throwError({}, Messages.InvalidRegExpFlag); - } +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +var _whitespace = _dereq_("./whitespace"); - if (flags.indexOf("u") >= 0) { - // Replace each astral symbol and every Unicode code point - // escape sequence with a single ASCII symbol to avoid throwing on - // regular expressions that are only valid in combination with the - // `/u` flag. - // Note: replacing with the ASCII symbol `x` might cause false - // negatives in unlikely scenarios. For example, `[\u{61}-b]` is a - // perfectly valid pattern that is equivalent to `[a-b]`, but it - // would be replaced by `[x-b]` which throws an error. - tmp = tmp - .replace(/\\u\{([0-9a-fA-F]+)\}/g, function ($0, $1) { - if (parseInt($1, 16) <= 0x10FFFF) { - return "x"; - } - throwError({}, Messages.InvalidRegExp); - }) - .replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g, "x"); - } +// These are used when `options.locations` is on, for the +// `startLoc` and `endLoc` properties. - // First, detect invalid regular expressions. - try { - RegExp(tmp); - } catch (e) { - throwError({}, Messages.InvalidRegExp); - } +var Position = (function () { + function Position(line, col) { + _classCallCheck(this, Position); - // Return a regular expression object for this pattern-flag pair, or - // `null` in case the current environment doesn't support the flags it - // uses. - try { - return new RegExp(pattern, flags); - } catch (exception) { - return null; - } -} + this.line = line; + this.column = col; + } -function scanRegExpBody() { - var ch, str, classMarker, terminated, body; + Position.prototype.offset = function offset(n) { + return new Position(this.line, this.column + n); + }; - ch = source[index]; - assert(ch === "/", "Regular expression literal must start with a slash"); - str = source[index++]; + return Position; +})(); - classMarker = false; - terminated = false; - while (index < length) { - ch = source[index++]; - str += ch; - if (ch === "\\") { - ch = source[index++]; - // ECMA-262 7.8.5 - if (syntax.isLineTerminator(ch.charCodeAt(0))) { - throwError({}, Messages.UnterminatedRegExp); - } - str += ch; - } else if (syntax.isLineTerminator(ch.charCodeAt(0))) { - throwError({}, Messages.UnterminatedRegExp); - } else if (classMarker) { - if (ch === "]") { - classMarker = false; - } - } else { - if (ch === "/") { - terminated = true; - break; - } else if (ch === "[") { - classMarker = true; - } - } - } +exports.Position = Position; - if (!terminated) { - throwError({}, Messages.UnterminatedRegExp); - } +var SourceLocation = function SourceLocation(p, start, end) { + _classCallCheck(this, SourceLocation); - // Exclude leading and trailing slash. - body = str.substr(1, str.length - 2); - return { - value: body, - literal: str - }; + this.start = start; + this.end = end; + if (p.sourceFile !== null) this.source = p.sourceFile; } -function scanRegExpFlags() { - var ch, str, flags, restore; +// The `getLineInfo` function is mostly useful when the +// `locations` option is off (for performance reasons) and you +// want to find the line/column position for a given character +// offset. `input` should be the code string that the offset refers +// into. - str = ""; - flags = ""; - while (index < length) { - ch = source[index]; - if (!syntax.isIdentifierPart(ch.charCodeAt(0))) { - break; - } +; - ++index; - if (ch === "\\" && index < length) { - ch = source[index]; - if (ch === "u") { - ++index; - restore = index; - ch = scanHexEscape("u"); - if (ch) { - flags += ch; - for (str += "\\u"; restore < index; ++restore) { - str += source[restore]; - } - } else { - index = restore; - flags += "u"; - str += "\\u"; - } - throwErrorTolerant({}, Messages.UnexpectedToken, "ILLEGAL"); - } else { - str += "\\"; - throwErrorTolerant({}, Messages.UnexpectedToken, "ILLEGAL"); - } - } else { - flags += ch; - str += ch; - } - } +exports.SourceLocation = SourceLocation; - return { - value: flags, - literal: str - }; +function getLineInfo(input, offset) { + for (var line = 1, cur = 0;;) { + _whitespace.lineBreakG.lastIndex = cur; + var match = _whitespace.lineBreakG.exec(input); + if (match && match.index < offset) { + ++line; + cur = match.index + match[0].length; + } else { + return new Position(line, offset - cur); + } + } } -function scanRegExp() { - var start, body, flags, value; - - lookahead = null; - skipComment(); - start = index; - - body = scanRegExpBody(); - flags = scanRegExpFlags(); - value = testRegExp(body.value, flags.value); +},{"./whitespace":16}],6:[function(_dereq_,module,exports){ +"use strict"; - if (extra.tokenize) { - return { - type: Token.RegularExpression, - value: value, - regex: { - pattern: body.value, - flags: flags.value - }, - lineNumber: lineNumber, - lineStart: lineStart, - range: [start, index] - }; - } +var _tokentype = _dereq_("./tokentype"); - return { - literal: body.literal + flags.literal, - value: value, - regex: { - pattern: body.value, - flags: flags.value - }, - range: [start, index] - }; -} +var _state = _dereq_("./state"); -function collectRegex() { - var pos, loc, regex, token; +var _util = _dereq_("./util"); - skipComment(); +var pp = _state.Parser.prototype; - pos = index; - loc = { - start: { - line: lineNumber, - column: index - lineStart - } - }; +// Convert existing expression atom to assignable pattern +// if possible. - regex = scanRegExp(); - loc.end = { - line: lineNumber, - column: index - lineStart - }; +pp.toAssignable = function (node, isBinding) { + if (this.options.ecmaVersion >= 6 && node) { + switch (node.type) { + case "Identifier": + case "ObjectPattern": + case "ArrayPattern": + break; - /* istanbul ignore next */ - if (!extra.tokenize) { - // Pop the previous token, which is likely "/" or "/=" - if (extra.tokens.length > 0) { - token = extra.tokens[extra.tokens.length - 1]; - if (token.range[0] === pos && token.type === "Punctuator") { - if (token.value === "/" || token.value === "/=") { - extra.tokens.pop(); - } - } + case "ObjectExpression": + node.type = "ObjectPattern"; + for (var i = 0; i < node.properties.length; i++) { + var prop = node.properties[i]; + if (prop.kind !== "init") this.raise(prop.key.start, "Object pattern can't contain getter or setter"); + this.toAssignable(prop.value, isBinding); } + break; - extra.tokens.push({ - type: "RegularExpression", - value: regex.literal, - regex: regex.regex, - range: [pos, index], - loc: loc - }); - } + case "ArrayExpression": + node.type = "ArrayPattern"; + this.toAssignableList(node.elements, isBinding); + break; - return regex; -} - -function isIdentifierName(token) { - return token.type === Token.Identifier || - token.type === Token.Keyword || - token.type === Token.BooleanLiteral || - token.type === Token.NullLiteral; -} - -function advanceSlash() { - var prevToken, - checkToken; - // Using the following algorithm: - // https://github.com/mozilla/sweet.js/wiki/design - prevToken = extra.tokens[extra.tokens.length - 1]; - if (!prevToken) { - // Nothing before that: it cannot be a division. - return collectRegex(); - } - if (prevToken.type === "Punctuator") { - if (prevToken.value === "]") { - return scanPunctuator(); - } - if (prevToken.value === ")") { - checkToken = extra.tokens[extra.openParenToken - 1]; - if (checkToken && - checkToken.type === "Keyword" && - (checkToken.value === "if" || - checkToken.value === "while" || - checkToken.value === "for" || - checkToken.value === "with")) { - return collectRegex(); - } - return scanPunctuator(); - } - if (prevToken.value === "}") { - // Dividing a function by anything makes little sense, - // but we have to check for that. - if (extra.tokens[extra.openCurlyToken - 3] && - extra.tokens[extra.openCurlyToken - 3].type === "Keyword") { - // Anonymous function. - checkToken = extra.tokens[extra.openCurlyToken - 4]; - if (!checkToken) { - return scanPunctuator(); - } - } else if (extra.tokens[extra.openCurlyToken - 4] && - extra.tokens[extra.openCurlyToken - 4].type === "Keyword") { - // Named function. - checkToken = extra.tokens[extra.openCurlyToken - 5]; - if (!checkToken) { - return collectRegex(); - } - } else { - return scanPunctuator(); - } - // checkToken determines whether the function is - // a declaration or an expression. - if (FnExprTokens.indexOf(checkToken.value) >= 0) { - // It is an expression. - return scanPunctuator(); - } - // It is a declaration. - return collectRegex(); - } - return collectRegex(); - } - if (prevToken.type === "Keyword") { - return collectRegex(); - } - return scanPunctuator(); -} + case "AssignmentExpression": + if (node.operator === "=") { + node.type = "AssignmentPattern"; + delete node.operator; + // falls through to AssignmentPattern + } else { + this.raise(node.left.end, "Only '=' operator can be used for specifying default value."); + break; + } -function advance() { - var ch, - allowJSX = extra.ecmaFeatures.jsx, - allowTemplateStrings = extra.ecmaFeatures.templateStrings; + case "AssignmentPattern": + if (node.right.type === "YieldExpression") this.raise(node.right.start, "Yield expression cannot be a default value"); + break; - /* - * If JSX isn't allowed or JSX is allowed and we're not inside an JSX child, - * then skip any comments. - */ - if (!allowJSX || !state.inJSXChild) { - skipComment(); - } + case "ParenthesizedExpression": + node.expression = this.toAssignable(node.expression, isBinding); + break; - if (index >= length) { - return { - type: Token.EOF, - lineNumber: lineNumber, - lineStart: lineStart, - range: [index, index] - }; - } + case "MemberExpression": + if (!isBinding) break; - // if inside an JSX child, then abort regular tokenization - if (allowJSX && state.inJSXChild) { - return advanceJSXChild(); + default: + this.raise(node.start, "Assigning to rvalue"); } + } + return node; +}; - ch = source.charCodeAt(index); +// Convert list of expression atoms to binding list. - // Very common: ( and ) and ; - if (ch === 0x28 || ch === 0x29 || ch === 0x3B) { - return scanPunctuator(); +pp.toAssignableList = function (exprList, isBinding) { + var end = exprList.length; + if (end) { + var last = exprList[end - 1]; + if (last && last.type == "RestElement") { + --end; + } else if (last && last.type == "SpreadElement") { + last.type = "RestElement"; + var arg = last.argument; + this.toAssignable(arg, isBinding); + if (arg.type !== "Identifier" && arg.type !== "MemberExpression" && arg.type !== "ArrayPattern") this.unexpected(arg.start); + --end; } - // String literal starts with single quote (U+0027) or double quote (U+0022). - if (ch === 0x27 || ch === 0x22) { - if (allowJSX && state.inJSXTag) { - return scanJSXStringLiteral(); - } + if (isBinding && last.type === "RestElement" && last.argument.type !== "Identifier") this.unexpected(last.argument.start); + } + for (var i = 0; i < end; i++) { + var elt = exprList[i]; + if (elt) this.toAssignable(elt, isBinding); + } + return exprList; +}; - return scanStringLiteral(); - } +// Parses spread element. - if (allowJSX && state.inJSXTag && syntax.isJSXIdentifierStart(ch)) { - return scanJSXIdentifier(); - } +pp.parseSpread = function (refDestructuringErrors) { + var node = this.startNode(); + this.next(); + node.argument = this.parseMaybeAssign(refDestructuringErrors); + return this.finishNode(node, "SpreadElement"); +}; - // Template strings start with backtick (U+0096) or closing curly brace (125) and backtick. - if (allowTemplateStrings) { +pp.parseRest = function (allowNonIdent) { + var node = this.startNode(); + this.next(); - // template strings start with backtick (96) or open curly (125) but only if the open - // curly closes a previously opened curly from a template. - if (ch === 96 || (ch === 125 && state.curlyStack[state.curlyStack.length - 1] === "template")) { - return scanTemplate(); - } - } + // RestElement inside of a function parameter must be an identifier + if (allowNonIdent) node.argument = this.type === _tokentype.types.name ? this.parseIdent() : this.unexpected();else node.argument = this.type === _tokentype.types.name || this.type === _tokentype.types.bracketL ? this.parseBindingAtom() : this.unexpected(); - if (syntax.isIdentifierStart(ch)) { - return scanIdentifier(); - } + return this.finishNode(node, "RestElement"); +}; - // Dot (.) U+002E can also start a floating-point number, hence the need - // to check the next character. - if (ch === 0x2E) { - if (syntax.isDecimalDigit(source.charCodeAt(index + 1))) { - return scanNumericLiteral(); - } - return scanPunctuator(); - } +// Parses lvalue (assignable) atom. - if (syntax.isDecimalDigit(ch)) { - return scanNumericLiteral(); - } +pp.parseBindingAtom = function () { + if (this.options.ecmaVersion < 6) return this.parseIdent(); + switch (this.type) { + case _tokentype.types.name: + return this.parseIdent(); - // Slash (/) U+002F can also start a regex. - if (extra.tokenize && ch === 0x2F) { - return advanceSlash(); - } + case _tokentype.types.bracketL: + var node = this.startNode(); + this.next(); + node.elements = this.parseBindingList(_tokentype.types.bracketR, true, true); + return this.finishNode(node, "ArrayPattern"); - return scanPunctuator(); -} + case _tokentype.types.braceL: + return this.parseObj(true); -function collectToken() { - var loc, token, range, value, entry, - allowJSX = extra.ecmaFeatures.jsx; + default: + this.unexpected(); + } +}; - /* istanbul ignore else */ - if (!allowJSX || !state.inJSXChild) { - skipComment(); +pp.parseBindingList = function (close, allowEmpty, allowTrailingComma, allowNonIdent) { + var elts = [], + first = true; + while (!this.eat(close)) { + if (first) first = false;else this.expect(_tokentype.types.comma); + if (allowEmpty && this.type === _tokentype.types.comma) { + elts.push(null); + } else if (allowTrailingComma && this.afterTrailingComma(close)) { + break; + } else if (this.type === _tokentype.types.ellipsis) { + var rest = this.parseRest(allowNonIdent); + this.parseBindingListItem(rest); + elts.push(rest); + this.expect(close); + break; + } else { + var elem = this.parseMaybeDefault(this.start, this.startLoc); + this.parseBindingListItem(elem); + elts.push(elem); } + } + return elts; +}; - loc = { - start: { - line: lineNumber, - column: index - lineStart - } - }; +pp.parseBindingListItem = function (param) { + return param; +}; - token = advance(); - loc.end = { - line: lineNumber, - column: index - lineStart - }; +// Parses assignment pattern around given atom if possible. - if (token.type !== Token.EOF) { - range = [token.range[0], token.range[1]]; - value = source.slice(token.range[0], token.range[1]); - entry = { - type: TokenName[token.type], - value: value, - range: range, - loc: loc - }; - if (token.regex) { - entry.regex = { - pattern: token.regex.pattern, - flags: token.regex.flags - }; - } - extra.tokens.push(entry); - } +pp.parseMaybeDefault = function (startPos, startLoc, left) { + left = left || this.parseBindingAtom(); + if (this.options.ecmaVersion < 6 || !this.eat(_tokentype.types.eq)) return left; + var node = this.startNodeAt(startPos, startLoc); + node.left = left; + node.right = this.parseMaybeAssign(); + return this.finishNode(node, "AssignmentPattern"); +}; - return token; -} +// Verify that a node is an lval — something that can be assigned +// to. -function lex() { - var token; +pp.checkLVal = function (expr, isBinding, checkClashes) { + switch (expr.type) { + case "Identifier": + if (this.strict && this.reservedWordsStrictBind.test(expr.name)) this.raise(expr.start, (isBinding ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); + if (checkClashes) { + if (_util.has(checkClashes, expr.name)) this.raise(expr.start, "Argument name clash"); + checkClashes[expr.name] = true; + } + break; - token = lookahead; - index = token.range[1]; - lineNumber = token.lineNumber; - lineStart = token.lineStart; + case "MemberExpression": + if (isBinding) this.raise(expr.start, (isBinding ? "Binding" : "Assigning to") + " member expression"); + break; - lookahead = (typeof extra.tokens !== "undefined") ? collectToken() : advance(); + case "ObjectPattern": + for (var i = 0; i < expr.properties.length; i++) { + this.checkLVal(expr.properties[i].value, isBinding, checkClashes); + }break; - index = token.range[1]; - lineNumber = token.lineNumber; - lineStart = token.lineStart; + case "ArrayPattern": + for (var i = 0; i < expr.elements.length; i++) { + var elem = expr.elements[i]; + if (elem) this.checkLVal(elem, isBinding, checkClashes); + } + break; - return token; -} + case "AssignmentPattern": + this.checkLVal(expr.left, isBinding, checkClashes); + break; -function peek() { - var pos, - line, - start; + case "RestElement": + this.checkLVal(expr.argument, isBinding, checkClashes); + break; - pos = index; - line = lineNumber; - start = lineStart; + case "ParenthesizedExpression": + this.checkLVal(expr.expression, isBinding, checkClashes); + break; - lookahead = (typeof extra.tokens !== "undefined") ? collectToken() : advance(); + default: + this.raise(expr.start, (isBinding ? "Binding" : "Assigning to") + " rvalue"); + } +}; - index = pos; - lineNumber = line; - lineStart = start; -} +},{"./state":10,"./tokentype":14,"./util":15}],7:[function(_dereq_,module,exports){ +"use strict"; -function lookahead2() { - var adv, pos, line, start, result; +exports.__esModule = true; - // If we are collecting the tokens, don't grab the next one yet. - /* istanbul ignore next */ - adv = (typeof extra.advance === "function") ? extra.advance : advance; +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - pos = index; - line = lineNumber; - start = lineStart; +var _state = _dereq_("./state"); - // Scan for the next immediate token. - /* istanbul ignore if */ - if (lookahead === null) { - lookahead = adv(); - } - index = lookahead.range[1]; - lineNumber = lookahead.lineNumber; - lineStart = lookahead.lineStart; +var _locutil = _dereq_("./locutil"); - // Grab the token right after. - result = adv(); - index = pos; - lineNumber = line; - lineStart = start; +var Node = function Node(parser, pos, loc) { + _classCallCheck(this, Node); - return result; + this.type = ""; + this.start = pos; + this.end = 0; + if (parser.options.locations) this.loc = new _locutil.SourceLocation(parser, loc); + if (parser.options.directSourceFile) this.sourceFile = parser.options.directSourceFile; + if (parser.options.ranges) this.range = [pos, 0]; } +// Start an AST node, attaching a start offset. -//------------------------------------------------------------------------------ -// JSX -//------------------------------------------------------------------------------ +; -function getQualifiedJSXName(object) { - if (object.type === astNodeTypes.JSXIdentifier) { - return object.name; - } - if (object.type === astNodeTypes.JSXNamespacedName) { - return object.namespace.name + ":" + object.name.name; - } - /* istanbul ignore else */ - if (object.type === astNodeTypes.JSXMemberExpression) { - return ( - getQualifiedJSXName(object.object) + "." + - getQualifiedJSXName(object.property) - ); - } - /* istanbul ignore next */ - throwUnexpected(object); -} +exports.Node = Node; +var pp = _state.Parser.prototype; -function scanJSXIdentifier() { - var ch, start, value = ""; +pp.startNode = function () { + return new Node(this, this.start, this.startLoc); +}; - start = index; - while (index < length) { - ch = source.charCodeAt(index); - if (!syntax.isJSXIdentifierPart(ch)) { - break; - } - value += source[index++]; - } +pp.startNodeAt = function (pos, loc) { + return new Node(this, pos, loc); +}; - return { - type: Token.JSXIdentifier, - value: value, - lineNumber: lineNumber, - lineStart: lineStart, - range: [start, index] - }; +// Finish an AST node, adding `type` and `end` properties. + +function finishNodeAt(node, type, pos, loc) { + node.type = type; + node.end = pos; + if (this.options.locations) node.loc.end = loc; + if (this.options.ranges) node.range[1] = pos; + return node; } -function scanJSXEntity() { - var ch, str = "", start = index, count = 0, code; - ch = source[index]; - assert(ch === "&", "Entity must start with an ampersand"); - index++; - while (index < length && count++ < 10) { - ch = source[index++]; - if (ch === ";") { - break; - } - str += ch; - } +pp.finishNode = function (node, type) { + return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc); +}; - // Well-formed entity (ending was found). - if (ch === ";") { - // Numeric entity. - if (str[0] === "#") { - if (str[1] === "x") { - code = +("0" + str.substr(1)); - } else { - // Removing leading zeros in order to avoid treating as octal in old browsers. - code = +str.substr(1).replace(Regex.LeadingZeros, ""); - } +// Finish node at given position - if (!isNaN(code)) { - return String.fromCharCode(code); - } - /* istanbul ignore else */ - } else if (XHTMLEntities[str]) { - return XHTMLEntities[str]; - } - } +pp.finishNodeAt = function (node, type, pos, loc) { + return finishNodeAt.call(this, node, type, pos, loc); +}; - // Treat non-entity sequences as regular text. - index = start + 1; - return "&"; +},{"./locutil":5,"./state":10}],8:[function(_dereq_,module,exports){ +"use strict"; + +exports.__esModule = true; +exports.getOptions = getOptions; + +var _util = _dereq_("./util"); + +var _locutil = _dereq_("./locutil"); + +// A second optional argument can be given to further configure +// the parser process. These options are recognized: + +var defaultOptions = { + // `ecmaVersion` indicates the ECMAScript version to parse. Must + // be either 3, or 5, or 6. This influences support for strict + // mode, the set of reserved words, support for getters and + // setters and other features. + ecmaVersion: 5, + // Source type ("script" or "module") for different semantics + sourceType: "script", + // `onInsertedSemicolon` can be a callback that will be called + // when a semicolon is automatically inserted. It will be passed + // th position of the comma as an offset, and if `locations` is + // enabled, it is given the location as a `{line, column}` object + // as second argument. + onInsertedSemicolon: null, + // `onTrailingComma` is similar to `onInsertedSemicolon`, but for + // trailing commas. + onTrailingComma: null, + // By default, reserved words are only enforced if ecmaVersion >= 5. + // Set `allowReserved` to a boolean value to explicitly turn this on + // an off. When this option has the value "never", reserved words + // and keywords can also not be used as property names. + allowReserved: null, + // When enabled, a return at the top level is not considered an + // error. + allowReturnOutsideFunction: false, + // When enabled, import/export statements are not constrained to + // appearing at the top of the program. + allowImportExportEverywhere: false, + // When enabled, hashbang directive in the beginning of file + // is allowed and treated as a line comment. + allowHashBang: false, + // When `locations` is on, `loc` properties holding objects with + // `start` and `end` properties in `{line, column}` form (with + // line being 1-based and column 0-based) will be attached to the + // nodes. + locations: false, + // A function can be passed as `onToken` option, which will + // cause Acorn to call that function with object in the same + // format as tokens returned from `tokenizer().getToken()`. Note + // that you are not allowed to call the parser from the + // callback—that will corrupt its internal state. + onToken: null, + // A function can be passed as `onComment` option, which will + // cause Acorn to call that function with `(block, text, start, + // end)` parameters whenever a comment is skipped. `block` is a + // boolean indicating whether this is a block (`/* */`) comment, + // `text` is the content of the comment, and `start` and `end` are + // character offsets that denote the start and end of the comment. + // When the `locations` option is on, two more parameters are + // passed, the full `{line, column}` locations of the start and + // end of the comments. Note that you are not allowed to call the + // parser from the callback—that will corrupt its internal state. + onComment: null, + // Nodes have their start and end characters offsets recorded in + // `start` and `end` properties (directly on the node, rather than + // the `loc` object, which holds line/column data. To also add a + // [semi-standardized][range] `range` property holding a `[start, + // end]` array with the same numbers, set the `ranges` option to + // `true`. + // + // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678 + ranges: false, + // It is possible to parse multiple files into a single AST by + // passing the tree produced by parsing the first file as + // `program` option in subsequent parses. This will add the + // toplevel forms of the parsed file to the `Program` (top) node + // of an existing parse tree. + program: null, + // When `locations` is on, you can pass this to record the source + // file in every node's `loc` object. + sourceFile: null, + // This value, if given, is stored in every node, whether + // `locations` is on or off. + directSourceFile: null, + // When enabled, parenthesized expressions are represented by + // (non-standard) ParenthesizedExpression nodes + preserveParens: false, + plugins: {} +}; + +exports.defaultOptions = defaultOptions; +// Interpret and default an options object + +function getOptions(opts) { + var options = {}; + for (var opt in defaultOptions) { + options[opt] = opts && _util.has(opts, opt) ? opts[opt] : defaultOptions[opt]; + }if (options.allowReserved == null) options.allowReserved = options.ecmaVersion < 5; + + if (_util.isArray(options.onToken)) { + (function () { + var tokens = options.onToken; + options.onToken = function (token) { + return tokens.push(token); + }; + })(); + } + if (_util.isArray(options.onComment)) options.onComment = pushComment(options, options.onComment); + + return options; } -function scanJSXText(stopChars) { - var ch, str = "", start; - start = index; - while (index < length) { - ch = source[index]; - if (stopChars.indexOf(ch) !== -1) { - break; - } - if (ch === "&") { - str += scanJSXEntity(); - } else { - index++; - if (ch === "\r" && source[index] === "\n") { - str += ch; - ch = source[index]; - index++; - } - if (syntax.isLineTerminator(ch.charCodeAt(0))) { - ++lineNumber; - lineStart = index; - } - str += ch; - } - } - return { - type: Token.JSXText, - value: str, - lineNumber: lineNumber, - lineStart: lineStart, - range: [start, index] +function pushComment(options, array) { + return function (block, text, start, end, startLoc, endLoc) { + var comment = { + type: block ? 'Block' : 'Line', + value: text, + start: start, + end: end }; + if (options.locations) comment.loc = new _locutil.SourceLocation(this, startLoc, endLoc); + if (options.ranges) comment.range = [start, end]; + array.push(comment); + }; } -function scanJSXStringLiteral() { - var innerToken, quote, start; - - quote = source[index]; - assert((quote === "\"" || quote === "'"), - "String literal must starts with a quote"); - - start = index; - ++index; - - innerToken = scanJSXText([quote]); - - if (quote !== source[index]) { - throwError({}, Messages.UnexpectedToken, "ILLEGAL"); - } +},{"./locutil":5,"./util":15}],9:[function(_dereq_,module,exports){ +"use strict"; - ++index; +var _tokentype = _dereq_("./tokentype"); - innerToken.range = [start, index]; +var _state = _dereq_("./state"); - return innerToken; -} +var _whitespace = _dereq_("./whitespace"); -/* - * Between JSX opening and closing tags (e.g. HERE), anything that - * is not another JSX tag and is not an expression wrapped by {} is text. - */ -function advanceJSXChild() { - var ch = source.charCodeAt(index); +var pp = _state.Parser.prototype; - // { (123) and < (60) - if (ch !== 123 && ch !== 60) { - return scanJSXText(["<", "{"]); - } +// ## Parser utilities - return scanPunctuator(); -} +// Test whether a statement node is the string literal `"use strict"`. -function parseJSXIdentifier() { - var token, marker = markerCreate(); +pp.isUseStrict = function (stmt) { + return this.options.ecmaVersion >= 5 && stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && stmt.expression.raw.slice(1, -1) === "use strict"; +}; - if (lookahead.type !== Token.JSXIdentifier) { - throwUnexpected(lookahead); - } +// Predicate that tests whether the next token is of the given +// type, and if yes, consumes it as a side effect. - token = lex(); - return markerApply(marker, astNodeFactory.createJSXIdentifier(token.value)); -} +pp.eat = function (type) { + if (this.type === type) { + this.next(); + return true; + } else { + return false; + } +}; -function parseJSXNamespacedName() { - var namespace, name, marker = markerCreate(); +// Tests whether parsed token is a contextual keyword. - namespace = parseJSXIdentifier(); - expect(":"); - name = parseJSXIdentifier(); +pp.isContextual = function (name) { + return this.type === _tokentype.types.name && this.value === name; +}; - return markerApply(marker, astNodeFactory.createJSXNamespacedName(namespace, name)); -} +// Consumes contextual keyword if possible. -function parseJSXMemberExpression() { - var marker = markerCreate(), - expr = parseJSXIdentifier(); +pp.eatContextual = function (name) { + return this.value === name && this.eat(_tokentype.types.name); +}; - while (match(".")) { - lex(); - expr = markerApply(marker, astNodeFactory.createJSXMemberExpression(expr, parseJSXIdentifier())); - } +// Asserts that following token is given contextual keyword. - return expr; -} +pp.expectContextual = function (name) { + if (!this.eatContextual(name)) this.unexpected(); +}; -function parseJSXElementName() { - if (lookahead2().value === ":") { - return parseJSXNamespacedName(); - } - if (lookahead2().value === ".") { - return parseJSXMemberExpression(); - } +// Test whether a semicolon can be inserted at the current position. - return parseJSXIdentifier(); -} +pp.canInsertSemicolon = function () { + return this.type === _tokentype.types.eof || this.type === _tokentype.types.braceR || _whitespace.lineBreak.test(this.input.slice(this.lastTokEnd, this.start)); +}; -function parseJSXAttributeName() { - if (lookahead2().value === ":") { - return parseJSXNamespacedName(); - } +pp.insertSemicolon = function () { + if (this.canInsertSemicolon()) { + if (this.options.onInsertedSemicolon) this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc); + return true; + } +}; - return parseJSXIdentifier(); -} +// Consume a semicolon, or, failing that, see if we are allowed to +// pretend that there is a semicolon at this position. -function parseJSXAttributeValue() { - var value, marker; - if (match("{")) { - value = parseJSXExpressionContainer(); - if (value.expression.type === astNodeTypes.JSXEmptyExpression) { - throwError( - value, - "JSX attributes must only be assigned a non-empty " + - "expression" - ); - } - } else if (match("<")) { - value = parseJSXElement(); - } else if (lookahead.type === Token.JSXText) { - marker = markerCreate(); - value = markerApply(marker, astNodeFactory.createLiteralFromSource(lex(), source)); - } else { - throwError({}, Messages.InvalidJSXAttributeValue); - } - return value; -} +pp.semicolon = function () { + if (!this.eat(_tokentype.types.semi) && !this.insertSemicolon()) this.unexpected(); +}; -function parseJSXEmptyExpression() { - var marker = markerCreatePreserveWhitespace(); - while (source.charAt(index) !== "}") { - index++; - } - return markerApply(marker, astNodeFactory.createJSXEmptyExpression()); -} +pp.afterTrailingComma = function (tokType) { + if (this.type == tokType) { + if (this.options.onTrailingComma) this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc); + this.next(); + return true; + } +}; -function parseJSXExpressionContainer() { - var expression, origInJSXChild, origInJSXTag, marker = markerCreate(); +// Expect a token of a given type. If found, consume it, otherwise, +// raise an unexpected token error. - origInJSXChild = state.inJSXChild; - origInJSXTag = state.inJSXTag; - state.inJSXChild = false; - state.inJSXTag = false; +pp.expect = function (type) { + this.eat(type) || this.unexpected(); +}; - expect("{"); +// Raise an unexpected token error. - if (match("}")) { - expression = parseJSXEmptyExpression(); - } else { - expression = parseExpression(); - } +pp.unexpected = function (pos) { + this.raise(pos != null ? pos : this.start, "Unexpected token"); +}; - state.inJSXChild = origInJSXChild; - state.inJSXTag = origInJSXTag; +pp.checkPatternErrors = function (refDestructuringErrors, andThrow) { + var pos = refDestructuringErrors && refDestructuringErrors.trailingComma; + if (!andThrow) return !!pos; + if (pos) this.raise(pos, "Trailing comma is not permitted in destructuring patterns"); +}; - expect("}"); +pp.checkExpressionErrors = function (refDestructuringErrors, andThrow) { + var pos = refDestructuringErrors && refDestructuringErrors.shorthandAssign; + if (!andThrow) return !!pos; + if (pos) this.raise(pos, "Shorthand property assignments are valid only in destructuring patterns"); +}; - return markerApply(marker, astNodeFactory.createJSXExpressionContainer(expression)); -} +},{"./state":10,"./tokentype":14,"./whitespace":16}],10:[function(_dereq_,module,exports){ +"use strict"; -function parseJSXSpreadAttribute() { - var expression, origInJSXChild, origInJSXTag, marker = markerCreate(); +exports.__esModule = true; - origInJSXChild = state.inJSXChild; - origInJSXTag = state.inJSXTag; - state.inJSXChild = false; - state.inJSXTag = false; - state.inJSXSpreadAttribute = true; +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - expect("{"); - expect("..."); +var _identifier = _dereq_("./identifier"); - state.inJSXSpreadAttribute = false; +var _tokentype = _dereq_("./tokentype"); - expression = parseAssignmentExpression(); +var _whitespace = _dereq_("./whitespace"); - state.inJSXChild = origInJSXChild; - state.inJSXTag = origInJSXTag; +var _options = _dereq_("./options"); - expect("}"); +// Registered plugins +var plugins = {}; - return markerApply(marker, astNodeFactory.createJSXSpreadAttribute(expression)); +exports.plugins = plugins; +function keywordRegexp(words) { + return new RegExp("^(" + words.replace(/ /g, "|") + ")$"); } -function parseJSXAttribute() { - var name, marker; - - if (match("{")) { - return parseJSXSpreadAttribute(); - } +var Parser = (function () { + function Parser(options, input, startPos) { + _classCallCheck(this, Parser); - marker = markerCreate(); + this.options = options = _options.getOptions(options); + this.sourceFile = options.sourceFile; + this.keywords = keywordRegexp(_identifier.keywords[options.ecmaVersion >= 6 ? 6 : 5]); + var reserved = options.allowReserved ? "" : _identifier.reservedWords[options.ecmaVersion] + (options.sourceType == "module" ? " await" : ""); + this.reservedWords = keywordRegexp(reserved); + var reservedStrict = (reserved ? reserved + " " : "") + _identifier.reservedWords.strict; + this.reservedWordsStrict = keywordRegexp(reservedStrict); + this.reservedWordsStrictBind = keywordRegexp(reservedStrict + " " + _identifier.reservedWords.strictBind); + this.input = String(input); - name = parseJSXAttributeName(); + // Used to signal to callers of `readWord1` whether the word + // contained any escape sequences. This is needed because words with + // escape sequences must not be interpreted as keywords. + this.containsEsc = false; - // HTML empty attribute - if (match("=")) { - lex(); - return markerApply(marker, astNodeFactory.createJSXAttribute(name, parseJSXAttributeValue())); - } + // Load plugins + this.loadPlugins(options.plugins); - return markerApply(marker, astNodeFactory.createJSXAttribute(name)); -} + // Set up token state -function parseJSXChild() { - var token, marker; - if (match("{")) { - token = parseJSXExpressionContainer(); - } else if (lookahead.type === Token.JSXText) { - marker = markerCreatePreserveWhitespace(); - token = markerApply(marker, astNodeFactory.createLiteralFromSource(lex(), source)); + // The current position of the tokenizer in the input. + if (startPos) { + this.pos = startPos; + this.lineStart = Math.max(0, this.input.lastIndexOf("\n", startPos)); + this.curLine = this.input.slice(0, this.lineStart).split(_whitespace.lineBreak).length; } else { - token = parseJSXElement(); - } - return token; -} + this.pos = this.lineStart = 0; + this.curLine = 1; + } + + // Properties of the current token: + // Its type + this.type = _tokentype.types.eof; + // For tokens that include more information than their type, the value + this.value = null; + // Its start and end offset + this.start = this.end = this.pos; + // And, if locations are used, the {line, column} object + // corresponding to those offsets + this.startLoc = this.endLoc = this.curPosition(); + + // Position information for the previous token + this.lastTokEndLoc = this.lastTokStartLoc = null; + this.lastTokStart = this.lastTokEnd = this.pos; + + // The context stack is used to superficially track syntactic + // context to predict whether a regular expression is allowed in a + // given position. + this.context = this.initialContext(); + this.exprAllowed = true; + + // Figure out if it's a module code. + this.strict = this.inModule = options.sourceType === "module"; + + // Used to signify the start of a potential arrow function + this.potentialArrowAt = -1; + + // Flags to track whether we are in a function, a generator. + this.inFunction = this.inGenerator = false; + // Labels in scope. + this.labels = []; + + // If enabled, skip leading hashbang line. + if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === '#!') this.skipLineComment(2); + } -function parseJSXClosingElement() { - var name, origInJSXChild, origInJSXTag, marker = markerCreate(); - origInJSXChild = state.inJSXChild; - origInJSXTag = state.inJSXTag; - state.inJSXChild = false; - state.inJSXTag = true; - expect("<"); - expect("/"); - name = parseJSXElementName(); - // Because advance() (called by lex() called by expect()) expects there - // to be a valid token after >, it needs to know whether to look for a - // standard JS token or an JSX text node - state.inJSXChild = origInJSXChild; - state.inJSXTag = origInJSXTag; - expect(">"); - return markerApply(marker, astNodeFactory.createJSXClosingElement(name)); -} - -function parseJSXOpeningElement() { - var name, attributes = [], selfClosing = false, origInJSXChild, - origInJSXTag, marker = markerCreate(); - - origInJSXChild = state.inJSXChild; - origInJSXTag = state.inJSXTag; - state.inJSXChild = false; - state.inJSXTag = true; - - expect("<"); - - name = parseJSXElementName(); - - while (index < length && - lookahead.value !== "/" && - lookahead.value !== ">") { - attributes.push(parseJSXAttribute()); - } - - state.inJSXTag = origInJSXTag; - - if (lookahead.value === "/") { - expect("/"); - // Because advance() (called by lex() called by expect()) expects - // there to be a valid token after >, it needs to know whether to - // look for a standard JS token or an JSX text node - state.inJSXChild = origInJSXChild; - expect(">"); - selfClosing = true; - } else { - state.inJSXChild = true; - expect(">"); - } - return markerApply(marker, astNodeFactory.createJSXOpeningElement(name, attributes, selfClosing)); -} + // DEPRECATED Kept for backwards compatibility until 3.0 in case a plugin uses them -function parseJSXElement() { - var openingElement, closingElement = null, children = [], origInJSXChild, origInJSXTag, marker = markerCreate(); + Parser.prototype.isKeyword = function isKeyword(word) { + return this.keywords.test(word); + }; - origInJSXChild = state.inJSXChild; - origInJSXTag = state.inJSXTag; - openingElement = parseJSXOpeningElement(); + Parser.prototype.isReservedWord = function isReservedWord(word) { + return this.reservedWords.test(word); + }; - if (!openingElement.selfClosing) { - while (index < length) { - state.inJSXChild = false; // Call lookahead2() with inJSXChild = false because one
two
; - * - * the default error message is a bit incomprehensible. Since it"s - * rarely (never?) useful to write a less-than sign after an JSX - * element, we disallow it here in the parser in order to provide a - * better error message. (In the rare case that the less-than operator - * was intended, the left tag can be wrapped in parentheses.) - */ - if (!origInJSXChild && match("<")) { - throwError(lookahead, Messages.AdjacentJSXElements); + Parser.prototype.loadPlugins = function loadPlugins(pluginConfigs) { + for (var _name in pluginConfigs) { + var plugin = plugins[_name]; + if (!plugin) throw new Error("Plugin '" + _name + "' not found"); + plugin(this, pluginConfigs[_name]); } + }; - return markerApply(marker, astNodeFactory.createJSXElement(openingElement, closingElement, children)); -} - -//------------------------------------------------------------------------------ -// Location markers -//------------------------------------------------------------------------------ - -/** - * Applies location information to the given node by using the given marker. - * The marker indicates the point at which the node is said to have to begun - * in the source code. - * @param {Object} marker The marker to use for the node. - * @param {ASTNode} node The AST node to apply location information to. - * @returns {ASTNode} The node that was passed in. - * @private - */ -function markerApply(marker, node) { + Parser.prototype.parse = function parse() { + var node = this.options.program || this.startNode(); + this.nextToken(); + return this.parseTopLevel(node); + }; - // add range information to the node if present - if (extra.range) { - node.range = [marker.offset, index]; - } + return Parser; +})(); - // add location information the node if present - if (extra.loc) { - node.loc = { - start: { - line: marker.line, - column: marker.col - }, - end: { - line: lineNumber, - column: index - lineStart - } - }; - // Attach extra.source information to the location, if present - if (extra.source) { - node.loc.source = extra.source; - } - } +exports.Parser = Parser; - // attach leading and trailing comments if requested - if (extra.attachComment) { - commentAttachment.processComment(node); - } +},{"./identifier":2,"./options":8,"./tokentype":14,"./whitespace":16}],11:[function(_dereq_,module,exports){ +"use strict"; - return node; -} +var _tokentype = _dereq_("./tokentype"); -/** - * Creates a location marker in the source code. Location markers are used for - * tracking where tokens and nodes appear in the source code. - * @returns {Object} A marker object or undefined if the parser doesn't have - * any location information. - * @private - */ -function markerCreate() { +var _state = _dereq_("./state"); - if (!extra.loc && !extra.range) { - return undefined; - } +var _whitespace = _dereq_("./whitespace"); - skipComment(); +var pp = _state.Parser.prototype; - return { - offset: index, - line: lineNumber, - col: index - lineStart - }; -} +// ### Statement parsing -/** - * Creates a location marker in the source code. Location markers are used for - * tracking where tokens and nodes appear in the source code. This method - * doesn't skip comments or extra whitespace which is important for JSX. - * @returns {Object} A marker object or undefined if the parser doesn't have - * any location information. - * @private - */ -function markerCreatePreserveWhitespace() { +// Parse a program. Initializes the parser, reads any number of +// statements, and wraps them in a Program node. Optionally takes a +// `program` argument. If present, the statements will be appended +// to its body instead of creating a new node. - if (!extra.loc && !extra.range) { - return undefined; +pp.parseTopLevel = function (node) { + var first = true; + if (!node.body) node.body = []; + while (this.type !== _tokentype.types.eof) { + var stmt = this.parseStatement(true, true); + node.body.push(stmt); + if (first) { + if (this.isUseStrict(stmt)) this.setStrict(true); + first = false; } + } + this.next(); + if (this.options.ecmaVersion >= 6) { + node.sourceType = this.options.sourceType; + } + return this.finishNode(node, "Program"); +}; - return { - offset: index, - line: lineNumber, - col: index - lineStart - }; -} - +var loopLabel = { kind: "loop" }, + switchLabel = { kind: "switch" }; -//------------------------------------------------------------------------------ -// Syntax Tree Delegate -//------------------------------------------------------------------------------ +// Parse a single statement. +// +// If expecting a statement and finding a slash operator, parse a +// regular expression literal. This is to handle cases like +// `if (foo) /blah/.exec(foo)`, where looking at the previous token +// does not help. + +pp.parseStatement = function (declaration, topLevel) { + var starttype = this.type, + node = this.startNode(); + + // Most types of statements are recognized by the keyword they + // start with. Many are trivial to parse, some require a bit of + // complexity. + + switch (starttype) { + case _tokentype.types._break:case _tokentype.types._continue: + return this.parseBreakContinueStatement(node, starttype.keyword); + case _tokentype.types._debugger: + return this.parseDebuggerStatement(node); + case _tokentype.types._do: + return this.parseDoStatement(node); + case _tokentype.types._for: + return this.parseForStatement(node); + case _tokentype.types._function: + if (!declaration && this.options.ecmaVersion >= 6) this.unexpected(); + return this.parseFunctionStatement(node); + case _tokentype.types._class: + if (!declaration) this.unexpected(); + return this.parseClass(node, true); + case _tokentype.types._if: + return this.parseIfStatement(node); + case _tokentype.types._return: + return this.parseReturnStatement(node); + case _tokentype.types._switch: + return this.parseSwitchStatement(node); + case _tokentype.types._throw: + return this.parseThrowStatement(node); + case _tokentype.types._try: + return this.parseTryStatement(node); + case _tokentype.types._let:case _tokentype.types._const: + if (!declaration) this.unexpected(); // NOTE: falls through to _var + case _tokentype.types._var: + return this.parseVarStatement(node, starttype); + case _tokentype.types._while: + return this.parseWhileStatement(node); + case _tokentype.types._with: + return this.parseWithStatement(node); + case _tokentype.types.braceL: + return this.parseBlock(); + case _tokentype.types.semi: + return this.parseEmptyStatement(node); + case _tokentype.types._export: + case _tokentype.types._import: + if (!this.options.allowImportExportEverywhere) { + if (!topLevel) this.raise(this.start, "'import' and 'export' may only appear at the top level"); + if (!this.inModule) this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'"); + } + return starttype === _tokentype.types._import ? this.parseImport(node) : this.parseExport(node); -// Return true if there is a line terminator before the next token. + // If the statement does not start with a statement keyword or a + // brace, it's an ExpressionStatement or LabeledStatement. We + // simply start parsing an expression, and afterwards, if the + // next token is a colon and the expression was a simple + // Identifier node, we switch to interpreting it as a label. + default: + var maybeName = this.value, + expr = this.parseExpression(); + if (starttype === _tokentype.types.name && expr.type === "Identifier" && this.eat(_tokentype.types.colon)) return this.parseLabeledStatement(node, maybeName, expr);else return this.parseExpressionStatement(node, expr); + } +}; -function peekLineTerminator() { - var pos, line, start, found; +pp.parseBreakContinueStatement = function (node, keyword) { + var isBreak = keyword == "break"; + this.next(); + if (this.eat(_tokentype.types.semi) || this.insertSemicolon()) node.label = null;else if (this.type !== _tokentype.types.name) this.unexpected();else { + node.label = this.parseIdent(); + this.semicolon(); + } - pos = index; - line = lineNumber; - start = lineStart; - skipComment(); - found = lineNumber !== line; - index = pos; - lineNumber = line; - lineStart = start; + // Verify that there is an actual destination to break or + // continue to. + for (var i = 0; i < this.labels.length; ++i) { + var lab = this.labels[i]; + if (node.label == null || lab.name === node.label.name) { + if (lab.kind != null && (isBreak || lab.kind === "loop")) break; + if (node.label && isBreak) break; + } + } + if (i === this.labels.length) this.raise(node.start, "Unsyntactic " + keyword); + return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement"); +}; + +pp.parseDebuggerStatement = function (node) { + this.next(); + this.semicolon(); + return this.finishNode(node, "DebuggerStatement"); +}; + +pp.parseDoStatement = function (node) { + this.next(); + this.labels.push(loopLabel); + node.body = this.parseStatement(false); + this.labels.pop(); + this.expect(_tokentype.types._while); + node.test = this.parseParenExpression(); + if (this.options.ecmaVersion >= 6) this.eat(_tokentype.types.semi);else this.semicolon(); + return this.finishNode(node, "DoWhileStatement"); +}; + +// Disambiguating between a `for` and a `for`/`in` or `for`/`of` +// loop is non-trivial. Basically, we have to parse the init `var` +// statement or expression, disallowing the `in` operator (see +// the second parameter to `parseExpression`), and then check +// whether the next token is `in` or `of`. When there is no init +// part (semicolon immediately after the opening parenthesis), it +// is a regular `for` loop. + +pp.parseForStatement = function (node) { + this.next(); + this.labels.push(loopLabel); + this.expect(_tokentype.types.parenL); + if (this.type === _tokentype.types.semi) return this.parseFor(node, null); + if (this.type === _tokentype.types._var || this.type === _tokentype.types._let || this.type === _tokentype.types._const) { + var _init = this.startNode(), + varKind = this.type; + this.next(); + this.parseVar(_init, true, varKind); + this.finishNode(_init, "VariableDeclaration"); + if ((this.type === _tokentype.types._in || this.options.ecmaVersion >= 6 && this.isContextual("of")) && _init.declarations.length === 1 && !(varKind !== _tokentype.types._var && _init.declarations[0].init)) return this.parseForIn(node, _init); + return this.parseFor(node, _init); + } + var refDestructuringErrors = { shorthandAssign: 0, trailingComma: 0 }; + var init = this.parseExpression(true, refDestructuringErrors); + if (this.type === _tokentype.types._in || this.options.ecmaVersion >= 6 && this.isContextual("of")) { + this.checkPatternErrors(refDestructuringErrors, true); + this.toAssignable(init); + this.checkLVal(init); + return this.parseForIn(node, init); + } else { + this.checkExpressionErrors(refDestructuringErrors, true); + } + return this.parseFor(node, init); +}; - return found; -} +pp.parseFunctionStatement = function (node) { + this.next(); + return this.parseFunction(node, true); +}; -// Throw an exception +pp.parseIfStatement = function (node) { + this.next(); + node.test = this.parseParenExpression(); + node.consequent = this.parseStatement(false); + node.alternate = this.eat(_tokentype.types._else) ? this.parseStatement(false) : null; + return this.finishNode(node, "IfStatement"); +}; -function throwError(token, messageFormat) { +pp.parseReturnStatement = function (node) { + if (!this.inFunction && !this.options.allowReturnOutsideFunction) this.raise(this.start, "'return' outside of function"); + this.next(); - var error, - args = Array.prototype.slice.call(arguments, 2), - msg = messageFormat.replace( - /%(\d)/g, - function (whole, index) { - assert(index < args.length, "Message reference must be in range"); - return args[index]; - } - ); + // In `return` (and `break`/`continue`), the keywords with + // optional arguments, we eagerly look for a semicolon or the + // possibility to insert one. - if (typeof token.lineNumber === "number") { - error = new Error("Line " + token.lineNumber + ": " + msg); - error.index = token.range[0]; - error.lineNumber = token.lineNumber; - error.column = token.range[0] - token.lineStart + 1; + if (this.eat(_tokentype.types.semi) || this.insertSemicolon()) node.argument = null;else { + node.argument = this.parseExpression();this.semicolon(); + } + return this.finishNode(node, "ReturnStatement"); +}; + +pp.parseSwitchStatement = function (node) { + this.next(); + node.discriminant = this.parseParenExpression(); + node.cases = []; + this.expect(_tokentype.types.braceL); + this.labels.push(switchLabel); + + // Statements under must be grouped (by label) in SwitchCase + // nodes. `cur` is used to keep the node that we are currently + // adding statements to. + + for (var cur, sawDefault = false; this.type != _tokentype.types.braceR;) { + if (this.type === _tokentype.types._case || this.type === _tokentype.types._default) { + var isCase = this.type === _tokentype.types._case; + if (cur) this.finishNode(cur, "SwitchCase"); + node.cases.push(cur = this.startNode()); + cur.consequent = []; + this.next(); + if (isCase) { + cur.test = this.parseExpression(); + } else { + if (sawDefault) this.raise(this.lastTokStart, "Multiple default clauses"); + sawDefault = true; + cur.test = null; + } + this.expect(_tokentype.types.colon); } else { - error = new Error("Line " + lineNumber + ": " + msg); - error.index = index; - error.lineNumber = lineNumber; - error.column = index - lineStart + 1; + if (!cur) this.unexpected(); + cur.consequent.push(this.parseStatement(true)); } - - error.description = msg; - throw error; -} - -function throwErrorTolerant() { - try { - throwError.apply(null, arguments); - } catch (e) { - if (extra.errors) { - extra.errors.push(e); - } else { - throw e; - } + } + if (cur) this.finishNode(cur, "SwitchCase"); + this.next(); // Closing brace + this.labels.pop(); + return this.finishNode(node, "SwitchStatement"); +}; + +pp.parseThrowStatement = function (node) { + this.next(); + if (_whitespace.lineBreak.test(this.input.slice(this.lastTokEnd, this.start))) this.raise(this.lastTokEnd, "Illegal newline after throw"); + node.argument = this.parseExpression(); + this.semicolon(); + return this.finishNode(node, "ThrowStatement"); +}; + +// Reused empty array added for node fields that are always empty. + +var empty = []; + +pp.parseTryStatement = function (node) { + this.next(); + node.block = this.parseBlock(); + node.handler = null; + if (this.type === _tokentype.types._catch) { + var clause = this.startNode(); + this.next(); + this.expect(_tokentype.types.parenL); + clause.param = this.parseBindingAtom(); + this.checkLVal(clause.param, true); + this.expect(_tokentype.types.parenR); + clause.body = this.parseBlock(); + node.handler = this.finishNode(clause, "CatchClause"); + } + node.finalizer = this.eat(_tokentype.types._finally) ? this.parseBlock() : null; + if (!node.handler && !node.finalizer) this.raise(node.start, "Missing catch or finally clause"); + return this.finishNode(node, "TryStatement"); +}; + +pp.parseVarStatement = function (node, kind) { + this.next(); + this.parseVar(node, false, kind); + this.semicolon(); + return this.finishNode(node, "VariableDeclaration"); +}; + +pp.parseWhileStatement = function (node) { + this.next(); + node.test = this.parseParenExpression(); + this.labels.push(loopLabel); + node.body = this.parseStatement(false); + this.labels.pop(); + return this.finishNode(node, "WhileStatement"); +}; + +pp.parseWithStatement = function (node) { + if (this.strict) this.raise(this.start, "'with' in strict mode"); + this.next(); + node.object = this.parseParenExpression(); + node.body = this.parseStatement(false); + return this.finishNode(node, "WithStatement"); +}; + +pp.parseEmptyStatement = function (node) { + this.next(); + return this.finishNode(node, "EmptyStatement"); +}; + +pp.parseLabeledStatement = function (node, maybeName, expr) { + for (var i = 0; i < this.labels.length; ++i) { + if (this.labels[i].name === maybeName) this.raise(expr.start, "Label '" + maybeName + "' is already declared"); + }var kind = this.type.isLoop ? "loop" : this.type === _tokentype.types._switch ? "switch" : null; + for (var i = this.labels.length - 1; i >= 0; i--) { + var label = this.labels[i]; + if (label.statementStart == node.start) { + label.statementStart = this.start; + label.kind = kind; + } else break; + } + this.labels.push({ name: maybeName, kind: kind, statementStart: this.start }); + node.body = this.parseStatement(true); + this.labels.pop(); + node.label = expr; + return this.finishNode(node, "LabeledStatement"); +}; + +pp.parseExpressionStatement = function (node, expr) { + node.expression = expr; + this.semicolon(); + return this.finishNode(node, "ExpressionStatement"); +}; + +// Parse a semicolon-enclosed block of statements, handling `"use +// strict"` declarations when `allowStrict` is true (used for +// function bodies). + +pp.parseBlock = function (allowStrict) { + var node = this.startNode(), + first = true, + oldStrict = undefined; + node.body = []; + this.expect(_tokentype.types.braceL); + while (!this.eat(_tokentype.types.braceR)) { + var stmt = this.parseStatement(true); + node.body.push(stmt); + if (first && allowStrict && this.isUseStrict(stmt)) { + oldStrict = this.strict; + this.setStrict(this.strict = true); + } + first = false; + } + if (oldStrict === false) this.setStrict(false); + return this.finishNode(node, "BlockStatement"); +}; + +// Parse a regular `for` loop. The disambiguation code in +// `parseStatement` will already have parsed the init statement or +// expression. + +pp.parseFor = function (node, init) { + node.init = init; + this.expect(_tokentype.types.semi); + node.test = this.type === _tokentype.types.semi ? null : this.parseExpression(); + this.expect(_tokentype.types.semi); + node.update = this.type === _tokentype.types.parenR ? null : this.parseExpression(); + this.expect(_tokentype.types.parenR); + node.body = this.parseStatement(false); + this.labels.pop(); + return this.finishNode(node, "ForStatement"); +}; + +// Parse a `for`/`in` and `for`/`of` loop, which are almost +// same from parser's perspective. + +pp.parseForIn = function (node, init) { + var type = this.type === _tokentype.types._in ? "ForInStatement" : "ForOfStatement"; + this.next(); + node.left = init; + node.right = this.parseExpression(); + this.expect(_tokentype.types.parenR); + node.body = this.parseStatement(false); + this.labels.pop(); + return this.finishNode(node, type); +}; + +// Parse a list of variable declarations. + +pp.parseVar = function (node, isFor, kind) { + node.declarations = []; + node.kind = kind.keyword; + for (;;) { + var decl = this.startNode(); + this.parseVarId(decl); + if (this.eat(_tokentype.types.eq)) { + decl.init = this.parseMaybeAssign(isFor); + } else if (kind === _tokentype.types._const && !(this.type === _tokentype.types._in || this.options.ecmaVersion >= 6 && this.isContextual("of"))) { + this.unexpected(); + } else if (decl.id.type != "Identifier" && !(isFor && (this.type === _tokentype.types._in || this.isContextual("of")))) { + this.raise(this.lastTokEnd, "Complex binding patterns require an initialization value"); + } else { + decl.init = null; } -} + node.declarations.push(this.finishNode(decl, "VariableDeclarator")); + if (!this.eat(_tokentype.types.comma)) break; + } + return node; +}; + +pp.parseVarId = function (decl) { + decl.id = this.parseBindingAtom(); + this.checkLVal(decl.id, true); +}; + +// Parse a function declaration or literal (depending on the +// `isStatement` parameter). + +pp.parseFunction = function (node, isStatement, allowExpressionBody) { + this.initFunction(node); + if (this.options.ecmaVersion >= 6) node.generator = this.eat(_tokentype.types.star); + if (isStatement || this.type === _tokentype.types.name) node.id = this.parseIdent(); + this.parseFunctionParams(node); + this.parseFunctionBody(node, allowExpressionBody); + return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression"); +}; + +pp.parseFunctionParams = function (node) { + this.expect(_tokentype.types.parenL); + node.params = this.parseBindingList(_tokentype.types.parenR, false, false, true); +}; + +// Parse a class declaration or literal (depending on the +// `isStatement` parameter). + +pp.parseClass = function (node, isStatement) { + this.next(); + this.parseClassId(node, isStatement); + this.parseClassSuper(node); + var classBody = this.startNode(); + var hadConstructor = false; + classBody.body = []; + this.expect(_tokentype.types.braceL); + while (!this.eat(_tokentype.types.braceR)) { + if (this.eat(_tokentype.types.semi)) continue; + var method = this.startNode(); + var isGenerator = this.eat(_tokentype.types.star); + var isMaybeStatic = this.type === _tokentype.types.name && this.value === "static"; + this.parsePropertyName(method); + method["static"] = isMaybeStatic && this.type !== _tokentype.types.parenL; + if (method["static"]) { + if (isGenerator) this.unexpected(); + isGenerator = this.eat(_tokentype.types.star); + this.parsePropertyName(method); + } + method.kind = "method"; + var isGetSet = false; + if (!method.computed) { + var key = method.key; + + if (!isGenerator && key.type === "Identifier" && this.type !== _tokentype.types.parenL && (key.name === "get" || key.name === "set")) { + isGetSet = true; + method.kind = key.name; + key = this.parsePropertyName(method); + } + if (!method["static"] && (key.type === "Identifier" && key.name === "constructor" || key.type === "Literal" && key.value === "constructor")) { + if (hadConstructor) this.raise(key.start, "Duplicate constructor in the same class"); + if (isGetSet) this.raise(key.start, "Constructor can't have get/set modifier"); + if (isGenerator) this.raise(key.start, "Constructor can't be a generator"); + method.kind = "constructor"; + hadConstructor = true; + } + } + this.parseClassMethod(classBody, method, isGenerator); + if (isGetSet) { + var paramCount = method.kind === "get" ? 0 : 1; + if (method.value.params.length !== paramCount) { + var start = method.value.start; + if (method.kind === "get") this.raise(start, "getter should have no params");else this.raise(start, "setter should have exactly one param"); + } + if (method.kind === "set" && method.value.params[0].type === "RestElement") this.raise(method.value.params[0].start, "Setter cannot use rest params"); + } + } + node.body = this.finishNode(classBody, "ClassBody"); + return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression"); +}; +pp.parseClassMethod = function (classBody, method, isGenerator) { + method.value = this.parseMethod(isGenerator); + classBody.body.push(this.finishNode(method, "MethodDefinition")); +}; -// Throw an exception because of the token. +pp.parseClassId = function (node, isStatement) { + node.id = this.type === _tokentype.types.name ? this.parseIdent() : isStatement ? this.unexpected() : null; +}; -function throwUnexpected(token) { +pp.parseClassSuper = function (node) { + node.superClass = this.eat(_tokentype.types._extends) ? this.parseExprSubscripts() : null; +}; - if (token.type === Token.EOF) { - throwError(token, Messages.UnexpectedEOS); - } +// Parses module export declaration. - if (token.type === Token.NumericLiteral) { - throwError(token, Messages.UnexpectedNumber); +pp.parseExport = function (node) { + this.next(); + // export * from '...' + if (this.eat(_tokentype.types.star)) { + this.expectContextual("from"); + node.source = this.type === _tokentype.types.string ? this.parseExprAtom() : this.unexpected(); + this.semicolon(); + return this.finishNode(node, "ExportAllDeclaration"); + } + if (this.eat(_tokentype.types._default)) { + // export default ... + var expr = this.parseMaybeAssign(); + var needsSemi = true; + if (expr.type == "FunctionExpression" || expr.type == "ClassExpression") { + needsSemi = false; + if (expr.id) { + expr.type = expr.type == "FunctionExpression" ? "FunctionDeclaration" : "ClassDeclaration"; + } } + node.declaration = expr; + if (needsSemi) this.semicolon(); + return this.finishNode(node, "ExportDefaultDeclaration"); + } + // export var|const|let|function|class ... + if (this.shouldParseExportStatement()) { + node.declaration = this.parseStatement(true); + node.specifiers = []; + node.source = null; + } else { + // export { x, y as z } [from '...'] + node.declaration = null; + node.specifiers = this.parseExportSpecifiers(); + if (this.eatContextual("from")) { + node.source = this.type === _tokentype.types.string ? this.parseExprAtom() : this.unexpected(); + } else { + // check for keywords used as local names + for (var i = 0; i < node.specifiers.length; i++) { + if (this.keywords.test(node.specifiers[i].local.name) || this.reservedWords.test(node.specifiers[i].local.name)) { + this.unexpected(node.specifiers[i].local.start); + } + } - if (token.type === Token.StringLiteral || token.type === Token.JSXText) { - throwError(token, Messages.UnexpectedString); + node.source = null; } + this.semicolon(); + } + return this.finishNode(node, "ExportNamedDeclaration"); +}; - if (token.type === Token.Identifier) { - throwError(token, Messages.UnexpectedIdentifier); - } +pp.shouldParseExportStatement = function () { + return this.type.keyword; +}; - if (token.type === Token.Keyword) { - if (syntax.isFutureReservedWord(token.value)) { - throwError(token, Messages.UnexpectedReserved); - } else if (strict && syntax.isStrictModeReservedWord(token.value, extra.ecmaFeatures)) { - throwErrorTolerant(token, Messages.StrictReservedWord); - return; - } - throwError(token, Messages.UnexpectedToken, token.value); - } +// Parses a comma-separated list of module exports. - if (token.type === Token.Template) { - throwError(token, Messages.UnexpectedTemplate, token.value.raw); - } +pp.parseExportSpecifiers = function () { + var nodes = [], + first = true; + // export { x, y as z } [from '...'] + this.expect(_tokentype.types.braceL); + while (!this.eat(_tokentype.types.braceR)) { + if (!first) { + this.expect(_tokentype.types.comma); + if (this.afterTrailingComma(_tokentype.types.braceR)) break; + } else first = false; - // BooleanLiteral, NullLiteral, or Punctuator. - throwError(token, Messages.UnexpectedToken, token.value); -} + var node = this.startNode(); + node.local = this.parseIdent(this.type === _tokentype.types._default); + node.exported = this.eatContextual("as") ? this.parseIdent(true) : node.local; + nodes.push(this.finishNode(node, "ExportSpecifier")); + } + return nodes; +}; -// Expect the next token to match the specified punctuator. -// If not, an exception will be thrown. +// Parses import declaration. -function expect(value) { - var token = lex(); - if (token.type !== Token.Punctuator || token.value !== value) { - throwUnexpected(token); +pp.parseImport = function (node) { + this.next(); + // import '...' + if (this.type === _tokentype.types.string) { + node.specifiers = empty; + node.source = this.parseExprAtom(); + } else { + node.specifiers = this.parseImportSpecifiers(); + this.expectContextual("from"); + node.source = this.type === _tokentype.types.string ? this.parseExprAtom() : this.unexpected(); + } + this.semicolon(); + return this.finishNode(node, "ImportDeclaration"); +}; + +// Parses a comma-separated list of module imports. + +pp.parseImportSpecifiers = function () { + var nodes = [], + first = true; + if (this.type === _tokentype.types.name) { + // import defaultObj, { x, y as z } from '...' + var node = this.startNode(); + node.local = this.parseIdent(); + this.checkLVal(node.local, true); + nodes.push(this.finishNode(node, "ImportDefaultSpecifier")); + if (!this.eat(_tokentype.types.comma)) return nodes; + } + if (this.type === _tokentype.types.star) { + var node = this.startNode(); + this.next(); + this.expectContextual("as"); + node.local = this.parseIdent(); + this.checkLVal(node.local, true); + nodes.push(this.finishNode(node, "ImportNamespaceSpecifier")); + return nodes; + } + this.expect(_tokentype.types.braceL); + while (!this.eat(_tokentype.types.braceR)) { + if (!first) { + this.expect(_tokentype.types.comma); + if (this.afterTrailingComma(_tokentype.types.braceR)) break; + } else first = false; + + var node = this.startNode(); + node.imported = this.parseIdent(true); + if (this.eatContextual("as")) { + node.local = this.parseIdent(); + } else { + node.local = node.imported; + if (this.isKeyword(node.local.name)) this.unexpected(node.local.start); + if (this.reservedWordsStrict.test(node.local.name)) this.raise(node.local.start, "The keyword '" + node.local.name + "' is reserved"); } -} + this.checkLVal(node.local, true); + nodes.push(this.finishNode(node, "ImportSpecifier")); + } + return nodes; +}; -// Expect the next token to match the specified keyword. -// If not, an exception will be thrown. +},{"./state":10,"./tokentype":14,"./whitespace":16}],12:[function(_dereq_,module,exports){ +// The algorithm used to determine whether a regexp can appear at a +// given point in the program is loosely based on sweet.js' approach. +// See https://github.com/mozilla/sweet.js/wiki/design -function expectKeyword(keyword) { - var token = lex(); - if (token.type !== Token.Keyword || token.value !== keyword) { - throwUnexpected(token); - } -} +"use strict"; -// Return true if the next token matches the specified punctuator. +exports.__esModule = true; -function match(value) { - return lookahead.type === Token.Punctuator && lookahead.value === value; -} +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } -// Return true if the next token matches the specified keyword +var _state = _dereq_("./state"); -function matchKeyword(keyword) { - return lookahead.type === Token.Keyword && lookahead.value === keyword; -} +var _tokentype = _dereq_("./tokentype"); -// Return true if the next token matches the specified contextual keyword -// (where an identifier is sometimes a keyword depending on the context) +var _whitespace = _dereq_("./whitespace"); -function matchContextualKeyword(keyword) { - return lookahead.type === Token.Identifier && lookahead.value === keyword; -} +var TokContext = function TokContext(token, isExpr, preserveSpace, override) { + _classCallCheck(this, TokContext); -// Return true if the next token is an assignment operator + this.token = token; + this.isExpr = !!isExpr; + this.preserveSpace = !!preserveSpace; + this.override = override; +}; -function matchAssign() { - var op; +exports.TokContext = TokContext; +var types = { + b_stat: new TokContext("{", false), + b_expr: new TokContext("{", true), + b_tmpl: new TokContext("${", true), + p_stat: new TokContext("(", false), + p_expr: new TokContext("(", true), + q_tmpl: new TokContext("`", true, true, function (p) { + return p.readTmplToken(); + }), + f_expr: new TokContext("function", true) +}; - if (lookahead.type !== Token.Punctuator) { - return false; - } - op = lookahead.value; - return op === "=" || - op === "*=" || - op === "/=" || - op === "%=" || - op === "+=" || - op === "-=" || - op === "<<=" || - op === ">>=" || - op === ">>>=" || - op === "&=" || - op === "^=" || - op === "|="; -} - -function consumeSemicolon() { - var line; - - // Catch the very common case first: immediately a semicolon (U+003B). - if (source.charCodeAt(index) === 0x3B || match(";")) { - lex(); - return; - } +exports.types = types; +var pp = _state.Parser.prototype; - line = lineNumber; - skipComment(); - if (lineNumber !== line) { - return; - } +pp.initialContext = function () { + return [types.b_stat]; +}; - if (lookahead.type !== Token.EOF && !match("}")) { - throwUnexpected(lookahead); - } -} +pp.braceIsBlock = function (prevType) { + if (prevType === _tokentype.types.colon) { + var _parent = this.curContext(); + if (_parent === types.b_stat || _parent === types.b_expr) return !_parent.isExpr; + } + if (prevType === _tokentype.types._return) return _whitespace.lineBreak.test(this.input.slice(this.lastTokEnd, this.start)); + if (prevType === _tokentype.types._else || prevType === _tokentype.types.semi || prevType === _tokentype.types.eof || prevType === _tokentype.types.parenR) return true; + if (prevType == _tokentype.types.braceL) return this.curContext() === types.b_stat; + return !this.exprAllowed; +}; -// Return true if provided expression is LeftHandSideExpression +pp.updateContext = function (prevType) { + var update = undefined, + type = this.type; + if (type.keyword && prevType == _tokentype.types.dot) this.exprAllowed = false;else if (update = type.updateContext) update.call(this, prevType);else this.exprAllowed = type.beforeExpr; +}; -function isLeftHandSide(expr) { - return expr.type === astNodeTypes.Identifier || expr.type === astNodeTypes.MemberExpression; -} +// Token-specific context update code -// 11.1.4 Array Initialiser +_tokentype.types.parenR.updateContext = _tokentype.types.braceR.updateContext = function () { + if (this.context.length == 1) { + this.exprAllowed = true; + return; + } + var out = this.context.pop(); + if (out === types.b_stat && this.curContext() === types.f_expr) { + this.context.pop(); + this.exprAllowed = false; + } else if (out === types.b_tmpl) { + this.exprAllowed = true; + } else { + this.exprAllowed = !out.isExpr; + } +}; -function parseArrayInitialiser() { - var elements = [], - marker = markerCreate(), - tmp; +_tokentype.types.braceL.updateContext = function (prevType) { + this.context.push(this.braceIsBlock(prevType) ? types.b_stat : types.b_expr); + this.exprAllowed = true; +}; - expect("["); +_tokentype.types.dollarBraceL.updateContext = function () { + this.context.push(types.b_tmpl); + this.exprAllowed = true; +}; - while (!match("]")) { - if (match(",")) { - lex(); // only get here when you have [a,,] or similar - elements.push(null); - } else { - tmp = parseSpreadOrAssignmentExpression(); - elements.push(tmp); - if (!(match("]"))) { - expect(","); // handles the common case of comma-separated values - } - } - } +_tokentype.types.parenL.updateContext = function (prevType) { + var statementParens = prevType === _tokentype.types._if || prevType === _tokentype.types._for || prevType === _tokentype.types._with || prevType === _tokentype.types._while; + this.context.push(statementParens ? types.p_stat : types.p_expr); + this.exprAllowed = true; +}; - expect("]"); +_tokentype.types.incDec.updateContext = function () { + // tokExprAllowed stays unchanged +}; - return markerApply(marker, astNodeFactory.createArrayExpression(elements)); -} +_tokentype.types._function.updateContext = function () { + if (this.curContext() !== types.b_stat) this.context.push(types.f_expr); + this.exprAllowed = false; +}; -// 11.1.5 Object Initialiser +_tokentype.types.backQuote.updateContext = function () { + if (this.curContext() === types.q_tmpl) this.context.pop();else this.context.push(types.q_tmpl); + this.exprAllowed = false; +}; -function parsePropertyFunction(paramInfo, options) { - var previousStrict = strict, - previousYieldAllowed = state.yieldAllowed, - generator = options ? options.generator : false, - body; +},{"./state":10,"./tokentype":14,"./whitespace":16}],13:[function(_dereq_,module,exports){ +"use strict"; - state.yieldAllowed = generator; +exports.__esModule = true; - /* - * Esprima uses parseConciseBody() here, which is incorrect. Object literal - * methods must have braces. - */ - body = parseFunctionSourceElements(); +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - if (strict && paramInfo.firstRestricted) { - throwErrorTolerant(paramInfo.firstRestricted, Messages.StrictParamName); - } +var _identifier = _dereq_("./identifier"); - if (strict && paramInfo.stricted) { - throwErrorTolerant(paramInfo.stricted, paramInfo.message); - } +var _tokentype = _dereq_("./tokentype"); + +var _state = _dereq_("./state"); + +var _locutil = _dereq_("./locutil"); + +var _whitespace = _dereq_("./whitespace"); - strict = previousStrict; - state.yieldAllowed = previousYieldAllowed; +// Object type used to represent tokens. Note that normally, tokens +// simply exist as properties on the parser object. This is only +// used for the onToken callback and the external tokenizer. - return markerApply(options.marker, astNodeFactory.createFunctionExpression( - null, - paramInfo.params, - body, - generator, - body.type !== astNodeTypes.BlockStatement - )); +var Token = function Token(p) { + _classCallCheck(this, Token); + + this.type = p.type; + this.value = p.value; + this.start = p.start; + this.end = p.end; + if (p.options.locations) this.loc = new _locutil.SourceLocation(p, p.startLoc, p.endLoc); + if (p.options.ranges) this.range = [p.start, p.end]; } -function parsePropertyMethodFunction(options) { - var previousStrict = strict, - marker = markerCreate(), - params, - method; +// ## Tokenizer + +; + +exports.Token = Token; +var pp = _state.Parser.prototype; + +// Are we running under Rhino? +var isRhino = typeof Packages == "object" && Object.prototype.toString.call(Packages) == "[object JavaPackage]"; - strict = true; +// Move to the next token - params = parseParams(); +pp.next = function () { + if (this.options.onToken) this.options.onToken(new Token(this)); - if (params.stricted) { - throwErrorTolerant(params.stricted, params.message); + this.lastTokEnd = this.end; + this.lastTokStart = this.start; + this.lastTokEndLoc = this.endLoc; + this.lastTokStartLoc = this.startLoc; + this.nextToken(); +}; + +pp.getToken = function () { + this.next(); + return new Token(this); +}; + +// If we're in an ES6 environment, make parsers iterable +if (typeof Symbol !== "undefined") pp[Symbol.iterator] = function () { + var self = this; + return { next: function next() { + var token = self.getToken(); + return { + done: token.type === _tokentype.types.eof, + value: token + }; + } }; +}; + +// Toggle strict mode. Re-reads the next number or string to please +// pedantic tests (`"use strict"; 010;` should fail). + +pp.setStrict = function (strict) { + this.strict = strict; + if (this.type !== _tokentype.types.num && this.type !== _tokentype.types.string) return; + this.pos = this.start; + if (this.options.locations) { + while (this.pos < this.lineStart) { + this.lineStart = this.input.lastIndexOf("\n", this.lineStart - 2) + 1; + --this.curLine; } + } + this.nextToken(); +}; - method = parsePropertyFunction(params, { - generator: options ? options.generator : false, - marker: marker - }); +pp.curContext = function () { + return this.context[this.context.length - 1]; +}; - strict = previousStrict; +// Read a single token, updating the parser object's token-related +// properties. - return method; -} +pp.nextToken = function () { + var curContext = this.curContext(); + if (!curContext || !curContext.preserveSpace) this.skipSpace(); -function parseObjectPropertyKey() { - var marker = markerCreate(), - token = lex(), - allowObjectLiteralComputed = extra.ecmaFeatures.objectLiteralComputedProperties, - expr, - result; + this.start = this.pos; + if (this.options.locations) this.startLoc = this.curPosition(); + if (this.pos >= this.input.length) return this.finishToken(_tokentype.types.eof); - // Note: This function is called only from parseObjectProperty(), where - // EOF and Punctuator tokens are already filtered out. + if (curContext.override) return curContext.override(this);else this.readToken(this.fullCharCodeAtPos()); +}; - switch (token.type) { - case Token.StringLiteral: - case Token.NumericLiteral: - if (strict && token.octal) { - throwErrorTolerant(token, Messages.StrictOctalLiteral); - } - return markerApply(marker, astNodeFactory.createLiteralFromSource(token, source)); +pp.readToken = function (code) { + // Identifier or keyword. '\uXXXX' sequences are allowed in + // identifiers, so '\' also dispatches to that. + if (_identifier.isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */) return this.readWord(); - case Token.Identifier: - case Token.BooleanLiteral: - case Token.NullLiteral: - case Token.Keyword: - return markerApply(marker, astNodeFactory.createIdentifier(token.value)); + return this.getTokenFromCode(code); +}; - case Token.Punctuator: - if ((!state.inObjectLiteral || allowObjectLiteralComputed) && - token.value === "[") { - // For computed properties we should skip the [ and ], and - // capture in marker only the assignment expression itself. - marker = markerCreate(); - expr = parseAssignmentExpression(); - result = markerApply(marker, expr); - expect("]"); - return result; - } +pp.fullCharCodeAtPos = function () { + var code = this.input.charCodeAt(this.pos); + if (code <= 0xd7ff || code >= 0xe000) return code; + var next = this.input.charCodeAt(this.pos + 1); + return (code << 10) + next - 0x35fdc00; +}; - // no default +pp.skipBlockComment = function () { + var startLoc = this.options.onComment && this.curPosition(); + var start = this.pos, + end = this.input.indexOf("*/", this.pos += 2); + if (end === -1) this.raise(this.pos - 2, "Unterminated comment"); + this.pos = end + 2; + if (this.options.locations) { + _whitespace.lineBreakG.lastIndex = start; + var match = undefined; + while ((match = _whitespace.lineBreakG.exec(this.input)) && match.index < this.pos) { + ++this.curLine; + this.lineStart = match.index + match[0].length; } + } + if (this.options.onComment) this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos, startLoc, this.curPosition()); +}; - throwUnexpected(token); -} +pp.skipLineComment = function (startSkip) { + var start = this.pos; + var startLoc = this.options.onComment && this.curPosition(); + var ch = this.input.charCodeAt(this.pos += startSkip); + while (this.pos < this.input.length && ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8233) { + ++this.pos; + ch = this.input.charCodeAt(this.pos); + } + if (this.options.onComment) this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos, startLoc, this.curPosition()); +}; -function lookaheadPropertyName() { - switch (lookahead.type) { - case Token.Identifier: - case Token.StringLiteral: - case Token.BooleanLiteral: - case Token.NullLiteral: - case Token.NumericLiteral: - case Token.Keyword: - return true; - case Token.Punctuator: - return lookahead.value === "["; - // no default +// Called at the start of the parse and after every token. Skips +// whitespace and comments, and. + +pp.skipSpace = function () { + loop: while (this.pos < this.input.length) { + var ch = this.input.charCodeAt(this.pos); + switch (ch) { + case 32:case 160: + // ' ' + ++this.pos; + break; + case 13: + if (this.input.charCodeAt(this.pos + 1) === 10) { + ++this.pos; + } + case 10:case 8232:case 8233: + ++this.pos; + if (this.options.locations) { + ++this.curLine; + this.lineStart = this.pos; + } + break; + case 47: + // '/' + switch (this.input.charCodeAt(this.pos + 1)) { + case 42: + // '*' + this.skipBlockComment(); + break; + case 47: + this.skipLineComment(2); + break; + default: + break loop; + } + break; + default: + if (ch > 8 && ch < 14 || ch >= 5760 && _whitespace.nonASCIIwhitespace.test(String.fromCharCode(ch))) { + ++this.pos; + } else { + break loop; + } } - return false; -} + } +}; -// This function is to try to parse a MethodDefinition as defined in 14.3. But in the case of object literals, -// it might be called at a position where there is in fact a short hand identifier pattern or a data property. -// This can only be determined after we consumed up to the left parentheses. -// In order to avoid back tracking, it returns `null` if the position is not a MethodDefinition and the caller -// is responsible to visit other options. -function tryParseMethodDefinition(token, key, computed, marker) { - var value, options, methodMarker; - - if (token.type === Token.Identifier) { - // check for `get` and `set`; - - if (token.value === "get" && lookaheadPropertyName()) { - - computed = match("["); - key = parseObjectPropertyKey(); - methodMarker = markerCreate(); - expect("("); - expect(")"); - - value = parsePropertyFunction({ - params: [], - stricted: null, - firstRestricted: null, - message: null - }, { - marker: methodMarker - }); +// Called at the end of every token. Sets `end`, `val`, and +// maintains `context` and `exprAllowed`, and skips the space after +// the token, so that the next one's `start` will point at the +// right position. - return markerApply(marker, astNodeFactory.createProperty("get", key, value, false, false, computed)); +pp.finishToken = function (type, val) { + this.end = this.pos; + if (this.options.locations) this.endLoc = this.curPosition(); + var prevType = this.type; + this.type = type; + this.value = val; - } else if (token.value === "set" && lookaheadPropertyName()) { - computed = match("["); - key = parseObjectPropertyKey(); - methodMarker = markerCreate(); - expect("("); + this.updateContext(prevType); +}; - options = { - params: [], - defaultCount: 0, - stricted: null, - firstRestricted: null, - paramSet: new StringMap() - }; - if (match(")")) { - throwErrorTolerant(lookahead, Messages.UnexpectedToken, lookahead.value); - } else { - parseParam(options); - } - expect(")"); +// ### Token reading - value = parsePropertyFunction(options, { marker: methodMarker }); - return markerApply(marker, astNodeFactory.createProperty("set", key, value, false, false, computed)); - } - } +// This is the function that is called to fetch the next token. It +// is somewhat obscure, because it works in character codes rather +// than characters, and because operator parsing has been inlined +// into it. +// +// All in the name of speed. +// +pp.readToken_dot = function () { + var next = this.input.charCodeAt(this.pos + 1); + if (next >= 48 && next <= 57) return this.readNumber(true); + var next2 = this.input.charCodeAt(this.pos + 2); + if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) { + // 46 = dot '.' + this.pos += 3; + return this.finishToken(_tokentype.types.ellipsis); + } else { + ++this.pos; + return this.finishToken(_tokentype.types.dot); + } +}; - if (match("(")) { - value = parsePropertyMethodFunction(); - return markerApply(marker, astNodeFactory.createProperty("init", key, value, true, false, computed)); - } +pp.readToken_slash = function () { + // '/' + var next = this.input.charCodeAt(this.pos + 1); + if (this.exprAllowed) { + ++this.pos;return this.readRegexp(); + } + if (next === 61) return this.finishOp(_tokentype.types.assign, 2); + return this.finishOp(_tokentype.types.slash, 1); +}; - // Not a MethodDefinition. - return null; -} +pp.readToken_mult_modulo = function (code) { + // '%*' + var next = this.input.charCodeAt(this.pos + 1); + if (next === 61) return this.finishOp(_tokentype.types.assign, 2); + return this.finishOp(code === 42 ? _tokentype.types.star : _tokentype.types.modulo, 1); +}; -/** - * Parses Generator Properties - * @param {ASTNode} key The property key (usually an identifier). - * @param {Object} marker The marker to use for the node. - * @returns {ASTNode} The generator property node. - */ -function parseGeneratorProperty(key, marker) { +pp.readToken_pipe_amp = function (code) { + // '|&' + var next = this.input.charCodeAt(this.pos + 1); + if (next === code) return this.finishOp(code === 124 ? _tokentype.types.logicalOR : _tokentype.types.logicalAND, 2); + if (next === 61) return this.finishOp(_tokentype.types.assign, 2); + return this.finishOp(code === 124 ? _tokentype.types.bitwiseOR : _tokentype.types.bitwiseAND, 1); +}; - var computed = (lookahead.type === Token.Punctuator && lookahead.value === "["); +pp.readToken_caret = function () { + // '^' + var next = this.input.charCodeAt(this.pos + 1); + if (next === 61) return this.finishOp(_tokentype.types.assign, 2); + return this.finishOp(_tokentype.types.bitwiseXOR, 1); +}; - if (!match("(")) { - throwUnexpected(lex()); +pp.readToken_plus_min = function (code) { + // '+-' + var next = this.input.charCodeAt(this.pos + 1); + if (next === code) { + if (next == 45 && this.input.charCodeAt(this.pos + 2) == 62 && _whitespace.lineBreak.test(this.input.slice(this.lastTokEnd, this.pos))) { + // A `-->` line comment + this.skipLineComment(3); + this.skipSpace(); + return this.nextToken(); } + return this.finishOp(_tokentype.types.incDec, 2); + } + if (next === 61) return this.finishOp(_tokentype.types.assign, 2); + return this.finishOp(_tokentype.types.plusMin, 1); +}; + +pp.readToken_lt_gt = function (code) { + // '<>' + var next = this.input.charCodeAt(this.pos + 1); + var size = 1; + if (next === code) { + size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2; + if (this.input.charCodeAt(this.pos + size) === 61) return this.finishOp(_tokentype.types.assign, size + 1); + return this.finishOp(_tokentype.types.bitShift, size); + } + if (next == 33 && code == 60 && this.input.charCodeAt(this.pos + 2) == 45 && this.input.charCodeAt(this.pos + 3) == 45) { + if (this.inModule) this.unexpected(); + // ` none + * import * as myModule from "my-module.js" --> all + * import {myMember} from "my-module.js" --> single + * import {foo, bar} from "my-module.js" --> multiple + * + * @param {ASTNode} node - the ImportDeclaration node. + * @returns {string} used member parameter style, ["all", "multiple", "single"] + */ + function usedMemberSyntax(node) { + if (node.specifiers.length === 0) { + return "none"; + } else if (node.specifiers[0].type === "ImportNamespaceSpecifier") { + return "all"; + } else if (node.specifiers.length === 1) { + return "single"; + } else { + return "multiple"; + } + } + + /** + * Gets the group by member parameter index for given declaration. + * @param {ASTNode} node - the ImportDeclaration node. + * @returns {number} the declaration group by member index. + */ + function getMemberParameterGroupIndex(node) { + return memberSyntaxSortOrder.indexOf(usedMemberSyntax(node)); + } + + /** + * Gets the local name of the first imported module. + * @param {ASTNode} node - the ImportDeclaration node. + * @returns {?string} the local name of the first imported module. + */ + function getFirstLocalMemberName(node) { + if (node.specifiers[0]) { + return node.specifiers[0].local.name; + } else { + return null; + } + } + + return { + "ImportDeclaration": function(node) { + if (previousDeclaration) { + var currentLocalMemberName = getFirstLocalMemberName(node), + currentMemberSyntaxGroupIndex = getMemberParameterGroupIndex(node), + previousLocalMemberName = getFirstLocalMemberName(previousDeclaration), + previousMemberSyntaxGroupIndex = getMemberParameterGroupIndex(previousDeclaration); + + if (ignoreCase) { + previousLocalMemberName = previousLocalMemberName.toLowerCase(); + currentLocalMemberName = currentLocalMemberName.toLowerCase(); + } + + // When the current declaration uses a different member syntax, + // then check if the ordering is correct. + // Otherwise, make a default string compare (like rule sort-vars to be consistent) of the first used local member name. + if (currentMemberSyntaxGroupIndex !== previousMemberSyntaxGroupIndex) { + if (currentMemberSyntaxGroupIndex < previousMemberSyntaxGroupIndex) { + context.report({ + node: node, + message: "Expected '{{syntaxA}}' syntax before '{{syntaxB}}' syntax.", + data: { + syntaxA: memberSyntaxSortOrder[currentMemberSyntaxGroupIndex], + syntaxB: memberSyntaxSortOrder[previousMemberSyntaxGroupIndex] + } + }); + } + } else { + if (currentLocalMemberName < previousLocalMemberName) { + context.report({ + node: node, + message: "Imports should be sorted alphabetically." + }); + } + } + } + + // Multiple members of an import declaration should also be sorted alphabetically. + if (!ignoreMemberSort && node.specifiers.length > 1) { + node.specifiers.reduce(function(previousSpecifier, currentSpecifier) { + var currentSpecifierName = currentSpecifier.local.name, + previousSpecifierName = previousSpecifier.local.name; + + if (ignoreCase) { + currentSpecifierName = currentSpecifierName.toLowerCase(); + previousSpecifierName = previousSpecifierName.toLowerCase(); + } + + if (currentSpecifierName < previousSpecifierName) { + context.report({ + node: currentSpecifier, + message: "Member '{{memberName}}' of the import declaration should be sorted alphabetically.", + data: { + memberName: currentSpecifier.local.name + } + }); + } + + return currentSpecifier; + }, node.specifiers[0]); + } + + previousDeclaration = node; + } + }; +}; + module.exports.schema = [ { - "enum": ["always", "never"] + "type": "object", + "properties": { + "ignoreCase": { + "type": "boolean" + }, + "memberSyntaxSortOrder": { + "type": "array", + "items": { + "enum": ["none", "all", "multiple", "single"] + }, + "uniqueItems": true, + "minItems": 4, + "maxItems": 4 + }, + "ignoreMemberSort": { + "type": "boolean" + } + }, + "additionalProperties": false } ]; -},{}],323:[function(require,module,exports){ +},{}],351:[function(require,module,exports){ /** * @fileoverview Rule to require sorting of variables within a single Variable Declaration block * @author Ilya Volodin @@ -38546,7 +44366,7 @@ module.exports.schema = [ } ]; -},{}],324:[function(require,module,exports){ +},{}],352:[function(require,module,exports){ /** * @fileoverview Rule to enforce the number of spaces after certain keywords * @author Nick Fisher @@ -38582,7 +44402,8 @@ module.exports = function(context) { if (hasSpace !== requiresSpace) { context.report({ node: node, - message: "Keyword \"{{value}}\" must {{not}}be followed by whitespace.", + loc: left.loc.end, + message: "Keyword '{{value}}' must {{not}}be followed by whitespace.", data: { value: value, not: requiresSpace ? "" : "not " @@ -38595,21 +44416,6 @@ module.exports = function(context) { } } }); - } else if (left.loc.end.line !== right.loc.start.line) { - context.report({ - node: node, - message: "Keyword \"{{value}}\" must not be followed by a newline.", - data: { - value: value - }, - fix: function(fixer) { - var text = ""; - if (requiresSpace) { - text = " "; - } - return fixer.replaceTextRange([left.range[1], right.range[0]], text); - } - }); } } @@ -38660,7 +44466,7 @@ module.exports.schema = [ } ]; -},{}],325:[function(require,module,exports){ +},{}],353:[function(require,module,exports){ /** * @fileoverview A rule to ensure whitespace before blocks. * @author Mathias Schreck @@ -38679,24 +44485,28 @@ module.exports = function(context) { var config = context.options[0], sourceCode = context.getSourceCode(), checkFunctions = true, - checkKeywords = true; + checkKeywords = true, + checkClasses = true; if (typeof config === "object") { checkFunctions = config.functions !== "never"; checkKeywords = config.keywords !== "never"; + checkClasses = config.classes !== "never"; } else if (config === "never") { checkFunctions = false; checkKeywords = false; + checkClasses = false; } /** - * Checks whether or not a given token is an arrow operator (=>). + * Checks whether or not a given token is an arrow operator (=>) or a keyword + * in order to avoid to conflict with `arrow-spacing` and `keyword-spacing`. * * @param {Token} token - A token to check. * @returns {boolean} `true` if the token is an arrow operator. */ - function isArrow(token) { - return token.type === "Punctuator" && token.value === "=>"; + function isConflicted(token) { + return (token.type === "Punctuator" && token.value === "=>") || token.type === "Keyword"; } /** @@ -38710,11 +44520,13 @@ module.exports = function(context) { parent, requireSpace; - if (precedingToken && !isArrow(precedingToken) && astUtils.isTokenOnSameLine(precedingToken, node)) { + if (precedingToken && !isConflicted(precedingToken) && astUtils.isTokenOnSameLine(precedingToken, node)) { hasSpace = sourceCode.isSpaceBetweenTokens(precedingToken, node); parent = context.getAncestors().pop(); if (parent.type === "FunctionExpression" || parent.type === "FunctionDeclaration") { requireSpace = checkFunctions; + } else if (node.type === "ClassBody") { + requireSpace = checkClasses; } else { requireSpace = checkKeywords; } @@ -38785,6 +44597,9 @@ module.exports.schema = [ }, "functions": { "enum": ["always", "never"] + }, + "classes": { + "enum": ["always", "never"] } }, "additionalProperties": false @@ -38793,7 +44608,7 @@ module.exports.schema = [ } ]; -},{"../ast-utils":151}],326:[function(require,module,exports){ +},{"../ast-utils":152}],354:[function(require,module,exports){ /** * @fileoverview Rule to validate spacing before function paren. * @author Mathias Schreck @@ -38833,7 +44648,7 @@ module.exports = function(context) { return true; } - parent = context.getAncestors().pop(); + parent = node.parent; return parent.type === "MethodDefinition" || (parent.type === "Property" && ( @@ -38851,7 +44666,6 @@ module.exports = function(context) { */ function validateSpacingBeforeParentheses(node) { var isNamed = isNamedFunction(node), - tokens, leftToken, rightToken, location; @@ -38860,31 +44674,11 @@ module.exports = function(context) { return; } - tokens = context.getTokens(node); - - if (node.generator) { - if (node.id) { - leftToken = tokens[2]; - rightToken = tokens[3]; - } else { - // Object methods are named but don't have an id - leftToken = context.getTokenBefore(node); - rightToken = tokens[0]; - } - } else if (isNamed) { - if (node.id) { - leftToken = tokens[1]; - rightToken = tokens[2]; - } else { - // Object methods are named but don't have an id - leftToken = context.getTokenBefore(node); - rightToken = tokens[0]; - } - } else { - leftToken = tokens[0]; - rightToken = tokens[1]; + rightToken = sourceCode.getFirstToken(node); + while (rightToken.value !== "(") { + rightToken = sourceCode.getTokenAfter(rightToken); } - + leftToken = context.getTokenBefore(rightToken); location = leftToken.loc.end; if (sourceCode.isSpaceBetweenTokens(leftToken, rightToken)) { @@ -38940,7 +44734,7 @@ module.exports.schema = [ } ]; -},{}],327:[function(require,module,exports){ +},{}],355:[function(require,module,exports){ /** * @fileoverview Require or disallow spaces before keywords * @author Marko Raatikka @@ -38955,8 +44749,8 @@ var astUtils = require("../ast-utils"); // Rule Definition //------------------------------------------------------------------------------ -var ERROR_MSG_SPACE_EXPECTED = "Missing space before keyword \"{{keyword}}\"."; -var ERROR_MSG_NO_SPACE_EXPECTED = "Unexpected space before keyword \"{{keyword}}\"."; +var ERROR_MSG_SPACE_EXPECTED = "Missing space before keyword '{{keyword}}'."; +var ERROR_MSG_NO_SPACE_EXPECTED = "Unexpected space before keyword '{{keyword}}'."; module.exports = function(context) { @@ -39077,7 +44871,10 @@ module.exports = function(context) { check(node); // else if (node.alternate) { - check(context.getTokenBefore(node.alternate), { requireSpace: SPACE_REQUIRED }); + var tokens = context.getTokensBefore(node.alternate, 2); + if (tokens[0].value === "}") { + check(tokens[1], { requireSpace: SPACE_REQUIRED }); + } } }, "ForStatement": check, @@ -39128,7 +44925,7 @@ module.exports = function(context) { return; } - checkTokens(node, left, right, { allowedPrecedingChars: [ "(", "{" ] }); + checkTokens(node, left, right, { allowedPrecedingChars: [ "(", "{", "[" ] }); }, "YieldExpression": function(node) { check(node, { allowedPrecedingChars: [ "(", "{" ] }); @@ -39153,7 +44950,7 @@ module.exports.schema = [ } ]; -},{"../ast-utils":151}],328:[function(require,module,exports){ +},{"../ast-utils":152}],356:[function(require,module,exports){ /** * @fileoverview Disallows or enforces spaces inside of parentheses. * @author Jonathan Rajavuori @@ -39162,6 +44959,8 @@ module.exports.schema = [ */ "use strict"; +var astUtils = require("../ast-utils"); + //------------------------------------------------------------------------------ // Rule Definition //------------------------------------------------------------------------------ @@ -39170,258 +44969,205 @@ module.exports = function(context) { var MISSING_SPACE_MESSAGE = "There must be a space inside this paren.", REJECTED_SPACE_MESSAGE = "There should be no spaces inside this paren.", - exceptionsArray = (context.options.length === 2) ? context.options[1].exceptions : [], + ALWAYS = context.options[0] === "always", + + exceptionsArrayOptions = (context.options.length === 2) ? context.options[1].exceptions : [], options = {}, - rejectedSpaceRegExp, - missingSpaceRegExp, - spaceChecks; + exceptions; - if (exceptionsArray && exceptionsArray.length) { - options.braceException = exceptionsArray.indexOf("{}") !== -1 || false; - options.bracketException = exceptionsArray.indexOf("[]") !== -1 || false; - options.parenException = exceptionsArray.indexOf("()") !== -1 || false; - options.empty = exceptionsArray.indexOf("empty") !== -1 || false; + if (exceptionsArrayOptions.length) { + options.braceException = exceptionsArrayOptions.indexOf("{}") !== -1; + options.bracketException = exceptionsArrayOptions.indexOf("[]") !== -1; + options.parenException = exceptionsArrayOptions.indexOf("()") !== -1; + options.empty = exceptionsArrayOptions.indexOf("empty") !== -1; } /** - * Used with the `never` option to produce, given the exception options, - * two regular expressions to check for missing and rejected spaces. + * Produces an object with the opener and closer exception values * @param {Object} opts The exception options - * @returns {Object} `missingSpace` and `rejectedSpace` regular expressions + * @returns {Object} `openers` and `closers` exception values * @private */ - function getNeverChecks(opts) { - var missingSpaceOpeners = [], - missingSpaceClosers = [], - rejectedSpaceOpeners = ["\\s"], - rejectedSpaceClosers = ["\\s"], - missingSpaceCheck, - rejectedSpaceCheck; - - // Populate openers and closers - if (opts.braceException) { - missingSpaceOpeners.push("\\{"); - missingSpaceClosers.push("\\}"); - rejectedSpaceOpeners.push("\\{"); - rejectedSpaceClosers.push("\\}"); - } - if (opts.bracketException) { - missingSpaceOpeners.push("\\["); - missingSpaceClosers.push("\\]"); - rejectedSpaceOpeners.push("\\["); - rejectedSpaceClosers.push("\\]"); - } - if (opts.parenException) { - missingSpaceOpeners.push("\\("); - missingSpaceClosers.push("\\)"); - rejectedSpaceOpeners.push("\\("); - rejectedSpaceClosers.push("\\)"); - } - if (opts.empty) { - missingSpaceOpeners.push("\\)"); - missingSpaceClosers.push("\\("); - rejectedSpaceOpeners.push("\\)"); - rejectedSpaceClosers.push("\\("); + function getExceptions() { + var openers = [], + closers = []; + if (options.braceException) { + openers.push("{"); + closers.push("}"); } - if (missingSpaceOpeners.length) { - missingSpaceCheck = "\\((" + missingSpaceOpeners.join("|") + ")"; - if (missingSpaceClosers.length) { - missingSpaceCheck += "|"; - } - } - if (missingSpaceClosers.length) { - missingSpaceCheck += "(" + missingSpaceClosers.join("|") + ")\\)"; + if (options.bracketException) { + openers.push("["); + closers.push("]"); } - // compose the rejected regexp - rejectedSpaceCheck = "\\( +[^" + rejectedSpaceOpeners.join("") + "]"; - rejectedSpaceCheck += "|[^" + rejectedSpaceClosers.join("") + "] +\\)"; - - return { - // e.g. \((\{)|(\})\) --- where {} is an exception - missingSpace: missingSpaceCheck || ".^", - // e.g. \( +[^ \n\r\{]|[^ \n\r\}] +\) --- where {} is an exception - rejectedSpace: rejectedSpaceCheck - }; - } - - /** - * Used with the `always` option to produce, given the exception options, - * two regular expressions to check for missing and rejected spaces. - * @param {Object} opts The exception options - * @returns {Object} `missingSpace` and `rejectedSpace` regular expressions - * @private - */ - function getAlwaysChecks(opts) { - var missingSpaceOpeners = ["\\s", "\\)"], - missingSpaceClosers = ["\\s", "\\("], - rejectedSpaceOpeners = [], - rejectedSpaceClosers = [], - missingSpaceCheck, - rejectedSpaceCheck; - - // Populate openers and closers - if (opts.braceException) { - missingSpaceOpeners.push("\\{"); - missingSpaceClosers.push("\\}"); - rejectedSpaceOpeners.push(" \\{"); - rejectedSpaceClosers.push("\\} "); - } - if (opts.bracketException) { - missingSpaceOpeners.push("\\["); - missingSpaceClosers.push("\\]"); - rejectedSpaceOpeners.push(" \\["); - rejectedSpaceClosers.push("\\] "); + if (options.parenException) { + openers.push("("); + closers.push(")"); } - if (opts.parenException) { - missingSpaceOpeners.push("\\("); - missingSpaceClosers.push("\\)"); - rejectedSpaceOpeners.push(" \\("); - rejectedSpaceClosers.push("\\) "); - } - if (opts.empty) { - rejectedSpaceOpeners.push(" \\)"); - rejectedSpaceClosers.push("\\( "); - } - - // compose the allowed regexp - missingSpaceCheck = "\\([^" + missingSpaceOpeners.join("") + "]"; - missingSpaceCheck += "|[^" + missingSpaceClosers.join("") + "]\\)"; - // compose the rejected regexp - if (rejectedSpaceOpeners.length) { - rejectedSpaceCheck = "\\((" + rejectedSpaceOpeners.join("|") + ")"; - if (rejectedSpaceClosers.length) { - rejectedSpaceCheck += "|"; - } - } - if (rejectedSpaceClosers.length) { - rejectedSpaceCheck += "(" + rejectedSpaceClosers.join("|") + ")\\)"; + if (options.empty) { + openers.push(")"); + closers.push("("); } return { - // e.g. \([^ \)\r\n\{]|[^ \(\r\n\}]\) --- where {} is an exception - missingSpace: missingSpaceCheck, - // e.g. \(( \{})|(\} )\) --- where {} is an excpetion - rejectedSpace: rejectedSpaceCheck || ".^" + openers: openers, + closers: closers }; } - spaceChecks = (context.options[0] === "always") ? getAlwaysChecks(options) : getNeverChecks(options); - missingSpaceRegExp = new RegExp(spaceChecks.missingSpace, "mg"); - rejectedSpaceRegExp = new RegExp(spaceChecks.rejectedSpace, "mg"); - - //-------------------------------------------------------------------------- // Helpers //-------------------------------------------------------------------------- - - var skipRanges = []; + var sourceCode = context.getSourceCode(); /** - * Adds the range of a node to the set to be skipped when checking parens - * @param {ASTNode} node The node to skip - * @returns {void} - * @private + * Determines if a token is one of the exceptions for the opener paren + * @param {Object} token The token to check + * @returns {boolean} True if the token is one of the exceptions for the opener paren */ - function addSkipRange(node) { - skipRanges.push(node.range); + function isOpenerException(token) { + return token.type === "Punctuator" && exceptions.openers.indexOf(token.value) >= 0; } /** - * Sorts the skipRanges array. Must be called before shouldSkip - * @returns {void} - * @private + * Determines if a token is one of the exceptions for the closer paren + * @param {Object} token The token to check + * @returns {boolean} True if the token is one of the exceptions for the closer paren */ - function sortSkipRanges() { - skipRanges.sort(function(a, b) { - return a[0] - b[0]; - }); + function isCloserException(token) { + return token.type === "Punctuator" && exceptions.closers.indexOf(token.value) >= 0; } /** - * Checks if a certain position in the source should be skipped - * @param {Number} pos The 0-based index in the source - * @returns {boolean} whether the position should be skipped - * @private + * Determines if an opener paren should have a missing space after it + * @param {Object} left The paren token + * @param {Object} right The token after it + * @returns {boolean} True if the paren should have a space */ - function shouldSkip(pos) { - var i, len, range; - for (i = 0, len = skipRanges.length; i < len; i += 1) { - range = skipRanges[i]; - if (pos < range[0]) { - break; - } else if (pos < range[1]) { - return true; + function shouldOpenerHaveSpace(left, right) { + if (sourceCode.isSpaceBetweenTokens(left, right)) { + return false; + } + + if (ALWAYS) { + if (right.type === "Punctuator" && right.value === ")") { + return false; } + return !isOpenerException(right); + } else { + return isOpenerException(right); } - return false; } + /** + * Determines if an closer paren should have a missing space after it + * @param {Object} left The token before the paren + * @param {Object} right The paren token + * @returns {boolean} True if the paren should have a space + */ + function shouldCloserHaveSpace(left, right) { + if (left.type === "Punctuator" && left.value === "(") { + return false; + } - //-------------------------------------------------------------------------- - // Public - //-------------------------------------------------------------------------- - - return { - - "Program:exit": function checkParenSpaces(node) { + if (sourceCode.isSpaceBetweenTokens(left, right)) { + return false; + } - var nextMatch, - nextLine, - column, - line = 1, - source = context.getSource(), - pos = 0; + if (ALWAYS) { + return !isCloserException(left); + } else { + return isCloserException(left); + } + } - /** - * Check the match - * @param {object} match Object to match - * @param {string} message Message to report - * @returns {void} - * @private - */ - function checkMatch(match, message) { - if (source.charAt(match.index) !== "(") { - // Matched a closing paren pattern - match.index += 1; - } + /** + * Determines if an opener paren should not have an existing space after it + * @param {Object} left The paren token + * @param {Object} right The token after it + * @returns {boolean} True if the paren should reject the space + */ + function shouldOpenerRejectSpace(left, right) { + if (right.type === "Line") { + return false; + } - if (!shouldSkip(match.index)) { - while ((nextLine = source.indexOf("\n", pos)) !== -1 && nextLine < match.index) { - pos = nextLine + 1; - line += 1; - } - column = match.index - pos; + if (!astUtils.isTokenOnSameLine(left, right)) { + return false; + } - context.report(node, { line: line, column: column }, message); - } - } + if (!sourceCode.isSpaceBetweenTokens(left, right)) { + return false; + } - sortSkipRanges(); + if (ALWAYS) { + return isOpenerException(right); + } else { + return !isOpenerException(right); + } + } - while ((nextMatch = rejectedSpaceRegExp.exec(source)) !== null) { - checkMatch(nextMatch, REJECTED_SPACE_MESSAGE); - } + /** + * Determines if an closer paren should not have an existing space after it + * @param {Object} left The token before the paren + * @param {Object} right The paren token + * @returns {boolean} True if the paren should reject the space + */ + function shouldCloserRejectSpace(left, right) { + if (left.type === "Punctuator" && left.value === "(") { + return false; + } - while ((nextMatch = missingSpaceRegExp.exec(source)) !== null) { - checkMatch(nextMatch, MISSING_SPACE_MESSAGE); - } + if (!astUtils.isTokenOnSameLine(left, right)) { + return false; + } - }, + if (!sourceCode.isSpaceBetweenTokens(left, right)) { + return false; + } + if (ALWAYS) { + return isCloserException(left); + } else { + return !isCloserException(left); + } + } - // These nodes can contain parentheses that this rule doesn't care about + //-------------------------------------------------------------------------- + // Public + //-------------------------------------------------------------------------- - LineComment: addSkipRange, + return { + "Program": function checkParenSpaces(node) { + var tokens, prevToken, nextToken; + exceptions = getExceptions(); + tokens = sourceCode.tokensAndComments; - BlockComment: addSkipRange, + tokens.forEach(function(token, i) { + prevToken = tokens[i - 1]; + nextToken = tokens[i + 1]; - Literal: addSkipRange, + if (token.type !== "Punctuator") { + return; + } - TemplateElement: addSkipRange + if (token.value !== "(" && token.value !== ")") { + return; + } + if (token.value === "(" && shouldOpenerHaveSpace(token, nextToken)) { + context.report(node, token.loc.start, MISSING_SPACE_MESSAGE); + } else if (token.value === "(" && shouldOpenerRejectSpace(token, nextToken)) { + context.report(node, token.loc.start, REJECTED_SPACE_MESSAGE); + } else if (token.value === ")" && shouldCloserHaveSpace(prevToken, token)) { + context.report(node, token.loc.start, MISSING_SPACE_MESSAGE); + } else if (token.value === ")" && shouldCloserRejectSpace(prevToken, token)) { + context.report(node, token.loc.start, REJECTED_SPACE_MESSAGE); + } + }); + } }; }; @@ -39445,7 +45191,7 @@ module.exports.schema = [ } ]; -},{}],329:[function(require,module,exports){ +},{"../ast-utils":152}],357:[function(require,module,exports){ /** * @fileoverview Require spaces around infix operators * @author Michael Ficarra @@ -39593,7 +45339,7 @@ module.exports.schema = [ } ]; -},{}],330:[function(require,module,exports){ +},{}],358:[function(require,module,exports){ /** * @fileoverview Require spaces following return, throw, and case * @author Michael Ficarra @@ -39619,7 +45365,7 @@ module.exports = function(context) { if (tokens[0].range[1] >= tokens[1].range[0]) { context.report({ node: node, - message: "Keyword \"" + value + "\" must be followed by whitespace.", + message: "Keyword '" + value + "' must be followed by whitespace.", fix: function(fixer) { return fixer.insertTextAfterRange(tokens[0].range, " "); } @@ -39645,7 +45391,7 @@ module.exports = function(context) { module.exports.schema = []; -},{}],331:[function(require,module,exports){ +},{}],359:[function(require,module,exports){ /** * @fileoverview This rule shoud require or disallow spaces before or after unary operations. * @author Marcin Kumorek @@ -39698,7 +45444,7 @@ module.exports = function(context) { if (secondToken.range[0] === firstToken.range[1]) { context.report({ node: node, - message: "Unary word operator \"" + word + "\" must be followed by whitespace.", + message: "Unary word operator '" + word + "' must be followed by whitespace.", fix: function(fixer) { return fixer.insertTextAfter(firstToken, " "); } @@ -39710,7 +45456,7 @@ module.exports = function(context) { if (secondToken.range[0] > firstToken.range[1]) { context.report({ node: node, - message: "Unexpected space after unary word operator \"" + word + "\".", + message: "Unexpected space after unary word operator '" + word + "'.", fix: function(fixer) { return fixer.removeRange([firstToken.range[1], secondToken.range[0]]); } @@ -39731,18 +45477,18 @@ module.exports = function(context) { if ((node.type === "NewExpression" || node.prefix) && firstToken.type === "Keyword") { checkUnaryWordOperatorForSpaces(node, firstToken, secondToken); - return void 0; + return; } if (options.nonwords) { if (node.prefix) { if (isFirstBangInBangBangExpression(node)) { - return void 0; + return; } if (firstToken.range[1] === secondToken.range[0]) { context.report({ node: node, - message: "Unary operator \"" + firstToken.value + "\" must be followed by whitespace.", + message: "Unary operator '" + firstToken.value + "' must be followed by whitespace.", fix: function(fixer) { return fixer.insertTextAfter(firstToken, " "); } @@ -39752,7 +45498,7 @@ module.exports = function(context) { if (firstToken.range[1] === secondToken.range[0]) { context.report({ node: node, - message: "Space is required before unary expressions \"" + secondToken.value + "\".", + message: "Space is required before unary expressions '" + secondToken.value + "'.", fix: function(fixer) { return fixer.insertTextBefore(secondToken, " "); } @@ -39764,7 +45510,7 @@ module.exports = function(context) { if (secondToken.range[0] > firstToken.range[1]) { context.report({ node: node, - message: "Unexpected space after unary operator \"" + firstToken.value + "\".", + message: "Unexpected space after unary operator '" + firstToken.value + "'.", fix: function(fixer) { return fixer.removeRange([firstToken.range[1], secondToken.range[0]]); } @@ -39774,7 +45520,7 @@ module.exports = function(context) { if (secondToken.range[0] > firstToken.range[1]) { context.report({ node: node, - message: "Unexpected space before unary operator \"" + secondToken.value + "\".", + message: "Unexpected space before unary operator '" + secondToken.value + "'.", fix: function(fixer) { return fixer.removeRange([firstToken.range[1], secondToken.range[0]]); } @@ -39796,16 +45542,11 @@ module.exports = function(context) { var tokens = context.getFirstTokens(node, 3), word = "yield"; - if (!node.argument) { + if (!node.argument || node.delegate) { return; } - if (node.delegate) { - word += "*"; - checkUnaryWordOperatorForSpaces(node, tokens[1], tokens[2], word); - } else { - checkUnaryWordOperatorForSpaces(node, tokens[0], tokens[1], word); - } + checkUnaryWordOperatorForSpaces(node, tokens[0], tokens[1], word); } }; @@ -39826,7 +45567,7 @@ module.exports.schema = [ } ]; -},{}],332:[function(require,module,exports){ +},{}],360:[function(require,module,exports){ /** * @fileoverview Source code for spaced-comments rule * @author Gyandeep Singh @@ -39870,9 +45611,7 @@ function escapeAndRepeat(s) { * @returns {string[]} A marker list. */ function parseMarkersOption(markers) { - if (!markers) { - markers = []; - } + markers = markers ? markers.slice(0) : []; // `*` is a marker for JSDoc comments. if (markers.indexOf("*") === -1) { @@ -39947,7 +45686,7 @@ function createAlwaysStylePattern(markers, exceptions) { * @returns {RegExp} A RegExp object for `never` mode. */ function createNeverStylePattern(markers) { - var pattern = "^(" + markers.map(escape).join("|") + ")?[ \t]"; + var pattern = "^(" + markers.map(escape).join("|") + ")?[ \t]+"; return new RegExp(pattern); } @@ -39969,12 +45708,44 @@ module.exports = function(context) { // Create RegExp object for valid patterns. rule[type] = { regex: requireSpace ? createAlwaysStylePattern(markers, exceptions) : createNeverStylePattern(markers), - hasExceptions: exceptions.length > 0 + hasExceptions: exceptions.length > 0, + markers: new RegExp("^(" + markers.map(escape).join("|") + ")") }; return rule; }, {}); + /** + * Reports a spacing error with an appropriate message. + * @param {ASTNode} node - A comment node to check. + * @param {string} message - An error message to report + * @param {Array} match - An array of match results for markers. + * @returns {void} + */ + function report(node, message, match) { + var type = node.type.toLowerCase(), + commentIdentifier = type === "block" ? "/*" : "//"; + + context.report({ + node: node, + fix: function(fixer) { + var start = node.range[0], + end = start + 2; + + if (requireSpace) { + if (match) { + end += match[0].length; + } + return fixer.insertTextAfterRange([start, end], " "); + } else { + end += match[0].length; + return fixer.replaceTextRange([start, end], commentIdentifier + (match[1] ? match[1] : "")); + } + }, + message: message + }); + } + /** * Reports a given comment if it's invalid. * @param {ASTNode} node - a comment node to check. @@ -39993,19 +45764,21 @@ module.exports = function(context) { // Checks. if (requireSpace) { if (!rule.regex.test(node.value)) { + var hasMarker = rule.markers.exec(node.value); + var marker = hasMarker ? commentIdentifier + hasMarker[0] : commentIdentifier; if (rule.hasExceptions) { - context.report(node, "Expected exception block, space or tab after " + commentIdentifier + " in comment."); + report(node, "Expected exception block, space or tab after '" + marker + "' in comment.", hasMarker); } else { - context.report(node, "Expected space or tab after " + commentIdentifier + " in comment."); + report(node, "Expected space or tab after '" + marker + "' in comment.", hasMarker); } } } else { var matched = rule.regex.exec(node.value); if (matched) { if (!matched[1]) { - context.report(node, "Unexpected space or tab after " + commentIdentifier + " in comment."); + report(node, "Unexpected space or tab after '" + commentIdentifier + "' in comment.", matched); } else { - context.report(node, "Unexpected space or tab after marker (" + matched[1] + ") in comment."); + report(node, "Unexpected space or tab after marker (" + matched[1] + ") in comment.", matched); } } } @@ -40079,7 +45852,7 @@ module.exports.schema = [ } ]; -},{"escape-string-regexp":20}],333:[function(require,module,exports){ +},{"escape-string-regexp":76}],361:[function(require,module,exports){ /** * @fileoverview Rule to control usage of strict mode directives. * @author Brandon Mills @@ -40090,18 +45863,24 @@ module.exports.schema = [ "use strict"; +//------------------------------------------------------------------------------ +// Requirements +//------------------------------------------------------------------------------ + +var assign = require("object-assign"); + //------------------------------------------------------------------------------ // Helpers //------------------------------------------------------------------------------ var messages = { - function: "Use the function form of \"use strict\".", - global: "Use the global form of \"use strict\".", - multiple: "Multiple \"use strict\" directives.", + function: "Use the function form of 'use strict'.", + global: "Use the global form of 'use strict'.", + multiple: "Multiple 'use strict' directives.", never: "Strict mode is not permitted.", - unnecessary: "Unnecessary \"use strict\" directive.", - unnecessaryInModules: "\"use strict\" is unnecessary inside of modules.", - unnecessaryInClasses: "\"use strict\" is unnecessary inside of classes." + unnecessary: "Unnecessary 'use strict' directive.", + module: "'use strict' is unnecessary inside of modules.", + unnecessaryInClasses: "'use strict' is unnecessary inside of classes." }; /** @@ -40137,175 +45916,156 @@ function getUseStrictDirectives(statements) { module.exports = function(context) { - var mode = context.options[0]; + var mode = context.options[0] || "safe", + scopes = [], + classScopes = [], + rule; + + if (mode === "safe") { + mode = context.parserOptions.ecmaFeatures && + context.parserOptions.ecmaFeatures.globalReturn ? + "global" : "function"; + } /** - * Report a node or array of nodes with a given message. - * @param {(ASTNode|ASTNode[])} nodes Node or nodes to report. + * Report a slice of an array of nodes with a given message. + * @param {ASTNode[]} nodes Nodes. + * @param {string} start Index to start from. + * @param {string} end Index to end before. * @param {string} message Message to display. * @returns {void} */ - function report(nodes, message) { + function reportSlice(nodes, start, end, message) { var i; - if (Array.isArray(nodes)) { - for (i = 0; i < nodes.length; i++) { - context.report(nodes[i], message); - } - } else { - context.report(nodes, message); + for (i = start; i < end; i++) { + context.report(nodes[i], message); } } - //-------------------------------------------------------------------------- - // "never" mode - //-------------------------------------------------------------------------- - - if (mode === "never") { - return { - "Program": function(node) { - report(getUseStrictDirectives(node.body), messages.never); - }, - "FunctionDeclaration": function(node) { - report(getUseStrictDirectives(node.body.body), messages.never); - }, - "FunctionExpression": function(node) { - report(getUseStrictDirectives(node.body.body), messages.never); - }, - "ArrowFunctionExpression": function(node) { - if (node.body.type === "BlockStatement") { - report(getUseStrictDirectives(node.body.body), messages.never); - } - } - }; - } - - //-------------------------------------------------------------------------- - // If this is modules, all "use strict" directives are unnecessary. - //-------------------------------------------------------------------------- - - if (context.ecmaFeatures.modules) { - return { - "Program": function(node) { - report(getUseStrictDirectives(node.body), messages.unnecessaryInModules); - }, - "FunctionDeclaration": function(node) { - report(getUseStrictDirectives(node.body.body), messages.unnecessaryInModules); - }, - "FunctionExpression": function(node) { - report(getUseStrictDirectives(node.body.body), messages.unnecessaryInModules); - }, - "ArrowFunctionExpression": function(node) { - if (node.body.type === "BlockStatement") { - report(getUseStrictDirectives(node.body.body), messages.unnecessaryInModules); - } - } - }; + /** + * Report all nodes in an array with a given message. + * @param {ASTNode[]} nodes Nodes. + * @param {string} message Message to display. + * @returns {void} + */ + function reportAll(nodes, message) { + reportSlice(nodes, 0, nodes.length, message); } - //-------------------------------------------------------------------------- - // "global" mode - //-------------------------------------------------------------------------- - - if (mode === "global") { - return { - "Program": function(node) { - var useStrictDirectives = getUseStrictDirectives(node.body); - - if (node.body.length > 0 && useStrictDirectives.length === 0) { - report(node, messages.global); - } else { - report(useStrictDirectives.slice(1), messages.multiple); - } - }, - "FunctionDeclaration": function(node) { - report(getUseStrictDirectives(node.body.body), messages.global); - }, - "FunctionExpression": function(node) { - report(getUseStrictDirectives(node.body.body), messages.global); - }, - "ArrowFunctionExpression": function(node) { - if (node.body.type === "BlockStatement") { - report(getUseStrictDirectives(node.body.body), messages.global); - } - } - }; + /** + * Report all nodes in an array, except the first, with a given message. + * @param {ASTNode[]} nodes Nodes. + * @param {string} message Message to display. + * @returns {void} + */ + function reportAllExceptFirst(nodes, message) { + reportSlice(nodes, 1, nodes.length, message); } - //-------------------------------------------------------------------------- - // "function" mode (Default) - //-------------------------------------------------------------------------- - - var scopes = [], - classScopes = []; - /** - * Entering a function pushes a new nested scope onto the stack. The new - * scope is true if the nested function is strict mode code. + * Entering a function in 'function' mode pushes a new nested scope onto the + * stack. The new scope is true if the nested function is strict mode code. * @param {ASTNode} node The function declaration or expression. + * @param {ASTNode[]} useStrictDirectives The Use Strict Directives of the node. * @returns {void} */ - function enterFunction(node) { + function enterFunctionInFunctionMode(node, useStrictDirectives) { var isInClass = classScopes.length > 0, isParentGlobal = scopes.length === 0 && classScopes.length === 0, isParentStrict = scopes.length > 0 && scopes[scopes.length - 1], - isNotBlock = node.body.type !== "BlockStatement", - useStrictDirectives = isNotBlock ? [] : getUseStrictDirectives(node.body.body), isStrict = useStrictDirectives.length > 0; if (isStrict) { if (isParentStrict) { - report(useStrictDirectives[0], messages.unnecessary); + context.report(useStrictDirectives[0], messages.unnecessary); } else if (isInClass) { - report(useStrictDirectives[0], messages.unnecessaryInClasses); + context.report(useStrictDirectives[0], messages.unnecessaryInClasses); } - report(useStrictDirectives.slice(1), messages.multiple); + reportAllExceptFirst(useStrictDirectives, messages.multiple); } else if (isParentGlobal) { - report(node, messages.function); + context.report(node, messages.function); } scopes.push(isParentStrict || isStrict); } /** - * Exiting a function pops its scope off the stack. + * Exiting a function in 'function' mode pops its scope off the stack. * @returns {void} */ - function exitFunction() { + function exitFunctionInFunctionMode() { scopes.pop(); } - return { + /** + * Enter a function and either: + * - Push a new nested scope onto the stack (in 'function' mode). + * - Report all the Use Strict Directives (in the other modes). + * @param {ASTNode} node The function declaration or expression. + * @returns {void} + */ + function enterFunction(node) { + var isBlock = node.body.type === "BlockStatement", + useStrictDirectives = isBlock ? + getUseStrictDirectives(node.body.body) : []; + + if (mode === "function") { + enterFunctionInFunctionMode(node, useStrictDirectives); + } else { + reportAll(useStrictDirectives, messages[mode]); + } + } + + rule = { "Program": function(node) { - report(getUseStrictDirectives(node.body), messages.function); - }, + var useStrictDirectives = getUseStrictDirectives(node.body); - // Inside of class bodies are always strict mode. - "ClassBody": function() { - classScopes.push(true); - }, - "ClassBody:exit": function() { - classScopes.pop(); - }, + if (node.sourceType === "module") { + mode = "module"; + } + if (mode === "global") { + if (node.body.length > 0 && useStrictDirectives.length === 0) { + context.report(node, messages.global); + } + reportAllExceptFirst(useStrictDirectives, messages.multiple); + } else { + reportAll(useStrictDirectives, messages[mode]); + } + }, "FunctionDeclaration": enterFunction, "FunctionExpression": enterFunction, - "ArrowFunctionExpression": enterFunction, - - "FunctionDeclaration:exit": exitFunction, - "FunctionExpression:exit": exitFunction, - "ArrowFunctionExpression:exit": exitFunction + "ArrowFunctionExpression": enterFunction }; + + if (mode === "function") { + assign(rule, { + // Inside of class bodies are always strict mode. + "ClassBody": function() { + classScopes.push(true); + }, + "ClassBody:exit": function() { + classScopes.pop(); + }, + + "FunctionDeclaration:exit": exitFunctionInFunctionMode, + "FunctionExpression:exit": exitFunctionInFunctionMode, + "ArrowFunctionExpression:exit": exitFunctionInFunctionMode + }); + } + + return rule; }; module.exports.schema = [ { - "enum": ["never", "global", "function"] + "enum": ["never", "global", "function", "safe"] } ]; -},{}],334:[function(require,module,exports){ +},{"object-assign":151}],362:[function(require,module,exports){ /** * @fileoverview Rule to flag comparisons to the value NaN * @author James Allardice @@ -40333,7 +46093,7 @@ module.exports = function(context) { module.exports.schema = []; -},{}],335:[function(require,module,exports){ +},{}],363:[function(require,module,exports){ /** * @fileoverview Validates JSDoc comments are syntactically correct * @author Nicholas C. Zakas @@ -40360,7 +46120,10 @@ module.exports = function(context) { // these both default to true, so you have to explicitly make them false requireReturn = options.requireReturn !== false, requireParamDescription = options.requireParamDescription !== false, - requireReturnDescription = options.requireReturnDescription !== false; + requireReturnDescription = options.requireReturnDescription !== false, + requireReturnType = options.requireReturnType !== false, + preferType = options.preferType || {}, + checkPreferType = Object.keys(preferType).length !== 0; //-------------------------------------------------------------------------- // Helpers @@ -40369,6 +46132,16 @@ module.exports = function(context) { // Using a stack to store if a function returns or not (handling nested functions) var fns = []; + /** + * Check if node type is a Class + * @param {ASTNode} node node to check. + * @returns {boolean} True is its a class + * @private + */ + function isTypeClass(node) { + return node.type === "ClassExpression" || node.type === "ClassDeclaration"; + } + /** * When parsing a new function, store it in our function stack. * @param {ASTNode} node A function node to check. @@ -40377,7 +46150,8 @@ module.exports = function(context) { */ function startFunction(node) { fns.push({ - returnPresent: (node.type === "ArrowFunctionExpression" && node.body.type !== "BlockStatement") + returnPresent: (node.type === "ArrowFunctionExpression" && node.body.type !== "BlockStatement") || + isTypeClass(node) }); } @@ -40402,7 +46176,93 @@ module.exports = function(context) { * @private */ function isValidReturnType(tag) { - return tag.type.name === "void" || tag.type.type === "UndefinedLiteral"; + return tag.type === null || tag.type.name === "void" || tag.type.type === "UndefinedLiteral"; + } + + /** + * Check if type should be validated based on some exceptions + * @param {Object} type JSDoc tag + * @returns {boolean} True if it can be validated + * @private + */ + function canTypeBeValidated(type) { + return type !== "UndefinedLiteral" && // {undefined} as there is no name property available. + type !== "NullLiteral" && // {null} + type !== "NullableLiteral" && // {?} + type !== "FunctionType" && // {function(a)} + type !== "AllLiteral"; // {*} + } + + /** + * Extract the current and expected type based on the input type object + * @param {Object} type JSDoc tag + * @returns {Object} current and expected type object + * @private + */ + function getCurrentExpectedTypes(type) { + var currentType; + var expectedType; + + if (!type.name) { + currentType = type.expression.name; + } else { + currentType = type.name; + } + + expectedType = preferType[currentType]; + + return { + currentType: currentType, + expectedType: expectedType + }; + } + + /** + * Check if return tag type is void or undefined + * @param {Object} tag JSDoc tag + * @param {Object} jsdocNode JSDoc node + * @returns {void} + * @private + */ + function validateTagType(tag, jsdocNode) { + if (!tag.type || !canTypeBeValidated(tag.type.type)) { + return; + } + + var typesToCheck = []; + var elements = []; + + if (tag.type.type === "TypeApplication") { // {Array.} + elements = tag.type.applications; + typesToCheck.push(getCurrentExpectedTypes(tag.type)); + } else if (tag.type.type === "RecordType") { // {{20:String}} + elements = tag.type.fields; + } else if (tag.type.type === "UnionType") { // {String|number|Test} + elements = tag.type.elements; + } else { + typesToCheck.push(getCurrentExpectedTypes(tag.type)); + } + + elements.forEach(function(type) { + type = type.value ? type.value : type; // we have to use type.value for RecordType + if (canTypeBeValidated(type.type)) { + typesToCheck.push(getCurrentExpectedTypes(type)); + } + }); + + typesToCheck.forEach(function(type) { + if (type.expectedType && + type.expectedType !== type.currentType) { + context.report({ + node: jsdocNode, + message: "Use '{{expectedType}}' instead of '{{currentType}}'.", + data: { + currentType: type.currentType, + expectedType: type.expectedType + } + }); + } + }); } /** @@ -40416,6 +46276,7 @@ module.exports = function(context) { functionData = fns.pop(), hasReturns = false, hasConstructor = false, + isInterface = false, isOverride = false, params = Object.create(null), jsdoc; @@ -40442,7 +46303,7 @@ module.exports = function(context) { jsdoc.tags.forEach(function(tag) { - switch (tag.title) { + switch (tag.title.toLowerCase()) { case "param": case "arg": @@ -40466,10 +46327,10 @@ module.exports = function(context) { case "returns": hasReturns = true; - if (!requireReturn && !functionData.returnPresent && tag.type.name !== "void" && tag.type.name !== "undefined") { + if (!requireReturn && !functionData.returnPresent && (tag.type === null || !isValidReturnType(tag))) { context.report(jsdocNode, "Unexpected @" + tag.title + " tag; function has no return statement."); } else { - if (!tag.type) { + if (requireReturnType && !tag.type) { context.report(jsdocNode, "Missing JSDoc return type."); } @@ -40490,18 +46351,28 @@ module.exports = function(context) { isOverride = true; break; + case "interface": + isInterface = true; + break; + // no default } // check tag preferences - if (prefer.hasOwnProperty(tag.title)) { + if (prefer.hasOwnProperty(tag.title) && tag.title !== prefer[tag.title]) { context.report(jsdocNode, "Use @{{name}} instead.", { name: prefer[tag.title] }); } + // validate the types + if (checkPreferType) { + validateTagType(tag, jsdocNode); + } }); // check for functions missing @returns - if (!isOverride && !hasReturns && !hasConstructor && node.parent.kind !== "get") { + if (!isOverride && !hasReturns && !hasConstructor && !isInterface && + node.parent.kind !== "get" && node.parent.kind !== "constructor" && + node.parent.kind !== "set" && !isTypeClass(node)) { if (requireReturn || functionData.returnPresent) { context.report(jsdocNode, "Missing JSDoc @" + (prefer.returns || "returns") + " for function."); } @@ -40510,23 +46381,33 @@ module.exports = function(context) { // check the parameters var jsdocParams = Object.keys(params); - node.params.forEach(function(param, i) { - var name = param.name; + if (node.params) { + node.params.forEach(function(param, i) { + var name = param.name; - // TODO(nzakas): Figure out logical things to do with destructured, default, rest params - if (param.type === "Identifier") { - if (jsdocParams[i] && (name !== jsdocParams[i])) { - context.report(jsdocNode, "Expected JSDoc for '{{name}}' but found '{{jsdocName}}'.", { - name: name, - jsdocName: jsdocParams[i] - }); - } else if (!params[name] && !isOverride) { - context.report(jsdocNode, "Missing JSDoc for parameter '{{name}}'.", { - name: name - }); + // TODO(nzakas): Figure out logical things to do with destructured, default, rest params + if (param.type === "Identifier") { + if (jsdocParams[i] && (name !== jsdocParams[i])) { + context.report(jsdocNode, "Expected JSDoc for '{{name}}' but found '{{jsdocName}}'.", { + name: name, + jsdocName: jsdocParams[i] + }); + } else if (!params[name] && !isOverride) { + context.report(jsdocNode, "Missing JSDoc for parameter '{{name}}'.", { + name: name + }); + } } + }); + } + + if (options.matchDescription) { + var regex = new RegExp(options.matchDescription); + + if (!regex.test(jsdoc.description)) { + context.report(jsdocNode, "JSDoc description does not satisfy the regex pattern."); } - }); + } } @@ -40540,9 +46421,13 @@ module.exports = function(context) { "ArrowFunctionExpression": startFunction, "FunctionExpression": startFunction, "FunctionDeclaration": startFunction, + "ClassExpression": startFunction, + "ClassDeclaration": startFunction, "ArrowFunctionExpression:exit": checkJSDoc, "FunctionExpression:exit": checkJSDoc, "FunctionDeclaration:exit": checkJSDoc, + "ClassExpression:exit": checkJSDoc, + "ClassDeclaration:exit": checkJSDoc, "ReturnStatement": addReturn }; @@ -40558,6 +46443,12 @@ module.exports.schema = [ "type": "string" } }, + "preferType": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, "requireReturn": { "type": "boolean" }, @@ -40566,13 +46457,19 @@ module.exports.schema = [ }, "requireReturnDescription": { "type": "boolean" + }, + "matchDescription": { + "type": "string" + }, + "requireReturnType": { + "type": "boolean" } }, "additionalProperties": false } ]; -},{"doctrine":11}],336:[function(require,module,exports){ +},{"doctrine":14}],364:[function(require,module,exports){ /** * @fileoverview Ensures that the results of typeof are compared against a valid string * @author Ian Christian Myers @@ -40616,7 +46513,7 @@ module.exports = function(context) { module.exports.schema = []; -},{}],337:[function(require,module,exports){ +},{}],365:[function(require,module,exports){ /** * @fileoverview Rule to enforce var declarations are only at the top of a function. * @author Danny Fritz @@ -40631,7 +46528,7 @@ module.exports.schema = []; //------------------------------------------------------------------------------ module.exports = function(context) { - var errorMessage = "All \"var\" declarations must be at the top of the function scope."; + var errorMessage = "All 'var' declarations must be at the top of the function scope."; //-------------------------------------------------------------------------- // Helpers @@ -40680,6 +46577,8 @@ module.exports = function(context) { return true; } } + + return false; } /** @@ -40719,8 +46618,8 @@ module.exports = function(context) { var parent = ancestors.pop(); var grandParent = ancestors.pop(); - if (node.kind === "var") {// check variable is `var` type and not `let` or `const` - if (parent.type === "Program") {// That means its a global variable + if (node.kind === "var") { // check variable is `var` type and not `let` or `const` + if (parent.type === "Program") { // That means its a global variable globalVarCheck(node, parent); } else { blockScopeVarCheck(node, parent, grandParent); @@ -40733,7 +46632,7 @@ module.exports = function(context) { module.exports.schema = []; -},{}],338:[function(require,module,exports){ +},{}],366:[function(require,module,exports){ /** * @fileoverview Rule to flag when IIFE is not wrapped in parens * @author Ilya Volodin @@ -40789,7 +46688,7 @@ module.exports.schema = [ } ]; -},{}],339:[function(require,module,exports){ +},{}],367:[function(require,module,exports){ /** * @fileoverview Rule to flag when regex literals are not wrapped in parens * @author Matt DuVall @@ -40829,7 +46728,110 @@ module.exports = function(context) { module.exports.schema = []; -},{}],340:[function(require,module,exports){ +},{}],368:[function(require,module,exports){ +/** + * @fileoverview Rule to check the spacing around the * in yield* expressions. + * @author Bryan Smith + * @copyright 2015 Bryan Smith. All rights reserved. + */ + +"use strict"; + +//------------------------------------------------------------------------------ +// Rule Definition +//------------------------------------------------------------------------------ + +module.exports = function(context) { + var sourceCode = context.getSourceCode(); + + var mode = (function(option) { + if (!option || typeof option === "string") { + return { + before: { before: true, after: false }, + after: { before: false, after: true }, + both: { before: true, after: true }, + neither: { before: false, after: false } + }[option || "after"]; + } + return option; + }(context.options[0])); + + /** + * Checks the spacing between two tokens before or after the star token. + * @param {string} side Either "before" or "after". + * @param {Token} leftToken `function` keyword token if side is "before", or + * star token if side is "after". + * @param {Token} rightToken Star token if side is "before", or identifier + * token if side is "after". + * @returns {void} + */ + function checkSpacing(side, leftToken, rightToken) { + if (sourceCode.isSpaceBetweenTokens(leftToken, rightToken) !== mode[side]) { + var after = leftToken.value === "*"; + var spaceRequired = mode[side]; + var node = after ? leftToken : rightToken; + var type = spaceRequired ? "Missing" : "Unexpected"; + var message = type + " space " + side + " *."; + context.report({ + node: node, + message: message, + fix: function(fixer) { + if (spaceRequired) { + if (after) { + return fixer.insertTextAfter(node, " "); + } + return fixer.insertTextBefore(node, " "); + } + return fixer.removeRange([leftToken.range[1], rightToken.range[0]]); + } + }); + } + } + + /** + * Enforces the spacing around the star if node is a yield* expression. + * @param {ASTNode} node A yield expression node. + * @returns {void} + */ + function checkExpression(node) { + if (!node.delegate) { + return; + } + + var tokens = sourceCode.getFirstTokens(node, 3); + var yieldToken = tokens[0]; + var starToken = tokens[1]; + var nextToken = tokens[2]; + + checkSpacing("before", yieldToken, starToken); + checkSpacing("after", starToken, nextToken); + } + + return { + "YieldExpression": checkExpression + }; + +}; + +module.exports.schema = [ + { + "oneOf": [ + { + "enum": ["before", "after", "both", "neither"] + }, + { + "type": "object", + "properties": { + "before": {"type": "boolean"}, + "after": {"type": "boolean"} + }, + "additionalProperties": false + } + ] + } +]; + +},{}],369:[function(require,module,exports){ /** * @fileoverview Rule to require or disallow yoda comparisons * @author Nicholas C. Zakas @@ -41073,7 +47075,7 @@ module.exports.schema = [ } ]; -},{}],341:[function(require,module,exports){ +},{}],370:[function(require,module,exports){ (function (process){ /** * @fileoverview Tracks performance of individual rules. @@ -41215,7 +47217,7 @@ module.exports = (function() { }()); }).call(this,require('_process')) -},{"_process":8}],342:[function(require,module,exports){ +},{"_process":8}],371:[function(require,module,exports){ /** * @fileoverview Object to handle access and retrieval of tokens. * @author Brandon Mills @@ -41418,7 +47420,7 @@ module.exports = function(tokens) { return api; }; -},{}],343:[function(require,module,exports){ +},{}],372:[function(require,module,exports){ /** * @fileoverview Common utilities. */ @@ -41428,134 +47430,21 @@ module.exports = function(tokens) { // Constants //------------------------------------------------------------------------------ -var PLUGIN_NAME_PREFIX = "eslint-plugin-", - NAMESPACE_REGEX = /^@.*\//i; - -//------------------------------------------------------------------------------ -// Public Interface -//------------------------------------------------------------------------------ - -/** - * Merges two config objects. This will not only add missing keys, but will also modify values to match. - * @param {Object} target config object - * @param {Object} src config object. Overrides in this config object will take priority over base. - * @param {boolean} [combine] Whether to combine arrays or not - * @param {boolean} [isRule] Whether its a rule - * @returns {Object} merged config object. - */ -exports.mergeConfigs = function deepmerge(target, src, combine, isRule) { - /* - The MIT License (MIT) - - Copyright (c) 2012 Nicholas Fisher - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - */ - // This code is taken from deepmerge repo (https://github.com/KyleAMathews/deepmerge) and modified to meet our needs. - var array = Array.isArray(src) || Array.isArray(target); - var dst = array && [] || {}; - - combine = !!combine; - isRule = !!isRule; - if (array) { - target = target || []; - if (isRule && src.length > 1) { - dst = dst.concat(src); - } else { - dst = dst.concat(target); - } - if (typeof src !== "object" && !Array.isArray(src)) { - src = [src]; - } - Object.keys(src).forEach(function(e, i) { - e = src[i]; - if (typeof dst[i] === "undefined") { - dst[i] = e; - } else if (typeof e === "object") { - if (isRule) { - dst[i] = e; - } else { - dst[i] = deepmerge(target[i], e, combine, isRule); - } - } else { - if (!combine) { - dst[i] = e; - } else { - if (dst.indexOf(e) === -1) { - dst.push(e); - } - } - } - }); - } else { - if (target && typeof target === "object") { - Object.keys(target).forEach(function(key) { - dst[key] = target[key]; - }); - } - Object.keys(src).forEach(function(key) { - if (Array.isArray(src[key]) || Array.isArray(target[key])) { - dst[key] = deepmerge(target[key], src[key], key === "plugins", isRule); - } else if (typeof src[key] !== "object" || !src[key]) { - dst[key] = src[key]; - } else { - if (!target[key]) { - dst[key] = src[key]; - } else { - dst[key] = deepmerge(target[key], src[key], combine, key === "rules"); - } - } - }); - } - - return dst; -}; - -/** - * Removes the prefix `eslint-plugin-` from a plugin name. - * @param {string} pluginName The name of the plugin which may have the prefix. - * @returns {string} The name of the plugin without prefix. - */ -exports.removePluginPrefix = function removePluginPrefix(pluginName) { - return pluginName.indexOf(PLUGIN_NAME_PREFIX) === 0 ? pluginName.substring(PLUGIN_NAME_PREFIX.length) : pluginName; -}; - /** - * @param {string} pluginName The name of the plugin which may have the prefix. - * @returns {string} The name of the plugins namepace if it has one. + * Gets the last element of a given array. + * @param {any[]} xs - An array to get. + * @returns {any|null} The last element, or `null` if the array is empty. */ -exports.getNamespace = function getNamespace(pluginName) { - return pluginName.match(NAMESPACE_REGEX) ? pluginName.match(NAMESPACE_REGEX)[0] : ""; -}; +function getLast(xs) { + var length = xs.length; + return (length === 0 ? null : xs[length - 1]); +} -/** - * Removes the namespace from a plugin name. - * @param {string} pluginName The name of the plugin which may have the prefix. - * @returns {string} The name of the plugin without the namespace. - */ -exports.removeNameSpace = function removeNameSpace(pluginName) { - return pluginName.replace(NAMESPACE_REGEX, ""); +module.exports = { + getLast: getLast }; -exports.PLUGIN_NAME_PREFIX = PLUGIN_NAME_PREFIX; - -},{}],344:[function(require,module,exports){ +},{}],373:[function(require,module,exports){ /** * @fileoverview The event generator for comments. * @author Toru Nagashima @@ -41673,7 +47562,64 @@ CommentEventGenerator.prototype = { module.exports = CommentEventGenerator; -},{}],345:[function(require,module,exports){ +},{}],374:[function(require,module,exports){ +/** + * @fileoverview Patch for estraverse + * @author Toru Nagashima + * @copyright 2015 Toru Nagashima. All rights reserved. + * See LICENSE file in root directory for full license. + */ +"use strict"; + +//------------------------------------------------------------------------------ +// Requirements +//------------------------------------------------------------------------------ + +var estraverse = require("estraverse"), + jsxKeys = require("estraverse-fb/keys"); + +//------------------------------------------------------------------------------ +// Helers +//------------------------------------------------------------------------------ + +var experimentalKeys = { + ExperimentalRestProperty: ["argument"], + ExperimentalSpreadProperty: ["argument"] +}; + +/** + * Adds a given keys to Syntax and VisitorKeys of estraverse. + * + * @param {object} keys - Key definitions to add. + * This is an object as map. + * Keys are the node type. + * Values are an array of property names to visit. + * @returns {void} + */ +function installKeys(keys) { + for (var key in keys) { + /* istanbul ignore else */ + if (keys.hasOwnProperty(key)) { + estraverse.Syntax[key] = key; + if (keys[key]) { + estraverse.VisitorKeys[key] = keys[key]; + } + } + } +} + +// Add JSX node types. +installKeys(jsxKeys); +// Add Experimental node types. +installKeys(experimentalKeys); + +//------------------------------------------------------------------------------ +// Public Interface +//------------------------------------------------------------------------------ + +module.exports = estraverse; + +},{"estraverse":136,"estraverse-fb/keys":135}],375:[function(require,module,exports){ /** * @fileoverview A shared list of ES3 keywords. * @author Josh Perez @@ -41743,7 +47689,7 @@ module.exports = [ "with" ]; -},{}],346:[function(require,module,exports){ +},{}],376:[function(require,module,exports){ /** * @fileoverview The event generator for AST nodes. * @author Toru Nagashima @@ -41800,7 +47746,7 @@ NodeEventGenerator.prototype = { module.exports = NodeEventGenerator; -},{}],347:[function(require,module,exports){ +},{}],377:[function(require,module,exports){ /** * @fileoverview An object that creates fix commands for rules. * @author Nicholas C. Zakas @@ -41949,7 +47895,7 @@ RuleFixer.prototype = { module.exports = RuleFixer; -},{}],348:[function(require,module,exports){ +},{}],378:[function(require,module,exports){ /** * @fileoverview Abstraction of JavaScript source code. * @author Nicholas C. Zakas @@ -41957,14 +47903,13 @@ module.exports = RuleFixer; * See LICENSE file in root directory for full license. */ "use strict"; -/* eslint no-underscore-dangle: 0*/ //------------------------------------------------------------------------------ // Requirements //------------------------------------------------------------------------------ var createTokenStore = require("../token-store.js"), - estraverse = require("estraverse"), + estraverse = require("./estraverse"), assign = require("object-assign"); //------------------------------------------------------------------------------ @@ -42040,19 +47985,25 @@ function looksLikeExport(astNode) { /** * Represents parsed source code. - * @param {string} text The source code text. - * @param {ASTNode} ast The Program node of the AST representing the code. + * @param {string} text - The source code text. + * @param {ASTNode} ast - The Program node of the AST representing the code. This AST should be created from the text that BOM was stripped. * @constructor */ function SourceCode(text, ast) { - validate(ast); + /** + * The flag to indicate that the source code has Unicode BOM. + * @type boolean + */ + this.hasBOM = (text.charCodeAt(0) === 0xFEFF); + /** * The original text source code. + * BOM was stripped from this text. * @type string */ - this.text = text; + this.text = (this.hasBOM ? text.slice(1) : text); /** * The parsed AST for the source code. @@ -42065,7 +48016,11 @@ function SourceCode(text, ast) { * This is done to avoid each rule needing to do so separately. * @type string[] */ - this.lines = text.split(/\r\n|\r|\n|\u2028|\u2029/g); + this.lines = SourceCode.splitLines(this.text); + + this.tokensAndComments = ast.tokens.concat(ast.comments).sort(function(left, right) { + return left.range[0] - right.range[0]; + }); // create token store methods var tokenStore = createTokenStore(ast.tokens); @@ -42073,11 +48028,25 @@ function SourceCode(text, ast) { this[methodName] = tokenStore[methodName]; }, this); + var tokensAndCommentsStore = createTokenStore(this.tokensAndComments); + this.getTokenOrCommentBefore = tokensAndCommentsStore.getTokenBefore; + this.getTokenOrCommentAfter = tokensAndCommentsStore.getTokenAfter; + // don't allow modification of this object Object.freeze(this); Object.freeze(this.lines); } +/** + * Split the source code into multiple lines based on the line delimiters + * @param {string} text Source code as a string + * @returns {string[]} Array of source code lines + * @public + */ +SourceCode.splitLines = function(text) { + return text.split(/\r\n|\r|\n|\u2028|\u2029/g); +}; + SourceCode.prototype = { constructor: SourceCode, @@ -42090,8 +48059,8 @@ SourceCode.prototype = { */ getText: function(node, beforeCount, afterCount) { if (node) { - return (this.text !== null) ? this.text.slice(Math.max(node.range[0] - (beforeCount || 0), 0), - node.range[1] + (afterCount || 0)) : null; + return this.text.slice(Math.max(node.range[0] - (beforeCount || 0), 0), + node.range[1] + (afterCount || 0)); } else { return this.text; } @@ -42151,27 +48120,30 @@ SourceCode.prototype = { */ getJSDocComment: function(node) { - var parent = node.parent, - line = node.loc.start.line; + var parent = node.parent; switch (node.type) { + case "ClassDeclaration": case "FunctionDeclaration": if (looksLikeExport(parent)) { - return findJSDocComment(parent.leadingComments, line); - } else { - return findJSDocComment(node.leadingComments, line); + return findJSDocComment(parent.leadingComments, parent.loc.start.line); } - break; + return findJSDocComment(node.leadingComments, node.loc.start.line); + + case "ClassExpression": + return findJSDocComment(parent.parent.leadingComments, parent.parent.loc.start.line); case "ArrowFunctionExpression": case "FunctionExpression": if (parent.type !== "CallExpression" && parent.type !== "NewExpression") { - while (parent && !parent.leadingComments && !/Function/.test(parent.type)) { + while (parent && !parent.leadingComments && !/Function/.test(parent.type) && parent.type !== "MethodDefinition" && parent.type !== "Property") { parent = parent.parent; } - return parent && (parent.type !== "FunctionDeclaration") ? findJSDocComment(parent.leadingComments, line) : null; + return parent && (parent.type !== "FunctionDeclaration") ? findJSDocComment(parent.leadingComments, parent.loc.start.line) : null; + } else if (node.leadingComments) { + return findJSDocComment(node.leadingComments, node.loc.start.line); } // falls through @@ -42188,11 +48160,13 @@ SourceCode.prototype = { */ getNodeByRangeIndex: function(index) { var result = null; + var resultParent = null; estraverse.traverse(this.ast, { enter: function(node, parent) { if (node.range[0] <= index && index < node.range[1]) { - result = assign({ parent: parent }, node); + result = node; + resultParent = parent; } else { this.skip(); } @@ -42204,7 +48178,7 @@ SourceCode.prototype = { } }); - return result; + return result ? assign({parent: resultParent}, result) : null; }, /** @@ -42225,5 +48199,5 @@ SourceCode.prototype = { module.exports = SourceCode; -},{"../token-store.js":342,"estraverse":133,"object-assign":148}]},{},[153])(153) +},{"../token-store.js":371,"./estraverse":374,"object-assign":151}]},{},[163])(163) }); \ No newline at end of file diff --git a/eslint.js b/eslint.js index 006bd6f..724036f 100644 --- a/eslint.js +++ b/eslint.js @@ -206,13 +206,21 @@ } } - - function isEmpty( obj ) { - for ( var prop in obj ) { - return false; - } - return true; + // Hack for collecting node location by waiting for fix https://github.com/eslint/eslint/issues/3307 + function getMessageId(ruleId, severity, line, column) { + return ruleId + "_" + severity + "_" + line + "_" + column; } + + var report = eslint.report; + eslint.report = function(ruleId, severity, node, location, message, opts, fix, meta) { + report(ruleId, severity, node, location, message, opts, fix, meta); + if (typeof location === "string") { + location = node.loc.start; + } + if (node && node.loc.start == location) this.messages_loc[getMessageId(ruleId, severity, location.line, location.column + 1)] = node; + } + + function isEmpty( obj ) {for ( var prop in obj ) {return false;} return true;} function normPath(name) { return name.replace(/\\/g, "/"); } @@ -296,10 +304,10 @@ if (node && node.range) { return from ? node.range[0] : node.range[1]; } - var line = error.line-1, ch = from ? error.column - 1 : error.column; - if (error.node && error.node.loc) { - line = from ? error.node.loc.start.line -1 : error.node.loc.end.line -1; - ch = from ? error.node.loc.start.column : error.node.loc.end.column; + var line = error.line - 1, ch = from ? error.column - 1 : error.column; + if (node && node.loc) { + line = from ? node.loc.start.line - 1 : node.loc.end.line - 1; + ch = from ? node.loc.start.column : node.loc.end.column; } // adjust ch if (from) { @@ -309,7 +317,9 @@ if (ch < 2) ch = 1; else if (ch >= file.text.length) ch = file.text.length; } - return tern.resolvePos(file, {line: line, ch: ch}); + var pos = tern.resolvePos(file, {line: line, ch: ch}, true); + if (pos > file.text.length) pos = file.text.length; + return pos; } function getSeverity(error) { @@ -324,7 +334,18 @@ } function makeError(message) { - var from = getPos(message, true), to = getPos(message, false); + if (!message.node) { + // ESLint message doesn't contains node information (see https://github.com/eslint/eslint/issues/3307) + // try to retrieve if from messages_loc + var node = eslint.messages_loc[getMessageId(message.ruleId, message.severity, message.line, message.column)]; + if (node) message.node = node; + } + var from = getPos(message, true), to = getPos(message, false); + if (from == to) { + console.error(from) + if (from == 0 && file.text.length >=1) to = 1; + else from--; + } var error = { message: message.message, severity: getSeverity(message), @@ -337,9 +358,10 @@ return error; } - //clear all existing settings for a new file + // clear all existing settings for a new file eslint.reset(); - + eslint.messages_loc = []; + var text = file.text, eslintConfig = server.mod.eslint.config; // Update eslint config if needed. eslintConfig.update(); diff --git a/package.json b/package.json index f0a0179..bf8f0d6 100644 --- a/package.json +++ b/package.json @@ -14,12 +14,12 @@ "test": "node ./test/all.js" }, "dependencies": { - "tern": "^0.16.0", + "tern": "^0.17.0", "eslint": "^1.10.3" }, "devDependencies": { "test": ">=0.0.5", - "codemirror": "^5.9.0", + "codemirror": "^5.11.0", "codemirror-extension": "^0.2.0", "codemirror-javascript": "^0.2.0" }, diff --git a/test/validate_default.js b/test/validate_default.js index eae57bf..f996368 100644 --- a/test/validate_default.js +++ b/test/validate_default.js @@ -8,7 +8,7 @@ exports['test never used'] = function() { "message" : "\"arr\" is defined but never used", "severity" : "error", "from" : 4, - "to" : 5, + "to" : 7, "lineNumber": 1, "id": "no-unused-vars", "file": "test1.js"}