Domanda

Ho il seguente codice dardo:

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

Il codice JavaScript generato dal compilatore dardo per il codice di cui sopra è il seguente:

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

E la dimensione di helloworld.dart.app.js è 102k!

Quando correva in modalità ottimizzare, ha generato il seguente javascript - helloworld.dart.js che è di dimensioni 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:[]);
$

Perché è il codice javascript che è stato generato da un compilatore dardo così enorme?

Quale problema stanno cercando di risolvere generando tali file enorme javascript?

Nota a margine: I file javascript erano così enorme, così gettato il seguente errore:

Oops! La tua domanda non poteva essere presentata in quanto: il corpo è limitata a 30000 caratteri; immesso 140.984

È stato utile?

Soluzione

Se si desidera ottenere anche una migliore JavaScript, provare il compilatore rana al posto di DartC. Rana ist scritto a Dart sé.

http://turbomanage.wordpress.com/2011 / 12/09 / dardo-dev-mode-vien /

Nota, questo blogpost sopra è un po 'obsolete. È intanto possibile utilizzare il dardo SDK per Frog: http://gsdview.appspot.com/dart-editor-archive-continuous/ 3058 /

Questo post potrebbe anche essere di interesse per voi, spettacoli Seth come la rana generato sguardi JS come: http://blog.sethladd.com/2011 /12/10-lessons-from-porting-javascript-to.html

Ecco come è possibile abilitare Rana in Editor attuale: https://groups.google.com/a/dartlang.org / gruppo / misc / msg / 5dfe04c69ed0fed3

Altri suggerimenti

Quale problema stanno cercando di risolvere generando tali file enorme javascript?

Il problema di bilanciare Dart per essere ottimale nella maggior parte dei casi, piuttosto che questo personale, specifica, artificiosa, programma inutile esempio che nessuno avrebbe mai seriamente provare a utilizzare in un progetto di produzione.

Perché è il codice javascript che è stato generato da un codice dardo da un compilatore dardo è così enorme?

Perché include un runtime Dart.

Quale problema stanno cercando di risolvere generando tali file enorme javascript?

Il problema di esecuzione di codice JavaScript che non è in un browser.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top