Socket
Socket
Sign inDemoInstall

acorn-has-side-effect

Package Overview
Dependencies
1
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    acorn-has-side-effect

A simple module to check whether an expression has any side effects


Version published
Weekly downloads
1
Maintainers
1
Install size
2.63 MB
Created
Weekly downloads
 

Readme

Source

acorn-has-side-effect

A simple module to check whether an expression has any side effects. This is aimed at being useful for writing optimising JavaScript compilers.

Build Status Dependency Status NPM version

Installation

npm install acorn-has-side-effect

Usage

'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.

License

MIT

Keywords

FAQs

Last updated on 17 Jan 2015

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.

Install

Related posts

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