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

babel-plugin-class-autobind

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-class-autobind - npm Package Compare versions

Comparing version 0.0.1 to 1.0.0

25

lib/index.js
'use strict';
var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; })();
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

@@ -15,3 +15,3 @@ Object.defineProperty(exports, "__esModule", {

if (path.node.kind === 'constructor') {
path.container.forEach(function (node) {
path.container.forEach(function (node, idx) {
if (t.isClassMethod(node) && node !== path.node) {

@@ -25,2 +25,20 @@ var _node$key$name$split = node.key.name.split(/[A-Z0-9]/);

if (~BIND_PREFIXES.indexOf(keyPrefix)) {
if (node.leadingComments) {
var ignored = null;
node.leadingComments.some(function (comment) {
if (~comment.value.indexOf(IGNORE_PREFIX)) {
ignored = comment;
return true;
}
return false;
});
if (ignored) {
node.leadingComments = (0, _without2.default)(node.leadingComments, ignored);
node.start = node.start - 1;
if (idx > 0) {
path.container[idx - 1].trailingComments = (0, _without2.default)(path.container[idx - 1].trailingComments, ignored);
}
}
return;
}
path.get('body').pushContainer('body', t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier(node.key.name)), t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier(node.key.name), false), t.identifier('bind'), false), [t.thisExpression()]))));

@@ -94,3 +112,4 @@ }

var PREFIX = 'cb-class-autobind ';
var PREFIX = '@autobind ';
var IGNORE_PREFIX = '@autobind-ignore';
var BIND_PREFIXES = ['on', 'handle', '_on', '_handle'];

10

package.json
{
"description": "binds prefixed class handlers",
"author": "Alexander @coobaha Ryzhikov",
"version": "0.0.1",
"version": "1.0.0",
"main": "lib/index.js",
"devDependencies": {
"babel": "^6.3.26",
"babel-cli": "^6.3.17",
"babel-core": "^6.3.17",
"babel-cli": "^6.4.0",
"babel-core": "^6.4.0",
"babel-eslint": "^4.1.6",

@@ -17,3 +17,3 @@ "babel-plugin-syntax-jsx": "^6.3.13",

"eslint-config-airbnb": "^2.1.1",
"eslint-plugin-react": "^3.13.1",
"eslint-plugin-react": "^3.15.0",
"mocha": "^2.2.5",

@@ -55,2 +55,2 @@ "semantic-release": "^4.3.5"

}
}
}
# babel-plugin-class-autobind
This plugin will autobind handlers all components listed in directive 'cb-class-autobind'
This plugin will autobind handlers all components listed in directive '@autobind'
prefixes = `on, _on, handle, _handle`;
## Example

@@ -9,3 +11,3 @@

```js
'cb-class-autobind Component';
'@autobind Component';

@@ -18,2 +20,4 @@ class Component {

noBind(){}
// @autobind-ignore
onIgnored(){}
}

@@ -33,2 +37,3 @@ ```

noBind() {}
onIgnored() {}
}

@@ -44,3 +49,3 @@ ```

if no components are listed in directive - all handlers in file classes will be bound to class instance. (equal to `cb-class-autobind *`)
if no components are listed in directive - all handlers in file classes will be bound to class instance. (equal to `@autobind *`)

@@ -47,0 +52,0 @@

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

'cb-class-autobind Component';
'@autobind Component';

@@ -3,0 +3,0 @@ class Component {

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

'cb-class-autobind Component,Bindable';
'@autobind Component,Bindable';

@@ -15,2 +15,6 @@ class Component {

handleMe() {}
// @autobind-ignore
onIgnored(){}
/* @autobind-ignore */
onIgnoredToo(){}
}

@@ -20,2 +20,5 @@ class Component {

handleMe() {}
onIgnored() {}
onIgnoredToo() {}
}

Sorry, the diff of this file is not supported yet

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