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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js/printer.dart

Issue 246633006: Revert "JS templates" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
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; 5 part of js;
6 6
7 class Printer implements NodeVisitor { 7 class Printer implements NodeVisitor {
8 final bool shouldCompressOutput; 8 final bool shouldCompressOutput;
9 leg.Compiler compiler; 9 leg.Compiler compiler;
10 leg.CodeBuffer outBuffer; 10 leg.CodeBuffer outBuffer;
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 for (int i = 0; i < inputsLength; i++) { 871 for (int i = 0; i < inputsLength; i++) {
872 visit(inputs[i]); 872 visit(inputs[i]);
873 out(parts[i + 1]); 873 out(parts[i + 1]);
874 } 874 }
875 } 875 }
876 876
877 visitLiteralStatement(LiteralStatement node) { 877 visitLiteralStatement(LiteralStatement node) {
878 outLn(node.code); 878 outLn(node.code);
879 } 879 }
880 880
881 visitInterpolatedNode(InterpolatedNode node) { 881 visitJSExpression(JSExpression node) {
882 out('#${node.name}'); 882 compiler.internalError(NO_LOCATION_SPANNABLE,
883 'JSPrinter should never see a JSExpression.');
883 } 884 }
884 885
885 visitInterpolatedExpression(InterpolatedExpression node) => 886 visitInterpolatedExpression(InterpolatedExpression node) {
886 visitInterpolatedNode(node); 887 visit(node.value);
887 888 }
888 visitInterpolatedLiteral(InterpolatedLiteral node) =>
889 visitInterpolatedNode(node);
890
891 visitInterpolatedParameter(InterpolatedParameter node) =>
892 visitInterpolatedNode(node);
893
894 visitInterpolatedSelector(InterpolatedSelector node) =>
895 visitInterpolatedNode(node);
896 889
897 visitInterpolatedStatement(InterpolatedStatement node) { 890 visitInterpolatedStatement(InterpolatedStatement node) {
898 outLn('#${node.name}'); 891 visit(node.value);
899 } 892 }
900 893
901 void visitComment(Comment node) { 894 void visitComment(Comment node) {
902 if (shouldCompressOutput) return; 895 if (shouldCompressOutput) return;
903 String comment = node.comment.trim(); 896 String comment = node.comment.trim();
904 if (comment.isEmpty) return; 897 if (comment.isEmpty) return;
905 for (var line in comment.split('\n')) { 898 for (var line in comment.split('\n')) {
906 if (comment.startsWith('//')) { 899 if (comment.startsWith('//')) {
907 outIndentLn(line.trim()); 900 outIndentLn(line.trim());
908 } else { 901 } else {
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 } 1096 }
1104 1097
1105 // Parameters go from a to z and variables go from z to a. This makes each 1098 // Parameters go from a to z and variables go from z to a. This makes each
1106 // argument list and each top-of-function var declaration look similar and 1099 // argument list and each top-of-function var declaration look similar and
1107 // helps gzip compress the file. If we have more than 26 arguments and 1100 // helps gzip compress the file. If we have more than 26 arguments and
1108 // variables then we meet somewhere in the middle of the alphabet. After 1101 // variables then we meet somewhere in the middle of the alphabet. After
1109 // that we give up trying to be nice to the compression algorithm and just 1102 // that we give up trying to be nice to the compression algorithm and just
1110 // use the same namespace for arguments and variables, starting with A, and 1103 // use the same namespace for arguments and variables, starting with A, and
1111 // moving on to a0, a1, etc. 1104 // moving on to a0, a1, etc.
1112 String declareVariable(String oldName) { 1105 String declareVariable(String oldName) {
1113 // Variables of this $form$ are used in pattern matching the message of JS
1114 // exceptions, so should not be renamed.
1115 // TODO(sra): Introduce a way for indicating in the JS text which variables
1116 // should not be renamed.
1117 if (oldName.startsWith(r'$') && oldName.endsWith(r'$')) return oldName;
1118
1119 var newName; 1106 var newName;
1120 if (variableNumber + parameterNumber < LOWER_CASE_LETTERS) { 1107 if (variableNumber + parameterNumber < LOWER_CASE_LETTERS) {
1121 // Variables start from z and go backwards, for better gzipability. 1108 // Variables start from z and go backwards, for better gzipability.
1122 newName = getNameNumber(oldName, LOWER_CASE_LETTERS - 1 - variableNumber); 1109 newName = getNameNumber(oldName, LOWER_CASE_LETTERS - 1 - variableNumber);
1123 } else { 1110 } else {
1124 // After 26 variables and parameters we allocate them in the same order. 1111 // After 26 variables and parameters we allocate them in the same order.
1125 newName = getNameNumber(oldName, variableNumber + parameterNumber); 1112 newName = getNameNumber(oldName, variableNumber + parameterNumber);
1126 } 1113 }
1127 variableNumber++; 1114 variableNumber++;
1128 return newName; 1115 return newName;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 codes.add(nthLetter((n ~/ nameSpaceSize) % LETTERS)); 1155 codes.add(nthLetter((n ~/ nameSpaceSize) % LETTERS));
1169 } 1156 }
1170 codes.add(charCodes.$0 + digit); 1157 codes.add(charCodes.$0 + digit);
1171 newName = new String.fromCharCodes(codes); 1158 newName = new String.fromCharCodes(codes);
1172 } 1159 }
1173 assert(new RegExp(r'[a-zA-Z][a-zA-Z0-9]*').hasMatch(newName)); 1160 assert(new RegExp(r'[a-zA-Z][a-zA-Z0-9]*').hasMatch(newName));
1174 maps.last[oldName] = newName; 1161 maps.last[oldName] = newName;
1175 return newName; 1162 return newName;
1176 } 1163 }
1177 } 1164 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/js/nodes.dart ('k') | sdk/lib/_internal/compiler/implementation/js/template.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698