From b5b6bf4ad5fce497ddd6f7fceff31c53f77ea116 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sat, 13 Jun 2015 02:21:22 +0100 Subject: [PATCH] add isDirective method, --- src/babel/traversal/path/introspection.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/babel/traversal/path/introspection.js b/src/babel/traversal/path/introspection.js index 2ded47c9d9..173bded39c 100644 --- a/src/babel/traversal/path/introspection.js +++ b/src/babel/traversal/path/introspection.js @@ -146,6 +146,18 @@ export function isCompletionRecord(allowInsideFunction?) { return true; } +/** + * Description + */ + +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. @@ -229,7 +241,7 @@ export function getSource() { * Description */ -export function willIMaybeExecutesBefore(target) { +export function willIMaybeExecuteBefore(target) { return this._guessExecutionStatusRelativeTo(target) !== "after"; } @@ -249,6 +261,8 @@ export function _guessExecutionStatusRelativeTo(target) { } var targetPaths = getAncestry(target); + //if (targetPaths.indexOf(this) >= 0) return "after"; + var selfPaths = getAncestry(this); // get ancestor where the branches intersect @@ -281,7 +295,7 @@ export function _guessExecutionStatusRelativeTo(target) { // otherwise we're associated by a parent node, check which key comes before the other var targetKeyPosition = t.VISITOR_KEYS[targetRelationship.type].indexOf(targetRelationship.key); - var selfKeyPosition = t.VISITOR_KEYS[selfRelationship.type].indexOf(selfRelationship.key); + var selfKeyPosition = t.VISITOR_KEYS[selfRelationship.type].indexOf(selfRelationship.key); return targetKeyPosition > selfKeyPosition ? "before" : "after"; }