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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_backend/minify_namer.dart

Issue 12049036: Cleanup the namer, and add a test with fields that used to clash with internal names used by the co… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 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) 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 {
11 MinifyNamer(Compiler compiler) : super(compiler) { 11 MinifyNamer(Compiler compiler) : super(compiler) {
12 reserveBackendNames(); 12 reserveBackendNames();
13 } 13 }
14 14
15 String get isolateName => 'I'; 15 String get isolateName => 'I';
16 String get isolatePropertiesName => 'p'; 16 String get isolatePropertiesName => 'p';
17 bool get shouldMinify => true; 17 bool get shouldMinify => true;
18 18
19 const ALPHABET_CHARACTERS = 52; // a-zA-Z. 19 const ALPHABET_CHARACTERS = 52; // a-zA-Z.
20 const ALPHANUMERIC_CHARACTERS = 62; // a-zA-Z0-9. 20 const ALPHANUMERIC_CHARACTERS = 62; // a-zA-Z0-9.
21 21
22 // You can pass an invalid identifier to this and unlike its non-minifying 22 // You can pass an invalid identifier to this and unlike its non-minifying
23 // counterpart it will never return the proposedName as the new fresh name. 23 // counterpart it will never return the proposedName as the new fresh name.
24 String getFreshName(String proposedName, Set<String> usedNames) { 24 String getFreshName(String proposedName,
25 Set<String> usedNames,
26 {bool ensureSafe: true}) {
25 var freshName = _getUnusedName(proposedName, usedNames); 27 var freshName = _getUnusedName(proposedName, usedNames);
26 usedNames.add(freshName); 28 usedNames.add(freshName);
27 return freshName; 29 return freshName;
28 } 30 }
29 31
30 SourceString getClosureVariableName(SourceString name, int id) { 32 SourceString getClosureVariableName(SourceString name, int id) {
31 if (id < ALPHABET_CHARACTERS) { 33 if (id < ALPHABET_CHARACTERS) {
32 return new SourceString(new String.fromCharCodes([_letterNumber(id)])); 34 return new SourceString(new String.fromCharCodes([_letterNumber(id)]));
33 } 35 }
34 return new SourceString("${getMappedInstanceName('closure')}_$id"); 36 return new SourceString("${getMappedInstanceName('closure')}_$id");
35 } 37 }
36 38
37 void reserveBackendNames() { 39 void reserveBackendNames() {
38 for (var name in JsNames.reservedNativeProperties) { 40 // TODO(7554): We need a complete list from the DOM.
41 const reservedNativeProperties = const <String>["x", "y", "z"];
42 for (var name in reservedNativeProperties) {
39 if (name.length < 3) { 43 if (name.length < 3) {
40 instanceNameMap[name] = name; 44 instanceNameMap[name] = name;
41 } 45 }
42 usedInstanceNames.add(name); 46 usedInstanceNames.add(name);
43 } 47 }
44 } 48 }
45 49
46 // This gets a minified name based on a hash of the proposed name. This 50 // This gets a minified name based on a hash of the proposed name. This
47 // is slightly less efficient than just getting the next name in a series, 51 // is slightly less efficient than just getting the next name in a series,
48 // but it means that small changes in the input program will give smallish 52 // but it means that small changes in the input program will give smallish
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 } 121 }
118 122
119 int _alphaNumericNumber(int x) { 123 int _alphaNumericNumber(int x) {
120 if (x >= ALPHANUMERIC_CHARACTERS) x %= ALPHANUMERIC_CHARACTERS; 124 if (x >= ALPHANUMERIC_CHARACTERS) x %= ALPHANUMERIC_CHARACTERS;
121 if (x < 26) return $a + x; 125 if (x < 26) return $a + x;
122 if (x < 52) return $A + x - 26; 126 if (x < 52) return $A + x - 26;
123 return $0 + x - 52; 127 return $0 + x - 52;
124 } 128 }
125 129
126 } 130 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698