Skip to content

Commit 90ab159

Browse files
committed
Revert "Use builtin bigint support"
This reverts commit 37006ab.
1 parent 4ce2160 commit 90ab159

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

build.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function privateClassElements (str) {
2222
return str.replace('acorn-private-class-elements', '../private-class-elements')
2323
}
2424

25+
compile('acorn-bigint', './lib/bigint/index.js')
2526
compile('acorn-import-meta', './lib/import-meta/index.js')
2627
compile('acorn-export-ns-from', './lib/export-ns-from/index.js')
2728
compile('acorn-class-fields', './lib/class-fields/index.js', privateClassElements)

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var acorn = require('acorn')
22
var xtend = require('xtend')
33

44
var CJSParser = acorn.Parser
5+
.extend(require('./lib/bigint'))
56
.extend(require('./lib/class-fields'))
67
.extend(require('./lib/static-class-features'))
78
var ESModulesParser = CJSParser

lib/bigint/index.js

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"xtend": "^4.0.2"
1313
},
1414
"devDependencies": {
15+
"acorn-bigint": "^0.4.0",
1516
"acorn-class-fields": "^0.3.1",
1617
"acorn-export-ns-from": "^0.1.0",
1718
"acorn-import-meta": "^1.0.0",

0 commit comments

Comments
 (0)