# acorn-has-side-effect

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

Latest version **1.0.0** (published 2015-01-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install acorn-has-side-effect
pnpm add acorn-has-side-effect
yarn add acorn-has-side-effect
bun add acorn-has-side-effect
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2015-01-17 |
| First published | 2015-01-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | ForbesLindesay |
| Maintainers | forbeslindesay |
| Keywords | acorn |

## Links

- npm: https://www.npmjs.com/package/acorn-has-side-effect
- Repository: https://github.com/ForbesLindesay/acorn-has-side-effect
- Issues: https://github.com/ForbesLindesay/acorn-has-side-effect/issues
- npm.io page: https://npm.io/package/acorn-has-side-effect

## Dependencies (1)

- [acorn](https://npm.io/package/acorn.md) ^0.11.0

## Recent versions

- 1.0.0 (latest) — 2015-01-17

## README

# 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](https://img.shields.io/travis/ForbesLindesay/acorn-has-side-effect/master.svg)](https://travis-ci.org/ForbesLindesay/acorn-has-side-effect)
[![Dependency Status](https://img.shields.io/gemnasium/ForbesLindesay/acorn-has-side-effect.svg)](https://gemnasium.com/ForbesLindesay/acorn-has-side-effect)
[![NPM version](https://img.shields.io/npm/v/acorn-has-side-effect.svg)](https://www.npmjs.org/package/acorn-has-side-effect)

## Installation

    npm install acorn-has-side-effect

## Usage

```js
'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

---
_Source: https://npm.io/package/acorn-has-side-effect · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
