@babel/helper-annotate-as-pure
JavaScript
declare export default annotateAsPure(nodeOrPath: Node | NodePath);
用法
🌐 Usage
JavaScript
import traverse from "@babel/traverse";
import annotateAsPure from "@babel/helper-annotate-as-pure";
// ...
traverse(file, {
CallExpression(path) {
annotateAsPure(path);
},
});
使用 UglifyJS 3.1.0 之前的版本需要注意
🌐 Caveat with UglifyJS pre v3.1.0
@babel/helper-annotate-as-pure 会把已有的前置注释附加到 #__PURE__ 注解上。v3.1.0 之前的 UglifyJS 版本会 忽略 这些注解,因为它们只检查最后一个前置注释中的注解。
例如,使用上面的 Usage 代码片段:
🌐 For example, using the Usage snippet above:
在
JavaScript
const four = /* foo */ add(2, 2);
出
JavaScript
const four = /* #__PURE__ */ /* foo */ add(2, 2);