|
| 1 | +/* Generated by `npm run build`, do not edit! */ |
| 2 | + |
| 3 | +"use strict" |
| 4 | + |
| 5 | +var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g |
| 6 | + |
| 7 | +var acorn = require("acorn") |
| 8 | +var tt = acorn.tokTypes |
| 9 | + |
| 10 | +function maybeParseFieldValue(field) { |
| 11 | + if (this.eat(tt.eq)) { |
| 12 | + var oldInFieldValue = this._inStaticFieldValue |
| 13 | + this._inStaticFieldValue = true |
| 14 | + field.value = this.parseExpression() |
| 15 | + this._inStaticFieldValue = oldInFieldValue |
| 16 | + } else { field.value = null } |
| 17 | +} |
| 18 | + |
| 19 | +var privateClassElements = require("acorn-private-class-elements") |
| 20 | + |
| 21 | +module.exports = function(Parser) { |
| 22 | + var ExtendedParser = privateClassElements(Parser) |
| 23 | + |
| 24 | + return /*@__PURE__*/(function (ExtendedParser) { |
| 25 | + function anonymous () { |
| 26 | + ExtendedParser.apply(this, arguments); |
| 27 | + } |
| 28 | + |
| 29 | + if ( ExtendedParser ) anonymous.__proto__ = ExtendedParser; |
| 30 | + anonymous.prototype = Object.create( ExtendedParser && ExtendedParser.prototype ); |
| 31 | + anonymous.prototype.constructor = anonymous; |
| 32 | + |
| 33 | + anonymous.prototype.parseClassElement = function parseClassElement (_constructorAllowsSuper) { |
| 34 | + var this$1 = this; |
| 35 | + |
| 36 | + if (this.eat(tt.semi)) { return null } |
| 37 | + |
| 38 | + var node = this.startNode() |
| 39 | + |
| 40 | + var tryContextual = function (k, noLineBreak) { |
| 41 | + if (typeof noLineBreak == "undefined") { noLineBreak = false } |
| 42 | + var start = this$1.start, startLoc = this$1.startLoc |
| 43 | + if (!this$1.eatContextual(k)) { return false } |
| 44 | + if (this$1.type !== tt.parenL && (!noLineBreak || !this$1.canInsertSemicolon())) { return true } |
| 45 | + if (node.key) { this$1.unexpected() } |
| 46 | + node.computed = false |
| 47 | + node.key = this$1.startNodeAt(start, startLoc) |
| 48 | + node.key.name = k |
| 49 | + this$1.finishNode(node.key, "Identifier") |
| 50 | + return false |
| 51 | + } |
| 52 | + |
| 53 | + node.static = tryContextual("static") |
| 54 | + if (!node.static) { return ExtendedParser.prototype.parseClassElement.apply(this, arguments) } |
| 55 | + |
| 56 | + var isGenerator = this.eat(tt.star) |
| 57 | + var isAsync = false |
| 58 | + if (!isGenerator) { |
| 59 | + // Special-case for `async`, since `parseClassMember` currently looks |
| 60 | + // for `(` to determine whether `async` is a method name |
| 61 | + if (this.options.ecmaVersion >= 8 && this.isContextual("async")) { |
| 62 | + skipWhiteSpace.lastIndex = this.pos |
| 63 | + var skip = skipWhiteSpace.exec(this.input) |
| 64 | + var next = this.input.charAt(this.pos + skip[0].length) |
| 65 | + if (next === ";" || next === "=") { |
| 66 | + node.key = this.parseIdent(true) |
| 67 | + node.computed = false |
| 68 | + maybeParseFieldValue.call(this, node) |
| 69 | + this.finishNode(node, "FieldDefinition") |
| 70 | + this.semicolon() |
| 71 | + return node |
| 72 | + } else if (this.options.ecmaVersion >= 8 && tryContextual("async", true)) { |
| 73 | + isAsync = true |
| 74 | + isGenerator = this.options.ecmaVersion >= 9 && this.eat(tt.star) |
| 75 | + } |
| 76 | + } else if (tryContextual("get")) { |
| 77 | + node.kind = "get" |
| 78 | + } else if (tryContextual("set")) { |
| 79 | + node.kind = "set" |
| 80 | + } |
| 81 | + } |
| 82 | + if (this.type === this.privateNameToken) { |
| 83 | + this.parsePrivateClassElementName(node) |
| 84 | + if (this.type !== tt.parenL) { |
| 85 | + if (node.key.name === "prototype") { |
| 86 | + this.raise(node.key.start, "Classes may not have a private static property named prototype") |
| 87 | + } |
| 88 | + maybeParseFieldValue.call(this, node) |
| 89 | + this.finishNode(node, "FieldDefinition") |
| 90 | + this.semicolon() |
| 91 | + return node |
| 92 | + } |
| 93 | + } else if (!node.key) { |
| 94 | + this.parsePropertyName(node) |
| 95 | + if ((node.key.name || node.key.value) === "prototype" && !node.computed) { |
| 96 | + this.raise(node.key.start, "Classes may not have a static property named prototype") |
| 97 | + } |
| 98 | + } |
| 99 | + if (!node.kind) { node.kind = "method" } |
| 100 | + this.parseClassMethod(node, isGenerator, isAsync) |
| 101 | + if (!node.kind && (node.key.name || node.key.value) === "constructor" && !node.computed) { |
| 102 | + this.raise(node.key.start, "Classes may not have a static field named constructor") |
| 103 | + } |
| 104 | + if (node.kind === "get" && node.value.params.length !== 0) { |
| 105 | + this.raiseRecoverable(node.value.start, "getter should have no params") |
| 106 | + } |
| 107 | + if (node.kind === "set" && node.value.params.length !== 1) { |
| 108 | + this.raiseRecoverable(node.value.start, "setter should have exactly one param") |
| 109 | + } |
| 110 | + if (node.kind === "set" && node.value.params[0].type === "RestElement") { |
| 111 | + this.raiseRecoverable(node.value.params[0].start, "Setter cannot use rest params") |
| 112 | + } |
| 113 | + |
| 114 | + return node |
| 115 | + |
| 116 | + }; |
| 117 | + |
| 118 | + // Parse public static fields |
| 119 | + anonymous.prototype.parseClassMethod = function parseClassMethod (method, isGenerator, isAsync, _allowsDirectSuper) { |
| 120 | + if (isGenerator || isAsync || method.kind != "method" || !method.static || this.options.ecmaVersion < 8 || this.type == tt.parenL) { |
| 121 | + return ExtendedParser.prototype.parseClassMethod.apply(this, arguments) |
| 122 | + } |
| 123 | + maybeParseFieldValue.call(this, method) |
| 124 | + delete method.kind |
| 125 | + method = this.finishNode(method, "FieldDefinition") |
| 126 | + this.semicolon() |
| 127 | + return method |
| 128 | + }; |
| 129 | + |
| 130 | + // Prohibit arguments in class field initializers |
| 131 | + anonymous.prototype.parseIdent = function parseIdent (liberal, isBinding) { |
| 132 | + var ident = ExtendedParser.prototype.parseIdent.call(this, liberal, isBinding) |
| 133 | + if (this._inStaticFieldValue && ident.name == "arguments") { this.raise(ident.start, "A static class field initializer may not contain arguments") } |
| 134 | + return ident |
| 135 | + }; |
| 136 | + |
| 137 | + return anonymous; |
| 138 | + }(ExtendedParser)) |
| 139 | +} |
0 commit comments