index.js 544 B

123456789101112131415161718192021222324252627
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = annotateAsPure;
  6. var _t = require("@babel/types");
  7. const {
  8. addComment
  9. } = _t;
  10. const PURE_ANNOTATION = "#__PURE__";
  11. const isPureAnnotated = ({
  12. leadingComments
  13. }) => !!leadingComments && leadingComments.some(comment => /[@#]__PURE__/.test(comment.value));
  14. function annotateAsPure(pathOrNode) {
  15. const node = pathOrNode["node"] || pathOrNode;
  16. if (isPureAnnotated(node)) {
  17. return;
  18. }
  19. addComment(node, "leading", PURE_ANNOTATION);
  20. }