utils.js 914 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. const {
  10. isCallExpression,
  11. isExpressionStatement,
  12. isIdentifier,
  13. isStringLiteral
  14. } = _t;
  15. function getImportSource({
  16. node
  17. }) {
  18. if (node.specifiers.length === 0) return node.source.value;
  19. }
  20. function getRequireSource({
  21. node
  22. }) {
  23. if (!isExpressionStatement(node)) return;
  24. const {
  25. expression
  26. } = node;
  27. if (isCallExpression(expression) && isIdentifier(expression.callee) && expression.callee.name === "require" && expression.arguments.length === 1 && isStringLiteral(expression.arguments[0])) {
  28. return expression.arguments[0].value;
  29. }
  30. }
  31. function isPolyfillSource(source) {
  32. return source === "@babel/polyfill" || source === "core-js";
  33. }