Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

cosmetic changes to the generated JS? #425

Closed
devoncarew opened this issue Jan 22, 2016 · 5 comments
Closed

cosmetic changes to the generated JS? #425

devoncarew opened this issue Jan 22, 2016 · 5 comments

Comments

@devoncarew
Copy link
Contributor

Here's the current generated JS for a sample dart file:

dart_library.library('entry', null, /* Imports */[
  'dart/_runtime',
  'logging/logging',
  'dart/core',
  'atom/atom',
  'atom_flutter/flutter'
], /* Lazy imports */[
], function(exports, dart, logging, core, atom, flutter) {
  'use strict';
  let dartx = dart.dartx;
  function main() {
    logging.Logger.root.level = logging.Level.INFO;
    logging.Logger.root.onRecord.listen(dart.fn(r => {
      let tag = `[${r.loggerName} ${r.level.name[dartx.toLowerCase]()}: `;
      core.print(`${tag} ${r.message}`);
      if (r.error != null) core.print(`${tag}   ${r.error}`);
      if (r.stackTrace != null) core.print(`${tag}   ${r.stackTrace}`);
    }, dart.void, [logging.LogRecord]));
    atom.registerPackageDDC(new flutter.FlutterDevPackage());
  }
  dart.fn(main);
  // Exports:
  exports.main = main;
});
//# sourceMappingURL=entry.js.map

Here is the sample file with some tweaks:

// Compiled from web/entry.dart.

dart_library.library(
  'entry',
  null,
  /* Imports */ [
    'dart/_runtime', 'logging/logging', 'dart/core', 'atom/atom', 'atom_flutter/flutter'
  ],
  /* Lazy imports */ [
  ],
  function(
    exports, dart, logging, core, atom, flutter
) {

'use strict';

let dartx = dart.dartx;

function main() {
  logging.Logger.root.level = logging.Level.INFO;
  logging.Logger.root.onRecord.listen(dart.fn(r => {
    let tag = `[${r.loggerName} ${r.level.name[dartx.toLowerCase]()}: `;
    core.print(`${tag} ${r.message}`);
    if (r.error != null) core.print(`${tag}   ${r.error}`);
    if (r.stackTrace != null) core.print(`${tag}   ${r.stackTrace}`);
  }, dart.void, [logging.LogRecord]));
  atom.registerPackageDDC(new flutter.FlutterDevPackage());
}

dart.fn(main);

// Exports:
exports.main = main;

});

//# sourceMappingURL=entry.js.map
@devoncarew
Copy link
Contributor Author

This is:

  • add some more blank lines to help group things
  • unindents the bit in the middle that corresponds to the user's code, so a void main() starts at indent 0 instead of 2
  • changing the formatting of the dart_library.library header a bit. Don't know if that's a win -
  • adding a line comment to tell the user what the source file was

W/ the de-indent change, this file will also be slightly smaller.

@jmesserly
Copy link
Contributor

jmesserly commented Jan 22, 2016

We haven't done anything to tweak the module boilerplate, because it will be fixed by generating much much cleaner ES6 modules.

Or even just following one of the ES5 module patterns, so the code looks like what humans write for ES5. That's covered by #285, #284, #34.

As far as newlines in a few more places that is #66 (edit: that issue was dup'd against this fresher one)

@jmesserly
Copy link
Contributor

I think this is covered by those other issues, but let me know if I missed anything.

@devoncarew
Copy link
Contributor Author

Ah, properly pretty much covered then. Here's one more tweak to the format (which doesn't try and change the module header format):

// Compiled from web/entry.dart.

dart_library.library('entry', null, /* Imports */[
  'dart/_runtime',
  'logging/logging',
  'dart/core',
  'atom/atom',
  'atom_flutter/flutter'
], /* Lazy imports */[
], function(exports, dart, logging, core, atom, flutter) {

'use strict';
let dartx = dart.dartx;

function main() {
  logging.Logger.root.level = logging.Level.INFO;
  logging.Logger.root.onRecord.listen(dart.fn(r => {
    let tag = `[${r.loggerName} ${r.level.name[dartx.toLowerCase]()}: `;
    core.print(`${tag} ${r.message}`);
    if (r.error != null) core.print(`${tag}   ${r.error}`);
    if (r.stackTrace != null) core.print(`${tag}   ${r.stackTrace}`);
  }, dart.void, [logging.LogRecord]));
  atom.registerPackageDDC(new flutter.FlutterDevPackage());
}
dart.fn(main);

exports.main = main;
});

//# sourceMappingURL=entry.js.map

@jmesserly
Copy link
Contributor

This issue was moved to dart-lang/sdk#27306

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants