Registry / babel-plugin-transform-proto-to-assign

babel-plugin-transform-proto-to-assign

JSON →
library6.26.0jsnpmunverified

This Babel plugin transforms assignments to __proto__ into a shallow property copy, enabling prototype-like inheritance in environments that do not support __proto__ or Object.setPrototypeOf. The latest stable version is 6.26.0 (2017-01-30), part of Babel 6.x. It is maintained as part of the Babel monorepo but is considered legacy; Babel 7+ discourages use of this plugin and instead recommends using Object.setPrototypeOf or Object.create for performance reasons. The plugin does a shallow clone of all enumerable own properties from the target prototype. It works only with assignments like `obj.__proto__ = proto`, not `Object.setPrototypeOf`. It modifies Object.prototype, which can cause side effects. It is a single-purpose transform, not part of any preset-env. Alternative: use `@babel/plugin-transform-proto-to-assign` for Babel 7. The plugin is deprecated in favor of modern Object.setPrototypeOf.

npm install babel-plugin-transform-proto-to-assign
INSTALL
IMPORT
SIG · BABEL-PLUGIN-TRANS
B
babel-plugin-transform-proto-to-assign
javascriptv6.26.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (plugin)
module.exports = require('babel-plugin-transform-proto-to-assign');
import p from 'babel-plugin-transform-proto-to-assign';
This plugin is designed for Babel 6's CommonJS module system. In Babel 6, plugins are loaded via require; ES import syntax may not work directly. For Babel 7, use @babel/plugin-transform-proto-to-assign.
babel-core transform with plugin
require('babel-core').transform(code, { plugins: ['transform-proto-to-assign'] });
require('babel-core').transform(code, { plugins: [require('babel-plugin-transform-proto-to-assign')] }); // may work but string name is preferred
In Babel 6, plugins can be specified by package name string. Passing the plugin object directly also works but string is standard.
.babelrc configuration
{ "plugins": ["transform-proto-to-assign"] }
{ "plugins": ["babel-plugin-transform-proto-to-assign"] } // also valid, but shorter name without prefix is typical
Babel automatically resolves the 'babel-plugin-' prefix, so either 'transform-proto-to-assign' or 'babel-plugin-transform-proto-to-assign' works.

Shows installation, configuration, source code with __proto__ assignment, and compilation output.

// Step 1: Install the plugin // npm install --save-dev babel-plugin-transform-proto-to-assign // Step 2: Create .babelrc with the plugin // { // "plugins": ["transform-proto-to-assign"] // } // Step 3: Write source with __proto__ assignment var foo = { a: 1 }; var bar = { b: 2 }; bar.__proto__ = foo; // Step 4: Compile with Babel // npx babel script.js --out-file compiled.js // compiled.js output (simplified): // var _defaults = ...; // _defaults(bar, foo); // Note: Does not support dynamic prototype chain; only shallow copy of properties at assignment time.
Debug
Known issues
deprecatedThis plugin is part of Babel 6 and has no active development. For Babel 7+, use '@babel/plugin-transform-proto-to-assign' instead.
fix
Upgrade to Babel 7+ and install @babel/plugin-transform-proto-to-assign.
affects: >=6.0.0
gotchaThe transform does a shallow copy of properties at the moment of assignment, not a live prototype chain. Changing the prototype later does not affect already-assigned properties.
fix
Use Object.setPrototypeOf or Object.create for proper prototype chain if needed.
affects: >=0.0.0
gotchaModifying Object.prototype can cause performance issues and side effects in other code. Avoid if possible.
fix
Use explicit property assignment or Object.assign instead of __proto__ manipulation.
affects: >=0.0.0
breakingOnly transforms assignments like `obj.__proto__ = value`. Does not handle Object.setPrototypeOf or Reflect.setPrototypeOf.
fix
Add a separate plugin or polyfill if supporting Object.setPrototypeOf is required.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'babel-plugin-transform-proto-to-assign'
Plugin not installed or not in node_modules.
fix
Run 'npm install --save-dev babel-plugin-transform-proto-to-assign' and ensure node_modules is present.
Error: Plugin .__proto__ is not a function
Attempting to use the plugin with Babel 7 where the package name has changed.
fix
Use '@babel/plugin-transform-proto-to-assign' instead, or downgrade to Babel 6.
TypeError: Cannot set property __proto__ of undefined
Assigning to __proto__ on a non-object value (null/undefined).
fix
Ensure the left-hand side of __proto__ assignment is an object.
Upgrade
Version history
6.26.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
babel-plugin-transform-proto-to-assign — npm install babel-plugin-transform-proto-to-assign · libregistry