Force parentheses around array and conditional infer (#11227)
This commit is contained in:
parent
eb65195f09
commit
cb9d28c42c
@ -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 []);;);
|
||||||
|
|||||||
@ -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() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user