@babel/plugin-transform-proto-to-assign
Advanced tools
Comparing version 7.0.0-beta.42 to 7.0.0-beta.43
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _helperPluginUtils = require("@babel/helper-plugin-utils"); | ||
function _helperPluginUtils() { | ||
const data = require("@babel/helper-plugin-utils"); | ||
var _pull = _interopRequireDefault(require("lodash/pull")); | ||
_helperPluginUtils = function () { | ||
return data; | ||
}; | ||
var _core = require("@babel/core"); | ||
return data; | ||
} | ||
function _pull() { | ||
const data = _interopRequireDefault(require("lodash/pull")); | ||
_pull = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _core() { | ||
const data = require("@babel/core"); | ||
_core = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _default = (0, _helperPluginUtils.declare)(function (api) { | ||
var _default = (0, _helperPluginUtils().declare)(api => { | ||
api.assertVersion(7); | ||
function isProtoKey(node) { | ||
return _core.types.isLiteral(_core.types.toComputedKey(node, node.key), { | ||
return _core().types.isLiteral(_core().types.toComputedKey(node, node.key), { | ||
value: "__proto__" | ||
@@ -24,4 +50,4 @@ }); | ||
function isProtoAssignmentExpression(node) { | ||
var left = node.left; | ||
return _core.types.isMemberExpression(left) && _core.types.isLiteral(_core.types.toComputedKey(left, left.property), { | ||
const left = node.left; | ||
return _core().types.isMemberExpression(left) && _core().types.isLiteral(_core().types.toComputedKey(left, left.property), { | ||
value: "__proto__" | ||
@@ -32,3 +58,3 @@ }); | ||
function buildDefaultsCallExpression(expr, ref, file) { | ||
return _core.types.expressionStatement(_core.types.callExpression(file.addHelper("defaults"), [ref, expr.right])); | ||
return _core().types.expressionStatement(_core().types.callExpression(file.addHelper("defaults"), [ref, expr.right])); | ||
} | ||
@@ -38,19 +64,20 @@ | ||
visitor: { | ||
AssignmentExpression: function AssignmentExpression(path, file) { | ||
AssignmentExpression(path, file) { | ||
if (!isProtoAssignmentExpression(path.node)) return; | ||
var nodes = []; | ||
var left = path.node.left.object; | ||
var temp = path.scope.maybeGenerateMemoised(left); | ||
const nodes = []; | ||
const left = path.node.left.object; | ||
const temp = path.scope.maybeGenerateMemoised(left); | ||
if (temp) { | ||
nodes.push(_core.types.expressionStatement(_core.types.assignmentExpression("=", temp, left))); | ||
nodes.push(_core().types.expressionStatement(_core().types.assignmentExpression("=", temp, left))); | ||
} | ||
nodes.push(buildDefaultsCallExpression(path.node, _core.types.cloneNode(temp || left), file)); | ||
if (temp) nodes.push(_core.types.cloneNode(temp)); | ||
nodes.push(buildDefaultsCallExpression(path.node, _core().types.cloneNode(temp || left), file)); | ||
if (temp) nodes.push(_core().types.cloneNode(temp)); | ||
path.replaceWithMultiple(nodes); | ||
}, | ||
ExpressionStatement: function ExpressionStatement(path, file) { | ||
var expr = path.node.expression; | ||
if (!_core.types.isAssignmentExpression(expr, { | ||
ExpressionStatement(path, file) { | ||
const expr = path.node.expression; | ||
if (!_core().types.isAssignmentExpression(expr, { | ||
operator: "=" | ||
@@ -63,13 +90,13 @@ })) return; | ||
}, | ||
ObjectExpression: function ObjectExpression(path, file) { | ||
var proto; | ||
var node = path.node; | ||
var _arr = node.properties; | ||
for (var _i = 0; _i < _arr.length; _i++) { | ||
var prop = _arr[_i]; | ||
ObjectExpression(path, file) { | ||
let proto; | ||
const { | ||
node | ||
} = path; | ||
for (const prop of node.properties) { | ||
if (isProtoKey(prop)) { | ||
proto = prop.value; | ||
(0, _pull.default)(node.properties, prop); | ||
(0, _pull().default)(node.properties, prop); | ||
} | ||
@@ -79,7 +106,8 @@ } | ||
if (proto) { | ||
var args = [_core.types.objectExpression([]), proto]; | ||
const args = [_core().types.objectExpression([]), proto]; | ||
if (node.properties.length) args.push(node); | ||
path.replaceWith(_core.types.callExpression(file.addHelper("extends"), args)); | ||
path.replaceWith(_core().types.callExpression(file.addHelper("extends"), args)); | ||
} | ||
} | ||
} | ||
@@ -86,0 +114,0 @@ }; |
{ | ||
"name": "@babel/plugin-transform-proto-to-assign", | ||
"version": "7.0.0-beta.42", | ||
"version": "7.0.0-beta.43", | ||
"description": "Babel plugin for turning __proto__ into a shallow property clone", | ||
@@ -12,11 +12,11 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-proto-to-assign", | ||
"dependencies": { | ||
"@babel/helper-plugin-utils": "7.0.0-beta.42" | ||
"@babel/helper-plugin-utils": "7.0.0-beta.43" | ||
}, | ||
"peerDependencies": { | ||
"@babel/core": "7.0.0-beta.42" | ||
"@babel/core": "7.0.0-beta.43" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "7.0.0-beta.42", | ||
"@babel/helper-plugin-test-runner": "7.0.0-beta.42" | ||
"@babel/core": "7.0.0-beta.43", | ||
"@babel/helper-plugin-test-runner": "7.0.0-beta.43" | ||
} | ||
} |
4702
86
+ Added@babel/code-frame@7.0.0-beta.43(transitive)
+ Added@babel/core@7.0.0-beta.43(transitive)
+ Added@babel/generator@7.0.0-beta.43(transitive)
+ Added@babel/helper-function-name@7.0.0-beta.43(transitive)
+ Added@babel/helper-get-function-arity@7.0.0-beta.43(transitive)
+ Added@babel/helper-plugin-utils@7.0.0-beta.43(transitive)
+ Added@babel/helper-split-export-declaration@7.0.0-beta.43(transitive)
+ Added@babel/helpers@7.0.0-beta.43(transitive)
+ Added@babel/highlight@7.0.0-beta.43(transitive)
+ Added@babel/template@7.0.0-beta.43(transitive)
+ Added@babel/traverse@7.0.0-beta.43(transitive)
+ Added@babel/types@7.0.0-beta.43(transitive)
+ Addedbabylon@7.0.0-beta.43(transitive)
- Removed@babel/code-frame@7.0.0-beta.42(transitive)
- Removed@babel/core@7.0.0-beta.42(transitive)
- Removed@babel/generator@7.0.0-beta.42(transitive)
- Removed@babel/helper-function-name@7.0.0-beta.42(transitive)
- Removed@babel/helper-get-function-arity@7.0.0-beta.42(transitive)
- Removed@babel/helper-plugin-utils@7.0.0-beta.42(transitive)
- Removed@babel/helper-split-export-declaration@7.0.0-beta.42(transitive)
- Removed@babel/helpers@7.0.0-beta.42(transitive)
- Removed@babel/highlight@7.0.0-beta.42(transitive)
- Removed@babel/template@7.0.0-beta.42(transitive)
- Removed@babel/traverse@7.0.0-beta.42(transitive)
- Removed@babel/types@7.0.0-beta.42(transitive)
- Removedbabylon@7.0.0-beta.42(transitive)