Skip to content

Commit

Permalink
Respect preserveComments option in tempate.ast() (babel#11112)
Browse files Browse the repository at this point in the history
  • Loading branch information
dentrado authored and rajasekarm committed Feb 17, 2020
1 parent 87d20e3 commit d778427
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/babel-template/src/options.js
Expand Up @@ -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,
};
Expand Down
12 changes: 12 additions & 0 deletions packages/babel-template/test/index.js
Expand Up @@ -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");
Expand Down

0 comments on commit d778427

Please sign in to comment.