estools / escodegen

ECMAScript code generator
BSD 2-Clause "Simplified" License
2.64k stars 334 forks source link

"NewExpression" generated without arguments #460

Closed canmingir closed 8 months ago

canmingir commented 8 months ago
const escodegen = require("escodegen"); // 2.1.0
const { FORMAT_MINIFY } = require("escodegen");

const program = {
  type: "Program",
  body: [
    {
      type: "VariableDeclaration",
      declarations: [
        {
          type: "VariableDeclarator",
          id: {
            type: "Identifier",
            name: "date",
          },
          init: {
            type: "NewExpression",
            callee: {
              type: "Identifier",
              name: "Date",
            },
            arguments: [],
          },
        },
      ],
      kind: "var",
    },
  ],
  sourceType: "script",
};

const code = escodegen.generate(program, { format: FORMAT_MINIFY });
console.log(code);

In 2.1.0 version, escodegen generates above like this var date=new Date without arguments in parenthesis

canmingir commented 8 months ago

I've tried with FORMAT_DEFAULTS, it seems working with that like var date = new Date();, I must be something with FORMAT_MINIFY.

papandreou commented 8 months ago

You can see the logic here.

Note that new Date is correct JavaScript code.