OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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_backend; | 5 part of js_backend; |
6 | 6 |
7 /** | 7 /** |
8 * Assigns JavaScript identifiers to Dart variables, class-names and members. | 8 * Assigns JavaScript identifiers to Dart variables, class-names and members. |
9 */ | 9 */ |
10 class MinifyNamer extends Namer { | 10 class MinifyNamer extends Namer { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 instanceNameMap[name] = name; | 78 instanceNameMap[name] = name; |
79 } | 79 } |
80 usedInstanceNames.add(name); | 80 usedInstanceNames.add(name); |
81 // Getter and setter names are autogenerated by prepending 'g' and 's' to | 81 // Getter and setter names are autogenerated by prepending 'g' and 's' to |
82 // field names. Therefore there are some field names we don't want to | 82 // field names. Therefore there are some field names we don't want to |
83 // use. It is implicit in the next line that the banned prefix is | 83 // use. It is implicit in the next line that the banned prefix is |
84 // only one character. | 84 // only one character. |
85 if (_hasBannedPrefix(name)) usedInstanceNames.add(name.substring(1)); | 85 if (_hasBannedPrefix(name)) usedInstanceNames.add(name.substring(1)); |
86 } | 86 } |
87 | 87 |
88 // This list of popular instance variable names generated with: | 88 // These popular names are present in most programs and deserve |
89 // cat out.js | | 89 // single character minified names. We could determine the popular names |
90 // perl -ne '$_=~s/(?<![^a-z0-9_\$]\$)\.([a-z0-9_\$]+)/print("$1\n")/gei' | | 90 // individually per program, but that would mean that the output of the |
91 // sort | uniq -c | sort -nr | head -40 | 91 // minifier was less stable from version to version of the program being |
92 // Removed: html, call*, hasOwnProperty. | 92 // minified. |
93 _populateSuggestedNames( | 93 _populateSuggestedNames( |
94 suggestedInstanceNames, | 94 suggestedInstanceNames, |
95 usedInstanceNames, | 95 usedInstanceNames, |
96 const <String>[ | 96 const <String>[ |
97 r'$add', r'add$1', r'box_0', r'codeUnitAt$1', r'constructor', | 97 r'$add', r'add$1', r'$and', r'codeUnitAt$1', r'$or', |
98 r'current', r'$defineNativeClass', r'$eq', r'$ne', | 98 r'current', r'$shr', r'$eq', r'$ne', |
99 r'getPrototypeOf', r'hasOwnProperty', r'$index', r'$indexSet', | 99 r'getPrototypeOf', r'hasOwnProperty', r'$index', r'$indexSet', |
100 r'$isJavaScriptIndexingBehavior', r'$isolateProperties', | 100 r'$isJavaScriptIndexingBehavior', r'$xor', |
101 r'iterator', r'length', r'$lt', r'$gt', r'$le', r'$ge', | 101 r'iterator', r'length', r'$lt', r'$gt', r'$le', r'$ge', |
102 r'moveNext$0', r'node', r'on', r'prototype', r'push', r'self', | 102 r'moveNext$0', r'node', r'on', r'$negate', r'push', r'self', |
103 r'start', r'target', r'this_0', r'value', r'width', r'style']); | 103 r'start', r'target', r'$shl', r'value', r'width', r'style', |
| 104 r'noSuchMethod$1', r'$mul', r'$div', r'$sub', r'$not', r'$mod', |
| 105 r'$tdiv']); |
104 | 106 |
105 _populateSuggestedNames( | 107 _populateSuggestedNames( |
106 suggestedGlobalNames, | 108 suggestedGlobalNames, |
107 usedGlobalNames, | 109 usedGlobalNames, |
108 const <String>[ | 110 const <String>[ |
109 r'Object', r'$throw', r'$eq', r'S', r'ioore', r'UnsupportedError$', | 111 r'Object', r'$throw', r'$eq', r'S', r'ioore', r'UnsupportedError$', |
110 r'length', r'$sub', r'getInterceptor$JSArrayJSString', r'$add', | 112 r'length', r'$sub', r'getInterceptor$JSArrayJSString', r'$add', |
111 r'$gt', r'$ge', r'$lt', r'$le', r'add', r'getInterceptor$JSNumber', | 113 r'$gt', r'$ge', r'$lt', r'$le', r'add', r'getInterceptor$JSNumber', |
112 r'iterator', r'$index', r'iae', r'getInterceptor$JSArray', | 114 r'iterator', r'$index', r'iae', r'getInterceptor$JSArray', |
113 r'ArgumentError$', r'BoundClosure', r'StateError$', | 115 r'ArgumentError$', r'BoundClosure', r'StateError$', |
114 r'getInterceptor', r'max', r'$mul', r'List_List', r'Map_Map', | 116 r'getInterceptor', r'max', r'$mul', r'List_List', r'Map_Map', |
115 r'getInterceptor$JSString', r'$div', r'$indexSet', | 117 r'getInterceptor$JSString', r'$div', r'$indexSet', |
116 r'List_List$from', r'Set_Set$from', r'toString', r'toInt', r'min', | 118 r'List_List$from', r'Set_Set$from', r'toString', r'toInt', r'min', |
117 r'StringBuffer_StringBuffer', r'contains1', r'WhereIterable$', | 119 r'StringBuffer_StringBuffer', r'contains1', r'WhereIterable$', |
118 r'RangeError$value', r'JSString', r'JSNumber', | 120 r'RangeError$value', r'JSString', r'JSNumber', |
119 r'JSArray' | 121 r'JSArray', r'createInvocationMirror' |
120 ]); | 122 ]); |
121 } | 123 } |
122 | 124 |
123 void _populateSuggestedNames(Map<String, String> suggestionMap, | 125 void _populateSuggestedNames(Map<String, String> suggestionMap, |
124 Set<String> used, | 126 Set<String> used, |
125 List<String> suggestions) { | 127 List<String> suggestions) { |
126 int c = $a - 1; | 128 int c = $a - 1; |
127 String letter; | 129 String letter; |
128 for (String name in suggestions) { | 130 for (String name in suggestions) { |
129 do { | 131 do { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 } | 214 } |
213 | 215 |
214 int _alphaNumericNumber(int x) { | 216 int _alphaNumericNumber(int x) { |
215 if (x >= ALPHANUMERIC_CHARACTERS) x %= ALPHANUMERIC_CHARACTERS; | 217 if (x >= ALPHANUMERIC_CHARACTERS) x %= ALPHANUMERIC_CHARACTERS; |
216 if (x < 26) return $a + x; | 218 if (x < 26) return $a + x; |
217 if (x < 52) return $A + x - 26; | 219 if (x < 52) return $A + x - 26; |
218 return $0 + x - 52; | 220 return $0 + x - 52; |
219 } | 221 } |
220 | 222 |
221 } | 223 } |
OLD | NEW |