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
|
node: BabelNodeFunction
|
||||||
): number;
|
): 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 * as t from "@babel/types";
|
||||||
|
import type { Node } from "@babel/types";
|
||||||
|
|
||||||
const PURE_ANNOTATION = "#__PURE__";
|
const PURE_ANNOTATION = "#__PURE__";
|
||||||
|
|
||||||
const isPureAnnotated = ({ leadingComments }) =>
|
const isPureAnnotated = ({ leadingComments }: Node): boolean =>
|
||||||
!!leadingComments &&
|
!!leadingComments &&
|
||||||
leadingComments.some(comment => /[@#]__PURE__/.test(comment.value));
|
leadingComments.some(comment => /[@#]__PURE__/.test(comment.value));
|
||||||
|
|
||||||
export default function annotateAsPure(pathOrNode) {
|
export default function annotateAsPure(
|
||||||
const node = pathOrNode.node || pathOrNode;
|
pathOrNode: Node | { node: Node },
|
||||||
|
): void {
|
||||||
|
const node = pathOrNode["node"] || pathOrNode;
|
||||||
if (isPureAnnotated(node)) {
|
if (isPureAnnotated(node)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user