How to use the traceur.syntax 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 / 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 vojtajina / js2dart / src / class_transformer.js View on Github external
var traceur = require('traceur');
var ParseTreeTransformer = traceur.codegeneration.ParseTreeTransformer;

// var token = traceur.syntax.TokenType;
// var CONSTRUCTOR = token.CONSTRUCTOR;

var parseToken = traceur.syntax.trees.ParseTreeType;
var PROPERTY_METHOD_ASSIGNMENT = parseToken.PROPERTY_METHOD_ASSIGNMENT;
var MEMBER_EXPRESSION = parseToken.MEMBER_EXPRESSION;
var THIS_EXPRESSION = parseToken.THIS_EXPRESSION;
var BINARY_EXPRESSION = 'BINARY_EXPRESSION';
var EQUAL_EQUAL_EQUAL = traceur.syntax.TokenType.EQUAL_EQUAL_EQUAL;
var CONSTRUCTOR = traceur.syntax.PredefinedName.CONSTRUCTOR;

var VariableDeclarationList = traceur.syntax.trees.VariableDeclarationList;
var VariableStatement = traceur.syntax.trees.VariableStatement;

var Token = traceur.syntax.Token;
var propName = traceur.staticsemantics.propName;


var createVariableStatement = traceur.codegeneration.ParseTreeFactory.createVariableStatement;
var createCallExpression = traceur.codegeneration.ParseTreeFactory.createCallExpression;
var createIdentifierExpression = traceur.codegeneration.ParseTreeFactory.createIdentifierExpression;
var createArgumentList = traceur.codegeneration.ParseTreeFactory.createArgumentList;


var ClassFieldParseTree = require('./ast/class_field');
github tarruda / grunt-traceur-build / tasks / traceur_build.js View on Github external
// this hack is needed because the traceur developers have made the
// command line compiler modules private. without this we won't get
// the automatic dependency resolution done by parsing the modules
// 'import' statements.
try {
  var modPath = path.resolve('node_modules/grunt-traceur-build/node_modules/traceur/src/node/inline-module');
} catch (e) {
  var modPath = path.resolve('node_modules/traceur/src/node/inline-module');
}
var inlineAndCompileSync = require(modPath).inlineAndCompileSync;

var TreeWriter = traceur.outputgeneration.TreeWriter;
var SourceMapGenerator = traceur.outputgeneration.SourceMapGenerator;
var TestErrorReporter = traceur.util.TestErrorReporter;
var Project = traceur.semantics.symbols.Project;
var SourceFile = traceur.syntax.SourceFile;

var NAME = 'traceur_build';
var DESC =
  'Compiles ECMAScript 6 (harmony) files, optionally merging and ' +
  'generating source maps.';

function generateIncludeFile(files) {
  var rv = [];
  files.forEach(function(f) {
    rv.push('module ' + traceur.generateNameForUrl(f) + ' from "' + f + '"');
  });
  return rv.join('\n');
}

function wrapClosure(code, param, expression, sourceMapGenerator) {
    code = '(function(' + (param || 'global') + ') {\n' + code;
github vojtajina / js2dart / src / class_transformer.js View on Github external
var traceur = require('traceur');
var ParseTreeTransformer = traceur.codegeneration.ParseTreeTransformer;

// var token = traceur.syntax.TokenType;
// var CONSTRUCTOR = token.CONSTRUCTOR;

var parseToken = traceur.syntax.trees.ParseTreeType;
var PROPERTY_METHOD_ASSIGNMENT = parseToken.PROPERTY_METHOD_ASSIGNMENT;
var MEMBER_EXPRESSION = parseToken.MEMBER_EXPRESSION;
var THIS_EXPRESSION = parseToken.THIS_EXPRESSION;
var BINARY_EXPRESSION = 'BINARY_EXPRESSION';
var EQUAL_EQUAL_EQUAL = traceur.syntax.TokenType.EQUAL_EQUAL_EQUAL;
var CONSTRUCTOR = traceur.syntax.PredefinedName.CONSTRUCTOR;

var VariableDeclarationList = traceur.syntax.trees.VariableDeclarationList;
var VariableStatement = traceur.syntax.trees.VariableStatement;

var Token = traceur.syntax.Token;
var propName = traceur.staticsemantics.propName;


var createVariableStatement = traceur.codegeneration.ParseTreeFactory.createVariableStatement;
var createCallExpression = traceur.codegeneration.ParseTreeFactory.createCallExpression;
github bjoerge / react-es6-class / boilerplate / transpile-es6.js View on Github external
// ES5 source transform/transpiler based on the es6ify browserify transform by thlorenz

'use strict';

var traceur            =  require('traceur')
  , compile            =  traceur.codegeneration.Compiler.compile
  , Project            =  traceur.semantics.symbols.Project
  , ProjectWriter      =  traceur.outputgeneration.ProjectWriter
  , SourceFile         =  traceur.syntax.SourceFile
  , format             =  require('util').format
  , path               =  require('path')
  ;

+function initGlobalTraceurOptions() {
  [ 'arrayComprehension'
    , 'arrowFunctions'
    , 'classes'
    , 'defaultParameters'
    , 'destructuring'
    , 'forOf'
    , 'propertyMethods'
    , 'propertyNameShorthand'
    , 'templateLiterals'
    , 'restParameters'
    , 'spread'
github stealjs / steal-tools / lib / load / get_es_module_imports.js View on Github external
module.exports = function(load) {
	load.address = load.address || "anon" + (++anonCnt);

	var Parser = traceur.syntax.Parser;
	var SourceFile = traceur.syntax.SourceFile;

	var parser = new Parser(new SourceFile(load.address, load.source));
	var body = parser.parseModule();

	return getImports(body);
};
github stealjs / steal-tools / lib / load / get_es_module_imports.js View on Github external
module.exports = function(load) {
	load.address = load.address || "anon" + (++anonCnt);

	var Parser = traceur.syntax.Parser;
	var SourceFile = traceur.syntax.SourceFile;

	var parser = new Parser(new SourceFile(load.address, load.source));
	var body = parser.parseModule();

	return getImports(body);
};
github vojtajina / js2dart / src / ast / class_field.js View on Github external
var traceur = require('traceur');
var ParseTree = traceur.syntax.trees.ParseTree;

var CLASS_FIELD = 'CLASS_FIELD';

function ClassField(location, identifier, typeAnnotation) {
  this.location = location;
  this.identifier = identifier;
  this.typeAnnotation = typeAnnotation;
}

ClassField.prototype = Object.create(ParseTree.prototype);
ClassField.prototype.type = CLASS_FIELD;
ClassField.prototype.visit = function(visitor) {
  visitor.visitClassField(this);
};
ClassField.prototype.transform = function(transformer) {
  return this;
github tarruda / grunt-traceur-build / tasks / traceur_build.js View on Github external
}).map(function(filepath) {
    var sourceFile = new traceur.syntax.SourceFile(path.relative(cwd, filepath),
      grunt.file.read(filepath));
    project.addFile(sourceFile);
  });