diff options
Diffstat (limited to 'node_modules/@babel/plugin-transform-block-scoped-functions')
3 files changed, 162 insertions, 0 deletions
diff --git a/node_modules/@babel/plugin-transform-block-scoped-functions/README.md b/node_modules/@babel/plugin-transform-block-scoped-functions/README.md new file mode 100644 index 00000000..95985cf6 --- /dev/null +++ b/node_modules/@babel/plugin-transform-block-scoped-functions/README.md @@ -0,0 +1,60 @@ +# @babel/plugin-transform-block-scoped-functions + +> Babel plugin to ensure function declarations at the block level are block scoped. + +## Examples + +**In** + +```javascript +{ + function name (n) { + return n; + } +} + +name("Steve"); +``` + +**Out** + +```javascript +{ + let name = function (n) { + return n; + }; +} +name("Steve"); +``` + +## Installation + +```sh +npm install --save-dev @babel/plugin-transform-block-scoped-functions +``` + +## Usage + +### Via `.babelrc` (Recommended) + +**.babelrc** + +```json +{ + "plugins": ["@babel/plugin-transform-block-scoped-functions"] +} +``` + +### Via CLI + +```sh +babel --plugins @babel/plugin-transform-block-scoped-functions script.js +``` + +### Via Node API + +```javascript +require("@babel/core").transform("code", { + plugins: ["@babel/plugin-transform-block-scoped-functions"] +}); +``` diff --git a/node_modules/@babel/plugin-transform-block-scoped-functions/lib/index.js b/node_modules/@babel/plugin-transform-block-scoped-functions/lib/index.js new file mode 100644 index 00000000..970590bb --- /dev/null +++ b/node_modules/@babel/plugin-transform-block-scoped-functions/lib/index.js @@ -0,0 +1,81 @@ +"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 _core() { + const data = require("@babel/core"); + + _core = function _core() { + return data; + }; + + return data; +} + +var _default = (0, _helperPluginUtils().declare)(api => { + api.assertVersion(7); + + function statementList(key, path) { + const paths = path.get(key); + + for (var _iterator = paths, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { + var _ref; + + if (_isArray) { + if (_i >= _iterator.length) break; + _ref = _iterator[_i++]; + } else { + _i = _iterator.next(); + if (_i.done) break; + _ref = _i.value; + } + + const path = _ref; + const func = path.node; + if (!path.isFunctionDeclaration()) continue; + + const declar = _core().types.variableDeclaration("let", [_core().types.variableDeclarator(func.id, _core().types.toExpression(func))]); + + declar._blockHoist = 2; + func.id = null; + path.replaceWith(declar); + } + } + + return { + visitor: { + BlockStatement(path) { + const node = path.node, + parent = path.parent; + + if (_core().types.isFunction(parent, { + body: node + }) || _core().types.isExportDeclaration(parent)) { + return; + } + + statementList("body", path); + }, + + SwitchCase(path) { + statementList("consequent", path); + } + + } + }; +}); + +exports.default = _default;
\ No newline at end of file diff --git a/node_modules/@babel/plugin-transform-block-scoped-functions/package.json b/node_modules/@babel/plugin-transform-block-scoped-functions/package.json new file mode 100644 index 00000000..6e310e79 --- /dev/null +++ b/node_modules/@babel/plugin-transform-block-scoped-functions/package.json @@ -0,0 +1,21 @@ +{ + "name": "@babel/plugin-transform-block-scoped-functions", + "version": "7.0.0-beta.47", + "description": "Babel plugin to ensure function declarations at the block level are block scoped", + "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-block-scoped-functions", + "license": "MIT", + "main": "lib/index.js", + "keywords": [ + "babel-plugin" + ], + "dependencies": { + "@babel/helper-plugin-utils": "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" + } +} |
