Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
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;
// 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'
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');
// - rename constructor (name of the class - default Dart constructor)
// - collect fields (set in the constructor) and define them as class fields
function ClassTransformer() {
ParseTreeTransformer.call(this);
// Transform multi-var declarations, into multiple statements:
// var x, y;
// ==>
// var x;
// var y;
// TODO(vojta): move this into a separate transformer.
f.src.filter(function(filepath) {
if (!grunt.file.exists(filepath)) {
grunt.log.warn('Source file "' + filepath + '" not found.');
return false;
} else {
return true;
}
}).map(function(filepath) {
var sourceFile = new traceur.syntax.SourceFile(path.relative(cwd, filepath),
grunt.file.read(filepath));
project.addFile(sourceFile);
});
currentDir = process.cwd();
process.chdir(cwd);
asts = traceur.codegeneration.Compiler.compile(reporter, project);
process.chdir(currentDir);
if (reporter.hadError()) {
grunt.log.error('Compilation error!');
reporter.errors.forEach(function(e) {
grunt.log.error(e);
});
return false;
}
asts.keys().forEach(function(file) {
var ast, code, treeWriteOpts, sourceMapGenerator;
var sourceMapDest, sourceMapRoot, sourceMapConfig;
var outFile = f.dest;
var outDir = path.dirname(outFile);