Skip to content

Commit 3a8e452

Browse files
committed
Support BigInt syntax
This change adds BigInt support which is specified in [1]. [1]: https://github.com/estree/estree/blob/master/es2020.md
1 parent 0b1a75b commit 3a8e452

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

escodegen.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
Copyright (C) 2012 Joost-Wim Boekesteijn <joost-wim@boekesteijn.nl>
1212
Copyright (C) 2012 Kris Kowal <kris.kowal@cixar.com>
1313
Copyright (C) 2012 Arpad Borsos <arpad.borsos@googlemail.com>
14+
Copyright (C) 2020 Apple Inc. All rights reserved.
1415
1516
Redistribution and use in source and binary forms, with or without
1617
modification, are permitted provided that the following conditions are met:
@@ -2348,6 +2349,16 @@
23482349
return '/' + expr.regex.pattern + '/' + expr.regex.flags;
23492350
}
23502351

2352+
if (typeof expr.value === 'bigint') {
2353+
return expr.value.toString() + 'n';
2354+
}
2355+
2356+
// `expr.value` can be null if `expr.bigint` exists. We need to check
2357+
// `expr.bigint` first.
2358+
if (expr.bigint) {
2359+
return expr.bigint + 'n';
2360+
}
2361+
23512362
if (expr.value === null) {
23522363
return 'null';
23532364
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2000n + 30;
2+
20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n + 30;
3+
-20000000000000000000000000000n;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2000n+30;20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n+30;-20000000000000000000000000000n

test/compare-acorn-es2020/bigint.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (C) 2020 Apple Inc.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
* 1. Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
*
13+
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17+
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23+
* THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
2000n + 30;
27+
20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n + 30;
28+
-20000000000000000000000000000n;

0 commit comments

Comments
 (0)