簡體   English   中英

為什么dart生成的javascript文件如此龐大?

[英]Why is javascript files generated by dart is so huge?

我有以下飛鏢碼:

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

dart編譯器為上面代碼生成的javascript代碼如下:

$ 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:[]);
$

為什么由dart編譯器生成的javascript代碼如此龐大?

他們試圖通過生成如此巨大的JavaScript文件來解決什么問題?

附注:javascript文件太大了,SO引發了以下錯誤:

哎呀! 您的問題無法提交,因為:正文限制為30000個字符; 你輸入了140984

他們試圖通過生成如此巨大的JavaScript文件來解決什么問題?

在大多數情況下,平衡Dart是最佳的問題,而不僅僅是這個個人的,具體的,人為的,無用的示例程序,沒有人會認真地嘗試在生產項目中使用。

如果您想獲得更好的JavaScript,請嘗試使用Frog編譯器而不是DartC。 青蛙是用Dart本身寫的。

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

注意,上面這篇博文有點過時了。 您可以同時使用Dart SDK for Frog: http//gsdview.appspot.com/dart-editor-archive-continuous/3058/

這篇文章也可能對你有用,Seth展示了Frog生成JS的樣子: http//blog.sethladd.com/2011/12/10-lessons-from-porting-javascript-to.html

以下是在當前編輯器中啟用Frog的方法: https//groups.google.com/a/dartlang.org/group/misc/msg/5dfe04c69ed0fed3

為什么dart編譯器從dart代碼生成的javascript代碼如此龐大?

因為它包含Dart運行時。

他們試圖通過生成如此巨大的JavaScript文件來解決什么問題?

在瀏覽器中運行非JavaScript的代碼的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM