| OLD | NEW |
| 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 13 matching lines...) Expand all Loading... |
| 24 import 'package:analyzer/src/generated/element.dart'; | 24 import 'package:analyzer/src/generated/element.dart'; |
| 25 import 'package:analyzer/src/generated/engine.dart' | 25 import 'package:analyzer/src/generated/engine.dart' |
| 26 show ParseDartTask, AnalysisContext; | 26 show ParseDartTask, AnalysisContext; |
| 27 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; | 27 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; |
| 28 import 'package:analyzer/src/generated/source.dart' show Source; | 28 import 'package:analyzer/src/generated/source.dart' show Source; |
| 29 import 'package:analyzer/analyzer.dart' show parseDirectives; | 29 import 'package:analyzer/analyzer.dart' show parseDirectives; |
| 30 import 'package:crypto/crypto.dart' show CryptoUtils, MD5; | 30 import 'package:crypto/crypto.dart' show CryptoUtils, MD5; |
| 31 import 'package:source_span/source_span.dart'; | 31 import 'package:source_span/source_span.dart'; |
| 32 import 'package:yaml/yaml.dart'; | 32 import 'package:yaml/yaml.dart'; |
| 33 | 33 |
| 34 import 'codegen/js_names.dart' show invalidJSVariableName; | 34 import 'codegen/js_names.dart' show invalidVariableName; |
| 35 | 35 |
| 36 bool isDartPrivateLibrary(LibraryElement library) { | 36 bool isDartPrivateLibrary(LibraryElement library) { |
| 37 var uri = library.source.uri; | 37 var uri = library.source.uri; |
| 38 if (uri.scheme != "dart") return false; | 38 if (uri.scheme != "dart") return false; |
| 39 return Identifier.isPrivateName(uri.path); | 39 return Identifier.isPrivateName(uri.path); |
| 40 } | 40 } |
| 41 | 41 |
| 42 /// Choose a canonical name from the library element. This is safe to use as a | 42 /// Choose a canonical name from the library element. This is safe to use as a |
| 43 /// namespace in JS and Dart code generation. This never uses the library's | 43 /// namespace in JS and Dart code generation. This never uses the library's |
| 44 /// name (the identifier in the `library` declaration) as it doesn't have any | 44 /// name (the identifier in the `library` declaration) as it doesn't have any |
| (...skipping 17 matching lines...) Expand all Loading... |
| 62 buffer = new StringBuffer(name.substring(0, i)); | 62 buffer = new StringBuffer(name.substring(0, i)); |
| 63 } | 63 } |
| 64 if (buffer != null) { | 64 if (buffer != null) { |
| 65 buffer.write(needsEscape ? '\$${ch.codeUnits.join("")}' : ch); | 65 buffer.write(needsEscape ? '\$${ch.codeUnits.join("")}' : ch); |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 | 68 |
| 69 var result = buffer != null ? '$buffer' : name; | 69 var result = buffer != null ? '$buffer' : name; |
| 70 // Ensure the identifier first character is not numeric and that the whole | 70 // Ensure the identifier first character is not numeric and that the whole |
| 71 // identifier is not a keyword. | 71 // identifier is not a keyword. |
| 72 if (result.startsWith(new RegExp('[0-9]')) || invalidJSVariableName(result)) { | 72 if (result.startsWith(new RegExp('[0-9]')) || invalidVariableName(result)) { |
| 73 return '\$$result'; | 73 return '\$$result'; |
| 74 } | 74 } |
| 75 return result; | 75 return result; |
| 76 } | 76 } |
| 77 | 77 |
| 78 // Invalid characters for identifiers, which would need to be escaped. | 78 // Invalid characters for identifiers, which would need to be escaped. |
| 79 final _invalidCharInIdentifier = new RegExp(r'[^A-Za-z_$0-9]'); | 79 final _invalidCharInIdentifier = new RegExp(r'[^A-Za-z_$0-9]'); |
| 80 | 80 |
| 81 /// Returns all libraries transitively imported or exported from [start]. | 81 /// Returns all libraries transitively imported or exported from [start]. |
| 82 Iterable<LibraryElement> reachableLibraries(LibraryElement start) { | 82 Iterable<LibraryElement> reachableLibraries(LibraryElement start) { |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 }); | 417 }); |
| 418 // Add getters. | 418 // Add getters. |
| 419 element.accessors | 419 element.accessors |
| 420 .where((member) => !member.isStatic && member.isGetter) | 420 .where((member) => !member.isStatic && member.isGetter) |
| 421 .forEach((member) { | 421 .forEach((member) { |
| 422 map[member.name] = member.type.returnType; | 422 map[member.name] = member.type.returnType; |
| 423 }); | 423 }); |
| 424 } | 424 } |
| 425 return map; | 425 return map; |
| 426 } | 426 } |
| OLD | NEW |