Force parentheses around array and conditional infer (#11227)

This commit is contained in:
Sergey Melyukov 2020-03-10 19:27:52 +03:00 committed by GitHub
parent eb65195f09
commit cb9d28c42c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -157,6 +157,10 @@ export function TSUnionType(node: Object, parent: Object): boolean {
export { TSUnionType as TSIntersectionType }; 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 { export function BinaryExpression(node: Object, parent: Object): boolean {
// let i = (1 in []); // let i = (1 in []);
// for ((1 in []);;); // for ((1 in []);;);

View File

@ -295,6 +295,15 @@ describe("generation", function() {
expect(generated).toHaveProperty("map"); expect(generated).toHaveProperty("map");
expect(typeof generated.map).toBe("object"); expect(typeof generated.map).toBe("object");
}); });
it("wraps around infer inside an array type", () => {
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() { describe("programmatic generation", function() {