Always print directives with double quotes when minified (#14094)

This commit is contained in:
overlookmotel 2022-01-06 15:28:28 +00:00 committed by GitHub
parent ddd93b9c61
commit 3942d72745
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -58,7 +58,7 @@ const unescapedDoubleQuoteRE = /(?:^|[^\\])(?:\\\\)*"/;
export function DirectiveLiteral(this: Printer, node: t.DirectiveLiteral) { export function DirectiveLiteral(this: Printer, node: t.DirectiveLiteral) {
const raw = this.getPossibleRaw(node); const raw = this.getPossibleRaw(node);
if (raw != null) { if (!this.format.minified && raw != null) {
this.token(raw); this.token(raw);
return; return;
} }

View File

@ -548,6 +548,20 @@ describe("programmatic generation", function () {
generate(directive); generate(directive);
}).toThrow(); }).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 () { describe("typescript generate parentheses if necessary", function () {