Comparing version 0.0.7 to 0.0.8
{ | ||
"name": "traceur", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "Experimental ES6 to ES5 compiler", | ||
@@ -41,4 +41,5 @@ "keywords": [ | ||
"chai": ">=1.5", | ||
"node-uuid": ">=1.4" | ||
"node-uuid": ">=1.4", | ||
"rsvp": ">=2.0" | ||
} | ||
} |
@@ -26,10 +26,12 @@ // Copyright 2012 Traceur Authors. | ||
var $create = Object.create; | ||
var $defineProperty = Object.defineProperty; | ||
var $defineProperties = Object.defineProperties; | ||
var $freeze = Object.freeze; | ||
var $getOwnPropertyNames = Object.getOwnPropertyNames; | ||
var $getPrototypeOf = Object.getPrototypeOf; | ||
var $hasOwnProperty = Object.prototype.hasOwnProperty; | ||
var $getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; | ||
var $Object = Object; | ||
var $TypeError = TypeError; | ||
var $create = $Object.create; | ||
var $defineProperties = $Object.defineProperties; | ||
var $defineProperty = $Object.defineProperty; | ||
var $freeze = $Object.freeze; | ||
var $getOwnPropertyDescriptor = $Object.getOwnPropertyDescriptor; | ||
var $getOwnPropertyNames = $Object.getOwnPropertyNames; | ||
var $getPrototypeOf = $Object.getPrototypeOf; | ||
var $hasOwnProperty = $Object.prototype.hasOwnProperty; | ||
@@ -179,3 +181,3 @@ function nonEnum(value) { | ||
// the symbol object if all we have is the string key representing the symbol. | ||
var symbolValues = Object.create(null); | ||
var symbolValues = $create(null); | ||
@@ -251,4 +253,2 @@ function isSymbol(symbol) { | ||
Symbol.iterator = Symbol(); | ||
function toProperty(name) { | ||
@@ -315,3 +315,3 @@ if (isSymbol(name)) | ||
if (descriptor.enumerable) { | ||
descriptor = Object.create(descriptor, { | ||
descriptor = $create(descriptor, { | ||
enumerable: {value: false} | ||
@@ -522,7 +522,193 @@ }); | ||
function exportStar(object) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var names = $getOwnPropertyNames(arguments[i]); | ||
for (var j = 0; j < names.length; j++) { | ||
(function(mod, name) { | ||
$defineProperty(object, name, { | ||
get: function() { return mod[name]; }, | ||
enumerable: true | ||
}); | ||
})(arguments[i], names[j]); | ||
} | ||
} | ||
return object; | ||
} | ||
function toObject(value) { | ||
if (value == null) | ||
throw $TypeError(); | ||
return $Object(value); | ||
} | ||
function spread() { | ||
var rv = [], k = 0; | ||
for (var i = 0; i < arguments.length; i++) { | ||
var valueToSpread = toObject(arguments[i]); | ||
for (var j = 0; j < valueToSpread.length; j++) { | ||
rv[k++] = valueToSpread[j]; | ||
} | ||
} | ||
return rv; | ||
} | ||
function getPropertyDescriptor(object, name) { | ||
while (object !== null) { | ||
var result = $getOwnPropertyDescriptor(object, name); | ||
if (result) | ||
return result; | ||
object = $getPrototypeOf(object); | ||
} | ||
return undefined; | ||
} | ||
function superDescriptor(homeObject, name) { | ||
var proto = $getPrototypeOf(homeObject); | ||
if (!proto) | ||
throw $TypeError('super is null'); | ||
return getPropertyDescriptor(proto, name); | ||
} | ||
function superCall(self, homeObject, name, args) { | ||
var descriptor = superDescriptor(homeObject, name); | ||
if (descriptor) { | ||
if ('value' in descriptor) | ||
return descriptor.value.apply(self, args); | ||
if (descriptor.get) | ||
return descriptor.get.call(self).apply(self, args); | ||
} | ||
throw $TypeError("super has no method '" + name + "'."); | ||
} | ||
function superGet(self, homeObject, name) { | ||
var descriptor = superDescriptor(homeObject, name); | ||
if (descriptor) { | ||
if (descriptor.get) | ||
return descriptor.get.call(self); | ||
else if ('value' in descriptor) | ||
return descriptor.value; | ||
} | ||
return undefined; | ||
} | ||
function superSet(self, homeObject, name, value) { | ||
var descriptor = superDescriptor(homeObject, name); | ||
if (descriptor && descriptor.set) { | ||
descriptor.set.call(self, value); | ||
return; | ||
} | ||
throw $TypeError("super has no setter '" + name + "'."); | ||
} | ||
function getDescriptors(object) { | ||
var descriptors = {}, name, names = $getOwnPropertyNames(object); | ||
for (var i = 0; i < names.length; i++) { | ||
var name = names[i]; | ||
descriptors[name] = $getOwnPropertyDescriptor(object, name); | ||
} | ||
return descriptors; | ||
} | ||
// The next three functions are more or less identical to | ||
// ClassDefinitionEvaluation in the ES6 draft. | ||
function createClass(ctor, object, staticObject, superClass) { | ||
$defineProperty(object, 'constructor', { | ||
value: ctor, | ||
configurable: true, | ||
enumerable: false, | ||
writable: true | ||
}); | ||
if (arguments.length > 3) { | ||
if (typeof superClass === 'function') | ||
ctor.__proto__ = superClass; | ||
ctor.prototype = $create(getProtoParent(superClass), | ||
getDescriptors(object)); | ||
} else { | ||
ctor.prototype = object; | ||
} | ||
$defineProperty(ctor, 'prototype', {configurable: false, writable: false}); | ||
return $defineProperties(ctor, getDescriptors(staticObject)); | ||
} | ||
function getProtoParent(superClass) { | ||
if (typeof superClass === 'function') { | ||
var prototype = superClass.prototype; | ||
if ($Object(prototype) === prototype || prototype === null) | ||
return superClass.prototype; | ||
} | ||
if (superClass === null) | ||
return null; | ||
throw new TypeError(); | ||
} | ||
function defaultSuperCall(self, homeObject, args) { | ||
if ($getPrototypeOf(homeObject) !== null) | ||
superCall(self, homeObject, 'constructor', args); | ||
} | ||
var ST_NEWBORN = 0; | ||
var ST_EXECUTING = 1; | ||
var ST_SUSPENDED = 2; | ||
var ST_CLOSED = 3; | ||
var ACTION_SEND = 0; | ||
var ACTION_THROW = 1; | ||
function addIterator(object) { | ||
// This needs the non native defineProperty to handle symbols correctly. | ||
return defineProperty(object, Symbol.iterator, nonEnum(function() { | ||
return this; | ||
})); | ||
} | ||
function generatorWrap(generator) { | ||
return addIterator({ | ||
next: function(x) { | ||
switch (generator.GState) { | ||
case ST_EXECUTING: | ||
throw new Error('"next" on executing generator'); | ||
case ST_CLOSED: | ||
throw new Error('"next" on closed generator'); | ||
case ST_NEWBORN: | ||
if (x !== undefined) { | ||
throw $TypeError('Sent value to newborn generator'); | ||
} | ||
// fall through | ||
case ST_SUSPENDED: | ||
generator.GState = ST_EXECUTING; | ||
if (generator.moveNext(x, ACTION_SEND)) { | ||
generator.GState = ST_SUSPENDED; | ||
return {value: generator.current, done: false}; | ||
} | ||
generator.GState = ST_CLOSED; | ||
return {value: generator.yieldReturn, done: true}; | ||
} | ||
}, | ||
throw: function(x) { | ||
switch (generator.GState) { | ||
case ST_EXECUTING: | ||
throw new Error('"throw" on executing generator'); | ||
case ST_CLOSED: | ||
throw new Error('"throw" on closed generator'); | ||
case ST_NEWBORN: | ||
generator.GState = ST_CLOSED; | ||
throw x; | ||
case ST_SUSPENDED: | ||
generator.GState = ST_EXECUTING; | ||
if (generator.moveNext(x, ACTION_THROW)) { | ||
generator.GState = ST_SUSPENDED; | ||
return {value: generator.current, done: false}; | ||
} | ||
generator.GState = ST_CLOSED; | ||
return {value: generator.yieldReturn, done: true}; | ||
} | ||
} | ||
}); | ||
} | ||
function setupGlobals(global) { | ||
if (!global.Symbol) | ||
global.Symbol = Symbol; | ||
if (!global.Symbol.iterator) | ||
global.Symbol.iterator = Symbol(); | ||
global.Symbol = Symbol; | ||
global.Symbol.iterator = Symbol(); | ||
@@ -539,7 +725,15 @@ polyfillString(global.String); | ||
// This file is sometimes used without traceur.js so make it a new global. | ||
global.$traceurRuntime = { | ||
Deferred: Deferred, | ||
createClass: createClass, | ||
defaultSuperCall: defaultSuperCall, | ||
exportStar: exportStar, | ||
generatorWrap: generatorWrap, | ||
setProperty: setProperty, | ||
setupGlobals: setupGlobals, | ||
spread: spread, | ||
superCall: superCall, | ||
superGet: superGet, | ||
superSet: superSet, | ||
toObject: toObject, | ||
toProperty: toProperty, | ||
@@ -546,0 +740,0 @@ typeof: typeOf, |
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
820139
5
20774