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

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

Issue 1335983004: Add ImportElement and ExportElement (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 5 years, 3 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
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 1126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 ClassElement enclosingClass = element.enclosingClass; 1137 ClassElement enclosingClass = element.enclosingClass;
1138 name = "${enclosingClass.name}_" 1138 name = "${enclosingClass.name}_"
1139 "${element.name}"; 1139 "${element.name}";
1140 } else { 1140 } else {
1141 name = element.name.replaceAll('+', '_'); 1141 name = element.name.replaceAll('+', '_');
1142 } 1142 }
1143 } else if (element.isLibrary) { 1143 } else if (element.isLibrary) {
1144 LibraryElement library = element; 1144 LibraryElement library = element;
1145 name = libraryLongNames[library]; 1145 name = libraryLongNames[library];
1146 if (name != null) return name; 1146 if (name != null) return name;
1147 name = library.getLibraryOrScriptName(); 1147 name = library.libraryOrScriptName;
1148 if (name.contains('.')) { 1148 if (name.contains('.')) {
1149 // For libraries that have a library tag, we use the last part 1149 // For libraries that have a library tag, we use the last part
1150 // of the fully qualified name as their base name. For all other 1150 // of the fully qualified name as their base name. For all other
1151 // libraries, we use the first part of their filename. 1151 // libraries, we use the first part of their filename.
1152 name = library.hasLibraryName() 1152 name = library.hasLibraryName
1153 ? name.substring(name.lastIndexOf('.') + 1) 1153 ? name.substring(name.lastIndexOf('.') + 1)
1154 : name.substring(0, name.indexOf('.')); 1154 : name.substring(0, name.indexOf('.'));
1155 } 1155 }
1156 // The filename based name can contain all kinds of nasty characters. Make 1156 // The filename based name can contain all kinds of nasty characters. Make
1157 // sure it is an identifier. 1157 // sure it is an identifier.
1158 if (!IDENTIFIER.hasMatch(name)) { 1158 if (!IDENTIFIER.hasMatch(name)) {
1159 name = name.replaceAllMapped(NON_IDENTIFIER_CHAR, 1159 name = name.replaceAllMapped(NON_IDENTIFIER_CHAR,
1160 (match) => match[0].codeUnitAt(0).toRadixString(16)); 1160 (match) => match[0].codeUnitAt(0).toRadixString(16));
1161 if (!IDENTIFIER.hasMatch(name)) { // e.g. starts with digit. 1161 if (!IDENTIFIER.hasMatch(name)) { // e.g. starts with digit.
1162 name = 'lib_$name'; 1162 name = 'lib_$name';
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1339 String globalObjectFor(Element element) { 1339 String globalObjectFor(Element element) {
1340 if (_isPropertyOfStaticStateHolder(element)) return staticStateHolder; 1340 if (_isPropertyOfStaticStateHolder(element)) return staticStateHolder;
1341 LibraryElement library = element.library; 1341 LibraryElement library = element.library;
1342 if (library == backend.interceptorsLibrary) return 'J'; 1342 if (library == backend.interceptorsLibrary) return 'J';
1343 if (library.isInternalLibrary) return 'H'; 1343 if (library.isInternalLibrary) return 'H';
1344 if (library.isPlatformLibrary) { 1344 if (library.isPlatformLibrary) {
1345 if ('${library.canonicalUri}' == 'dart:html') return 'W'; 1345 if ('${library.canonicalUri}' == 'dart:html') return 'W';
1346 return 'P'; 1346 return 'P';
1347 } 1347 }
1348 return userGlobalObjects[ 1348 return userGlobalObjects[
1349 library.getLibraryOrScriptName().hashCode % userGlobalObjects.length]; 1349 library.libraryOrScriptName.hashCode % userGlobalObjects.length];
1350 } 1350 }
1351 1351
1352 jsAst.Name deriveLazyInitializerName(jsAst.Name name) { 1352 jsAst.Name deriveLazyInitializerName(jsAst.Name name) {
1353 // These are not real dart getters, so do not use GetterName; 1353 // These are not real dart getters, so do not use GetterName;
1354 return new CompoundName([_literalLazyGetterPrefix, name]); 1354 return new CompoundName([_literalLazyGetterPrefix, name]);
1355 } 1355 }
1356 1356
1357 jsAst.Name lazyInitializerName(Element element) { 1357 jsAst.Name lazyInitializerName(Element element) {
1358 assert(Elements.isStaticOrTopLevelField(element)); 1358 assert(Elements.isStaticOrTopLevelField(element));
1359 jsAst.Name name = _disambiguateGlobal(element); 1359 jsAst.Name name = _disambiguateGlobal(element);
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after
1981 first = true; 1981 first = true;
1982 } 1982 }
1983 } 1983 }
1984 } 1984 }
1985 } 1985 }
1986 1986
1987 enum NamingScope { 1987 enum NamingScope {
1988 global, 1988 global,
1989 instance, 1989 instance,
1990 constant 1990 constant
1991 } 1991 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/backend.dart ('k') | pkg/compiler/lib/src/js_emitter/full_emitter/emitter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698