index.js 516 B

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