refactor: move @babel/helper-annotate-as-pure to ts (#12415)
* refactor: move @babel/helper-annotate-as-pure to ts * chore: add flow types
This commit is contained in:
parent
5e4b85ab1c
commit
7000ae04a5
@ -49,3 +49,13 @@ declare module "@babel/helper-get-function-arity" {
|
||||
node: BabelNodeFunction
|
||||
): number;
|
||||
}
|
||||
|
||||
declare module "@babel/helper-annotate-as-pure" {
|
||||
declare export default function annotateAsPure(
|
||||
pathOrNode:
|
||||
| BabelNode
|
||||
| {
|
||||
node: BabelNode,
|
||||
}
|
||||
): void;
|
||||
}
|
||||
|
||||
@ -1,13 +1,16 @@
|
||||
import * as t from "@babel/types";
|
||||
import type { Node } from "@babel/types";
|
||||
|
||||
const PURE_ANNOTATION = "#__PURE__";
|
||||
|
||||
const isPureAnnotated = ({ leadingComments }) =>
|
||||
const isPureAnnotated = ({ leadingComments }: Node): boolean =>
|
||||
!!leadingComments &&
|
||||
leadingComments.some(comment => /[@#]__PURE__/.test(comment.value));
|
||||
|
||||
export default function annotateAsPure(pathOrNode) {
|
||||
const node = pathOrNode.node || pathOrNode;
|
||||
export default function annotateAsPure(
|
||||
pathOrNode: Node | { node: Node },
|
||||
): void {
|
||||
const node = pathOrNode["node"] || pathOrNode;
|
||||
if (isPureAnnotated(node)) {
|
||||
return;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user