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.
27 lines
544 B
27 lines
544 B
3 years ago
|
"use strict";
|
||
|
|
||
|
Object.defineProperty(exports, "__esModule", {
|
||
|
value: true
|
||
|
});
|
||
|
exports.default = annotateAsPure;
|
||
|
|
||
|
var _t = require("@babel/types");
|
||
|
|
||
|
const {
|
||
|
addComment
|
||
|
} = _t;
|
||
|
const PURE_ANNOTATION = "#__PURE__";
|
||
|
|
||
|
const isPureAnnotated = ({
|
||
|
leadingComments
|
||
|
}) => !!leadingComments && leadingComments.some(comment => /[@#]__PURE__/.test(comment.value));
|
||
|
|
||
|
function annotateAsPure(pathOrNode) {
|
||
|
const node = pathOrNode["node"] || pathOrNode;
|
||
|
|
||
|
if (isPureAnnotated(node)) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
addComment(node, "leading", PURE_ANNOTATION);
|
||
|
}
|