index.js 5.4 KB

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