utils.js 845 B

12345678910111213141516171819202122232425262728293031
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.getImportSource = getImportSource;
  6. exports.getRequireSource = getRequireSource;
  7. exports.isPolyfillSource = isPolyfillSource;
  8. var t = require("@babel/types");
  9. function getImportSource({
  10. node
  11. }) {
  12. if (node.specifiers.length === 0) return node.source.value;
  13. }
  14. function getRequireSource({
  15. node
  16. }) {
  17. if (!t.isExpressionStatement(node)) return;
  18. const {
  19. expression
  20. } = node;
  21. const isRequire = t.isCallExpression(expression) && t.isIdentifier(expression.callee) && expression.callee.name === "require" && expression.arguments.length === 1 && t.isStringLiteral(expression.arguments[0]);
  22. if (isRequire) return expression.arguments[0].value;
  23. }
  24. function isPolyfillSource(source) {
  25. return source === "@babel/polyfill" || source === "core-js";
  26. }