UNPKG

544 BJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = annotateAsPure;
7
8var _t = require("@babel/types");
9
10const {
11 addComment
12} = _t;
13const PURE_ANNOTATION = "#__PURE__";
14
15const isPureAnnotated = ({
16 leadingComments
17}) => !!leadingComments && leadingComments.some(comment => /[@#]__PURE__/.test(comment.value));
18
19function annotateAsPure(pathOrNode) {
20 const node = pathOrNode["node"] || pathOrNode;
21
22 if (isPureAnnotated(node)) {
23 return;
24 }
25
26 addComment(node, "leading", PURE_ANNOTATION);
27}
\No newline at end of file