diff options
author | 2020-11-16 00:10:28 +0100 | |
---|---|---|
committer | 2020-11-16 00:10:28 +0100 | |
commit | e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d (patch) | |
tree | 55713f725f77b44ebfec86e4eec3ce33e71458ca /node_modules/babel-plugin-transform-object-rest-spread | |
download | website_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.tar.gz website_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.tar.bz2 website_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.zip |
api, login, auth
Diffstat (limited to 'node_modules/babel-plugin-transform-object-rest-spread')
4 files changed, 426 insertions, 0 deletions
diff --git a/node_modules/babel-plugin-transform-object-rest-spread/.npmignore b/node_modules/babel-plugin-transform-object-rest-spread/.npmignore new file mode 100644 index 0000000..3185290 --- /dev/null +++ b/node_modules/babel-plugin-transform-object-rest-spread/.npmignore @@ -0,0 +1,4 @@ +node_modules +*.log +src +test diff --git a/node_modules/babel-plugin-transform-object-rest-spread/README.md b/node_modules/babel-plugin-transform-object-rest-spread/README.md new file mode 100644 index 0000000..79f2432 --- /dev/null +++ b/node_modules/babel-plugin-transform-object-rest-spread/README.md @@ -0,0 +1,88 @@ +# babel-plugin-transform-object-rest-spread + +> This plugin allows Babel to transform rest properties for object destructuring assignment and spread properties for object literals. + +## Example + +### Rest Properties + +```js +let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 }; +console.log(x); // 1 +console.log(y); // 2 +console.log(z); // { a: 3, b: 4 } +``` + +### Spread Properties + +```js +let n = { x, y, ...z }; +console.log(n); // { x: 1, y: 2, a: 3, b: 4 } +``` + +## Installation + +```sh +npm install --save-dev babel-plugin-transform-object-rest-spread +``` + +## Usage + +### Via `.babelrc` (Recommended) + +**.babelrc** + +```json +{ + "plugins": ["transform-object-rest-spread"] +} +``` + +### Via CLI + +```sh +babel --plugins transform-object-rest-spread script.js +``` + +### Via Node API + +```javascript +require("babel-core").transform("code", { + plugins: ["transform-object-rest-spread"] +}); +``` + +## Options + +### `useBuiltIns` + +`boolean`, defaults to `false`. + +By default, this plugin uses Babel's `extends` helper which polyfills `Object.assign`. Enabling this option will use `Object.assign` directly. + +**.babelrc** + +```json +{ + "plugins": [ + ["transform-object-rest-spread", { "useBuiltIns": true }] + ] +} +``` + +**In** + +```js +z = { x, ...y }; +``` + +**Out** + +```js +z = Object.assign({ x }, y); +``` + +## References + +* [Proposal: Object Rest/Spread Properties for ECMAScript](https://github.com/sebmarkbage/ecmascript-rest-spread) +* [Spec](http://sebmarkbage.github.io/ecmascript-rest-spread) diff --git a/node_modules/babel-plugin-transform-object-rest-spread/lib/index.js b/node_modules/babel-plugin-transform-object-rest-spread/lib/index.js new file mode 100644 index 0000000..136e9bd --- /dev/null +++ b/node_modules/babel-plugin-transform-object-rest-spread/lib/index.js @@ -0,0 +1,288 @@ +"use strict"; + +exports.__esModule = true; + +var _getIterator2 = require("babel-runtime/core-js/get-iterator"); + +var _getIterator3 = _interopRequireDefault(_getIterator2); + +exports.default = function (_ref) { + var t = _ref.types; + + function hasRestProperty(path) { + var foundRestProperty = false; + path.traverse({ + RestProperty: function RestProperty() { + foundRestProperty = true; + path.stop(); + } + }); + return foundRestProperty; + } + + function hasSpread(node) { + for (var _iterator = node.properties, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) { + var _ref2; + + if (_isArray) { + if (_i >= _iterator.length) break; + _ref2 = _iterator[_i++]; + } else { + _i = _iterator.next(); + if (_i.done) break; + _ref2 = _i.value; + } + + var prop = _ref2; + + if (t.isSpreadProperty(prop)) { + return true; + } + } + return false; + } + + function createObjectSpread(file, props, objRef) { + var restProperty = props.pop(); + + var keys = []; + for (var _iterator2 = props, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) { + var _ref3; + + if (_isArray2) { + if (_i2 >= _iterator2.length) break; + _ref3 = _iterator2[_i2++]; + } else { + _i2 = _iterator2.next(); + if (_i2.done) break; + _ref3 = _i2.value; + } + + var prop = _ref3; + + var key = prop.key; + if (t.isIdentifier(key) && !prop.computed) { + key = t.stringLiteral(prop.key.name); + } + keys.push(key); + } + + return [restProperty.argument, t.callExpression(file.addHelper("objectWithoutProperties"), [objRef, t.arrayExpression(keys)])]; + } + + function replaceRestProperty(parentPath, paramPath, i, numParams) { + if (paramPath.isAssignmentPattern()) { + replaceRestProperty(parentPath, paramPath.get("left"), i, numParams); + return; + } + + if (paramPath.isObjectPattern() && hasRestProperty(paramPath)) { + var uid = parentPath.scope.generateUidIdentifier("ref"); + + var declar = t.variableDeclaration("let", [t.variableDeclarator(paramPath.node, uid)]); + declar._blockHoist = i ? numParams - i : 1; + + parentPath.ensureBlock(); + parentPath.get("body").unshiftContainer("body", declar); + paramPath.replaceWith(uid); + } + } + + return { + inherits: require("babel-plugin-syntax-object-rest-spread"), + + visitor: { + Function: function Function(path) { + var params = path.get("params"); + for (var i = 0; i < params.length; i++) { + replaceRestProperty(params[i].parentPath, params[i], i, params.length); + } + }, + VariableDeclarator: function VariableDeclarator(path, file) { + if (!path.get("id").isObjectPattern()) { + return; + } + + var insertionPath = path; + + path.get("id").traverse({ + RestProperty: function RestProperty(path) { + if (this.originalPath.node.id.properties.length > 1 && !t.isIdentifier(this.originalPath.node.init)) { + var initRef = path.scope.generateUidIdentifierBasedOnNode(this.originalPath.node.init, "ref"); + + this.originalPath.insertBefore(t.variableDeclarator(initRef, this.originalPath.node.init)); + + this.originalPath.replaceWith(t.variableDeclarator(this.originalPath.node.id, initRef)); + + return; + } + + var ref = this.originalPath.node.init; + var refPropertyPath = []; + + path.findParent(function (path) { + if (path.isObjectProperty()) { + refPropertyPath.unshift(path.node.key.name); + } else if (path.isVariableDeclarator()) { + return true; + } + }); + + if (refPropertyPath.length) { + refPropertyPath.forEach(function (prop) { + ref = t.memberExpression(ref, t.identifier(prop)); + }); + } + + var _createObjectSpread = createObjectSpread(file, path.parentPath.node.properties, ref), + argument = _createObjectSpread[0], + callExpression = _createObjectSpread[1]; + + insertionPath.insertAfter(t.variableDeclarator(argument, callExpression)); + + insertionPath = insertionPath.getSibling(insertionPath.key + 1); + + if (path.parentPath.node.properties.length === 0) { + path.findParent(function (path) { + return path.isObjectProperty() || path.isVariableDeclarator(); + }).remove(); + } + } + }, { + originalPath: path + }); + }, + ExportNamedDeclaration: function ExportNamedDeclaration(path) { + var declaration = path.get("declaration"); + if (!declaration.isVariableDeclaration()) return; + if (!hasRestProperty(declaration)) return; + + var specifiers = []; + + for (var name in path.getOuterBindingIdentifiers(path)) { + var id = t.identifier(name); + specifiers.push(t.exportSpecifier(id, id)); + } + + path.replaceWith(declaration.node); + path.insertAfter(t.exportNamedDeclaration(null, specifiers)); + }, + CatchClause: function CatchClause(path) { + var paramPath = path.get("param"); + replaceRestProperty(paramPath.parentPath, paramPath); + }, + AssignmentExpression: function AssignmentExpression(path, file) { + var leftPath = path.get("left"); + if (leftPath.isObjectPattern() && hasRestProperty(leftPath)) { + var nodes = []; + + var ref = void 0; + if (path.isCompletionRecord() || path.parentPath.isExpressionStatement()) { + ref = path.scope.generateUidIdentifierBasedOnNode(path.node.right, "ref"); + + nodes.push(t.variableDeclaration("var", [t.variableDeclarator(ref, path.node.right)])); + } + + var _createObjectSpread2 = createObjectSpread(file, path.node.left.properties, ref), + argument = _createObjectSpread2[0], + callExpression = _createObjectSpread2[1]; + + var nodeWithoutSpread = t.clone(path.node); + nodeWithoutSpread.right = ref; + nodes.push(t.expressionStatement(nodeWithoutSpread)); + nodes.push(t.toStatement(t.assignmentExpression("=", argument, callExpression))); + + if (ref) { + nodes.push(t.expressionStatement(ref)); + } + + path.replaceWithMultiple(nodes); + } + }, + ForXStatement: function ForXStatement(path) { + var node = path.node, + scope = path.scope; + + var leftPath = path.get("left"); + var left = node.left; + + if (t.isObjectPattern(left) && hasRestProperty(leftPath)) { + var temp = scope.generateUidIdentifier("ref"); + + node.left = t.variableDeclaration("var", [t.variableDeclarator(temp)]); + + path.ensureBlock(); + + node.body.body.unshift(t.variableDeclaration("var", [t.variableDeclarator(left, temp)])); + + return; + } + + if (!t.isVariableDeclaration(left)) return; + + var pattern = left.declarations[0].id; + if (!t.isObjectPattern(pattern)) return; + + var key = scope.generateUidIdentifier("ref"); + node.left = t.variableDeclaration(left.kind, [t.variableDeclarator(key, null)]); + + path.ensureBlock(); + + node.body.body.unshift(t.variableDeclaration(node.left.kind, [t.variableDeclarator(pattern, key)])); + }, + ObjectExpression: function ObjectExpression(path, file) { + if (!hasSpread(path.node)) return; + + var useBuiltIns = file.opts.useBuiltIns || false; + if (typeof useBuiltIns !== "boolean") { + throw new Error("transform-object-rest-spread currently only accepts a boolean " + "option for useBuiltIns (defaults to false)"); + } + + var args = []; + var props = []; + + function push() { + if (!props.length) return; + args.push(t.objectExpression(props)); + props = []; + } + + for (var _iterator3 = path.node.properties, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : (0, _getIterator3.default)(_iterator3);;) { + var _ref4; + + if (_isArray3) { + if (_i3 >= _iterator3.length) break; + _ref4 = _iterator3[_i3++]; + } else { + _i3 = _iterator3.next(); + if (_i3.done) break; + _ref4 = _i3.value; + } + + var prop = _ref4; + + if (t.isSpreadProperty(prop)) { + push(); + args.push(prop.argument); + } else { + props.push(prop); + } + } + + push(); + + if (!t.isObjectExpression(args[0])) { + args.unshift(t.objectExpression([])); + } + + var helper = useBuiltIns ? t.memberExpression(t.identifier("Object"), t.identifier("assign")) : file.addHelper("extends"); + + path.replaceWith(t.callExpression(helper, args)); + } + } + }; +}; + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +module.exports = exports["default"];
\ No newline at end of file diff --git a/node_modules/babel-plugin-transform-object-rest-spread/package.json b/node_modules/babel-plugin-transform-object-rest-spread/package.json new file mode 100644 index 0000000..1f4e72f --- /dev/null +++ b/node_modules/babel-plugin-transform-object-rest-spread/package.json @@ -0,0 +1,46 @@ +{ + "_from": "babel-plugin-transform-object-rest-spread@^6.22.0", + "_id": "babel-plugin-transform-object-rest-spread@6.26.0", + "_inBundle": false, + "_integrity": "sha1-DzZpLVD+9rfi1LOsFHgTepY7ewY=", + "_location": "/babel-plugin-transform-object-rest-spread", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-plugin-transform-object-rest-spread@^6.22.0", + "name": "babel-plugin-transform-object-rest-spread", + "escapedName": "babel-plugin-transform-object-rest-spread", + "rawSpec": "^6.22.0", + "saveSpec": null, + "fetchSpec": "^6.22.0" + }, + "_requiredBy": [ + "/babel-preset-stage-3" + ], + "_resolved": "https://registry.npmjs.org/babel-plugin-transform-object-rest-spread/-/babel-plugin-transform-object-rest-spread-6.26.0.tgz", + "_shasum": "0f36692d50fef6b7e2d4b3ac1478137a963b7b06", + "_spec": "babel-plugin-transform-object-rest-spread@^6.22.0", + "_where": "/home/pruss/Dev/3-minute-website/node_modules/babel-preset-stage-3", + "bundleDependencies": false, + "dependencies": { + "babel-plugin-syntax-object-rest-spread": "^6.8.0", + "babel-runtime": "^6.26.0" + }, + "deprecated": false, + "description": "Compile object rest and spread to ES5", + "devDependencies": { + "babel-helper-plugin-test-runner": "^6.22.0" + }, + "keywords": [ + "babel-plugin" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-plugin-transform-object-rest-spread", + "repository": { + "type": "git", + "url": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-object-rest-spread" + }, + "version": "6.26.0" +} |