Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-transform-proto-to-assign-robust

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-proto-to-assign-robust

This plugin allows Babel to transform all **proto** assignments to a method that will do a shallow copy of all properties with symbol.

  • 6.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

babel-plugin-transform-proto-to-assign-robust

build status NPM version NPM Downloads

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

Inspired by babel-plugin-transform-proto-to-assign

Why?

When we using es6 class extend syntax in IE<=10 which has not Object.setPrototypeOf and __proto__, so We need use babel-plugin-transform-proto-to-assign to transforming.

  • In
bar.__proto__ = foo
  • Out
var _defaults = function(obj, defaults) {
  var keys = Object.getOwnPropertyNames(defaults)
  for (var i = 0; i < keys.length; i++) {
    var key = keys[i]
    var value = Object.getOwnPropertyDescriptor(defaults, key)
    if (value && value.configurable && obj[key] === undefined) {
      Object.defineProperty(obj, key, value)
    }
  }
  return obj
}

_defaults(bar, foo)

The above transform are worked by babel-plugin-transform-proto-to-assign.

However the _default function DO NOT assign the Symbol static value, but babel-plugin-transform-proto-to-assign-robust do it!

Transform

  • In
bar.__proto__ = foo
  • Out
;(function (obj, defaults) {
  var keys = Object.getOwnPropertyNames(defaults)
  for (var i = 0; i < keys.length; i++) {
    var key = keys[i]
    var value = Object.getOwnPropertyDescriptor(defaults, key)
    if (value && value.configurable && obj[key] === undefined) {
      Object.defineProperty(obj, key, value)
    }
  }
  return obj
})(bar, foo);

Keywords

FAQs

Package last updated on 18 Aug 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc