25 | | module.exports = { |
26 | | asciiIdentifierStartTable: identifierStartTable, |
27 | | asciiIdentifierPartTable: identifierPartTable |
| 32 | /******/ // Execute the module function |
| 33 | /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); |
| 34 | |
| 35 | /******/ // Flag the module as loaded |
| 36 | /******/ module.loaded = true; |
| 37 | |
| 38 | /******/ // Return the exports of the module |
| 39 | /******/ return module.exports; |
| 40 | /******/ } |
| 41 | |
| 42 | |
| 43 | /******/ // expose the modules object (__webpack_modules__) |
| 44 | /******/ __webpack_require__.m = modules; |
| 45 | |
| 46 | /******/ // expose the module cache |
| 47 | /******/ __webpack_require__.c = installedModules; |
| 48 | |
| 49 | /******/ // __webpack_public_path__ |
| 50 | /******/ __webpack_require__.p = ""; |
| 51 | |
| 52 | /******/ // Load entry module and return exports |
| 53 | /******/ return __webpack_require__(0); |
| 54 | /******/ }) |
| 55 | /************************************************************************/ |
| 56 | /******/ ([ |
| 57 | /* 0 */ |
| 58 | /***/ function(module, exports, __webpack_require__) { |
| 59 | |
| 60 | "use strict"; |
| 61 | /* |
| 62 | Copyright JS Foundation and other contributors, https://js.foundation/ |
| 63 | |
| 64 | Redistribution and use in source and binary forms, with or without |
| 65 | modification, are permitted provided that the following conditions are met: |
| 66 | |
| 67 | * Redistributions of source code must retain the above copyright |
| 68 | notice, this list of conditions and the following disclaimer. |
| 69 | * Redistributions in binary form must reproduce the above copyright |
| 70 | notice, this list of conditions and the following disclaimer in the |
| 71 | documentation and/or other materials provided with the distribution. |
| 72 | |
| 73 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 74 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 75 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 76 | ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY |
| 77 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 78 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 79 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 80 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 81 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 82 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 83 | */ |
| 84 | Object.defineProperty(exports, "__esModule", { value: true }); |
| 85 | var comment_handler_1 = __webpack_require__(1); |
| 86 | var jsx_parser_1 = __webpack_require__(3); |
| 87 | var parser_1 = __webpack_require__(8); |
| 88 | var tokenizer_1 = __webpack_require__(15); |
| 89 | function parse(code, options, delegate) { |
| 90 | var commentHandler = null; |
| 91 | var proxyDelegate = function (node, metadata) { |
| 92 | if (delegate) { |
| 93 | delegate(node, metadata); |
| 94 | } |
| 95 | if (commentHandler) { |
| 96 | commentHandler.visit(node, metadata); |
| 97 | } |
| 98 | }; |
| 99 | var parserDelegate = (typeof delegate === 'function') ? proxyDelegate : null; |
| 100 | var collectComment = false; |
| 101 | if (options) { |
| 102 | collectComment = (typeof options.comment === 'boolean' && options.comment); |
| 103 | var attachComment = (typeof options.attachComment === 'boolean' && options.attachComment); |
| 104 | if (collectComment || attachComment) { |
| 105 | commentHandler = new comment_handler_1.CommentHandler(); |
| 106 | commentHandler.attach = attachComment; |
| 107 | options.comment = true; |
| 108 | parserDelegate = proxyDelegate; |
| 109 | } |
| 110 | } |
| 111 | var isModule = false; |
| 112 | if (options && typeof options.sourceType === 'string') { |
| 113 | isModule = (options.sourceType === 'module'); |
| 114 | } |
| 115 | var parser; |
| 116 | if (options && typeof options.jsx === 'boolean' && options.jsx) { |
| 117 | parser = new jsx_parser_1.JSXParser(code, options, parserDelegate); |
| 118 | } |
| 119 | else { |
| 120 | parser = new parser_1.Parser(code, options, parserDelegate); |
| 121 | } |
| 122 | var program = isModule ? parser.parseModule() : parser.parseScript(); |
| 123 | var ast = program; |
| 124 | if (collectComment && commentHandler) { |
| 125 | ast.comments = commentHandler.comments; |
| 126 | } |
| 127 | if (parser.config.tokens) { |
| 128 | ast.tokens = parser.tokens; |
| 129 | } |
| 130 | if (parser.config.tolerant) { |
| 131 | ast.errors = parser.errorHandler.errors; |
| 132 | } |
| 133 | return ast; |
| 134 | } |
| 135 | exports.parse = parse; |
| 136 | function parseModule(code, options, delegate) { |
| 137 | var parsingOptions = options || {}; |
| 138 | parsingOptions.sourceType = 'module'; |
| 139 | return parse(code, parsingOptions, delegate); |
| 140 | } |
| 141 | exports.parseModule = parseModule; |
| 142 | function parseScript(code, options, delegate) { |
| 143 | var parsingOptions = options || {}; |
| 144 | parsingOptions.sourceType = 'script'; |
| 145 | return parse(code, parsingOptions, delegate); |
| 146 | } |
| 147 | exports.parseScript = parseScript; |
| 148 | function tokenize(code, options, delegate) { |
| 149 | var tokenizer = new tokenizer_1.Tokenizer(code, options); |
| 150 | var tokens; |
| 151 | tokens = []; |
| 152 | try { |
| 153 | while (true) { |
| 154 | var token = tokenizer.getNextToken(); |
| 155 | if (!token) { |
| 156 | break; |
| 157 | } |
| 158 | if (delegate) { |
| 159 | token = delegate(token); |
| 160 | } |
| 161 | tokens.push(token); |
| 162 | } |
| 163 | } |
| 164 | catch (e) { |
| 165 | tokenizer.errorHandler.tolerate(e); |
| 166 | } |
| 167 | if (tokenizer.errorHandler.tolerant) { |
| 168 | tokens.errors = tokenizer.errors(); |
| 169 | } |
| 170 | return tokens; |
| 171 | } |
| 172 | exports.tokenize = tokenize; |
| 173 | var syntax_1 = __webpack_require__(2); |
| 174 | exports.Syntax = syntax_1.Syntax; |
| 175 | // Sync with *.json manifests. |
| 176 | exports.version = '4.0.0'; |
| 177 | |
| 178 | |
| 179 | /***/ }, |
| 180 | /* 1 */ |
| 181 | /***/ function(module, exports, __webpack_require__) { |
| 182 | |
| 183 | "use strict"; |
| 184 | Object.defineProperty(exports, "__esModule", { value: true }); |
| 185 | var syntax_1 = __webpack_require__(2); |
| 186 | var CommentHandler = (function () { |
| 187 | function CommentHandler() { |
| 188 | this.attach = false; |
| 189 | this.comments = []; |
| 190 | this.stack = []; |
| 191 | this.leading = []; |
| 192 | this.trailing = []; |
| 193 | } |
| 194 | CommentHandler.prototype.insertInnerComments = function (node, metadata) { |
| 195 | // innnerComments for properties empty block |
| 196 | // `function a() {/** comments **\/}` |
| 197 | if (node.type === syntax_1.Syntax.BlockStatement && node.body.length === 0) { |
| 198 | var innerComments = []; |
| 199 | for (var i = this.leading.length - 1; i >= 0; --i) { |
| 200 | var entry = this.leading[i]; |
| 201 | if (metadata.end.offset >= entry.start) { |
| 202 | innerComments.unshift(entry.comment); |
| 203 | this.leading.splice(i, 1); |
| 204 | this.trailing.splice(i, 1); |
| 205 | } |
| 206 | } |
| 207 | if (innerComments.length) { |
| 208 | node.innerComments = innerComments; |
| 209 | } |
| 210 | } |
| 211 | }; |
| 212 | CommentHandler.prototype.findTrailingComments = function (metadata) { |
| 213 | var trailingComments = []; |
| 214 | if (this.trailing.length > 0) { |
| 215 | for (var i = this.trailing.length - 1; i >= 0; --i) { |
| 216 | var entry_1 = this.trailing[i]; |
| 217 | if (entry_1.start >= metadata.end.offset) { |
| 218 | trailingComments.unshift(entry_1.comment); |
| 219 | } |
| 220 | } |
| 221 | this.trailing.length = 0; |
| 222 | return trailingComments; |
| 223 | } |
| 224 | var entry = this.stack[this.stack.length - 1]; |
| 225 | if (entry && entry.node.trailingComments) { |
| 226 | var firstComment = entry.node.trailingComments[0]; |
| 227 | if (firstComment && firstComment.range[0] >= metadata.end.offset) { |
| 228 | trailingComments = entry.node.trailingComments; |
| 229 | delete entry.node.trailingComments; |
| 230 | } |
| 231 | } |
| 232 | return trailingComments; |
| 233 | }; |
| 234 | CommentHandler.prototype.findLeadingComments = function (metadata) { |
| 235 | var leadingComments = []; |
| 236 | var target; |
| 237 | while (this.stack.length > 0) { |
| 238 | var entry = this.stack[this.stack.length - 1]; |
| 239 | if (entry && entry.start >= metadata.start.offset) { |
| 240 | target = entry.node; |
| 241 | this.stack.pop(); |
| 242 | } |
| 243 | else { |
| 244 | break; |
| 245 | } |
| 246 | } |
| 247 | if (target) { |
| 248 | var count = target.leadingComments ? target.leadingComments.length : 0; |
| 249 | for (var i = count - 1; i >= 0; --i) { |
| 250 | var comment = target.leadingComments[i]; |
| 251 | if (comment.range[1] <= metadata.start.offset) { |
| 252 | leadingComments.unshift(comment); |
| 253 | target.leadingComments.splice(i, 1); |
| 254 | } |
| 255 | } |
| 256 | if (target.leadingComments && target.leadingComments.length === 0) { |
| 257 | delete target.leadingComments; |
| 258 | } |
| 259 | return leadingComments; |
| 260 | } |
| 261 | for (var i = this.leading.length - 1; i >= 0; --i) { |
| 262 | var entry = this.leading[i]; |
| 263 | if (entry.start <= metadata.start.offset) { |
| 264 | leadingComments.unshift(entry.comment); |
| 265 | this.leading.splice(i, 1); |
| 266 | } |
| 267 | } |
| 268 | return leadingComments; |
| 269 | }; |
| 270 | CommentHandler.prototype.visitNode = function (node, metadata) { |
| 271 | if (node.type === syntax_1.Syntax.Program && node.body.length > 0) { |
| 272 | return; |
| 273 | } |
| 274 | this.insertInnerComments(node, metadata); |
| 275 | var trailingComments = this.findTrailingComments(metadata); |
| 276 | var leadingComments = this.findLeadingComments(metadata); |
| 277 | if (leadingComments.length > 0) { |
| 278 | node.leadingComments = leadingComments; |
| 279 | } |
| 280 | if (trailingComments.length > 0) { |
| 281 | node.trailingComments = trailingComments; |
| 282 | } |
| 283 | this.stack.push({ |
| 284 | node: node, |
| 285 | start: metadata.start.offset |
| 286 | }); |
| 287 | }; |
| 288 | CommentHandler.prototype.visitComment = function (node, metadata) { |
| 289 | var type = (node.type[0] === 'L') ? 'Line' : 'Block'; |
| 290 | var comment = { |
| 291 | type: type, |
| 292 | value: node.value |
| 293 | }; |
| 294 | if (node.range) { |
| 295 | comment.range = node.range; |
| 296 | } |
| 297 | if (node.loc) { |
| 298 | comment.loc = node.loc; |
| 299 | } |
| 300 | this.comments.push(comment); |
| 301 | if (this.attach) { |
| 302 | var entry = { |
| 303 | comment: { |
| 304 | type: type, |
| 305 | value: node.value, |
| 306 | range: [metadata.start.offset, metadata.end.offset] |
| 307 | }, |
| 308 | start: metadata.start.offset |
| 309 | }; |
| 310 | if (node.loc) { |
| 311 | entry.comment.loc = node.loc; |
| 312 | } |
| 313 | node.type = type; |
| 314 | this.leading.push(entry); |
| 315 | this.trailing.push(entry); |
| 316 | } |
| 317 | }; |
| 318 | CommentHandler.prototype.visit = function (node, metadata) { |
| 319 | if (node.type === 'LineComment') { |
| 320 | this.visitComment(node, metadata); |
| 321 | } |
| 322 | else if (node.type === 'BlockComment') { |
| 323 | this.visitComment(node, metadata); |
| 324 | } |
| 325 | else if (this.attach) { |
| 326 | this.visitNode(node, metadata); |
| 327 | } |
| 328 | }; |
| 329 | return CommentHandler; |
| 330 | }()); |
| 331 | exports.CommentHandler = CommentHandler; |
| 332 | |
| 333 | |
| 334 | /***/ }, |
| 335 | /* 2 */ |
| 336 | /***/ function(module, exports) { |
| 337 | |
| 338 | "use strict"; |
| 339 | Object.defineProperty(exports, "__esModule", { value: true }); |
| 340 | exports.Syntax = { |
| 341 | AssignmentExpression: 'AssignmentExpression', |
| 342 | AssignmentPattern: 'AssignmentPattern', |
| 343 | ArrayExpression: 'ArrayExpression', |
| 344 | ArrayPattern: 'ArrayPattern', |
| 345 | ArrowFunctionExpression: 'ArrowFunctionExpression', |
| 346 | AwaitExpression: 'AwaitExpression', |
| 347 | BlockStatement: 'BlockStatement', |
| 348 | BinaryExpression: 'BinaryExpression', |
| 349 | BreakStatement: 'BreakStatement', |
| 350 | CallExpression: 'CallExpression', |
| 351 | CatchClause: 'CatchClause', |
| 352 | ClassBody: 'ClassBody', |
| 353 | ClassDeclaration: 'ClassDeclaration', |
| 354 | ClassExpression: 'ClassExpression', |
| 355 | ConditionalExpression: 'ConditionalExpression', |
| 356 | ContinueStatement: 'ContinueStatement', |
| 357 | DoWhileStatement: 'DoWhileStatement', |
| 358 | DebuggerStatement: 'DebuggerStatement', |
| 359 | EmptyStatement: 'EmptyStatement', |
| 360 | ExportAllDeclaration: 'ExportAllDeclaration', |
| 361 | ExportDefaultDeclaration: 'ExportDefaultDeclaration', |
| 362 | ExportNamedDeclaration: 'ExportNamedDeclaration', |
| 363 | ExportSpecifier: 'ExportSpecifier', |
| 364 | ExpressionStatement: 'ExpressionStatement', |
| 365 | ForStatement: 'ForStatement', |
| 366 | ForOfStatement: 'ForOfStatement', |
| 367 | ForInStatement: 'ForInStatement', |
| 368 | FunctionDeclaration: 'FunctionDeclaration', |
| 369 | FunctionExpression: 'FunctionExpression', |
| 370 | Identifier: 'Identifier', |
| 371 | IfStatement: 'IfStatement', |
| 372 | ImportDeclaration: 'ImportDeclaration', |
| 373 | ImportDefaultSpecifier: 'ImportDefaultSpecifier', |
| 374 | ImportNamespaceSpecifier: 'ImportNamespaceSpecifier', |
| 375 | ImportSpecifier: 'ImportSpecifier', |
| 376 | Literal: 'Literal', |
| 377 | LabeledStatement: 'LabeledStatement', |
| 378 | LogicalExpression: 'LogicalExpression', |
| 379 | MemberExpression: 'MemberExpression', |
| 380 | MetaProperty: 'MetaProperty', |
| 381 | MethodDefinition: 'MethodDefinition', |
| 382 | NewExpression: 'NewExpression', |
| 383 | ObjectExpression: 'ObjectExpression', |
| 384 | ObjectPattern: 'ObjectPattern', |
| 385 | Program: 'Program', |
| 386 | Property: 'Property', |
| 387 | RestElement: 'RestElement', |
| 388 | ReturnStatement: 'ReturnStatement', |
| 389 | SequenceExpression: 'SequenceExpression', |
| 390 | SpreadElement: 'SpreadElement', |
| 391 | Super: 'Super', |
| 392 | SwitchCase: 'SwitchCase', |
| 393 | SwitchStatement: 'SwitchStatement', |
| 394 | TaggedTemplateExpression: 'TaggedTemplateExpression', |
| 395 | TemplateElement: 'TemplateElement', |
| 396 | TemplateLiteral: 'TemplateLiteral', |
| 397 | ThisExpression: 'ThisExpression', |
| 398 | ThrowStatement: 'ThrowStatement', |
| 399 | TryStatement: 'TryStatement', |
| 400 | UnaryExpression: 'UnaryExpression', |
| 401 | UpdateExpression: 'UpdateExpression', |
| 402 | VariableDeclaration: 'VariableDeclaration', |
| 403 | VariableDeclarator: 'VariableDeclarator', |
| 404 | WhileStatement: 'WhileStatement', |
| 405 | WithStatement: 'WithStatement', |
| 406 | YieldExpression: 'YieldExpression' |
| 407 | }; |
| 408 | |
| 409 | |
| 410 | /***/ }, |
| 411 | /* 3 */ |
| 412 | /***/ function(module, exports, __webpack_require__) { |
| 413 | |
| 414 | "use strict"; |
| 415 | /* istanbul ignore next */ |
| 416 | var __extends = (this && this.__extends) || (function () { |
| 417 | var extendStatics = Object.setPrototypeOf || |
| 418 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || |
| 419 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; |
| 420 | return function (d, b) { |
| 421 | extendStatics(d, b); |
| 422 | function __() { this.constructor = d; } |
| 423 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); |
| 424 | }; |
| 425 | })(); |
| 426 | Object.defineProperty(exports, "__esModule", { value: true }); |
| 427 | var character_1 = __webpack_require__(4); |
| 428 | var JSXNode = __webpack_require__(5); |
| 429 | var jsx_syntax_1 = __webpack_require__(6); |
| 430 | var Node = __webpack_require__(7); |
| 431 | var parser_1 = __webpack_require__(8); |
| 432 | var token_1 = __webpack_require__(13); |
| 433 | var xhtml_entities_1 = __webpack_require__(14); |
| 434 | token_1.TokenName[100 /* Identifier */] = 'JSXIdentifier'; |
| 435 | token_1.TokenName[101 /* Text */] = 'JSXText'; |
| 436 | // Fully qualified element name, e.g. <svg:path> returns "svg:path" |
| 437 | function getQualifiedElementName(elementName) { |
| 438 | var qualifiedName; |
| 439 | switch (elementName.type) { |
| 440 | case jsx_syntax_1.JSXSyntax.JSXIdentifier: |
| 441 | var id = elementName; |
| 442 | qualifiedName = id.name; |
| 443 | break; |
| 444 | case jsx_syntax_1.JSXSyntax.JSXNamespacedName: |
| 445 | var ns = elementName; |
| 446 | qualifiedName = getQualifiedElementName(ns.namespace) + ':' + |
| 447 | getQualifiedElementName(ns.name); |
| 448 | break; |
| 449 | case jsx_syntax_1.JSXSyntax.JSXMemberExpression: |
| 450 | var expr = elementName; |
| 451 | qualifiedName = getQualifiedElementName(expr.object) + '.' + |
| 452 | getQualifiedElementName(expr.property); |
| 453 | break; |
| 454 | /* istanbul ignore next */ |
| 455 | default: |
| 456 | break; |
| 457 | } |
| 458 | return qualifiedName; |
| 459 | } |
| 460 | var JSXParser = (function (_super) { |
| 461 | __extends(JSXParser, _super); |
| 462 | function JSXParser(code, options, delegate) { |
| 463 | return _super.call(this, code, options, delegate) || this; |
| 464 | } |
| 465 | JSXParser.prototype.parsePrimaryExpression = function () { |
| 466 | return this.match('<') ? this.parseJSXRoot() : _super.prototype.parsePrimaryExpression.call(this); |
| 467 | }; |
| 468 | JSXParser.prototype.startJSX = function () { |
| 469 | // Unwind the scanner before the lookahead token. |
| 470 | this.scanner.index = this.startMarker.index; |
| 471 | this.scanner.lineNumber = this.startMarker.line; |
| 472 | this.scanner.lineStart = this.startMarker.index - this.startMarker.column; |
| 473 | }; |
| 474 | JSXParser.prototype.finishJSX = function () { |
| 475 | // Prime the next lookahead. |
| 476 | this.nextToken(); |
| 477 | }; |
| 478 | JSXParser.prototype.reenterJSX = function () { |
| 479 | this.startJSX(); |
| 480 | this.expectJSX('}'); |
| 481 | // Pop the closing '}' added from the lookahead. |
| 482 | if (this.config.tokens) { |
| 483 | this.tokens.pop(); |
| 484 | } |
| 485 | }; |
| 486 | JSXParser.prototype.createJSXNode = function () { |
| 487 | this.collectComments(); |
| 488 | return { |
| 489 | index: this.scanner.index, |
| 490 | line: this.scanner.lineNumber, |
| 491 | column: this.scanner.index - this.scanner.lineStart |
| 492 | }; |
| 493 | }; |
| 494 | JSXParser.prototype.createJSXChildNode = function () { |
| 495 | return { |
| 496 | index: this.scanner.index, |
| 497 | line: this.scanner.lineNumber, |
| 498 | column: this.scanner.index - this.scanner.lineStart |
| 499 | }; |
| 500 | }; |
| 501 | JSXParser.prototype.scanXHTMLEntity = function (quote) { |
| 502 | var result = '&'; |
| 503 | var valid = true; |
| 504 | var terminated = false; |
| 505 | var numeric = false; |
| 506 | var hex = false; |
| 507 | while (!this.scanner.eof() && valid && !terminated) { |
| 508 | var ch = this.scanner.source[this.scanner.index]; |
| 509 | if (ch === quote) { |
| 510 | break; |
| 511 | } |
| 512 | terminated = (ch === ';'); |
| 513 | result += ch; |
| 514 | ++this.scanner.index; |
| 515 | if (!terminated) { |
| 516 | switch (result.length) { |
| 517 | case 2: |
| 518 | // e.g. '{' |
| 519 | numeric = (ch === '#'); |
| 520 | break; |
| 521 | case 3: |
| 522 | if (numeric) { |
| 523 | // e.g. 'A' |
| 524 | hex = (ch === 'x'); |
| 525 | valid = hex || character_1.Character.isDecimalDigit(ch.charCodeAt(0)); |
| 526 | numeric = numeric && !hex; |
| 527 | } |
| 528 | break; |
| 529 | default: |
| 530 | valid = valid && !(numeric && !character_1.Character.isDecimalDigit(ch.charCodeAt(0))); |
| 531 | valid = valid && !(hex && !character_1.Character.isHexDigit(ch.charCodeAt(0))); |
| 532 | break; |
| 533 | } |
| 534 | } |
| 535 | } |
| 536 | if (valid && terminated && result.length > 2) { |
| 537 | // e.g. 'A' becomes just '#x41' |
| 538 | var str = result.substr(1, result.length - 2); |
| 539 | if (numeric && str.length > 1) { |
| 540 | result = String.fromCharCode(parseInt(str.substr(1), 10)); |
| 541 | } |
| 542 | else if (hex && str.length > 2) { |
| 543 | result = String.fromCharCode(parseInt('0' + str.substr(1), 16)); |
| 544 | } |
| 545 | else if (!numeric && !hex && xhtml_entities_1.XHTMLEntities[str]) { |
| 546 | result = xhtml_entities_1.XHTMLEntities[str]; |
| 547 | } |
| 548 | } |
| 549 | return result; |
| 550 | }; |
| 551 | // Scan the next JSX token. This replaces Scanner#lex when in JSX mode. |
| 552 | JSXParser.prototype.lexJSX = function () { |
| 553 | var cp = this.scanner.source.charCodeAt(this.scanner.index); |
| 554 | // < > / : = { } |
| 555 | if (cp === 60 || cp === 62 || cp === 47 || cp === 58 || cp === 61 || cp === 123 || cp === 125) { |
| 556 | var value = this.scanner.source[this.scanner.index++]; |
| 557 | return { |
| 558 | type: 7 /* Punctuator */, |
| 559 | value: value, |
| 560 | lineNumber: this.scanner.lineNumber, |
| 561 | lineStart: this.scanner.lineStart, |
| 562 | start: this.scanner.index - 1, |
| 563 | end: this.scanner.index |
| 564 | }; |
| 565 | } |
| 566 | // " ' |
| 567 | if (cp === 34 || cp === 39) { |
| 568 | var start = this.scanner.index; |
| 569 | var quote = this.scanner.source[this.scanner.index++]; |
| 570 | var str = ''; |
| 571 | while (!this.scanner.eof()) { |
| 572 | var ch = this.scanner.source[this.scanner.index++]; |
| 573 | if (ch === quote) { |
| 574 | break; |
| 575 | } |
| 576 | else if (ch === '&') { |
| 577 | str += this.scanXHTMLEntity(quote); |
| 578 | } |
| 579 | else { |
| 580 | str += ch; |
| 581 | } |
| 582 | } |
| 583 | return { |
| 584 | type: 8 /* StringLiteral */, |
| 585 | value: str, |
| 586 | lineNumber: this.scanner.lineNumber, |
| 587 | lineStart: this.scanner.lineStart, |
| 588 | start: start, |
| 589 | end: this.scanner.index |
| 590 | }; |
| 591 | } |
| 592 | // ... or . |
| 593 | if (cp === 46) { |
| 594 | var n1 = this.scanner.source.charCodeAt(this.scanner.index + 1); |
| 595 | var n2 = this.scanner.source.charCodeAt(this.scanner.index + 2); |
| 596 | var value = (n1 === 46 && n2 === 46) ? '...' : '.'; |
| 597 | var start = this.scanner.index; |
| 598 | this.scanner.index += value.length; |
| 599 | return { |
| 600 | type: 7 /* Punctuator */, |
| 601 | value: value, |
| 602 | lineNumber: this.scanner.lineNumber, |
| 603 | lineStart: this.scanner.lineStart, |
| 604 | start: start, |
| 605 | end: this.scanner.index |
| 606 | }; |
| 607 | } |
| 608 | // ` |
| 609 | if (cp === 96) { |
| 610 | // Only placeholder, since it will be rescanned as a real assignment expression. |
| 611 | return { |
| 612 | type: 10 /* Template */, |
| 613 | value: '', |
| 614 | lineNumber: this.scanner.lineNumber, |
| 615 | lineStart: this.scanner.lineStart, |
| 616 | start: this.scanner.index, |
| 617 | end: this.scanner.index |
| 618 | }; |
| 619 | } |
| 620 | // Identifer can not contain backslash (char code 92). |
| 621 | if (character_1.Character.isIdentifierStart(cp) && (cp !== 92)) { |
| 622 | var start = this.scanner.index; |
| 623 | ++this.scanner.index; |
| 624 | while (!this.scanner.eof()) { |
| 625 | var ch = this.scanner.source.charCodeAt(this.scanner.index); |
| 626 | if (character_1.Character.isIdentifierPart(ch) && (ch !== 92)) { |
| 627 | ++this.scanner.index; |
| 628 | } |
| 629 | else if (ch === 45) { |
| 630 | // Hyphen (char code 45) can be part of an identifier. |
| 631 | ++this.scanner.index; |
| 632 | } |
| 633 | else { |
| 634 | break; |
| 635 | } |
| 636 | } |
| 637 | var id = this.scanner.source.slice(start, this.scanner.index); |
| 638 | return { |
| 639 | type: 100 /* Identifier */, |
| 640 | value: id, |
| 641 | lineNumber: this.scanner.lineNumber, |
| 642 | lineStart: this.scanner.lineStart, |
| 643 | start: start, |
| 644 | end: this.scanner.index |
| 645 | }; |
| 646 | } |
| 647 | return this.scanner.lex(); |
| 648 | }; |
| 649 | JSXParser.prototype.nextJSXToken = function () { |
| 650 | this.collectComments(); |
| 651 | this.startMarker.index = this.scanner.index; |
| 652 | this.startMarker.line = this.scanner.lineNumber; |
| 653 | this.startMarker.column = this.scanner.index - this.scanner.lineStart; |
| 654 | var token = this.lexJSX(); |
| 655 | this.lastMarker.index = this.scanner.index; |
| 656 | this.lastMarker.line = this.scanner.lineNumber; |
| 657 | this.lastMarker.column = this.scanner.index - this.scanner.lineStart; |
| 658 | if (this.config.tokens) { |
| 659 | this.tokens.push(this.convertToken(token)); |
| 660 | } |
| 661 | return token; |
| 662 | }; |
| 663 | JSXParser.prototype.nextJSXText = function () { |
| 664 | this.startMarker.index = this.scanner.index; |
| 665 | this.startMarker.line = this.scanner.lineNumber; |
| 666 | this.startMarker.column = this.scanner.index - this.scanner.lineStart; |
| 667 | var start = this.scanner.index; |
| 668 | var text = ''; |
| 669 | while (!this.scanner.eof()) { |
| 670 | var ch = this.scanner.source[this.scanner.index]; |
| 671 | if (ch === '{' || ch === '<') { |
| 672 | break; |
| 673 | } |
| 674 | ++this.scanner.index; |
| 675 | text += ch; |
| 676 | if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) { |
| 677 | ++this.scanner.lineNumber; |
| 678 | if (ch === '\r' && this.scanner.source[this.scanner.index] === '\n') { |
| 679 | ++this.scanner.index; |
| 680 | } |
| 681 | this.scanner.lineStart = this.scanner.index; |
| 682 | } |
| 683 | } |
| 684 | this.lastMarker.index = this.scanner.index; |
| 685 | this.lastMarker.line = this.scanner.lineNumber; |
| 686 | this.lastMarker.column = this.scanner.index - this.scanner.lineStart; |
| 687 | var token = { |
| 688 | type: 101 /* Text */, |
| 689 | value: text, |
| 690 | lineNumber: this.scanner.lineNumber, |
| 691 | lineStart: this.scanner.lineStart, |
| 692 | start: start, |
| 693 | end: this.scanner.index |
| 694 | }; |
| 695 | if ((text.length > 0) && this.config.tokens) { |
| 696 | this.tokens.push(this.convertToken(token)); |
| 697 | } |
| 698 | return token; |
| 699 | }; |
| 700 | JSXParser.prototype.peekJSXToken = function () { |
| 701 | var state = this.scanner.saveState(); |
| 702 | this.scanner.scanComments(); |
| 703 | var next = this.lexJSX(); |
| 704 | this.scanner.restoreState(state); |
| 705 | return next; |
| 706 | }; |
| 707 | // Expect the next JSX token to match the specified punctuator. |
| 708 | // If not, an exception will be thrown. |
| 709 | JSXParser.prototype.expectJSX = function (value) { |
| 710 | var token = this.nextJSXToken(); |
| 711 | if (token.type !== 7 /* Punctuator */ || token.value !== value) { |
| 712 | this.throwUnexpectedToken(token); |
| 713 | } |
| 714 | }; |
| 715 | // Return true if the next JSX token matches the specified punctuator. |
| 716 | JSXParser.prototype.matchJSX = function (value) { |
| 717 | var next = this.peekJSXToken(); |
| 718 | return next.type === 7 /* Punctuator */ && next.value === value; |
| 719 | }; |
| 720 | JSXParser.prototype.parseJSXIdentifier = function () { |
| 721 | var node = this.createJSXNode(); |
| 722 | var token = this.nextJSXToken(); |
| 723 | if (token.type !== 100 /* Identifier */) { |
| 724 | this.throwUnexpectedToken(token); |
| 725 | } |
| 726 | return this.finalize(node, new JSXNode.JSXIdentifier(token.value)); |
| 727 | }; |
| 728 | JSXParser.prototype.parseJSXElementName = function () { |
| 729 | var node = this.createJSXNode(); |
| 730 | var elementName = this.parseJSXIdentifier(); |
| 731 | if (this.matchJSX(':')) { |
| 732 | var namespace = elementName; |
| 733 | this.expectJSX(':'); |
| 734 | var name_1 = this.parseJSXIdentifier(); |
| 735 | elementName = this.finalize(node, new JSXNode.JSXNamespacedName(namespace, name_1)); |
| 736 | } |
| 737 | else if (this.matchJSX('.')) { |
| 738 | while (this.matchJSX('.')) { |
| 739 | var object = elementName; |
| 740 | this.expectJSX('.'); |
| 741 | var property = this.parseJSXIdentifier(); |
| 742 | elementName = this.finalize(node, new JSXNode.JSXMemberExpression(object, property)); |
| 743 | } |
| 744 | } |
| 745 | return elementName; |
| 746 | }; |
| 747 | JSXParser.prototype.parseJSXAttributeName = function () { |
| 748 | var node = this.createJSXNode(); |
| 749 | var attributeName; |
| 750 | var identifier = this.parseJSXIdentifier(); |
| 751 | if (this.matchJSX(':')) { |
| 752 | var namespace = identifier; |
| 753 | this.expectJSX(':'); |
| 754 | var name_2 = this.parseJSXIdentifier(); |
| 755 | attributeName = this.finalize(node, new JSXNode.JSXNamespacedName(namespace, name_2)); |
| 756 | } |
| 757 | else { |
| 758 | attributeName = identifier; |
| 759 | } |
| 760 | return attributeName; |
| 761 | }; |
| 762 | JSXParser.prototype.parseJSXStringLiteralAttribute = function () { |
| 763 | var node = this.createJSXNode(); |
| 764 | var token = this.nextJSXToken(); |
| 765 | if (token.type !== 8 /* StringLiteral */) { |
| 766 | this.throwUnexpectedToken(token); |
| 767 | } |
| 768 | var raw = this.getTokenRaw(token); |
| 769 | return this.finalize(node, new Node.Literal(token.value, raw)); |
| 770 | }; |
| 771 | JSXParser.prototype.parseJSXExpressionAttribute = function () { |
| 772 | var node = this.createJSXNode(); |
| 773 | this.expectJSX('{'); |
| 774 | this.finishJSX(); |
| 775 | if (this.match('}')) { |
| 776 | this.tolerateError('JSX attributes must only be assigned a non-empty expression'); |
| 777 | } |
| 778 | var expression = this.parseAssignmentExpression(); |
| 779 | this.reenterJSX(); |
| 780 | return this.finalize(node, new JSXNode.JSXExpressionContainer(expression)); |
| 781 | }; |
| 782 | JSXParser.prototype.parseJSXAttributeValue = function () { |
| 783 | return this.matchJSX('{') ? this.parseJSXExpressionAttribute() : |
| 784 | this.matchJSX('<') ? this.parseJSXElement() : this.parseJSXStringLiteralAttribute(); |
| 785 | }; |
| 786 | JSXParser.prototype.parseJSXNameValueAttribute = function () { |
| 787 | var node = this.createJSXNode(); |
| 788 | var name = this.parseJSXAttributeName(); |
| 789 | var value = null; |
| 790 | if (this.matchJSX('=')) { |
| 791 | this.expectJSX('='); |
| 792 | value = this.parseJSXAttributeValue(); |
| 793 | } |
| 794 | return this.finalize(node, new JSXNode.JSXAttribute(name, value)); |
| 795 | }; |
| 796 | JSXParser.prototype.parseJSXSpreadAttribute = function () { |
| 797 | var node = this.createJSXNode(); |
| 798 | this.expectJSX('{'); |
| 799 | this.expectJSX('...'); |
| 800 | this.finishJSX(); |
| 801 | var argument = this.parseAssignmentExpression(); |
| 802 | this.reenterJSX(); |
| 803 | return this.finalize(node, new JSXNode.JSXSpreadAttribute(argument)); |
| 804 | }; |
| 805 | JSXParser.prototype.parseJSXAttributes = function () { |
| 806 | var attributes = []; |
| 807 | while (!this.matchJSX('/') && !this.matchJSX('>')) { |
| 808 | var attribute = this.matchJSX('{') ? this.parseJSXSpreadAttribute() : |
| 809 | this.parseJSXNameValueAttribute(); |
| 810 | attributes.push(attribute); |
| 811 | } |
| 812 | return attributes; |
| 813 | }; |
| 814 | JSXParser.prototype.parseJSXOpeningElement = function () { |
| 815 | var node = this.createJSXNode(); |
| 816 | this.expectJSX('<'); |
| 817 | var name = this.parseJSXElementName(); |
| 818 | var attributes = this.parseJSXAttributes(); |
| 819 | var selfClosing = this.matchJSX('/'); |
| 820 | if (selfClosing) { |
| 821 | this.expectJSX('/'); |
| 822 | } |
| 823 | this.expectJSX('>'); |
| 824 | return this.finalize(node, new JSXNode.JSXOpeningElement(name, selfClosing, attributes)); |
| 825 | }; |
| 826 | JSXParser.prototype.parseJSXBoundaryElement = function () { |
| 827 | var node = this.createJSXNode(); |
| 828 | this.expectJSX('<'); |
| 829 | if (this.matchJSX('/')) { |
| 830 | this.expectJSX('/'); |
| 831 | var name_3 = this.parseJSXElementName(); |
| 832 | this.expectJSX('>'); |
| 833 | return this.finalize(node, new JSXNode.JSXClosingElement(name_3)); |
| 834 | } |
| 835 | var name = this.parseJSXElementName(); |
| 836 | var attributes = this.parseJSXAttributes(); |
| 837 | var selfClosing = this.matchJSX('/'); |
| 838 | if (selfClosing) { |
| 839 | this.expectJSX('/'); |
| 840 | } |
| 841 | this.expectJSX('>'); |
| 842 | return this.finalize(node, new JSXNode.JSXOpeningElement(name, selfClosing, attributes)); |
| 843 | }; |
| 844 | JSXParser.prototype.parseJSXEmptyExpression = function () { |
| 845 | var node = this.createJSXChildNode(); |
| 846 | this.collectComments(); |
| 847 | this.lastMarker.index = this.scanner.index; |
| 848 | this.lastMarker.line = this.scanner.lineNumber; |
| 849 | this.lastMarker.column = this.scanner.index - this.scanner.lineStart; |
| 850 | return this.finalize(node, new JSXNode.JSXEmptyExpression()); |
| 851 | }; |
| 852 | JSXParser.prototype.parseJSXExpressionContainer = function () { |
| 853 | var node = this.createJSXNode(); |
| 854 | this.expectJSX('{'); |
| 855 | var expression; |
| 856 | if (this.matchJSX('}')) { |
| 857 | expression = this.parseJSXEmptyExpression(); |
| 858 | this.expectJSX('}'); |
| 859 | } |
| 860 | else { |
| 861 | this.finishJSX(); |
| 862 | expression = this.parseAssignmentExpression(); |
| 863 | this.reenterJSX(); |
| 864 | } |
| 865 | return this.finalize(node, new JSXNode.JSXExpressionContainer(expression)); |
| 866 | }; |
| 867 | JSXParser.prototype.parseJSXChildren = function () { |
| 868 | var children = []; |
| 869 | while (!this.scanner.eof()) { |
| 870 | var node = this.createJSXChildNode(); |
| 871 | var token = this.nextJSXText(); |
| 872 | if (token.start < token.end) { |
| 873 | var raw = this.getTokenRaw(token); |
| 874 | var child = this.finalize(node, new JSXNode.JSXText(token.value, raw)); |
| 875 | children.push(child); |
| 876 | } |
| 877 | if (this.scanner.source[this.scanner.index] === '{') { |
| 878 | var container = this.parseJSXExpressionContainer(); |
| 879 | children.push(container); |
| 880 | } |
| 881 | else { |
| 882 | break; |
| 883 | } |
| 884 | } |
| 885 | return children; |
| 886 | }; |
| 887 | JSXParser.prototype.parseComplexJSXElement = function (el) { |
| 888 | var stack = []; |
| 889 | while (!this.scanner.eof()) { |
| 890 | el.children = el.children.concat(this.parseJSXChildren()); |
| 891 | var node = this.createJSXChildNode(); |
| 892 | var element = this.parseJSXBoundaryElement(); |
| 893 | if (element.type === jsx_syntax_1.JSXSyntax.JSXOpeningElement) { |
| 894 | var opening = element; |
| 895 | if (opening.selfClosing) { |
| 896 | var child = this.finalize(node, new JSXNode.JSXElement(opening, [], null)); |
| 897 | el.children.push(child); |
| 898 | } |
| 899 | else { |
| 900 | stack.push(el); |
| 901 | el = { node: node, opening: opening, closing: null, children: [] }; |
| 902 | } |
| 903 | } |
| 904 | if (element.type === jsx_syntax_1.JSXSyntax.JSXClosingElement) { |
| 905 | el.closing = element; |
| 906 | var open_1 = getQualifiedElementName(el.opening.name); |
| 907 | var close_1 = getQualifiedElementName(el.closing.name); |
| 908 | if (open_1 !== close_1) { |
| 909 | this.tolerateError('Expected corresponding JSX closing tag for %0', open_1); |
| 910 | } |
| 911 | if (stack.length > 0) { |
| 912 | var child = this.finalize(el.node, new JSXNode.JSXElement(el.opening, el.children, el.closing)); |
| 913 | el = stack[stack.length - 1]; |
| 914 | el.children.push(child); |
| 915 | stack.pop(); |
| 916 | } |
| 917 | else { |
| 918 | break; |
| 919 | } |
| 920 | } |
| 921 | } |
| 922 | return el; |
| 923 | }; |
| 924 | JSXParser.prototype.parseJSXElement = function () { |
| 925 | var node = this.createJSXNode(); |
| 926 | var opening = this.parseJSXOpeningElement(); |
| 927 | var children = []; |
| 928 | var closing = null; |
| 929 | if (!opening.selfClosing) { |
| 930 | var el = this.parseComplexJSXElement({ node: node, opening: opening, closing: closing, children: children }); |
| 931 | children = el.children; |
| 932 | closing = el.closing; |
| 933 | } |
| 934 | return this.finalize(node, new JSXNode.JSXElement(opening, children, closing)); |
| 935 | }; |
| 936 | JSXParser.prototype.parseJSXRoot = function () { |
| 937 | // Pop the opening '<' added from the lookahead. |
| 938 | if (this.config.tokens) { |
| 939 | this.tokens.pop(); |
| 940 | } |
| 941 | this.startJSX(); |
| 942 | var element = this.parseJSXElement(); |
| 943 | this.finishJSX(); |
| 944 | return element; |
| 945 | }; |
| 946 | JSXParser.prototype.isStartOfExpression = function () { |
| 947 | return _super.prototype.isStartOfExpression.call(this) || this.match('<'); |
| 948 | }; |
| 949 | return JSXParser; |
| 950 | }(parser_1.Parser)); |
| 951 | exports.JSXParser = JSXParser; |
| 952 | |
| 953 | |
| 954 | /***/ }, |
| 955 | /* 4 */ |
| 956 | /***/ function(module, exports) { |
| 957 | |
| 958 | "use strict"; |
| 959 | Object.defineProperty(exports, "__esModule", { value: true }); |
| 960 | // See also tools/generate-unicode-regex.js. |
| 961 | var Regex = { |
| 962 | // Unicode v8.0.0 NonAsciiIdentifierStart: |
| 963 | 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\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1]|\uD87E[\uDC00-\uDE1D]/, |
| 964 | // Unicode v8.0.0 NonAsciiIdentifierPart: |
| 965 | 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\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/ |
| 966 | }; |
| 967 | exports.Character = { |
| 968 | /* tslint:disable:no-bitwise */ |
| 969 | fromCodePoint: function (cp) { |
| 970 | return (cp < 0x10000) ? String.fromCharCode(cp) : |
| 971 | String.fromCharCode(0xD800 + ((cp - 0x10000) >> 10)) + |
| 972 | String.fromCharCode(0xDC00 + ((cp - 0x10000) & 1023)); |
| 973 | }, |
| 974 | // https://tc39.github.io/ecma262/#sec-white-space |
| 975 | isWhiteSpace: function (cp) { |
| 976 | return (cp === 0x20) || (cp === 0x09) || (cp === 0x0B) || (cp === 0x0C) || (cp === 0xA0) || |
| 977 | (cp >= 0x1680 && [0x1680, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202F, 0x205F, 0x3000, 0xFEFF].indexOf(cp) >= 0); |
| 978 | }, |
| 979 | // https://tc39.github.io/ecma262/#sec-line-terminators |
| 980 | isLineTerminator: function (cp) { |
| 981 | return (cp === 0x0A) || (cp === 0x0D) || (cp === 0x2028) || (cp === 0x2029); |
| 982 | }, |
| 983 | // https://tc39.github.io/ecma262/#sec-names-and-keywords |
| 984 | isIdentifierStart: function (cp) { |
| 985 | return (cp === 0x24) || (cp === 0x5F) || |
| 986 | (cp >= 0x41 && cp <= 0x5A) || |
| 987 | (cp >= 0x61 && cp <= 0x7A) || |
| 988 | (cp === 0x5C) || |
| 989 | ((cp >= 0x80) && Regex.NonAsciiIdentifierStart.test(exports.Character.fromCodePoint(cp))); |
| 990 | }, |
| 991 | isIdentifierPart: function (cp) { |
| 992 | return (cp === 0x24) || (cp === 0x5F) || |
| 993 | (cp >= 0x41 && cp <= 0x5A) || |
| 994 | (cp >= 0x61 && cp <= 0x7A) || |
| 995 | (cp >= 0x30 && cp <= 0x39) || |
| 996 | (cp === 0x5C) || |
| 997 | ((cp >= 0x80) && Regex.NonAsciiIdentifierPart.test(exports.Character.fromCodePoint(cp))); |
| 998 | }, |
| 999 | // https://tc39.github.io/ecma262/#sec-literals-numeric-literals |
| 1000 | isDecimalDigit: function (cp) { |
| 1001 | return (cp >= 0x30 && cp <= 0x39); // 0..9 |
| 1002 | }, |
| 1003 | isHexDigit: function (cp) { |
| 1004 | return (cp >= 0x30 && cp <= 0x39) || |
| 1005 | (cp >= 0x41 && cp <= 0x46) || |
| 1006 | (cp >= 0x61 && cp <= 0x66); // a..f |
| 1007 | }, |
| 1008 | isOctalDigit: function (cp) { |
| 1009 | return (cp >= 0x30 && cp <= 0x37); // 0..7 |
| 1010 | } |
| 1011 | }; |
| 1012 | |
| 1013 | |
| 1014 | /***/ }, |
| 1015 | /* 5 */ |
| 1016 | /***/ function(module, exports, __webpack_require__) { |
| 1017 | |
| 1018 | "use strict"; |
| 1019 | Object.defineProperty(exports, "__esModule", { value: true }); |
| 1020 | var jsx_syntax_1 = __webpack_require__(6); |
| 1021 | /* tslint:disable:max-classes-per-file */ |
| 1022 | var JSXClosingElement = (function () { |
| 1023 | function JSXClosingElement(name) { |
| 1024 | this.type = jsx_syntax_1.JSXSyntax.JSXClosingElement; |
| 1025 | this.name = name; |
| 1026 | } |
| 1027 | return JSXClosingElement; |
| 1028 | }()); |
| 1029 | exports.JSXClosingElement = JSXClosingElement; |
| 1030 | var JSXElement = (function () { |
| 1031 | function JSXElement(openingElement, children, closingElement) { |
| 1032 | this.type = jsx_syntax_1.JSXSyntax.JSXElement; |
| 1033 | this.openingElement = openingElement; |
| 1034 | this.children = children; |
| 1035 | this.closingElement = closingElement; |
| 1036 | } |
| 1037 | return JSXElement; |
| 1038 | }()); |
| 1039 | exports.JSXElement = JSXElement; |
| 1040 | var JSXEmptyExpression = (function () { |
| 1041 | function JSXEmptyExpression() { |
| 1042 | this.type = jsx_syntax_1.JSXSyntax.JSXEmptyExpression; |
| 1043 | } |
| 1044 | return JSXEmptyExpression; |
| 1045 | }()); |
| 1046 | exports.JSXEmptyExpression = JSXEmptyExpression; |
| 1047 | var JSXExpressionContainer = (function () { |
| 1048 | function JSXExpressionContainer(expression) { |
| 1049 | this.type = jsx_syntax_1.JSXSyntax.JSXExpressionContainer; |
| 1050 | this.expression = expression; |
| 1051 | } |
| 1052 | return JSXExpressionContainer; |
| 1053 | }()); |
| 1054 | exports.JSXExpressionContainer = JSXExpressionContainer; |
| 1055 | var JSXIdentifier = (function () { |
| 1056 | function JSXIdentifier(name) { |
| 1057 | this.type = jsx_syntax_1.JSXSyntax.JSXIdentifier; |
| 1058 | this.name = name; |
| 1059 | } |
| 1060 | return JSXIdentifier; |
| 1061 | }()); |
| 1062 | exports.JSXIdentifier = JSXIdentifier; |
| 1063 | var JSXMemberExpression = (function () { |
| 1064 | function JSXMemberExpression(object, property) { |
| 1065 | this.type = jsx_syntax_1.JSXSyntax.JSXMemberExpression; |
| 1066 | this.object = object; |
| 1067 | this.property = property; |
| 1068 | } |
| 1069 | return JSXMemberExpression; |
| 1070 | }()); |
| 1071 | exports.JSXMemberExpression = JSXMemberExpression; |
| 1072 | var JSXAttribute = (function () { |
| 1073 | function JSXAttribute(name, value) { |
| 1074 | this.type = jsx_syntax_1.JSXSyntax.JSXAttribute; |
| 1075 | this.name = name; |
| 1076 | this.value = value; |
| 1077 | } |
| 1078 | return JSXAttribute; |
| 1079 | }()); |
| 1080 | exports.JSXAttribute = JSXAttribute; |
| 1081 | var JSXNamespacedName = (function () { |
| 1082 | function JSXNamespacedName(namespace, name) { |
| 1083 | this.type = jsx_syntax_1.JSXSyntax.JSXNamespacedName; |
| 1084 | this.namespace = namespace; |
| 1085 | this.name = name; |
| 1086 | } |
| 1087 | return JSXNamespacedName; |
| 1088 | }()); |
| 1089 | exports.JSXNamespacedName = JSXNamespacedName; |
| 1090 | var JSXOpeningElement = (function () { |
| 1091 | function JSXOpeningElement(name, selfClosing, attributes) { |
| 1092 | this.type = jsx_syntax_1.JSXSyntax.JSXOpeningElement; |
| 1093 | this.name = name; |
| 1094 | this.selfClosing = selfClosing; |
| 1095 | this.attributes = attributes; |
| 1096 | } |
| 1097 | return JSXOpeningElement; |
| 1098 | }()); |
| 1099 | exports.JSXOpeningElement = JSXOpeningElement; |
| 1100 | var JSXSpreadAttribute = (function () { |
| 1101 | function JSXSpreadAttribute(argument) { |
| 1102 | this.type = jsx_syntax_1.JSXSyntax.JSXSpreadAttribute; |
| 1103 | this.argument = argument; |
| 1104 | } |
| 1105 | return JSXSpreadAttribute; |
| 1106 | }()); |
| 1107 | exports.JSXSpreadAttribute = JSXSpreadAttribute; |
| 1108 | var JSXText = (function () { |
| 1109 | function JSXText(value, raw) { |
| 1110 | this.type = jsx_syntax_1.JSXSyntax.JSXText; |
| 1111 | this.value = value; |
| 1112 | this.raw = raw; |
| 1113 | } |
| 1114 | return JSXText; |
| 1115 | }()); |
| 1116 | exports.JSXText = JSXText; |
| 1117 | |
| 1118 | |
| 1119 | /***/ }, |
| 1120 | /* 6 */ |
| 1121 | /***/ function(module, exports) { |
| 1122 | |
| 1123 | "use strict"; |
| 1124 | Object.defineProperty(exports, "__esModule", { value: true }); |
| 1125 | exports.JSXSyntax = { |
| 1126 | JSXAttribute: 'JSXAttribute', |
| 1127 | JSXClosingElement: 'JSXClosingElement', |
| 1128 | JSXElement: 'JSXElement', |
| 1129 | JSXEmptyExpression: 'JSXEmptyExpression', |
| 1130 | JSXExpressionContainer: 'JSXExpressionContainer', |
| 1131 | JSXIdentifier: 'JSXIdentifier', |
| 1132 | JSXMemberExpression: 'JSXMemberExpression', |
| 1133 | JSXNamespacedName: 'JSXNamespacedName', |
| 1134 | JSXOpeningElement: 'JSXOpeningElement', |
| 1135 | JSXSpreadAttribute: 'JSXSpreadAttribute', |
| 1136 | JSXText: 'JSXText' |
| 1137 | }; |
| 1138 | |
| 1139 | |
| 1140 | /***/ }, |
| 1141 | /* 7 */ |
| 1142 | /***/ function(module, exports, __webpack_require__) { |
| 1143 | |
| 1144 | "use strict"; |
| 1145 | Object.defineProperty(exports, "__esModule", { value: true }); |
| 1146 | var syntax_1 = __webpack_require__(2); |
| 1147 | /* tslint:disable:max-classes-per-file */ |
| 1148 | var ArrayExpression = (function () { |
| 1149 | function ArrayExpression(elements) { |
| 1150 | this.type = syntax_1.Syntax.ArrayExpression; |
| 1151 | this.elements = elements; |
| 1152 | } |
| 1153 | return ArrayExpression; |
| 1154 | }()); |
| 1155 | exports.ArrayExpression = ArrayExpression; |
| 1156 | var ArrayPattern = (function () { |
| 1157 | function ArrayPattern(elements) { |
| 1158 | this.type = syntax_1.Syntax.ArrayPattern; |
| 1159 | this.elements = elements; |
| 1160 | } |
| 1161 | return ArrayPattern; |
| 1162 | }()); |
| 1163 | exports.ArrayPattern = ArrayPattern; |
| 1164 | var ArrowFunctionExpression = (function () { |
| 1165 | function ArrowFunctionExpression(params, body, expression) { |
| 1166 | this.type = syntax_1.Syntax.ArrowFunctionExpression; |
| 1167 | this.id = null; |
| 1168 | this.params = params; |
| 1169 | this.body = body; |
| 1170 | this.generator = false; |
| 1171 | this.expression = expression; |
| 1172 | this.async = false; |
| 1173 | } |
| 1174 | return ArrowFunctionExpression; |
| 1175 | }()); |
| 1176 | exports.ArrowFunctionExpression = ArrowFunctionExpression; |
| 1177 | var AssignmentExpression = (function () { |
| 1178 | function AssignmentExpression(operator, left, right) { |
| 1179 | this.type = syntax_1.Syntax.AssignmentExpression; |
| 1180 | this.operator = operator; |
| 1181 | this.left = left; |
| 1182 | this.right = right; |
| 1183 | } |
| 1184 | return AssignmentExpression; |
| 1185 | }()); |
| 1186 | exports.AssignmentExpression = AssignmentExpression; |
| 1187 | var AssignmentPattern = (function () { |
| 1188 | function AssignmentPattern(left, right) { |
| 1189 | this.type = syntax_1.Syntax.AssignmentPattern; |
| 1190 | this.left = left; |
| 1191 | this.right = right; |
| 1192 | } |
| 1193 | return AssignmentPattern; |
| 1194 | }()); |
| 1195 | exports.AssignmentPattern = AssignmentPattern; |
| 1196 | var AsyncArrowFunctionExpression = (function () { |
| 1197 | function AsyncArrowFunctionExpression(params, body, expression) { |
| 1198 | this.type = syntax_1.Syntax.ArrowFunctionExpression; |
| 1199 | this.id = null; |
| 1200 | this.params = params; |
| 1201 | this.body = body; |
| 1202 | this.generator = false; |
| 1203 | this.expression = expression; |
| 1204 | this.async = true; |
| 1205 | } |
| 1206 | return AsyncArrowFunctionExpression; |
| 1207 | }()); |
| 1208 | exports.AsyncArrowFunctionExpression = AsyncArrowFunctionExpression; |
| 1209 | var AsyncFunctionDeclaration = (function () { |
| 1210 | function AsyncFunctionDeclaration(id, params, body) { |
| 1211 | this.type = syntax_1.Syntax.FunctionDeclaration; |
| 1212 | this.id = id; |
| 1213 | this.params = params; |
| 1214 | this.body = body; |
| 1215 | this.generator = false; |
| 1216 | this.expression = false; |
| 1217 | this.async = true; |
| 1218 | } |
| 1219 | return AsyncFunctionDeclaration; |
| 1220 | }()); |
| 1221 | exports.AsyncFunctionDeclaration = AsyncFunctionDeclaration; |
| 1222 | var AsyncFunctionExpression = (function () { |
| 1223 | function AsyncFunctionExpression(id, params, body) { |
| 1224 | this.type = syntax_1.Syntax.FunctionExpression; |
| 1225 | this.id = id; |
| 1226 | this.params = params; |
| 1227 | this.body = body; |
| 1228 | this.generator = false; |
| 1229 | this.expression = false; |
| 1230 | this.async = true; |
| 1231 | } |
| 1232 | return AsyncFunctionExpression; |
| 1233 | }()); |
| 1234 | exports.AsyncFunctionExpression = AsyncFunctionExpression; |
| 1235 | var AwaitExpression = (function () { |
| 1236 | function AwaitExpression(argument) { |
| 1237 | this.type = syntax_1.Syntax.AwaitExpression; |
| 1238 | this.argument = argument; |
| 1239 | } |
| 1240 | return AwaitExpression; |
| 1241 | }()); |
| 1242 | exports.AwaitExpression = AwaitExpression; |
| 1243 | var BinaryExpression = (function () { |
| 1244 | function BinaryExpression(operator, left, right) { |
| 1245 | var logical = (operator === '||' || operator === '&&'); |
| 1246 | this.type = logical ? syntax_1.Syntax.LogicalExpression : syntax_1.Syntax.BinaryExpression; |
| 1247 | this.operator = operator; |
| 1248 | this.left = left; |
| 1249 | this.right = right; |
| 1250 | } |
| 1251 | return BinaryExpression; |
| 1252 | }()); |
| 1253 | exports.BinaryExpression = BinaryExpression; |
| 1254 | var BlockStatement = (function () { |
| 1255 | function BlockStatement(body) { |
| 1256 | this.type = syntax_1.Syntax.BlockStatement; |
| 1257 | this.body = body; |
| 1258 | } |
| 1259 | return BlockStatement; |
| 1260 | }()); |
| 1261 | exports.BlockStatement = BlockStatement; |
| 1262 | var BreakStatement = (function () { |
| 1263 | function BreakStatement(label) { |
| 1264 | this.type = syntax_1.Syntax.BreakStatement; |
| 1265 | this.label = label; |
| 1266 | } |
| 1267 | return BreakStatement; |
| 1268 | }()); |
| 1269 | exports.BreakStatement = BreakStatement; |
| 1270 | var CallExpression = (function () { |
| 1271 | function CallExpression(callee, args) { |
| 1272 | this.type = syntax_1.Syntax.CallExpression; |
| 1273 | this.callee = callee; |
| 1274 | this.arguments = args; |
| 1275 | } |
| 1276 | return CallExpression; |
| 1277 | }()); |
| 1278 | exports.CallExpression = CallExpression; |
| 1279 | var CatchClause = (function () { |
| 1280 | function CatchClause(param, body) { |
| 1281 | this.type = syntax_1.Syntax.CatchClause; |
| 1282 | this.param = param; |
| 1283 | this.body = body; |
| 1284 | } |
| 1285 | return CatchClause; |
| 1286 | }()); |
| 1287 | exports.CatchClause = CatchClause; |
| 1288 | var ClassBody = (function () { |
| 1289 | function ClassBody(body) { |
| 1290 | this.type = syntax_1.Syntax.ClassBody; |
| 1291 | this.body = body; |
| 1292 | } |
| 1293 | return ClassBody; |
| 1294 | }()); |
| 1295 | exports.ClassBody = ClassBody; |
| 1296 | var ClassDeclaration = (function () { |
| 1297 | function ClassDeclaration(id, superClass, body) { |
| 1298 | this.type = syntax_1.Syntax.ClassDeclaration; |
| 1299 | this.id = id; |
| 1300 | this.superClass = superClass; |
| 1301 | this.body = body; |
| 1302 | } |
| 1303 | return ClassDeclaration; |
| 1304 | }()); |
| 1305 | exports.ClassDeclaration = ClassDeclaration; |
| 1306 | var ClassExpression = (function () { |
| 1307 | function ClassExpression(id, superClass, body) { |
| 1308 | this.type = syntax_1.Syntax.ClassExpression; |
| 1309 | this.id = id; |
| 1310 | this.superClass = superClass; |
| 1311 | this.body = body; |
| 1312 | } |
| 1313 | return ClassExpression; |
| 1314 | }()); |
| 1315 | exports.ClassExpression = ClassExpression; |
| 1316 | var ComputedMemberExpression = (function () { |
| 1317 | function ComputedMemberExpression(object, property) { |
| 1318 | this.type = syntax_1.Syntax.MemberExpression; |
| 1319 | this.computed = true; |
| 1320 | this.object = object; |
| 1321 | this.property = property; |
| 1322 | } |
| 1323 | return ComputedMemberExpression; |
| 1324 | }()); |
| 1325 | exports.ComputedMemberExpression = ComputedMemberExpression; |
| 1326 | var ConditionalExpression = (function () { |
| 1327 | function ConditionalExpression(test, consequent, alternate) { |
| 1328 | this.type = syntax_1.Syntax.ConditionalExpression; |
| 1329 | this.test = test; |
| 1330 | this.consequent = consequent; |
| 1331 | this.alternate = alternate; |
| 1332 | } |
| 1333 | return ConditionalExpression; |
| 1334 | }()); |
| 1335 | exports.ConditionalExpression = ConditionalExpression; |
| 1336 | var ContinueStatement = (function () { |
| 1337 | function ContinueStatement(label) { |
| 1338 | this.type = syntax_1.Syntax.ContinueStatement; |
| 1339 | this.label = label; |
| 1340 | } |
| 1341 | return ContinueStatement; |
| 1342 | }()); |
| 1343 | exports.ContinueStatement = ContinueStatement; |
| 1344 | var DebuggerStatement = (function () { |
| 1345 | function DebuggerStatement() { |
| 1346 | this.type = syntax_1.Syntax.DebuggerStatement; |
| 1347 | } |
| 1348 | return DebuggerStatement; |
| 1349 | }()); |
| 1350 | exports.DebuggerStatement = DebuggerStatement; |
| 1351 | var Directive = (function () { |
| 1352 | function Directive(expression, directive) { |
| 1353 | this.type = syntax_1.Syntax.ExpressionStatement; |
| 1354 | this.expression = expression; |
| 1355 | this.directive = directive; |
| 1356 | } |
| 1357 | return Directive; |
| 1358 | }()); |
| 1359 | exports.Directive = Directive; |
| 1360 | var DoWhileStatement = (function () { |
| 1361 | function DoWhileStatement(body, test) { |
| 1362 | this.type = syntax_1.Syntax.DoWhileStatement; |
| 1363 | this.body = body; |
| 1364 | this.test = test; |
| 1365 | } |
| 1366 | return DoWhileStatement; |
| 1367 | }()); |
| 1368 | exports.DoWhileStatement = DoWhileStatement; |
| 1369 | var EmptyStatement = (function () { |
| 1370 | function EmptyStatement() { |
| 1371 | this.type = syntax_1.Syntax.EmptyStatement; |
| 1372 | } |
| 1373 | return EmptyStatement; |
| 1374 | }()); |
| 1375 | exports.EmptyStatement = EmptyStatement; |
| 1376 | var ExportAllDeclaration = (function () { |
| 1377 | function ExportAllDeclaration(source) { |
| 1378 | this.type = syntax_1.Syntax.ExportAllDeclaration; |
| 1379 | this.source = source; |
| 1380 | } |
| 1381 | return ExportAllDeclaration; |
| 1382 | }()); |
| 1383 | exports.ExportAllDeclaration = ExportAllDeclaration; |
| 1384 | var ExportDefaultDeclaration = (function () { |
| 1385 | function ExportDefaultDeclaration(declaration) { |
| 1386 | this.type = syntax_1.Syntax.ExportDefaultDeclaration; |
| 1387 | this.declaration = declaration; |
| 1388 | } |
| 1389 | return ExportDefaultDeclaration; |
| 1390 | }()); |
| 1391 | exports.ExportDefaultDeclaration = ExportDefaultDeclaration; |
| 1392 | var ExportNamedDeclaration = (function () { |
| 1393 | function ExportNamedDeclaration(declaration, specifiers, source) { |
| 1394 | this.type = syntax_1.Syntax.ExportNamedDeclaration; |
| 1395 | this.declaration = declaration; |
| 1396 | this.specifiers = specifiers; |
| 1397 | this.source = source; |
| 1398 | } |
| 1399 | return ExportNamedDeclaration; |
| 1400 | }()); |
| 1401 | exports.ExportNamedDeclaration = ExportNamedDeclaration; |
| 1402 | var ExportSpecifier = (function () { |
| 1403 | function ExportSpecifier(local, exported) { |
| 1404 | this.type = syntax_1.Syntax.ExportSpecifier; |
| 1405 | this.exported = exported; |
| 1406 | this.local = local; |
| 1407 | } |
| 1408 | return ExportSpecifier; |
| 1409 | }()); |
| 1410 | exports.ExportSpecifier = ExportSpecifier; |
| 1411 | var ExpressionStatement = (function () { |
| 1412 | function ExpressionStatement(expression) { |
| 1413 | this.type = syntax_1.Syntax.ExpressionStatement; |
| 1414 | this.expression = expression; |
| 1415 | } |
| 1416 | return ExpressionStatement; |
| 1417 | }()); |
| 1418 | exports.ExpressionStatement = ExpressionStatement; |
| 1419 | var ForInStatement = (function () { |
| 1420 | function ForInStatement(left, right, body) { |
| 1421 | this.type = syntax_1.Syntax.ForInStatement; |
| 1422 | this.left = left; |
| 1423 | this.right = right; |
| 1424 | this.body = body; |
| 1425 | this.each = false; |
| 1426 | } |
| 1427 | return ForInStatement; |
| 1428 | }()); |
| 1429 | exports.ForInStatement = ForInStatement; |
| 1430 | var ForOfStatement = (function () { |
| 1431 | function ForOfStatement(left, right, body) { |
| 1432 | this.type = syntax_1.Syntax.ForOfStatement; |
| 1433 | this.left = left; |
| 1434 | this.right = right; |
| 1435 | this.body = body; |
| 1436 | } |
| 1437 | return ForOfStatement; |
| 1438 | }()); |
| 1439 | exports.ForOfStatement = ForOfStatement; |
| 1440 | var ForStatement = (function () { |
| 1441 | function ForStatement(init, test, update, body) { |
| 1442 | this.type = syntax_1.Syntax.ForStatement; |
| 1443 | this.init = init; |
| 1444 | this.test = test; |
| 1445 | this.update = update; |
| 1446 | this.body = body; |
| 1447 | } |
| 1448 | return ForStatement; |
| 1449 | }()); |
| 1450 | exports.ForStatement = ForStatement; |
| 1451 | var FunctionDeclaration = (function () { |
| 1452 | function FunctionDeclaration(id, params, body, generator) { |
| 1453 | this.type = syntax_1.Syntax.FunctionDeclaration; |
| 1454 | this.id = id; |
| 1455 | this.params = params; |
| 1456 | this.body = body; |
| 1457 | this.generator = generator; |
| 1458 | this.expression = false; |
| 1459 | this.async = false; |
| 1460 | } |
| 1461 | return FunctionDeclaration; |
| 1462 | }()); |
| 1463 | exports.FunctionDeclaration = FunctionDeclaration; |
| 1464 | var FunctionExpression = (function () { |
| 1465 | function FunctionExpression(id, params, body, generator) { |
| 1466 | this.type = syntax_1.Syntax.FunctionExpression; |
| 1467 | this.id = id; |
| 1468 | this.params = params; |
| 1469 | this.body = body; |
| 1470 | this.generator = generator; |
| 1471 | this.expression = false; |
| 1472 | this.async = false; |
| 1473 | } |
| 1474 | return FunctionExpression; |
| 1475 | }()); |
| 1476 | exports.FunctionExpression = FunctionExpression; |
| 1477 | var Identifier = (function () { |
| 1478 | function Identifier(name) { |
| 1479 | this.type = syntax_1.Syntax.Identifier; |
| 1480 | this.name = name; |
| 1481 | } |
| 1482 | return Identifier; |
| 1483 | }()); |
| 1484 | exports.Identifier = Identifier; |
| 1485 | var IfStatement = (function () { |
| 1486 | function IfStatement(test, consequent, alternate) { |
| 1487 | this.type = syntax_1.Syntax.IfStatement; |
| 1488 | this.test = test; |
| 1489 | this.consequent = consequent; |
| 1490 | this.alternate = alternate; |
| 1491 | } |
| 1492 | return IfStatement; |
| 1493 | }()); |
| 1494 | exports.IfStatement = IfStatement; |
| 1495 | var ImportDeclaration = (function () { |
| 1496 | function ImportDeclaration(specifiers, source) { |
| 1497 | this.type = syntax_1.Syntax.ImportDeclaration; |
| 1498 | this.specifiers = specifiers; |
| 1499 | this.source = source; |
| 1500 | } |
| 1501 | return ImportDeclaration; |
| 1502 | }()); |
| 1503 | exports.ImportDeclaration = ImportDeclaration; |
| 1504 | var ImportDefaultSpecifier = (function () { |
| 1505 | function ImportDefaultSpecifier(local) { |
| 1506 | this.type = syntax_1.Syntax.ImportDefaultSpecifier; |
| 1507 | this.local = local; |
| 1508 | } |
| 1509 | return ImportDefaultSpecifier; |
| 1510 | }()); |
| 1511 | exports.ImportDefaultSpecifier = ImportDefaultSpecifier; |
| 1512 | var ImportNamespaceSpecifier = (function () { |
| 1513 | function ImportNamespaceSpecifier(local) { |
| 1514 | this.type = syntax_1.Syntax.ImportNamespaceSpecifier; |
| 1515 | this.local = local; |
| 1516 | } |
| 1517 | return ImportNamespaceSpecifier; |
| 1518 | }()); |
| 1519 | exports.ImportNamespaceSpecifier = ImportNamespaceSpecifier; |
| 1520 | var ImportSpecifier = (function () { |
| 1521 | function ImportSpecifier(local, imported) { |
| 1522 | this.type = syntax_1.Syntax.ImportSpecifier; |
| 1523 | this.local = local; |
| 1524 | this.imported = imported; |
| 1525 | } |
| 1526 | return ImportSpecifier; |
| 1527 | }()); |
| 1528 | exports.ImportSpecifier = ImportSpecifier; |
| 1529 | var LabeledStatement = (function () { |
| 1530 | function LabeledStatement(label, body) { |
| 1531 | this.type = syntax_1.Syntax.LabeledStatement; |
| 1532 | this.label = label; |
| 1533 | this.body = body; |
| 1534 | } |
| 1535 | return LabeledStatement; |
| 1536 | }()); |
| 1537 | exports.LabeledStatement = LabeledStatement; |
| 1538 | var Literal = (function () { |
| 1539 | function Literal(value, raw) { |
| 1540 | this.type = syntax_1.Syntax.Literal; |
| 1541 | this.value = value; |
| 1542 | this.raw = raw; |
| 1543 | } |
| 1544 | return Literal; |
| 1545 | }()); |
| 1546 | exports.Literal = Literal; |
| 1547 | var MetaProperty = (function () { |
| 1548 | function MetaProperty(meta, property) { |
| 1549 | this.type = syntax_1.Syntax.MetaProperty; |
| 1550 | this.meta = meta; |
| 1551 | this.property = property; |
| 1552 | } |
| 1553 | return MetaProperty; |
| 1554 | }()); |
| 1555 | exports.MetaProperty = MetaProperty; |
| 1556 | var MethodDefinition = (function () { |
| 1557 | function MethodDefinition(key, computed, value, kind, isStatic) { |
| 1558 | this.type = syntax_1.Syntax.MethodDefinition; |
| 1559 | this.key = key; |
| 1560 | this.computed = computed; |
| 1561 | this.value = value; |
| 1562 | this.kind = kind; |
| 1563 | this.static = isStatic; |
| 1564 | } |
| 1565 | return MethodDefinition; |
| 1566 | }()); |
| 1567 | exports.MethodDefinition = MethodDefinition; |
| 1568 | var Module = (function () { |
| 1569 | function Module(body) { |
| 1570 | this.type = syntax_1.Syntax.Program; |
| 1571 | this.body = body; |
| 1572 | this.sourceType = 'module'; |
| 1573 | } |
| 1574 | return Module; |
| 1575 | }()); |
| 1576 | exports.Module = Module; |
| 1577 | var NewExpression = (function () { |
| 1578 | function NewExpression(callee, args) { |
| 1579 | this.type = syntax_1.Syntax.NewExpression; |
| 1580 | this.callee = callee; |
| 1581 | this.arguments = args; |
| 1582 | } |
| 1583 | return NewExpression; |
| 1584 | }()); |
| 1585 | exports.NewExpression = NewExpression; |
| 1586 | var ObjectExpression = (function () { |
| 1587 | function ObjectExpression(properties) { |
| 1588 | this.type = syntax_1.Syntax.ObjectExpression; |
| 1589 | this.properties = properties; |
| 1590 | } |
| 1591 | return ObjectExpression; |
| 1592 | }()); |
| 1593 | exports.ObjectExpression = ObjectExpression; |
| 1594 | var ObjectPattern = (function () { |
| 1595 | function ObjectPattern(properties) { |
| 1596 | this.type = syntax_1.Syntax.ObjectPattern; |
| 1597 | this.properties = properties; |
| 1598 | } |
| 1599 | return ObjectPattern; |
| 1600 | }()); |
| 1601 | exports.ObjectPattern = ObjectPattern; |
| 1602 | var Property = (function () { |
| 1603 | function Property(kind, key, computed, value, method, shorthand) { |
| 1604 | this.type = syntax_1.Syntax.Property; |
| 1605 | this.key = key; |
| 1606 | this.computed = computed; |
| 1607 | this.value = value; |
| 1608 | this.kind = kind; |
| 1609 | this.method = method; |
| 1610 | this.shorthand = shorthand; |
| 1611 | } |
| 1612 | return Property; |
| 1613 | }()); |
| 1614 | exports.Property = Property; |
| 1615 | var RegexLiteral = (function () { |
| 1616 | function RegexLiteral(value, raw, pattern, flags) { |
| 1617 | this.type = syntax_1.Syntax.Literal; |
| 1618 | this.value = value; |
| 1619 | this.raw = raw; |
| 1620 | this.regex = { pattern: pattern, flags: flags }; |
| 1621 | } |
| 1622 | return RegexLiteral; |
| 1623 | }()); |
| 1624 | exports.RegexLiteral = RegexLiteral; |
| 1625 | var RestElement = (function () { |
| 1626 | function RestElement(argument) { |
| 1627 | this.type = syntax_1.Syntax.RestElement; |
| 1628 | this.argument = argument; |
| 1629 | } |
| 1630 | return RestElement; |
| 1631 | }()); |
| 1632 | exports.RestElement = RestElement; |
| 1633 | var ReturnStatement = (function () { |
| 1634 | function ReturnStatement(argument) { |
| 1635 | this.type = syntax_1.Syntax.ReturnStatement; |
| 1636 | this.argument = argument; |
| 1637 | } |
| 1638 | return ReturnStatement; |
| 1639 | }()); |
| 1640 | exports.ReturnStatement = ReturnStatement; |
| 1641 | var Script = (function () { |
| 1642 | function Script(body) { |
| 1643 | this.type = syntax_1.Syntax.Program; |
| 1644 | this.body = body; |
| 1645 | this.sourceType = 'script'; |
| 1646 | } |
| 1647 | return Script; |
| 1648 | }()); |
| 1649 | exports.Script = Script; |
| 1650 | var SequenceExpression = (function () { |
| 1651 | function SequenceExpression(expressions) { |
| 1652 | this.type = syntax_1.Syntax.SequenceExpression; |
| 1653 | this.expressions = expressions; |
| 1654 | } |
| 1655 | return SequenceExpression; |
| 1656 | }()); |
| 1657 | exports.SequenceExpression = SequenceExpression; |
| 1658 | var SpreadElement = (function () { |
| 1659 | function SpreadElement(argument) { |
| 1660 | this.type = syntax_1.Syntax.SpreadElement; |
| 1661 | this.argument = argument; |
| 1662 | } |
| 1663 | return SpreadElement; |
| 1664 | }()); |
| 1665 | exports.SpreadElement = SpreadElement; |
| 1666 | var StaticMemberExpression = (function () { |
| 1667 | function StaticMemberExpression(object, property) { |
| 1668 | this.type = syntax_1.Syntax.MemberExpression; |
| 1669 | this.computed = false; |
| 1670 | this.object = object; |
| 1671 | this.property = property; |
| 1672 | } |
| 1673 | return StaticMemberExpression; |
| 1674 | }()); |
| 1675 | exports.StaticMemberExpression = StaticMemberExpression; |
| 1676 | var Super = (function () { |
| 1677 | function Super() { |
| 1678 | this.type = syntax_1.Syntax.Super; |
| 1679 | } |
| 1680 | return Super; |
| 1681 | }()); |
| 1682 | exports.Super = Super; |
| 1683 | var SwitchCase = (function () { |
| 1684 | function SwitchCase(test, consequent) { |
| 1685 | this.type = syntax_1.Syntax.SwitchCase; |
| 1686 | this.test = test; |
| 1687 | this.consequent = consequent; |
| 1688 | } |
| 1689 | return SwitchCase; |
| 1690 | }()); |
| 1691 | exports.SwitchCase = SwitchCase; |
| 1692 | var SwitchStatement = (function () { |
| 1693 | function SwitchStatement(discriminant, cases) { |
| 1694 | this.type = syntax_1.Syntax.SwitchStatement; |
| 1695 | this.discriminant = discriminant; |
| 1696 | this.cases = cases; |
| 1697 | } |
| 1698 | return SwitchStatement; |
| 1699 | }()); |
| 1700 | exports.SwitchStatement = SwitchStatement; |
| 1701 | var TaggedTemplateExpression = (function () { |
| 1702 | function TaggedTemplateExpression(tag, quasi) { |
| 1703 | this.type = syntax_1.Syntax.TaggedTemplateExpression; |
| 1704 | this.tag = tag; |
| 1705 | this.quasi = quasi; |
| 1706 | } |
| 1707 | return TaggedTemplateExpression; |
| 1708 | }()); |
| 1709 | exports.TaggedTemplateExpression = TaggedTemplateExpression; |
| 1710 | var TemplateElement = (function () { |
| 1711 | function TemplateElement(value, tail) { |
| 1712 | this.type = syntax_1.Syntax.TemplateElement; |
| 1713 | this.value = value; |
| 1714 | this.tail = tail; |
| 1715 | } |
| 1716 | return TemplateElement; |
| 1717 | }()); |
| 1718 | exports.TemplateElement = TemplateElement; |
| 1719 | var TemplateLiteral = (function () { |
| 1720 | function TemplateLiteral(quasis, expressions) { |
| 1721 | this.type = syntax_1.Syntax.TemplateLiteral; |
| 1722 | this.quasis = quasis; |
| 1723 | this.expressions = expressions; |
| 1724 | } |
| 1725 | return TemplateLiteral; |
| 1726 | }()); |
| 1727 | exports.TemplateLiteral = TemplateLiteral; |
| 1728 | var ThisExpression = (function () { |
| 1729 | function ThisExpression() { |
| 1730 | this.type = syntax_1.Syntax.ThisExpression; |
| 1731 | } |
| 1732 | return ThisExpression; |
| 1733 | }()); |
| 1734 | exports.ThisExpression = ThisExpression; |
| 1735 | var ThrowStatement = (function () { |
| 1736 | function ThrowStatement(argument) { |
| 1737 | this.type = syntax_1.Syntax.ThrowStatement; |
| 1738 | this.argument = argument; |
| 1739 | } |
| 1740 | return ThrowStatement; |
| 1741 | }()); |
| 1742 | exports.ThrowStatement = ThrowStatement; |
| 1743 | var TryStatement = (function () { |
| 1744 | function TryStatement(block, handler, finalizer) { |
| 1745 | this.type = syntax_1.Syntax.TryStatement; |
| 1746 | this.block = block; |
| 1747 | this.handler = handler; |
| 1748 | this.finalizer = finalizer; |
| 1749 | } |
| 1750 | return TryStatement; |
| 1751 | }()); |
| 1752 | exports.TryStatement = TryStatement; |
| 1753 | var UnaryExpression = (function () { |
| 1754 | function UnaryExpression(operator, argument) { |
| 1755 | this.type = syntax_1.Syntax.UnaryExpression; |
| 1756 | this.operator = operator; |
| 1757 | this.argument = argument; |
| 1758 | this.prefix = true; |
| 1759 | } |
| 1760 | return UnaryExpression; |
| 1761 | }()); |
| 1762 | exports.UnaryExpression = UnaryExpression; |
| 1763 | var UpdateExpression = (function () { |
| 1764 | function UpdateExpression(operator, argument, prefix) { |
| 1765 | this.type = syntax_1.Syntax.UpdateExpression; |
| 1766 | this.operator = operator; |
| 1767 | this.argument = argument; |
| 1768 | this.prefix = prefix; |
| 1769 | } |
| 1770 | return UpdateExpression; |
| 1771 | }()); |
| 1772 | exports.UpdateExpression = UpdateExpression; |
| 1773 | var VariableDeclaration = (function () { |
| 1774 | function VariableDeclaration(declarations, kind) { |
| 1775 | this.type = syntax_1.Syntax.VariableDeclaration; |
| 1776 | this.declarations = declarations; |
| 1777 | this.kind = kind; |
| 1778 | } |
| 1779 | return VariableDeclaration; |
| 1780 | }()); |
| 1781 | exports.VariableDeclaration = VariableDeclaration; |
| 1782 | var VariableDeclarator = (function () { |
| 1783 | function VariableDeclarator(id, init) { |
| 1784 | this.type = syntax_1.Syntax.VariableDeclarator; |
| 1785 | this.id = id; |
| 1786 | this.init = init; |
| 1787 | } |
| 1788 | return VariableDeclarator; |
| 1789 | }()); |
| 1790 | exports.VariableDeclarator = VariableDeclarator; |
| 1791 | var WhileStatement = (function () { |
| 1792 | function WhileStatement(test, body) { |
| 1793 | this.type = syntax_1.Syntax.WhileStatement; |
| 1794 | this.test = test; |
| 1795 | this.body = body; |
| 1796 | } |
| 1797 | return WhileStatement; |
| 1798 | }()); |
| 1799 | exports.WhileStatement = WhileStatement; |
| 1800 | var WithStatement = (function () { |
| 1801 | function WithStatement(object, body) { |
| 1802 | this.type = syntax_1.Syntax.WithStatement; |
| 1803 | this.object = object; |
| 1804 | this.body = body; |
| 1805 | } |
| 1806 | return WithStatement; |
| 1807 | }()); |
| 1808 | exports.WithStatement = WithStatement; |
| 1809 | var YieldExpression = (function () { |
| 1810 | function YieldExpression(argument, delegate) { |
| 1811 | this.type = syntax_1.Syntax.YieldExpression; |
| 1812 | this.argument = argument; |
| 1813 | this.delegate = delegate; |
| 1814 | } |
| 1815 | return YieldExpression; |
| 1816 | }()); |
| 1817 | exports.YieldExpression = YieldExpression; |
| 1818 | |
| 1819 | |
| 1820 | /***/ }, |
| 1821 | /* 8 */ |
| 1822 | /***/ function(module, exports, __webpack_require__) { |
| 1823 | |
| 1824 | "use strict"; |
| 1825 | Object.defineProperty(exports, "__esModule", { value: true }); |
| 1826 | var assert_1 = __webpack_require__(9); |
| 1827 | var error_handler_1 = __webpack_require__(10); |
| 1828 | var messages_1 = __webpack_require__(11); |
| 1829 | var Node = __webpack_require__(7); |
| 1830 | var scanner_1 = __webpack_require__(12); |
| 1831 | var syntax_1 = __webpack_require__(2); |
| 1832 | var token_1 = __webpack_require__(13); |
| 1833 | var ArrowParameterPlaceHolder = 'ArrowParameterPlaceHolder'; |
| 1834 | var Parser = (function () { |
| 1835 | function Parser(code, options, delegate) { |
| 1836 | if (options === void 0) { options = {}; } |
| 1837 | this.config = { |
| 1838 | range: (typeof options.range === 'boolean') && options.range, |
| 1839 | loc: (typeof options.loc === 'boolean') && options.loc, |
| 1840 | source: null, |
| 1841 | tokens: (typeof options.tokens === 'boolean') && options.tokens, |
| 1842 | comment: (typeof options.comment === 'boolean') && options.comment, |
| 1843 | tolerant: (typeof options.tolerant === 'boolean') && options.tolerant |
| 1844 | }; |
| 1845 | if (this.config.loc && options.source && options.source !== null) { |
| 1846 | this.config.source = String(options.source); |
| 1847 | } |
| 1848 | this.delegate = delegate; |
| 1849 | this.errorHandler = new error_handler_1.ErrorHandler(); |
| 1850 | this.errorHandler.tolerant = this.config.tolerant; |
| 1851 | this.scanner = new scanner_1.Scanner(code, this.errorHandler); |
| 1852 | this.scanner.trackComment = this.config.comment; |
| 1853 | this.operatorPrecedence = { |
| 1854 | ')': 0, |
| 1855 | ';': 0, |
| 1856 | ',': 0, |
| 1857 | '=': 0, |
| 1858 | ']': 0, |
| 1859 | '||': 1, |
| 1860 | '&&': 2, |
| 1861 | '|': 3, |
| 1862 | '^': 4, |
| 1863 | '&': 5, |
| 1864 | '==': 6, |
| 1865 | '!=': 6, |
| 1866 | '===': 6, |
| 1867 | '!==': 6, |
| 1868 | '<': 7, |
| 1869 | '>': 7, |
| 1870 | '<=': 7, |
| 1871 | '>=': 7, |
| 1872 | '<<': 8, |
| 1873 | '>>': 8, |
| 1874 | '>>>': 8, |
| 1875 | '+': 9, |
| 1876 | '-': 9, |
| 1877 | '*': 11, |
| 1878 | '/': 11, |
| 1879 | '%': 11 |
| 1880 | }; |
| 1881 | this.lookahead = { |
| 1882 | type: 2 /* EOF */, |
| 1883 | value: '', |
| 1884 | lineNumber: this.scanner.lineNumber, |
| 1885 | lineStart: 0, |
| 1886 | start: 0, |
| 1887 | end: 0 |
| 1888 | }; |
| 1889 | this.hasLineTerminator = false; |
| 1890 | this.context = { |
| 1891 | isModule: false, |
| 1892 | await: false, |
| 1893 | allowIn: true, |
| 1894 | allowStrictDirective: true, |
| 1895 | allowYield: true, |
| 1896 | firstCoverInitializedNameError: null, |
| 1897 | isAssignmentTarget: false, |
| 1898 | isBindingElement: false, |
| 1899 | inFunctionBody: false, |
| 1900 | inIteration: false, |
| 1901 | inSwitch: false, |
| 1902 | labelSet: {}, |
| 1903 | strict: false |
| 1904 | }; |
| 1905 | this.tokens = []; |
| 1906 | this.startMarker = { |
| 1907 | index: 0, |
| 1908 | line: this.scanner.lineNumber, |
| 1909 | column: 0 |
| 1910 | }; |
| 1911 | this.lastMarker = { |
| 1912 | index: 0, |
| 1913 | line: this.scanner.lineNumber, |
| 1914 | column: 0 |
| 1915 | }; |
| 1916 | this.nextToken(); |
| 1917 | this.lastMarker = { |
| 1918 | index: this.scanner.index, |
| 1919 | line: this.scanner.lineNumber, |
| 1920 | column: this.scanner.index - this.scanner.lineStart |
| 1921 | }; |
| 1922 | } |
| 1923 | Parser.prototype.throwError = function (messageFormat) { |
| 1924 | var values = []; |
| 1925 | for (var _i = 1; _i < arguments.length; _i++) { |
| 1926 | values[_i - 1] = arguments[_i]; |
| 1927 | } |
| 1928 | var args = Array.prototype.slice.call(arguments, 1); |
| 1929 | var msg = messageFormat.replace(/%(\d)/g, function (whole, idx) { |
| 1930 | assert_1.assert(idx < args.length, 'Message reference must be in range'); |
| 1931 | return args[idx]; |
| 1932 | }); |
| 1933 | var index = this.lastMarker.index; |
| 1934 | var line = this.lastMarker.line; |
| 1935 | var column = this.lastMarker.column + 1; |
| 1936 | throw this.errorHandler.createError(index, line, column, msg); |
| 1937 | }; |
| 1938 | Parser.prototype.tolerateError = function (messageFormat) { |
| 1939 | var values = []; |
| 1940 | for (var _i = 1; _i < arguments.length; _i++) { |
| 1941 | values[_i - 1] = arguments[_i]; |
| 1942 | } |
| 1943 | var args = Array.prototype.slice.call(arguments, 1); |
| 1944 | var msg = messageFormat.replace(/%(\d)/g, function (whole, idx) { |
| 1945 | assert_1.assert(idx < args.length, 'Message reference must be in range'); |
| 1946 | return args[idx]; |
| 1947 | }); |
| 1948 | var index = this.lastMarker.index; |
| 1949 | var line = this.scanner.lineNumber; |
| 1950 | var column = this.lastMarker.column + 1; |
| 1951 | this.errorHandler.tolerateError(index, line, column, msg); |
| 1952 | }; |
| 1953 | // Throw an exception because of the token. |
| 1954 | Parser.prototype.unexpectedTokenError = function (token, message) { |
| 1955 | var msg = message || messages_1.Messages.UnexpectedToken; |
| 1956 | var value; |
| 1957 | if (token) { |
| 1958 | if (!message) { |
| 1959 | msg = (token.type === 2 /* EOF */) ? messages_1.Messages.UnexpectedEOS : |
| 1960 | (token.type === 3 /* Identifier */) ? messages_1.Messages.UnexpectedIdentifier : |
| 1961 | (token.type === 6 /* NumericLiteral */) ? messages_1.Messages.UnexpectedNumber : |
| 1962 | (token.type === 8 /* StringLiteral */) ? messages_1.Messages.UnexpectedString : |
| 1963 | (token.type === 10 /* Template */) ? messages_1.Messages.UnexpectedTemplate : |
| 1964 | messages_1.Messages.UnexpectedToken; |
| 1965 | if (token.type === 4 /* Keyword */) { |
| 1966 | if (this.scanner.isFutureReservedWord(token.value)) { |
| 1967 | msg = messages_1.Messages.UnexpectedReserved; |
| 1968 | } |
| 1969 | else if (this.context.strict && this.scanner.isStrictModeReservedWord(token.value)) { |
| 1970 | msg = messages_1.Messages.StrictReservedWord; |
| 1971 | } |
| 1972 | } |
| 1973 | } |
| 1974 | value = token.value; |
| 1975 | } |
| 1976 | else { |
| 1977 | value = 'ILLEGAL'; |
| 1978 | } |
| 1979 | msg = msg.replace('%0', value); |
| 1980 | if (token && typeof token.lineNumber === 'number') { |
| 1981 | var index = token.start; |
| 1982 | var line = token.lineNumber; |
| 1983 | var lastMarkerLineStart = this.lastMarker.index - this.lastMarker.column; |
| 1984 | var column = token.start - lastMarkerLineStart + 1; |
| 1985 | return this.errorHandler.createError(index, line, column, msg); |
| 1986 | } |
| 1987 | else { |
| 1988 | var index = this.lastMarker.index; |
| 1989 | var line = this.lastMarker.line; |
| 1990 | var column = this.lastMarker.column + 1; |
| 1991 | return this.errorHandler.createError(index, line, column, msg); |
| 1992 | } |
| 1993 | }; |
| 1994 | Parser.prototype.throwUnexpectedToken = function (token, message) { |
| 1995 | throw this.unexpectedTokenError(token, message); |
| 1996 | }; |
| 1997 | Parser.prototype.tolerateUnexpectedToken = function (token, message) { |
| 1998 | this.errorHandler.tolerate(this.unexpectedTokenError(token, message)); |
| 1999 | }; |
| 2000 | Parser.prototype.collectComments = function () { |
| 2001 | if (!this.config.comment) { |
| 2002 | this.scanner.scanComments(); |
| 2003 | } |
| 2004 | else { |
| 2005 | var comments = this.scanner.scanComments(); |
| 2006 | if (comments.length > 0 && this.delegate) { |
| 2007 | for (var i = 0; i < comments.length; ++i) { |
| 2008 | var e = comments[i]; |
| 2009 | var node = void 0; |
| 2010 | node = { |
| 2011 | type: e.multiLine ? 'BlockComment' : 'LineComment', |
| 2012 | value: this.scanner.source.slice(e.slice[0], e.slice[1]) |
| 2013 | }; |
| 2014 | if (this.config.range) { |
| 2015 | node.range = e.range; |
| 2016 | } |
| 2017 | if (this.config.loc) { |
| 2018 | node.loc = e.loc; |
| 2019 | } |
| 2020 | var metadata = { |
| 2021 | start: { |
| 2022 | line: e.loc.start.line, |
| 2023 | column: e.loc.start.column, |
| 2024 | offset: e.range[0] |
| 2025 | }, |
| 2026 | end: { |
| 2027 | line: e.loc.end.line, |
| 2028 | column: e.loc.end.column, |
| 2029 | offset: e.range[1] |
| 2030 | } |
| 2031 | }; |
| 2032 | this.delegate(node, metadata); |
| 2033 | } |
| 2034 | } |
| 2035 | } |
| 2036 | }; |
| 2037 | // From internal representation to an external structure |
| 2038 | Parser.prototype.getTokenRaw = function (token) { |
| 2039 | return this.scanner.source.slice(token.start, token.end); |
| 2040 | }; |
| 2041 | Parser.prototype.convertToken = function (token) { |
| 2042 | var t = { |
| 2043 | type: token_1.TokenName[token.type], |
| 2044 | value: this.getTokenRaw(token) |
| 2045 | }; |
| 2046 | if (this.config.range) { |
| 2047 | t.range = [token.start, token.end]; |
| 2048 | } |
| 2049 | if (this.config.loc) { |
| 2050 | t.loc = { |
| 2051 | start: { |
| 2052 | line: this.startMarker.line, |
| 2053 | column: this.startMarker.column |
| 2054 | }, |
| 2055 | end: { |
| 2056 | line: this.scanner.lineNumber, |
| 2057 | column: this.scanner.index - this.scanner.lineStart |
| 2058 | } |
| 2059 | }; |
| 2060 | } |
| 2061 | if (token.type === 9 /* RegularExpression */) { |
| 2062 | var pattern = token.pattern; |
| 2063 | var flags = token.flags; |
| 2064 | t.regex = { pattern: pattern, flags: flags }; |
| 2065 | } |
| 2066 | return t; |
| 2067 | }; |
| 2068 | Parser.prototype.nextToken = function () { |
| 2069 | var token = this.lookahead; |
| 2070 | this.lastMarker.index = this.scanner.index; |
| 2071 | this.lastMarker.line = this.scanner.lineNumber; |
| 2072 | this.lastMarker.column = this.scanner.index - this.scanner.lineStart; |
| 2073 | this.collectComments(); |
| 2074 | if (this.scanner.index !== this.startMarker.index) { |
| 2075 | this.startMarker.index = this.scanner.index; |
| 2076 | this.startMarker.line = this.scanner.lineNumber; |
| 2077 | this.startMarker.column = this.scanner.index - this.scanner.lineStart; |
| 2078 | } |
| 2079 | var next = this.scanner.lex(); |
| 2080 | this.hasLineTerminator = (token.lineNumber !== next.lineNumber); |
| 2081 | if (next && this.context.strict && next.type === 3 /* Identifier */) { |
| 2082 | if (this.scanner.isStrictModeReservedWord(next.value)) { |
| 2083 | next.type = 4 /* Keyword */; |
| 2084 | } |
| 2085 | } |
| 2086 | this.lookahead = next; |
| 2087 | if (this.config.tokens && next.type !== 2 /* EOF */) { |
| 2088 | this.tokens.push(this.convertToken(next)); |
| 2089 | } |
| 2090 | return token; |
| 2091 | }; |
| 2092 | Parser.prototype.nextRegexToken = function () { |
| 2093 | this.collectComments(); |
| 2094 | var token = this.scanner.scanRegExp(); |
| 2095 | if (this.config.tokens) { |
| 2096 | // Pop the previous token, '/' or '/=' |
| 2097 | // This is added from the lookahead token. |
| 2098 | this.tokens.pop(); |
| 2099 | this.tokens.push(this.convertToken(token)); |
| 2100 | } |
| 2101 | // Prime the next lookahead. |
| 2102 | this.lookahead = token; |
| 2103 | this.nextToken(); |
| 2104 | return token; |
| 2105 | }; |
| 2106 | Parser.prototype.createNode = function () { |
| 2107 | return { |
| 2108 | index: this.startMarker.index, |
| 2109 | line: this.startMarker.line, |
| 2110 | column: this.startMarker.column |
| 2111 | }; |
| 2112 | }; |
| 2113 | Parser.prototype.startNode = function (token) { |
| 2114 | return { |
| 2115 | index: token.start, |
| 2116 | line: token.lineNumber, |
| 2117 | column: token.start - token.lineStart |
| 2118 | }; |
| 2119 | }; |
| 2120 | Parser.prototype.finalize = function (marker, node) { |
| 2121 | if (this.config.range) { |
| 2122 | node.range = [marker.index, this.lastMarker.index]; |
| 2123 | } |
| 2124 | if (this.config.loc) { |
| 2125 | node.loc = { |
| 2126 | start: { |
| 2127 | line: marker.line, |
| 2128 | column: marker.column, |
| 2129 | }, |
| 2130 | end: { |
| 2131 | line: this.lastMarker.line, |
| 2132 | column: this.lastMarker.column |
| 2133 | } |
| 2134 | }; |
| 2135 | if (this.config.source) { |
| 2136 | node.loc.source = this.config.source; |
| 2137 | } |
| 2138 | } |
| 2139 | if (this.delegate) { |
| 2140 | var metadata = { |
| 2141 | start: { |
| 2142 | line: marker.line, |
| 2143 | column: marker.column, |
| 2144 | offset: marker.index |
| 2145 | }, |
| 2146 | end: { |
| 2147 | line: this.lastMarker.line, |
| 2148 | column: this.lastMarker.column, |
| 2149 | offset: this.lastMarker.index |
| 2150 | } |
| 2151 | }; |
| 2152 | this.delegate(node, metadata); |
| 2153 | } |
| 2154 | return node; |
| 2155 | }; |
| 2156 | // Expect the next token to match the specified punctuator. |
| 2157 | // If not, an exception will be thrown. |
| 2158 | Parser.prototype.expect = function (value) { |
| 2159 | var token = this.nextToken(); |
| 2160 | if (token.type !== 7 /* Punctuator */ || token.value !== value) { |
| 2161 | this.throwUnexpectedToken(token); |
| 2162 | } |
| 2163 | }; |
| 2164 | // Quietly expect a comma when in tolerant mode, otherwise delegates to expect(). |
| 2165 | Parser.prototype.expectCommaSeparator = function () { |
| 2166 | if (this.config.tolerant) { |
| 2167 | var token = this.lookahead; |
| 2168 | if (token.type === 7 /* Punctuator */ && token.value === ',') { |
| 2169 | this.nextToken(); |
| 2170 | } |
| 2171 | else if (token.type === 7 /* Punctuator */ && token.value === ';') { |
| 2172 | this.nextToken(); |
| 2173 | this.tolerateUnexpectedToken(token); |
| 2174 | } |
| 2175 | else { |
| 2176 | this.tolerateUnexpectedToken(token, messages_1.Messages.UnexpectedToken); |
| 2177 | } |
| 2178 | } |
| 2179 | else { |
| 2180 | this.expect(','); |
| 2181 | } |
| 2182 | }; |
| 2183 | // Expect the next token to match the specified keyword. |
| 2184 | // If not, an exception will be thrown. |
| 2185 | Parser.prototype.expectKeyword = function (keyword) { |
| 2186 | var token = this.nextToken(); |
| 2187 | if (token.type !== 4 /* Keyword */ || token.value !== keyword) { |
| 2188 | this.throwUnexpectedToken(token); |
| 2189 | } |
| 2190 | }; |
| 2191 | // Return true if the next token matches the specified punctuator. |
| 2192 | Parser.prototype.match = function (value) { |
| 2193 | return this.lookahead.type === 7 /* Punctuator */ && this.lookahead.value === value; |
| 2194 | }; |
| 2195 | // Return true if the next token matches the specified keyword |
| 2196 | Parser.prototype.matchKeyword = function (keyword) { |
| 2197 | return this.lookahead.type === 4 /* Keyword */ && this.lookahead.value === keyword; |
| 2198 | }; |
| 2199 | // Return true if the next token matches the specified contextual keyword |
| 2200 | // (where an identifier is sometimes a keyword depending on the context) |
| 2201 | Parser.prototype.matchContextualKeyword = function (keyword) { |
| 2202 | return this.lookahead.type === 3 /* Identifier */ && this.lookahead.value === keyword; |
| 2203 | }; |
| 2204 | // Return true if the next token is an assignment operator |
| 2205 | Parser.prototype.matchAssign = function () { |
| 2206 | if (this.lookahead.type !== 7 /* Punctuator */) { |
| 2207 | return false; |
| 2208 | } |
| 2209 | var op = this.lookahead.value; |
| 2210 | return op === '=' || |
| 2211 | op === '*=' || |
| 2212 | op === '**=' || |
| 2213 | op === '/=' || |
| 2214 | op === '%=' || |
| 2215 | op === '+=' || |
| 2216 | op === '-=' || |
| 2217 | op === '<<=' || |
| 2218 | op === '>>=' || |
| 2219 | op === '>>>=' || |
| 2220 | op === '&=' || |
| 2221 | op === '^=' || |
| 2222 | op === '|='; |
| 2223 | }; |
| 2224 | // Cover grammar support. |
| 2225 | // |
| 2226 | // When an assignment expression position starts with an left parenthesis, the determination of the type |
| 2227 | // of the syntax is to be deferred arbitrarily long until the end of the parentheses pair (plus a lookahead) |
| 2228 | // or the first comma. This situation also defers the determination of all the expressions nested in the pair. |
| 2229 | // |
| 2230 | // There are three productions that can be parsed in a parentheses pair that needs to be determined |
| 2231 | // after the outermost pair is closed. They are: |
| 2232 | // |
| 2233 | // 1. AssignmentExpression |
| 2234 | // 2. BindingElements |
| 2235 | // 3. AssignmentTargets |
| 2236 | // |
| 2237 | // In order to avoid exponential backtracking, we use two flags to denote if the production can be |
| 2238 | // binding element or assignment target. |
| 2239 | // |
| 2240 | // The three productions have the relationship: |
| 2241 | // |
| 2242 | // BindingElements ⊆ AssignmentTargets ⊆ AssignmentExpression |
| 2243 | // |
| 2244 | // with a single exception that CoverInitializedName when used directly in an Expression, generates |
| 2245 | // an early error. Therefore, we need the third state, firstCoverInitializedNameError, to track the |
| 2246 | // first usage of CoverInitializedName and report it when we reached the end of the parentheses pair. |
| 2247 | // |
| 2248 | // isolateCoverGrammar function runs the given parser function with a new cover grammar context, and it does not |
| 2249 | // effect the current flags. This means the production the parser parses is only used as an expression. Therefore |
| 2250 | // the CoverInitializedName check is conducted. |
| 2251 | // |
| 2252 | // inheritCoverGrammar function runs the given parse function with a new cover grammar context, and it propagates |
| 2253 | // the flags outside of the parser. This means the production the parser parses is used as a part of a potential |
| 2254 | // pattern. The CoverInitializedName check is deferred. |
| 2255 | Parser.prototype.isolateCoverGrammar = function (parseFunction) { |
| 2256 | var previousIsBindingElement = this.context.isBindingElement; |
| 2257 | var previousIsAssignmentTarget = this.context.isAssignmentTarget; |
| 2258 | var previousFirstCoverInitializedNameError = this.context.firstCoverInitializedNameError; |
| 2259 | this.context.isBindingElement = true; |
| 2260 | this.context.isAssignmentTarget = true; |
| 2261 | this.context.firstCoverInitializedNameError = null; |
| 2262 | var result = parseFunction.call(this); |
| 2263 | if (this.context.firstCoverInitializedNameError !== null) { |
| 2264 | this.throwUnexpectedToken(this.context.firstCoverInitializedNameError); |
| 2265 | } |
| 2266 | this.context.isBindingElement = previousIsBindingElement; |
| 2267 | this.context.isAssignmentTarget = previousIsAssignmentTarget; |
| 2268 | this.context.firstCoverInitializedNameError = previousFirstCoverInitializedNameError; |
| 2269 | return result; |
| 2270 | }; |
| 2271 | Parser.prototype.inheritCoverGrammar = function (parseFunction) { |
| 2272 | var previousIsBindingElement = this.context.isBindingElement; |
| 2273 | var previousIsAssignmentTarget = this.context.isAssignmentTarget; |
| 2274 | var previousFirstCoverInitializedNameError = this.context.firstCoverInitializedNameError; |
| 2275 | this.context.isBindingElement = true; |
| 2276 | this.context.isAssignmentTarget = true; |
| 2277 | this.context.firstCoverInitializedNameError = null; |
| 2278 | var result = parseFunction.call(this); |
| 2279 | this.context.isBindingElement = this.context.isBindingElement && previousIsBindingElement; |
| 2280 | this.context.isAssignmentTarget = this.context.isAssignmentTarget && previousIsAssignmentTarget; |
| 2281 | this.context.firstCoverInitializedNameError = previousFirstCoverInitializedNameError || this.context.firstCoverInitializedNameError; |
| 2282 | return result; |
| 2283 | }; |
| 2284 | Parser.prototype.consumeSemicolon = function () { |
| 2285 | if (this.match(';')) { |
| 2286 | this.nextToken(); |
| 2287 | } |
| 2288 | else if (!this.hasLineTerminator) { |
| 2289 | if (this.lookahead.type !== 2 /* EOF */ && !this.match('}')) { |
| 2290 | this.throwUnexpectedToken(this.lookahead); |
| 2291 | } |
| 2292 | this.lastMarker.index = this.startMarker.index; |
| 2293 | this.lastMarker.line = this.startMarker.line; |
| 2294 | this.lastMarker.column = this.startMarker.column; |
| 2295 | } |
| 2296 | }; |
| 2297 | // https://tc39.github.io/ecma262/#sec-primary-expression |
| 2298 | Parser.prototype.parsePrimaryExpression = function () { |
| 2299 | var node = this.createNode(); |
| 2300 | var expr; |
| 2301 | var token, raw; |
| 2302 | switch (this.lookahead.type) { |
| 2303 | case 3 /* Identifier */: |
| 2304 | if ((this.context.isModule || this.context.await) && this.lookahead.value === 'await') { |
| 2305 | this.tolerateUnexpectedToken(this.lookahead); |
| 2306 | } |
| 2307 | expr = this.matchAsyncFunction() ? this.parseFunctionExpression() : this.finalize(node, new Node.Identifier(this.nextToken().value)); |
| 2308 | break; |
| 2309 | case 6 /* NumericLiteral */: |
| 2310 | case 8 /* StringLiteral */: |
| 2311 | if (this.context.strict && this.lookahead.octal) { |
| 2312 | this.tolerateUnexpectedToken(this.lookahead, messages_1.Messages.StrictOctalLiteral); |
| 2313 | } |
| 2314 | this.context.isAssignmentTarget = false; |
| 2315 | this.context.isBindingElement = false; |
| 2316 | token = this.nextToken(); |
| 2317 | raw = this.getTokenRaw(token); |
| 2318 | expr = this.finalize(node, new Node.Literal(token.value, raw)); |
| 2319 | break; |
| 2320 | case 1 /* BooleanLiteral */: |
| 2321 | this.context.isAssignmentTarget = false; |
| 2322 | this.context.isBindingElement = false; |
| 2323 | token = this.nextToken(); |
| 2324 | raw = this.getTokenRaw(token); |
| 2325 | expr = this.finalize(node, new Node.Literal(token.value === 'true', raw)); |
| 2326 | break; |
| 2327 | case 5 /* NullLiteral */: |
| 2328 | this.context.isAssignmentTarget = false; |
| 2329 | this.context.isBindingElement = false; |
| 2330 | token = this.nextToken(); |
| 2331 | raw = this.getTokenRaw(token); |
| 2332 | expr = this.finalize(node, new Node.Literal(null, raw)); |
| 2333 | break; |
| 2334 | case 10 /* Template */: |
| 2335 | expr = this.parseTemplateLiteral(); |
| 2336 | break; |
| 2337 | case 7 /* Punctuator */: |
| 2338 | switch (this.lookahead.value) { |
| 2339 | case '(': |
| 2340 | this.context.isBindingElement = false; |
| 2341 | expr = this.inheritCoverGrammar(this.parseGroupExpression); |
| 2342 | break; |
| 2343 | case '[': |
| 2344 | expr = this.inheritCoverGrammar(this.parseArrayInitializer); |
| 2345 | break; |
| 2346 | case '{': |
| 2347 | expr = this.inheritCoverGrammar(this.parseObjectInitializer); |
| 2348 | break; |
| 2349 | case '/': |
| 2350 | case '/=': |
| 2351 | this.context.isAssignmentTarget = false; |
| 2352 | this.context.isBindingElement = false; |
| 2353 | this.scanner.index = this.startMarker.index; |
| 2354 | token = this.nextRegexToken(); |
| 2355 | raw = this.getTokenRaw(token); |
| 2356 | expr = this.finalize(node, new Node.RegexLiteral(token.regex, raw, token.pattern, token.flags)); |
| 2357 | break; |
| 2358 | default: |
| 2359 | expr = this.throwUnexpectedToken(this.nextToken()); |
| 2360 | } |
| 2361 | break; |
| 2362 | case 4 /* Keyword */: |
| 2363 | if (!this.context.strict && this.context.allowYield && this.matchKeyword('yield')) { |
| 2364 | expr = this.parseIdentifierName(); |
| 2365 | } |
| 2366 | else if (!this.context.strict && this.matchKeyword('let')) { |
| 2367 | expr = this.finalize(node, new Node.Identifier(this.nextToken().value)); |
| 2368 | } |
| 2369 | else { |
| 2370 | this.context.isAssignmentTarget = false; |
| 2371 | this.context.isBindingElement = false; |
| 2372 | if (this.matchKeyword('function')) { |
| 2373 | expr = this.parseFunctionExpression(); |
| 2374 | } |
| 2375 | else if (this.matchKeyword('this')) { |
| 2376 | this.nextToken(); |
| 2377 | expr = this.finalize(node, new Node.ThisExpression()); |
| 2378 | } |
| 2379 | else if (this.matchKeyword('class')) { |
| 2380 | expr = this.parseClassExpression(); |
| 2381 | } |
| 2382 | else { |
| 2383 | expr = this.throwUnexpectedToken(this.nextToken()); |
| 2384 | } |
| 2385 | } |
| 2386 | break; |
| 2387 | default: |
| 2388 | expr = this.throwUnexpectedToken(this.nextToken()); |
| 2389 | } |
| 2390 | return expr; |
| 2391 | }; |
| 2392 | // https://tc39.github.io/ecma262/#sec-array-initializer |
| 2393 | Parser.prototype.parseSpreadElement = function () { |
| 2394 | var node = this.createNode(); |
| 2395 | this.expect('...'); |
| 2396 | var arg = this.inheritCoverGrammar(this.parseAssignmentExpression); |
| 2397 | return this.finalize(node, new Node.SpreadElement(arg)); |
| 2398 | }; |
| 2399 | Parser.prototype.parseArrayInitializer = function () { |
| 2400 | var node = this.createNode(); |
| 2401 | var elements = []; |
| 2402 | this.expect('['); |
| 2403 | while (!this.match(']')) { |
| 2404 | if (this.match(',')) { |
| 2405 | this.nextToken(); |
| 2406 | elements.push(null); |
| 2407 | } |
| 2408 | else if (this.match('...')) { |
| 2409 | var element = this.parseSpreadElement(); |
| 2410 | if (!this.match(']')) { |
| 2411 | this.context.isAssignmentTarget = false; |
| 2412 | this.context.isBindingElement = false; |
| 2413 | this.expect(','); |
| 2414 | } |
| 2415 | elements.push(element); |
| 2416 | } |
| 2417 | else { |
| 2418 | elements.push(this.inheritCoverGrammar(this.parseAssignmentExpression)); |
| 2419 | if (!this.match(']')) { |
| 2420 | this.expect(','); |
| 2421 | } |
| 2422 | } |
| 2423 | } |
| 2424 | this.expect(']'); |
| 2425 | return this.finalize(node, new Node.ArrayExpression(elements)); |
| 2426 | }; |
| 2427 | // https://tc39.github.io/ecma262/#sec-object-initializer |
| 2428 | Parser.prototype.parsePropertyMethod = function (params) { |
| 2429 | this.context.isAssignmentTarget = false; |
| 2430 | this.context.isBindingElement = false; |
| 2431 | var previousStrict = this.context.strict; |
| 2432 | var previousAllowStrictDirective = this.context.allowStrictDirective; |
| 2433 | this.context.allowStrictDirective = params.simple; |
| 2434 | var body = this.isolateCoverGrammar(this.parseFunctionSourceElements); |
| 2435 | if (this.context.strict && params.firstRestricted) { |
| 2436 | this.tolerateUnexpectedToken(params.firstRestricted, params.message); |
| 2437 | } |
| 2438 | if (this.context.strict && params.stricted) { |
| 2439 | this.tolerateUnexpectedToken(params.stricted, params.message); |
| 2440 | } |
| 2441 | this.context.strict = previousStrict; |
| 2442 | this.context.allowStrictDirective = previousAllowStrictDirective; |
| 2443 | return body; |
| 2444 | }; |
| 2445 | Parser.prototype.parsePropertyMethodFunction = function () { |
| 2446 | var isGenerator = false; |
| 2447 | var node = this.createNode(); |
| 2448 | var previousAllowYield = this.context.allowYield; |
| 2449 | this.context.allowYield = false; |
| 2450 | var params = this.parseFormalParameters(); |
| 2451 | var method = this.parsePropertyMethod(params); |
| 2452 | this.context.allowYield = previousAllowYield; |
| 2453 | return this.finalize(node, new Node.FunctionExpression(null, params.params, method, isGenerator)); |
| 2454 | }; |
| 2455 | Parser.prototype.parsePropertyMethodAsyncFunction = function () { |
| 2456 | var node = this.createNode(); |
| 2457 | var previousAllowYield = this.context.allowYield; |
| 2458 | var previousAwait = this.context.await; |
| 2459 | this.context.allowYield = false; |
| 2460 | this.context.await = true; |
| 2461 | var params = this.parseFormalParameters(); |
| 2462 | var method = this.parsePropertyMethod(params); |
| 2463 | this.context.allowYield = previousAllowYield; |
| 2464 | this.context.await = previousAwait; |
| 2465 | return this.finalize(node, new Node.AsyncFunctionExpression(null, params.params, method)); |
| 2466 | }; |
| 2467 | Parser.prototype.parseObjectPropertyKey = function () { |
| 2468 | var node = this.createNode(); |
| 2469 | var token = this.nextToken(); |
| 2470 | var key; |
| 2471 | switch (token.type) { |
| 2472 | case 8 /* StringLiteral */: |
| 2473 | case 6 /* NumericLiteral */: |
| 2474 | if (this.context.strict && token.octal) { |
| 2475 | this.tolerateUnexpectedToken(token, messages_1.Messages.StrictOctalLiteral); |
| 2476 | } |
| 2477 | var raw = this.getTokenRaw(token); |
| 2478 | key = this.finalize(node, new Node.Literal(token.value, raw)); |
| 2479 | break; |
| 2480 | case 3 /* Identifier */: |
| 2481 | case 1 /* BooleanLiteral */: |
| 2482 | case 5 /* NullLiteral */: |
| 2483 | case 4 /* Keyword */: |
| 2484 | key = this.finalize(node, new Node.Identifier(token.value)); |
| 2485 | break; |
| 2486 | case 7 /* Punctuator */: |
| 2487 | if (token.value === '[') { |
| 2488 | key = this.isolateCoverGrammar(this.parseAssignmentExpression); |
| 2489 | this.expect(']'); |
| 2490 | } |
| 2491 | else { |
| 2492 | key = this.throwUnexpectedToken(token); |
| 2493 | } |
| 2494 | break; |
| 2495 | default: |
| 2496 | key = this.throwUnexpectedToken(token); |
| 2497 | } |
| 2498 | return key; |
| 2499 | }; |
| 2500 | Parser.prototype.isPropertyKey = function (key, value) { |
| 2501 | return (key.type === syntax_1.Syntax.Identifier && key.name === value) || |
| 2502 | (key.type === syntax_1.Syntax.Literal && key.value === value); |
| 2503 | }; |
| 2504 | Parser.prototype.parseObjectProperty = function (hasProto) { |
| 2505 | var node = this.createNode(); |
| 2506 | var token = this.lookahead; |
| 2507 | var kind; |
| 2508 | var key = null; |
| 2509 | var value = null; |
| 2510 | var computed = false; |
| 2511 | var method = false; |
| 2512 | var shorthand = false; |
| 2513 | var isAsync = false; |
| 2514 | if (token.type === 3 /* Identifier */) { |
| 2515 | var id = token.value; |
| 2516 | this.nextToken(); |
| 2517 | computed = this.match('['); |
| 2518 | isAsync = !this.hasLineTerminator && (id === 'async') && |
| 2519 | !this.match(':') && !this.match('(') && !this.match('*'); |
| 2520 | key = isAsync ? this.parseObjectPropertyKey() : this.finalize(node, new Node.Identifier(id)); |
| 2521 | } |
| 2522 | else if (this.match('*')) { |
| 2523 | this.nextToken(); |
| 2524 | } |
| 2525 | else { |
| 2526 | computed = this.match('['); |
| 2527 | key = this.parseObjectPropertyKey(); |
| 2528 | } |
| 2529 | var lookaheadPropertyKey = this.qualifiedPropertyName(this.lookahead); |
| 2530 | if (token.type === 3 /* Identifier */ && !isAsync && token.value === 'get' && lookaheadPropertyKey) { |
| 2531 | kind = 'get'; |
| 2532 | computed = this.match('['); |
| 2533 | key = this.parseObjectPropertyKey(); |
| 2534 | this.context.allowYield = false; |
| 2535 | value = this.parseGetterMethod(); |
| 2536 | } |
| 2537 | else if (token.type === 3 /* Identifier */ && !isAsync && token.value === 'set' && lookaheadPropertyKey) { |
| 2538 | kind = 'set'; |
| 2539 | computed = this.match('['); |
| 2540 | key = this.parseObjectPropertyKey(); |
| 2541 | value = this.parseSetterMethod(); |
| 2542 | } |
| 2543 | else if (token.type === 7 /* Punctuator */ && token.value === '*' && lookaheadPropertyKey) { |
| 2544 | kind = 'init'; |
| 2545 | computed = this.match('['); |
| 2546 | key = this.parseObjectPropertyKey(); |
| 2547 | value = this.parseGeneratorMethod(); |
| 2548 | method = true; |
| 2549 | } |
| 2550 | else { |
| 2551 | if (!key) { |
| 2552 | this.throwUnexpectedToken(this.lookahead); |
| 2553 | } |
| 2554 | kind = 'init'; |
| 2555 | if (this.match(':') && !isAsync) { |
| 2556 | if (!computed && this.isPropertyKey(key, '__proto__')) { |
| 2557 | if (hasProto.value) { |
| 2558 | this.tolerateError(messages_1.Messages.DuplicateProtoProperty); |
| 2559 | } |
| 2560 | hasProto.value = true; |
| 2561 | } |
| 2562 | this.nextToken(); |
| 2563 | value = this.inheritCoverGrammar(this.parseAssignmentExpression); |
| 2564 | } |
| 2565 | else if (this.match('(')) { |
| 2566 | value = isAsync ? this.parsePropertyMethodAsyncFunction() : this.parsePropertyMethodFunction(); |
| 2567 | method = true; |
| 2568 | } |
| 2569 | else if (token.type === 3 /* Identifier */) { |
| 2570 | var id = this.finalize(node, new Node.Identifier(token.value)); |
| 2571 | if (this.match('=')) { |
| 2572 | this.context.firstCoverInitializedNameError = this.lookahead; |
| 2573 | this.nextToken(); |
| 2574 | shorthand = true; |
| 2575 | var init = this.isolateCoverGrammar(this.parseAssignmentExpression); |
| 2576 | value = this.finalize(node, new Node.AssignmentPattern(id, init)); |
| 2577 | } |
| 2578 | else { |
| 2579 | shorthand = true; |
| 2580 | value = id; |
| 2581 | } |
| 2582 | } |
| 2583 | else { |
| 2584 | this.throwUnexpectedToken(this.nextToken()); |
| 2585 | } |
| 2586 | } |
| 2587 | return this.finalize(node, new Node.Property(kind, key, computed, value, method, shorthand)); |
| 2588 | }; |
| 2589 | Parser.prototype.parseObjectInitializer = function () { |
| 2590 | var node = this.createNode(); |
| 2591 | this.expect('{'); |
| 2592 | var properties = []; |
| 2593 | var hasProto = { value: false }; |
| 2594 | while (!this.match('}')) { |
| 2595 | properties.push(this.parseObjectProperty(hasProto)); |
| 2596 | if (!this.match('}')) { |
| 2597 | this.expectCommaSeparator(); |
| 2598 | } |
| 2599 | } |
| 2600 | this.expect('}'); |
| 2601 | return this.finalize(node, new Node.ObjectExpression(properties)); |
| 2602 | }; |
| 2603 | // https://tc39.github.io/ecma262/#sec-template-literals |
| 2604 | Parser.prototype.parseTemplateHead = function () { |
| 2605 | assert_1.assert(this.lookahead.head, 'Template literal must start with a template head'); |
| 2606 | var node = this.createNode(); |
| 2607 | var token = this.nextToken(); |
| 2608 | var raw = token.value; |
| 2609 | var cooked = token.cooked; |
| 2610 | return this.finalize(node, new Node.TemplateElement({ raw: raw, cooked: cooked }, token.tail)); |
| 2611 | }; |
| 2612 | Parser.prototype.parseTemplateElement = function () { |
| 2613 | if (this.lookahead.type !== 10 /* Template */) { |
| 2614 | this.throwUnexpectedToken(); |
| 2615 | } |
| 2616 | var node = this.createNode(); |
| 2617 | var token = this.nextToken(); |
| 2618 | var raw = token.value; |
| 2619 | var cooked = token.cooked; |
| 2620 | return this.finalize(node, new Node.TemplateElement({ raw: raw, cooked: cooked }, token.tail)); |
| 2621 | }; |
| 2622 | Parser.prototype.parseTemplateLiteral = function () { |
| 2623 | var node = this.createNode(); |
| 2624 | var expressions = []; |
| 2625 | var quasis = []; |
| 2626 | var quasi = this.parseTemplateHead(); |
| 2627 | quasis.push(quasi); |
| 2628 | while (!quasi.tail) { |
| 2629 | expressions.push(this.parseExpression()); |
| 2630 | quasi = this.parseTemplateElement(); |
| 2631 | quasis.push(quasi); |
| 2632 | } |
| 2633 | return this.finalize(node, new Node.TemplateLiteral(quasis, expressions)); |
| 2634 | }; |
| 2635 | // https://tc39.github.io/ecma262/#sec-grouping-operator |
| 2636 | Parser.prototype.reinterpretExpressionAsPattern = function (expr) { |
| 2637 | switch (expr.type) { |
| 2638 | case syntax_1.Syntax.Identifier: |
| 2639 | case syntax_1.Syntax.MemberExpression: |
| 2640 | case syntax_1.Syntax.RestElement: |
| 2641 | case syntax_1.Syntax.AssignmentPattern: |
| 2642 | break; |
| 2643 | case syntax_1.Syntax.SpreadElement: |
| 2644 | expr.type = syntax_1.Syntax.RestElement; |
| 2645 | this.reinterpretExpressionAsPattern(expr.argument); |
| 2646 | break; |
| 2647 | case syntax_1.Syntax.ArrayExpression: |
| 2648 | expr.type = syntax_1.Syntax.ArrayPattern; |
| 2649 | for (var i = 0; i < expr.elements.length; i++) { |
| 2650 | if (expr.elements[i] !== null) { |
| 2651 | this.reinterpretExpressionAsPattern(expr.elements[i]); |
| 2652 | } |
| 2653 | } |
| 2654 | break; |
| 2655 | case syntax_1.Syntax.ObjectExpression: |
| 2656 | expr.type = syntax_1.Syntax.ObjectPattern; |
| 2657 | for (var i = 0; i < expr.properties.length; i++) { |
| 2658 | this.reinterpretExpressionAsPattern(expr.properties[i].value); |
| 2659 | } |
| 2660 | break; |
| 2661 | case syntax_1.Syntax.AssignmentExpression: |
| 2662 | expr.type = syntax_1.Syntax.AssignmentPattern; |
| 2663 | delete expr.operator; |
| 2664 | this.reinterpretExpressionAsPattern(expr.left); |
| 2665 | break; |
| 2666 | default: |
| 2667 | // Allow other node type for tolerant parsing. |
| 2668 | break; |
| 2669 | } |
| 2670 | }; |
| 2671 | Parser.prototype.parseGroupExpression = function () { |
| 2672 | var expr; |
| 2673 | this.expect('('); |
| 2674 | if (this.match(')')) { |
| 2675 | this.nextToken(); |
| 2676 | if (!this.match('=>')) { |
| 2677 | this.expect('=>'); |
| 2678 | } |
| 2679 | expr = { |
| 2680 | type: ArrowParameterPlaceHolder, |
| 2681 | params: [], |
| 2682 | async: false |
| 2683 | }; |
| 2684 | } |
| 2685 | else { |
| 2686 | var startToken = this.lookahead; |
| 2687 | var params = []; |
| 2688 | if (this.match('...')) { |
| 2689 | expr = this.parseRestElement(params); |
| 2690 | this.expect(')'); |
| 2691 | if (!this.match('=>')) { |
| 2692 | this.expect('=>'); |
| 2693 | } |
| 2694 | expr = { |
| 2695 | type: ArrowParameterPlaceHolder, |
| 2696 | params: [expr], |
| 2697 | async: false |
| 2698 | }; |
| 2699 | } |
| 2700 | else { |
| 2701 | var arrow = false; |
| 2702 | this.context.isBindingElement = true; |
| 2703 | expr = this.inheritCoverGrammar(this.parseAssignmentExpression); |
| 2704 | if (this.match(',')) { |
| 2705 | var expressions = []; |
| 2706 | this.context.isAssignmentTarget = false; |
| 2707 | expressions.push(expr); |
| 2708 | while (this.lookahead.type !== 2 /* EOF */) { |
| 2709 | if (!this.match(',')) { |
| 2710 | break; |
| 2711 | } |
| 2712 | this.nextToken(); |
| 2713 | if (this.match(')')) { |
| 2714 | this.nextToken(); |
| 2715 | for (var i = 0; i < expressions.length; i++) { |
| 2716 | this.reinterpretExpressionAsPattern(expressions[i]); |
| 2717 | } |
| 2718 | arrow = true; |
| 2719 | expr = { |
| 2720 | type: ArrowParameterPlaceHolder, |
| 2721 | params: expressions, |
| 2722 | async: false |
| 2723 | }; |
| 2724 | } |
| 2725 | else if (this.match('...')) { |
| 2726 | if (!this.context.isBindingElement) { |
| 2727 | this.throwUnexpectedToken(this.lookahead); |
| 2728 | } |
| 2729 | expressions.push(this.parseRestElement(params)); |
| 2730 | this.expect(')'); |
| 2731 | if (!this.match('=>')) { |
| 2732 | this.expect('=>'); |
| 2733 | } |
| 2734 | this.context.isBindingElement = false; |
| 2735 | for (var i = 0; i < expressions.length; i++) { |
| 2736 | this.reinterpretExpressionAsPattern(expressions[i]); |
| 2737 | } |
| 2738 | arrow = true; |
| 2739 | expr = { |
| 2740 | type: ArrowParameterPlaceHolder, |
| 2741 | params: expressions, |
| 2742 | async: false |
| 2743 | }; |
| 2744 | } |
| 2745 | else { |
| 2746 | expressions.push(this.inheritCoverGrammar(this.parseAssignmentExpression)); |
| 2747 | } |
| 2748 | if (arrow) { |
| 2749 | break; |
| 2750 | } |
| 2751 | } |
| 2752 | if (!arrow) { |
| 2753 | expr = this.finalize(this.startNode(startToken), new Node.SequenceExpression(expressions)); |
| 2754 | } |
| 2755 | } |
| 2756 | if (!arrow) { |
| 2757 | this.expect(')'); |
| 2758 | if (this.match('=>')) { |
| 2759 | if (expr.type === syntax_1.Syntax.Identifier && expr.name === 'yield') { |
| 2760 | arrow = true; |
| 2761 | expr = { |
| 2762 | type: ArrowParameterPlaceHolder, |
| 2763 | params: [expr], |
| 2764 | async: false |
| 2765 | }; |
| 2766 | } |
| 2767 | if (!arrow) { |
| 2768 | if (!this.context.isBindingElement) { |
| 2769 | this.throwUnexpectedToken(this.lookahead); |
| 2770 | } |
| 2771 | if (expr.type === syntax_1.Syntax.SequenceExpression) { |
| 2772 | for (var i = 0; i < expr.expressions.length; i++) { |
| 2773 | this.reinterpretExpressionAsPattern(expr.expressions[i]); |
| 2774 | } |
| 2775 | } |
| 2776 | else { |
| 2777 | this.reinterpretExpressionAsPattern(expr); |
| 2778 | } |
| 2779 | var parameters = (expr.type === syntax_1.Syntax.SequenceExpression ? expr.expressions : [expr]); |
| 2780 | expr = { |
| 2781 | type: ArrowParameterPlaceHolder, |
| 2782 | params: parameters, |
| 2783 | async: false |
| 2784 | }; |
| 2785 | } |
| 2786 | } |
| 2787 | this.context.isBindingElement = false; |
| 2788 | } |
| 2789 | } |
| 2790 | } |
| 2791 | return expr; |
| 2792 | }; |
| 2793 | // https://tc39.github.io/ecma262/#sec-left-hand-side-expressions |
| 2794 | Parser.prototype.parseArguments = function () { |
| 2795 | this.expect('('); |
| 2796 | var args = []; |
| 2797 | if (!this.match(')')) { |
| 2798 | while (true) { |
| 2799 | var expr = this.match('...') ? this.parseSpreadElement() : |
| 2800 | this.isolateCoverGrammar(this.parseAssignmentExpression); |
| 2801 | args.push(expr); |
| 2802 | if (this.match(')')) { |
| 2803 | break; |
| 2804 | } |
| 2805 | this.expectCommaSeparator(); |
| 2806 | if (this.match(')')) { |
| 2807 | break; |
| 2808 | } |
| 2809 | } |
| 2810 | } |
| 2811 | this.expect(')'); |
| 2812 | return args; |
| 2813 | }; |
| 2814 | Parser.prototype.isIdentifierName = function (token) { |
| 2815 | return token.type === 3 /* Identifier */ || |
| 2816 | token.type === 4 /* Keyword */ || |
| 2817 | token.type === 1 /* BooleanLiteral */ || |
| 2818 | token.type === 5 /* NullLiteral */; |
| 2819 | }; |
| 2820 | Parser.prototype.parseIdentifierName = function () { |
| 2821 | var node = this.createNode(); |
| 2822 | var token = this.nextToken(); |
| 2823 | if (!this.isIdentifierName(token)) { |
| 2824 | this.throwUnexpectedToken(token); |
| 2825 | } |
| 2826 | return this.finalize(node, new Node.Identifier(token.value)); |
| 2827 | }; |
| 2828 | Parser.prototype.parseNewExpression = function () { |
| 2829 | var node = this.createNode(); |
| 2830 | var id = this.parseIdentifierName(); |
| 2831 | assert_1.assert(id.name === 'new', 'New expression must start with `new`'); |
| 2832 | var expr; |
| 2833 | if (this.match('.')) { |
| 2834 | this.nextToken(); |
| 2835 | if (this.lookahead.type === 3 /* Identifier */ && this.context.inFunctionBody && this.lookahead.value === 'target') { |
| 2836 | var property = this.parseIdentifierName(); |
| 2837 | expr = new Node.MetaProperty(id, property); |
| 2838 | } |
| 2839 | else { |
| 2840 | this.throwUnexpectedToken(this.lookahead); |
| 2841 | } |
| 2842 | } |
| 2843 | else { |
| 2844 | var callee = this.isolateCoverGrammar(this.parseLeftHandSideExpression); |
| 2845 | var args = this.match('(') ? this.parseArguments() : []; |
| 2846 | expr = new Node.NewExpression(callee, args); |
| 2847 | this.context.isAssignmentTarget = false; |
| 2848 | this.context.isBindingElement = false; |
| 2849 | } |
| 2850 | return this.finalize(node, expr); |
| 2851 | }; |
| 2852 | Parser.prototype.parseAsyncArgument = function () { |
| 2853 | var arg = this.parseAssignmentExpression(); |
| 2854 | this.context.firstCoverInitializedNameError = null; |
| 2855 | return arg; |
| 2856 | }; |
| 2857 | Parser.prototype.parseAsyncArguments = function () { |
| 2858 | this.expect('('); |
| 2859 | var args = []; |
| 2860 | if (!this.match(')')) { |
| 2861 | while (true) { |
| 2862 | var expr = this.match('...') ? this.parseSpreadElement() : |
| 2863 | this.isolateCoverGrammar(this.parseAsyncArgument); |
| 2864 | args.push(expr); |
| 2865 | if (this.match(')')) { |
| 2866 | break; |
| 2867 | } |
| 2868 | this.expectCommaSeparator(); |
| 2869 | if (this.match(')')) { |
| 2870 | break; |
| 2871 | } |
| 2872 | } |
| 2873 | } |
| 2874 | this.expect(')'); |
| 2875 | return args; |
| 2876 | }; |
| 2877 | Parser.prototype.parseLeftHandSideExpressionAllowCall = function () { |
| 2878 | var startToken = this.lookahead; |
| 2879 | var maybeAsync = this.matchContextualKeyword('async'); |
| 2880 | var previousAllowIn = this.context.allowIn; |
| 2881 | this.context.allowIn = true; |
| 2882 | var expr; |
| 2883 | if (this.matchKeyword('super') && this.context.inFunctionBody) { |
| 2884 | expr = this.createNode(); |
| 2885 | this.nextToken(); |
| 2886 | expr = this.finalize(expr, new Node.Super()); |
| 2887 | if (!this.match('(') && !this.match('.') && !this.match('[')) { |
| 2888 | this.throwUnexpectedToken(this.lookahead); |
| 2889 | } |
| 2890 | } |
| 2891 | else { |
| 2892 | expr = this.inheritCoverGrammar(this.matchKeyword('new') ? this.parseNewExpression : this.parsePrimaryExpression); |
| 2893 | } |
| 2894 | while (true) { |
| 2895 | if (this.match('.')) { |
| 2896 | this.context.isBindingElement = false; |
| 2897 | this.context.isAssignmentTarget = true; |
| 2898 | this.expect('.'); |
| 2899 | var property = this.parseIdentifierName(); |
| 2900 | expr = this.finalize(this.startNode(startToken), new Node.StaticMemberExpression(expr, property)); |
| 2901 | } |
| 2902 | else if (this.match('(')) { |
| 2903 | var asyncArrow = maybeAsync && (startToken.lineNumber === this.lookahead.lineNumber); |
| 2904 | this.context.isBindingElement = false; |
| 2905 | this.context.isAssignmentTarget = false; |
| 2906 | var args = asyncArrow ? this.parseAsyncArguments() : this.parseArguments(); |
| 2907 | expr = this.finalize(this.startNode(startToken), new Node.CallExpression(expr, args)); |
| 2908 | if (asyncArrow && this.match('=>')) { |
| 2909 | for (var i = 0; i < args.length; ++i) { |
| 2910 | this.reinterpretExpressionAsPattern(args[i]); |
| 2911 | } |
| 2912 | expr = { |
| 2913 | type: ArrowParameterPlaceHolder, |
| 2914 | params: args, |
| 2915 | async: true |
| 2916 | }; |
| 2917 | } |
| 2918 | } |
| 2919 | else if (this.match('[')) { |
| 2920 | this.context.isBindingElement = false; |
| 2921 | this.context.isAssignmentTarget = true; |
| 2922 | this.expect('['); |
| 2923 | var property = this.isolateCoverGrammar(this.parseExpression); |
| 2924 | this.expect(']'); |
| 2925 | expr = this.finalize(this.startNode(startToken), new Node.ComputedMemberExpression(expr, property)); |
| 2926 | } |
| 2927 | else if (this.lookahead.type === 10 /* Template */ && this.lookahead.head) { |
| 2928 | var quasi = this.parseTemplateLiteral(); |
| 2929 | expr = this.finalize(this.startNode(startToken), new Node.TaggedTemplateExpression(expr, quasi)); |
| 2930 | } |
| 2931 | else { |
| 2932 | break; |
| 2933 | } |
| 2934 | } |
| 2935 | this.context.allowIn = previousAllowIn; |
| 2936 | return expr; |
| 2937 | }; |
| 2938 | Parser.prototype.parseSuper = function () { |
| 2939 | var node = this.createNode(); |
| 2940 | this.expectKeyword('super'); |
| 2941 | if (!this.match('[') && !this.match('.')) { |
| 2942 | this.throwUnexpectedToken(this.lookahead); |
| 2943 | } |
| 2944 | return this.finalize(node, new Node.Super()); |
| 2945 | }; |
| 2946 | Parser.prototype.parseLeftHandSideExpression = function () { |
| 2947 | assert_1.assert(this.context.allowIn, 'callee of new expression always allow in keyword.'); |
| 2948 | var node = this.startNode(this.lookahead); |
| 2949 | var expr = (this.matchKeyword('super') && this.context.inFunctionBody) ? this.parseSuper() : |
| 2950 | this.inheritCoverGrammar(this.matchKeyword('new') ? this.parseNewExpression : this.parsePrimaryExpression); |
| 2951 | while (true) { |
| 2952 | if (this.match('[')) { |
| 2953 | this.context.isBindingElement = false; |
| 2954 | this.context.isAssignmentTarget = true; |
| 2955 | this.expect('['); |
| 2956 | var property = this.isolateCoverGrammar(this.parseExpression); |
| 2957 | this.expect(']'); |
| 2958 | expr = this.finalize(node, new Node.ComputedMemberExpression(expr, property)); |
| 2959 | } |
| 2960 | else if (this.match('.')) { |
| 2961 | this.context.isBindingElement = false; |
| 2962 | this.context.isAssignmentTarget = true; |
| 2963 | this.expect('.'); |
| 2964 | var property = this.parseIdentifierName(); |
| 2965 | expr = this.finalize(node, new Node.StaticMemberExpression(expr, property)); |
| 2966 | } |
| 2967 | else if (this.lookahead.type === 10 /* Template */ && this.lookahead.head) { |
| 2968 | var quasi = this.parseTemplateLiteral(); |
| 2969 | expr = this.finalize(node, new Node.TaggedTemplateExpression(expr, quasi)); |
| 2970 | } |
| 2971 | else { |
| 2972 | break; |
| 2973 | } |
| 2974 | } |
| 2975 | return expr; |
| 2976 | }; |
| 2977 | // https://tc39.github.io/ecma262/#sec-update-expressions |
| 2978 | Parser.prototype.parseUpdateExpression = function () { |
| 2979 | var expr; |
| 2980 | var startToken = this.lookahead; |
| 2981 | if (this.match('++') || this.match('--')) { |
| 2982 | var node = this.startNode(startToken); |
| 2983 | var token = this.nextToken(); |
| 2984 | expr = this.inheritCoverGrammar(this.parseUnaryExpression); |
| 2985 | if (this.context.strict && expr.type === syntax_1.Syntax.Identifier && this.scanner.isRestrictedWord(expr.name)) { |
| 2986 | this.tolerateError(messages_1.Messages.StrictLHSPrefix); |
| 2987 | } |
| 2988 | if (!this.context.isAssignmentTarget) { |
| 2989 | this.tolerateError(messages_1.Messages.InvalidLHSInAssignment); |
| 2990 | } |
| 2991 | var prefix = true; |
| 2992 | expr = this.finalize(node, new Node.UpdateExpression(token.value, expr, prefix)); |
| 2993 | this.context.isAssignmentTarget = false; |
| 2994 | this.context.isBindingElement = false; |
| 2995 | } |
| 2996 | else { |
| 2997 | expr = this.inheritCoverGrammar(this.parseLeftHandSideExpressionAllowCall); |
| 2998 | if (!this.hasLineTerminator && this.lookahead.type === 7 /* Punctuator */) { |
| 2999 | if (this.match('++') || this.match('--')) { |
| 3000 | if (this.context.strict && expr.type === syntax_1.Syntax.Identifier && this.scanner.isRestrictedWord(expr.name)) { |
| 3001 | this.tolerateError(messages_1.Messages.StrictLHSPostfix); |
| 3002 | } |
| 3003 | if (!this.context.isAssignmentTarget) { |
| 3004 | this.tolerateError(messages_1.Messages.InvalidLHSInAssignment); |
| 3005 | } |
| 3006 | this.context.isAssignmentTarget = false; |
| 3007 | this.context.isBindingElement = false; |
| 3008 | var operator = this.nextToken().value; |
| 3009 | var prefix = false; |
| 3010 | expr = this.finalize(this.startNode(startToken), new Node.UpdateExpression(operator, expr, prefix)); |
| 3011 | } |
| 3012 | } |
| 3013 | } |
| 3014 | return expr; |
| 3015 | }; |
| 3016 | // https://tc39.github.io/ecma262/#sec-unary-operators |
| 3017 | Parser.prototype.parseAwaitExpression = function () { |
| 3018 | var node = this.createNode(); |
| 3019 | this.nextToken(); |
| 3020 | var argument = this.parseUnaryExpression(); |
| 3021 | return this.finalize(node, new Node.AwaitExpression(argument)); |
| 3022 | }; |
| 3023 | Parser.prototype.parseUnaryExpression = function () { |
| 3024 | var expr; |
| 3025 | if (this.match('+') || this.match('-') || this.match('~') || this.match('!') || |
| 3026 | this.matchKeyword('delete') || this.matchKeyword('void') || this.matchKeyword('typeof')) { |
| 3027 | var node = this.startNode(this.lookahead); |
| 3028 | var token = this.nextToken(); |
| 3029 | expr = this.inheritCoverGrammar(this.parseUnaryExpression); |
| 3030 | expr = this.finalize(node, new Node.UnaryExpression(token.value, expr)); |
| 3031 | if (this.context.strict && expr.operator === 'delete' && expr.argument.type === syntax_1.Syntax.Identifier) { |
| 3032 | this.tolerateError(messages_1.Messages.StrictDelete); |
| 3033 | } |
| 3034 | this.context.isAssignmentTarget = false; |
| 3035 | this.context.isBindingElement = false; |
| 3036 | } |
| 3037 | else if (this.context.await && this.matchContextualKeyword('await')) { |
| 3038 | expr = this.parseAwaitExpression(); |
| 3039 | } |
| 3040 | else { |
| 3041 | expr = this.parseUpdateExpression(); |
| 3042 | } |
| 3043 | return expr; |
| 3044 | }; |
| 3045 | Parser.prototype.parseExponentiationExpression = function () { |
| 3046 | var startToken = this.lookahead; |
| 3047 | var expr = this.inheritCoverGrammar(this.parseUnaryExpression); |
| 3048 | if (expr.type !== syntax_1.Syntax.UnaryExpression && this.match('**')) { |
| 3049 | this.nextToken(); |
| 3050 | this.context.isAssignmentTarget = false; |
| 3051 | this.context.isBindingElement = false; |
| 3052 | var left = expr; |
| 3053 | var right = this.isolateCoverGrammar(this.parseExponentiationExpression); |
| 3054 | expr = this.finalize(this.startNode(startToken), new Node.BinaryExpression('**', left, right)); |
| 3055 | } |
| 3056 | return expr; |
| 3057 | }; |
| 3058 | // https://tc39.github.io/ecma262/#sec-exp-operator |
| 3059 | // https://tc39.github.io/ecma262/#sec-multiplicative-operators |
| 3060 | // https://tc39.github.io/ecma262/#sec-additive-operators |
| 3061 | // https://tc39.github.io/ecma262/#sec-bitwise-shift-operators |
| 3062 | // https://tc39.github.io/ecma262/#sec-relational-operators |
| 3063 | // https://tc39.github.io/ecma262/#sec-equality-operators |
| 3064 | // https://tc39.github.io/ecma262/#sec-binary-bitwise-operators |
| 3065 | // https://tc39.github.io/ecma262/#sec-binary-logical-operators |
| 3066 | Parser.prototype.binaryPrecedence = function (token) { |
| 3067 | var op = token.value; |
| 3068 | var precedence; |
| 3069 | if (token.type === 7 /* Punctuator */) { |
| 3070 | precedence = this.operatorPrecedence[op] || 0; |
| 3071 | } |
| 3072 | else if (token.type === 4 /* Keyword */) { |
| 3073 | precedence = (op === 'instanceof' || (this.context.allowIn && op === 'in')) ? 7 : 0; |
| 3074 | } |
| 3075 | else { |
| 3076 | precedence = 0; |
| 3077 | } |
| 3078 | return precedence; |
| 3079 | }; |
| 3080 | Parser.prototype.parseBinaryExpression = function () { |
| 3081 | var startToken = this.lookahead; |
| 3082 | var expr = this.inheritCoverGrammar(this.parseExponentiationExpression); |
| 3083 | var token = this.lookahead; |
| 3084 | var prec = this.binaryPrecedence(token); |
| 3085 | if (prec > 0) { |
| 3086 | this.nextToken(); |
| 3087 | this.context.isAssignmentTarget = false; |
| 3088 | this.context.isBindingElement = false; |
| 3089 | var markers = [startToken, this.lookahead]; |
| 3090 | var left = expr; |
| 3091 | var right = this.isolateCoverGrammar(this.parseExponentiationExpression); |
| 3092 | var stack = [left, token.value, right]; |
| 3093 | var precedences = [prec]; |
| 3094 | while (true) { |
| 3095 | prec = this.binaryPrecedence(this.lookahead); |
| 3096 | if (prec <= 0) { |
| 3097 | break; |
| 3098 | } |
| 3099 | // Reduce: make a binary expression from the three topmost entries. |
| 3100 | while ((stack.length > 2) && (prec <= precedences[precedences.length - 1])) { |
| 3101 | right = stack.pop(); |
| 3102 | var operator = stack.pop(); |
| 3103 | precedences.pop(); |
| 3104 | left = stack.pop(); |
| 3105 | markers.pop(); |
| 3106 | var node = this.startNode(markers[markers.length - 1]); |
| 3107 | stack.push(this.finalize(node, new Node.BinaryExpression(operator, left, right))); |
| 3108 | } |
| 3109 | // Shift. |
| 3110 | stack.push(this.nextToken().value); |
| 3111 | precedences.push(prec); |
| 3112 | markers.push(this.lookahead); |
| 3113 | stack.push(this.isolateCoverGrammar(this.parseExponentiationExpression)); |
| 3114 | } |
| 3115 | // Final reduce to clean-up the stack. |
| 3116 | var i = stack.length - 1; |
| 3117 | expr = stack[i]; |
| 3118 | markers.pop(); |
| 3119 | while (i > 1) { |
| 3120 | var node = this.startNode(markers.pop()); |
| 3121 | var operator = stack[i - 1]; |
| 3122 | expr = this.finalize(node, new Node.BinaryExpression(operator, stack[i - 2], expr)); |
| 3123 | i -= 2; |
| 3124 | } |
| 3125 | } |
| 3126 | return expr; |
| 3127 | }; |
| 3128 | // https://tc39.github.io/ecma262/#sec-conditional-operator |
| 3129 | Parser.prototype.parseConditionalExpression = function () { |
| 3130 | var startToken = this.lookahead; |
| 3131 | var expr = this.inheritCoverGrammar(this.parseBinaryExpression); |
| 3132 | if (this.match('?')) { |
| 3133 | this.nextToken(); |
| 3134 | var previousAllowIn = this.context.allowIn; |
| 3135 | this.context.allowIn = true; |
| 3136 | var consequent = this.isolateCoverGrammar(this.parseAssignmentExpression); |
| 3137 | this.context.allowIn = previousAllowIn; |
| 3138 | this.expect(':'); |
| 3139 | var alternate = this.isolateCoverGrammar(this.parseAssignmentExpression); |
| 3140 | expr = this.finalize(this.startNode(startToken), new Node.ConditionalExpression(expr, consequent, alternate)); |
| 3141 | this.context.isAssignmentTarget = false; |
| 3142 | this.context.isBindingElement = false; |
| 3143 | } |
| 3144 | return expr; |
| 3145 | }; |
| 3146 | // https://tc39.github.io/ecma262/#sec-assignment-operators |
| 3147 | Parser.prototype.checkPatternParam = function (options, param) { |
| 3148 | switch (param.type) { |
| 3149 | case syntax_1.Syntax.Identifier: |
| 3150 | this.validateParam(options, param, param.name); |
| 3151 | break; |
| 3152 | case syntax_1.Syntax.RestElement: |
| 3153 | this.checkPatternParam(options, param.argument); |
| 3154 | break; |
| 3155 | case syntax_1.Syntax.AssignmentPattern: |
| 3156 | this.checkPatternParam(options, param.left); |
| 3157 | break; |
| 3158 | case syntax_1.Syntax.ArrayPattern: |
| 3159 | for (var i = 0; i < param.elements.length; i++) { |
| 3160 | if (param.elements[i] !== null) { |
| 3161 | this.checkPatternParam(options, param.elements[i]); |
| 3162 | } |
| 3163 | } |
| 3164 | break; |
| 3165 | case syntax_1.Syntax.ObjectPattern: |
| 3166 | for (var i = 0; i < param.properties.length; i++) { |
| 3167 | this.checkPatternParam(options, param.properties[i].value); |
| 3168 | } |
| 3169 | break; |
| 3170 | default: |
| 3171 | break; |
| 3172 | } |
| 3173 | options.simple = options.simple && (param instanceof Node.Identifier); |
| 3174 | }; |
| 3175 | Parser.prototype.reinterpretAsCoverFormalsList = function (expr) { |
| 3176 | var params = [expr]; |
| 3177 | var options; |
| 3178 | var asyncArrow = false; |
| 3179 | switch (expr.type) { |
| 3180 | case syntax_1.Syntax.Identifier: |
| 3181 | break; |
| 3182 | case ArrowParameterPlaceHolder: |
| 3183 | params = expr.params; |
| 3184 | asyncArrow = expr.async; |
| 3185 | break; |
| 3186 | default: |
| 3187 | return null; |
| 3188 | } |
| 3189 | options = { |
| 3190 | simple: true, |
| 3191 | paramSet: {} |
| 3192 | }; |
| 3193 | for (var i = 0; i < params.length; ++i) { |
| 3194 | var param = params[i]; |
| 3195 | if (param.type === syntax_1.Syntax.AssignmentPattern) { |
| 3196 | if (param.right.type === syntax_1.Syntax.YieldExpression) { |
| 3197 | if (param.right.argument) { |
| 3198 | this.throwUnexpectedToken(this.lookahead); |
| 3199 | } |
| 3200 | param.right.type = syntax_1.Syntax.Identifier; |
| 3201 | param.right.name = 'yield'; |
| 3202 | delete param.right.argument; |
| 3203 | delete param.right.delegate; |
| 3204 | } |
| 3205 | } |
| 3206 | else if (asyncArrow && param.type === syntax_1.Syntax.Identifier && param.name === 'await') { |
| 3207 | this.throwUnexpectedToken(this.lookahead); |
| 3208 | } |
| 3209 | this.checkPatternParam(options, param); |
| 3210 | params[i] = param; |
| 3211 | } |
| 3212 | if (this.context.strict || !this.context.allowYield) { |
| 3213 | for (var i = 0; i < params.length; ++i) { |
| 3214 | var param = params[i]; |
| 3215 | if (param.type === syntax_1.Syntax.YieldExpression) { |
| 3216 | this.throwUnexpectedToken(this.lookahead); |
| 3217 | } |
| 3218 | } |
| 3219 | } |
| 3220 | if (options.message === messages_1.Messages.StrictParamDupe) { |
| 3221 | var token = this.context.strict ? options.stricted : options.firstRestricted; |
| 3222 | this.throwUnexpectedToken(token, options.message); |
| 3223 | } |
| 3224 | return { |
| 3225 | simple: options.simple, |
| 3226 | params: params, |
| 3227 | stricted: options.stricted, |
| 3228 | firstRestricted: options.firstRestricted, |
| 3229 | message: options.message |
| 3230 | }; |
| 3231 | }; |
| 3232 | Parser.prototype.parseAssignmentExpression = function () { |
| 3233 | var expr; |
| 3234 | if (!this.context.allowYield && this.matchKeyword('yield')) { |
| 3235 | expr = this.parseYieldExpression(); |
| 3236 | } |
| 3237 | else { |
| 3238 | var startToken = this.lookahead; |
| 3239 | var token = startToken; |
| 3240 | expr = this.parseConditionalExpression(); |
| 3241 | if (token.type === 3 /* Identifier */ && (token.lineNumber === this.lookahead.lineNumber) && token.value === 'async') { |
| 3242 | if (this.lookahead.type === 3 /* Identifier */ || this.matchKeyword('yield')) { |
| 3243 | var arg = this.parsePrimaryExpression(); |
| 3244 | this.reinterpretExpressionAsPattern(arg); |
| 3245 | expr = { |
| 3246 | type: ArrowParameterPlaceHolder, |
| 3247 | params: [arg], |
| 3248 | async: true |
| 3249 | }; |
| 3250 | } |
| 3251 | } |
| 3252 | if (expr.type === ArrowParameterPlaceHolder || this.match('=>')) { |
| 3253 | // https://tc39.github.io/ecma262/#sec-arrow-function-definitions |
| 3254 | this.context.isAssignmentTarget = false; |
| 3255 | this.context.isBindingElement = false; |
| 3256 | var isAsync = expr.async; |
| 3257 | var list = this.reinterpretAsCoverFormalsList(expr); |
| 3258 | if (list) { |
| 3259 | if (this.hasLineTerminator) { |
| 3260 | this.tolerateUnexpectedToken(this.lookahead); |
| 3261 | } |
| 3262 | this.context.firstCoverInitializedNameError = null; |
| 3263 | var previousStrict = this.context.strict; |
| 3264 | var previousAllowStrictDirective = this.context.allowStrictDirective; |
| 3265 | this.context.allowStrictDirective = list.simple; |
| 3266 | var previousAllowYield = this.context.allowYield; |
| 3267 | var previousAwait = this.context.await; |
| 3268 | this.context.allowYield = true; |
| 3269 | this.context.await = isAsync; |
| 3270 | var node = this.startNode(startToken); |
| 3271 | this.expect('=>'); |
| 3272 | var body = void 0; |
| 3273 | if (this.match('{')) { |
| 3274 | var previousAllowIn = this.context.allowIn; |
| 3275 | this.context.allowIn = true; |
| 3276 | body = this.parseFunctionSourceElements(); |
| 3277 | this.context.allowIn = previousAllowIn; |
| 3278 | } |
| 3279 | else { |
| 3280 | body = this.isolateCoverGrammar(this.parseAssignmentExpression); |
| 3281 | } |
| 3282 | var expression = body.type !== syntax_1.Syntax.BlockStatement; |
| 3283 | if (this.context.strict && list.firstRestricted) { |
| 3284 | this.throwUnexpectedToken(list.firstRestricted, list.message); |
| 3285 | } |
| 3286 | if (this.context.strict && list.stricted) { |
| 3287 | this.tolerateUnexpectedToken(list.stricted, list.message); |
| 3288 | } |
| 3289 | expr = isAsync ? this.finalize(node, new Node.AsyncArrowFunctionExpression(list.params, body, expression)) : |
| 3290 | this.finalize(node, new Node.ArrowFunctionExpression(list.params, body, expression)); |
| 3291 | this.context.strict = previousStrict; |
| 3292 | this.context.allowStrictDirective = previousAllowStrictDirective; |
| 3293 | this.context.allowYield = previousAllowYield; |
| 3294 | this.context.await = previousAwait; |
| 3295 | } |
| 3296 | } |
| 3297 | else { |
| 3298 | if (this.matchAssign()) { |
| 3299 | if (!this.context.isAssignmentTarget) { |
| 3300 | this.tolerateError(messages_1.Messages.InvalidLHSInAssignment); |
| 3301 | } |
| 3302 | if (this.context.strict && expr.type === syntax_1.Syntax.Identifier) { |
| 3303 | var id = expr; |
| 3304 | if (this.scanner.isRestrictedWord(id.name)) { |
| 3305 | this.tolerateUnexpectedToken(token, messages_1.Messages.StrictLHSAssignment); |
| 3306 | } |
| 3307 | if (this.scanner.isStrictModeReservedWord(id.name)) { |
| 3308 | this.tolerateUnexpectedToken(token, messages_1.Messages.StrictReservedWord); |
| 3309 | } |
| 3310 | } |
| 3311 | if (!this.match('=')) { |
| 3312 | this.context.isAssignmentTarget = false; |
| 3313 | this.context.isBindingElement = false; |
| 3314 | } |
| 3315 | else { |
| 3316 | this.reinterpretExpressionAsPattern(expr); |
| 3317 | } |
| 3318 | token = this.nextToken(); |
| 3319 | var operator = token.value; |
| 3320 | var right = this.isolateCoverGrammar(this.parseAssignmentExpression); |
| 3321 | expr = this.finalize(this.startNode(startToken), new Node.AssignmentExpression(operator, expr, right)); |
| 3322 | this.context.firstCoverInitializedNameError = null; |
| 3323 | } |
| 3324 | } |
| 3325 | } |
| 3326 | return expr; |
| 3327 | }; |
| 3328 | // https://tc39.github.io/ecma262/#sec-comma-operator |
| 3329 | Parser.prototype.parseExpression = function () { |
| 3330 | var startToken = this.lookahead; |
| 3331 | var expr = this.isolateCoverGrammar(this.parseAssignmentExpression); |
| 3332 | if (this.match(',')) { |
| 3333 | var expressions = []; |
| 3334 | expressions.push(expr); |
| 3335 | while (this.lookahead.type !== 2 /* EOF */) { |
| 3336 | if (!this.match(',')) { |
| 3337 | break; |
| 3338 | } |
| 3339 | this.nextToken(); |
| 3340 | expressions.push(this.isolateCoverGrammar(this.parseAssignmentExpression)); |
| 3341 | } |
| 3342 | expr = this.finalize(this.startNode(startToken), new Node.SequenceExpression(expressions)); |
| 3343 | } |
| 3344 | return expr; |
| 3345 | }; |
| 3346 | // https://tc39.github.io/ecma262/#sec-block |
| 3347 | Parser.prototype.parseStatementListItem = function () { |
| 3348 | var statement; |
| 3349 | this.context.isAssignmentTarget = true; |
| 3350 | this.context.isBindingElement = true; |
| 3351 | if (this.lookahead.type === 4 /* Keyword */) { |
| 3352 | switch (this.lookahead.value) { |
| 3353 | case 'export': |
| 3354 | if (!this.context.isModule) { |
| 3355 | this.tolerateUnexpectedToken(this.lookahead, messages_1.Messages.IllegalExportDeclaration); |
| 3356 | } |
| 3357 | statement = this.parseExportDeclaration(); |
| 3358 | break; |
| 3359 | case 'import': |
| 3360 | if (!this.context.isModule) { |
| 3361 | this.tolerateUnexpectedToken(this.lookahead, messages_1.Messages.IllegalImportDeclaration); |
| 3362 | } |
| 3363 | statement = this.parseImportDeclaration(); |
| 3364 | break; |
| 3365 | case 'const': |
| 3366 | statement = this.parseLexicalDeclaration({ inFor: false }); |
| 3367 | break; |
| 3368 | case 'function': |
| 3369 | statement = this.parseFunctionDeclaration(); |
| 3370 | break; |
| 3371 | case 'class': |
| 3372 | statement = this.parseClassDeclaration(); |
| 3373 | break; |
| 3374 | case 'let': |
| 3375 | statement = this.isLexicalDeclaration() ? this.parseLexicalDeclaration({ inFor: false }) : this.parseStatement(); |
| 3376 | break; |
| 3377 | default: |
| 3378 | statement = this.parseStatement(); |
| 3379 | break; |
| 3380 | } |
| 3381 | } |
| 3382 | else { |
| 3383 | statement = this.parseStatement(); |
| 3384 | } |
| 3385 | return statement; |
| 3386 | }; |
| 3387 | Parser.prototype.parseBlock = function () { |
| 3388 | var node = this.createNode(); |
| 3389 | this.expect('{'); |
| 3390 | var block = []; |
| 3391 | while (true) { |
| 3392 | if (this.match('}')) { |
| 3393 | break; |
| 3394 | } |
| 3395 | block.push(this.parseStatementListItem()); |
| 3396 | } |
| 3397 | this.expect('}'); |
| 3398 | return this.finalize(node, new Node.BlockStatement(block)); |
| 3399 | }; |
| 3400 | // https://tc39.github.io/ecma262/#sec-let-and-const-declarations |
| 3401 | Parser.prototype.parseLexicalBinding = function (kind, options) { |
| 3402 | var node = this.createNode(); |
| 3403 | var params = []; |
| 3404 | var id = this.parsePattern(params, kind); |
| 3405 | if (this.context.strict && id.type === syntax_1.Syntax.Identifier) { |
| 3406 | if (this.scanner.isRestrictedWord(id.name)) { |
| 3407 | this.tolerateError(messages_1.Messages.StrictVarName); |
| 3408 | } |
| 3409 | } |
| 3410 | var init = null; |
| 3411 | if (kind === 'const') { |
| 3412 | if (!this.matchKeyword('in') && !this.matchContextualKeyword('of')) { |
| 3413 | if (this.match('=')) { |
| 3414 | this.nextToken(); |
| 3415 | init = this.isolateCoverGrammar(this.parseAssignmentExpression); |
| 3416 | } |
| 3417 | else { |
| 3418 | this.throwError(messages_1.Messages.DeclarationMissingInitializer, 'const'); |
| 3419 | } |
| 3420 | } |
| 3421 | } |
| 3422 | else if ((!options.inFor && id.type !== syntax_1.Syntax.Identifier) || this.match('=')) { |
| 3423 | this.expect('='); |
| 3424 | init = this.isolateCoverGrammar(this.parseAssignmentExpression); |
| 3425 | } |
| 3426 | return this.finalize(node, new Node.VariableDeclarator(id, init)); |
| 3427 | }; |
| 3428 | Parser.prototype.parseBindingList = function (kind, options) { |
| 3429 | var list = [this.parseLexicalBinding(kind, options)]; |
| 3430 | while (this.match(',')) { |
| 3431 | this.nextToken(); |
| 3432 | list.push(this.parseLexicalBinding(kind, options)); |
| 3433 | } |
| 3434 | return list; |
| 3435 | }; |
| 3436 | Parser.prototype.isLexicalDeclaration = function () { |
| 3437 | var state = this.scanner.saveState(); |
| 3438 | this.scanner.scanComments(); |
| 3439 | var next = this.scanner.lex(); |
| 3440 | this.scanner.restoreState(state); |
| 3441 | return (next.type === 3 /* Identifier */) || |
| 3442 | (next.type === 7 /* Punctuator */ && next.value === '[') || |
| 3443 | (next.type === 7 /* Punctuator */ && next.value === '{') || |
| 3444 | (next.type === 4 /* Keyword */ && next.value === 'let') || |
| 3445 | (next.type === 4 /* Keyword */ && next.value === 'yield'); |
| 3446 | }; |
| 3447 | Parser.prototype.parseLexicalDeclaration = function (options) { |
| 3448 | var node = this.createNode(); |
| 3449 | var kind = this.nextToken().value; |
| 3450 | assert_1.assert(kind === 'let' || kind === 'const', 'Lexical declaration must be either let or const'); |
| 3451 | var declarations = this.parseBindingList(kind, options); |
| 3452 | this.consumeSemicolon(); |
| 3453 | return this.finalize(node, new Node.VariableDeclaration(declarations, kind)); |
| 3454 | }; |
| 3455 | // https://tc39.github.io/ecma262/#sec-destructuring-binding-patterns |
| 3456 | Parser.prototype.parseBindingRestElement = function (params, kind) { |
| 3457 | var node = this.createNode(); |
| 3458 | this.expect('...'); |
| 3459 | var arg = this.parsePattern(params, kind); |
| 3460 | return this.finalize(node, new Node.RestElement(arg)); |
| 3461 | }; |
| 3462 | Parser.prototype.parseArrayPattern = function (params, kind) { |
| 3463 | var node = this.createNode(); |
| 3464 | this.expect('['); |
| 3465 | var elements = []; |
| 3466 | while (!this.match(']')) { |
| 3467 | if (this.match(',')) { |
| 3468 | this.nextToken(); |
| 3469 | elements.push(null); |
| 3470 | } |
| 3471 | else { |
| 3472 | if (this.match('...')) { |
| 3473 | elements.push(this.parseBindingRestElement(params, kind)); |
| 3474 | break; |
| 3475 | } |
| 3476 | else { |
| 3477 | elements.push(this.parsePatternWithDefault(params, kind)); |
| 3478 | } |
| 3479 | if (!this.match(']')) { |
| 3480 | this.expect(','); |
| 3481 | } |
| 3482 | } |
| 3483 | } |
| 3484 | this.expect(']'); |
| 3485 | return this.finalize(node, new Node.ArrayPattern(elements)); |
| 3486 | }; |
| 3487 | Parser.prototype.parsePropertyPattern = function (params, kind) { |
| 3488 | var node = this.createNode(); |
| 3489 | var computed = false; |
| 3490 | var shorthand = false; |
| 3491 | var method = false; |
| 3492 | var key; |
| 3493 | var value; |
| 3494 | if (this.lookahead.type === 3 /* Identifier */) { |
| 3495 | var keyToken = this.lookahead; |
| 3496 | key = this.parseVariableIdentifier(); |
| 3497 | var init = this.finalize(node, new Node.Identifier(keyToken.value)); |
| 3498 | if (this.match('=')) { |
| 3499 | params.push(keyToken); |
| 3500 | shorthand = true; |
| 3501 | this.nextToken(); |
| 3502 | var expr = this.parseAssignmentExpression(); |
| 3503 | value = this.finalize(this.startNode(keyToken), new Node.AssignmentPattern(init, expr)); |
| 3504 | } |
| 3505 | else if (!this.match(':')) { |
| 3506 | params.push(keyToken); |
| 3507 | shorthand = true; |
| 3508 | value = init; |
| 3509 | } |
| 3510 | else { |
| 3511 | this.expect(':'); |
| 3512 | value = this.parsePatternWithDefault(params, kind); |
| 3513 | } |
| 3514 | } |
| 3515 | else { |
| 3516 | computed = this.match('['); |
| 3517 | key = this.parseObjectPropertyKey(); |
| 3518 | this.expect(':'); |
| 3519 | value = this.parsePatternWithDefault(params, kind); |
| 3520 | } |
| 3521 | return this.finalize(node, new Node.Property('init', key, computed, value, method, shorthand)); |
| 3522 | }; |
| 3523 | Parser.prototype.parseObjectPattern = function (params, kind) { |
| 3524 | var node = this.createNode(); |
| 3525 | var properties = []; |
| 3526 | this.expect('{'); |
| 3527 | while (!this.match('}')) { |
| 3528 | properties.push(this.parsePropertyPattern(params, kind)); |
| 3529 | if (!this.match('}')) { |
| 3530 | this.expect(','); |
| 3531 | } |
| 3532 | } |
| 3533 | this.expect('}'); |
| 3534 | return this.finalize(node, new Node.ObjectPattern(properties)); |
| 3535 | }; |
| 3536 | Parser.prototype.parsePattern = function (params, kind) { |
| 3537 | var pattern; |
| 3538 | if (this.match('[')) { |
| 3539 | pattern = this.parseArrayPattern(params, kind); |
| 3540 | } |
| 3541 | else if (this.match('{')) { |
| 3542 | pattern = this.parseObjectPattern(params, kind); |
| 3543 | } |
| 3544 | else { |
| 3545 | if (this.matchKeyword('let') && (kind === 'const' || kind === 'let')) { |
| 3546 | this.tolerateUnexpectedToken(this.lookahead, messages_1.Messages.LetInLexicalBinding); |
| 3547 | } |
| 3548 | params.push(this.lookahead); |
| 3549 | pattern = this.parseVariableIdentifier(kind); |
| 3550 | } |
| 3551 | return pattern; |
| 3552 | }; |
| 3553 | Parser.prototype.parsePatternWithDefault = function (params, kind) { |
| 3554 | var startToken = this.lookahead; |
| 3555 | var pattern = this.parsePattern(params, kind); |
| 3556 | if (this.match('=')) { |
| 3557 | this.nextToken(); |
| 3558 | var previousAllowYield = this.context.allowYield; |
| 3559 | this.context.allowYield = true; |
| 3560 | var right = this.isolateCoverGrammar(this.parseAssignmentExpression); |
| 3561 | this.context.allowYield = previousAllowYield; |
| 3562 | pattern = this.finalize(this.startNode(startToken), new Node.AssignmentPattern(pattern, right)); |
| 3563 | } |
| 3564 | return pattern; |
| 3565 | }; |
| 3566 | // https://tc39.github.io/ecma262/#sec-variable-statement |
| 3567 | Parser.prototype.parseVariableIdentifier = function (kind) { |
| 3568 | var node = this.createNode(); |
| 3569 | var token = this.nextToken(); |
| 3570 | if (token.type === 4 /* Keyword */ && token.value === 'yield') { |
| 3571 | if (this.context.strict) { |
| 3572 | this.tolerateUnexpectedToken(token, messages_1.Messages.StrictReservedWord); |
| 3573 | } |
| 3574 | else if (!this.context.allowYield) { |
| 3575 | this.throwUnexpectedToken(token); |
| 3576 | } |
| 3577 | } |
| 3578 | else if (token.type !== 3 /* Identifier */) { |
| 3579 | if (this.context.strict && token.type === 4 /* Keyword */ && this.scanner.isStrictModeReservedWord(token.value)) { |
| 3580 | this.tolerateUnexpectedToken(token, messages_1.Messages.StrictReservedWord); |
| 3581 | } |
| 3582 | else { |
| 3583 | if (this.context.strict || token.value !== 'let' || kind !== 'var') { |
| 3584 | this.throwUnexpectedToken(token); |
| 3585 | } |
| 3586 | } |
| 3587 | } |
| 3588 | else if ((this.context.isModule || this.context.await) && token.type === 3 /* Identifier */ && token.value === 'await') { |
| 3589 | this.tolerateUnexpectedToken(token); |
| 3590 | } |
| 3591 | return this.finalize(node, new Node.Identifier(token.value)); |
| 3592 | }; |
| 3593 | Parser.prototype.parseVariableDeclaration = function (options) { |
| 3594 | var node = this.createNode(); |
| 3595 | var params = []; |
| 3596 | var id = this.parsePattern(params, 'var'); |
| 3597 | if (this.context.strict && id.type === syntax_1.Syntax.Identifier) { |
| 3598 | if (this.scanner.isRestrictedWord(id.name)) { |
| 3599 | this.tolerateError(messages_1.Messages.StrictVarName); |
| 3600 | } |
| 3601 | } |
| 3602 | var init = null; |
| 3603 | if (this.match('=')) { |
| 3604 | this.nextToken(); |
| 3605 | init = this.isolateCoverGrammar(this.parseAssignmentExpression); |
| 3606 | } |
| 3607 | else if (id.type !== syntax_1.Syntax.Identifier && !options.inFor) { |
| 3608 | this.expect('='); |
| 3609 | } |
| 3610 | return this.finalize(node, new Node.VariableDeclarator(id, init)); |
| 3611 | }; |
| 3612 | Parser.prototype.parseVariableDeclarationList = function (options) { |
| 3613 | var opt = { inFor: options.inFor }; |
| 3614 | var list = []; |
| 3615 | list.push(this.parseVariableDeclaration(opt)); |
| 3616 | while (this.match(',')) { |
| 3617 | this.nextToken(); |
| 3618 | list.push(this.parseVariableDeclaration(opt)); |
| 3619 | } |
| 3620 | return list; |
| 3621 | }; |
| 3622 | Parser.prototype.parseVariableStatement = function () { |
| 3623 | var node = this.createNode(); |
| 3624 | this.expectKeyword('var'); |
| 3625 | var declarations = this.parseVariableDeclarationList({ inFor: false }); |
| 3626 | this.consumeSemicolon(); |
| 3627 | return this.finalize(node, new Node.VariableDeclaration(declarations, 'var')); |
| 3628 | }; |
| 3629 | // https://tc39.github.io/ecma262/#sec-empty-statement |
| 3630 | Parser.prototype.parseEmptyStatement = function () { |
| 3631 | var node = this.createNode(); |
| 3632 | this.expect(';'); |
| 3633 | return this.finalize(node, new Node.EmptyStatement()); |
| 3634 | }; |
| 3635 | // https://tc39.github.io/ecma262/#sec-expression-statement |
| 3636 | Parser.prototype.parseExpressionStatement = function () { |
| 3637 | var node = this.createNode(); |
| 3638 | var expr = this.parseExpression(); |
| 3639 | this.consumeSemicolon(); |
| 3640 | return this.finalize(node, new Node.ExpressionStatement(expr)); |
| 3641 | }; |
| 3642 | // https://tc39.github.io/ecma262/#sec-if-statement |
| 3643 | Parser.prototype.parseIfClause = function () { |
| 3644 | if (this.context.strict && this.matchKeyword('function')) { |
| 3645 | this.tolerateError(messages_1.Messages.StrictFunction); |
| 3646 | } |
| 3647 | return this.parseStatement(); |
| 3648 | }; |
| 3649 | Parser.prototype.parseIfStatement = function () { |
| 3650 | var node = this.createNode(); |
| 3651 | var consequent; |
| 3652 | var alternate = null; |
| 3653 | this.expectKeyword('if'); |
| 3654 | this.expect('('); |
| 3655 | var test = this.parseExpression(); |
| 3656 | if (!this.match(')') && this.config.tolerant) { |
| 3657 | this.tolerateUnexpectedToken(this.nextToken()); |
| 3658 | consequent = this.finalize(this.createNode(), new Node.EmptyStatement()); |
| 3659 | } |
| 3660 | else { |
| 3661 | this.expect(')'); |
| 3662 | consequent = this.parseIfClause(); |
| 3663 | if (this.matchKeyword('else')) { |
| 3664 | this.nextToken(); |
| 3665 | alternate = this.parseIfClause(); |
| 3666 | } |
| 3667 | } |
| 3668 | return this.finalize(node, new Node.IfStatement(test, consequent, alternate)); |
| 3669 | }; |
| 3670 | // https://tc39.github.io/ecma262/#sec-do-while-statement |
| 3671 | Parser.prototype.parseDoWhileStatement = function () { |
| 3672 | var node = this.createNode(); |
| 3673 | this.expectKeyword('do'); |
| 3674 | var previousInIteration = this.context.inIteration; |
| 3675 | this.context.inIteration = true; |
| 3676 | var body = this.parseStatement(); |
| 3677 | this.context.inIteration = previousInIteration; |
| 3678 | this.expectKeyword('while'); |
| 3679 | this.expect('('); |
| 3680 | var test = this.parseExpression(); |
| 3681 | if (!this.match(')') && this.config.tolerant) { |
| 3682 | this.tolerateUnexpectedToken(this.nextToken()); |
| 3683 | } |
| 3684 | else { |
| 3685 | this.expect(')'); |
| 3686 | if (this.match(';')) { |
| 3687 | this.nextToken(); |
| 3688 | } |
| 3689 | } |
| 3690 | return this.finalize(node, new Node.DoWhileStatement(body, test)); |
| 3691 | }; |
| 3692 | // https://tc39.github.io/ecma262/#sec-while-statement |
| 3693 | Parser.prototype.parseWhileStatement = function () { |
| 3694 | var node = this.createNode(); |
| 3695 | var body; |
| 3696 | this.expectKeyword('while'); |
| 3697 | this.expect('('); |
| 3698 | var test = this.parseExpression(); |
| 3699 | if (!this.match(')') && this.config.tolerant) { |
| 3700 | this.tolerateUnexpectedToken(this.nextToken()); |
| 3701 | body = this.finalize(this.createNode(), new Node.EmptyStatement()); |
| 3702 | } |
| 3703 | else { |
| 3704 | this.expect(')'); |
| 3705 | var previousInIteration = this.context.inIteration; |
| 3706 | this.context.inIteration = true; |
| 3707 | body = this.parseStatement(); |
| 3708 | this.context.inIteration = previousInIteration; |
| 3709 | } |
| 3710 | return this.finalize(node, new Node.WhileStatement(test, body)); |
| 3711 | }; |
| 3712 | // https://tc39.github.io/ecma262/#sec-for-statement |
| 3713 | // https://tc39.github.io/ecma262/#sec-for-in-and-for-of-statements |
| 3714 | Parser.prototype.parseForStatement = function () { |
| 3715 | var init = null; |
| 3716 | var test = null; |
| 3717 | var update = null; |
| 3718 | var forIn = true; |
| 3719 | var left, right; |
| 3720 | var node = this.createNode(); |
| 3721 | this.expectKeyword('for'); |
| 3722 | this.expect('('); |
| 3723 | if (this.match(';')) { |
| 3724 | this.nextToken(); |
| 3725 | } |
| 3726 | else { |
| 3727 | if (this.matchKeyword('var')) { |
| 3728 | init = this.createNode(); |
| 3729 | this.nextToken(); |
| 3730 | var previousAllowIn = this.context.allowIn; |
| 3731 | this.context.allowIn = false; |
| 3732 | var declarations = this.parseVariableDeclarationList({ inFor: true }); |
| 3733 | this.context.allowIn = previousAllowIn; |
| 3734 | if (declarations.length === 1 && this.matchKeyword('in')) { |
| 3735 | var decl = declarations[0]; |
| 3736 | if (decl.init && (decl.id.type === syntax_1.Syntax.ArrayPattern || decl.id.type === syntax_1.Syntax.ObjectPattern || this.context.strict)) { |
| 3737 | this.tolerateError(messages_1.Messages.ForInOfLoopInitializer, 'for-in'); |
| 3738 | } |
| 3739 | init = this.finalize(init, new Node.VariableDeclaration(declarations, 'var')); |
| 3740 | this.nextToken(); |
| 3741 | left = init; |
| 3742 | right = this.parseExpression(); |
| 3743 | init = null; |
| 3744 | } |
| 3745 | else if (declarations.length === 1 && declarations[0].init === null && this.matchContextualKeyword('of')) { |
| 3746 | init = this.finalize(init, new Node.VariableDeclaration(declarations, 'var')); |
| 3747 | this.nextToken(); |
| 3748 | left = init; |
| 3749 | right = this.parseAssignmentExpression(); |
| 3750 | init = null; |
| 3751 | forIn = false; |
| 3752 | } |
| 3753 | else { |
| 3754 | init = this.finalize(init, new Node.VariableDeclaration(declarations, 'var')); |
| 3755 | this.expect(';'); |
| 3756 | } |
| 3757 | } |
| 3758 | else if (this.matchKeyword('const') || this.matchKeyword('let')) { |
| 3759 | init = this.createNode(); |
| 3760 | var kind = this.nextToken().value; |
| 3761 | if (!this.context.strict && this.lookahead.value === 'in') { |
| 3762 | init = this.finalize(init, new Node.Identifier(kind)); |
| 3763 | this.nextToken(); |
| 3764 | left = init; |
| 3765 | right = this.parseExpression(); |
| 3766 | init = null; |
| 3767 | } |
| 3768 | else { |
| 3769 | var previousAllowIn = this.context.allowIn; |
| 3770 | this.context.allowIn = false; |
| 3771 | var declarations = this.parseBindingList(kind, { inFor: true }); |
| 3772 | this.context.allowIn = previousAllowIn; |
| 3773 | if (declarations.length === 1 && declarations[0].init === null && this.matchKeyword('in')) { |
| 3774 | init = this.finalize(init, new Node.VariableDeclaration(declarations, kind)); |
| 3775 | this.nextToken(); |
| 3776 | left = init; |
| 3777 | right = this.parseExpression(); |
| 3778 | init = null; |
| 3779 | } |
| 3780 | else if (declarations.length === 1 && declarations[0].init === null && this.matchContextualKeyword('of')) { |
| 3781 | init = this.finalize(init, new Node.VariableDeclaration(declarations, kind)); |
| 3782 | this.nextToken(); |
| 3783 | left = init; |
| 3784 | right = this.parseAssignmentExpression(); |
| 3785 | init = null; |
| 3786 | forIn = false; |
| 3787 | } |
| 3788 | else { |
| 3789 | this.consumeSemicolon(); |
| 3790 | init = this.finalize(init, new Node.VariableDeclaration(declarations, kind)); |
| 3791 | } |
| 3792 | } |
| 3793 | } |
| 3794 | else { |
| 3795 | var initStartToken = this.lookahead; |
| 3796 | var previousAllowIn = this.context.allowIn; |
| 3797 | this.context.allowIn = false; |
| 3798 | init = this.inheritCoverGrammar(this.parseAssignmentExpression); |
| 3799 | this.context.allowIn = previousAllowIn; |
| 3800 | if (this.matchKeyword('in')) { |
| 3801 | if (!this.context.isAssignmentTarget || init.type === syntax_1.Syntax.AssignmentExpression) { |
| 3802 | this.tolerateError(messages_1.Messages.InvalidLHSInForIn); |
| 3803 | } |
| 3804 | this.nextToken(); |
| 3805 | this.reinterpretExpressionAsPattern(init); |
| 3806 | left = init; |
| 3807 | right = this.parseExpression(); |
| 3808 | init = null; |
| 3809 | } |
| 3810 | else if (this.matchContextualKeyword('of')) { |
| 3811 | if (!this.context.isAssignmentTarget || init.type === syntax_1.Syntax.AssignmentExpression) { |
| 3812 | this.tolerateError(messages_1.Messages.InvalidLHSInForLoop); |
| 3813 | } |
| 3814 | this.nextToken(); |
| 3815 | this.reinterpretExpressionAsPattern(init); |
| 3816 | left = init; |
| 3817 | right = this.parseAssignmentExpression(); |
| 3818 | init = null; |
| 3819 | forIn = false; |
| 3820 | } |
| 3821 | else { |
| 3822 | if (this.match(',')) { |
| 3823 | var initSeq = [init]; |
| 3824 | while (this.match(',')) { |
| 3825 | this.nextToken(); |
| 3826 | initSeq.push(this.isolateCoverGrammar(this.parseAssignmentExpression)); |
| 3827 | } |
| 3828 | init = this.finalize(this.startNode(initStartToken), new Node.SequenceExpression(initSeq)); |
| 3829 | } |
| 3830 | this.expect(';'); |
| 3831 | } |
| 3832 | } |
| 3833 | } |
| 3834 | if (typeof left === 'undefined') { |
| 3835 | if (!this.match(';')) { |
| 3836 | test = this.parseExpression(); |
| 3837 | } |
| 3838 | this.expect(';'); |
| 3839 | if (!this.match(')')) { |
| 3840 | update = this.parseExpression(); |
| 3841 | } |
| 3842 | } |
| 3843 | var body; |
| 3844 | if (!this.match(')') && this.config.tolerant) { |
| 3845 | this.tolerateUnexpectedToken(this.nextToken()); |
| 3846 | body = this.finalize(this.createNode(), new Node.EmptyStatement()); |
| 3847 | } |
| 3848 | else { |
| 3849 | this.expect(')'); |
| 3850 | var previousInIteration = this.context.inIteration; |
| 3851 | this.context.inIteration = true; |
| 3852 | body = this.isolateCoverGrammar(this.parseStatement); |
| 3853 | this.context.inIteration = previousInIteration; |
| 3854 | } |
| 3855 | return (typeof left === 'undefined') ? |
| 3856 | this.finalize(node, new Node.ForStatement(init, test, update, body)) : |
| 3857 | forIn ? this.finalize(node, new Node.ForInStatement(left, right, body)) : |
| 3858 | this.finalize(node, new Node.ForOfStatement(left, right, body)); |
| 3859 | }; |
| 3860 | // https://tc39.github.io/ecma262/#sec-continue-statement |
| 3861 | Parser.prototype.parseContinueStatement = function () { |
| 3862 | var node = this.createNode(); |
| 3863 | this.expectKeyword('continue'); |
| 3864 | var label = null; |
| 3865 | if (this.lookahead.type === 3 /* Identifier */ && !this.hasLineTerminator) { |
| 3866 | var id = this.parseVariableIdentifier(); |
| 3867 | label = id; |
| 3868 | var key = '$' + id.name; |
| 3869 | if (!Object.prototype.hasOwnProperty.call(this.context.labelSet, key)) { |
| 3870 | this.throwError(messages_1.Messages.UnknownLabel, id.name); |
| 3871 | } |
| 3872 | } |
| 3873 | this.consumeSemicolon(); |
| 3874 | if (label === null && !this.context.inIteration) { |
| 3875 | this.throwError(messages_1.Messages.IllegalContinue); |
| 3876 | } |
| 3877 | return this.finalize(node, new Node.ContinueStatement(label)); |
| 3878 | }; |
| 3879 | // https://tc39.github.io/ecma262/#sec-break-statement |
| 3880 | Parser.prototype.parseBreakStatement = function () { |
| 3881 | var node = this.createNode(); |
| 3882 | this.expectKeyword('break'); |
| 3883 | var label = null; |
| 3884 | if (this.lookahead.type === 3 /* Identifier */ && !this.hasLineTerminator) { |
| 3885 | var id = this.parseVariableIdentifier(); |
| 3886 | var key = '$' + id.name; |
| 3887 | if (!Object.prototype.hasOwnProperty.call(this.context.labelSet, key)) { |
| 3888 | this.throwError(messages_1.Messages.UnknownLabel, id.name); |
| 3889 | } |
| 3890 | label = id; |
| 3891 | } |
| 3892 | this.consumeSemicolon(); |
| 3893 | if (label === null && !this.context.inIteration && !this.context.inSwitch) { |
| 3894 | this.throwError(messages_1.Messages.IllegalBreak); |
| 3895 | } |
| 3896 | return this.finalize(node, new Node.BreakStatement(label)); |
| 3897 | }; |
| 3898 | // https://tc39.github.io/ecma262/#sec-return-statement |
| 3899 | Parser.prototype.parseReturnStatement = function () { |
| 3900 | if (!this.context.inFunctionBody) { |
| 3901 | this.tolerateError(messages_1.Messages.IllegalReturn); |
| 3902 | } |
| 3903 | var node = this.createNode(); |
| 3904 | this.expectKeyword('return'); |
| 3905 | var hasArgument = !this.match(';') && !this.match('}') && |
| 3906 | !this.hasLineTerminator && this.lookahead.type !== 2 /* EOF */; |
| 3907 | var argument = hasArgument ? this.parseExpression() : null; |
| 3908 | this.consumeSemicolon(); |
| 3909 | return this.finalize(node, new Node.ReturnStatement(argument)); |
| 3910 | }; |
| 3911 | // https://tc39.github.io/ecma262/#sec-with-statement |
| 3912 | Parser.prototype.parseWithStatement = function () { |
| 3913 | if (this.context.strict) { |
| 3914 | this.tolerateError(messages_1.Messages.StrictModeWith); |
| 3915 | } |
| 3916 | var node = this.createNode(); |
| 3917 | var body; |
| 3918 | this.expectKeyword('with'); |
| 3919 | this.expect('('); |
| 3920 | var object = this.parseExpression(); |
| 3921 | if (!this.match(')') && this.config.tolerant) { |
| 3922 | this.tolerateUnexpectedToken(this.nextToken()); |
| 3923 | body = this.finalize(this.createNode(), new Node.EmptyStatement()); |
| 3924 | } |
| 3925 | else { |
| 3926 | this.expect(')'); |
| 3927 | body = this.parseStatement(); |
| 3928 | } |
| 3929 | return this.finalize(node, new Node.WithStatement(object, body)); |
| 3930 | }; |
| 3931 | // https://tc39.github.io/ecma262/#sec-switch-statement |
| 3932 | Parser.prototype.parseSwitchCase = function () { |
| 3933 | var node = this.createNode(); |
| 3934 | var test; |
| 3935 | if (this.matchKeyword('default')) { |
| 3936 | this.nextToken(); |
| 3937 | test = null; |
| 3938 | } |
| 3939 | else { |
| 3940 | this.expectKeyword('case'); |
| 3941 | test = this.parseExpression(); |
| 3942 | } |
| 3943 | this.expect(':'); |
| 3944 | var consequent = []; |
| 3945 | while (true) { |
| 3946 | if (this.match('}') || this.matchKeyword('default') || this.matchKeyword('case')) { |
| 3947 | break; |
| 3948 | } |
| 3949 | consequent.push(this.parseStatementListItem()); |
| 3950 | } |
| 3951 | return this.finalize(node, new Node.SwitchCase(test, consequent)); |
| 3952 | }; |
| 3953 | Parser.prototype.parseSwitchStatement = function () { |
| 3954 | var node = this.createNode(); |
| 3955 | this.expectKeyword('switch'); |
| 3956 | this.expect('('); |
| 3957 | var discriminant = this.parseExpression(); |
| 3958 | this.expect(')'); |
| 3959 | var previousInSwitch = this.context.inSwitch; |
| 3960 | this.context.inSwitch = true; |
| 3961 | var cases = []; |
| 3962 | var defaultFound = false; |
| 3963 | this.expect('{'); |
| 3964 | while (true) { |
| 3965 | if (this.match('}')) { |
| 3966 | break; |
| 3967 | } |
| 3968 | var clause = this.parseSwitchCase(); |
| 3969 | if (clause.test === null) { |
| 3970 | if (defaultFound) { |
| 3971 | this.throwError(messages_1.Messages.MultipleDefaultsInSwitch); |
| 3972 | } |
| 3973 | defaultFound = true; |
| 3974 | } |
| 3975 | cases.push(clause); |
| 3976 | } |
| 3977 | this.expect('}'); |
| 3978 | this.context.inSwitch = previousInSwitch; |
| 3979 | return this.finalize(node, new Node.SwitchStatement(discriminant, cases)); |
| 3980 | }; |
| 3981 | // https://tc39.github.io/ecma262/#sec-labelled-statements |
| 3982 | Parser.prototype.parseLabelledStatement = function () { |
| 3983 | var node = this.createNode(); |
| 3984 | var expr = this.parseExpression(); |
| 3985 | var statement; |
| 3986 | if ((expr.type === syntax_1.Syntax.Identifier) && this.match(':')) { |
| 3987 | this.nextToken(); |
| 3988 | var id = expr; |
| 3989 | var key = '$' + id.name; |
| 3990 | if (Object.prototype.hasOwnProperty.call(this.context.labelSet, key)) { |
| 3991 | this.throwError(messages_1.Messages.Redeclaration, 'Label', id.name); |
| 3992 | } |
| 3993 | this.context.labelSet[key] = true; |
| 3994 | var body = void 0; |
| 3995 | if (this.matchKeyword('class')) { |
| 3996 | this.tolerateUnexpectedToken(this.lookahead); |
| 3997 | body = this.parseClassDeclaration(); |
| 3998 | } |
| 3999 | else if (this.matchKeyword('function')) { |
| 4000 | var token = this.lookahead; |
| 4001 | var declaration = this.parseFunctionDeclaration(); |
| 4002 | if (this.context.strict) { |
| 4003 | this.tolerateUnexpectedToken(token, messages_1.Messages.StrictFunction); |
| 4004 | } |
| 4005 | else if (declaration.generator) { |
| 4006 | this.tolerateUnexpectedToken(token, messages_1.Messages.GeneratorInLegacyContext); |
| 4007 | } |
| 4008 | body = declaration; |
| 4009 | } |
| 4010 | else { |
| 4011 | body = this.parseStatement(); |
| 4012 | } |
| 4013 | delete this.context.labelSet[key]; |
| 4014 | statement = new Node.LabeledStatement(id, body); |
| 4015 | } |
| 4016 | else { |
| 4017 | this.consumeSemicolon(); |
| 4018 | statement = new Node.ExpressionStatement(expr); |
| 4019 | } |
| 4020 | return this.finalize(node, statement); |
| 4021 | }; |
| 4022 | // https://tc39.github.io/ecma262/#sec-throw-statement |
| 4023 | Parser.prototype.parseThrowStatement = function () { |
| 4024 | var node = this.createNode(); |
| 4025 | this.expectKeyword('throw'); |
| 4026 | if (this.hasLineTerminator) { |
| 4027 | this.throwError(messages_1.Messages.NewlineAfterThrow); |
| 4028 | } |
| 4029 | var argument = this.parseExpression(); |
| 4030 | this.consumeSemicolon(); |
| 4031 | return this.finalize(node, new Node.ThrowStatement(argument)); |
| 4032 | }; |
| 4033 | // https://tc39.github.io/ecma262/#sec-try-statement |
| 4034 | Parser.prototype.parseCatchClause = function () { |
| 4035 | var node = this.createNode(); |
| 4036 | this.expectKeyword('catch'); |
| 4037 | this.expect('('); |
| 4038 | if (this.match(')')) { |
| 4039 | this.throwUnexpectedToken(this.lookahead); |
| 4040 | } |
| 4041 | var params = []; |
| 4042 | var param = this.parsePattern(params); |
| 4043 | var paramMap = {}; |
| 4044 | for (var i = 0; i < params.length; i++) { |
| 4045 | var key = '$' + params[i].value; |
| 4046 | if (Object.prototype.hasOwnProperty.call(paramMap, key)) { |
| 4047 | this.tolerateError(messages_1.Messages.DuplicateBinding, params[i].value); |
| 4048 | } |
| 4049 | paramMap[key] = true; |
| 4050 | } |
| 4051 | if (this.context.strict && param.type === syntax_1.Syntax.Identifier) { |
| 4052 | if (this.scanner.isRestrictedWord(param.name)) { |
| 4053 | this.tolerateError(messages_1.Messages.StrictCatchVariable); |
| 4054 | } |
| 4055 | } |
| 4056 | this.expect(')'); |
| 4057 | var body = this.parseBlock(); |
| 4058 | return this.finalize(node, new Node.CatchClause(param, body)); |
| 4059 | }; |
| 4060 | Parser.prototype.parseFinallyClause = function () { |
| 4061 | this.expectKeyword('finally'); |
| 4062 | return this.parseBlock(); |
| 4063 | }; |
| 4064 | Parser.prototype.parseTryStatement = function () { |
| 4065 | var node = this.createNode(); |
| 4066 | this.expectKeyword('try'); |
| 4067 | var block = this.parseBlock(); |
| 4068 | var handler = this.matchKeyword('catch') ? this.parseCatchClause() : null; |
| 4069 | var finalizer = this.matchKeyword('finally') ? this.parseFinallyClause() : null; |
| 4070 | if (!handler && !finalizer) { |
| 4071 | this.throwError(messages_1.Messages.NoCatchOrFinally); |
| 4072 | } |
| 4073 | return this.finalize(node, new Node.TryStatement(block, handler, finalizer)); |
| 4074 | }; |
| 4075 | // https://tc39.github.io/ecma262/#sec-debugger-statement |
| 4076 | Parser.prototype.parseDebuggerStatement = function () { |
| 4077 | var node = this.createNode(); |
| 4078 | this.expectKeyword('debugger'); |
| 4079 | this.consumeSemicolon(); |
| 4080 | return this.finalize(node, new Node.DebuggerStatement()); |
| 4081 | }; |
| 4082 | // https://tc39.github.io/ecma262/#sec-ecmascript-language-statements-and-declarations |
| 4083 | Parser.prototype.parseStatement = function () { |
| 4084 | var statement; |
| 4085 | switch (this.lookahead.type) { |
| 4086 | case 1 /* BooleanLiteral */: |
| 4087 | case 5 /* NullLiteral */: |
| 4088 | case 6 /* NumericLiteral */: |
| 4089 | case 8 /* StringLiteral */: |
| 4090 | case 10 /* Template */: |
| 4091 | case 9 /* RegularExpression */: |
| 4092 | statement = this.parseExpressionStatement(); |
| 4093 | break; |
| 4094 | case 7 /* Punctuator */: |
| 4095 | var value = this.lookahead.value; |
| 4096 | if (value === '{') { |
| 4097 | statement = this.parseBlock(); |
| 4098 | } |
| 4099 | else if (value === '(') { |
| 4100 | statement = this.parseExpressionStatement(); |
| 4101 | } |
| 4102 | else if (value === ';') { |
| 4103 | statement = this.parseEmptyStatement(); |
| 4104 | } |
| 4105 | else { |
| 4106 | statement = this.parseExpressionStatement(); |
| 4107 | } |
| 4108 | break; |
| 4109 | case 3 /* Identifier */: |
| 4110 | statement = this.matchAsyncFunction() ? this.parseFunctionDeclaration() : this.parseLabelledStatement(); |
| 4111 | break; |
| 4112 | case 4 /* Keyword */: |
| 4113 | switch (this.lookahead.value) { |
| 4114 | case 'break': |
| 4115 | statement = this.parseBreakStatement(); |
| 4116 | break; |
| 4117 | case 'continue': |
| 4118 | statement = this.parseContinueStatement(); |
| 4119 | break; |
| 4120 | case 'debugger': |
| 4121 | statement = this.parseDebuggerStatement(); |
| 4122 | break; |
| 4123 | case 'do': |
| 4124 | statement = this.parseDoWhileStatement(); |
| 4125 | break; |
| 4126 | case 'for': |
| 4127 | statement = this.parseForStatement(); |
| 4128 | break; |
| 4129 | case 'function': |
| 4130 | statement = this.parseFunctionDeclaration(); |
| 4131 | break; |
| 4132 | case 'if': |
| 4133 | statement = this.parseIfStatement(); |
| 4134 | break; |
| 4135 | case 'return': |
| 4136 | statement = this.parseReturnStatement(); |
| 4137 | break; |
| 4138 | case 'switch': |
| 4139 | statement = this.parseSwitchStatement(); |
| 4140 | break; |
| 4141 | case 'throw': |
| 4142 | statement = this.parseThrowStatement(); |
| 4143 | break; |
| 4144 | case 'try': |
| 4145 | statement = this.parseTryStatement(); |
| 4146 | break; |
| 4147 | case 'var': |
| 4148 | statement = this.parseVariableStatement(); |
| 4149 | break; |
| 4150 | case 'while': |
| 4151 | statement = this.parseWhileStatement(); |
| 4152 | break; |
| 4153 | case 'with': |
| 4154 | statement = this.parseWithStatement(); |
| 4155 | break; |
| 4156 | default: |
| 4157 | statement = this.parseExpressionStatement(); |
| 4158 | break; |
| 4159 | } |
| 4160 | break; |
| 4161 | default: |
| 4162 | statement = this.throwUnexpectedToken(this.lookahead); |
| 4163 | } |
| 4164 | return statement; |
| 4165 | }; |
| 4166 | // https://tc39.github.io/ecma262/#sec-function-definitions |
| 4167 | Parser.prototype.parseFunctionSourceElements = function () { |
| 4168 | var node = this.createNode(); |
| 4169 | this.expect('{'); |
| 4170 | var body = this.parseDirectivePrologues(); |
| 4171 | var previousLabelSet = this.context.labelSet; |
| 4172 | var previousInIteration = this.context.inIteration; |
| 4173 | var previousInSwitch = this.context.inSwitch; |
| 4174 | var previousInFunctionBody = this.context.inFunctionBody; |
| 4175 | this.context.labelSet = {}; |
| 4176 | this.context.inIteration = false; |
| 4177 | this.context.inSwitch = false; |
| 4178 | this.context.inFunctionBody = true; |
| 4179 | while (this.lookahead.type !== 2 /* EOF */) { |
| 4180 | if (this.match('}')) { |
| 4181 | break; |
| 4182 | } |
| 4183 | body.push(this.parseStatementListItem()); |
| 4184 | } |
| 4185 | this.expect('}'); |
| 4186 | this.context.labelSet = previousLabelSet; |
| 4187 | this.context.inIteration = previousInIteration; |
| 4188 | this.context.inSwitch = previousInSwitch; |
| 4189 | this.context.inFunctionBody = previousInFunctionBody; |
| 4190 | return this.finalize(node, new Node.BlockStatement(body)); |
| 4191 | }; |
| 4192 | Parser.prototype.validateParam = function (options, param, name) { |
| 4193 | var key = '$' + name; |
| 4194 | if (this.context.strict) { |
| 4195 | if (this.scanner.isRestrictedWord(name)) { |
| 4196 | options.stricted = param; |
| 4197 | options.message = messages_1.Messages.StrictParamName; |
| 4198 | } |
| 4199 | if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) { |
| 4200 | options.stricted = param; |
| 4201 | options.message = messages_1.Messages.StrictParamDupe; |
| 4202 | } |
| 4203 | } |
| 4204 | else if (!options.firstRestricted) { |
| 4205 | if (this.scanner.isRestrictedWord(name)) { |
| 4206 | options.firstRestricted = param; |
| 4207 | options.message = messages_1.Messages.StrictParamName; |
| 4208 | } |
| 4209 | else if (this.scanner.isStrictModeReservedWord(name)) { |
| 4210 | options.firstRestricted = param; |
| 4211 | options.message = messages_1.Messages.StrictReservedWord; |
| 4212 | } |
| 4213 | else if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) { |
| 4214 | options.stricted = param; |
| 4215 | options.message = messages_1.Messages.StrictParamDupe; |
| 4216 | } |
| 4217 | } |
| 4218 | /* istanbul ignore next */ |
| 4219 | if (typeof Object.defineProperty === 'function') { |
| 4220 | Object.defineProperty(options.paramSet, key, { value: true, enumerable: true, writable: true, configurable: true }); |
| 4221 | } |
| 4222 | else { |
| 4223 | options.paramSet[key] = true; |
| 4224 | } |
| 4225 | }; |
| 4226 | Parser.prototype.parseRestElement = function (params) { |
| 4227 | var node = this.createNode(); |
| 4228 | this.expect('...'); |
| 4229 | var arg = this.parsePattern(params); |
| 4230 | if (this.match('=')) { |
| 4231 | this.throwError(messages_1.Messages.DefaultRestParameter); |
| 4232 | } |
| 4233 | if (!this.match(')')) { |
| 4234 | this.throwError(messages_1.Messages.ParameterAfterRestParameter); |
| 4235 | } |
| 4236 | return this.finalize(node, new Node.RestElement(arg)); |
| 4237 | }; |
| 4238 | Parser.prototype.parseFormalParameter = function (options) { |
| 4239 | var params = []; |
| 4240 | var param = this.match('...') ? this.parseRestElement(params) : this.parsePatternWithDefault(params); |
| 4241 | for (var i = 0; i < params.length; i++) { |
| 4242 | this.validateParam(options, params[i], params[i].value); |
| 4243 | } |
| 4244 | options.simple = options.simple && (param instanceof Node.Identifier); |
| 4245 | options.params.push(param); |
| 4246 | }; |
| 4247 | Parser.prototype.parseFormalParameters = function (firstRestricted) { |
| 4248 | var options; |
| 4249 | options = { |
| 4250 | simple: true, |
| 4251 | params: [], |
| 4252 | firstRestricted: firstRestricted |
| 4253 | }; |
| 4254 | this.expect('('); |
| 4255 | if (!this.match(')')) { |
| 4256 | options.paramSet = {}; |
| 4257 | while (this.lookahead.type !== 2 /* EOF */) { |
| 4258 | this.parseFormalParameter(options); |
| 4259 | if (this.match(')')) { |
| 4260 | break; |
| 4261 | } |
| 4262 | this.expect(','); |
| 4263 | if (this.match(')')) { |
| 4264 | break; |
| 4265 | } |
| 4266 | } |
| 4267 | } |
| 4268 | this.expect(')'); |
| 4269 | return { |
| 4270 | simple: options.simple, |
| 4271 | params: options.params, |
| 4272 | stricted: options.stricted, |
| 4273 | firstRestricted: options.firstRestricted, |
| 4274 | message: options.message |
| 4275 | }; |
| 4276 | }; |
| 4277 | Parser.prototype.matchAsyncFunction = function () { |
| 4278 | var match = this.matchContextualKeyword('async'); |
| 4279 | if (match) { |
| 4280 | var state = this.scanner.saveState(); |
| 4281 | this.scanner.scanComments(); |
| 4282 | var next = this.scanner.lex(); |
| 4283 | this.scanner.restoreState(state); |
| 4284 | match = (state.lineNumber === next.lineNumber) && (next.type === 4 /* Keyword */) && (next.value === 'function'); |
| 4285 | } |
| 4286 | return match; |
| 4287 | }; |
| 4288 | Parser.prototype.parseFunctionDeclaration = function (identifierIsOptional) { |
| 4289 | var node = this.createNode(); |
| 4290 | var isAsync = this.matchContextualKeyword('async'); |
| 4291 | if (isAsync) { |
| 4292 | this.nextToken(); |
| 4293 | } |
| 4294 | this.expectKeyword('function'); |
| 4295 | var isGenerator = isAsync ? false : this.match('*'); |
| 4296 | if (isGenerator) { |
| 4297 | this.nextToken(); |
| 4298 | } |
| 4299 | var message; |
| 4300 | var id = null; |
| 4301 | var firstRestricted = null; |
| 4302 | if (!identifierIsOptional || !this.match('(')) { |
| 4303 | var token = this.lookahead; |
| 4304 | id = this.parseVariableIdentifier(); |
| 4305 | if (this.context.strict) { |
| 4306 | if (this.scanner.isRestrictedWord(token.value)) { |
| 4307 | this.tolerateUnexpectedToken(token, messages_1.Messages.StrictFunctionName); |
| 4308 | } |
| 4309 | } |
| 4310 | else { |
| 4311 | if (this.scanner.isRestrictedWord(token.value)) { |
| 4312 | firstRestricted = token; |
| 4313 | message = messages_1.Messages.StrictFunctionName; |
| 4314 | } |
| 4315 | else if (this.scanner.isStrictModeReservedWord(token.value)) { |
| 4316 | firstRestricted = token; |
| 4317 | message = messages_1.Messages.StrictReservedWord; |
| 4318 | } |
| 4319 | } |
| 4320 | } |
| 4321 | var previousAllowAwait = this.context.await; |
| 4322 | var previousAllowYield = this.context.allowYield; |
| 4323 | this.context.await = isAsync; |
| 4324 | this.context.allowYield = !isGenerator; |
| 4325 | var formalParameters = this.parseFormalParameters(firstRestricted); |
| 4326 | var params = formalParameters.params; |
| 4327 | var stricted = formalParameters.stricted; |
| 4328 | firstRestricted = formalParameters.firstRestricted; |
| 4329 | if (formalParameters.message) { |
| 4330 | message = formalParameters.message; |
| 4331 | } |
| 4332 | var previousStrict = this.context.strict; |
| 4333 | var previousAllowStrictDirective = this.context.allowStrictDirective; |
| 4334 | this.context.allowStrictDirective = formalParameters.simple; |
| 4335 | var body = this.parseFunctionSourceElements(); |
| 4336 | if (this.context.strict && firstRestricted) { |
| 4337 | this.throwUnexpectedToken(firstRestricted, message); |
| 4338 | } |
| 4339 | if (this.context.strict && stricted) { |
| 4340 | this.tolerateUnexpectedToken(stricted, message); |
| 4341 | } |
| 4342 | this.context.strict = previousStrict; |
| 4343 | this.context.allowStrictDirective = previousAllowStrictDirective; |
| 4344 | this.context.await = previousAllowAwait; |
| 4345 | this.context.allowYield = previousAllowYield; |
| 4346 | return isAsync ? this.finalize(node, new Node.AsyncFunctionDeclaration(id, params, body)) : |
| 4347 | this.finalize(node, new Node.FunctionDeclaration(id, params, body, isGenerator)); |
| 4348 | }; |
| 4349 | Parser.prototype.parseFunctionExpression = function () { |
| 4350 | var node = this.createNode(); |
| 4351 | var isAsync = this.matchContextualKeyword('async'); |
| 4352 | if (isAsync) { |
| 4353 | this.nextToken(); |
| 4354 | } |
| 4355 | this.expectKeyword('function'); |
| 4356 | var isGenerator = isAsync ? false : this.match('*'); |
| 4357 | if (isGenerator) { |
| 4358 | this.nextToken(); |
| 4359 | } |
| 4360 | var message; |
| 4361 | var id = null; |
| 4362 | var firstRestricted; |
| 4363 | var previousAllowAwait = this.context.await; |
| 4364 | var previousAllowYield = this.context.allowYield; |
| 4365 | this.context.await = isAsync; |
| 4366 | this.context.allowYield = !isGenerator; |
| 4367 | if (!this.match('(')) { |
| 4368 | var token = this.lookahead; |
| 4369 | id = (!this.context.strict && !isGenerator && this.matchKeyword('yield')) ? this.parseIdentifierName() : this.parseVariableIdentifier(); |
| 4370 | if (this.context.strict) { |
| 4371 | if (this.scanner.isRestrictedWord(token.value)) { |
| 4372 | this.tolerateUnexpectedToken(token, messages_1.Messages.StrictFunctionName); |
| 4373 | } |
| 4374 | } |
| 4375 | else { |
| 4376 | if (this.scanner.isRestrictedWord(token.value)) { |
| 4377 | firstRestricted = token; |
| 4378 | message = messages_1.Messages.StrictFunctionName; |
| 4379 | } |
| 4380 | else if (this.scanner.isStrictModeReservedWord(token.value)) { |
| 4381 | firstRestricted = token; |
| 4382 | message = messages_1.Messages.StrictReservedWord; |
| 4383 | } |
| 4384 | } |
| 4385 | } |
| 4386 | var formalParameters = this.parseFormalParameters(firstRestricted); |
| 4387 | var params = formalParameters.params; |
| 4388 | var stricted = formalParameters.stricted; |
| 4389 | firstRestricted = formalParameters.firstRestricted; |
| 4390 | if (formalParameters.message) { |
| 4391 | message = formalParameters.message; |
| 4392 | } |
| 4393 | var previousStrict = this.context.strict; |
| 4394 | var previousAllowStrictDirective = this.context.allowStrictDirective; |
| 4395 | this.context.allowStrictDirective = formalParameters.simple; |
| 4396 | var body = this.parseFunctionSourceElements(); |
| 4397 | if (this.context.strict && firstRestricted) { |
| 4398 | this.throwUnexpectedToken(firstRestricted, message); |
| 4399 | } |
| 4400 | if (this.context.strict && stricted) { |
| 4401 | this.tolerateUnexpectedToken(stricted, message); |
| 4402 | } |
| 4403 | this.context.strict = previousStrict; |
| 4404 | this.context.allowStrictDirective = previousAllowStrictDirective; |
| 4405 | this.context.await = previousAllowAwait; |
| 4406 | this.context.allowYield = previousAllowYield; |
| 4407 | return isAsync ? this.finalize(node, new Node.AsyncFunctionExpression(id, params, body)) : |
| 4408 | this.finalize(node, new Node.FunctionExpression(id, params, body, isGenerator)); |
| 4409 | }; |
| 4410 | // https://tc39.github.io/ecma262/#sec-directive-prologues-and-the-use-strict-directive |
| 4411 | Parser.prototype.parseDirective = function () { |
| 4412 | var token = this.lookahead; |
| 4413 | var node = this.createNode(); |
| 4414 | var expr = this.parseExpression(); |
| 4415 | var directive = (expr.type === syntax_1.Syntax.Literal) ? this.getTokenRaw(token).slice(1, -1) : null; |
| 4416 | this.consumeSemicolon(); |
| 4417 | return this.finalize(node, directive ? new Node.Directive(expr, directive) : new Node.ExpressionStatement(expr)); |
| 4418 | }; |
| 4419 | Parser.prototype.parseDirectivePrologues = function () { |
| 4420 | var firstRestricted = null; |
| 4421 | var body = []; |
| 4422 | while (true) { |
| 4423 | var token = this.lookahead; |
| 4424 | if (token.type !== 8 /* StringLiteral */) { |
| 4425 | break; |
| 4426 | } |
| 4427 | var statement = this.parseDirective(); |
| 4428 | body.push(statement); |
| 4429 | var directive = statement.directive; |
| 4430 | if (typeof directive !== 'string') { |
| 4431 | break; |
| 4432 | } |
| 4433 | if (directive === 'use strict') { |
| 4434 | this.context.strict = true; |
| 4435 | if (firstRestricted) { |
| 4436 | this.tolerateUnexpectedToken(firstRestricted, messages_1.Messages.StrictOctalLiteral); |
| 4437 | } |
| 4438 | if (!this.context.allowStrictDirective) { |
| 4439 | this.tolerateUnexpectedToken(token, messages_1.Messages.IllegalLanguageModeDirective); |
| 4440 | } |
| 4441 | } |
| 4442 | else { |
| 4443 | if (!firstRestricted && token.octal) { |
| 4444 | firstRestricted = token; |
| 4445 | } |
| 4446 | } |
| 4447 | } |
| 4448 | return body; |
| 4449 | }; |
| 4450 | // https://tc39.github.io/ecma262/#sec-method-definitions |
| 4451 | Parser.prototype.qualifiedPropertyName = function (token) { |
| 4452 | switch (token.type) { |
| 4453 | case 3 /* Identifier */: |
| 4454 | case 8 /* StringLiteral */: |
| 4455 | case 1 /* BooleanLiteral */: |
| 4456 | case 5 /* NullLiteral */: |
| 4457 | case 6 /* NumericLiteral */: |
| 4458 | case 4 /* Keyword */: |
| 4459 | return true; |
| 4460 | case 7 /* Punctuator */: |
| 4461 | return token.value === '['; |
| 4462 | default: |
| 4463 | break; |
| 4464 | } |
| 4465 | return false; |
| 4466 | }; |
| 4467 | Parser.prototype.parseGetterMethod = function () { |
| 4468 | var node = this.createNode(); |
| 4469 | var isGenerator = false; |
| 4470 | var previousAllowYield = this.context.allowYield; |
| 4471 | this.context.allowYield = false; |
| 4472 | var formalParameters = this.parseFormalParameters(); |
| 4473 | if (formalParameters.params.length > 0) { |
| 4474 | this.tolerateError(messages_1.Messages.BadGetterArity); |
| 4475 | } |
| 4476 | var method = this.parsePropertyMethod(formalParameters); |
| 4477 | this.context.allowYield = previousAllowYield; |
| 4478 | return this.finalize(node, new Node.FunctionExpression(null, formalParameters.params, method, isGenerator)); |
| 4479 | }; |
| 4480 | Parser.prototype.parseSetterMethod = function () { |
| 4481 | var node = this.createNode(); |
| 4482 | var isGenerator = false; |
| 4483 | var previousAllowYield = this.context.allowYield; |
| 4484 | this.context.allowYield = false; |
| 4485 | var formalParameters = this.parseFormalParameters(); |
| 4486 | if (formalParameters.params.length !== 1) { |
| 4487 | this.tolerateError(messages_1.Messages.BadSetterArity); |
| 4488 | } |
| 4489 | else if (formalParameters.params[0] instanceof Node.RestElement) { |
| 4490 | this.tolerateError(messages_1.Messages.BadSetterRestParameter); |
| 4491 | } |
| 4492 | var method = this.parsePropertyMethod(formalParameters); |
| 4493 | this.context.allowYield = previousAllowYield; |
| 4494 | return this.finalize(node, new Node.FunctionExpression(null, formalParameters.params, method, isGenerator)); |
| 4495 | }; |
| 4496 | Parser.prototype.parseGeneratorMethod = function () { |
| 4497 | var node = this.createNode(); |
| 4498 | var isGenerator = true; |
| 4499 | var previousAllowYield = this.context.allowYield; |
| 4500 | this.context.allowYield = true; |
| 4501 | var params = this.parseFormalParameters(); |
| 4502 | this.context.allowYield = false; |
| 4503 | var method = this.parsePropertyMethod(params); |
| 4504 | this.context.allowYield = previousAllowYield; |
| 4505 | return this.finalize(node, new Node.FunctionExpression(null, params.params, method, isGenerator)); |
| 4506 | }; |
| 4507 | // https://tc39.github.io/ecma262/#sec-generator-function-definitions |
| 4508 | Parser.prototype.isStartOfExpression = function () { |
| 4509 | var start = true; |
| 4510 | var value = this.lookahead.value; |
| 4511 | switch (this.lookahead.type) { |
| 4512 | case 7 /* Punctuator */: |
| 4513 | start = (value === '[') || (value === '(') || (value === '{') || |
| 4514 | (value === '+') || (value === '-') || |
| 4515 | (value === '!') || (value === '~') || |
| 4516 | (value === '++') || (value === '--') || |
| 4517 | (value === '/') || (value === '/='); // regular expression literal |
| 4518 | break; |
| 4519 | case 4 /* Keyword */: |
| 4520 | start = (value === 'class') || (value === 'delete') || |
| 4521 | (value === 'function') || (value === 'let') || (value === 'new') || |
| 4522 | (value === 'super') || (value === 'this') || (value === 'typeof') || |
| 4523 | (value === 'void') || (value === 'yield'); |
| 4524 | break; |
| 4525 | default: |
| 4526 | break; |
| 4527 | } |
| 4528 | return start; |
| 4529 | }; |
| 4530 | Parser.prototype.parseYieldExpression = function () { |
| 4531 | var node = this.createNode(); |
| 4532 | this.expectKeyword('yield'); |
| 4533 | var argument = null; |
| 4534 | var delegate = false; |
| 4535 | if (!this.hasLineTerminator) { |
| 4536 | var previousAllowYield = this.context.allowYield; |
| 4537 | this.context.allowYield = false; |
| 4538 | delegate = this.match('*'); |
| 4539 | if (delegate) { |
| 4540 | this.nextToken(); |
| 4541 | argument = this.parseAssignmentExpression(); |
| 4542 | } |
| 4543 | else if (this.isStartOfExpression()) { |
| 4544 | argument = this.parseAssignmentExpression(); |
| 4545 | } |
| 4546 | this.context.allowYield = previousAllowYield; |
| 4547 | } |
| 4548 | return this.finalize(node, new Node.YieldExpression(argument, delegate)); |
| 4549 | }; |
| 4550 | // https://tc39.github.io/ecma262/#sec-class-definitions |
| 4551 | Parser.prototype.parseClassElement = function (hasConstructor) { |
| 4552 | var token = this.lookahead; |
| 4553 | var node = this.createNode(); |
| 4554 | var kind = ''; |
| 4555 | var key = null; |
| 4556 | var value = null; |
| 4557 | var computed = false; |
| 4558 | var method = false; |
| 4559 | var isStatic = false; |
| 4560 | var isAsync = false; |
| 4561 | if (this.match('*')) { |
| 4562 | this.nextToken(); |
| 4563 | } |
| 4564 | else { |
| 4565 | computed = this.match('['); |
| 4566 | key = this.parseObjectPropertyKey(); |
| 4567 | var id = key; |
| 4568 | if (id.name === 'static' && (this.qualifiedPropertyName(this.lookahead) || this.match('*'))) { |
| 4569 | token = this.lookahead; |
| 4570 | isStatic = true; |
| 4571 | computed = this.match('['); |
| 4572 | if (this.match('*')) { |
| 4573 | this.nextToken(); |
| 4574 | } |
| 4575 | else { |
| 4576 | key = this.parseObjectPropertyKey(); |
| 4577 | } |
| 4578 | } |
| 4579 | if ((token.type === 3 /* Identifier */) && !this.hasLineTerminator && (token.value === 'async')) { |
| 4580 | var punctuator = this.lookahead.value; |
| 4581 | if (punctuator !== ':' && punctuator !== '(' && punctuator !== '*') { |
| 4582 | isAsync = true; |
| 4583 | token = this.lookahead; |
| 4584 | key = this.parseObjectPropertyKey(); |
| 4585 | if (token.type === 3 /* Identifier */) { |
| 4586 | if (token.value === 'get' || token.value === 'set') { |
| 4587 | this.tolerateUnexpectedToken(token); |
| 4588 | } |
| 4589 | else if (token.value === 'constructor') { |
| 4590 | this.tolerateUnexpectedToken(token, messages_1.Messages.ConstructorIsAsync); |
| 4591 | } |
| 4592 | } |
| 4593 | } |
| 4594 | } |
| 4595 | } |
| 4596 | var lookaheadPropertyKey = this.qualifiedPropertyName(this.lookahead); |
| 4597 | if (token.type === 3 /* Identifier */) { |
| 4598 | if (token.value === 'get' && lookaheadPropertyKey) { |
| 4599 | kind = 'get'; |
| 4600 | computed = this.match('['); |
| 4601 | key = this.parseObjectPropertyKey(); |
| 4602 | this.context.allowYield = false; |
| 4603 | value = this.parseGetterMethod(); |
| 4604 | } |
| 4605 | else if (token.value === 'set' && lookaheadPropertyKey) { |
| 4606 | kind = 'set'; |
| 4607 | computed = this.match('['); |
| 4608 | key = this.parseObjectPropertyKey(); |
| 4609 | value = this.parseSetterMethod(); |
| 4610 | } |
| 4611 | } |
| 4612 | else if (token.type === 7 /* Punctuator */ && token.value === '*' && lookaheadPropertyKey) { |
| 4613 | kind = 'init'; |
| 4614 | computed = this.match('['); |
| 4615 | key = this.parseObjectPropertyKey(); |
| 4616 | value = this.parseGeneratorMethod(); |
| 4617 | method = true; |
| 4618 | } |
| 4619 | if (!kind && key && this.match('(')) { |
| 4620 | kind = 'init'; |
| 4621 | value = isAsync ? this.parsePropertyMethodAsyncFunction() : this.parsePropertyMethodFunction(); |
| 4622 | method = true; |
| 4623 | } |
| 4624 | if (!kind) { |
| 4625 | this.throwUnexpectedToken(this.lookahead); |
| 4626 | } |
| 4627 | if (kind === 'init') { |
| 4628 | kind = 'method'; |
| 4629 | } |
| 4630 | if (!computed) { |
| 4631 | if (isStatic && this.isPropertyKey(key, 'prototype')) { |
| 4632 | this.throwUnexpectedToken(token, messages_1.Messages.StaticPrototype); |
| 4633 | } |
| 4634 | if (!isStatic && this.isPropertyKey(key, 'constructor')) { |
| 4635 | if (kind !== 'method' || !method || (value && value.generator)) { |
| 4636 | this.throwUnexpectedToken(token, messages_1.Messages.ConstructorSpecialMethod); |
| 4637 | } |
| 4638 | if (hasConstructor.value) { |
| 4639 | this.throwUnexpectedToken(token, messages_1.Messages.DuplicateConstructor); |
| 4640 | } |
| 4641 | else { |
| 4642 | hasConstructor.value = true; |
| 4643 | } |
| 4644 | kind = 'constructor'; |
| 4645 | } |
| 4646 | } |
| 4647 | return this.finalize(node, new Node.MethodDefinition(key, computed, value, kind, isStatic)); |
| 4648 | }; |
| 4649 | Parser.prototype.parseClassElementList = function () { |
| 4650 | var body = []; |
| 4651 | var hasConstructor = { value: false }; |
| 4652 | this.expect('{'); |
| 4653 | while (!this.match('}')) { |
| 4654 | if (this.match(';')) { |
| 4655 | this.nextToken(); |
| 4656 | } |
| 4657 | else { |
| 4658 | body.push(this.parseClassElement(hasConstructor)); |
| 4659 | } |
| 4660 | } |
| 4661 | this.expect('}'); |
| 4662 | return body; |
| 4663 | }; |
| 4664 | Parser.prototype.parseClassBody = function () { |
| 4665 | var node = this.createNode(); |
| 4666 | var elementList = this.parseClassElementList(); |
| 4667 | return this.finalize(node, new Node.ClassBody(elementList)); |
| 4668 | }; |
| 4669 | Parser.prototype.parseClassDeclaration = function (identifierIsOptional) { |
| 4670 | var node = this.createNode(); |
| 4671 | var previousStrict = this.context.strict; |
| 4672 | this.context.strict = true; |
| 4673 | this.expectKeyword('class'); |
| 4674 | var id = (identifierIsOptional && (this.lookahead.type !== 3 /* Identifier */)) ? null : this.parseVariableIdentifier(); |
| 4675 | var superClass = null; |
| 4676 | if (this.matchKeyword('extends')) { |
| 4677 | this.nextToken(); |
| 4678 | superClass = this.isolateCoverGrammar(this.parseLeftHandSideExpressionAllowCall); |
| 4679 | } |
| 4680 | var classBody = this.parseClassBody(); |
| 4681 | this.context.strict = previousStrict; |
| 4682 | return this.finalize(node, new Node.ClassDeclaration(id, superClass, classBody)); |
| 4683 | }; |
| 4684 | Parser.prototype.parseClassExpression = function () { |
| 4685 | var node = this.createNode(); |
| 4686 | var previousStrict = this.context.strict; |
| 4687 | this.context.strict = true; |
| 4688 | this.expectKeyword('class'); |
| 4689 | var id = (this.lookahead.type === 3 /* Identifier */) ? this.parseVariableIdentifier() : null; |
| 4690 | var superClass = null; |
| 4691 | if (this.matchKeyword('extends')) { |
| 4692 | this.nextToken(); |
| 4693 | superClass = this.isolateCoverGrammar(this.parseLeftHandSideExpressionAllowCall); |
| 4694 | } |
| 4695 | var classBody = this.parseClassBody(); |
| 4696 | this.context.strict = previousStrict; |
| 4697 | return this.finalize(node, new Node.ClassExpression(id, superClass, classBody)); |
| 4698 | }; |
| 4699 | // https://tc39.github.io/ecma262/#sec-scripts |
| 4700 | // https://tc39.github.io/ecma262/#sec-modules |
| 4701 | Parser.prototype.parseModule = function () { |
| 4702 | this.context.strict = true; |
| 4703 | this.context.isModule = true; |
| 4704 | var node = this.createNode(); |
| 4705 | var body = this.parseDirectivePrologues(); |
| 4706 | while (this.lookahead.type !== 2 /* EOF */) { |
| 4707 | body.push(this.parseStatementListItem()); |
| 4708 | } |
| 4709 | return this.finalize(node, new Node.Module(body)); |
| 4710 | }; |
| 4711 | Parser.prototype.parseScript = function () { |
| 4712 | var node = this.createNode(); |
| 4713 | var body = this.parseDirectivePrologues(); |
| 4714 | while (this.lookahead.type !== 2 /* EOF */) { |
| 4715 | body.push(this.parseStatementListItem()); |
| 4716 | } |
| 4717 | return this.finalize(node, new Node.Script(body)); |
| 4718 | }; |
| 4719 | // https://tc39.github.io/ecma262/#sec-imports |
| 4720 | Parser.prototype.parseModuleSpecifier = function () { |
| 4721 | var node = this.createNode(); |
| 4722 | if (this.lookahead.type !== 8 /* StringLiteral */) { |
| 4723 | this.throwError(messages_1.Messages.InvalidModuleSpecifier); |
| 4724 | } |
| 4725 | var token = this.nextToken(); |
| 4726 | var raw = this.getTokenRaw(token); |
| 4727 | return this.finalize(node, new Node.Literal(token.value, raw)); |
| 4728 | }; |
| 4729 | // import {<foo as bar>} ...; |
| 4730 | Parser.prototype.parseImportSpecifier = function () { |
| 4731 | var node = this.createNode(); |
| 4732 | var imported; |
| 4733 | var local; |
| 4734 | if (this.lookahead.type === 3 /* Identifier */) { |
| 4735 | imported = this.parseVariableIdentifier(); |
| 4736 | local = imported; |
| 4737 | if (this.matchContextualKeyword('as')) { |
| 4738 | this.nextToken(); |
| 4739 | local = this.parseVariableIdentifier(); |
| 4740 | } |
| 4741 | } |
| 4742 | else { |
| 4743 | imported = this.parseIdentifierName(); |
| 4744 | local = imported; |
| 4745 | if (this.matchContextualKeyword('as')) { |
| 4746 | this.nextToken(); |
| 4747 | local = this.parseVariableIdentifier(); |
| 4748 | } |
| 4749 | else { |
| 4750 | this.throwUnexpectedToken(this.nextToken()); |
| 4751 | } |
| 4752 | } |
| 4753 | return this.finalize(node, new Node.ImportSpecifier(local, imported)); |
| 4754 | }; |
| 4755 | // {foo, bar as bas} |
| 4756 | Parser.prototype.parseNamedImports = function () { |
| 4757 | this.expect('{'); |
| 4758 | var specifiers = []; |
| 4759 | while (!this.match('}')) { |
| 4760 | specifiers.push(this.parseImportSpecifier()); |
| 4761 | if (!this.match('}')) { |
| 4762 | this.expect(','); |
| 4763 | } |
| 4764 | } |
| 4765 | this.expect('}'); |
| 4766 | return specifiers; |
| 4767 | }; |
| 4768 | // import <foo> ...; |
| 4769 | Parser.prototype.parseImportDefaultSpecifier = function () { |
| 4770 | var node = this.createNode(); |
| 4771 | var local = this.parseIdentifierName(); |
| 4772 | return this.finalize(node, new Node.ImportDefaultSpecifier(local)); |
| 4773 | }; |
| 4774 | // import <* as foo> ...; |
| 4775 | Parser.prototype.parseImportNamespaceSpecifier = function () { |
| 4776 | var node = this.createNode(); |
| 4777 | this.expect('*'); |
| 4778 | if (!this.matchContextualKeyword('as')) { |
| 4779 | this.throwError(messages_1.Messages.NoAsAfterImportNamespace); |
| 4780 | } |
| 4781 | this.nextToken(); |
| 4782 | var local = this.parseIdentifierName(); |
| 4783 | return this.finalize(node, new Node.ImportNamespaceSpecifier(local)); |
| 4784 | }; |
| 4785 | Parser.prototype.parseImportDeclaration = function () { |
| 4786 | if (this.context.inFunctionBody) { |
| 4787 | this.throwError(messages_1.Messages.IllegalImportDeclaration); |
| 4788 | } |
| 4789 | var node = this.createNode(); |
| 4790 | this.expectKeyword('import'); |
| 4791 | var src; |
| 4792 | var specifiers = []; |
| 4793 | if (this.lookahead.type === 8 /* StringLiteral */) { |
| 4794 | // import 'foo'; |
| 4795 | src = this.parseModuleSpecifier(); |
| 4796 | } |
| 4797 | else { |
| 4798 | if (this.match('{')) { |
| 4799 | // import {bar} |
| 4800 | specifiers = specifiers.concat(this.parseNamedImports()); |
| 4801 | } |
| 4802 | else if (this.match('*')) { |
| 4803 | // import * as foo |
| 4804 | specifiers.push(this.parseImportNamespaceSpecifier()); |
| 4805 | } |
| 4806 | else if (this.isIdentifierName(this.lookahead) && !this.matchKeyword('default')) { |
| 4807 | // import foo |
| 4808 | specifiers.push(this.parseImportDefaultSpecifier()); |
| 4809 | if (this.match(',')) { |
| 4810 | this.nextToken(); |
| 4811 | if (this.match('*')) { |
| 4812 | // import foo, * as foo |
| 4813 | specifiers.push(this.parseImportNamespaceSpecifier()); |
| 4814 | } |
| 4815 | else if (this.match('{')) { |
| 4816 | // import foo, {bar} |
| 4817 | specifiers = specifiers.concat(this.parseNamedImports()); |
| 4818 | } |
| 4819 | else { |
| 4820 | this.throwUnexpectedToken(this.lookahead); |
| 4821 | } |
| 4822 | } |
| 4823 | } |
| 4824 | else { |
| 4825 | this.throwUnexpectedToken(this.nextToken()); |
| 4826 | } |
| 4827 | if (!this.matchContextualKeyword('from')) { |
| 4828 | var message = this.lookahead.value ? messages_1.Messages.UnexpectedToken : messages_1.Messages.MissingFromClause; |
| 4829 | this.throwError(message, this.lookahead.value); |
| 4830 | } |
| 4831 | this.nextToken(); |
| 4832 | src = this.parseModuleSpecifier(); |
| 4833 | } |
| 4834 | this.consumeSemicolon(); |
| 4835 | return this.finalize(node, new Node.ImportDeclaration(specifiers, src)); |
| 4836 | }; |
| 4837 | // https://tc39.github.io/ecma262/#sec-exports |
| 4838 | Parser.prototype.parseExportSpecifier = function () { |
| 4839 | var node = this.createNode(); |
| 4840 | var local = this.parseIdentifierName(); |
| 4841 | var exported = local; |
| 4842 | if (this.matchContextualKeyword('as')) { |
| 4843 | this.nextToken(); |
| 4844 | exported = this.parseIdentifierName(); |
| 4845 | } |
| 4846 | return this.finalize(node, new Node.ExportSpecifier(local, exported)); |
| 4847 | }; |
| 4848 | Parser.prototype.parseExportDeclaration = function () { |
| 4849 | if (this.context.inFunctionBody) { |
| 4850 | this.throwError(messages_1.Messages.IllegalExportDeclaration); |
| 4851 | } |
| 4852 | var node = this.createNode(); |
| 4853 | this.expectKeyword('export'); |
| 4854 | var exportDeclaration; |
| 4855 | if (this.matchKeyword('default')) { |
| 4856 | // export default ... |
| 4857 | this.nextToken(); |
| 4858 | if (this.matchKeyword('function')) { |