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

Unified Diff: lib/src/utils.dart

Issue 998043002: Fixes in codegen and test script (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
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 side-by-side diff with in-line comments
Download patch
Index: lib/src/utils.dart
diff --git a/lib/src/utils.dart b/lib/src/utils.dart
index a30473d5290f12642b1e68ccc6c3b0ba57396915..9056f861250c79733a70ea2ab7dde10016f756fc 100644
--- a/lib/src/utils.dart
+++ b/lib/src/utils.dart
@@ -37,7 +37,16 @@ bool isDartPrivateLibrary(LibraryElement library) {
/// meaningful rules enforced.
String canonicalLibraryName(LibraryElement library) {
var uri = library.source.uri;
- return path.basenameWithoutExtension(uri.pathSegments.last);
+ var name = path.basenameWithoutExtension(uri.pathSegments.last);
+ return _toIdentifier(name);
+}
+
+/// Sanitize [name] to make it into a valid identifier.
+String _toIdentifier(String name) {
+ if (name.length == 0) return r'$';
+ name = name.replaceAllMapped(new RegExp(r'[^A-Za-z_$0-9]'), (c) => '_');
Jennifer Messerly 2015/03/11 20:28:54 are we worried about collisions? would an escaping
Siggi Cherem (dart-lang) 2015/03/11 23:27:22 Good point - went with an escaping scheme.
+ if (name.startsWith(new RegExp('[0-9]'))) return '\$$name';
+ return name;
Jennifer Messerly 2015/03/11 20:28:54 do we need to exclude JS keywords if generating JS
Siggi Cherem (dart-lang) 2015/03/11 23:27:22 Good point - I made isJsKeyword in js_ast public f
Jennifer Messerly 2015/03/11 23:48:00 Generally I've been sticking to adds. But that was
}
/// Returns all libraries transitively imported or exported from [start].

Powered by Google App Engine
This is Rietveld 408576698