Respect preserveComments option in tempate.ast() (#11112)
This commit is contained in:
parent
3907396bd8
commit
bc308a1b15
@ -131,7 +131,7 @@ export function validate(opts: mixed): TemplateOpts {
|
|||||||
placeholderWhitelist: placeholderWhitelist || undefined,
|
placeholderWhitelist: placeholderWhitelist || undefined,
|
||||||
placeholderPattern:
|
placeholderPattern:
|
||||||
placeholderPattern == null ? undefined : placeholderPattern,
|
placeholderPattern == null ? undefined : placeholderPattern,
|
||||||
preserveComments: preserveComments == null ? false : preserveComments,
|
preserveComments: preserveComments == null ? undefined : preserveComments,
|
||||||
syntacticPlaceholders:
|
syntacticPlaceholders:
|
||||||
syntacticPlaceholders == null ? undefined : syntacticPlaceholders,
|
syntacticPlaceholders == null ? undefined : syntacticPlaceholders,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -28,6 +28,18 @@ describe("@babel/template", function() {
|
|||||||
expect(generator(output).code).toBe(comments);
|
expect(generator(output).code).toBe(comments);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should preserve comments with a flag", function() {
|
||||||
|
const output = template(comments, { preserveComments: true })();
|
||||||
|
expect(generator(output).code).toBe(comments);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should preserve comments with a flag when using .ast", function() {
|
||||||
|
const output1 = template.ast(comments, { preserveComments: true });
|
||||||
|
const output2 = template({ preserveComments: true }).ast(comments);
|
||||||
|
expect(generator(output1).code).toBe(comments);
|
||||||
|
expect(generator(output2).code).toBe(comments);
|
||||||
|
});
|
||||||
|
|
||||||
describe("string-based", () => {
|
describe("string-based", () => {
|
||||||
it("should handle replacing values from an object", () => {
|
it("should handle replacing values from an object", () => {
|
||||||
const value = t.stringLiteral("some string value");
|
const value = t.stringLiteral("some string value");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user