Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. function _helperPluginUtils() {
  7. const data = require("@babel/helper-plugin-utils");
  8. _helperPluginUtils = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. function _path() {
  14. const data = _interopRequireDefault(require("path"));
  15. _path = function () {
  16. return data;
  17. };
  18. return data;
  19. }
  20. function _core() {
  21. const data = require("@babel/core");
  22. _core = function () {
  23. return data;
  24. };
  25. return data;
  26. }
  27. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  28. var _default = (0, _helperPluginUtils().declare)(api => {
  29. api.assertVersion(7);
  30. function addDisplayName(id, call) {
  31. const props = call.arguments[0].properties;
  32. let safe = true;
  33. for (let i = 0; i < props.length; i++) {
  34. const prop = props[i];
  35. const key = _core().types.toComputedKey(prop);
  36. if (_core().types.isLiteral(key, {
  37. value: "displayName"
  38. })) {
  39. safe = false;
  40. break;
  41. }
  42. }
  43. if (safe) {
  44. props.unshift(_core().types.objectProperty(_core().types.identifier("displayName"), _core().types.stringLiteral(id)));
  45. }
  46. }
  47. const isCreateClassCallExpression = _core().types.buildMatchMemberExpression("React.createClass");
  48. const isCreateClassAddon = callee => callee.name === "createReactClass";
  49. function isCreateClass(node) {
  50. if (!node || !_core().types.isCallExpression(node)) return false;
  51. if (!isCreateClassCallExpression(node.callee) && !isCreateClassAddon(node.callee)) {
  52. return false;
  53. }
  54. const args = node.arguments;
  55. if (args.length !== 1) return false;
  56. const first = args[0];
  57. if (!_core().types.isObjectExpression(first)) return false;
  58. return true;
  59. }
  60. return {
  61. name: "transform-react-display-name",
  62. visitor: {
  63. ExportDefaultDeclaration({
  64. node
  65. }, state) {
  66. if (isCreateClass(node.declaration)) {
  67. const filename = state.filename || "unknown";
  68. let displayName = _path().default.basename(filename, _path().default.extname(filename));
  69. if (displayName === "index") {
  70. displayName = _path().default.basename(_path().default.dirname(filename));
  71. }
  72. addDisplayName(displayName, node.declaration);
  73. }
  74. },
  75. CallExpression(path) {
  76. const {
  77. node
  78. } = path;
  79. if (!isCreateClass(node)) return;
  80. let id;
  81. path.find(function (path) {
  82. if (path.isAssignmentExpression()) {
  83. id = path.node.left;
  84. } else if (path.isObjectProperty()) {
  85. id = path.node.key;
  86. } else if (path.isVariableDeclarator()) {
  87. id = path.node.id;
  88. } else if (path.isStatement()) {
  89. return true;
  90. }
  91. if (id) return true;
  92. });
  93. if (!id) return;
  94. if (_core().types.isMemberExpression(id)) {
  95. id = id.property;
  96. }
  97. if (_core().types.isIdentifier(id)) {
  98. addDisplayName(id.name, node);
  99. }
  100. }
  101. }
  102. };
  103. });
  104. exports.default = _default;