index.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = annotateAsPure;
  6. function t() {
  7. const data = _interopRequireWildcard(require("@babel/types"));
  8. t = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
  14. const PURE_ANNOTATION = "#__PURE__";
  15. const isPureAnnotated = ({
  16. leadingComments
  17. }) => !!leadingComments && leadingComments.some(comment => /[@#]__PURE__/.test(comment.value));
  18. function annotateAsPure(pathOrNode) {
  19. const node = pathOrNode.node || pathOrNode;
  20. if (isPureAnnotated(node)) {
  21. return;
  22. }
  23. t().addComment(node, "leading", PURE_ANNOTATION);
  24. }