You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

6708 lines
277 KiB

5 years ago
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. /* istanbul ignore next */
  3. if(typeof exports === 'object' && typeof module === 'object')
  4. module.exports = factory();
  5. else if(typeof define === 'function' && define.amd)
  6. define([], factory);
  7. /* istanbul ignore next */
  8. else if(typeof exports === 'object')
  9. exports["esprima"] = factory();
  10. else
  11. root["esprima"] = factory();
  12. })(this, function() {
  13. return /******/ (function(modules) { // webpackBootstrap
  14. /******/ // The module cache
  15. /******/ var installedModules = {};
  16. /******/ // The require function
  17. /******/ function __webpack_require__(moduleId) {
  18. /******/ // Check if module is in cache
  19. /* istanbul ignore if */
  20. /******/ if(installedModules[moduleId])
  21. /******/ return installedModules[moduleId].exports;
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ exports: {},
  25. /******/ id: moduleId,
  26. /******/ loaded: false
  27. /******/ };
  28. /******/ // Execute the module function
  29. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  30. /******/ // Flag the module as loaded
  31. /******/ module.loaded = true;
  32. /******/ // Return the exports of the module
  33. /******/ return module.exports;
  34. /******/ }
  35. /******/ // expose the modules object (__webpack_modules__)
  36. /******/ __webpack_require__.m = modules;
  37. /******/ // expose the module cache
  38. /******/ __webpack_require__.c = installedModules;
  39. /******/ // __webpack_public_path__
  40. /******/ __webpack_require__.p = "";
  41. /******/ // Load entry module and return exports
  42. /******/ return __webpack_require__(0);
  43. /******/ })
  44. /************************************************************************/
  45. /******/ ([
  46. /* 0 */
  47. /***/ function(module, exports, __webpack_require__) {
  48. "use strict";
  49. /*
  50. Copyright JS Foundation and other contributors, https://js.foundation/
  51. Redistribution and use in source and binary forms, with or without
  52. modification, are permitted provided that the following conditions are met:
  53. * Redistributions of source code must retain the above copyright
  54. notice, this list of conditions and the following disclaimer.
  55. * Redistributions in binary form must reproduce the above copyright
  56. notice, this list of conditions and the following disclaimer in the
  57. documentation and/or other materials provided with the distribution.
  58. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  59. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  60. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  61. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  62. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  63. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  64. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  65. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  66. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  67. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  68. */
  69. Object.defineProperty(exports, "__esModule", { value: true });
  70. var comment_handler_1 = __webpack_require__(1);
  71. var jsx_parser_1 = __webpack_require__(3);
  72. var parser_1 = __webpack_require__(8);
  73. var tokenizer_1 = __webpack_require__(15);
  74. function parse(code, options, delegate) {
  75. var commentHandler = null;
  76. var proxyDelegate = function (node, metadata) {
  77. if (delegate) {
  78. delegate(node, metadata);
  79. }
  80. if (commentHandler) {
  81. commentHandler.visit(node, metadata);
  82. }
  83. };
  84. var parserDelegate = (typeof delegate === 'function') ? proxyDelegate : null;
  85. var collectComment = false;
  86. if (options) {
  87. collectComment = (typeof options.comment === 'boolean' && options.comment);
  88. var attachComment = (typeof options.attachComment === 'boolean' && options.attachComment);
  89. if (collectComment || attachComment) {
  90. commentHandler = new comment_handler_1.CommentHandler();
  91. commentHandler.attach = attachComment;
  92. options.comment = true;
  93. parserDelegate = proxyDelegate;
  94. }
  95. }
  96. var isModule = false;
  97. if (options && typeof options.sourceType === 'string') {
  98. isModule = (options.sourceType === 'module');
  99. }
  100. var parser;
  101. if (options && typeof options.jsx === 'boolean' && options.jsx) {
  102. parser = new jsx_parser_1.JSXParser(code, options, parserDelegate);
  103. }
  104. else {
  105. parser = new parser_1.Parser(code, options, parserDelegate);
  106. }
  107. var program = isModule ? parser.parseModule() : parser.parseScript();
  108. var ast = program;
  109. if (collectComment && commentHandler) {
  110. ast.comments = commentHandler.comments;
  111. }
  112. if (parser.config.tokens) {
  113. ast.tokens = parser.tokens;
  114. }
  115. if (parser.config.tolerant) {
  116. ast.errors = parser.errorHandler.errors;
  117. }
  118. return ast;
  119. }
  120. exports.parse = parse;
  121. function parseModule(code, options, delegate) {
  122. var parsingOptions = options || {};
  123. parsingOptions.sourceType = 'module';
  124. return parse(code, parsingOptions, delegate);
  125. }
  126. exports.parseModule = parseModule;
  127. function parseScript(code, options, delegate) {
  128. var parsingOptions = options || {};
  129. parsingOptions.sourceType = 'script';
  130. return parse(code, parsingOptions, delegate);
  131. }
  132. exports.parseScript = parseScript;
  133. function tokenize(code, options, delegate) {
  134. var tokenizer = new tokenizer_1.Tokenizer(code, options);
  135. var tokens;
  136. tokens = [];
  137. try {
  138. while (true) {
  139. var token = tokenizer.getNextToken();
  140. if (!token) {
  141. break;
  142. }
  143. if (delegate) {
  144. token = delegate(token);
  145. }
  146. tokens.push(token);
  147. }
  148. }
  149. catch (e) {
  150. tokenizer.errorHandler.tolerate(e);
  151. }
  152. if (tokenizer.errorHandler.tolerant) {
  153. tokens.errors = tokenizer.errors();
  154. }
  155. return tokens;
  156. }
  157. exports.tokenize = tokenize;
  158. var syntax_1 = __webpack_require__(2);
  159. exports.Syntax = syntax_1.Syntax;
  160. // Sync with *.json manifests.
  161. exports.version = '4.0.1';
  162. /***/ },
  163. /* 1 */
  164. /***/ function(module, exports, __webpack_require__) {
  165. "use strict";
  166. Object.defineProperty(exports, "__esModule", { value: true });
  167. var syntax_1 = __webpack_require__(2);
  168. var CommentHandler = (function () {
  169. function CommentHandler() {
  170. this.attach = false;
  171. this.comments = [];
  172. this.stack = [];
  173. this.leading = [];
  174. this.trailing = [];
  175. }
  176. CommentHandler.prototype.insertInnerComments = function (node, metadata) {
  177. // innnerComments for properties empty block
  178. // `function a() {/** comments **\/}`
  179. if (node.type === syntax_1.Syntax.BlockStatement && node.body.length === 0) {
  180. var innerComments = [];
  181. for (var i = this.leading.length - 1; i >= 0; --i) {
  182. var entry = this.leading[i];
  183. if (metadata.end.offset >= entry.start) {
  184. innerComments.unshift(entry.comment);
  185. this.leading.splice(i, 1);
  186. this.trailing.splice(i, 1);
  187. }
  188. }
  189. if (innerComments.length) {
  190. node.innerComments = innerComments;
  191. }
  192. }
  193. };
  194. CommentHandler.prototype.findTrailingComments = function (metadata) {
  195. var trailingComments = [];
  196. if (this.trailing.length > 0) {
  197. for (var i = this.trailing.length - 1; i >= 0; --i) {
  198. var entry_1 = this.trailing[i];
  199. if (entry_1.start >= metadata.end.offset) {
  200. trailingComments.unshift(entry_1.comment);
  201. }
  202. }
  203. this.trailing.length = 0;
  204. return trailingComments;
  205. }
  206. var entry = this.stack[this.stack.length - 1];
  207. if (entry && entry.node.trailingComments) {
  208. var firstComment = entry.node.trailingComments[0];
  209. if (firstComment && firstComment.range[0] >= metadata.end.offset) {
  210. trailingComments = entry.node.trailingComments;
  211. delete entry.node.trailingComments;
  212. }
  213. }
  214. return trailingComments;
  215. };
  216. CommentHandler.prototype.findLeadingComments = function (metadata) {
  217. var leadingComments = [];
  218. var target;
  219. while (this.stack.length > 0) {
  220. var entry = this.stack[this.stack.length - 1];
  221. if (entry && entry.start >= metadata.start.offset) {
  222. target = entry.node;
  223. this.stack.pop();
  224. }
  225. else {
  226. break;
  227. }
  228. }
  229. if (target) {
  230. var count = target.leadingComments ? target.leadingComments.length : 0;
  231. for (var i = count - 1; i >= 0; --i) {
  232. var comment = target.leadingComments[i];
  233. if (comment.range[1] <= metadata.start.offset) {
  234. leadingComments.unshift(comment);
  235. target.leadingComments.splice(i, 1);
  236. }
  237. }
  238. if (target.leadingComments && target.leadingComments.length === 0) {
  239. delete target.leadingComments;
  240. }
  241. return leadingComments;
  242. }
  243. for (var i = this.leading.length - 1; i >= 0; --i) {
  244. var entry = this.leading[i];
  245. if (entry.start <= metadata.start.offset) {
  246. leadingComments.unshift(entry.comment);
  247. this.leading.splice(i, 1);
  248. }
  249. }
  250. return leadingComments;
  251. };
  252. CommentHandler.prototype.visitNode = function (node, metadata) {
  253. if (node.type === syntax_1.Syntax.Program && node.body.length > 0) {
  254. return;
  255. }
  256. this.insertInnerComments(node, metadata);
  257. var trailingComments = this.findTrailingComments(metadata);
  258. var leadingComments = this.findLeadingComments(metadata);
  259. if (leadingComments.length > 0) {
  260. node.leadingComments = leadingComments;
  261. }
  262. if (trailingComments.length > 0) {
  263. node.trailingComments = trailingComments;
  264. }
  265. this.stack.push({
  266. node: node,
  267. start: metadata.start.offset
  268. });
  269. };
  270. CommentHandler.prototype.visitComment = function (node, metadata) {
  271. var type = (node.type[0] === 'L') ? 'Line' : 'Block';
  272. var comment = {
  273. type: type,
  274. value: node.value
  275. };
  276. if (node.range) {
  277. comment.range = node.range;
  278. }
  279. if (node.loc) {
  280. comment.loc = node.loc;
  281. }
  282. this.comments.push(comment);
  283. if (this.attach) {
  284. var entry = {
  285. comment: {
  286. type: type,
  287. value: node.value,
  288. range: [metadata.start.offset, metadata.end.offset]
  289. },
  290. start: metadata.start.offset
  291. };
  292. if (node.loc) {
  293. entry.comment.loc = node.loc;
  294. }
  295. node.type = type;
  296. this.leading.push(entry);
  297. this.trailing.push(entry);
  298. }
  299. };
  300. CommentHandler.prototype.visit = function (node, metadata) {
  301. if (node.type === 'LineComment') {
  302. this.visitComment(node, metadata);
  303. }
  304. else if (node.type === 'BlockComment') {
  305. this.visitComment(node, metadata);
  306. }
  307. else if (this.attach) {
  308. this.visitNode(node, metadata);
  309. }
  310. };
  311. return CommentHandler;
  312. }());
  313. exports.CommentHandler = CommentHandler;
  314. /***/ },
  315. /* 2 */
  316. /***/ function(module, exports) {
  317. "use strict";
  318. Object.defineProperty(exports, "__esModule", { value: true });
  319. exports.Syntax = {
  320. AssignmentExpression: 'AssignmentExpression',
  321. AssignmentPattern: 'AssignmentPattern',
  322. ArrayExpression: 'ArrayExpression',
  323. ArrayPattern: 'ArrayPattern',
  324. ArrowFunctionExpression: 'ArrowFunctionExpression',
  325. AwaitExpression: 'AwaitExpression',
  326. BlockStatement: 'BlockStatement',
  327. BinaryExpression: 'BinaryExpression',
  328. BreakStatement: 'BreakStatement',
  329. CallExpression: 'CallExpression',
  330. CatchClause: 'CatchClause',
  331. ClassBody: 'ClassBody',
  332. ClassDeclaration: 'ClassDeclaration',
  333. ClassExpression: 'ClassExpression',
  334. ConditionalExpression: 'ConditionalExpression',
  335. ContinueStatement: 'ContinueStatement',
  336. DoWhileStatement: 'DoWhileStatement',
  337. DebuggerStatement: 'DebuggerStatement',
  338. EmptyStatement: 'EmptyStatement',
  339. ExportAllDeclaration: 'ExportAllDeclaration',
  340. ExportDefaultDeclaration: 'ExportDefaultDeclaration',
  341. ExportNamedDeclaration: 'ExportNamedDeclaration',
  342. ExportSpecifier: 'ExportSpecifier',
  343. ExpressionStatement: 'ExpressionStatement',
  344. ForStatement: 'ForStatement',
  345. ForOfStatement: 'ForOfStatement',
  346. ForInStatement: 'ForInStatement',
  347. FunctionDeclaration: 'FunctionDeclaration',
  348. FunctionExpression: 'FunctionExpression',
  349. Identifier: 'Identifier',
  350. IfStatement: 'IfStatement',
  351. ImportDeclaration: 'ImportDeclaration',
  352. ImportDefaultSpecifier: 'ImportDefaultSpecifier',
  353. ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',
  354. ImportSpecifier: 'ImportSpecifier',
  355. Literal: 'Literal',
  356. LabeledStatement: 'LabeledStatement',
  357. LogicalExpression: 'LogicalExpression',
  358. MemberExpression: 'MemberExpression',
  359. MetaProperty: 'MetaProperty',
  360. MethodDefinition: 'MethodDefinition',
  361. NewExpression: 'NewExpression',
  362. ObjectExpression: 'ObjectExpression',
  363. ObjectPattern: 'ObjectPattern',
  364. Program: 'Program',
  365. Property: 'Property',
  366. RestElement: 'RestElement',
  367. ReturnStatement: 'ReturnStatement',
  368. SequenceExpression: 'SequenceExpression',
  369. SpreadElement: 'SpreadElement',
  370. Super: 'Super',
  371. SwitchCase: 'SwitchCase',
  372. SwitchStatement: 'SwitchStatement',
  373. TaggedTemplateExpression: 'TaggedTemplateExpression',
  374. TemplateElement: 'TemplateElement',
  375. TemplateLiteral: 'TemplateLiteral',
  376. ThisExpression: 'ThisExpression',
  377. ThrowStatement: 'ThrowStatement',
  378. TryStatement: 'TryStatement',
  379. UnaryExpression: 'UnaryExpression',
  380. UpdateExpression: 'UpdateExpression',
  381. VariableDeclaration: 'VariableDeclaration',
  382. VariableDeclarator: 'VariableDeclarator',
  383. WhileStatement: 'WhileStatement',
  384. WithStatement: 'WithStatement',
  385. YieldExpression: 'YieldExpression'
  386. };
  387. /***/ },
  388. /* 3 */
  389. /***/ function(module, exports, __webpack_require__) {
  390. "use strict";
  391. /* istanbul ignore next */
  392. var __extends = (this && this.__extends) || (function () {
  393. var extendStatics = Object.setPrototypeOf ||
  394. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  395. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  396. return function (d, b) {
  397. extendStatics(d, b);
  398. function __() { this.constructor = d; }
  399. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  400. };
  401. })();
  402. Object.defineProperty(exports, "__esModule", { value: true });
  403. var character_1 = __webpack_require__(4);
  404. var JSXNode = __webpack_require__(5);
  405. var jsx_syntax_1 = __webpack_require__(6);
  406. var Node = __webpack_require__(7);
  407. var parser_1 = __webpack_require__(8);
  408. var token_1 = __webpack_require__(13);
  409. var xhtml_entities_1 = __webpack_require__(14);
  410. token_1.TokenName[100 /* Identifier */] = 'JSXIdentifier';
  411. token_1.TokenName[101 /* Text */] = 'JSXText';
  412. // Fully qualified element name, e.g. <svg:path> returns "svg:path"
  413. function getQualifiedElementName(elementName) {
  414. var qualifiedName;
  415. switch (elementName.type) {
  416. case jsx_syntax_1.JSXSyntax.JSXIdentifier:
  417. var id = elementName;
  418. qualifiedName = id.name;
  419. break;
  420. case jsx_syntax_1.JSXSyntax.JSXNamespacedName:
  421. var ns = elementName;
  422. qualifiedName = getQualifiedElementName(ns.namespace) + ':' +
  423. getQualifiedElementName(ns.name);
  424. break;
  425. case jsx_syntax_1.JSXSyntax.JSXMemberExpression:
  426. var expr = elementName;
  427. qualifiedName = getQualifiedElementName(expr.object) + '.' +
  428. getQualifiedElementName(expr.property);
  429. break;
  430. /* istanbul ignore next */
  431. default:
  432. break;
  433. }
  434. return qualifiedName;
  435. }
  436. var JSXParser = (function (_super) {
  437. __extends(JSXParser, _super);
  438. function JSXParser(code, options, delegate) {
  439. return _super.call(this, code, options, delegate) || this;
  440. }
  441. JSXParser.prototype.parsePrimaryExpression = function () {
  442. return this.match('<') ? this.parseJSXRoot() : _super.prototype.parsePrimaryExpression.call(this);
  443. };
  444. JSXParser.prototype.startJSX = function () {
  445. // Unwind the scanner before the lookahead token.
  446. this.scanner.index = this.startMarker.index;
  447. this.scanner.lineNumber = this.startMarker.line;
  448. this.scanner.lineStart = this.startMarker.index - this.startMarker.column;
  449. };
  450. JSXParser.prototype.finishJSX = function () {
  451. // Prime the next lookahead.
  452. this.nextToken();
  453. };
  454. JSXParser.prototype.reenterJSX = function () {
  455. this.startJSX();
  456. this.expectJSX('}');
  457. // Pop the closing '}' added from the lookahead.
  458. if (this.config.tokens) {
  459. this.tokens.pop();
  460. }
  461. };
  462. JSXParser.prototype.createJSXNode = function () {
  463. this.collectComments();
  464. return {
  465. index: this.scanner.index,
  466. line: this.scanner.lineNumber,
  467. column: this.scanner.index - this.scanner.lineStart
  468. };
  469. };
  470. JSXParser.prototype.createJSXChildNode = function () {
  471. return {
  472. index: this.scanner.index,
  473. line: this.scanner.lineNumber,
  474. column: this.scanner.index - this.scanner.lineStart
  475. };
  476. };
  477. JSXParser.prototype.scanXHTMLEntity = function (quote) {
  478. var result = '&';
  479. var valid = true;
  480. var terminated = false;
  481. var numeric = false;
  482. var hex = false;
  483. while (!this.scanner.eof() && valid && !terminated) {
  484. var ch = this.scanner.source[this.scanner.index];
  485. if (ch === quote) {
  486. break;
  487. }
  488. terminated = (ch === ';');
  489. result += ch;
  490. ++this.scanner.index;
  491. if (!terminated) {
  492. switch (result.length) {
  493. case 2:
  494. // e.g. '&#123;'
  495. numeric = (ch === '#');
  496. break;
  497. case 3:
  498. if (numeric) {
  499. // e.g. '&#x41;'
  500. hex = (ch === 'x');
  501. valid = hex || character_1.Character.isDecimalDigit(ch.charCodeAt(0));
  502. numeric = numeric && !hex;
  503. }
  504. break;
  505. default:
  506. valid = valid && !(numeric && !character_1.Character.isDecimalDigit(ch.charCodeAt(0)));
  507. valid = valid && !(hex && !character_1.Character.isHexDigit(ch.charCodeAt(0)));
  508. break;
  509. }
  510. }
  511. }
  512. if (valid && terminated && result.length > 2) {
  513. // e.g. '&#x41;' becomes just '#x41'
  514. var str = result.substr(1, result.length - 2);
  515. if (numeric && str.length > 1) {
  516. result = String.fromCharCode(parseInt(str.substr(1), 10));
  517. }
  518. else if (hex && str.length > 2) {
  519. result = String.fromCharCode(parseInt('0' + str.substr(1), 16));
  520. }
  521. else if (!numeric && !hex && xhtml_entities_1.XHTMLEntities[str]) {
  522. result = xhtml_entities_1.XHTMLEntities[str];
  523. }
  524. }
  525. return result;
  526. };
  527. // Scan the next JSX token. This replaces Scanner#lex when in JSX mode.
  528. JSXParser.prototype.lexJSX = function () {
  529. var cp = this.scanner.source.charCodeAt(this.scanner.index);
  530. // < > / : = { }
  531. if (cp === 60 || cp === 62 || cp === 47 || cp === 58 || cp === 61 || cp === 123 || cp === 125) {
  532. var value = this.scanner.source[this.scanner.index++];
  533. return {
  534. type: 7 /* Punctuator */,
  535. value: value,
  536. lineNumber: this.scanner.lineNumber,
  537. lineStart: this.scanner.lineStart,
  538. start: this.scanner.index - 1,
  539. end: this.scanner.index
  540. };
  541. }
  542. // " '
  543. if (cp === 34 || cp === 39) {
  544. var start = this.scanner.index;
  545. var quote = this.scanner.source[this.scanner.index++];
  546. var str = '';
  547. while (!this.scanner.eof()) {
  548. var ch = this.scanner.source[this.scanner.index++];
  549. if (ch === quote) {
  550. break;
  551. }
  552. else if (ch === '&') {
  553. str += this.scanXHTMLEntity(quote);
  554. }
  555. else {
  556. str += ch;
  557. }
  558. }
  559. return {
  560. type: 8 /* StringLiteral */,
  561. value: str,
  562. lineNumber: this.scanner.lineNumber,
  563. lineStart: this.scanner.lineStart,
  564. start: start,
  565. end: this.scanner.index
  566. };
  567. }
  568. // ... or .
  569. if (cp === 46) {
  570. var n1 = this.scanner.source.charCodeAt(this.scanner.index + 1);
  571. var n2 = this.scanner.source.charCodeAt(this.scanner.index + 2);
  572. var value = (n1 === 46 && n2 === 46) ? '...' : '.';
  573. var start = this.scanner.index;
  574. this.scanner.index += value.length;
  575. return {
  576. type: 7 /* Punctuator */,
  577. value: value,
  578. lineNumber: this.scanner.lineNumber,
  579. lineStart: this.scanner.lineStart,
  580. start: start,
  581. end: this.scanner.index
  582. };
  583. }
  584. // `
  585. if (cp === 96) {
  586. // Only placeholder, since it will be rescanned as a real assignment expression.
  587. return {
  588. type: 10 /* Template */,
  589. value: '',
  590. lineNumber: this.scanner.lineNumber,
  591. lineStart: this.scanner.lineStart,
  592. start: this.scanner.index,
  593. end: this.scanner.index
  594. };
  595. }
  596. // Identifer can not contain backslash (char code 92).
  597. if (character_1.Character.isIdentifierStart(cp) && (cp !== 92)) {
  598. var start = this.scanner.index;
  599. ++this.scanner.index;
  600. while (!this.scanner.eof()) {
  601. var ch = this.scanner.source.charCodeAt(this.scanner.index);
  602. if (character_1.Character.isIdentifierPart(ch) && (ch !== 92)) {
  603. ++this.scanner.index;
  604. }
  605. else if (ch === 45) {
  606. // Hyphen (char code 45) can be part of an identifier.
  607. ++this.scanner.index;
  608. }
  609. else {
  610. break;
  611. }
  612. }
  613. var id = this.scanner.source.slice(start, this.scanner.index);
  614. return {
  615. type: 100 /* Identifier */,
  616. value: id,
  617. lineNumber: this.scanner.lineNumber,
  618. lineStart: this.scanner.lineStart,
  619. start: start,
  620. end: this.scanner.index
  621. };
  622. }
  623. return this.scanner.lex();
  624. };
  625. JSXParser.prototype.nextJSXToken = function () {
  626. this.collectComments();
  627. this.startMarker.index = this.scanner.index;
  628. this.startMarker.line = this.scanner.lineNumber;
  629. this.startMarker.column = this.scanner.index - this.scanner.lineStart;
  630. var token = this.lexJSX();
  631. this.lastMarker.index = this.scanner.index;
  632. this.lastMarker.line = this.scanner.lineNumber;
  633. this.lastMarker.column = this.scanner.index - this.scanner.lineStart;
  634. if (this.config.tokens) {
  635. this.tokens.push(this.convertToken(token));
  636. }
  637. return token;
  638. };
  639. JSXParser.prototype.nextJSXText = function () {
  640. this.startMarker.index = this.scanner.index;
  641. this.startMarker.line = this.scanner.lineNumber;
  642. this.startMarker.column = this.scanner.index - this.scanner.lineStart;
  643. var start = this.scanner.index;
  644. var text = '';
  645. while (!this.scanner.eof()) {
  646. var ch = this.scanner.source[this.scanner.index];
  647. if (ch === '{' || ch === '<') {
  648. break;
  649. }
  650. ++this.scanner.index;
  651. text += ch;
  652. if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
  653. ++this.scanner.lineNumber;
  654. if (ch === '\r' && this.scanner.source[this.scanner.index] === '\n') {
  655. ++this.scanner.index;
  656. }
  657. this.scanner.lineStart = this.scanner.index;
  658. }
  659. }
  660. this.lastMarker.index = this.scanner.index;
  661. this.lastMarker.line = this.scanner.lineNumber;
  662. this.lastMarker.column = this.scanner.index - this.scanner.lineStart;
  663. var token = {
  664. type: 101 /* Text */,
  665. value: text,
  666. lineNumber: this.scanner.lineNumber,
  667. lineStart: this.scanner.lineStart,
  668. start: start,
  669. end: this.scanner.index
  670. };
  671. if ((text.length > 0) && this.config.tokens) {
  672. this.tokens.push(this.convertToken(token));
  673. }
  674. return token;
  675. };
  676. JSXParser.prototype.peekJSXToken = function () {
  677. var state = this.scanner.saveState();
  678. this.scanner.scanComments();
  679. var next = this.lexJSX();
  680. this.scanner.restoreState(state);
  681. return next;
  682. };
  683. // Expect the next JSX token to match the specified punctuator.
  684. // If not, an exception will be thrown.
  685. JSXParser.prototype.expectJSX = function (value) {
  686. var token = this.nextJSXToken();
  687. if (token.type !== 7 /* Punctuator */ || token.value !== value) {
  688. this.throwUnexpectedToken(token);
  689. }
  690. };
  691. // Return true if the next JSX token matches the specified punctuator.
  692. JSXParser.prototype.matchJSX = function (value) {
  693. var next = this.peekJSXToken();
  694. return next.type === 7 /* Punctuator */ && next.value === value;
  695. };
  696. JSXParser.prototype.parseJSXIdentifier = function () {
  697. var node = this.createJSXNode();
  698. var token = this.nextJSXToken();
  699. if (token.type !== 100 /* Identifier */) {
  700. this.throwUnexpectedToken(token);
  701. }
  702. return this.finalize(node, new JSXNode.JSXIdentifier(token.value));
  703. };
  704. JSXParser.prototype.parseJSXElementName = function () {
  705. var node = this.createJSXNode();
  706. var elementName = this.parseJSXIdentifier();
  707. if (this.matchJSX(':')) {
  708. var namespace = elementName;
  709. this.expectJSX(':');
  710. var name_1 = this.parseJSXIdentifier();
  711. elementName = this.finalize(node, new JSXNode.JSXNamespacedName(namespace, name_1));
  712. }
  713. else if (this.matchJSX('.')) {
  714. while (this.matchJSX('.')) {
  715. var object = elementName;
  716. this.expectJSX('.');
  717. var property = this.parseJSXIdentifier();
  718. elementName = this.finalize(node, new JSXNode.JSXMemberExpression(object, property));
  719. }
  720. }
  721. return elementName;
  722. };
  723. JSXParser.prototype.parseJSXAttributeName = function () {
  724. var node = this.createJSXNode();
  725. var attributeName;
  726. var identifier = this.parseJSXIdentifier();
  727. if (this.matchJSX(':')) {
  728. var namespace = identifier;
  729. this.expectJSX(':');
  730. var name_2 = this.parseJSXIdentifier();
  731. attributeName = this.finalize(node, new JSXNode.JSXNamespacedName(namespace, name_2));
  732. }
  733. else {
  734. attributeName = identifier;
  735. }
  736. return attributeName;
  737. };
  738. JSXParser.prototype.parseJSXStringLiteralAttribute = function () {
  739. var node = this.createJSXNode();
  740. var token = this.nextJSXToken();
  741. if (token.type !== 8 /* StringLiteral */) {
  742. this.throwUnexpectedToken(token);
  743. }
  744. var raw = this.getTokenRaw(token);
  745. return this.finalize(node, new Node.Literal(token.value, raw));
  746. };
  747. JSXParser.prototype.parseJSXExpressionAttribute = function () {
  748. var node = this.createJSXNode();
  749. this.expectJSX('{');
  750. this.finishJSX();
  751. if (this.match('}')) {
  752. this.tolerateError('JSX attributes must only be assigned a non-empty expression');
  753. }
  754. var expression = this.parseAssignmentExpression();
  755. this.reenterJSX();
  756. return this.finalize(node, new JSXNode.JSXExpressionContainer(expression));
  757. };
  758. JSXParser.prototype.parseJSXAttributeValue = function () {
  759. return this.matchJSX('{') ? this.parseJSXExpressionAttribute() :
  760. this.matchJSX('<') ? this.parseJSXElement() : this.parseJSXStringLiteralAttribute();
  761. };
  762. JSXParser.prototype.parseJSXNameValueAttribute = function () {
  763. var node = this.createJSXNode();
  764. var name = this.parseJSXAttributeName();
  765. var value = null;
  766. if (this.matchJSX('=')) {
  767. this.expectJSX('=');
  768. value = this.parseJSXAttributeValue();
  769. }
  770. return this.finalize(node, new JSXNode.JSXAttribute(name, value));
  771. };
  772. JSXParser.prototype.parseJSXSpreadAttribute = function () {
  773. var node = this.createJSXNode();
  774. this.expectJSX('{');
  775. this.expectJSX('...');
  776. this.finishJSX();
  777. var argument = this.parseAssignmentExpression();
  778. this.reenterJSX();
  779. return this.finalize(node, new JSXNode.JSXSpreadAttribute(argument));
  780. };
  781. JSXParser.prototype.parseJSXAttributes = function () {
  782. var attributes = [];
  783. while (!this.matchJSX('/') && !this.matchJSX('>')) {
  784. var attribute = this.matchJSX('{') ? this.parseJSXSpreadAttribute() :
  785. this.parseJSXNameValueAttribute();
  786. attributes.push(attribute);
  787. }
  788. return attributes;
  789. };
  790. JSXParser.prototype.parseJSXOpeningElement = function () {
  791. var node = this.createJSXNode();
  792. this.expectJSX('<');
  793. var name = this.parseJSXElementName();
  794. var attributes = this.parseJSXAttributes();
  795. var selfClosing = this.matchJSX('/');
  796. if (selfClosing) {
  797. this.expectJSX('/');
  798. }
  799. this.expectJSX('>');
  800. return this.finalize(node, new JSXNode.JSXOpeningElement(name, selfClosing, attributes));
  801. };
  802. JSXParser.prototype.parseJSXBoundaryElement = function () {
  803. var node = this.createJSXNode();
  804. this.expectJSX('<');
  805. if (this.matchJSX('/')) {
  806. this.expectJSX('/');
  807. var name_3 = this.parseJSXElementName();
  808. this.expectJSX('>');
  809. return this.finalize(node, new JSXNode.JSXClosingElement(name_3));
  810. }
  811. var name = this.parseJSXElementName();
  812. var attributes = this.parseJSXAttributes();
  813. var selfClosing = this.matchJSX('/');
  814. if (selfClosing) {
  815. this.expectJSX('/');
  816. }
  817. this.expectJSX('>');
  818. return this.finalize(node, new JSXNode.JSXOpeningElement(name, selfClosing, attributes));
  819. };
  820. JSXParser.prototype.parseJSXEmptyExpression = function () {
  821. var node = this.createJSXChildNode();
  822. this.collectComments();
  823. this.lastMarker.index = this.scanner.index;
  824. this.lastMarker.line = this.scanner.lineNumber;
  825. this.lastMarker.column = this.scanner.index - this.scanner.lineStart;
  826. return this.finalize(node, new JSXNode.JSXEmptyExpression());
  827. };
  828. JSXParser.prototype.parseJSXExpressionContainer = function () {
  829. var node = this.createJSXNode();
  830. this.expectJSX('{');
  831. var expression;
  832. if (this.matchJSX('}')) {
  833. expression = this.parseJSXEmptyExpression();
  834. this.expectJSX('}');
  835. }
  836. else {
  837. this.finishJSX();
  838. expression = this.parseAssignmentExpression();
  839. this.reenterJSX();
  840. }
  841. return this.finalize(node, new JSXNode.JSXExpressionContainer(expression));
  842. };
  843. JSXParser.prototype.parseJSXChildren = function () {
  844. var children = [];
  845. while (!this.scanner.eof()) {
  846. var node = this.createJSXChildNode();
  847. var token = this.nextJSXText();
  848. if (token.start < token.end) {
  849. var raw = this.getTokenRaw(token);
  850. var child = this.finalize(node, new JSXNode.JSXText(token.value, raw));
  851. children.push(child);
  852. }
  853. if (this.scanner.source[this.scanner.index] === '{') {
  854. var container = this.parseJSXExpressionContainer();
  855. children.push(container);
  856. }
  857. else {
  858. break;
  859. }
  860. }
  861. return children;
  862. };
  863. JSXParser.prototype.parseComplexJSXElement = function (el) {
  864. var stack = [];
  865. while (!this.scanner.eof()) {
  866. el.children = el.children.concat(this.parseJSXChildren());
  867. var node = this.createJSXChildNode();
  868. var element = this.parseJSXBoundaryElement();
  869. if (element.type === jsx_syntax_1.JSXSyntax.JSXOpeningElement) {
  870. var opening = element;
  871. if (opening.selfClosing) {
  872. var child = this.finalize(node, new JSXNode.JSXElement(opening, [], null));
  873. el.children.push(child);
  874. }
  875. else {
  876. stack.push(el);
  877. el = { node: node, opening: opening, closing: null, children: [] };
  878. }
  879. }
  880. if (element.type === jsx_syntax_1.JSXSyntax.JSXClosingElement) {
  881. el.closing = element;
  882. var open_1 = getQualifiedElementName(el.opening.name);
  883. var close_1 = getQualifiedElementName(el.closing.name);
  884. if (open_1 !== close_1) {
  885. this.tolerateError('Expected corresponding JSX closing tag for %0', open_1);
  886. }
  887. if (stack.length > 0) {
  888. var child = this.finalize(el.node, new JSXNode.JSXElement(el.opening, el.children, el.closing));
  889. el = stack[stack.length - 1];
  890. el.children.push(child);
  891. stack.pop();
  892. }
  893. else {
  894. break;
  895. }
  896. }
  897. }
  898. return el;
  899. };
  900. JSXParser.prototype.parseJSXElement = function () {
  901. var node = this.createJSXNode();
  902. var opening = this.parseJSXOpeningElement();
  903. var children = [];
  904. var closing = null;
  905. if (!opening.selfClosing) {
  906. var el = this.parseComplexJSXElement({ node: node, opening: opening, closing: closing, children: children });
  907. children = el.children;
  908. closing = el.closing;
  909. }
  910. return this.finalize(node, new JSXNode.JSXElement(opening, children, closing));
  911. };
  912. JSXParser.prototype.parseJSXRoot = function () {
  913. // Pop the opening '<' added from the lookahead.
  914. if (this.config.tokens) {
  915. this.tokens.pop();
  916. }
  917. this.startJSX();
  918. var element = this.parseJSXElement();
  919. this.finishJSX();
  920. return element;
  921. };
  922. JSXParser.prototype.isStartOfExpression = function () {
  923. return _super.prototype.isStartOfExpression.call(this) || this.match('<');
  924. };
  925. return JSXParser;
  926. }(parser_1.Parser));
  927. exports.JSXParser = JSXParser;
  928. /***/ },
  929. /* 4 */
  930. /***/ function(module, exports) {
  931. "use strict";
  932. Object.defineProperty(exports, "__esModule", { value: true });
  933. // See also tools/generate-unicode-regex.js.
  934. var Regex = {
  935. // Unicode v8.0.0 NonAsciiIdentifierStart:
  936. NonAsciiIdentifierStart: /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\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-\u08B4\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\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\u0AF9\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-\u0C39\u0C3D\u0C58-\u0C5A\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\u0D5F-\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-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\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\u2118-\u211D\u2124\u2126\u2128\u212A-\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\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309B-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\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\u
  937. // Unicode v8.0.0 NonAsciiIdentifierPart:
  938. NonAsciiIdentifierPart: /[\xAA\xB5\xB7\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\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-\u08B4\u08E3-\u0963\u0966-\u096F\u0971-\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\u0AF9\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\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C81-\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\u0D01-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\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\u1369-\u1371\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\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-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1CD0-\u1CD2\u1CD4-\u1CF6\u1CF8\u1CF9\u1D00-\u1DF5\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\u2118-\u211D\u2124\u2126\u2128\u212A-\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\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u
  939. };
  940. exports.Character = {
  941. /* tslint:disable:no-bitwise */
  942. fromCodePoint: function (cp) {
  943. return (cp < 0x10000) ? String.fromCharCode(cp) :
  944. String.fromCharCode(0xD800 + ((cp - 0x10000) >> 10)) +
  945. String.fromCharCode(0xDC00 + ((cp - 0x10000) & 1023));
  946. },
  947. // https://tc39.github.io/ecma262/#sec-white-space
  948. isWhiteSpace: function (cp) {
  949. return (cp === 0x20) || (cp === 0x09) || (cp === 0x0B) || (cp === 0x0C) || (cp === 0xA0) ||
  950. (cp >= 0x1680 && [0x1680, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202F, 0x205F, 0x3000, 0xFEFF].indexOf(cp) >= 0);
  951. },
  952. // https://tc39.github.io/ecma262/#sec-line-terminators
  953. isLineTerminator: function (cp) {
  954. return (cp === 0x0A) || (cp === 0x0D) || (cp === 0x2028) || (cp === 0x2029);
  955. },
  956. // https://tc39.github.io/ecma262/#sec-names-and-keywords
  957. isIdentifierStart: function (cp) {
  958. return (cp === 0x24) || (cp === 0x5F) ||
  959. (cp >= 0x41 && cp <= 0x5A) ||
  960. (cp >= 0x61 && cp <= 0x7A) ||
  961. (cp === 0x5C) ||
  962. ((cp >= 0x80) && Regex.NonAsciiIdentifierStart.test(exports.Character.fromCodePoint(cp)));
  963. },
  964. isIdentifierPart: function (cp) {
  965. return (cp === 0x24) || (cp === 0x5F) ||
  966. (cp >= 0x41 && cp <= 0x5A) ||
  967. (cp >= 0x61 && cp <= 0x7A) ||
  968. (cp >= 0x30 && cp <= 0x39) ||
  969. (cp === 0x5C) ||
  970. ((cp >= 0x80) && Regex.NonAsciiIdentifierPart.test(exports.Character.fromCodePoint(cp)));
  971. },
  972. // https://tc39.github.io/ecma262/#sec-literals-numeric-literals
  973. isDecimalDigit: function (cp) {
  974. return (cp >= 0x30 && cp <= 0x39); // 0..9
  975. },
  976. isHexDigit: function (cp) {
  977. return (cp >= 0x30 && cp <= 0x39) ||
  978. (cp >= 0x41 && cp <= 0x46) ||
  979. (cp >= 0x61 && cp <= 0x66); // a..f
  980. },
  981. isOctalDigit: function (cp) {
  982. return (cp >= 0x30 && cp <= 0x37); // 0..7
  983. }
  984. };
  985. /***/ },
  986. /* 5 */
  987. /***/ function(module, exports, __webpack_require__) {
  988. "use strict";
  989. Object.defineProperty(exports, "__esModule", { value: true });
  990. var jsx_syntax_1 = __webpack_require__(6);
  991. /* tslint:disable:max-classes-per-file */
  992. var JSXClosingElement = (function () {
  993. function JSXClosingElement(name) {
  994. this.type = jsx_syntax_1.JSXSyntax.JSXClosingElement;
  995. this.name = name;
  996. }
  997. return JSXClosingElement;
  998. }());
  999. exports.JSXClosingElement = JSXClosingElement;
  1000. var JSXElement = (function () {
  1001. function JSXElement(openingElement, children, closingElement) {
  1002. this.type = jsx_syntax_1.JSXSyntax.JSXElement;
  1003. this.openingElement = openingElement;
  1004. this.children = children;
  1005. this.closingElement = closingElement;
  1006. }
  1007. return JSXElement;
  1008. }());
  1009. exports.JSXElement = JSXElement;
  1010. var JSXEmptyExpression = (function () {
  1011. function JSXEmptyExpression() {
  1012. this.type = jsx_syntax_1.JSXSyntax.JSXEmptyExpression;
  1013. }
  1014. return JSXEmptyExpression;
  1015. }());
  1016. exports.JSXEmptyExpression = JSXEmptyExpression;
  1017. var JSXExpressionContainer = (function () {
  1018. function JSXExpressionContainer(expression) {
  1019. this.type = jsx_syntax_1.JSXSyntax.JSXExpressionContainer;
  1020. this.expression = expression;
  1021. }
  1022. return JSXExpressionContainer;
  1023. }());
  1024. exports.JSXExpressionContainer = JSXExpressionContainer;
  1025. var JSXIdentifier = (function () {
  1026. function JSXIdentifier(name) {
  1027. this.type = jsx_syntax_1.JSXSyntax.JSXIdentifier;
  1028. this.name = name;
  1029. }
  1030. return JSXIdentifier;
  1031. }());
  1032. exports.JSXIdentifier = JSXIdentifier;
  1033. var JSXMemberExpression = (function () {
  1034. function JSXMemberExpression(object, property) {
  1035. this.type = jsx_syntax_1.JSXSyntax.JSXMemberExpression;
  1036. this.object = object;
  1037. this.property = property;
  1038. }
  1039. return JSXMemberExpression;
  1040. }());
  1041. exports.JSXMemberExpression = JSXMemberExpression;
  1042. var JSXAttribute = (function () {
  1043. function JSXAttribute(name, value) {
  1044. this.type = jsx_syntax_1.JSXSyntax.JSXAttribute;
  1045. this.name = name;
  1046. this.value = value;
  1047. }
  1048. return JSXAttribute;
  1049. }());
  1050. exports.JSXAttribute = JSXAttribute;
  1051. var JSXNamespacedName = (function () {
  1052. function JSXNamespacedName(namespace, name) {
  1053. this.type = jsx_syntax_1.JSXSyntax.JSXNamespacedName;
  1054. this.namespace = namespace;
  1055. this.name = name;
  1056. }
  1057. return JSXNamespacedName;
  1058. }());
  1059. exports.JSXNamespacedName = JSXNamespacedName;
  1060. var JSXOpeningElement = (function () {
  1061. function JSXOpeningElement(name, selfClosing, attributes) {
  1062. this.type = jsx_syntax_1.JSXSyntax.JSXOpeningElement;
  1063. this.name = name;
  1064. this.selfClosing = selfClosing;
  1065. this.attributes = attributes;
  1066. }
  1067. return JSXOpeningElement;
  1068. }());
  1069. exports.JSXOpeningElement = JSXOpeningElement;
  1070. var JSXSpreadAttribute = (function () {
  1071. function JSXSpreadAttribute(argument) {
  1072. this.type = jsx_syntax_1.JSXSyntax.JSXSpreadAttribute;
  1073. this.argument = argument;
  1074. }
  1075. return JSXSpreadAttribute;
  1076. }());
  1077. exports.JSXSpreadAttribute = JSXSpreadAttribute;
  1078. var JSXText = (function () {
  1079. function JSXText(value, raw) {
  1080. this.type = jsx_syntax_1.JSXSyntax.JSXText;
  1081. this.value = value;
  1082. this.raw = raw;
  1083. }
  1084. return JSXText;
  1085. }());
  1086. exports.JSXText = JSXText;
  1087. /***/ },
  1088. /* 6 */
  1089. /***/ function(module, exports) {
  1090. "use strict";
  1091. Object.defineProperty(exports, "__esModule", { value: true });
  1092. exports.JSXSyntax = {
  1093. JSXAttribute: 'JSXAttribute',
  1094. JSXClosingElement: 'JSXClosingElement',
  1095. JSXElement: 'JSXElement',
  1096. JSXEmptyExpression: 'JSXEmptyExpression',
  1097. JSXExpressionContainer: 'JSXExpressionContainer',
  1098. JSXIdentifier: 'JSXIdentifier',
  1099. JSXMemberExpression: 'JSXMemberExpression',
  1100. JSXNamespacedName: 'JSXNamespacedName',
  1101. JSXOpeningElement: 'JSXOpeningElement',
  1102. JSXSpreadAttribute: 'JSXSpreadAttribute',
  1103. JSXText: 'JSXText'
  1104. };
  1105. /***/ },
  1106. /* 7 */
  1107. /***/ function(module, exports, __webpack_require__) {
  1108. "use strict";
  1109. Object.defineProperty(exports, "__esModule", { value: true });
  1110. var syntax_1 = __webpack_require__(2);
  1111. /* tslint:disable:max-classes-per-file */
  1112. var ArrayExpression = (function () {
  1113. function ArrayExpression(elements) {
  1114. this.type = syntax_1.Syntax.ArrayExpression;
  1115. this.elements = elements;
  1116. }
  1117. return ArrayExpression;
  1118. }());
  1119. exports.ArrayExpression = ArrayExpression;
  1120. var ArrayPattern = (function () {
  1121. function ArrayPattern(elements) {
  1122. this.type = syntax_1.Syntax.ArrayPattern;
  1123. this.elements = elements;
  1124. }
  1125. return ArrayPattern;
  1126. }());
  1127. exports.ArrayPattern = ArrayPattern;
  1128. var ArrowFunctionExpression = (function () {
  1129. function ArrowFunctionExpression(params, body, expression) {
  1130. this.type = syntax_1.Syntax.ArrowFunctionExpression;
  1131. this.id = null;
  1132. this.params = params;
  1133. this.body = body;
  1134. this.generator = false;
  1135. this.expression = expression;
  1136. this.async = false;
  1137. }
  1138. return ArrowFunctionExpression;
  1139. }());
  1140. exports.ArrowFunctionExpression = ArrowFunctionExpression;
  1141. var AssignmentExpression = (function () {
  1142. function AssignmentExpression(operator, left, right) {
  1143. this.type = syntax_1.Syntax.AssignmentExpression;
  1144. this.operator = operator;
  1145. this.left = left;
  1146. this.right = right;
  1147. }
  1148. return AssignmentExpression;
  1149. }());
  1150. exports.AssignmentExpression = AssignmentExpression;
  1151. var AssignmentPattern = (function () {
  1152. function AssignmentPattern(left, right) {
  1153. this.type = syntax_1.Syntax.AssignmentPattern;
  1154. this.left = left;
  1155. this.right = right;
  1156. }
  1157. return AssignmentPattern;
  1158. }());
  1159. exports.AssignmentPattern = AssignmentPattern;
  1160. var AsyncArrowFunctionExpression = (function () {
  1161. function AsyncArrowFunctionExpression(params, body, expression) {
  1162. this.type = syntax_1.Syntax.ArrowFunctionExpression;
  1163. this.id = null;
  1164. this.params = params;
  1165. this.body = body;
  1166. this.generator = false;
  1167. this.expression = expression;
  1168. this.async = true;
  1169. }
  1170. return AsyncArrowFunctionExpression;
  1171. }());
  1172. exports.AsyncArrowFunctionExpression = AsyncArrowFunctionExpression;
  1173. var AsyncFunctionDeclaration = (function () {
  1174. function AsyncFunctionDeclaration(id, params, body) {
  1175. this.type = syntax_1.Syntax.FunctionDeclaration;
  1176. this.id = id;
  1177. this.params = params;
  1178. this.body = body;
  1179. this.generator = false;
  1180. this.expression = false;
  1181. this.async = true;
  1182. }
  1183. return AsyncFunctionDeclaration;
  1184. }());
  1185. exports.AsyncFunctionDeclaration = AsyncFunctionDeclaration;
  1186. var AsyncFunctionExpression = (function () {
  1187. function AsyncFunctionExpression(id, params, body) {
  1188. this.type = syntax_1.Syntax.FunctionExpression;
  1189. this.id = id;
  1190. this.params = params;
  1191. this.body = body;
  1192. this.generator = false;
  1193. this.expression = false;
  1194. this.async = true;
  1195. }
  1196. return AsyncFunctionExpression;
  1197. }());
  1198. exports.AsyncFunctionExpression = AsyncFunctionExpression;
  1199. var AwaitExpression = (function () {
  1200. function AwaitExpression(argument) {
  1201. this.type = syntax_1.Syntax.AwaitExpression;
  1202. this.argument = argument;
  1203. }
  1204. return AwaitExpression;
  1205. }());
  1206. exports.AwaitExpression = AwaitExpression;
  1207. var BinaryExpression = (function () {
  1208. function BinaryExpression(operator, left, right) {
  1209. var logical = (operator === '||' || operator === '&&');
  1210. this.type = logical ? syntax_1.Syntax.LogicalExpression : syntax_1.Syntax.BinaryExpression;
  1211. this.operator = operator;
  1212. this.left = left;
  1213. this.right = right;
  1214. }
  1215. return BinaryExpression;
  1216. }());
  1217. exports.BinaryExpression = BinaryExpression;
  1218. var BlockStatement = (function () {
  1219. function BlockStatement(body) {
  1220. this.type = syntax_1.Syntax.BlockStatement;
  1221. this.body = body;
  1222. }
  1223. return BlockStatement;
  1224. }());
  1225. exports.BlockStatement = BlockStatement;
  1226. var BreakStatement = (function () {
  1227. function BreakStatement(label) {
  1228. this.type = syntax_1.Syntax.BreakStatement;
  1229. this.label = label;
  1230. }
  1231. return BreakStatement;
  1232. }());
  1233. exports.BreakStatement = BreakStatement;
  1234. var CallExpression = (function () {
  1235. function CallExpression(callee, args) {
  1236. this.type = syntax_1.Syntax.CallExpression;
  1237. this.callee = callee;
  1238. this.arguments = args;
  1239. }
  1240. return CallExpression;
  1241. }());
  1242. exports.CallExpression = CallExpression;
  1243. var CatchClause = (function () {
  1244. function CatchClause(param, body) {
  1245. this.type = syntax_1.Syntax.CatchClause;
  1246. this.param = param;
  1247. this.body = body;
  1248. }
  1249. return CatchClause;
  1250. }());
  1251. exports.CatchClause = CatchClause;
  1252. var ClassBody = (function () {
  1253. function ClassBody(body) {
  1254. this.type = syntax_1.Syntax.ClassBody;
  1255. this.body = body;
  1256. }
  1257. return ClassBody;
  1258. }());
  1259. exports.ClassBody = ClassBody;
  1260. var ClassDeclaration = (function () {
  1261. function ClassDeclaration(id, superClass, body) {
  1262. this.type = syntax_1.Syntax.ClassDeclaration;
  1263. this.id = id;
  1264. this.superClass = superClass;
  1265. this.body = body;
  1266. }
  1267. return ClassDeclaration;
  1268. }());
  1269. exports.ClassDeclaration = ClassDeclaration;
  1270. var ClassExpression = (function () {
  1271. function ClassExpression(id, superClass, body) {
  1272. this.type = syntax_1.Syntax.ClassExpression;
  1273. this.id = id;
  1274. this.superClass = superClass;
  1275. this.body = body;
  1276. }
  1277. return ClassExpression;
  1278. }());
  1279. exports.ClassExpression = ClassExpression;
  1280. var ComputedMemberExpression = (function () {
  1281. function ComputedMemberExpression(object, property) {
  1282. this.type = syntax_1.Syntax.MemberExpression;
  1283. this.computed = true;
  1284. this.object = object;
  1285. this.property = property;
  1286. }
  1287. return ComputedMemberExpression;
  1288. }());
  1289. exports.ComputedMemberExpression = ComputedMemberExpression;
  1290. var ConditionalExpression = (function () {
  1291. function ConditionalExpression(test, consequent, alternate) {
  1292. this.type = syntax_1.Syntax.ConditionalExpression;
  1293. this.test = test;
  1294. this.consequent = consequent;
  1295. this.alternate = alternate;
  1296. }
  1297. return ConditionalExpression;
  1298. }());
  1299. exports.ConditionalExpression = ConditionalExpression;
  1300. var ContinueStatement = (function () {
  1301. function ContinueStatement(label) {
  1302. this.type = syntax_1.Syntax.ContinueStatement;
  1303. this.label = label;
  1304. }
  1305. return ContinueStatement;
  1306. }());
  1307. exports.ContinueStatement = ContinueStatement;
  1308. var DebuggerStatement = (function () {
  1309. function DebuggerStatement() {
  1310. this.type = syntax_1.Syntax.DebuggerStatement;
  1311. }
  1312. return DebuggerStatement;
  1313. }());
  1314. exports.DebuggerStatement = DebuggerStatement;
  1315. var Directive = (function () {
  1316. function Directive(expression, directive) {
  1317. this.type = syntax_1.Syntax.ExpressionStatement;
  1318. this.expression = expression;
  1319. this.directive = directive;
  1320. }
  1321. return Directive;
  1322. }());
  1323. exports.Directive = Directive;
  1324. var DoWhileStatement = (function () {
  1325. function DoWhileStatement(body, test) {
  1326. this.type = syntax_1.Syntax.DoWhileStatement;
  1327. this.body = body;
  1328. this.test = test;
  1329. }
  1330. return DoWhileStatement;
  1331. }());
  1332. exports.DoWhileStatement = DoWhileStatement;
  1333. var EmptyStatement = (function () {
  1334. function EmptyStatement() {
  1335. this.type = syntax_1.Syntax.EmptyStatement;
  1336. }
  1337. return EmptyStatement;
  1338. }());
  1339. exports.EmptyStatement = EmptyStatement;
  1340. var ExportAllDeclaration = (function () {
  1341. function ExportAllDeclaration(source) {
  1342. this.type = syntax_1.Syntax.ExportAllDeclaration;
  1343. this.source = source;
  1344. }
  1345. return ExportAllDeclaration;
  1346. }());
  1347. exports.ExportAllDeclaration = ExportAllDeclaration;
  1348. var ExportDefaultDeclaration = (function () {
  1349. function ExportDefaultDeclaration(declaration) {
  1350. this.type = syntax_1.Syntax.ExportDefaultDeclaration;
  1351. this.declaration = declaration;
  1352. }
  1353. return ExportDefaultDeclaration;
  1354. }());
  1355. exports.ExportDefaultDeclaration = ExportDefaultDeclaration;
  1356. var ExportNamedDeclaration = (function () {
  1357. function ExportNamedDeclaration(declaration, specifiers, source) {
  1358. this.type = syntax_1.Syntax.ExportNamedDeclaration;
  1359. this.declaration = declaration;
  1360. this.specifiers = specifiers;
  1361. this.source = source;
  1362. }
  1363. return ExportNamedDeclaration;
  1364. }());
  1365. exports.ExportNamedDeclaration = ExportNamedDeclaration;
  1366. var ExportSpecifier = (function () {
  1367. function ExportSpecifier(local, exported) {
  1368. this.type = syntax_1.Syntax.ExportSpecifier;
  1369. this.exported = exported;
  1370. this.local = local;
  1371. }
  1372. return ExportSpecifier;
  1373. }());
  1374. exports.ExportSpecifier = ExportSpecifier;
  1375. var ExpressionStatement = (function () {
  1376. function ExpressionStatement(expression) {
  1377. this.type = syntax_1.Syntax.ExpressionStatement;
  1378. this.expression = expression;
  1379. }
  1380. return ExpressionStatement;
  1381. }());
  1382. exports.ExpressionStatement = ExpressionStatement;
  1383. var ForInStatement = (function () {
  1384. function ForInStatement(left, right, body) {
  1385. this.type = syntax_1.Syntax.ForInStatement;
  1386. this.left = left;
  1387. this.right = right;
  1388. this.body = body;
  1389. this.each = false;
  1390. }
  1391. return ForInStatement;
  1392. }());
  1393. exports.ForInStatement = ForInStatement;
  1394. var ForOfStatement = (function () {
  1395. function ForOfStatement(left, right, body) {
  1396. this.type = syntax_1.Syntax.ForOfStatement;
  1397. this.left = left;
  1398. this.right = right;
  1399. this.body = body;
  1400. }
  1401. return ForOfStatement;
  1402. }());
  1403. exports.ForOfStatement = ForOfStatement;
  1404. var ForStatement = (function () {
  1405. function ForStatement(init, test, update, body) {
  1406. this.type = syntax_1.Syntax.ForStatement;
  1407. this.init = init;
  1408. this.test = test;
  1409. this.update = update;
  1410. this.body = body;
  1411. }
  1412. return ForStatement;
  1413. }());
  1414. exports.ForStatement = ForStatement;
  1415. var FunctionDeclaration = (function () {
  1416. function FunctionDeclaration(id, params, body, generator) {
  1417. this.type = syntax_1.Syntax.FunctionDeclaration;
  1418. this.id = id;
  1419. this.params = params;
  1420. this.body = body;
  1421. this.generator = generator;
  1422. this.expression = false;
  1423. this.async = false;
  1424. }
  1425. return FunctionDeclaration;
  1426. }());
  1427. exports.FunctionDeclaration = FunctionDeclaration;
  1428. var FunctionExpression = (function () {
  1429. function FunctionExpression(id, params, body, generator) {
  1430. this.type = syntax_1.Syntax.FunctionExpression;
  1431. this.id = id;
  1432. this.params = params;
  1433. this.body = body;
  1434. this.generator = generator;
  1435. this.expression = false;
  1436. this.async = false;
  1437. }
  1438. return FunctionExpression;
  1439. }());
  1440. exports.FunctionExpression = FunctionExpression;
  1441. var Identifier = (function () {
  1442. function Identifier(name) {
  1443. this.type = syntax_1.Syntax.Identifier;
  1444. this.name = name;
  1445. }
  1446. return Identifier;
  1447. }());
  1448. exports.Identifier = Identifier;
  1449. var IfStatement = (function () {
  1450. function IfStatement(test, consequent, alternate) {
  1451. this.type = syntax_1.Syntax.IfStatement;
  1452. this.test = test;
  1453. this.consequent = consequent;
  1454. this.alternate = alternate;
  1455. }
  1456. return IfStatement;
  1457. }());
  1458. exports.IfStatement = IfStatement;
  1459. var ImportDeclaration = (function () {
  1460. function ImportDeclaration(specifiers, source) {
  1461. this.type = syntax_1.Syntax.ImportDeclaration;
  1462. this.specifiers = specifiers;
  1463. this.source = source;
  1464. }
  1465. return ImportDeclaration;
  1466. }());
  1467. exports.ImportDeclaration = ImportDeclaration;
  1468. var ImportDefaultSpecifier = (function () {
  1469. function ImportDefaultSpecifier(local) {
  1470. this.type = syntax_1.Syntax.ImportDefaultSpecifier;
  1471. this.local = local;
  1472. }
  1473. return ImportDefaultSpecifier;
  1474. }());
  1475. exports.ImportDefaultSpecifier = ImportDefaultSpecifier;
  1476. var ImportNamespaceSpecifier = (function () {
  1477. function ImportNamespaceSpecifier(local) {
  1478. this.type = syntax_1.Syntax.ImportNamespaceSpecifier;
  1479. this.local = local;
  1480. }
  1481. return ImportNamespaceSpecifier;
  1482. }());
  1483. exports.ImportNamespaceSpecifier = ImportNamespaceSpecifier;
  1484. var ImportSpecifier = (function () {
  1485. function ImportSpecifier(local, imported) {
  1486. this.type = syntax_1.Syntax.ImportSpecifier;
  1487. this.local = local;
  1488. this.imported = imported;
  1489. }
  1490. return ImportSpecifier;
  1491. }());
  1492. exports.ImportSpecifier = ImportSpecifier;
  1493. var LabeledStatement = (function () {
  1494. function LabeledStatement(label, body) {
  1495. this.type = syntax_1.Syntax.LabeledStatement;
  1496. this.label = label;
  1497. this.body = body;
  1498. }
  1499. return LabeledStatement;
  1500. }());
  1501. exports.LabeledStatement = LabeledStatement;
  1502. var Literal = (function () {
  1503. function Literal(value, raw) {
  1504. this.type = syntax_1.Syntax.Literal;
  1505. this.value = value;
  1506. this.raw = raw;
  1507. }
  1508. return Literal;
  1509. }());
  1510. exports.Literal = Literal;
  1511. var MetaProperty = (function () {
  1512. function MetaProperty(meta, property) {
  1513. this.type = syntax_1.Syntax.MetaProperty;
  1514. this.meta = meta;
  1515. this.property = property;
  1516. }
  1517. return MetaProperty;
  1518. }());
  1519. exports.MetaProperty = MetaProperty;
  1520. var MethodDefinition = (function () {
  1521. function MethodDefinition(key, computed, value, kind, isStatic) {
  1522. this.type = syntax_1.Syntax.MethodDefinition;
  1523. this.key = key;
  1524. this.computed = computed;
  1525. this.value = value;
  1526. this.kind = kind;
  1527. this.static = isStatic;
  1528. }
  1529. return MethodDefinition;
  1530. }());
  1531. exports.MethodDefinition = MethodDefinition;
  1532. var Module = (function () {
  1533. function Module(body) {
  1534. this.type = syntax_1.Syntax.Program;
  1535. this.body = body;
  1536. this.sourceType = 'module';
  1537. }
  1538. return Module;
  1539. }());
  1540. exports.Module = Module;
  1541. var NewExpression = (function () {
  1542. function NewExpression(callee, args) {
  1543. this.type = syntax_1.Syntax.NewExpression;
  1544. this.callee = callee;
  1545. this.arguments = args;
  1546. }
  1547. return NewExpression;
  1548. }());
  1549. exports.NewExpression = NewExpression;
  1550. var ObjectExpression = (function () {
  1551. function ObjectExpression(properties) {
  1552. this.type = syntax_1.Syntax.ObjectExpression;
  1553. this.properties = properties;
  1554. }
  1555. return ObjectExpression;
  1556. }());
  1557. exports.ObjectExpression = ObjectExpression;
  1558. var ObjectPattern = (function () {
  1559. function ObjectPattern(properties) {
  1560. this.type = syntax_1.Syntax.ObjectPattern;
  1561. this.properties = properties;
  1562. }
  1563. return ObjectPattern;
  1564. }());
  1565. exports.ObjectPattern = ObjectPattern;
  1566. var Property = (function () {
  1567. function Property(kind, key, computed, value, method, shorthand) {
  1568. this.type = syntax_1.Syntax.Property;
  1569. this.key = key;
  1570. this.computed = computed;
  1571. this.value = value;
  1572. this.kind = kind;
  1573. this.method = method;
  1574. this.shorthand = shorthand;
  1575. }
  1576. return Property;
  1577. }());
  1578. exports.Property = Property;
  1579. var RegexLiteral = (function () {
  1580. function RegexLiteral(value, raw, pattern, flags) {
  1581. this.type = syntax_1.Syntax.Literal;
  1582. this.value = value;
  1583. this.raw = raw;
  1584. this.regex = { pattern: pattern, flags: flags };
  1585. }
  1586. return RegexLiteral;
  1587. }());
  1588. exports.RegexLiteral = RegexLiteral;
  1589. var RestElement = (function () {
  1590. function RestElement(argument) {
  1591. this.type = syntax_1.Syntax.RestElement;
  1592. this.argument = argument;
  1593. }
  1594. return RestElement;
  1595. }());
  1596. exports.RestElement = RestElement;
  1597. var ReturnStatement = (function () {
  1598. function ReturnStatement(argument) {
  1599. this.type = syntax_1.Syntax.ReturnStatement;
  1600. this.argument = argument;
  1601. }
  1602. return ReturnStatement;
  1603. }());
  1604. exports.ReturnStatement = ReturnStatement;
  1605. var Script = (function () {
  1606. function Script(body) {
  1607. this.type = syntax_1.Syntax.Program;
  1608. this.body = body;
  1609. this.sourceType = 'script';
  1610. }
  1611. return Script;
  1612. }());
  1613. exports.Script = Script;
  1614. var SequenceExpression = (function () {
  1615. function SequenceExpression(expressions) {
  1616. this.type = syntax_1.Syntax.SequenceExpression;
  1617. this.expressions = expressions;
  1618. }
  1619. return SequenceExpression;
  1620. }());
  1621. exports.SequenceExpression = SequenceExpression;
  1622. var SpreadElement = (function () {
  1623. function SpreadElement(argument) {
  1624. this.type = syntax_1.Syntax.SpreadElement;
  1625. this.argument = argument;
  1626. }
  1627. return SpreadElement;
  1628. }());
  1629. exports.SpreadElement = SpreadElement;
  1630. var StaticMemberExpression = (function () {
  1631. function StaticMemberExpression(object, property) {
  1632. this.type = syntax_1.Syntax.MemberExpression;
  1633. this.computed = false;
  1634. this.object = object;
  1635. this.property = property;
  1636. }
  1637. return StaticMemberExpression;
  1638. }());
  1639. exports.StaticMemberExpression = StaticMemberExpression;
  1640. var Super = (function () {
  1641. function Super() {
  1642. this.type = syntax_1.Syntax.Super;
  1643. }
  1644. return Super;
  1645. }());
  1646. exports.Super = Super;
  1647. var SwitchCase = (function () {
  1648. function SwitchCase(test, consequent) {
  1649. this.type = syntax_1.Syntax.SwitchCase;
  1650. this.test = test;
  1651. this.consequent = consequent;
  1652. }
  1653. return SwitchCase;
  1654. }());
  1655. exports.SwitchCase = SwitchCase;
  1656. var SwitchStatement = (function () {
  1657. function SwitchStatement(discriminant, cases) {
  1658. this.type = syntax_1.Syntax.SwitchStatement;
  1659. this.discriminant = discriminant;
  1660. this.cases = cases;
  1661. }
  1662. return SwitchStatement;
  1663. }());
  1664. exports.SwitchStatement = SwitchStatement;
  1665. var TaggedTemplateExpression = (function () {
  1666. function TaggedTemplateExpression(tag, quasi) {
  1667. this.type = syntax_1.Syntax.TaggedTemplateExpression;
  1668. this.tag = tag;
  1669. this.quasi = quasi;
  1670. }
  1671. return TaggedTemplateExpression;
  1672. }());
  1673. exports.TaggedTemplateExpression = TaggedTemplateExpression;
  1674. var TemplateElement = (function () {
  1675. function TemplateElement(value, tail) {
  1676. this.type = syntax_1.Syntax.TemplateElement;
  1677. this.value = value;
  1678. this.tail = tail;
  1679. }
  1680. return TemplateElement;
  1681. }());
  1682. exports.TemplateElement = TemplateElement;
  1683. var TemplateLiteral = (function () {
  1684. function TemplateLiteral(quasis, expressions) {
  1685. this.type = syntax_1.Syntax.TemplateLiteral;
  1686. this.quasis = quasis;
  1687. this.expressions = expressions;
  1688. }
  1689. return TemplateLiteral;
  1690. }());
  1691. exports.TemplateLiteral = TemplateLiteral;
  1692. var ThisExpression = (function () {
  1693. function ThisExpression() {
  1694. this.type = syntax_1.Syntax.ThisExpression;
  1695. }
  1696. return ThisExpression;
  1697. }());
  1698. exports.ThisExpression = ThisExpression;
  1699. var ThrowStatement = (function () {
  1700. function ThrowStatement(argument) {
  1701. this.type = syntax_1.Syntax.ThrowStatement;
  1702. this.argument = argument;
  1703. }
  1704. return ThrowStatement;
  1705. }());
  1706. exports.ThrowStatement = ThrowStatement;
  1707. var TryStatement = (function () {
  1708. function TryStatement(block, handler, finalizer) {
  1709. this.type = syntax_1.Syntax.TryStatement;
  1710. this.block = block;
  1711. this.handler = handler;
  1712. this.finalizer = finalizer;
  1713. }
  1714. return TryStatement;
  1715. }());
  1716. exports.TryStatement = TryStatement;
  1717. var UnaryExpression = (function () {
  1718. function UnaryExpression(operator, argument) {
  1719. this.type = syntax_1.Syntax.UnaryExpression;
  1720. this.operator = operator;
  1721. this.argument = argument;
  1722. this.prefix = true;
  1723. }
  1724. return UnaryExpression;
  1725. }());
  1726. exports.UnaryExpression = UnaryExpression;
  1727. var UpdateExpression = (function () {
  1728. function UpdateExpression(operator, argument, prefix) {
  1729. this.type = syntax_1.Syntax.UpdateExpression;
  1730. this.operator = operator;
  1731. this.argument = argument;
  1732. this.prefix = prefix;
  1733. }
  1734. return UpdateExpression;
  1735. }());
  1736. exports.UpdateExpression = UpdateExpression;
  1737. var VariableDeclaration = (function () {
  1738. function VariableDeclaration(declarations, kind) {
  1739. this.type = syntax_1.Syntax.VariableDeclaration;
  1740. this.declarations = declarations;
  1741. this.kind = kind;
  1742. }
  1743. return VariableDeclaration;
  1744. }());
  1745. exports.VariableDeclaration = VariableDeclaration;
  1746. var VariableDeclarator = (function () {
  1747. function VariableDeclarator(id, init) {
  1748. this.type = syntax_1.Syntax.VariableDeclarator;
  1749. this.id = id;
  1750. this.init = init;
  1751. }
  1752. return VariableDeclarator;
  1753. }());
  1754. exports.VariableDeclarator = VariableDeclarator;
  1755. var WhileStatement = (function () {
  1756. function WhileStatement(test, body) {
  1757. this.type = syntax_1.Syntax.WhileStatement;
  1758. this.test = test;
  1759. this.body = body;
  1760. }
  1761. return WhileStatement;
  1762. }());
  1763. exports.WhileStatement = WhileStatement;
  1764. var WithStatement = (function () {
  1765. function WithStatement(object, body) {
  1766. this.type = syntax_1.Syntax.WithStatement;
  1767. this.object = object;
  1768. this.body = body;
  1769. }
  1770. return WithStatement;
  1771. }());
  1772. exports.WithStatement = WithStatement;
  1773. var YieldExpression = (function () {
  1774. function YieldExpression(argument, delegate) {
  1775. this.type = syntax_1.Syntax.YieldExpression;
  1776. this.argument = argument;
  1777. this.delegate = delegate;
  1778. }
  1779. return YieldExpression;
  1780. }());
  1781. exports.YieldExpression = YieldExpression;
  1782. /***/ },
  1783. /* 8 */
  1784. /***/ function(module, exports, __webpack_require__) {
  1785. "use strict";
  1786. Object.defineProperty(exports, "__esModule", { value: true });
  1787. var assert_1 = __webpack_require__(9);
  1788. var error_handler_1 = __webpack_require__(10);
  1789. var messages_1 = __webpack_require__(11);
  1790. var Node = __webpack_require__(7);
  1791. var scanner_1 = __webpack_require__(12);
  1792. var syntax_1 = __webpack_require__(2);
  1793. var token_1 = __webpack_require__(13);
  1794. var ArrowParameterPlaceHolder = 'ArrowParameterPlaceHolder';
  1795. var Parser = (function () {
  1796. function Parser(code, options, delegate) {
  1797. if (options === void 0) { options = {}; }
  1798. this.config = {
  1799. range: (typeof options.range === 'boolean') && options.range,
  1800. loc: (typeof options.loc === 'boolean') && options.loc,
  1801. source: null,
  1802. tokens: (typeof options.tokens === 'boolean') && options.tokens,
  1803. comment: (typeof options.comment === 'boolean') && options.comment,
  1804. tolerant: (typeof options.tolerant === 'boolean') && options.tolerant
  1805. };
  1806. if (this.config.loc && options.source && options.source !== null) {
  1807. this.config.source = String(options.source);
  1808. }
  1809. this.delegate = delegate;
  1810. this.errorHandler = new error_handler_1.ErrorHandler();
  1811. this.errorHandler.tolerant = this.config.tolerant;
  1812. this.scanner = new scanner_1.Scanner(code, this.errorHandler);
  1813. this.scanner.trackComment = this.config.comment;
  1814. this.operatorPrecedence = {
  1815. ')': 0,
  1816. ';': 0,
  1817. ',': 0,
  1818. '=': 0,
  1819. ']': 0,
  1820. '||': 1,
  1821. '&&': 2,
  1822. '|': 3,
  1823. '^': 4,
  1824. '&': 5,
  1825. '==': 6,
  1826. '!=': 6,
  1827. '===': 6,
  1828. '!==': 6,
  1829. '<': 7,
  1830. '>': 7,
  1831. '<=': 7,
  1832. '>=': 7,
  1833. '<<': 8,
  1834. '>>': 8,
  1835. '>>>': 8,
  1836. '+': 9,
  1837. '-': 9,
  1838. '*': 11,
  1839. '/': 11,
  1840. '%': 11
  1841. };
  1842. this.lookahead = {
  1843. type: 2 /* EOF */,
  1844. value: '',
  1845. lineNumber: this.scanner.lineNumber,
  1846. lineStart: 0,
  1847. start: 0,
  1848. end: 0
  1849. };
  1850. this.hasLineTerminator = false;
  1851. this.context = {
  1852. isModule: false,
  1853. await: false,
  1854. allowIn: true,
  1855. allowStrictDirective: true,
  1856. allowYield: true,
  1857. firstCoverInitializedNameError: null,
  1858. isAssignmentTarget: false,
  1859. isBindingElement: false,
  1860. inFunctionBody: false,
  1861. inIteration: false,
  1862. inSwitch: false,
  1863. labelSet: {},
  1864. strict: false
  1865. };
  1866. this.tokens = [];
  1867. this.startMarker = {
  1868. index: 0,
  1869. line: this.scanner.lineNumber,
  1870. column: 0
  1871. };
  1872. this.lastMarker = {
  1873. index: 0,
  1874. line: this.scanner.lineNumber,
  1875. column: 0
  1876. };
  1877. this.nextToken();
  1878. this.lastMarker = {
  1879. index: this.scanner.index,
  1880. line: this.scanner.lineNumber,
  1881. column: this.scanner.index - this.scanner.lineStart
  1882. };
  1883. }
  1884. Parser.prototype.throwError = function (messageFormat) {
  1885. var values = [];
  1886. for (var _i = 1; _i < arguments.length; _i++) {
  1887. values[_i - 1] = arguments[_i];
  1888. }
  1889. var args = Array.prototype.slice.call(arguments, 1);
  1890. var msg = messageFormat.replace(/%(\d)/g, function (whole, idx) {
  1891. assert_1.assert(idx < args.length, 'Message reference must be in range');
  1892. return args[idx];
  1893. });
  1894. var index = this.lastMarker.index;
  1895. var line = this.lastMarker.line;
  1896. var column = this.lastMarker.column + 1;
  1897. throw this.errorHandler.createError(index, line, column, msg);
  1898. };
  1899. Parser.prototype.tolerateError = function (messageFormat) {
  1900. var values = [];
  1901. for (var _i = 1; _i < arguments.length; _i++) {
  1902. values[_i - 1] = arguments[_i];
  1903. }
  1904. var args = Array.prototype.slice.call(arguments, 1);
  1905. var msg = messageFormat.replace(/%(\d)/g, function (whole, idx) {
  1906. assert_1.assert(idx < args.length, 'Message reference must be in range');
  1907. return args[idx];
  1908. });
  1909. var index = this.lastMarker.index;
  1910. var line = this.scanner.lineNumber;
  1911. var column = this.lastMarker.column + 1;
  1912. this.errorHandler.tolerateError(index, line, column, msg);
  1913. };
  1914. // Throw an exception because of the token.
  1915. Parser.prototype.unexpectedTokenError = function (token, message) {
  1916. var msg = message || messages_1.Messages.UnexpectedToken;
  1917. var value;
  1918. if (token) {
  1919. if (!message) {
  1920. msg = (token.type === 2 /* EOF */) ? messages_1.Messages.UnexpectedEOS :
  1921. (token.type === 3 /* Identifier */) ? messages_1.Messages.UnexpectedIdentifier :
  1922. (token.type === 6 /* NumericLiteral */) ? messages_1.Messages.UnexpectedNumber :
  1923. (token.type === 8 /* StringLiteral */) ? messages_1.Messages.UnexpectedString :
  1924. (token.type === 10 /* Template */) ? messages_1.Messages.UnexpectedTemplate :
  1925. messages_1.Messages.UnexpectedToken;
  1926. if (token.type === 4 /* Keyword */) {
  1927. if (this.scanner.isFutureReservedWord(token.value)) {
  1928. msg = messages_1.Messages.UnexpectedReserved;
  1929. }
  1930. else if (this.context.strict && this.scanner.isStrictModeReservedWord(token.value)) {
  1931. msg = messages_1.Messages.StrictReservedWord;
  1932. }
  1933. }
  1934. }
  1935. value = token.value;
  1936. }
  1937. else {
  1938. value = 'ILLEGAL';
  1939. }
  1940. msg = msg.replace('%0', value);
  1941. if (token && typeof token.lineNumber === 'number') {
  1942. var index = token.start;
  1943. var line = token.lineNumber;
  1944. var lastMarkerLineStart = this.lastMarker.index - this.lastMarker.column;
  1945. var column = token.start - lastMarkerLineStart + 1;
  1946. return this.errorHandler.createError(index, line, column, msg);
  1947. }
  1948. else {
  1949. var index = this.lastMarker.index;
  1950. var line = this.lastMarker.line;
  1951. var column = this.lastMarker.column + 1;
  1952. return this.errorHandler.createError(index, line, column, msg);
  1953. }
  1954. };
  1955. Parser.prototype.throwUnexpectedToken = function (token, message) {
  1956. throw this.unexpectedTokenError(token, message);
  1957. };
  1958. Parser.prototype.tolerateUnexpectedToken = function (token, message) {
  1959. this.errorHandler.tolerate(this.unexpectedTokenError(token, message));
  1960. };
  1961. Parser.prototype.collectComments = function () {
  1962. if (!this.config.comment) {
  1963. this.scanner.scanComments();
  1964. }
  1965. else {
  1966. var comments = this.scanner.scanComments();
  1967. if (comments.length > 0 && this.delegate) {
  1968. for (var i = 0; i < comments.length; ++i) {
  1969. var e = comments[i];
  1970. var node = void 0;
  1971. node = {
  1972. type: e.multiLine ? 'BlockComment' : 'LineComment',
  1973. value: this.scanner.source.slice(e.slice[0], e.slice[1])
  1974. };
  1975. if (this.config.range) {
  1976. node.range = e.range;
  1977. }
  1978. if (this.config.loc) {
  1979. node.loc = e.loc;
  1980. }
  1981. var metadata = {
  1982. start: {
  1983. line: e.loc.start.line,
  1984. column: e.loc.start.column,
  1985. offset: e.range[0]
  1986. },
  1987. end: {
  1988. line: e.loc.end.line,
  1989. column: e.loc.end.column,
  1990. offset: e.range[1]
  1991. }
  1992. };
  1993. this.delegate(node, metadata);
  1994. }
  1995. }
  1996. }
  1997. };
  1998. // From internal representation to an external structure
  1999. Parser.prototype.getTokenRaw = function (token) {
  2000. return this.scanner.source.slice(token.start, token.end);
  2001. };
  2002. Parser.prototype.convertToken = function (token) {
  2003. var t = {
  2004. type: token_1.TokenName[token.type],
  2005. value: this.getTokenRaw(token)
  2006. };
  2007. if (this.config.range) {
  2008. t.range = [token.start, token.end];
  2009. }
  2010. if (this.config.loc) {
  2011. t.loc = {
  2012. start: {
  2013. line: this.startMarker.line,
  2014. column: this.startMarker.column
  2015. },
  2016. end: {
  2017. line: this.scanner.lineNumber,
  2018. column: this.scanner.index - this.scanner.lineStart
  2019. }
  2020. };
  2021. }
  2022. if (token.type === 9 /* RegularExpression */) {
  2023. var pattern = token.pattern;
  2024. var flags = token.flags;
  2025. t.regex = { pattern: pattern, flags: flags };
  2026. }
  2027. return t;
  2028. };
  2029. Parser.prototype.nextToken = function () {
  2030. var token = this.lookahead;
  2031. this.lastMarker.index = this.scanner.index;
  2032. this.lastMarker.line = this.scanner.lineNumber;
  2033. this.lastMarker.column = this.scanner.index - this.scanner.lineStart;
  2034. this.collectComments();
  2035. if (this.scanner.index !== this.startMarker.index) {
  2036. this.startMarker.index = this.scanner.index;
  2037. this.startMarker.line = this.scanner.lineNumber;
  2038. this.startMarker.column = this.scanner.index - this.scanner.lineStart;
  2039. }
  2040. var next = this.scanner.lex();
  2041. this.hasLineTerminator = (token.lineNumber !== next.lineNumber);
  2042. if (next && this.context.strict && next.type === 3 /* Identifier */) {
  2043. if (this.scanner.isStrictModeReservedWord(next.value)) {
  2044. next.type = 4 /* Keyword */;
  2045. }
  2046. }
  2047. this.lookahead = next;
  2048. if (this.config.tokens && next.type !== 2 /* EOF */) {
  2049. this.tokens.push(this.convertToken(next));
  2050. }
  2051. return token;
  2052. };
  2053. Parser.prototype.nextRegexToken = function () {
  2054. this.collectComments();
  2055. var token = this.scanner.scanRegExp();
  2056. if (this.config.tokens) {
  2057. // Pop the previous token, '/' or '/='
  2058. // This is added from the lookahead token.
  2059. this.tokens.pop();
  2060. this.tokens.push(this.convertToken(token));
  2061. }
  2062. // Prime the next lookahead.
  2063. this.lookahead = token;
  2064. this.nextToken();
  2065. return token;
  2066. };
  2067. Parser.prototype.createNode = function () {
  2068. return {
  2069. index: this.startMarker.index,
  2070. line: this.startMarker.line,
  2071. column: this.startMarker.column
  2072. };
  2073. };
  2074. Parser.prototype.startNode = function (token, lastLineStart) {
  2075. if (lastLineStart === void 0) { lastLineStart = 0; }
  2076. var column = token.start - token.lineStart;
  2077. var line = token.lineNumber;
  2078. if (column < 0) {
  2079. column += lastLineStart;
  2080. line--;
  2081. }
  2082. return {
  2083. index: token.start,
  2084. line: line,
  2085. column: column
  2086. };
  2087. };
  2088. Parser.prototype.finalize = function (marker, node) {
  2089. if (this.config.range) {
  2090. node.range = [marker.index, this.lastMarker.index];
  2091. }
  2092. if (this.config.loc) {
  2093. node.loc = {
  2094. start: {
  2095. line: marker.line,
  2096. column: marker.column,
  2097. },
  2098. end: {
  2099. line: this.lastMarker.line,
  2100. column: this.lastMarker.column
  2101. }
  2102. };
  2103. if (this.config.source) {
  2104. node.loc.source = this.config.source;
  2105. }
  2106. }
  2107. if (this.delegate) {
  2108. var metadata = {
  2109. start: {
  2110. line: marker.line,
  2111. column: marker.column,
  2112. offset: marker.index
  2113. },
  2114. end: {
  2115. line: this.lastMarker.line,
  2116. column: this.lastMarker.column,
  2117. offset: this.lastMarker.index
  2118. }
  2119. };
  2120. this.delegate(node, metadata);
  2121. }
  2122. return node;
  2123. };
  2124. // Expect the next token to match the specified punctuator.
  2125. // If not, an exception will be thrown.
  2126. Parser.prototype.expect = function (value) {
  2127. var token = this.nextToken();
  2128. if (token.type !== 7 /* Punctuator */ || token.value !== value) {
  2129. this.throwUnexpectedToken(token);
  2130. }
  2131. };
  2132. // Quietly expect a comma when in tolerant mode, otherwise delegates to expect().
  2133. Parser.prototype.expectCommaSeparator = function () {
  2134. if (this.config.tolerant) {
  2135. var token = this.lookahead;
  2136. if (token.type === 7 /* Punctuator */ && token.value === ',') {
  2137. this.nextToken();
  2138. }
  2139. else if (token.type === 7 /* Punctuator */ && token.value === ';') {
  2140. this.nextToken();
  2141. this.tolerateUnexpectedToken(token);
  2142. }
  2143. else {
  2144. this.tolerateUnexpectedToken(token, messages_1.Messages.UnexpectedToken);
  2145. }
  2146. }
  2147. else {
  2148. this.expect(',');
  2149. }
  2150. };
  2151. // Expect the next token to match the specified keyword.
  2152. // If not, an exception will be thrown.
  2153. Parser.prototype.expectKeyword = function (keyword) {
  2154. var token = this.nextToken();
  2155. if (token.type !== 4 /* Keyword */ || token.value !== keyword) {
  2156. this.throwUnexpectedToken(token);
  2157. }
  2158. };
  2159. // Return true if the next token matches the specified punctuator.
  2160. Parser.prototype.match = function (value) {
  2161. return this.lookahead.type === 7 /* Punctuator */ && this.lookahead.value === value;
  2162. };
  2163. // Return true if the next token matches the specified keyword
  2164. Parser.prototype.matchKeyword = function (keyword) {
  2165. return this.lookahead.type === 4 /* Keyword */ && this.lookahead.value === keyword;
  2166. };
  2167. // Return true if the next token matches the specified contextual keyword
  2168. // (where an identifier is sometimes a keyword depending on the context)
  2169. Parser.prototype.matchContextualKeyword = function (keyword) {
  2170. return this.lookahead.type === 3 /* Identifier */ && this.lookahead.value === keyword;
  2171. };
  2172. // Return true if the next token is an assignment operator
  2173. Parser.prototype.matchAssign = function () {
  2174. if (this.lookahead.type !== 7 /* Punctuator */) {
  2175. return false;
  2176. }
  2177. var op = this.lookahead.value;
  2178. return op === '=' ||
  2179. op === '*=' ||
  2180. op === '**=' ||
  2181. op === '/=' ||
  2182. op === '%=' ||
  2183. op === '+=' ||
  2184. op === '-=' ||
  2185. op === '<<=' ||
  2186. op === '>>=' ||
  2187. op === '>>>=' ||
  2188. op === '&=' ||
  2189. op === '^=' ||
  2190. op === '|=';
  2191. };
  2192. // Cover grammar support.
  2193. //
  2194. // When an assignment expression position starts with an left parenthesis, the determination of the type
  2195. // of the syntax is to be deferred arbitrarily long until the end of the parentheses pair (plus a lookahead)
  2196. // or the first comma. This situation also defers the determination of all the expressions nested in the pair.
  2197. //
  2198. // There are three productions that can be parsed in a parentheses pair that needs to be determined
  2199. // after the outermost pair is closed. They are:
  2200. //
  2201. // 1. AssignmentExpression
  2202. // 2. BindingElements
  2203. // 3. AssignmentTargets
  2204. //
  2205. // In order to avoid exponential backtracking, we use two flags to denote if the production can be
  2206. // binding element or assignment target.
  2207. //
  2208. // The three productions have the relationship:
  2209. //
  2210. // BindingElements ⊆ AssignmentTargets ⊆ AssignmentExpression
  2211. //
  2212. // with a single exception that CoverInitializedName when used directly in an Expression, generates
  2213. // an early error. Therefore, we need the third state, firstCoverInitializedNameError, to track the
  2214. // first usage of CoverInitializedName and report it when we reached the end of the parentheses pair.
  2215. //
  2216. // isolateCoverGrammar function runs the given parser function with a new cover grammar context, and it does not
  2217. // effect the current flags. This means the production the parser parses is only used as an expression. Therefore
  2218. // the CoverInitializedName check is conducted.
  2219. //
  2220. // inheritCoverGrammar function runs the given parse function with a new cover grammar context, and it propagates
  2221. // the flags outside of the parser. This means the production the parser parses is used as a part of a potential
  2222. // pattern. The CoverInitializedName check is deferred.
  2223. Parser.prototype.isolateCoverGrammar = function (parseFunction) {
  2224. var previousIsBindingElement = this.context.isBindingElement;
  2225. var previousIsAssignmentTarget = this.context.isAssignmentTarget;
  2226. var previousFirstCoverInitializedNameError = this.context.firstCoverInitializedNameError;
  2227. this.context.isBindingElement = true;
  2228. this.context.isAssignmentTarget = true;
  2229. this.context.firstCoverInitializedNameError = null;
  2230. var result = parseFunction.call(this);
  2231. if (this.context.firstCoverInitializedNameError !== null) {
  2232. this.throwUnexpectedToken(this.context.firstCoverInitializedNameError);
  2233. }
  2234. this.context.isBindingElement = previousIsBindingElement;
  2235. this.context.isAssignmentTarget = previousIsAssignmentTarget;
  2236. this.context.firstCoverInitializedNameError = previousFirstCoverInitializedNameError;
  2237. return result;
  2238. };
  2239. Parser.prototype.inheritCoverGrammar = function (parseFunction) {
  2240. var previousIsBindingElement = this.context.isBindingElement;
  2241. var previousIsAssignmentTarget = this.context.isAssignmentTarget;
  2242. var previousFirstCoverInitializedNameError = this.context.firstCoverInitializedNameError;
  2243. this.context.isBindingElement = true;
  2244. this.context.isAssignmentTarget = true;
  2245. this.context.firstCoverInitializedNameError = null;
  2246. var result = parseFunction.call(this);
  2247. this.context.isBindingElement = this.context.isBindingElement && previousIsBindingElement;
  2248. this.context.isAssignmentTarget = this.context.isAssignmentTarget && previousIsAssignmentTarget;
  2249. this.context.firstCoverInitializedNameError = previousFirstCoverInitializedNameError || this.context.firstCoverInitializedNameError;
  2250. return result;
  2251. };
  2252. Parser.prototype.consumeSemicolon = function () {
  2253. if (this.match(';')) {
  2254. this.nextToken();
  2255. }
  2256. else if (!this.hasLineTerminator) {
  2257. if (this.lookahead.type !== 2 /* EOF */ && !this.match('}')) {
  2258. this.throwUnexpectedToken(this.lookahead);
  2259. }
  2260. this.lastMarker.index = this.startMarker.index;
  2261. this.lastMarker.line = this.startMarker.line;
  2262. this.lastMarker.column = this.startMarker.column;
  2263. }
  2264. };
  2265. // https://tc39.github.io/ecma262/#sec-primary-expression
  2266. Parser.prototype.parsePrimaryExpression = function () {
  2267. var node = this.createNode();
  2268. var expr;
  2269. var token, raw;
  2270. switch (this.lookahead.type) {
  2271. case 3 /* Identifier */:
  2272. if ((this.context.isModule || this.context.await) && this.lookahead.value === 'await') {
  2273. this.tolerateUnexpectedToken(this.lookahead);
  2274. }
  2275. expr = this.matchAsyncFunction() ? this.parseFunctionExpression() : this.finalize(node, new Node.Identifier(this.nextToken().value));
  2276. break;
  2277. case 6 /* NumericLiteral */:
  2278. case 8 /* StringLiteral */:
  2279. if (this.context.strict && this.lookahead.octal) {
  2280. this.tolerateUnexpectedToken(this.lookahead, messages_1.Messages.StrictOctalLiteral);
  2281. }
  2282. this.context.isAssignmentTarget = false;
  2283. this.context.isBindingElement = false;
  2284. token = this.nextToken();
  2285. raw = this.getTokenRaw(token);
  2286. expr = this.finalize(node, new Node.Literal(token.value, raw));
  2287. break;
  2288. case 1 /* BooleanLiteral */:
  2289. this.context.isAssignmentTarget = false;
  2290. this.context.isBindingElement = false;
  2291. token = this.nextToken();
  2292. raw = this.getTokenRaw(token);
  2293. expr = this.finalize(node, new Node.Literal(token.value === 'true', raw));
  2294. break;
  2295. case 5 /* NullLiteral */:
  2296. this.context.isAssignmentTarget = false;
  2297. this.context.isBindingElement = false;
  2298. token = this.nextToken();
  2299. raw = this.getTokenRaw(token);
  2300. expr = this.finalize(node, new Node.Literal(null, raw));
  2301. break;
  2302. case 10 /* Template */:
  2303. expr = this.parseTemplateLiteral();
  2304. break;
  2305. case 7 /* Punctuator */:
  2306. switch (this.lookahead.value) {
  2307. case '(':
  2308. this.context.isBindingElement = false;
  2309. expr = this.inheritCoverGrammar(this.parseGroupExpression);
  2310. break;
  2311. case '[':
  2312. expr = this.inheritCoverGrammar(this.parseArrayInitializer);
  2313. break;
  2314. case '{':
  2315. expr = this.inheritCoverGrammar(this.parseObjectInitializer);
  2316. break;
  2317. case '/':
  2318. case '/=':
  2319. this.context.isAssignmentTarget = false;
  2320. this.context.isBindingElement = false;
  2321. this.scanner.index = this.startMarker.index;
  2322. token = this.nextRegexToken();
  2323. raw = this.getTokenRaw(token);
  2324. expr = this.finalize(node, new Node.RegexLiteral(token.regex, raw, token.pattern, token.flags));
  2325. break;
  2326. default:
  2327. expr = this.throwUnexpectedToken(this.nextToken());
  2328. }
  2329. break;
  2330. case 4 /* Keyword */:
  2331. if (!this.context.strict && this.context.allowYield && this.matchKeyword('yield')) {
  2332. expr = this.parseIdentifierName();
  2333. }
  2334. else if (!this.context.strict && this.matchKeyword('let')) {
  2335. expr = this.finalize(node, new Node.Identifier(this.nextToken().value));
  2336. }
  2337. else {
  2338. this.context.isAssignmentTarget = false;
  2339. this.context.isBindingElement = false;
  2340. if (this.matchKeyword('function')) {
  2341. expr = this.parseFunctionExpression();
  2342. }
  2343. else if (this.matchKeyword('this')) {
  2344. this.nextToken();
  2345. expr = this.finalize(node, new Node.ThisExpression());
  2346. }
  2347. else if (this.matchKeyword('class')) {
  2348. expr = this.parseClassExpression();
  2349. }
  2350. else {
  2351. expr = this.throwUnexpectedToken(this.nextToken());
  2352. }
  2353. }
  2354. break;
  2355. default:
  2356. expr = this.throwUnexpectedToken(this.nextToken());
  2357. }
  2358. return expr;
  2359. };
  2360. // https://tc39.github.io/ecma262/#sec-array-initializer
  2361. Parser.prototype.parseSpreadElement = function () {
  2362. var node = this.createNode();
  2363. this.expect('...');
  2364. var arg = this.inheritCoverGrammar(this.parseAssignmentExpression);
  2365. return this.finalize(node, new Node.SpreadElement(arg));
  2366. };
  2367. Parser.prototype.parseArrayInitializer = function () {
  2368. var node = this.createNode();
  2369. var elements = [];
  2370. this.expect('[');
  2371. while (!this.match(']')) {
  2372. if (this.match(',')) {
  2373. this.nextToken();
  2374. elements.push(null);
  2375. }
  2376. else if (this.match('...')) {
  2377. var element = this.parseSpreadElement();
  2378. if (!this.match(']')) {
  2379. this.context.isAssignmentTarget = false;
  2380. this.context.isBindingElement = false;
  2381. this.expect(',');
  2382. }
  2383. elements.push(element);
  2384. }
  2385. else {
  2386. elements.push(this.inheritCoverGrammar(this.parseAssignmentExpression));
  2387. if (!this.match(']')) {
  2388. this.expect(',');
  2389. }
  2390. }
  2391. }
  2392. this.expect(']');
  2393. return this.finalize(node, new Node.ArrayExpression(elements));
  2394. };
  2395. // https://tc39.github.io/ecma262/#sec-object-initializer
  2396. Parser.prototype.parsePropertyMethod = function (params) {
  2397. this.context.isAssignmentTarget = false;
  2398. this.context.isBindingElement = false;
  2399. var previousStrict = this.context.strict;
  2400. var previousAllowStrictDirective = this.context.allowStrictDirective;
  2401. this.context.allowStrictDirective = params.simple;
  2402. var body = this.isolateCoverGrammar(this.parseFunctionSourceElements);
  2403. if (this.context.strict && params.firstRestricted) {
  2404. this.tolerateUnexpectedToken(params.firstRestricted, params.message);
  2405. }
  2406. if (this.context.strict && params.stricted) {
  2407. this.tolerateUnexpectedToken(params.stricted, params.message);
  2408. }
  2409. this.context.strict = previousStrict;
  2410. this.context.allowStrictDirective = previousAllowStrictDirective;
  2411. return body;
  2412. };
  2413. Parser.prototype.parsePropertyMethodFunction = function () {
  2414. var isGenerator = false;
  2415. var node = this.createNode();
  2416. var previousAllowYield = this.context.allowYield;
  2417. this.context.allowYield = true;
  2418. var params = this.parseFormalParameters();
  2419. var method = this.parsePropertyMethod(params);
  2420. this.context.allowYield = previousAllowYield;
  2421. return this.finalize(node, new Node.FunctionExpression(null, params.params, method, isGenerator));
  2422. };
  2423. Parser.prototype.parsePropertyMethodAsyncFunction = function () {
  2424. var node = this.createNode();
  2425. var previousAllowYield = this.context.allowYield;
  2426. var previousAwait = this.context.await;
  2427. this.context.allowYield = false;
  2428. this.context.await = true;
  2429. var params = this.parseFormalParameters();
  2430. var method = this.parsePropertyMethod(params);
  2431. this.context.allowYield = previousAllowYield;
  2432. this.context.await = previousAwait;
  2433. return this.finalize(node, new Node.AsyncFunctionExpression(null, params.params, method));
  2434. };
  2435. Parser.prototype.parseObjectPropertyKey = function () {
  2436. var node = this.createNode();
  2437. var token = this.nextToken();
  2438. var key;
  2439. switch (token.type) {
  2440. case 8 /* StringLiteral */:
  2441. case 6 /* NumericLiteral */:
  2442. if (this.context.strict && token.octal) {
  2443. this.tolerateUnexpectedToken(token, messages_1.Messages.StrictOctalLiteral);
  2444. }
  2445. var raw = this.getTokenRaw(token);
  2446. key = this.finalize(node, new Node.Literal(token.value, raw));
  2447. break;
  2448. case 3 /* Identifier */:
  2449. case 1 /* BooleanLiteral */:
  2450. case 5 /* NullLiteral */:
  2451. case 4 /* Keyword */:
  2452. key = this.finalize(node, new Node.Identifier(token.value));
  2453. break;
  2454. case 7 /* Punctuator */:
  2455. if (token.value === '[') {
  2456. key = this.isolateCoverGrammar(this.parseAssignmentExpression);
  2457. this.expect(']');
  2458. }
  2459. else {
  2460. key = this.throwUnexpectedToken(token);
  2461. }
  2462. break;
  2463. default:
  2464. key = this.throwUnexpectedToken(token);
  2465. }
  2466. return key;
  2467. };
  2468. Parser.prototype.isPropertyKey = function (key, value) {
  2469. return (key.type === syntax_1.Syntax.Identifier && key.name === value) ||
  2470. (key.type === syntax_1.Syntax.Literal && key.value === value);
  2471. };
  2472. Parser.prototype.parseObjectProperty = function (hasProto) {
  2473. var node = this.createNode();
  2474. var token = this.lookahead;
  2475. var kind;
  2476. var key = null;
  2477. var value = null;
  2478. var computed = false;
  2479. var method = false;
  2480. var shorthand = false;
  2481. var isAsync = false;
  2482. if (token.type === 3 /* Identifier */) {
  2483. var id = token.value;
  2484. this.nextToken();
  2485. computed = this.match('[');
  2486. isAsync = !this.hasLineTerminator && (id === 'async') &&
  2487. !this.match(':') && !this.match('(') && !this.match('*') && !this.match(',');
  2488. key = isAsync ? this.parseObjectPropertyKey() : this.finalize(node, new Node.Identifier(id));
  2489. }
  2490. else if (this.match('*')) {
  2491. this.nextToken();
  2492. }
  2493. else {
  2494. computed = this.match('[');
  2495. key = this.parseObjectPropertyKey();
  2496. }
  2497. var lookaheadPropertyKey = this.qualifiedPropertyName(this.lookahead);
  2498. if (token.type === 3 /* Identifier */ && !isAsync && token.value === 'get' && lookaheadPropertyKey) {
  2499. kind = 'get';
  2500. computed = this.match('[');
  2501. key = this.parseObjectPropertyKey();
  2502. this.context.allowYield = false;
  2503. value = this.parseGetterMethod();
  2504. }
  2505. else if (token.type === 3 /* Identifier */ && !isAsync && token.value === 'set' && lookaheadPropertyKey) {
  2506. kind = 'set';
  2507. computed = this.match('[');
  2508. key = this.parseObjectPropertyKey();
  2509. value = this.parseSetterMethod();
  2510. }
  2511. else if (token.type === 7 /* Punctuator */ && token.value === '*' && lookaheadPropertyKey) {
  2512. kind = 'init';
  2513. computed = this.match('[');
  2514. key = this.parseObjectPropertyKey();
  2515. value = this.parseGeneratorMethod();
  2516. method = true;
  2517. }
  2518. else {
  2519. if (!key) {
  2520. this.throwUnexpectedToken(this.lookahead);
  2521. }
  2522. kind = 'init';
  2523. if (this.match(':') && !isAsync) {
  2524. if (!computed && this.isPropertyKey(key, '__proto__')) {
  2525. if (hasProto.value) {
  2526. this.tolerateError(messages_1.Messages.DuplicateProtoProperty);
  2527. }
  2528. hasProto.value = true;
  2529. }
  2530. this.nextToken();
  2531. value = this.inheritCoverGrammar(this.parseAssignmentExpression);
  2532. }
  2533. else if (this.match('(')) {
  2534. value = isAsync ? this.parsePropertyMethodAsyncFunction() : this.parsePropertyMethodFunction();
  2535. method = true;
  2536. }
  2537. else if (token.type === 3 /* Identifier */) {
  2538. var id = this.finalize(node, new Node.Identifier(token.value));
  2539. if (this.match('=')) {
  2540. this.context.firstCoverInitializedNameError = this.lookahead;
  2541. this.nextToken();
  2542. shorthand = true;
  2543. var init = this.isolateCoverGrammar(this.parseAssignmentExpression);
  2544. value = this.finalize(node, new Node.AssignmentPattern(id, init));
  2545. }
  2546. else {
  2547. shorthand = true;
  2548. value = id;
  2549. }
  2550. }
  2551. else {
  2552. this.throwUnexpectedToken(this.nextToken());
  2553. }
  2554. }
  2555. return this.finalize(node, new Node.Property(kind, key, computed, value, method, shorthand));
  2556. };
  2557. Parser.prototype.parseObjectInitializer = function () {
  2558. var node = this.createNode();
  2559. this.expect('{');
  2560. var properties = [];
  2561. var hasProto = { value: false };
  2562. while (!this.match('}')) {
  2563. properties.push(this.parseObjectProperty(hasProto));
  2564. if (!this.match('}')) {
  2565. this.expectCommaSeparator();
  2566. }
  2567. }
  2568. this.expect('}');
  2569. return this.finalize(node, new Node.ObjectExpression(properties));
  2570. };
  2571. // https://tc39.github.io/ecma262/#sec-template-literals
  2572. Parser.prototype.parseTemplateHead = function () {
  2573. assert_1.assert(this.lookahead.head, 'Template literal must start with a template head');
  2574. var node = this.createNode();
  2575. var token = this.nextToken();
  2576. var raw = token.value;
  2577. var cooked = token.cooked;
  2578. return this.finalize(node, new Node.TemplateElement({ raw: raw, cooked: cooked }, token.tail));
  2579. };
  2580. Parser.prototype.parseTemplateElement = function () {
  2581. if (this.lookahead.type !== 10 /* Template */) {
  2582. this.throwUnexpectedToken();
  2583. }
  2584. var node = this.createNode();
  2585. var token = this.nextToken();
  2586. var raw = token.value;
  2587. var cooked = token.cooked;
  2588. return this.finalize(node, new Node.TemplateElement({ raw: raw, cooked: cooked }, token.tail));
  2589. };
  2590. Parser.prototype.parseTemplateLiteral = function () {
  2591. var node = this.createNode();
  2592. var expressions = [];
  2593. var quasis = [];
  2594. var quasi = this.parseTemplateHead();
  2595. quasis.push(quasi);
  2596. while (!quasi.tail) {
  2597. expressions.push(this.parseExpression());
  2598. quasi = this.parseTemplateElement();
  2599. quasis.push(quasi);
  2600. }
  2601. return this.finalize(node, new Node.TemplateLiteral(quasis, expressions));
  2602. };
  2603. // https://tc39.github.io/ecma262/#sec-grouping-operator
  2604. Parser.prototype.reinterpretExpressionAsPattern = function (expr) {
  2605. switch (expr.type) {
  2606. case syntax_1.Syntax.Identifier:
  2607. case syntax_1.Syntax.MemberExpression:
  2608. case syntax_1.Syntax.RestElement:
  2609. case syntax_1.Syntax.AssignmentPattern:
  2610. break;
  2611. case syntax_1.Syntax.SpreadElement:
  2612. expr.type = syntax_1.Syntax.RestElement;
  2613. this.reinterpretExpressionAsPattern(expr.argument);
  2614. break;
  2615. case syntax_1.Syntax.ArrayExpression:
  2616. expr.type = syntax_1.Syntax.ArrayPattern;
  2617. for (var i = 0; i < expr.elements.length; i++) {
  2618. if (expr.elements[i] !== null) {
  2619. this.reinterpretExpressionAsPattern(expr.elements[i]);
  2620. }
  2621. }
  2622. break;
  2623. case syntax_1.Syntax.ObjectExpression:
  2624. expr.type = syntax_1.Syntax.ObjectPattern;
  2625. for (var i = 0; i < expr.properties.length; i++) {
  2626. this.reinterpretExpressionAsPattern(expr.properties[i].value);
  2627. }
  2628. break;
  2629. case syntax_1.Syntax.AssignmentExpression:
  2630. expr.type = syntax_1.Syntax.AssignmentPattern;
  2631. delete expr.operator;
  2632. this.reinterpretExpressionAsPattern(expr.left);
  2633. break;
  2634. default:
  2635. // Allow other node type for tolerant parsing.
  2636. break;
  2637. }
  2638. };
  2639. Parser.prototype.parseGroupExpression = function () {
  2640. var expr;
  2641. this.expect('(');
  2642. if (this.match(')')) {
  2643. this.nextToken();
  2644. if (!this.match('=>')) {
  2645. this.expect('=>');
  2646. }
  2647. expr = {
  2648. type: ArrowParameterPlaceHolder,
  2649. params: [],
  2650. async: false
  2651. };
  2652. }
  2653. else {
  2654. var startToken = this.lookahead;
  2655. var params = [];
  2656. if (this.match('...')) {
  2657. expr = this.parseRestElement(params);
  2658. this.expect(')');
  2659. if (!this.match('=>')) {
  2660. this.expect('=>');
  2661. }
  2662. expr = {
  2663. type: ArrowParameterPlaceHolder,
  2664. params: [expr],
  2665. async: false
  2666. };
  2667. }
  2668. else {
  2669. var arrow = false;
  2670. this.context.isBindingElement = true;
  2671. expr = this.inheritCoverGrammar(this.parseAssignmentExpression);
  2672. if (this.match(',')) {
  2673. var expressions = [];
  2674. this.context.isAssignmentTarget = false;
  2675. expressions.push(expr);
  2676. while (this.lookahead.type !== 2 /* EOF */) {
  2677. if (!this.match(',')) {
  2678. break;
  2679. }
  2680. this.nextToken();
  2681. if (this.match(')')) {
  2682. this.nextToken();
  2683. for (var i = 0; i < expressions.length; i++) {
  2684. this.reinterpretExpressionAsPattern(expressions[i]);
  2685. }
  2686. arrow = true;
  2687. expr = {
  2688. type: ArrowParameterPlaceHolder,
  2689. params: expressions,
  2690. async: false
  2691. };
  2692. }
  2693. else if (this.match('...')) {
  2694. if (!this.context.isBindingElement) {
  2695. this.throwUnexpectedToken(this.lookahead);
  2696. }
  2697. expressions.push(this.parseRestElement(params));
  2698. this.expect(')');
  2699. if (!this.match('=>')) {
  2700. this.expect('=>');
  2701. }
  2702. this.context.isBindingElement = false;
  2703. for (var i = 0; i < expressions.length; i++) {
  2704. this.reinterpretExpressionAsPattern(expressions[i]);
  2705. }
  2706. arrow = true;
  2707. expr = {
  2708. type: ArrowParameterPlaceHolder,
  2709. params: expressions,
  2710. async: false
  2711. };
  2712. }
  2713. else {
  2714. expressions.push(this.inheritCoverGrammar(this.parseAssignmentExpression));
  2715. }
  2716. if (arrow) {
  2717. break;
  2718. }
  2719. }
  2720. if (!arrow) {
  2721. expr = this.finalize(this.startNode(startToken), new Node.SequenceExpression(expressions));
  2722. }
  2723. }
  2724. if (!arrow) {
  2725. this.expect(')');
  2726. if (this.match('=>')) {
  2727. if (expr.type === syntax_1.Syntax.Identifier && expr.name === 'yield') {
  2728. arrow = true;
  2729. expr = {
  2730. type: ArrowParameterPlaceHolder,
  2731. params: [expr],
  2732. async: false
  2733. };
  2734. }
  2735. if (!arrow) {
  2736. if (!this.context.isBindingElement) {
  2737. this.throwUnexpectedToken(this.lookahead);
  2738. }
  2739. if (expr.type === syntax_1.Syntax.SequenceExpression) {
  2740. for (var i = 0; i < expr.expressions.length; i++) {
  2741. this.reinterpretExpressionAsPattern(expr.expressions[i]);
  2742. }
  2743. }
  2744. else {
  2745. this.reinterpretExpressionAsPattern(expr);
  2746. }
  2747. var parameters = (expr.type === syntax_1.Syntax.SequenceExpression ? expr.expressions : [expr]);
  2748. expr = {
  2749. type: ArrowParameterPlaceHolder,
  2750. params: parameters,
  2751. async: false
  2752. };
  2753. }
  2754. }
  2755. this.context.isBindingElement = false;
  2756. }
  2757. }
  2758. }
  2759. return expr;
  2760. };
  2761. // https://tc39.github.io/ecma262/#sec-left-hand-side-expressions
  2762. Parser.prototype.parseArguments = function () {
  2763. this.expect('(');
  2764. var args = [];
  2765. if (!this.match(')')) {
  2766. while (true) {
  2767. var expr = this.match('...') ? this.parseSpreadElement() :
  2768. this.isolateCoverGrammar(this.parseAssignmentExpression);
  2769. args.push(expr);
  2770. if (this.match(')')) {
  2771. break;
  2772. }
  2773. this.expectCommaSeparator();
  2774. if (this.match(')')) {
  2775. break;
  2776. }
  2777. }
  2778. }
  2779. this.expect(')');
  2780. return args;
  2781. };
  2782. Parser.prototype.isIdentifierName = function (token) {
  2783. return token.type === 3 /* Identifier */ ||
  2784. token.type === 4 /* Keyword */ ||
  2785. token.type === 1 /* BooleanLiteral */ ||
  2786. token.type === 5 /* NullLiteral */;
  2787. };
  2788. Parser.prototype.parseIdentifierName = function () {
  2789. var node = this.createNode();
  2790. var token = this.nextToken();
  2791. if (!this.isIdentifierName(token)) {
  2792. this.throwUnexpectedToken(token);
  2793. }
  2794. return this.finalize(node, new Node.Identifier(token.value));
  2795. };
  2796. Parser.prototype.parseNewExpression = function () {
  2797. var node = this.createNode();
  2798. var id = this.parseIdentifierName();
  2799. assert_1.assert(id.name === 'new', 'New expression must start with `new`');
  2800. var expr;
  2801. if (this.match('.')) {
  2802. this.nextToken();
  2803. if (this.lookahead.type === 3 /* Identifier */ && this.context.inFunctionBody && this.lookahead.value === 'target') {
  2804. var property = this.parseIdentifierName();
  2805. expr = new Node.MetaProperty(id, property);
  2806. }
  2807. else {
  2808. this.throwUnexpectedToken(this.lookahead);
  2809. }
  2810. }
  2811. else {
  2812. var callee = this.isolateCoverGrammar(this.parseLeftHandSideExpression);
  2813. var args = this.match('(') ? this.parseArguments() : [];
  2814. expr = new Node.NewExpression(callee, args);
  2815. this.context.isAssignmentTarget = false;
  2816. this.context.isBindingElement = false;
  2817. }
  2818. return this.finalize(node, expr);
  2819. };
  2820. Parser.prototype.parseAsyncArgument = function () {
  2821. var arg = this.parseAssignmentExpression();
  2822. this.context.firstCoverInitializedNameError = null;
  2823. return arg;
  2824. };
  2825. Parser.prototype.parseAsyncArguments = function () {
  2826. this.expect('(');
  2827. var args = [];
  2828. if (!this.match(')')) {
  2829. while (true) {
  2830. var expr = this.match('...') ? this.parseSpreadElement() :
  2831. this.isolateCoverGrammar(this.parseAsyncArgument);
  2832. args.push(expr);
  2833. if (this.match(')')) {
  2834. break;
  2835. }
  2836. this.expectCommaSeparator();
  2837. if (this.match(')')) {
  2838. break;
  2839. }
  2840. }
  2841. }
  2842. this.expect(')');
  2843. return args;
  2844. };
  2845. Parser.prototype.parseLeftHandSideExpressionAllowCall = function () {
  2846. var startToken = this.lookahead;
  2847. var maybeAsync = this.matchContextualKeyword('async');
  2848. var previousAllowIn = this.context.allowIn;
  2849. this.context.allowIn = true;
  2850. var expr;
  2851. if (this.matchKeyword('super') && this.context.inFunctionBody) {
  2852. expr = this.createNode();
  2853. this.nextToken();
  2854. expr = this.finalize(expr, new Node.Super());
  2855. if (!this.match('(') && !this.match('.') && !this.match('[')) {
  2856. this.throwUnexpectedToken(this.lookahead);
  2857. }
  2858. }
  2859. else {
  2860. expr = this.inheritCoverGrammar(this.matchKeyword('new') ? this.parseNewExpression : this.parsePrimaryExpression);
  2861. }
  2862. while (true) {
  2863. if (this.match('.')) {
  2864. this.context.isBindingElement = false;
  2865. this.context.isAssignmentTarget = true;
  2866. this.expect('.');
  2867. var property = this.parseIdentifierName();
  2868. expr = this.finalize(this.startNode(startToken), new Node.StaticMemberExpression(expr, property));
  2869. }
  2870. else if (this.match('(')) {
  2871. var asyncArrow = maybeAsync && (startToken.lineNumber === this.lookahead.lineNumber);
  2872. this.context.isBindingElement = false;
  2873. this.context.isAssignmentTarget = false;
  2874. var args = asyncArrow ? this.parseAsyncArguments() : this.parseArguments();
  2875. expr = this.finalize(this.startNode(startToken), new Node.CallExpression(expr, args));
  2876. if (asyncArrow && this.match('=>')) {
  2877. for (var i = 0; i < args.length; ++i) {
  2878. this.reinterpretExpressionAsPattern(args[i]);
  2879. }
  2880. expr = {
  2881. type: ArrowParameterPlaceHolder,
  2882. params: args,
  2883. async: true
  2884. };
  2885. }
  2886. }
  2887. else if (this.match('[')) {
  2888. this.context.isBindingElement = false;
  2889. this.context.isAssignmentTarget = true;
  2890. this.expect('[');
  2891. var property = this.isolateCoverGrammar(this.parseExpression);
  2892. this.expect(']');
  2893. expr = this.finalize(this.startNode(startToken), new Node.ComputedMemberExpression(expr, property));
  2894. }
  2895. else if (this.lookahead.type === 10 /* Template */ && this.lookahead.head) {
  2896. var quasi = this.parseTemplateLiteral();
  2897. expr = this.finalize(this.startNode(startToken), new Node.TaggedTemplateExpression(expr, quasi));
  2898. }
  2899. else {
  2900. break;
  2901. }
  2902. }
  2903. this.context.allowIn = previousAllowIn;
  2904. return expr;
  2905. };
  2906. Parser.prototype.parseSuper = function () {
  2907. var node = this.createNode();
  2908. this.expectKeyword('super');
  2909. if (!this.match('[') && !this.match('.')) {
  2910. this.throwUnexpectedToken(this.lookahead);
  2911. }
  2912. return this.finalize(node, new Node.Super());
  2913. };
  2914. Parser.prototype.parseLeftHandSideExpression = function () {
  2915. assert_1.assert(this.context.allowIn, 'callee of new expression always allow in keyword.');
  2916. var node = this.startNode(this.lookahead);
  2917. var expr = (this.matchKeyword('super') && this.context.inFunctionBody) ? this.parseSuper() :
  2918. this.inheritCoverGrammar(this.matchKeyword('new') ? this.parseNewExpression : this.parsePrimaryExpression);
  2919. while (true) {
  2920. if (this.match('[')) {
  2921. this.context.isBindingElement = false;
  2922. this.context.isAssignmentTarget = true;
  2923. this.expect('[');
  2924. var property = this.isolateCoverGrammar(this.parseExpression);
  2925. this.expect(']');
  2926. expr = this.finalize(node, new Node.ComputedMemberExpression(expr, property));
  2927. }
  2928. else if (this.match('.')) {
  2929. this.context.isBindingElement = false;
  2930. this.context.isAssignmentTarget = true;
  2931. this.expect('.');
  2932. var property = this.parseIdentifierName();
  2933. expr = this.finalize(node, new Node.StaticMemberExpression(expr, property));
  2934. }
  2935. else if (this.lookahead.type === 10 /* Template */ && this.lookahead.head) {
  2936. var quasi = this.parseTemplateLiteral();
  2937. expr = this.finalize(node, new Node.TaggedTemplateExpression(expr, quasi));
  2938. }
  2939. else {
  2940. break;
  2941. }
  2942. }
  2943. return expr;
  2944. };
  2945. // https://tc39.github.io/ecma262/#sec-update-expressions
  2946. Parser.prototype.parseUpdateExpression = function () {
  2947. var expr;
  2948. var startToken = this.lookahead;
  2949. if (this.match('++') || this.match('--')) {
  2950. var node = this.startNode(startToken);
  2951. var token = this.nextToken();
  2952. expr = this.inheritCoverGrammar(this.parseUnaryExpression);
  2953. if (this.context.strict && expr.type === syntax_1.Syntax.Identifier && this.scanner.isRestrictedWord(expr.name)) {
  2954. this.tolerateError(messages_1.Messages.StrictLHSPrefix);
  2955. }
  2956. if (!this.context.isAssignmentTarget) {
  2957. this.tolerateError(messages_1.Messages.InvalidLHSInAssignment);
  2958. }
  2959. var prefix = true;
  2960. expr = this.finalize(node, new Node.UpdateExpression(token.value, expr, prefix));
  2961. this.context.isAssignmentTarget = false;
  2962. this.context.isBindingElement = false;
  2963. }
  2964. else {
  2965. expr = this.inheritCoverGrammar(this.parseLeftHandSideExpressionAllowCall);
  2966. if (!this.hasLineTerminator && this.lookahead.type === 7 /* Punctuator */) {
  2967. if (this.match('++') || this.match('--')) {
  2968. if (this.context.strict && expr.type === syntax_1.Syntax.Identifier && this.scanner.isRestrictedWord(expr.name)) {
  2969. this.tolerateError(messages_1.Messages.StrictLHSPostfix);
  2970. }
  2971. if (!this.context.isAssignmentTarget) {
  2972. this.tolerateError(messages_1.Messages.InvalidLHSInAssignment);
  2973. }
  2974. this.context.isAssignmentTarget = false;
  2975. this.context.isBindingElement = false;
  2976. var operator = this.nextToken().value;
  2977. var prefix = false;
  2978. expr = this.finalize(this.startNode(startToken), new Node.UpdateExpression(operator, expr, prefix));
  2979. }
  2980. }
  2981. }
  2982. return expr;
  2983. };
  2984. // https://tc39.github.io/ecma262/#sec-unary-operators
  2985. Parser.prototype.parseAwaitExpression = function () {
  2986. var node = this.createNode();
  2987. this.nextToken();
  2988. var argument = this.parseUnaryExpression();
  2989. return this.finalize(node, new Node.AwaitExpression(argument));
  2990. };
  2991. Parser.prototype.parseUnaryExpression = function () {
  2992. var expr;
  2993. if (this.match('+') || this.match('-') || this.match('~') || this.match('!') ||
  2994. this.matchKeyword('delete') || this.matchKeyword('void') || this.matchKeyword('typeof')) {
  2995. var node = this.startNode(this.lookahead);
  2996. var token = this.nextToken();
  2997. expr = this.inheritCoverGrammar(this.parseUnaryExpression);
  2998. expr = this.finalize(node, new Node.UnaryExpression(token.value, expr));
  2999. if (this.context.strict && expr.operator === 'delete' && expr.argument.type === syntax_1.Syntax.Identifier) {
  3000. this.tolerateError(messages_1.Messages.StrictDelete);
  3001. }
  3002. this.context.isAssignmentTarget = false;
  3003. this.context.isBindingElement = false;
  3004. }
  3005. else if (this.context.await && this.matchContextualKeyword('await')) {
  3006. expr = this.parseAwaitExpression();
  3007. }
  3008. else {
  3009. expr = this.parseUpdateExpression();
  3010. }
  3011. return expr;
  3012. };
  3013. Parser.prototype.parseExponentiationExpression = function () {
  3014. var startToken = this.lookahead;
  3015. var expr = this.inheritCoverGrammar(this.parseUnaryExpression);
  3016. if (expr.type !== syntax_1.Syntax.UnaryExpression && this.match('**')) {
  3017. this.nextToken();
  3018. this.context.isAssignmentTarget = false;
  3019. this.context.isBindingElement = false;
  3020. var left = expr;
  3021. var right = this.isolateCoverGrammar(this.parseExponentiationExpression);
  3022. expr = this.finalize(this.startNode(startToken), new Node.BinaryExpression('**', left, right));
  3023. }
  3024. return expr;
  3025. };
  3026. // https://tc39.github.io/ecma262/#sec-exp-operator
  3027. // https://tc39.github.io/ecma262/#sec-multiplicative-operators
  3028. // https://tc39.github.io/ecma262/#sec-additive-operators
  3029. // https://tc39.github.io/ecma262/#sec-bitwise-shift-operators
  3030. // https://tc39.github.io/ecma262/#sec-relational-operators
  3031. // https://tc39.github.io/ecma262/#sec-equality-operators
  3032. // https://tc39.github.io/ecma262/#sec-binary-bitwise-operators
  3033. // https://tc39.github.io/ecma262/#sec-binary-logical-operators
  3034. Parser.prototype.binaryPrecedence = function (token) {
  3035. var op = token.value;
  3036. var precedence;
  3037. if (token.type === 7 /* Punctuator */) {
  3038. precedence = this.operatorPrecedence[op] || 0;
  3039. }
  3040. else if (token.type === 4 /* Keyword */) {
  3041. precedence = (op === 'instanceof' || (this.context.allowIn && op === 'in')) ? 7 : 0;
  3042. }
  3043. else {
  3044. precedence = 0;
  3045. }
  3046. return precedence;
  3047. };
  3048. Parser.prototype.parseBinaryExpression = function () {
  3049. var startToken = this.lookahead;
  3050. var expr = this.inheritCoverGrammar(this.parseExponentiationExpression);
  3051. var token = this.lookahead;
  3052. var prec = this.binaryPrecedence(token);
  3053. if (prec > 0) {
  3054. this.nextToken();
  3055. this.context.isAssignmentTarget = false;
  3056. this.context.isBindingElement = false;
  3057. var markers = [startToken, this.lookahead];
  3058. var left = expr;
  3059. var right = this.isolateCoverGrammar(this.parseExponentiationExpression);
  3060. var stack = [left, token.value, right];
  3061. var precedences = [prec];
  3062. while (true) {
  3063. prec = this.binaryPrecedence(this.lookahead);
  3064. if (prec <= 0) {
  3065. break;
  3066. }
  3067. // Reduce: make a binary expression from the three topmost entries.
  3068. while ((stack.length > 2) && (prec <= precedences[precedences.length - 1])) {
  3069. right = stack.pop();
  3070. var operator = stack.pop();
  3071. precedences.pop();
  3072. left = stack.pop();
  3073. markers.pop();
  3074. var node = this.startNode(markers[markers.length - 1]);
  3075. stack.push(this.finalize(node, new Node.BinaryExpression(operator, left, right)));
  3076. }
  3077. // Shift.
  3078. stack.push(this.nextToken().value);
  3079. precedences.push(prec);
  3080. markers.push(this.lookahead);
  3081. stack.push(this.isolateCoverGrammar(this.parseExponentiationExpression));
  3082. }
  3083. // Final reduce to clean-up the stack.
  3084. var i = stack.length - 1;
  3085. expr = stack[i];
  3086. var lastMarker = markers.pop();
  3087. while (i > 1) {
  3088. var marker = markers.pop();
  3089. var lastLineStart = lastMarker && lastMarker.lineStart;
  3090. var node = this.startNode(marker, lastLineStart);
  3091. var operator = stack[i - 1];
  3092. expr = this.finalize(node, new Node.BinaryExpression(operator, stack[i - 2], expr));
  3093. i -= 2;
  3094. lastMarker = marker;
  3095. }
  3096. }
  3097. return expr;
  3098. };
  3099. // https://tc39.github.io/ecma262/#sec-conditional-operator
  3100. Parser.prototype.parseConditionalExpression = function () {
  3101. var startToken = this.lookahead;
  3102. var expr = this.inheritCoverGrammar(this.parseBinaryExpression);
  3103. if (this.match('?')) {
  3104. this.nextToken();
  3105. var previousAllowIn = this.context.allowIn;
  3106. this.context.allowIn = true;
  3107. var consequent = this.isolateCoverGrammar(this.parseAssignmentExpression);
  3108. this.context.allowIn = previousAllowIn;
  3109. this.expect(':');
  3110. var alternate = this.isolateCoverGrammar(this.parseAssignmentExpression);
  3111. expr = this.finalize(this.startNode(startToken), new Node.ConditionalExpression(expr, consequent, alternate));
  3112. this.context.isAssignmentTarget = false;
  3113. this.context.isBindingElement = false;
  3114. }
  3115. return expr;
  3116. };
  3117. // https://tc39.github.io/ecma262/#sec-assignment-operators
  3118. Parser.prototype.checkPatternParam = function (options, param) {
  3119. switch (param.type) {
  3120. case syntax_1.Syntax.Identifier:
  3121. this.validateParam(options, param, param.name);
  3122. break;
  3123. case syntax_1.Syntax.RestElement:
  3124. this.checkPatternParam(options, param.argument);
  3125. break;
  3126. case syntax_1.Syntax.AssignmentPattern:
  3127. this.checkPatternParam(options, param.left);
  3128. break;
  3129. case syntax_1.Syntax.ArrayPattern:
  3130. for (var i = 0; i < param.elements.length; i++) {
  3131. if (param.elements[i] !== null) {
  3132. this.checkPatternParam(options, param.elements[i]);
  3133. }
  3134. }
  3135. break;
  3136. case syntax_1.Syntax.ObjectPattern:
  3137. for (var i = 0; i < param.properties.length; i++) {
  3138. this.checkPatternParam(options, param.properties[i].value);
  3139. }
  3140. break;
  3141. default:
  3142. break;
  3143. }
  3144. options.simple = options.simple && (param instanceof Node.Identifier);
  3145. };
  3146. Parser.prototype.reinterpretAsCoverFormalsList = function (expr) {
  3147. var params = [expr];
  3148. var options;
  3149. var asyncArrow = false;
  3150. switch (expr.type) {
  3151. case syntax_1.Syntax.Identifier:
  3152. break;
  3153. case ArrowParameterPlaceHolder:
  3154. params = expr.params;
  3155. asyncArrow = expr.async;
  3156. break;
  3157. default:
  3158. return null;
  3159. }
  3160. options = {
  3161. simple: true,
  3162. paramSet: {}
  3163. };
  3164. for (var i = 0; i < params.length; ++i) {
  3165. var param = params[i];
  3166. if (param.type === syntax_1.Syntax.AssignmentPattern) {
  3167. if (param.right.type === syntax_1.Syntax.YieldExpression) {
  3168. if (param.right.argument) {
  3169. this.throwUnexpectedToken(this.lookahead);
  3170. }
  3171. param.right.type = syntax_1.Syntax.Identifier;
  3172. param.right.name = 'yield';
  3173. delete param.right.argument;
  3174. delete param.right.delegate;
  3175. }
  3176. }
  3177. else if (asyncArrow && param.type === syntax_1.Syntax.Identifier && param.name === 'await') {
  3178. this.throwUnexpectedToken(this.lookahead);
  3179. }
  3180. this.checkPatternParam(options, param);
  3181. params[i] = param;
  3182. }
  3183. if (this.context.strict || !this.context.allowYield) {
  3184. for (var i = 0; i < params.length; ++i) {
  3185. var param = params[i];
  3186. if (param.type === syntax_1.Syntax.YieldExpression) {
  3187. this.throwUnexpectedToken(this.lookahead);
  3188. }
  3189. }
  3190. }
  3191. if (options.message === messages_1.Messages.StrictParamDupe) {
  3192. var token = this.context.strict ? options.stricted : options.firstRestricted;
  3193. this.throwUnexpectedToken(token, options.message);
  3194. }
  3195. return {
  3196. simple: options.simple,
  3197. params: params,
  3198. stricted: options.stricted,
  3199. firstRestricted: options.firstRestricted,
  3200. message: options.message
  3201. };
  3202. };
  3203. Parser.prototype.parseAssignmentExpression = function () {
  3204. var expr;
  3205. if (!this.context.allowYield && this.matchKeyword('yield')) {
  3206. expr = this.parseYieldExpression();
  3207. }
  3208. else {
  3209. var startToken = this.lookahead;
  3210. var token = startToken;
  3211. expr = this.parseConditionalExpression();
  3212. if (token.type === 3 /* Identifier */ && (token.lineNumber === this.lookahead.lineNumber) && token.value === 'async') {
  3213. if (this.lookahead.type === 3 /* Identifier */ || this.matchKeyword('yield')) {
  3214. var arg = this.parsePrimaryExpression();
  3215. this.reinterpretExpressionAsPattern(arg);
  3216. expr = {
  3217. type: ArrowParameterPlaceHolder,
  3218. params: [arg],
  3219. async: true
  3220. };
  3221. }
  3222. }
  3223. if (expr.type === ArrowParameterPlaceHolder || this.match('=>')) {
  3224. // https://tc39.github.io/ecma262/#sec-arrow-function-definitions
  3225. this.context.isAssignmentTarget = false;
  3226. this.context.isBindingElement = false;
  3227. var isAsync = expr.async;
  3228. var list = this.reinterpretAsCoverFormalsList(expr);
  3229. if (list) {
  3230. if (this.hasLineTerminator) {
  3231. this.tolerateUnexpectedToken(this.lookahead);
  3232. }
  3233. this.context.firstCoverInitializedNameError = null;
  3234. var previousStrict = this.context.strict;
  3235. var previousAllowStrictDirective = this.context.allowStrictDirective;
  3236. this.context.allowStrictDirective = list.simple;
  3237. var previousAllowYield = this.context.allowYield;
  3238. var previousAwait = this.context.await;
  3239. this.context.allowYield = true;
  3240. this.context.await = isAsync;
  3241. var node = this.startNode(startToken);
  3242. this.expect('=>');
  3243. var body = void 0;
  3244. if (this.match('{')) {
  3245. var previousAllowIn = this.context.allowIn;
  3246. this.context.allowIn = true;
  3247. body = this.parseFunctionSourceElements();
  3248. this.context.allowIn = previousAllowIn;
  3249. }
  3250. else {
  3251. body = this.isolateCoverGrammar(this.parseAssignmentExpression);
  3252. }
  3253. var expression = body.type !== syntax_1.Syntax.BlockStatement;
  3254. if (this.context.strict && list.firstRestricted) {
  3255. this.throwUnexpectedToken(list.firstRestricted, list.message);
  3256. }
  3257. if (this.context.strict && list.stricted) {
  3258. this.tolerateUnexpectedToken(list.stricted, list.message);
  3259. }
  3260. expr = isAsync ? this.finalize(node, new Node.AsyncArrowFunctionExpression(list.params, body, expression)) :
  3261. this.finalize(node, new Node.ArrowFunctionExpression(list.params, body, expression));
  3262. this.context.strict = previousStrict;
  3263. this.context.allowStrictDirective = previousAllowStrictDirective;
  3264. this.context.allowYield = previousAllowYield;
  3265. this.context.await = previousAwait;
  3266. }
  3267. }
  3268. else {
  3269. if (this.matchAssign()) {
  3270. if (!this.context.isAssignmentTarget) {
  3271. this.tolerateError(messages_1.Messages.InvalidLHSInAssignment);
  3272. }
  3273. if (this.context.strict && expr.type === syntax_1.Syntax.Identifier) {
  3274. var id = expr;
  3275. if (this.scanner.isRestrictedWord(id.name)) {
  3276. this.tolerateUnexpectedToken(token, messages_1.Messages.StrictLHSAssignment);
  3277. }
  3278. if (this.scanner.isStrictModeReservedWord(id.name)) {
  3279. this.tolerateUnexpectedToken(token, messages_1.Messages.StrictReservedWord);
  3280. }
  3281. }
  3282. if (!this.match('=')) {
  3283. this.context.isAssignmentTarget = false;
  3284. this.context.isBindingElement = false;
  3285. }
  3286. else {
  3287. this.reinterpretExpressionAsPattern(expr);
  3288. }
  3289. token = this.nextToken();
  3290. var operator = token.value;
  3291. var right = this.isolateCoverGrammar(this.parseAssignmentExpression);
  3292. expr = this.finalize(this.startNode(startToken), new Node.AssignmentExpression(operator, expr, right));
  3293. this.context.firstCoverInitializedNameError = null;
  3294. }
  3295. }
  3296. }
  3297. return expr;
  3298. };
  3299. // https://tc39.github.io/ecma262/#sec-comma-operator
  3300. Parser.prototype.parseExpression = function () {
  3301. var startToken = this.lookahead;
  3302. var expr = this.isolateCoverGrammar(this.parseAssignmentExpression);
  3303. if (this.match(',')) {
  3304. var expressions = [];
  3305. expressions.push(expr);
  3306. while (this.lookahead.type !== 2 /* EOF */) {
  3307. if (!this.match(',')) {
  3308. break;
  3309. }
  3310. this.nextToken();
  3311. expressions.push(this.isolateCoverGrammar(this.parseAssignmentExpression));
  3312. }
  3313. expr = this.finalize(this.startNode(startToken), new Node.SequenceExpression(expressions));
  3314. }
  3315. return expr;
  3316. };
  3317. // https://tc39.github.io/ecma262/#sec-block
  3318. Parser.prototype.parseStatementListItem = function () {
  3319. var statement;
  3320. this.context.isAssignmentTarget = true;
  3321. this.context.isBindingElement = true;
  3322. if (this.lookahead.type === 4 /* Keyword */) {
  3323. switch (this.lookahead.value) {
  3324. case 'export':
  3325. if (!this.context.isModule) {
  3326. this.tolerateUnexpectedToken(this.lookahead, messages_1.Messages.IllegalExportDeclaration);
  3327. }
  3328. statement = this.parseExportDeclaration();
  3329. break;
  3330. case 'import':
  3331. if (!this.context.isModule) {
  3332. this.tolerateUnexpectedToken(this.lookahead, messages_1.Messages.IllegalImportDeclaration);
  3333. }
  3334. statement = this.parseImportDeclaration();
  3335. break;
  3336. case 'const':
  3337. statement = this.parseLexicalDeclaration({ inFor: false });
  3338. break;
  3339. case 'function':
  3340. statement = this.parseFunctionDeclaration();
  3341. break;
  3342. case 'class':
  3343. statement = this.parseClassDeclaration();
  3344. break;
  3345. case 'let':
  3346. statement = this.isLexicalDeclaration() ? this.parseLexicalDeclaration({ inFor: false }) : this.parseStatement();
  3347. break;
  3348. default:
  3349. statement = this.parseStatement();
  3350. break;
  3351. }
  3352. }
  3353. else {
  3354. statement = this.parseStatement();
  3355. }
  3356. return statement;
  3357. };
  3358. Parser.prototype.parseBlock = function () {
  3359. var node = this.createNode();
  3360. this.expect('{');
  3361. var block = [];
  3362. while (true) {
  3363. if (this.match('}')) {
  3364. break;
  3365. }
  3366. block.push(this.parseStatementListItem());
  3367. }
  3368. this.expect('}');
  3369. return this.finalize(node, new Node.BlockStatement(block));
  3370. };
  3371. // https://tc39.github.io/ecma262/#sec-let-and-const-declarations
  3372. Parser.prototype.parseLexicalBinding = function (kind, options) {
  3373. var node = this.createNode();
  3374. var params = [];
  3375. var id = this.parsePattern(params, kind);
  3376. if (this.context.strict && id.type === syntax_1.Syntax.Identifier) {
  3377. if (this.scanner.isRestrictedWord(id.name)) {
  3378. this.tolerateError(messages_1.Messages.StrictVarName);
  3379. }
  3380. }
  3381. var init = null;
  3382. if (kind === 'const') {
  3383. if (!this.matchKeyword('in') && !this.matchContextualKeyword('of')) {
  3384. if (this.match('=')) {
  3385. this.nextToken();
  3386. init = this.isolateCoverGrammar(this.parseAssignmentExpression);
  3387. }
  3388. else {
  3389. this.throwError(messages_1.Messages.DeclarationMissingInitializer, 'const');
  3390. }
  3391. }
  3392. }
  3393. else if ((!options.inFor && id.type !== syntax_1.Syntax.Identifier) || this.match('=')) {
  3394. this.expect('=');
  3395. init = this.isolateCoverGrammar(this.parseAssignmentExpression);
  3396. }
  3397. return this.finalize(node, new Node.VariableDeclarator(id, init));
  3398. };
  3399. Parser.prototype.parseBindingList = function (kind, options) {
  3400. var list = [this.parseLexicalBinding(kind, options)];
  3401. while (this.match(',')) {
  3402. this.nextToken();
  3403. list.push(this.parseLexicalBinding(kind, options));
  3404. }
  3405. return list;
  3406. };
  3407. Parser.prototype.isLexicalDeclaration = function () {
  3408. var state = this.scanner.saveState();
  3409. this.scanner.scanComments();
  3410. var next = this.scanner.lex();
  3411. this.scanner.restoreState(state);
  3412. return (next.type === 3 /* Identifier */) ||
  3413. (next.type === 7 /* Punctuator */ && next.value === '[') ||
  3414. (next.type === 7 /* Punctuator */ && next.value === '{') ||
  3415. (next.type === 4 /* Keyword */ && next.value === 'let') ||
  3416. (next.type === 4 /* Keyword */ && next.value === 'yield');
  3417. };
  3418. Parser.prototype.parseLexicalDeclaration = function (options) {
  3419. var node = this.createNode();
  3420. var kind = this.nextToken().value;
  3421. assert_1.assert(kind === 'let' || kind === 'const', 'Lexical declaration must be either let or const');
  3422. var declarations = this.parseBindingList(kind, options);
  3423. this.consumeSemicolon();
  3424. return this.finalize(node, new Node.VariableDeclaration(declarations, kind));
  3425. };
  3426. // https://tc39.github.io/ecma262/#sec-destructuring-binding-patterns
  3427. Parser.prototype.parseBindingRestElement = function (params, kind) {
  3428. var node = this.createNode();
  3429. this.expect('...');
  3430. var arg = this.parsePattern(params, kind);
  3431. return this.finalize(node, new Node.RestElement(arg));
  3432. };
  3433. Parser.prototype.parseArrayPattern = function (params, kind) {
  3434. var node = this.createNode();
  3435. this.expect('[');
  3436. var elements = [];
  3437. while (!this.match(']')) {
  3438. if (this.match(',')) {
  3439. this.nextToken();
  3440. elements.push(null);
  3441. }
  3442. else {
  3443. if (this.match('...')) {
  3444. elements.push(this.parseBindingRestElement(params, kind));
  3445. break;
  3446. }
  3447. else {
  3448. elements.push(this.parsePatternWithDefault(params, kind));
  3449. }
  3450. if (!this.match(']')) {
  3451. this.expect(',');
  3452. }
  3453. }
  3454. }
  3455. this.expect(']');
  3456. return this.finalize(node, new Node.ArrayPattern(elements));
  3457. };
  3458. Parser.prototype.parsePropertyPattern = function (params, kind) {
  3459. var node = this.createNode();
  3460. var computed = false;
  3461. var shorthand = false;
  3462. var method = false;
  3463. var key;
  3464. var value;
  3465. if (this.lookahead.type === 3 /* Identifier */) {
  3466. var keyToken = this.lookahead;
  3467. key = this.parseVariableIdentifier();
  3468. var init = this.finalize(node, new Node.Identifier(keyToken.value));
  3469. if (this.match('=')) {
  3470. params.push(keyToken);
  3471. shorthand = true;
  3472. this.nextToken();
  3473. var expr = this.parseAssignmentExpression();
  3474. value = this.finalize(this.startNode(keyToken), new Node.AssignmentPattern(init, expr));
  3475. }
  3476. else if (!this.match(':')) {
  3477. params.push(keyToken);
  3478. shorthand = true;
  3479. value = init;
  3480. }
  3481. else {
  3482. this.expect(':');
  3483. value = this.parsePatternWithDefault(params, kind);
  3484. }
  3485. }
  3486. else {
  3487. computed = this.match('[');
  3488. key = this.parseObjectPropertyKey();
  3489. this.expect(':');
  3490. value = this.parsePatternWithDefault(params, kind);
  3491. }
  3492. return this.finalize(node, new Node.Property('init', key, computed, value, method, shorthand));
  3493. };
  3494. Parser.prototype.parseObjectPattern = function (params, kind) {
  3495. var node = this.createNode();
  3496. var properties = [];
  3497. this.expect('{');
  3498. while (!this.match('}')) {
  3499. properties.push(this.parsePropertyPattern(params, kind));
  3500. if (!this.match('}')) {
  3501. this.expect(',');
  3502. }
  3503. }
  3504. this.expect('}');
  3505. return this.finalize(node, new Node.ObjectPattern(properties));
  3506. };
  3507. Parser.prototype.parsePattern = function (params, kind) {
  3508. var pattern;
  3509. if (this.match('[')) {
  3510. pattern = this.parseArrayPattern(params, kind);
  3511. }
  3512. else if (this.match('{')) {
  3513. pattern = this.parseObjectPattern(params, kind);
  3514. }
  3515. else {
  3516. if (this.matchKeyword('let') && (kind === 'const' || kind === 'let')) {
  3517. this.tolerateUnexpectedToken(this.lookahead, messages_1.Messages.LetInLexicalBinding);
  3518. }
  3519. params.push(this.lookahead);
  3520. pattern = this.parseVariableIdentifier(kind);
  3521. }
  3522. return pattern;
  3523. };
  3524. Parser.prototype.parsePatternWithDefault = function (params, kind) {
  3525. var startToken = this.lookahead;
  3526. var pattern = this.parsePattern(params, kind);
  3527. if (this.match('=')) {
  3528. this.nextToken();
  3529. var previousAllowYield = this.context.allowYield;
  3530. this.context.allowYield = true;
  3531. var right = this.isolateCoverGrammar(this.parseAssignmentExpression);
  3532. this.context.allowYield = previousAllowYield;
  3533. pattern = this.finalize(this.startNode(startToken), new Node.AssignmentPattern(pattern, right));
  3534. }
  3535. return pattern;
  3536. };
  3537. // https://tc39.github.io/ecma262/#sec-variable-statement
  3538. Parser.prototype.parseVariableIdentifier = function (kind) {
  3539. var node = this.createNode();
  3540. var token = this.nextToken();
  3541. if (token.type === 4 /* Keyword */ && token.value === 'yield') {
  3542. if (this.context.strict) {
  3543. this.tolerateUnexpectedToken(token, messages_1.Messages.StrictReservedWord);
  3544. }
  3545. else if (!this.context.allowYield) {
  3546. this.throwUnexpectedToken(token);
  3547. }
  3548. }
  3549. else if (token.type !== 3 /* Identifier */) {
  3550. if (this.context.strict && token.type === 4 /* Keyword */ && this.scanner.isStrictModeReservedWord(token.value)) {
  3551. this.tolerateUnexpectedToken(token, messages_1.Messages.StrictReservedWord);
  3552. }
  3553. else {
  3554. if (this.context.strict || token.value !== 'let' || kind !== 'var') {
  3555. this.throwUnexpectedToken(token);
  3556. }
  3557. }
  3558. }
  3559. else if ((this.context.isModule || this.context.await) && token.type === 3 /* Identifier */ && token.value === 'await') {
  3560. this.tolerateUnexpectedToken(token);
  3561. }
  3562. return this.finalize(node, new Node.Identifier(token.value));
  3563. };
  3564. Parser.prototype.parseVariableDeclaration = function (options) {
  3565. var node = this.createNode();
  3566. var params = [];
  3567. var id = this.parsePattern(params, 'var');
  3568. if (this.context.strict && id.type === syntax_1.Syntax.Identifier) {
  3569. if (this.scanner.isRestrictedWord(id.name)) {
  3570. this.tolerateError(messages_1.Messages.StrictVarName);
  3571. }
  3572. }
  3573. var init = null;
  3574. if (this.match('=')) {
  3575. this.nextToken();
  3576. init = this.isolateCoverGrammar(this.parseAssignmentExpression);
  3577. }
  3578. else if (id.type !== syntax_1.Syntax.Identifier && !options.inFor) {
  3579. this.expect('=');
  3580. }
  3581. return this.finalize(node, new Node.VariableDeclarator(id, init));
  3582. };
  3583. Parser.prototype.parseVariableDeclarationList = function (options) {
  3584. var opt = { inFor: options.inFor };
  3585. var list = [];
  3586. list.push(this.parseVariableDeclaration(opt));
  3587. while (this.match(',')) {
  3588. this.nextToken();
  3589. list.push(this.parseVariableDeclaration(opt));
  3590. }
  3591. return list;
  3592. };
  3593. Parser.prototype.parseVariableStatement = function () {
  3594. var node = this.createNode();
  3595. this.expectKeyword('var');
  3596. var declarations = this.parseVariableDeclarationList({ inFor: false });
  3597. this.consumeSemicolon();
  3598. return this.finalize(node, new Node.VariableDeclaration(declarations, 'var'));
  3599. };
  3600. // https://tc39.github.io/ecma262/#sec-empty-statement
  3601. Parser.prototype.parseEmptyStatement = function () {
  3602. var node = this.createNode();
  3603. this.expect(';');
  3604. return this.finalize(node, new Node.EmptyStatement());
  3605. };
  3606. // https://tc39.github.io/ecma262/#sec-expression-statement
  3607. Parser.prototype.parseExpressionStatement = function () {
  3608. var node = this.createNode();
  3609. var expr = this.parseExpression();
  3610. this.consumeSemicolon();
  3611. return this.finalize(node, new Node.ExpressionStatement(expr));
  3612. };
  3613. // https://tc39.github.io/ecma262/#sec-if-statement
  3614. Parser.prototype.parseIfClause = function () {
  3615. if (this.context.strict && this.matchKeyword('function')) {
  3616. this.tolerateError(messages_1.Messages.StrictFunction);
  3617. }
  3618. return this.parseStatement();
  3619. };
  3620. Parser.prototype.parseIfStatement = function () {
  3621. var node = this.createNode();
  3622. var consequent;
  3623. var alternate = null;
  3624. this.expectKeyword('if');
  3625. this.expect('(');
  3626. var test = this.parseExpression();
  3627. if (!this.match(')') && this.config.tolerant) {
  3628. this.tolerateUnexpectedToken(this.nextToken());
  3629. consequent = this.finalize(this.createNode(), new Node.EmptyStatement());
  3630. }
  3631. else {
  3632. this.expect(')');
  3633. consequent = this.parseIfClause();
  3634. if (this.matchKeyword('else')) {
  3635. this.nextToken();
  3636. alternate = this.parseIfClause();
  3637. }
  3638. }
  3639. return this.finalize(node, new Node.IfStatement(test, consequent, alternate));
  3640. };
  3641. // https://tc39.github.io/ecma262/#sec-do-while-statement
  3642. Parser.prototype.parseDoWhileStatement = function () {
  3643. var node = this.createNode();
  3644. this.expectKeyword('do');
  3645. var previousInIteration = this.context.inIteration;
  3646. this.context.inIteration = true;
  3647. var body = this.parseStatement();
  3648. this.context.inIteration = previousInIteration;
  3649. this.expectKeyword('while');
  3650. this.expect('(');
  3651. var test = this.parseExpression();
  3652. if (!this.match(')') && this.config.tolerant) {
  3653. this.tolerateUnexpectedToken(this.nextToken());
  3654. }
  3655. else {
  3656. this.expect(')');
  3657. if (this.match(';')) {
  3658. this.nextToken();
  3659. }
  3660. }
  3661. return this.finalize(node, new Node.DoWhileStatement(body, test));
  3662. };
  3663. // https://tc39.github.io/ecma262/#sec-while-statement
  3664. Parser.prototype.parseWhileStatement = function () {
  3665. var node = this.createNode();
  3666. var body;
  3667. this.expectKeyword('while');
  3668. this.expect('(');
  3669. var test = this.parseExpression();
  3670. if (!this.match(')') && this.config.tolerant) {
  3671. this.tolerateUnexpectedToken(this.nextToken());
  3672. body = this.finalize(this.createNode(), new Node.EmptyStatement());
  3673. }
  3674. else {
  3675. this.expect(')');
  3676. var previousInIteration = this.context.inIteration;
  3677. this.context.inIteration = true;
  3678. body = this.parseStatement();
  3679. this.context.inIteration = previousInIteration;
  3680. }
  3681. return this.finalize(node, new Node.WhileStatement(test, body));
  3682. };
  3683. // https://tc39.github.io/ecma262/#sec-for-statement
  3684. // https://tc39.github.io/ecma262/#sec-for-in-and-for-of-statements
  3685. Parser.prototype.parseForStatement = function () {
  3686. var init = null;
  3687. var test = null;
  3688. var update = null;
  3689. var forIn = true;
  3690. var left, right;
  3691. var node = this.createNode();
  3692. this.expectKeyword('for');
  3693. this.expect('(');
  3694. if (this.match(';')) {
  3695. this.nextToken();
  3696. }
  3697. else {
  3698. if (this.matchKeyword('var')) {
  3699. init = this.createNode();
  3700. this.nextToken();
  3701. var previousAllowIn = this.context.allowIn;
  3702. this.context.allowIn = false;
  3703. var declarations = this.parseVariableDeclarationList({ inFor: true });
  3704. this.context.allowIn = previousAllowIn;
  3705. if (declarations.length === 1 && this.matchKeyword('in')) {
  3706. var decl = declarations[0];
  3707. if (decl.init && (decl.id.type === syntax_1.Syntax.ArrayPattern || decl.id.type === syntax_1.Syntax.ObjectPattern || this.context.strict)) {
  3708. this.tolerateError(messages_1.Messages.ForInOfLoopInitializer, 'for-in');
  3709. }
  3710. init = this.finalize(init, new Node.VariableDeclaration(declarations, 'var'));
  3711. this.nextToken();
  3712. left = init;
  3713. right = this.parseExpression();
  3714. init = null;
  3715. }
  3716. else if (declarations.length === 1 && declarations[0].init === null && this.matchContextualKeyword('of')) {
  3717. init = this.finalize(init, new Node.VariableDeclaration(declarations, 'var'));
  3718. this.nextToken();
  3719. left = init;
  3720. right = this.parseAssignmentExpression();
  3721. init = null;
  3722. forIn = false;
  3723. }
  3724. else {
  3725. init = this.finalize(init, new Node.VariableDeclaration(declarations, 'var'));
  3726. this.expect(';');
  3727. }
  3728. }
  3729. else if (this.matchKeyword('const') || this.matchKeyword('let')) {
  3730. init = this.createNode();
  3731. var kind = this.nextToken().value;
  3732. if (!this.context.strict && this.lookahead.value === 'in') {
  3733. init = this.finalize(init, new Node.Identifier(kind));
  3734. this.nextToken();
  3735. left = init;
  3736. right = this.parseExpression();
  3737. init = null;
  3738. }
  3739. else {
  3740. var previousAllowIn = this.context.allowIn;
  3741. this.context.allowIn = false;
  3742. var declarations = this.parseBindingList(kind, { inFor: true });
  3743. this.context.allowIn = previousAllowIn;
  3744. if (declarations.length === 1 && declarations[0].init === null && this.matchKeyword('in')) {
  3745. init = this.finalize(init, new Node.VariableDeclaration(declarations, kind));
  3746. this.nextToken();
  3747. left = init;
  3748. right = this.parseExpression();
  3749. init = null;
  3750. }
  3751. else if (declarations.length === 1 && declarations[0].init === null && this.matchContextualKeyword('of')) {
  3752. init = this.finalize(init, new Node.VariableDeclaration(declarations, kind));
  3753. this.nextToken();
  3754. left = init;
  3755. right = this.parseAssignmentExpression();
  3756. init = null;
  3757. forIn = false;
  3758. }
  3759. else {
  3760. this.consumeSemicolon();
  3761. init = this.finalize(init, new Node.VariableDeclaration(declarations, kind));
  3762. }
  3763. }
  3764. }
  3765. else {
  3766. var initStartToken = this.lookahead;
  3767. var previousAllowIn = this.context.allowIn;
  3768. this.context.allowIn = false;
  3769. init = this.inheritCoverGrammar(this.parseAssignmentExpression);
  3770. this.context.allowIn = previousAllowIn;
  3771. if (this.matchKeyword('in')) {
  3772. if (!this.context.isAssignmentTarget || init.type === syntax_1.Syntax.AssignmentExpression) {
  3773. this.tolerateError(messages_1.Messages.InvalidLHSInForIn);
  3774. }
  3775. this.nextToken();
  3776. this.reinterpretExpressionAsPattern(init);
  3777. left = init;
  3778. right = this.parseExpression();
  3779. init = null;
  3780. }
  3781. else if (this.matchContextualKeyword('of')) {
  3782. if (!this.context.isAssignmentTarget || init.type === syntax_1.Syntax.AssignmentExpression) {
  3783. this.tolerateError(messages_1.Messages.InvalidLHSInForLoop);
  3784. }
  3785. this.nextToken();
  3786. this.reinterpretExpressionAsPattern(init);
  3787. left = init;
  3788. right = this.parseAssignmentExpression();
  3789. init = null;
  3790. forIn = false;
  3791. }
  3792. else {
  3793. if (this.match(',')) {
  3794. var initSeq = [init];
  3795. while (this.match(',')) {
  3796. this.nextToken();
  3797. initSeq.push(this.isolateCoverGrammar(this.parseAssignmentExpression));
  3798. }
  3799. init = this.finalize(this.startNode(initStartToken), new Node.SequenceExpression(initSeq));
  3800. }
  3801. this.expect(';');
  3802. }
  3803. }
  3804. }
  3805. if (typeof left === 'undefined') {
  3806. if (!this.match(';')) {
  3807. test = this.parseExpression();
  3808. }
  3809. this.expect(';');
  3810. if (!this.match(')')) {
  3811. update = this.parseExpression();
  3812. }
  3813. }
  3814. var body;
  3815. if (!this.match(')') && this.config.tolerant) {
  3816. this.tolerateUnexpectedToken(this.nextToken());
  3817. body = this.finalize(this.createNode(), new Node.EmptyStatement());
  3818. }
  3819. else {
  3820. this.expect(')');
  3821. var previousInIteration = this.context.inIteration;
  3822. this.context.inIteration = true;
  3823. body = this.isolateCoverGrammar(this.parseStatement);
  3824. this.context.inIteration = previousInIteration;
  3825. }
  3826. return (typeof left === 'undefined') ?
  3827. this.finalize(node, new Node.ForStatement(init, test, update, body)) :
  3828. forIn ? this.finalize(node, new Node.ForInStatement(left, right, body)) :
  3829. this.finalize(node, new Node.ForOfStatement(left, right, body));
  3830. };
  3831. // https://tc39.github.io/ecma262/#sec-continue-statement
  3832. Parser.prototype.parseContinueStatement = function () {
  3833. var node = this.createNode();
  3834. this.expectKeyword('continue');
  3835. var label = null;
  3836. if (this.lookahead.type === 3 /* Identifier */ && !this.hasLineTerminator) {
  3837. var id = this.parseVariableIdentifier();
  3838. label = id;
  3839. var key = '$' + id.name;
  3840. if (!Object.prototype.hasOwnProperty.call(this.context.labelSet, key)) {
  3841. this.throwError(messages_1.Messages.UnknownLabel, id.name);
  3842. }
  3843. }
  3844. this.consumeSemicolon();
  3845. if (label === null && !this.context.inIteration) {
  3846. this.throwError(messages_1.Messages.IllegalContinue);
  3847. }
  3848. return this.finalize(node, new Node.ContinueStatement(label));
  3849. };
  3850. // https://tc39.github.io/ecma262/#sec-break-statement
  3851. Parser.prototype.parseBreakStatement = function () {
  3852. var node = this.createNode();
  3853. this.expectKeyword('break');
  3854. var label = null;
  3855. if (this.lookahead.type === 3 /* Identifier */ && !this.hasLineTerminator) {
  3856. var id = this.parseVariableIdentifier();
  3857. var key = '$' + id.name;
  3858. if (!Object.prototype.hasOwnProperty.call(this.context.labelSet, key)) {
  3859. this.throwError(messages_1.Messages.UnknownLabel, id.name);
  3860. }
  3861. label = id;
  3862. }
  3863. this.consumeSemicolon();
  3864. if (label === null && !this.context.inIteration && !this.context.inSwitch) {
  3865. this.throwError(messages_1.Messages.IllegalBreak);
  3866. }
  3867. return this.finalize(node, new Node.BreakStatement(label));
  3868. };
  3869. // https://tc39.github.io/ecma262/#sec-return-statement
  3870. Parser.prototype.parseReturnStatement = function () {
  3871. if (!this.context.inFunctionBody) {
  3872. this.tolerateError(messages_1.Messages.IllegalReturn);
  3873. }
  3874. var node = this.createNode();
  3875. this.expectKeyword('return');
  3876. var hasArgument = (!this.match(';') && !this.match('}') &&
  3877. !this.hasLineTerminator && this.lookahead.type !== 2 /* EOF */) ||
  3878. this.lookahead.type === 8 /* StringLiteral */ ||
  3879. this.lookahead.type === 10 /* Template */;
  3880. var argument = hasArgument ? this.parseExpression() : null;
  3881. this.consumeSemicolon();
  3882. return this.finalize(node, new Node.ReturnStatement(argument));
  3883. };
  3884. // https://tc39.github.io/ecma262/#sec-with-statement
  3885. Parser.prototype.parseWithStatement = function () {
  3886. if (this.context.strict) {
  3887. this.tolerateError(messages_1.Messages.StrictModeWith);
  3888. }
  3889. var node = this.createNode();
  3890. var body;
  3891. this.expectKeyword('with');
  3892. this.expect('(');
  3893. var object = this.parseExpression();
  3894. if (!this.match(')') && this.config.tolerant) {
  3895. this.tolerateUnexpectedToken(this.nextToken());
  3896. body = this.finalize(this.createNode(), new Node.EmptyStatement());
  3897. }
  3898. else {
  3899. this.expect(')');
  3900. body = this.parseStatement();
  3901. }
  3902. return this.finalize(node, new Node.WithStatement(object, body));
  3903. };
  3904. // https://tc39.github.io/ecma262/#sec-switch-statement
  3905. Parser.prototype.parseSwitchCase = function () {
  3906. var node = this.createNode();
  3907. var test;
  3908. if (this.matchKeyword('default')) {
  3909. this.nextToken();
  3910. test = null;
  3911. }
  3912. else {
  3913. this.expectKeyword('case');
  3914. test = this.parseExpression();
  3915. }
  3916. this.expect(':');
  3917. var consequent = [];
  3918. while (true) {
  3919. if (this.match('}') || this.matchKeyword('default') || this.matchKeyword('case')) {
  3920. break;
  3921. }
  3922. consequent.push(this.parseStatementListItem());
  3923. }
  3924. return this.finalize(node, new Node.SwitchCase(test, consequent));
  3925. };
  3926. Parser.prototype.parseSwitchStatement = function () {
  3927. var node = this.createNode();
  3928. this.expectKeyword('switch');
  3929. this.expect('(');
  3930. var discriminant = this.parseExpression();
  3931. this.expect(')');
  3932. var previousInSwitch = this.context.inSwitch;
  3933. this.context.inSwitch = true;
  3934. var cases = [];
  3935. var defaultFound = false;
  3936. this.expect('{');
  3937. while (true) {
  3938. if (this.match('}')) {
  3939. break;
  3940. }
  3941. var clause = this.parseSwitchCase();
  3942. if (clause.test === null) {
  3943. if (defaultFound) {
  3944. this.throwError(messages_1.Messages.MultipleDefaultsInSwitch);
  3945. }
  3946. defaultFound = true;
  3947. }
  3948. cases.push(clause);
  3949. }
  3950. this.expect('}');
  3951. this.context.inSwitch = previousInSwitch;
  3952. return this.finalize(node, new Node.SwitchStatement(discriminant, cases));
  3953. };
  3954. // https://tc39.github.io/ecma262/#sec-labelled-statements
  3955. Parser.prototype.parseLabelledStatement = function () {
  3956. var node = this.createNode();
  3957. var expr = this.parseExpression();
  3958. var statement;
  3959. if ((expr.type === syntax_1.Syntax.Identifier) && this.match(':')) {
  3960. this.nextToken();
  3961. var id = expr;
  3962. var key = '$' + id.name;
  3963. if (Object.prototype.hasOwnProperty.call(this.context.labelSet, key)) {
  3964. this.throwError(messages_1.Messages.Redeclaration, 'Label', id.name);
  3965. }
  3966. this.context.labelSet[key] = true;
  3967. var body = void 0;
  3968. if (this.matchKeyword('class')) {
  3969. this.tolerateUnexpectedToken(this.lookahead);
  3970. body = this.parseClassDeclaration();
  3971. }
  3972. else if (this.matchKeyword('function')) {
  3973. var token = this.lookahead;
  3974. var declaration = this.parseFunctionDeclaration();
  3975. if (this.context.strict) {
  3976. this.tolerateUnexpectedToken(token, messages_1.Messages.StrictFunction);
  3977. }
  3978. else if (declaration.generator) {
  3979. this.tolerateUnexpectedToken(token, messages_1.Messages.GeneratorInLegacyContext);
  3980. }
  3981. body = declaration;
  3982. }
  3983. else {
  3984. body = this.parseStatement();
  3985. }
  3986. delete this.context.labelSet[key];
  3987. statement = new Node.LabeledStatement(id, body);
  3988. }
  3989. else {
  3990. this.consumeSemicolon();
  3991. statement = new Node.ExpressionStatement(expr);
  3992. }
  3993. return this.finalize(node, statement);
  3994. };
  3995. // https://tc39.github.io/ecma262/#sec-throw-statement
  3996. Parser.prototype.parseThrowStatement = function () {
  3997. var node = this.createNode();
  3998. this.expectKeyword('throw');
  3999. if (this.hasLineTerminator) {
  4000. this.throwError(messages_1.Messages.NewlineAfterThrow);
  4001. }
  4002. var argument = this.parseExpression();
  4003. this.consumeSemicolon();
  4004. return this.finalize(node, new Node.ThrowStatement(argument));
  4005. };
  4006. // https://tc39.github.io/ecma262/#sec-try-statement
  4007. Parser.prototype.parseCatchClause = function () {
  4008. var node = this.createNode();
  4009. this.expectKeyword('catch');
  4010. this.expect('(');
  4011. if (this.match(')')) {
  4012. this.throwUnexpectedToken(this.lookahead);
  4013. }
  4014. var params = [];
  4015. var param = this.parsePattern(params);
  4016. var paramMap = {};
  4017. for (var i = 0; i < params.length; i++) {
  4018. var key = '$' + params[i].value;
  4019. if (Object.prototype.hasOwnProperty.call(paramMap, key)) {
  4020. this.tolerateError(messages_1.Messages.DuplicateBinding, params[i].value);
  4021. }
  4022. paramMap[key] = true;
  4023. }
  4024. if (this.context.strict && param.type === syntax_1.Syntax.Identifier) {
  4025. if (this.scanner.isRestrictedWord(param.name)) {
  4026. this.tolerateError(messages_1.Messages.StrictCatchVariable);
  4027. }
  4028. }
  4029. this.expect(')');
  4030. var body = this.parseBlock();
  4031. return this.finalize(node, new Node.CatchClause(param, body));
  4032. };
  4033. Parser.prototype.parseFinallyClause = function () {
  4034. this.expectKeyword('finally');
  4035. return this.parseBlock();
  4036. };
  4037. Parser.prototype.parseTryStatement = function () {
  4038. var node = this.createNode();
  4039. this.expectKeyword('try');
  4040. var block = this.parseBlock();
  4041. var handler = this.matchKeyword('catch') ? this.parseCatchClause() : null;
  4042. var finalizer = this.matchKeyword('finally') ? this.parseFinallyClause() : null;
  4043. if (!handler && !finalizer) {
  4044. this.throwError(messages_1.Messages.NoCatchOrFinally);
  4045. }
  4046. return this.finalize(node, new Node.TryStatement(block, handler, finalizer));
  4047. };
  4048. // https://tc39.github.io/ecma262/#sec-debugger-statement
  4049. Parser.prototype.parseDebuggerStatement = function () {
  4050. var node = this.createNode();
  4051. this.expectKeyword('debugger');
  4052. this.consumeSemicolon();
  4053. return this.finalize(node, new Node.DebuggerStatement());
  4054. };
  4055. // https://tc39.github.io/ecma262/#sec-ecmascript-language-statements-and-declarations
  4056. Parser.prototype.parseStatement = function () {
  4057. var statement;
  4058. switch (this.lookahead.type) {
  4059. case 1 /* BooleanLiteral */:
  4060. case 5 /* NullLiteral */:
  4061. case 6 /* NumericLiteral */:
  4062. case 8 /* StringLiteral */:
  4063. case 10 /* Template */:
  4064. case 9 /* RegularExpression */:
  4065. statement = this.parseExpressionStatement();
  4066. break;
  4067. case 7 /* Punctuator */:
  4068. var value = this.lookahead.value;
  4069. if (value === '{') {
  4070. statement = this.parseBlock();
  4071. }
  4072. else if (value === '(') {
  4073. statement = this.parseExpressionStatement();
  4074. }
  4075. else if (value === ';') {
  4076. statement = this.parseEmptyStatement();
  4077. }
  4078. else {
  4079. statement = this.parseExpressionStatement();
  4080. }
  4081. break;
  4082. case 3 /* Identifier */:
  4083. statement = this.matchAsyncFunction() ? this.parseFunctionDeclaration() : this.parseLabelledStatement();
  4084. break;
  4085. case 4 /* Keyword */:
  4086. switch (this.lookahead.value) {
  4087. case 'break':
  4088. statement = this.parseBreakStatement();
  4089. break;
  4090. case 'continue':
  4091. statement = this.parseContinueStatement();
  4092. break;
  4093. case 'debugger':
  4094. statement = this.parseDebuggerStatement();
  4095. break;
  4096. case 'do':
  4097. statement = this.parseDoWhileStatement();
  4098. break;
  4099. case 'for':
  4100. statement = this.parseForStatement();
  4101. break;
  4102. case 'function':
  4103. statement = this.parseFunctionDeclaration();
  4104. break;
  4105. case 'if':
  4106. statement = this.parseIfStatement();
  4107. break;
  4108. case 'return':
  4109. statement = this.parseReturnStatement();
  4110. break;
  4111. case 'switch':
  4112. statement = this.parseSwitchStatement();
  4113. break;
  4114. case 'throw':
  4115. statement = this.parseThrowStatement();
  4116. break;
  4117. case 'try':
  4118. statement = this.parseTryStatement();
  4119. break;
  4120. case 'var':
  4121. statement = this.parseVariableStatement();
  4122. break;
  4123. case 'while':
  4124. statement = this.parseWhileStatement();
  4125. break;
  4126. case 'with':
  4127. statement = this.parseWithStatement();
  4128. break;
  4129. default:
  4130. statement = this.parseExpressionStatement();
  4131. break;
  4132. }
  4133. break;
  4134. default:
  4135. statement = this.throwUnexpectedToken(this.lookahead);
  4136. }
  4137. return statement;
  4138. };
  4139. // https://tc39.github.io/ecma262/#sec-function-definitions
  4140. Parser.prototype.parseFunctionSourceElements = function () {
  4141. var node = this.createNode();
  4142. this.expect('{');
  4143. var body = this.parseDirectivePrologues();
  4144. var previousLabelSet = this.context.labelSet;
  4145. var previousInIteration = this.context.inIteration;
  4146. var previousInSwitch = this.context.inSwitch;
  4147. var previousInFunctionBody = this.context.inFunctionBody;
  4148. this.context.labelSet = {};
  4149. this.context.inIteration = false;
  4150. this.context.inSwitch = false;
  4151. this.context.inFunctionBody = true;
  4152. while (this.lookahead.type !== 2 /* EOF */) {
  4153. if (this.match('}')) {
  4154. break;
  4155. }
  4156. body.push(this.parseStatementListItem());
  4157. }
  4158. this.expect('}');
  4159. this.context.labelSet = previousLabelSet;
  4160. this.context.inIteration = previousInIteration;
  4161. this.context.inSwitch = previousInSwitch;
  4162. this.context.inFunctionBody = previousInFunctionBody;
  4163. return this.finalize(node, new Node.BlockStatement(body));
  4164. };
  4165. Parser.prototype.validateParam = function (options, param, name) {
  4166. var key = '$' + name;
  4167. if (this.context.strict) {
  4168. if (this.scanner.isRestrictedWord(name)) {
  4169. options.stricted = param;
  4170. options.message = messages_1.Messages.StrictParamName;
  4171. }
  4172. if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {
  4173. options.stricted = param;
  4174. options.message = messages_1.Messages.StrictParamDupe;
  4175. }
  4176. }
  4177. else if (!options.firstRestricted) {
  4178. if (this.scanner.isRestrictedWord(name)) {
  4179. options.firstRestricted = param;
  4180. options.message = messages_1.Messages.StrictParamName;
  4181. }
  4182. else if (this.scanner.isStrictModeReservedWord(name)) {
  4183. options.firstRestricted = param;
  4184. options.message = messages_1.Messages.StrictReservedWord;
  4185. }
  4186. else if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {
  4187. options.stricted = param;
  4188. options.message = messages_1.Messages.StrictParamDupe;
  4189. }
  4190. }
  4191. /* istanbul ignore next */
  4192. if (typeof Object.defineProperty === 'function') {
  4193. Object.defineProperty(options.paramSet, key, { value: true, enumerable: true, writable: true, configurable: true });
  4194. }
  4195. else {
  4196. options.paramSet[key] = true;
  4197. }
  4198. };
  4199. Parser.prototype.parseRestElement = function (params) {
  4200. var node = this.createNode();
  4201. this.expect('...');
  4202. var arg = this.parsePattern(params);
  4203. if (this.match('=')) {
  4204. this.throwError(messages_1.Messages.DefaultRestParameter);
  4205. }
  4206. if (!this.match(')')) {
  4207. this.throwError(messages_1.Messages.ParameterAfterRestParameter);
  4208. }
  4209. return this.finalize(node, new Node.RestElement(arg));
  4210. };
  4211. Parser.prototype.parseFormalParameter = function (options) {
  4212. var params = [];
  4213. var param = this.match('...') ? this.parseRestElement(params) : this.parsePatternWithDefault(params);
  4214. for (var i = 0; i < params.length; i++) {
  4215. this.validateParam(options, params[i], params[i].value);
  4216. }
  4217. options.simple = options.simple && (param instanceof Node.Identifier);
  4218. options.params.push(param);
  4219. };
  4220. Parser.prototype.parseFormalParameters = function (firstRestricted) {
  4221. var options;
  4222. options = {
  4223. simple: true,
  4224. params: [],
  4225. firstRestricted: firstRestricted
  4226. };
  4227. this.expect('(');
  4228. if (!this.match(')')) {
  4229. options.paramSet = {};
  4230. while (this.lookahead.type !== 2 /* EOF */) {
  4231. this.parseFormalParameter(options);
  4232. if (this.match(')')) {
  4233. break;
  4234. }
  4235. this.expect(',');
  4236. if (this.match(')')) {
  4237. break;
  4238. }
  4239. }
  4240. }
  4241. this.expect(')');
  4242. return {
  4243. simple: options.simple,
  4244. params: options.params,
  4245. stricted: options.stricted,
  4246. firstRestricted: options.firstRestricted,
  4247. message: options.message
  4248. };
  4249. };
  4250. Parser.prototype.matchAsyncFunction = function () {
  4251. var match = this.matchContextualKeyword('async');
  4252. if (match) {
  4253. var state = this.scanner.saveState();
  4254. this.scanner.scanComments();
  4255. var next = this.scanner.lex();
  4256. this.scanner.restoreState(state);
  4257. match = (state.lineNumber === next.lineNumber) && (next.type === 4 /* Keyword */) && (next.value === 'function');
  4258. }
  4259. return match;
  4260. };
  4261. Parser.prototype.parseFunctionDeclaration = function (identifierIsOptional) {
  4262. var node = this.createNode();
  4263. var isAsync = this.matchContextualKeyword('async');
  4264. if (isAsync) {
  4265. this.nextToken();
  4266. }
  4267. this.expectKeyword('function');
  4268. var isGenerator = isAsync ? false : this.match('*');
  4269. if (isGenerator) {
  4270. this.nextToken();
  4271. }
  4272. var message;
  4273. var id = null;
  4274. var firstRestricted = null;
  4275. if (!identifierIsOptional || !this.match('(')) {
  4276. var token = this.lookahead;
  4277. id = this.parseVariableIdentifier();
  4278. if (this.context.strict) {
  4279. if (this.scanner.isRestrictedWord(token.value)) {
  4280. this.tolerateUnexpectedToken(token, messages_1.Messages.StrictFunctionName);
  4281. }
  4282. }
  4283. else {
  4284. if (this.scanner.isRestrictedWord(token.value)) {
  4285. firstRestricted = token;
  4286. message = messages_1.Messages.StrictFunctionName;
  4287. }
  4288. else if (this.scanner.isStrictModeReservedWord(token.value)) {
  4289. firstRestricted = token;
  4290. message = messages_1.Messages.StrictReservedWord;
  4291. }
  4292. }
  4293. }
  4294. var previousAllowAwait = this.context.await;
  4295. var previousAllowYield = this.context.allowYield;
  4296. this.context.await = isAsync;
  4297. this.context.allowYield = !isGenerator;
  4298. var formalParameters = this.parseFormalParameters(firstRestricted);
  4299. var params = formalParameters.params;
  4300. var stricted = formalParameters.stricted;
  4301. firstRestricted = formalParameters.firstRestricted;
  4302. if (formalParameters.message) {
  4303. message = formalParameters.message;
  4304. }
  4305. var previousStrict = this.context.strict;
  4306. var previousAllowStrictDirective = this.context.allowStrictDirective;
  4307. this.context.allowStrictDirective = formalParameters.simple;
  4308. var body = this.parseFunctionSourceElements();
  4309. if (this.context.strict && firstRestricted) {
  4310. this.throwUnexpectedToken(firstRestricted, message);
  4311. }
  4312. if (this.context.strict && stricted) {
  4313. this.tolerateUnexpectedToken(stricted, message);
  4314. }
  4315. this.context.strict = previousStrict;
  4316. this.context.allowStrictDirective = previousAllowStrictDirective;
  4317. this.context.await = previousAllowAwait;
  4318. this.context.allowYield = previousAllowYield;
  4319. return isAsync ? this.finalize(node, new Node.AsyncFunctionDeclaration(id, params, body)) :
  4320. this.finalize(node, new Node.FunctionDeclaration(id, params, body, isGenerator));
  4321. };
  4322. Parser.prototype.parseFunctionExpression = function () {
  4323. var node = this.createNode();
  4324. var isAsync = this.matchContextualKeyword('async');
  4325. if (isAsync) {
  4326. this.nextToken();
  4327. }
  4328. this.expectKeyword('function');
  4329. var isGenerator = isAsync ? false : this.match('*');
  4330. if (isGenerator) {
  4331. this.nextToken();
  4332. }
  4333. var message;
  4334. var id = null;
  4335. var firstRestricted;
  4336. var previousAllowAwait = this.context.await;
  4337. var previousAllowYield = this.context.allowYield;
  4338. this.context.await = isAsync;
  4339. this.context.allowYield = !isGenerator;
  4340. if (!this.match('(')) {
  4341. var token = this.lookahead;
  4342. id = (!this.context.strict && !isGenerator && this.matchKeyword('yield')) ? this.parseIdentifierName() : this.parseVariableIdentifier();
  4343. if (this.context.strict) {
  4344. if (this.scanner.isRestrictedWord(token.value)) {
  4345. this.tolerateUnexpectedToken(token, messages_1.Messages.StrictFunctionName);
  4346. }
  4347. }
  4348. else {
  4349. if (this.scanner.isRestrictedWord(token.value)) {
  4350. firstRestricted = token;
  4351. message = messages_1.Messages.StrictFunctionName;
  4352. }
  4353. else if (this.scanner.isStrictModeReservedWord(token.value)) {
  4354. firstRestricted = token;
  4355. message = messages_1.Messages.StrictReservedWord;
  4356. }
  4357. }
  4358. }
  4359. var formalParameters = this.parseFormalParameters(firstRestricted);
  4360. var params = formalParameters.params;
  4361. var stricted = formalParameters.stricted;
  4362. firstRestricted = formalParameters.firstRestricted;
  4363. if (formalParameters.message) {
  4364. message = formalParameters.message;
  4365. }
  4366. var previousStrict = this.context.strict;
  4367. var previousAllowStrictDirective = this.context.allowStrictDirective;
  4368. this.context.allowStrictDirective = formalParameters.simple;
  4369. var body = this.parseFunctionSourceElements();
  4370. if (this.context.strict && firstRestricted) {
  4371. this.throwUnexpectedToken(firstRestricted, message);
  4372. }
  4373. if (this.context.strict && stricted) {
  4374. this.tolerateUnexpectedToken(stricted, message);
  4375. }
  4376. this.context.strict = previousStrict;
  4377. this.context.allowStrictDirective = previousAllowStrictDirective;
  4378. this.context.await = previousAllowAwait;
  4379. this.context.allowYield = previousAllowYield;
  4380. return isAsync ? this.finalize(node, new Node.AsyncFunctionExpression(id, params, body)) :
  4381. this.finalize(node, new Node.FunctionExpression(id, params, body, isGenerator));
  4382. };
  4383. // https://tc39.github.io/ecma262/#sec-directive-prologues-and-the-use-strict-directive
  4384. Parser.prototype.parseDirective = function () {
  4385. var token = this.lookahead;
  4386. var node = this.createNode();
  4387. var expr = this.parseExpression();
  4388. var directive = (expr.type === syntax_1.Syntax.Literal) ? this.getTokenRaw(token).slice(1, -1) : null;
  4389. this.consumeSemicolon();
  4390. return this.finalize(node, directive ? new Node.Directive(expr, directive) : new Node.ExpressionStatement(expr));
  4391. };
  4392. Parser.prototype.parseDirectivePrologues = function () {
  4393. var firstRestricted = null;
  4394. var body = [];
  4395. while (true) {
  4396. var token = this.lookahead;
  4397. if (token.type !== 8 /* StringLiteral */) {
  4398. break;
  4399. }
  4400. var statement = this.parseDirective();
  4401. body.push(statement);
  4402. var directive = statement.directive;
  4403. if (typeof directive !== 'string') {
  4404. break;
  4405. }
  4406. if (directive === 'use strict') {
  4407. this.context.strict = true;
  4408. if (firstRestricted) {
  4409. this.tolerateUnexpectedToken(firstRestricted, messages_1.Messages.StrictOctalLiteral);
  4410. }
  4411. if (!this.context.allowStrictDirective) {
  4412. this.tolerateUnexpectedToken(token, messages_1.Messages.IllegalLanguageModeDirective);
  4413. }
  4414. }
  4415. else {
  4416. if (!firstRestricted && token.octal) {
  4417. firstRestricted = token;
  4418. }
  4419. }
  4420. }
  4421. return body;
  4422. };
  4423. // https://tc39.github.io/ecma262/#sec-method-definitions
  4424. Parser.prototype.qualifiedPropertyName = function (token) {
  4425. switch (token.type) {
  4426. case 3 /* Identifier */:
  4427. case 8 /* StringLiteral */:
  4428. case 1 /* BooleanLiteral */:
  4429. case 5 /* NullLiteral */:
  4430. case 6 /* NumericLiteral */:
  4431. case 4 /* Keyword */:
  4432. return true;
  4433. case 7 /* Punctuator */:
  4434. return token.value === '[';
  4435. default:
  4436. break;
  4437. }
  4438. return false;
  4439. };
  4440. Parser.prototype.parseGetterMethod = function () {
  4441. var node = this.createNode();
  4442. var isGenerator = false;
  4443. var previousAllowYield = this.context.allowYield;
  4444. this.context.allowYield = !isGenerator;
  4445. var formalParameters = this.parseFormalParameters();
  4446. if (formalParameters.params.length > 0) {
  4447. this.tolerateError(messages_1.Messages.BadGetterArity);
  4448. }
  4449. var method = this.parsePropertyMethod(formalParameters);
  4450. this.context.allowYield = previousAllowYield;
  4451. return this.finalize(node, new Node.FunctionExpression(null, formalParameters.params, method, isGenerator));
  4452. };
  4453. Parser.prototype.parseSetterMethod = function () {
  4454. var node = this.createNode();
  4455. var isGenerator = false;
  4456. var previousAllowYield = this.context.allowYield;
  4457. this.context.allowYield = !isGenerator;
  4458. var formalParameters = this.parseFormalParameters();
  4459. if (formalParameters.params.length !== 1) {
  4460. this.tolerateError(messages_1.Messages.BadSetterArity);
  4461. }
  4462. else if (formalParameters.params[0] instanceof Node.RestElement) {
  4463. this.tolerateError(messages_1.Messages.BadSetterRestParameter);
  4464. }
  4465. var method = this.parsePropertyMethod(formalParameters);
  4466. this.context.allowYield = previousAllowYield;
  4467. return this.finalize(node, new Node.FunctionExpression(null, formalParameters.params, method, isGenerator));
  4468. };
  4469. Parser.prototype.parseGeneratorMethod = function () {
  4470. var node = this.createNode();
  4471. var isGenerator = true;
  4472. var previousAllowYield = this.context.allowYield;
  4473. this.context.allowYield = true;
  4474. var params = this.parseFormalParameters();
  4475. this.context.allowYield = false;
  4476. var method = this.parsePropertyMethod(params);
  4477. this.context.allowYield = previousAllowYield;
  4478. return this.finalize(node, new Node.FunctionExpression(null, params.params, method, isGenerator));
  4479. };
  4480. // https://tc39.github.io/ecma262/#sec-generator-function-definitions
  4481. Parser.prototype.isStartOfExpression = function () {
  4482. var start = true;
  4483. var value = this.lookahead.value;
  4484. switch (this.lookahead.type) {
  4485. case 7 /* Punctuator */:
  4486. start = (value === '[') || (value === '(') || (value === '{') ||
  4487. (value === '+') || (value === '-') ||
  4488. (value === '!') || (value === '~') ||
  4489. (value === '++') || (value === '--') ||
  4490. (value === '/') || (value === '/='); // regular expression literal
  4491. break;
  4492. case 4 /* Keyword */:
  4493. start = (value === 'class') || (value === 'delete') ||
  4494. (value === 'function') || (value === 'let') || (value === 'new') ||
  4495. (value === 'super') || (value === 'this') || (value === 'typeof') ||
  4496. (value === 'void') || (value === 'yield');
  4497. break;
  4498. default:
  4499. break;
  4500. }
  4501. return start;
  4502. };
  4503. Parser.prototype.parseYieldExpression = function () {
  4504. var node = this.createNode();
  4505. this.expectKeyword('yield');
  4506. var argument = null;
  4507. var delegate = false;
  4508. if (!this.hasLineTerminator) {
  4509. var previousAllowYield = this.context.allowYield;
  4510. this.context.allowYield = false;
  4511. delegate = this.match('*');
  4512. if (delegate) {
  4513. this.nextToken();
  4514. argument = this.parseAssignmentExpression();
  4515. }
  4516. else if (this.isStartOfExpression()) {
  4517. argument = this.parseAssignmentExpression();
  4518. }
  4519. this.context.allowYield = previousAllowYield;
  4520. }
  4521. return this.finalize(node, new Node.YieldExpression(argument, delegate));
  4522. };
  4523. // https://tc39.github.io/ecma262/#sec-class-definitions
  4524. Parser.prototype.parseClassElement = function (hasConstructor) {
  4525. var token = this.lookahead;
  4526. var node = this.createNode();
  4527. var kind = '';
  4528. var key = null;
  4529. var value = null;
  4530. var computed = false;
  4531. var method = false;
  4532. var isStatic = false;
  4533. var isAsync = false;
  4534. if (this.match('*')) {
  4535. this.nextToken();
  4536. }
  4537. else {
  4538. computed = this.match('[');
  4539. key = this.parseObjectPropertyKey();
  4540. var id = key;
  4541. if (id.name === 'static' && (this.qualifiedPropertyName(this.lookahead) || this.match('*'))) {
  4542. token = this.lookahead;
  4543. isStatic = true;
  4544. computed = this.match('[');
  4545. if (this.match('*')) {
  4546. this.nextToken();
  4547. }
  4548. else {
  4549. key = this.parseObjectPropertyKey();
  4550. }
  4551. }
  4552. if ((token.type === 3 /* Identifier */) && !this.hasLineTerminator && (token.value === 'async')) {
  4553. var punctuator = this.lookahead.value;
  4554. if (punctuator !== ':' && punctuator !== '(' && punctuator !== '*') {
  4555. isAsync = true;
  4556. token = this.lookahead;
  4557. key = this.parseObjectPropertyKey();
  4558. if (token.type === 3 /* Identifier */ && token.value === 'constructor') {
  4559. this.tolerateUnexpectedToken(token, messages_1.Messages.ConstructorIsAsync);
  4560. }
  4561. }
  4562. }
  4563. }
  4564. var lookaheadPropertyKey = this.qualifiedPropertyName(this.lookahead);
  4565. if (token.type === 3 /* Identifier */) {
  4566. if (token.value === 'get' && lookaheadPropertyKey) {
  4567. kind = 'get';
  4568. computed = this.match('[');
  4569. key = this.parseObjectPropertyKey();
  4570. this.context.allowYield = false;
  4571. value = this.parseGetterMethod();
  4572. }
  4573. else if (token.value === 'set' && lookaheadPropertyKey) {
  4574. kind = 'set';
  4575. computed = this.match('[');
  4576. key = this.parseObjectPropertyKey();
  4577. value = this.parseSetterMethod();
  4578. }
  4579. }
  4580. else if (token.type === 7 /* Punctuator */ && token.value === '*' && lookaheadPropertyKey) {
  4581. kind = 'init';
  4582. computed = this.match('[');
  4583. key = this.parseObjectPropertyKey();
  4584. value = this.parseGeneratorMethod();
  4585. method = true;
  4586. }
  4587. if (!kind && key && this.match('(')) {
  4588. kind = 'init';
  4589. value = isAsync ? this.parsePropertyMethodAsyncFunction() : this.parsePropertyMethodFunction();
  4590. method = true;
  4591. }
  4592. if (!kind) {
  4593. this.throwUnexpectedToken(this.lookahead);
  4594. }
  4595. if (kind === 'init') {
  4596. kind = 'method';
  4597. }
  4598. if (!computed) {
  4599. if (isStatic && this.isPropertyKey(key, 'prototype')) {
  4600. this.throwUnexpectedToken(token, messages_1.Messages.StaticPrototype);
  4601. }
  4602. if (!isStatic && this.isPropertyKey(key, 'constructor')) {
  4603. if (kind !== 'method' || !method || (value && value.generator)) {
  4604. this.throwUnexpectedToken(token, messages_1.Messages.ConstructorSpecialMethod);
  4605. }
  4606. if (hasConstructor.value) {
  4607. this.throwUnexpectedToken(token, messages_1.Messages.DuplicateConstructor);
  4608. }
  4609. else {
  4610. hasConstructor.value = true;
  4611. }
  4612. kind = 'constructor';
  4613. }
  4614. }
  4615. return this.finalize(node, new Node.MethodDefinition(key, computed, value, kind, isStatic));
  4616. };
  4617. Parser.prototype.parseClassElementList = function () {
  4618. var body = [];
  4619. var hasConstructor = { value: false };
  4620. this.expect('{');
  4621. while (!this.match('}')) {
  4622. if (this.match(';')) {
  4623. this.nextToken();
  4624. }
  4625. else {
  4626. body.push(this.parseClassElement(hasConstructor));
  4627. }
  4628. }
  4629. this.expect('}');
  4630. return body;
  4631. };
  4632. Parser.prototype.parseClassBody = function () {
  4633. var node = this.createNode();
  4634. var elementList = this.parseClassElementList();
  4635. return this.finalize(node, new Node.ClassBody(elementList));
  4636. };
  4637. Parser.prototype.parseClassDeclaration = function (identifierIsOptional) {
  4638. var node = this.createNode();
  4639. var previousStrict = this.context.strict;
  4640. this.context.strict = true;
  4641. this.expectKeyword('class');
  4642. var id = (identifierIsOptional && (this.lookahead.type !== 3 /* Identifier */)) ? null : this.parseVariableIdentifier();
  4643. var superClass = null;
  4644. if (this.matchKeyword('extends')) {
  4645. this.nextToken();
  4646. superClass = this.isolateCoverGrammar(this.parseLeftHandSideExpressionAllowCall);
  4647. }
  4648. var classBody = this.parseClassBody();
  4649. this.context.strict = previousStrict;
  4650. return this.finalize(node, new Node.ClassDeclaration(id, superClass, classBody));
  4651. };
  4652. Parser.prototype.parseClassExpression = function () {
  4653. var node = this.createNode();
  4654. var previousStrict = this.context.strict;
  4655. this.context.strict = true;
  4656. this.expectKeyword('class');
  4657. var id = (this.lookahead.type === 3 /* Identifier */) ? this.parseVariableIdentifier() : null;
  4658. var superClass = null;
  4659. if (this.matchKeyword('extends')) {
  4660. this.nextToken();
  4661. superClass = this.isolateCoverGrammar(this.parseLeftHandSideExpressionAllowCall);
  4662. }
  4663. var classBody = this.parseClassBody();
  4664. this.context.strict = previousStrict;
  4665. return this.finalize(node, new Node.ClassExpression(id, superClass, classBody));
  4666. };
  4667. // https://tc39.github.io/ecma262/#sec-scripts
  4668. // https://tc39.github.io/ecma262/#sec-modules
  4669. Parser.prototype.parseModule = function () {
  4670. this.context.strict = true;
  4671. this.context.isModule = true;
  4672. this.scanner.isModule = true;
  4673. var node = this.createNode();
  4674. var body = this.parseDirectivePrologues();
  4675. while (this.lookahead.type !== 2 /* EOF */) {
  4676. body.push(this.parseStatementListItem());
  4677. }
  4678. return this.finalize(node, new Node.Module(body));
  4679. };
  4680. Parser.prototype.parseScript = function () {
  4681. var node = this.createNode();
  4682. var body = this.parseDirectivePrologues();
  4683. while (this.lookahead.type !== 2 /* EOF */) {
  4684. body.push(this.parseStatementListItem());
  4685. }
  4686. return this.finalize(node, new Node.Script(body));
  4687. };
  4688. // https://tc39.github.io/ecma262/#sec-imports
  4689. Parser.prototype.parseModuleSpecifier = function () {
  4690. var node = this.createNode();
  4691. if (this.lookahead.type !== 8 /* StringLiteral */) {
  4692. this.throwError(messages_1.Messages.InvalidModuleSpecifier);
  4693. }
  4694. var token = this.nextToken();
  4695. var raw = this.getTokenRaw(token);
  4696. return this.finalize(node, new Node.Literal(token.value, raw));
  4697. };
  4698. // import {<foo as bar>} ...;
  4699. Parser.prototype.parseImportSpecifier = function () {
  4700. var node = this.createNode();
  4701. var imported;
  4702. var local;
  4703. if (this.lookahead.type === 3 /* Identifier */) {
  4704. imported = this.parseVariableIdentifier();
  4705. local = imported;
  4706. if (this.matchContextualKeyword('as')) {
  4707. this.nextToken();
  4708. local = this.parseVariableIdentifier();
  4709. }
  4710. }
  4711. else {
  4712. imported = this.parseIdentifierName();
  4713. local = imported;
  4714. if (this.matchContextualKeyword('as')) {
  4715. this.nextToken();
  4716. local = this.parseVariableIdentifier();
  4717. }
  4718. else {
  4719. this.throwUnexpectedToken(this.nextToken());
  4720. }
  4721. }
  4722. return this.finalize(node, new Node.ImportSpecifier(local, imported));
  4723. };
  4724. // {foo, bar as bas}
  4725. Parser.prototype.parseNamedImports = function () {
  4726. this.expect('{');
  4727. var specifiers = [];
  4728. while (!this.match('}')) {
  4729. specifiers.push(this.parseImportSpecifier());
  4730. if (!this.match('}')) {
  4731. this.expect(',');
  4732. }
  4733. }
  4734. this.expect('}');
  4735. return specifiers;
  4736. };
  4737. // import <foo> ...;
  4738. Parser.prototype.parseImportDefaultSpecifier = function () {
  4739. var node = this.createNode();
  4740. var local = this.parseIdentifierName();
  4741. return this.finalize(node, new Node.ImportDefaultSpecifier(local));
  4742. };
  4743. // import <* as foo> ...;
  4744. Parser.prototype.parseImportNamespaceSpecifier = function () {
  4745. var node = this.createNode();
  4746. this.expect('*');
  4747. if (!this.matchContextualKeyword('as')) {
  4748. this.throwError(messages_1.Messages.NoAsAfterImportNamespace);
  4749. }
  4750. this.nextToken();
  4751. var local = this.parseIdentifierName();
  4752. return this.finalize(node, new Node.ImportNamespaceSpecifier(local));
  4753. };
  4754. Parser.prototype.parseImportDeclaration = function () {
  4755. if (this.context.inFunctionBody) {
  4756. this.throwError(messages_1.Messages.IllegalImportDeclaration);
  4757. }
  4758. var node = this.createNode();
  4759. this.expectKeyword('import');
  4760. var src;
  4761. var specifiers = [];
  4762. if (this.lookahead.type === 8 /* StringLiteral */) {
  4763. // import 'foo';
  4764. src = this.parseModuleSpecifier();
  4765. }
  4766. else {
  4767. if (this.match('{')) {
  4768. // import {bar}
  4769. specifiers = specifiers.concat(this.parseNamedImports());
  4770. }
  4771. else if (this.match('*')) {
  4772. // import * as foo
  4773. specifiers.push(this.parseImportNamespaceSpecifier());
  4774. }
  4775. else if (this.isIdentifierName(this.lookahead) && !this.matchKeyword('default')) {
  4776. // import foo
  4777. specifiers.push(this.parseImportDefaultSpecifier());
  4778. if (this.match(',')) {
  4779. this.nextToken();
  4780. if (this.match('*')) {
  4781. // import foo, * as foo
  4782. specifiers.push(this.parseImportNamespaceSpecifier());
  4783. }
  4784. else if (this.match('{')) {
  4785. // import foo, {bar}
  4786. specifiers = specifiers.concat(this.parseNamedImports());
  4787. }
  4788. else {
  4789. this.throwUnexpectedToken(this.lookahead);
  4790. }
  4791. }
  4792. }
  4793. else {
  4794. this.throwUnexpectedToken(this.nextToken());
  4795. }
  4796. if (!this.matchContextualKeyword('from')) {
  4797. var message = this.lookahead.value ? messages_1.Messages.UnexpectedToken : messages_1.Messages.MissingFromClause;
  4798. this.throwError(message, this.lookahead.value);
  4799. }
  4800. this.nextToken();
  4801. src = this.parseModuleSpecifier();
  4802. }
  4803. this.consumeSemicolon();
  4804. return this.finalize(node, new Node.ImportDeclaration(specifiers, src));
  4805. };
  4806. // https://tc39.github.io/ecma262/#sec-exports
  4807. Parser.prototype.parseExportSpecifier = function () {
  4808. var node = this.createNode();
  4809. var local = this.parseIdentifierName();
  4810. var exported = local;
  4811. if (this.matchContextualKeyword('as')) {
  4812. this.nextToken();
  4813. exported = this.parseIdentifierName();
  4814. }
  4815. return this.finalize(node, new Node.ExportSpecifier(local, exported));
  4816. };
  4817. Parser.prototype.parseExportDeclaration = function () {
  4818. if (this.context.inFunctionBody) {
  4819. this.throwError(messages_1.Messages.IllegalExportDeclaration);
  4820. }
  4821. var node = this.createNode();
  4822. this.expectKeyword('export');
  4823. var exportDeclaration;
  4824. if (this.matchKeyword('default')) {
  4825. // export default ...
  4826. this.nextToken();
  4827. if (this.matchKeyword('function')) {
  4828. // export default function foo () {}
  4829. // export default function () {}
  4830. var declaration = this.parseFunctionDeclaration(true);
  4831. exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration));
  4832. }
  4833. else if (this.matchKeyword('class')) {
  4834. // export default class foo {}
  4835. var declaration = this.parseClassDeclaration(true);
  4836. exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration));
  4837. }
  4838. else if (this.matchContextualKeyword('async')) {
  4839. // export default async function f () {}
  4840. // export default async function () {}
  4841. // export default async x => x
  4842. var declaration = this.matchAsyncFunction() ? this.parseFunctionDeclaration(true) : this.parseAssignmentExpression();
  4843. exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration));
  4844. }
  4845. else {
  4846. if (this.matchContextualKeyword('from')) {
  4847. this.throwError(messages_1.Messages.UnexpectedToken, this.lookahead.value);
  4848. }
  4849. // export default {};
  4850. // export default [];
  4851. // export default (1 + 2);
  4852. var declaration = this.match('{') ? this.parseObjectInitializer() :
  4853. this.match('[') ? this.parseArrayInitializer() : this.parseAssignmentExpression();
  4854. this.consumeSemicolon();
  4855. exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration));
  4856. }
  4857. }
  4858. else if (this.match('*')) {
  4859. // export * from 'foo';
  4860. this.nextToken();
  4861. if (!this.matchContextualKeyword('from')) {
  4862. var message = this.lookahead.value ? messages_1.Messages.UnexpectedToken : messages_1.Messages.MissingFromClause;
  4863. this.throwError(message, this.lookahead.value);
  4864. }
  4865. this.nextToken();
  4866. var src = this.parseModuleSpecifier();
  4867. this.consumeSemicolon();
  4868. exportDeclaration = this.finalize(node, new Node.ExportAllDeclaration(src));
  4869. }
  4870. else if (this.lookahead.type === 4 /* Keyword */) {
  4871. // export var f = 1;
  4872. var declaration = void 0;
  4873. switch (this.lookahead.value) {
  4874. case 'let':
  4875. case 'const':
  4876. declaration = this.parseLexicalDeclaration({ inFor: false });
  4877. break;
  4878. case 'var':
  4879. case 'class':
  4880. case 'function':
  4881. declaration = this.parseStatementListItem();
  4882. break;
  4883. default:
  4884. this.throwUnexpectedToken(this.lookahead);
  4885. }
  4886. exportDeclaration = this.finalize(node, new Node.ExportNamedDeclaration(declaration, [], null));
  4887. }
  4888. else if (this.matchAsyncFunction()) {
  4889. var declaration = this.parseFunctionDeclaration();
  4890. exportDeclaration = this.finalize(node, new Node.ExportNamedDeclaration(declaration, [], null));
  4891. }
  4892. else {
  4893. var specifiers = [];
  4894. var source = null;
  4895. var isExportFromIdentifier = false;
  4896. this.expect('{');
  4897. while (!this.match('}')) {
  4898. isExportFromIdentifier = isExportFromIdentifier || this.matchKeyword('default');
  4899. specifiers.push(this.parseExportSpecifier());
  4900. if (!this.match('}')) {
  4901. this.expect(',');
  4902. }
  4903. }
  4904. this.expect('}');
  4905. if (this.matchContextualKeyword('from')) {
  4906. // export {default} from 'foo';
  4907. // export {foo} from 'foo';
  4908. this.nextToken();
  4909. source = this.parseModuleSpecifier();
  4910. this.consumeSemicolon();
  4911. }
  4912. else if (isExportFromIdentifier) {
  4913. // export {default}; // missing fromClause
  4914. var message = this.lookahead.value ? messages_1.Messages.UnexpectedToken : messages_1.Messages.MissingFromClause;
  4915. this.throwError(message, this.lookahead.value);
  4916. }
  4917. else {
  4918. // export {foo};
  4919. this.consumeSemicolon();
  4920. }
  4921. exportDeclaration = this.finalize(node, new Node.ExportNamedDeclaration(null, specifiers, source));
  4922. }
  4923. return exportDeclaration;
  4924. };
  4925. return Parser;
  4926. }());
  4927. exports.Parser = Parser;
  4928. /***/ },
  4929. /* 9 */
  4930. /***/ function(module, exports) {
  4931. "use strict";
  4932. // Ensure the condition is true, otherwise throw an error.
  4933. // This is only to have a better contract semantic, i.e. another safety net
  4934. // to catch a logic error. The condition shall be fulfilled in normal case.
  4935. // Do NOT use this to enforce a certain condition on any user input.
  4936. Object.defineProperty(exports, "__esModule", { value: true });
  4937. function assert(condition, message) {
  4938. /* istanbul ignore if */
  4939. if (!condition) {
  4940. throw new Error('ASSERT: ' + message);
  4941. }
  4942. }
  4943. exports.assert = assert;
  4944. /***/ },
  4945. /* 10 */
  4946. /***/ function(module, exports) {
  4947. "use strict";
  4948. /* tslint:disable:max-classes-per-file */
  4949. Object.defineProperty(exports, "__esModule", { value: true });
  4950. var ErrorHandler = (function () {
  4951. function ErrorHandler() {
  4952. this.errors = [];
  4953. this.tolerant = false;
  4954. }
  4955. ErrorHandler.prototype.recordError = function (error) {
  4956. this.errors.push(error);
  4957. };
  4958. ErrorHandler.prototype.tolerate = function (error) {
  4959. if (this.tolerant) {
  4960. this.recordError(error);
  4961. }
  4962. else {
  4963. throw error;
  4964. }
  4965. };
  4966. ErrorHandler.prototype.constructError = function (msg, column) {
  4967. var error = new Error(msg);
  4968. try {
  4969. throw error;
  4970. }
  4971. catch (base) {
  4972. /* istanbul ignore else */
  4973. if (Object.create && Object.defineProperty) {
  4974. error = Object.create(base);
  4975. Object.defineProperty(error, 'column', { value: column });
  4976. }
  4977. }
  4978. /* istanbul ignore next */
  4979. return error;
  4980. };
  4981. ErrorHandler.prototype.createError = function (index, line, col, description) {
  4982. var msg = 'Line ' + line + ': ' + description;
  4983. var error = this.constructError(msg, col);
  4984. error.index = index;
  4985. error.lineNumber = line;
  4986. error.description = description;
  4987. return error;
  4988. };
  4989. ErrorHandler.prototype.throwError = function (index, line, col, description) {
  4990. throw this.createError(index, line, col, description);
  4991. };
  4992. ErrorHandler.prototype.tolerateError = function (index, line, col, description) {
  4993. var error = this.createError(index, line, col, description);
  4994. if (this.tolerant) {
  4995. this.recordError(error);
  4996. }
  4997. else {
  4998. throw error;
  4999. }
  5000. };
  5001. return ErrorHandler;
  5002. }());
  5003. exports.ErrorHandler = ErrorHandler;
  5004. /***/ },
  5005. /* 11 */
  5006. /***/ function(module, exports) {
  5007. "use strict";
  5008. Object.defineProperty(exports, "__esModule", { value: true });
  5009. // Error messages should be identical to V8.
  5010. exports.Messages = {
  5011. BadGetterArity: 'Getter must not have any formal parameters',
  5012. BadSetterArity: 'Setter must have exactly one formal parameter',
  5013. BadSetterRestParameter: 'Setter function argument must not be a rest parameter',
  5014. ConstructorIsAsync: 'Class constructor may not be an async method',
  5015. ConstructorSpecialMethod: 'Class constructor may not be an accessor',
  5016. DeclarationMissingInitializer: 'Missing initializer in %0 declaration',
  5017. DefaultRestParameter: 'Unexpected token =',
  5018. DuplicateBinding: 'Duplicate binding %0',
  5019. DuplicateConstructor: 'A class may only have one constructor',
  5020. DuplicateProtoProperty: 'Duplicate __proto__ fields are not allowed in object literals',
  5021. ForInOfLoopInitializer: '%0 loop variable declaration may not have an initializer',
  5022. GeneratorInLegacyContext: 'Generator declarations are not allowed in legacy contexts',
  5023. IllegalBreak: 'Illegal break statement',
  5024. IllegalContinue: 'Illegal continue statement',
  5025. IllegalExportDeclaration: 'Unexpected token',
  5026. IllegalImportDeclaration: 'Unexpected token',
  5027. IllegalLanguageModeDirective: 'Illegal \'use strict\' directive in function with non-simple parameter list',
  5028. IllegalReturn: 'Illegal return statement',
  5029. InvalidEscapedReservedWord: 'Keyword must not contain escaped characters',
  5030. InvalidHexEscapeSequence: 'Invalid hexadecimal escape sequence',
  5031. InvalidLHSInAssignment: 'Invalid left-hand side in assignment',
  5032. InvalidLHSInForIn: 'Invalid left-hand side in for-in',
  5033. InvalidLHSInForLoop: 'Invalid left-hand side in for-loop',
  5034. InvalidModuleSpecifier: 'Unexpected token',
  5035. InvalidRegExp: 'Invalid regular expression',
  5036. LetInLexicalBinding: 'let is disallowed as a lexically bound name',
  5037. MissingFromClause: 'Unexpected token',
  5038. MultipleDefaultsInSwitch: 'More than one default clause in switch statement',
  5039. NewlineAfterThrow: 'Illegal newline after throw',
  5040. NoAsAfterImportNamespace: 'Unexpected token',
  5041. NoCatchOrFinally: 'Missing catch or finally after try',
  5042. ParameterAfterRestParameter: 'Rest parameter must be last formal parameter',
  5043. Redeclaration: '%0 \'%1\' has already been declared',
  5044. StaticPrototype: 'Classes may not have static property named prototype',
  5045. StrictCatchVariable: 'Catch variable may not be eval or arguments in strict mode',
  5046. StrictDelete: 'Delete of an unqualified identifier in strict mode.',
  5047. StrictFunction: 'In strict mode code, functions can only be declared at top level or inside a block',
  5048. StrictFunctionName: 'Function name may not be eval or arguments in strict mode',
  5049. StrictLHSAssignment: 'Assignment to eval or arguments is not allowed in strict mode',
  5050. StrictLHSPostfix: 'Postfix increment/decrement may not have eval or arguments operand in strict mode',
  5051. StrictLHSPrefix: 'Prefix increment/decrement may not have eval or arguments operand in strict mode',
  5052. StrictModeWith: 'Strict mode code may not include a with statement',
  5053. StrictOctalLiteral: 'Octal literals are not allowed in strict mode.',
  5054. StrictParamDupe: 'Strict mode function may not have duplicate parameter names',
  5055. StrictParamName: 'Parameter name eval or arguments is not allowed in strict mode',
  5056. StrictReservedWord: 'Use of future reserved word in strict mode',
  5057. StrictVarName: 'Variable name may not be eval or arguments in strict mode',
  5058. TemplateOctalLiteral: 'Octal literals are not allowed in template strings.',
  5059. UnexpectedEOS: 'Unexpected end of input',
  5060. UnexpectedIdentifier: 'Unexpected identifier',
  5061. UnexpectedNumber: 'Unexpected number',
  5062. UnexpectedReserved: 'Unexpected reserved word',
  5063. UnexpectedString: 'Unexpected string',
  5064. UnexpectedTemplate: 'Unexpected quasi %0',
  5065. UnexpectedToken: 'Unexpected token %0',
  5066. UnexpectedTokenIllegal: 'Unexpected token ILLEGAL',
  5067. UnknownLabel: 'Undefined label \'%0\'',
  5068. UnterminatedRegExp: 'Invalid regular expression: missing /'
  5069. };
  5070. /***/ },
  5071. /* 12 */
  5072. /***/ function(module, exports, __webpack_require__) {
  5073. "use strict";
  5074. Object.defineProperty(exports, "__esModule", { value: true });
  5075. var assert_1 = __webpack_require__(9);
  5076. var character_1 = __webpack_require__(4);
  5077. var messages_1 = __webpack_require__(11);
  5078. function hexValue(ch) {
  5079. return '0123456789abcdef'.indexOf(ch.toLowerCase());
  5080. }
  5081. function octalValue(ch) {
  5082. return '01234567'.indexOf(ch);
  5083. }
  5084. var Scanner = (function () {
  5085. function Scanner(code, handler) {
  5086. this.source = code;
  5087. this.errorHandler = handler;
  5088. this.trackComment = false;
  5089. this.isModule = false;
  5090. this.length = code.length;
  5091. this.index = 0;
  5092. this.lineNumber = (code.length > 0) ? 1 : 0;
  5093. this.lineStart = 0;
  5094. this.curlyStack = [];
  5095. }
  5096. Scanner.prototype.saveState = function () {
  5097. return {
  5098. index: this.index,
  5099. lineNumber: this.lineNumber,
  5100. lineStart: this.lineStart
  5101. };
  5102. };
  5103. Scanner.prototype.restoreState = function (state) {
  5104. this.index = state.index;
  5105. this.lineNumber = state.lineNumber;
  5106. this.lineStart = state.lineStart;
  5107. };
  5108. Scanner.prototype.eof = function () {
  5109. return this.index >= this.length;
  5110. };
  5111. Scanner.prototype.throwUnexpectedToken = function (message) {
  5112. if (message === void 0) { message = messages_1.Messages.UnexpectedTokenIllegal; }
  5113. return this.errorHandler.throwError(this.index, this.lineNumber, this.index - this.lineStart + 1, message);
  5114. };
  5115. Scanner.prototype.tolerateUnexpectedToken = function (message) {
  5116. if (message === void 0) { message = messages_1.Messages.UnexpectedTokenIllegal; }
  5117. this.errorHandler.tolerateError(this.index, this.lineNumber, this.index - this.lineStart + 1, message);
  5118. };
  5119. // https://tc39.github.io/ecma262/#sec-comments
  5120. Scanner.prototype.skipSingleLineComment = function (offset) {
  5121. var comments = [];
  5122. var start, loc;
  5123. if (this.trackComment) {
  5124. comments = [];
  5125. start = this.index - offset;
  5126. loc = {
  5127. start: {
  5128. line: this.lineNumber,
  5129. column: this.index - this.lineStart - offset
  5130. },
  5131. end: {}
  5132. };
  5133. }
  5134. while (!this.eof()) {
  5135. var ch = this.source.charCodeAt(this.index);
  5136. ++this.index;
  5137. if (character_1.Character.isLineTerminator(ch)) {
  5138. if (this.trackComment) {
  5139. loc.end = {
  5140. line: this.lineNumber,
  5141. column: this.index - this.lineStart - 1
  5142. };
  5143. var entry = {
  5144. multiLine: false,
  5145. slice: [start + offset, this.index - 1],
  5146. range: [start, this.index - 1],
  5147. loc: loc
  5148. };
  5149. comments.push(entry);
  5150. }
  5151. if (ch === 13 && this.source.charCodeAt(this.index) === 10) {
  5152. ++this.index;
  5153. }
  5154. ++this.lineNumber;
  5155. this.lineStart = this.index;
  5156. return comments;
  5157. }
  5158. }
  5159. if (this.trackComment) {
  5160. loc.end = {
  5161. line: this.lineNumber,
  5162. column: this.index - this.lineStart
  5163. };
  5164. var entry = {
  5165. multiLine: false,
  5166. slice: [start + offset, this.index],
  5167. range: [start, this.index],
  5168. loc: loc
  5169. };
  5170. comments.push(entry);
  5171. }
  5172. return comments;
  5173. };
  5174. Scanner.prototype.skipMultiLineComment = function () {
  5175. var comments = [];
  5176. var start, loc;
  5177. if (this.trackComment) {
  5178. comments = [];
  5179. start = this.index - 2;
  5180. loc = {
  5181. start: {
  5182. line: this.lineNumber,
  5183. column: this.index - this.lineStart - 2
  5184. },
  5185. end: {}
  5186. };
  5187. }
  5188. while (!this.eof()) {
  5189. var ch = this.source.charCodeAt(this.index);
  5190. if (character_1.Character.isLineTerminator(ch)) {
  5191. if (ch === 0x0D && this.source.charCodeAt(this.index + 1) === 0x0A) {
  5192. ++this.index;
  5193. }
  5194. ++this.lineNumber;
  5195. ++this.index;
  5196. this.lineStart = this.index;
  5197. }
  5198. else if (ch === 0x2A) {
  5199. // Block comment ends with '*/'.
  5200. if (this.source.charCodeAt(this.index + 1) === 0x2F) {
  5201. this.index += 2;
  5202. if (this.trackComment) {
  5203. loc.end = {
  5204. line: this.lineNumber,
  5205. column: this.index - this.lineStart
  5206. };
  5207. var entry = {
  5208. multiLine: true,
  5209. slice: [start + 2, this.index - 2],
  5210. range: [start, this.index],
  5211. loc: loc
  5212. };
  5213. comments.push(entry);
  5214. }
  5215. return comments;
  5216. }
  5217. ++this.index;
  5218. }
  5219. else {
  5220. ++this.index;
  5221. }
  5222. }
  5223. // Ran off the end of the file - the whole thing is a comment
  5224. if (this.trackComment) {
  5225. loc.end = {
  5226. line: this.lineNumber,
  5227. column: this.index - this.lineStart
  5228. };
  5229. var entry = {
  5230. multiLine: true,
  5231. slice: [start + 2, this.index],
  5232. range: [start, this.index],
  5233. loc: loc
  5234. };
  5235. comments.push(entry);
  5236. }
  5237. this.tolerateUnexpectedToken();
  5238. return comments;
  5239. };
  5240. Scanner.prototype.scanComments = function () {
  5241. var comments;
  5242. if (this.trackComment) {
  5243. comments = [];
  5244. }
  5245. var start = (this.index === 0);
  5246. while (!this.eof()) {
  5247. var ch = this.source.charCodeAt(this.index);
  5248. if (character_1.Character.isWhiteSpace(ch)) {
  5249. ++this.index;
  5250. }
  5251. else if (character_1.Character.isLineTerminator(ch)) {
  5252. ++this.index;
  5253. if (ch === 0x0D && this.source.charCodeAt(this.index) === 0x0A) {
  5254. ++this.index;
  5255. }
  5256. ++this.lineNumber;
  5257. this.lineStart = this.index;
  5258. start = true;
  5259. }
  5260. else if (ch === 0x2F) {
  5261. ch = this.source.charCodeAt(this.index + 1);
  5262. if (ch === 0x2F) {
  5263. this.index += 2;
  5264. var comment = this.skipSingleLineComment(2);
  5265. if (this.trackComment) {
  5266. comments = comments.concat(comment);
  5267. }
  5268. start = true;
  5269. }
  5270. else if (ch === 0x2A) {
  5271. this.index += 2;
  5272. var comment = this.skipMultiLineComment();
  5273. if (this.trackComment) {
  5274. comments = comments.concat(comment);
  5275. }
  5276. }
  5277. else {
  5278. break;
  5279. }
  5280. }
  5281. else if (start && ch === 0x2D) {
  5282. // U+003E is '>'
  5283. if ((this.source.charCodeAt(this.index + 1) === 0x2D) && (this.source.charCodeAt(this.index + 2) === 0x3E)) {
  5284. // '-->' is a single-line comment
  5285. this.index += 3;
  5286. var comment = this.skipSingleLineComment(3);
  5287. if (this.trackComment) {
  5288. comments = comments.concat(comment);
  5289. }
  5290. }
  5291. else {
  5292. break;
  5293. }
  5294. }
  5295. else if (ch === 0x3C && !this.isModule) {
  5296. if (this.source.slice(this.index + 1, this.index + 4) === '!--') {
  5297. this.index += 4; // `<!--`
  5298. var comment = this.skipSingleLineComment(4);
  5299. if (this.trackComment) {
  5300. comments = comments.concat(comment);
  5301. }
  5302. }
  5303. else {
  5304. break;
  5305. }
  5306. }
  5307. else {
  5308. break;
  5309. }
  5310. }
  5311. return comments;
  5312. };
  5313. // https://tc39.github.io/ecma262/#sec-future-reserved-words
  5314. Scanner.prototype.isFutureReservedWord = function (id) {
  5315. switch (id) {
  5316. case 'enum':
  5317. case 'export':
  5318. case 'import':
  5319. case 'super':
  5320. return true;
  5321. default:
  5322. return false;
  5323. }
  5324. };
  5325. Scanner.prototype.isStrictModeReservedWord = function (id) {
  5326. switch (id) {
  5327. case 'implements':
  5328. case 'interface':
  5329. case 'package':
  5330. case 'private':
  5331. case 'protected':
  5332. case 'public':
  5333. case 'static':
  5334. case 'yield':
  5335. case 'let':
  5336. return true;
  5337. default:
  5338. return false;
  5339. }
  5340. };
  5341. Scanner.prototype.isRestrictedWord = function (id) {
  5342. return id === 'eval' || id === 'arguments';
  5343. };
  5344. // https://tc39.github.io/ecma262/#sec-keywords
  5345. Scanner.prototype.isKeyword = function (id) {
  5346. switch (id.length) {
  5347. case 2:
  5348. return (id === 'if') || (id === 'in') || (id === 'do');
  5349. case 3:
  5350. return (id === 'var') || (id === 'for') || (id === 'new') ||
  5351. (id === 'try') || (id === 'let');
  5352. case 4:
  5353. return (id === 'this') || (id === 'else') || (id === 'case') ||
  5354. (id === 'void') || (id === 'with') || (id === 'enum');
  5355. case 5:
  5356. return (id === 'while') || (id === 'break') || (id === 'catch') ||
  5357. (id === 'throw') || (id === 'const') || (id === 'yield') ||
  5358. (id === 'class') || (id === 'super');
  5359. case 6:
  5360. return (id === 'return') || (id === 'typeof') || (id === 'delete') ||
  5361. (id === 'switch') || (id === 'export') || (id === 'import');
  5362. case 7:
  5363. return (id === 'default') || (id === 'finally') || (id === 'extends');
  5364. case 8:
  5365. return (id === 'function') || (id === 'continue') || (id === 'debugger');
  5366. case 10:
  5367. return (id === 'instanceof');
  5368. default:
  5369. return false;
  5370. }
  5371. };
  5372. Scanner.prototype.codePointAt = function (i) {
  5373. var cp = this.source.charCodeAt(i);
  5374. if (cp >= 0xD800 && cp <= 0xDBFF) {
  5375. var second = this.source.charCodeAt(i + 1);
  5376. if (second >= 0xDC00 && second <= 0xDFFF) {
  5377. var first = cp;
  5378. cp = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
  5379. }
  5380. }
  5381. return cp;
  5382. };
  5383. Scanner.prototype.scanHexEscape = function (prefix) {
  5384. var len = (prefix === 'u') ? 4 : 2;
  5385. var code = 0;
  5386. for (var i = 0; i < len; ++i) {
  5387. if (!this.eof() && character_1.Character.isHexDigit(this.source.charCodeAt(this.index))) {
  5388. code = code * 16 + hexValue(this.source[this.index++]);
  5389. }
  5390. else {
  5391. return null;
  5392. }
  5393. }
  5394. return String.fromCharCode(code);
  5395. };
  5396. Scanner.prototype.scanUnicodeCodePointEscape = function () {
  5397. var ch = this.source[this.index];
  5398. var code = 0;
  5399. // At least, one hex digit is required.
  5400. if (ch === '}') {
  5401. this.throwUnexpectedToken();
  5402. }
  5403. while (!this.eof()) {
  5404. ch = this.source[this.index++];
  5405. if (!character_1.Character.isHexDigit(ch.charCodeAt(0))) {
  5406. break;
  5407. }
  5408. code = code * 16 + hexValue(ch);
  5409. }
  5410. if (code > 0x10FFFF || ch !== '}') {
  5411. this.throwUnexpectedToken();
  5412. }
  5413. return character_1.Character.fromCodePoint(code);
  5414. };
  5415. Scanner.prototype.getIdentifier = function () {
  5416. var start = this.index++;
  5417. while (!this.eof()) {
  5418. var ch = this.source.charCodeAt(this.index);
  5419. if (ch === 0x5C) {
  5420. // Blackslash (U+005C) marks Unicode escape sequence.
  5421. this.index = start;
  5422. return this.getComplexIdentifier();
  5423. }
  5424. else if (ch >= 0xD800 && ch < 0xDFFF) {
  5425. // Need to handle surrogate pairs.
  5426. this.index = start;
  5427. return this.getComplexIdentifier();
  5428. }
  5429. if (character_1.Character.isIdentifierPart(ch)) {
  5430. ++this.index;
  5431. }
  5432. else {
  5433. break;
  5434. }
  5435. }
  5436. return this.source.slice(start, this.index);
  5437. };
  5438. Scanner.prototype.getComplexIdentifier = function () {
  5439. var cp = this.codePointAt(this.index);
  5440. var id = character_1.Character.fromCodePoint(cp);
  5441. this.index += id.length;
  5442. // '\u' (U+005C, U+0075) denotes an escaped character.
  5443. var ch;
  5444. if (cp === 0x5C) {
  5445. if (this.source.charCodeAt(this.index) !== 0x75) {
  5446. this.throwUnexpectedToken();
  5447. }
  5448. ++this.index;
  5449. if (this.source[this.index] === '{') {
  5450. ++this.index;
  5451. ch = this.scanUnicodeCodePointEscape();
  5452. }
  5453. else {
  5454. ch = this.scanHexEscape('u');
  5455. if (ch === null || ch === '\\' || !character_1.Character.isIdentifierStart(ch.charCodeAt(0))) {
  5456. this.throwUnexpectedToken();
  5457. }
  5458. }
  5459. id = ch;
  5460. }
  5461. while (!this.eof()) {
  5462. cp = this.codePointAt(this.index);
  5463. if (!character_1.Character.isIdentifierPart(cp)) {
  5464. break;
  5465. }
  5466. ch = character_1.Character.fromCodePoint(cp);
  5467. id += ch;
  5468. this.index += ch.length;
  5469. // '\u' (U+005C, U+0075) denotes an escaped character.
  5470. if (cp === 0x5C) {
  5471. id = id.substr(0, id.length - 1);
  5472. if (this.source.charCodeAt(this.index) !== 0x75) {
  5473. this.throwUnexpectedToken();
  5474. }
  5475. ++this.index;
  5476. if (this.source[this.index] === '{') {
  5477. ++this.index;
  5478. ch = this.scanUnicodeCodePointEscape();
  5479. }
  5480. else {
  5481. ch = this.scanHexEscape('u');
  5482. if (ch === null || ch === '\\' || !character_1.Character.isIdentifierPart(ch.charCodeAt(0))) {
  5483. this.throwUnexpectedToken();
  5484. }
  5485. }
  5486. id += ch;
  5487. }
  5488. }
  5489. return id;
  5490. };
  5491. Scanner.prototype.octalToDecimal = function (ch) {
  5492. // \0 is not octal escape sequence
  5493. var octal = (ch !== '0');
  5494. var code = octalValue(ch);
  5495. if (!this.eof() && character_1.Character.isOctalDigit(this.source.charCodeAt(this.index))) {
  5496. octal = true;
  5497. code = code * 8 + octalValue(this.source[this.index++]);
  5498. // 3 digits are only allowed when string starts
  5499. // with 0, 1, 2, 3
  5500. if ('0123'.indexOf(ch) >= 0 && !this.eof() && character_1.Character.isOctalDigit(this.source.charCodeAt(this.index))) {
  5501. code = code * 8 + octalValue(this.source[this.index++]);
  5502. }
  5503. }
  5504. return {
  5505. code: code,
  5506. octal: octal
  5507. };
  5508. };
  5509. // https://tc39.github.io/ecma262/#sec-names-and-keywords
  5510. Scanner.prototype.scanIdentifier = function () {
  5511. var type;
  5512. var start = this.index;
  5513. // Backslash (U+005C) starts an escaped character.
  5514. var id = (this.source.charCodeAt(start) === 0x5C) ? this.getComplexIdentifier() : this.getIdentifier();
  5515. // There is no keyword or literal with only one character.
  5516. // Thus, it must be an identifier.
  5517. if (id.length === 1) {
  5518. type = 3 /* Identifier */;
  5519. }
  5520. else if (this.isKeyword(id)) {
  5521. type = 4 /* Keyword */;
  5522. }
  5523. else if (id === 'null') {
  5524. type = 5 /* NullLiteral */;
  5525. }
  5526. else if (id === 'true' || id === 'false') {
  5527. type = 1 /* BooleanLiteral */;
  5528. }
  5529. else {
  5530. type = 3 /* Identifier */;
  5531. }
  5532. if (type !== 3 /* Identifier */ && (start + id.length !== this.index)) {
  5533. var restore = this.index;
  5534. this.index = start;
  5535. this.tolerateUnexpectedToken(messages_1.Messages.InvalidEscapedReservedWord);
  5536. this.index = restore;
  5537. }
  5538. return {
  5539. type: type,
  5540. value: id,
  5541. lineNumber: this.lineNumber,
  5542. lineStart: this.lineStart,
  5543. start: start,
  5544. end: this.index
  5545. };
  5546. };
  5547. // https://tc39.github.io/ecma262/#sec-punctuators
  5548. Scanner.prototype.scanPunctuator = function () {
  5549. var start = this.index;
  5550. // Check for most common single-character punctuators.
  5551. var str = this.source[this.index];
  5552. switch (str) {
  5553. case '(':
  5554. case '{':
  5555. if (str === '{') {
  5556. this.curlyStack.push('{');
  5557. }
  5558. ++this.index;
  5559. break;
  5560. case '.':
  5561. ++this.index;
  5562. if (this.source[this.index] === '.' && this.source[this.index + 1] === '.') {
  5563. // Spread operator: ...
  5564. this.index += 2;
  5565. str = '...';
  5566. }
  5567. break;
  5568. case '}':
  5569. ++this.index;
  5570. this.curlyStack.pop();
  5571. break;
  5572. case ')':
  5573. case ';':
  5574. case ',':
  5575. case '[':
  5576. case ']':
  5577. case ':':
  5578. case '?':
  5579. case '~':
  5580. ++this.index;
  5581. break;
  5582. default:
  5583. // 4-character punctuator.
  5584. str = this.source.substr(this.index, 4);
  5585. if (str === '>>>=') {
  5586. this.index += 4;
  5587. }
  5588. else {
  5589. // 3-character punctuators.
  5590. str = str.substr(0, 3);
  5591. if (str === '===' || str === '!==' || str === '>>>' ||
  5592. str === '<<=' || str === '>>=' || str === '**=') {
  5593. this.index += 3;
  5594. }
  5595. else {
  5596. // 2-character punctuators.
  5597. str = str.substr(0, 2);
  5598. if (str === '&&' || str === '||' || str === '==' || str === '!=' ||
  5599. str === '+=' || str === '-=' || str === '*=' || str === '/=' ||
  5600. str === '++' || str === '--' || str === '<<' || str === '>>' ||
  5601. str === '&=' || str === '|=' || str === '^=' || str === '%=' ||
  5602. str === '<=' || str === '>=' || str === '=>' || str === '**') {
  5603. this.index += 2;
  5604. }
  5605. else {
  5606. // 1-character punctuators.
  5607. str = this.source[this.index];
  5608. if ('<>=!+-*%&|^/'.indexOf(str) >= 0) {
  5609. ++this.index;
  5610. }
  5611. }
  5612. }
  5613. }
  5614. }
  5615. if (this.index === start) {
  5616. this.throwUnexpectedToken();
  5617. }
  5618. return {
  5619. type: 7 /* Punctuator */,
  5620. value: str,
  5621. lineNumber: this.lineNumber,
  5622. lineStart: this.lineStart,
  5623. start: start,
  5624. end: this.index
  5625. };
  5626. };
  5627. // https://tc39.github.io/ecma262/#sec-literals-numeric-literals
  5628. Scanner.prototype.scanHexLiteral = function (start) {
  5629. var num = '';
  5630. while (!this.eof()) {
  5631. if (!character_1.Character.isHexDigit(this.source.charCodeAt(this.index))) {
  5632. break;
  5633. }
  5634. num += this.source[this.index++];
  5635. }
  5636. if (num.length === 0) {
  5637. this.throwUnexpectedToken();
  5638. }
  5639. if (character_1.Character.isIdentifierStart(this.source.charCodeAt(this.index))) {
  5640. this.throwUnexpectedToken();
  5641. }
  5642. return {
  5643. type: 6 /* NumericLiteral */,
  5644. value: parseInt('0x' + num, 16),
  5645. lineNumber: this.lineNumber,
  5646. lineStart: this.lineStart,
  5647. start: start,
  5648. end: this.index
  5649. };
  5650. };
  5651. Scanner.prototype.scanBinaryLiteral = function (start) {
  5652. var num = '';
  5653. var ch;
  5654. while (!this.eof()) {
  5655. ch = this.source[this.index];
  5656. if (ch !== '0' && ch !== '1') {
  5657. break;
  5658. }
  5659. num += this.source[this.index++];
  5660. }
  5661. if (num.length === 0) {
  5662. // only 0b or 0B
  5663. this.throwUnexpectedToken();
  5664. }
  5665. if (!this.eof()) {
  5666. ch = this.source.charCodeAt(this.index);
  5667. /* istanbul ignore else */
  5668. if (character_1.Character.isIdentifierStart(ch) || character_1.Character.isDecimalDigit(ch)) {
  5669. this.throwUnexpectedToken();
  5670. }
  5671. }
  5672. return {
  5673. type: 6 /* NumericLiteral */,
  5674. value: parseInt(num, 2),
  5675. lineNumber: this.lineNumber,
  5676. lineStart: this.lineStart,
  5677. start: start,
  5678. end: this.index
  5679. };
  5680. };
  5681. Scanner.prototype.scanOctalLiteral = function (prefix, start) {
  5682. var num = '';
  5683. var octal = false;
  5684. if (character_1.Character.isOctalDigit(prefix.charCodeAt(0))) {
  5685. octal = true;
  5686. num = '0' + this.source[this.index++];
  5687. }
  5688. else {
  5689. ++this.index;
  5690. }
  5691. while (!this.eof()) {
  5692. if (!character_1.Character.isOctalDigit(this.source.charCodeAt(this.index))) {
  5693. break;
  5694. }
  5695. num += this.source[this.index++];
  5696. }
  5697. if (!octal && num.length === 0) {
  5698. // only 0o or 0O
  5699. this.throwUnexpectedToken();
  5700. }
  5701. if (character_1.Character.isIdentifierStart(this.source.charCodeAt(this.index)) || character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
  5702. this.throwUnexpectedToken();
  5703. }
  5704. return {
  5705. type: 6 /* NumericLiteral */,
  5706. value: parseInt(num, 8),
  5707. octal: octal,
  5708. lineNumber: this.lineNumber,
  5709. lineStart: this.lineStart,
  5710. start: start,
  5711. end: this.index
  5712. };
  5713. };
  5714. Scanner.prototype.isImplicitOctalLiteral = function () {
  5715. // Implicit octal, unless there is a non-octal digit.
  5716. // (Annex B.1.1 on Numeric Literals)
  5717. for (var i = this.index + 1; i < this.length; ++i) {
  5718. var ch = this.source[i];
  5719. if (ch === '8' || ch === '9') {
  5720. return false;
  5721. }
  5722. if (!character_1.Character.isOctalDigit(ch.charCodeAt(0))) {
  5723. return true;
  5724. }
  5725. }
  5726. return true;
  5727. };
  5728. Scanner.prototype.scanNumericLiteral = function () {
  5729. var start = this.index;
  5730. var ch = this.source[start];
  5731. assert_1.assert(character_1.Character.isDecimalDigit(ch.charCodeAt(0)) || (ch === '.'), 'Numeric literal must start with a decimal digit or a decimal point');
  5732. var num = '';
  5733. if (ch !== '.') {
  5734. num = this.source[this.index++];
  5735. ch = this.source[this.index];
  5736. // Hex number starts with '0x'.
  5737. // Octal number starts with '0'.
  5738. // Octal number in ES6 starts with '0o'.
  5739. // Binary number in ES6 starts with '0b'.
  5740. if (num === '0') {
  5741. if (ch === 'x' || ch === 'X') {
  5742. ++this.index;
  5743. return this.scanHexLiteral(start);
  5744. }
  5745. if (ch === 'b' || ch === 'B') {
  5746. ++this.index;
  5747. return this.scanBinaryLiteral(start);
  5748. }
  5749. if (ch === 'o' || ch === 'O') {
  5750. return this.scanOctalLiteral(ch, start);
  5751. }
  5752. if (ch && character_1.Character.isOctalDigit(ch.charCodeAt(0))) {
  5753. if (this.isImplicitOctalLiteral()) {
  5754. return this.scanOctalLiteral(ch, start);
  5755. }
  5756. }
  5757. }
  5758. while (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
  5759. num += this.source[this.index++];
  5760. }
  5761. ch = this.source[this.index];
  5762. }
  5763. if (ch === '.') {
  5764. num += this.source[this.index++];
  5765. while (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
  5766. num += this.source[this.index++];
  5767. }
  5768. ch = this.source[this.index];
  5769. }
  5770. if (ch === 'e' || ch === 'E') {
  5771. num += this.source[this.index++];
  5772. ch = this.source[this.index];
  5773. if (ch === '+' || ch === '-') {
  5774. num += this.source[this.index++];
  5775. }
  5776. if (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
  5777. while (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
  5778. num += this.source[this.index++];
  5779. }
  5780. }
  5781. else {
  5782. this.throwUnexpectedToken();
  5783. }
  5784. }
  5785. if (character_1.Character.isIdentifierStart(this.source.charCodeAt(this.index))) {
  5786. this.throwUnexpectedToken();
  5787. }
  5788. return {
  5789. type: 6 /* NumericLiteral */,
  5790. value: parseFloat(num),
  5791. lineNumber: this.lineNumber,
  5792. lineStart: this.lineStart,
  5793. start: start,
  5794. end: this.index
  5795. };
  5796. };
  5797. // https://tc39.github.io/ecma262/#sec-literals-string-literals
  5798. Scanner.prototype.scanStringLiteral = function () {
  5799. var start = this.index;
  5800. var quote = this.source[start];
  5801. assert_1.assert((quote === '\'' || quote === '"'), 'String literal must starts with a quote');
  5802. ++this.index;
  5803. var octal = false;
  5804. var str = '';
  5805. while (!this.eof()) {
  5806. var ch = this.source[this.index++];
  5807. if (ch === quote) {
  5808. quote = '';
  5809. break;
  5810. }
  5811. else if (ch === '\\') {
  5812. ch = this.source[this.index++];
  5813. if (!ch || !character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
  5814. switch (ch) {
  5815. case 'u':
  5816. if (this.source[this.index] === '{') {
  5817. ++this.index;
  5818. str += this.scanUnicodeCodePointEscape();
  5819. }
  5820. else {
  5821. var unescaped_1 = this.scanHexEscape(ch);
  5822. if (unescaped_1 === null) {
  5823. this.throwUnexpectedToken();
  5824. }
  5825. str += unescaped_1;
  5826. }
  5827. break;
  5828. case 'x':
  5829. var unescaped = this.scanHexEscape(ch);
  5830. if (unescaped === null) {
  5831. this.throwUnexpectedToken(messages_1.Messages.InvalidHexEscapeSequence);
  5832. }
  5833. str += unescaped;
  5834. break;
  5835. case 'n':
  5836. str += '\n';
  5837. break;
  5838. case 'r':
  5839. str += '\r';
  5840. break;
  5841. case 't':
  5842. str += '\t';
  5843. break;
  5844. case 'b':
  5845. str += '\b';
  5846. break;
  5847. case 'f':
  5848. str += '\f';
  5849. break;
  5850. case 'v':
  5851. str += '\x0B';
  5852. break;
  5853. case '8':
  5854. case '9':
  5855. str += ch;
  5856. this.tolerateUnexpectedToken();
  5857. break;
  5858. default:
  5859. if (ch && character_1.Character.isOctalDigit(ch.charCodeAt(0))) {
  5860. var octToDec = this.octalToDecimal(ch);
  5861. octal = octToDec.octal || octal;
  5862. str += String.fromCharCode(octToDec.code);
  5863. }
  5864. else {
  5865. str += ch;
  5866. }
  5867. break;
  5868. }
  5869. }
  5870. else {
  5871. ++this.lineNumber;
  5872. if (ch === '\r' && this.source[this.index] === '\n') {
  5873. ++this.index;
  5874. }
  5875. this.lineStart = this.index;
  5876. }
  5877. }
  5878. else if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
  5879. break;
  5880. }
  5881. else {
  5882. str += ch;
  5883. }
  5884. }
  5885. if (quote !== '') {
  5886. this.index = start;
  5887. this.throwUnexpectedToken();
  5888. }
  5889. return {
  5890. type: 8 /* StringLiteral */,
  5891. value: str,
  5892. octal: octal,
  5893. lineNumber: this.lineNumber,
  5894. lineStart: this.lineStart,
  5895. start: start,
  5896. end: this.index
  5897. };
  5898. };
  5899. // https://tc39.github.io/ecma262/#sec-template-literal-lexical-components
  5900. Scanner.prototype.scanTemplate = function () {
  5901. var cooked = '';
  5902. var terminated = false;
  5903. var start = this.index;
  5904. var head = (this.source[start] === '`');
  5905. var tail = false;
  5906. var rawOffset = 2;
  5907. ++this.index;
  5908. while (!this.eof()) {
  5909. var ch = this.source[this.index++];
  5910. if (ch === '`') {
  5911. rawOffset = 1;
  5912. tail = true;
  5913. terminated = true;
  5914. break;
  5915. }
  5916. else if (ch === '$') {
  5917. if (this.source[this.index] === '{') {
  5918. this.curlyStack.push('${');
  5919. ++this.index;
  5920. terminated = true;
  5921. break;
  5922. }
  5923. cooked += ch;
  5924. }
  5925. else if (ch === '\\') {
  5926. ch = this.source[this.index++];
  5927. if (!character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
  5928. switch (ch) {
  5929. case 'n':
  5930. cooked += '\n';
  5931. break;
  5932. case 'r':
  5933. cooked += '\r';
  5934. break;
  5935. case 't':
  5936. cooked += '\t';
  5937. break;
  5938. case 'u':
  5939. if (this.source[this.index] === '{') {
  5940. ++this.index;
  5941. cooked += this.scanUnicodeCodePointEscape();
  5942. }
  5943. else {
  5944. var restore = this.index;
  5945. var unescaped_2 = this.scanHexEscape(ch);
  5946. if (unescaped_2 !== null) {
  5947. cooked += unescaped_2;
  5948. }
  5949. else {
  5950. this.index = restore;
  5951. cooked += ch;
  5952. }
  5953. }
  5954. break;
  5955. case 'x':
  5956. var unescaped = this.scanHexEscape(ch);
  5957. if (unescaped === null) {
  5958. this.throwUnexpectedToken(messages_1.Messages.InvalidHexEscapeSequence);
  5959. }
  5960. cooked += unescaped;
  5961. break;
  5962. case 'b':
  5963. cooked += '\b';
  5964. break;
  5965. case 'f':
  5966. cooked += '\f';
  5967. break;
  5968. case 'v':
  5969. cooked += '\v';
  5970. break;
  5971. default:
  5972. if (ch === '0') {
  5973. if (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
  5974. // Illegal: \01 \02 and so on
  5975. this.throwUnexpectedToken(messages_1.Messages.TemplateOctalLiteral);
  5976. }
  5977. cooked += '\0';
  5978. }
  5979. else if (character_1.Character.isOctalDigit(ch.charCodeAt(0))) {
  5980. // Illegal: \1 \2
  5981. this.throwUnexpectedToken(messages_1.Messages.TemplateOctalLiteral);
  5982. }
  5983. else {
  5984. cooked += ch;
  5985. }
  5986. break;
  5987. }
  5988. }
  5989. else {
  5990. ++this.lineNumber;
  5991. if (ch === '\r' && this.source[this.index] === '\n') {
  5992. ++this.index;
  5993. }
  5994. this.lineStart = this.index;
  5995. }
  5996. }
  5997. else if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
  5998. ++this.lineNumber;
  5999. if (ch === '\r' && this.source[this.index] === '\n') {
  6000. ++this.index;
  6001. }
  6002. this.lineStart = this.index;
  6003. cooked += '\n';
  6004. }
  6005. else {
  6006. cooked += ch;
  6007. }
  6008. }
  6009. if (!terminated) {
  6010. this.throwUnexpectedToken();
  6011. }
  6012. if (!head) {
  6013. this.curlyStack.pop();
  6014. }
  6015. return {
  6016. type: 10 /* Template */,
  6017. value: this.source.slice(start + 1, this.index - rawOffset),
  6018. cooked: cooked,
  6019. head: head,
  6020. tail: tail,
  6021. lineNumber: this.lineNumber,
  6022. lineStart: this.lineStart,
  6023. start: start,
  6024. end: this.index
  6025. };
  6026. };
  6027. // https://tc39.github.io/ecma262/#sec-literals-regular-expression-literals
  6028. Scanner.prototype.testRegExp = function (pattern, flags) {
  6029. // The BMP character to use as a replacement for astral symbols when
  6030. // translating an ES6 "u"-flagged pattern to an ES5-compatible
  6031. // approximation.
  6032. // Note: replacing with '\uFFFF' enables false positives in unlikely
  6033. // scenarios. For example, `[\u{1044f}-\u{10440}]` is an invalid
  6034. // pattern that would not be detected by this substitution.
  6035. var astralSubstitute = '\uFFFF';
  6036. var tmp = pattern;
  6037. var self = this;
  6038. if (flags.indexOf('u') >= 0) {
  6039. tmp = tmp
  6040. .replace(/\\u\{([0-9a-fA-F]+)\}|\\u([a-fA-F0-9]{4})/g, function ($0, $1, $2) {
  6041. var codePoint = parseInt($1 || $2, 16);
  6042. if (codePoint > 0x10FFFF) {
  6043. self.throwUnexpectedToken(messages_1.Messages.InvalidRegExp);
  6044. }
  6045. if (codePoint <= 0xFFFF) {
  6046. return String.fromCharCode(codePoint);
  6047. }
  6048. return astralSubstitute;
  6049. })
  6050. .replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g, astralSubstitute);
  6051. }
  6052. // First, detect invalid regular expressions.
  6053. try {
  6054. RegExp(tmp);
  6055. }
  6056. catch (e) {
  6057. this.throwUnexpectedToken(messages_1.Messages.InvalidRegExp);
  6058. }
  6059. // Return a regular expression object for this pattern-flag pair, or
  6060. // `null` in case the current environment doesn't support the flags it
  6061. // uses.
  6062. try {
  6063. return new RegExp(pattern, flags);
  6064. }
  6065. catch (exception) {
  6066. /* istanbul ignore next */
  6067. return null;
  6068. }
  6069. };
  6070. Scanner.prototype.scanRegExpBody = function () {
  6071. var ch = this.source[this.index];
  6072. assert_1.assert(ch === '/', 'Regular expression literal must start with a slash');
  6073. var str = this.source[this.index++];
  6074. var classMarker = false;
  6075. var terminated = false;
  6076. while (!this.eof()) {
  6077. ch = this.source[this.index++];
  6078. str += ch;
  6079. if (ch === '\\') {
  6080. ch = this.source[this.index++];
  6081. // https://tc39.github.io/ecma262/#sec-literals-regular-expression-literals
  6082. if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
  6083. this.throwUnexpectedToken(messages_1.Messages.UnterminatedRegExp);
  6084. }
  6085. str += ch;
  6086. }
  6087. else if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
  6088. this.throwUnexpectedToken(messages_1.Messages.UnterminatedRegExp);
  6089. }
  6090. else if (classMarker) {
  6091. if (ch === ']') {
  6092. classMarker = false;
  6093. }
  6094. }
  6095. else {
  6096. if (ch === '/') {
  6097. terminated = true;
  6098. break;
  6099. }
  6100. else if (ch === '[') {
  6101. classMarker = true;
  6102. }
  6103. }
  6104. }
  6105. if (!terminated) {
  6106. this.throwUnexpectedToken(messages_1.Messages.UnterminatedRegExp);
  6107. }
  6108. // Exclude leading and trailing slash.
  6109. return str.substr(1, str.length - 2);
  6110. };
  6111. Scanner.prototype.scanRegExpFlags = function () {
  6112. var str = '';
  6113. var flags = '';
  6114. while (!this.eof()) {
  6115. var ch = this.source[this.index];
  6116. if (!character_1.Character.isIdentifierPart(ch.charCodeAt(0))) {
  6117. break;
  6118. }
  6119. ++this.index;
  6120. if (ch === '\\' && !this.eof()) {
  6121. ch = this.source[this.index];
  6122. if (ch === 'u') {
  6123. ++this.index;
  6124. var restore = this.index;
  6125. var char = this.scanHexEscape('u');
  6126. if (char !== null) {
  6127. flags += char;
  6128. for (str += '\\u'; restore < this.index; ++restore) {
  6129. str += this.source[restore];
  6130. }
  6131. }
  6132. else {
  6133. this.index = restore;
  6134. flags += 'u';
  6135. str += '\\u';
  6136. }
  6137. this.tolerateUnexpectedToken();
  6138. }
  6139. else {
  6140. str += '\\';
  6141. this.tolerateUnexpectedToken();
  6142. }
  6143. }
  6144. else {
  6145. flags += ch;
  6146. str += ch;
  6147. }
  6148. }
  6149. return flags;
  6150. };
  6151. Scanner.prototype.scanRegExp = function () {
  6152. var start = this.index;
  6153. var pattern = this.scanRegExpBody();
  6154. var flags = this.scanRegExpFlags();
  6155. var value = this.testRegExp(pattern, flags);
  6156. return {
  6157. type: 9 /* RegularExpression */,
  6158. value: '',
  6159. pattern: pattern,
  6160. flags: flags,
  6161. regex: value,
  6162. lineNumber: this.lineNumber,
  6163. lineStart: this.lineStart,
  6164. start: start,
  6165. end: this.index
  6166. };
  6167. };
  6168. Scanner.prototype.lex = function () {
  6169. if (this.eof()) {
  6170. return {
  6171. type: 2 /* EOF */,
  6172. value: '',
  6173. lineNumber: this.lineNumber,
  6174. lineStart: this.lineStart,
  6175. start: this.index,
  6176. end: this.index
  6177. };
  6178. }
  6179. var cp = this.source.charCodeAt(this.index);
  6180. if (character_1.Character.isIdentifierStart(cp)) {
  6181. return this.scanIdentifier();
  6182. }
  6183. // Very common: ( and ) and ;
  6184. if (cp === 0x28 || cp === 0x29 || cp === 0x3B) {
  6185. return this.scanPunctuator();
  6186. }
  6187. // String literal starts with single quote (U+0027) or double quote (U+0022).
  6188. if (cp === 0x27 || cp === 0x22) {
  6189. return this.scanStringLiteral();
  6190. }
  6191. // Dot (.) U+002E can also start a floating-point number, hence the need
  6192. // to check the next character.
  6193. if (cp === 0x2E) {
  6194. if (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index + 1))) {
  6195. return this.scanNumericLiteral();
  6196. }
  6197. return this.scanPunctuator();
  6198. }
  6199. if (character_1.Character.isDecimalDigit(cp)) {
  6200. return this.scanNumericLiteral();
  6201. }
  6202. // Template literals start with ` (U+0060) for template head
  6203. // or } (U+007D) for template middle or template tail.
  6204. if (cp === 0x60 || (cp === 0x7D && this.curlyStack[this.curlyStack.length - 1] === '${')) {
  6205. return this.scanTemplate();
  6206. }
  6207. // Possible identifier start in a surrogate pair.
  6208. if (cp >= 0xD800 && cp < 0xDFFF) {
  6209. if (character_1.Character.isIdentifierStart(this.codePointAt(this.index))) {
  6210. return this.scanIdentifier();
  6211. }
  6212. }
  6213. return this.scanPunctuator();
  6214. };
  6215. return Scanner;
  6216. }());
  6217. exports.Scanner = Scanner;
  6218. /***/ },
  6219. /* 13 */
  6220. /***/ function(module, exports) {
  6221. "use strict";
  6222. Object.defineProperty(exports, "__esModule", { value: true });
  6223. exports.TokenName = {};
  6224. exports.TokenName[1 /* BooleanLiteral */] = 'Boolean';
  6225. exports.TokenName[2 /* EOF */] = '<end>';
  6226. exports.TokenName[3 /* Identifier */] = 'Identifier';
  6227. exports.TokenName[4 /* Keyword */] = 'Keyword';
  6228. exports.TokenName[5 /* NullLiteral */] = 'Null';
  6229. exports.TokenName[6 /* NumericLiteral */] = 'Numeric';
  6230. exports.TokenName[7 /* Punctuator */] = 'Punctuator';
  6231. exports.TokenName[8 /* StringLiteral */] = 'String';
  6232. exports.TokenName[9 /* RegularExpression */] = 'RegularExpression';
  6233. exports.TokenName[10 /* Template */] = 'Template';
  6234. /***/ },
  6235. /* 14 */
  6236. /***/ function(module, exports) {
  6237. "use strict";
  6238. // Generated by generate-xhtml-entities.js. DO NOT MODIFY!
  6239. Object.defineProperty(exports, "__esModule", { value: true });
  6240. exports.XHTMLEntities = {
  6241. quot: '\u0022',
  6242. amp: '\u0026',
  6243. apos: '\u0027',
  6244. gt: '\u003E',
  6245. nbsp: '\u00A0',
  6246. iexcl: '\u00A1',
  6247. cent: '\u00A2',
  6248. pound: '\u00A3',
  6249. curren: '\u00A4',
  6250. yen: '\u00A5',
  6251. brvbar: '\u00A6',
  6252. sect: '\u00A7',
  6253. uml: '\u00A8',
  6254. copy: '\u00A9',
  6255. ordf: '\u00AA',
  6256. laquo: '\u00AB',
  6257. not: '\u00AC',
  6258. shy: '\u00AD',
  6259. reg: '\u00AE',
  6260. macr: '\u00AF',
  6261. deg: '\u00B0',
  6262. plusmn: '\u00B1',
  6263. sup2: '\u00B2',
  6264. sup3: '\u00B3',
  6265. acute: '\u00B4',
  6266. micro: '\u00B5',
  6267. para: '\u00B6',
  6268. middot: '\u00B7',
  6269. cedil: '\u00B8',
  6270. sup1: '\u00B9',
  6271. ordm: '\u00BA',
  6272. raquo: '\u00BB',
  6273. frac14: '\u00BC',
  6274. frac12: '\u00BD',
  6275. frac34: '\u00BE',
  6276. iquest: '\u00BF',
  6277. Agrave: '\u00C0',
  6278. Aacute: '\u00C1',
  6279. Acirc: '\u00C2',
  6280. Atilde: '\u00C3',
  6281. Auml: '\u00C4',
  6282. Aring: '\u00C5',
  6283. AElig: '\u00C6',
  6284. Ccedil: '\u00C7',
  6285. Egrave: '\u00C8',
  6286. Eacute: '\u00C9',
  6287. Ecirc: '\u00CA',
  6288. Euml: '\u00CB',
  6289. Igrave: '\u00CC',
  6290. Iacute: '\u00CD',
  6291. Icirc: '\u00CE',
  6292. Iuml: '\u00CF',
  6293. ETH: '\u00D0',
  6294. Ntilde: '\u00D1',
  6295. Ograve: '\u00D2',
  6296. Oacute: '\u00D3',
  6297. Ocirc: '\u00D4',
  6298. Otilde: '\u00D5',
  6299. Ouml: '\u00D6',
  6300. times: '\u00D7',
  6301. Oslash: '\u00D8',
  6302. Ugrave: '\u00D9',
  6303. Uacute: '\u00DA',
  6304. Ucirc: '\u00DB',
  6305. Uuml: '\u00DC',
  6306. Yacute: '\u00DD',
  6307. THORN: '\u00DE',
  6308. szlig: '\u00DF',
  6309. agrave: '\u00E0',
  6310. aacute: '\u00E1',
  6311. acirc: '\u00E2',
  6312. atilde: '\u00E3',
  6313. auml: '\u00E4',
  6314. aring: '\u00E5',
  6315. aelig: '\u00E6',
  6316. ccedil: '\u00E7',
  6317. egrave: '\u00E8',
  6318. eacute: '\u00E9',
  6319. ecirc: '\u00EA',
  6320. euml: '\u00EB',
  6321. igrave: '\u00EC',
  6322. iacute: '\u00ED',
  6323. icirc: '\u00EE',
  6324. iuml: '\u00EF',
  6325. eth: '\u00F0',
  6326. ntilde: '\u00F1',
  6327. ograve: '\u00F2',
  6328. oacute: '\u00F3',
  6329. ocirc: '\u00F4',
  6330. otilde: '\u00F5',
  6331. ouml: '\u00F6',
  6332. divide: '\u00F7',
  6333. oslash: '\u00F8',
  6334. ugrave: '\u00F9',
  6335. uacute: '\u00FA',
  6336. ucirc: '\u00FB',
  6337. uuml: '\u00FC',
  6338. yacute: '\u00FD',
  6339. thorn: '\u00FE',
  6340. yuml: '\u00FF',
  6341. OElig: '\u0152',
  6342. oelig: '\u0153',
  6343. Scaron: '\u0160',
  6344. scaron: '\u0161',
  6345. Yuml: '\u0178',
  6346. fnof: '\u0192',
  6347. circ: '\u02C6',
  6348. tilde: '\u02DC',
  6349. Alpha: '\u0391',
  6350. Beta: '\u0392',
  6351. Gamma: '\u0393',
  6352. Delta: '\u0394',
  6353. Epsilon: '\u0395',
  6354. Zeta: '\u0396',
  6355. Eta: '\u0397',
  6356. Theta: '\u0398',
  6357. Iota: '\u0399',
  6358. Kappa: '\u039A',
  6359. Lambda: '\u039B',
  6360. Mu: '\u039C',
  6361. Nu: '\u039D',
  6362. Xi: '\u039E',
  6363. Omicron: '\u039F',
  6364. Pi: '\u03A0',
  6365. Rho: '\u03A1',
  6366. Sigma: '\u03A3',
  6367. Tau: '\u03A4',
  6368. Upsilon: '\u03A5',
  6369. Phi: '\u03A6',
  6370. Chi: '\u03A7',
  6371. Psi: '\u03A8',
  6372. Omega: '\u03A9',
  6373. alpha: '\u03B1',
  6374. beta: '\u03B2',
  6375. gamma: '\u03B3',
  6376. delta: '\u03B4',
  6377. epsilon: '\u03B5',
  6378. zeta: '\u03B6',
  6379. eta: '\u03B7',
  6380. theta: '\u03B8',
  6381. iota: '\u03B9',
  6382. kappa: '\u03BA',
  6383. lambda: '\u03BB',
  6384. mu: '\u03BC',
  6385. nu: '\u03BD',
  6386. xi: '\u03BE',
  6387. omicron: '\u03BF',
  6388. pi: '\u03C0',
  6389. rho: '\u03C1',
  6390. sigmaf: '\u03C2',
  6391. sigma: '\u03C3',
  6392. tau: '\u03C4',
  6393. upsilon: '\u03C5',
  6394. phi: '\u03C6',
  6395. chi: '\u03C7',
  6396. psi: '\u03C8',
  6397. omega: '\u03C9',
  6398. thetasym: '\u03D1',
  6399. upsih: '\u03D2',
  6400. piv: '\u03D6',
  6401. ensp: '\u2002',
  6402. emsp: '\u2003',
  6403. thinsp: '\u2009',
  6404. zwnj: '\u200C',
  6405. zwj: '\u200D',
  6406. lrm: '\u200E',
  6407. rlm: '\u200F',
  6408. ndash: '\u2013',
  6409. mdash: '\u2014',
  6410. lsquo: '\u2018',
  6411. rsquo: '\u2019',
  6412. sbquo: '\u201A',
  6413. ldquo: '\u201C',
  6414. rdquo: '\u201D',
  6415. bdquo: '\u201E',
  6416. dagger: '\u2020',
  6417. Dagger: '\u2021',
  6418. bull: '\u2022',
  6419. hellip: '\u2026',
  6420. permil: '\u2030',
  6421. prime: '\u2032',
  6422. Prime: '\u2033',
  6423. lsaquo: '\u2039',
  6424. rsaquo: '\u203A',
  6425. oline: '\u203E',
  6426. frasl: '\u2044',
  6427. euro: '\u20AC',
  6428. image: '\u2111',
  6429. weierp: '\u2118',
  6430. real: '\u211C',
  6431. trade: '\u2122',
  6432. alefsym: '\u2135',
  6433. larr: '\u2190',
  6434. uarr: '\u2191',
  6435. rarr: '\u2192',
  6436. darr: '\u2193',
  6437. harr: '\u2194',
  6438. crarr: '\u21B5',
  6439. lArr: '\u21D0',
  6440. uArr: '\u21D1',
  6441. rArr: '\u21D2',
  6442. dArr: '\u21D3',
  6443. hArr: '\u21D4',
  6444. forall: '\u2200',
  6445. part: '\u2202',
  6446. exist: '\u2203',
  6447. empty: '\u2205',
  6448. nabla: '\u2207',
  6449. isin: '\u2208',
  6450. notin: '\u2209',
  6451. ni: '\u220B',
  6452. prod: '\u220F',
  6453. sum: '\u2211',
  6454. minus: '\u2212',
  6455. lowast: '\u2217',
  6456. radic: '\u221A',
  6457. prop: '\u221D',
  6458. infin: '\u221E',
  6459. ang: '\u2220',
  6460. and: '\u2227',
  6461. or: '\u2228',
  6462. cap: '\u2229',
  6463. cup: '\u222A',
  6464. int: '\u222B',
  6465. there4: '\u2234',
  6466. sim: '\u223C',
  6467. cong: '\u2245',
  6468. asymp: '\u2248',
  6469. ne: '\u2260',
  6470. equiv: '\u2261',
  6471. le: '\u2264',
  6472. ge: '\u2265',
  6473. sub: '\u2282',
  6474. sup: '\u2283',
  6475. nsub: '\u2284',
  6476. sube: '\u2286',
  6477. supe: '\u2287',
  6478. oplus: '\u2295',
  6479. otimes: '\u2297',
  6480. perp: '\u22A5',
  6481. sdot: '\u22C5',
  6482. lceil: '\u2308',
  6483. rceil: '\u2309',
  6484. lfloor: '\u230A',
  6485. rfloor: '\u230B',
  6486. loz: '\u25CA',
  6487. spades: '\u2660',
  6488. clubs: '\u2663',
  6489. hearts: '\u2665',
  6490. diams: '\u2666',
  6491. lang: '\u27E8',
  6492. rang: '\u27E9'
  6493. };
  6494. /***/ },
  6495. /* 15 */
  6496. /***/ function(module, exports, __webpack_require__) {
  6497. "use strict";
  6498. Object.defineProperty(exports, "__esModule", { value: true });
  6499. var error_handler_1 = __webpack_require__(10);
  6500. var scanner_1 = __webpack_require__(12);
  6501. var token_1 = __webpack_require__(13);
  6502. var Reader = (function () {
  6503. function Reader() {
  6504. this.values = [];
  6505. this.curly = this.paren = -1;
  6506. }
  6507. // A function following one of those tokens is an expression.
  6508. Reader.prototype.beforeFunctionExpression = function (t) {
  6509. return ['(', '{', '[', 'in', 'typeof', 'instanceof', 'new',
  6510. 'return', 'case', 'delete', 'throw', 'void',
  6511. // assignment operators
  6512. '=', '+=', '-=', '*=', '**=', '/=', '%=', '<<=', '>>=', '>>>=',
  6513. '&=', '|=', '^=', ',',
  6514. // binary/unary operators
  6515. '+', '-', '*', '**', '/', '%', '++', '--', '<<', '>>', '>>>', '&',
  6516. '|', '^', '!', '~', '&&', '||', '?', ':', '===', '==', '>=',
  6517. '<=', '<', '>', '!=', '!=='].indexOf(t) >= 0;
  6518. };
  6519. // Determine if forward slash (/) is an operator or part of a regular expression
  6520. // https://github.com/mozilla/sweet.js/wiki/design
  6521. Reader.prototype.isRegexStart = function () {
  6522. var previous = this.values[this.values.length - 1];
  6523. var regex = (previous !== null);
  6524. switch (previous) {
  6525. case 'this':
  6526. case ']':
  6527. regex = false;
  6528. break;
  6529. case ')':
  6530. var keyword = this.values[this.paren - 1];
  6531. regex = (keyword === 'if' || keyword === 'while' || keyword === 'for' || keyword === 'with');
  6532. break;
  6533. case '}':
  6534. // Dividing a function by anything makes little sense,
  6535. // but we have to check for that.
  6536. regex = false;
  6537. if (this.values[this.curly - 3] === 'function') {
  6538. // Anonymous function, e.g. function(){} /42
  6539. var check = this.values[this.curly - 4];
  6540. regex = check ? !this.beforeFunctionExpression(check) : false;
  6541. }
  6542. else if (this.values[this.curly - 4] === 'function') {
  6543. // Named function, e.g. function f(){} /42/
  6544. var check = this.values[this.curly - 5];
  6545. regex = check ? !this.beforeFunctionExpression(check) : true;
  6546. }
  6547. break;
  6548. default:
  6549. break;
  6550. }
  6551. return regex;
  6552. };
  6553. Reader.prototype.push = function (token) {
  6554. if (token.type === 7 /* Punctuator */ || token.type === 4 /* Keyword */) {
  6555. if (token.value === '{') {
  6556. this.curly = this.values.length;
  6557. }
  6558. else if (token.value === '(') {
  6559. this.paren = this.values.length;
  6560. }
  6561. this.values.push(token.value);
  6562. }
  6563. else {
  6564. this.values.push(null);
  6565. }
  6566. };
  6567. return Reader;
  6568. }());
  6569. var Tokenizer = (function () {
  6570. function Tokenizer(code, config) {
  6571. this.errorHandler = new error_handler_1.ErrorHandler();
  6572. this.errorHandler.tolerant = config ? (typeof config.tolerant === 'boolean' && config.tolerant) : false;
  6573. this.scanner = new scanner_1.Scanner(code, this.errorHandler);
  6574. this.scanner.trackComment = config ? (typeof config.comment === 'boolean' && config.comment) : false;
  6575. this.trackRange = config ? (typeof config.range === 'boolean' && config.range) : false;
  6576. this.trackLoc = config ? (typeof config.loc === 'boolean' && config.loc) : false;
  6577. this.buffer = [];
  6578. this.reader = new Reader();
  6579. }
  6580. Tokenizer.prototype.errors = function () {
  6581. return this.errorHandler.errors;
  6582. };
  6583. Tokenizer.prototype.getNextToken = function () {
  6584. if (this.buffer.length === 0) {
  6585. var comments = this.scanner.scanComments();
  6586. if (this.scanner.trackComment) {
  6587. for (var i = 0; i < comments.length; ++i) {
  6588. var e = comments[i];
  6589. var value = this.scanner.source.slice(e.slice[0], e.slice[1]);
  6590. var comment = {
  6591. type: e.multiLine ? 'BlockComment' : 'LineComment',
  6592. value: value
  6593. };
  6594. if (this.trackRange) {
  6595. comment.range = e.range;
  6596. }
  6597. if (this.trackLoc) {
  6598. comment.loc = e.loc;
  6599. }
  6600. this.buffer.push(comment);
  6601. }
  6602. }
  6603. if (!this.scanner.eof()) {
  6604. var loc = void 0;
  6605. if (this.trackLoc) {
  6606. loc = {
  6607. start: {
  6608. line: this.scanner.lineNumber,
  6609. column: this.scanner.index - this.scanner.lineStart
  6610. },
  6611. end: {}
  6612. };
  6613. }
  6614. var startRegex = (this.scanner.source[this.scanner.index] === '/') && this.reader.isRegexStart();
  6615. var token = startRegex ? this.scanner.scanRegExp() : this.scanner.lex();
  6616. this.reader.push(token);
  6617. var entry = {
  6618. type: token_1.TokenName[token.type],
  6619. value: this.scanner.source.slice(token.start, token.end)
  6620. };
  6621. if (this.trackRange) {
  6622. entry.range = [token.start, token.end];
  6623. }
  6624. if (this.trackLoc) {
  6625. loc.end = {
  6626. line: this.scanner.lineNumber,
  6627. column: this.scanner.index - this.scanner.lineStart
  6628. };
  6629. entry.loc = loc;
  6630. }
  6631. if (token.type === 9 /* RegularExpression */) {
  6632. var pattern = token.pattern;
  6633. var flags = token.flags;
  6634. entry.regex = { pattern: pattern, flags: flags };
  6635. }
  6636. this.buffer.push(entry);
  6637. }
  6638. }
  6639. return this.buffer.shift();
  6640. };
  6641. return Tokenizer;
  6642. }());
  6643. exports.Tokenizer = Tokenizer;
  6644. /***/ }
  6645. /******/ ])
  6646. });
  6647. ;