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

Side by Side Diff: pkg/compiler/lib/src/js_backend/namer.dart

Issue 1022023002: Revert "Do not use the namer for naming closure elements." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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
« no previous file with comments | « pkg/compiler/lib/src/js_backend/minify_namer.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 * Names are generated through three stages: 10 * Names are generated through three stages:
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 * (The [getterPrefix] and [setterPrefix] are different in [MinifyNamer]). 94 * (The [getterPrefix] and [setterPrefix] are different in [MinifyNamer]).
95 * 95 *
96 * 3. The `is` and operator uses the following names: 96 * 3. The `is` and operator uses the following names:
97 * 97 *
98 * $is<NAME> 98 * $is<NAME>
99 * $as<NAME> 99 * $as<NAME>
100 * 100 *
101 * For local variables, the [Namer] only provides *proposed names*. These names 101 * For local variables, the [Namer] only provides *proposed names*. These names
102 * must be disambiguated elsewhere. 102 * must be disambiguated elsewhere.
103 */ 103 */
104 class Namer { 104 class Namer implements ClosureNamer {
105 105
106 static const List<String> javaScriptKeywords = const <String>[ 106 static const List<String> javaScriptKeywords = const <String>[
107 // These are current keywords. 107 // These are current keywords.
108 "break", "delete", "function", "return", "typeof", "case", "do", "if", 108 "break", "delete", "function", "return", "typeof", "case", "do", "if",
109 "switch", "var", "catch", "else", "in", "this", "void", "continue", 109 "switch", "var", "catch", "else", "in", "this", "void", "continue",
110 "false", "instanceof", "throw", "while", "debugger", "finally", "new", 110 "false", "instanceof", "throw", "while", "debugger", "finally", "new",
111 "true", "with", "default", "for", "null", "try", 111 "true", "with", "default", "for", "null", "try",
112 112
113 // These are future keywords. 113 // These are future keywords.
114 "abstract", "double", "goto", "native", "static", "boolean", "enum", 114 "abstract", "double", "goto", "native", "static", "boolean", "enum",
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 /// If [name] is not an annotated name, the result will not be an annotated 965 /// If [name] is not an annotated name, the result will not be an annotated
966 /// name either. 966 /// name either.
967 String _sanitizeForNatives(String name) { 967 String _sanitizeForNatives(String name) {
968 if (!name.contains(r'$')) { 968 if (!name.contains(r'$')) {
969 // Prepend $$. The result must not coincide with an annotated name. 969 // Prepend $$. The result must not coincide with an annotated name.
970 name = '\$\$$name'; 970 name = '\$\$$name';
971 } 971 }
972 return name; 972 return name;
973 } 973 }
974 974
975 /// Generate a unique name for the [id]th closure variable, with proposed name
976 /// [name].
977 ///
978 /// The result is used as the name of [BoxFieldElement]s and
979 /// [ClosureFieldElement]s, and must therefore be unique to avoid breaking an
980 /// invariant in the element model (classes cannot declare multiple fields
981 /// with the same name).
982 ///
983 /// Since the result is used as an element name, it will later show up as a
984 /// *proposed name* when the element is passed to [instanceFieldPropertyName].
985 String getClosureVariableName(String name, int id) {
986 return "${name}_$id";
987 }
988
975 /** 989 /**
976 * Returns a proposed name for the given top-level or static element. 990 * Returns a proposed name for the given top-level or static element.
977 * The returned id is guaranteed to be a valid JS-id. 991 * The returned id is guaranteed to be a valid JS-id.
978 */ 992 */
979 String _proposeNameForGlobal(Element element) { 993 String _proposeNameForGlobal(Element element) {
980 assert(!element.isInstanceMember); 994 assert(!element.isInstanceMember);
981 String name; 995 String name;
982 if (element.isGenerativeConstructor) { 996 if (element.isGenerativeConstructor) {
983 name = "${element.enclosingClass.name}\$" 997 name = "${element.enclosingClass.name}\$"
984 "${element.name}"; 998 "${element.name}";
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after
1755 if (!first) { 1769 if (!first) {
1756 sb.write('_'); 1770 sb.write('_');
1757 } 1771 }
1758 sb.write('_'); 1772 sb.write('_');
1759 visit(parameter); 1773 visit(parameter);
1760 first = true; 1774 first = true;
1761 } 1775 }
1762 } 1776 }
1763 } 1777 }
1764 } 1778 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/minify_namer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698