Repository: babel/babel
File: packages/babel-types/test/converters.js (JavaScript)

Code before:
      expect(t.valueToNode(-0)).toEqual(
        t.unaryExpression("-", t.numericLiteral(0)),
      );
      expect(t.valueToNode(NaN)).toEqual(
        t.binaryExpression("/", t.numericLiteral(0), t.numericLiteral(0)),
      );
      expect(t.valueToNode(-NaN)).toEqual(
        t.binaryExpression("/", t.numericLiteral(0), t.numericLiteral(0)),
      );

      expect(t.valueToNode(Infinity)).toEqual(
        t.binaryExpression("/", t.numericLiteral(1), t.numericLiteral(0)),
      );
      expect(t.valueToNode(-Infinity)).toEqual(
        t.unaryExpression(
          "-",
          t.binaryExpression("/", t.numericLiteral(1), t.numericLiteral(0)),
        ),
      );
    });
    it("bigint", function () {
      expect(t.valueToNode(123n)).toEqual(t.bigIntLiteral("123"));
    });
    it("string", function () {
      expect(t.valueToNode('This is a "string"')).toEqual(
        t.stringLiteral('This is a "string"'),
      );
    });
    it("boolean", function () {
      expect(t.valueToNode(true)).toEqual(t.booleanLiteral(true));
      expect(t.valueToNode(false)).toEqual(t.booleanLiteral(false));
    });
    it("null", function () {
      expect(t.valueToNode(null)).toEqual(t.nullLiteral());
    });
    it("undefined", function () {
      expect(t.valueToNode(undefined)).toEqual(t.identifier("undefined"));
    });
    it("RegExp", function () {
      // eslint-disable-next-line regexp/no-useless-flag
      expect(t.valueToNode(/abc.+/gm)).toEqual(t.regExpLiteral("abc.+", "gm"));
    });
    it("array", function () {
      expect(t.valueToNode([1, "a"])).toEqual(
        t.arrayExpression([t.numericLiteral(1), t.stringLiteral("a")]),
      );
    });
    it("object", function () {
      expect(
        t.valueToNode({
          a: 1,

Review comment (bug):
This test will fail on Node.js 8 and Node.js 6 because they don't have native bigint support. To make the CI green we can use the `BigInt` constructor and wrap this test with `itGte("10.4.0")` so that the test will only run on Node.js >= 10.4.0. See `eslint/babel-eslint-tests/test/integration/parser-override.js` for an example usage.

Code after:
      expect(t.valueToNode(0)).toEqual(t.numericLiteral(0));
      expect(t.valueToNode(-0)).toEqual(
        t.unaryExpression("-", t.numericLiteral(0)),
      );
      expect(t.valueToNode(NaN)).toEqual(
        t.binaryExpression("/", t.numericLiteral(0), t.numericLiteral(0)),
      );
      expect(t.valueToNode(-NaN)).toEqual(
        t.binaryExpression("/", t.numericLiteral(0), t.numericLiteral(0)),
      );

      expect(t.valueToNode(Infinity)).toEqual(
        t.binaryExpression("/", t.numericLiteral(1), t.numericLiteral(0)),
      );
      expect(t.valueToNode(-Infinity)).toEqual(
        t.unaryExpression(
          "-",
          t.binaryExpression("/", t.numericLiteral(1), t.numericLiteral(0)),
        ),
      );
    });

    const nodeGte10 = itGte("10.4.0");
    nodeGte10("bigint", function () {
      expect(t.valueToNode(BigInt(123))).toEqual(t.bigIntLiteral("123"));
    });
    it("string", function () {
      expect(t.valueToNode('This is a "string"')).toEqual(
        t.stringLiteral('This is a "string"'),
      );
    });
    it("boolean", function () {
      expect(t.valueToNode(true)).toEqual(t.booleanLiteral(true));
      expect(t.valueToNode(false)).toEqual(t.booleanLiteral(false));
    });
    it("null", function () {
      expect(t.valueToNode(null)).toEqual(t.nullLiteral());
    });
    it("undefined", function () {
      expect(t.valueToNode(undefined)).toEqual(t.identifier("undefined"));
    });
    it("RegExp", function () {
      // eslint-disable-next-line regexp/no-useless-flag
      expect(t.valueToNode(/abc.+/gm)).toEqual(t.regExpLiteral("abc.+", "gm"));
    });
    it("array", function () {
      expect(t.valueToNode([1, "a"])).toEqual(
        t.arrayExpression([t.numericLiteral(1), t.stringLiteral("a")]),
      );
    });
    it("object", function () {