index.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* Generated by `npm run build`, do not edit! */
  2. "use strict"
  3. var acorn = require("acorn")
  4. var tt = acorn.tokTypes
  5. var isIdentifierStart = acorn.isIdentifierStart
  6. module.exports = function(Parser) {
  7. return /*@__PURE__*/(function (Parser) {
  8. function anonymous () {
  9. Parser.apply(this, arguments);
  10. }
  11. if ( Parser ) anonymous.__proto__ = Parser;
  12. anonymous.prototype = Object.create( Parser && Parser.prototype );
  13. anonymous.prototype.constructor = anonymous;
  14. anonymous.prototype.parseLiteral = function parseLiteral (value) {
  15. var node = Parser.prototype.parseLiteral.call(this, value)
  16. if (node.raw.charCodeAt(node.raw.length - 1) == 110) { node.bigint = this.getNumberInput(node.start, node.end) }
  17. return node
  18. };
  19. anonymous.prototype.readRadixNumber = function readRadixNumber (radix) {
  20. var start = this.pos
  21. this.pos += 2 // 0x
  22. var val = this.readInt(radix)
  23. if (val === null) { this.raise(this.start + 2, ("Expected number in radix " + radix)) }
  24. if (this.input.charCodeAt(this.pos) == 110) {
  25. var str = this.getNumberInput(start, this.pos)
  26. val = typeof BigInt !== "undefined" ? BigInt(str) : null
  27. ++this.pos
  28. } else if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number") }
  29. return this.finishToken(tt.num, val)
  30. };
  31. anonymous.prototype.readNumber = function readNumber (startsWithDot) {
  32. var start = this.pos
  33. // Not an int
  34. if (startsWithDot) { return Parser.prototype.readNumber.call(this, startsWithDot) }
  35. // Legacy octal
  36. if (this.input.charCodeAt(start) === 48 && this.input.charCodeAt(start + 1) !== 110) {
  37. return Parser.prototype.readNumber.call(this, startsWithDot)
  38. }
  39. if (this.readInt(10) === null) { this.raise(start, "Invalid number") }
  40. // Not a BigInt, reset and parse again
  41. if (this.input.charCodeAt(this.pos) != 110) {
  42. this.pos = start
  43. return Parser.prototype.readNumber.call(this, startsWithDot)
  44. }
  45. var str = this.getNumberInput(start, this.pos)
  46. var val = typeof BigInt !== "undefined" ? BigInt(str) : null
  47. ++this.pos
  48. return this.finishToken(tt.num, val)
  49. };
  50. // This is basically a hook for acorn-numeric-separator
  51. anonymous.prototype.getNumberInput = function getNumberInput (start, end) {
  52. if (Parser.prototype.getNumberInput) { return Parser.prototype.getNumberInput.call(this, start, end) }
  53. return this.input.slice(start, end)
  54. };
  55. return anonymous;
  56. }(Parser))
  57. }