From 421b01865faa8d2c0db842bdc5d4ea32ca2bd2c4 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Wed, 8 Jul 2015 11:35:56 +0100 Subject: [PATCH] add Generated/User/Directive virtual node types --- src/babel/traversal/path/introspection.js | 28 ------------------- src/babel/traversal/path/lib/virtual-types.js | 26 +++++++++++++++++ 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/babel/traversal/path/introspection.js b/src/babel/traversal/path/introspection.js index b1139444fb..b843e32564 100644 --- a/src/babel/traversal/path/introspection.js +++ b/src/babel/traversal/path/introspection.js @@ -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`. */ diff --git a/src/babel/traversal/path/lib/virtual-types.js b/src/babel/traversal/path/lib/virtual-types.js index 35ab29e4a9..4a0a9456e0 100644 --- a/src/babel/traversal/path/lib/virtual-types.js +++ b/src/babel/traversal/path/lib/virtual-types.js @@ -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(); + } +};