Socket
Socket
Sign inDemoInstall

autobind-decorator

Package Overview
Dependencies
0
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.3.0 to 2.3.1

src/__tests__/.babelrc

5

CHANGELOG.md

@@ -5,2 +5,7 @@ # Change Log

<a name="2.3.1"></a>
## [2.3.1](https://github.com/andreypopp/autobind-decorator/compare/v2.3.0...v2.3.1) (2018-11-17)
<a name="2.3.0"></a>

@@ -7,0 +12,0 @@ # [2.3.0](https://github.com/andreypopp/autobind-decorator/compare/v2.2.1...v2.3.0) (2018-11-17)

40

lib/index.js

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {

});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
exports.boundMethod = boundMethod;
exports.boundClass = boundClass;
exports.default = autobind;
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
/**

@@ -22,13 +22,13 @@ * Return a descriptor removing the value and returning a getter

if (typeof fn !== 'function') {
throw new Error('@boundMethod decorator can only be applied to methods not: ' + (typeof fn === 'undefined' ? 'undefined' : _typeof(fn)));
}
// In IE11 calling Object.defineProperty has a side-effect of evaluating the
throw new TypeError("@boundMethod decorator can only be applied to methods not: ".concat(_typeof(fn)));
} // In IE11 calling Object.defineProperty has a side-effect of evaluating the
// getter for the property which is being replaced. This causes infinite
// recursion and an "Out of stack space" error.
var definingProperty = false;
return {
configurable: true,
get: function get() {
// eslint-disable-next-line no-prototype-builtins
if (definingProperty || this === target.prototype || this.hasOwnProperty(key) || typeof fn !== 'function') {

@@ -58,15 +58,16 @@ return fn;

}
/**
* Use boundMethod to bind all methods on the target.prototype
*/
function boundClass(target) {
// (Using reflect to get all keys including symbols)
var keys = void 0;
// Use Reflect if exists
var keys; // Use Reflect if exists
if (typeof Reflect !== 'undefined' && typeof Reflect.ownKeys === 'function') {
keys = Reflect.ownKeys(target.prototype);
} else {
keys = Object.getOwnPropertyNames(target.prototype);
// use symbols if support is provided
keys = Object.getOwnPropertyNames(target.prototype); // Use symbols if support is provided
if (typeof Object.getOwnPropertySymbols === 'function') {

@@ -83,5 +84,4 @@ keys = keys.concat(Object.getOwnPropertySymbols(target.prototype));

var descriptor = Object.getOwnPropertyDescriptor(target.prototype, key);
var descriptor = Object.getOwnPropertyDescriptor(target.prototype, key); // Only methods need binding
// Only methods need binding
if (typeof descriptor.value === 'function') {

@@ -96,6 +96,6 @@ Object.defineProperty(target.prototype, key, boundMethod(target, key, descriptor));

if (arguments.length === 1) {
return boundClass.apply(undefined, arguments);
} else {
return boundMethod.apply(undefined, arguments);
return boundClass.apply(void 0, arguments);
}
}
return boundMethod.apply(void 0, arguments);
}
{
"name": "autobind-decorator",
"version": "2.3.0",
"version": "2.3.1",
"description": "Decorator for binding method to an object",
"main": "lib/index.js",
"module": "src/index.js",
"types": "./index.d.ts",
"types": "index.d.ts",
"scripts": {
"build": "make build",
"build-test": "make build-test",
"test": "make test",
"lint": "make lint",
"clean": "make clean",
"release": "make release"
"clean": "rm -rf lib",
"build": "babel src --out-dir lib --ignore \"src/__tests__/*.js\"",
"lint": "xo",
"test": "npm run lint && jest --coverage",
"release": "standard-version",
"prepublish": "npm run clean && npm run build && npm test"
},

@@ -19,13 +19,34 @@ "author": "Andrey Popp <8mayday@gmail.com>",

"devDependencies": {
"babel-cli": "^6.26.0",
"babel-eslint": "^7.0.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-es2015": "^6.16.0",
"babelify": "^7.3.0",
"core-js": "^0.9.18",
"eslint": "^3.8.0",
"mochify": "^2.18.1",
"phantomjs": "^2.1.7",
"standard-version": "^4.4.0"
"@babel/cli": "^7.1.5",
"@babel/core": "^7.1.6",
"@babel/plugin-proposal-decorators": "^7.1.6",
"@babel/preset-env": "^7.1.6",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^23.6.0",
"jest": "^23.6.0",
"regenerator-runtime": "^0.13.1",
"standard-version": "^4.4.0",
"xo": "^0.23.0"
},
"xo": {
"parser": "babel-eslint",
"globals": [
"describe",
"test",
"beforeEach",
"afterEach"
],
"overrides": [
{
"files": "src/__tests__/*.js",
"rules": {
"no-global-assign": "off",
"no-self-compare": "off",
"func-names": "off",
"func-name-matching": "off"
}
}
]
},
"repository": {

@@ -32,0 +53,0 @@ "type": "git",

@@ -27,3 +27,3 @@ # autobind decorator

We target IE11+ browsers with the following caveats:
We target IE11+ browsers (see [out browserslist](./src/browserslist)) with the following caveats:

@@ -30,0 +30,0 @@ `main` entry is in ES5

@@ -7,40 +7,41 @@ /**

export function boundMethod(target, key, descriptor) {
let fn = descriptor.value;
let fn = descriptor.value;
if (typeof fn !== 'function') {
throw new Error(`@boundMethod decorator can only be applied to methods not: ${typeof fn}`);
}
if (typeof fn !== 'function') {
throw new TypeError(`@boundMethod decorator can only be applied to methods not: ${typeof fn}`);
}
// In IE11 calling Object.defineProperty has a side-effect of evaluating the
// getter for the property which is being replaced. This causes infinite
// recursion and an "Out of stack space" error.
let definingProperty = false;
// In IE11 calling Object.defineProperty has a side-effect of evaluating the
// getter for the property which is being replaced. This causes infinite
// recursion and an "Out of stack space" error.
let definingProperty = false;
return {
configurable: true,
get() {
if (definingProperty || this === target.prototype || this.hasOwnProperty(key)
|| typeof fn !== 'function') {
return fn;
}
return {
configurable: true,
get() {
// eslint-disable-next-line no-prototype-builtins
if (definingProperty || this === target.prototype || this.hasOwnProperty(key) ||
typeof fn !== 'function') {
return fn;
}
let boundFn = fn.bind(this);
definingProperty = true;
Object.defineProperty(this, key, {
configurable: true,
get() {
return boundFn;
},
set(value) {
fn = value;
delete this[key];
}
});
definingProperty = false;
return boundFn;
},
set(value) {
fn = value;
}
};
const boundFn = fn.bind(this);
definingProperty = true;
Object.defineProperty(this, key, {
configurable: true,
get() {
return boundFn;
},
set(value) {
fn = value;
delete this[key];
}
});
definingProperty = false;
return boundFn;
},
set(value) {
fn = value;
}
};
}

@@ -52,37 +53,36 @@

export function boundClass(target) {
// (Using reflect to get all keys including symbols)
let keys;
// Use Reflect if exists
if (typeof Reflect !== 'undefined' && typeof Reflect.ownKeys === 'function') {
keys = Reflect.ownKeys(target.prototype);
} else {
keys = Object.getOwnPropertyNames(target.prototype);
// use symbols if support is provided
if (typeof Object.getOwnPropertySymbols === 'function') {
keys = keys.concat(Object.getOwnPropertySymbols(target.prototype));
}
}
// (Using reflect to get all keys including symbols)
let keys;
// Use Reflect if exists
if (typeof Reflect !== 'undefined' && typeof Reflect.ownKeys === 'function') {
keys = Reflect.ownKeys(target.prototype);
} else {
keys = Object.getOwnPropertyNames(target.prototype);
// Use symbols if support is provided
if (typeof Object.getOwnPropertySymbols === 'function') {
keys = keys.concat(Object.getOwnPropertySymbols(target.prototype));
}
}
keys.forEach(key => {
// Ignore special case target method
if (key === 'constructor') {
return;
}
keys.forEach(key => {
// Ignore special case target method
if (key === 'constructor') {
return;
}
let descriptor = Object.getOwnPropertyDescriptor(target.prototype, key);
const descriptor = Object.getOwnPropertyDescriptor(target.prototype, key);
// Only methods need binding
if (typeof descriptor.value === 'function') {
Object.defineProperty(target.prototype, key, boundMethod(target, key, descriptor));
}
});
return target;
// Only methods need binding
if (typeof descriptor.value === 'function') {
Object.defineProperty(target.prototype, key, boundMethod(target, key, descriptor));
}
});
return target;
}
export default function autobind(...args) {
if (args.length === 1) {
return boundClass(...args);
} else {
return boundMethod(...args);
}
if (args.length === 1) {
return boundClass(...args);
}
return boundMethod(...args);
}
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc