How to use traceur - 10 common examples

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 frankwallis / plugin-typescript / test / compiler-load-spec.js View on Github external
var fs = require('fs');
var os = require('os');
var path = require('path');
var should  = require('should');
var Promise = require('bluebird');

var Traceur = require('traceur');

// Traceur will compile all JS aside from node modules
Traceur.require.makeDefault(function(filename) {
   return !(/node_modules/.test(filename));
});

var Compiler = require('../lib/incremental-compiler').IncrementalCompiler;
var formatErrors = require('../lib/format-errors').formatErrors;

var missingFile = '/somefolder/fixtures/program1/missing-file.ts';
var circularFile = require.resolve('./fixtures/circular/circular.ts');
var missingImport = require.resolve('./fixtures/program1/missing-import.ts');
var syntaxError = require.resolve('./fixtures/program1/syntax-error.ts');
var typeError = require.resolve('./fixtures/program1/type-error.ts');
var nestedTypeError = require.resolve('./fixtures/program1/nested-type-error.ts');
var noImports = require.resolve('./fixtures/program1/no-imports.ts');
var oneImport = require.resolve('./fixtures/program1/one-import.ts');
var ambientImportJs = require.resolve('./fixtures/ambients/ambient-import-js.ts');
var ambientImportTs = require.resolve('./fixtures/ambients/ambient-import-ts.ts');
github frankwallis / plugin-typescript / test / compiler-compile-spec.js View on Github external
var fs = require('fs');
var path = require('path');
var should  = require('should');
var Promise = require('bluebird');

var Traceur = require('traceur');

// Traceur will compile all JS aside from node modules
Traceur.require.makeDefault(function(filename) {
   return !(/node_modules/.test(filename));
});

var Compiler = require('../lib/incremental-compiler').IncrementalCompiler;
var formatErrors = require('../lib/format-errors').formatErrors;

var missingFile = '/somefolder/fixtures/program1/missing-file.ts';
var missingImport = require.resolve('./fixtures/program1/missing-import.ts');
var syntaxError = require.resolve('./fixtures/program1/syntax-error.ts');
var referenceSyntaxError = require.resolve('./fixtures/program1/ref-syntax-error.ts');
var typeError = require.resolve('./fixtures/program1/type-error.ts');
var nestedTypeError = require.resolve('./fixtures/program1/nested-type-error.ts');
var noImports = require.resolve('./fixtures/program1/no-imports.ts');
var oneImport = require.resolve('./fixtures/program1/one-import.ts');
var ambientReference = require.resolve('./fixtures/ambients/ambient-reference.ts');
var ambientImportJs = require.resolve('./fixtures/ambients/ambient-import-js.ts');
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 jspm / jspm-cli / traceur-compiler.js View on Github external
o.options
      o.file
      o.originalFile
    */

    traceur.options = o.options;
    traceur.options.sourceMaps = true;
    traceur.options.modules = 'parse';

    var reporter = new traceur.util.ErrorReporter();
    reporter.reportMessageInternal = function(location, kind, format, args) {
      process.stdout.write(JSON.stringify({ err: kind + '\n' + o.file + location }));
      process.exit(0);
    }

    var parser = new traceur.syntax.Parser(reporter, new traceur.syntax.SourceFile(o.file, o.source));
    var tree = parser.parseModule();

    var project = new traceur.semantics.symbols.Project(o.file);
    var transformer = new traceur.codegeneration.ProgramTransformer(reporter, project);
    tree = transformer.transform(tree);

    // generate source
    var sourceMapGenerator = new traceur.outputgeneration.SourceMapGenerator({ file: o.originalFile });
    var opt = { sourceMapGenerator: sourceMapGenerator };

    var source = traceur.outputgeneration.TreeWriter.write(tree, opt);

    process.stdout.write(JSON.stringify({
      source: source,
      sourceMap: opt.sourceMap
    }));
github jspm / jspm-cli / traceur-compiler.js View on Github external
process.stdin.on('end', function(data) {
  inData.push(data || '');
  try {
    var o = JSON.parse(inData.join(''));

    /*
      o.source
      o.options
      o.file
      o.originalFile
    */

    traceur.options = o.options;
    traceur.options.sourceMaps = true;
    traceur.options.modules = 'parse';

    var reporter = new traceur.util.ErrorReporter();
    reporter.reportMessageInternal = function(location, kind, format, args) {
      process.stdout.write(JSON.stringify({ err: kind + '\n' + o.file + location }));
      process.exit(0);
    }

    var parser = new traceur.syntax.Parser(reporter, new traceur.syntax.SourceFile(o.file, o.source));
    var tree = parser.parseModule();

    var project = new traceur.semantics.symbols.Project(o.file);
    var transformer = new traceur.codegeneration.ProgramTransformer(reporter, project);
    tree = transformer.transform(tree);

    // generate source
github jspm / jspm-cli / traceur-compiler.js View on Github external
process.stdin.on('end', function(data) {
  inData.push(data || '');
  try {
    var o = JSON.parse(inData.join(''));

    /*
      o.source
      o.options
      o.file
      o.originalFile
    */

    traceur.options = o.options;
    traceur.options.sourceMaps = true;
    traceur.options.modules = 'parse';

    var reporter = new traceur.util.ErrorReporter();
    reporter.reportMessageInternal = function(location, kind, format, args) {
      process.stdout.write(JSON.stringify({ err: kind + '\n' + o.file + location }));
      process.exit(0);
    }

    var parser = new traceur.syntax.Parser(reporter, new traceur.syntax.SourceFile(o.file, o.source));
    var tree = parser.parseModule();

    var project = new traceur.semantics.symbols.Project(o.file);
    var transformer = new traceur.codegeneration.ProgramTransformer(reporter, project);
    tree = transformer.transform(tree);

    // generate source
    var sourceMapGenerator = new traceur.outputgeneration.SourceMapGenerator({ file: o.originalFile });
github jspm / jspm-cli / traceur-compiler.js View on Github external
traceur.options = o.options;
    traceur.options.sourceMaps = true;
    traceur.options.modules = 'parse';

    var reporter = new traceur.util.ErrorReporter();
    reporter.reportMessageInternal = function(location, kind, format, args) {
      process.stdout.write(JSON.stringify({ err: kind + '\n' + o.file + location }));
      process.exit(0);
    }

    var parser = new traceur.syntax.Parser(reporter, new traceur.syntax.SourceFile(o.file, o.source));
    var tree = parser.parseModule();

    var project = new traceur.semantics.symbols.Project(o.file);
    var transformer = new traceur.codegeneration.ProgramTransformer(reporter, project);
    tree = transformer.transform(tree);

    // generate source
    var sourceMapGenerator = new traceur.outputgeneration.SourceMapGenerator({ file: o.originalFile });
    var opt = { sourceMapGenerator: sourceMapGenerator };

    var source = traceur.outputgeneration.TreeWriter.write(tree, opt);

    process.stdout.write(JSON.stringify({
      source: source,
      sourceMap: opt.sourceMap
    }));
  }
  catch(e) {
    process.stdout.write(JSON.stringify({ err: e.toString() }));
    return process.exit(0);
github jspm / jspm-cli / traceur-compiler.js View on Github external
var reporter = new traceur.util.ErrorReporter();
    reporter.reportMessageInternal = function(location, kind, format, args) {
      process.stdout.write(JSON.stringify({ err: kind + '\n' + o.file + location }));
      process.exit(0);
    }

    var parser = new traceur.syntax.Parser(reporter, new traceur.syntax.SourceFile(o.file, o.source));
    var tree = parser.parseModule();

    var project = new traceur.semantics.symbols.Project(o.file);
    var transformer = new traceur.codegeneration.ProgramTransformer(reporter, project);
    tree = transformer.transform(tree);

    // generate source
    var sourceMapGenerator = new traceur.outputgeneration.SourceMapGenerator({ file: o.originalFile });
    var opt = { sourceMapGenerator: sourceMapGenerator };

    var source = traceur.outputgeneration.TreeWriter.write(tree, opt);

    process.stdout.write(JSON.stringify({
      source: source,
      sourceMap: opt.sourceMap
    }));
  }
  catch(e) {
    process.stdout.write(JSON.stringify({ err: e.toString() }));
    return process.exit(0);
  }
});
process.stdin.resume();
github jspm / jspm-cli / traceur-compiler.js View on Github external
process.stdout.write(JSON.stringify({ err: kind + '\n' + o.file + location }));
      process.exit(0);
    }

    var parser = new traceur.syntax.Parser(reporter, new traceur.syntax.SourceFile(o.file, o.source));
    var tree = parser.parseModule();

    var project = new traceur.semantics.symbols.Project(o.file);
    var transformer = new traceur.codegeneration.ProgramTransformer(reporter, project);
    tree = transformer.transform(tree);

    // generate source
    var sourceMapGenerator = new traceur.outputgeneration.SourceMapGenerator({ file: o.originalFile });
    var opt = { sourceMapGenerator: sourceMapGenerator };

    var source = traceur.outputgeneration.TreeWriter.write(tree, opt);

    process.stdout.write(JSON.stringify({
      source: source,
      sourceMap: opt.sourceMap
    }));
  }
  catch(e) {
    process.stdout.write(JSON.stringify({ err: e.toString() }));
    return process.exit(0);
  }
});
process.stdin.resume();
github jspm / jspm-cli / traceur-compiler.js View on Github external
*/

    traceur.options = o.options;
    traceur.options.sourceMaps = true;
    traceur.options.modules = 'parse';

    var reporter = new traceur.util.ErrorReporter();
    reporter.reportMessageInternal = function(location, kind, format, args) {
      process.stdout.write(JSON.stringify({ err: kind + '\n' + o.file + location }));
      process.exit(0);
    }

    var parser = new traceur.syntax.Parser(reporter, new traceur.syntax.SourceFile(o.file, o.source));
    var tree = parser.parseModule();

    var project = new traceur.semantics.symbols.Project(o.file);
    var transformer = new traceur.codegeneration.ProgramTransformer(reporter, project);
    tree = transformer.transform(tree);

    // generate source
    var sourceMapGenerator = new traceur.outputgeneration.SourceMapGenerator({ file: o.originalFile });
    var opt = { sourceMapGenerator: sourceMapGenerator };

    var source = traceur.outputgeneration.TreeWriter.write(tree, opt);

    process.stdout.write(JSON.stringify({
      source: source,
      sourceMap: opt.sourceMap
    }));
  }
  catch(e) {
    process.stdout.write(JSON.stringify({ err: e.toString() }));