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

babel-plugin-sitrep

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-sitrep - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

2

package.json
{
"name": "babel-plugin-sitrep",
"version": "1.2.0",
"version": "1.2.1",
"description": "Log all assignments and the return value of a function with a simple comment",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -172,4 +172,29 @@ const pluginTester = require('babel-plugin-tester')

}
},
{
title: 'function has a for loop',
code: `
// sitrep
function test() {
var sum = 0;
for (var i = 0; i < 5; i++) {
sum = sum + i;
}
return sum;
}
`
},
{
title: 'function has a for-of loop',
code: `
// sitrep
function test(arr) {
var sum = 0;
for (const value of arr) {
sum += value;
}
}
`
}
]
})

@@ -50,9 +50,9 @@ module.exports = function (babel) {

function functionVisitor (path, state) {
if (path.isArrowFunctionExpression()) {
function functionVisitor (functionPath, state) {
if (functionPath.isArrowFunctionExpression()) {
return
}
let name = getName(path)
path
let name = getName(functionPath)
functionPath
.get('body')

@@ -68,3 +68,3 @@ .unshiftContainer(

let didWriteGroupEnd = false
path.traverse({
functionPath.traverse({
AssignmentExpression (path) {

@@ -75,4 +75,8 @@ path.insertAfter(

},
VariableDeclaration (path) {
const decls = path.node.declarations
VariableDeclaration (variableDeclPath) {
if (!variableDeclPath.parentPath.isBlockStatement()) {
return
}
const decls = variableDeclPath.node.declarations
decls.forEach(dec => {

@@ -84,3 +88,3 @@ if (t.isPattern(dec.id)) {

.forEach(prop => {
path.insertAfter(
variableDeclPath.insertAfter(
t.expressionStatement(

@@ -99,14 +103,14 @@ t.callExpression(logCallee, [

path.insertAfter(t.expressionStatement(createLogStatement(dec.id)))
variableDeclPath.insertAfter(t.expressionStatement(createLogStatement(dec.id)))
})
},
ReturnStatement (path) {
const id = path.scope.generateUidIdentifier('returnValue')
path.insertBefore(
ReturnStatement (returnPath) {
const id = returnPath.scope.generateUidIdentifier('returnValue')
returnPath.insertBefore(
t.variableDeclaration('var', [
t.variableDeclarator(id, path.node.argument)
t.variableDeclarator(id, returnPath.node.argument)
])
)
path.insertBefore(
returnPath.insertBefore(
t.expressionStatement(

@@ -119,7 +123,7 @@ t.callExpression(createGroupCallee(true, state.opts.collapsed), [

didWriteGroupEnd = true
path.node.argument = id
returnPath.node.argument = id
}
})
if (!didWriteGroupEnd) {
path
functionPath
.get('body')

@@ -126,0 +130,0 @@ .pushContainer(

Sorry, the diff of this file is not supported yet

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