Skip to content

Commit

Permalink
refactor: move @babel/helper-annotate-as-pure to ts (babel#12415)
Browse files Browse the repository at this point in the history
* refactor: move @babel/helper-annotate-as-pure to ts

* chore: add flow types
  • Loading branch information
JLHwung authored and nicolo-ribaudo committed Dec 2, 2020
1 parent c13853b commit 130c103
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 10 additions & 0 deletions lib/babel-packages.js.flow
Expand Up @@ -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;
}
Expand Down

0 comments on commit 130c103

Please sign in to comment.