How to use the traceur.Compiler function in traceur

To help you get started, we’ve selected a few traceur examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jspm / jspm-cli / lib / build.js View on Github external
.then(function() {
            if (!options.transpile)
              return;

            var traceur = require('traceur');

            traceur.options.sourceMaps = true;
            traceur.options.modules = 'instantiate';

            try {
              var compiler = new traceur.Compiler({
                moduleName: '',
                modules: 'instantiate'
              });

              source = compiler.compile(source, relFile, path.basename(relFile.replace(/\.js$/, '.src.js')));
              sourceMap = compiler.getSourceMap();
            }
            catch(e) {
              // an error in one compiled file doesn't stop all compilation

              if (!e.stack)
                compileErrors +=  + '\n';
              else
                compileErrors += e.stack + '\n' + relFile + ': Unable to transpile ES Module\n';
            }
          })
github google / traceur-compiler / third_party / es6-module-loader / system.js View on Github external
(function () {
        try {
          load.kind = 'declarative';

          var options = load.metadata.traceurOptions || {};
          options.modules = 'instantiate';

          var compiler = new traceur.Compiler(options);
          var tree = compiler.parse(load.source, load.address);
          depsList = getImports(tree);
          tree = compiler.transform(tree);
          source = compiler.write(tree);
          var sourceMap = compiler.getSourceMap();

          if (global.btoa && sourceMap)
            source += '\n//# sourceMappingURL=data:application/json;base64,' + btoa(unescape(encodeURIComponent(sourceMap))) + '\n';

          __eval(source, global, load);
        }
        catch(e) {
          if (e.name == 'SyntaxError' || e.name == 'TypeError')
            e.message = 'Evaluating ' + (load.name || load.address) + '\n\t' + e.message;
          throw e;
        }
github systemjs / builder / compilers / esm.js View on Github external
function remap(source, map, fileName) {
  var compiler = new traceur.Compiler();

  var tree = compiler.parse(source, fileName);

  tree = new TraceurImportNormalizeTransformer(map).transformAny(tree);

  return Promise.resolve({
    source: compiler.write(tree)
  });
}
exports.remap = remap;
github systemjs / builder / compilers / esm.js View on Github external
function remap(source, map, fileName) {
  var compiler = new traceur.Compiler();

  var tree = compiler.parse(source, fileName);

  tree = new TraceurImportNormalizeTransformer(map).transformAny(tree);

  return Promise.resolve({
    source: compiler.write(tree)
  });
}
exports.remap = remap;
github systemjs / builder / lib / get-deferred-imports.js View on Github external
return Promise.all(Object.keys(trace).map(function(name) {
    var load = trace[name];

    if (load.deferredImports) {
      deferredImports = deferredImports.concat(load.deferredImports);
      return;
    }

    var curDeferredImports = [];

    if (!load || load.conditional)
      return;

    var compiler = new traceur.Compiler({ script: load.metadata.format !== 'esm' });

    var tree = compiler.parse(load.source, load.path);

    var transformer = new DeferredImportsTransformer();

    tree = transformer.transformAny(tree);

    return Promise.all(transformer.imports.map(function(impt) {
      return builder.loader.normalize(impt)
      .then(function(moduleName) {
        var canonical = getCanonicalName(builder.loader, moduleName);

        curDeferredImports.push({
          name: canonical,
          parent: name
        });
github gocardless / es6-angularjs / script / lib / precompile.js View on Github external
function precompile(inFile, outFile, basePath, callback) {
  if (!traceurConfig) {
    loadConfig();
  }

  traceurConfig.moduleName = null;

  var compiler = new traceur.Compiler(traceurConfig);

  var sourceMapFile = outFile.replace(/\.js$/, '.map');

  fs.readFile(path.resolve(basePath, inFile), function(err, inSource) {
    if (err)
      return callback(err);

    var source, sourceMap;

    try {
      source = compiler.compile(inSource.toString(), '/' + inFile, path.basename(outFile));
      sourceMap = compiler.getSourceMap();  
    }
    catch(e) {
      return callback(e);
    }
github VadimDez / ngx-img-fallback / node_modules / systemjs-builder / compilers / esm.js View on Github external
function remap(source, map, fileName) {
  var compiler = new traceur.Compiler();

  var tree = compiler.parse(source, fileName);

  tree = new TraceurImportNormalizeTransformer(map).transformAny(tree);

  return Promise.resolve({
    source: compiler.write(tree)
  });
}
exports.remap = remap;