PageRenderTime 144ms CodeModel.GetById 27ms RepoModel.GetById 3ms app.codeStats 2ms

/dist/jasmine/blanket_jasmine.js

https://github.com/geekdave/blanket
JavaScript | 5442 lines | 4485 code | 731 blank | 226 comment | 811 complexity | e48ea7fe662ee563a53e84a29ac6d7c2 MD5 | raw file
Possible License(s): MIT

Large files files are truncated, but you can click here to view the full file

  1. /*! blanket - v1.1.5 */
  2. (function(define){
  3. /*
  4. Copyright (C) 2012 Ariya Hidayat <ariya.hidayat@gmail.com>
  5. Copyright (C) 2012 Mathias Bynens <mathias@qiwi.be>
  6. Copyright (C) 2012 Joost-Wim Boekesteijn <joost-wim@boekesteijn.nl>
  7. Copyright (C) 2012 Kris Kowal <kris.kowal@cixar.com>
  8. Copyright (C) 2012 Yusuke Suzuki <utatane.tea@gmail.com>
  9. Copyright (C) 2012 Arpad Borsos <arpad.borsos@googlemail.com>
  10. Copyright (C) 2011 Ariya Hidayat <ariya.hidayat@gmail.com>
  11. Redistribution and use in source and binary forms, with or without
  12. modification, are permitted provided that the following conditions are met:
  13. * Redistributions of source code must retain the above copyright
  14. notice, this list of conditions and the following disclaimer.
  15. * Redistributions in binary form must reproduce the above copyright
  16. notice, this list of conditions and the following disclaimer in the
  17. documentation and/or other materials provided with the distribution.
  18. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  22. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. /*jslint bitwise:true plusplus:true */
  30. /*global esprima:true, define:true, exports:true, window: true,
  31. throwError: true, createLiteral: true, generateStatement: true,
  32. parseAssignmentExpression: true, parseBlock: true, parseExpression: true,
  33. parseFunctionDeclaration: true, parseFunctionExpression: true,
  34. parseFunctionSourceElements: true, parseVariableIdentifier: true,
  35. parseLeftHandSideExpression: true,
  36. parseStatement: true, parseSourceElement: true */
  37. (function (root, factory) {
  38. 'use strict';
  39. // Universal Module Definition (UMD) to support AMD, CommonJS/Node.js,
  40. // Rhino, and plain browser loading.
  41. if (typeof define === 'function' && define.amd) {
  42. define(['exports'], factory);
  43. } else if (typeof exports !== 'undefined') {
  44. factory(exports);
  45. } else {
  46. factory((root.esprima = {}));
  47. }
  48. }(this, function (exports) {
  49. 'use strict';
  50. var Token,
  51. TokenName,
  52. Syntax,
  53. PropertyKind,
  54. Messages,
  55. Regex,
  56. source,
  57. strict,
  58. index,
  59. lineNumber,
  60. lineStart,
  61. length,
  62. buffer,
  63. state,
  64. extra;
  65. Token = {
  66. BooleanLiteral: 1,
  67. EOF: 2,
  68. Identifier: 3,
  69. Keyword: 4,
  70. NullLiteral: 5,
  71. NumericLiteral: 6,
  72. Punctuator: 7,
  73. StringLiteral: 8
  74. };
  75. TokenName = {};
  76. TokenName[Token.BooleanLiteral] = 'Boolean';
  77. TokenName[Token.EOF] = '<end>';
  78. TokenName[Token.Identifier] = 'Identifier';
  79. TokenName[Token.Keyword] = 'Keyword';
  80. TokenName[Token.NullLiteral] = 'Null';
  81. TokenName[Token.NumericLiteral] = 'Numeric';
  82. TokenName[Token.Punctuator] = 'Punctuator';
  83. TokenName[Token.StringLiteral] = 'String';
  84. Syntax = {
  85. AssignmentExpression: 'AssignmentExpression',
  86. ArrayExpression: 'ArrayExpression',
  87. BlockStatement: 'BlockStatement',
  88. BinaryExpression: 'BinaryExpression',
  89. BreakStatement: 'BreakStatement',
  90. CallExpression: 'CallExpression',
  91. CatchClause: 'CatchClause',
  92. ConditionalExpression: 'ConditionalExpression',
  93. ContinueStatement: 'ContinueStatement',
  94. DoWhileStatement: 'DoWhileStatement',
  95. DebuggerStatement: 'DebuggerStatement',
  96. EmptyStatement: 'EmptyStatement',
  97. ExpressionStatement: 'ExpressionStatement',
  98. ForStatement: 'ForStatement',
  99. ForInStatement: 'ForInStatement',
  100. FunctionDeclaration: 'FunctionDeclaration',
  101. FunctionExpression: 'FunctionExpression',
  102. Identifier: 'Identifier',
  103. IfStatement: 'IfStatement',
  104. Literal: 'Literal',
  105. LabeledStatement: 'LabeledStatement',
  106. LogicalExpression: 'LogicalExpression',
  107. MemberExpression: 'MemberExpression',
  108. NewExpression: 'NewExpression',
  109. ObjectExpression: 'ObjectExpression',
  110. Program: 'Program',
  111. Property: 'Property',
  112. ReturnStatement: 'ReturnStatement',
  113. SequenceExpression: 'SequenceExpression',
  114. SwitchStatement: 'SwitchStatement',
  115. SwitchCase: 'SwitchCase',
  116. ThisExpression: 'ThisExpression',
  117. ThrowStatement: 'ThrowStatement',
  118. TryStatement: 'TryStatement',
  119. UnaryExpression: 'UnaryExpression',
  120. UpdateExpression: 'UpdateExpression',
  121. VariableDeclaration: 'VariableDeclaration',
  122. VariableDeclarator: 'VariableDeclarator',
  123. WhileStatement: 'WhileStatement',
  124. WithStatement: 'WithStatement'
  125. };
  126. PropertyKind = {
  127. Data: 1,
  128. Get: 2,
  129. Set: 4
  130. };
  131. // Error messages should be identical to V8.
  132. Messages = {
  133. UnexpectedToken: 'Unexpected token %0',
  134. UnexpectedNumber: 'Unexpected number',
  135. UnexpectedString: 'Unexpected string',
  136. UnexpectedIdentifier: 'Unexpected identifier',
  137. UnexpectedReserved: 'Unexpected reserved word',
  138. UnexpectedEOS: 'Unexpected end of input',
  139. NewlineAfterThrow: 'Illegal newline after throw',
  140. InvalidRegExp: 'Invalid regular expression',
  141. UnterminatedRegExp: 'Invalid regular expression: missing /',
  142. InvalidLHSInAssignment: 'Invalid left-hand side in assignment',
  143. InvalidLHSInForIn: 'Invalid left-hand side in for-in',
  144. MultipleDefaultsInSwitch: 'More than one default clause in switch statement',
  145. NoCatchOrFinally: 'Missing catch or finally after try',
  146. UnknownLabel: 'Undefined label \'%0\'',
  147. Redeclaration: '%0 \'%1\' has already been declared',
  148. IllegalContinue: 'Illegal continue statement',
  149. IllegalBreak: 'Illegal break statement',
  150. IllegalReturn: 'Illegal return statement',
  151. StrictModeWith: 'Strict mode code may not include a with statement',
  152. StrictCatchVariable: 'Catch variable may not be eval or arguments in strict mode',
  153. StrictVarName: 'Variable name may not be eval or arguments in strict mode',
  154. StrictParamName: 'Parameter name eval or arguments is not allowed in strict mode',
  155. StrictParamDupe: 'Strict mode function may not have duplicate parameter names',
  156. StrictFunctionName: 'Function name may not be eval or arguments in strict mode',
  157. StrictOctalLiteral: 'Octal literals are not allowed in strict mode.',
  158. StrictDelete: 'Delete of an unqualified identifier in strict mode.',
  159. StrictDuplicateProperty: 'Duplicate data property in object literal not allowed in strict mode',
  160. AccessorDataProperty: 'Object literal may not have data and accessor property with the same name',
  161. AccessorGetSet: 'Object literal may not have multiple get/set accessors with the same name',
  162. StrictLHSAssignment: 'Assignment to eval or arguments is not allowed in strict mode',
  163. StrictLHSPostfix: 'Postfix increment/decrement may not have eval or arguments operand in strict mode',
  164. StrictLHSPrefix: 'Prefix increment/decrement may not have eval or arguments operand in strict mode',
  165. StrictReservedWord: 'Use of future reserved word in strict mode'
  166. };
  167. // See also tools/generate-unicode-regex.py.
  168. Regex = {
  169. 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]'),
  170. 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]')
  171. };
  172. // Ensure the condition is true, otherwise throw an error.
  173. // This is only to have a better contract semantic, i.e. another safety net
  174. // to catch a logic error. The condition shall be fulfilled in normal case.
  175. // Do NOT use this to enforce a certain condition on any user input.
  176. function assert(condition, message) {
  177. if (!condition) {
  178. throw new Error('ASSERT: ' + message);
  179. }
  180. }
  181. function sliceSource(from, to) {
  182. return source.slice(from, to);
  183. }
  184. if (typeof 'esprima'[0] === 'undefined') {
  185. sliceSource = function sliceArraySource(from, to) {
  186. return source.slice(from, to).join('');
  187. };
  188. }
  189. function isDecimalDigit(ch) {
  190. return '0123456789'.indexOf(ch) >= 0;
  191. }
  192. function isHexDigit(ch) {
  193. return '0123456789abcdefABCDEF'.indexOf(ch) >= 0;
  194. }
  195. function isOctalDigit(ch) {
  196. return '01234567'.indexOf(ch) >= 0;
  197. }
  198. // 7.2 White Space
  199. function isWhiteSpace(ch) {
  200. return (ch === ' ') || (ch === '\u0009') || (ch === '\u000B') ||
  201. (ch === '\u000C') || (ch === '\u00A0') ||
  202. (ch.charCodeAt(0) >= 0x1680 &&
  203. '\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\uFEFF'.indexOf(ch) >= 0);
  204. }
  205. // 7.3 Line Terminators
  206. function isLineTerminator(ch) {
  207. return (ch === '\n' || ch === '\r' || ch === '\u2028' || ch === '\u2029');
  208. }
  209. // 7.6 Identifier Names and Identifiers
  210. function isIdentifierStart(ch) {
  211. return (ch === '$') || (ch === '_') || (ch === '\\') ||
  212. (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ||
  213. ((ch.charCodeAt(0) >= 0x80) && Regex.NonAsciiIdentifierStart.test(ch));
  214. }
  215. function isIdentifierPart(ch) {
  216. return (ch === '$') || (ch === '_') || (ch === '\\') ||
  217. (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ||
  218. ((ch >= '0') && (ch <= '9')) ||
  219. ((ch.charCodeAt(0) >= 0x80) && Regex.NonAsciiIdentifierPart.test(ch));
  220. }
  221. // 7.6.1.2 Future Reserved Words
  222. function isFutureReservedWord(id) {
  223. switch (id) {
  224. // Future reserved words.
  225. case 'class':
  226. case 'enum':
  227. case 'export':
  228. case 'extends':
  229. case 'import':
  230. case 'super':
  231. return true;
  232. }
  233. return false;
  234. }
  235. function isStrictModeReservedWord(id) {
  236. switch (id) {
  237. // Strict Mode reserved words.
  238. case 'implements':
  239. case 'interface':
  240. case 'package':
  241. case 'private':
  242. case 'protected':
  243. case 'public':
  244. case 'static':
  245. case 'yield':
  246. case 'let':
  247. return true;
  248. }
  249. return false;
  250. }
  251. function isRestrictedWord(id) {
  252. return id === 'eval' || id === 'arguments';
  253. }
  254. // 7.6.1.1 Keywords
  255. function isKeyword(id) {
  256. var keyword = false;
  257. switch (id.length) {
  258. case 2:
  259. keyword = (id === 'if') || (id === 'in') || (id === 'do');
  260. break;
  261. case 3:
  262. keyword = (id === 'var') || (id === 'for') || (id === 'new') || (id === 'try');
  263. break;
  264. case 4:
  265. keyword = (id === 'this') || (id === 'else') || (id === 'case') || (id === 'void') || (id === 'with');
  266. break;
  267. case 5:
  268. keyword = (id === 'while') || (id === 'break') || (id === 'catch') || (id === 'throw');
  269. break;
  270. case 6:
  271. keyword = (id === 'return') || (id === 'typeof') || (id === 'delete') || (id === 'switch');
  272. break;
  273. case 7:
  274. keyword = (id === 'default') || (id === 'finally');
  275. break;
  276. case 8:
  277. keyword = (id === 'function') || (id === 'continue') || (id === 'debugger');
  278. break;
  279. case 10:
  280. keyword = (id === 'instanceof');
  281. break;
  282. }
  283. if (keyword) {
  284. return true;
  285. }
  286. switch (id) {
  287. // Future reserved words.
  288. // 'const' is specialized as Keyword in V8.
  289. case 'const':
  290. return true;
  291. // For compatiblity to SpiderMonkey and ES.next
  292. case 'yield':
  293. case 'let':
  294. return true;
  295. }
  296. if (strict && isStrictModeReservedWord(id)) {
  297. return true;
  298. }
  299. return isFutureReservedWord(id);
  300. }
  301. // 7.4 Comments
  302. function skipComment() {
  303. var ch, blockComment, lineComment;
  304. blockComment = false;
  305. lineComment = false;
  306. while (index < length) {
  307. ch = source[index];
  308. if (lineComment) {
  309. ch = source[index++];
  310. if (isLineTerminator(ch)) {
  311. lineComment = false;
  312. if (ch === '\r' && source[index] === '\n') {
  313. ++index;
  314. }
  315. ++lineNumber;
  316. lineStart = index;
  317. }
  318. } else if (blockComment) {
  319. if (isLineTerminator(ch)) {
  320. if (ch === '\r' && source[index + 1] === '\n') {
  321. ++index;
  322. }
  323. ++lineNumber;
  324. ++index;
  325. lineStart = index;
  326. if (index >= length) {
  327. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  328. }
  329. } else {
  330. ch = source[index++];
  331. if (index >= length) {
  332. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  333. }
  334. if (ch === '*') {
  335. ch = source[index];
  336. if (ch === '/') {
  337. ++index;
  338. blockComment = false;
  339. }
  340. }
  341. }
  342. } else if (ch === '/') {
  343. ch = source[index + 1];
  344. if (ch === '/') {
  345. index += 2;
  346. lineComment = true;
  347. } else if (ch === '*') {
  348. index += 2;
  349. blockComment = true;
  350. if (index >= length) {
  351. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  352. }
  353. } else {
  354. break;
  355. }
  356. } else if (isWhiteSpace(ch)) {
  357. ++index;
  358. } else if (isLineTerminator(ch)) {
  359. ++index;
  360. if (ch === '\r' && source[index] === '\n') {
  361. ++index;
  362. }
  363. ++lineNumber;
  364. lineStart = index;
  365. } else {
  366. break;
  367. }
  368. }
  369. }
  370. function scanHexEscape(prefix) {
  371. var i, len, ch, code = 0;
  372. len = (prefix === 'u') ? 4 : 2;
  373. for (i = 0; i < len; ++i) {
  374. if (index < length && isHexDigit(source[index])) {
  375. ch = source[index++];
  376. code = code * 16 + '0123456789abcdef'.indexOf(ch.toLowerCase());
  377. } else {
  378. return '';
  379. }
  380. }
  381. return String.fromCharCode(code);
  382. }
  383. function scanIdentifier() {
  384. var ch, start, id, restore;
  385. ch = source[index];
  386. if (!isIdentifierStart(ch)) {
  387. return;
  388. }
  389. start = index;
  390. if (ch === '\\') {
  391. ++index;
  392. if (source[index] !== 'u') {
  393. return;
  394. }
  395. ++index;
  396. restore = index;
  397. ch = scanHexEscape('u');
  398. if (ch) {
  399. if (ch === '\\' || !isIdentifierStart(ch)) {
  400. return;
  401. }
  402. id = ch;
  403. } else {
  404. index = restore;
  405. id = 'u';
  406. }
  407. } else {
  408. id = source[index++];
  409. }
  410. while (index < length) {
  411. ch = source[index];
  412. if (!isIdentifierPart(ch)) {
  413. break;
  414. }
  415. if (ch === '\\') {
  416. ++index;
  417. if (source[index] !== 'u') {
  418. return;
  419. }
  420. ++index;
  421. restore = index;
  422. ch = scanHexEscape('u');
  423. if (ch) {
  424. if (ch === '\\' || !isIdentifierPart(ch)) {
  425. return;
  426. }
  427. id += ch;
  428. } else {
  429. index = restore;
  430. id += 'u';
  431. }
  432. } else {
  433. id += source[index++];
  434. }
  435. }
  436. // There is no keyword or literal with only one character.
  437. // Thus, it must be an identifier.
  438. if (id.length === 1) {
  439. return {
  440. type: Token.Identifier,
  441. value: id,
  442. lineNumber: lineNumber,
  443. lineStart: lineStart,
  444. range: [start, index]
  445. };
  446. }
  447. if (isKeyword(id)) {
  448. return {
  449. type: Token.Keyword,
  450. value: id,
  451. lineNumber: lineNumber,
  452. lineStart: lineStart,
  453. range: [start, index]
  454. };
  455. }
  456. // 7.8.1 Null Literals
  457. if (id === 'null') {
  458. return {
  459. type: Token.NullLiteral,
  460. value: id,
  461. lineNumber: lineNumber,
  462. lineStart: lineStart,
  463. range: [start, index]
  464. };
  465. }
  466. // 7.8.2 Boolean Literals
  467. if (id === 'true' || id === 'false') {
  468. return {
  469. type: Token.BooleanLiteral,
  470. value: id,
  471. lineNumber: lineNumber,
  472. lineStart: lineStart,
  473. range: [start, index]
  474. };
  475. }
  476. return {
  477. type: Token.Identifier,
  478. value: id,
  479. lineNumber: lineNumber,
  480. lineStart: lineStart,
  481. range: [start, index]
  482. };
  483. }
  484. // 7.7 Punctuators
  485. function scanPunctuator() {
  486. var start = index,
  487. ch1 = source[index],
  488. ch2,
  489. ch3,
  490. ch4;
  491. // Check for most common single-character punctuators.
  492. if (ch1 === ';' || ch1 === '{' || ch1 === '}') {
  493. ++index;
  494. return {
  495. type: Token.Punctuator,
  496. value: ch1,
  497. lineNumber: lineNumber,
  498. lineStart: lineStart,
  499. range: [start, index]
  500. };
  501. }
  502. if (ch1 === ',' || ch1 === '(' || ch1 === ')') {
  503. ++index;
  504. return {
  505. type: Token.Punctuator,
  506. value: ch1,
  507. lineNumber: lineNumber,
  508. lineStart: lineStart,
  509. range: [start, index]
  510. };
  511. }
  512. // Dot (.) can also start a floating-point number, hence the need
  513. // to check the next character.
  514. ch2 = source[index + 1];
  515. if (ch1 === '.' && !isDecimalDigit(ch2)) {
  516. return {
  517. type: Token.Punctuator,
  518. value: source[index++],
  519. lineNumber: lineNumber,
  520. lineStart: lineStart,
  521. range: [start, index]
  522. };
  523. }
  524. // Peek more characters.
  525. ch3 = source[index + 2];
  526. ch4 = source[index + 3];
  527. // 4-character punctuator: >>>=
  528. if (ch1 === '>' && ch2 === '>' && ch3 === '>') {
  529. if (ch4 === '=') {
  530. index += 4;
  531. return {
  532. type: Token.Punctuator,
  533. value: '>>>=',
  534. lineNumber: lineNumber,
  535. lineStart: lineStart,
  536. range: [start, index]
  537. };
  538. }
  539. }
  540. // 3-character punctuators: === !== >>> <<= >>=
  541. if (ch1 === '=' && ch2 === '=' && ch3 === '=') {
  542. index += 3;
  543. return {
  544. type: Token.Punctuator,
  545. value: '===',
  546. lineNumber: lineNumber,
  547. lineStart: lineStart,
  548. range: [start, index]
  549. };
  550. }
  551. if (ch1 === '!' && ch2 === '=' && ch3 === '=') {
  552. index += 3;
  553. return {
  554. type: Token.Punctuator,
  555. value: '!==',
  556. lineNumber: lineNumber,
  557. lineStart: lineStart,
  558. range: [start, index]
  559. };
  560. }
  561. if (ch1 === '>' && ch2 === '>' && ch3 === '>') {
  562. index += 3;
  563. return {
  564. type: Token.Punctuator,
  565. value: '>>>',
  566. lineNumber: lineNumber,
  567. lineStart: lineStart,
  568. range: [start, index]
  569. };
  570. }
  571. if (ch1 === '<' && ch2 === '<' && ch3 === '=') {
  572. index += 3;
  573. return {
  574. type: Token.Punctuator,
  575. value: '<<=',
  576. lineNumber: lineNumber,
  577. lineStart: lineStart,
  578. range: [start, index]
  579. };
  580. }
  581. if (ch1 === '>' && ch2 === '>' && ch3 === '=') {
  582. index += 3;
  583. return {
  584. type: Token.Punctuator,
  585. value: '>>=',
  586. lineNumber: lineNumber,
  587. lineStart: lineStart,
  588. range: [start, index]
  589. };
  590. }
  591. // 2-character punctuators: <= >= == != ++ -- << >> && ||
  592. // += -= *= %= &= |= ^= /=
  593. if (ch2 === '=') {
  594. if ('<>=!+-*%&|^/'.indexOf(ch1) >= 0) {
  595. index += 2;
  596. return {
  597. type: Token.Punctuator,
  598. value: ch1 + ch2,
  599. lineNumber: lineNumber,
  600. lineStart: lineStart,
  601. range: [start, index]
  602. };
  603. }
  604. }
  605. if (ch1 === ch2 && ('+-<>&|'.indexOf(ch1) >= 0)) {
  606. if ('+-<>&|'.indexOf(ch2) >= 0) {
  607. index += 2;
  608. return {
  609. type: Token.Punctuator,
  610. value: ch1 + ch2,
  611. lineNumber: lineNumber,
  612. lineStart: lineStart,
  613. range: [start, index]
  614. };
  615. }
  616. }
  617. // The remaining 1-character punctuators.
  618. if ('[]<>+-*%&|^!~?:=/'.indexOf(ch1) >= 0) {
  619. return {
  620. type: Token.Punctuator,
  621. value: source[index++],
  622. lineNumber: lineNumber,
  623. lineStart: lineStart,
  624. range: [start, index]
  625. };
  626. }
  627. }
  628. // 7.8.3 Numeric Literals
  629. function scanNumericLiteral() {
  630. var number, start, ch;
  631. ch = source[index];
  632. assert(isDecimalDigit(ch) || (ch === '.'),
  633. 'Numeric literal must start with a decimal digit or a decimal point');
  634. start = index;
  635. number = '';
  636. if (ch !== '.') {
  637. number = source[index++];
  638. ch = source[index];
  639. // Hex number starts with '0x'.
  640. // Octal number starts with '0'.
  641. if (number === '0') {
  642. if (ch === 'x' || ch === 'X') {
  643. number += source[index++];
  644. while (index < length) {
  645. ch = source[index];
  646. if (!isHexDigit(ch)) {
  647. break;
  648. }
  649. number += source[index++];
  650. }
  651. if (number.length <= 2) {
  652. // only 0x
  653. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  654. }
  655. if (index < length) {
  656. ch = source[index];
  657. if (isIdentifierStart(ch)) {
  658. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  659. }
  660. }
  661. return {
  662. type: Token.NumericLiteral,
  663. value: parseInt(number, 16),
  664. lineNumber: lineNumber,
  665. lineStart: lineStart,
  666. range: [start, index]
  667. };
  668. } else if (isOctalDigit(ch)) {
  669. number += source[index++];
  670. while (index < length) {
  671. ch = source[index];
  672. if (!isOctalDigit(ch)) {
  673. break;
  674. }
  675. number += source[index++];
  676. }
  677. if (index < length) {
  678. ch = source[index];
  679. if (isIdentifierStart(ch) || isDecimalDigit(ch)) {
  680. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  681. }
  682. }
  683. return {
  684. type: Token.NumericLiteral,
  685. value: parseInt(number, 8),
  686. octal: true,
  687. lineNumber: lineNumber,
  688. lineStart: lineStart,
  689. range: [start, index]
  690. };
  691. }
  692. // decimal number starts with '0' such as '09' is illegal.
  693. if (isDecimalDigit(ch)) {
  694. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  695. }
  696. }
  697. while (index < length) {
  698. ch = source[index];
  699. if (!isDecimalDigit(ch)) {
  700. break;
  701. }
  702. number += source[index++];
  703. }
  704. }
  705. if (ch === '.') {
  706. number += source[index++];
  707. while (index < length) {
  708. ch = source[index];
  709. if (!isDecimalDigit(ch)) {
  710. break;
  711. }
  712. number += source[index++];
  713. }
  714. }
  715. if (ch === 'e' || ch === 'E') {
  716. number += source[index++];
  717. ch = source[index];
  718. if (ch === '+' || ch === '-') {
  719. number += source[index++];
  720. }
  721. ch = source[index];
  722. if (isDecimalDigit(ch)) {
  723. number += source[index++];
  724. while (index < length) {
  725. ch = source[index];
  726. if (!isDecimalDigit(ch)) {
  727. break;
  728. }
  729. number += source[index++];
  730. }
  731. } else {
  732. ch = 'character ' + ch;
  733. if (index >= length) {
  734. ch = '<end>';
  735. }
  736. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  737. }
  738. }
  739. if (index < length) {
  740. ch = source[index];
  741. if (isIdentifierStart(ch)) {
  742. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  743. }
  744. }
  745. return {
  746. type: Token.NumericLiteral,
  747. value: parseFloat(number),
  748. lineNumber: lineNumber,
  749. lineStart: lineStart,
  750. range: [start, index]
  751. };
  752. }
  753. // 7.8.4 String Literals
  754. function scanStringLiteral() {
  755. var str = '', quote, start, ch, code, unescaped, restore, octal = false;
  756. quote = source[index];
  757. assert((quote === '\'' || quote === '"'),
  758. 'String literal must starts with a quote');
  759. start = index;
  760. ++index;
  761. while (index < length) {
  762. ch = source[index++];
  763. if (ch === quote) {
  764. quote = '';
  765. break;
  766. } else if (ch === '\\') {
  767. ch = source[index++];
  768. if (!isLineTerminator(ch)) {
  769. switch (ch) {
  770. case 'n':
  771. str += '\n';
  772. break;
  773. case 'r':
  774. str += '\r';
  775. break;
  776. case 't':
  777. str += '\t';
  778. break;
  779. case 'u':
  780. case 'x':
  781. restore = index;
  782. unescaped = scanHexEscape(ch);
  783. if (unescaped) {
  784. str += unescaped;
  785. } else {
  786. index = restore;
  787. str += ch;
  788. }
  789. break;
  790. case 'b':
  791. str += '\b';
  792. break;
  793. case 'f':
  794. str += '\f';
  795. break;
  796. case 'v':
  797. str += '\v';
  798. break;
  799. default:
  800. if (isOctalDigit(ch)) {
  801. code = '01234567'.indexOf(ch);
  802. // \0 is not octal escape sequence
  803. if (code !== 0) {
  804. octal = true;
  805. }
  806. if (index < length && isOctalDigit(source[index])) {
  807. octal = true;
  808. code = code * 8 + '01234567'.indexOf(source[index++]);
  809. // 3 digits are only allowed when string starts
  810. // with 0, 1, 2, 3
  811. if ('0123'.indexOf(ch) >= 0 &&
  812. index < length &&
  813. isOctalDigit(source[index])) {
  814. code = code * 8 + '01234567'.indexOf(source[index++]);
  815. }
  816. }
  817. str += String.fromCharCode(code);
  818. } else {
  819. str += ch;
  820. }
  821. break;
  822. }
  823. } else {
  824. ++lineNumber;
  825. if (ch === '\r' && source[index] === '\n') {
  826. ++index;
  827. }
  828. }
  829. } else if (isLineTerminator(ch)) {
  830. break;
  831. } else {
  832. str += ch;
  833. }
  834. }
  835. if (quote !== '') {
  836. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  837. }
  838. return {
  839. type: Token.StringLiteral,
  840. value: str,
  841. octal: octal,
  842. lineNumber: lineNumber,
  843. lineStart: lineStart,
  844. range: [start, index]
  845. };
  846. }
  847. function scanRegExp() {
  848. var str, ch, start, pattern, flags, value, classMarker = false, restore, terminated = false;
  849. buffer = null;
  850. skipComment();
  851. start = index;
  852. ch = source[index];
  853. assert(ch === '/', 'Regular expression literal must start with a slash');
  854. str = source[index++];
  855. while (index < length) {
  856. ch = source[index++];
  857. str += ch;
  858. if (classMarker) {
  859. if (ch === ']') {
  860. classMarker = false;
  861. }
  862. } else {
  863. if (ch === '\\') {
  864. ch = source[index++];
  865. // ECMA-262 7.8.5
  866. if (isLineTerminator(ch)) {
  867. throwError({}, Messages.UnterminatedRegExp);
  868. }
  869. str += ch;
  870. } else if (ch === '/') {
  871. terminated = true;
  872. break;
  873. } else if (ch === '[') {
  874. classMarker = true;
  875. } else if (isLineTerminator(ch)) {
  876. throwError({}, Messages.UnterminatedRegExp);
  877. }
  878. }
  879. }
  880. if (!terminated) {
  881. throwError({}, Messages.UnterminatedRegExp);
  882. }
  883. // Exclude leading and trailing slash.
  884. pattern = str.substr(1, str.length - 2);
  885. flags = '';
  886. while (index < length) {
  887. ch = source[index];
  888. if (!isIdentifierPart(ch)) {
  889. break;
  890. }
  891. ++index;
  892. if (ch === '\\' && index < length) {
  893. ch = source[index];
  894. if (ch === 'u') {
  895. ++index;
  896. restore = index;
  897. ch = scanHexEscape('u');
  898. if (ch) {
  899. flags += ch;
  900. str += '\\u';
  901. for (; restore < index; ++restore) {
  902. str += source[restore];
  903. }
  904. } else {
  905. index = restore;
  906. flags += 'u';
  907. str += '\\u';
  908. }
  909. } else {
  910. str += '\\';
  911. }
  912. } else {
  913. flags += ch;
  914. str += ch;
  915. }
  916. }
  917. try {
  918. value = new RegExp(pattern, flags);
  919. } catch (e) {
  920. throwError({}, Messages.InvalidRegExp);
  921. }
  922. return {
  923. literal: str,
  924. value: value,
  925. range: [start, index]
  926. };
  927. }
  928. function isIdentifierName(token) {
  929. return token.type === Token.Identifier ||
  930. token.type === Token.Keyword ||
  931. token.type === Token.BooleanLiteral ||
  932. token.type === Token.NullLiteral;
  933. }
  934. function advance() {
  935. var ch, token;
  936. skipComment();
  937. if (index >= length) {
  938. return {
  939. type: Token.EOF,
  940. lineNumber: lineNumber,
  941. lineStart: lineStart,
  942. range: [index, index]
  943. };
  944. }
  945. token = scanPunctuator();
  946. if (typeof token !== 'undefined') {
  947. return token;
  948. }
  949. ch = source[index];
  950. if (ch === '\'' || ch === '"') {
  951. return scanStringLiteral();
  952. }
  953. if (ch === '.' || isDecimalDigit(ch)) {
  954. return scanNumericLiteral();
  955. }
  956. token = scanIdentifier();
  957. if (typeof token !== 'undefined') {
  958. return token;
  959. }
  960. throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
  961. }
  962. function lex() {
  963. var token;
  964. if (buffer) {
  965. index = buffer.range[1];
  966. lineNumber = buffer.lineNumber;
  967. lineStart = buffer.lineStart;
  968. token = buffer;
  969. buffer = null;
  970. return token;
  971. }
  972. buffer = null;
  973. return advance();
  974. }
  975. function lookahead() {
  976. var pos, line, start;
  977. if (buffer !== null) {
  978. return buffer;
  979. }
  980. pos = index;
  981. line = lineNumber;
  982. start = lineStart;
  983. buffer = advance();
  984. index = pos;
  985. lineNumber = line;
  986. lineStart = start;
  987. return buffer;
  988. }
  989. // Return true if there is a line terminator before the next token.
  990. function peekLineTerminator() {
  991. var pos, line, start, found;
  992. pos = index;
  993. line = lineNumber;
  994. start = lineStart;
  995. skipComment();
  996. found = lineNumber !== line;
  997. index = pos;
  998. lineNumber = line;
  999. lineStart = start;
  1000. return found;
  1001. }
  1002. // Throw an exception
  1003. function throwError(token, messageFormat) {
  1004. var error,
  1005. args = Array.prototype.slice.call(arguments, 2),
  1006. msg = messageFormat.replace(
  1007. /%(\d)/g,
  1008. function (whole, index) {
  1009. return args[index] || '';
  1010. }
  1011. );
  1012. if (typeof token.lineNumber === 'number') {
  1013. error = new Error('Line ' + token.lineNumber + ': ' + msg);
  1014. error.index = token.range[0];
  1015. error.lineNumber = token.lineNumber;
  1016. error.column = token.range[0] - lineStart + 1;
  1017. } else {
  1018. error = new Error('Line ' + lineNumber + ': ' + msg);
  1019. error.index = index;
  1020. error.lineNumber = lineNumber;
  1021. error.column = index - lineStart + 1;
  1022. }
  1023. throw error;
  1024. }
  1025. function throwErrorTolerant() {
  1026. try {
  1027. throwError.apply(null, arguments);
  1028. } catch (e) {
  1029. if (extra.errors) {
  1030. extra.errors.push(e);
  1031. } else {
  1032. throw e;
  1033. }
  1034. }
  1035. }
  1036. // Throw an exception because of the token.
  1037. function throwUnexpected(token) {
  1038. if (token.type === Token.EOF) {
  1039. throwError(token, Messages.UnexpectedEOS);
  1040. }
  1041. if (token.type === Token.NumericLiteral) {
  1042. throwError(token, Messages.UnexpectedNumber);
  1043. }
  1044. if (token.type === Token.StringLiteral) {
  1045. throwError(token, Messages.UnexpectedString);
  1046. }
  1047. if (token.type === Token.Identifier) {
  1048. throwError(token, Messages.UnexpectedIdentifier);
  1049. }
  1050. if (token.type === Token.Keyword) {
  1051. if (isFutureReservedWord(token.value)) {
  1052. throwError(token, Messages.UnexpectedReserved);
  1053. } else if (strict && isStrictModeReservedWord(token.value)) {
  1054. throwErrorTolerant(token, Messages.StrictReservedWord);
  1055. return;
  1056. }
  1057. throwError(token, Messages.UnexpectedToken, token.value);
  1058. }
  1059. // BooleanLiteral, NullLiteral, or Punctuator.
  1060. throwError(token, Messages.UnexpectedToken, token.value);
  1061. }
  1062. // Expect the next token to match the specified punctuator.
  1063. // If not, an exception will be thrown.
  1064. function expect(value) {
  1065. var token = lex();
  1066. if (token.type !== Token.Punctuator || token.value !== value) {
  1067. throwUnexpected(token);
  1068. }
  1069. }
  1070. // Expect the next token to match the specified keyword.
  1071. // If not, an exception will be thrown.
  1072. function expectKeyword(keyword) {
  1073. var token = lex();
  1074. if (token.type !== Token.Keyword || token.value !== keyword) {
  1075. throwUnexpected(token);
  1076. }
  1077. }
  1078. // Return true if the next token matches the specified punctuator.
  1079. function match(value) {
  1080. var token = lookahead();
  1081. return token.type === Token.Punctuator && token.value === value;
  1082. }
  1083. // Return true if the next token matches the specified keyword
  1084. function matchKeyword(keyword) {
  1085. var token = lookahead();
  1086. return token.type === Token.Keyword && token.value === keyword;
  1087. }
  1088. // Return true if the next token is an assignment operator
  1089. function matchAssign() {
  1090. var token = lookahead(),
  1091. op = token.value;
  1092. if (token.type !== Token.Punctuator) {
  1093. return false;
  1094. }
  1095. return op === '=' ||
  1096. op === '*=' ||
  1097. op === '/=' ||
  1098. op === '%=' ||
  1099. op === '+=' ||
  1100. op === '-=' ||
  1101. op === '<<=' ||
  1102. op === '>>=' ||
  1103. op === '>>>=' ||
  1104. op === '&=' ||
  1105. op === '^=' ||
  1106. op === '|=';
  1107. }
  1108. function consumeSemicolon() {
  1109. var token, line;
  1110. // Catch the very common case first.
  1111. if (source[index] === ';') {
  1112. lex();
  1113. return;
  1114. }
  1115. line = lineNumber;
  1116. skipComment();
  1117. if (lineNumber !== line) {
  1118. return;
  1119. }
  1120. if (match(';')) {
  1121. lex();
  1122. return;
  1123. }
  1124. token = lookahead();
  1125. if (token.type !== Token.EOF && !match('}')) {
  1126. throwUnexpected(token);
  1127. }
  1128. }
  1129. // Return true if provided expression is LeftHandSideExpression
  1130. function isLeftHandSide(expr) {
  1131. return expr.type === Syntax.Identifier || expr.type === Syntax.MemberExpression;
  1132. }
  1133. // 11.1.4 Array Initialiser
  1134. function parseArrayInitialiser() {
  1135. var elements = [];
  1136. expect('[');
  1137. while (!match(']')) {
  1138. if (match(',')) {
  1139. lex();
  1140. elements.push(null);
  1141. } else {
  1142. elements.push(parseAssignmentExpression

Large files files are truncated, but you can click here to view the full file