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 26 matching lines...) Expand all Loading... |
37 | 37 |
38 String lastAddedString = null; | 38 String lastAddedString = null; |
39 int get lastCharCode { | 39 int get lastCharCode { |
40 if (lastAddedString == null) return 0; | 40 if (lastAddedString == null) return 0; |
41 assert(lastAddedString.length != ""); | 41 assert(lastAddedString.length != ""); |
42 return lastAddedString.charCodeAt(lastAddedString.length - 1); | 42 return lastAddedString.charCodeAt(lastAddedString.length - 1); |
43 } | 43 } |
44 | 44 |
45 void out(String str) { | 45 void out(String str) { |
46 if (str != "") { | 46 if (str != "") { |
47 const identifierRegexp = const RegExp(r'^[a-zA-Z_0-9$]'); | 47 const identifierCharacterRegExp = const RegExp(r'^[a-zA-Z_0-9$]'); |
48 if (pendingSemicolon && (!shouldCompressOutput || str != "}")) { | 48 if (pendingSemicolon && (!shouldCompressOutput || str != "}")) { |
49 outBuffer.add(";"); | 49 outBuffer.add(";"); |
50 } | 50 } |
51 if (pendingSpace && | 51 if (pendingSpace && |
52 (!shouldCompressOutput || identifierRegexp.hasMatch(str))) { | 52 (!shouldCompressOutput || identifierCharacterRegExp.hasMatch(str))) { |
53 outBuffer.add(" "); | 53 outBuffer.add(" "); |
54 } | 54 } |
55 pendingSpace = false; | 55 pendingSpace = false; |
56 pendingSemicolon = false; | 56 pendingSemicolon = false; |
57 outBuffer.add(str); | 57 outBuffer.add(str); |
58 lastAddedString = str; | 58 lastAddedString = str; |
59 } | 59 } |
60 } | 60 } |
61 | 61 |
62 void outLn(String str) { | 62 void outLn(String str) { |
(...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1004 } | 1004 } |
1005 codes.add(charCodes.$0 + digit); | 1005 codes.add(charCodes.$0 + digit); |
1006 newName = new String.fromCharCodes(codes); | 1006 newName = new String.fromCharCodes(codes); |
1007 } | 1007 } |
1008 assert(const RegExp(r'[a-zA-Z][a-zA-Z0-9]*').hasMatch(newName)); | 1008 assert(const RegExp(r'[a-zA-Z][a-zA-Z0-9]*').hasMatch(newName)); |
1009 nameNumber++; | 1009 nameNumber++; |
1010 maps.last[oldName] = newName; | 1010 maps.last[oldName] = newName; |
1011 return newName; | 1011 return newName; |
1012 } | 1012 } |
1013 } | 1013 } |
OLD | NEW |