How to use the traceur.NodeCompiler 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 rolandjitsu / angular-lab / tools / build / ng.js View on Github external
return through.obj(function (file, enc, cb) {
        if (file.isNull()) {
			cb(null, file);
			return;
		}
		if (file.isStream()) {
            cb(new gutil.PluginError('ng:build', 'Streaming not supported'));
			return;
		}
        opts = opts || {};
		opts.traceurOptions = assign({
			inputSourceMap: file.sourceMap
		}, traceurDefaultOptions, opts.traceurOptions);
		try {
            var moduleName = parseModuleName(file, opts.namespace);
			var compiler = new traceur.NodeCompiler(opts.traceurOptions);
			var ret = compiler.compile(
                file.contents.toString(),
                // input/output file name must be the same to avoid sourceURL inside files https://github.com/google/traceur-compiler/issues/1748#issuecomment-75329693
                moduleName,
                moduleName,
                file.base
            );
			var sourceMap = file.sourceMap && compiler.getSourceMap();
            if (ret) file.contents = new Buffer(ret);
			if (sourceMap) {
                applySourceMap(file, sourceMap);
            }
			this.push(file);
		} catch (e) {
			this.emit('error', new gutil.PluginError('ng:build', Array.isArray(e) ? e.join('\n') : e, {
				fileName: file.path,
github ggoodman / plunker-run-plugin / adapters / transformers / es6.js View on Github external
var Fs = require("fs");
var Traceur = require("traceur");

var compileOptions = {
    annotations: true,
    memberVariables: true,
    modules: "instantiate",
    typeAssertions: false,
    // typeAssertionModule: 'rtts_assert/rtts_assert',
    types: true
};

var compiler = new Traceur.NodeCompiler(compileOptions);
var runtime = Fs.readFileSync(Traceur.RUNTIME_PATH, "utf8");

module.exports = {
  matches: /\.js$/,
  provides: ".es6.js",
  transform: function (request, reply) {
    try {
      var result = compiler.compile(request.content, request.path.replace(/\.es6\.js$/, ""));
      var response = {
        content: /*runtime + "\n\n" + */result,
        encoding: "utf8",
      };
    } catch (err) {
      
      return process.nextTick(function () {
        reply(err);
github greggman / HappyFunTimes / server / es6-support.js View on Github external
var compile = function(content, filename) {
    debug("compile: " + filename);
    var compiler = new traceur.NodeCompiler({
      filename: filename + ".src",
      sourceMaps: true,
      // etc other Traceur options
      modules: 'commonjs',
    });
    var src = compiler.compile(content);
    var mapName = filename + ".map";
    debug("adding srcmap: " + mapName);
    var srcMap = compiler.getSourceMap();
    srcMaps[mapName] = srcMap;
    return src;
  };
github aaronfrost / grunt-traceur / lib / compiler.js View on Github external
exports.compile = function(content, options) {
  // import lazzily as traceur pollutes the global namespace.
  var traceur = require('traceur');
  var sourceMap = '';
  var compiler, result;

  compiler = new traceur.NodeCompiler(getTraceurOptions(options));

  try {
    result = compiler.compile(content, options.sourceName, options.outputName);

    if (options.sourceMaps) {
      sourceMap = compiler.getSourceMap();
    }
  } catch (e) {
    throw new Error(e);
  }

  return [result, sourceMap];
};
github sindresorhus / gulp-traceur / index.js View on Github external
cb(null, file);
			return;
		}

		if (file.isStream()) {
			cb(new PluginError('gulp-traceur', 'Streaming not supported'));
			return;
		}

		options = Object.assign({
			modules: 'commonjs',
			inputSourceMap: file.sourceMap
		}, options);

		try {
			const compiler = new traceur.NodeCompiler(options);
			const ret = compiler.compile(file.contents.toString(), file.relative, file.relative, file.base);
			const sourceMap = file.sourceMap && compiler.getSourceMap();

			if (ret) {
				file.contents = Buffer.from(ret);
			}

			if (sourceMap) {
				applySourceMap(file, sourceMap);
			}

			this.push(file);
		} catch (err) {
			const msg = Array.isArray(err) ? err.join('\n') : err;
			this.emit('error', new PluginError('gulp-traceur', msg, {
				fileName: file.path,
github thlorenz / es6ify / compile.js View on Github external
exports = module.exports = function compileFile(file, contents, traceurOverrides) {
  var options = buildTraceurOptions(traceurOverrides);
  try{
    var compiler = new Compiler(options);

    var result = compiler.compile(contents, file, file);
  }catch(errors){
      return { source: null, error: errors[0] };
  }

  return {
      source: result,
      error: null
  };
};
github handsontable / hot-builder / lib / transformers / es6ify.js View on Github external
function compile(file, contents, traceurOverrides) {
  var options = buildTraceurOptions(traceurOverrides);

  try{
    var compiler = new Compiler(options);

    var result = compiler.compile(contents, file, file);
  }catch(errors){
    return { source: null, error: errors[0] };
  }

  return {
    source: result,
    error: null
  };
};
github karma-runner / karma-traceur-preprocessor / index.js View on Github external
return function(content, file, done) {
    log.debug('Processing "%s".', file.originalPath);
    file.path = transformPath(file.originalPath);
    var filename = file.originalPath;
    var transpiledContent;
    var compiler = new traceur.NodeCompiler(options);

    try {
      transpiledContent = compiler.compile(content, filename);
    } catch (e) {
      log.error(e);
      done(new Error('TRACEUR COMPILE ERROR\n', e.toString()));
    }

    if (compiler.getSourceMap() !== undefined) {
      var map = JSON.parse(compiler.getSourceMap());
      map.file = file.path;
      transpiledContent += '\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,';
      transpiledContent += new Buffer(JSON.stringify(map)).toString('base64') + '\n';
      file.sourceMap = map;
    }
    return done(null, transpiledContent);