add t.createTypeAnnotationBasedOnTypeof method

This commit is contained in:
Sebastian McKenzie 2015-06-09 03:23:28 +01:00
parent 0c37b7b973
commit b7320ce400
2 changed files with 25 additions and 14 deletions

View File

@ -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) {

View File

@ -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
}
}