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/plugin-proposal-function-sent/lib/index.js | |
| parent | 2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff) | |
| download | xmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip | |
switch to vuepress
Diffstat (limited to 'node_modules/@babel/plugin-proposal-function-sent/lib/index.js')
| -rw-r--r-- | node_modules/@babel/plugin-proposal-function-sent/lib/index.js | 104 |
1 files changed, 104 insertions, 0 deletions
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 |
