You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
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
npmnpm
Version published
Maintainers
1
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

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

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