aboutsummaryrefslogtreecommitdiff
path: root/node_modules/@babel/plugin-proposal-function-sent
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/@babel/plugin-proposal-function-sent')
-rw-r--r--node_modules/@babel/plugin-proposal-function-sent/README.md66
-rw-r--r--node_modules/@babel/plugin-proposal-function-sent/lib/index.js104
-rw-r--r--node_modules/@babel/plugin-proposal-function-sent/package.json23
3 files changed, 193 insertions, 0 deletions
diff --git a/node_modules/@babel/plugin-proposal-function-sent/README.md b/node_modules/@babel/plugin-proposal-function-sent/README.md
new file mode 100644
index 00000000..9c498491
--- /dev/null
+++ b/node_modules/@babel/plugin-proposal-function-sent/README.md
@@ -0,0 +1,66 @@
+# @babel/plugin-proposal-function-sent
+
+> Compile the `function.sent` meta property, used inside generator functions, to valid ES2015 code.
+
+## Example
+
+```js
+function* generator() {
+ console.log("Sent", function.sent);
+ console.log("Yield", yield);
+}
+
+const iterator = generator();
+iterator.next(1); // Logs "Sent 1"
+iterator.next(2); // Logs "Yield 2"
+```
+
+Is compiled roughly to
+
+```js
+let generator = _skipFirstGeneratorNext(function* () {
+ const _functionSent = yield;
+ console.log("Sent", _functionSent);
+ console.log("Yield", yield);
+});
+
+const iterator = generator();
+iterator.next(1); // Logs "Sent 1"
+iterator.next(2); // Logs "Yield 1"
+```
+
+## Installation
+
+```sh
+npm install --save-dev @babel/plugin-proposal-function-sent
+```
+
+## Usage
+
+### Via `.babelrc` (Recommended)
+
+**.babelrc**
+
+```json
+{
+ "plugins": ["@babel/plugin-proposal-function-sent"]
+}
+```
+
+### Via CLI
+
+```sh
+babel --plugins @babel/plugin-proposal-function-sent script.js
+```
+
+### Via Node API
+
+```javascript
+require("@babel/core").transform("code", {
+ plugins: ["@babel/plugin-proposal-function-sent"]
+});
+```
+
+## References
+
+* [Proposal](https://github.com/allenwb/ESideas/blob/master/Generator%20metaproperty.md)
diff --git a/node_modules/@babel/plugin-proposal-function-sent/lib/index.js b/node_modules/@babel/plugin-proposal-function-sent/lib/index.js
new file mode 100644
index 00000000..d42d5d7f
--- /dev/null
+++ b/node_modules/@babel/plugin-proposal-function-sent/lib/index.js
@@ -0,0 +1,104 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.default = void 0;
+
+function _helperPluginUtils() {
+ const data = require("@babel/helper-plugin-utils");
+
+ _helperPluginUtils = function _helperPluginUtils() {
+ return data;
+ };
+
+ return data;
+}
+
+function _pluginSyntaxFunctionSent() {
+ const data = _interopRequireDefault(require("@babel/plugin-syntax-function-sent"));
+
+ _pluginSyntaxFunctionSent = function _pluginSyntaxFunctionSent() {
+ return data;
+ };
+
+ return data;
+}
+
+function _helperWrapFunction() {
+ const data = _interopRequireDefault(require("@babel/helper-wrap-function"));
+
+ _helperWrapFunction = function _helperWrapFunction() {
+ return data;
+ };
+
+ return data;
+}
+
+function _core() {
+ const data = require("@babel/core");
+
+ _core = function _core() {
+ return data;
+ };
+
+ return data;
+}
+
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+
+var _default = (0, _helperPluginUtils().declare)(api => {
+ api.assertVersion(7);
+
+ const isFunctionSent = node => _core().types.isIdentifier(node.meta, {
+ name: "function"
+ }) && _core().types.isIdentifier(node.property, {
+ name: "sent"
+ });
+
+ const hasBeenReplaced = (node, sentId) => _core().types.isAssignmentExpression(node) && _core().types.isIdentifier(node.left, {
+ name: sentId
+ });
+
+ const yieldVisitor = {
+ Function(path) {
+ path.skip();
+ },
+
+ YieldExpression(path) {
+ if (!hasBeenReplaced(path.parent, this.sentId)) {
+ path.replaceWith(_core().types.assignmentExpression("=", _core().types.identifier(this.sentId), path.node));
+ }
+ },
+
+ MetaProperty(path) {
+ if (isFunctionSent(path.node)) {
+ path.replaceWith(_core().types.identifier(this.sentId));
+ }
+ }
+
+ };
+ return {
+ inherits: _pluginSyntaxFunctionSent().default,
+ visitor: {
+ MetaProperty(path, state) {
+ if (!isFunctionSent(path.node)) return;
+ const fnPath = path.getFunctionParent();
+
+ if (!fnPath.node.generator) {
+ throw new Error("Parent generator function not found");
+ }
+
+ const sentId = path.scope.generateUid("function.sent");
+ fnPath.traverse(yieldVisitor, {
+ sentId
+ });
+ fnPath.node.body.body.unshift(_core().types.variableDeclaration("let", [_core().types.variableDeclarator(_core().types.identifier(sentId), _core().types.yieldExpression())]));
+ (0, _helperWrapFunction().default)(fnPath, state.addHelper("skipFirstGeneratorNext"));
+ }
+
+ }
+ };
+});
+
+exports.default = _default; \ No newline at end of file
diff --git a/node_modules/@babel/plugin-proposal-function-sent/package.json b/node_modules/@babel/plugin-proposal-function-sent/package.json
new file mode 100644
index 00000000..7f0562fa
--- /dev/null
+++ b/node_modules/@babel/plugin-proposal-function-sent/package.json
@@ -0,0 +1,23 @@
+{
+ "name": "@babel/plugin-proposal-function-sent",
+ "version": "7.0.0-beta.47",
+ "description": "Compile the function.sent meta propety to valid ES2015 code",
+ "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-proposal-function-sent",
+ "license": "MIT",
+ "main": "lib/index.js",
+ "keywords": [
+ "babel-plugin"
+ ],
+ "dependencies": {
+ "@babel/helper-plugin-utils": "7.0.0-beta.47",
+ "@babel/helper-wrap-function": "7.0.0-beta.47",
+ "@babel/plugin-syntax-function-sent": "7.0.0-beta.47"
+ },
+ "peerDependencies": {
+ "@babel/core": "7.0.0-beta.47"
+ },
+ "devDependencies": {
+ "@babel/core": "7.0.0-beta.47",
+ "@babel/helper-plugin-test-runner": "7.0.0-beta.47"
+ }
+}