diff --git a/packages/babel-generator/src/index.ts b/packages/babel-generator/src/index.ts index 6bc9cc138d..6c1a396c70 100644 --- a/packages/babel-generator/src/index.ts +++ b/packages/babel-generator/src/index.ts @@ -58,7 +58,7 @@ function normalizeOptions(code, opts): Format { jsescOption: { quotes: "double", wrap: true, - minimal: true, + minimal: process.env.BABEL_8_BREAKING ? true : false, ...opts.jsescOption, }, recordAndTupleSyntaxType: opts.recordAndTupleSyntaxType, @@ -66,7 +66,6 @@ function normalizeOptions(code, opts): Format { if (!process.env.BABEL_8_BREAKING) { format.jsonCompatibleStrings = opts.jsonCompatibleStrings; - delete format.jsescOption.minimal; } if (format.minified) { diff --git a/packages/babel-generator/test/index.js b/packages/babel-generator/test/index.js index bf28092957..0993e5c352 100644 --- a/packages/babel-generator/test/index.js +++ b/packages/babel-generator/test/index.js @@ -700,6 +700,30 @@ describe("programmatic generation", function () { expect(output).toBe("export default (class {});"); }); }); + + describe("jsescOption.minimal", () => { + const string = t.stringLiteral("\u8868\u683C_\u526F\u672C"); + + it("true", () => { + const output = generate(string, { jsescOption: { minimal: true } }).code; + expect(output).toBe(`"表格_副本"`); + }); + + it("false", () => { + const output = generate(string, { jsescOption: { minimal: false } }).code; + expect(output).toBe(`"\\u8868\\u683C_\\u526F\\u672C"`); + }); + + it("default", () => { + const output = generate(string).code; + + if (process.env.BABEL_8_BREAKING) { + expect(output).toBe(`"表格_副本"`); + } else { + expect(output).toBe(`"\\u8868\\u683C_\\u526F\\u672C"`); + } + }); + }); }); describe("CodeGenerator", function () {