Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 945 } | 945 } |
| 946 | 946 |
| 947 @override | 947 @override |
| 948 void visitFun(Fun fun) { | 948 void visitFun(Fun fun) { |
| 949 VarCollector vars = new VarCollector(); | 949 VarCollector vars = new VarCollector(); |
| 950 vars.visitFun(fun); | 950 vars.visitFun(fun); |
| 951 currentNode.closingPosition = functionOut(fun, null, vars); | 951 currentNode.closingPosition = functionOut(fun, null, vars); |
| 952 } | 952 } |
| 953 | 953 |
| 954 @override | 954 @override |
| 955 void visitLiteralBool(LiteralBool node) { | 955 visitTokenExpression(TokenExpression node) { |
| 956 // Continue printing with the expression value. | |
| 957 node.value.accept(this); | |
|
sra1
2015/05/27 19:38:51
Either the precedence needs to be fixed or this co
herhut
2015/06/09 11:10:00
Done.
| |
| 958 } | |
| 959 | |
| 960 @override | |
| 961 visitTokenNumber(TokenNumber node) { | |
| 962 String value = "${node.value}"; | |
| 963 int charCode = value.codeUnitAt(0); | |
| 964 if (charCode == charCodes.$MINUS && lastCharCode == charCodes.$MINUS) { | |
| 965 out(" "); | |
|
sra1
2015/05/27 20:30:15
I'd like to see a test that covers this case.
herhut
2015/06/09 11:10:00
I have factored out the logic from visitLiteralNum
| |
| 966 } | |
| 967 out(value); | |
| 968 } | |
| 969 | |
| 970 @override | |
| 971 visitTokenString(TokenString node) { | |
| 972 out(node.value); | |
| 973 } | |
| 974 | |
| 975 @override | |
| 976 visitLiteralBool(LiteralBool node) { | |
| 956 out(node.value ? "true" : "false"); | 977 out(node.value ? "true" : "false"); |
| 957 } | 978 } |
| 958 | 979 |
| 959 @override | 980 @override |
| 960 void visitLiteralString(LiteralString node) { | 981 void visitLiteralString(LiteralString node) { |
| 961 out(node.value); | 982 out(node.value); |
| 962 } | 983 } |
| 963 | 984 |
| 964 @override | 985 @override |
| 965 void visitLiteralNumber(LiteralNumber node) { | 986 visitStringConcatenation(StringConcatenation node) { |
| 987 node.visitChildren(this); | |
| 988 } | |
| 989 | |
| 990 @override | |
| 991 visitLiteralNumber(LiteralNumber node) { | |
| 966 int charCode = node.value.codeUnitAt(0); | 992 int charCode = node.value.codeUnitAt(0); |
| 967 if (charCode == charCodes.$MINUS && lastCharCode == charCodes.$MINUS) { | 993 if (charCode == charCodes.$MINUS && lastCharCode == charCodes.$MINUS) { |
| 968 out(" ", isWhitespace: true); | 994 out(" ", isWhitespace: true); |
| 969 } | 995 } |
| 970 out(node.value); | 996 out(node.value); |
| 971 } | 997 } |
| 972 | 998 |
| 973 @override | 999 @override |
| 974 void visitLiteralNull(LiteralNull node) { | 1000 void visitLiteralNull(LiteralNull node) { |
| 975 out("null"); | 1001 out("null"); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 1006 | 1032 |
| 1007 @override | 1033 @override |
| 1008 void visitObjectInitializer(ObjectInitializer node) { | 1034 void visitObjectInitializer(ObjectInitializer node) { |
| 1009 // Print all the properties on one line until we see a function-valued | 1035 // Print all the properties on one line until we see a function-valued |
| 1010 // property. Ideally, we would use a proper pretty-printer to make the | 1036 // property. Ideally, we would use a proper pretty-printer to make the |
| 1011 // decision based on layout. | 1037 // decision based on layout. |
| 1012 List<Property> properties = node.properties; | 1038 List<Property> properties = node.properties; |
| 1013 out("{"); | 1039 out("{"); |
| 1014 indentMore(); | 1040 indentMore(); |
| 1015 for (int i = 0; i < properties.length; i++) { | 1041 for (int i = 0; i < properties.length; i++) { |
| 1016 Expression value = properties[i].value; | |
| 1017 if (i != 0) { | 1042 if (i != 0) { |
| 1018 out(","); | 1043 out(","); |
| 1019 if (node.isOneLiner) spaceOut(); | 1044 if (node.isOneLiner) spaceOut(); |
| 1020 } | 1045 } |
| 1021 if (!node.isOneLiner) { | 1046 if (!node.isOneLiner) { |
| 1022 forceLine(); | 1047 forceLine(); |
| 1023 indent(); | 1048 indent(); |
| 1024 } | 1049 } |
| 1025 visit(properties[i]); | 1050 visit(properties[i]); |
| 1026 } | 1051 } |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1425 } | 1450 } |
| 1426 } | 1451 } |
| 1427 | 1452 |
| 1428 EnterExitNode exitNode(JavaScriptPrintingContext context, int position) { | 1453 EnterExitNode exitNode(JavaScriptPrintingContext context, int position) { |
| 1429 // Enter must happen before exit. | 1454 // Enter must happen before exit. |
| 1430 addToNode(context, position); | 1455 addToNode(context, position); |
| 1431 context.exitNode(node, startPosition, position, closingPosition); | 1456 context.exitNode(node, startPosition, position, closingPosition); |
| 1432 return parent; | 1457 return parent; |
| 1433 } | 1458 } |
| 1434 } | 1459 } |
| OLD | NEW |