Code Monkey home page Code Monkey logo

esomin's Introduction

esomin

Experiments in minifying with files that use some es5+ features, mainly for mozilla-based code, specifically, minifying Gaia apps.

Ideally, can use the AST parse tree from Reflect, then convert to code that at a minimum:

  • strips comments.

Nice to have features:

  • Keep line returns.
  • Allow for light mangling, does not need to take extraordinary measures.

Something that allows the following features:

  • arrow functions
  • template strings

How to run tests

ESOMINXPC=/path/to/xpcshell ./test.sh

Some basic tests, just confirms the files can be parsed and generated, and runs the generated file. The test just output strings, and current expectations for the output should look like this:

simple OK: hello something
arrow-func OK: hello something
template OK: hello apple
TEMPLATE-TAG OK: hello 15 WORLD 50

Dependencies

  1. escodegen:

    git clone --recursive [email protected]:Constellation/escodegen.git cd escodegen/ git checkout 1.4.1 npm install npm run-script build cp escodegen.browser.js ..

escodegen options

  1. esprima/harmony branch:

    Oct 18: https://github.com/ariya/esprima/blob/54f49ada8739b90f07a9197394dcbd3574596c81/esprima.js

Discarded

esmangle 1.0.1:

git clone --recursive [email protected]:Constellation/esmangle.git
cd esmangle
git checkout 1.0.1
npm install
make bundle
cp esmangle.js ..

Implementation notes

I wanted to use native SpiderMonkey Reflect.parse, as it stays current with the JS engine implementation, and it is likely the fastest parse option when in xpcshell. However, there is a mismatch between its output and what the escodegen/esmangle projects expect.

There is the Mozilla bug 913617 to bring them closer into alignment.

I tried just doing a rename fix (discarded/fixes.js) for ArrowFunctionExpression to ArrowExpression in escodegen, and while that got the arrow functions to work, the template strings still had problems. The Reflect code mentions quasis, and that breaks when given to escodegen.

So, I switched to using the esprima/harmony branch for parsing, and no more discarded/fixes.js use. That esprima branch does not have releases, so I just grabbed the latest as of the day I did this investigation.

I tried using esmangle, but it has problems, does not seem to be up to date with what esprima generates. I was using an actual release, 1.0.1. When trying to use its master, I could not generate a build locally from the cloned git repo. So skipping it for now, and just relying on escodegen.

So for now, just getting comment stripping.

esomin's People

Contributors

jrburke avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

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.