index.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* Generated by `npm run build`, do not edit! */
  2. "use strict"
  3. var acorn = require("acorn")
  4. var tt = acorn.tokTypes
  5. var privateClassElements = require("../private-class-elements")
  6. function maybeParseFieldValue(field) {
  7. if (this.eat(tt.eq)) {
  8. var oldInFieldValue = this._inFieldValue
  9. this._inFieldValue = true
  10. field.value = this.parseExpression()
  11. this._inFieldValue = oldInFieldValue
  12. } else { field.value = null }
  13. }
  14. module.exports = function(Parser) {
  15. Parser = privateClassElements(Parser)
  16. return /*@__PURE__*/(function (Parser) {
  17. function anonymous () {
  18. Parser.apply(this, arguments);
  19. }
  20. if ( Parser ) anonymous.__proto__ = Parser;
  21. anonymous.prototype = Object.create( Parser && Parser.prototype );
  22. anonymous.prototype.constructor = anonymous;
  23. anonymous.prototype.parseClassElement = function parseClassElement (_constructorAllowsSuper) {
  24. if (this.options.ecmaVersion >= 8 && (this.type == tt.name || this.type == this.privateNameToken || this.type == tt.bracketL || this.type == tt.string)) {
  25. var branch = this._branch()
  26. if (branch.type == tt.bracketL) {
  27. var count = 0
  28. do {
  29. if (branch.eat(tt.bracketL)) { ++count }
  30. else if (branch.eat(tt.bracketR)) { --count }
  31. else { branch.next() }
  32. } while (count > 0)
  33. } else { branch.next() }
  34. if (branch.type == tt.eq || branch.canInsertSemicolon() || branch.type == tt.semi) {
  35. var node = this.startNode()
  36. if (this.type == this.privateNameToken) {
  37. this.parsePrivateClassElementName(node)
  38. } else {
  39. this.parsePropertyName(node)
  40. }
  41. if ((node.key.type === "Identifier" && node.key.name === "constructor") ||
  42. (node.key.type === "Literal" && node.key.value === "constructor")) {
  43. this.raise(node.key.start, "Classes may not have a field called constructor")
  44. }
  45. maybeParseFieldValue.call(this, node)
  46. this.finishNode(node, "FieldDefinition")
  47. this.semicolon()
  48. return node
  49. }
  50. }
  51. return Parser.prototype.parseClassElement.apply(this, arguments)
  52. };
  53. // Prohibit arguments in class field initializers
  54. anonymous.prototype.parseIdent = function parseIdent (liberal, isBinding) {
  55. var ident = Parser.prototype.parseIdent.call(this, liberal, isBinding)
  56. if (this._inFieldValue && ident.name == "arguments") { this.raise(ident.start, "A class field initializer may not contain arguments") }
  57. return ident
  58. };
  59. return anonymous;
  60. }(Parser))
  61. }