fizzygum-coffeescript-min
v1.0.0
Published
Minimal compile-only CoffeeScript for the browser — a size-trimmed fork of CoffeeScript 2.0.3 that emits byte-identical JavaScript for the supported subset. Built for the Fizzygum runtime.
Maintainers
Readme
fizzygum-coffeescript-min
A minimal, compile-only build of CoffeeScript for the browser — a size-trimmed fork of CoffeeScript 2.0.3 that emits byte-for-byte identical JavaScript to the stock compiler for the language subset it supports, in a single self-contained UMD ~19% smaller than the stock browser distribution and free of the Babel-ES5 shim.
Built for the Fizzygum runtime, which compiles its
~470 class sources in the browser at boot and needs exactly one function:
CoffeeScript.compile(source, { bare: true }). Everything the stock browser bundle ships for
the CLI / <script type="text/coffeescript"> / source-map use cases is dead weight in that
setting. This build removes it.
| | size (minified) | |---|---| | stock CoffeeScript 2.0.3 browser bundle (Babel-ES5) | 257,123 bytes | | fizzygum-coffeescript-min | ~208,554 bytes (−18.9%) |
Use
Browser — a classic <script> sets the CoffeeScript global:
<script src="dist/coffeescript.js"></script>
<script>
var js = CoffeeScript.compile('add = (a, b) -> a + b', { bare: true });
</script>Node — it is also require-able:
const CoffeeScript = require('fizzygum-coffeescript-min');
CoffeeScript.compile('x = 1', { bare: true }); // "var x;\n\nx = 1;\n"
CoffeeScript.VERSION; // "2.0.3"The public surface is deliberately just compile and VERSION. There is no run, eval,
register, nodes/tokens guarantees, source maps, or file I/O.
What's removed (and why it's safe)
Everything removed is unreachable for compile-only, { bare: true }, no-filename usage. Removals
were verified two ways: (1) a byte-identity check — the fork's emitted JS is diffed against
stock 2.0.3 for the whole corpus and must be empty; (2) empirical V8 coverage over a real
compile of the whole corpus, to confirm the removed code never executes.
- Whole modules never on the compile path:
browser.js(XHR loading,text/coffeescript,CoffeeScript.load/run,btoa),cake.js,command.js,optparse.js(CLI),repl.js,register.js(Noderequirehook). - Babel-ES5 transpilation — targets modern JS (current Chrome / Safari), not ES5.
- Source maps —
sourcemap.js,base64encode, the map-building insidecompile(), theinlineMap/sourceMap/transpilereturn branches. (The emittedjsnever depended on them.) Error.prepareStackTracemonkey-patch,getSourceMap,formatSourcePosition.- ES module declarations —
import/exportnode classes. - JSX / CSX — the
csxTokenlexer path + CSX codegen. - Literate CoffeeScript (
invertLiterate/isLiterate), shebang handling (checkShebangLine),baseFileName.
What's kept
The full CoffeeScript language: classes, inheritance and super, comprehensions and ranges,
destructuring, splats, default parameters, string interpolation and heredocs, existential ?,
switch, try/catch, do, the ** / %% operators, splice assignment, regexes, and the
complete error-reporting path (pretty syntax errors) — so a typo still produces a clear
message, not a crash. See test/corpus/ for the exercised subset.
Guarantee & verification
For the supported subset, compile(src, { bare: true }) is byte-for-byte identical to stock
CoffeeScript 2.0.3. npm run verify (also npm test) compiles every file in test/corpus/
with both this fork and the stock 2.0.3 devDependency and asserts equal output.
The fork intentionally supports only the CoffeeScript that Fizzygum uses. Source that relies on a removed feature (JSX,
import/export, source maps, literate) will not compile — that is by design, not a bug.
Re-deriving from source
This is a derivative of [email protected]'s compiled lib/coffeescript/*.js modules. The
fork keeps only the compile-path modules, applies the edits in patched/ (each file documents
its cut at the top), and bundles + minifies them into a single UMD:
npm install # pulls [email protected] (devDep) + terser
npm run build # writes dist/coffeescript.js (min) and dist/coffeescript.full.js
npm run verify # asserts byte-identity vs stock 2.0.3 over test/corpus/dist/ is committed so consumers need no build step; patched/ + build.js make the fork fully
reproducible.
License / provenance
MIT. This is a derivative work of CoffeeScript (Copyright © 2009–2018 Jeremy Ashkenas and
contributors, MIT). See LICENSE.
