From a754ea6bc2cc83ac88fb25e53bf0c56b896ae21d Mon Sep 17 00:00:00 2001 From: John Coker Date: Thu, 28 Dec 2023 10:37:13 -0800 Subject: [PATCH] BigIntLiteral.toSource includes suffix --- .../mozilla/javascript/ast/BigIntLiteral.java | 2 +- .../mozilla/javascript/tests/BigIntTest.java | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 testsrc/org/mozilla/javascript/tests/BigIntTest.java diff --git a/src/org/mozilla/javascript/ast/BigIntLiteral.java b/src/org/mozilla/javascript/ast/BigIntLiteral.java index b1af370abf..86751f13e4 100644 --- a/src/org/mozilla/javascript/ast/BigIntLiteral.java +++ b/src/org/mozilla/javascript/ast/BigIntLiteral.java @@ -71,7 +71,7 @@ public void setBigInt(BigInteger value) { @Override public String toSource(int depth) { - return makeIndent(depth) + (bigInt == null ? "" : bigInt.toString()); + return makeIndent(depth) + (bigInt == null ? "" : bigInt.toString() + "n"); } /** Visits this node. There are no children to visit. */ diff --git a/testsrc/org/mozilla/javascript/tests/BigIntTest.java b/testsrc/org/mozilla/javascript/tests/BigIntTest.java new file mode 100644 index 0000000000..424e24f400 --- /dev/null +++ b/testsrc/org/mozilla/javascript/tests/BigIntTest.java @@ -0,0 +1,47 @@ +package org.mozilla.javascript.tests; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mozilla.javascript.CompilerEnvirons; +import org.mozilla.javascript.Context; +import org.mozilla.javascript.Parser; +import org.mozilla.javascript.Scriptable; +import org.mozilla.javascript.ast.AstRoot; +import org.mozilla.javascript.tools.shell.Global; + +/** This is a set of tests for parsing and using BigInts. */ +public class BigIntTest { + + private Context cx; + private Scriptable global; + + @Before + public void init() { + cx = Context.enter(); + cx.setLanguageVersion(Context.VERSION_ES6); + cx.getWrapFactory().setJavaPrimitiveWrap(false); + global = new Global(cx); + } + + @After + public void terminate() { + Context.exit(); + } + + @Test + public void parse() throws IOException { + String[] INPUTS = + new String[] {"0n", "12n", "-12n", "1234567890987654321n", "-1234567890987654321n"}; + CompilerEnvirons env = new CompilerEnvirons(); + env.setLanguageVersion(Context.VERSION_ES6); + for (String input : INPUTS) { + String stmt = "x = " + input + ";\n"; + AstRoot root = new Parser(env).parse(stmt, "bigint.js", 1); + assertEquals(stmt, root.toSource()); + } + } +}