https://github.com/kcmr/babel-plugin-transform-block-scope-to-iife
Babel plugin to transform top level block scope to IIFE
https://github.com/kcmr/babel-plugin-transform-block-scope-to-iife
babel babel-plugin babel7
Last synced: 5 months ago
JSON representation
Babel plugin to transform top level block scope to IIFE
- Host: GitHub
- URL: https://github.com/kcmr/babel-plugin-transform-block-scope-to-iife
- Owner: kcmr
- License: mit
- Created: 2020-04-17T14:57:15.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T03:38:52.000Z (over 3 years ago)
- Last Synced: 2025-10-25T10:51:38.675Z (8 months ago)
- Topics: babel, babel-plugin, babel7
- Language: JavaScript
- Size: 1.87 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.com/kcmr/babel-plugin-transform-block-scope-to-iife)
[](http://commitizen.github.io/cz-cli/)
[](https://github.com/semantic-release/semantic-release)
[](https://codecov.io/gh/kcmr/babel-plugin-transform-block-scope-to-iife)

[](https://nodei.co/npm/babel-plugin-transform-block-scope-to-iife/)
# babel-plugin-transform-block-scope-to-iife
Replaces brackets used as scope in a file by an IIFE.
This prevents exposing variables in `window` when `const` or `let` are transformed to `var` after transpiling to ES5.
**Input:**
```js
{
const { Element } = Polymer;
}
```
**Output:**
```js
(function () {
const {
Element
} = Polymer;
})();
```
## Install
```
npm i babel-plugin-transform-block-scope-to-iife
```
## Usage
### With a configuration file (`.babelrc`)
```json
{
"plugins": [
["babel-plugin-transform-block-scope-to-iife"]
]
}
```
### Via Node API
```js
require("@babel/core").transform("code", {
plugins: ["babel-plugin-transform-block-scope-to-iife"],
});
```
## License
This project is licensed under the [MIT License](LICENSE).