Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Unified Diff: sdk/lib/_internal/compiler/implementation/js/printer.dart

Issue 12084043: dart2js: Replace semicolons with newlines in minified output (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/implementation/js/printer.dart
diff --git a/sdk/lib/_internal/compiler/implementation/js/printer.dart b/sdk/lib/_internal/compiler/implementation/js/printer.dart
index 1cdfbf977d261038b16aa2db2738d62b738b044e..504933d8070a5628ccf1133289ae5892259f76fc 100644
--- a/sdk/lib/_internal/compiler/implementation/js/printer.dart
+++ b/sdk/lib/_internal/compiler/implementation/js/printer.dart
@@ -16,6 +16,7 @@ class Printer implements NodeVisitor {
bool pendingSemicolon = false;
bool pendingSpace = false;
static final identifierCharacterRegExp = new RegExp(r'^[a-zA-Z_0-9$]');
+ static final expressionContinuationRegExp = new RegExp(r'^[-+([]');
Printer(leg.Compiler compiler, { allowVariableMinification: true })
: shouldCompressOutput = compiler.enableMinification,
@@ -52,8 +53,23 @@ class Printer implements NodeVisitor {
void out(String str) {
if (str != "") {
- if (pendingSemicolon && (!shouldCompressOutput || str != "}")) {
- outBuffer.add(";");
+ if (pendingSemicolon) {
+ if (!shouldCompressOutput) {
+ outBuffer.add(";");
+ } else if (str != "}") {
+ // We want to output newline instead of semicolon because it makes
+ // the raw stack traces much easier to read and it also makes line-
+ // based tools like diff work much better. JavaScript will
+ // automatically insert the semicolon at the newline if it means a
+ // parsing error is avoided, so we can only do this trick if the
+ // next line is not something that can be glued onto a valid
+ // expression to make a new valid expression.
+ if (expressionContinuationRegExp.hasMatch(str)) {
+ outBuffer.add(";");
+ } else {
+ outBuffer.add("\n");
+ }
+ }
}
if (pendingSpace &&
(!shouldCompressOutput || identifierCharacterRegExp.hasMatch(str))) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698