-
Notifications
You must be signed in to change notification settings - Fork 398
Build System
The goal of the build system is to package all Shumway files into a single minified JavaScript file. The extension/firefox/build.js
script is responsible for this. You can run the build script using:
node build.js content/web/scripts.js
If you open up the scripts.js file you'll notice that it's just a regular JavaScript file. This file is parsed by the build.js
script which performs several steps:
- Replace identifiers:
$DEBUG
becomestrue
/false
, or$SHUMWAY_HOME
is replaced with the appropriate absolute path. (Note: All environment variables are made available and expanded in JavaScript files.) - Fold constant expressions:
1 + 1
becomes2
. - Fold logical expressions:
true || ...
becomestrue
. - Remove assertions:
assert(x, ...)
. - Replace
load(file | directory)
with the contents of the included file or those of the files in the specified directory. This process is recursive, so all the previous steps execute all over again.
The build script uses esprima to parse all JavaScript files, estransform to apply AST transformations on the parsed tree, and finally escodegen to serialize the AST. As an additional step, the build script can also call the closure compiler to further optimize the code. For instance if you write the following code:
if ($DEBUG) {
...
}
the build script may produce
if (false) {
...
}
and finally, the closure compiler removes the entire if
expression.
Mozilla 2019