babel-plugin-sitrep
Advanced tools
Comparing version 1.2.1 to 1.2.2
{ | ||
"name": "babel-plugin-sitrep", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "Log all assignments and the return value of a function with a simple comment", | ||
@@ -24,2 +24,3 @@ "main": "src/index.js", | ||
"babel-plugin-tester": "^4.0.0", | ||
"babel-plugin-transform-class-properties": "^6.24.1", | ||
"jest": "^20.0.4", | ||
@@ -26,0 +27,0 @@ "jest-cli": "^20.0.4", |
@@ -197,4 +197,21 @@ const pluginTester = require('babel-plugin-tester') | ||
` | ||
}, | ||
{ | ||
title: 'class property', | ||
code: ` | ||
class Foo { | ||
// sitrep | ||
handleClick = (e) =>{ | ||
const foo = e.target.innerText; | ||
// some actions based on foo | ||
e.preventDefault() | ||
} | ||
} | ||
`, | ||
babelOptions: { | ||
babelrc: true, | ||
filename: __filename | ||
} | ||
} | ||
] | ||
}) |
@@ -27,3 +27,3 @@ module.exports = function (babel) { | ||
logCallee, | ||
thing.name && thing.name.includes('returnValue') | ||
thing.name && thing.name.indexOf('returnValue') > -1 | ||
? [t.stringLiteral('Return Value:'), thing] | ||
@@ -35,2 +35,8 @@ : thing.name ? [t.stringLiteral(`${thing.name}: `), thing] : [thing] | ||
function getName (path) { | ||
if (path.parentPath.isClassProperty()) { | ||
if (path.parentPath.node.key && t.isIdentifier(path.parentPath.node.key)) { | ||
return path.parentPath.node.key.name | ||
} | ||
} | ||
if (path.node.id && path.node.id.name) { | ||
@@ -53,6 +59,2 @@ return path.node.id.name | ||
function functionVisitor (functionPath, state) { | ||
if (functionPath.isArrowFunctionExpression()) { | ||
return | ||
} | ||
let name = getName(functionPath) | ||
@@ -102,3 +104,5 @@ functionPath | ||
variableDeclPath.insertAfter(t.expressionStatement(createLogStatement(dec.id))) | ||
variableDeclPath.insertAfter( | ||
t.expressionStatement(createLogStatement(dec.id)) | ||
) | ||
}) | ||
@@ -142,2 +146,15 @@ }, | ||
visitor: { | ||
Class (path, state) { | ||
path.traverse({ | ||
ClassProperty (path) { | ||
if (hasSitrepComments(getComments(path.node), state.opts.label)) { | ||
path.traverse({ | ||
Function (path) { | ||
functionVisitor(path, state) | ||
} | ||
}) | ||
} | ||
} | ||
}) | ||
}, | ||
Function (path, state) { | ||
@@ -144,0 +161,0 @@ if (hasSitrepComments(getComments(path.node), state.opts.label)) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
257835
26
837
7