Comparing version 0.0.60 to 0.0.61
{ | ||
"name": "traceur", | ||
"version": "0.0.60", | ||
"version": "0.0.61", | ||
"description": "ES6 to ES5 compiler", | ||
@@ -25,2 +25,8 @@ "keywords": [ | ||
}, | ||
"files": [ | ||
"src/node/*.js", | ||
"bin/traceur.js", | ||
"bin/traceur-runtime.js", | ||
"traceur" | ||
], | ||
"scripts": { | ||
@@ -39,2 +45,3 @@ "test": "make test", | ||
"glob": "4.x", | ||
"regexpu": "0.2.1", | ||
"rsvp": "^3.0.13", | ||
@@ -52,3 +59,3 @@ "semver": "2.x" | ||
"semver": "2.x", | ||
"traceur": "0.0.59", | ||
"traceur": "0.0.60", | ||
"promises-aplus-tests": "2.x", | ||
@@ -55,0 +62,0 @@ "compat-table": "git+https://github.com/kangax/compat-table.git#gh-pages", |
@@ -26,3 +26,3 @@ [![Build Status](https://travis-ci.org/google/traceur-compiler.svg)](https://travis-ci.org/google/traceur-compiler) | ||
even try it out in your browser | ||
[here](http://google.github.io/traceur-compiler/demo/repl.html). | ||
[here](https://google.github.io/traceur-compiler/demo/repl.html). | ||
Just type in some code and see what Traceur produces. For an idea of what is | ||
@@ -29,0 +29,0 @@ available and what we have in the pipeline, see the |
@@ -24,9 +24,13 @@ // Copyright 2013 Traceur Authors. | ||
var traceur = require('./traceur.js'); | ||
var NodeCompilerModule = require('./NodeCompiler.js'); | ||
var NodeCompiler = NodeCompilerModule.NodeCompiler; | ||
var recursiveModuleCompile = require('./recursiveModuleCompile.js'); | ||
var compileAllJsFilesInDir = require('./compileAllJsFilesInDir.js'); | ||
var Compiler = traceur.Compiler; | ||
function compile(src, options) { | ||
return NodeCompilerModule.moduleToCommonJS(src, options).js; | ||
return new NodeCompiler(Compiler.commonJSOptions(options)).compile(src); | ||
} | ||
@@ -49,6 +53,5 @@ | ||
compile: compile, | ||
moduleToCommonJS: NodeCompilerModule.moduleToCommonJS, | ||
moduleToAmd: NodeCompilerModule.moduleToAmd, | ||
writeCompiledCodeToFile: NodeCompilerModule.writeCompiledCodeToFile, | ||
commonJSOptions: Compiler.commonJSOptions, | ||
amdOptions: Compiler.amdOptions, | ||
RUNTIME_PATH: RUNTIME_PATH | ||
}; |
@@ -128,2 +128,3 @@ // Copyright 2013 Traceur Authors. | ||
if (isSingleFileCompile) { | ||
commandOptions.filename = out; | ||
traceurAPI.recursiveModuleCompileToSingleFile(out, rootSources, | ||
@@ -146,10 +147,3 @@ commandOptions).then(function() { | ||
throw new Error('Compile all in directory requires exactly one input filename'); | ||
traceurAPI.compileAllJsFilesInDir(dir, rootSources[0].name, | ||
function(content) { | ||
var compiler = new traceurAPI.NodeCompiler(commandOptions); | ||
return { | ||
js: compiler.compile(content), | ||
sourceMap: compiler.getSourceMap() | ||
} | ||
}); | ||
traceurAPI.compileAllJsFilesInDir(dir, rootSources[0].name, commandOptions); | ||
} else { | ||
@@ -156,0 +150,0 @@ rootSources.forEach(function(obj) { |
@@ -17,29 +17,9 @@ // Copyright 2013 Traceur Authors. | ||
var glob = require("glob") | ||
var fs = require('fs'); | ||
var glob = require('glob'); | ||
var path = require('path'); | ||
var writeCompiledCodeToFile = | ||
require('./NodeCompiler.js').writeCompiledCodeToFile; | ||
var NodeCompiler = require('./NodeCompiler.js').NodeCompiler; | ||
function compileSingleFile(inputFilePath, outputFilePath, compile) { | ||
return fs.readFile(inputFilePath, function(err, contents) { | ||
if (err) | ||
throw new Error('While reading ' + inputFilePath + ': ' + err); | ||
var result = compile(contents.toString()); | ||
if (result.error) | ||
throw new Error(result.errors.join('\n')); | ||
writeCompiledCodeToFile(result.js, outputFilePath, result.sourceMap); | ||
}); | ||
} | ||
function compileAllJsFilesInDir(inputDir, outputDir, compile) { | ||
if (typeof compile !== 'function') | ||
throw new Error('Missing required function(string) -> result'); | ||
function compileAllJsFilesInDir(inputDir, outputDir, options) { | ||
inputDir = path.normalize(inputDir).replace(/\\/g, '/'); | ||
outputDir = path.normalize(outputDir).replace(/\\/g, '/'); | ||
glob(inputDir + '/**/*.js', {}, function (er, files) { | ||
@@ -51,3 +31,6 @@ if (er) | ||
var outputFilePath = inputFilePath.replace(inputDir, outputDir); | ||
compileSingleFile(inputFilePath, outputFilePath, compile); | ||
var compiler = new NodeCompiler(options); | ||
compiler.compileSingleFile(inputFilePath, outputFilePath, function(err) { | ||
throw new Error('While reading ' + inputFilePath + ': ' + err); | ||
}); | ||
}); | ||
@@ -54,0 +37,0 @@ }); |
@@ -29,3 +29,3 @@ // Copyright 2013 Traceur Authors. | ||
console.error(err.stack || err + ''); | ||
process.exit(8); | ||
process.exit(1); | ||
}); | ||
@@ -32,0 +32,0 @@ } |
@@ -23,11 +23,12 @@ // Copyright 2014 Traceur Authors. | ||
var path = require('path'); | ||
var traceur = require('./traceur.js'); | ||
var fs = require('fs'); | ||
var util = require('./file-util.js'); | ||
var writeFile = util.writeFile; | ||
var traceur = require('./traceur.js'); | ||
var Compiler = traceur.Compiler; | ||
function NodeCompiler(options) { | ||
Compiler.call(this, options); | ||
this.cwd = process.cwd(); | ||
function NodeCompiler(options, sourceRoot) { | ||
sourceRoot = sourceRoot || process.cwd(); | ||
Compiler.call(this, options, sourceRoot); | ||
} | ||
@@ -37,2 +38,3 @@ | ||
__proto__: Compiler.prototype, | ||
resolveModuleName: function(filename) { | ||
@@ -42,59 +44,42 @@ if (!filename) | ||
var moduleName = filename.replace(/\.js$/, ''); | ||
return path.relative(this.cwd, moduleName).replace(/\\/g,'/'); | ||
return path.relative(this.sourceRoot, moduleName).replace(/\\/g,'/'); | ||
}, | ||
sourceRootForFilename: function(filename) { | ||
return path.relative(path.dirname(filename), '.'); | ||
} | ||
}; | ||
/** | ||
* Use Traceur to Compile ES6 module source code to commonjs format. | ||
* | ||
* @param {string} content ES6 source code. | ||
* @param {Object=} options Traceur options. | ||
* @return {{js: string, errors: Array, sourceMap: string} Transpiled code. | ||
*/ | ||
function moduleToCommonJS(content, options) { | ||
var compiler = new NodeCompiler(Compiler.commonJSOptions(options)); | ||
return { | ||
js: compiler.compile(content), | ||
sourceMap: compiler.getSourceMap() | ||
}; | ||
} | ||
/** | ||
* Use Traceur to Compile ES6 module source code to amd format. | ||
* | ||
* @param {string} content ES6 source code. | ||
* @param {Object=} options Traceur options. | ||
* @return {{js: string, errors: Array, sourceMap: string} Transpiled code. | ||
*/ | ||
function moduleToAmd(content, options) { | ||
var compiler = new NodeCompiler(Compiler.amdOptions(options)); | ||
return { | ||
js: compiler.compile(content), | ||
sourceMap: compiler.getSourceMap() | ||
}; | ||
} | ||
sourceName: function(filename) { | ||
return path.relative(this.sourceRoot, filename); | ||
}, | ||
function getSourceMapFileName(name) { | ||
return name.replace(/\.js$/, '.map'); | ||
} | ||
writeTreeToFile: function(tree, filename) { | ||
var compiledCode = this.write(tree); | ||
var sourcemap = this.getSourceMap(); | ||
if (sourcemap) { | ||
// Assume that the .map and .js will be in the same subdirectory, | ||
// Use the rule from Source Map Revision 3: | ||
// If the generated code is associated with a script element and the | ||
// script element has a “src” attribute, the “src” attribute of the script | ||
// element will be the source origin. | ||
var sourceMapFilePath = path.basename(filename.replace(/\.js$/, '.map')); | ||
compiledCode += '\n//# sourceMappingURL=' + sourceMapFilePath + '\n'; | ||
writeFile(sourceMapFilePath, sourcemap); | ||
} | ||
writeFile(filename, compiledCode); | ||
}, | ||
function writeCompiledCodeToFile(compiledCode, filename, sourcemap) { | ||
var sourceMapFilePath; | ||
if (sourcemap) { | ||
sourceMapFilePath = getSourceMapFileName(filename); | ||
compiledCode += '\n//# sourceMappingURL=' + | ||
path.basename(sourceMapFilePath) + '\n'; | ||
compileSingleFile: function(inputFilePath, outputFilePath, errback) { | ||
fs.readFile(inputFilePath, function(err, contents) { | ||
if (err) { | ||
errback(err); | ||
return; | ||
} | ||
this.options_.filename = inputFilePath; | ||
this.writeTreeToFile(this.transform(this.parse(contents.toString())), | ||
outputFilePath); | ||
}.bind(this)); | ||
} | ||
writeFile(filename, compiledCode); | ||
if (sourcemap) | ||
writeFile(sourceMapFilePath, sourcemap); | ||
} | ||
}; | ||
module.exports = { | ||
NodeCompiler: NodeCompiler, | ||
moduleToCommonJS: moduleToCommonJS, | ||
moduleToAmd: moduleToAmd, | ||
writeCompiledCodeToFile: writeCompiledCodeToFile, | ||
NodeCompiler: NodeCompiler | ||
}; |
@@ -25,10 +25,5 @@ // Copyright 2012 Traceur Authors. | ||
var NodeCompiler = require('./NodeCompiler.js').NodeCompiler; | ||
var writeCompiledCodeToFile = | ||
require('./NodeCompiler.js').writeCompiledCodeToFile; | ||
var cwd = process.cwd(); | ||
function writeTreeToFile(tree, filename, compiler) { | ||
writeCompiledCodeToFile(compiler.write(tree), filename, compiler.getSourceMap()); | ||
} | ||
@@ -39,3 +34,2 @@ function recursiveModuleCompileToSingleFile(outputFile, includes, options) { | ||
var outputDir = path.dirname(resolvedOutputFile); | ||
var compiler = new NodeCompiler(options); | ||
@@ -48,2 +42,4 @@ // Resolve includes before changing directory. | ||
var compiler = new NodeCompiler(options, cwd + '/'); | ||
mkdirRecursive(outputDir); | ||
@@ -59,3 +55,3 @@ process.chdir(outputDir); | ||
recursiveModuleCompile(resolvedIncludes, options, function(tree) { | ||
writeTreeToFile(tree, resolvedOutputFile, compiler); | ||
compiler.writeTreeToFile(tree, resolvedOutputFile); | ||
process.chdir(cwd); | ||
@@ -80,3 +76,3 @@ resolve(); | ||
var outputFileName = path.join(outputDir, includes[current].name); | ||
writeTreeToFile(tree, outputFileName, compiler); | ||
compiler.writeTreeToFile(tree, outputFileName); | ||
current++; | ||
@@ -94,7 +90,4 @@ next(); | ||
var TraceurLoader = traceur.runtime.TraceurLoader; | ||
var InlineLoaderHooks = traceur.runtime.InlineLoaderHooks; | ||
var InlineLoaderCompiler = traceur.runtime.InlineLoaderCompiler; | ||
var Options = traceur.util.Options; | ||
var Script = traceur.syntax.trees.Script; | ||
var SourceFile = traceur.syntax.SourceFile | ||
var moduleStore = traceur.runtime.ModuleStore; | ||
@@ -140,7 +133,5 @@ | ||
var elements = []; | ||
var hooks = new InlineLoaderHooks(basePath, elements, | ||
nodeLoader, // Load modules using node fs. | ||
moduleStore); // Look up modules in our static module store | ||
var loaderCompiler = new InlineLoaderCompiler(elements); | ||
var loader = new TraceurLoader(hooks); | ||
var loader = new TraceurLoader(nodeLoader, basePath, loaderCompiler); | ||
@@ -164,3 +155,2 @@ function appendEvaluateModule(name, referrerName) { | ||
var moduleOption = optionsCopy.modules; | ||
if (input.type === 'script') { | ||
@@ -175,3 +165,2 @@ loadFunction = loader.loadAsScript; | ||
} | ||
var loadOptions = { | ||
@@ -183,3 +172,2 @@ referrerName: referrerName, | ||
function() { | ||
optionsCopy.modules = moduleOption; | ||
if (doEvaluateModule) | ||
@@ -194,3 +182,3 @@ appendEvaluateModule(name, referrerName); | ||
} else { | ||
var tree = hooks.toTree(basePath, elements); | ||
var tree = loaderCompiler.toTree(basePath, elements); | ||
callback(tree); | ||
@@ -197,0 +185,0 @@ } |
@@ -19,10 +19,8 @@ // Copyright 2014 Traceur Authors. | ||
var traceur = require('./traceur.js'); | ||
var path = require('path'); | ||
var nodeLoader = require('./nodeLoader.js'); | ||
var path = require('path'); | ||
var reporter = new traceur.util.ErrorReporter(); | ||
var LoaderHooks = traceur.runtime.LoaderHooks; | ||
var url = (path.resolve('./') + '/').replace(/\\/g, '/'); | ||
var loaderHooks = new LoaderHooks(reporter, url, nodeLoader); | ||
var System = new traceur.runtime.TraceurLoader(loaderHooks); | ||
var System = new traceur.runtime.TraceurLoader(nodeLoader, url); | ||
@@ -29,0 +27,0 @@ Reflect.global.System = System; |
@@ -28,2 +28,2 @@ // Copyright 2013 Traceur Authors. | ||
traceurAPI.compileAllJsFilesInDir(inputDir, outputDir, traceurAPI.moduleToAmd); | ||
traceurAPI.compileAllJsFilesInDir(inputDir, outputDir, traceurAPI.amdOptions()); |
@@ -28,2 +28,3 @@ // Copyright 2013 Traceur Authors. | ||
traceurAPI.compileAllJsFilesInDir(inputDir, outputDir, traceurAPI.moduleToCommonJS); | ||
traceurAPI.compileAllJsFilesInDir(inputDir, outputDir, | ||
traceurAPI.commonJSOptions()); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
High entropy strings
Supply chain riskContains high entropy strings. This could be a sign of encrypted data, leaked secrets or obfuscated code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1142996
29800
5
12
+ Addedregexpu@0.2.1
+ Addedamdefine@1.0.1(transitive)
+ Addedast-types@0.4.13(transitive)
+ Addedcls@0.1.5(transitive)
+ Addeddepd@1.0.1(transitive)
+ Addedesprima-fb@6001.1001.0-dev-harmony-fb(transitive)
+ Addedjsesc@0.5.0(transitive)
+ Addedprivate@0.1.8(transitive)
+ Addedrecast@0.7.5(transitive)
+ Addedregenerate@0.6.4(transitive)
+ Addedregexpu@0.2.1(transitive)
+ Addedregjsgen@0.2.0(transitive)
+ Addedregjsparser@0.1.5(transitive)
+ Addedsource-map@0.1.32(transitive)