Comparing version 0.0.8 to 0.0.9
{ | ||
"name": "traceur", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "Experimental ES6 to ES5 compiler", | ||
@@ -21,3 +21,3 @@ "keywords": [ | ||
}, | ||
"main": "./src/node/traceur.js", | ||
"main": "./src/node/api.js", | ||
"bin": { | ||
@@ -36,3 +36,4 @@ "traceur": "./traceur" | ||
"dependencies": { | ||
"commander": ">=1.1" | ||
"commander": ">=1.1", | ||
"q-io": "~1.10.6" | ||
}, | ||
@@ -44,4 +45,5 @@ "devDependencies": { | ||
"node-uuid": ">=1.4", | ||
"rsvp": ">=2.0" | ||
"rsvp": ">=2.0", | ||
"requirejs": "~2.1.9" | ||
} | ||
} |
@@ -112,1 +112,2 @@ // Copyright 2013 Traceur Authors. | ||
exports.compileToDirectory = compileToDirectory; | ||
exports.writeTreeToFile = writeTreeToFile; |
@@ -19,5 +19,5 @@ // Copyright 2013 Traceur Authors. | ||
* Wrap a single async function to make the callback optional and hook it to | ||
* trigger errback/callback on a Deferred object that it creates a promise | ||
* from, which it returns (this ignores the async function's return value). | ||
* This enables the use of await with the wrapped function. | ||
* trigger reject/resolve of the Promise, which it returns (this ignores the | ||
* async function's return value). This enables the use of await with the | ||
* wrapped function. | ||
* | ||
@@ -30,3 +30,7 @@ * @param {Function} fn Function to wrap. | ||
return function() { | ||
var deferred = new Deferred; | ||
var resolve, reject; | ||
var promise = new Promise(function(res, rej) { | ||
resolve = res; | ||
reject = rej; | ||
}); | ||
@@ -41,5 +45,5 @@ var args = [].slice.call(arguments); | ||
if (err) | ||
deferred.errback(err); | ||
reject(err); | ||
else | ||
deferred.callback(value); | ||
resolve(value); | ||
} | ||
@@ -61,3 +65,3 @@ | ||
return deferred.createPromise(); | ||
return promise; | ||
}; | ||
@@ -64,0 +68,0 @@ } |
@@ -19,3 +19,3 @@ // Copyright 2012 Traceur Authors. | ||
var path = require('path'); | ||
var NodeLoader = require('./NodeLoader.js'); | ||
var nodeLoader = require('./nodeLoader.js'); | ||
var normalizePath = require('./file-util.js').normalizePath; | ||
@@ -25,10 +25,10 @@ | ||
var InternalLoader = traceur.modules.internals.InternalLoader; | ||
var LoaderHooks = traceur.modules.internals.LoaderHooks; | ||
var Script = traceur.syntax.trees.Script; | ||
var Project = traceur.semantics.symbols.Project; | ||
var SourceFile = traceur.syntax.SourceFile | ||
var SourceMapGenerator = traceur.outputgeneration.SourceMapGenerator; | ||
var ModuleAnalyzer = traceur.semantics.ModuleAnalyzer; | ||
/** | ||
* @param {ErrorReporter} reporter | ||
* @param {Project} project | ||
* @param {Array.<ParseTree>} elements | ||
@@ -38,6 +38,8 @@ * @param {string|undefined} depTarget A valid depTarget means dependency | ||
*/ | ||
function InlineCodeLoader(reporter, project, elements, depTarget) { | ||
InternalLoader.call(this, reporter, project, new NodeLoader); | ||
function InlineCodeLoader(reporter, url, elements, depTarget) { | ||
var loaderHooks = new LoaderHooks(reporter, url); | ||
loaderHooks.fileLoader = nodeLoader; | ||
InternalLoader.call(this, loaderHooks); | ||
this.elements = elements; | ||
this.dirname = project.url; | ||
this.dirname = url; | ||
this.depTarget = depTarget && normalizePath(path.relative('.', depTarget)); | ||
@@ -93,4 +95,3 @@ this.codeUnitList = []; | ||
var elements = []; | ||
var project = new Project(basePath); | ||
var loader = new InlineCodeLoader(reporter, project, elements, depTarget); | ||
var loader = new InlineCodeLoader(reporter, basePath, elements, depTarget); | ||
@@ -111,4 +112,4 @@ function loadNext() { | ||
}, function() { | ||
console.error(codeUnit.loader.error); | ||
errback(codeUnit.loader.error); | ||
console.error(codeUnit.error); | ||
errback(codeUnit.error); | ||
}); | ||
@@ -127,4 +128,3 @@ } | ||
var elements = []; | ||
var project = new Project(basePath); | ||
var loader = new InlineCodeLoader(reporter, project, elements, depTarget); | ||
var loader = new InlineCodeLoader(reporter, basePath, elements, depTarget); | ||
@@ -131,0 +131,0 @@ filenames.forEach(function(filename) { |
@@ -16,4 +16,4 @@ // Copyright 2013 Traceur Authors. | ||
var traceur = require('./traceur.js'); | ||
var NodeLoader = require('./NodeLoader.js'); | ||
var nodeLoader = require('./nodeLoader.js'); | ||
traceur.modules.internals.InternalLoader.FileLoader = NodeLoader; | ||
traceur.modules.internals.InternalLoader.fileLoader = nodeLoader; |
@@ -36,2 +36,3 @@ // Copyright 2012 Traceur Authors. | ||
var $hasOwnProperty = $Object.prototype.hasOwnProperty; | ||
var $toString = $Object.prototype.toString; | ||
@@ -49,103 +50,2 @@ function nonEnum(value) { | ||
function polyfillString(String) { | ||
// Harmony String Extras | ||
// http://wiki.ecmascript.org/doku.php?id=harmony:string_extras | ||
$defineProperties(String.prototype, { | ||
startsWith: method(function(s) { | ||
return this.lastIndexOf(s, 0) === 0; | ||
}), | ||
endsWith: method(function(s) { | ||
var t = String(s); | ||
var l = this.length - t.length; | ||
return l >= 0 && this.indexOf(t, l) === l; | ||
}), | ||
contains: method(function(s) { | ||
return this.indexOf(s) !== -1; | ||
}), | ||
toArray: method(function() { | ||
return this.split(''); | ||
}), | ||
codePointAt: method(function(position) { | ||
/*! http://mths.be/codepointat v0.1.0 by @mathias */ | ||
var string = String(this); | ||
var size = string.length; | ||
// `ToInteger` | ||
var index = position ? Number(position) : 0; | ||
if (isNaN(index)) { | ||
index = 0; | ||
} | ||
// Account for out-of-bounds indices: | ||
if (index < 0 || index >= size) { | ||
return undefined; | ||
} | ||
// Get the first code unit | ||
var first = string.charCodeAt(index); | ||
var second; | ||
if ( // check if it’s the start of a surrogate pair | ||
first >= 0xD800 && first <= 0xDBFF && // high surrogate | ||
size > index + 1 // there is a next code unit | ||
) { | ||
second = string.charCodeAt(index + 1); | ||
if (second >= 0xDC00 && second <= 0xDFFF) { // low surrogate | ||
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae | ||
return (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000; | ||
} | ||
} | ||
return first; | ||
}) | ||
}); | ||
$defineProperties(String, { | ||
// 21.1.2.4 String.raw(callSite, ...substitutions) | ||
raw: method(function(callsite) { | ||
var raw = callsite.raw; | ||
var len = raw.length >>> 0; // ToUint | ||
if (len === 0) | ||
return ''; | ||
var s = ''; | ||
var i = 0; | ||
while (true) { | ||
s += raw[i]; | ||
if (i + 1 === len) | ||
return s; | ||
s += arguments[++i]; | ||
} | ||
}), | ||
// 21.1.2.2 String.fromCodePoint(...codePoints) | ||
fromCodePoint: method(function() { | ||
// http://mths.be/fromcodepoint v0.1.0 by @mathias | ||
var codeUnits = []; | ||
var floor = Math.floor; | ||
var highSurrogate; | ||
var lowSurrogate; | ||
var index = -1; | ||
var length = arguments.length; | ||
if (!length) { | ||
return ''; | ||
} | ||
while (++index < length) { | ||
var codePoint = Number(arguments[index]); | ||
if ( | ||
!isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity` | ||
codePoint < 0 || // not a valid Unicode code point | ||
codePoint > 0x10FFFF || // not a valid Unicode code point | ||
floor(codePoint) != codePoint // not an integer | ||
) { | ||
throw RangeError('Invalid code point: ' + codePoint); | ||
} | ||
if (codePoint <= 0xFFFF) { // BMP code point | ||
codeUnits.push(codePoint); | ||
} else { // Astral code point; split in surrogate halves | ||
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae | ||
codePoint -= 0x10000; | ||
highSurrogate = (codePoint >> 10) + 0xD800; | ||
lowSurrogate = (codePoint % 0x400) + 0xDC00; | ||
codeUnits.push(highSurrogate, lowSurrogate); | ||
} | ||
} | ||
return String.fromCharCode.apply(null, codeUnits); | ||
}) | ||
}); | ||
} | ||
// ### Symbols | ||
@@ -392,130 +292,2 @@ // | ||
/** | ||
* @param {Function} canceller | ||
* @constructor | ||
*/ | ||
function Deferred(canceller) { | ||
this.canceller_ = canceller; | ||
this.listeners_ = []; | ||
} | ||
function notify(self) { | ||
while (self.listeners_.length > 0) { | ||
var current = self.listeners_.shift(); | ||
var currentResult = undefined; | ||
try { | ||
try { | ||
if (self.result_[1]) { | ||
if (current.errback) | ||
currentResult = current.errback.call(undefined, self.result_[0]); | ||
} else { | ||
if (current.callback) | ||
currentResult = current.callback.call(undefined, self.result_[0]); | ||
} | ||
current.deferred.callback(currentResult); | ||
} catch (err) { | ||
current.deferred.errback(err); | ||
} | ||
} catch (unused) {} | ||
} | ||
} | ||
function fire(self, value, isError) { | ||
if (self.fired_) | ||
throw new Error('already fired'); | ||
self.fired_ = true; | ||
self.result_ = [value, isError]; | ||
notify(self); | ||
} | ||
Deferred.prototype = { | ||
constructor: Deferred, | ||
fired_: false, | ||
result_: undefined, | ||
createPromise: function() { | ||
return {then: this.then.bind(this), cancel: this.cancel.bind(this)}; | ||
}, | ||
callback: function(value) { | ||
fire(this, value, false); | ||
}, | ||
errback: function(err) { | ||
fire(this, err, true); | ||
}, | ||
then: function(callback, errback) { | ||
var result = new Deferred(this.cancel.bind(this)); | ||
this.listeners_.push({ | ||
deferred: result, | ||
callback: callback, | ||
errback: errback | ||
}); | ||
if (this.fired_) | ||
notify(this); | ||
return result.createPromise(); | ||
}, | ||
cancel: function() { | ||
if (this.fired_) | ||
throw new Error('already finished'); | ||
var result; | ||
if (this.canceller_) { | ||
result = this.canceller_(this); | ||
if (!result instanceof Error) | ||
result = new Error(result); | ||
} else { | ||
result = new Error('cancelled'); | ||
} | ||
if (!this.fired_) { | ||
this.result_ = [result, true]; | ||
notify(this); | ||
} | ||
} | ||
}; | ||
// System.get/set and @traceur/module gets overridden in @traceur/modules to | ||
// be more correct. | ||
function ModuleImpl(url, func, self) { | ||
this.url = url; | ||
this.func = func; | ||
this.self = self; | ||
this.value_ = null; | ||
} | ||
ModuleImpl.prototype = { | ||
get value() { | ||
if (this.value_) | ||
return this.value_; | ||
return this.value_ = this.func.call(this.self); | ||
} | ||
}; | ||
var modules = { | ||
'@traceur/module': { | ||
ModuleImpl: ModuleImpl, | ||
registerModule: function(url, func, self) { | ||
modules[url] = new ModuleImpl(url, func, self); | ||
}, | ||
getModuleImpl: function(url) { | ||
return modules[url].value; | ||
} | ||
} | ||
}; | ||
var System = { | ||
get: function(name) { | ||
var module = modules[name]; | ||
if (module instanceof ModuleImpl) | ||
return modules[name] = module.value; | ||
return module; | ||
}, | ||
set: function(name, object) { | ||
modules[name] = object; | ||
} | ||
}; | ||
function exportStar(object) { | ||
@@ -713,8 +485,4 @@ for (var i = 1; i < arguments.length; i++) { | ||
polyfillString(global.String); | ||
polyfillObject(global.Object); | ||
polyfillArray(global.Array); | ||
global.System = System; | ||
// TODO(arv): Don't export this. | ||
global.Deferred = Deferred; | ||
} | ||
@@ -725,3 +493,2 @@ | ||
global.$traceurRuntime = { | ||
Deferred: Deferred, | ||
createClass: createClass, | ||
@@ -728,0 +495,0 @@ defaultSuperCall: defaultSuperCall, |
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
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
20
8
813393
2
6
20698
+ Addedq-io@~1.10.6
+ Addedcollections@0.2.2(transitive)
+ Addedmime@1.2.11(transitive)
+ Addedmimeparse@0.1.4(transitive)
+ Addedq@0.9.7(transitive)
+ Addedq-io@1.10.9(transitive)
+ Addedqs@0.1.0(transitive)
+ Addedurl2@0.0.0(transitive)
+ Addedweak-map@1.0.0(transitive)