Skip to content

cosmetic changes to the generated JS? #27306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jmesserly opened this issue Sep 13, 2016 · 5 comments
Closed

cosmetic changes to the generated JS? #27306

jmesserly opened this issue Sep 13, 2016 · 5 comments

Comments

@jmesserly
Copy link

From @devoncarew on January 22, 2016 20:0

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

Copied from original issue: dart-archive/dev_compiler#425

@jmesserly
Copy link
Author

From @devoncarew on January 22, 2016 20:5

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
Author

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 dart-archive/dev_compiler#285, dart-archive/dev_compiler#284, dart-archive/dev_compiler#34.

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

@jmesserly
Copy link
Author

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

@jmesserly
Copy link
Author

From @devoncarew on January 22, 2016 20:10

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
Author

I don't think we're likely to make cosmetic improvements at this point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant