visually split up inference inferer methods

This commit is contained in:
Sebastian McKenzie
2015-06-09 22:52:21 +01:00
parent 572261f9ce
commit fa670ac71e

View File

@@ -2,6 +2,8 @@ import * as t from "../../../types";
export { default as Identifier } from "./inferer-reference";
//
export function VariableDeclarator() {
var id = this.get("id");
@@ -12,12 +14,16 @@ export function VariableDeclarator() {
}
}
//
export function TypeCastExpression(node) {
return node.typeAnnotation;
}
TypeCastExpression.validParent = true;
//
export function NewExpression(node) {
if (this.get("callee").isIdentifier()) {
// only resolve identifier callee
@@ -25,10 +31,14 @@ export function NewExpression(node) {
}
}
//
export function TemplateLiteral() {
return t.stringTypeAnnotation();
}
//
export function UnaryExpression(node) {
let operator = node.operator;
@@ -43,6 +53,8 @@ export function UnaryExpression(node) {
}
}
//
export function BinaryExpression(node) {
let operator = node.operator;
@@ -70,6 +82,8 @@ export function BinaryExpression(node) {
}
}
//
export function LogicalExpression() {
return t.createUnionTypeAnnotation([
this.get("left").getTypeAnnotation(),
@@ -77,6 +91,8 @@ export function LogicalExpression() {
]);
}
//
export function ConditionalExpression() {
return t.createUnionTypeAnnotation([
this.get("consequent").getTypeAnnotation(),
@@ -84,14 +100,20 @@ export function ConditionalExpression() {
]);
}
//
export function SequenceExpression(node) {
return this.get("expressions").pop().getTypeAnnotation();
}
//
export function AssignmentExpression(node) {
return this.get("right").getTypeAnnotation();
}
//
export function UpdateExpression(node) {
let operator = node.operator;
if (operator === "++" || operator === "--") {
@@ -99,6 +121,8 @@ export function UpdateExpression(node) {
}
}
//
export function Literal(node) {
var value = node.value;
if (typeof value === "string") return t.stringTypeAnnotation();
@@ -108,26 +132,36 @@ export function Literal(node) {
if (node.regex) return t.genericTypeAnnotation(t.identifier("RegExp"));
}
//
export function ObjectExpression() {
return t.genericTypeAnnotation(t.identifier("Object"));
}
//
export function ArrayExpression () {
return t.genericTypeAnnotation(t.identifier("Array"));
}
//
export function RestElement() {
return ArrayExpression();
}
RestElement.validParent = true;
export function Func() {
//
function Func() {
return t.genericTypeAnnotation(t.identifier("Function"));
}
export { Func as Function, Func as Class };
//
export function CallExpression() {
return resolveCall(this.get("callee"));
}