JSPM

  • Created
  • Published
  • Downloads 44276226
  • Score
    100M100P100Q266570F
  • License MIT

Helper function to annotate paths and nodes with #__PURE__ comment

Package Exports

  • @babel/helper-annotate-as-pure

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@babel/helper-annotate-as-pure) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@babel/helper-annotate-as-pure

API

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);