-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(babel-plugin-espower): eliminate babel-core dependency
- Loading branch information
Showing
5 changed files
with
33 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,29 @@ | ||
'use strict'; | ||
|
||
var types = require('babel-core').types; | ||
module.exports = function (babel) { | ||
var types = babel.types; | ||
|
||
function traverseUp (ancestors, traversalPath) { | ||
ancestors.push(traversalPath.key); | ||
if (Array.isArray(traversalPath.container)) { // traversing array via TraversalContext#visitMultiple | ||
var parentNode = traversalPath.parent; | ||
var candidateKeys = types.VISITOR_KEYS[parentNode.type].filter(function (key) { | ||
return parentNode[key] === traversalPath.container; // searching for current key in parentNode | ||
}); | ||
if (candidateKeys.length === 1) { | ||
var currentTraversingKey = candidateKeys[0]; // ex. 'arguments' in CallExpression | ||
ancestors.push(currentTraversingKey); | ||
function traverseUp (ancestors, traversalPath) { | ||
ancestors.push(traversalPath.key); | ||
if (Array.isArray(traversalPath.container)) { // traversing array via TraversalContext#visitMultiple | ||
var parentNode = traversalPath.parent; | ||
var candidateKeys = types.VISITOR_KEYS[parentNode.type].filter(function (key) { | ||
return parentNode[key] === traversalPath.container; // searching for current key in parentNode | ||
}); | ||
if (candidateKeys.length === 1) { | ||
var currentTraversingKey = candidateKeys[0]; // ex. 'arguments' in CallExpression | ||
ancestors.push(currentTraversingKey); | ||
} | ||
} | ||
if (traversalPath.parentPath) { | ||
traverseUp(ancestors, traversalPath.parentPath); | ||
} | ||
} | ||
if (traversalPath.parentPath) { | ||
traverseUp(ancestors, traversalPath.parentPath); | ||
} | ||
} | ||
|
||
module.exports = function estreePath (traversalPath) { | ||
var ancestors = []; | ||
traverseUp(ancestors, traversalPath); | ||
ancestors.reverse(); | ||
return ancestors; | ||
return function estreePath (traversalPath) { | ||
var ancestors = []; | ||
traverseUp(ancestors, traversalPath); | ||
ancestors.reverse(); | ||
return ancestors; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters