2012-01-11 8 views
8

私は、次のダーツのコードを持って次のように上記のコードのためのダーツコンパイラによって生成されたJavaScriptコードがあるなぜdartによって生成されたjavascriptファイルはとても大きいのですか?

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

$ 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.slice()) : this.arguments) : []); 
$ 

そしてhelloworld.dart.app.jsのサイズは102Kです!

それは、以下のJavaScriptを生成し、最適化モードで実行されていました - サイズであるhelloworld.dart.js 20K

$ cat helloworld.dart.js 
var e;function f(a,b){if(b>=0&&b<a.length)return b;h(i(b))};var j={},k={};function aa(a,b,c){if(b)a.g=function(){return b.call(c)}}function ba(a,b,c,d){function g(b,g,t,m){return a.call(c,d,b,g,t,m)}aa(g,b,c);return g}function l(a,b){if(a.prototype.__proto__)a.prototype.__proto__=b.prototype;else{var c=function(){};c.prototype=b.prototype;a.prototype=new c;a.prototype.constructor=a}}function ca(a,b){return typeof a=="number"&&typeof b=="number"?a+b:a.na(b)}function da(a){a/=4;return a<0?Math.ceil(a):Math.floor(a)} 
function o(a,b){if(a===void 0)return b===void 0;else if(typeof a==typeof b&&typeof a!="object")return a===b;return a.G(b)}function h(a){a&&typeof a=="object"&&Error.captureStackTrace&&Error.captureStackTrace(a);throw a;}function p(){var a=new q;a.f=s("ya",ea);a.va="";a.qa="";a.N=[];h(a)}var u={d:0}; 

<snapped> 

y.push(function(){x.fb=j;x.eb=j;x.gb=j});y.push(function(){x.Ta=j;x.Sa=j;x.Ra=j;x.Wa=j;x.Va=j;x.Ua=j});(function(a,b){if(!A){var c=new ya;oa=c;sa(c,function(){a(b)});Ea();x=c}})(function(){return qb()(1,u,"Hello world!")},this.arguments?this.arguments.slice?[].concat(this.arguments.slice()):this.arguments:[]); 
$ 

なぜダーツコンパイラによって生成されたJavaScriptコードは非常に巨大ですか?

このような巨大なjavascriptファイルを生成して解決しようとしている問題は何ですか?

側注:それはダートランタイムが含まれているため

Oops! Your question couldn't be submitted because: body is limited to 30000 characters; you entered 140984

+1

Javascriptが原因です。 – Aziz

+4

新しいコンパイラは、そのサイズを大幅に縮小しました。 「Hello World」はFrogコンパイラを使って8行に​​なりました。 – moraes

答えて

10

さらに優れたJavaScriptを入手したい場合は、DartCではなくFrogコンパイラを使用してください。カエルはダーツ自体で書かれています。

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

注、上記本ブログ記事は少し古くなっています。あなたはその間カエルのためにダートSDKを使用することができます。 http://gsdview.appspot.com/dart-editor-archive-continuous/3058/

この投稿は、またあなたのために関心のあるかもしれない、セスはカエルがJSがどのように見える生成方法を示しています。ここでは http://blog.sethladd.com/2011/12/10-lessons-from-porting-javascript-to.html

あなたがカエルを有効にする方法であります現在のエディタ: https://groups.google.com/a/dartlang.org/group/misc/msg/5dfe04c69ed0fed3

9

Why is the javascript code which was generated from a dart code by a dart compiler is so huge?

:JavaScriptファイルには、SO、次のエラーを投げ、とても巨大でした。

What problem are they trying to solve by generating such huge javascript files?

ブラウザでJavaScript以外のコードを実行する問題。

+3

ダーツランタイムは含まれていません。以前に生成されたJavaScriptには、多数の組み込みライブラリが含まれていましたが、最近のコンパイラは必要なものだけを含めるのが最善です。打ち上げからの17k「Hello World」は、例えば8行になりました。 – moraes

12

What problem are they trying to solve by generating such huge javascript files?

というだけで、この1個人、特定、不自然な、無用のプログラム例誰もがなり、これまでよりも、それ自体、ほとんどの場合に最適であるとダートのバランスの問題冗長な生産プロジェクトで使用しようとします。

+5

これがなぜ落とされたのか分かりませんが、それは素晴らしい答えです。 – funkybro

-1

多くのアプリケーションの大部分は、固定されているアセット(データベース、画像、オーディオファイルなど)で構成されています。サイズ。本当のアプリケーションの場合、JSの連鎖は、「こんにちは世界」のアプリケーションのように全体の一部として重要であるとは思われません。結局のところ、それは自分のツールを選ぶことです.JSはもともと単純なページの振る舞い制御(大規模な複雑なWebアプリケーションではない)を念頭に置いて設計されていました。この点で、それはまだその場所を持っています(そして、コンピュータが "こんにちはの世界"を言うようにするために、存在するツールとして完璧です)。

関連する問題