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 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 _core() {
  14. const data = require("@babel/core");
  15. _core = function () {
  16. return data;
  17. };
  18. return data;
  19. }
  20. const TRACE_ID = "__source";
  21. const FILE_NAME_VAR = "_jsxFileName";
  22. var _default = (0, _helperPluginUtils().declare)(api => {
  23. api.assertVersion(7);
  24. function makeTrace(fileNameIdentifier, lineNumber) {
  25. const fileLineLiteral = lineNumber != null ? _core().types.numericLiteral(lineNumber) : _core().types.nullLiteral();
  26. const fileNameProperty = _core().types.objectProperty(_core().types.identifier("fileName"), fileNameIdentifier);
  27. const lineNumberProperty = _core().types.objectProperty(_core().types.identifier("lineNumber"), fileLineLiteral);
  28. return _core().types.objectExpression([fileNameProperty, lineNumberProperty]);
  29. }
  30. const visitor = {
  31. JSXOpeningElement(path, state) {
  32. const id = _core().types.jsxIdentifier(TRACE_ID);
  33. const location = path.container.openingElement.loc;
  34. if (!location) {
  35. return;
  36. }
  37. const attributes = path.container.openingElement.attributes;
  38. for (let i = 0; i < attributes.length; i++) {
  39. const name = attributes[i].name;
  40. if (name && name.name === TRACE_ID) {
  41. return;
  42. }
  43. }
  44. if (!state.fileNameIdentifier) {
  45. const fileName = state.filename || "";
  46. const fileNameIdentifier = path.scope.generateUidIdentifier(FILE_NAME_VAR);
  47. const scope = path.hub.getScope();
  48. if (scope) {
  49. scope.push({
  50. id: fileNameIdentifier,
  51. init: _core().types.stringLiteral(fileName)
  52. });
  53. }
  54. state.fileNameIdentifier = fileNameIdentifier;
  55. }
  56. const trace = makeTrace(state.fileNameIdentifier, location.start.line);
  57. attributes.push(_core().types.jsxAttribute(id, _core().types.jsxExpressionContainer(trace)));
  58. }
  59. };
  60. return {
  61. name: "transform-react-jsx-source",
  62. visitor
  63. };
  64. });
  65. exports.default = _default;