1 |
|
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 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | (function (root, factory) {
|
49 | 'use strict';
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
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 |
|
108 | FnExprTokens = ['(', '{', '[', 'in', 'typeof', 'instanceof', 'new',
|
109 | 'return', 'case', 'delete', 'throw', 'void',
|
110 |
|
111 | '=', '+=', '-=', '*=', '/=', '%=', '<<=', '>>=', '>>>=',
|
112 | '&=', '|=', '^=', ',',
|
113 |
|
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 |
|
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 |
|
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 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 | function assert(condition, message) {
|
216 |
|
217 | if (!condition) {
|
218 | throw new Error('ASSERT: ' + message);
|
219 | }
|
220 | }
|
221 |
|
222 | function isDecimalDigit(ch) {
|
223 | return (ch >= 48 && ch <= 57);
|
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 |
|
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 |
|
243 |
|
244 | function isLineTerminator(ch) {
|
245 | return (ch === 0x0A) || (ch === 0x0D) || (ch === 0x2028) || (ch === 0x2029);
|
246 | }
|
247 |
|
248 |
|
249 |
|
250 | function isIdentifierStart(ch) {
|
251 | return (ch == 0x40) || (ch === 0x24) || (ch === 0x5F) ||
|
252 | (ch >= 0x41 && ch <= 0x5A) ||
|
253 | (ch >= 0x61 && ch <= 0x7A) ||
|
254 | (ch === 0x5C) ||
|
255 | ((ch >= 0x80) && Regex.NonAsciiIdentifierStart.test(String.fromCharCode(ch)));
|
256 | }
|
257 |
|
258 | function isIdentifierPart(ch) {
|
259 | return (ch === 0x24) || (ch === 0x5F) ||
|
260 | (ch >= 0x41 && ch <= 0x5A) ||
|
261 | (ch >= 0x61 && ch <= 0x7A) ||
|
262 | (ch >= 0x30 && ch <= 0x39) ||
|
263 | (ch === 0x5C) ||
|
264 | ((ch >= 0x80) && Regex.NonAsciiIdentifierPart.test(String.fromCharCode(ch)));
|
265 | }
|
266 |
|
267 |
|
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 |
|
305 |
|
306 | function isKeyword(id) {
|
307 | if (strict && isStrictModeReservedWord(id)) {
|
308 | return true;
|
309 | }
|
310 |
|
311 |
|
312 |
|
313 |
|
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 |
|
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 |
|
350 |
|
351 |
|
352 |
|
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 |
|
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) {
|
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) {
|
491 | ++index;
|
492 | ++index;
|
493 | skipMultiLineComment();
|
494 | } else {
|
495 | break;
|
496 | }
|
497 | } else if (start && ch === 0x2D) {
|
498 |
|
499 | if ((source.charCodeAt(index + 1) === 0x2D) && (source.charCodeAt(index + 2) === 0x3E)) {
|
500 |
|
501 | index += 3;
|
502 | skipSingleLineComment(3);
|
503 | } else {
|
504 | break;
|
505 | }
|
506 | } else if (ch === 0x3C) {
|
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 |
|
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 |
|
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 |
|
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 |
|
609 | id = (source.charCodeAt(index) === 0x5C) ? getEscapedIdentifier() : getIdentifier();
|
610 |
|
611 |
|
612 |
|
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 |
|
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 |
|
650 | case 0x2E:
|
651 | case 0x28:
|
652 | case 0x29:
|
653 | case 0x3B:
|
654 | case 0x2C:
|
655 | case 0x7B:
|
656 | case 0x7D:
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
856 |
|
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 |
|
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 |
|
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 |
|
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 |
|
984 |
|
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 |
|
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 |
|
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 |
|
1180 | if (!extra.tokenize) {
|
1181 |
|
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 |
|
1213 |
|
1214 | prevToken = extra.tokens[extra.tokens.length - 1];
|
1215 | if (!prevToken) {
|
1216 |
|
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 |
|
1237 |
|
1238 | if (extra.tokens[extra.openCurlyToken - 3] &&
|
1239 | extra.tokens[extra.openCurlyToken - 3].type === 'Keyword') {
|
1240 |
|
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 |
|
1248 | checkToken = extra.tokens[extra.openCurlyToken - 5];
|
1249 | if (!checkToken) {
|
1250 | return collectRegex();
|
1251 | }
|
1252 | } else {
|
1253 | return scanPunctuator();
|
1254 | }
|
1255 |
|
1256 |
|
1257 | if (FnExprTokens.indexOf(checkToken.value) >= 0) {
|
1258 |
|
1259 | return scanPunctuator();
|
1260 | }
|
1261 |
|
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 |
|
1294 | if (ch === 0x28 || ch === 0x29 || ch === 0x3B) {
|
1295 | return scanPunctuator();
|
1296 | }
|
1297 |
|
1298 |
|
1299 | if (ch === 0x27 || ch === 0x22) {
|
1300 | return scanStringLiteral();
|
1301 | }
|
1302 |
|
1303 |
|
1304 |
|
1305 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
1892 | throwError(token, Messages.UnexpectedToken, token.value);
|
1893 | }
|
1894 |
|
1895 |
|
1896 |
|
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 |
|
1906 |
|
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 |
|
1916 |
|
1917 | function match(value) {
|
1918 | return lookahead.type === Token.Punctuator && lookahead.value === value;
|
1919 | }
|
1920 |
|
1921 |
|
1922 |
|
1923 | function matchKeyword(keyword) {
|
1924 | return lookahead.type === Token.Keyword && lookahead.value === keyword;
|
1925 | }
|
1926 |
|
1927 |
|
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 |
|
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 |
|
1971 |
|
1972 | function isLeftHandSide(expr) {
|
1973 | return expr.type === Syntax.Identifier || expr.type === Syntax.MemberExpression;
|
1974 | }
|
1975 |
|
1976 |
|
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 |
|
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 |
|
2024 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
2465 |
|
2466 |
|
2467 |
|
2468 |
|
2469 |
|
2470 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
2566 | if (!isLeftHandSide(left)) {
|
2567 | throwErrorTolerant({}, Messages.InvalidLHSInAssignment);
|
2568 | }
|
2569 |
|
2570 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
2704 |
|
2705 |
|
2706 |
|
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 |
|
2722 |
|
2723 | function parseEmptyStatement() {
|
2724 | expect(';');
|
2725 | return delegate.createEmptyStatement();
|
2726 | }
|
2727 |
|
2728 |
|
2729 |
|
2730 | function parseExpressionStatement() {
|
2731 | var expr = parseExpression();
|
2732 | consumeSemicolon();
|
2733 | return delegate.createExpressionStatement(expr);
|
2734 | }
|
2735 |
|
2736 |
|
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 |
|
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 |
|
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 |
|
2894 |
|
2895 | function parseContinueStatement() {
|
2896 | var label = null, key;
|
2897 |
|
2898 | expectKeyword('continue');
|
2899 |
|
2900 |
|
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 |
|
2938 |
|
2939 | function parseBreakStatement() {
|
2940 | var label = null, key;
|
2941 |
|
2942 | expectKeyword('break');
|
2943 |
|
2944 |
|
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 |
|
2982 |
|
2983 | function parseReturnStatement() {
|
2984 | var argument = null;
|
2985 |
|
2986 | expectKeyword('return');
|
2987 |
|
2988 | if (!state.inFunctionBody) {
|
2989 | throwErrorTolerant({}, Messages.IllegalReturn);
|
2990 | }
|
2991 |
|
2992 |
|
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 |
|
3017 |
|
3018 | function parseWithStatement() {
|
3019 | var object, body;
|
3020 |
|
3021 | if (strict) {
|
3022 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
3177 |
|
3178 | function parseDebuggerStatement() {
|
3179 | expectKeyword('debugger');
|
3180 |
|
3181 | consumeSemicolon();
|
3182 |
|
3183 | return delegate.createDebuggerStatement();
|
3184 | }
|
3185 |
|
3186 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
3597 | options = options || {};
|
3598 |
|
3599 |
|
3600 | options.tokens = true;
|
3601 | extra.tokens = [];
|
3602 | extra.tokenize = true;
|
3603 |
|
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 |
|
3632 |
|
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 |
|
3730 | exports.version = '1.2.2';
|
3731 |
|
3732 | exports.tokenize = tokenize;
|
3733 |
|
3734 | exports.parse = parse;
|
3735 |
|
3736 |
|
3737 |
|
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 |
|
3760 |
|
3761 | },{}],1:[function(require,module,exports){
|
3762 | (function (process){
|
3763 |
|
3764 |
|
3765 |
|
3766 |
|
3767 |
|
3768 |
|
3769 |
|
3770 |
|
3771 |
|
3772 |
|
3773 |
|
3774 |
|
3775 |
|
3776 |
|
3777 |
|
3778 |
|
3779 |
|
3780 |
|
3781 |
|
3782 |
|
3783 |
|
3784 |
|
3785 |
|
3786 |
|
3787 |
|
3788 |
|
3789 |
|
3790 |
|
3791 |
|
3792 |
|
3793 |
|
3794 |
|
3795 |
|
3796 |
|
3797 |
|
3798 |
|
3799 |
|
3800 |
|
3801 |
|
3802 |
|
3803 |
|
3804 |
|
3805 |
|
3806 |
|
3807 |
|
3808 |
|
3809 |
|
3810 |
|
3811 |
|
3812 |
|
3813 |
|
3814 |
|
3815 |
|
3816 |
|
3817 |
|
3818 |
|
3819 |
|
3820 |
|
3821 |
|
3822 |
|
3823 |
|
3824 |
|
3825 |
|
3826 |
|
3827 |
|
3828 |
|
3829 |
|
3830 |
|
3831 |
|
3832 |
|
3833 |
|
3834 |
|
3835 |
|
3836 | var parser = (function(){
|
3837 | var parser = {trace: function trace() { },
|
3838 | yy: {},
|
3839 | symbols_: {"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},
|
3840 | terminals_: {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"},
|
3841 | productions_: [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]],
|
3842 | performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */
|
3843 | /**/) {
|
3844 |
|
3845 | if (!yy.ast) {
|
3846 | yy.ast = _ast;
|
3847 | _ast.initialize();
|
3848 | }
|
3849 |
|
3850 | var $0 = $$.length - 1;
|
3851 | switch (yystate) {
|
3852 | case 1:yy.ast.set({ expression: { type: "root", value: $$[$0] } }); yy.ast.unshift(); return yy.ast.yield()
|
3853 | break;
|
3854 | case 2:yy.ast.set({ expression: { type: "root", value: $$[$0-1] } }); yy.ast.unshift(); return yy.ast.yield()
|
3855 | break;
|
3856 | case 3:yy.ast.unshift(); return yy.ast.yield()
|
3857 | break;
|
3858 | case 4:yy.ast.set({ operation: "member", scope: "child", expression: { type: "identifier", value: $$[$0-1] }}); yy.ast.unshift(); return yy.ast.yield()
|
3859 | break;
|
3860 | case 5:
|
3861 | break;
|
3862 | case 6:
|
3863 | break;
|
3864 | case 7:yy.ast.set({ operation: "member" }); yy.ast.push()
|
3865 | break;
|
3866 | case 8:yy.ast.set({ operation: "subscript" }); yy.ast.push()
|
3867 | break;
|
3868 | case 9:yy.ast.set({ scope: "child" })
|
3869 | break;
|
3870 | case 10:yy.ast.set({ scope: "descendant" })
|
3871 | break;
|
3872 | case 11:
|
3873 | break;
|
3874 | case 12:yy.ast.set({ scope: "child", operation: "member" })
|
3875 | break;
|
3876 | case 13:
|
3877 | break;
|
3878 | case 14:yy.ast.set({ expression: { type: "wildcard", value: $$[$0] } })
|
3879 | break;
|
3880 | case 15:yy.ast.set({ expression: { type: "identifier", value: $$[$0] } })
|
3881 | break;
|
3882 | case 16:yy.ast.set({ expression: { type: "script_expression", value: $$[$0] } })
|
3883 | break;
|
3884 | case 17:yy.ast.set({ expression: { type: "numeric_literal", value: parseInt($$[$0]) } })
|
3885 | break;
|
3886 | case 18:
|
3887 | break;
|
3888 | case 19:yy.ast.set({ scope: "child" })
|
3889 | break;
|
3890 | case 20:yy.ast.set({ scope: "descendant" })
|
3891 | break;
|
3892 | case 21:
|
3893 | break;
|
3894 | case 22:
|
3895 | break;
|
3896 | case 23:
|
3897 | break;
|
3898 | case 24:$$[$0].length > 1? yy.ast.set({ expression: { type: "union", value: $$[$0] } }) : this.$ = $$[$0]
|
3899 | break;
|
3900 | case 25:this.$ = [$$[$0]]
|
3901 | break;
|
3902 | case 26:this.$ = $$[$0-2].concat($$[$0])
|
3903 | break;
|
3904 | case 27:this.$ = { expression: { type: "numeric_literal", value: parseInt($$[$0]) } }; yy.ast.set(this.$)
|
3905 | break;
|
3906 | case 28:this.$ = { expression: { type: "string_literal", value: $$[$0] } }; yy.ast.set(this.$)
|
3907 | break;
|
3908 | case 29:this.$ = { expression: { type: "slice", value: $$[$0] } }; yy.ast.set(this.$)
|
3909 | break;
|
3910 | case 30:this.$ = { expression: { type: "wildcard", value: $$[$0] } }; yy.ast.set(this.$)
|
3911 | break;
|
3912 | case 31:this.$ = { expression: { type: "script_expression", value: $$[$0] } }; yy.ast.set(this.$)
|
3913 | break;
|
3914 | case 32:this.$ = { expression: { type: "filter_expression", value: $$[$0] } }; yy.ast.set(this.$)
|
3915 | break;
|
3916 | case 33:this.$ = $$[$0]
|
3917 | break;
|
3918 | case 34:this.$ = $$[$0]
|
3919 | break;
|
3920 | }
|
3921 | },
|
3922 | table: [{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]}],
|
3923 | defaultActions: {27:[2,23],29:[2,30],30:[2,31],31:[2,32]},
|
3924 | parseError: function parseError(str, hash) {
|
3925 | if (hash.recoverable) {
|
3926 | this.trace(str);
|
3927 | } else {
|
3928 | throw new Error(str);
|
3929 | }
|
3930 | },
|
3931 | parse: 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 | }};
|
4061 | var _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 |
|
4096 | var lexer = (function(){
|
4097 | var lexer = {
|
4098 |
|
4099 | EOF:1,
|
4100 |
|
4101 | parseError: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 |
|
4110 | setInput: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 |
|
4130 | input: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 |
|
4153 | unput: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 |
|
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 |
|
4188 | more:function () {
|
4189 | this._more = true;
|
4190 | return this;
|
4191 | },
|
4192 |
|
4193 |
|
4194 | reject: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 |
|
4209 | less:function (n) {
|
4210 | this.unput(this.match.slice(n));
|
4211 | },
|
4212 |
|
4213 |
|
4214 | pastInput: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 |
|
4220 | upcomingInput: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 |
|
4229 | showPosition: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 |
|
4236 | test_match:function (match, indexed_rule) {
|
4237 | var token,
|
4238 | lines,
|
4239 | backup;
|
4240 |
|
4241 | if (this.options.backtrack_lexer) {
|
4242 |
|
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 |
|
4299 | for (var k in backup) {
|
4300 | this[k] = backup[k];
|
4301 | }
|
4302 | return false;
|
4303 | }
|
4304 | return false;
|
4305 | },
|
4306 |
|
4307 |
|
4308 | next: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;
|
4337 | } else {
|
4338 |
|
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 |
|
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 |
|
4366 | lex:function lex() {
|
4367 | var r = this.next();
|
4368 | if (r) {
|
4369 | return r;
|
4370 | } else {
|
4371 | return this.lex();
|
4372 | }
|
4373 | },
|
4374 |
|
4375 |
|
4376 | begin:function begin(condition) {
|
4377 | this.conditionStack.push(condition);
|
4378 | },
|
4379 |
|
4380 |
|
4381 | popState: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 |
|
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 |
|
4400 | topState: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 |
|
4410 | pushState:function pushState(condition) {
|
4411 | this.begin(condition);
|
4412 | },
|
4413 |
|
4414 |
|
4415 | stateStackSize:function stateStackSize() {
|
4416 | return this.conditionStack.length;
|
4417 | },
|
4418 | options: {},
|
4419 | performAction: function anonymous(yy,yy_,$avoiding_name_collisions,YY_START
|
4420 | /**/) {
|
4421 |
|
4422 | var YYSTATE=YY_START;
|
4423 | switch($avoiding_name_collisions) {
|
4424 | case 0:return 4
|
4425 | break;
|
4426 | case 1:return 14
|
4427 | break;
|
4428 | case 2:return 12
|
4429 | break;
|
4430 | case 3:return 15
|
4431 | break;
|
4432 | case 4:return 16
|
4433 | break;
|
4434 | case 5:return 22
|
4435 | break;
|
4436 | case 6:return 24
|
4437 | break;
|
4438 | case 7:return 28
|
4439 | break;
|
4440 | case 8:return 30
|
4441 | break;
|
4442 | case 9:return 18
|
4443 | break;
|
4444 | case 10:yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2); return 32;
|
4445 | break;
|
4446 | case 11:yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2); return 33;
|
4447 | break;
|
4448 | case 12:return 17
|
4449 | break;
|
4450 | case 13:return 31
|
4451 | break;
|
4452 | }
|
4453 | },
|
4454 | rules: [/^(?:\$)/,/^(?:\.\.)/,/^(?:\.)/,/^(?:\*)/,/^(?:[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}|[^'\\])*')/,/^(?:\(.+?\)(?=\]))/,/^(?:\?\(.+?\)(?=\]))/],
|
4455 | conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13],"inclusive":true}}
|
4456 | };
|
4457 | return lexer;
|
4458 | })();
|
4459 | parser.lexer = lexer;
|
4460 | function Parser () {
|
4461 | this.yy = {};
|
4462 | }
|
4463 | Parser.prototype = parser;parser.Parser = Parser;
|
4464 | return new Parser;
|
4465 | })();
|
4466 |
|
4467 |
|
4468 | if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
|
4469 | exports.parser = parser;
|
4470 | exports.Parser = parser.Parser;
|
4471 | exports.parse = function () { return parser.parse.apply(parser, arguments); };
|
4472 | exports.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 | };
|
4480 | if (typeof module !== 'undefined' && require.main === module) {
|
4481 | exports.main(process.argv.slice(1));
|
4482 | }
|
4483 | }
|
4484 |
|
4485 | }).call(this,require('_process'))
|
4486 | },{"_process":14,"fs":12,"path":13}],2:[function(require,module,exports){
|
4487 | module.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){
|
4495 | var dict = require('./dict');
|
4496 | var fs = require('fs');
|
4497 | var grammar = {
|
4498 |
|
4499 | lex: {
|
4500 |
|
4501 | macros: {
|
4502 | esc: "\\\\",
|
4503 | int: dict.integer
|
4504 | },
|
4505 |
|
4506 | rules: [
|
4507 | ["\\$", "return 'DOLLAR'"],
|
4508 | ["\\.\\.", "return 'DOT_DOT'"],
|
4509 | ["\\.", "return 'DOT'"],
|
4510 | ["\\*", "return 'STAR'"],
|
4511 | [dict.identifier, "return 'IDENTIFIER'"],
|
4512 | ["\\[", "return '['"],
|
4513 | ["\\]", "return ']'"],
|
4514 | [",", "return ','"],
|
4515 | ["({int})?\\:({int})?(\\:({int})?)?", "return 'ARRAY_SLICE'"],
|
4516 | ["{int}", "return 'INTEGER'"],
|
4517 | [dict.qq_string, "yytext = yytext.substr(1,yyleng-2); return 'QQ_STRING';"],
|
4518 | [dict.q_string, "yytext = yytext.substr(1,yyleng-2); return 'Q_STRING';"],
|
4519 | ["\\(.+?\\)(?=\\])", "return 'SCRIPT_EXPRESSION'"],
|
4520 | ["\\?\\(.+?\\)(?=\\])", "return 'FILTER_EXPRESSION'"]
|
4521 | ]
|
4522 | },
|
4523 |
|
4524 | start: "JSON_PATH",
|
4525 |
|
4526 | bnf: {
|
4527 |
|
4528 | JSON_PATH: [
|
4529 | [ 'DOLLAR', 'yy.ast.set({ expression: { type: "root", value: $1 } }); yy.ast.unshift(); return yy.ast.yield()' ],
|
4530 | [ 'DOLLAR PATH_COMPONENTS', 'yy.ast.set({ expression: { type: "root", value: $1 } }); yy.ast.unshift(); return yy.ast.yield()' ],
|
4531 | [ 'LEADING_CHILD_MEMBER_EXPRESSION', 'yy.ast.unshift(); return yy.ast.yield()' ],
|
4532 | [ '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()' ] ],
|
4533 |
|
4534 | PATH_COMPONENTS: [
|
4535 | [ 'PATH_COMPONENT', '' ],
|
4536 | [ 'PATH_COMPONENTS PATH_COMPONENT', '' ] ],
|
4537 |
|
4538 | PATH_COMPONENT: [
|
4539 | [ 'MEMBER_COMPONENT', 'yy.ast.set({ operation: "member" }); yy.ast.push()' ],
|
4540 | [ 'SUBSCRIPT_COMPONENT', 'yy.ast.set({ operation: "subscript" }); yy.ast.push() ' ] ],
|
4541 |
|
4542 | MEMBER_COMPONENT: [
|
4543 | [ 'CHILD_MEMBER_COMPONENT', 'yy.ast.set({ scope: "child" })' ],
|
4544 | [ 'DESCENDANT_MEMBER_COMPONENT', 'yy.ast.set({ scope: "descendant" })' ] ],
|
4545 |
|
4546 | CHILD_MEMBER_COMPONENT: [
|
4547 | [ 'DOT MEMBER_EXPRESSION', '' ] ],
|
4548 |
|
4549 | LEADING_CHILD_MEMBER_EXPRESSION: [
|
4550 | [ 'MEMBER_EXPRESSION', 'yy.ast.set({ scope: "child", operation: "member" })' ] ],
|
4551 |
|
4552 | DESCENDANT_MEMBER_COMPONENT: [
|
4553 | [ 'DOT_DOT MEMBER_EXPRESSION', '' ] ],
|
4554 |
|
4555 | MEMBER_EXPRESSION: [
|
4556 | [ 'STAR', 'yy.ast.set({ expression: { type: "wildcard", value: $1 } })' ],
|
4557 | [ 'IDENTIFIER', 'yy.ast.set({ expression: { type: "identifier", value: $1 } })' ],
|
4558 | [ 'SCRIPT_EXPRESSION', 'yy.ast.set({ expression: { type: "script_expression", value: $1 } })' ],
|
4559 | [ 'INTEGER', 'yy.ast.set({ expression: { type: "numeric_literal", value: parseInt($1) } })' ],
|
4560 | [ 'END', '' ] ],
|
4561 |
|
4562 | SUBSCRIPT_COMPONENT: [
|
4563 | [ 'CHILD_SUBSCRIPT_COMPONENT', 'yy.ast.set({ scope: "child" })' ],
|
4564 | [ 'DESCENDANT_SUBSCRIPT_COMPONENT', 'yy.ast.set({ scope: "descendant" })' ] ],
|
4565 |
|
4566 | CHILD_SUBSCRIPT_COMPONENT: [
|
4567 | [ '[ SUBSCRIPT ]', '' ] ],
|
4568 |
|
4569 | DESCENDANT_SUBSCRIPT_COMPONENT: [
|
4570 | [ 'DOT_DOT [ SUBSCRIPT ]', '' ] ],
|
4571 |
|
4572 | SUBSCRIPT: [
|
4573 | [ 'SUBSCRIPT_EXPRESSION', '' ],
|
4574 | [ 'SUBSCRIPT_EXPRESSION_LIST', '$1.length > 1? yy.ast.set({ expression: { type: "union", value: $1 } }) : $$ = $1' ] ],
|
4575 |
|
4576 | SUBSCRIPT_EXPRESSION_LIST: [
|
4577 | [ 'SUBSCRIPT_EXPRESSION_LISTABLE', '$$ = [$1]'],
|
4578 | [ 'SUBSCRIPT_EXPRESSION_LIST , SUBSCRIPT_EXPRESSION_LISTABLE', '$$ = $1.concat($3)' ] ],
|
4579 |
|
4580 | SUBSCRIPT_EXPRESSION_LISTABLE: [
|
4581 | [ 'INTEGER', '$$ = { expression: { type: "numeric_literal", value: parseInt($1) } }; yy.ast.set($$)' ],
|
4582 | [ 'STRING_LITERAL', '$$ = { expression: { type: "string_literal", value: $1 } }; yy.ast.set($$)' ],
|
4583 | [ 'ARRAY_SLICE', '$$ = { expression: { type: "slice", value: $1 } }; yy.ast.set($$)' ] ],
|
4584 |
|
4585 | SUBSCRIPT_EXPRESSION: [
|
4586 | [ 'STAR', '$$ = { expression: { type: "wildcard", value: $1 } }; yy.ast.set($$)' ],
|
4587 | [ 'SCRIPT_EXPRESSION', '$$ = { expression: { type: "script_expression", value: $1 } }; yy.ast.set($$)' ],
|
4588 | [ 'FILTER_EXPRESSION', '$$ = { expression: { type: "filter_expression", value: $1 } }; yy.ast.set($$)' ] ],
|
4589 |
|
4590 | STRING_LITERAL: [
|
4591 | [ 'QQ_STRING', "$$ = $1" ],
|
4592 | [ 'Q_STRING', "$$ = $1" ] ]
|
4593 | }
|
4594 | };
|
4595 | if (fs.readFileSync) {
|
4596 | grammar.moduleInclude = fs.readFileSync(require.resolve("../include/module.js"));
|
4597 | grammar.actionInclude = fs.readFileSync(require.resolve("../include/action.js"));
|
4598 | }
|
4599 |
|
4600 | module.exports = grammar;
|
4601 |
|
4602 | },{"./dict":2,"fs":12}],4:[function(require,module,exports){
|
4603 | var aesprim = require('./aesprim');
|
4604 | var slice = require('./slice');
|
4605 | var _evaluate = require('static-eval');
|
4606 | var _uniq = require('underscore').uniq;
|
4607 |
|
4608 | var Handlers = function() {
|
4609 | return this.initialize.apply(this, arguments);
|
4610 | }
|
4611 |
|
4612 | Handlers.prototype.initialize = function() {
|
4613 | this.traverse = traverser(true);
|
4614 | this.descend = traverser();
|
4615 | }
|
4616 |
|
4617 | Handlers.prototype.keys = Object.keys;
|
4618 |
|
4619 | Handlers.prototype.resolve = function(component) {
|
4620 |
|
4621 | var key = [ component.operation, component.scope, component.expression.type ].join('-');
|
4622 | var method = this._fns[key];
|
4623 |
|
4624 | if (!method) throw new Error("couldn't resolve key: " + key);
|
4625 | return method.bind(this);
|
4626 | };
|
4627 |
|
4628 | Handlers.prototype.register = function(key, handler) {
|
4629 |
|
4630 | if (!handler instanceof Function) {
|
4631 | throw new Error("handler must be a function");
|
4632 | }
|
4633 |
|
4634 | this._fns[key] = handler;
|
4635 | };
|
4636 |
|
4637 | Handlers.prototype._fns = {
|
4638 |
|
4639 | 'member-child-identifier': function(component, partial) {
|
4640 | var key = component.expression.value;
|
4641 | var value = partial.value;
|
4642 | if (value instanceof Object && key in value) {
|
4643 | return [ { value: value[key], path: partial.path.concat(key) } ]
|
4644 | }
|
4645 | },
|
4646 |
|
4647 | 'member-descendant-identifier':
|
4648 | _traverse(function(key, value, ref) { return key == ref }),
|
4649 |
|
4650 | 'subscript-child-numeric_literal':
|
4651 | _descend(function(key, value, ref) { return key === ref }),
|
4652 |
|
4653 | 'member-child-numeric_literal':
|
4654 | _descend(function(key, value, ref) { return String(key) === String(ref) }),
|
4655 |
|
4656 | 'subscript-descendant-numeric_literal':
|
4657 | _traverse(function(key, value, ref) { return key === ref }),
|
4658 |
|
4659 | 'member-child-wildcard':
|
4660 | _descend(function() { return true }),
|
4661 |
|
4662 | 'member-descendant-wildcard':
|
4663 | _traverse(function() { return true }),
|
4664 |
|
4665 | 'subscript-descendant-wildcard':
|
4666 | _traverse(function() { return true }),
|
4667 |
|
4668 | 'subscript-child-wildcard':
|
4669 | _descend(function() { return true }),
|
4670 |
|
4671 | 'subscript-child-slice': function(component, partial) {
|
4672 | if (is_array(partial.value)) {
|
4673 | var args = component.expression.value.split(':').map(_parse_nullable_int);
|
4674 | var values = partial.value.map(function(v, i) { return { value: v, path: partial.path.concat(i) } });
|
4675 | return slice.apply(null, [values].concat(args));
|
4676 | }
|
4677 | },
|
4678 |
|
4679 | 'subscript-child-union': function(component, partial) {
|
4680 | var results = [];
|
4681 | component.expression.value.forEach(function(component) {
|
4682 | var _component = { operation: 'subscript', scope: 'child', expression: component.expression };
|
4683 | var handler = this.resolve(_component);
|
4684 | var _results = handler(_component, partial);
|
4685 | if (_results) {
|
4686 | results = results.concat(_results);
|
4687 | }
|
4688 | }, this);
|
4689 |
|
4690 | return unique(results);
|
4691 | },
|
4692 |
|
4693 | 'subscript-descendant-union': function(component, partial, count) {
|
4694 |
|
4695 | var jp = require('..');
|
4696 | var self = this;
|
4697 |
|
4698 | var results = [];
|
4699 | var nodes = jp.nodes(partial, '$..*').slice(1);
|
4700 |
|
4701 | nodes.forEach(function(node) {
|
4702 | if (results.length >= count) return;
|
4703 | component.expression.value.forEach(function(component) {
|
4704 | var _component = { operation: 'subscript', scope: 'child', expression: component.expression };
|
4705 | var handler = self.resolve(_component);
|
4706 | var _results = handler(_component, node);
|
4707 | results = results.concat(_results);
|
4708 | });
|
4709 | });
|
4710 |
|
4711 | return unique(results);
|
4712 | },
|
4713 |
|
4714 | 'subscript-child-filter_expression': function(component, partial, count) {
|
4715 |
|
4716 |
|
4717 | var src = component.expression.value.slice(2, -1);
|
4718 | var ast = aesprim.parse(src).body[0].expression;
|
4719 |
|
4720 | var passable = function(key, value) {
|
4721 | return evaluate(ast, { '@': value });
|
4722 | }
|
4723 |
|
4724 | return this.descend(partial, null, passable, count);
|
4725 |
|
4726 | },
|
4727 |
|
4728 | 'subscript-descendant-filter_expression': function(component, partial, count) {
|
4729 |
|
4730 |
|
4731 | var src = component.expression.value.slice(2, -1);
|
4732 | var ast = aesprim.parse(src).body[0].expression;
|
4733 |
|
4734 | var passable = function(key, value) {
|
4735 | return evaluate(ast, { '@': value });
|
4736 | }
|
4737 |
|
4738 | return this.traverse(partial, null, passable, count);
|
4739 | },
|
4740 |
|
4741 | 'subscript-child-script_expression': function(component, partial) {
|
4742 | var exp = component.expression.value.slice(1, -1);
|
4743 | return eval_recurse(partial, exp, '$[{{value}}]');
|
4744 | },
|
4745 |
|
4746 | 'member-child-script_expression': function(component, partial) {
|
4747 | var exp = component.expression.value.slice(1, -1);
|
4748 | return eval_recurse(partial, exp, '$.{{value}}');
|
4749 | },
|
4750 |
|
4751 | 'member-descendant-script_expression': function(component, partial) {
|
4752 | var exp = component.expression.value.slice(1, -1);
|
4753 | return eval_recurse(partial, exp, '$..value');
|
4754 | }
|
4755 | };
|
4756 |
|
4757 | Handlers.prototype._fns['subscript-child-string_literal'] =
|
4758 | Handlers.prototype._fns['member-child-identifier'];
|
4759 |
|
4760 | Handlers.prototype._fns['member-descendant-numeric_literal'] =
|
4761 | Handlers.prototype._fns['subscript-descendant-string_literal'] =
|
4762 | Handlers.prototype._fns['member-descendant-identifier'];
|
4763 |
|
4764 | function 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 |
|
4779 | function is_array(val) {
|
4780 | return Array.isArray(val);
|
4781 | }
|
4782 |
|
4783 | function is_object(val) {
|
4784 |
|
4785 | return val && !(val instanceof Array) && val instanceof Object;
|
4786 | }
|
4787 |
|
4788 | function 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 |
|
4832 | function _descend(passable) {
|
4833 | return function(component, partial, count) {
|
4834 | return this.descend(partial, component.expression.value, passable, count);
|
4835 | }
|
4836 | }
|
4837 |
|
4838 | function _traverse(passable) {
|
4839 | return function(component, partial, count) {
|
4840 | return this.traverse(partial, component.expression.value, passable, count);
|
4841 | }
|
4842 | }
|
4843 |
|
4844 | function evaluate() {
|
4845 | try { return _evaluate.apply(this, arguments) }
|
4846 | catch (e) { }
|
4847 | }
|
4848 |
|
4849 | function unique(results) {
|
4850 | results = results.filter(function(d) { return d })
|
4851 | return _uniq(
|
4852 | results,
|
4853 | function(r) { return r.path.map(function(c) { return String(c).replace('-', '--') }).join('-') }
|
4854 | );
|
4855 | }
|
4856 |
|
4857 | function _parse_nullable_int(val) {
|
4858 | var sval = String(val);
|
4859 | return sval.match(/^-?[0-9]+$/) ? parseInt(sval) : null;
|
4860 | }
|
4861 |
|
4862 | module.exports = Handlers;
|
4863 |
|
4864 | },{"..":"jsonpath","./aesprim":"./aesprim","./index":5,"./slice":7,"static-eval":15,"underscore":12}],5:[function(require,module,exports){
|
4865 | var assert = require('assert');
|
4866 | var dict = require('./dict');
|
4867 | var Parser = require('./parser');
|
4868 | var Handlers = require('./handlers');
|
4869 |
|
4870 | var JSONPath = function() {
|
4871 | this.initialize.apply(this, arguments);
|
4872 | };
|
4873 |
|
4874 | JSONPath.prototype.initialize = function() {
|
4875 | this.parser = new Parser();
|
4876 | this.handlers = new Handlers();
|
4877 | };
|
4878 |
|
4879 | JSONPath.prototype.parse = function(string) {
|
4880 | assert.ok(_is_string(string), "we need a path");
|
4881 | return this.parser.parse(string);
|
4882 | };
|
4883 |
|
4884 | JSONPath.prototype.parent = function(obj, string) {
|
4885 |
|
4886 | assert.ok(obj instanceof Object, "obj needs to be an object");
|
4887 | assert.ok(string, "we need a path");
|
4888 |
|
4889 | var node = this.nodes(obj, string)[0];
|
4890 | var key = node.path.pop();
|
4891 | return this.value(obj, node.path);
|
4892 | }
|
4893 |
|
4894 | JSONPath.prototype.apply = function(obj, string, fn) {
|
4895 |
|
4896 | assert.ok(obj instanceof Object, "obj needs to be an object");
|
4897 | assert.ok(string, "we need a path");
|
4898 | assert.equal(typeof fn, "function", "fn needs to be function")
|
4899 |
|
4900 | var nodes = this.nodes(obj, string).sort(function(a, b) {
|
4901 |
|
4902 | return b.path.length - a.path.length;
|
4903 | });
|
4904 |
|
4905 | nodes.forEach(function(node) {
|
4906 | var key = node.path.pop();
|
4907 | var parent = this.value(obj, this.stringify(node.path));
|
4908 | var val = node.value = fn.call(obj, parent[key]);
|
4909 | parent[key] = val;
|
4910 | }, this);
|
4911 |
|
4912 | return nodes;
|
4913 | }
|
4914 |
|
4915 | JSONPath.prototype.value = function(obj, path, value) {
|
4916 |
|
4917 | assert.ok(obj instanceof Object, "obj needs to be an object");
|
4918 | assert.ok(path, "we need a path");
|
4919 |
|
4920 | if (arguments.length >= 3) {
|
4921 | var node = this.nodes(obj, path).shift();
|
4922 | if (!node) return this._vivify(obj, path, value);
|
4923 | var key = node.path.slice(-1).shift();
|
4924 | var parent = this.parent(obj, this.stringify(node.path));
|
4925 | parent[key] = value;
|
4926 | }
|
4927 | return this.query(obj, this.stringify(path), 1).shift();
|
4928 | }
|
4929 |
|
4930 | JSONPath.prototype._vivify = function(obj, string, value) {
|
4931 |
|
4932 | var self = this;
|
4933 |
|
4934 | assert.ok(obj instanceof Object, "obj needs to be an object");
|
4935 | assert.ok(string, "we need a path");
|
4936 |
|
4937 | var path = this.parser.parse(string)
|
4938 | .map(function(component) { return component.expression.value });
|
4939 |
|
4940 | var setValue = function(path, value) {
|
4941 | var key = path.pop();
|
4942 | var node = self.value(obj, path);
|
4943 | if (!node) {
|
4944 | setValue(path.concat(), typeof key === 'string' ? {} : []);
|
4945 | node = self.value(obj, path);
|
4946 | }
|
4947 | node[key] = value;
|
4948 | }
|
4949 | setValue(path, value);
|
4950 | return this.query(obj, string)[0];
|
4951 | }
|
4952 |
|
4953 | JSONPath.prototype.query = function(obj, string, count) {
|
4954 |
|
4955 | assert.ok(obj instanceof Object, "obj needs to be an object");
|
4956 | assert.ok(_is_string(string), "we need a path");
|
4957 |
|
4958 | var results = this.nodes(obj, string, count)
|
4959 | .map(function(r) { return r.value });
|
4960 |
|
4961 | return results;
|
4962 | };
|
4963 |
|
4964 | JSONPath.prototype.paths = function(obj, string, count) {
|
4965 |
|
4966 | assert.ok(obj instanceof Object, "obj needs to be an object");
|
4967 | assert.ok(string, "we need a path");
|
4968 |
|
4969 | var results = this.nodes(obj, string, count)
|
4970 | .map(function(r) { return r.path });
|
4971 |
|
4972 | return results;
|
4973 | };
|
4974 |
|
4975 | JSONPath.prototype.nodes = function(obj, string, count) {
|
4976 |
|
4977 | assert.ok(obj instanceof Object, "obj needs to be an object");
|
4978 | assert.ok(string, "we need a path");
|
4979 |
|
4980 | if (count === 0) return [];
|
4981 |
|
4982 | var path = this.parser.parse(string);
|
4983 | var handlers = this.handlers;
|
4984 |
|
4985 | var partials = [ { path: ['$'], value: obj } ];
|
4986 | var matches = [];
|
4987 |
|
4988 | if (path.length && path[0].expression.type == 'root') path.shift();
|
4989 |
|
4990 | if (!path.length) return partials;
|
4991 |
|
4992 | path.forEach(function(component, index) {
|
4993 |
|
4994 | if (matches.length >= count) return;
|
4995 | var handler = handlers.resolve(component);
|
4996 | var _partials = [];
|
4997 |
|
4998 | partials.forEach(function(p) {
|
4999 |
|
5000 | if (matches.length >= count) return;
|
5001 | var results = handler(component, p, count);
|
5002 |
|
5003 | if (index == path.length - 1) {
|
5004 |
|
5005 | matches = matches.concat(results || []);
|
5006 | } else {
|
5007 |
|
5008 | _partials = _partials.concat(results || []);
|
5009 | }
|
5010 | });
|
5011 |
|
5012 | partials = _partials;
|
5013 |
|
5014 | });
|
5015 |
|
5016 | return count ? matches.slice(0, count) : matches;
|
5017 | };
|
5018 |
|
5019 | JSONPath.prototype.stringify = function(path) {
|
5020 |
|
5021 | assert.ok(path, "we need a path");
|
5022 |
|
5023 | var string = '$';
|
5024 |
|
5025 | var templates = {
|
5026 | 'descendant-member': '..{{value}}',
|
5027 | 'child-member': '.{{value}}',
|
5028 | 'descendant-subscript': '..[{{value}}]',
|
5029 | 'child-subscript': '[{{value}}]'
|
5030 | };
|
5031 |
|
5032 | path = this._normalize(path);
|
5033 |
|
5034 | path.forEach(function(component) {
|
5035 |
|
5036 | if (component.expression.type == 'root') return;
|
5037 |
|
5038 | var key = [component.scope, component.operation].join('-');
|
5039 | var template = templates[key];
|
5040 | var value;
|
5041 |
|
5042 | if (component.expression.type == 'string_literal') {
|
5043 | value = JSON.stringify(component.expression.value)
|
5044 | } else {
|
5045 | value = component.expression.value;
|
5046 | }
|
5047 |
|
5048 | if (!template) throw new Error("couldn't find template " + key);
|
5049 |
|
5050 | string += template.replace(/{{value}}/, value);
|
5051 | });
|
5052 |
|
5053 | return string;
|
5054 | }
|
5055 |
|
5056 | JSONPath.prototype._normalize = function(path) {
|
5057 |
|
5058 | assert.ok(path, "we need a path");
|
5059 |
|
5060 | if (typeof path == "string") {
|
5061 |
|
5062 | return this.parser.parse(path);
|
5063 |
|
5064 | } else if (Array.isArray(path) && typeof path[0] == "string") {
|
5065 |
|
5066 | var _path = [ { expression: { type: "root", value: "$" } } ];
|
5067 |
|
5068 | path.forEach(function(component, index) {
|
5069 |
|
5070 | if (component == '$' && index === 0) return;
|
5071 |
|
5072 | if (typeof component == "string" && component.match("^" + dict.identifier + "$")) {
|
5073 |
|
5074 | _path.push({
|
5075 | operation: 'member',
|
5076 | scope: 'child',
|
5077 | expression: { value: component, type: 'identifier' }
|
5078 | });
|
5079 |
|
5080 | } else {
|
5081 |
|
5082 | var type = typeof component == "number" ?
|
5083 | 'numeric_literal' : 'string_literal';
|
5084 |
|
5085 | _path.push({
|
5086 | operation: 'subscript',
|
5087 | scope: 'child',
|
5088 | expression: { value: component, type: type }
|
5089 | });
|
5090 | }
|
5091 | });
|
5092 |
|
5093 | return _path;
|
5094 |
|
5095 | } else if (Array.isArray(path) && typeof path[0] == "object") {
|
5096 |
|
5097 | return path
|
5098 | }
|
5099 |
|
5100 | throw new Error("couldn't understand path " + path);
|
5101 | }
|
5102 |
|
5103 | function _is_string(obj) {
|
5104 | return Object.prototype.toString.call(obj) == '[object String]';
|
5105 | }
|
5106 |
|
5107 | JSONPath.Handlers = Handlers;
|
5108 | JSONPath.Parser = Parser;
|
5109 |
|
5110 | var instance = new JSONPath;
|
5111 | instance.JSONPath = JSONPath;
|
5112 |
|
5113 | module.exports = instance;
|
5114 |
|
5115 | },{"./dict":2,"./handlers":4,"./parser":6,"assert":8}],6:[function(require,module,exports){
|
5116 | var grammar = require('./grammar');
|
5117 | var gparser = require('../generated/parser');
|
5118 |
|
5119 | var Parser = function() {
|
5120 |
|
5121 | var parser = new gparser.Parser();
|
5122 |
|
5123 | var _parseError = parser.parseError;
|
5124 | parser.yy.parseError = function() {
|
5125 | if (parser.yy.ast) {
|
5126 | parser.yy.ast.initialize();
|
5127 | }
|
5128 | _parseError.apply(parser, arguments);
|
5129 | }
|
5130 |
|
5131 | return parser;
|
5132 |
|
5133 | };
|
5134 |
|
5135 | Parser.grammar = grammar;
|
5136 | module.exports = Parser;
|
5137 |
|
5138 | },{"../generated/parser":1,"./grammar":3}],7:[function(require,module,exports){
|
5139 | module.exports = function(arr, start, end, step) {
|
5140 |
|
5141 | if (typeof start == 'string') throw new Error("start cannot be a string");
|
5142 | if (typeof end == 'string') throw new Error("end cannot be a string");
|
5143 | if (typeof step == 'string') throw new Error("step cannot be a string");
|
5144 |
|
5145 | var len = arr.length;
|
5146 |
|
5147 | if (step === 0) throw new Error("step cannot be zero");
|
5148 | step = step ? integer(step) : 1;
|
5149 |
|
5150 |
|
5151 | start = start < 0 ? len + start : start;
|
5152 | end = end < 0 ? len + end : end;
|
5153 |
|
5154 |
|
5155 | start = integer(start === 0 ? 0 : !start ? (step > 0 ? 0 : len - 1) : start);
|
5156 | end = integer(end === 0 ? 0 : !end ? (step > 0 ? len : -1) : end);
|
5157 |
|
5158 |
|
5159 | start = step > 0 ? Math.max(0, start) : Math.min(len, start);
|
5160 | end = step > 0 ? Math.min(end, len) : Math.max(-1, end);
|
5161 |
|
5162 |
|
5163 | if (step > 0 && end <= start) return [];
|
5164 | if (step < 0 && start <= end) return [];
|
5165 |
|
5166 | var result = [];
|
5167 |
|
5168 | for (var i = start; i != end; i += step) {
|
5169 | if ((step < 0 && i <= end) || (step > 0 && i >= end)) break;
|
5170 | result.push(arr[i]);
|
5171 | }
|
5172 |
|
5173 | return result;
|
5174 | }
|
5175 |
|
5176 | function integer(val) {
|
5177 | return String(val).match(/^[0-9]+$/) ? parseInt(val) :
|
5178 | Number.isFinite(val) ? parseInt(val, 10) : 0;
|
5179 | }
|
5180 |
|
5181 | },{}],8:[function(require,module,exports){
|
5182 |
|
5183 |
|
5184 |
|
5185 |
|
5186 |
|
5187 |
|
5188 |
|
5189 |
|
5190 |
|
5191 |
|
5192 |
|
5193 |
|
5194 |
|
5195 |
|
5196 |
|
5197 |
|
5198 |
|
5199 |
|
5200 |
|
5201 |
|
5202 |
|
5203 |
|
5204 |
|
5205 |
|
5206 |
|
5207 |
|
5208 |
|
5209 | var util = require('util/');
|
5210 |
|
5211 | var pSlice = Array.prototype.slice;
|
5212 | var hasOwn = Object.prototype.hasOwnProperty;
|
5213 |
|
5214 |
|
5215 |
|
5216 |
|
5217 |
|
5218 | var assert = module.exports = ok;
|
5219 |
|
5220 |
|
5221 |
|
5222 |
|
5223 |
|
5224 |
|
5225 | assert.AssertionError = function AssertionError(options) {
|
5226 | this.name = 'AssertionError';
|
5227 | this.actual = options.actual;
|
5228 | this.expected = options.expected;
|
5229 | this.operator = options.operator;
|
5230 | if (options.message) {
|
5231 | this.message = options.message;
|
5232 | this.generatedMessage = false;
|
5233 | } else {
|
5234 | this.message = getMessage(this);
|
5235 | this.generatedMessage = true;
|
5236 | }
|
5237 | var stackStartFunction = options.stackStartFunction || fail;
|
5238 |
|
5239 | if (Error.captureStackTrace) {
|
5240 | Error.captureStackTrace(this, stackStartFunction);
|
5241 | }
|
5242 | else {
|
5243 |
|
5244 | var err = new Error();
|
5245 | if (err.stack) {
|
5246 | var out = err.stack;
|
5247 |
|
5248 |
|
5249 | var fn_name = stackStartFunction.name;
|
5250 | var idx = out.indexOf('\n' + fn_name);
|
5251 | if (idx >= 0) {
|
5252 |
|
5253 |
|
5254 | var next_line = out.indexOf('\n', idx + 1);
|
5255 | out = out.substring(next_line + 1);
|
5256 | }
|
5257 |
|
5258 | this.stack = out;
|
5259 | }
|
5260 | }
|
5261 | };
|
5262 |
|
5263 |
|
5264 | util.inherits(assert.AssertionError, Error);
|
5265 |
|
5266 | function replacer(key, value) {
|
5267 | if (util.isUndefined(value)) {
|
5268 | return '' + value;
|
5269 | }
|
5270 | if (util.isNumber(value) && !isFinite(value)) {
|
5271 | return value.toString();
|
5272 | }
|
5273 | if (util.isFunction(value) || util.isRegExp(value)) {
|
5274 | return value.toString();
|
5275 | }
|
5276 | return value;
|
5277 | }
|
5278 |
|
5279 | function truncate(s, n) {
|
5280 | if (util.isString(s)) {
|
5281 | return s.length < n ? s : s.slice(0, n);
|
5282 | } else {
|
5283 | return s;
|
5284 | }
|
5285 | }
|
5286 |
|
5287 | function getMessage(self) {
|
5288 | return truncate(JSON.stringify(self.actual, replacer), 128) + ' ' +
|
5289 | self.operator + ' ' +
|
5290 | truncate(JSON.stringify(self.expected, replacer), 128);
|
5291 | }
|
5292 |
|
5293 |
|
5294 |
|
5295 |
|
5296 |
|
5297 |
|
5298 |
|
5299 |
|
5300 |
|
5301 |
|
5302 |
|
5303 |
|
5304 | function fail(actual, expected, message, operator, stackStartFunction) {
|
5305 | throw new assert.AssertionError({
|
5306 | message: message,
|
5307 | actual: actual,
|
5308 | expected: expected,
|
5309 | operator: operator,
|
5310 | stackStartFunction: stackStartFunction
|
5311 | });
|
5312 | }
|
5313 |
|
5314 |
|
5315 | assert.fail = fail;
|
5316 |
|
5317 |
|
5318 |
|
5319 |
|
5320 |
|
5321 |
|
5322 |
|
5323 |
|
5324 | function ok(value, message) {
|
5325 | if (!value) fail(value, true, message, '==', assert.ok);
|
5326 | }
|
5327 | assert.ok = ok;
|
5328 |
|
5329 |
|
5330 |
|
5331 |
|
5332 |
|
5333 | assert.equal = function equal(actual, expected, message) {
|
5334 | if (actual != expected) fail(actual, expected, message, '==', assert.equal);
|
5335 | };
|
5336 |
|
5337 |
|
5338 |
|
5339 |
|
5340 | assert.notEqual = function notEqual(actual, expected, message) {
|
5341 | if (actual == expected) {
|
5342 | fail(actual, expected, message, '!=', assert.notEqual);
|
5343 | }
|
5344 | };
|
5345 |
|
5346 |
|
5347 |
|
5348 |
|
5349 | assert.deepEqual = function deepEqual(actual, expected, message) {
|
5350 | if (!_deepEqual(actual, expected)) {
|
5351 | fail(actual, expected, message, 'deepEqual', assert.deepEqual);
|
5352 | }
|
5353 | };
|
5354 |
|
5355 | function _deepEqual(actual, expected) {
|
5356 |
|
5357 | if (actual === expected) {
|
5358 | return true;
|
5359 |
|
5360 | } else if (util.isBuffer(actual) && util.isBuffer(expected)) {
|
5361 | if (actual.length != expected.length) return false;
|
5362 |
|
5363 | for (var i = 0; i < actual.length; i++) {
|
5364 | if (actual[i] !== expected[i]) return false;
|
5365 | }
|
5366 |
|
5367 | return true;
|
5368 |
|
5369 |
|
5370 |
|
5371 | } else if (util.isDate(actual) && util.isDate(expected)) {
|
5372 | return actual.getTime() === expected.getTime();
|
5373 |
|
5374 |
|
5375 |
|
5376 |
|
5377 | } else if (util.isRegExp(actual) && util.isRegExp(expected)) {
|
5378 | return actual.source === expected.source &&
|
5379 | actual.global === expected.global &&
|
5380 | actual.multiline === expected.multiline &&
|
5381 | actual.lastIndex === expected.lastIndex &&
|
5382 | actual.ignoreCase === expected.ignoreCase;
|
5383 |
|
5384 |
|
5385 |
|
5386 | } else if (!util.isObject(actual) && !util.isObject(expected)) {
|
5387 | return actual == expected;
|
5388 |
|
5389 |
|
5390 |
|
5391 |
|
5392 |
|
5393 |
|
5394 |
|
5395 | } else {
|
5396 | return objEquiv(actual, expected);
|
5397 | }
|
5398 | }
|
5399 |
|
5400 | function isArguments(object) {
|
5401 | return Object.prototype.toString.call(object) == '[object Arguments]';
|
5402 | }
|
5403 |
|
5404 | function objEquiv(a, b) {
|
5405 | if (util.isNullOrUndefined(a) || util.isNullOrUndefined(b))
|
5406 | return false;
|
5407 |
|
5408 | if (a.prototype !== b.prototype) return false;
|
5409 |
|
5410 | if (util.isPrimitive(a) || util.isPrimitive(b)) {
|
5411 | return a === b;
|
5412 | }
|
5413 | var aIsArgs = isArguments(a),
|
5414 | bIsArgs = isArguments(b);
|
5415 | if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs))
|
5416 | return false;
|
5417 | if (aIsArgs) {
|
5418 | a = pSlice.call(a);
|
5419 | b = pSlice.call(b);
|
5420 | return _deepEqual(a, b);
|
5421 | }
|
5422 | var ka = objectKeys(a),
|
5423 | kb = objectKeys(b),
|
5424 | key, i;
|
5425 |
|
5426 |
|
5427 | if (ka.length != kb.length)
|
5428 | return false;
|
5429 |
|
5430 | ka.sort();
|
5431 | kb.sort();
|
5432 |
|
5433 | for (i = ka.length - 1; i >= 0; i--) {
|
5434 | if (ka[i] != kb[i])
|
5435 | return false;
|
5436 | }
|
5437 |
|
5438 |
|
5439 | for (i = ka.length - 1; i >= 0; i--) {
|
5440 | key = ka[i];
|
5441 | if (!_deepEqual(a[key], b[key])) return false;
|
5442 | }
|
5443 | return true;
|
5444 | }
|
5445 |
|
5446 |
|
5447 |
|
5448 |
|
5449 | assert.notDeepEqual = function notDeepEqual(actual, expected, message) {
|
5450 | if (_deepEqual(actual, expected)) {
|
5451 | fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual);
|
5452 | }
|
5453 | };
|
5454 |
|
5455 |
|
5456 |
|
5457 |
|
5458 | assert.strictEqual = function strictEqual(actual, expected, message) {
|
5459 | if (actual !== expected) {
|
5460 | fail(actual, expected, message, '===', assert.strictEqual);
|
5461 | }
|
5462 | };
|
5463 |
|
5464 |
|
5465 |
|
5466 |
|
5467 | assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
|
5468 | if (actual === expected) {
|
5469 | fail(actual, expected, message, '!==', assert.notStrictEqual);
|
5470 | }
|
5471 | };
|
5472 |
|
5473 | function expectedException(actual, expected) {
|
5474 | if (!actual || !expected) {
|
5475 | return false;
|
5476 | }
|
5477 |
|
5478 | if (Object.prototype.toString.call(expected) == '[object RegExp]') {
|
5479 | return expected.test(actual);
|
5480 | } else if (actual instanceof expected) {
|
5481 | return true;
|
5482 | } else if (expected.call({}, actual) === true) {
|
5483 | return true;
|
5484 | }
|
5485 |
|
5486 | return false;
|
5487 | }
|
5488 |
|
5489 | function _throws(shouldThrow, block, expected, message) {
|
5490 | var actual;
|
5491 |
|
5492 | if (util.isString(expected)) {
|
5493 | message = expected;
|
5494 | expected = null;
|
5495 | }
|
5496 |
|
5497 | try {
|
5498 | block();
|
5499 | } catch (e) {
|
5500 | actual = e;
|
5501 | }
|
5502 |
|
5503 | message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
|
5504 | (message ? ' ' + message : '.');
|
5505 |
|
5506 | if (shouldThrow && !actual) {
|
5507 | fail(actual, expected, 'Missing expected exception' + message);
|
5508 | }
|
5509 |
|
5510 | if (!shouldThrow && expectedException(actual, expected)) {
|
5511 | fail(actual, expected, 'Got unwanted exception' + message);
|
5512 | }
|
5513 |
|
5514 | if ((shouldThrow && actual && expected &&
|
5515 | !expectedException(actual, expected)) || (!shouldThrow && actual)) {
|
5516 | throw actual;
|
5517 | }
|
5518 | }
|
5519 |
|
5520 |
|
5521 |
|
5522 |
|
5523 | assert.throws = function(block, /*optional*/error, /*optional*/message) {
|
5524 | _throws.apply(this, [true].concat(pSlice.call(arguments)));
|
5525 | };
|
5526 |
|
5527 |
|
5528 | assert.doesNotThrow = function(block, /*optional*/message) {
|
5529 | _throws.apply(this, [false].concat(pSlice.call(arguments)));
|
5530 | };
|
5531 |
|
5532 | assert.ifError = function(err) { if (err) {throw err;}};
|
5533 |
|
5534 | var objectKeys = Object.keys || function (obj) {
|
5535 | var keys = [];
|
5536 | for (var key in obj) {
|
5537 | if (hasOwn.call(obj, key)) keys.push(key);
|
5538 | }
|
5539 | return keys;
|
5540 | };
|
5541 |
|
5542 | },{"util/":11}],9:[function(require,module,exports){
|
5543 | if (typeof Object.create === 'function') {
|
5544 |
|
5545 | module.exports = function inherits(ctor, superCtor) {
|
5546 | ctor.super_ = superCtor
|
5547 | ctor.prototype = Object.create(superCtor.prototype, {
|
5548 | constructor: {
|
5549 | value: ctor,
|
5550 | enumerable: false,
|
5551 | writable: true,
|
5552 | configurable: true
|
5553 | }
|
5554 | });
|
5555 | };
|
5556 | } else {
|
5557 |
|
5558 | module.exports = function inherits(ctor, superCtor) {
|
5559 | ctor.super_ = superCtor
|
5560 | var TempCtor = function () {}
|
5561 | TempCtor.prototype = superCtor.prototype
|
5562 | ctor.prototype = new TempCtor()
|
5563 | ctor.prototype.constructor = ctor
|
5564 | }
|
5565 | }
|
5566 |
|
5567 | },{}],10:[function(require,module,exports){
|
5568 | module.exports = function isBuffer(arg) {
|
5569 | return arg && typeof arg === 'object'
|
5570 | && typeof arg.copy === 'function'
|
5571 | && typeof arg.fill === 'function'
|
5572 | && typeof arg.readUInt8 === 'function';
|
5573 | }
|
5574 | },{}],11:[function(require,module,exports){
|
5575 | (function (process,global){
|
5576 |
|
5577 |
|
5578 |
|
5579 |
|
5580 |
|
5581 |
|
5582 |
|
5583 |
|
5584 |
|
5585 |
|
5586 |
|
5587 |
|
5588 |
|
5589 |
|
5590 |
|
5591 |
|
5592 |
|
5593 |
|
5594 |
|
5595 |
|
5596 |
|
5597 | var formatRegExp = /%[sdj%]/g;
|
5598 | exports.format = function(f) {
|
5599 | if (!isString(f)) {
|
5600 | var objects = [];
|
5601 | for (var i = 0; i < arguments.length; i++) {
|
5602 | objects.push(inspect(arguments[i]));
|
5603 | }
|
5604 | return objects.join(' ');
|
5605 | }
|
5606 |
|
5607 | var i = 1;
|
5608 | var args = arguments;
|
5609 | var len = args.length;
|
5610 | var str = String(f).replace(formatRegExp, function(x) {
|
5611 | if (x === '%%') return '%';
|
5612 | if (i >= len) return x;
|
5613 | switch (x) {
|
5614 | case '%s': return String(args[i++]);
|
5615 | case '%d': return Number(args[i++]);
|
5616 | case '%j':
|
5617 | try {
|
5618 | return JSON.stringify(args[i++]);
|
5619 | } catch (_) {
|
5620 | return '[Circular]';
|
5621 | }
|
5622 | default:
|
5623 | return x;
|
5624 | }
|
5625 | });
|
5626 | for (var x = args[i]; i < len; x = args[++i]) {
|
5627 | if (isNull(x) || !isObject(x)) {
|
5628 | str += ' ' + x;
|
5629 | } else {
|
5630 | str += ' ' + inspect(x);
|
5631 | }
|
5632 | }
|
5633 | return str;
|
5634 | };
|
5635 |
|
5636 |
|
5637 |
|
5638 |
|
5639 |
|
5640 | exports.deprecate = function(fn, msg) {
|
5641 |
|
5642 | if (isUndefined(global.process)) {
|
5643 | return function() {
|
5644 | return exports.deprecate(fn, msg).apply(this, arguments);
|
5645 | };
|
5646 | }
|
5647 |
|
5648 | if (process.noDeprecation === true) {
|
5649 | return fn;
|
5650 | }
|
5651 |
|
5652 | var warned = false;
|
5653 | function deprecated() {
|
5654 | if (!warned) {
|
5655 | if (process.throwDeprecation) {
|
5656 | throw new Error(msg);
|
5657 | } else if (process.traceDeprecation) {
|
5658 | console.trace(msg);
|
5659 | } else {
|
5660 | console.error(msg);
|
5661 | }
|
5662 | warned = true;
|
5663 | }
|
5664 | return fn.apply(this, arguments);
|
5665 | }
|
5666 |
|
5667 | return deprecated;
|
5668 | };
|
5669 |
|
5670 |
|
5671 | var debugs = {};
|
5672 | var debugEnviron;
|
5673 | exports.debuglog = function(set) {
|
5674 | if (isUndefined(debugEnviron))
|
5675 | debugEnviron = process.env.NODE_DEBUG || '';
|
5676 | set = set.toUpperCase();
|
5677 | if (!debugs[set]) {
|
5678 | if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
|
5679 | var pid = process.pid;
|
5680 | debugs[set] = function() {
|
5681 | var msg = exports.format.apply(exports, arguments);
|
5682 | console.error('%s %d: %s', set, pid, msg);
|
5683 | };
|
5684 | } else {
|
5685 | debugs[set] = function() {};
|
5686 | }
|
5687 | }
|
5688 | return debugs[set];
|
5689 | };
|
5690 |
|
5691 |
|
5692 | /**
|
5693 | * Echos the value of a value. Trys to print the value out
|
5694 | * in the best way possible given the different types.
|
5695 | *
|
5696 | * @param {Object} obj The object to print out.
|
5697 | * @param {Object} opts Optional options object that alters the output.
|
5698 | */
|
5699 |
|
5700 | function inspect(obj, opts) {
|
5701 |
|
5702 | var ctx = {
|
5703 | seen: [],
|
5704 | stylize: stylizeNoColor
|
5705 | };
|
5706 |
|
5707 | if (arguments.length >= 3) ctx.depth = arguments[2];
|
5708 | if (arguments.length >= 4) ctx.colors = arguments[3];
|
5709 | if (isBoolean(opts)) {
|
5710 |
|
5711 | ctx.showHidden = opts;
|
5712 | } else if (opts) {
|
5713 |
|
5714 | exports._extend(ctx, opts);
|
5715 | }
|
5716 |
|
5717 | if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
|
5718 | if (isUndefined(ctx.depth)) ctx.depth = 2;
|
5719 | if (isUndefined(ctx.colors)) ctx.colors = false;
|
5720 | if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
|
5721 | if (ctx.colors) ctx.stylize = stylizeWithColor;
|
5722 | return formatValue(ctx, obj, ctx.depth);
|
5723 | }
|
5724 | exports.inspect = inspect;
|
5725 |
|
5726 |
|
5727 |
|
5728 | inspect.colors = {
|
5729 | 'bold' : [1, 22],
|
5730 | 'italic' : [3, 23],
|
5731 | 'underline' : [4, 24],
|
5732 | 'inverse' : [7, 27],
|
5733 | 'white' : [37, 39],
|
5734 | 'grey' : [90, 39],
|
5735 | 'black' : [30, 39],
|
5736 | 'blue' : [34, 39],
|
5737 | 'cyan' : [36, 39],
|
5738 | 'green' : [32, 39],
|
5739 | 'magenta' : [35, 39],
|
5740 | 'red' : [31, 39],
|
5741 | 'yellow' : [33, 39]
|
5742 | };
|
5743 |
|
5744 |
|
5745 | inspect.styles = {
|
5746 | 'special': 'cyan',
|
5747 | 'number': 'yellow',
|
5748 | 'boolean': 'yellow',
|
5749 | 'undefined': 'grey',
|
5750 | 'null': 'bold',
|
5751 | 'string': 'green',
|
5752 | 'date': 'magenta',
|
5753 |
|
5754 | 'regexp': 'red'
|
5755 | };
|
5756 |
|
5757 |
|
5758 | function stylizeWithColor(str, styleType) {
|
5759 | var style = inspect.styles[styleType];
|
5760 |
|
5761 | if (style) {
|
5762 | return '\u001b[' + inspect.colors[style][0] + 'm' + str +
|
5763 | '\u001b[' + inspect.colors[style][1] + 'm';
|
5764 | } else {
|
5765 | return str;
|
5766 | }
|
5767 | }
|
5768 |
|
5769 |
|
5770 | function stylizeNoColor(str, styleType) {
|
5771 | return str;
|
5772 | }
|
5773 |
|
5774 |
|
5775 | function arrayToHash(array) {
|
5776 | var hash = {};
|
5777 |
|
5778 | array.forEach(function(val, idx) {
|
5779 | hash[val] = true;
|
5780 | });
|
5781 |
|
5782 | return hash;
|
5783 | }
|
5784 |
|
5785 |
|
5786 | function formatValue(ctx, value, recurseTimes) {
|
5787 |
|
5788 |
|
5789 | if (ctx.customInspect &&
|
5790 | value &&
|
5791 | isFunction(value.inspect) &&
|
5792 |
|
5793 | value.inspect !== exports.inspect &&
|
5794 |
|
5795 | !(value.constructor && value.constructor.prototype === value)) {
|
5796 | var ret = value.inspect(recurseTimes, ctx);
|
5797 | if (!isString(ret)) {
|
5798 | ret = formatValue(ctx, ret, recurseTimes);
|
5799 | }
|
5800 | return ret;
|
5801 | }
|
5802 |
|
5803 |
|
5804 | var primitive = formatPrimitive(ctx, value);
|
5805 | if (primitive) {
|
5806 | return primitive;
|
5807 | }
|
5808 |
|
5809 |
|
5810 | var keys = Object.keys(value);
|
5811 | var visibleKeys = arrayToHash(keys);
|
5812 |
|
5813 | if (ctx.showHidden) {
|
5814 | keys = Object.getOwnPropertyNames(value);
|
5815 | }
|
5816 |
|
5817 |
|
5818 |
|
5819 | if (isError(value)
|
5820 | && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
|
5821 | return formatError(value);
|
5822 | }
|
5823 |
|
5824 |
|
5825 | if (keys.length === 0) {
|
5826 | if (isFunction(value)) {
|
5827 | var name = value.name ? ': ' + value.name : '';
|
5828 | return ctx.stylize('[Function' + name + ']', 'special');
|
5829 | }
|
5830 | if (isRegExp(value)) {
|
5831 | return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
5832 | }
|
5833 | if (isDate(value)) {
|
5834 | return ctx.stylize(Date.prototype.toString.call(value), 'date');
|
5835 | }
|
5836 | if (isError(value)) {
|
5837 | return formatError(value);
|
5838 | }
|
5839 | }
|
5840 |
|
5841 | var base = '', array = false, braces = ['{', '}'];
|
5842 |
|
5843 |
|
5844 | if (isArray(value)) {
|
5845 | array = true;
|
5846 | braces = ['[', ']'];
|
5847 | }
|
5848 |
|
5849 |
|
5850 | if (isFunction(value)) {
|
5851 | var n = value.name ? ': ' + value.name : '';
|
5852 | base = ' [Function' + n + ']';
|
5853 | }
|
5854 |
|
5855 |
|
5856 | if (isRegExp(value)) {
|
5857 | base = ' ' + RegExp.prototype.toString.call(value);
|
5858 | }
|
5859 |
|
5860 |
|
5861 | if (isDate(value)) {
|
5862 | base = ' ' + Date.prototype.toUTCString.call(value);
|
5863 | }
|
5864 |
|
5865 |
|
5866 | if (isError(value)) {
|
5867 | base = ' ' + formatError(value);
|
5868 | }
|
5869 |
|
5870 | if (keys.length === 0 && (!array || value.length == 0)) {
|
5871 | return braces[0] + base + braces[1];
|
5872 | }
|
5873 |
|
5874 | if (recurseTimes < 0) {
|
5875 | if (isRegExp(value)) {
|
5876 | return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
5877 | } else {
|
5878 | return ctx.stylize('[Object]', 'special');
|
5879 | }
|
5880 | }
|
5881 |
|
5882 | ctx.seen.push(value);
|
5883 |
|
5884 | var output;
|
5885 | if (array) {
|
5886 | output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
|
5887 | } else {
|
5888 | output = keys.map(function(key) {
|
5889 | return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
|
5890 | });
|
5891 | }
|
5892 |
|
5893 | ctx.seen.pop();
|
5894 |
|
5895 | return reduceToSingleString(output, base, braces);
|
5896 | }
|
5897 |
|
5898 |
|
5899 | function formatPrimitive(ctx, value) {
|
5900 | if (isUndefined(value))
|
5901 | return ctx.stylize('undefined', 'undefined');
|
5902 | if (isString(value)) {
|
5903 | var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
|
5904 | .replace(/'/g, "\\'")
|
5905 | .replace(/\\"/g, '"') + '\'';
|
5906 | return ctx.stylize(simple, 'string');
|
5907 | }
|
5908 | if (isNumber(value))
|
5909 | return ctx.stylize('' + value, 'number');
|
5910 | if (isBoolean(value))
|
5911 | return ctx.stylize('' + value, 'boolean');
|
5912 |
|
5913 | if (isNull(value))
|
5914 | return ctx.stylize('null', 'null');
|
5915 | }
|
5916 |
|
5917 |
|
5918 | function formatError(value) {
|
5919 | return '[' + Error.prototype.toString.call(value) + ']';
|
5920 | }
|
5921 |
|
5922 |
|
5923 | function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
|
5924 | var output = [];
|
5925 | for (var i = 0, l = value.length; i < l; ++i) {
|
5926 | if (hasOwnProperty(value, String(i))) {
|
5927 | output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
5928 | String(i), true));
|
5929 | } else {
|
5930 | output.push('');
|
5931 | }
|
5932 | }
|
5933 | keys.forEach(function(key) {
|
5934 | if (!key.match(/^\d+$/)) {
|
5935 | output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
5936 | key, true));
|
5937 | }
|
5938 | });
|
5939 | return output;
|
5940 | }
|
5941 |
|
5942 |
|
5943 | function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
|
5944 | var name, str, desc;
|
5945 | desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
|
5946 | if (desc.get) {
|
5947 | if (desc.set) {
|
5948 | str = ctx.stylize('[Getter/Setter]', 'special');
|
5949 | } else {
|
5950 | str = ctx.stylize('[Getter]', 'special');
|
5951 | }
|
5952 | } else {
|
5953 | if (desc.set) {
|
5954 | str = ctx.stylize('[Setter]', 'special');
|
5955 | }
|
5956 | }
|
5957 | if (!hasOwnProperty(visibleKeys, key)) {
|
5958 | name = '[' + key + ']';
|
5959 | }
|
5960 | if (!str) {
|
5961 | if (ctx.seen.indexOf(desc.value) < 0) {
|
5962 | if (isNull(recurseTimes)) {
|
5963 | str = formatValue(ctx, desc.value, null);
|
5964 | } else {
|
5965 | str = formatValue(ctx, desc.value, recurseTimes - 1);
|
5966 | }
|
5967 | if (str.indexOf('\n') > -1) {
|
5968 | if (array) {
|
5969 | str = str.split('\n').map(function(line) {
|
5970 | return ' ' + line;
|
5971 | }).join('\n').substr(2);
|
5972 | } else {
|
5973 | str = '\n' + str.split('\n').map(function(line) {
|
5974 | return ' ' + line;
|
5975 | }).join('\n');
|
5976 | }
|
5977 | }
|
5978 | } else {
|
5979 | str = ctx.stylize('[Circular]', 'special');
|
5980 | }
|
5981 | }
|
5982 | if (isUndefined(name)) {
|
5983 | if (array && key.match(/^\d+$/)) {
|
5984 | return str;
|
5985 | }
|
5986 | name = JSON.stringify('' + key);
|
5987 | if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
|
5988 | name = name.substr(1, name.length - 2);
|
5989 | name = ctx.stylize(name, 'name');
|
5990 | } else {
|
5991 | name = name.replace(/'/g, "\\'")
|
5992 | .replace(/\\"/g, '"')
|
5993 | .replace(/(^"|"$)/g, "'");
|
5994 | name = ctx.stylize(name, 'string');
|
5995 | }
|
5996 | }
|
5997 |
|
5998 | return name + ': ' + str;
|
5999 | }
|
6000 |
|
6001 |
|
6002 | function reduceToSingleString(output, base, braces) {
|
6003 | var numLinesEst = 0;
|
6004 | var length = output.reduce(function(prev, cur) {
|
6005 | numLinesEst++;
|
6006 | if (cur.indexOf('\n') >= 0) numLinesEst++;
|
6007 | return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
|
6008 | }, 0);
|
6009 |
|
6010 | if (length > 60) {
|
6011 | return braces[0] +
|
6012 | (base === '' ? '' : base + '\n ') +
|
6013 | ' ' +
|
6014 | output.join(',\n ') +
|
6015 | ' ' +
|
6016 | braces[1];
|
6017 | }
|
6018 |
|
6019 | return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
|
6020 | }
|
6021 |
|
6022 |
|
6023 |
|
6024 |
|
6025 | function isArray(ar) {
|
6026 | return Array.isArray(ar);
|
6027 | }
|
6028 | exports.isArray = isArray;
|
6029 |
|
6030 | function isBoolean(arg) {
|
6031 | return typeof arg === 'boolean';
|
6032 | }
|
6033 | exports.isBoolean = isBoolean;
|
6034 |
|
6035 | function isNull(arg) {
|
6036 | return arg === null;
|
6037 | }
|
6038 | exports.isNull = isNull;
|
6039 |
|
6040 | function isNullOrUndefined(arg) {
|
6041 | return arg == null;
|
6042 | }
|
6043 | exports.isNullOrUndefined = isNullOrUndefined;
|
6044 |
|
6045 | function isNumber(arg) {
|
6046 | return typeof arg === 'number';
|
6047 | }
|
6048 | exports.isNumber = isNumber;
|
6049 |
|
6050 | function isString(arg) {
|
6051 | return typeof arg === 'string';
|
6052 | }
|
6053 | exports.isString = isString;
|
6054 |
|
6055 | function isSymbol(arg) {
|
6056 | return typeof arg === 'symbol';
|
6057 | }
|
6058 | exports.isSymbol = isSymbol;
|
6059 |
|
6060 | function isUndefined(arg) {
|
6061 | return arg === void 0;
|
6062 | }
|
6063 | exports.isUndefined = isUndefined;
|
6064 |
|
6065 | function isRegExp(re) {
|
6066 | return isObject(re) && objectToString(re) === '[object RegExp]';
|
6067 | }
|
6068 | exports.isRegExp = isRegExp;
|
6069 |
|
6070 | function isObject(arg) {
|
6071 | return typeof arg === 'object' && arg !== null;
|
6072 | }
|
6073 | exports.isObject = isObject;
|
6074 |
|
6075 | function isDate(d) {
|
6076 | return isObject(d) && objectToString(d) === '[object Date]';
|
6077 | }
|
6078 | exports.isDate = isDate;
|
6079 |
|
6080 | function isError(e) {
|
6081 | return isObject(e) &&
|
6082 | (objectToString(e) === '[object Error]' || e instanceof Error);
|
6083 | }
|
6084 | exports.isError = isError;
|
6085 |
|
6086 | function isFunction(arg) {
|
6087 | return typeof arg === 'function';
|
6088 | }
|
6089 | exports.isFunction = isFunction;
|
6090 |
|
6091 | function isPrimitive(arg) {
|
6092 | return arg === null ||
|
6093 | typeof arg === 'boolean' ||
|
6094 | typeof arg === 'number' ||
|
6095 | typeof arg === 'string' ||
|
6096 | typeof arg === 'symbol' ||
|
6097 | typeof arg === 'undefined';
|
6098 | }
|
6099 | exports.isPrimitive = isPrimitive;
|
6100 |
|
6101 | exports.isBuffer = require('./support/isBuffer');
|
6102 |
|
6103 | function objectToString(o) {
|
6104 | return Object.prototype.toString.call(o);
|
6105 | }
|
6106 |
|
6107 |
|
6108 | function pad(n) {
|
6109 | return n < 10 ? '0' + n.toString(10) : n.toString(10);
|
6110 | }
|
6111 |
|
6112 |
|
6113 | var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
|
6114 | 'Oct', 'Nov', 'Dec'];
|
6115 |
|
6116 |
|
6117 | function timestamp() {
|
6118 | var d = new Date();
|
6119 | var time = [pad(d.getHours()),
|
6120 | pad(d.getMinutes()),
|
6121 | pad(d.getSeconds())].join(':');
|
6122 | return [d.getDate(), months[d.getMonth()], time].join(' ');
|
6123 | }
|
6124 |
|
6125 |
|
6126 |
|
6127 | exports.log = function() {
|
6128 | console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
|
6129 | };
|
6130 |
|
6131 |
|
6132 |
|
6133 |
|
6134 |
|
6135 |
|
6136 |
|
6137 |
|
6138 |
|
6139 |
|
6140 |
|
6141 |
|
6142 |
|
6143 |
|
6144 |
|
6145 | exports.inherits = require('inherits');
|
6146 |
|
6147 | exports._extend = function(origin, add) {
|
6148 |
|
6149 | if (!add || !isObject(add)) return origin;
|
6150 |
|
6151 | var keys = Object.keys(add);
|
6152 | var i = keys.length;
|
6153 | while (i--) {
|
6154 | origin[keys[i]] = add[keys[i]];
|
6155 | }
|
6156 | return origin;
|
6157 | };
|
6158 |
|
6159 | function hasOwnProperty(obj, prop) {
|
6160 | return Object.prototype.hasOwnProperty.call(obj, prop);
|
6161 | }
|
6162 |
|
6163 | }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
6164 | },{"./support/isBuffer":10,"_process":14,"inherits":9}],12:[function(require,module,exports){
|
6165 |
|
6166 | },{}],13:[function(require,module,exports){
|
6167 | (function (process){
|
6168 |
|
6169 |
|
6170 |
|
6171 |
|
6172 |
|
6173 |
|
6174 |
|
6175 |
|
6176 |
|
6177 |
|
6178 |
|
6179 |
|
6180 |
|
6181 |
|
6182 |
|
6183 |
|
6184 |
|
6185 |
|
6186 |
|
6187 |
|
6188 |
|
6189 |
|
6190 |
|
6191 |
|
6192 |
|
6193 |
|
6194 |
|
6195 |
|
6196 | function normalizeArray(parts, allowAboveRoot) {
|
6197 |
|
6198 | var up = 0;
|
6199 | for (var i = parts.length - 1; i >= 0; i--) {
|
6200 | var last = parts[i];
|
6201 | if (last === '.') {
|
6202 | parts.splice(i, 1);
|
6203 | } else if (last === '..') {
|
6204 | parts.splice(i, 1);
|
6205 | up++;
|
6206 | } else if (up) {
|
6207 | parts.splice(i, 1);
|
6208 | up--;
|
6209 | }
|
6210 | }
|
6211 |
|
6212 |
|
6213 | if (allowAboveRoot) {
|
6214 | for (; up--; up) {
|
6215 | parts.unshift('..');
|
6216 | }
|
6217 | }
|
6218 |
|
6219 | return parts;
|
6220 | }
|
6221 |
|
6222 |
|
6223 |
|
6224 | exports.resolve = function() {
|
6225 | var resolvedPath = '',
|
6226 | resolvedAbsolute = false;
|
6227 |
|
6228 | for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
6229 | var path = (i >= 0) ? arguments[i] : process.cwd();
|
6230 |
|
6231 |
|
6232 | if (typeof path !== 'string') {
|
6233 | throw new TypeError('Arguments to path.resolve must be strings');
|
6234 | } else if (!path) {
|
6235 | continue;
|
6236 | }
|
6237 |
|
6238 | resolvedPath = path + '/' + resolvedPath;
|
6239 | resolvedAbsolute = path.charAt(0) === '/';
|
6240 | }
|
6241 |
|
6242 |
|
6243 |
|
6244 |
|
6245 |
|
6246 | resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
|
6247 | return !!p;
|
6248 | }), !resolvedAbsolute).join('/');
|
6249 |
|
6250 | return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
|
6251 | };
|
6252 |
|
6253 |
|
6254 |
|
6255 | exports.normalize = function(path) {
|
6256 | var isAbsolute = exports.isAbsolute(path),
|
6257 | trailingSlash = substr(path, -1) === '/';
|
6258 |
|
6259 |
|
6260 | path = normalizeArray(filter(path.split('/'), function(p) {
|
6261 | return !!p;
|
6262 | }), !isAbsolute).join('/');
|
6263 |
|
6264 | if (!path && !isAbsolute) {
|
6265 | path = '.';
|
6266 | }
|
6267 | if (path && trailingSlash) {
|
6268 | path += '/';
|
6269 | }
|
6270 |
|
6271 | return (isAbsolute ? '/' : '') + path;
|
6272 | };
|
6273 |
|
6274 |
|
6275 | exports.isAbsolute = function(path) {
|
6276 | return path.charAt(0) === '/';
|
6277 | };
|
6278 |
|
6279 |
|
6280 | exports.join = function() {
|
6281 | var paths = Array.prototype.slice.call(arguments, 0);
|
6282 | return exports.normalize(filter(paths, function(p, index) {
|
6283 | if (typeof p !== 'string') {
|
6284 | throw new TypeError('Arguments to path.join must be strings');
|
6285 | }
|
6286 | return p;
|
6287 | }).join('/'));
|
6288 | };
|
6289 |
|
6290 |
|
6291 |
|
6292 |
|
6293 | exports.relative = function(from, to) {
|
6294 | from = exports.resolve(from).substr(1);
|
6295 | to = exports.resolve(to).substr(1);
|
6296 |
|
6297 | function trim(arr) {
|
6298 | var start = 0;
|
6299 | for (; start < arr.length; start++) {
|
6300 | if (arr[start] !== '') break;
|
6301 | }
|
6302 |
|
6303 | var end = arr.length - 1;
|
6304 | for (; end >= 0; end--) {
|
6305 | if (arr[end] !== '') break;
|
6306 | }
|
6307 |
|
6308 | if (start > end) return [];
|
6309 | return arr.slice(start, end - start + 1);
|
6310 | }
|
6311 |
|
6312 | var fromParts = trim(from.split('/'));
|
6313 | var toParts = trim(to.split('/'));
|
6314 |
|
6315 | var length = Math.min(fromParts.length, toParts.length);
|
6316 | var samePartsLength = length;
|
6317 | for (var i = 0; i < length; i++) {
|
6318 | if (fromParts[i] !== toParts[i]) {
|
6319 | samePartsLength = i;
|
6320 | break;
|
6321 | }
|
6322 | }
|
6323 |
|
6324 | var outputParts = [];
|
6325 | for (var i = samePartsLength; i < fromParts.length; i++) {
|
6326 | outputParts.push('..');
|
6327 | }
|
6328 |
|
6329 | outputParts = outputParts.concat(toParts.slice(samePartsLength));
|
6330 |
|
6331 | return outputParts.join('/');
|
6332 | };
|
6333 |
|
6334 | exports.sep = '/';
|
6335 | exports.delimiter = ':';
|
6336 |
|
6337 | exports.dirname = function (path) {
|
6338 | if (typeof path !== 'string') path = path + '';
|
6339 | if (path.length === 0) return '.';
|
6340 | var code = path.charCodeAt(0);
|
6341 | var hasRoot = code === 47 ;
|
6342 | var end = -1;
|
6343 | var matchedSlash = true;
|
6344 | for (var i = path.length - 1; i >= 1; --i) {
|
6345 | code = path.charCodeAt(i);
|
6346 | if (code === 47 ) {
|
6347 | if (!matchedSlash) {
|
6348 | end = i;
|
6349 | break;
|
6350 | }
|
6351 | } else {
|
6352 |
|
6353 | matchedSlash = false;
|
6354 | }
|
6355 | }
|
6356 |
|
6357 | if (end === -1) return hasRoot ? '/' : '.';
|
6358 | if (hasRoot && end === 1) {
|
6359 |
|
6360 |
|
6361 | return '/';
|
6362 | }
|
6363 | return path.slice(0, end);
|
6364 | };
|
6365 |
|
6366 | function basename(path) {
|
6367 | if (typeof path !== 'string') path = path + '';
|
6368 |
|
6369 | var start = 0;
|
6370 | var end = -1;
|
6371 | var matchedSlash = true;
|
6372 | var i;
|
6373 |
|
6374 | for (i = path.length - 1; i >= 0; --i) {
|
6375 | if (path.charCodeAt(i) === 47 ) {
|
6376 |
|
6377 |
|
6378 | if (!matchedSlash) {
|
6379 | start = i + 1;
|
6380 | break;
|
6381 | }
|
6382 | } else if (end === -1) {
|
6383 |
|
6384 |
|
6385 | matchedSlash = false;
|
6386 | end = i + 1;
|
6387 | }
|
6388 | }
|
6389 |
|
6390 | if (end === -1) return '';
|
6391 | return path.slice(start, end);
|
6392 | }
|
6393 |
|
6394 |
|
6395 |
|
6396 | exports.basename = function (path, ext) {
|
6397 | var f = basename(path);
|
6398 | if (ext && f.substr(-1 * ext.length) === ext) {
|
6399 | f = f.substr(0, f.length - ext.length);
|
6400 | }
|
6401 | return f;
|
6402 | };
|
6403 |
|
6404 | exports.extname = function (path) {
|
6405 | if (typeof path !== 'string') path = path + '';
|
6406 | var startDot = -1;
|
6407 | var startPart = 0;
|
6408 | var end = -1;
|
6409 | var matchedSlash = true;
|
6410 |
|
6411 |
|
6412 | var preDotState = 0;
|
6413 | for (var i = path.length - 1; i >= 0; --i) {
|
6414 | var code = path.charCodeAt(i);
|
6415 | if (code === 47 ) {
|
6416 |
|
6417 |
|
6418 | if (!matchedSlash) {
|
6419 | startPart = i + 1;
|
6420 | break;
|
6421 | }
|
6422 | continue;
|
6423 | }
|
6424 | if (end === -1) {
|
6425 |
|
6426 |
|
6427 | matchedSlash = false;
|
6428 | end = i + 1;
|
6429 | }
|
6430 | if (code === 46 ) {
|
6431 |
|
6432 | if (startDot === -1)
|
6433 | startDot = i;
|
6434 | else if (preDotState !== 1)
|
6435 | preDotState = 1;
|
6436 | } else if (startDot !== -1) {
|
6437 |
|
6438 |
|
6439 | preDotState = -1;
|
6440 | }
|
6441 | }
|
6442 |
|
6443 | if (startDot === -1 || end === -1 ||
|
6444 |
|
6445 | preDotState === 0 ||
|
6446 |
|
6447 | preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
|
6448 | return '';
|
6449 | }
|
6450 | return path.slice(startDot, end);
|
6451 | };
|
6452 |
|
6453 | function filter (xs, f) {
|
6454 | if (xs.filter) return xs.filter(f);
|
6455 | var res = [];
|
6456 | for (var i = 0; i < xs.length; i++) {
|
6457 | if (f(xs[i], i, xs)) res.push(xs[i]);
|
6458 | }
|
6459 | return res;
|
6460 | }
|
6461 |
|
6462 |
|
6463 | var substr = 'ab'.substr(-1) === 'b'
|
6464 | ? function (str, start, len) { return str.substr(start, len) }
|
6465 | : function (str, start, len) {
|
6466 | if (start < 0) start = str.length + start;
|
6467 | return str.substr(start, len);
|
6468 | }
|
6469 | ;
|
6470 |
|
6471 | }).call(this,require('_process'))
|
6472 | },{"_process":14}],14:[function(require,module,exports){
|
6473 |
|
6474 | var process = module.exports = {};
|
6475 |
|
6476 |
|
6477 |
|
6478 |
|
6479 |
|
6480 |
|
6481 | var cachedSetTimeout;
|
6482 | var cachedClearTimeout;
|
6483 |
|
6484 | function defaultSetTimout() {
|
6485 | throw new Error('setTimeout has not been defined');
|
6486 | }
|
6487 | function defaultClearTimeout () {
|
6488 | throw new Error('clearTimeout has not been defined');
|
6489 | }
|
6490 | (function () {
|
6491 | try {
|
6492 | if (typeof setTimeout === 'function') {
|
6493 | cachedSetTimeout = setTimeout;
|
6494 | } else {
|
6495 | cachedSetTimeout = defaultSetTimout;
|
6496 | }
|
6497 | } catch (e) {
|
6498 | cachedSetTimeout = defaultSetTimout;
|
6499 | }
|
6500 | try {
|
6501 | if (typeof clearTimeout === 'function') {
|
6502 | cachedClearTimeout = clearTimeout;
|
6503 | } else {
|
6504 | cachedClearTimeout = defaultClearTimeout;
|
6505 | }
|
6506 | } catch (e) {
|
6507 | cachedClearTimeout = defaultClearTimeout;
|
6508 | }
|
6509 | } ())
|
6510 | function runTimeout(fun) {
|
6511 | if (cachedSetTimeout === setTimeout) {
|
6512 |
|
6513 | return setTimeout(fun, 0);
|
6514 | }
|
6515 |
|
6516 | if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
|
6517 | cachedSetTimeout = setTimeout;
|
6518 | return setTimeout(fun, 0);
|
6519 | }
|
6520 | try {
|
6521 |
|
6522 | return cachedSetTimeout(fun, 0);
|
6523 | } catch(e){
|
6524 | try {
|
6525 |
|
6526 | return cachedSetTimeout.call(null, fun, 0);
|
6527 | } catch(e){
|
6528 |
|
6529 | return cachedSetTimeout.call(this, fun, 0);
|
6530 | }
|
6531 | }
|
6532 |
|
6533 |
|
6534 | }
|
6535 | function runClearTimeout(marker) {
|
6536 | if (cachedClearTimeout === clearTimeout) {
|
6537 |
|
6538 | return clearTimeout(marker);
|
6539 | }
|
6540 |
|
6541 | if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
|
6542 | cachedClearTimeout = clearTimeout;
|
6543 | return clearTimeout(marker);
|
6544 | }
|
6545 | try {
|
6546 |
|
6547 | return cachedClearTimeout(marker);
|
6548 | } catch (e){
|
6549 | try {
|
6550 |
|
6551 | return cachedClearTimeout.call(null, marker);
|
6552 | } catch (e){
|
6553 |
|
6554 |
|
6555 | return cachedClearTimeout.call(this, marker);
|
6556 | }
|
6557 | }
|
6558 |
|
6559 |
|
6560 |
|
6561 | }
|
6562 | var queue = [];
|
6563 | var draining = false;
|
6564 | var currentQueue;
|
6565 | var queueIndex = -1;
|
6566 |
|
6567 | function cleanUpNextTick() {
|
6568 | if (!draining || !currentQueue) {
|
6569 | return;
|
6570 | }
|
6571 | draining = false;
|
6572 | if (currentQueue.length) {
|
6573 | queue = currentQueue.concat(queue);
|
6574 | } else {
|
6575 | queueIndex = -1;
|
6576 | }
|
6577 | if (queue.length) {
|
6578 | drainQueue();
|
6579 | }
|
6580 | }
|
6581 |
|
6582 | function drainQueue() {
|
6583 | if (draining) {
|
6584 | return;
|
6585 | }
|
6586 | var timeout = runTimeout(cleanUpNextTick);
|
6587 | draining = true;
|
6588 |
|
6589 | var len = queue.length;
|
6590 | while(len) {
|
6591 | currentQueue = queue;
|
6592 | queue = [];
|
6593 | while (++queueIndex < len) {
|
6594 | if (currentQueue) {
|
6595 | currentQueue[queueIndex].run();
|
6596 | }
|
6597 | }
|
6598 | queueIndex = -1;
|
6599 | len = queue.length;
|
6600 | }
|
6601 | currentQueue = null;
|
6602 | draining = false;
|
6603 | runClearTimeout(timeout);
|
6604 | }
|
6605 |
|
6606 | process.nextTick = function (fun) {
|
6607 | var args = new Array(arguments.length - 1);
|
6608 | if (arguments.length > 1) {
|
6609 | for (var i = 1; i < arguments.length; i++) {
|
6610 | args[i - 1] = arguments[i];
|
6611 | }
|
6612 | }
|
6613 | queue.push(new Item(fun, args));
|
6614 | if (queue.length === 1 && !draining) {
|
6615 | runTimeout(drainQueue);
|
6616 | }
|
6617 | };
|
6618 |
|
6619 |
|
6620 | function Item(fun, array) {
|
6621 | this.fun = fun;
|
6622 | this.array = array;
|
6623 | }
|
6624 | Item.prototype.run = function () {
|
6625 | this.fun.apply(null, this.array);
|
6626 | };
|
6627 | process.title = 'browser';
|
6628 | process.browser = true;
|
6629 | process.env = {};
|
6630 | process.argv = [];
|
6631 | process.version = '';
|
6632 | process.versions = {};
|
6633 |
|
6634 | function noop() {}
|
6635 |
|
6636 | process.on = noop;
|
6637 | process.addListener = noop;
|
6638 | process.once = noop;
|
6639 | process.off = noop;
|
6640 | process.removeListener = noop;
|
6641 | process.removeAllListeners = noop;
|
6642 | process.emit = noop;
|
6643 | process.prependListener = noop;
|
6644 | process.prependOnceListener = noop;
|
6645 |
|
6646 | process.listeners = function (name) { return [] }
|
6647 |
|
6648 | process.binding = function (name) {
|
6649 | throw new Error('process.binding is not supported');
|
6650 | };
|
6651 |
|
6652 | process.cwd = function () { return '/' };
|
6653 | process.chdir = function (dir) {
|
6654 | throw new Error('process.chdir is not supported');
|
6655 | };
|
6656 | process.umask = function() { return 0; };
|
6657 |
|
6658 | },{}],15:[function(require,module,exports){
|
6659 | var unparse = require('escodegen').generate;
|
6660 |
|
6661 | module.exports = function (ast, vars) {
|
6662 | if (!vars) vars = {};
|
6663 | var FAIL = {};
|
6664 |
|
6665 | var result = (function walk (node, scopeVars) {
|
6666 | if (node.type === 'Literal') {
|
6667 | return node.value;
|
6668 | }
|
6669 | else if (node.type === 'UnaryExpression'){
|
6670 | var val = walk(node.argument)
|
6671 | if (node.operator === '+') return +val
|
6672 | if (node.operator === '-') return -val
|
6673 | if (node.operator === '~') return ~val
|
6674 | if (node.operator === '!') return !val
|
6675 | return FAIL
|
6676 | }
|
6677 | else if (node.type === 'ArrayExpression') {
|
6678 | var xs = [];
|
6679 | for (var i = 0, l = node.elements.length; i < l; i++) {
|
6680 | var x = walk(node.elements[i]);
|
6681 | if (x === FAIL) return FAIL;
|
6682 | xs.push(x);
|
6683 | }
|
6684 | return xs;
|
6685 | }
|
6686 | else if (node.type === 'ObjectExpression') {
|
6687 | var obj = {};
|
6688 | for (var i = 0; i < node.properties.length; i++) {
|
6689 | var prop = node.properties[i];
|
6690 | var value = prop.value === null
|
6691 | ? prop.value
|
6692 | : walk(prop.value)
|
6693 | ;
|
6694 | if (value === FAIL) return FAIL;
|
6695 | obj[prop.key.value || prop.key.name] = value;
|
6696 | }
|
6697 | return obj;
|
6698 | }
|
6699 | else if (node.type === 'BinaryExpression' ||
|
6700 | node.type === 'LogicalExpression') {
|
6701 | var l = walk(node.left);
|
6702 | if (l === FAIL) return FAIL;
|
6703 | var r = walk(node.right);
|
6704 | if (r === FAIL) return FAIL;
|
6705 |
|
6706 | var op = node.operator;
|
6707 | if (op === '==') return l == r;
|
6708 | if (op === '===') return l === r;
|
6709 | if (op === '!=') return l != r;
|
6710 | if (op === '!==') return l !== r;
|
6711 | if (op === '+') return l + r;
|
6712 | if (op === '-') return l - r;
|
6713 | if (op === '*') return l * r;
|
6714 | if (op === '/') return l / r;
|
6715 | if (op === '%') return l % r;
|
6716 | if (op === '<') return l < r;
|
6717 | if (op === '<=') return l <= r;
|
6718 | if (op === '>') return l > r;
|
6719 | if (op === '>=') return l >= r;
|
6720 | if (op === '|') return l | r;
|
6721 | if (op === '&') return l & r;
|
6722 | if (op === '^') return l ^ r;
|
6723 | if (op === '&&') return l && r;
|
6724 | if (op === '||') return l || r;
|
6725 |
|
6726 | return FAIL;
|
6727 | }
|
6728 | else if (node.type === 'Identifier') {
|
6729 | if ({}.hasOwnProperty.call(vars, node.name)) {
|
6730 | return vars[node.name];
|
6731 | }
|
6732 | else return FAIL;
|
6733 | }
|
6734 | else if (node.type === 'ThisExpression') {
|
6735 | if ({}.hasOwnProperty.call(vars, 'this')) {
|
6736 | return vars['this'];
|
6737 | }
|
6738 | else return FAIL;
|
6739 | }
|
6740 | else if (node.type === 'CallExpression') {
|
6741 | var callee = walk(node.callee);
|
6742 | if (callee === FAIL) return FAIL;
|
6743 | if (typeof callee !== 'function') return FAIL;
|
6744 |
|
6745 | var ctx = node.callee.object ? walk(node.callee.object) : FAIL;
|
6746 | if (ctx === FAIL) ctx = null;
|
6747 |
|
6748 | var args = [];
|
6749 | for (var i = 0, l = node.arguments.length; i < l; i++) {
|
6750 | var x = walk(node.arguments[i]);
|
6751 | if (x === FAIL) return FAIL;
|
6752 | args.push(x);
|
6753 | }
|
6754 | return callee.apply(ctx, args);
|
6755 | }
|
6756 | else if (node.type === 'MemberExpression') {
|
6757 | var obj = walk(node.object);
|
6758 |
|
6759 | if((obj === FAIL) || (typeof obj == 'function')){
|
6760 | return FAIL;
|
6761 | }
|
6762 | if (node.property.type === 'Identifier') {
|
6763 | return obj[node.property.name];
|
6764 | }
|
6765 | var prop = walk(node.property);
|
6766 | if (prop === FAIL) return FAIL;
|
6767 | return obj[prop];
|
6768 | }
|
6769 | else if (node.type === 'ConditionalExpression') {
|
6770 | var val = walk(node.test)
|
6771 | if (val === FAIL) return FAIL;
|
6772 | return val ? walk(node.consequent) : walk(node.alternate)
|
6773 | }
|
6774 | else if (node.type === 'ExpressionStatement') {
|
6775 | var val = walk(node.expression)
|
6776 | if (val === FAIL) return FAIL;
|
6777 | return val;
|
6778 | }
|
6779 | else if (node.type === 'ReturnStatement') {
|
6780 | return walk(node.argument)
|
6781 | }
|
6782 | else if (node.type === 'FunctionExpression') {
|
6783 |
|
6784 | var bodies = node.body.body;
|
6785 |
|
6786 |
|
6787 | var oldVars = {};
|
6788 | Object.keys(vars).forEach(function(element){
|
6789 | oldVars[element] = vars[element];
|
6790 | })
|
6791 |
|
6792 | for(var i=0; i<node.params.length; i++){
|
6793 | var key = node.params[i];
|
6794 | if(key.type == 'Identifier'){
|
6795 | vars[key.name] = null;
|
6796 | }
|
6797 | else return FAIL;
|
6798 | }
|
6799 | for(var i in bodies){
|
6800 | if(walk(bodies[i]) === FAIL){
|
6801 | return FAIL;
|
6802 | }
|
6803 | }
|
6804 |
|
6805 | vars = oldVars;
|
6806 |
|
6807 | var keys = Object.keys(vars);
|
6808 | var vals = keys.map(function(key) {
|
6809 | return vars[key];
|
6810 | });
|
6811 | return Function(keys.join(', '), 'return ' + unparse(node)).apply(null, vals);
|
6812 | }
|
6813 | else if (node.type === 'TemplateLiteral') {
|
6814 | var str = '';
|
6815 | for (var i = 0; i < node.expressions.length; i++) {
|
6816 | str += walk(node.quasis[i]);
|
6817 | str += walk(node.expressions[i]);
|
6818 | }
|
6819 | str += walk(node.quasis[i]);
|
6820 | return str;
|
6821 | }
|
6822 | else if (node.type === 'TaggedTemplateExpression') {
|
6823 | var tag = walk(node.tag);
|
6824 | var quasi = node.quasi;
|
6825 | var strings = quasi.quasis.map(walk);
|
6826 | var values = quasi.expressions.map(walk);
|
6827 | return tag.apply(null, [strings].concat(values));
|
6828 | }
|
6829 | else if (node.type === 'TemplateElement') {
|
6830 | return node.value.cooked;
|
6831 | }
|
6832 | else return FAIL;
|
6833 | })(ast);
|
6834 |
|
6835 | return result === FAIL ? undefined : result;
|
6836 | };
|
6837 |
|
6838 | },{"escodegen":12}],"jsonpath":[function(require,module,exports){
|
6839 | module.exports = require('./lib/index');
|
6840 |
|
6841 | },{"./lib/index":5}]},{},["jsonpath"])("jsonpath")
|
6842 | });
|