Huáng Jùnliàng 7000ae04a5
refactor: move @babel/helper-annotate-as-pure to ts (#12415)
* refactor: move @babel/helper-annotate-as-pure to ts

* chore: add flow types
2020-12-01 11:23:23 -05:00

19 lines
510 B
TypeScript

import * as t from "@babel/types";
import type { Node } from "@babel/types";
const PURE_ANNOTATION = "#__PURE__";
const isPureAnnotated = ({ leadingComments }: Node): boolean =>
!!leadingComments &&
leadingComments.some(comment => /[@#]__PURE__/.test(comment.value));
export default function annotateAsPure(
pathOrNode: Node | { node: Node },
): void {
const node = pathOrNode["node"] || pathOrNode;
if (isPureAnnotated(node)) {
return;
}
t.addComment(node, "leading", PURE_ANNOTATION);
}