Extract isBabelPluginFactory helper
This commit is contained in:
parent
2be54111c0
commit
c59db52954
@ -0,0 +1,26 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const getReferenceOrigin = require("./get-reference-origin");
|
||||||
|
const getExportName = require("./get-export-name");
|
||||||
|
|
||||||
|
module.exports = function isBabelPluginFactory(node, scope) {
|
||||||
|
const { parent } = node;
|
||||||
|
|
||||||
|
if (parent.type === "CallExpression") {
|
||||||
|
const calleeOrigin = getReferenceOrigin(parent.callee, scope);
|
||||||
|
|
||||||
|
// Using "declare" from "@babel/helper-plugin-utils"
|
||||||
|
return !!(
|
||||||
|
calleeOrigin &&
|
||||||
|
calleeOrigin.kind === "import" &&
|
||||||
|
calleeOrigin.name === "declare" &&
|
||||||
|
calleeOrigin.source === "@babel/helper-plugin-utils"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const exportName = getExportName(node);
|
||||||
|
|
||||||
|
// export default function ({ types: t }) {}
|
||||||
|
// module.exports = function ({ types: t }) {}
|
||||||
|
return exportName === "default" || exportName === "module.exports";
|
||||||
|
};
|
||||||
@ -1,7 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const getReferenceOrigin = require("./get-reference-origin");
|
const isBabelPluginFactory = require("./is-babel-plugin-factory");
|
||||||
const getExportName = require("./get-export-name");
|
|
||||||
|
|
||||||
// Check if a ReferenceOrigin (returned by ./get-reference-origin.js)
|
// Check if a ReferenceOrigin (returned by ./get-reference-origin.js)
|
||||||
// is a reference to a @babel/types export.
|
// is a reference to a @babel/types export.
|
||||||
@ -25,32 +24,12 @@ module.exports = function isFromBabelTypes(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
origin.kind !== "property" ||
|
origin.kind === "property" &&
|
||||||
origin.base.kind !== "param" ||
|
origin.base.kind === "param" &&
|
||||||
origin.base.index !== 0
|
origin.base.index === 0
|
||||||
) {
|
) {
|
||||||
// Not a parameter of the plugin factory function
|
return isBabelPluginFactory(origin.base.functionNode, scope);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const { functionNode } = origin.base;
|
return false;
|
||||||
const { parent } = functionNode;
|
|
||||||
|
|
||||||
if (parent.type === "CallExpression") {
|
|
||||||
const calleeOrigin = getReferenceOrigin(parent.callee, scope);
|
|
||||||
|
|
||||||
// Using "declare" from "@babel/helper-plugin-utils"
|
|
||||||
return !!(
|
|
||||||
calleeOrigin &&
|
|
||||||
calleeOrigin.kind === "import" &&
|
|
||||||
calleeOrigin.name === "declare" &&
|
|
||||||
calleeOrigin.source === "@babel/helper-plugin-utils"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const exportName = getExportName(functionNode);
|
|
||||||
|
|
||||||
// export default function ({ types: t }) {}
|
|
||||||
// module.exports = function ({ types: t }) {}
|
|
||||||
return exportName === "default" || exportName === "module.exports";
|
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user