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

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

Issue 1140703006: dart2js: Construct the entire output as a single AST before printing. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 7 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 class JavaScriptPrintingOptions { 8 class JavaScriptPrintingOptions {
9 final bool shouldCompressOutput; 9 final bool shouldCompressOutput;
10 final bool minifyLocalVariables; 10 final bool minifyLocalVariables;
(...skipping 1138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 1149
1150 void forEach(void fun(T x)) { 1150 void forEach(void fun(T x)) {
1151 list.forEach(fun); 1151 list.forEach(fun);
1152 } 1152 }
1153 } 1153 }
1154 1154
1155 // Collects all the var declarations in the function. We need to do this in a 1155 // Collects all the var declarations in the function. We need to do this in a
1156 // separate pass because JS vars are lifted to the top of the function. 1156 // separate pass because JS vars are lifted to the top of the function.
1157 class VarCollector extends BaseVisitor { 1157 class VarCollector extends BaseVisitor {
1158 bool nested; 1158 bool nested;
1159 bool disableRenaming = false;
floitsch 2015/05/19 13:43:35 change to "enableRenaming".
herhut 2015/05/19 14:08:09 Done.
1159 final OrderedSet<String> vars; 1160 final OrderedSet<String> vars;
1160 final OrderedSet<String> params; 1161 final OrderedSet<String> params;
1161 1162
1163 static final String disableVariableMinificationPattern = "::norenaming::";
1164 static final String enableVariableMinificationPattern = "::dorenaming::";
1165
1162 VarCollector() : nested = false, 1166 VarCollector() : nested = false,
1163 vars = new OrderedSet<String>(), 1167 vars = new OrderedSet<String>(),
1164 params = new OrderedSet<String>(); 1168 params = new OrderedSet<String>();
1165 1169
1166 void forEachVar(void fn(String v)) => vars.forEach(fn); 1170 void forEachVar(void fn(String v)) => vars.forEach(fn);
1167 void forEachParam(void fn(String p)) => params.forEach(fn); 1171 void forEachParam(void fn(String p)) => params.forEach(fn);
1168 1172
1169 void collectVarsInFunction(Fun fun) { 1173 void collectVarsInFunction(Fun fun) {
1170 if (!nested) { 1174 if (!nested) {
1171 nested = true; 1175 nested = true;
(...skipping 16 matching lines...) Expand all
1188 // Note that we don't bother collecting the name of the function. 1192 // Note that we don't bother collecting the name of the function.
1189 collectVarsInFunction(namedFunction.function); 1193 collectVarsInFunction(namedFunction.function);
1190 } 1194 }
1191 1195
1192 void visitFun(Fun fun) { 1196 void visitFun(Fun fun) {
1193 collectVarsInFunction(fun); 1197 collectVarsInFunction(fun);
1194 } 1198 }
1195 1199
1196 void visitThis(This node) {} 1200 void visitThis(This node) {}
1197 1201
1202 void visitComment(Comment node) {
1203 if (node.comment.contains(disableVariableMinificationPattern)) {
1204 disableRenaming = true;
1205 } else if (node.comment.contains(enableVariableMinificationPattern)) {
1206 disableRenaming = false;
1207 }
1208 }
1209
1198 void visitVariableDeclaration(VariableDeclaration decl) { 1210 void visitVariableDeclaration(VariableDeclaration decl) {
1199 if (decl.allowRename) vars.add(decl.name); 1211 if (!disableRenaming && decl.allowRename) vars.add(decl.name);
1200 } 1212 }
1201 } 1213 }
1202 1214
1203 1215
1204 /** 1216 /**
1205 * Returns true, if the given node must be wrapped into braces when used 1217 * Returns true, if the given node must be wrapped into braces when used
1206 * as then-statement in an [If] that has an else branch. 1218 * as then-statement in an [If] that has an else branch.
1207 */ 1219 */
1208 class DanglingElseVisitor extends BaseVisitor<bool> { 1220 class DanglingElseVisitor extends BaseVisitor<bool> {
1209 JavaScriptPrintingContext context; 1221 JavaScriptPrintingContext context;
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1413 } 1425 }
1414 } 1426 }
1415 1427
1416 EnterExitNode exitNode(JavaScriptPrintingContext context, int position) { 1428 EnterExitNode exitNode(JavaScriptPrintingContext context, int position) {
1417 // Enter must happen before exit. 1429 // Enter must happen before exit.
1418 addToNode(context, position); 1430 addToNode(context, position);
1419 context.exitNode(node, startPosition, position, closingPosition); 1431 context.exitNode(node, startPosition, position, closingPosition);
1420 return parent; 1432 return parent;
1421 } 1433 }
1422 } 1434 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698