PageRenderTime 67ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/dist/qunit/blanket.js

https://github.com/morkai/blanket
JavaScript | 4300 lines | 3448 code | 671 blank | 181 comment | 631 complexity | 66591ef832801d558c208a22efdd158a MD5 | raw file
Possible License(s): MIT

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

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

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