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

Side by Side Diff: pkg/js_ast/lib/src/printer.dart

Issue 1212613009: dart2js: Implement frequency based naming. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of js_ast; 5 part of js_ast;
6 6
7 7
8 typedef String Renamer(Name);
9
8 class JavaScriptPrintingOptions { 10 class JavaScriptPrintingOptions {
9 final bool shouldCompressOutput; 11 final bool shouldCompressOutput;
10 final bool minifyLocalVariables; 12 final bool minifyLocalVariables;
11 final bool preferSemicolonToNewlineInMinifiedOutput; 13 final bool preferSemicolonToNewlineInMinifiedOutput;
14 final Renamer renamerForNames;
12 15
13 JavaScriptPrintingOptions( 16 JavaScriptPrintingOptions(
14 {this.shouldCompressOutput: false, 17 {this.shouldCompressOutput: false,
15 this.minifyLocalVariables: false, 18 this.minifyLocalVariables: false,
16 this.preferSemicolonToNewlineInMinifiedOutput: false}); 19 this.preferSemicolonToNewlineInMinifiedOutput: false,
20 this.renamerForNames: identityRenamer});
21
22 static String identityRenamer(Name name) => name.name;
17 } 23 }
18 24
19 25
20 /// An environment in which JavaScript printing is done. Provides emitting of 26 /// An environment in which JavaScript printing is done. Provides emitting of
21 /// text and pre- and post-visit callbacks. 27 /// text and pre- and post-visit callbacks.
22 abstract class JavaScriptPrintingContext { 28 abstract class JavaScriptPrintingContext {
23 /// Signals an error. This should happen only for serious internal errors. 29 /// Signals an error. This should happen only for serious internal errors.
24 void error(String message) { throw message; } 30 void error(String message) { throw message; }
25 31
26 /// Adds [string] to the output. 32 /// Adds [string] to the output.
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 String fieldWithQuotes = selectorString.value; 929 String fieldWithQuotes = selectorString.value;
924 if (isValidJavaScriptId(fieldWithQuotes)) { 930 if (isValidJavaScriptId(fieldWithQuotes)) {
925 if (access.receiver is LiteralNumber) out(" ", isWhitespace: true); 931 if (access.receiver is LiteralNumber) out(" ", isWhitespace: true);
926 out("."); 932 out(".");
927 out(fieldWithQuotes.substring(1, fieldWithQuotes.length - 1)); 933 out(fieldWithQuotes.substring(1, fieldWithQuotes.length - 1));
928 return; 934 return;
929 } 935 }
930 } else if (selector is Name) { 936 } else if (selector is Name) {
931 if (access.receiver is LiteralNumber) out(" ", isWhitespace: true); 937 if (access.receiver is LiteralNumber) out(" ", isWhitespace: true);
932 out("."); 938 out(".");
933 out(selector.name); 939 selector.accept(this);
934 return; 940 return;
935 } 941 }
936 out("["); 942 out("[");
937 visitNestedExpression(selector, EXPRESSION, 943 visitNestedExpression(selector, EXPRESSION,
938 newInForInit: false, newAtStatementBegin: false); 944 newInForInit: false, newAtStatementBegin: false);
939 out("]"); 945 out("]");
940 } 946 }
941 947
942 @override 948 @override
943 void visitNamedFunction(NamedFunction namedFunction) { 949 void visitNamedFunction(NamedFunction namedFunction) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 out(node.value); 997 out(node.value);
992 } 998 }
993 999
994 @override 1000 @override
995 visitStringConcatenation(StringConcatenation node) { 1001 visitStringConcatenation(StringConcatenation node) {
996 node.visitChildren(this); 1002 node.visitChildren(this);
997 } 1003 }
998 1004
999 @override 1005 @override
1000 visitName(Name node) { 1006 visitName(Name node) {
1001 out(node.name); 1007 out(options.renamerForNames(node));
1002 } 1008 }
1003 1009
1004 @override 1010 @override
1005 visitLiteralNumber(LiteralNumber node) { 1011 visitLiteralNumber(LiteralNumber node) {
1006 outputNumberWithRequiredWhitespace(node.value); 1012 outputNumberWithRequiredWhitespace(node.value);
1007 } 1013 }
1008 1014
1009 @override 1015 @override
1010 void visitLiteralNull(LiteralNull node) { 1016 void visitLiteralNull(LiteralNull node) {
1011 out("null"); 1017 out("null");
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 } 1468 }
1463 } 1469 }
1464 1470
1465 EnterExitNode exitNode(JavaScriptPrintingContext context, int position) { 1471 EnterExitNode exitNode(JavaScriptPrintingContext context, int position) {
1466 // Enter must happen before exit. 1472 // Enter must happen before exit.
1467 addToNode(context, position); 1473 addToNode(context, position);
1468 context.exitNode(node, startPosition, position, closingPosition); 1474 context.exitNode(node, startPosition, position, closingPosition);
1469 return parent; 1475 return parent;
1470 } 1476 }
1471 } 1477 }
OLDNEW
« pkg/compiler/lib/src/js_emitter/metadata_collector.dart ('K') | « pkg/js_ast/lib/src/nodes.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698