Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always print directives with double quotes when minified #14094

Merged
merged 1 commit into from Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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