Adding createFlowUnionType in place of createUnionTypeAnnotati… (#11448)
* 🔄 createUnionTypeAnnotation => createFlowUnionType * ➕ add createFlowUnionType if it exists (in new versions only ⚠️) * 🔄 use createFlowUnionType for createUnionTypeAnnotation
This commit is contained in:
parent
928b9f8c95
commit
a34424a894
@ -99,6 +99,10 @@ function getTypeAnnotationBindingConstantViolations(binding, path, name) {
|
||||
return t.createTSUnionType(types);
|
||||
}
|
||||
|
||||
if (t.createFlowUnionType) {
|
||||
return t.createFlowUnionType(types);
|
||||
}
|
||||
|
||||
return t.createUnionTypeAnnotation(types);
|
||||
}
|
||||
|
||||
@ -214,6 +218,13 @@ function getConditionalAnnotation(binding, path, name) {
|
||||
};
|
||||
}
|
||||
|
||||
if (t.createFlowUnionType) {
|
||||
return {
|
||||
typeAnnotation: t.createFlowUnionType(types),
|
||||
ifStatement,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
typeAnnotation: t.createUnionTypeAnnotation(types),
|
||||
ifStatement,
|
||||
|
||||
@ -92,6 +92,10 @@ export function LogicalExpression() {
|
||||
return t.createTSUnionType(argumentTypes);
|
||||
}
|
||||
|
||||
if (t.createFlowUnionType) {
|
||||
return t.createFlowUnionType(argumentTypes);
|
||||
}
|
||||
|
||||
return t.createUnionTypeAnnotation(argumentTypes);
|
||||
}
|
||||
|
||||
@ -105,6 +109,10 @@ export function ConditionalExpression() {
|
||||
return t.createTSUnionType(argumentTypes);
|
||||
}
|
||||
|
||||
if (t.createFlowUnionType) {
|
||||
return t.createFlowUnionType(argumentTypes);
|
||||
}
|
||||
|
||||
return t.createUnionTypeAnnotation(argumentTypes);
|
||||
}
|
||||
|
||||
|
||||
@ -128,6 +128,8 @@ lines.push(
|
||||
`declare function createTypeAnnotationBasedOnTypeof(type: 'string' | 'number' | 'undefined' | 'boolean' | 'function' | 'object' | 'symbol'): ${NODE_PREFIX}TypeAnnotation`,
|
||||
// eslint-disable-next-line max-len
|
||||
`declare function createUnionTypeAnnotation(types: Array<${NODE_PREFIX}FlowType>): ${NODE_PREFIX}UnionTypeAnnotation`,
|
||||
// eslint-disable-next-line max-len
|
||||
`declare function createFlowUnionType(types: Array<${NODE_PREFIX}FlowType>): ${NODE_PREFIX}UnionTypeAnnotation`,
|
||||
// this smells like "internal API"
|
||||
// eslint-disable-next-line max-len
|
||||
`declare function buildChildren(node: { children: Array<${NODE_PREFIX}JSXText | ${NODE_PREFIX}JSXExpressionContainer | ${NODE_PREFIX}JSXSpreadChild | ${NODE_PREFIX}JSXElement | ${NODE_PREFIX}JSXFragment | ${NODE_PREFIX}JSXEmptyExpression> }): Array<${NODE_PREFIX}JSXText | ${NODE_PREFIX}JSXExpressionContainer | ${NODE_PREFIX}JSXSpreadChild | ${NODE_PREFIX}JSXElement | ${NODE_PREFIX}JSXFragment>`,
|
||||
|
||||
@ -144,9 +144,11 @@ lines.push(
|
||||
// eslint-disable-next-line max-len
|
||||
`export function createTypeAnnotationBasedOnTypeof(type: 'string' | 'number' | 'undefined' | 'boolean' | 'function' | 'object' | 'symbol'): StringTypeAnnotation | VoidTypeAnnotation | NumberTypeAnnotation | BooleanTypeAnnotation | GenericTypeAnnotation`,
|
||||
`export function createUnionTypeAnnotation<T extends FlowType>(types: [T]): T`,
|
||||
`export function createFlowUnionType<T extends FlowType>(types: [T]): T`,
|
||||
// this probably misbehaves if there are 0 elements, and it's not a UnionTypeAnnotation if there's only 1
|
||||
// it is possible to require "2 or more" for this overload ([T, T, ...T[]]) but it requires typescript 3.0
|
||||
`export function createUnionTypeAnnotation(types: ReadonlyArray<FlowType>): UnionTypeAnnotation`,
|
||||
`export function createFlowUnionType(types: ReadonlyArray<FlowType>): UnionTypeAnnotation`,
|
||||
// this smells like "internal API"
|
||||
// eslint-disable-next-line max-len
|
||||
`export function buildChildren(node: { children: ReadonlyArray<JSXText | JSXExpressionContainer | JSXSpreadChild | JSXElement | JSXFragment | JSXEmptyExpression> }): JSXElement['children']`,
|
||||
|
||||
@ -6,9 +6,7 @@ import removeTypeDuplicates from "../../modifications/flow/removeTypeDuplicates"
|
||||
* Takes an array of `types` and flattens them, removing duplicates and
|
||||
* returns a `UnionTypeAnnotation` node containg them.
|
||||
*/
|
||||
export default function createUnionTypeAnnotation(
|
||||
types: Array<Object>,
|
||||
): Object {
|
||||
export default function createFlowUnionType(types: Array<Object>): Object {
|
||||
const flattened = removeTypeDuplicates(types);
|
||||
|
||||
if (flattened.length === 1) {
|
||||
@ -9,7 +9,8 @@ export * from "./asserts/generated";
|
||||
|
||||
// builders
|
||||
export { default as createTypeAnnotationBasedOnTypeof } from "./builders/flow/createTypeAnnotationBasedOnTypeof";
|
||||
export { default as createUnionTypeAnnotation } from "./builders/flow/createUnionTypeAnnotation";
|
||||
export { default as createUnionTypeAnnotation } from "./builders/flow/createFlowUnionType";
|
||||
export { default as createFlowUnionType } from "./builders/flow/createFlowUnionType";
|
||||
export { default as createTSUnionType } from "./builders/typescript/createTSUnionType";
|
||||
export * from "./builders/generated";
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user