-
-
Save mattmccray/3916195 to your computer and use it in GitHub Desktop.
/usr/bin/time dart2js -ooutput/dart.js source/simple.dart | |
3.30 real 3.01 user 0.25 sys | |
/usr/bin/time tsc --out output/typescript.js --sourcemap source/simple.ts | |
0.98 real 0.86 user 0.10 sys | |
/usr/bin/time coffee -p source/simple.coffee > output/coffee.js | |
0.18 real 0.14 user 0.02 sys | |
/usr/bin/time haxe -cp source/ -main Simple -js output/haxe.js --dead-code-elimination --js-modern -debug | |
0.05 real 0.04 user 0.01 sys | |
/usr/bin/time jsx --executable web --enable-source-map --output output/jsx.js source/simple.jsx | |
0.42 real 0.35 user 0.05 sys |
(function() { | |
var Simple; | |
Simple = (function() { | |
function Simple(name) { | |
this.name = name != null ? name : "default"; | |
} | |
Simple.prototype.greet = function(who) { | |
return "Greetings " + who + ", I'm " + this.name + "!"; | |
}; | |
Simple.main = function() { | |
var s; | |
s = new Simple("Flynn"); | |
return console.log(s.greet("Program")); | |
}; | |
return Simple; | |
})(); | |
Simple.main(); | |
}).call(this); |
// Generated by dart2js, the Dart to JavaScript compiler. | |
// The code supports the following hooks: | |
// dartPrint(message) - if this function is defined it is called | |
// instead of the Dart [print] method. | |
// dartMainRunner(main) - if this function is defined, the Dart [main] | |
// method will not be invoked directly. | |
// Instead, a closure that will invoke [main] is | |
// passed to [dartMainRunner]. | |
function Isolate() {} | |
init(); | |
var $$ = {}; | |
var $ = Isolate.$isolateProperties; | |
$$.StringBufferImpl = {"": | |
["_buffer", "_length"], | |
"super": "Object", | |
get$length: function() { | |
return this._length; | |
}, | |
isEmpty$0: function() { | |
return this._length === 0; | |
}, | |
add$1: function(obj) { | |
var str = $.toString(obj); | |
if (str == null || $.isEmpty(str) === true) | |
return this; | |
$.add$1(this._buffer, str); | |
this._length = $.add(this._length, $.get$length(str)); | |
return this; | |
}, | |
clear$0: function() { | |
this._buffer = $.ListImplementation_List(null); | |
this._length = 0; | |
return this; | |
}, | |
toString$0: function() { | |
if ($.get$length(this._buffer) === 0) | |
return ''; | |
if ($.get$length(this._buffer) === 1) | |
return $.index(this._buffer, 0); | |
var result = $.StringImplementation_concatAll(this._buffer); | |
$.clear(this._buffer); | |
$.add$1(this._buffer, result); | |
return result; | |
}, | |
StringBufferImpl$1: function(content$) { | |
this.clear$0(); | |
this.add$1(content$); | |
} | |
}; | |
$$.ArgumentError = {"": | |
["message"], | |
"super": "Object", | |
toString$0: function() { | |
var t1 = this.message; | |
if (!(t1 == null)) | |
return 'Illegal argument(s): ' + $.S(t1); | |
return 'Illegal argument(s)'; | |
} | |
}; | |
$$.IndexOutOfRangeException = {"": | |
["_value"], | |
"super": "Object", | |
toString$0: function() { | |
return 'IndexOutOfRangeException: ' + $.S(this._value); | |
} | |
}; | |
$$.NullPointerException = {"": | |
["functionName", "arguments"], | |
"super": "Object", | |
toString$0: function() { | |
var t1 = this.functionName; | |
if (t1 == null) | |
return this.get$exceptionName(); | |
else | |
return $.S(this.get$exceptionName()) + ' : method: \'' + $.S(t1) + '\'\n' + 'Receiver: null\n' + 'Arguments: ' + $.S(this.arguments); | |
}, | |
get$exceptionName: function() { | |
return 'NullPointerException'; | |
} | |
}; | |
$$.NoMoreElementsException = {"": | |
[], | |
"super": "Object", | |
toString$0: function() { | |
return 'NoMoreElementsException'; | |
} | |
}; | |
$$.UnsupportedOperationException = {"": | |
["_message"], | |
"super": "Object", | |
toString$0: function() { | |
return 'UnsupportedOperationException: ' + this._message; | |
} | |
}; | |
$$.Object = {"": | |
[], | |
"super": "", | |
operator$eq$1: function(other) { | |
return this === other; | |
}, | |
toString$0: function() { | |
return $.Primitives_objectToString(this); | |
} | |
}; | |
$$.ListIterator = {"": | |
["i", "list"], | |
"super": "Object", | |
hasNext$0: function() { | |
return this.i < this.list.length; | |
}, | |
next$0: function() { | |
if (this.hasNext$0() !== true) | |
throw $.$$throw($.NoMoreElementsException$()); | |
var value = this.list[this.i]; | |
this.i = this.i + 1; | |
return value; | |
} | |
}; | |
$$.Closure = {"": | |
[], | |
"super": "Object", | |
toString$0: function() { | |
return 'Closure'; | |
} | |
}; | |
$$.Simple = {"": | |
["name"], | |
"super": "Object", | |
greet$1: function(who) { | |
return 'Greetings ' + who + ', I\'m ' + this.name + '!'; | |
} | |
}; | |
$$.Maps__emitMap_anon = {"": | |
["result_3", "box_0", "visiting_2"], | |
"super": "Closure", | |
call$2: function(k, v) { | |
var t1 = this.box_0; | |
if (t1.first_1 !== true) | |
$.add$1(this.result_3, ', '); | |
t1.first_1 = false; | |
t1 = this.result_3; | |
var t2 = this.visiting_2; | |
$.Collections__emitObject(k, t1, t2); | |
$.add$1(t1, ': '); | |
$.Collections__emitObject(v, t1, t2); | |
} | |
}; | |
$.S = function(value) { | |
var res = $.toString(value); | |
if (!(typeof res === 'string')) | |
throw $.$$throw($.ArgumentError$(value)); | |
return res; | |
}; | |
$.StringBuffer_StringBuffer = function(content$) { | |
return $.StringBufferImpl$(content$); | |
}; | |
$.gt$slow = function(a, b) { | |
if ($.checkNumbers(a, b)) | |
return a > b; | |
return a.operator$gt$1(b); | |
}; | |
$.checkGrowable = function(list, reason) { | |
if (!!(list.fixed$length)) | |
throw $.$$throw($.UnsupportedOperationException$(reason)); | |
}; | |
$.$$throw = function(ex) { | |
if (ex == null) | |
ex = $.CTC; | |
var jsError = new Error(); | |
jsError.name = ex; | |
jsError.description = ex; | |
jsError.dartException = ex; | |
jsError.toString = $.toStringWrapper.call$0; | |
throw jsError; | |
}; | |
$.iterator = function(receiver) { | |
if ($.isJsArray(receiver)) | |
return $.ListIterator$(receiver); | |
return receiver.iterator$0(); | |
}; | |
$.ArgumentError$ = function(message) { | |
return new $.ArgumentError(message); | |
}; | |
$.NullPointerException$ = function(functionName, arguments$) { | |
return new $.NullPointerException(functionName, arguments$); | |
}; | |
$.eqB = function(a, b) { | |
if (a == null) | |
return b == null; | |
if (b == null) | |
return false; | |
if (typeof a === "object") | |
if (!!a.operator$eq$1) | |
return a.operator$eq$1(b) === true; | |
return a === b; | |
}; | |
$.add$1 = function(receiver, value) { | |
if ($.isJsArray(receiver)) { | |
$.checkGrowable(receiver, 'add'); | |
receiver.push(value); | |
return; | |
} | |
return receiver.add$1(value); | |
}; | |
$.Collections__emitCollection = function(c, result, visiting) { | |
$.add$1(visiting, c); | |
var isList = typeof c === 'object' && c !== null && (c.constructor === Array || !!c.is$List); | |
$.add$1(result, isList ? '[' : '{'); | |
for (var t1 = $.iterator(c), first = true; t1.hasNext$0() === true;) { | |
var t2 = t1.next$0(); | |
if (!first) | |
$.add$1(result, ', '); | |
$.Collections__emitObject(t2, result, visiting); | |
first = false; | |
} | |
$.add$1(result, isList ? ']' : '}'); | |
$.removeLast(visiting); | |
}; | |
$.Primitives_newList = function(length$) { | |
if (length$ == null) | |
return new Array(); | |
if (!(typeof length$ === 'number' && Math.floor(length$) === length$) || length$ < 0) | |
throw $.$$throw($.ArgumentError$(length$)); | |
var result = new Array(length$); | |
result.fixed$length = true; | |
return result; | |
}; | |
$.set$length = function(receiver, newLength) { | |
if ($.isJsArray(receiver)) { | |
$.checkNull(newLength); | |
if (newLength < 0) | |
throw $.$$throw($.IndexOutOfRangeException$(newLength)); | |
$.checkGrowable(receiver, 'set length'); | |
receiver.length = newLength; | |
} else | |
receiver.set$length(newLength); | |
return newLength; | |
}; | |
$.Primitives_printString = function(string) { | |
if (typeof dartPrint == "function") { | |
dartPrint(string); | |
return; | |
} | |
if (typeof window == "object") { | |
if (typeof console == "object") | |
console.log(string); | |
return; | |
} | |
if (typeof print == "function") { | |
print(string); | |
return; | |
} | |
throw 'Unable to print message: ' + String(string); | |
}; | |
$.toStringWrapper = function() { | |
return $.toString(this.dartException); | |
}; | |
$.checkNum = function(value) { | |
if (!(typeof value === 'number')) { | |
$.checkNull(value); | |
throw $.$$throw($.ArgumentError$(value)); | |
} | |
return value; | |
}; | |
$.get$length = function(receiver) { | |
if (typeof receiver === 'string' || $.isJsArray(receiver)) | |
return receiver.length; | |
else | |
return receiver.get$length(); | |
}; | |
$.constructorNameFallback = function(object) { | |
var constructor$ = object.constructor; | |
if (typeof(constructor$) === 'function') { | |
var name$ = constructor$.name; | |
if (typeof name$ === 'string') | |
var t1 = !(name$ === '') && !(name$ === 'Object') && !(name$ === 'Function.prototype'); | |
else | |
t1 = false; | |
if (t1) | |
return name$; | |
} | |
var string = Object.prototype.toString.call(object); | |
return string.substring(8, string.length - 1); | |
}; | |
$.toString = function(value) { | |
if (typeof value == "object" && value !== null) | |
if ($.isJsArray(value)) | |
return $.Collections_collectionToString(value); | |
else | |
return value.toString$0(); | |
if (value === 0 && (1 / value) < 0) | |
return '-0.0'; | |
if (value == null) | |
return 'null'; | |
if (typeof value == "function") | |
return 'Closure'; | |
return String(value); | |
}; | |
$.IndexOutOfRangeException$ = function(_value) { | |
return new $.IndexOutOfRangeException(_value); | |
}; | |
$.index = function(a, index) { | |
if (typeof a == "string" || a.constructor === Array) { | |
var key = index >>> 0; | |
if (key === index && key < a.length) | |
return a[key]; | |
} | |
return $.index$slow(a, index); | |
}; | |
$.substring$2 = function(receiver, startIndex, endIndex) { | |
$.checkNum(startIndex); | |
var length$ = receiver.length; | |
if (endIndex == null) | |
endIndex = length$; | |
$.checkNum(endIndex); | |
if (startIndex < 0) | |
throw $.$$throw($.IndexOutOfRangeException$(startIndex)); | |
if ($.gtB(startIndex, endIndex)) | |
throw $.$$throw($.IndexOutOfRangeException$(startIndex)); | |
if ($.gtB(endIndex, length$)) | |
throw $.$$throw($.IndexOutOfRangeException$(endIndex)); | |
return $.substringUnchecked(receiver, startIndex, endIndex); | |
}; | |
$.StringBufferImpl$ = function(content$) { | |
var t1 = new $.StringBufferImpl(null, null); | |
t1.StringBufferImpl$1(content$); | |
return t1; | |
}; | |
$.UnsupportedOperationException$ = function(_message) { | |
return new $.UnsupportedOperationException(_message); | |
}; | |
$.removeLast = function(receiver) { | |
if ($.isJsArray(receiver)) { | |
$.checkGrowable(receiver, 'removeLast'); | |
if ($.get$length(receiver) === 0) | |
throw $.$$throw($.IndexOutOfRangeException$(-1)); | |
return receiver.pop(); | |
} | |
return receiver.removeLast$0(); | |
}; | |
$.gtB = function(a, b) { | |
return typeof a === 'number' && typeof b === 'number' ? a > b : $.gt$slow(a, b) === true; | |
}; | |
$.Simple$ = function(name$) { | |
return new $.Simple(name$); | |
}; | |
$.ltB = function(a, b) { | |
return typeof a === 'number' && typeof b === 'number' ? a < b : $.lt$slow(a, b) === true; | |
}; | |
$.isJsArray = function(value) { | |
return !(value == null) && value.constructor === Array; | |
}; | |
$.StringImplementation_concatAll = function(strings) { | |
return $.stringJoinUnchecked($.StringImplementation__toJsStringArray(strings), ''); | |
}; | |
$.substring$1 = function(receiver, startIndex) { | |
if (!(typeof receiver === 'string')) | |
return receiver.substring$1(startIndex); | |
return $.substring$2(receiver, startIndex, null); | |
}; | |
$.clear = function(receiver) { | |
if (!$.isJsArray(receiver)) | |
return receiver.clear$0(); | |
$.set$length(receiver, 0); | |
}; | |
$.checkNull = function(object) { | |
if (object == null) | |
throw $.$$throw($.NullPointerException$(null, $.CTC0)); | |
return object; | |
}; | |
$.charCodeAt = function(receiver, index) { | |
if (typeof receiver === 'string') { | |
if (index < 0) | |
throw $.$$throw($.IndexOutOfRangeException$(index)); | |
if (index >= receiver.length) | |
throw $.$$throw($.IndexOutOfRangeException$(index)); | |
return receiver.charCodeAt(index); | |
} else | |
return receiver.charCodeAt$1(index); | |
}; | |
$.Primitives_objectToString = function(object) { | |
return 'Instance of \'' + $.S($.Primitives_objectTypeName(object)) + '\''; | |
}; | |
$.Primitives_objectTypeName = function(object) { | |
var name$ = $.constructorNameFallback(object); | |
if ($.eqB(name$, 'Object')) { | |
var decompiled = String(object.constructor).match(/^\s*function\s*(\S*)\s*\(/)[1]; | |
if (typeof decompiled === 'string') | |
name$ = decompiled; | |
} | |
return $.charCodeAt(name$, 0) === 36 ? $.substring$1(name$, 1) : name$; | |
}; | |
$.lt$slow = function(a, b) { | |
if ($.checkNumbers(a, b)) | |
return a < b; | |
return a.operator$lt$1(b); | |
}; | |
$.Collections__emitObject = function(o, result, visiting) { | |
if (typeof o === 'object' && o !== null && (o.constructor === Array || !!o.is$Collection)) | |
if ($.Collections__containsRef(visiting, o)) | |
$.add$1(result, typeof o === 'object' && o !== null && (o.constructor === Array || !!o.is$List) ? '[...]' : '{...}'); | |
else | |
$.Collections__emitCollection(o, result, visiting); | |
else if (typeof o === 'object' && o !== null && !!o.is$Map) | |
if ($.Collections__containsRef(visiting, o)) | |
$.add$1(result, '{...}'); | |
else | |
$.Maps__emitMap(o, result, visiting); | |
else | |
$.add$1(result, o); | |
}; | |
$.Maps__emitMap = function(m, result, visiting) { | |
var t1 = {}; | |
$.add$1(visiting, m); | |
$.add$1(result, '{'); | |
t1.first_1 = true; | |
m.forEach$1(new $.Maps__emitMap_anon(result, t1, visiting)); | |
$.add$1(result, '}'); | |
$.removeLast(visiting); | |
}; | |
$.checkNumbers = function(a, b) { | |
if (typeof a === 'number') | |
if (typeof b === 'number') | |
return true; | |
else { | |
$.checkNull(b); | |
throw $.$$throw($.ArgumentError$(b)); | |
} | |
return false; | |
}; | |
$.main = function() { | |
$.print($.Simple$('Flyn').greet$1('Program')); | |
}; | |
$.StringImplementation__toJsStringArray = function(strings) { | |
if (typeof strings !== 'object' || strings === null || (strings.constructor !== Array || !!strings.immutable$list) && !strings.is$JavaScriptIndexingBehavior) | |
return $.StringImplementation__toJsStringArray$bailout(1, strings); | |
$.checkNull(strings); | |
var length$ = strings.length; | |
if ($.isJsArray(strings)) { | |
for (var i = 0; i < length$; ++i) { | |
if (i >= strings.length) | |
throw $.ioore(i); | |
var string = strings[i]; | |
$.checkNull(string); | |
if (!(typeof string === 'string')) | |
throw $.$$throw($.ArgumentError$(string)); | |
} | |
var array = strings; | |
} else { | |
array = $.ListImplementation_List(length$); | |
for (i = 0; i < length$; ++i) { | |
if (i >= strings.length) | |
throw $.ioore(i); | |
string = strings[i]; | |
$.checkNull(string); | |
if (!(typeof string === 'string')) | |
throw $.$$throw($.ArgumentError$(string)); | |
array[i] = string; | |
} | |
} | |
return array; | |
}; | |
$.ListImplementation_List = function(length$) { | |
return $.Primitives_newList(length$); | |
}; | |
$.index$slow = function(a, index) { | |
if (typeof a === 'string' || $.isJsArray(a)) { | |
if (!(typeof index === 'number' && Math.floor(index) === index)) { | |
if (!(typeof index === 'number')) | |
throw $.$$throw($.ArgumentError$(index)); | |
if (!($.truncate(index) === index)) | |
throw $.$$throw($.ArgumentError$(index)); | |
} | |
if ($.ltB(index, 0) || $.geB(index, $.get$length(a))) | |
throw $.$$throw($.IndexOutOfRangeException$(index)); | |
return a[index]; | |
} | |
return a.operator$index$1(index); | |
}; | |
$.add = function(a, b) { | |
return typeof a === 'number' && typeof b === 'number' ? a + b : $.add$slow(a, b); | |
}; | |
$.truncate = function(receiver) { | |
return receiver < 0 ? $.ceil(receiver) : $.floor(receiver); | |
}; | |
$.print = function(object) { | |
if (typeof object === 'string') | |
$.Primitives_printString(object); | |
else | |
$.Primitives_printString($.toString(object)); | |
}; | |
$.ceil = function(receiver) { | |
return Math.ceil(receiver); | |
}; | |
$.ListIterator$ = function(list) { | |
return new $.ListIterator(0, list); | |
}; | |
$.Collections__containsRef = function(c, ref) { | |
for (var t1 = $.iterator(c); t1.hasNext$0() === true;) { | |
var t2 = t1.next$0(); | |
if (t2 == null ? ref == null : t2 === ref) | |
return true; | |
} | |
return false; | |
}; | |
$.Collections_collectionToString = function(c) { | |
var result = $.StringBuffer_StringBuffer(''); | |
$.Collections__emitCollection(c, result, $.ListImplementation_List(null)); | |
return $.toString(result); | |
}; | |
$.NoMoreElementsException$ = function() { | |
return new $.NoMoreElementsException(); | |
}; | |
$.isEmpty = function(receiver) { | |
if (typeof receiver === 'string' || $.isJsArray(receiver)) | |
return receiver.length === 0; | |
return receiver.isEmpty$0(); | |
}; | |
$.stringJoinUnchecked = function(array, separator) { | |
return array.join(separator); | |
}; | |
$.geB = function(a, b) { | |
return typeof a === 'number' && typeof b === 'number' ? a >= b : $.ge$slow(a, b) === true; | |
}; | |
$.ge$slow = function(a, b) { | |
if ($.checkNumbers(a, b)) | |
return a >= b; | |
return a.operator$ge$1(b); | |
}; | |
$.substringUnchecked = function(receiver, startIndex, endIndex) { | |
return receiver.substring(startIndex, endIndex); | |
}; | |
$.ioore = function(index) { | |
throw $.$$throw($.IndexOutOfRangeException$(index)); | |
}; | |
$.floor = function(receiver) { | |
return Math.floor(receiver); | |
}; | |
$.add$slow = function(a, b) { | |
if ($.checkNumbers(a, b)) | |
return a + b; | |
return a.operator$add$1(b); | |
}; | |
$.StringImplementation__toJsStringArray$bailout = function(state0, strings) { | |
$.checkNull(strings); | |
var length$ = $.get$length(strings); | |
if ($.isJsArray(strings)) { | |
for (var i = 0; $.ltB(i, length$); ++i) { | |
var string = $.index(strings, i); | |
$.checkNull(string); | |
if (!(typeof string === 'string')) | |
throw $.$$throw($.ArgumentError$(string)); | |
} | |
var array = strings; | |
} else { | |
array = $.ListImplementation_List(length$); | |
for (i = 0; $.ltB(i, length$); ++i) { | |
string = $.index(strings, i); | |
$.checkNull(string); | |
if (!(typeof string === 'string')) | |
throw $.$$throw($.ArgumentError$(string)); | |
if (i >= array.length) | |
throw $.ioore(i); | |
array[i] = string; | |
} | |
} | |
return array; | |
}; | |
$.toStringWrapper.call$0 = $.toStringWrapper; | |
$.toStringWrapper.$name = "toStringWrapper"; | |
Isolate.$finishClasses($$); | |
$$ = {}; | |
Isolate.makeConstantList = function(list) { | |
list.immutable$list = true; | |
list.fixed$length = true; | |
return list; | |
}; | |
$.CTC0 = Isolate.makeConstantList([]); | |
$.CTC1 = null; | |
$.CTC = new Isolate.$isolateProperties.NullPointerException(null, Isolate.$isolateProperties.CTC0); | |
$.Primitives_DOLLAR_CHAR_VALUE = 36; | |
var $ = null; | |
Isolate.$finishClasses($$); | |
$$ = {}; | |
Isolate = Isolate.$finishIsolateConstructor(Isolate); | |
var $ = new Isolate(); | |
// | |
// BEGIN invoke [main]. | |
// | |
if (typeof document != 'undefined' && document.readyState != 'complete') { | |
document.addEventListener('readystatechange', function () { | |
if (document.readyState == 'complete') { | |
if (typeof dartMainRunner == 'function') { | |
dartMainRunner(function() { $.main(); }); | |
} else { | |
$.main(); | |
} | |
} | |
}, false); | |
} else { | |
if (typeof dartMainRunner == 'function') { | |
dartMainRunner(function() { $.main(); }); | |
} else { | |
$.main(); | |
} | |
} | |
// | |
// END invoke [main]. | |
// | |
function init() { | |
Isolate.$isolateProperties = {}; | |
Isolate.$defineClass = function(cls, fields, prototype) { | |
var generateGetterSetter = function(field, prototype) { | |
var len = field.length; | |
var lastChar = field[len - 1]; | |
var needsGetter = lastChar == '?' || lastChar == '='; | |
var needsSetter = lastChar == '!' || lastChar == '='; | |
if (needsGetter || needsSetter) field = field.substring(0, len - 1); | |
if (needsGetter) { | |
var getterString = "return this." + field + ";"; | |
prototype["get$" + field] = new Function(getterString); | |
} | |
if (needsSetter) { | |
var setterString = "this." + field + " = v;"; | |
prototype["set$" + field] = new Function("v", setterString); | |
} | |
return field; | |
}; | |
var constructor; | |
if (typeof fields == 'function') { | |
constructor = fields; | |
} else { | |
var str = "function " + cls + "("; | |
var body = ""; | |
for (var i = 0; i < fields.length; i++) { | |
if (i != 0) str += ", "; | |
var field = fields[i]; | |
field = generateGetterSetter(field, prototype); | |
str += field; | |
body += "this." + field + " = " + field + ";\n"; | |
} | |
str += ") {" + body + "}\n"; | |
str += "return " + cls + ";"; | |
constructor = new Function(str)(); | |
} | |
constructor.prototype = prototype; | |
return constructor; | |
}; | |
var supportsProto = false; | |
var tmp = Isolate.$defineClass('c', ['f?'], {}).prototype; | |
if (tmp.__proto__) { | |
tmp.__proto__ = {}; | |
if (typeof tmp.get$f !== "undefined") supportsProto = true; | |
} | |
Isolate.$pendingClasses = {}; | |
Isolate.$finishClasses = function(collectedClasses) { | |
var hasOwnProperty = Object.prototype.hasOwnProperty; | |
for (var cls in collectedClasses) { | |
if (hasOwnProperty.call(collectedClasses, cls)) { | |
var desc = collectedClasses[cls]; | |
Isolate.$isolateProperties[cls] = Isolate.$defineClass(cls, desc[''], desc); | |
if (desc['super'] !== "") Isolate.$pendingClasses[cls] = desc['super']; | |
} | |
} | |
var pendingClasses = Isolate.$pendingClasses; | |
Isolate.$pendingClasses = {}; | |
var finishedClasses = {}; | |
function finishClass(cls) { | |
var hasOwnProperty = Object.prototype.hasOwnProperty; | |
if (hasOwnProperty.call(finishedClasses, cls)) return; | |
finishedClasses[cls] = true; | |
var superclass = pendingClasses[cls]; | |
if (!superclass) return; | |
finishClass(superclass); | |
var constructor = Isolate.$isolateProperties[cls]; | |
var superConstructor = Isolate.$isolateProperties[superclass]; | |
var prototype = constructor.prototype; | |
if (supportsProto) { | |
prototype.__proto__ = superConstructor.prototype; | |
prototype.constructor = constructor; | |
} else { | |
function tmp() {}; | |
tmp.prototype = superConstructor.prototype; | |
var newPrototype = new tmp(); | |
constructor.prototype = newPrototype; | |
newPrototype.constructor = constructor; | |
for (var member in prototype) { | |
if (member == '' || member == 'super') continue; | |
if (hasOwnProperty.call(prototype, member)) { | |
newPrototype[member] = prototype[member]; | |
} | |
} | |
} | |
} | |
for (var cls in pendingClasses) finishClass(cls); | |
}; | |
Isolate.$finishIsolateConstructor = function(oldIsolate) { | |
var isolateProperties = oldIsolate.$isolateProperties; | |
var isolatePrototype = oldIsolate.prototype; | |
var str = "{\n"; | |
str += "var properties = Isolate.$isolateProperties;\n"; | |
for (var staticName in isolateProperties) { | |
if (Object.prototype.hasOwnProperty.call(isolateProperties, staticName)) { | |
str += "this." + staticName + "= properties." + staticName + ";\n"; | |
} | |
} | |
str += "}\n"; | |
var newIsolate = new Function(str); | |
newIsolate.prototype = isolatePrototype; | |
isolatePrototype.constructor = newIsolate; | |
newIsolate.$isolateProperties = isolateProperties; | |
return newIsolate; | |
}; | |
} | |
//@ sourceMappingURL=dart.js.map |
{ | |
"version": 3, | |
"mappings": "A;;;;;;;;A;A;;A;A;A;A,E,Q,C,E,Q,C;A,kB,C;A,aAqBEA;AACE,SAAOC;CACT,A,C;A,YAEAC;AACE,SAAOD;CACT,A,C;A,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AAMvC,mBAAkBA;CAC1C,A;;A,ULxbM;;IAEFtB;;IAEAA,yBAAuB8D;CAE3B,A;;A,SK2YAC;AAGE;CACF,A;;A,kBJpEE1C;;CAAuC,A;;A,6BKpMvCG;AACE;;;AACiB;;AACjB,AACA;CACF,A;;A,mCA1EAA;eACmBxC;EACjBqE,yCAA+BjE;AAC/B,SAAOoB;CACT,A;;A,6BRsBA;;CAA+B,A;;A,YOFjCwD;sCAC4B5C;AACxB;AAEF,SAAqBE;CACvB,A;;A,wBI4BAuB;AACE;CACF,A;;A,QRxFAoB;AAAkB,mEAEZC;CAAsB,A;;A,YAsJ5BA;MACMpD;AACF;AAEF,SAAqBC;CACvB,A;;A,uBAshBAwB;AACE;CAAqE,A;;A,UA1EvE4B;QACYtC,UAAAA;CACZ,A;;A,UIhQAuC;AAGE;CACF,A;;A,aJ7SAR;MACM9C;AACF;AAEF,SAAqBC;CACvB,A;;A,kDO5FES;EACEI;gBAEe+B;MACXvC;AAEF,oBAAkB;;MAEhBQ;;cACiCjB,UAAAA;;AACnC;;YAEYvB;AACZ,gBAAkB;;MAEhBwC;;cACiCjB,UAAAA;;;;;AAEnC;AAEF;CACF,A;;A;A;A;A;A,O;;;;;A,S,wB,E,E;A,S,I;A,Q,I,+C,C,I,E,+B,C;A,iC,E;A;A;A;A;A;A;;;;;;;;;;;;;;;;;;;;;;;;;A;A;A;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;A;;;;;;A;A;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;A;;;;;;;;;;;;;;;;;A", | |
"sources": ["file:///Users/darthapo/Dev/dart/dart-sdk/lib/coreimpl/string_buffer.dart","file:///Users/darthapo/Dev/dart/dart-sdk/lib/core/errors.dart","file:///Users/darthapo/Dev/dart/dart-sdk/lib/core/exceptions.dart","file:///Users/darthapo/Dev/dart/dart-sdk/lib/core/object.dart","file:///Users/darthapo/Dev/dart/dart-sdk/pkg/compiler/implementation/lib/core_patch.dart","file:///Users/darthapo/Dev/dart/dart-sdk/pkg/compiler/implementation/lib/js_helper.dart","file:///Users/darthapo/Projects/Gists/compile-to-js-comparisions/source/simple.dart","file:///Users/darthapo/Dev/dart/dart-sdk/lib/coreimpl/maps.dart","file:///Users/darthapo/Dev/dart/dart-sdk/lib/core/string_buffer.dart","file:///Users/darthapo/Dev/dart/dart-sdk/pkg/compiler/implementation/lib/interceptors.dart","file:///Users/darthapo/Dev/dart/dart-sdk/lib/coreimpl/collections.dart","file:///Users/darthapo/Dev/dart/dart-sdk/pkg/compiler/implementation/lib/native_helper.dart","file:///Users/darthapo/Dev/dart/dart-sdk/pkg/compiler/implementation/lib/coreimpl_patch.dart","file:///Users/darthapo/Dev/dart/dart-sdk/pkg/compiler/implementation/lib/string_helper.dart"], | |
"names": ["int","_length","bool","StringBuffer","obj","str","_buffer","List","String","StringImplementation","StringBufferImpl","clear","add","message","_value","functionName","exceptionName","arguments","_message","Primitives","i","list","T","hasNext","NoMoreElementsException","greet","name","result","Collections","value","ArgumentError","factory","gt$slow","checkNumbers","a","checkGrowable","UnsupportedOperationException","$throw","iterator","isJsArray","ListIterator","receiver","add$1","static","visiting","_emitObject","set$length","checkNull","IndexOutOfRangeException","toStringWrapper","JS","checkNum","get$length","string","toString","index","index$slow","substring$2","substringUnchecked","removeLast","gtB","Simple","ltB","lt$slow","stringJoinUnchecked","_toJsStringArray","substring$1","NullPointerException","charCodeAt","objectTypeName","constructorNameFallback","_containsRef","_emitCollection","Maps","m","main","print","s","strings","add$slow","truncate","object","ceil","isEmpty","geB","ge$slow","ioore","floor"] | |
} |
(function () { "use strict"; | |
var Simple = function(name) { | |
this.name = name; | |
}; | |
Simple.main = function() { | |
var s = new Simple("Flynn"); | |
console.log(s.greet("Program")); | |
} | |
Simple.prototype = { | |
greet: function(who) { | |
return "Greetings " + who + ", I'm " + this.name + "!"; | |
} | |
} | |
var Std = function() { } | |
Simple.main(); | |
})(); | |
//@ sourceMappingURL=haxe.js.map |
{ | |
"version":3, | |
"file":"haxe.js", | |
"sourceRoot":"file://", | |
"sources":["/Users/darthapo/Projects/Gists/compile-to-js-comparisions/source/simple.hx"], | |
"names":[], | |
"mappings":";SAMC,MAA0B;CACxB,EAAW;;cAON,HAAgB;CACrB,EAAe,QAAW;CAC1B,WAAO,XAAQ;;;OANjB,OAA2B;OAClB,AAAC,JAAW,AAAG,AAAO,AAAI;;;;;;;" | |
} |
var JSX = {}; | |
(function () { | |
/** | |
* copies the implementations from source interface to target | |
*/ | |
function $__jsx_merge_interface(target, source) { | |
for (var k in source.prototype) | |
if (source.prototype.hasOwnProperty(k)) | |
target.prototype[k] = source.prototype[k]; | |
} | |
/** | |
* defers the initialization of the property | |
*/ | |
function $__jsx_lazy_init(obj, prop, func) { | |
function reset(obj, prop, value) { | |
delete obj[prop]; | |
obj[prop] = value; | |
return value; | |
} | |
Object.defineProperty(obj, prop, { | |
get: function () { | |
return reset(obj, prop, func()); | |
}, | |
set: function (v) { | |
reset(obj, prop, v); | |
}, | |
enumerable: true, | |
configurable: true | |
}); | |
} | |
/** | |
* sideeffect().a /= b | |
*/ | |
function $__jsx_div_assign(obj, prop, divisor) { | |
return obj[prop] = (obj[prop] / divisor) | 0; | |
} | |
/* | |
* global functions called by JSX | |
* (enamed so that they do not conflict with local variable names) | |
*/ | |
var $__jsx_parseInt = parseInt; | |
var $__jsx_parseFloat = parseFloat; | |
var $__jsx_isNaN = isNaN; | |
var $__jsx_isFinite = isFinite; | |
var $__jsx_encodeURIComponent = encodeURIComponent; | |
var $__jsx_decodeURIComponent = decodeURIComponent; | |
var $__jsx_encodeURI = encodeURI; | |
var $__jsx_decodeURI = decodeURI; | |
var $__jsx_ObjectToString = Object.prototype.toString; | |
var $__jsx_ObjectHasOwnProperty = Object.prototype.hasOwnProperty; | |
/* | |
* profiler object, initialized afterwards | |
*/ | |
function $__jsx_profiler() { | |
} | |
/* | |
* public interface to JSX code | |
*/ | |
JSX.require = function (path) { | |
var m = $__jsx_classMap[path]; | |
return m !== undefined ? m : null; | |
}; | |
JSX.profilerIsRunning = function () { | |
return $__jsx_profiler.getResults != null; | |
}; | |
JSX.getProfileResults = function () { | |
return ($__jsx_profiler.getResults || function () { return {}; })(); | |
}; | |
JSX.postProfileResults = function (url) { | |
if ($__jsx_profiler.postResults == null) | |
throw new Error("profiler has not been turned on"); | |
return $__jsx_profiler.postResults(url); | |
}; | |
JSX.resetProfileResults = function () { | |
if ($__jsx_profiler.resetResults == null) | |
throw new Error("profiler has not been turned on"); | |
return $__jsx_profiler.resetResults(); | |
}; | |
/** | |
* class Simple extends Object | |
* @constructor | |
*/ | |
function Simple() { | |
} | |
Simple.prototype = new Object; | |
/** | |
* @constructor | |
* @param {!string} name | |
*/ | |
function Simple$S(name) { | |
this.name = name; | |
}; | |
Simple$S.prototype = new Simple; | |
/** | |
* @param {!string} who | |
* @return {!string} | |
*/ | |
Simple.prototype.greet$S = function (who) { | |
return "Greetings " + who + ", I'm " + this.name + "!"; | |
}; | |
/** | |
* class _Main extends Object | |
* @constructor | |
*/ | |
function _Main() { | |
} | |
_Main.prototype = new Object; | |
/** | |
* @constructor | |
*/ | |
function _Main$() { | |
}; | |
_Main$.prototype = new _Main; | |
/** | |
* @param {Array.<undefined|!string>} args | |
*/ | |
_Main.main$AS = function (args) { | |
/** @type {Simple} */ | |
var s; | |
s = new Simple$S("Flynn"); | |
console.log(s.greet$S("Program")); | |
}; | |
var _Main$main$AS = _Main.main$AS; | |
var $__jsx_classMap = { | |
"source/simple.jsx": { | |
Simple: Simple, | |
Simple$S: Simple$S, | |
_Main: _Main, | |
_Main$: _Main$ | |
} | |
}; | |
/** | |
* launches _Main.main(:string[]):void invoked by jsx --run|--executable | |
*/ | |
JSX.runMain = function (sourceFile, args) { | |
var module = JSX.require(sourceFile); | |
if (! module._Main) { | |
throw new Error("entry point _Main not found in " + sourceFile); | |
} | |
if (! module._Main.main$AS) { | |
throw new Error("entry point _Main.main(:string[]):void not found in " + sourceFile); | |
} | |
module._Main.main$AS(args); | |
}; | |
/** | |
* launches _Test#test*():void invoked by jsx --test | |
*/ | |
JSX.runTests = function (sourceFile, tests) { | |
var module = JSX.require(sourceFile); | |
var testClass = module._Test$; | |
if (!testClass) return; // skip if there's no test class | |
if(tests.length === 0) { | |
var p = testClass.prototype; | |
for (var m in p) { | |
if (p[m] instanceof Function | |
&& /^test.*[$]$/.test(m)) { | |
tests.push(m); | |
} | |
} | |
} | |
else { // set as process arguments | |
tests = tests.map(function (name) { | |
return name + "$"; // mangle for function test*():void | |
}); | |
} | |
var testCase = new testClass(); | |
if (testCase.beforeClass$AS != null) | |
testCase.beforeClass$AS(tests); | |
for (var i = 0; i < tests.length; ++i) { | |
(function (method) { | |
if (method in testCase) { | |
testCase.run$SF$V$(method, function() { testCase[method](); }); | |
} | |
else { | |
throw new ReferenceError("No such test method: " + method); | |
} | |
}(tests[i])); | |
} | |
if (testCase.afterClass$ != null) | |
testCase.afterClass$(); | |
}; | |
/** | |
* call a function on load/DOMContentLoaded | |
*/ | |
function $__jsx_onload (event) { | |
window.removeEventListener("load", $__jsx_onload); | |
document.removeEventListener("DOMContentLoaded", $__jsx_onload); | |
JSX.runMain("source/simple.jsx", []) | |
} | |
window.addEventListener("load", $__jsx_onload); | |
document.addEventListener("DOMContentLoaded", $__jsx_onload); | |
})(); | |
//@ sourceMappingURL=output/jsx.js.mapping |
{"version":3,"file":"output/jsx.js","sources":["source/simple.jsx"],"names":["Simple","name","greet","who","_Main","main","args","s"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QACMA;;;;;;;;QAAAA,SAIiBC;AACnB,IAAKA,CAAAA,IAAK,GAAEA;;;;;;;;;gBAGLC,UAAT,UAAeC;OACN,YAAY,GAAEA,GAAI,GAAC,QAAQ,GAAE,IAAKF,CAAAA,IAAK,GAAC;;;;;;;QAK7CG;;;;;;;QAAAA;;;;;;;;KACYC,UAAT,UAAcC;;;AACfC,CAAC,GAAE,aAAW,OAAX;AACP,YAAIA,CAAEL,CAAAA,OAAK,CAAC,SAAD"} |
.PHONY: compile | |
time=/usr/bin/time | |
compile: dart typescript coffeescript haxe jsx | |
dart: | |
$(time) dart2js -ooutput/dart.js source/simple.dart | |
typescript: | |
$(time) tsc --out output/typescript.js --sourcemap source/simple.ts | |
coffeescript: | |
$(time) coffee -p source/simple.coffee > output/coffee.js | |
haxe: | |
$(time) haxe -cp source/ -main Simple -js output/haxe.js --dead-code-elimination --js-modern -debug | |
jsx: | |
$(time) jsx --executable web --enable-source-map --output output/jsx.js source/simple.jsx |
class Simple | |
constructor: (@name = "default") -> | |
greet: (who) -> | |
"Greetings #{ who }, I'm #{ @name }!" | |
@main: -> | |
s= new Simple "Flynn" | |
console.log s.greet "Program" | |
Simple.main() |
class Simple { | |
String name; | |
Simple(this.name); | |
greet(who) => "Greetings $who, I'm $name!"; | |
} | |
main() { | |
var s= new Simple('Flyn'); | |
print( s.greet('Program')); | |
} |
using Std; | |
class Simple { | |
var name:String; | |
function new(name:String) { | |
this.name= name; | |
} | |
function greet(who:String) { | |
return "Greetings $who, I'm $name!".format(); | |
} | |
static function main() { | |
var s:Simple = new Simple("Flynn"); | |
trace( s.greet("Program") ); | |
} | |
} |
class Simple { | |
var name:string; | |
function constructor(name:string) { | |
this.name = name; | |
} | |
function greet(who:string): string { | |
return "Greetings "+ who +", I'm "+ this.name +"!"; | |
} | |
} | |
class _Main { | |
static function main(args:string[]):void { | |
var s= new Simple("Flynn"); | |
log s.greet("Program"); | |
} | |
} |
class Simple { | |
constructor(public name: string) {} | |
greet(who: string) { | |
return "Greetings "+ who +", I'm "+ this.name +"!"; | |
} | |
static main() { | |
var s = new Simple('Flynn'); | |
console.log(s.greet("Program")); | |
} | |
} | |
Simple.main() |
var Simple = (function () { | |
function Simple(name) { | |
this.name = name; | |
} | |
Simple.prototype.greet = function (who) { | |
return "Greetings " + who + ", I'm " + this.name + "!"; | |
}; | |
Simple.main = function main() { | |
var s = new Simple('Flynn'); | |
console.log(s.greet("Program")); | |
} | |
return Simple; | |
})(); | |
Simple.main(); | |
//@ sourceMappingURL=typescript.js.map |
{"version":3,"file":"typescript.js","sources":["simple.ts"],"names":[],"mappings":"AACA;IAEE,gBAAY;QAAO,YAAA;AAAgB;IAEnC,yBAAA,UAAM;QACJ,OAAO,eAAc,MAAK,WAAU,KAAK,OAAM;AAChD;IAED,cAAA;QACE,IAAI,IAAQ,IAAA,OAAO;QACnB,QAAQ,IAAI,EAAE,MAAM;AACrB;IAXH;;AAeA,OAAO"} |
@Diullei: Thanks! Just pushed a new version what it included.
@borisyankov: I agree. Although I was surprised by the Haxe output. It was much better than I was expecting.
Does anyone know if there are flags I can add to the dart2js
compiler to get saner output?
@borisyankov you can compile with --bare in coffeescript to remove the IIFE, but that would be silly. Each file should have its own scope.
Dart's dart2js compiler has improved significantly. Here it is with the latest:
// Generated by dart2js, the Dart to JavaScript compiler.
// The code supports the following hooks:
// dartPrint(message) - if this function is defined it is called
// instead of the Dart [print] method.
// dartMainRunner(main) - if this function is defined, the Dart [main]
// method will not be invoked directly.
// Instead, a closure that will invoke [main] is
// passed to [dartMainRunner].
function Isolate() {}
init();
var $ = Isolate.$isolateProperties;
var $$ = {};
// Classes
$$.Object = {"": ";"};
$$.Simple = {"": "Object;name",
greet$1: function(who) {
return "Greetings " + who + ", I'm " + this.name + "!";
}
};
// Bound closures
Isolate.$finishClasses($$, $, null);
$$ = null;
$.Primitives_printString = function(string) {
if (typeof dartPrint == "function") {
dartPrint(string);
return;
}
if (typeof window == "object") {
if (typeof console == "object")
console.log(string);
return;
}
if (typeof print == "function") {
print(string);
return;
}
throw "Unable to print message: " + String(string);
};
$.Simple$ = function($name) {
return new $.Simple($name);
};
$.main = function() {
$.Primitives_printString($.Simple$("Flyn").greet$1("Program"));
};
$.String = {builtin$cls: "String"};
var $ = null;
Isolate = Isolate.$finishIsolateConstructor(Isolate);
var $ = new Isolate();
// BEGIN invoke [main].
if (typeof document !== "undefined" && document.readyState !== "complete") {
document.addEventListener("readystatechange", function () {
if (document.readyState == "complete") {
if (typeof dartMainRunner === "function") {
dartMainRunner(function() { $.main(); });
} else {
$.main();
}
}
}, false);
} else {
if (typeof dartMainRunner === "function") {
dartMainRunner(function() { $.main(); });
} else {
$.main();
}
}
// END invoke [main].
function init() {
Isolate.$isolateProperties = {};
function generateAccessor(field, prototype) {
var len = field.length;
var code = field.charCodeAt(len - 1);
code = code >= 60 && code <= 64 ? code - 59 : code >= 123 && code <= 126 ? code - 117 : code >= 37 && code <= 43 ? code - 27 : 0;
if (code) {
var getterCode = code & 3;
var setterCode = code >> 2;
var accessorName = field = field.substring(0, len - 1);
var divider = field.indexOf(":");
if (divider > 0) {
accessorName = field.substring(0, divider);
field = field.substring(divider + 1);
}
if (getterCode) {
var args = getterCode & 2 ? "receiver" : "";
var receiver = getterCode & 1 ? "this" : "receiver";
var body = "return " + receiver + "." + field;
prototype["get$" + accessorName] = new Function(args, body);
}
if (setterCode) {
var args = setterCode & 2 ? "receiver, value" : "value";
var receiver = setterCode & 1 ? "this" : "receiver";
var body = receiver + "." + field + " = value";
prototype["set$" + accessorName] = new Function(args, body);
}
}
return field;
}
Isolate.$isolateProperties.$generateAccessor = generateAccessor;
function defineClass(cls, fields, prototype) {
var constructor;
if (typeof fields == "function") {
constructor = fields;
} else {
var str = "function " + cls + "(";
var body = "";
for (var i = 0; i < fields.length; i++) {
if (i != 0)
str += ", ";
var field = fields[i];
field = generateAccessor(field, prototype);
str += field;
body += "this." + field + " = " + field + ";\n";
}
str += ") {" + body + "}\nreturn " + cls;
constructor = new Function(str)();
}
constructor.prototype = prototype;
constructor.builtin$cls = cls;
return constructor;
}
var supportsProto = false;
var tmp = defineClass("c", ["f?"], {}).prototype;
if (tmp.__proto__) {
tmp.__proto__ = {};
if (typeof tmp.get$f != "undefined")
supportsProto = true;
}
Isolate.$finishClasses = function(collectedClasses, isolateProperties, existingIsolateProperties) {
var pendingClasses = {};
var hasOwnProperty = Object.prototype.hasOwnProperty;
for (var cls in collectedClasses) {
if (hasOwnProperty.call(collectedClasses, cls)) {
var desc = collectedClasses[cls];
var fields = desc[""], supr;
if (typeof fields == "string") {
var s = fields.split(";");
supr = s[0];
fields = s[1] == "" ? [] : s[1].split(",");
} else {
supr = desc.super;
}
isolateProperties[cls] = defineClass(cls, fields, desc);
if (supr)
pendingClasses[cls] = supr;
}
}
var finishedClasses = {};
function finishClass(cls) {
var hasOwnProperty = Object.prototype.hasOwnProperty;
if (hasOwnProperty.call(finishedClasses, cls))
return;
finishedClasses[cls] = true;
var superclass = pendingClasses[cls];
if ((!superclass || typeof superclass) != "string")
return;
finishClass(superclass);
var constructor = isolateProperties[cls];
var superConstructor = isolateProperties[superclass];
if (!superConstructor)
superConstructor = existingIsolateProperties[superclass];
var prototype = constructor.prototype;
if (supportsProto) {
prototype.__proto__ = superConstructor.prototype;
prototype.constructor = constructor;
} else {
function tmp() {
}
tmp.prototype = superConstructor.prototype;
var newPrototype = new tmp();
constructor.prototype = newPrototype;
newPrototype.constructor = constructor;
for (var member in prototype) {
if (!member)
continue;
if (hasOwnProperty.call(prototype, member)) {
newPrototype[member] = prototype[member];
}
}
}
}
for (var cls in pendingClasses)
finishClass(cls);
};
Isolate.$finishIsolateConstructor = function(oldIsolate) {
var isolateProperties = oldIsolate.$isolateProperties;
isolateProperties.$currentScript = typeof document == "object" ? document.currentScript || document.scripts[document.scripts.length - 1] : null;
var isolatePrototype = oldIsolate.prototype;
var str = "{\n";
str += "var properties = Isolate.$isolateProperties;\n";
var hasOwnProperty = Object.prototype.hasOwnProperty;
for (var staticName in isolateProperties) {
if (hasOwnProperty.call(isolateProperties, staticName)) {
str += "this." + staticName + "= properties." + staticName + ";\n";
}
}
str += "}\n";
var newIsolate = new Function(str);
newIsolate.prototype = isolatePrototype;
isolatePrototype.constructor = newIsolate;
newIsolate.$isolateProperties = isolateProperties;
newIsolate.$finishClasses = oldIsolate.$finishClasses;
return newIsolate;
};
}
//@ sourceMappingURL=out.js.map
And of course you can minify, too :)
// Generated by dart2js, the Dart to JavaScript compiler.
function I(){}
init()
var $=I.p
var $$={}
$$.a={"":";"}
$$.Oh={"":"a;oc",
c1:function(a){return"Greetings "+a+", I'm "+this.oc+"!"}}
I.$finishClasses($$,$,null)
$$=null
$.ib=function(a){if(typeof dartPrint == "function"){dartPrint(a)
return}if(typeof window == "object"){if(typeof console == "object")console.log(a)
return}if(typeof print == "function"){print(a)
return}throw "Unable to print message: " + String(a)}
$.MI=function(a){return new $.Oh(a)}
$.E2=function(){$.ib($.MI("Flyn").c1("Program"))}
$.qU={builtin$cls:"qU"}
var $=null
I = I.$finishIsolateConstructor(I)
var $=new I()
if (typeof document !== "undefined" && document.readyState !== "complete") {
document.addEventListener("readystatechange", function () {
if (document.readyState == "complete") {
if (typeof dartMainRunner === "function") {
dartMainRunner(function() { $.E2(); });
} else {
$.E2();
}
}
}, false);
} else {
if (typeof dartMainRunner === "function") {
dartMainRunner(function() { $.E2(); });
} else {
$.E2();
}
}
function init(){I.p={}
function generateAccessor(a,b){var x=a.length
var w=a.charCodeAt(x-1)
w=w>=60&&w<=64?w-59:w>=123&&w<=126?w-117:w>=37&&w<=43?w-27:0
if(w){var v=w&3
var u=w>>2
var t=a=a.substring(0,x-1)
var s=a.indexOf(":")
if(s>0){t=a.substring(0,s)
a=a.substring(s+1)}if(v){var r=v&2?"r":""
var q=v&1?"this":"r"
var p="return "+q+"."+a
b["g"+t]=new Function(r,p)}if(u){var r=u&2?"r,v":"v"
var q=u&1?"this":"r"
var p=q+"."+a+"=v"
b["s"+t]=new Function(r,p)}}return a}I.p.$generateAccessor=generateAccessor
function defineClass(a,b,c){var x
if(typeof b=="function"){x=b}else{var w="function "+a+"("
var v=""
for(var u=0;u<b.length;u++){if(u!=0)w+=", "
var t=b[u]
t=generateAccessor(t,c)
w+=t
v+="this."+t+" = "+t+";\n"}w+=") {"+v+"}\nreturn "+a
x=new Function(w)()}x.prototype=c
x.builtin$cls=a
return x}var z=false
var y=defineClass("c",["f?"],{}).prototype
if(y.__proto__){y.__proto__={}
if(typeof y.get$f!="undefined")z=true}I.$finishClasses=function(a,b,c){var x={}
var w=Object.prototype.hasOwnProperty
for(var v in a){if(w.call(a,v)){var u=a[v]
var t=u[""],s
if(typeof t=="string"){var r=t.split(";")
s=r[0]
t=r[1]==""?[]:r[1].split(",")}else{s=u.super}b[v]=defineClass(v,t,u)
if(s)x[v]=s}}var q={}
function finishClass(d){var p=Object.prototype.hasOwnProperty
if(p.call(q,d))return
q[d]=true
var o=x[d]
if((!o||typeof o)!="string")return
finishClass(o)
var n=b[d]
var m=b[o]
if(!m)m=c[o]
var l=n.prototype
if(z){l.__proto__=m.prototype
l.constructor=n}else{function y(){}y.prototype=m.prototype
var k=new y()
n.prototype=k
k.constructor=n
for(var j in l){if(!j)continue
if(p.call(l,j)){k[j]=l[j]}}}}for(var v in x)finishClass(v)}
I.$finishIsolateConstructor=function(a){var x=a.p
x.$currentScript=typeof document=="object"?document.currentScript||document.scripts[document.scripts.length-1]:null
var w=a.prototype
var v="{\n"
v+="var properties = I.p;\n"
var u=Object.prototype.hasOwnProperty
for(var t in x){if(u.call(x,t)){v+="this."+t+"= properties."+t+";\n"}}v+="}\n"
var s=new Function(v)
s.prototype=w
w.constructor=s
s.p=x
s.$finishClasses=a.$finishClasses
return s}}//@ sourceMappingURL=out.js.map
typescript's output is the best.
Dart's the ugliest.
In Dart's defense, the definition of the language isn't meant to completely mirror Javascript. While the designers try to keep Dart's behavior as in-line with JS as possible, they implement a lot of different behavior that they believe make it an easier language to work with (such as range checking on array access). The downside of that is the generated javascript is uglier.
thanks for sharing information in such precise manner
Coming from an ActionScript 3.0 background, I think TypeScript and Haxe are the two most attractive options here, especially looking at the minimal JS generated by their compilers. But given that Haxe can compile to other platforms / devices, I wonder if it's really worth the time to learn TypeScript.
Haxe compile times also smoke the competition.
Ugliest output and 3 second compile, Dart, really? Google's losing it. =P =)
Test needs to be updated. Newest TypeScript compiles faster, Haxe 3 has new shorter syntax
Using Std isn't needed in the Haxe script. Output will be cleaner without.
Anyway this comparision is useless: what about the real world when you have tens or hundreds of classes?
FYI, there is a new Dart compiler being written [1] which will emit more idiomatic JavaScript. Perhaps someone can run it for comparison?
Looks like Bob Nystrom posted the new compiler's output:
@darthapo you can use the follow instruction to compile TypeScript and generate sourcemap:
tsc --out output/typescript.js --sourcemap source/simple.ts