Skip to content

Commit

Permalink
Always print directives with double quotes when minified (#14094)
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Jan 6, 2022
1 parent ddd93b9 commit 3942d72
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/babel-generator/src/generators/base.ts
Expand Up @@ -58,7 +58,7 @@ const unescapedDoubleQuoteRE = /(?:^|[^\\])(?:\\\\)*"/;

export function DirectiveLiteral(this: Printer, node: t.DirectiveLiteral) {
const raw = this.getPossibleRaw(node);
if (raw != null) {
if (!this.format.minified && raw != null) {
this.token(raw);
return;
}
Expand Down
14 changes: 14 additions & 0 deletions packages/babel-generator/test/index.js
Expand Up @@ -548,6 +548,20 @@ describe("programmatic generation", function () {
generate(directive);
}).toThrow();
});

it("preserves single quotes if not minified", function () {
const directive = parse("'use strict';").program.directives[0];
const output = generate(directive).code;

expect(output).toBe("'use strict';");
});

it("converts single quotes to double quotes if minified", function () {
const directive = parse("'use strict';").program.directives[0];
const output = generate(directive, { minified: true }).code;

expect(output).toBe('"use strict";');
});
});

describe("typescript generate parentheses if necessary", function () {
Expand Down

0 comments on commit 3942d72

Please sign in to comment.