Question

J'ai le code de fléchette suivant:

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

Le code JavaScript généré par le compilateur de dart pour le code ci-dessus est comme suit:

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

Et la taille de helloworld.dart.app.js est 102k!

Lorsque ran en mode d'optimisation, il a généré le javascript suivant - helloworld.dart.js qui est de taille 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:[]);
$

Pourquoi le code javascript qui a été généré par un compilateur de fléchette si énorme?

Quel problème sont-ils essayer de résoudre en générant de tels fichiers javascript énorme?

Side Note: Les fichiers javascript étaient si énormes, donc jeté l'erreur suivante:

Oops! Votre question n'a pas pu être soumise parce que: le corps est limité à 30000 caractères; vous avez entré 140984

Était-ce utile?

La solution

Si vous souhaitez obtenir encore un meilleur JavaScript, essayez le compilateur Frog au lieu de DartC. Frog ist écrit à Dart lui-même.

http://turbomanage.wordpress.com/2011 / 12/09 / fléchette-dev-mode-vient /

Notez cette blogpost ci-dessus est un peu vieillot. Vous pouvez utiliser le kit de développement quant à lui pour Dart Frog: http://gsdview.appspot.com/dart-editor-archive-continuous/ 3058 /

Ce poste peut également être intéressant pour vous, Seth montre comment la grenouille ressemble JS comme généré: http://blog.sethladd.com/2011 /12/10-lessons-from-porting-javascript-to.html

Voici comment vous pouvez activer Frog dans l'éditeur en cours: https://groups.google.com/a/dartlang.org / groupe / misc / msg / 5dfe04c69ed0fed3

Autres conseils

Quel problème sont-ils essayer de résoudre en générant de tels fichiers javascript énorme?

Le problème de l'équilibre Dart pour être optimale dans la plupart des cas, plutôt que celui-ci personnelle, spécifique, arrangé, exemple de programme inutile que personne ne jamais essayer sérieusement d'utiliser dans un projet de production.

Pourquoi le code javascript qui a été généré à partir d'un code de fléchette par un compilateur de fléchettes est si énorme?

Parce qu'il comprend un moteur d'exécution Dart.

Quel problème sont-ils essayer de résoudre en générant de tels fichiers javascript énorme?

Le problème de l'exécution de code JavaScript qui n'est pas dans un navigateur.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top