Skip to content

Commit

Permalink
Support BigInt syntax
Browse files Browse the repository at this point in the history
This change adds BigInt support which is specified in [1].

[1]: https://github.com/estree/estree/blob/master/es2020.md
  • Loading branch information
Constellation committed Dec 2, 2020
1 parent 0b1a75b commit 3a8e452
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
11 changes: 11 additions & 0 deletions escodegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Copyright (C) 2012 Joost-Wim Boekesteijn <joost-wim@boekesteijn.nl>
Copyright (C) 2012 Kris Kowal <kris.kowal@cixar.com>
Copyright (C) 2012 Arpad Borsos <arpad.borsos@googlemail.com>
Copyright (C) 2020 Apple Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -2348,6 +2349,16 @@
return '/' + expr.regex.pattern + '/' + expr.regex.flags;
}

if (typeof expr.value === 'bigint') {
return expr.value.toString() + 'n';
}

// `expr.value` can be null if `expr.bigint` exists. We need to check
// `expr.bigint` first.
if (expr.bigint) {
return expr.bigint + 'n';
}

if (expr.value === null) {
return 'null';
}
Expand Down
3 changes: 3 additions & 0 deletions test/compare-acorn-es2020/bigint.expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
2000n + 30;
20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n + 30;
-20000000000000000000000000000n;
1 change: 1 addition & 0 deletions test/compare-acorn-es2020/bigint.expected.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2000n+30;20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n+30;-20000000000000000000000000000n
28 changes: 28 additions & 0 deletions test/compare-acorn-es2020/bigint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2020 Apple Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

2000n + 30;
20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n + 30;
-20000000000000000000000000000n;

0 comments on commit 3a8e452

Please sign in to comment.