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; | 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 28 matching lines...) Expand all Loading... | |
| 39 | 39 |
| 40 String lastAddedString = null; | 40 String lastAddedString = null; |
| 41 int get lastCharCode { | 41 int get lastCharCode { |
| 42 if (lastAddedString == null) return 0; | 42 if (lastAddedString == null) return 0; |
| 43 assert(lastAddedString.length != ""); | 43 assert(lastAddedString.length != ""); |
| 44 return lastAddedString.charCodeAt(lastAddedString.length - 1); | 44 return lastAddedString.charCodeAt(lastAddedString.length - 1); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void out(String str) { | 47 void out(String str) { |
| 48 if (str != "") { | 48 if (str != "") { |
| 49 const identifierRegexp = const RegExp(r'^[a-zA-Z_0-9$]'); | 49 final identifierRegexp = new RegExp(r'^[a-zA-Z_0-9$]'); |
|
ahe
2012/11/12 13:35:03
I think this should be a static final field.
Anders Johnsen
2012/11/12 13:45:38
Done.
| |
| 50 if (pendingSemicolon && (!shouldCompressOutput || str != "}")) { | 50 if (pendingSemicolon && (!shouldCompressOutput || str != "}")) { |
| 51 outBuffer.add(";"); | 51 outBuffer.add(";"); |
| 52 } | 52 } |
| 53 if (pendingSpace && | 53 if (pendingSpace && |
| 54 (!shouldCompressOutput || identifierRegexp.hasMatch(str))) { | 54 (!shouldCompressOutput || identifierRegexp.hasMatch(str))) { |
| 55 outBuffer.add(" "); | 55 outBuffer.add(" "); |
| 56 } | 56 } |
| 57 pendingSpace = false; | 57 pendingSpace = false; |
| 58 pendingSemicolon = false; | 58 pendingSemicolon = false; |
| 59 outBuffer.add(str); | 59 outBuffer.add(str); |
| (...skipping 1000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1060 nameSpaceSize *= LETTERS; | 1060 nameSpaceSize *= LETTERS; |
| 1061 } | 1061 } |
| 1062 var codes = <int>[]; | 1062 var codes = <int>[]; |
| 1063 for (var i = 0; i < alphaChars; i++) { | 1063 for (var i = 0; i < alphaChars; i++) { |
| 1064 nameSpaceSize ~/= LETTERS; | 1064 nameSpaceSize ~/= LETTERS; |
| 1065 codes.add(nthLetter((n ~/ nameSpaceSize) % LETTERS)); | 1065 codes.add(nthLetter((n ~/ nameSpaceSize) % LETTERS)); |
| 1066 } | 1066 } |
| 1067 codes.add(charCodes.$0 + digit); | 1067 codes.add(charCodes.$0 + digit); |
| 1068 newName = new String.fromCharCodes(codes); | 1068 newName = new String.fromCharCodes(codes); |
| 1069 } | 1069 } |
| 1070 assert(const RegExp(r'[a-zA-Z][a-zA-Z0-9]*').hasMatch(newName)); | 1070 assert(new RegExp(r'[a-zA-Z][a-zA-Z0-9]*').hasMatch(newName)); |
| 1071 maps.last[oldName] = newName; | 1071 maps.last[oldName] = newName; |
| 1072 return newName; | 1072 return newName; |
| 1073 } | 1073 } |
| 1074 } | 1074 } |
| OLD | NEW |