Tweak and add tests to babel-helper-annotate-as-pure (#7245)
This commit is contained in:
parent
064c17e03f
commit
5ce54799ff
@ -2,13 +2,9 @@ import * as t from "@babel/types";
|
||||
|
||||
const PURE_ANNOTATION = "#__PURE__";
|
||||
|
||||
const isPureAnnotated = node => {
|
||||
const { leadingComments } = node;
|
||||
if (leadingComments === undefined) {
|
||||
return false;
|
||||
}
|
||||
return leadingComments.some(comment => /[@#]__PURE__/.test(comment.value));
|
||||
};
|
||||
const isPureAnnotated = ({ leadingComments }) =>
|
||||
leadingComments &&
|
||||
leadingComments.some(comment => /[@#]__PURE__/.test(comment.value));
|
||||
|
||||
export default function annotateAsPure(pathOrNode) {
|
||||
const node = pathOrNode.node || pathOrNode;
|
||||
|
||||
36
packages/babel-helper-annotate-as-pure/test/index.js
Normal file
36
packages/babel-helper-annotate-as-pure/test/index.js
Normal file
@ -0,0 +1,36 @@
|
||||
import annotateAsPure from "../";
|
||||
import assert from "assert";
|
||||
|
||||
describe("@babel/helper-annotate-as-pure", () => {
|
||||
it("will add leading comment", () => {
|
||||
const node = {};
|
||||
annotateAsPure(node);
|
||||
|
||||
assert.deepEqual(node.leadingComments, [
|
||||
{
|
||||
type: "CommentBlock",
|
||||
value: "#__PURE__",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("will not add an extra leading comment", () => {
|
||||
const node = {
|
||||
leadingComments: [
|
||||
{
|
||||
type: "CommentBlock",
|
||||
value: "#__PURE__",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
annotateAsPure(node);
|
||||
|
||||
assert.deepEqual(node.leadingComments, [
|
||||
{
|
||||
type: "CommentBlock",
|
||||
value: "#__PURE__",
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user