add Generated/User/Directive virtual node types

This commit is contained in:
Sebastian McKenzie 2015-07-08 11:35:56 +01:00
parent af7510adec
commit 421b01865f
2 changed files with 26 additions and 28 deletions

View File

@ -147,18 +147,6 @@ export function isCompletionRecord(allowInsideFunction?) {
return true;
}
/**
* Check if the current node is a directive.
*/
export function isDirective() {
if (this.isExpressionStatement()) {
return this.get("expression").isLiteral();
} else {
return this.isLiteral() && this.parentPath.isExpressionStatement();
}
}
/**
* Check whether or not the current `key` allows either a single statement or block statement
* so we can explode it if necessary.
@ -172,22 +160,6 @@ export function isStatementOrBlock() {
}
}
/**
* Check whether this node was a part of the original AST.
*/
export function isUser() {
return this.node && !!this.node.loc;
}
/**
* Check whether this node was generated by us and not a part of the original AST.
*/
export function isGenerated() {
return !this.isUser();
}
/**
* Check if the currently assigned path references the `importName` of `moduleSource`.
*/

View File

@ -77,3 +77,29 @@ export var Var = {
return t.isVar(path.node);
}
};
export var DirectiveLiteral = {
types: ["Literal"],
checkPath(path) {
return path.isLiteral() && path.parentPath.isExpressionStatement();
}
};
export var Directive = {
types: ["ExpressionStatement"],
checkPath(path) {
return path.get("expression").isLiteral();
}
};
export var User = {
checkPath(path) {
return path.node && !!path.node.loc;
}
};
export var Generated = {
checkPath(path) {
return !path.isUser();
}
};