Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

traceur

Package Overview
Dependencies
Maintainers
2
Versions
110
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

traceur - npm Package Compare versions

Comparing version 0.0.43 to 0.0.44

4

package.json
{
"name": "traceur",
"version": "0.0.43",
"version": "0.0.44",
"description": "ES6 to ES5 compiler",

@@ -48,3 +48,3 @@ "keywords": [

"semver": "2.2.1",
"traceur": "0.0.42",
"traceur": "0.0.43",
"promises-aplus-tests": "~2.0.4"

@@ -51,0 +51,0 @@ },

@@ -26,3 +26,3 @@ // Copyright 2013 Traceur Authors.

traceur.codegeneration.module.AttachModuleNameTransformer;
var ErrorReporter = traceur.util.TestErrorReporter;
var ErrorReporter = traceur.util.CollectingErrorReporter;
var FromOptionsTransformer = traceur.codegeneration.FromOptionsTransformer;

@@ -29,0 +29,0 @@ var PureES6Transformer = traceur.codegeneration.PureES6Transformer;

@@ -18,6 +18,6 @@ // Copyright 2013 Traceur Authors.

var path = require('path');
var flags;
var commandLine;
var cmdName = path.basename(process.argv[1]);
try {
flags = new (require('commander').Command)(cmdName);
commandLine = new (require('commander').Command)(cmdName);
} catch (ex) {

@@ -28,5 +28,6 @@ console.error('Commander.js is required for this to work. To install it ' +

}
flags.setMaxListeners(100);
commandLine.setMaxListeners(100);
var traceur = require('./traceur.js');
var interpret = require('./interpreter.js');

@@ -37,16 +38,22 @@ // The System object requires traceur, but we want it set for everything that

flags.option('--out <FILE>', 'Compile all input files into a single file');
flags.option('--referrer <name>',
'Prefix compiled code with System.referrName');
var rootSources = [];
commandLine.option('--script <fileName>', 'Parse as Script', function(fileName) {
rootSources.push({name: fileName, type: 'script'});
});
flags.option('--dir <INDIR> <OUTDIR>', 'Compile an input directory of modules into an output directory');
commandLine.option('--module <fileName>', 'Parse as Module', function(fileName) {
rootSources.push({name: fileName, type: 'module'});
});
flags.option('--sourcemap', 'Generate source maps');
flags.on('sourcemap', function() {
flags.sourceMaps = traceur.options.sourceMaps = true;
commandLine.option('--out <FILE>', 'Compile all input files into a single file');
commandLine.option('--dir <INDIR> <OUTDIR>', 'Compile an input directory of modules into an output directory');
commandLine.option('--sourcemap', 'Generate source maps');
commandLine.on('sourcemap', function() {
commandLine.sourceMaps = traceur.options.sourceMaps = true;
});
flags.option('--longhelp', 'Show all known options');
flags.on('longhelp', function() {
flags.help();
commandLine.option('--longhelp', 'Show all known options');
commandLine.on('longhelp', function() {
commandLine.help();
process.exit();

@@ -79,4 +86,4 @@ });

flags.option('-v, --version', 'Show version and exit');
flags.on('version', function() {
commandLine.option('-v, --version', 'Show version and exit');
commandLine.on('version', function() {
process.stdout.write(System.version.split('@')[1]);

@@ -86,3 +93,3 @@ processExit();

flags.on('--help', function() {
commandLine.on('--help', function() {
console.log(' Examples:');

@@ -96,110 +103,27 @@ console.log('');

traceur.options.addOptions(flags);
traceur.options.addOptions(commandLine);
flags.usage('[options] [files]');
commandLine.usage('[options] [files]');
// Override commander.js's optionHelp to filter out the Traceur feature flags
// from showing up in the help message.
var optionHelp = flags.optionHelp;
flags.optionHelp = function() {
if (!flags.longhelp) {
this.options = this.options.filter(function(command) {
var dashedName = command.long.slice(2);
return traceur.options.filterOption(dashedName);
});
}
return optionHelp.call(this);
}
/**
* HACK: Process arguments so that in interpret mode, commander.js only parses
* the flags, without the file name and anything past that. If an invalid flag
* is encountered, commander.js error reporting is emulated instead.
* @param {Array.<string>} argv
* @return {Array.<string>}
*/
function processArguments(argv) {
// Preserve the original.
argv = argv.slice();
var interpretMode = true;
for (var i = 2; i < argv.length; i++) {
var arg = argv[i], index;
if (arg === '--')
break;
// Normalize flags in-place.
if (arg.length > 2 && arg[0] === '-' && arg[1] !== '-') {
// TODO: Is this needed at all for traceur?
arg = arg.slice(1).split('').map(function(flag) {
return '-' + flag;
});
// Insert the normalized flags in argv.
argv.splice.apply(argv, [i, 1].concat(arg));
// Grab the first normalized flag and process it as usual.
arg = argv[i];
} else if (/^--/.test(arg) && (index = arg.indexOf('=')) !== -1) {
// Insert the flag argument in argv.
argv.splice(i + 1, 0, arg.slice(index + 1));
// Replace the flag with the stripped version and process it as usual.
arg = argv[i] = arg.slice(0, index);
commandLine.command('*').action(function() {
// The callback seems to receive a "command" at the end of arguments
for (var i = 0; i < arguments.length - 1; i++) {
rootSources.push({name: arguments[i], type: 'module'});
}
});
var option = flags.optionFor(arg);
if (option) {
if (arg === '--out' || arg === '--dir')
interpretMode = false;
commandLine.parse(process.argv);
if (option.required)
i++;
else if (option.optional) {
arg = argv[i + 1];
if (arg && arg[0] !== '-')
i++;
}
} else if (arg === '-h' || arg === '--help') {
// HACK: Special case for the implicit help flags, which can't have
// their own option, as --help would set flags.help to true, shadowing
// the flags.help() method.
} else if (arg[0] === '-') {
// HACK: Because commander.js has a flexible policy, this is the only
// reliable way of reporting invalid flags to the user, and it's limited
// to the first invalid flag encountered.
console.log('\n error: unknown option `%s\'\n', arg);
process.exit(1);
} else if (interpretMode) {
// Add a hint to stop commander.js from parsing following arguments.
// Note that this means that --out must come before any unknown flag as
// well as before any filename for it to be used as the out flag.
argv.splice(i, 0, '--');
// Save traceur flags for interpret.js.
argv.flags = argv.slice(2, i);
break;
}
}
return argv;
}
var argv = processArguments(process.argv);
flags.parse(argv);
var includes = traceur.options.scripts || [];
includes = includes.concat(flags.args);
if (!shouldExit && !includes.length) {
if (!shouldExit && !rootSources.length) {
// TODO: Start trepl
console.error('\n Error: At least one input file is needed');
flags.help();
commandLine.help();
process.exit(1);
}
var interpret = require('./interpreter.js');
var compiler = require('./compiler.js');
var compileToSingleFile = compiler.compileToSingleFile;
var compileToDirectory = compiler.compileToDirectory;
var out = flags.out;
var dir = flags.dir;
var out = commandLine.out;
var dir = commandLine.dir;
if (!shouldExit) {

@@ -209,12 +133,16 @@ if (out) {

if (isSingleFileCompile)
compileToSingleFile(out, includes, flags.sourceMaps);
compileToSingleFile(out, rootSources, commandLine.sourceMaps);
else
compileToDirectory(out, includes, flags.sourceMaps);
compileToDirectory(out, rootSources, commandLine.sourceMaps);
} else if (dir) {
var compileAllJsFilesInDir = require('./compile-single-file.js').compileAllJsFilesInDir;
compileAllJsFilesInDir(dir, includes[0], true);
if (rootSources.length !== 1)
throw new Error('Compile all in directory requires exactly one input filename');
var compileAllJsFilesInDir =
require('./compile-single-file.js').compileAllJsFilesInDir;
compileAllJsFilesInDir(dir, rootSources[0].name, true);
} else {
rootSources.forEach(function(obj) {
interpret(path.resolve(obj.name));
});
}
else {
interpret(path.resolve(includes[0]), includes.slice(1), argv.flags);
}
}

@@ -65,3 +65,4 @@ // Copyright 2013 Traceur Authors.

var resolvedIncludes = includes.map(function(include) {
return path.resolve(include);
include.name = path.resolve(include.name);
return include;
});

@@ -74,3 +75,4 @@

resolvedIncludes = resolvedIncludes.map(function(include) {
return normalizePath(path.relative(outputDir, include));
include.name = normalizePath(path.relative(outputDir, include.name));
return include;
});

@@ -82,2 +84,3 @@

}, function(err) {
console.error(err);
process.exit(1);

@@ -87,5 +90,5 @@ });

function compileToDirectory(outputFile, includes, useSourceMaps) {
function compileToDirectory(outputDir, includes, useSourceMaps) {
var reporter = new ErrorReporter();
var outputDir = path.resolve(outputFile);
var outputDir = path.resolve(outputDir);

@@ -101,3 +104,3 @@ var current = 0;

function(tree) {
var outputFile = path.join(outputDir, includes[current]);
var outputFile = path.join(outputDir, includes[current].name);
var sourceRoot = path.relative(path.dirname(outputFile), '.');

@@ -104,0 +107,0 @@ writeTreeToFile(tree, outputFile, useSourceMaps, sourceRoot);

@@ -60,3 +60,3 @@ // Copyright 2012 Traceur Authors.

function allLoaded(url, reporter, elements) {
function allLoaded(url, elements) {
return new Script(null, elements);

@@ -66,9 +66,10 @@ }

/**
* Compiles the files in "filenames" along with any associated modules, into a
* Compiles the files in "fileNamesAndTypes" along with any associated modules, into a
* single js file, in proper module dependency order.
*
* @param {Array.<string>} filenames The list of files to compile and concat.
* @param {Array.<Object>} fileNamesAndTypes The list of {name, type}
* to compile and concat; type is 'module' or 'script'
* @param {Object} options A container for misc options. 'depTarget' is the
* only currently available option, which results in the dependencies for
* 'filenames' being printed to stdout, with 'depTarget' as the target.
* 'fileNamesAndTypes' being printed to stdout, with 'depTarget' as the target.
* @param {ErrorReporter} reporter

@@ -80,3 +81,3 @@ * @param {Function} callback Callback used to return the result. A null result

*/
function inlineAndCompile(filenames, options, reporter, callback, errback) {
function inlineAndCompile(fileNamesAndTypes, options, reporter, callback, errback) {

@@ -102,4 +103,2 @@ var depTarget = options && options.depTarget;

var scriptsCount = options.scripts.length;
var loadCount = 0;

@@ -120,11 +119,11 @@ var elements = [];

function loadNext() {
var loadAsScript = scriptsCount && (loadCount < scriptsCount);
var doEvaluateModule = false;
var loadFunction = loader.import;
var name = filenames[loadCount];
if (loadAsScript) {
var input = fileNamesAndTypes[loadCount];
var name = input.name;
if (input.type === 'script') {
loadFunction = loader.loadAsScript;
} else {
name = name.replace(/\.js$/,'');
if (options.modules !== 'inline' && options.modules !== 'instantiate')
if (options.modules === 'register')
doEvaluateModule = true;

@@ -138,3 +137,3 @@ }

loadCount++;
if (loadCount < filenames.length) {
if (loadCount < fileNamesAndTypes.length) {
loadNext();

@@ -144,3 +143,3 @@ } else if (depTarget) {

} else {
var tree = allLoaded(basePath, reporter, elements);
var tree = allLoaded(basePath, elements);
callback(tree);

@@ -147,0 +146,0 @@ }

@@ -21,3 +21,3 @@ // Copyright 2013 Traceur Authors.

function interpret(filename, argv, flags) {
function interpret(filename) {
// Interpret the filename argument as a platform-independent,

@@ -24,0 +24,0 @@ // normalized module name.

@@ -28,12 +28,5 @@ // Copyright 2014 Traceur Authors.

global.System = System;
Reflect.global.System = System;
System.map = System.semverMap(System.version);
// If we are compiling into a package namespace, set up an alias table
// for the versions of the package.
var referrerName = traceur.options.referrer;
if (referrerName)
System.map = System.semverMap(referrerName);
else
System.map = System.semverMap(System.version);
module.exports = System;

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc