Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
acorn-has-side-effect
Advanced tools
A simple module to check whether an expression has any side effects
A simple module to check whether an expression has any side effects. This is aimed at being useful for writing optimising JavaScript compilers.
npm install acorn-has-side-effect
'use strict';
var assert = require('assert');
var hasSideEffect = require('./');
assert(hasSideEffect('x = 10') === true);
assert(hasSideEffect('x++') === true);
assert(hasSideEffect('x') === false);
assert(hasSideEffect('x', {strict: true}) === true);
assert(hasSideEffect('x.foo') === false);
assert(hasSideEffect('x.foo', {strict: true}) === true);
assert(hasSideEffect('this') === false);
assert(hasSideEffect('this', {strict: true}) === false);
assert(hasSideEffect('this.foo') === false);
assert(hasSideEffect('this.foo', {strict: true}) === true);
console.log('tests passed');
It assumes that property-access and variable-access should not count as a side effect, even though they technically could be because of property accessors and reference errors etc. For most purposes this should be fine, but it could go wrong in some rare circumstances. You can force it to treat even these nodes as having side effects by passing {strict: true}
for the options.
If you already have an AST, you can pass an acorn AST instead of a string for the source code.
MIT
FAQs
A simple module to check whether an expression has any side effects
We found that acorn-has-side-effect demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.