Babel
  • Docs
  • Setup
  • Try it out
  • Videos
  • Blog
  • Donate
  • Team
  • GitHub
Edit

@babel/helper-annotate-as-pure

declare export default annotateAsPure(nodeOrPath: Node | NodePath);

Usage

import traverse from "@babel/traverse";
import annotateAsPure from "@babel/helper-annotate-as-pure";

// ...

traverse(file, {
  CallExpression(path) {
    annotateAsPure(path);
  },
});

Caveat with UglifyJS pre v3.1.0

@babel/helper-annotate-as-pure will append any existing leading comments to the #__PURE__ annotation. Versions of UglifyJS prior to v3.1.0 will ignore these annotations, as they only check the last leading comment for the annotation.

For example, using the Usage snippet above:

In

const four = /* foo */ add(2, 2);

Out

const four = /* #__PURE__ */ /* foo */ add(2, 2);
  • Usage
  • Caveat with UglifyJS pre v3.1.0
Babel
Docs
Learn ES2015
Community
VideosUser ShowcaseStack OverflowSlack ChannelTwitter
More
BlogGitHub OrgGitHub RepoWebsite RepoOld 6.x SiteOld 5.x Site