Alex Rivera | Logout

Why is javascript files generated by dart is so huge?

Asked 2012-01-11T07:07:50.260
8

I have the following dart code:

$ cat helloworld.dart
main() => print('Hello world!');
$ 

The javascript code generated by the dart compiler for the above code is as follows:

$ cat helloworld.dart.app.js 
function native_ListFactory__new(typeToken, length) {
  return RTT.setTypeInfo(
      new Array(length),
      Array.$lookupRTT(RTT.getTypeInfo(typeToken).typeArgs));
}
function native_ListImplementation__indexOperator(index) {
  return this[index];
}
function native_ListImplementation__indexAssignOperator(index, value) {
  this[index] = value;
}
function native_ListImplementation_get$length() {
  return this.length;
}
function native_ListImplementation__setLength(length) {
  this.length = length;
}
function native_ListImplementation__add(element) {
  this.push(element);
}
function native_BoolImplementation_EQ(other) {
  return typeof other == 'boolean' && this == other;
}
function native_BoolImplementation_toString() {
  return this.toString();
}

<snapped>

var static$uninitialized = {};
var static$initializing = {};
function $inherits(child, parent) {
  if (child.prototype.__proto__) {
    child.prototype.__proto__ = parent.prototype;
  } else {
    function tmp() {};
    tmp.prototype = parent.prototype;
    child.prototype = new tmp();
    child.prototype.constructor = child;
  }
}
isolate$inits.push(function(){
  isolate$current.Duration$DartMILLISECONDS_PER_MINUTE$field = static$uninitialized;
  isolate$current.Duration$DartMILLISECONDS_PER_HOUR$field = static$uninitialized;
  isolate$current.Duration$DartMILLISECONDS_PER_DAY$field = static$uninitialized;
  isolate$current.Duration$DartSECONDS_PER_HOUR$field = static$uninitialized;
  isolate$current.Duration$DartSECONDS_PER_DAY$field = static$uninitialized;
  isolate$current.Duration$DartMINUTES_PER_DAY$field = static$uninitialized;
}
);
RunEntry(unnamedd9297f$main$member, this.arguments ? (this.arguments.slice ? [].concat(this.arguments.s
Edit
Report

1 Answer

10

If you would like to get even a better JavaScript, try the Frog compiler instead of DartC. Frog ist written in Dart itself.

http://turbomanage.wordpress.com/2011/12/09/dart-dev-mode-cometh/

Note, this blogpost above is a bit outdated. You can meanwhile use the Dart SDK for Frog: http://gsdview.appspot.com/dart-editor-archive-continuous/3058/

This post might also be of interest for you, Seth shows how the Frog generated JS looks like: http://blog.sethladd.com/2011/12/10-lessons-from-porting-javascript-to.html

Here is how you can enable Frog in current Editor: https://groups.google.com/a/dartlang.org/group/misc/msg/5dfe04c69ed0fed3

answered 2012-01-11T11:30:58.433

Your Answer