babel-plugin-transform-proto-to-assign

Babel plugin for turning __proto__ into a shallow property clone

MIT 37 个版本
安装
npm install babel-plugin-transform-proto-to-assign
yarn add babel-plugin-transform-proto-to-assign
pnpm add babel-plugin-transform-proto-to-assign
bun add babel-plugin-transform-proto-to-assign
README

babel-plugin-transform-proto-to-assign

This plugin allows Babel to transform all __proto__ assignments to a method that will do a shallow copy of all properties.

Detail

This means that the following will work:

var foo = { a: 1 };
var bar = { b: 2 };
bar.__proto__ = foo;
bar.a; // 1
bar.b; // 2

however the following will not:

var foo = { a: 1 };
var bar = { b: 2 };
bar.__proto__ = foo;
bar.a; // 1
foo.a = 2;
bar.a; // 1 - should be 2 but remember that nothing is bound and it's a straight copy

This is a case that you have to be aware of if you intend to use this plugin.

Example

In

bar.__proto__ = foo;

Out

var _defaults = ...;

_defaults(bar, foo);

Installation

npm install --save-dev babel-plugin-transform-proto-to-assign

Usage

.babelrc

{
  "plugins": ["transform-proto-to-assign"]
}

Via CLI

babel --plugins transform-proto-to-assign script.js

Via Node API

require("babel-core").transform("code", {
  plugins: ["transform-proto-to-assign"]
});
版本列表
7.0.0-beta.3 2017-10-15
7.0.0-beta.2 2017-09-26
7.0.0-beta.1 2017-09-19
7.0.0-beta.0 2017-09-12
7.0.0-alpha.20 2017-08-30
7.0.0-alpha.19 2017-08-07
7.0.0-alpha.18 2017-08-03
7.0.0-alpha.17 2017-07-26
7.0.0-alpha.16 2017-07-25
7.0.0-alpha.15 2017-07-12
7.0.0-alpha.14 2017-07-12
7.0.0-alpha.12 2017-05-31
7.0.0-alpha.11 2017-05-31
7.0.0-alpha.10 2017-05-25
7.0.0-alpha.9 2017-04-18
7.0.0-alpha.8 2017-04-17
7.0.0-alpha.7 2017-04-05
7.0.0-alpha.3 2017-03-23
7.0.0-alpha.1 2017-03-02
6.26.0 2017-08-16
6.23.0 2017-02-13
6.22.0 2017-01-20
6.9.0 2016-05-17
6.8.0 2016-05-02
6.6.5 2016-03-04
6.6.4 2016-03-02
6.6.0 2016-02-29
6.5.0-1 2016-02-07
6.5.0 2016-02-07
6.4.0 2016-01-06
6.3.13 2015-12-04
6.2.4 2015-11-25
6.1.18 2015-11-12
6.1.17 2015-11-12
6.1.4 2015-11-11
6.0.14 2015-10-30
6.0.2 2015-10-29