diff --git a/packages/babel-template/src/options.js b/packages/babel-template/src/options.js index 07230cf1cf0b..b1c6f38a6e86 100644 --- a/packages/babel-template/src/options.js +++ b/packages/babel-template/src/options.js @@ -131,7 +131,7 @@ export function validate(opts: mixed): TemplateOpts { placeholderWhitelist: placeholderWhitelist || undefined, placeholderPattern: placeholderPattern == null ? undefined : placeholderPattern, - preserveComments: preserveComments == null ? false : preserveComments, + preserveComments: preserveComments == null ? undefined : preserveComments, syntacticPlaceholders: syntacticPlaceholders == null ? undefined : syntacticPlaceholders, }; diff --git a/packages/babel-template/test/index.js b/packages/babel-template/test/index.js index a90db40540e4..65fc3d4080c3 100644 --- a/packages/babel-template/test/index.js +++ b/packages/babel-template/test/index.js @@ -28,6 +28,18 @@ describe("@babel/template", function() { 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", () => { it("should handle replacing values from an object", () => { const value = t.stringLiteral("some string value"); @@ -219,7 +231,7 @@ describe("@babel/template", function() { }); }); - describe.only(".syntacticPlaceholders", () => { + describe(".syntacticPlaceholders", () => { it("works in function body", () => { const output = template(`function f() %%A%%`)({ A: t.blockStatement([]),