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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 /// Holds a couple utility functions used at various places in the system. 5 /// Holds a couple utility functions used at various places in the system.
6 library dev_compiler.src.utils; 6 library dev_compiler.src.utils;
7 7
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:path/path.dart' as path; 10 import 'package:path/path.dart' as path;
(...skipping 19 matching lines...) Expand all
30 if (uri.scheme != "dart") return false; 30 if (uri.scheme != "dart") return false;
31 return Identifier.isPrivateName(uri.path); 31 return Identifier.isPrivateName(uri.path);
32 } 32 }
33 33
34 /// Choose a canonical name from the library element. This is safe to use as a 34 /// Choose a canonical name from the library element. This is safe to use as a
35 /// namespace in JS and Dart code generation. This never uses the library's 35 /// namespace in JS and Dart code generation. This never uses the library's
36 /// name (the identifier in the `library` declaration) as it doesn't have any 36 /// name (the identifier in the `library` declaration) as it doesn't have any
37 /// meaningful rules enforced. 37 /// meaningful rules enforced.
38 String canonicalLibraryName(LibraryElement library) { 38 String canonicalLibraryName(LibraryElement library) {
39 var uri = library.source.uri; 39 var uri = library.source.uri;
40 return path.basenameWithoutExtension(uri.pathSegments.last); 40 var name = path.basenameWithoutExtension(uri.pathSegments.last);
41 return _toIdentifier(name);
42 }
43
44 /// Sanitize [name] to make it into a valid identifier.
45 String _toIdentifier(String name) {
46 if (name.length == 0) return r'$';
47 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.
48 if (name.startsWith(new RegExp('[0-9]'))) return '\$$name';
49 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
41 } 50 }
42 51
43 /// Returns all libraries transitively imported or exported from [start]. 52 /// Returns all libraries transitively imported or exported from [start].
44 Iterable<LibraryElement> reachableLibraries(LibraryElement start) { 53 Iterable<LibraryElement> reachableLibraries(LibraryElement start) {
45 var results = <LibraryElement>[]; 54 var results = <LibraryElement>[];
46 var seen = new Set(); 55 var seen = new Set();
47 void find(LibraryElement lib) { 56 void find(LibraryElement lib) {
48 if (seen.contains(lib)) return; 57 if (seen.contains(lib)) return;
49 seen.add(lib); 58 seen.add(lib);
50 results.add(lib); 59 results.add(lib);
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 locationForOffset(unit, uri, end), '$text'); 269 locationForOffset(unit, uri, end), '$text');
261 } 270 }
262 271
263 /// Computes a hash for the given contents. 272 /// Computes a hash for the given contents.
264 String computeHash(String contents) { 273 String computeHash(String contents) {
265 if (contents == null || contents == '') return null; 274 if (contents == null || contents == '') return null;
266 return CryptoUtils.bytesToHex((new MD5()..add(contents.codeUnits)).close()); 275 return CryptoUtils.bytesToHex((new MD5()..add(contents.codeUnits)).close());
267 } 276 }
268 277
269 String resourceOutputPath(Uri resourceUri) => resourceUri.path; 278 String resourceOutputPath(Uri resourceUri) => resourceUri.path;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698