Giter Site home page Giter Site logo

Comments (1)

lifthrasiir avatar lifthrasiir commented on May 25, 2024

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")) avoids return but VARIABLES should be unique, limiting the optimization possibility. A variant using var 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 be undefined, 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.