add Flow virtual type
This commit is contained in:
parent
512707c7de
commit
b97dc4778b
@ -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);
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -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];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user