Skip to content

Options for Compiling

sseering edited this page Aug 31, 2017 · 16 revisions

Various options control which EcmaScript features are allowed in the source and what kind of output will be generated. The compile options are enumerated in Options.js. You can experiment with the options in the REPL page using the Options control in the upper right corner.

The command line (./traceur --help )supports these options by using --optionName, as well as a few more options:

  Usage: traceur [options] [files]

  Options:

    -h, --help              output usage information
    --out <FILE>            Compile all input files into a single file
    --dir <INDIR> <OUTDIR>  Compile an input directory of modules into an output directory
    --source-maps           Generate source maps
    --longhelp              Show all known options
    -v, --version           Show version and exit
    --experimental          Turns on all experimental features
    --script <fileName>     Parse as Script (must precede modules)

  Examples:

    $ traceur a.js [args]
    $ traceur --out compiled.js b.js c.js
    $ traceur --dir indir outdir

The [files] arguments should just be the 'root' modules, traceur will pull the rest. So for example if A.js requires B.js requires C.js, only list A.js on the command line.

Options in the Browser

To set options when compiling in the browser, use metadata.traceurOptions, e.g.:

<script>
  // Create the System object
  window.System = new traceur.runtime.BrowserTraceurLoader();
  // Set some experimental options
  var metadata = {
    traceurOptions: {
      properTailCalls: true,
      symbols: true,
      arrayComprehension: true,
      asyncFunctions: true,
      asyncGenerators: exponentiation,
      forOn: true,
      generatorComprehension: true
    }
  };
  // Load your module
  System.import('./myModule.js', {metadata: metadata}).catch(function(ex) {
    console.error('Import failed', ex.stack || ex);
  });
</script>

Options for Modules

The default format option is 'bootstrap'.

  • modules='amd': each input module creates an output file in AMD format. eg traceur --dir src/util test-amd/ --modules=amd
  • modules='commonjs': each input module creates an output file in ?
  • modules='instantiate': for systemjs bundling.
  • modules='inline': All dependencies of the root modules and/or scripts are compiled into a long script that creates modules upon execution then runs the dependents.
    • outputLanguage='es6': Preserve's ES6 formatting during inline. traceur --modules=inline --outputLanguage=es6 --out ./out/some-lib.js -- ./src/root.js
  • modules='bootstrap': All dependencies of the root modules and/or scripts are compiled in to functions that register the modules then execute any scripts.

The --moduleName <string> option allows you to set the __moduleName value; use "+" on the command line or true in code to cause the __moduleName to be the input file name. This option is not normally required.