add t.createTypeAnnotationBasedOnTypeof method
This commit is contained in:
parent
0c37b7b973
commit
b7320ce400
@ -177,20 +177,7 @@ function checkBinary(name, path) {
|
||||
if (!typeofPath.get("argument").isIdentifier({ name })) return;
|
||||
|
||||
// turn type value into a type annotation
|
||||
var value = typePath.node.value;
|
||||
if (value === "string") {
|
||||
return t.stringTypeAnnotation();
|
||||
} else if (value === "number") {
|
||||
return t.numberTypeAnnotation();
|
||||
} else if (value === "undefined") {
|
||||
return t.voidTypeAnnotation();
|
||||
} else if (value === "boolean") {
|
||||
return t.booleanTypeAnnotation();
|
||||
} else if (value === "function") {
|
||||
// todo
|
||||
} else if (value === "object") {
|
||||
// todo
|
||||
}
|
||||
return t.createTypeAnnotationBasedOnTypeof(typePath.node.value);
|
||||
}
|
||||
|
||||
function getParentConditional(path) {
|
||||
|
||||
@ -15,6 +15,10 @@ export function createUnionTypeAnnotation(types) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
export function removeTypeDuplicates(nodes) {
|
||||
var generics = {};
|
||||
var bases = {};
|
||||
@ -90,3 +94,23 @@ export function removeTypeDuplicates(nodes) {
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
export function createTypeAnnotationBasedOnTypeof(type) {
|
||||
if (value === "string") {
|
||||
return t.stringTypeAnnotation();
|
||||
} else if (value === "number") {
|
||||
return t.numberTypeAnnotation();
|
||||
} else if (value === "undefined") {
|
||||
return t.voidTypeAnnotation();
|
||||
} else if (value === "boolean") {
|
||||
return t.booleanTypeAnnotation();
|
||||
} else if (value === "function") {
|
||||
// todo
|
||||
} else if (value === "object") {
|
||||
// todo
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user