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

Force parentheses around array and conditional infer #11227

Merged
merged 1 commit into from Mar 10, 2020
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
4 changes: 4 additions & 0 deletions packages/babel-generator/src/node/parentheses.js
Expand Up @@ -157,6 +157,10 @@ export function TSUnionType(node: Object, parent: Object): boolean {

export { TSUnionType as TSIntersectionType };

export function TSInferType(node: Object, parent: Object): boolean {
return t.isTSArrayType(parent) || t.isTSOptionalType(parent);
}

export function BinaryExpression(node: Object, parent: Object): boolean {
// let i = (1 in []);
// for ((1 in []);;);
Expand Down
9 changes: 9 additions & 0 deletions packages/babel-generator/test/index.js
Expand Up @@ -295,6 +295,15 @@ describe("generation", function() {
expect(generated).toHaveProperty("map");
expect(typeof generated.map).toBe("object");
});

it("wraps around infer inside an array type", () => {
Copy link
Member

Choose a reason for hiding this comment

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

Nit, but can we move this down with the other typescript parens tests below?

https://github.com/smelukov/babel/blob/force-parentheses-around-infer/packages/babel-generator/test/index.js#L464

const type = t.tsArrayType(
t.tsInferType(t.tsTypeParameter(null, null, "T")),
);

const output = generate(type).code;
expect(output).toBe("(infer T)[]");
});
});

describe("programmatic generation", function() {
Expand Down