UNPKG

212 kBJavaScriptView Raw
1/*! jsonpath 0.2.5 */
2
3(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.jsonpath = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"./aesprim":[function(require,module,exports){
4/*
5 Copyright (C) 2013 Ariya Hidayat <ariya.hidayat@gmail.com>
6 Copyright (C) 2013 Thaddee Tyl <thaddee.tyl@gmail.com>
7 Copyright (C) 2013 Mathias Bynens <mathias@qiwi.be>
8 Copyright (C) 2012 Ariya Hidayat <ariya.hidayat@gmail.com>
9 Copyright (C) 2012 Mathias Bynens <mathias@qiwi.be>
10 Copyright (C) 2012 Joost-Wim Boekesteijn <joost-wim@boekesteijn.nl>
11 Copyright (C) 2012 Kris Kowal <kris.kowal@cixar.com>
12 Copyright (C) 2012 Yusuke Suzuki <utatane.tea@gmail.com>
13 Copyright (C) 2012 Arpad Borsos <arpad.borsos@googlemail.com>
14 Copyright (C) 2011 Ariya Hidayat <ariya.hidayat@gmail.com>
15
16 Redistribution and use in source and binary forms, with or without
17 modification, are permitted provided that the following conditions are met:
18
19 * Redistributions of source code must retain the above copyright
20 notice, this list of conditions and the following disclaimer.
21 * Redistributions in binary form must reproduce the above copyright
22 notice, this list of conditions and the following disclaimer in the
23 documentation and/or other materials provided with the distribution.
24
25 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
29 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
32 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35*/
36
37/*jslint bitwise:true plusplus:true */
38/*global esprima:true, define:true, exports:true, window: true,
39throwErrorTolerant: true,
40throwError: true, generateStatement: true, peek: true,
41parseAssignmentExpression: true, parseBlock: true, parseExpression: true,
42parseFunctionDeclaration: true, parseFunctionExpression: true,
43parseFunctionSourceElements: true, parseVariableIdentifier: true,
44parseLeftHandSideExpression: true,
45parseUnaryExpression: true,
46parseStatement: true, parseSourceElement: true */
47
48(function (root, factory) {
49 'use strict';
50
51 // Universal Module Definition (UMD) to support AMD, CommonJS/Node.js,
52 // Rhino, and plain browser loading.
53
54 /* istanbul ignore next */
55 if (typeof define === 'function' && define.amd) {
56 define(['exports'], factory);
57 } else if (typeof exports !== 'undefined') {
58 factory(exports);
59 } else {
60 factory((root.esprima = {}));
61 }
62}(this, function (exports) {
63 'use strict';
64
65 var Token,
66 TokenName,
67 FnExprTokens,
68 Syntax,
69 PropertyKind,
70 Messages,
71 Regex,
72 SyntaxTreeDelegate,
73 source,
74 strict,
75 index,
76 lineNumber,
77 lineStart,
78 length,
79 delegate,
80 lookahead,
81 state,
82 extra;
83
84 Token = {
85 BooleanLiteral: 1,
86 EOF: 2,
87 Identifier: 3,
88 Keyword: 4,
89 NullLiteral: 5,
90 NumericLiteral: 6,
91 Punctuator: 7,
92 StringLiteral: 8,
93 RegularExpression: 9
94 };
95
96 TokenName = {};
97 TokenName[Token.BooleanLiteral] = 'Boolean';
98 TokenName[Token.EOF] = '<end>';
99 TokenName[Token.Identifier] = 'Identifier';
100 TokenName[Token.Keyword] = 'Keyword';
101 TokenName[Token.NullLiteral] = 'Null';
102 TokenName[Token.NumericLiteral] = 'Numeric';
103 TokenName[Token.Punctuator] = 'Punctuator';
104 TokenName[Token.StringLiteral] = 'String';
105 TokenName[Token.RegularExpression] = 'RegularExpression';
106
107 // A function following one of those tokens is an expression.
108 FnExprTokens = ['(', '{', '[', 'in', 'typeof', 'instanceof', 'new',
109 'return', 'case', 'delete', 'throw', 'void',
110 // assignment operators
111 '=', '+=', '-=', '*=', '/=', '%=', '<<=', '>>=', '>>>=',
112 '&=', '|=', '^=', ',',
113 // binary/unary operators
114 '+', '-', '*', '/', '%', '++', '--', '<<', '>>', '>>>', '&',
115 '|', '^', '!', '~', '&&', '||', '?', ':', '===', '==', '>=',
116 '<=', '<', '>', '!=', '!=='];
117
118 Syntax = {
119 AssignmentExpression: 'AssignmentExpression',
120 ArrayExpression: 'ArrayExpression',
121 BlockStatement: 'BlockStatement',
122 BinaryExpression: 'BinaryExpression',
123 BreakStatement: 'BreakStatement',
124 CallExpression: 'CallExpression',
125 CatchClause: 'CatchClause',
126 ConditionalExpression: 'ConditionalExpression',
127 ContinueStatement: 'ContinueStatement',
128 DoWhileStatement: 'DoWhileStatement',
129 DebuggerStatement: 'DebuggerStatement',
130 EmptyStatement: 'EmptyStatement',
131 ExpressionStatement: 'ExpressionStatement',
132 ForStatement: 'ForStatement',
133 ForInStatement: 'ForInStatement',
134 FunctionDeclaration: 'FunctionDeclaration',
135 FunctionExpression: 'FunctionExpression',
136 Identifier: 'Identifier',
137 IfStatement: 'IfStatement',
138 Literal: 'Literal',
139 LabeledStatement: 'LabeledStatement',
140 LogicalExpression: 'LogicalExpression',
141 MemberExpression: 'MemberExpression',
142 NewExpression: 'NewExpression',
143 ObjectExpression: 'ObjectExpression',
144 Program: 'Program',
145 Property: 'Property',
146 ReturnStatement: 'ReturnStatement',
147 SequenceExpression: 'SequenceExpression',
148 SwitchStatement: 'SwitchStatement',
149 SwitchCase: 'SwitchCase',
150 ThisExpression: 'ThisExpression',
151 ThrowStatement: 'ThrowStatement',
152 TryStatement: 'TryStatement',
153 UnaryExpression: 'UnaryExpression',
154 UpdateExpression: 'UpdateExpression',
155 VariableDeclaration: 'VariableDeclaration',
156 VariableDeclarator: 'VariableDeclarator',
157 WhileStatement: 'WhileStatement',
158 WithStatement: 'WithStatement'
159 };
160
161 PropertyKind = {
162 Data: 1,
163 Get: 2,
164 Set: 4
165 };
166
167 // Error messages should be identical to V8.
168 Messages = {
169 UnexpectedToken: 'Unexpected token %0',
170 UnexpectedNumber: 'Unexpected number',
171 UnexpectedString: 'Unexpected string',
172 UnexpectedIdentifier: 'Unexpected identifier',
173 UnexpectedReserved: 'Unexpected reserved word',
174 UnexpectedEOS: 'Unexpected end of input',
175 NewlineAfterThrow: 'Illegal newline after throw',
176 InvalidRegExp: 'Invalid regular expression',
177 UnterminatedRegExp: 'Invalid regular expression: missing /',
178 InvalidLHSInAssignment: 'Invalid left-hand side in assignment',
179 InvalidLHSInForIn: 'Invalid left-hand side in for-in',
180 MultipleDefaultsInSwitch: 'More than one default clause in switch statement',
181 NoCatchOrFinally: 'Missing catch or finally after try',
182 UnknownLabel: 'Undefined label \'%0\'',
183 Redeclaration: '%0 \'%1\' has already been declared',
184 IllegalContinue: 'Illegal continue statement',
185 IllegalBreak: 'Illegal break statement',
186 IllegalReturn: 'Illegal return statement',
187 StrictModeWith: 'Strict mode code may not include a with statement',
188 StrictCatchVariable: 'Catch variable may not be eval or arguments in strict mode',
189 StrictVarName: 'Variable name may not be eval or arguments in strict mode',
190 StrictParamName: 'Parameter name eval or arguments is not allowed in strict mode',
191 StrictParamDupe: 'Strict mode function may not have duplicate parameter names',
192 StrictFunctionName: 'Function name may not be eval or arguments in strict mode',
193 StrictOctalLiteral: 'Octal literals are not allowed in strict mode.',
194 StrictDelete: 'Delete of an unqualified identifier in strict mode.',
195 StrictDuplicateProperty: 'Duplicate data property in object literal not allowed in strict mode',
196 AccessorDataProperty: 'Object literal may not have data and accessor property with the same name',
197 AccessorGetSet: 'Object literal may not have multiple get/set accessors with the same name',
198 StrictLHSAssignment: 'Assignment to eval or arguments is not allowed in strict mode',
199 StrictLHSPostfix: 'Postfix increment/decrement may not have eval or arguments operand in strict mode',
200 StrictLHSPrefix: 'Prefix increment/decrement may not have eval or arguments operand in strict mode',
201 StrictReservedWord: 'Use of future reserved word in strict mode'
202 };
203
204 // See also tools/generate-unicode-regex.py.
205 Regex = {
206 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]'),
207 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]')
208 };
209
210 // Ensure the condition is true, otherwise throw an error.
211 // This is only to have a better contract semantic, i.e. another safety net
212 // to catch a logic error. The condition shall be fulfilled in normal case.
213 // Do NOT use this to enforce a certain condition on any user input.
214
215 function assert(condition, message) {
216 /* istanbul ignore if */
217 if (!condition) {
218 throw new Error('ASSERT: ' + message);
219 }
220 }
221
222 function isDecimalDigit(ch) {
223 return (ch >= 48 && ch <= 57); // 0..9
224 }
225
226 function isHexDigit(ch) {
227 return '0123456789abcdefABCDEF'.indexOf(ch) >= 0;
228 }
229
230 function isOctalDigit(ch) {
231 return '01234567'.indexOf(ch) >= 0;
232 }
233
234
235 // 7.2 White Space
236
237 function isWhiteSpace(ch) {
238 return (ch === 0x20) || (ch === 0x09) || (ch === 0x0B) || (ch === 0x0C) || (ch === 0xA0) ||
239 (ch >= 0x1680 && [0x1680, 0x180E, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202F, 0x205F, 0x3000, 0xFEFF].indexOf(ch) >= 0);
240 }
241
242 // 7.3 Line Terminators
243
244 function isLineTerminator(ch) {
245 return (ch === 0x0A) || (ch === 0x0D) || (ch === 0x2028) || (ch === 0x2029);
246 }
247
248 // 7.6 Identifier Names and Identifiers
249
250 function isIdentifierStart(ch) {
251 return (ch == 0x40) || (ch === 0x24) || (ch === 0x5F) || // $ (dollar) and _ (underscore)
252 (ch >= 0x41 && ch <= 0x5A) || // A..Z
253 (ch >= 0x61 && ch <= 0x7A) || // a..z
254 (ch === 0x5C) || // \ (backslash)
255 ((ch >= 0x80) && Regex.NonAsciiIdentifierStart.test(String.fromCharCode(ch)));
256 }
257
258 function isIdentifierPart(ch) {
259 return (ch === 0x24) || (ch === 0x5F) || // $ (dollar) and _ (underscore)
260 (ch >= 0x41 && ch <= 0x5A) || // A..Z
261 (ch >= 0x61 && ch <= 0x7A) || // a..z
262 (ch >= 0x30 && ch <= 0x39) || // 0..9
263 (ch === 0x5C) || // \ (backslash)
264 ((ch >= 0x80) && Regex.NonAsciiIdentifierPart.test(String.fromCharCode(ch)));
265 }
266
267 // 7.6.1.2 Future Reserved Words
268
269 function isFutureReservedWord(id) {
270 switch (id) {
271 case 'class':
272 case 'enum':
273 case 'export':
274 case 'extends':
275 case 'import':
276 case 'super':
277 return true;
278 default:
279 return false;
280 }
281 }
282
283 function isStrictModeReservedWord(id) {
284 switch (id) {
285 case 'implements':
286 case 'interface':
287 case 'package':
288 case 'private':
289 case 'protected':
290 case 'public':
291 case 'static':
292 case 'yield':
293 case 'let':
294 return true;
295 default:
296 return false;
297 }
298 }
299
300 function isRestrictedWord(id) {
301 return id === 'eval' || id === 'arguments';
302 }
303
304 // 7.6.1.1 Keywords
305
306 function isKeyword(id) {
307 if (strict && isStrictModeReservedWord(id)) {
308 return true;
309 }
310
311 // 'const' is specialized as Keyword in V8.
312 // 'yield' and 'let' are for compatiblity with SpiderMonkey and ES.next.
313 // Some others are from future reserved words.
314
315 switch (id.length) {
316 case 2:
317 return (id === 'if') || (id === 'in') || (id === 'do');
318 case 3:
319 return (id === 'var') || (id === 'for') || (id === 'new') ||
320 (id === 'try') || (id === 'let');
321 case 4:
322 return (id === 'this') || (id === 'else') || (id === 'case') ||
323 (id === 'void') || (id === 'with') || (id === 'enum');
324 case 5:
325 return (id === 'while') || (id === 'break') || (id === 'catch') ||
326 (id === 'throw') || (id === 'const') || (id === 'yield') ||
327 (id === 'class') || (id === 'super');
328 case 6:
329 return (id === 'return') || (id === 'typeof') || (id === 'delete') ||
330 (id === 'switch') || (id === 'export') || (id === 'import');
331 case 7:
332 return (id === 'default') || (id === 'finally') || (id === 'extends');
333 case 8:
334 return (id === 'function') || (id === 'continue') || (id === 'debugger');
335 case 10:
336 return (id === 'instanceof');
337 default:
338 return false;
339 }
340 }
341
342 // 7.4 Comments
343
344 function addComment(type, value, start, end, loc) {
345 var comment, attacher;
346
347 assert(typeof start === 'number', 'Comment must have valid position');
348
349 // Because the way the actual token is scanned, often the comments
350 // (if any) are skipped twice during the lexical analysis.
351 // Thus, we need to skip adding a comment if the comment array already
352 // handled it.
353 if (state.lastCommentStart >= start) {
354 return;
355 }
356 state.lastCommentStart = start;
357
358 comment = {
359 type: type,
360 value: value
361 };
362 if (extra.range) {
363 comment.range = [start, end];
364 }
365 if (extra.loc) {
366 comment.loc = loc;
367 }
368 extra.comments.push(comment);
369 if (extra.attachComment) {
370 extra.leadingComments.push(comment);
371 extra.trailingComments.push(comment);
372 }
373 }
374
375 function skipSingleLineComment(offset) {
376 var start, loc, ch, comment;
377
378 start = index - offset;
379 loc = {
380 start: {
381 line: lineNumber,
382 column: index - lineStart - offset
383 }
384 };
385
386 while (index < length) {
387 ch = source.charCodeAt(index);
388 ++index;
389 if (isLineTerminator(ch)) {
390 if (extra.comments) {
391 comment = source.slice(start + offset, index - 1);
392 loc.end = {
393 line: lineNumber,
394 column: index - lineStart - 1
395 };
396 addComment('Line', comment, start, index - 1, loc);
397 }
398 if (ch === 13 && source.charCodeAt(index) === 10) {
399 ++index;
400 }
401 ++lineNumber;
402 lineStart = index;
403 return;
404 }
405 }
406
407 if (extra.comments) {
408 comment = source.slice(start + offset, index);
409 loc.end = {
410 line: lineNumber,
411 column: index - lineStart
412 };
413 addComment('Line', comment, start, index, loc);
414 }
415 }
416
417 function skipMultiLineComment() {
418 var start, loc, ch, comment;
419
420 if (extra.comments) {
421 start = index - 2;
422 loc = {
423 start: {
424 line: lineNumber,
425 column: index - lineStart - 2
426 }
427 };
428 }
429
430 while (index < length) {
431 ch = source.charCodeAt(index);
432 if (isLineTerminator(ch)) {
433 if (ch === 0x0D && source.charCodeAt(index + 1) === 0x0A) {
434 ++index;
435 }
436 ++lineNumber;
437 ++index;
438 lineStart = index;
439 if (index >= length) {
440 throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
441 }
442 } else if (ch === 0x2A) {
443 // Block comment ends with '*/'.
444 if (source.charCodeAt(index + 1) === 0x2F) {
445 ++index;
446 ++index;
447 if (extra.comments) {
448 comment = source.slice(start + 2, index - 2);
449 loc.end = {
450 line: lineNumber,
451 column: index - lineStart
452 };
453 addComment('Block', comment, start, index, loc);
454 }
455 return;
456 }
457 ++index;
458 } else {
459 ++index;
460 }
461 }
462
463 throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
464 }
465
466 function skipComment() {
467 var ch, start;
468
469 start = (index === 0);
470 while (index < length) {
471 ch = source.charCodeAt(index);
472
473 if (isWhiteSpace(ch)) {
474 ++index;
475 } else if (isLineTerminator(ch)) {
476 ++index;
477 if (ch === 0x0D && source.charCodeAt(index) === 0x0A) {
478 ++index;
479 }
480 ++lineNumber;
481 lineStart = index;
482 start = true;
483 } else if (ch === 0x2F) { // U+002F is '/'
484 ch = source.charCodeAt(index + 1);
485 if (ch === 0x2F) {
486 ++index;
487 ++index;
488 skipSingleLineComment(2);
489 start = true;
490 } else if (ch === 0x2A) { // U+002A is '*'
491 ++index;
492 ++index;
493 skipMultiLineComment();
494 } else {
495 break;
496 }
497 } else if (start && ch === 0x2D) { // U+002D is '-'
498 // U+003E is '>'
499 if ((source.charCodeAt(index + 1) === 0x2D) && (source.charCodeAt(index + 2) === 0x3E)) {
500 // '-->' is a single-line comment
501 index += 3;
502 skipSingleLineComment(3);
503 } else {
504 break;
505 }
506 } else if (ch === 0x3C) { // U+003C is '<'
507 if (source.slice(index + 1, index + 4) === '!--') {
508 ++index; // `<`
509 ++index; // `!`
510 ++index; // `-`
511 ++index; // `-`
512 skipSingleLineComment(4);
513 } else {
514 break;
515 }
516 } else {
517 break;
518 }
519 }
520 }
521
522 function scanHexEscape(prefix) {
523 var i, len, ch, code = 0;
524
525 len = (prefix === 'u') ? 4 : 2;
526 for (i = 0; i < len; ++i) {
527 if (index < length && isHexDigit(source[index])) {
528 ch = source[index++];
529 code = code * 16 + '0123456789abcdef'.indexOf(ch.toLowerCase());
530 } else {
531 return '';
532 }
533 }
534 return String.fromCharCode(code);
535 }
536
537 function getEscapedIdentifier() {
538 var ch, id;
539
540 ch = source.charCodeAt(index++);
541 id = String.fromCharCode(ch);
542
543 // '\u' (U+005C, U+0075) denotes an escaped character.
544 if (ch === 0x5C) {
545 if (source.charCodeAt(index) !== 0x75) {
546 throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
547 }
548 ++index;
549 ch = scanHexEscape('u');
550 if (!ch || ch === '\\' || !isIdentifierStart(ch.charCodeAt(0))) {
551 throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
552 }
553 id = ch;
554 }
555
556 while (index < length) {
557 ch = source.charCodeAt(index);
558 if (!isIdentifierPart(ch)) {
559 break;
560 }
561 ++index;
562 id += String.fromCharCode(ch);
563
564 // '\u' (U+005C, U+0075) denotes an escaped character.
565 if (ch === 0x5C) {
566 id = id.substr(0, id.length - 1);
567 if (source.charCodeAt(index) !== 0x75) {
568 throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
569 }
570 ++index;
571 ch = scanHexEscape('u');
572 if (!ch || ch === '\\' || !isIdentifierPart(ch.charCodeAt(0))) {
573 throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
574 }
575 id += ch;
576 }
577 }
578
579 return id;
580 }
581
582 function getIdentifier() {
583 var start, ch;
584
585 start = index++;
586 while (index < length) {
587 ch = source.charCodeAt(index);
588 if (ch === 0x5C) {
589 // Blackslash (U+005C) marks Unicode escape sequence.
590 index = start;
591 return getEscapedIdentifier();
592 }
593 if (isIdentifierPart(ch)) {
594 ++index;
595 } else {
596 break;
597 }
598 }
599
600 return source.slice(start, index);
601 }
602
603 function scanIdentifier() {
604 var start, id, type;
605
606 start = index;
607
608 // Backslash (U+005C) starts an escaped character.
609 id = (source.charCodeAt(index) === 0x5C) ? getEscapedIdentifier() : getIdentifier();
610
611 // There is no keyword or literal with only one character.
612 // Thus, it must be an identifier.
613 if (id.length === 1) {
614 type = Token.Identifier;
615 } else if (isKeyword(id)) {
616 type = Token.Keyword;
617 } else if (id === 'null') {
618 type = Token.NullLiteral;
619 } else if (id === 'true' || id === 'false') {
620 type = Token.BooleanLiteral;
621 } else {
622 type = Token.Identifier;
623 }
624
625 return {
626 type: type,
627 value: id,
628 lineNumber: lineNumber,
629 lineStart: lineStart,
630 start: start,
631 end: index
632 };
633 }
634
635
636 // 7.7 Punctuators
637
638 function scanPunctuator() {
639 var start = index,
640 code = source.charCodeAt(index),
641 code2,
642 ch1 = source[index],
643 ch2,
644 ch3,
645 ch4;
646
647 switch (code) {
648
649 // Check for most common single-character punctuators.
650 case 0x2E: // . dot
651 case 0x28: // ( open bracket
652 case 0x29: // ) close bracket
653 case 0x3B: // ; semicolon
654 case 0x2C: // , comma
655 case 0x7B: // { open curly brace
656 case 0x7D: // } close curly brace
657 case 0x5B: // [
658 case 0x5D: // ]
659 case 0x3A: // :
660 case 0x3F: // ?
661 case 0x7E: // ~
662 ++index;
663 if (extra.tokenize) {
664 if (code === 0x28) {
665 extra.openParenToken = extra.tokens.length;
666 } else if (code === 0x7B) {
667 extra.openCurlyToken = extra.tokens.length;
668 }
669 }
670 return {
671 type: Token.Punctuator,
672 value: String.fromCharCode(code),
673 lineNumber: lineNumber,
674 lineStart: lineStart,
675 start: start,
676 end: index
677 };
678
679 default:
680 code2 = source.charCodeAt(index + 1);
681
682 // '=' (U+003D) marks an assignment or comparison operator.
683 if (code2 === 0x3D) {
684 switch (code) {
685 case 0x2B: // +
686 case 0x2D: // -
687 case 0x2F: // /
688 case 0x3C: // <
689 case 0x3E: // >
690 case 0x5E: // ^
691 case 0x7C: // |
692 case 0x25: // %
693 case 0x26: // &
694 case 0x2A: // *
695 index += 2;
696 return {
697 type: Token.Punctuator,
698 value: String.fromCharCode(code) + String.fromCharCode(code2),
699 lineNumber: lineNumber,
700 lineStart: lineStart,
701 start: start,
702 end: index
703 };
704
705 case 0x21: // !
706 case 0x3D: // =
707 index += 2;
708
709 // !== and ===
710 if (source.charCodeAt(index) === 0x3D) {
711 ++index;
712 }
713 return {
714 type: Token.Punctuator,
715 value: source.slice(start, index),
716 lineNumber: lineNumber,
717 lineStart: lineStart,
718 start: start,
719 end: index
720 };
721 }
722 }
723 }
724
725 // 4-character punctuator: >>>=
726
727 ch4 = source.substr(index, 4);
728
729 if (ch4 === '>>>=') {
730 index += 4;
731 return {
732 type: Token.Punctuator,
733 value: ch4,
734 lineNumber: lineNumber,
735 lineStart: lineStart,
736 start: start,
737 end: index
738 };
739 }
740
741 // 3-character punctuators: === !== >>> <<= >>=
742
743 ch3 = ch4.substr(0, 3);
744
745 if (ch3 === '>>>' || ch3 === '<<=' || ch3 === '>>=') {
746 index += 3;
747 return {
748 type: Token.Punctuator,
749 value: ch3,
750 lineNumber: lineNumber,
751 lineStart: lineStart,
752 start: start,
753 end: index
754 };
755 }
756
757 // Other 2-character punctuators: ++ -- << >> && ||
758 ch2 = ch3.substr(0, 2);
759
760 if ((ch1 === ch2[1] && ('+-<>&|'.indexOf(ch1) >= 0)) || ch2 === '=>') {
761 index += 2;
762 return {
763 type: Token.Punctuator,
764 value: ch2,
765 lineNumber: lineNumber,
766 lineStart: lineStart,
767 start: start,
768 end: index
769 };
770 }
771
772 // 1-character punctuators: < > = ! + - * % & | ^ /
773 if ('<>=!+-*%&|^/'.indexOf(ch1) >= 0) {
774 ++index;
775 return {
776 type: Token.Punctuator,
777 value: ch1,
778 lineNumber: lineNumber,
779 lineStart: lineStart,
780 start: start,
781 end: index
782 };
783 }
784
785 throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
786 }
787
788 // 7.8.3 Numeric Literals
789
790 function scanHexLiteral(start) {
791 var number = '';
792
793 while (index < length) {
794 if (!isHexDigit(source[index])) {
795 break;
796 }
797 number += source[index++];
798 }
799
800 if (number.length === 0) {
801 throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
802 }
803
804 if (isIdentifierStart(source.charCodeAt(index))) {
805 throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
806 }
807
808 return {
809 type: Token.NumericLiteral,
810 value: parseInt('0x' + number, 16),
811 lineNumber: lineNumber,
812 lineStart: lineStart,
813 start: start,
814 end: index
815 };
816 }
817
818 function scanOctalLiteral(start) {
819 var number = '0' + source[index++];
820 while (index < length) {
821 if (!isOctalDigit(source[index])) {
822 break;
823 }
824 number += source[index++];
825 }
826
827 if (isIdentifierStart(source.charCodeAt(index)) || isDecimalDigit(source.charCodeAt(index))) {
828 throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
829 }
830
831 return {
832 type: Token.NumericLiteral,
833 value: parseInt(number, 8),
834 octal: true,
835 lineNumber: lineNumber,
836 lineStart: lineStart,
837 start: start,
838 end: index
839 };
840 }
841
842 function scanNumericLiteral() {
843 var number, start, ch;
844
845 ch = source[index];
846 assert(isDecimalDigit(ch.charCodeAt(0)) || (ch === '.'),
847 'Numeric literal must start with a decimal digit or a decimal point');
848
849 start = index;
850 number = '';
851 if (ch !== '.') {
852 number = source[index++];
853 ch = source[index];
854
855 // Hex number starts with '0x'.
856 // Octal number starts with '0'.
857 if (number === '0') {
858 if (ch === 'x' || ch === 'X') {
859 ++index;
860 return scanHexLiteral(start);
861 }
862 if (isOctalDigit(ch)) {
863 return scanOctalLiteral(start);
864 }
865
866 // decimal number starts with '0' such as '09' is illegal.
867 if (ch && isDecimalDigit(ch.charCodeAt(0))) {
868 throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
869 }
870 }
871
872 while (isDecimalDigit(source.charCodeAt(index))) {
873 number += source[index++];
874 }
875 ch = source[index];
876 }
877
878 if (ch === '.') {
879 number += source[index++];
880 while (isDecimalDigit(source.charCodeAt(index))) {
881 number += source[index++];
882 }
883 ch = source[index];
884 }
885
886 if (ch === 'e' || ch === 'E') {
887 number += source[index++];
888
889 ch = source[index];
890 if (ch === '+' || ch === '-') {
891 number += source[index++];
892 }
893 if (isDecimalDigit(source.charCodeAt(index))) {
894 while (isDecimalDigit(source.charCodeAt(index))) {
895 number += source[index++];
896 }
897 } else {
898 throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
899 }
900 }
901
902 if (isIdentifierStart(source.charCodeAt(index))) {
903 throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
904 }
905
906 return {
907 type: Token.NumericLiteral,
908 value: parseFloat(number),
909 lineNumber: lineNumber,
910 lineStart: lineStart,
911 start: start,
912 end: index
913 };
914 }
915
916 // 7.8.4 String Literals
917
918 function scanStringLiteral() {
919 var str = '', quote, start, ch, code, unescaped, restore, octal = false, startLineNumber, startLineStart;
920 startLineNumber = lineNumber;
921 startLineStart = lineStart;
922
923 quote = source[index];
924 assert((quote === '\'' || quote === '"'),
925 'String literal must starts with a quote');
926
927 start = index;
928 ++index;
929
930 while (index < length) {
931 ch = source[index++];
932
933 if (ch === quote) {
934 quote = '';
935 break;
936 } else if (ch === '\\') {
937 ch = source[index++];
938 if (!ch || !isLineTerminator(ch.charCodeAt(0))) {
939 switch (ch) {
940 case 'u':
941 case 'x':
942 restore = index;
943 unescaped = scanHexEscape(ch);
944 if (unescaped) {
945 str += unescaped;
946 } else {
947 index = restore;
948 str += ch;
949 }
950 break;
951 case 'n':
952 str += '\n';
953 break;
954 case 'r':
955 str += '\r';
956 break;
957 case 't':
958 str += '\t';
959 break;
960 case 'b':
961 str += '\b';
962 break;
963 case 'f':
964 str += '\f';
965 break;
966 case 'v':
967 str += '\x0B';
968 break;
969
970 default:
971 if (isOctalDigit(ch)) {
972 code = '01234567'.indexOf(ch);
973
974 // \0 is not octal escape sequence
975 if (code !== 0) {
976 octal = true;
977 }
978
979 if (index < length && isOctalDigit(source[index])) {
980 octal = true;
981 code = code * 8 + '01234567'.indexOf(source[index++]);
982
983 // 3 digits are only allowed when string starts
984 // with 0, 1, 2, 3
985 if ('0123'.indexOf(ch) >= 0 &&
986 index < length &&
987 isOctalDigit(source[index])) {
988 code = code * 8 + '01234567'.indexOf(source[index++]);
989 }
990 }
991 str += String.fromCharCode(code);
992 } else {
993 str += ch;
994 }
995 break;
996 }
997 } else {
998 ++lineNumber;
999 if (ch === '\r' && source[index] === '\n') {
1000 ++index;
1001 }
1002 lineStart = index;
1003 }
1004 } else if (isLineTerminator(ch.charCodeAt(0))) {
1005 break;
1006 } else {
1007 str += ch;
1008 }
1009 }
1010
1011 if (quote !== '') {
1012 throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
1013 }
1014
1015 return {
1016 type: Token.StringLiteral,
1017 value: str,
1018 octal: octal,
1019 startLineNumber: startLineNumber,
1020 startLineStart: startLineStart,
1021 lineNumber: lineNumber,
1022 lineStart: lineStart,
1023 start: start,
1024 end: index
1025 };
1026 }
1027
1028 function testRegExp(pattern, flags) {
1029 var value;
1030 try {
1031 value = new RegExp(pattern, flags);
1032 } catch (e) {
1033 throwError({}, Messages.InvalidRegExp);
1034 }
1035 return value;
1036 }
1037
1038 function scanRegExpBody() {
1039 var ch, str, classMarker, terminated, body;
1040
1041 ch = source[index];
1042 assert(ch === '/', 'Regular expression literal must start with a slash');
1043 str = source[index++];
1044
1045 classMarker = false;
1046 terminated = false;
1047 while (index < length) {
1048 ch = source[index++];
1049 str += ch;
1050 if (ch === '\\') {
1051 ch = source[index++];
1052 // ECMA-262 7.8.5
1053 if (isLineTerminator(ch.charCodeAt(0))) {
1054 throwError({}, Messages.UnterminatedRegExp);
1055 }
1056 str += ch;
1057 } else if (isLineTerminator(ch.charCodeAt(0))) {
1058 throwError({}, Messages.UnterminatedRegExp);
1059 } else if (classMarker) {
1060 if (ch === ']') {
1061 classMarker = false;
1062 }
1063 } else {
1064 if (ch === '/') {
1065 terminated = true;
1066 break;
1067 } else if (ch === '[') {
1068 classMarker = true;
1069 }
1070 }
1071 }
1072
1073 if (!terminated) {
1074 throwError({}, Messages.UnterminatedRegExp);
1075 }
1076
1077 // Exclude leading and trailing slash.
1078 body = str.substr(1, str.length - 2);
1079 return {
1080 value: body,
1081 literal: str
1082 };
1083 }
1084
1085 function scanRegExpFlags() {
1086 var ch, str, flags, restore;
1087
1088 str = '';
1089 flags = '';
1090 while (index < length) {
1091 ch = source[index];
1092 if (!isIdentifierPart(ch.charCodeAt(0))) {
1093 break;
1094 }
1095
1096 ++index;
1097 if (ch === '\\' && index < length) {
1098 ch = source[index];
1099 if (ch === 'u') {
1100 ++index;
1101 restore = index;
1102 ch = scanHexEscape('u');
1103 if (ch) {
1104 flags += ch;
1105 for (str += '\\u'; restore < index; ++restore) {
1106 str += source[restore];
1107 }
1108 } else {
1109 index = restore;
1110 flags += 'u';
1111 str += '\\u';
1112 }
1113 throwErrorTolerant({}, Messages.UnexpectedToken, 'ILLEGAL');
1114 } else {
1115 str += '\\';
1116 throwErrorTolerant({}, Messages.UnexpectedToken, 'ILLEGAL');
1117 }
1118 } else {
1119 flags += ch;
1120 str += ch;
1121 }
1122 }
1123
1124 return {
1125 value: flags,
1126 literal: str
1127 };
1128 }
1129
1130 function scanRegExp() {
1131 var start, body, flags, pattern, value;
1132
1133 lookahead = null;
1134 skipComment();
1135 start = index;
1136
1137 body = scanRegExpBody();
1138 flags = scanRegExpFlags();
1139 value = testRegExp(body.value, flags.value);
1140
1141 if (extra.tokenize) {
1142 return {
1143 type: Token.RegularExpression,
1144 value: value,
1145 lineNumber: lineNumber,
1146 lineStart: lineStart,
1147 start: start,
1148 end: index
1149 };
1150 }
1151
1152 return {
1153 literal: body.literal + flags.literal,
1154 value: value,
1155 start: start,
1156 end: index
1157 };
1158 }
1159
1160 function collectRegex() {
1161 var pos, loc, regex, token;
1162
1163 skipComment();
1164
1165 pos = index;
1166 loc = {
1167 start: {
1168 line: lineNumber,
1169 column: index - lineStart
1170 }
1171 };
1172
1173 regex = scanRegExp();
1174 loc.end = {
1175 line: lineNumber,
1176 column: index - lineStart
1177 };
1178
1179 /* istanbul ignore next */
1180 if (!extra.tokenize) {
1181 // Pop the previous token, which is likely '/' or '/='
1182 if (extra.tokens.length > 0) {
1183 token = extra.tokens[extra.tokens.length - 1];
1184 if (token.range[0] === pos && token.type === 'Punctuator') {
1185 if (token.value === '/' || token.value === '/=') {
1186 extra.tokens.pop();
1187 }
1188 }
1189 }
1190
1191 extra.tokens.push({
1192 type: 'RegularExpression',
1193 value: regex.literal,
1194 range: [pos, index],
1195 loc: loc
1196 });
1197 }
1198
1199 return regex;
1200 }
1201
1202 function isIdentifierName(token) {
1203 return token.type === Token.Identifier ||
1204 token.type === Token.Keyword ||
1205 token.type === Token.BooleanLiteral ||
1206 token.type === Token.NullLiteral;
1207 }
1208
1209 function advanceSlash() {
1210 var prevToken,
1211 checkToken;
1212 // Using the following algorithm:
1213 // https://github.com/mozilla/sweet.js/wiki/design
1214 prevToken = extra.tokens[extra.tokens.length - 1];
1215 if (!prevToken) {
1216 // Nothing before that: it cannot be a division.
1217 return collectRegex();
1218 }
1219 if (prevToken.type === 'Punctuator') {
1220 if (prevToken.value === ']') {
1221 return scanPunctuator();
1222 }
1223 if (prevToken.value === ')') {
1224 checkToken = extra.tokens[extra.openParenToken - 1];
1225 if (checkToken &&
1226 checkToken.type === 'Keyword' &&
1227 (checkToken.value === 'if' ||
1228 checkToken.value === 'while' ||
1229 checkToken.value === 'for' ||
1230 checkToken.value === 'with')) {
1231 return collectRegex();
1232 }
1233 return scanPunctuator();
1234 }
1235 if (prevToken.value === '}') {
1236 // Dividing a function by anything makes little sense,
1237 // but we have to check for that.
1238 if (extra.tokens[extra.openCurlyToken - 3] &&
1239 extra.tokens[extra.openCurlyToken - 3].type === 'Keyword') {
1240 // Anonymous function.
1241 checkToken = extra.tokens[extra.openCurlyToken - 4];
1242 if (!checkToken) {
1243 return scanPunctuator();
1244 }
1245 } else if (extra.tokens[extra.openCurlyToken - 4] &&
1246 extra.tokens[extra.openCurlyToken - 4].type === 'Keyword') {
1247 // Named function.
1248 checkToken = extra.tokens[extra.openCurlyToken - 5];
1249 if (!checkToken) {
1250 return collectRegex();
1251 }
1252 } else {
1253 return scanPunctuator();
1254 }
1255 // checkToken determines whether the function is
1256 // a declaration or an expression.
1257 if (FnExprTokens.indexOf(checkToken.value) >= 0) {
1258 // It is an expression.
1259 return scanPunctuator();
1260 }
1261 // It is a declaration.
1262 return collectRegex();
1263 }
1264 return collectRegex();
1265 }
1266 if (prevToken.type === 'Keyword') {
1267 return collectRegex();
1268 }
1269 return scanPunctuator();
1270 }
1271
1272 function advance() {
1273 var ch;
1274
1275 skipComment();
1276
1277 if (index >= length) {
1278 return {
1279 type: Token.EOF,
1280 lineNumber: lineNumber,
1281 lineStart: lineStart,
1282 start: index,
1283 end: index
1284 };
1285 }
1286
1287 ch = source.charCodeAt(index);
1288
1289 if (isIdentifierStart(ch)) {
1290 return scanIdentifier();
1291 }
1292
1293 // Very common: ( and ) and ;
1294 if (ch === 0x28 || ch === 0x29 || ch === 0x3B) {
1295 return scanPunctuator();
1296 }
1297
1298 // String literal starts with single quote (U+0027) or double quote (U+0022).
1299 if (ch === 0x27 || ch === 0x22) {
1300 return scanStringLiteral();
1301 }
1302
1303
1304 // Dot (.) U+002E can also start a floating-point number, hence the need
1305 // to check the next character.
1306 if (ch === 0x2E) {
1307 if (isDecimalDigit(source.charCodeAt(index + 1))) {
1308 return scanNumericLiteral();
1309 }
1310 return scanPunctuator();
1311 }
1312
1313 if (isDecimalDigit(ch)) {
1314 return scanNumericLiteral();
1315 }
1316
1317 // Slash (/) U+002F can also start a regex.
1318 if (extra.tokenize && ch === 0x2F) {
1319 return advanceSlash();
1320 }
1321
1322 return scanPunctuator();
1323 }
1324
1325 function collectToken() {
1326 var loc, token, range, value;
1327
1328 skipComment();
1329 loc = {
1330 start: {
1331 line: lineNumber,
1332 column: index - lineStart
1333 }
1334 };
1335
1336 token = advance();
1337 loc.end = {
1338 line: lineNumber,
1339 column: index - lineStart
1340 };
1341
1342 if (token.type !== Token.EOF) {
1343 value = source.slice(token.start, token.end);
1344 extra.tokens.push({
1345 type: TokenName[token.type],
1346 value: value,
1347 range: [token.start, token.end],
1348 loc: loc
1349 });
1350 }
1351
1352 return token;
1353 }
1354
1355 function lex() {
1356 var token;
1357
1358 token = lookahead;
1359 index = token.end;
1360 lineNumber = token.lineNumber;
1361 lineStart = token.lineStart;
1362
1363 lookahead = (typeof extra.tokens !== 'undefined') ? collectToken() : advance();
1364
1365 index = token.end;
1366 lineNumber = token.lineNumber;
1367 lineStart = token.lineStart;
1368
1369 return token;
1370 }
1371
1372 function peek() {
1373 var pos, line, start;
1374
1375 pos = index;
1376 line = lineNumber;
1377 start = lineStart;
1378 lookahead = (typeof extra.tokens !== 'undefined') ? collectToken() : advance();
1379 index = pos;
1380 lineNumber = line;
1381 lineStart = start;
1382 }
1383
1384 function Position(line, column) {
1385 this.line = line;
1386 this.column = column;
1387 }
1388
1389 function SourceLocation(startLine, startColumn, line, column) {
1390 this.start = new Position(startLine, startColumn);
1391 this.end = new Position(line, column);
1392 }
1393
1394 SyntaxTreeDelegate = {
1395
1396 name: 'SyntaxTree',
1397
1398 processComment: function (node) {
1399 var lastChild, trailingComments;
1400
1401 if (node.type === Syntax.Program) {
1402 if (node.body.length > 0) {
1403 return;
1404 }
1405 }
1406
1407 if (extra.trailingComments.length > 0) {
1408 if (extra.trailingComments[0].range[0] >= node.range[1]) {
1409 trailingComments = extra.trailingComments;
1410 extra.trailingComments = [];
1411 } else {
1412 extra.trailingComments.length = 0;
1413 }
1414 } else {
1415 if (extra.bottomRightStack.length > 0 &&
1416 extra.bottomRightStack[extra.bottomRightStack.length - 1].trailingComments &&
1417 extra.bottomRightStack[extra.bottomRightStack.length - 1].trailingComments[0].range[0] >= node.range[1]) {
1418 trailingComments = extra.bottomRightStack[extra.bottomRightStack.length - 1].trailingComments;
1419 delete extra.bottomRightStack[extra.bottomRightStack.length - 1].trailingComments;
1420 }
1421 }
1422
1423 // Eating the stack.
1424 while (extra.bottomRightStack.length > 0 && extra.bottomRightStack[extra.bottomRightStack.length - 1].range[0] >= node.range[0]) {
1425 lastChild = extra.bottomRightStack.pop();
1426 }
1427
1428 if (lastChild) {
1429 if (lastChild.leadingComments && lastChild.leadingComments[lastChild.leadingComments.length - 1].range[1] <= node.range[0]) {
1430 node.leadingComments = lastChild.leadingComments;
1431 delete lastChild.leadingComments;
1432 }
1433 } else if (extra.leadingComments.length > 0 && extra.leadingComments[extra.leadingComments.length - 1].range[1] <= node.range[0]) {
1434 node.leadingComments = extra.leadingComments;
1435 extra.leadingComments = [];
1436 }
1437
1438
1439 if (trailingComments) {
1440 node.trailingComments = trailingComments;
1441 }
1442
1443 extra.bottomRightStack.push(node);
1444 },
1445
1446 markEnd: function (node, startToken) {
1447 if (extra.range) {
1448 node.range = [startToken.start, index];
1449 }
1450 if (extra.loc) {
1451 node.loc = new SourceLocation(
1452 startToken.startLineNumber === undefined ? startToken.lineNumber : startToken.startLineNumber,
1453 startToken.start - (startToken.startLineStart === undefined ? startToken.lineStart : startToken.startLineStart),
1454 lineNumber,
1455 index - lineStart
1456 );
1457 this.postProcess(node);
1458 }
1459
1460 if (extra.attachComment) {
1461 this.processComment(node);
1462 }
1463 return node;
1464 },
1465
1466 postProcess: function (node) {
1467 if (extra.source) {
1468 node.loc.source = extra.source;
1469 }
1470 return node;
1471 },
1472
1473 createArrayExpression: function (elements) {
1474 return {
1475 type: Syntax.ArrayExpression,
1476 elements: elements
1477 };
1478 },
1479
1480 createAssignmentExpression: function (operator, left, right) {
1481 return {
1482 type: Syntax.AssignmentExpression,
1483 operator: operator,
1484 left: left,
1485 right: right
1486 };
1487 },
1488
1489 createBinaryExpression: function (operator, left, right) {
1490 var type = (operator === '||' || operator === '&&') ? Syntax.LogicalExpression :
1491 Syntax.BinaryExpression;
1492 return {
1493 type: type,
1494 operator: operator,
1495 left: left,
1496 right: right
1497 };
1498 },
1499
1500 createBlockStatement: function (body) {
1501 return {
1502 type: Syntax.BlockStatement,
1503 body: body
1504 };
1505 },
1506
1507 createBreakStatement: function (label) {
1508 return {
1509 type: Syntax.BreakStatement,
1510 label: label
1511 };
1512 },
1513
1514 createCallExpression: function (callee, args) {
1515 return {
1516 type: Syntax.CallExpression,
1517 callee: callee,
1518 'arguments': args
1519 };
1520 },
1521
1522 createCatchClause: function (param, body) {
1523 return {
1524 type: Syntax.CatchClause,
1525 param: param,
1526 body: body
1527 };
1528 },
1529
1530 createConditionalExpression: function (test, consequent, alternate) {
1531 return {
1532 type: Syntax.ConditionalExpression,
1533 test: test,
1534 consequent: consequent,
1535 alternate: alternate
1536 };
1537 },
1538
1539 createContinueStatement: function (label) {
1540 return {
1541 type: Syntax.ContinueStatement,
1542 label: label
1543 };
1544 },
1545
1546 createDebuggerStatement: function () {
1547 return {
1548 type: Syntax.DebuggerStatement
1549 };
1550 },
1551
1552 createDoWhileStatement: function (body, test) {
1553 return {
1554 type: Syntax.DoWhileStatement,
1555 body: body,
1556 test: test
1557 };
1558 },
1559
1560 createEmptyStatement: function () {
1561 return {
1562 type: Syntax.EmptyStatement
1563 };
1564 },
1565
1566 createExpressionStatement: function (expression) {
1567 return {
1568 type: Syntax.ExpressionStatement,
1569 expression: expression
1570 };
1571 },
1572
1573 createForStatement: function (init, test, update, body) {
1574 return {
1575 type: Syntax.ForStatement,
1576 init: init,
1577 test: test,
1578 update: update,
1579 body: body
1580 };
1581 },
1582
1583 createForInStatement: function (left, right, body) {
1584 return {
1585 type: Syntax.ForInStatement,
1586 left: left,
1587 right: right,
1588 body: body,
1589 each: false
1590 };
1591 },
1592
1593 createFunctionDeclaration: function (id, params, defaults, body) {
1594 return {
1595 type: Syntax.FunctionDeclaration,
1596 id: id,
1597 params: params,
1598 defaults: defaults,
1599 body: body,
1600 rest: null,
1601 generator: false,
1602 expression: false
1603 };
1604 },
1605
1606 createFunctionExpression: function (id, params, defaults, body) {
1607 return {
1608 type: Syntax.FunctionExpression,
1609 id: id,
1610 params: params,
1611 defaults: defaults,
1612 body: body,
1613 rest: null,
1614 generator: false,
1615 expression: false
1616 };
1617 },
1618
1619 createIdentifier: function (name) {
1620 return {
1621 type: Syntax.Identifier,
1622 name: name
1623 };
1624 },
1625
1626 createIfStatement: function (test, consequent, alternate) {
1627 return {
1628 type: Syntax.IfStatement,
1629 test: test,
1630 consequent: consequent,
1631 alternate: alternate
1632 };
1633 },
1634
1635 createLabeledStatement: function (label, body) {
1636 return {
1637 type: Syntax.LabeledStatement,
1638 label: label,
1639 body: body
1640 };
1641 },
1642
1643 createLiteral: function (token) {
1644 return {
1645 type: Syntax.Literal,
1646 value: token.value,
1647 raw: source.slice(token.start, token.end)
1648 };
1649 },
1650
1651 createMemberExpression: function (accessor, object, property) {
1652 return {
1653 type: Syntax.MemberExpression,
1654 computed: accessor === '[',
1655 object: object,
1656 property: property
1657 };
1658 },
1659
1660 createNewExpression: function (callee, args) {
1661 return {
1662 type: Syntax.NewExpression,
1663 callee: callee,
1664 'arguments': args
1665 };
1666 },
1667
1668 createObjectExpression: function (properties) {
1669 return {
1670 type: Syntax.ObjectExpression,
1671 properties: properties
1672 };
1673 },
1674
1675 createPostfixExpression: function (operator, argument) {
1676 return {
1677 type: Syntax.UpdateExpression,
1678 operator: operator,
1679 argument: argument,
1680 prefix: false
1681 };
1682 },
1683
1684 createProgram: function (body) {
1685 return {
1686 type: Syntax.Program,
1687 body: body
1688 };
1689 },
1690
1691 createProperty: function (kind, key, value) {
1692 return {
1693 type: Syntax.Property,
1694 key: key,
1695 value: value,
1696 kind: kind
1697 };
1698 },
1699
1700 createReturnStatement: function (argument) {
1701 return {
1702 type: Syntax.ReturnStatement,
1703 argument: argument
1704 };
1705 },
1706
1707 createSequenceExpression: function (expressions) {
1708 return {
1709 type: Syntax.SequenceExpression,
1710 expressions: expressions
1711 };
1712 },
1713
1714 createSwitchCase: function (test, consequent) {
1715 return {
1716 type: Syntax.SwitchCase,
1717 test: test,
1718 consequent: consequent
1719 };
1720 },
1721
1722 createSwitchStatement: function (discriminant, cases) {
1723 return {
1724 type: Syntax.SwitchStatement,
1725 discriminant: discriminant,
1726 cases: cases
1727 };
1728 },
1729
1730 createThisExpression: function () {
1731 return {
1732 type: Syntax.ThisExpression
1733 };
1734 },
1735
1736 createThrowStatement: function (argument) {
1737 return {
1738 type: Syntax.ThrowStatement,
1739 argument: argument
1740 };
1741 },
1742
1743 createTryStatement: function (block, guardedHandlers, handlers, finalizer) {
1744 return {
1745 type: Syntax.TryStatement,
1746 block: block,
1747 guardedHandlers: guardedHandlers,
1748 handlers: handlers,
1749 finalizer: finalizer
1750 };
1751 },
1752
1753 createUnaryExpression: function (operator, argument) {
1754 if (operator === '++' || operator === '--') {
1755 return {
1756 type: Syntax.UpdateExpression,
1757 operator: operator,
1758 argument: argument,
1759 prefix: true
1760 };
1761 }
1762 return {
1763 type: Syntax.UnaryExpression,
1764 operator: operator,
1765 argument: argument,
1766 prefix: true
1767 };
1768 },
1769
1770 createVariableDeclaration: function (declarations, kind) {
1771 return {
1772 type: Syntax.VariableDeclaration,
1773 declarations: declarations,
1774 kind: kind
1775 };
1776 },
1777
1778 createVariableDeclarator: function (id, init) {
1779 return {
1780 type: Syntax.VariableDeclarator,
1781 id: id,
1782 init: init
1783 };
1784 },
1785
1786 createWhileStatement: function (test, body) {
1787 return {
1788 type: Syntax.WhileStatement,
1789 test: test,
1790 body: body
1791 };
1792 },
1793
1794 createWithStatement: function (object, body) {
1795 return {
1796 type: Syntax.WithStatement,
1797 object: object,
1798 body: body
1799 };
1800 }
1801 };
1802
1803 // Return true if there is a line terminator before the next token.
1804
1805 function peekLineTerminator() {
1806 var pos, line, start, found;
1807
1808 pos = index;
1809 line = lineNumber;
1810 start = lineStart;
1811 skipComment();
1812 found = lineNumber !== line;
1813 index = pos;
1814 lineNumber = line;
1815 lineStart = start;
1816
1817 return found;
1818 }
1819
1820 // Throw an exception
1821
1822 function throwError(token, messageFormat) {
1823 var error,
1824 args = Array.prototype.slice.call(arguments, 2),
1825 msg = messageFormat.replace(
1826 /%(\d)/g,
1827 function (whole, index) {
1828 assert(index < args.length, 'Message reference must be in range');
1829 return args[index];
1830 }
1831 );
1832
1833 if (typeof token.lineNumber === 'number') {
1834 error = new Error('Line ' + token.lineNumber + ': ' + msg);
1835 error.index = token.start;
1836 error.lineNumber = token.lineNumber;
1837 error.column = token.start - lineStart + 1;
1838 } else {
1839 error = new Error('Line ' + lineNumber + ': ' + msg);
1840 error.index = index;
1841 error.lineNumber = lineNumber;
1842 error.column = index - lineStart + 1;
1843 }
1844
1845 error.description = msg;
1846 throw error;
1847 }
1848
1849 function throwErrorTolerant() {
1850 try {
1851 throwError.apply(null, arguments);
1852 } catch (e) {
1853 if (extra.errors) {
1854 extra.errors.push(e);
1855 } else {
1856 throw e;
1857 }
1858 }
1859 }
1860
1861
1862 // Throw an exception because of the token.
1863
1864 function throwUnexpected(token) {
1865 if (token.type === Token.EOF) {
1866 throwError(token, Messages.UnexpectedEOS);
1867 }
1868
1869 if (token.type === Token.NumericLiteral) {
1870 throwError(token, Messages.UnexpectedNumber);
1871 }
1872
1873 if (token.type === Token.StringLiteral) {
1874 throwError(token, Messages.UnexpectedString);
1875 }
1876
1877 if (token.type === Token.Identifier) {
1878 throwError(token, Messages.UnexpectedIdentifier);
1879 }
1880
1881 if (token.type === Token.Keyword) {
1882 if (isFutureReservedWord(token.value)) {
1883 throwError(token, Messages.UnexpectedReserved);
1884 } else if (strict && isStrictModeReservedWord(token.value)) {
1885 throwErrorTolerant(token, Messages.StrictReservedWord);
1886 return;
1887 }
1888 throwError(token, Messages.UnexpectedToken, token.value);
1889 }
1890
1891 // BooleanLiteral, NullLiteral, or Punctuator.
1892 throwError(token, Messages.UnexpectedToken, token.value);
1893 }
1894
1895 // Expect the next token to match the specified punctuator.
1896 // If not, an exception will be thrown.
1897
1898 function expect(value) {
1899 var token = lex();
1900 if (token.type !== Token.Punctuator || token.value !== value) {
1901 throwUnexpected(token);
1902 }
1903 }
1904
1905 // Expect the next token to match the specified keyword.
1906 // If not, an exception will be thrown.
1907
1908 function expectKeyword(keyword) {
1909 var token = lex();
1910 if (token.type !== Token.Keyword || token.value !== keyword) {
1911 throwUnexpected(token);
1912 }
1913 }
1914
1915 // Return true if the next token matches the specified punctuator.
1916
1917 function match(value) {
1918 return lookahead.type === Token.Punctuator && lookahead.value === value;
1919 }
1920
1921 // Return true if the next token matches the specified keyword
1922
1923 function matchKeyword(keyword) {
1924 return lookahead.type === Token.Keyword && lookahead.value === keyword;
1925 }
1926
1927 // Return true if the next token is an assignment operator
1928
1929 function matchAssign() {
1930 var op;
1931
1932 if (lookahead.type !== Token.Punctuator) {
1933 return false;
1934 }
1935 op = lookahead.value;
1936 return op === '=' ||
1937 op === '*=' ||
1938 op === '/=' ||
1939 op === '%=' ||
1940 op === '+=' ||
1941 op === '-=' ||
1942 op === '<<=' ||
1943 op === '>>=' ||
1944 op === '>>>=' ||
1945 op === '&=' ||
1946 op === '^=' ||
1947 op === '|=';
1948 }
1949
1950 function consumeSemicolon() {
1951 var line;
1952
1953 // Catch the very common case first: immediately a semicolon (U+003B).
1954 if (source.charCodeAt(index) === 0x3B || match(';')) {
1955 lex();
1956 return;
1957 }
1958
1959 line = lineNumber;
1960 skipComment();
1961 if (lineNumber !== line) {
1962 return;
1963 }
1964
1965 if (lookahead.type !== Token.EOF && !match('}')) {
1966 throwUnexpected(lookahead);
1967 }
1968 }
1969
1970 // Return true if provided expression is LeftHandSideExpression
1971
1972 function isLeftHandSide(expr) {
1973 return expr.type === Syntax.Identifier || expr.type === Syntax.MemberExpression;
1974 }
1975
1976 // 11.1.4 Array Initialiser
1977
1978 function parseArrayInitialiser() {
1979 var elements = [], startToken;
1980
1981 startToken = lookahead;
1982 expect('[');
1983
1984 while (!match(']')) {
1985 if (match(',')) {
1986 lex();
1987 elements.push(null);
1988 } else {
1989 elements.push(parseAssignmentExpression());
1990
1991 if (!match(']')) {
1992 expect(',');
1993 }
1994 }
1995 }
1996
1997 lex();
1998
1999 return delegate.markEnd(delegate.createArrayExpression(elements), startToken);
2000 }
2001
2002 // 11.1.5 Object Initialiser
2003
2004 function parsePropertyFunction(param, first) {
2005 var previousStrict, body, startToken;
2006
2007 previousStrict = strict;
2008 startToken = lookahead;
2009 body = parseFunctionSourceElements();
2010 if (first && strict && isRestrictedWord(param[0].name)) {
2011 throwErrorTolerant(first, Messages.StrictParamName);
2012 }
2013 strict = previousStrict;
2014 return delegate.markEnd(delegate.createFunctionExpression(null, param, [], body), startToken);
2015 }
2016
2017 function parseObjectPropertyKey() {
2018 var token, startToken;
2019
2020 startToken = lookahead;
2021 token = lex();
2022
2023 // Note: This function is called only from parseObjectProperty(), where
2024 // EOF and Punctuator tokens are already filtered out.
2025
2026 if (token.type === Token.StringLiteral || token.type === Token.NumericLiteral) {
2027 if (strict && token.octal) {
2028 throwErrorTolerant(token, Messages.StrictOctalLiteral);
2029 }
2030 return delegate.markEnd(delegate.createLiteral(token), startToken);
2031 }
2032
2033 return delegate.markEnd(delegate.createIdentifier(token.value), startToken);
2034 }
2035
2036 function parseObjectProperty() {
2037 var token, key, id, value, param, startToken;
2038
2039 token = lookahead;
2040 startToken = lookahead;
2041
2042 if (token.type === Token.Identifier) {
2043
2044 id = parseObjectPropertyKey();
2045
2046 // Property Assignment: Getter and Setter.
2047
2048 if (token.value === 'get' && !match(':')) {
2049 key = parseObjectPropertyKey();
2050 expect('(');
2051 expect(')');
2052 value = parsePropertyFunction([]);
2053 return delegate.markEnd(delegate.createProperty('get', key, value), startToken);
2054 }
2055 if (token.value === 'set' && !match(':')) {
2056 key = parseObjectPropertyKey();
2057 expect('(');
2058 token = lookahead;
2059 if (token.type !== Token.Identifier) {
2060 expect(')');
2061 throwErrorTolerant(token, Messages.UnexpectedToken, token.value);
2062 value = parsePropertyFunction([]);
2063 } else {
2064 param = [ parseVariableIdentifier() ];
2065 expect(')');
2066 value = parsePropertyFunction(param, token);
2067 }
2068 return delegate.markEnd(delegate.createProperty('set', key, value), startToken);
2069 }
2070 expect(':');
2071 value = parseAssignmentExpression();
2072 return delegate.markEnd(delegate.createProperty('init', id, value), startToken);
2073 }
2074 if (token.type === Token.EOF || token.type === Token.Punctuator) {
2075 throwUnexpected(token);
2076 } else {
2077 key = parseObjectPropertyKey();
2078 expect(':');
2079 value = parseAssignmentExpression();
2080 return delegate.markEnd(delegate.createProperty('init', key, value), startToken);
2081 }
2082 }
2083
2084 function parseObjectInitialiser() {
2085 var properties = [], property, name, key, kind, map = {}, toString = String, startToken;
2086
2087 startToken = lookahead;
2088
2089 expect('{');
2090
2091 while (!match('}')) {
2092 property = parseObjectProperty();
2093
2094 if (property.key.type === Syntax.Identifier) {
2095 name = property.key.name;
2096 } else {
2097 name = toString(property.key.value);
2098 }
2099 kind = (property.kind === 'init') ? PropertyKind.Data : (property.kind === 'get') ? PropertyKind.Get : PropertyKind.Set;
2100
2101 key = '$' + name;
2102 if (Object.prototype.hasOwnProperty.call(map, key)) {
2103 if (map[key] === PropertyKind.Data) {
2104 if (strict && kind === PropertyKind.Data) {
2105 throwErrorTolerant({}, Messages.StrictDuplicateProperty);
2106 } else if (kind !== PropertyKind.Data) {
2107 throwErrorTolerant({}, Messages.AccessorDataProperty);
2108 }
2109 } else {
2110 if (kind === PropertyKind.Data) {
2111 throwErrorTolerant({}, Messages.AccessorDataProperty);
2112 } else if (map[key] & kind) {
2113 throwErrorTolerant({}, Messages.AccessorGetSet);
2114 }
2115 }
2116 map[key] |= kind;
2117 } else {
2118 map[key] = kind;
2119 }
2120
2121 properties.push(property);
2122
2123 if (!match('}')) {
2124 expect(',');
2125 }
2126 }
2127
2128 expect('}');
2129
2130 return delegate.markEnd(delegate.createObjectExpression(properties), startToken);
2131 }
2132
2133 // 11.1.6 The Grouping Operator
2134
2135 function parseGroupExpression() {
2136 var expr;
2137
2138 expect('(');
2139
2140 expr = parseExpression();
2141
2142 expect(')');
2143
2144 return expr;
2145 }
2146
2147
2148 // 11.1 Primary Expressions
2149
2150 function parsePrimaryExpression() {
2151 var type, token, expr, startToken;
2152
2153 if (match('(')) {
2154 return parseGroupExpression();
2155 }
2156
2157 if (match('[')) {
2158 return parseArrayInitialiser();
2159 }
2160
2161 if (match('{')) {
2162 return parseObjectInitialiser();
2163 }
2164
2165 type = lookahead.type;
2166 startToken = lookahead;
2167
2168 if (type === Token.Identifier) {
2169 expr = delegate.createIdentifier(lex().value);
2170 } else if (type === Token.StringLiteral || type === Token.NumericLiteral) {
2171 if (strict && lookahead.octal) {
2172 throwErrorTolerant(lookahead, Messages.StrictOctalLiteral);
2173 }
2174 expr = delegate.createLiteral(lex());
2175 } else if (type === Token.Keyword) {
2176 if (matchKeyword('function')) {
2177 return parseFunctionExpression();
2178 }
2179 if (matchKeyword('this')) {
2180 lex();
2181 expr = delegate.createThisExpression();
2182 } else {
2183 throwUnexpected(lex());
2184 }
2185 } else if (type === Token.BooleanLiteral) {
2186 token = lex();
2187 token.value = (token.value === 'true');
2188 expr = delegate.createLiteral(token);
2189 } else if (type === Token.NullLiteral) {
2190 token = lex();
2191 token.value = null;
2192 expr = delegate.createLiteral(token);
2193 } else if (match('/') || match('/=')) {
2194 if (typeof extra.tokens !== 'undefined') {
2195 expr = delegate.createLiteral(collectRegex());
2196 } else {
2197 expr = delegate.createLiteral(scanRegExp());
2198 }
2199 peek();
2200 } else {
2201 throwUnexpected(lex());
2202 }
2203
2204 return delegate.markEnd(expr, startToken);
2205 }
2206
2207 // 11.2 Left-Hand-Side Expressions
2208
2209 function parseArguments() {
2210 var args = [];
2211
2212 expect('(');
2213
2214 if (!match(')')) {
2215 while (index < length) {
2216 args.push(parseAssignmentExpression());
2217 if (match(')')) {
2218 break;
2219 }
2220 expect(',');
2221 }
2222 }
2223
2224 expect(')');
2225
2226 return args;
2227 }
2228
2229 function parseNonComputedProperty() {
2230 var token, startToken;
2231
2232 startToken = lookahead;
2233 token = lex();
2234
2235 if (!isIdentifierName(token)) {
2236 throwUnexpected(token);
2237 }
2238
2239 return delegate.markEnd(delegate.createIdentifier(token.value), startToken);
2240 }
2241
2242 function parseNonComputedMember() {
2243 expect('.');
2244
2245 return parseNonComputedProperty();
2246 }
2247
2248 function parseComputedMember() {
2249 var expr;
2250
2251 expect('[');
2252
2253 expr = parseExpression();
2254
2255 expect(']');
2256
2257 return expr;
2258 }
2259
2260 function parseNewExpression() {
2261 var callee, args, startToken;
2262
2263 startToken = lookahead;
2264 expectKeyword('new');
2265 callee = parseLeftHandSideExpression();
2266 args = match('(') ? parseArguments() : [];
2267
2268 return delegate.markEnd(delegate.createNewExpression(callee, args), startToken);
2269 }
2270
2271 function parseLeftHandSideExpressionAllowCall() {
2272 var previousAllowIn, expr, args, property, startToken;
2273
2274 startToken = lookahead;
2275
2276 previousAllowIn = state.allowIn;
2277 state.allowIn = true;
2278 expr = matchKeyword('new') ? parseNewExpression() : parsePrimaryExpression();
2279 state.allowIn = previousAllowIn;
2280
2281 for (;;) {
2282 if (match('.')) {
2283 property = parseNonComputedMember();
2284 expr = delegate.createMemberExpression('.', expr, property);
2285 } else if (match('(')) {
2286 args = parseArguments();
2287 expr = delegate.createCallExpression(expr, args);
2288 } else if (match('[')) {
2289 property = parseComputedMember();
2290 expr = delegate.createMemberExpression('[', expr, property);
2291 } else {
2292 break;
2293 }
2294 delegate.markEnd(expr, startToken);
2295 }
2296
2297 return expr;
2298 }
2299
2300 function parseLeftHandSideExpression() {
2301 var previousAllowIn, expr, property, startToken;
2302
2303 startToken = lookahead;
2304
2305 previousAllowIn = state.allowIn;
2306 expr = matchKeyword('new') ? parseNewExpression() : parsePrimaryExpression();
2307 state.allowIn = previousAllowIn;
2308
2309 while (match('.') || match('[')) {
2310 if (match('[')) {
2311 property = parseComputedMember();
2312 expr = delegate.createMemberExpression('[', expr, property);
2313 } else {
2314 property = parseNonComputedMember();
2315 expr = delegate.createMemberExpression('.', expr, property);
2316 }
2317 delegate.markEnd(expr, startToken);
2318 }
2319
2320 return expr;
2321 }
2322
2323 // 11.3 Postfix Expressions
2324
2325 function parsePostfixExpression() {
2326 var expr, token, startToken = lookahead;
2327
2328 expr = parseLeftHandSideExpressionAllowCall();
2329
2330 if (lookahead.type === Token.Punctuator) {
2331 if ((match('++') || match('--')) && !peekLineTerminator()) {
2332 // 11.3.1, 11.3.2
2333 if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {
2334 throwErrorTolerant({}, Messages.StrictLHSPostfix);
2335 }
2336
2337 if (!isLeftHandSide(expr)) {
2338 throwErrorTolerant({}, Messages.InvalidLHSInAssignment);
2339 }
2340
2341 token = lex();
2342 expr = delegate.markEnd(delegate.createPostfixExpression(token.value, expr), startToken);
2343 }
2344 }
2345
2346 return expr;
2347 }
2348
2349 // 11.4 Unary Operators
2350
2351 function parseUnaryExpression() {
2352 var token, expr, startToken;
2353
2354 if (lookahead.type !== Token.Punctuator && lookahead.type !== Token.Keyword) {
2355 expr = parsePostfixExpression();
2356 } else if (match('++') || match('--')) {
2357 startToken = lookahead;
2358 token = lex();
2359 expr = parseUnaryExpression();
2360 // 11.4.4, 11.4.5
2361 if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {
2362 throwErrorTolerant({}, Messages.StrictLHSPrefix);
2363 }
2364
2365 if (!isLeftHandSide(expr)) {
2366 throwErrorTolerant({}, Messages.InvalidLHSInAssignment);
2367 }
2368
2369 expr = delegate.createUnaryExpression(token.value, expr);
2370 expr = delegate.markEnd(expr, startToken);
2371 } else if (match('+') || match('-') || match('~') || match('!')) {
2372 startToken = lookahead;
2373 token = lex();
2374 expr = parseUnaryExpression();
2375 expr = delegate.createUnaryExpression(token.value, expr);
2376 expr = delegate.markEnd(expr, startToken);
2377 } else if (matchKeyword('delete') || matchKeyword('void') || matchKeyword('typeof')) {
2378 startToken = lookahead;
2379 token = lex();
2380 expr = parseUnaryExpression();
2381 expr = delegate.createUnaryExpression(token.value, expr);
2382 expr = delegate.markEnd(expr, startToken);
2383 if (strict && expr.operator === 'delete' && expr.argument.type === Syntax.Identifier) {
2384 throwErrorTolerant({}, Messages.StrictDelete);
2385 }
2386 } else {
2387 expr = parsePostfixExpression();
2388 }
2389
2390 return expr;
2391 }
2392
2393 function binaryPrecedence(token, allowIn) {
2394 var prec = 0;
2395
2396 if (token.type !== Token.Punctuator && token.type !== Token.Keyword) {
2397 return 0;
2398 }
2399
2400 switch (token.value) {
2401 case '||':
2402 prec = 1;
2403 break;
2404
2405 case '&&':
2406 prec = 2;
2407 break;
2408
2409 case '|':
2410 prec = 3;
2411 break;
2412
2413 case '^':
2414 prec = 4;
2415 break;
2416
2417 case '&':
2418 prec = 5;
2419 break;
2420
2421 case '==':
2422 case '!=':
2423 case '===':
2424 case '!==':
2425 prec = 6;
2426 break;
2427
2428 case '<':
2429 case '>':
2430 case '<=':
2431 case '>=':
2432 case 'instanceof':
2433 prec = 7;
2434 break;
2435
2436 case 'in':
2437 prec = allowIn ? 7 : 0;
2438 break;
2439
2440 case '<<':
2441 case '>>':
2442 case '>>>':
2443 prec = 8;
2444 break;
2445
2446 case '+':
2447 case '-':
2448 prec = 9;
2449 break;
2450
2451 case '*':
2452 case '/':
2453 case '%':
2454 prec = 11;
2455 break;
2456
2457 default:
2458 break;
2459 }
2460
2461 return prec;
2462 }
2463
2464 // 11.5 Multiplicative Operators
2465 // 11.6 Additive Operators
2466 // 11.7 Bitwise Shift Operators
2467 // 11.8 Relational Operators
2468 // 11.9 Equality Operators
2469 // 11.10 Binary Bitwise Operators
2470 // 11.11 Binary Logical Operators
2471
2472 function parseBinaryExpression() {
2473 var marker, markers, expr, token, prec, stack, right, operator, left, i;
2474
2475 marker = lookahead;
2476 left = parseUnaryExpression();
2477
2478 token = lookahead;
2479 prec = binaryPrecedence(token, state.allowIn);
2480 if (prec === 0) {
2481 return left;
2482 }
2483 token.prec = prec;
2484 lex();
2485
2486 markers = [marker, lookahead];
2487 right = parseUnaryExpression();
2488
2489 stack = [left, token, right];
2490
2491 while ((prec = binaryPrecedence(lookahead, state.allowIn)) > 0) {
2492
2493 // Reduce: make a binary expression from the three topmost entries.
2494 while ((stack.length > 2) && (prec <= stack[stack.length - 2].prec)) {
2495 right = stack.pop();
2496 operator = stack.pop().value;
2497 left = stack.pop();
2498 expr = delegate.createBinaryExpression(operator, left, right);
2499 markers.pop();
2500 marker = markers[markers.length - 1];
2501 delegate.markEnd(expr, marker);
2502 stack.push(expr);
2503 }
2504
2505 // Shift.
2506 token = lex();
2507 token.prec = prec;
2508 stack.push(token);
2509 markers.push(lookahead);
2510 expr = parseUnaryExpression();
2511 stack.push(expr);
2512 }
2513
2514 // Final reduce to clean-up the stack.
2515 i = stack.length - 1;
2516 expr = stack[i];
2517 markers.pop();
2518 while (i > 1) {
2519 expr = delegate.createBinaryExpression(stack[i - 1].value, stack[i - 2], expr);
2520 i -= 2;
2521 marker = markers.pop();
2522 delegate.markEnd(expr, marker);
2523 }
2524
2525 return expr;
2526 }
2527
2528
2529 // 11.12 Conditional Operator
2530
2531 function parseConditionalExpression() {
2532 var expr, previousAllowIn, consequent, alternate, startToken;
2533
2534 startToken = lookahead;
2535
2536 expr = parseBinaryExpression();
2537
2538 if (match('?')) {
2539 lex();
2540 previousAllowIn = state.allowIn;
2541 state.allowIn = true;
2542 consequent = parseAssignmentExpression();
2543 state.allowIn = previousAllowIn;
2544 expect(':');
2545 alternate = parseAssignmentExpression();
2546
2547 expr = delegate.createConditionalExpression(expr, consequent, alternate);
2548 delegate.markEnd(expr, startToken);
2549 }
2550
2551 return expr;
2552 }
2553
2554 // 11.13 Assignment Operators
2555
2556 function parseAssignmentExpression() {
2557 var token, left, right, node, startToken;
2558
2559 token = lookahead;
2560 startToken = lookahead;
2561
2562 node = left = parseConditionalExpression();
2563
2564 if (matchAssign()) {
2565 // LeftHandSideExpression
2566 if (!isLeftHandSide(left)) {
2567 throwErrorTolerant({}, Messages.InvalidLHSInAssignment);
2568 }
2569
2570 // 11.13.1
2571 if (strict && left.type === Syntax.Identifier && isRestrictedWord(left.name)) {
2572 throwErrorTolerant(token, Messages.StrictLHSAssignment);
2573 }
2574
2575 token = lex();
2576 right = parseAssignmentExpression();
2577 node = delegate.markEnd(delegate.createAssignmentExpression(token.value, left, right), startToken);
2578 }
2579
2580 return node;
2581 }
2582
2583 // 11.14 Comma Operator
2584
2585 function parseExpression() {
2586 var expr, startToken = lookahead;
2587
2588 expr = parseAssignmentExpression();
2589
2590 if (match(',')) {
2591 expr = delegate.createSequenceExpression([ expr ]);
2592
2593 while (index < length) {
2594 if (!match(',')) {
2595 break;
2596 }
2597 lex();
2598 expr.expressions.push(parseAssignmentExpression());
2599 }
2600
2601 delegate.markEnd(expr, startToken);
2602 }
2603
2604 return expr;
2605 }
2606
2607 // 12.1 Block
2608
2609 function parseStatementList() {
2610 var list = [],
2611 statement;
2612
2613 while (index < length) {
2614 if (match('}')) {
2615 break;
2616 }
2617 statement = parseSourceElement();
2618 if (typeof statement === 'undefined') {
2619 break;
2620 }
2621 list.push(statement);
2622 }
2623
2624 return list;
2625 }
2626
2627 function parseBlock() {
2628 var block, startToken;
2629
2630 startToken = lookahead;
2631 expect('{');
2632
2633 block = parseStatementList();
2634
2635 expect('}');
2636
2637 return delegate.markEnd(delegate.createBlockStatement(block), startToken);
2638 }
2639
2640 // 12.2 Variable Statement
2641
2642 function parseVariableIdentifier() {
2643 var token, startToken;
2644
2645 startToken = lookahead;
2646 token = lex();
2647
2648 if (token.type !== Token.Identifier) {
2649 throwUnexpected(token);
2650 }
2651
2652 return delegate.markEnd(delegate.createIdentifier(token.value), startToken);
2653 }
2654
2655 function parseVariableDeclaration(kind) {
2656 var init = null, id, startToken;
2657
2658 startToken = lookahead;
2659 id = parseVariableIdentifier();
2660
2661 // 12.2.1
2662 if (strict && isRestrictedWord(id.name)) {
2663 throwErrorTolerant({}, Messages.StrictVarName);
2664 }
2665
2666 if (kind === 'const') {
2667 expect('=');
2668 init = parseAssignmentExpression();
2669 } else if (match('=')) {
2670 lex();
2671 init = parseAssignmentExpression();
2672 }
2673
2674 return delegate.markEnd(delegate.createVariableDeclarator(id, init), startToken);
2675 }
2676
2677 function parseVariableDeclarationList(kind) {
2678 var list = [];
2679
2680 do {
2681 list.push(parseVariableDeclaration(kind));
2682 if (!match(',')) {
2683 break;
2684 }
2685 lex();
2686 } while (index < length);
2687
2688 return list;
2689 }
2690
2691 function parseVariableStatement() {
2692 var declarations;
2693
2694 expectKeyword('var');
2695
2696 declarations = parseVariableDeclarationList();
2697
2698 consumeSemicolon();
2699
2700 return delegate.createVariableDeclaration(declarations, 'var');
2701 }
2702
2703 // kind may be `const` or `let`
2704 // Both are experimental and not in the specification yet.
2705 // see http://wiki.ecmascript.org/doku.php?id=harmony:const
2706 // and http://wiki.ecmascript.org/doku.php?id=harmony:let
2707 function parseConstLetDeclaration(kind) {
2708 var declarations, startToken;
2709
2710 startToken = lookahead;
2711
2712 expectKeyword(kind);
2713
2714 declarations = parseVariableDeclarationList(kind);
2715
2716 consumeSemicolon();
2717
2718 return delegate.markEnd(delegate.createVariableDeclaration(declarations, kind), startToken);
2719 }
2720
2721 // 12.3 Empty Statement
2722
2723 function parseEmptyStatement() {
2724 expect(';');
2725 return delegate.createEmptyStatement();
2726 }
2727
2728 // 12.4 Expression Statement
2729
2730 function parseExpressionStatement() {
2731 var expr = parseExpression();
2732 consumeSemicolon();
2733 return delegate.createExpressionStatement(expr);
2734 }
2735
2736 // 12.5 If statement
2737
2738 function parseIfStatement() {
2739 var test, consequent, alternate;
2740
2741 expectKeyword('if');
2742
2743 expect('(');
2744
2745 test = parseExpression();
2746
2747 expect(')');
2748
2749 consequent = parseStatement();
2750
2751 if (matchKeyword('else')) {
2752 lex();
2753 alternate = parseStatement();
2754 } else {
2755 alternate = null;
2756 }
2757
2758 return delegate.createIfStatement(test, consequent, alternate);
2759 }
2760
2761 // 12.6 Iteration Statements
2762
2763 function parseDoWhileStatement() {
2764 var body, test, oldInIteration;
2765
2766 expectKeyword('do');
2767
2768 oldInIteration = state.inIteration;
2769 state.inIteration = true;
2770
2771 body = parseStatement();
2772
2773 state.inIteration = oldInIteration;
2774
2775 expectKeyword('while');
2776
2777 expect('(');
2778
2779 test = parseExpression();
2780
2781 expect(')');
2782
2783 if (match(';')) {
2784 lex();
2785 }
2786
2787 return delegate.createDoWhileStatement(body, test);
2788 }
2789
2790 function parseWhileStatement() {
2791 var test, body, oldInIteration;
2792
2793 expectKeyword('while');
2794
2795 expect('(');
2796
2797 test = parseExpression();
2798
2799 expect(')');
2800
2801 oldInIteration = state.inIteration;
2802 state.inIteration = true;
2803
2804 body = parseStatement();
2805
2806 state.inIteration = oldInIteration;
2807
2808 return delegate.createWhileStatement(test, body);
2809 }
2810
2811 function parseForVariableDeclaration() {
2812 var token, declarations, startToken;
2813
2814 startToken = lookahead;
2815 token = lex();
2816 declarations = parseVariableDeclarationList();
2817
2818 return delegate.markEnd(delegate.createVariableDeclaration(declarations, token.value), startToken);
2819 }
2820
2821 function parseForStatement() {
2822 var init, test, update, left, right, body, oldInIteration;
2823
2824 init = test = update = null;
2825
2826 expectKeyword('for');
2827
2828 expect('(');
2829
2830 if (match(';')) {
2831 lex();
2832 } else {
2833 if (matchKeyword('var') || matchKeyword('let')) {
2834 state.allowIn = false;
2835 init = parseForVariableDeclaration();
2836 state.allowIn = true;
2837
2838 if (init.declarations.length === 1 && matchKeyword('in')) {
2839 lex();
2840 left = init;
2841 right = parseExpression();
2842 init = null;
2843 }
2844 } else {
2845 state.allowIn = false;
2846 init = parseExpression();
2847 state.allowIn = true;
2848
2849 if (matchKeyword('in')) {
2850 // LeftHandSideExpression
2851 if (!isLeftHandSide(init)) {
2852 throwErrorTolerant({}, Messages.InvalidLHSInForIn);
2853 }
2854
2855 lex();
2856 left = init;
2857 right = parseExpression();
2858 init = null;
2859 }
2860 }
2861
2862 if (typeof left === 'undefined') {
2863 expect(';');
2864 }
2865 }
2866
2867 if (typeof left === 'undefined') {
2868
2869 if (!match(';')) {
2870 test = parseExpression();
2871 }
2872 expect(';');
2873
2874 if (!match(')')) {
2875 update = parseExpression();
2876 }
2877 }
2878
2879 expect(')');
2880
2881 oldInIteration = state.inIteration;
2882 state.inIteration = true;
2883
2884 body = parseStatement();
2885
2886 state.inIteration = oldInIteration;
2887
2888 return (typeof left === 'undefined') ?
2889 delegate.createForStatement(init, test, update, body) :
2890 delegate.createForInStatement(left, right, body);
2891 }
2892
2893 // 12.7 The continue statement
2894
2895 function parseContinueStatement() {
2896 var label = null, key;
2897
2898 expectKeyword('continue');
2899
2900 // Optimize the most common form: 'continue;'.
2901 if (source.charCodeAt(index) === 0x3B) {
2902 lex();
2903
2904 if (!state.inIteration) {
2905 throwError({}, Messages.IllegalContinue);
2906 }
2907
2908 return delegate.createContinueStatement(null);
2909 }
2910
2911 if (peekLineTerminator()) {
2912 if (!state.inIteration) {
2913 throwError({}, Messages.IllegalContinue);
2914 }
2915
2916 return delegate.createContinueStatement(null);
2917 }
2918
2919 if (lookahead.type === Token.Identifier) {
2920 label = parseVariableIdentifier();
2921
2922 key = '$' + label.name;
2923 if (!Object.prototype.hasOwnProperty.call(state.labelSet, key)) {
2924 throwError({}, Messages.UnknownLabel, label.name);
2925 }
2926 }
2927
2928 consumeSemicolon();
2929
2930 if (label === null && !state.inIteration) {
2931 throwError({}, Messages.IllegalContinue);
2932 }
2933
2934 return delegate.createContinueStatement(label);
2935 }
2936
2937 // 12.8 The break statement
2938
2939 function parseBreakStatement() {
2940 var label = null, key;
2941
2942 expectKeyword('break');
2943
2944 // Catch the very common case first: immediately a semicolon (U+003B).
2945 if (source.charCodeAt(index) === 0x3B) {
2946 lex();
2947
2948 if (!(state.inIteration || state.inSwitch)) {
2949 throwError({}, Messages.IllegalBreak);
2950 }
2951
2952 return delegate.createBreakStatement(null);
2953 }
2954
2955 if (peekLineTerminator()) {
2956 if (!(state.inIteration || state.inSwitch)) {
2957 throwError({}, Messages.IllegalBreak);
2958 }
2959
2960 return delegate.createBreakStatement(null);
2961 }
2962
2963 if (lookahead.type === Token.Identifier) {
2964 label = parseVariableIdentifier();
2965
2966 key = '$' + label.name;
2967 if (!Object.prototype.hasOwnProperty.call(state.labelSet, key)) {
2968 throwError({}, Messages.UnknownLabel, label.name);
2969 }
2970 }
2971
2972 consumeSemicolon();
2973
2974 if (label === null && !(state.inIteration || state.inSwitch)) {
2975 throwError({}, Messages.IllegalBreak);
2976 }
2977
2978 return delegate.createBreakStatement(label);
2979 }
2980
2981 // 12.9 The return statement
2982
2983 function parseReturnStatement() {
2984 var argument = null;
2985
2986 expectKeyword('return');
2987
2988 if (!state.inFunctionBody) {
2989 throwErrorTolerant({}, Messages.IllegalReturn);
2990 }
2991
2992 // 'return' followed by a space and an identifier is very common.
2993 if (source.charCodeAt(index) === 0x20) {
2994 if (isIdentifierStart(source.charCodeAt(index + 1))) {
2995 argument = parseExpression();
2996 consumeSemicolon();
2997 return delegate.createReturnStatement(argument);
2998 }
2999 }
3000
3001 if (peekLineTerminator()) {
3002 return delegate.createReturnStatement(null);
3003 }
3004
3005 if (!match(';')) {
3006 if (!match('}') && lookahead.type !== Token.EOF) {
3007 argument = parseExpression();
3008 }
3009 }
3010
3011 consumeSemicolon();
3012
3013 return delegate.createReturnStatement(argument);
3014 }
3015
3016 // 12.10 The with statement
3017
3018 function parseWithStatement() {
3019 var object, body;
3020
3021 if (strict) {
3022 // TODO(ikarienator): Should we update the test cases instead?
3023 skipComment();
3024 throwErrorTolerant({}, Messages.StrictModeWith);
3025 }
3026
3027 expectKeyword('with');
3028
3029 expect('(');
3030
3031 object = parseExpression();
3032
3033 expect(')');
3034
3035 body = parseStatement();
3036
3037 return delegate.createWithStatement(object, body);
3038 }
3039
3040 // 12.10 The swith statement
3041
3042 function parseSwitchCase() {
3043 var test, consequent = [], statement, startToken;
3044
3045 startToken = lookahead;
3046 if (matchKeyword('default')) {
3047 lex();
3048 test = null;
3049 } else {
3050 expectKeyword('case');
3051 test = parseExpression();
3052 }
3053 expect(':');
3054
3055 while (index < length) {
3056 if (match('}') || matchKeyword('default') || matchKeyword('case')) {
3057 break;
3058 }
3059 statement = parseStatement();
3060 consequent.push(statement);
3061 }
3062
3063 return delegate.markEnd(delegate.createSwitchCase(test, consequent), startToken);
3064 }
3065
3066 function parseSwitchStatement() {
3067 var discriminant, cases, clause, oldInSwitch, defaultFound;
3068
3069 expectKeyword('switch');
3070
3071 expect('(');
3072
3073 discriminant = parseExpression();
3074
3075 expect(')');
3076
3077 expect('{');
3078
3079 cases = [];
3080
3081 if (match('}')) {
3082 lex();
3083 return delegate.createSwitchStatement(discriminant, cases);
3084 }
3085
3086 oldInSwitch = state.inSwitch;
3087 state.inSwitch = true;
3088 defaultFound = false;
3089
3090 while (index < length) {
3091 if (match('}')) {
3092 break;
3093 }
3094 clause = parseSwitchCase();
3095 if (clause.test === null) {
3096 if (defaultFound) {
3097 throwError({}, Messages.MultipleDefaultsInSwitch);
3098 }
3099 defaultFound = true;
3100 }
3101 cases.push(clause);
3102 }
3103
3104 state.inSwitch = oldInSwitch;
3105
3106 expect('}');
3107
3108 return delegate.createSwitchStatement(discriminant, cases);
3109 }
3110
3111 // 12.13 The throw statement
3112
3113 function parseThrowStatement() {
3114 var argument;
3115
3116 expectKeyword('throw');
3117
3118 if (peekLineTerminator()) {
3119 throwError({}, Messages.NewlineAfterThrow);
3120 }
3121
3122 argument = parseExpression();
3123
3124 consumeSemicolon();
3125
3126 return delegate.createThrowStatement(argument);
3127 }
3128
3129 // 12.14 The try statement
3130
3131 function parseCatchClause() {
3132 var param, body, startToken;
3133
3134 startToken = lookahead;
3135 expectKeyword('catch');
3136
3137 expect('(');
3138 if (match(')')) {
3139 throwUnexpected(lookahead);
3140 }
3141
3142 param = parseVariableIdentifier();
3143 // 12.14.1
3144 if (strict && isRestrictedWord(param.name)) {
3145 throwErrorTolerant({}, Messages.StrictCatchVariable);
3146 }
3147
3148 expect(')');
3149 body = parseBlock();
3150 return delegate.markEnd(delegate.createCatchClause(param, body), startToken);
3151 }
3152
3153 function parseTryStatement() {
3154 var block, handlers = [], finalizer = null;
3155
3156 expectKeyword('try');
3157
3158 block = parseBlock();
3159
3160 if (matchKeyword('catch')) {
3161 handlers.push(parseCatchClause());
3162 }
3163
3164 if (matchKeyword('finally')) {
3165 lex();
3166 finalizer = parseBlock();
3167 }
3168
3169 if (handlers.length === 0 && !finalizer) {
3170 throwError({}, Messages.NoCatchOrFinally);
3171 }
3172
3173 return delegate.createTryStatement(block, [], handlers, finalizer);
3174 }
3175
3176 // 12.15 The debugger statement
3177
3178 function parseDebuggerStatement() {
3179 expectKeyword('debugger');
3180
3181 consumeSemicolon();
3182
3183 return delegate.createDebuggerStatement();
3184 }
3185
3186 // 12 Statements
3187
3188 function parseStatement() {
3189 var type = lookahead.type,
3190 expr,
3191 labeledBody,
3192 key,
3193 startToken;
3194
3195 if (type === Token.EOF) {
3196 throwUnexpected(lookahead);
3197 }
3198
3199 if (type === Token.Punctuator && lookahead.value === '{') {
3200 return parseBlock();
3201 }
3202
3203 startToken = lookahead;
3204
3205 if (type === Token.Punctuator) {
3206 switch (lookahead.value) {
3207 case ';':
3208 return delegate.markEnd(parseEmptyStatement(), startToken);
3209 case '(':
3210 return delegate.markEnd(parseExpressionStatement(), startToken);
3211 default:
3212 break;
3213 }
3214 }
3215
3216 if (type === Token.Keyword) {
3217 switch (lookahead.value) {
3218 case 'break':
3219 return delegate.markEnd(parseBreakStatement(), startToken);
3220 case 'continue':
3221 return delegate.markEnd(parseContinueStatement(), startToken);
3222 case 'debugger':
3223 return delegate.markEnd(parseDebuggerStatement(), startToken);
3224 case 'do':
3225 return delegate.markEnd(parseDoWhileStatement(), startToken);
3226 case 'for':
3227 return delegate.markEnd(parseForStatement(), startToken);
3228 case 'function':
3229 return delegate.markEnd(parseFunctionDeclaration(), startToken);
3230 case 'if':
3231 return delegate.markEnd(parseIfStatement(), startToken);
3232 case 'return':
3233 return delegate.markEnd(parseReturnStatement(), startToken);
3234 case 'switch':
3235 return delegate.markEnd(parseSwitchStatement(), startToken);
3236 case 'throw':
3237 return delegate.markEnd(parseThrowStatement(), startToken);
3238 case 'try':
3239 return delegate.markEnd(parseTryStatement(), startToken);
3240 case 'var':
3241 return delegate.markEnd(parseVariableStatement(), startToken);
3242 case 'while':
3243 return delegate.markEnd(parseWhileStatement(), startToken);
3244 case 'with':
3245 return delegate.markEnd(parseWithStatement(), startToken);
3246 default:
3247 break;
3248 }
3249 }
3250
3251 expr = parseExpression();
3252
3253 // 12.12 Labelled Statements
3254 if ((expr.type === Syntax.Identifier) && match(':')) {
3255 lex();
3256
3257 key = '$' + expr.name;
3258 if (Object.prototype.hasOwnProperty.call(state.labelSet, key)) {
3259 throwError({}, Messages.Redeclaration, 'Label', expr.name);
3260 }
3261
3262 state.labelSet[key] = true;
3263 labeledBody = parseStatement();
3264 delete state.labelSet[key];
3265 return delegate.markEnd(delegate.createLabeledStatement(expr, labeledBody), startToken);
3266 }
3267
3268 consumeSemicolon();
3269
3270 return delegate.markEnd(delegate.createExpressionStatement(expr), startToken);
3271 }
3272
3273 // 13 Function Definition
3274
3275 function parseFunctionSourceElements() {
3276 var sourceElement, sourceElements = [], token, directive, firstRestricted,
3277 oldLabelSet, oldInIteration, oldInSwitch, oldInFunctionBody, startToken;
3278
3279 startToken = lookahead;
3280 expect('{');
3281
3282 while (index < length) {
3283 if (lookahead.type !== Token.StringLiteral) {
3284 break;
3285 }
3286 token = lookahead;
3287
3288 sourceElement = parseSourceElement();
3289 sourceElements.push(sourceElement);
3290 if (sourceElement.expression.type !== Syntax.Literal) {
3291 // this is not directive
3292 break;
3293 }
3294 directive = source.slice(token.start + 1, token.end - 1);
3295 if (directive === 'use strict') {
3296 strict = true;
3297 if (firstRestricted) {
3298 throwErrorTolerant(firstRestricted, Messages.StrictOctalLiteral);
3299 }
3300 } else {
3301 if (!firstRestricted && token.octal) {
3302 firstRestricted = token;
3303 }
3304 }
3305 }
3306
3307 oldLabelSet = state.labelSet;
3308 oldInIteration = state.inIteration;
3309 oldInSwitch = state.inSwitch;
3310 oldInFunctionBody = state.inFunctionBody;
3311
3312 state.labelSet = {};
3313 state.inIteration = false;
3314 state.inSwitch = false;
3315 state.inFunctionBody = true;
3316
3317 while (index < length) {
3318 if (match('}')) {
3319 break;
3320 }
3321 sourceElement = parseSourceElement();
3322 if (typeof sourceElement === 'undefined') {
3323 break;
3324 }
3325 sourceElements.push(sourceElement);
3326 }
3327
3328 expect('}');
3329
3330 state.labelSet = oldLabelSet;
3331 state.inIteration = oldInIteration;
3332 state.inSwitch = oldInSwitch;
3333 state.inFunctionBody = oldInFunctionBody;
3334
3335 return delegate.markEnd(delegate.createBlockStatement(sourceElements), startToken);
3336 }
3337
3338 function parseParams(firstRestricted) {
3339 var param, params = [], token, stricted, paramSet, key, message;
3340 expect('(');
3341
3342 if (!match(')')) {
3343 paramSet = {};
3344 while (index < length) {
3345 token = lookahead;
3346 param = parseVariableIdentifier();
3347 key = '$' + token.value;
3348 if (strict) {
3349 if (isRestrictedWord(token.value)) {
3350 stricted = token;
3351 message = Messages.StrictParamName;
3352 }
3353 if (Object.prototype.hasOwnProperty.call(paramSet, key)) {
3354 stricted = token;
3355 message = Messages.StrictParamDupe;
3356 }
3357 } else if (!firstRestricted) {
3358 if (isRestrictedWord(token.value)) {
3359 firstRestricted = token;
3360 message = Messages.StrictParamName;
3361 } else if (isStrictModeReservedWord(token.value)) {
3362 firstRestricted = token;
3363 message = Messages.StrictReservedWord;
3364 } else if (Object.prototype.hasOwnProperty.call(paramSet, key)) {
3365 firstRestricted = token;
3366 message = Messages.StrictParamDupe;
3367 }
3368 }
3369 params.push(param);
3370 paramSet[key] = true;
3371 if (match(')')) {
3372 break;
3373 }
3374 expect(',');
3375 }
3376 }
3377
3378 expect(')');
3379
3380 return {
3381 params: params,
3382 stricted: stricted,
3383 firstRestricted: firstRestricted,
3384 message: message
3385 };
3386 }
3387
3388 function parseFunctionDeclaration() {
3389 var id, params = [], body, token, stricted, tmp, firstRestricted, message, previousStrict, startToken;
3390
3391 startToken = lookahead;
3392
3393 expectKeyword('function');
3394 token = lookahead;
3395 id = parseVariableIdentifier();
3396 if (strict) {
3397 if (isRestrictedWord(token.value)) {
3398 throwErrorTolerant(token, Messages.StrictFunctionName);
3399 }
3400 } else {
3401 if (isRestrictedWord(token.value)) {
3402 firstRestricted = token;
3403 message = Messages.StrictFunctionName;
3404 } else if (isStrictModeReservedWord(token.value)) {
3405 firstRestricted = token;
3406 message = Messages.StrictReservedWord;
3407 }
3408 }
3409
3410 tmp = parseParams(firstRestricted);
3411 params = tmp.params;
3412 stricted = tmp.stricted;
3413 firstRestricted = tmp.firstRestricted;
3414 if (tmp.message) {
3415 message = tmp.message;
3416 }
3417
3418 previousStrict = strict;
3419 body = parseFunctionSourceElements();
3420 if (strict && firstRestricted) {
3421 throwError(firstRestricted, message);
3422 }
3423 if (strict && stricted) {
3424 throwErrorTolerant(stricted, message);
3425 }
3426 strict = previousStrict;
3427
3428 return delegate.markEnd(delegate.createFunctionDeclaration(id, params, [], body), startToken);
3429 }
3430
3431 function parseFunctionExpression() {
3432 var token, id = null, stricted, firstRestricted, message, tmp, params = [], body, previousStrict, startToken;
3433
3434 startToken = lookahead;
3435 expectKeyword('function');
3436
3437 if (!match('(')) {
3438 token = lookahead;
3439 id = parseVariableIdentifier();
3440 if (strict) {
3441 if (isRestrictedWord(token.value)) {
3442 throwErrorTolerant(token, Messages.StrictFunctionName);
3443 }
3444 } else {
3445 if (isRestrictedWord(token.value)) {
3446 firstRestricted = token;
3447 message = Messages.StrictFunctionName;
3448 } else if (isStrictModeReservedWord(token.value)) {
3449 firstRestricted = token;
3450 message = Messages.StrictReservedWord;
3451 }
3452 }
3453 }
3454
3455 tmp = parseParams(firstRestricted);
3456 params = tmp.params;
3457 stricted = tmp.stricted;
3458 firstRestricted = tmp.firstRestricted;
3459 if (tmp.message) {
3460 message = tmp.message;
3461 }
3462
3463 previousStrict = strict;
3464 body = parseFunctionSourceElements();
3465 if (strict && firstRestricted) {
3466 throwError(firstRestricted, message);
3467 }
3468 if (strict && stricted) {
3469 throwErrorTolerant(stricted, message);
3470 }
3471 strict = previousStrict;
3472
3473 return delegate.markEnd(delegate.createFunctionExpression(id, params, [], body), startToken);
3474 }
3475
3476 // 14 Program
3477
3478 function parseSourceElement() {
3479 if (lookahead.type === Token.Keyword) {
3480 switch (lookahead.value) {
3481 case 'const':
3482 case 'let':
3483 return parseConstLetDeclaration(lookahead.value);
3484 case 'function':
3485 return parseFunctionDeclaration();
3486 default:
3487 return parseStatement();
3488 }
3489 }
3490
3491 if (lookahead.type !== Token.EOF) {
3492 return parseStatement();
3493 }
3494 }
3495
3496 function parseSourceElements() {
3497 var sourceElement, sourceElements = [], token, directive, firstRestricted;
3498
3499 while (index < length) {
3500 token = lookahead;
3501 if (token.type !== Token.StringLiteral) {
3502 break;
3503 }
3504
3505 sourceElement = parseSourceElement();
3506 sourceElements.push(sourceElement);
3507 if (sourceElement.expression.type !== Syntax.Literal) {
3508 // this is not directive
3509 break;
3510 }
3511 directive = source.slice(token.start + 1, token.end - 1);
3512 if (directive === 'use strict') {
3513 strict = true;
3514 if (firstRestricted) {
3515 throwErrorTolerant(firstRestricted, Messages.StrictOctalLiteral);
3516 }
3517 } else {
3518 if (!firstRestricted && token.octal) {
3519 firstRestricted = token;
3520 }
3521 }
3522 }
3523
3524 while (index < length) {
3525 sourceElement = parseSourceElement();
3526 /* istanbul ignore if */
3527 if (typeof sourceElement === 'undefined') {
3528 break;
3529 }
3530 sourceElements.push(sourceElement);
3531 }
3532 return sourceElements;
3533 }
3534
3535 function parseProgram() {
3536 var body, startToken;
3537
3538 skipComment();
3539 peek();
3540 startToken = lookahead;
3541 strict = false;
3542
3543 body = parseSourceElements();
3544 return delegate.markEnd(delegate.createProgram(body), startToken);
3545 }
3546
3547 function filterTokenLocation() {
3548 var i, entry, token, tokens = [];
3549
3550 for (i = 0; i < extra.tokens.length; ++i) {
3551 entry = extra.tokens[i];
3552 token = {
3553 type: entry.type,
3554 value: entry.value
3555 };
3556 if (extra.range) {
3557 token.range = entry.range;
3558 }
3559 if (extra.loc) {
3560 token.loc = entry.loc;
3561 }
3562 tokens.push(token);
3563 }
3564
3565 extra.tokens = tokens;
3566 }
3567
3568 function tokenize(code, options) {
3569 var toString,
3570 token,
3571 tokens;
3572
3573 toString = String;
3574 if (typeof code !== 'string' && !(code instanceof String)) {
3575 code = toString(code);
3576 }
3577
3578 delegate = SyntaxTreeDelegate;
3579 source = code;
3580 index = 0;
3581 lineNumber = (source.length > 0) ? 1 : 0;
3582 lineStart = 0;
3583 length = source.length;
3584 lookahead = null;
3585 state = {
3586 allowIn: true,
3587 labelSet: {},
3588 inFunctionBody: false,
3589 inIteration: false,
3590 inSwitch: false,
3591 lastCommentStart: -1
3592 };
3593
3594 extra = {};
3595
3596 // Options matching.
3597 options = options || {};
3598
3599 // Of course we collect tokens here.
3600 options.tokens = true;
3601 extra.tokens = [];
3602 extra.tokenize = true;
3603 // The following two fields are necessary to compute the Regex tokens.
3604 extra.openParenToken = -1;
3605 extra.openCurlyToken = -1;
3606
3607 extra.range = (typeof options.range === 'boolean') && options.range;
3608 extra.loc = (typeof options.loc === 'boolean') && options.loc;
3609
3610 if (typeof options.comment === 'boolean' && options.comment) {
3611 extra.comments = [];
3612 }
3613 if (typeof options.tolerant === 'boolean' && options.tolerant) {
3614 extra.errors = [];
3615 }
3616
3617 try {
3618 peek();
3619 if (lookahead.type === Token.EOF) {
3620 return extra.tokens;
3621 }
3622
3623 token = lex();
3624 while (lookahead.type !== Token.EOF) {
3625 try {
3626 token = lex();
3627 } catch (lexError) {
3628 token = lookahead;
3629 if (extra.errors) {
3630 extra.errors.push(lexError);
3631 // We have to break on the first error
3632 // to avoid infinite loops.
3633 break;
3634 } else {
3635 throw lexError;
3636 }
3637 }
3638 }
3639
3640 filterTokenLocation();
3641 tokens = extra.tokens;
3642 if (typeof extra.comments !== 'undefined') {
3643 tokens.comments = extra.comments;
3644 }
3645 if (typeof extra.errors !== 'undefined') {
3646 tokens.errors = extra.errors;
3647 }
3648 } catch (e) {
3649 throw e;
3650 } finally {
3651 extra = {};
3652 }
3653 return tokens;
3654 }
3655
3656 function parse(code, options) {
3657 var program, toString;
3658
3659 toString = String;
3660 if (typeof code !== 'string' && !(code instanceof String)) {
3661 code = toString(code);
3662 }
3663
3664 delegate = SyntaxTreeDelegate;
3665 source = code;
3666 index = 0;
3667 lineNumber = (source.length > 0) ? 1 : 0;
3668 lineStart = 0;
3669 length = source.length;
3670 lookahead = null;
3671 state = {
3672 allowIn: true,
3673 labelSet: {},
3674 inFunctionBody: false,
3675 inIteration: false,
3676 inSwitch: false,
3677 lastCommentStart: -1
3678 };
3679
3680 extra = {};
3681 if (typeof options !== 'undefined') {
3682 extra.range = (typeof options.range === 'boolean') && options.range;
3683 extra.loc = (typeof options.loc === 'boolean') && options.loc;
3684 extra.attachComment = (typeof options.attachComment === 'boolean') && options.attachComment;
3685
3686 if (extra.loc && options.source !== null && options.source !== undefined) {
3687 extra.source = toString(options.source);
3688 }
3689
3690 if (typeof options.tokens === 'boolean' && options.tokens) {
3691 extra.tokens = [];
3692 }
3693 if (typeof options.comment === 'boolean' && options.comment) {
3694 extra.comments = [];
3695 }
3696 if (typeof options.tolerant === 'boolean' && options.tolerant) {
3697 extra.errors = [];
3698 }
3699 if (extra.attachComment) {
3700 extra.range = true;
3701 extra.comments = [];
3702 extra.bottomRightStack = [];
3703 extra.trailingComments = [];
3704 extra.leadingComments = [];
3705 }
3706 }
3707
3708 try {
3709 program = parseProgram();
3710 if (typeof extra.comments !== 'undefined') {
3711 program.comments = extra.comments;
3712 }
3713 if (typeof extra.tokens !== 'undefined') {
3714 filterTokenLocation();
3715 program.tokens = extra.tokens;
3716 }
3717 if (typeof extra.errors !== 'undefined') {
3718 program.errors = extra.errors;
3719 }
3720 } catch (e) {
3721 throw e;
3722 } finally {
3723 extra = {};
3724 }
3725
3726 return program;
3727 }
3728
3729 // Sync with *.json manifests.
3730 exports.version = '1.2.2';
3731
3732 exports.tokenize = tokenize;
3733
3734 exports.parse = parse;
3735
3736 // Deep copy.
3737 /* istanbul ignore next */
3738 exports.Syntax = (function () {
3739 var name, types = {};
3740
3741 if (typeof Object.create === 'function') {
3742 types = Object.create(null);
3743 }
3744
3745 for (name in Syntax) {
3746 if (Syntax.hasOwnProperty(name)) {
3747 types[name] = Syntax[name];
3748 }
3749 }
3750
3751 if (typeof Object.freeze === 'function') {
3752 Object.freeze(types);
3753 }
3754
3755 return types;
3756 }());
3757
3758}));
3759/* vim: set sw=4 ts=4 et tw=80 : */
3760
3761},{}],1:[function(require,module,exports){
3762(function (process){
3763/* parser generated by jison 0.4.13 */
3764/*
3765 Returns a Parser object of the following structure:
3766
3767 Parser: {
3768 yy: {}
3769 }
3770
3771 Parser.prototype: {
3772 yy: {},
3773 trace: function(),
3774 symbols_: {associative list: name ==> number},
3775 terminals_: {associative list: number ==> name},
3776 productions_: [...],
3777 performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$),
3778 table: [...],
3779 defaultActions: {...},
3780 parseError: function(str, hash),
3781 parse: function(input),
3782
3783 lexer: {
3784 EOF: 1,
3785 parseError: function(str, hash),
3786 setInput: function(input),
3787 input: function(),
3788 unput: function(str),
3789 more: function(),
3790 less: function(n),
3791 pastInput: function(),
3792 upcomingInput: function(),
3793 showPosition: function(),
3794 test_match: function(regex_match_array, rule_index),
3795 next: function(),
3796 lex: function(),
3797 begin: function(condition),
3798 popState: function(),
3799 _currentRules: function(),
3800 topState: function(),
3801 pushState: function(condition),
3802
3803 options: {
3804 ranges: boolean (optional: true ==> token location info will include a .range[] member)
3805 flex: boolean (optional: true ==> flex-like lexing behaviour where the rules are tested exhaustively to find the longest match)
3806 backtrack_lexer: boolean (optional: true ==> lexer regexes are tested in order and for each matching regex the action code is invoked; the lexer terminates the scan when a token is returned by the action code)
3807 },
3808
3809 performAction: function(yy, yy_, $avoiding_name_collisions, YY_START),
3810 rules: [...],
3811 conditions: {associative list: name ==> set},
3812 }
3813 }
3814
3815
3816 token location info (@$, _$, etc.): {
3817 first_line: n,
3818 last_line: n,
3819 first_column: n,
3820 last_column: n,
3821 range: [start_number, end_number] (where the numbers are indexes into the input string, regular zero-based)
3822 }
3823
3824
3825 the parseError function receives a 'hash' object with these members for lexer and parser errors: {
3826 text: (matched text)
3827 token: (the produced terminal token, if any)
3828 line: (yylineno)
3829 }
3830 while parser (grammar) errors will also provide these members, i.e. parser errors deliver a superset of attributes: {
3831 loc: (yylloc)
3832 expected: (string describing the set of expected tokens)
3833 recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error)
3834 }
3835*/
3836var parser = (function(){
3837var parser = {trace: function trace() { },
3838yy: {},
3839symbols_: {"error":2,"JSON_PATH":3,"DOLLAR":4,"PATH_COMPONENTS":5,"LEADING_CHILD_MEMBER_EXPRESSION":6,"PATH_COMPONENT":7,"MEMBER_COMPONENT":8,"SUBSCRIPT_COMPONENT":9,"CHILD_MEMBER_COMPONENT":10,"DESCENDANT_MEMBER_COMPONENT":11,"DOT":12,"MEMBER_EXPRESSION":13,"DOT_DOT":14,"STAR":15,"IDENTIFIER":16,"SCRIPT_EXPRESSION":17,"INTEGER":18,"END":19,"CHILD_SUBSCRIPT_COMPONENT":20,"DESCENDANT_SUBSCRIPT_COMPONENT":21,"[":22,"SUBSCRIPT":23,"]":24,"SUBSCRIPT_EXPRESSION":25,"SUBSCRIPT_EXPRESSION_LIST":26,"SUBSCRIPT_EXPRESSION_LISTABLE":27,",":28,"STRING_LITERAL":29,"ARRAY_SLICE":30,"FILTER_EXPRESSION":31,"QQ_STRING":32,"Q_STRING":33,"$accept":0,"$end":1},
3840terminals_: {2:"error",4:"DOLLAR",12:"DOT",14:"DOT_DOT",15:"STAR",16:"IDENTIFIER",17:"SCRIPT_EXPRESSION",18:"INTEGER",19:"END",22:"[",24:"]",28:",",30:"ARRAY_SLICE",31:"FILTER_EXPRESSION",32:"QQ_STRING",33:"Q_STRING"},
3841productions_: [0,[3,1],[3,2],[3,1],[3,2],[5,1],[5,2],[7,1],[7,1],[8,1],[8,1],[10,2],[6,1],[11,2],[13,1],[13,1],[13,1],[13,1],[13,1],[9,1],[9,1],[20,3],[21,4],[23,1],[23,1],[26,1],[26,3],[27,1],[27,1],[27,1],[25,1],[25,1],[25,1],[29,1],[29,1]],
3842performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */
3843/**/) {
3844/* this == yyval */
3845if (!yy.ast) {
3846 yy.ast = _ast;
3847 _ast.initialize();
3848}
3849
3850var $0 = $$.length - 1;
3851switch (yystate) {
3852case 1:yy.ast.set({ expression: { type: "root", value: $$[$0] } }); yy.ast.unshift(); return yy.ast.yield()
3853break;
3854case 2:yy.ast.set({ expression: { type: "root", value: $$[$0-1] } }); yy.ast.unshift(); return yy.ast.yield()
3855break;
3856case 3:yy.ast.unshift(); return yy.ast.yield()
3857break;
3858case 4:yy.ast.set({ operation: "member", scope: "child", expression: { type: "identifier", value: $$[$0-1] }}); yy.ast.unshift(); return yy.ast.yield()
3859break;
3860case 5:
3861break;
3862case 6:
3863break;
3864case 7:yy.ast.set({ operation: "member" }); yy.ast.push()
3865break;
3866case 8:yy.ast.set({ operation: "subscript" }); yy.ast.push()
3867break;
3868case 9:yy.ast.set({ scope: "child" })
3869break;
3870case 10:yy.ast.set({ scope: "descendant" })
3871break;
3872case 11:
3873break;
3874case 12:yy.ast.set({ scope: "child", operation: "member" })
3875break;
3876case 13:
3877break;
3878case 14:yy.ast.set({ expression: { type: "wildcard", value: $$[$0] } })
3879break;
3880case 15:yy.ast.set({ expression: { type: "identifier", value: $$[$0] } })
3881break;
3882case 16:yy.ast.set({ expression: { type: "script_expression", value: $$[$0] } })
3883break;
3884case 17:yy.ast.set({ expression: { type: "numeric_literal", value: parseInt($$[$0]) } })
3885break;
3886case 18:
3887break;
3888case 19:yy.ast.set({ scope: "child" })
3889break;
3890case 20:yy.ast.set({ scope: "descendant" })
3891break;
3892case 21:
3893break;
3894case 22:
3895break;
3896case 23:
3897break;
3898case 24:$$[$0].length > 1? yy.ast.set({ expression: { type: "union", value: $$[$0] } }) : this.$ = $$[$0]
3899break;
3900case 25:this.$ = [$$[$0]]
3901break;
3902case 26:this.$ = $$[$0-2].concat($$[$0])
3903break;
3904case 27:this.$ = { expression: { type: "numeric_literal", value: parseInt($$[$0]) } }; yy.ast.set(this.$)
3905break;
3906case 28:this.$ = { expression: { type: "string_literal", value: $$[$0] } }; yy.ast.set(this.$)
3907break;
3908case 29:this.$ = { expression: { type: "slice", value: $$[$0] } }; yy.ast.set(this.$)
3909break;
3910case 30:this.$ = { expression: { type: "wildcard", value: $$[$0] } }; yy.ast.set(this.$)
3911break;
3912case 31:this.$ = { expression: { type: "script_expression", value: $$[$0] } }; yy.ast.set(this.$)
3913break;
3914case 32:this.$ = { expression: { type: "filter_expression", value: $$[$0] } }; yy.ast.set(this.$)
3915break;
3916case 33:this.$ = $$[$0]
3917break;
3918case 34:this.$ = $$[$0]
3919break;
3920}
3921},
3922table: [{3:1,4:[1,2],6:3,13:4,15:[1,5],16:[1,6],17:[1,7],18:[1,8],19:[1,9]},{1:[3]},{1:[2,1],5:10,7:11,8:12,9:13,10:14,11:15,12:[1,18],14:[1,19],20:16,21:17,22:[1,20]},{1:[2,3],5:21,7:11,8:12,9:13,10:14,11:15,12:[1,18],14:[1,19],20:16,21:17,22:[1,20]},{1:[2,12],12:[2,12],14:[2,12],22:[2,12]},{1:[2,14],12:[2,14],14:[2,14],22:[2,14]},{1:[2,15],12:[2,15],14:[2,15],22:[2,15]},{1:[2,16],12:[2,16],14:[2,16],22:[2,16]},{1:[2,17],12:[2,17],14:[2,17],22:[2,17]},{1:[2,18],12:[2,18],14:[2,18],22:[2,18]},{1:[2,2],7:22,8:12,9:13,10:14,11:15,12:[1,18],14:[1,19],20:16,21:17,22:[1,20]},{1:[2,5],12:[2,5],14:[2,5],22:[2,5]},{1:[2,7],12:[2,7],14:[2,7],22:[2,7]},{1:[2,8],12:[2,8],14:[2,8],22:[2,8]},{1:[2,9],12:[2,9],14:[2,9],22:[2,9]},{1:[2,10],12:[2,10],14:[2,10],22:[2,10]},{1:[2,19],12:[2,19],14:[2,19],22:[2,19]},{1:[2,20],12:[2,20],14:[2,20],22:[2,20]},{13:23,15:[1,5],16:[1,6],17:[1,7],18:[1,8],19:[1,9]},{13:24,15:[1,5],16:[1,6],17:[1,7],18:[1,8],19:[1,9],22:[1,25]},{15:[1,29],17:[1,30],18:[1,33],23:26,25:27,26:28,27:32,29:34,30:[1,35],31:[1,31],32:[1,36],33:[1,37]},{1:[2,4],7:22,8:12,9:13,10:14,11:15,12:[1,18],14:[1,19],20:16,21:17,22:[1,20]},{1:[2,6],12:[2,6],14:[2,6],22:[2,6]},{1:[2,11],12:[2,11],14:[2,11],22:[2,11]},{1:[2,13],12:[2,13],14:[2,13],22:[2,13]},{15:[1,29],17:[1,30],18:[1,33],23:38,25:27,26:28,27:32,29:34,30:[1,35],31:[1,31],32:[1,36],33:[1,37]},{24:[1,39]},{24:[2,23]},{24:[2,24],28:[1,40]},{24:[2,30]},{24:[2,31]},{24:[2,32]},{24:[2,25],28:[2,25]},{24:[2,27],28:[2,27]},{24:[2,28],28:[2,28]},{24:[2,29],28:[2,29]},{24:[2,33],28:[2,33]},{24:[2,34],28:[2,34]},{24:[1,41]},{1:[2,21],12:[2,21],14:[2,21],22:[2,21]},{18:[1,33],27:42,29:34,30:[1,35],32:[1,36],33:[1,37]},{1:[2,22],12:[2,22],14:[2,22],22:[2,22]},{24:[2,26],28:[2,26]}],
3923defaultActions: {27:[2,23],29:[2,30],30:[2,31],31:[2,32]},
3924parseError: function parseError(str, hash) {
3925 if (hash.recoverable) {
3926 this.trace(str);
3927 } else {
3928 throw new Error(str);
3929 }
3930},
3931parse: function parse(input) {
3932 var self = this, stack = [0], vstack = [null], lstack = [], table = this.table, yytext = '', yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1;
3933 var args = lstack.slice.call(arguments, 1);
3934 this.lexer.setInput(input);
3935 this.lexer.yy = this.yy;
3936 this.yy.lexer = this.lexer;
3937 this.yy.parser = this;
3938 if (typeof this.lexer.yylloc == 'undefined') {
3939 this.lexer.yylloc = {};
3940 }
3941 var yyloc = this.lexer.yylloc;
3942 lstack.push(yyloc);
3943 var ranges = this.lexer.options && this.lexer.options.ranges;
3944 if (typeof this.yy.parseError === 'function') {
3945 this.parseError = this.yy.parseError;
3946 } else {
3947 this.parseError = Object.getPrototypeOf(this).parseError;
3948 }
3949 function popStack(n) {
3950 stack.length = stack.length - 2 * n;
3951 vstack.length = vstack.length - n;
3952 lstack.length = lstack.length - n;
3953 }
3954 function lex() {
3955 var token;
3956 token = self.lexer.lex() || EOF;
3957 if (typeof token !== 'number') {
3958 token = self.symbols_[token] || token;
3959 }
3960 return token;
3961 }
3962 var symbol, preErrorSymbol, state, action, a, r, yyval = {}, p, len, newState, expected;
3963 while (true) {
3964 state = stack[stack.length - 1];
3965 if (this.defaultActions[state]) {
3966 action = this.defaultActions[state];
3967 } else {
3968 if (symbol === null || typeof symbol == 'undefined') {
3969 symbol = lex();
3970 }
3971 action = table[state] && table[state][symbol];
3972 }
3973 if (typeof action === 'undefined' || !action.length || !action[0]) {
3974 var errStr = '';
3975 expected = [];
3976 for (p in table[state]) {
3977 if (this.terminals_[p] && p > TERROR) {
3978 expected.push('\'' + this.terminals_[p] + '\'');
3979 }
3980 }
3981 if (this.lexer.showPosition) {
3982 errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + this.lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\'';
3983 } else {
3984 errStr = 'Parse error on line ' + (yylineno + 1) + ': Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\'');
3985 }
3986 this.parseError(errStr, {
3987 text: this.lexer.match,
3988 token: this.terminals_[symbol] || symbol,
3989 line: this.lexer.yylineno,
3990 loc: yyloc,
3991 expected: expected
3992 });
3993 }
3994 if (action[0] instanceof Array && action.length > 1) {
3995 throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol);
3996 }
3997 switch (action[0]) {
3998 case 1:
3999 stack.push(symbol);
4000 vstack.push(this.lexer.yytext);
4001 lstack.push(this.lexer.yylloc);
4002 stack.push(action[1]);
4003 symbol = null;
4004 if (!preErrorSymbol) {
4005 yyleng = this.lexer.yyleng;
4006 yytext = this.lexer.yytext;
4007 yylineno = this.lexer.yylineno;
4008 yyloc = this.lexer.yylloc;
4009 if (recovering > 0) {
4010 recovering--;
4011 }
4012 } else {
4013 symbol = preErrorSymbol;
4014 preErrorSymbol = null;
4015 }
4016 break;
4017 case 2:
4018 len = this.productions_[action[1]][1];
4019 yyval.$ = vstack[vstack.length - len];
4020 yyval._$ = {
4021 first_line: lstack[lstack.length - (len || 1)].first_line,
4022 last_line: lstack[lstack.length - 1].last_line,
4023 first_column: lstack[lstack.length - (len || 1)].first_column,
4024 last_column: lstack[lstack.length - 1].last_column
4025 };
4026 if (ranges) {
4027 yyval._$.range = [
4028 lstack[lstack.length - (len || 1)].range[0],
4029 lstack[lstack.length - 1].range[1]
4030 ];
4031 }
4032 r = this.performAction.apply(yyval, [
4033 yytext,
4034 yyleng,
4035 yylineno,
4036 this.yy,
4037 action[1],
4038 vstack,
4039 lstack
4040 ].concat(args));
4041 if (typeof r !== 'undefined') {
4042 return r;
4043 }
4044 if (len) {
4045 stack = stack.slice(0, -1 * len * 2);
4046 vstack = vstack.slice(0, -1 * len);
4047 lstack = lstack.slice(0, -1 * len);
4048 }
4049 stack.push(this.productions_[action[1]][0]);
4050 vstack.push(yyval.$);
4051 lstack.push(yyval._$);
4052 newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
4053 stack.push(newState);
4054 break;
4055 case 3:
4056 return true;
4057 }
4058 }
4059 return true;
4060}};
4061var _ast = {
4062
4063 initialize: function() {
4064 this._nodes = [];
4065 this._node = {};
4066 this._stash = [];
4067 },
4068
4069 set: function(props) {
4070 for (var k in props) this._node[k] = props[k];
4071 return this._node;
4072 },
4073
4074 node: function(obj) {
4075 if (arguments.length) this._node = obj;
4076 return this._node;
4077 },
4078
4079 push: function() {
4080 this._nodes.push(this._node);
4081 this._node = {};
4082 },
4083
4084 unshift: function() {
4085 this._nodes.unshift(this._node);
4086 this._node = {};
4087 },
4088
4089 yield: function() {
4090 var _nodes = this._nodes;
4091 this.initialize();
4092 return _nodes;
4093 }
4094};
4095/* generated by jison-lex 0.2.1 */
4096var lexer = (function(){
4097var lexer = {
4098
4099EOF:1,
4100
4101parseError:function parseError(str, hash) {
4102 if (this.yy.parser) {
4103 this.yy.parser.parseError(str, hash);
4104 } else {
4105 throw new Error(str);
4106 }
4107 },
4108
4109// resets the lexer, sets new input
4110setInput:function (input) {
4111 this._input = input;
4112 this._more = this._backtrack = this.done = false;
4113 this.yylineno = this.yyleng = 0;
4114 this.yytext = this.matched = this.match = '';
4115 this.conditionStack = ['INITIAL'];
4116 this.yylloc = {
4117 first_line: 1,
4118 first_column: 0,
4119 last_line: 1,
4120 last_column: 0
4121 };
4122 if (this.options.ranges) {
4123 this.yylloc.range = [0,0];
4124 }
4125 this.offset = 0;
4126 return this;
4127 },
4128
4129// consumes and returns one char from the input
4130input:function () {
4131 var ch = this._input[0];
4132 this.yytext += ch;
4133 this.yyleng++;
4134 this.offset++;
4135 this.match += ch;
4136 this.matched += ch;
4137 var lines = ch.match(/(?:\r\n?|\n).*/g);
4138 if (lines) {
4139 this.yylineno++;
4140 this.yylloc.last_line++;
4141 } else {
4142 this.yylloc.last_column++;
4143 }
4144 if (this.options.ranges) {
4145 this.yylloc.range[1]++;
4146 }
4147
4148 this._input = this._input.slice(1);
4149 return ch;
4150 },
4151
4152// unshifts one char (or a string) into the input
4153unput:function (ch) {
4154 var len = ch.length;
4155 var lines = ch.split(/(?:\r\n?|\n)/g);
4156
4157 this._input = ch + this._input;
4158 this.yytext = this.yytext.substr(0, this.yytext.length - len - 1);
4159 //this.yyleng -= len;
4160 this.offset -= len;
4161 var oldLines = this.match.split(/(?:\r\n?|\n)/g);
4162 this.match = this.match.substr(0, this.match.length - 1);
4163 this.matched = this.matched.substr(0, this.matched.length - 1);
4164
4165 if (lines.length - 1) {
4166 this.yylineno -= lines.length - 1;
4167 }
4168 var r = this.yylloc.range;
4169
4170 this.yylloc = {
4171 first_line: this.yylloc.first_line,
4172 last_line: this.yylineno + 1,
4173 first_column: this.yylloc.first_column,
4174 last_column: lines ?
4175 (lines.length === oldLines.length ? this.yylloc.first_column : 0)
4176 + oldLines[oldLines.length - lines.length].length - lines[0].length :
4177 this.yylloc.first_column - len
4178 };
4179
4180 if (this.options.ranges) {
4181 this.yylloc.range = [r[0], r[0] + this.yyleng - len];
4182 }
4183 this.yyleng = this.yytext.length;
4184 return this;
4185 },
4186
4187// When called from action, caches matched text and appends it on next action
4188more:function () {
4189 this._more = true;
4190 return this;
4191 },
4192
4193// When called from action, signals the lexer that this rule fails to match the input, so the next matching rule (regex) should be tested instead.
4194reject:function () {
4195 if (this.options.backtrack_lexer) {
4196 this._backtrack = true;
4197 } else {
4198 return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n' + this.showPosition(), {
4199 text: "",
4200 token: null,
4201 line: this.yylineno
4202 });
4203
4204 }
4205 return this;
4206 },
4207
4208// retain first n characters of the match
4209less:function (n) {
4210 this.unput(this.match.slice(n));
4211 },
4212
4213// displays already matched input, i.e. for error messages
4214pastInput:function () {
4215 var past = this.matched.substr(0, this.matched.length - this.match.length);
4216 return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, "");
4217 },
4218
4219// displays upcoming input, i.e. for error messages
4220upcomingInput:function () {
4221 var next = this.match;
4222 if (next.length < 20) {
4223 next += this._input.substr(0, 20-next.length);
4224 }
4225 return (next.substr(0,20) + (next.length > 20 ? '...' : '')).replace(/\n/g, "");
4226 },
4227
4228// displays the character position where the lexing error occurred, i.e. for error messages
4229showPosition:function () {
4230 var pre = this.pastInput();
4231 var c = new Array(pre.length + 1).join("-");
4232 return pre + this.upcomingInput() + "\n" + c + "^";
4233 },
4234
4235// test the lexed token: return FALSE when not a match, otherwise return token
4236test_match:function (match, indexed_rule) {
4237 var token,
4238 lines,
4239 backup;
4240
4241 if (this.options.backtrack_lexer) {
4242 // save context
4243 backup = {
4244 yylineno: this.yylineno,
4245 yylloc: {
4246 first_line: this.yylloc.first_line,
4247 last_line: this.last_line,
4248 first_column: this.yylloc.first_column,
4249 last_column: this.yylloc.last_column
4250 },
4251 yytext: this.yytext,
4252 match: this.match,
4253 matches: this.matches,
4254 matched: this.matched,
4255 yyleng: this.yyleng,
4256 offset: this.offset,
4257 _more: this._more,
4258 _input: this._input,
4259 yy: this.yy,
4260 conditionStack: this.conditionStack.slice(0),
4261 done: this.done
4262 };
4263 if (this.options.ranges) {
4264 backup.yylloc.range = this.yylloc.range.slice(0);
4265 }
4266 }
4267
4268 lines = match[0].match(/(?:\r\n?|\n).*/g);
4269 if (lines) {
4270 this.yylineno += lines.length;
4271 }
4272 this.yylloc = {
4273 first_line: this.yylloc.last_line,
4274 last_line: this.yylineno + 1,
4275 first_column: this.yylloc.last_column,
4276 last_column: lines ?
4277 lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length :
4278 this.yylloc.last_column + match[0].length
4279 };
4280 this.yytext += match[0];
4281 this.match += match[0];
4282 this.matches = match;
4283 this.yyleng = this.yytext.length;
4284 if (this.options.ranges) {
4285 this.yylloc.range = [this.offset, this.offset += this.yyleng];
4286 }
4287 this._more = false;
4288 this._backtrack = false;
4289 this._input = this._input.slice(match[0].length);
4290 this.matched += match[0];
4291 token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
4292 if (this.done && this._input) {
4293 this.done = false;
4294 }
4295 if (token) {
4296 return token;
4297 } else if (this._backtrack) {
4298 // recover context
4299 for (var k in backup) {
4300 this[k] = backup[k];
4301 }
4302 return false; // rule action called reject() implying the next rule should be tested instead.
4303 }
4304 return false;
4305 },
4306
4307// return next match in input
4308next:function () {
4309 if (this.done) {
4310 return this.EOF;
4311 }
4312 if (!this._input) {
4313 this.done = true;
4314 }
4315
4316 var token,
4317 match,
4318 tempMatch,
4319 index;
4320 if (!this._more) {
4321 this.yytext = '';
4322 this.match = '';
4323 }
4324 var rules = this._currentRules();
4325 for (var i = 0; i < rules.length; i++) {
4326 tempMatch = this._input.match(this.rules[rules[i]]);
4327 if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
4328 match = tempMatch;
4329 index = i;
4330 if (this.options.backtrack_lexer) {
4331 token = this.test_match(tempMatch, rules[i]);
4332 if (token !== false) {
4333 return token;
4334 } else if (this._backtrack) {
4335 match = false;
4336 continue; // rule action called reject() implying a rule MISmatch.
4337 } else {
4338 // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
4339 return false;
4340 }
4341 } else if (!this.options.flex) {
4342 break;
4343 }
4344 }
4345 }
4346 if (match) {
4347 token = this.test_match(match, rules[index]);
4348 if (token !== false) {
4349 return token;
4350 }
4351 // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
4352 return false;
4353 }
4354 if (this._input === "") {
4355 return this.EOF;
4356 } else {
4357 return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), {
4358 text: "",
4359 token: null,
4360 line: this.yylineno
4361 });
4362 }
4363 },
4364
4365// return next match that has a token
4366lex:function lex() {
4367 var r = this.next();
4368 if (r) {
4369 return r;
4370 } else {
4371 return this.lex();
4372 }
4373 },
4374
4375// activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
4376begin:function begin(condition) {
4377 this.conditionStack.push(condition);
4378 },
4379
4380// pop the previously active lexer condition state off the condition stack
4381popState:function popState() {
4382 var n = this.conditionStack.length - 1;
4383 if (n > 0) {
4384 return this.conditionStack.pop();
4385 } else {
4386 return this.conditionStack[0];
4387 }
4388 },
4389
4390// produce the lexer rule set which is active for the currently active lexer condition state
4391_currentRules:function _currentRules() {
4392 if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
4393 return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
4394 } else {
4395 return this.conditions["INITIAL"].rules;
4396 }
4397 },
4398
4399// return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
4400topState:function topState(n) {
4401 n = this.conditionStack.length - 1 - Math.abs(n || 0);
4402 if (n >= 0) {
4403 return this.conditionStack[n];
4404 } else {
4405 return "INITIAL";
4406 }
4407 },
4408
4409// alias for begin(condition)
4410pushState:function pushState(condition) {
4411 this.begin(condition);
4412 },
4413
4414// return the number of states currently on the stack
4415stateStackSize:function stateStackSize() {
4416 return this.conditionStack.length;
4417 },
4418options: {},
4419performAction: function anonymous(yy,yy_,$avoiding_name_collisions,YY_START
4420/**/) {
4421
4422var YYSTATE=YY_START;
4423switch($avoiding_name_collisions) {
4424case 0:return 4
4425break;
4426case 1:return 14
4427break;
4428case 2:return 12
4429break;
4430case 3:return 15
4431break;
4432case 4:return 16
4433break;
4434case 5:return 22
4435break;
4436case 6:return 24
4437break;
4438case 7:return 28
4439break;
4440case 8:return 30
4441break;
4442case 9:return 18
4443break;
4444case 10:yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2); return 32;
4445break;
4446case 11:yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2); return 33;
4447break;
4448case 12:return 17
4449break;
4450case 13:return 31
4451break;
4452}
4453},
4454rules: [/^(?:\$)/,/^(?:\.\.)/,/^(?:\.)/,/^(?:\*)/,/^(?:[a-zA-Z_]+[a-zA-Z0-9_]*)/,/^(?:\[)/,/^(?:\])/,/^(?:,)/,/^(?:((-?(?:0|[1-9][0-9]*)))?\:((-?(?:0|[1-9][0-9]*)))?(\:((-?(?:0|[1-9][0-9]*)))?)?)/,/^(?:(-?(?:0|[1-9][0-9]*)))/,/^(?:"(?:\\["bfnrt/\\]|\\u[a-fA-F0-9]{4}|[^"\\])*")/,/^(?:'(?:\\['bfnrt/\\]|\\u[a-fA-F0-9]{4}|[^'\\])*')/,/^(?:\(.+?\)(?=\]))/,/^(?:\?\(.+?\)(?=\]))/],
4455conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13],"inclusive":true}}
4456};
4457return lexer;
4458})();
4459parser.lexer = lexer;
4460function Parser () {
4461 this.yy = {};
4462}
4463Parser.prototype = parser;parser.Parser = Parser;
4464return new Parser;
4465})();
4466
4467
4468if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
4469exports.parser = parser;
4470exports.Parser = parser.Parser;
4471exports.parse = function () { return parser.parse.apply(parser, arguments); };
4472exports.main = function commonjsMain(args) {
4473 if (!args[1]) {
4474 console.log('Usage: '+args[0]+' FILE');
4475 process.exit(1);
4476 }
4477 var source = require('fs').readFileSync(require('path').normalize(args[1]), "utf8");
4478 return exports.parser.parse(source);
4479};
4480if (typeof module !== 'undefined' && require.main === module) {
4481 exports.main(process.argv.slice(1));
4482}
4483}
4484
4485}).call(this,require('_process'))
4486},{"_process":12,"fs":9,"path":11}],2:[function(require,module,exports){
4487module.exports = {
4488 identifier: "[a-zA-Z_]+[a-zA-Z0-9_]*",
4489 integer: "-?(?:0|[1-9][0-9]*)",
4490 qq_string: "\"(?:\\\\[\"bfnrt/\\\\]|\\\\u[a-fA-F0-9]{4}|[^\"\\\\])*\"",
4491 q_string: "'(?:\\\\[\'bfnrt/\\\\]|\\\\u[a-fA-F0-9]{4}|[^\'\\\\])*'"
4492};
4493
4494},{}],3:[function(require,module,exports){
4495var dict = require('./dict');
4496var fs = require('fs');
4497fs.readFileSync = fs.readFileSync || function() {}
4498require.resolve = require.resolve || function() {}
4499
4500var grammar = {
4501
4502 lex: {
4503
4504 macros: {
4505 esc: "\\\\",
4506 int: dict.integer
4507 },
4508
4509 rules: [
4510 ["\\$", "return 'DOLLAR'"],
4511 ["\\.\\.", "return 'DOT_DOT'"],
4512 ["\\.", "return 'DOT'"],
4513 ["\\*", "return 'STAR'"],
4514 [dict.identifier, "return 'IDENTIFIER'"],
4515 ["\\[", "return '['"],
4516 ["\\]", "return ']'"],
4517 [",", "return ','"],
4518 ["({int})?\\:({int})?(\\:({int})?)?", "return 'ARRAY_SLICE'"],
4519 ["{int}", "return 'INTEGER'"],
4520 [dict.qq_string, "yytext = yytext.substr(1,yyleng-2); return 'QQ_STRING';"],
4521 [dict.q_string, "yytext = yytext.substr(1,yyleng-2); return 'Q_STRING';"],
4522 ["\\(.+?\\)(?=\\])", "return 'SCRIPT_EXPRESSION'"],
4523 ["\\?\\(.+?\\)(?=\\])", "return 'FILTER_EXPRESSION'"]
4524 ]
4525 },
4526
4527 start: "JSON_PATH",
4528
4529 bnf: {
4530
4531 JSON_PATH: [
4532 [ 'DOLLAR', 'yy.ast.set({ expression: { type: "root", value: $1 } }); yy.ast.unshift(); return yy.ast.yield()' ],
4533 [ 'DOLLAR PATH_COMPONENTS', 'yy.ast.set({ expression: { type: "root", value: $1 } }); yy.ast.unshift(); return yy.ast.yield()' ],
4534 [ 'LEADING_CHILD_MEMBER_EXPRESSION', 'yy.ast.unshift(); return yy.ast.yield()' ],
4535 [ 'LEADING_CHILD_MEMBER_EXPRESSION PATH_COMPONENTS', 'yy.ast.set({ operation: "member", scope: "child", expression: { type: "identifier", value: $1 }}); yy.ast.unshift(); return yy.ast.yield()' ] ],
4536
4537 PATH_COMPONENTS: [
4538 [ 'PATH_COMPONENT', '' ],
4539 [ 'PATH_COMPONENTS PATH_COMPONENT', '' ] ],
4540
4541 PATH_COMPONENT: [
4542 [ 'MEMBER_COMPONENT', 'yy.ast.set({ operation: "member" }); yy.ast.push()' ],
4543 [ 'SUBSCRIPT_COMPONENT', 'yy.ast.set({ operation: "subscript" }); yy.ast.push() ' ] ],
4544
4545 MEMBER_COMPONENT: [
4546 [ 'CHILD_MEMBER_COMPONENT', 'yy.ast.set({ scope: "child" })' ],
4547 [ 'DESCENDANT_MEMBER_COMPONENT', 'yy.ast.set({ scope: "descendant" })' ] ],
4548
4549 CHILD_MEMBER_COMPONENT: [
4550 [ 'DOT MEMBER_EXPRESSION', '' ] ],
4551
4552 LEADING_CHILD_MEMBER_EXPRESSION: [
4553 [ 'MEMBER_EXPRESSION', 'yy.ast.set({ scope: "child", operation: "member" })' ] ],
4554
4555 DESCENDANT_MEMBER_COMPONENT: [
4556 [ 'DOT_DOT MEMBER_EXPRESSION', '' ] ],
4557
4558 MEMBER_EXPRESSION: [
4559 [ 'STAR', 'yy.ast.set({ expression: { type: "wildcard", value: $1 } })' ],
4560 [ 'IDENTIFIER', 'yy.ast.set({ expression: { type: "identifier", value: $1 } })' ],
4561 [ 'SCRIPT_EXPRESSION', 'yy.ast.set({ expression: { type: "script_expression", value: $1 } })' ],
4562 [ 'INTEGER', 'yy.ast.set({ expression: { type: "numeric_literal", value: parseInt($1) } })' ],
4563 [ 'END', '' ] ],
4564
4565 SUBSCRIPT_COMPONENT: [
4566 [ 'CHILD_SUBSCRIPT_COMPONENT', 'yy.ast.set({ scope: "child" })' ],
4567 [ 'DESCENDANT_SUBSCRIPT_COMPONENT', 'yy.ast.set({ scope: "descendant" })' ] ],
4568
4569 CHILD_SUBSCRIPT_COMPONENT: [
4570 [ '[ SUBSCRIPT ]', '' ] ],
4571
4572 DESCENDANT_SUBSCRIPT_COMPONENT: [
4573 [ 'DOT_DOT [ SUBSCRIPT ]', '' ] ],
4574
4575 SUBSCRIPT: [
4576 [ 'SUBSCRIPT_EXPRESSION', '' ],
4577 [ 'SUBSCRIPT_EXPRESSION_LIST', '$1.length > 1? yy.ast.set({ expression: { type: "union", value: $1 } }) : $$ = $1' ] ],
4578
4579 SUBSCRIPT_EXPRESSION_LIST: [
4580 [ 'SUBSCRIPT_EXPRESSION_LISTABLE', '$$ = [$1]'],
4581 [ 'SUBSCRIPT_EXPRESSION_LIST , SUBSCRIPT_EXPRESSION_LISTABLE', '$$ = $1.concat($3)' ] ],
4582
4583 SUBSCRIPT_EXPRESSION_LISTABLE: [
4584 [ 'INTEGER', '$$ = { expression: { type: "numeric_literal", value: parseInt($1) } }; yy.ast.set($$)' ],
4585 [ 'STRING_LITERAL', '$$ = { expression: { type: "string_literal", value: $1 } }; yy.ast.set($$)' ],
4586 [ 'ARRAY_SLICE', '$$ = { expression: { type: "slice", value: $1 } }; yy.ast.set($$)' ] ],
4587
4588 SUBSCRIPT_EXPRESSION: [
4589 [ 'STAR', '$$ = { expression: { type: "wildcard", value: $1 } }; yy.ast.set($$)' ],
4590 [ 'SCRIPT_EXPRESSION', '$$ = { expression: { type: "script_expression", value: $1 } }; yy.ast.set($$)' ],
4591 [ 'FILTER_EXPRESSION', '$$ = { expression: { type: "filter_expression", value: $1 } }; yy.ast.set($$)' ] ],
4592
4593 STRING_LITERAL: [
4594 [ 'QQ_STRING', "$$ = $1" ],
4595 [ 'Q_STRING', "$$ = $1" ] ]
4596 },
4597
4598 moduleInclude: fs.readFileSync(require.resolve("../include/module.js")),
4599 actionInclude: fs.readFileSync(require.resolve("../include/action.js"))
4600};
4601
4602module.exports = grammar;
4603
4604},{"./dict":2,"fs":9}],4:[function(require,module,exports){
4605var aesprim = require('./aesprim');
4606var slice = require('./slice');
4607var _evaluate = require('static-eval');
4608var _uniq = require('underscore').uniq;
4609
4610var Handlers = function() {
4611 return this.initialize.apply(this, arguments);
4612}
4613
4614Handlers.prototype.initialize = function() {
4615 this.traverse = traverser(true);
4616 this.descend = traverser();
4617}
4618
4619Handlers.prototype.keys = Object.keys;
4620
4621Handlers.prototype.resolve = function(component) {
4622
4623 var key = [ component.operation, component.scope, component.expression.type ].join('-');
4624 var method = this._fns[key];
4625
4626 if (!method) throw new Error("couldn't resolve key: " + key);
4627 return method.bind(this);
4628};
4629
4630Handlers.prototype.register = function(key, handler) {
4631
4632 if (!handler instanceof Function) {
4633 throw new Error("handler must be a function");
4634 }
4635
4636 this._fns[key] = handler;
4637};
4638
4639Handlers.prototype._fns = {
4640
4641 'member-child-identifier': function(component, partial) {
4642 var key = component.expression.value;
4643 var value = partial.value;
4644 if (value instanceof Object && key in value) {
4645 return [ { value: value[key], path: partial.path.concat(key) } ]
4646 }
4647 },
4648
4649 'member-descendant-identifier':
4650 _traverse(function(key, value, ref) { return key == ref }),
4651
4652 'subscript-child-numeric_literal':
4653 _descend(function(key, value, ref) { return key === ref }),
4654
4655 'subscript-descendant-numeric_literal':
4656 _traverse(function(key, value, ref) { return key === ref }),
4657
4658 'member-child-wildcard':
4659 _descend(function() { return true }),
4660
4661 'member-descendant-wildcard':
4662 _traverse(function() { return true }),
4663
4664 'subscript-descendant-wildcard':
4665 _traverse(function() { return true }),
4666
4667 'subscript-child-wildcard':
4668 _descend(function() { return true }),
4669
4670 'subscript-child-slice': function(component, partial) {
4671 if (is_array(partial.value)) {
4672 var args = component.expression.value.split(':');
4673 var values = partial.value.map(function(v, i) { return { value: v, path: partial.path.concat(i) } });
4674 return slice.apply(null, [values].concat(args));
4675 }
4676 },
4677
4678 'subscript-child-union': function(component, partial) {
4679 var results = [];
4680 component.expression.value.forEach(function(component) {
4681 var _component = { operation: 'subscript', scope: 'child', expression: component.expression };
4682 var handler = this.resolve(_component);
4683 var _results = handler(_component, partial);
4684 results = results.concat(_results);
4685 }, this);
4686
4687 return unique(results);
4688 },
4689
4690 'subscript-descendant-union': function(component, partial, count) {
4691
4692 var jp = require('..');
4693 var self = this;
4694
4695 var results = [];
4696 var nodes = jp.nodes(partial, '$..*').slice(1);
4697
4698 nodes.forEach(function(node) {
4699 if (results.length >= count) return;
4700 component.expression.value.forEach(function(component) {
4701 var _component = { operation: 'subscript', scope: 'child', expression: component.expression };
4702 var handler = self.resolve(_component);
4703 var _results = handler(_component, node);
4704 results = results.concat(_results);
4705 });
4706 });
4707
4708 return unique(results);
4709 },
4710
4711 'subscript-child-filter_expression': function(component, partial, count) {
4712
4713 // slice out the expression from ?(expression)
4714 var src = component.expression.value.slice(2, -1);
4715 var ast = aesprim.parse(src).body[0].expression;
4716
4717 var passable = function(key, value) {
4718 return evaluate(ast, { '@': value });
4719 }
4720
4721 return this.descend(partial, null, passable, count);
4722
4723 },
4724
4725 'subscript-descendant-filter_expression': function(component, partial, count) {
4726
4727 // slice out the expression from ?(expression)
4728 var src = component.expression.value.slice(2, -1);
4729 var ast = aesprim.parse(src).body[0].expression;
4730
4731 var passable = function(key, value) {
4732 return evaluate(ast, { '@': value });
4733 }
4734
4735 return this.traverse(partial, null, passable, count);
4736 },
4737
4738 'subscript-child-script_expression': function(component, partial) {
4739 var exp = component.expression.value.slice(1, -1);
4740 return eval_recurse(partial, exp, '$[{{value}}]');
4741 },
4742
4743 'member-child-script_expression': function(component, partial) {
4744 var exp = component.expression.value.slice(1, -1);
4745 return eval_recurse(partial, exp, '$.{{value}}');
4746 },
4747
4748 'member-descendant-script_expression': function(component, partial) {
4749 var exp = component.expression.value.slice(1, -1);
4750 return eval_recurse(partial, exp, '$..value');
4751 }
4752};
4753
4754Handlers.prototype._fns['subscript-child-string_literal'] =
4755 Handlers.prototype._fns['member-child-identifier'];
4756
4757Handlers.prototype._fns['member-child-numeric_literal'] =
4758 Handlers.prototype._fns['subscript-child-numeric_literal'];
4759
4760Handlers.prototype._fns['member-descendant-numeric_literal'] =
4761 Handlers.prototype._fns['subscript-descendant-string_literal'] =
4762 Handlers.prototype._fns['member-descendant-identifier'];
4763
4764function eval_recurse(partial, src, template) {
4765
4766 var jp = require('./index');
4767 var ast = aesprim.parse(src).body[0].expression;
4768 var value = evaluate(ast, { '@': partial.value });
4769 var path = template.replace(/\{\{\s*value\s*\}\}/g, value);
4770
4771 var results = jp.nodes(partial.value, path);
4772 results.forEach(function(r) {
4773 r.path = partial.path.concat(r.path.slice(1));
4774 });
4775
4776 return results;
4777}
4778
4779function is_array(val) {
4780 return Array.isArray(val);
4781}
4782
4783function is_object(val) {
4784 // is this a non-array, non-null object?
4785 return val && !(val instanceof Array) && val instanceof Object;
4786}
4787
4788function traverser(recurse) {
4789
4790 return function(partial, ref, passable, count) {
4791
4792 var value = partial.value;
4793 var path = partial.path;
4794
4795 var results = [];
4796
4797 var descend = function(value, path) {
4798
4799 if (is_array(value)) {
4800 value.forEach(function(element, index) {
4801 if (results.length >= count) { return }
4802 if (passable(index, element, ref)) {
4803 results.push({ path: path.concat(index), value: element });
4804 }
4805 });
4806 value.forEach(function(element, index) {
4807 if (results.length >= count) { return }
4808 if (recurse) {
4809 descend(element, path.concat(index));
4810 }
4811 });
4812 } else if (is_object(value)) {
4813 this.keys(value).forEach(function(k) {
4814 if (results.length >= count) { return }
4815 if (passable(k, value[k], ref)) {
4816 results.push({ path: path.concat(k), value: value[k] });
4817 }
4818 })
4819 this.keys(value).forEach(function(k) {
4820 if (results.length >= count) { return }
4821 if (recurse) {
4822 descend(value[k], path.concat(k));
4823 }
4824 });
4825 }
4826 }.bind(this);
4827 descend(value, path);
4828 return results;
4829 }
4830}
4831
4832function _descend(passable) {
4833 return function(component, partial, count) {
4834 return this.descend(partial, component.expression.value, passable, count);
4835 }
4836}
4837
4838function _traverse(passable) {
4839 return function(component, partial, count) {
4840 return this.traverse(partial, component.expression.value, passable, count);
4841 }
4842}
4843
4844function evaluate() {
4845 try { return _evaluate.apply(this, arguments) }
4846 catch (e) { }
4847}
4848
4849function unique(results) {
4850 return _uniq(
4851 results,
4852 function(r) { return r.path.map(function(c) { return String(c).replace('-', '--') }).join('-') }
4853 );
4854}
4855
4856module.exports = Handlers;
4857
4858},{"..":"jsonpath","./aesprim":"./aesprim","./index":5,"./slice":7,"static-eval":13,"underscore":9}],5:[function(require,module,exports){
4859/* global toString */
4860
4861var assert = require('assert');
4862var dict = require('./dict');
4863var Parser = require('./parser');
4864var Handlers = require('./handlers');
4865
4866var JSONPath = function() {
4867 this.initialize.apply(this, arguments);
4868};
4869
4870JSONPath.prototype.initialize = function() {
4871 this.parser = new Parser();
4872 this.handlers = new Handlers();
4873};
4874
4875JSONPath.prototype.parse = function(string) {
4876 assert.ok(_is_string(string), "we need a path");
4877 return this.parser.parse(string);
4878};
4879
4880JSONPath.prototype.parent = function(obj, string) {
4881
4882 assert.ok(obj instanceof Object, "obj needs to be an object");
4883 assert.ok(string, "we need a path");
4884
4885 var node = this.nodes(obj, string)[0];
4886 var key = node.path.pop(); /* jshint unused:false */
4887 return this.value(obj, node.path);
4888}
4889
4890JSONPath.prototype.apply = function(obj, string, fn) {
4891
4892 assert.ok(obj instanceof Object, "obj needs to be an object");
4893 assert.ok(string, "we need a path");
4894 assert.equal(typeof fn, "function", "fn needs to be function")
4895
4896 var nodes = this.nodes(obj, string).sort(function(a, b) {
4897 // sort nodes so we apply from the bottom up
4898 return b.path.length - a.path.length;
4899 });
4900
4901 nodes.forEach(function(node) {
4902 var key = node.path.pop();
4903 var parent = this.value(obj, this.stringify(node.path));
4904 var val = node.value = fn.call(obj, parent[key]);
4905 parent[key] = val;
4906 }, this);
4907
4908 return nodes;
4909}
4910
4911JSONPath.prototype.value = function(obj, path, value) {
4912
4913 assert.ok(obj instanceof Object, "obj needs to be an object");
4914 assert.ok(path, "we need a path");
4915
4916 if (arguments.length >= 3) {
4917 var node = this.nodes(obj, path).shift();
4918 if (!node) return this._vivify(obj, path, value);
4919 var key = node.path.slice(-1).shift();
4920 var parent = this.parent(obj, this.stringify(node.path));
4921 parent[key] = value;
4922 }
4923 return this.query(obj, this.stringify(path), 1).shift();
4924}
4925
4926JSONPath.prototype._vivify = function(obj, string, value) {
4927
4928 var self = this;
4929
4930 assert.ok(obj instanceof Object, "obj needs to be an object");
4931 assert.ok(string, "we need a path");
4932
4933 var path = this.parser.parse(string)
4934 .map(function(component) { return component.expression.value });
4935
4936 var setValue = function(path, value) {
4937 var key = path.pop();
4938 var node = self.value(obj, path);
4939 if (!node) {
4940 setValue(path.concat(), typeof key === 'string' ? {} : []);
4941 node = self.value(obj, path);
4942 }
4943 node[key] = value;
4944 }
4945 setValue(path, value);
4946 return this.query(obj, string)[0];
4947}
4948
4949JSONPath.prototype.query = function(obj, string, count) {
4950
4951 assert.ok(obj instanceof Object, "obj needs to be an object");
4952 assert.ok(_is_string(string), "we need a path");
4953
4954 var results = this.nodes(obj, string, count)
4955 .map(function(r) { return r.value });
4956
4957 return results;
4958};
4959
4960JSONPath.prototype.paths = function(obj, string, count) {
4961
4962 assert.ok(obj instanceof Object, "obj needs to be an object");
4963 assert.ok(string, "we need a path");
4964
4965 var results = this.nodes(obj, string, count)
4966 .map(function(r) { return r.path });
4967
4968 return results;
4969};
4970
4971JSONPath.prototype.nodes = function(obj, string, count) {
4972
4973 assert.ok(obj instanceof Object, "obj needs to be an object");
4974 assert.ok(string, "we need a path");
4975
4976 if (count === 0) return [];
4977
4978 var path = this.parser.parse(string);
4979 var handlers = this.handlers;
4980
4981 var partials = [ { path: ['$'], value: obj } ];
4982 var matches = [];
4983
4984 if (path.length && path[0].expression.type == 'root') path.shift();
4985
4986 if (!path.length) return partials;
4987
4988 path.forEach(function(component, index) {
4989
4990 if (matches.length >= count) return;
4991 var handler = handlers.resolve(component);
4992 var _partials = [];
4993
4994 partials.forEach(function(p) {
4995
4996 if (matches.length >= count) return;
4997 var results = handler(component, p, count);
4998
4999 if (index == path.length - 1) {
5000 // if we're through the components we're done
5001 matches = matches.concat(results || []);
5002 } else {
5003 // otherwise accumulate and carry on through
5004 _partials = _partials.concat(results || []);
5005 }
5006 });
5007
5008 partials = _partials;
5009
5010 });
5011
5012 return count ? matches.slice(0, count) : matches;
5013};
5014
5015JSONPath.prototype.stringify = function(path) {
5016
5017 assert.ok(path, "we need a path");
5018
5019 var string = '$';
5020
5021 var templates = {
5022 'descendant-member': '..{{value}}',
5023 'child-member': '.{{value}}',
5024 'descendant-subscript': '..[{{value}}]',
5025 'child-subscript': '[{{value}}]'
5026 };
5027
5028 path = this._normalize(path);
5029
5030 path.forEach(function(component) {
5031
5032 if (component.expression.type == 'root') return;
5033
5034 var key = [component.scope, component.operation].join('-');
5035 var template = templates[key];
5036 var value;
5037
5038 if (component.expression.type == 'string_literal') {
5039 value = JSON.stringify(component.expression.value)
5040 } else {
5041 value = component.expression.value;
5042 }
5043
5044 if (!template) throw new Error("couldn't find template " + key);
5045
5046 string += template.replace(/{{value}}/, value);
5047 });
5048
5049 return string;
5050}
5051
5052JSONPath.prototype._normalize = function(path) {
5053
5054 assert.ok(path, "we need a path");
5055
5056 if (typeof path == "string") {
5057
5058 return this.parser.parse(path);
5059
5060 } else if (Array.isArray(path) && typeof path[0] == "string") {
5061
5062 var _path = [ { expression: { type: "root", value: "$" } } ];
5063
5064 path.forEach(function(component, index) {
5065
5066 if (component == '$' && index === 0) return;
5067
5068 if (typeof component == "string" && component.match("^" + dict.identifier + "$")) {
5069
5070 _path.push({
5071 operation: 'member',
5072 scope: 'child',
5073 expression: { value: component, type: 'identifier' }
5074 });
5075
5076 } else {
5077
5078 var type = typeof component == "number" ?
5079 'numeric_literal' : 'string_literal';
5080
5081 _path.push({
5082 operation: 'subscript',
5083 scope: 'child',
5084 expression: { value: component, type: type }
5085 });
5086 }
5087 });
5088
5089 return _path;
5090
5091 } else if (Array.isArray(path) && typeof path[0] == "object") {
5092
5093 return path
5094 }
5095
5096 throw new Error("couldn't understand path " + path);
5097}
5098
5099function _is_string(obj) {
5100 return toString.call(obj) == '[object String]';
5101}
5102
5103JSONPath.Handlers = Handlers;
5104JSONPath.Parser = Parser;
5105
5106var instance = new JSONPath;
5107instance.JSONPath = JSONPath;
5108
5109module.exports = instance;
5110
5111},{"./dict":2,"./handlers":4,"./parser":6,"assert":8}],6:[function(require,module,exports){
5112var grammar = require('./grammar');
5113var gparser = require('../generated/parser');
5114
5115var Parser = function() {
5116
5117 var parser = new gparser.Parser();
5118
5119 var _parseError = parser.parseError;
5120 parser.yy.parseError = function() {
5121 if (parser.yy.ast) {
5122 parser.yy.ast.initialize();
5123 }
5124 _parseError.apply(parser, arguments);
5125 }
5126
5127 return parser;
5128
5129};
5130
5131Parser.grammar = grammar;
5132module.exports = Parser;
5133
5134},{"../generated/parser":1,"./grammar":3}],7:[function(require,module,exports){
5135module.exports = function(arr, start, end, step) {
5136
5137 var len = arr.length;
5138
5139 if (step === 0) throw new Error("step cannot be zero");
5140 step = step ? integer(step) : 1;
5141
5142 // normalize negative values
5143 start = start < 0 ? len + start : start;
5144 end = end < 0 ? len + end : end;
5145
5146 // default extents to extents
5147 start = integer(start === 0 ? 0 : !start ? (step > 0 ? 0 : len - 1) : start);
5148 end = integer(end === 0 ? 0 : !end ? (step > 0 ? len : -1) : end);
5149
5150 // clamp extents
5151 start = step > 0 ? Math.max(0, start) : Math.min(len, start);
5152 end = step > 0 ? Math.min(end, len) : Math.max(-1, end);
5153
5154 // return empty if extents are backwards
5155 if (step > 0 && end <= start) return [];
5156 if (step < 0 && start <= end) return [];
5157
5158 var result = [];
5159
5160 for (var i = start; i != end; i += step) {
5161 if ((step < 0 && i <= end) || (step > 0 && i >= end)) break;
5162 result.push(arr[i]);
5163 }
5164
5165 return result;
5166}
5167
5168function integer(val) {
5169 return String(val).match(/^[0-9]+$/) ? parseInt(val) :
5170 Number.isFinite(val) ? parseInt(val, 10) : 0;
5171}
5172
5173},{}],8:[function(require,module,exports){
5174// http://wiki.commonjs.org/wiki/Unit_Testing/1.0
5175//
5176// THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8!
5177//
5178// Originally from narwhal.js (http://narwhaljs.org)
5179// Copyright (c) 2009 Thomas Robinson <280north.com>
5180//
5181// Permission is hereby granted, free of charge, to any person obtaining a copy
5182// of this software and associated documentation files (the 'Software'), to
5183// deal in the Software without restriction, including without limitation the
5184// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
5185// sell copies of the Software, and to permit persons to whom the Software is
5186// furnished to do so, subject to the following conditions:
5187//
5188// The above copyright notice and this permission notice shall be included in
5189// all copies or substantial portions of the Software.
5190//
5191// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5192// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
5193// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
5194// AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
5195// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
5196// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5197
5198// when used in node, this will actually load the util module we depend on
5199// versus loading the builtin util module as happens otherwise
5200// this is a bug in node module loading as far as I am concerned
5201var util = require('util/');
5202
5203var pSlice = Array.prototype.slice;
5204var hasOwn = Object.prototype.hasOwnProperty;
5205
5206// 1. The assert module provides functions that throw
5207// AssertionError's when particular conditions are not met. The
5208// assert module must conform to the following interface.
5209
5210var assert = module.exports = ok;
5211
5212// 2. The AssertionError is defined in assert.
5213// new assert.AssertionError({ message: message,
5214// actual: actual,
5215// expected: expected })
5216
5217assert.AssertionError = function AssertionError(options) {
5218 this.name = 'AssertionError';
5219 this.actual = options.actual;
5220 this.expected = options.expected;
5221 this.operator = options.operator;
5222 if (options.message) {
5223 this.message = options.message;
5224 this.generatedMessage = false;
5225 } else {
5226 this.message = getMessage(this);
5227 this.generatedMessage = true;
5228 }
5229 var stackStartFunction = options.stackStartFunction || fail;
5230
5231 if (Error.captureStackTrace) {
5232 Error.captureStackTrace(this, stackStartFunction);
5233 }
5234 else {
5235 // non v8 browsers so we can have a stacktrace
5236 var err = new Error();
5237 if (err.stack) {
5238 var out = err.stack;
5239
5240 // try to strip useless frames
5241 var fn_name = stackStartFunction.name;
5242 var idx = out.indexOf('\n' + fn_name);
5243 if (idx >= 0) {
5244 // once we have located the function frame
5245 // we need to strip out everything before it (and its line)
5246 var next_line = out.indexOf('\n', idx + 1);
5247 out = out.substring(next_line + 1);
5248 }
5249
5250 this.stack = out;
5251 }
5252 }
5253};
5254
5255// assert.AssertionError instanceof Error
5256util.inherits(assert.AssertionError, Error);
5257
5258function replacer(key, value) {
5259 if (util.isUndefined(value)) {
5260 return '' + value;
5261 }
5262 if (util.isNumber(value) && !isFinite(value)) {
5263 return value.toString();
5264 }
5265 if (util.isFunction(value) || util.isRegExp(value)) {
5266 return value.toString();
5267 }
5268 return value;
5269}
5270
5271function truncate(s, n) {
5272 if (util.isString(s)) {
5273 return s.length < n ? s : s.slice(0, n);
5274 } else {
5275 return s;
5276 }
5277}
5278
5279function getMessage(self) {
5280 return truncate(JSON.stringify(self.actual, replacer), 128) + ' ' +
5281 self.operator + ' ' +
5282 truncate(JSON.stringify(self.expected, replacer), 128);
5283}
5284
5285// At present only the three keys mentioned above are used and
5286// understood by the spec. Implementations or sub modules can pass
5287// other keys to the AssertionError's constructor - they will be
5288// ignored.
5289
5290// 3. All of the following functions must throw an AssertionError
5291// when a corresponding condition is not met, with a message that
5292// may be undefined if not provided. All assertion methods provide
5293// both the actual and expected values to the assertion error for
5294// display purposes.
5295
5296function fail(actual, expected, message, operator, stackStartFunction) {
5297 throw new assert.AssertionError({
5298 message: message,
5299 actual: actual,
5300 expected: expected,
5301 operator: operator,
5302 stackStartFunction: stackStartFunction
5303 });
5304}
5305
5306// EXTENSION! allows for well behaved errors defined elsewhere.
5307assert.fail = fail;
5308
5309// 4. Pure assertion tests whether a value is truthy, as determined
5310// by !!guard.
5311// assert.ok(guard, message_opt);
5312// This statement is equivalent to assert.equal(true, !!guard,
5313// message_opt);. To test strictly for the value true, use
5314// assert.strictEqual(true, guard, message_opt);.
5315
5316function ok(value, message) {
5317 if (!value) fail(value, true, message, '==', assert.ok);
5318}
5319assert.ok = ok;
5320
5321// 5. The equality assertion tests shallow, coercive equality with
5322// ==.
5323// assert.equal(actual, expected, message_opt);
5324
5325assert.equal = function equal(actual, expected, message) {
5326 if (actual != expected) fail(actual, expected, message, '==', assert.equal);
5327};
5328
5329// 6. The non-equality assertion tests for whether two objects are not equal
5330// with != assert.notEqual(actual, expected, message_opt);
5331
5332assert.notEqual = function notEqual(actual, expected, message) {
5333 if (actual == expected) {
5334 fail(actual, expected, message, '!=', assert.notEqual);
5335 }
5336};
5337
5338// 7. The equivalence assertion tests a deep equality relation.
5339// assert.deepEqual(actual, expected, message_opt);
5340
5341assert.deepEqual = function deepEqual(actual, expected, message) {
5342 if (!_deepEqual(actual, expected)) {
5343 fail(actual, expected, message, 'deepEqual', assert.deepEqual);
5344 }
5345};
5346
5347function _deepEqual(actual, expected) {
5348 // 7.1. All identical values are equivalent, as determined by ===.
5349 if (actual === expected) {
5350 return true;
5351
5352 } else if (util.isBuffer(actual) && util.isBuffer(expected)) {
5353 if (actual.length != expected.length) return false;
5354
5355 for (var i = 0; i < actual.length; i++) {
5356 if (actual[i] !== expected[i]) return false;
5357 }
5358
5359 return true;
5360
5361 // 7.2. If the expected value is a Date object, the actual value is
5362 // equivalent if it is also a Date object that refers to the same time.
5363 } else if (util.isDate(actual) && util.isDate(expected)) {
5364 return actual.getTime() === expected.getTime();
5365
5366 // 7.3 If the expected value is a RegExp object, the actual value is
5367 // equivalent if it is also a RegExp object with the same source and
5368 // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`).
5369 } else if (util.isRegExp(actual) && util.isRegExp(expected)) {
5370 return actual.source === expected.source &&
5371 actual.global === expected.global &&
5372 actual.multiline === expected.multiline &&
5373 actual.lastIndex === expected.lastIndex &&
5374 actual.ignoreCase === expected.ignoreCase;
5375
5376 // 7.4. Other pairs that do not both pass typeof value == 'object',
5377 // equivalence is determined by ==.
5378 } else if (!util.isObject(actual) && !util.isObject(expected)) {
5379 return actual == expected;
5380
5381 // 7.5 For all other Object pairs, including Array objects, equivalence is
5382 // determined by having the same number of owned properties (as verified
5383 // with Object.prototype.hasOwnProperty.call), the same set of keys
5384 // (although not necessarily the same order), equivalent values for every
5385 // corresponding key, and an identical 'prototype' property. Note: this
5386 // accounts for both named and indexed properties on Arrays.
5387 } else {
5388 return objEquiv(actual, expected);
5389 }
5390}
5391
5392function isArguments(object) {
5393 return Object.prototype.toString.call(object) == '[object Arguments]';
5394}
5395
5396function objEquiv(a, b) {
5397 if (util.isNullOrUndefined(a) || util.isNullOrUndefined(b))
5398 return false;
5399 // an identical 'prototype' property.
5400 if (a.prototype !== b.prototype) return false;
5401 // if one is a primitive, the other must be same
5402 if (util.isPrimitive(a) || util.isPrimitive(b)) {
5403 return a === b;
5404 }
5405 var aIsArgs = isArguments(a),
5406 bIsArgs = isArguments(b);
5407 if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs))
5408 return false;
5409 if (aIsArgs) {
5410 a = pSlice.call(a);
5411 b = pSlice.call(b);
5412 return _deepEqual(a, b);
5413 }
5414 var ka = objectKeys(a),
5415 kb = objectKeys(b),
5416 key, i;
5417 // having the same number of owned properties (keys incorporates
5418 // hasOwnProperty)
5419 if (ka.length != kb.length)
5420 return false;
5421 //the same set of keys (although not necessarily the same order),
5422 ka.sort();
5423 kb.sort();
5424 //~~~cheap key test
5425 for (i = ka.length - 1; i >= 0; i--) {
5426 if (ka[i] != kb[i])
5427 return false;
5428 }
5429 //equivalent values for every corresponding key, and
5430 //~~~possibly expensive deep test
5431 for (i = ka.length - 1; i >= 0; i--) {
5432 key = ka[i];
5433 if (!_deepEqual(a[key], b[key])) return false;
5434 }
5435 return true;
5436}
5437
5438// 8. The non-equivalence assertion tests for any deep inequality.
5439// assert.notDeepEqual(actual, expected, message_opt);
5440
5441assert.notDeepEqual = function notDeepEqual(actual, expected, message) {
5442 if (_deepEqual(actual, expected)) {
5443 fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual);
5444 }
5445};
5446
5447// 9. The strict equality assertion tests strict equality, as determined by ===.
5448// assert.strictEqual(actual, expected, message_opt);
5449
5450assert.strictEqual = function strictEqual(actual, expected, message) {
5451 if (actual !== expected) {
5452 fail(actual, expected, message, '===', assert.strictEqual);
5453 }
5454};
5455
5456// 10. The strict non-equality assertion tests for strict inequality, as
5457// determined by !==. assert.notStrictEqual(actual, expected, message_opt);
5458
5459assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
5460 if (actual === expected) {
5461 fail(actual, expected, message, '!==', assert.notStrictEqual);
5462 }
5463};
5464
5465function expectedException(actual, expected) {
5466 if (!actual || !expected) {
5467 return false;
5468 }
5469
5470 if (Object.prototype.toString.call(expected) == '[object RegExp]') {
5471 return expected.test(actual);
5472 } else if (actual instanceof expected) {
5473 return true;
5474 } else if (expected.call({}, actual) === true) {
5475 return true;
5476 }
5477
5478 return false;
5479}
5480
5481function _throws(shouldThrow, block, expected, message) {
5482 var actual;
5483
5484 if (util.isString(expected)) {
5485 message = expected;
5486 expected = null;
5487 }
5488
5489 try {
5490 block();
5491 } catch (e) {
5492 actual = e;
5493 }
5494
5495 message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
5496 (message ? ' ' + message : '.');
5497
5498 if (shouldThrow && !actual) {
5499 fail(actual, expected, 'Missing expected exception' + message);
5500 }
5501
5502 if (!shouldThrow && expectedException(actual, expected)) {
5503 fail(actual, expected, 'Got unwanted exception' + message);
5504 }
5505
5506 if ((shouldThrow && actual && expected &&
5507 !expectedException(actual, expected)) || (!shouldThrow && actual)) {
5508 throw actual;
5509 }
5510}
5511
5512// 11. Expected to throw an error:
5513// assert.throws(block, Error_opt, message_opt);
5514
5515assert.throws = function(block, /*optional*/error, /*optional*/message) {
5516 _throws.apply(this, [true].concat(pSlice.call(arguments)));
5517};
5518
5519// EXTENSION! This is annoying to write outside this module.
5520assert.doesNotThrow = function(block, /*optional*/message) {
5521 _throws.apply(this, [false].concat(pSlice.call(arguments)));
5522};
5523
5524assert.ifError = function(err) { if (err) {throw err;}};
5525
5526var objectKeys = Object.keys || function (obj) {
5527 var keys = [];
5528 for (var key in obj) {
5529 if (hasOwn.call(obj, key)) keys.push(key);
5530 }
5531 return keys;
5532};
5533
5534},{"util/":15}],9:[function(require,module,exports){
5535
5536},{}],10:[function(require,module,exports){
5537if (typeof Object.create === 'function') {
5538 // implementation from standard node.js 'util' module
5539 module.exports = function inherits(ctor, superCtor) {
5540 ctor.super_ = superCtor
5541 ctor.prototype = Object.create(superCtor.prototype, {
5542 constructor: {
5543 value: ctor,
5544 enumerable: false,
5545 writable: true,
5546 configurable: true
5547 }
5548 });
5549 };
5550} else {
5551 // old school shim for old browsers
5552 module.exports = function inherits(ctor, superCtor) {
5553 ctor.super_ = superCtor
5554 var TempCtor = function () {}
5555 TempCtor.prototype = superCtor.prototype
5556 ctor.prototype = new TempCtor()
5557 ctor.prototype.constructor = ctor
5558 }
5559}
5560
5561},{}],11:[function(require,module,exports){
5562(function (process){
5563// Copyright Joyent, Inc. and other Node contributors.
5564//
5565// Permission is hereby granted, free of charge, to any person obtaining a
5566// copy of this software and associated documentation files (the
5567// "Software"), to deal in the Software without restriction, including
5568// without limitation the rights to use, copy, modify, merge, publish,
5569// distribute, sublicense, and/or sell copies of the Software, and to permit
5570// persons to whom the Software is furnished to do so, subject to the
5571// following conditions:
5572//
5573// The above copyright notice and this permission notice shall be included
5574// in all copies or substantial portions of the Software.
5575//
5576// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
5577// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
5578// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
5579// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
5580// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
5581// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
5582// USE OR OTHER DEALINGS IN THE SOFTWARE.
5583
5584// resolves . and .. elements in a path array with directory names there
5585// must be no slashes, empty elements, or device names (c:\) in the array
5586// (so also no leading and trailing slashes - it does not distinguish
5587// relative and absolute paths)
5588function normalizeArray(parts, allowAboveRoot) {
5589 // if the path tries to go above the root, `up` ends up > 0
5590 var up = 0;
5591 for (var i = parts.length - 1; i >= 0; i--) {
5592 var last = parts[i];
5593 if (last === '.') {
5594 parts.splice(i, 1);
5595 } else if (last === '..') {
5596 parts.splice(i, 1);
5597 up++;
5598 } else if (up) {
5599 parts.splice(i, 1);
5600 up--;
5601 }
5602 }
5603
5604 // if the path is allowed to go above the root, restore leading ..s
5605 if (allowAboveRoot) {
5606 for (; up--; up) {
5607 parts.unshift('..');
5608 }
5609 }
5610
5611 return parts;
5612}
5613
5614// Split a filename into [root, dir, basename, ext], unix version
5615// 'root' is just a slash, or nothing.
5616var splitPathRe =
5617 /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
5618var splitPath = function(filename) {
5619 return splitPathRe.exec(filename).slice(1);
5620};
5621
5622// path.resolve([from ...], to)
5623// posix version
5624exports.resolve = function() {
5625 var resolvedPath = '',
5626 resolvedAbsolute = false;
5627
5628 for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
5629 var path = (i >= 0) ? arguments[i] : process.cwd();
5630
5631 // Skip empty and invalid entries
5632 if (typeof path !== 'string') {
5633 throw new TypeError('Arguments to path.resolve must be strings');
5634 } else if (!path) {
5635 continue;
5636 }
5637
5638 resolvedPath = path + '/' + resolvedPath;
5639 resolvedAbsolute = path.charAt(0) === '/';
5640 }
5641
5642 // At this point the path should be resolved to a full absolute path, but
5643 // handle relative paths to be safe (might happen when process.cwd() fails)
5644
5645 // Normalize the path
5646 resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
5647 return !!p;
5648 }), !resolvedAbsolute).join('/');
5649
5650 return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
5651};
5652
5653// path.normalize(path)
5654// posix version
5655exports.normalize = function(path) {
5656 var isAbsolute = exports.isAbsolute(path),
5657 trailingSlash = substr(path, -1) === '/';
5658
5659 // Normalize the path
5660 path = normalizeArray(filter(path.split('/'), function(p) {
5661 return !!p;
5662 }), !isAbsolute).join('/');
5663
5664 if (!path && !isAbsolute) {
5665 path = '.';
5666 }
5667 if (path && trailingSlash) {
5668 path += '/';
5669 }
5670
5671 return (isAbsolute ? '/' : '') + path;
5672};
5673
5674// posix version
5675exports.isAbsolute = function(path) {
5676 return path.charAt(0) === '/';
5677};
5678
5679// posix version
5680exports.join = function() {
5681 var paths = Array.prototype.slice.call(arguments, 0);
5682 return exports.normalize(filter(paths, function(p, index) {
5683 if (typeof p !== 'string') {
5684 throw new TypeError('Arguments to path.join must be strings');
5685 }
5686 return p;
5687 }).join('/'));
5688};
5689
5690
5691// path.relative(from, to)
5692// posix version
5693exports.relative = function(from, to) {
5694 from = exports.resolve(from).substr(1);
5695 to = exports.resolve(to).substr(1);
5696
5697 function trim(arr) {
5698 var start = 0;
5699 for (; start < arr.length; start++) {
5700 if (arr[start] !== '') break;
5701 }
5702
5703 var end = arr.length - 1;
5704 for (; end >= 0; end--) {
5705 if (arr[end] !== '') break;
5706 }
5707
5708 if (start > end) return [];
5709 return arr.slice(start, end - start + 1);
5710 }
5711
5712 var fromParts = trim(from.split('/'));
5713 var toParts = trim(to.split('/'));
5714
5715 var length = Math.min(fromParts.length, toParts.length);
5716 var samePartsLength = length;
5717 for (var i = 0; i < length; i++) {
5718 if (fromParts[i] !== toParts[i]) {
5719 samePartsLength = i;
5720 break;
5721 }
5722 }
5723
5724 var outputParts = [];
5725 for (var i = samePartsLength; i < fromParts.length; i++) {
5726 outputParts.push('..');
5727 }
5728
5729 outputParts = outputParts.concat(toParts.slice(samePartsLength));
5730
5731 return outputParts.join('/');
5732};
5733
5734exports.sep = '/';
5735exports.delimiter = ':';
5736
5737exports.dirname = function(path) {
5738 var result = splitPath(path),
5739 root = result[0],
5740 dir = result[1];
5741
5742 if (!root && !dir) {
5743 // No dirname whatsoever
5744 return '.';
5745 }
5746
5747 if (dir) {
5748 // It has a dirname, strip trailing slash
5749 dir = dir.substr(0, dir.length - 1);
5750 }
5751
5752 return root + dir;
5753};
5754
5755
5756exports.basename = function(path, ext) {
5757 var f = splitPath(path)[2];
5758 // TODO: make this comparison case-insensitive on windows?
5759 if (ext && f.substr(-1 * ext.length) === ext) {
5760 f = f.substr(0, f.length - ext.length);
5761 }
5762 return f;
5763};
5764
5765
5766exports.extname = function(path) {
5767 return splitPath(path)[3];
5768};
5769
5770function filter (xs, f) {
5771 if (xs.filter) return xs.filter(f);
5772 var res = [];
5773 for (var i = 0; i < xs.length; i++) {
5774 if (f(xs[i], i, xs)) res.push(xs[i]);
5775 }
5776 return res;
5777}
5778
5779// String.prototype.substr - negative index don't work in IE8
5780var substr = 'ab'.substr(-1) === 'b'
5781 ? function (str, start, len) { return str.substr(start, len) }
5782 : function (str, start, len) {
5783 if (start < 0) start = str.length + start;
5784 return str.substr(start, len);
5785 }
5786;
5787
5788}).call(this,require('_process'))
5789},{"_process":12}],12:[function(require,module,exports){
5790// shim for using process in browser
5791
5792var process = module.exports = {};
5793var queue = [];
5794var draining = false;
5795var currentQueue;
5796var queueIndex = -1;
5797
5798function cleanUpNextTick() {
5799 if (!draining || !currentQueue) {
5800 return;
5801 }
5802 draining = false;
5803 if (currentQueue.length) {
5804 queue = currentQueue.concat(queue);
5805 } else {
5806 queueIndex = -1;
5807 }
5808 if (queue.length) {
5809 drainQueue();
5810 }
5811}
5812
5813function drainQueue() {
5814 if (draining) {
5815 return;
5816 }
5817 var timeout = setTimeout(cleanUpNextTick);
5818 draining = true;
5819
5820 var len = queue.length;
5821 while(len) {
5822 currentQueue = queue;
5823 queue = [];
5824 while (++queueIndex < len) {
5825 if (currentQueue) {
5826 currentQueue[queueIndex].run();
5827 }
5828 }
5829 queueIndex = -1;
5830 len = queue.length;
5831 }
5832 currentQueue = null;
5833 draining = false;
5834 clearTimeout(timeout);
5835}
5836
5837process.nextTick = function (fun) {
5838 var args = new Array(arguments.length - 1);
5839 if (arguments.length > 1) {
5840 for (var i = 1; i < arguments.length; i++) {
5841 args[i - 1] = arguments[i];
5842 }
5843 }
5844 queue.push(new Item(fun, args));
5845 if (queue.length === 1 && !draining) {
5846 setTimeout(drainQueue, 0);
5847 }
5848};
5849
5850// v8 likes predictible objects
5851function Item(fun, array) {
5852 this.fun = fun;
5853 this.array = array;
5854}
5855Item.prototype.run = function () {
5856 this.fun.apply(null, this.array);
5857};
5858process.title = 'browser';
5859process.browser = true;
5860process.env = {};
5861process.argv = [];
5862process.version = ''; // empty string to avoid regexp issues
5863process.versions = {};
5864
5865function noop() {}
5866
5867process.on = noop;
5868process.addListener = noop;
5869process.once = noop;
5870process.off = noop;
5871process.removeListener = noop;
5872process.removeAllListeners = noop;
5873process.emit = noop;
5874
5875process.binding = function (name) {
5876 throw new Error('process.binding is not supported');
5877};
5878
5879process.cwd = function () { return '/' };
5880process.chdir = function (dir) {
5881 throw new Error('process.chdir is not supported');
5882};
5883process.umask = function() { return 0; };
5884
5885},{}],13:[function(require,module,exports){
5886var unparse = require('escodegen').generate;
5887
5888module.exports = function (ast, vars) {
5889 if (!vars) vars = {};
5890 var FAIL = {};
5891
5892 var result = (function walk (node) {
5893 if (node.type === 'Literal') {
5894 return node.value;
5895 }
5896 else if (node.type === 'UnaryExpression'){
5897 var val = walk(node.argument)
5898 if (node.operator === '+') return +val
5899 if (node.operator === '-') return -val
5900 if (node.operator === '~') return ~val
5901 if (node.operator === '!') return !val
5902 return FAIL
5903 }
5904 else if (node.type === 'ArrayExpression') {
5905 var xs = [];
5906 for (var i = 0, l = node.elements.length; i < l; i++) {
5907 var x = walk(node.elements[i]);
5908 if (x === FAIL) return FAIL;
5909 xs.push(x);
5910 }
5911 return xs;
5912 }
5913 else if (node.type === 'ObjectExpression') {
5914 var obj = {};
5915 for (var i = 0; i < node.properties.length; i++) {
5916 var prop = node.properties[i];
5917 var value = prop.value === null
5918 ? prop.value
5919 : walk(prop.value)
5920 ;
5921 if (value === FAIL) return FAIL;
5922 obj[prop.key.value || prop.key.name] = value;
5923 }
5924 return obj;
5925 }
5926 else if (node.type === 'BinaryExpression' ||
5927 node.type === 'LogicalExpression') {
5928 var l = walk(node.left);
5929 if (l === FAIL) return FAIL;
5930 var r = walk(node.right);
5931 if (r === FAIL) return FAIL;
5932
5933 var op = node.operator;
5934 if (op === '==') return l == r;
5935 if (op === '===') return l === r;
5936 if (op === '!=') return l != r;
5937 if (op === '!==') return l !== r;
5938 if (op === '+') return l + r;
5939 if (op === '-') return l - r;
5940 if (op === '*') return l * r;
5941 if (op === '/') return l / r;
5942 if (op === '%') return l % r;
5943 if (op === '<') return l < r;
5944 if (op === '<=') return l <= r;
5945 if (op === '>') return l > r;
5946 if (op === '>=') return l >= r;
5947 if (op === '|') return l | r;
5948 if (op === '&') return l & r;
5949 if (op === '^') return l ^ r;
5950 if (op === '&&') return l && r;
5951 if (op === '||') return l || r;
5952
5953 return FAIL;
5954 }
5955 else if (node.type === 'Identifier') {
5956 if ({}.hasOwnProperty.call(vars, node.name)) {
5957 return vars[node.name];
5958 }
5959 else return FAIL;
5960 }
5961 else if (node.type === 'CallExpression') {
5962 var callee = walk(node.callee);
5963 if (callee === FAIL) return FAIL;
5964
5965 var ctx = node.callee.object ? walk(node.callee.object) : FAIL;
5966 if (ctx === FAIL) ctx = null;
5967
5968 var args = [];
5969 for (var i = 0, l = node.arguments.length; i < l; i++) {
5970 var x = walk(node.arguments[i]);
5971 if (x === FAIL) return FAIL;
5972 args.push(x);
5973 }
5974 return callee.apply(ctx, args);
5975 }
5976 else if (node.type === 'MemberExpression') {
5977 var obj = walk(node.object);
5978 if (obj === FAIL) return FAIL;
5979 if (node.property.type === 'Identifier') {
5980 return obj[node.property.name];
5981 }
5982 var prop = walk(node.property);
5983 if (prop === FAIL) return FAIL;
5984 return obj[prop];
5985 }
5986 else if (node.type === 'ConditionalExpression') {
5987 var val = walk(node.test)
5988 if (val === FAIL) return FAIL;
5989 return val ? walk(node.consequent) : walk(node.alternate)
5990 }
5991 else if (node.type === 'FunctionExpression') {
5992 return Function('return ' + unparse(node))();
5993 }
5994 else return FAIL;
5995 })(ast);
5996
5997 return result === FAIL ? undefined : result;
5998};
5999
6000},{"escodegen":9}],14:[function(require,module,exports){
6001module.exports = function isBuffer(arg) {
6002 return arg && typeof arg === 'object'
6003 && typeof arg.copy === 'function'
6004 && typeof arg.fill === 'function'
6005 && typeof arg.readUInt8 === 'function';
6006}
6007},{}],15:[function(require,module,exports){
6008(function (process,global){
6009// Copyright Joyent, Inc. and other Node contributors.
6010//
6011// Permission is hereby granted, free of charge, to any person obtaining a
6012// copy of this software and associated documentation files (the
6013// "Software"), to deal in the Software without restriction, including
6014// without limitation the rights to use, copy, modify, merge, publish,
6015// distribute, sublicense, and/or sell copies of the Software, and to permit
6016// persons to whom the Software is furnished to do so, subject to the
6017// following conditions:
6018//
6019// The above copyright notice and this permission notice shall be included
6020// in all copies or substantial portions of the Software.
6021//
6022// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
6023// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
6024// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
6025// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
6026// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
6027// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
6028// USE OR OTHER DEALINGS IN THE SOFTWARE.
6029
6030var formatRegExp = /%[sdj%]/g;
6031exports.format = function(f) {
6032 if (!isString(f)) {
6033 var objects = [];
6034 for (var i = 0; i < arguments.length; i++) {
6035 objects.push(inspect(arguments[i]));
6036 }
6037 return objects.join(' ');
6038 }
6039
6040 var i = 1;
6041 var args = arguments;
6042 var len = args.length;
6043 var str = String(f).replace(formatRegExp, function(x) {
6044 if (x === '%%') return '%';
6045 if (i >= len) return x;
6046 switch (x) {
6047 case '%s': return String(args[i++]);
6048 case '%d': return Number(args[i++]);
6049 case '%j':
6050 try {
6051 return JSON.stringify(args[i++]);
6052 } catch (_) {
6053 return '[Circular]';
6054 }
6055 default:
6056 return x;
6057 }
6058 });
6059 for (var x = args[i]; i < len; x = args[++i]) {
6060 if (isNull(x) || !isObject(x)) {
6061 str += ' ' + x;
6062 } else {
6063 str += ' ' + inspect(x);
6064 }
6065 }
6066 return str;
6067};
6068
6069
6070// Mark that a method should not be used.
6071// Returns a modified function which warns once by default.
6072// If --no-deprecation is set, then it is a no-op.
6073exports.deprecate = function(fn, msg) {
6074 // Allow for deprecating things in the process of starting up.
6075 if (isUndefined(global.process)) {
6076 return function() {
6077 return exports.deprecate(fn, msg).apply(this, arguments);
6078 };
6079 }
6080
6081 if (process.noDeprecation === true) {
6082 return fn;
6083 }
6084
6085 var warned = false;
6086 function deprecated() {
6087 if (!warned) {
6088 if (process.throwDeprecation) {
6089 throw new Error(msg);
6090 } else if (process.traceDeprecation) {
6091 console.trace(msg);
6092 } else {
6093 console.error(msg);
6094 }
6095 warned = true;
6096 }
6097 return fn.apply(this, arguments);
6098 }
6099
6100 return deprecated;
6101};
6102
6103
6104var debugs = {};
6105var debugEnviron;
6106exports.debuglog = function(set) {
6107 if (isUndefined(debugEnviron))
6108 debugEnviron = process.env.NODE_DEBUG || '';
6109 set = set.toUpperCase();
6110 if (!debugs[set]) {
6111 if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
6112 var pid = process.pid;
6113 debugs[set] = function() {
6114 var msg = exports.format.apply(exports, arguments);
6115 console.error('%s %d: %s', set, pid, msg);
6116 };
6117 } else {
6118 debugs[set] = function() {};
6119 }
6120 }
6121 return debugs[set];
6122};
6123
6124
6125/**
6126 * Echos the value of a value. Trys to print the value out
6127 * in the best way possible given the different types.
6128 *
6129 * @param {Object} obj The object to print out.
6130 * @param {Object} opts Optional options object that alters the output.
6131 */
6132/* legacy: obj, showHidden, depth, colors*/
6133function inspect(obj, opts) {
6134 // default options
6135 var ctx = {
6136 seen: [],
6137 stylize: stylizeNoColor
6138 };
6139 // legacy...
6140 if (arguments.length >= 3) ctx.depth = arguments[2];
6141 if (arguments.length >= 4) ctx.colors = arguments[3];
6142 if (isBoolean(opts)) {
6143 // legacy...
6144 ctx.showHidden = opts;
6145 } else if (opts) {
6146 // got an "options" object
6147 exports._extend(ctx, opts);
6148 }
6149 // set default options
6150 if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
6151 if (isUndefined(ctx.depth)) ctx.depth = 2;
6152 if (isUndefined(ctx.colors)) ctx.colors = false;
6153 if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
6154 if (ctx.colors) ctx.stylize = stylizeWithColor;
6155 return formatValue(ctx, obj, ctx.depth);
6156}
6157exports.inspect = inspect;
6158
6159
6160// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
6161inspect.colors = {
6162 'bold' : [1, 22],
6163 'italic' : [3, 23],
6164 'underline' : [4, 24],
6165 'inverse' : [7, 27],
6166 'white' : [37, 39],
6167 'grey' : [90, 39],
6168 'black' : [30, 39],
6169 'blue' : [34, 39],
6170 'cyan' : [36, 39],
6171 'green' : [32, 39],
6172 'magenta' : [35, 39],
6173 'red' : [31, 39],
6174 'yellow' : [33, 39]
6175};
6176
6177// Don't use 'blue' not visible on cmd.exe
6178inspect.styles = {
6179 'special': 'cyan',
6180 'number': 'yellow',
6181 'boolean': 'yellow',
6182 'undefined': 'grey',
6183 'null': 'bold',
6184 'string': 'green',
6185 'date': 'magenta',
6186 // "name": intentionally not styling
6187 'regexp': 'red'
6188};
6189
6190
6191function stylizeWithColor(str, styleType) {
6192 var style = inspect.styles[styleType];
6193
6194 if (style) {
6195 return '\u001b[' + inspect.colors[style][0] + 'm' + str +
6196 '\u001b[' + inspect.colors[style][1] + 'm';
6197 } else {
6198 return str;
6199 }
6200}
6201
6202
6203function stylizeNoColor(str, styleType) {
6204 return str;
6205}
6206
6207
6208function arrayToHash(array) {
6209 var hash = {};
6210
6211 array.forEach(function(val, idx) {
6212 hash[val] = true;
6213 });
6214
6215 return hash;
6216}
6217
6218
6219function formatValue(ctx, value, recurseTimes) {
6220 // Provide a hook for user-specified inspect functions.
6221 // Check that value is an object with an inspect function on it
6222 if (ctx.customInspect &&
6223 value &&
6224 isFunction(value.inspect) &&
6225 // Filter out the util module, it's inspect function is special
6226 value.inspect !== exports.inspect &&
6227 // Also filter out any prototype objects using the circular check.
6228 !(value.constructor && value.constructor.prototype === value)) {
6229 var ret = value.inspect(recurseTimes, ctx);
6230 if (!isString(ret)) {
6231 ret = formatValue(ctx, ret, recurseTimes);
6232 }
6233 return ret;
6234 }
6235
6236 // Primitive types cannot have properties
6237 var primitive = formatPrimitive(ctx, value);
6238 if (primitive) {
6239 return primitive;
6240 }
6241
6242 // Look up the keys of the object.
6243 var keys = Object.keys(value);
6244 var visibleKeys = arrayToHash(keys);
6245
6246 if (ctx.showHidden) {
6247 keys = Object.getOwnPropertyNames(value);
6248 }
6249
6250 // IE doesn't make error fields non-enumerable
6251 // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
6252 if (isError(value)
6253 && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
6254 return formatError(value);
6255 }
6256
6257 // Some type of object without properties can be shortcutted.
6258 if (keys.length === 0) {
6259 if (isFunction(value)) {
6260 var name = value.name ? ': ' + value.name : '';
6261 return ctx.stylize('[Function' + name + ']', 'special');
6262 }
6263 if (isRegExp(value)) {
6264 return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
6265 }
6266 if (isDate(value)) {
6267 return ctx.stylize(Date.prototype.toString.call(value), 'date');
6268 }
6269 if (isError(value)) {
6270 return formatError(value);
6271 }
6272 }
6273
6274 var base = '', array = false, braces = ['{', '}'];
6275
6276 // Make Array say that they are Array
6277 if (isArray(value)) {
6278 array = true;
6279 braces = ['[', ']'];
6280 }
6281
6282 // Make functions say that they are functions
6283 if (isFunction(value)) {
6284 var n = value.name ? ': ' + value.name : '';
6285 base = ' [Function' + n + ']';
6286 }
6287
6288 // Make RegExps say that they are RegExps
6289 if (isRegExp(value)) {
6290 base = ' ' + RegExp.prototype.toString.call(value);
6291 }
6292
6293 // Make dates with properties first say the date
6294 if (isDate(value)) {
6295 base = ' ' + Date.prototype.toUTCString.call(value);
6296 }
6297
6298 // Make error with message first say the error
6299 if (isError(value)) {
6300 base = ' ' + formatError(value);
6301 }
6302
6303 if (keys.length === 0 && (!array || value.length == 0)) {
6304 return braces[0] + base + braces[1];
6305 }
6306
6307 if (recurseTimes < 0) {
6308 if (isRegExp(value)) {
6309 return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
6310 } else {
6311 return ctx.stylize('[Object]', 'special');
6312 }
6313 }
6314
6315 ctx.seen.push(value);
6316
6317 var output;
6318 if (array) {
6319 output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
6320 } else {
6321 output = keys.map(function(key) {
6322 return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
6323 });
6324 }
6325
6326 ctx.seen.pop();
6327
6328 return reduceToSingleString(output, base, braces);
6329}
6330
6331
6332function formatPrimitive(ctx, value) {
6333 if (isUndefined(value))
6334 return ctx.stylize('undefined', 'undefined');
6335 if (isString(value)) {
6336 var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
6337 .replace(/'/g, "\\'")
6338 .replace(/\\"/g, '"') + '\'';
6339 return ctx.stylize(simple, 'string');
6340 }
6341 if (isNumber(value))
6342 return ctx.stylize('' + value, 'number');
6343 if (isBoolean(value))
6344 return ctx.stylize('' + value, 'boolean');
6345 // For some reason typeof null is "object", so special case here.
6346 if (isNull(value))
6347 return ctx.stylize('null', 'null');
6348}
6349
6350
6351function formatError(value) {
6352 return '[' + Error.prototype.toString.call(value) + ']';
6353}
6354
6355
6356function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
6357 var output = [];
6358 for (var i = 0, l = value.length; i < l; ++i) {
6359 if (hasOwnProperty(value, String(i))) {
6360 output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
6361 String(i), true));
6362 } else {
6363 output.push('');
6364 }
6365 }
6366 keys.forEach(function(key) {
6367 if (!key.match(/^\d+$/)) {
6368 output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
6369 key, true));
6370 }
6371 });
6372 return output;
6373}
6374
6375
6376function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
6377 var name, str, desc;
6378 desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
6379 if (desc.get) {
6380 if (desc.set) {
6381 str = ctx.stylize('[Getter/Setter]', 'special');
6382 } else {
6383 str = ctx.stylize('[Getter]', 'special');
6384 }
6385 } else {
6386 if (desc.set) {
6387 str = ctx.stylize('[Setter]', 'special');
6388 }
6389 }
6390 if (!hasOwnProperty(visibleKeys, key)) {
6391 name = '[' + key + ']';
6392 }
6393 if (!str) {
6394 if (ctx.seen.indexOf(desc.value) < 0) {
6395 if (isNull(recurseTimes)) {
6396 str = formatValue(ctx, desc.value, null);
6397 } else {
6398 str = formatValue(ctx, desc.value, recurseTimes - 1);
6399 }
6400 if (str.indexOf('\n') > -1) {
6401 if (array) {
6402 str = str.split('\n').map(function(line) {
6403 return ' ' + line;
6404 }).join('\n').substr(2);
6405 } else {
6406 str = '\n' + str.split('\n').map(function(line) {
6407 return ' ' + line;
6408 }).join('\n');
6409 }
6410 }
6411 } else {
6412 str = ctx.stylize('[Circular]', 'special');
6413 }
6414 }
6415 if (isUndefined(name)) {
6416 if (array && key.match(/^\d+$/)) {
6417 return str;
6418 }
6419 name = JSON.stringify('' + key);
6420 if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
6421 name = name.substr(1, name.length - 2);
6422 name = ctx.stylize(name, 'name');
6423 } else {
6424 name = name.replace(/'/g, "\\'")
6425 .replace(/\\"/g, '"')
6426 .replace(/(^"|"$)/g, "'");
6427 name = ctx.stylize(name, 'string');
6428 }
6429 }
6430
6431 return name + ': ' + str;
6432}
6433
6434
6435function reduceToSingleString(output, base, braces) {
6436 var numLinesEst = 0;
6437 var length = output.reduce(function(prev, cur) {
6438 numLinesEst++;
6439 if (cur.indexOf('\n') >= 0) numLinesEst++;
6440 return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
6441 }, 0);
6442
6443 if (length > 60) {
6444 return braces[0] +
6445 (base === '' ? '' : base + '\n ') +
6446 ' ' +
6447 output.join(',\n ') +
6448 ' ' +
6449 braces[1];
6450 }
6451
6452 return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
6453}
6454
6455
6456// NOTE: These type checking functions intentionally don't use `instanceof`
6457// because it is fragile and can be easily faked with `Object.create()`.
6458function isArray(ar) {
6459 return Array.isArray(ar);
6460}
6461exports.isArray = isArray;
6462
6463function isBoolean(arg) {
6464 return typeof arg === 'boolean';
6465}
6466exports.isBoolean = isBoolean;
6467
6468function isNull(arg) {
6469 return arg === null;
6470}
6471exports.isNull = isNull;
6472
6473function isNullOrUndefined(arg) {
6474 return arg == null;
6475}
6476exports.isNullOrUndefined = isNullOrUndefined;
6477
6478function isNumber(arg) {
6479 return typeof arg === 'number';
6480}
6481exports.isNumber = isNumber;
6482
6483function isString(arg) {
6484 return typeof arg === 'string';
6485}
6486exports.isString = isString;
6487
6488function isSymbol(arg) {
6489 return typeof arg === 'symbol';
6490}
6491exports.isSymbol = isSymbol;
6492
6493function isUndefined(arg) {
6494 return arg === void 0;
6495}
6496exports.isUndefined = isUndefined;
6497
6498function isRegExp(re) {
6499 return isObject(re) && objectToString(re) === '[object RegExp]';
6500}
6501exports.isRegExp = isRegExp;
6502
6503function isObject(arg) {
6504 return typeof arg === 'object' && arg !== null;
6505}
6506exports.isObject = isObject;
6507
6508function isDate(d) {
6509 return isObject(d) && objectToString(d) === '[object Date]';
6510}
6511exports.isDate = isDate;
6512
6513function isError(e) {
6514 return isObject(e) &&
6515 (objectToString(e) === '[object Error]' || e instanceof Error);
6516}
6517exports.isError = isError;
6518
6519function isFunction(arg) {
6520 return typeof arg === 'function';
6521}
6522exports.isFunction = isFunction;
6523
6524function isPrimitive(arg) {
6525 return arg === null ||
6526 typeof arg === 'boolean' ||
6527 typeof arg === 'number' ||
6528 typeof arg === 'string' ||
6529 typeof arg === 'symbol' || // ES6 symbol
6530 typeof arg === 'undefined';
6531}
6532exports.isPrimitive = isPrimitive;
6533
6534exports.isBuffer = require('./support/isBuffer');
6535
6536function objectToString(o) {
6537 return Object.prototype.toString.call(o);
6538}
6539
6540
6541function pad(n) {
6542 return n < 10 ? '0' + n.toString(10) : n.toString(10);
6543}
6544
6545
6546var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
6547 'Oct', 'Nov', 'Dec'];
6548
6549// 26 Feb 16:19:34
6550function timestamp() {
6551 var d = new Date();
6552 var time = [pad(d.getHours()),
6553 pad(d.getMinutes()),
6554 pad(d.getSeconds())].join(':');
6555 return [d.getDate(), months[d.getMonth()], time].join(' ');
6556}
6557
6558
6559// log is just a thin wrapper to console.log that prepends a timestamp
6560exports.log = function() {
6561 console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
6562};
6563
6564
6565/**
6566 * Inherit the prototype methods from one constructor into another.
6567 *
6568 * The Function.prototype.inherits from lang.js rewritten as a standalone
6569 * function (not on Function.prototype). NOTE: If this file is to be loaded
6570 * during bootstrapping this function needs to be rewritten using some native
6571 * functions as prototype setup using normal JavaScript does not work as
6572 * expected during bootstrapping (see mirror.js in r114903).
6573 *
6574 * @param {function} ctor Constructor function which needs to inherit the
6575 * prototype.
6576 * @param {function} superCtor Constructor function to inherit prototype from.
6577 */
6578exports.inherits = require('inherits');
6579
6580exports._extend = function(origin, add) {
6581 // Don't do anything if add isn't an object
6582 if (!add || !isObject(add)) return origin;
6583
6584 var keys = Object.keys(add);
6585 var i = keys.length;
6586 while (i--) {
6587 origin[keys[i]] = add[keys[i]];
6588 }
6589 return origin;
6590};
6591
6592function hasOwnProperty(obj, prop) {
6593 return Object.prototype.hasOwnProperty.call(obj, prop);
6594}
6595
6596}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
6597},{"./support/isBuffer":14,"_process":12,"inherits":10}],"jsonpath":[function(require,module,exports){
6598module.exports = require('./lib/index');
6599
6600},{"./lib/index":5}]},{},["jsonpath"])("jsonpath")
6601});
\No newline at end of file