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

Respect preserveComments option in tempate.ast() #11112

Merged
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-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
14 changes: 13 additions & 1 deletion 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 Expand Up @@ -219,7 +231,7 @@ describe("@babel/template", function() {
});
});

describe.only(".syntacticPlaceholders", () => {
describe(".syntacticPlaceholders", () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😬

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably lint for this 😬

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it looks like we should be linting for this already: https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/no-focused-tests.md is a recommended rule. 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We added it yesterday 😛
#11119

it("works in function body", () => {
const output = template(`function f() %%A%%`)({
A: t.blockStatement([]),
Expand Down