Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Jan 30, 2023
1 parent 8082167 commit 0d0b04f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/babel-traverse/src/path/inference/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ export function createUnionType(
types: Array<t.FlowType | t.TSType>,
): t.FlowType | t.TSType {
if (process.env.BABEL_8_BREAKING) {
if (isFlowType(types[0])) {
if (types.every(v => isFlowType(v))) {
return createFlowUnionType(types as t.FlowType[]);
}
if (isTSType(types[0])) {
if (types.every(v => isTSType(v))) {
return createTSUnionType(types as t.TSType[]);
}
} else {
if (isFlowType(types[0])) {
if (types.every(v => isFlowType(v))) {
if (createFlowUnionType) {
return createFlowUnionType(types as t.FlowType[]);
}

return createUnionTypeAnnotation(types as t.FlowType[]);
} else {
} else if (types.every(v => isTSType(v))) {
if (createTSUnionType) {
return createTSUnionType(types as t.TSType[]);
}
Expand Down
7 changes: 7 additions & 0 deletions packages/babel-traverse/test/inference.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,5 +701,12 @@ describe("inference with TypeScript", function () {
const path = tsGetPath(input).get("body.0.expression");
expect(path.isGenericType("Array")).toBe(true);
});
it("should not throw both flow and ts types", () => {
const path = tsGetPath(
`const bar = 0 ? mkList() : [];function mkList(): any[] {return [];}`,
).get("body.0.declarations.0");
// TODO: This should be true
expect(path.isGenericType("Array")).toBe(false);
});
});
});

0 comments on commit 0d0b04f

Please sign in to comment.