# babel-plugin-hot-swap-declarative-modules

> Enables hot swaps for modules with declarative structures

Latest version **1.1.1** (published 2016-03-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install babel-plugin-hot-swap-declarative-modules
pnpm add babel-plugin-hot-swap-declarative-modules
yarn add babel-plugin-hot-swap-declarative-modules
bun add babel-plugin-hot-swap-declarative-modules
```

## 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.1.1 |
| Published | 2016-03-11 |
| First published | 2016-03-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Mark Finger |
| Maintainers | markfinger |

## Links

- npm: https://www.npmjs.com/package/babel-plugin-hot-swap-declarative-modules
- Repository: https://github.com/markfinger/babel-plugin-hot-swap-declarative-modules
- Homepage: https://github.com/markfinger/babel-plugin-hot-swap-declarative-modules#readme
- Issues: https://github.com/markfinger/babel-plugin-hot-swap-declarative-modules/issues
- npm.io page: https://npm.io/package/babel-plugin-hot-swap-declarative-modules

## Recent versions

- 1.1.1 (latest) — 2016-03-11
- 1.1.0 — 2016-03-11
- 1.0.0 — 2016-03-05

## README

# babel-plugin-hot-swap-declarative-modules

A babel plugin that enables hot swaps for declarative modules by inserting
`module.hot.accept()` at the top of the file.

Unlike `react-hot-loader` or `react-transform-hmr`, this plugin does not aim to
transition state between hot swaps. Instead, it simply aims to remove boilerplate.
Works best with a code-base that consolidates state into a single location.


## Installation

```
npm install --save babel-plugin-hot-swap-declarative-modules
```

Add `"hot-swap-declarative-modules"` to the plugins in your `.babelrc`:

```
{
  "plugins": [
    "hot-swap-declarative-modules"
  ]
}
```


## Caveats & Explanation

The structural scan is quite naive and scan does not traverse beyond the
most superficial level, so false positives are not the most difficult thing
to achieve.

Currently, the scan involves a simple iteration over the root of the module
and bails if it encounters anything but es2015 import/export declarations,
variable declarations (including var, let and const), class declarations or
function declarations.

If the iteration completes without encountering a non-declarative item, it
injects a `module.hot.accept` call. The `accept` call is placed at the top
of the file so that synchronous failures during evaluation of dependencies
does not prevent a module from accepting further hot swaps.

An example of the language features that are inferred as declarative is

```js
import a from './a';
export {b} from './b';

const c = 'c';

export const d = c + 'd';

export default function() {
  // ...
}

export class e extends a {
  // ...
}
```

An example of the language features that are inferred as non-declarative is

```
a();

if (b > 10) {
  // ...
}

const c = {};
c.d = 'd';
```

In short: conditionals, global variables, property assignments and function
calls should be avoided at the root level.


## Exceptions

Mindful of assisting with debugging, calls to the `console` object's properties
are assumed to be declarative.

---
_Source: https://npm.io/package/babel-plugin-hot-swap-declarative-modules · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
