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 909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
920 Node selector = access.selector; | 920 Node selector = access.selector; |
921 if (selector is LiteralString) { | 921 if (selector is LiteralString) { |
922 LiteralString selectorString = selector; | 922 LiteralString selectorString = selector; |
923 String fieldWithQuotes = selectorString.value; | 923 String fieldWithQuotes = selectorString.value; |
924 if (isValidJavaScriptId(fieldWithQuotes)) { | 924 if (isValidJavaScriptId(fieldWithQuotes)) { |
925 if (access.receiver is LiteralNumber) out(" ", isWhitespace: true); | 925 if (access.receiver is LiteralNumber) out(" ", isWhitespace: true); |
926 out("."); | 926 out("."); |
927 out(fieldWithQuotes.substring(1, fieldWithQuotes.length - 1)); | 927 out(fieldWithQuotes.substring(1, fieldWithQuotes.length - 1)); |
928 return; | 928 return; |
929 } | 929 } |
| 930 } else if (selector is Name) { |
| 931 if (access.receiver is LiteralNumber) out(" ", isWhitespace: true); |
| 932 out("."); |
| 933 out(selector.name); |
| 934 return; |
930 } | 935 } |
931 out("["); | 936 out("["); |
932 visitNestedExpression(selector, EXPRESSION, | 937 visitNestedExpression(selector, EXPRESSION, |
933 newInForInit: false, newAtStatementBegin: false); | 938 newInForInit: false, newAtStatementBegin: false); |
934 out("]"); | 939 out("]"); |
935 } | 940 } |
936 | 941 |
937 @override | 942 @override |
938 void visitNamedFunction(NamedFunction namedFunction) { | 943 void visitNamedFunction(NamedFunction namedFunction) { |
939 VarCollector vars = new VarCollector(); | 944 VarCollector vars = new VarCollector(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 void visitLiteralString(LiteralString node) { | 990 void visitLiteralString(LiteralString node) { |
986 out(node.value); | 991 out(node.value); |
987 } | 992 } |
988 | 993 |
989 @override | 994 @override |
990 visitStringConcatenation(StringConcatenation node) { | 995 visitStringConcatenation(StringConcatenation node) { |
991 node.visitChildren(this); | 996 node.visitChildren(this); |
992 } | 997 } |
993 | 998 |
994 @override | 999 @override |
| 1000 visitName(Name node) { |
| 1001 out(node.name); |
| 1002 } |
| 1003 |
| 1004 @override |
995 visitLiteralNumber(LiteralNumber node) { | 1005 visitLiteralNumber(LiteralNumber node) { |
996 outputNumberWithRequiredWhitespace(node.value); | 1006 outputNumberWithRequiredWhitespace(node.value); |
997 } | 1007 } |
998 | 1008 |
999 @override | 1009 @override |
1000 void visitLiteralNull(LiteralNull node) { | 1010 void visitLiteralNull(LiteralNull node) { |
1001 out("null"); | 1011 out("null"); |
1002 } | 1012 } |
1003 | 1013 |
1004 @override | 1014 @override |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1060 @override | 1070 @override |
1061 void visitProperty(Property node) { | 1071 void visitProperty(Property node) { |
1062 if (node.name is LiteralString) { | 1072 if (node.name is LiteralString) { |
1063 LiteralString nameString = node.name; | 1073 LiteralString nameString = node.name; |
1064 String name = nameString.value; | 1074 String name = nameString.value; |
1065 if (isValidJavaScriptId(name)) { | 1075 if (isValidJavaScriptId(name)) { |
1066 out(name.substring(1, name.length - 1)); | 1076 out(name.substring(1, name.length - 1)); |
1067 } else { | 1077 } else { |
1068 out(name); | 1078 out(name); |
1069 } | 1079 } |
| 1080 } else if (node.name is Name) { |
| 1081 node.name.accept(this); |
1070 } else { | 1082 } else { |
1071 assert(node.name is LiteralNumber); | 1083 assert(node.name is LiteralNumber); |
1072 LiteralNumber nameNumber = node.name; | 1084 LiteralNumber nameNumber = node.name; |
1073 out(nameNumber.value); | 1085 out(nameNumber.value); |
1074 } | 1086 } |
1075 out(":"); | 1087 out(":"); |
1076 spaceOut(); | 1088 spaceOut(); |
1077 visitNestedExpression(node.value, ASSIGNMENT, | 1089 visitNestedExpression(node.value, ASSIGNMENT, |
1078 newInForInit: false, newAtStatementBegin: false); | 1090 newInForInit: false, newAtStatementBegin: false); |
1079 } | 1091 } |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1450 } | 1462 } |
1451 } | 1463 } |
1452 | 1464 |
1453 EnterExitNode exitNode(JavaScriptPrintingContext context, int position) { | 1465 EnterExitNode exitNode(JavaScriptPrintingContext context, int position) { |
1454 // Enter must happen before exit. | 1466 // Enter must happen before exit. |
1455 addToNode(context, position); | 1467 addToNode(context, position); |
1456 context.exitNode(node, startPosition, position, closingPosition); | 1468 context.exitNode(node, startPosition, position, closingPosition); |
1457 return parent; | 1469 return parent; |
1458 } | 1470 } |
1459 } | 1471 } |
OLD | NEW |