diff options
| author | ruki <waruqi@gmail.com> | 2018-11-08 00:38:48 +0800 |
|---|---|---|
| committer | ruki <waruqi@gmail.com> | 2018-11-07 21:53:09 +0800 |
| commit | 26105034da4fcce7ac883c899d781f016559310d (patch) | |
| tree | c459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/@babel/helper-annotate-as-pure | |
| parent | 2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff) | |
| download | xmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip | |
switch to vuepress
Diffstat (limited to 'node_modules/@babel/helper-annotate-as-pure')
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" + } +} |
