Comments (1)
I've experimented with multiple implementation strategies:
- Insert
delete VARIABLE;
s at the beginning of the input. This turned out to be unworkable if the variable was only used locally and got hoisted (delete f; function f() { ... }
will be incorrect for example). So this workaround only works when we do the escape analysis, which is unreasonable for Roadroller. - Insert
delete VARIABLE;
s right before the actual eval. This is less invalid than before but still can cause a problem if there is other uncompressed code around. I'm not sure if we should support this mode or not though. eval(((A='COMPRESSED DATA', VARIABLES...) => { VAR=INIT; ...; return c })())
was very lengthy.eval(eval("let A='COMPRESSED DATA'," + [...'VARIABLES'] + "; VAR=INIT; ...; c"))
avoidsreturn
but VARIABLES should be unique, limiting the optimization possibility. A variant usingvar
would allow duplicates but pollutes the global scope.eval(Function("A='COMPRESSED DATA'", ...'VARIABLES', "VAR=INIT; ...; return c")())
still has the same problem but seems to be a bit smaller.eval(Function("A='COMPRESSED DATA'", ...'SOME VARIABLES', "VAR=INIT", "...; return c")())
combines initial assignments with argument definitions.eval(Function("[A='COMPRESSED DATA'", ...']VARIABLES', "...; return c")([], INIT...))
eliminates initial assignments by reusing arguments. The first variable has to beundefined
, hence a weird argument definition (translates to[A=...,],V,A,R,I,A,B,L,E,S
). This seems to be the best alternative so far, only ~25B larger than before. (But see below.)
Some of these experiments required another variable renaming, and honestly I'm sick of it. So the next step is to make variable names fully configurable.
from roadroller.
Related Issues (20)
- Make the compressor only produce the estimated number of bytes used during optimization
- Reuse the memory in the wasm compressor
- Uncompressed input
- Configurable output format
- New output format: Seven-bit coding (`-F7`)
- New output format: Single-byte encoding (`-F8l1` or `-F8cyrl`)
- New output format: Self-XHR/Fetch (`-F8xhr`, `-F8fetch`)
- Better support for larger inputs HOT 1
- Source map support
- Abbreviate non-identifier tokens
- Length-reducing preprocessor
- Adhere to Content Security Policy? HOT 3
- decoder size is saved 2bytes
- console report error
- Build a rollup plugin? HOT 1
- suggestion of decoder HOT 1
- Whitespace between math operators
- parcel plugin
- --uncompressed-only option for fair comparisson when output is single JS
- RangeError with -M 1024
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from roadroller.