| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 class FrequencyBasedNamer extends Namer with _MinifiedFieldNamer, | 7 class FrequencyBasedNamer extends Namer |
| 8 _MinifiedOneShotInterceptorNamer implements jsAst.TokenFinalizer { | 8 with _MinifiedFieldNamer, _MinifiedOneShotInterceptorNamer |
| 9 implements jsAst.TokenFinalizer { |
| 9 _FieldNamingRegistry fieldRegistry; | 10 _FieldNamingRegistry fieldRegistry; |
| 10 List<TokenName> tokens = new List<TokenName>(); | 11 List<TokenName> tokens = new List<TokenName>(); |
| 11 | 12 |
| 12 Map<NamingScope, TokenScope> _tokenScopes = | 13 Map<NamingScope, TokenScope> _tokenScopes = |
| 13 new Maplet<NamingScope, TokenScope>(); | 14 new Maplet<NamingScope, TokenScope>(); |
| 14 | 15 |
| 15 // Some basic settings for smaller names | 16 // Some basic settings for smaller names |
| 16 String get isolateName => 'I'; | 17 String get isolateName => 'I'; |
| 17 String get isolatePropertiesName => 'p'; | 18 String get isolatePropertiesName => 'p'; |
| 18 bool get shouldMinify => true; | 19 bool get shouldMinify => true; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 38 } | 39 } |
| 39 } | 40 } |
| 40 return new TokenScope(illegalNames); | 41 return new TokenScope(illegalNames); |
| 41 } else { | 42 } else { |
| 42 return new TokenScope(jsReserved); | 43 return new TokenScope(jsReserved); |
| 43 } | 44 } |
| 44 } | 45 } |
| 45 | 46 |
| 46 @override | 47 @override |
| 47 jsAst.Name getFreshName(NamingScope scope, String proposedName, | 48 jsAst.Name getFreshName(NamingScope scope, String proposedName, |
| 48 {bool sanitizeForNatives: false, | 49 {bool sanitizeForNatives: false, bool sanitizeForAnnotations: false}) { |
| 49 bool sanitizeForAnnotations: false}) { | |
| 50 // Grab the scope for this token | 50 // Grab the scope for this token |
| 51 TokenScope tokenScope = _tokenScopes.putIfAbsent(scope, | 51 TokenScope tokenScope = |
| 52 () => newScopeFor(scope)); | 52 _tokenScopes.putIfAbsent(scope, () => newScopeFor(scope)); |
| 53 | 53 |
| 54 // Get the name the normal namer would use as a key. | 54 // Get the name the normal namer would use as a key. |
| 55 String proposed = _generateFreshStringForName(proposedName, | 55 String proposed = _generateFreshStringForName(proposedName, scope, |
| 56 scope, | 56 sanitizeForNatives: sanitizeForNatives, |
| 57 sanitizeForNatives: | 57 sanitizeForAnnotations: sanitizeForAnnotations); |
| 58 sanitizeForNatives, | |
| 59 sanitizeForAnnotations: | |
| 60 sanitizeForAnnotations); | |
| 61 | 58 |
| 62 TokenName name = new TokenName(tokenScope, proposed); | 59 TokenName name = new TokenName(tokenScope, proposed); |
| 63 tokens.add(name); | 60 tokens.add(name); |
| 64 return name; | 61 return name; |
| 65 } | 62 } |
| 66 | 63 |
| 67 @override | 64 @override |
| 68 jsAst.Name instanceFieldPropertyName(Element element) { | 65 jsAst.Name instanceFieldPropertyName(Element element) { |
| 69 jsAst.Name proposed = _minifiedInstanceFieldPropertyName(element); | 66 jsAst.Name proposed = _minifiedInstanceFieldPropertyName(element); |
| 70 if (proposed != null) { | 67 if (proposed != null) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 _nextName.add($_); | 126 _nextName.add($_); |
| 130 } | 127 } |
| 131 } | 128 } |
| 132 | 129 |
| 133 String getNextName() { | 130 String getNextName() { |
| 134 String proposal; | 131 String proposal; |
| 135 do { | 132 do { |
| 136 proposal = new String.fromCharCodes(_nextName); | 133 proposal = new String.fromCharCodes(_nextName); |
| 137 _incrementName(); | 134 _incrementName(); |
| 138 } while (MinifyNamer._hasBannedPrefix(proposal) || | 135 } while (MinifyNamer._hasBannedPrefix(proposal) || |
| 139 illegalNames.contains(proposal)); | 136 illegalNames.contains(proposal)); |
| 140 | 137 |
| 141 return proposal; | 138 return proposal; |
| 142 } | 139 } |
| 143 } | 140 } |
| 144 | |
| OLD | NEW |