Chromium Code Reviews| 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]. |