Skip to content

Commit

Permalink
Respect the jsescOption.minimal generator option (#12755)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Feb 4, 2021
1 parent a0e3ef2 commit 77d46bc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
3 changes: 1 addition & 2 deletions packages/babel-generator/src/index.ts
Expand Up @@ -58,15 +58,14 @@ 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,
};

if (!process.env.BABEL_8_BREAKING) {
format.jsonCompatibleStrings = opts.jsonCompatibleStrings;
delete format.jsescOption.minimal;
}

if (format.minified) {
Expand Down
24 changes: 24 additions & 0 deletions packages/babel-generator/test/index.js
Expand Up @@ -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 () {
Expand Down

0 comments on commit 77d46bc

Please sign in to comment.