aboutsummaryrefslogtreecommitdiff
path: root/node_modules/@babel/helper-annotate-as-pure
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/@babel/helper-annotate-as-pure')
-rw-r--r--node_modules/@babel/helper-annotate-as-pure/README.md40
-rw-r--r--node_modules/@babel/helper-annotate-as-pure/lib/index.js34
-rw-r--r--node_modules/@babel/helper-annotate-as-pure/package.json11
3 files changed, 85 insertions, 0 deletions
diff --git a/node_modules/@babel/helper-annotate-as-pure/README.md b/node_modules/@babel/helper-annotate-as-pure/README.md
new file mode 100644
index 00000000..2e8d9642
--- /dev/null
+++ b/node_modules/@babel/helper-annotate-as-pure/README.md
@@ -0,0 +1,40 @@
+# @babel/helper-annotate-as-pure
+
+## API
+
+```js
+declare export default annotateAsPure(nodeOrPath: Node | NodePath);
+```
+
+## Usage
+
+```js
+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**
+
+```js
+const four = /* foo */ add(2, 2);
+```
+
+**Out**
+
+```js
+const four = /* #__PURE__ */ /* foo */ add(2, 2);
+```
diff --git a/node_modules/@babel/helper-annotate-as-pure/lib/index.js b/node_modules/@babel/helper-annotate-as-pure/lib/index.js
new file mode 100644
index 00000000..2251317b
--- /dev/null
+++ b/node_modules/@babel/helper-annotate-as-pure/lib/index.js
@@ -0,0 +1,34 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.default = annotateAsPure;
+
+function t() {
+ const data = _interopRequireWildcard(require("@babel/types"));
+
+ t = function t() {
+ return data;
+ };
+
+ return data;
+}
+
+function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
+
+const PURE_ANNOTATION = "#__PURE__";
+
+const isPureAnnotated = ({
+ leadingComments
+}) => !!leadingComments && leadingComments.some(comment => /[@#]__PURE__/.test(comment.value));
+
+function annotateAsPure(pathOrNode) {
+ const node = pathOrNode.node || pathOrNode;
+
+ if (isPureAnnotated(node)) {
+ return;
+ }
+
+ t().addComment(node, "leading", PURE_ANNOTATION);
+} \ No newline at end of file
diff --git a/node_modules/@babel/helper-annotate-as-pure/package.json b/node_modules/@babel/helper-annotate-as-pure/package.json
new file mode 100644
index 00000000..47956e35
--- /dev/null
+++ b/node_modules/@babel/helper-annotate-as-pure/package.json
@@ -0,0 +1,11 @@
+{
+ "name": "@babel/helper-annotate-as-pure",
+ "version": "7.0.0-beta.47",
+ "description": "Helper function to annotate paths and nodes with #__PURE__ comment",
+ "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-annotate-as-pure",
+ "license": "MIT",
+ "main": "lib/index.js",
+ "dependencies": {
+ "@babel/types": "7.0.0-beta.47"
+ }
+}