babel-plugin-idx
Advanced tools
Comparing version
@@ -117,15 +117,25 @@ /** | ||
var idxVisitor = { | ||
CallExpression: function CallExpression(path) { | ||
var node = path.node; | ||
if (isIdxCall(node)) { | ||
checkIdxArguments(node.arguments); | ||
var ternary = constructTernary(node.arguments[0], node.arguments[1].body, path.scope.generateUidIdentifier.bind(path.scope)); | ||
path.replaceWith(ternary.expression); | ||
for (var ii = 0; ii < ternary.uids.length; ii++) { | ||
var uid = ternary.uids[ii]; | ||
path.scope.push({ id: t.Identifier(uid) }); | ||
} | ||
} | ||
} | ||
}; | ||
return { | ||
visitor: { | ||
CallExpression: function CallExpression(path) { | ||
var node = path.node; | ||
if (isIdxCall(node)) { | ||
checkIdxArguments(node.arguments); | ||
var ternary = constructTernary(node.arguments[0], node.arguments[1].body, path.scope.generateUidIdentifier.bind(path.scope)); | ||
path.replaceWith(ternary.expression); | ||
for (var ii = 0; ii < ternary.uids.length; ii++) { | ||
var uid = ternary.uids[ii]; | ||
path.scope.push({ id: t.Identifier(uid) }); | ||
} | ||
} | ||
Program: function Program(path) { | ||
// We're very strict about the shape of idx. Some transforms, like | ||
// "babel-plugin-transform-async-to-generator", will convert arrow | ||
// functions inside async functions into regular functions. So we do | ||
// our transformation before any one else interferes. | ||
path.traverse(idxVisitor); | ||
} | ||
@@ -132,0 +142,0 @@ } |
{ | ||
"name": "babel-plugin-idx", | ||
"version": "1.1.0", | ||
"version": "1.3.0", | ||
"description": "Babel plugin for transforming the idx utility function.", | ||
@@ -20,2 +20,3 @@ "main": "lib/babel-plugin-idx.js", | ||
"babel-jest": "^19.0.0", | ||
"babel-plugin-transform-async-to-generator": "^6.22.0", | ||
"babel-plugin-transform-flow-strip-types": "^6.22.0", | ||
@@ -22,0 +23,0 @@ "babel-preset-env": "^1.1.11", |
8019
5.74%128
7.56%6
20%