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

Side by Side Diff: lib/src/js/printer.dart

Issue 1153003003: fixes #40, extension methods for primitive types (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 6 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 876 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 } 887 }
888 out(node.value); 888 out(node.value);
889 } 889 }
890 890
891 visitLiteralNull(LiteralNull node) { 891 visitLiteralNull(LiteralNull node) {
892 out("null"); 892 out("null");
893 } 893 }
894 894
895 visitArrayInitializer(ArrayInitializer node) { 895 visitArrayInitializer(ArrayInitializer node) {
896 out("["); 896 out("[");
897 indentMore();
898 var multiline = node.multiline;
897 List<Expression> elements = node.elements; 899 List<Expression> elements = node.elements;
898 for (int i = 0; i < elements.length; i++) { 900 for (int i = 0; i < elements.length; i++) {
899 Expression element = elements[i]; 901 Expression element = elements[i];
900 if (element is ArrayHole) { 902 if (element is ArrayHole) {
901 // Note that array holes must have a trailing "," even if they are 903 // Note that array holes must have a trailing "," even if they are
902 // in last position. Otherwise `[,]` (having length 1) would become 904 // in last position. Otherwise `[,]` (having length 1) would become
903 // equal to `[]` (the empty array) 905 // equal to `[]` (the empty array)
904 // and [1,,] (array with 1 and a hole) would become [1,] = [1]. 906 // and [1,,] (array with 1 and a hole) would become [1,] = [1].
905 out(","); 907 out(",");
906 continue; 908 continue;
907 } 909 }
908 if (i != 0) spaceOut(); 910 if (i != 0 && !multiline) spaceOut();
911 if (multiline) {
912 forceLine();
913 indent();
914 }
909 visitNestedExpression(element, ASSIGNMENT, 915 visitNestedExpression(element, ASSIGNMENT,
910 newInForInit: false, newAtStatementBegin: false); 916 newInForInit: false, newAtStatementBegin: false);
911 // We can skip the trailing "," for the last element (since it's not 917 // We can skip the trailing "," for the last element (since it's not
912 // an array hole). 918 // an array hole).
913 if (i != elements.length - 1) out(","); 919 if (i != elements.length - 1) out(",");
914 } 920 }
921 indentLess();
922 if (multiline) {
923 lineOut();
924 indent();
925 }
915 out("]"); 926 out("]");
916 } 927 }
917 928
918 visitArrayHole(ArrayHole node) { 929 visitArrayHole(ArrayHole node) {
919 throw "Unreachable"; 930 throw "Unreachable";
920 } 931 }
921 932
922 visitObjectInitializer(ObjectInitializer node) { 933 visitObjectInitializer(ObjectInitializer node) {
923 List<Property> properties = node.properties; 934 List<Property> properties = node.properties;
924 out("{"); 935 out("{");
925 indentMore(); 936 indentMore();
926 937
927 var isOneLiner = !node.vertical; 938 var multiline = node.multiline;
928 for (int i = 0; i < properties.length; i++) { 939 for (int i = 0; i < properties.length; i++) {
929 if (i != 0) { 940 if (i != 0) {
930 out(","); 941 out(",");
931 if (isOneLiner) spaceOut(); 942 if (!multiline) spaceOut();
932 } 943 }
933 if (!isOneLiner) { 944 if (multiline) {
934 forceLine(); 945 forceLine();
935 indent(); 946 indent();
936 } 947 }
937 visit(properties[i]); 948 visit(properties[i]);
938 } 949 }
939 indentLess(); 950 indentLess();
940 if (!isOneLiner) { 951 if (multiline) {
941 lineOut(); 952 lineOut();
942 indent(); 953 indent();
943 } 954 }
944 out("}"); 955 out("}");
945 } 956 }
946 957
947 visitProperty(Property node) { 958 visitProperty(Property node) {
948 propertyNameOut(node.name); 959 propertyNameOut(node.name);
949 out(":"); 960 out(":");
950 spaceOut(); 961 spaceOut();
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
1431 declare(node.name); 1442 declare(node.name);
1432 node.function.accept(this); 1443 node.function.accept(this);
1433 } 1444 }
1434 1445
1435 visitClassExpression(ClassExpression node) { 1446 visitClassExpression(ClassExpression node) {
1436 declare(node.name); 1447 declare(node.name);
1437 if (node.heritage != null) node.heritage.accept(this); 1448 if (node.heritage != null) node.heritage.accept(this);
1438 for (Method element in node.methods) element.accept(this); 1449 for (Method element in node.methods) element.accept(this);
1439 } 1450 }
1440 } 1451 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698