add Flow virtual type

This commit is contained in:
Sebastian McKenzie 2015-07-21 01:14:19 +01:00
parent 512707c7de
commit b97dc4778b
3 changed files with 35 additions and 3 deletions

View File

@ -145,8 +145,7 @@ for (let type of (t.TYPES: Array)) {
for (let type in virtualTypes) {
if (type[0] === "_") continue;
t.TYPES.push(type);
if (t.TYPES.indexOf(type) < 0) t.TYPES.push(type);
NodePath.prototype[`is${type}`] = function (opts) {
return virtualTypes[type].checkPath(this, opts);

View File

@ -110,6 +110,10 @@ export var Var = {
}
};
/**
* [Please add a description.]
*/
export var DirectiveLiteral = {
types: ["Literal"],
checkPath(path) {
@ -117,6 +121,10 @@ export var DirectiveLiteral = {
}
};
/**
* [Please add a description.]
*/
export var Directive = {
types: ["ExpressionStatement"],
checkPath(path) {
@ -124,14 +132,39 @@ export var Directive = {
}
};
/**
* [Please add a description.]
*/
export var User = {
checkPath(path) {
return path.node && !!path.node.loc;
}
};
/**
* [Please add a description.]
*/
export var Generated = {
checkPath(path) {
return !path.isUser();
}
};
/**
* [Please add a description.]
*/
export var Flow = {
types: ["Flow", "ImportDeclaration"],
checkPath({ node }) {
if (t.isFlow(node)) {
return true;
} else if (t.isImportDeclaration(node)) {
return node.importKind === "type" || node.importKind === "typeof";
} else {
return false;
}
}
};

View File

@ -40,7 +40,7 @@ export function explode(visitor) {
ensureCallbackArrays(visitor);
// add type wrappers
for (let nodeType in visitor) {
for (let nodeType of (Object.keys(visitor): Array)) {
if (shouldIgnoreKey(nodeType)) continue;
var wrapper = virtualTypes[nodeType];