Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/karimsa/iife-pop
Remove IIFEs at compile-time.
https://github.com/karimsa/iife-pop
babel iife javascript minification transpiler
Last synced: 15 days ago
JSON representation
Remove IIFEs at compile-time.
- Host: GitHub
- URL: https://github.com/karimsa/iife-pop
- Owner: karimsa
- License: mit
- Created: 2018-04-03T22:02:50.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-15T16:35:11.000Z (almost 6 years ago)
- Last Synced: 2025-01-23T00:04:54.194Z (15 days ago)
- Topics: babel, iife, javascript, minification, transpiler
- Language: TypeScript
- Homepage: http://npmjs.org/iife-pop
- Size: 251 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
iife-pop
Remove IIFE-s at compile-time.
## Motivation
The purpose of this babel plugin is to be able to evaluate & remove the existence of
an IIFE at compile-time where it is possible to do so. The idea is to simplify code as
much as possible at compile-time so that optimizations such as constant-folding can actually
reduce code even further than they currently do.As an example, look at this code:
```javascript
const myValue = (function (arg) {
switch (arg) {
case 'A':
return 0case 'B':
return 1case 'C':
return 2default:
return 3
}
}( 'some-value' ))
```Modern-day minifiers such as babel-minify and uglify-js are able to reduce this down to:
```javascript
const myValue=function(a){return'A'===a?0:'B'===a?1:'C'===a?2:3}('some-value');
```Though this saves quite a few bytes via mangling, constant folding is not able to take place
because of the IIFE. If we replace the IIFE in the original code, it might look something like this:```javascript
const _arg = 'some-value'
let _returnValueswitch (_arg) {
case 'A':
_returnValue = 0
breakcase 'B':
_returnValue = 1
breakcase 'C':
_returnValue = 2
breakdefault:
_returnValue = 3
break
}const myValue = _arg
```The code is the same, just without an IIFE. This new code can be minified down to:
```javascript
const myValue=3;
```Which saves a further 63 bytes in this case (~80%) - plus much less work for the runtime to do.
## License
Licensed under MIT license.
Copyright (C) 2018-present Karim Alibhai.