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; |
11 import 'package:analyzer/src/generated/ast.dart' | 11 import 'package:analyzer/src/generated/ast.dart' |
12 show | 12 show |
13 ImportDirective, | 13 ImportDirective, |
14 ExportDirective, | 14 ExportDirective, |
15 PartDirective, | 15 PartDirective, |
16 CompilationUnit, | 16 CompilationUnit, |
17 Identifier, | 17 Identifier, |
18 AnnotatedNode, | 18 AnnotatedNode, |
19 AstNode, | 19 AstNode, |
20 Expression, | 20 Expression, |
21 SimpleIdentifier, | 21 SimpleIdentifier, |
22 MethodInvocation; | 22 MethodInvocation, |
23 NodeLocator, | |
Jennifer Messerly
2015/06/10 22:34:17
will revert this.
| |
24 UnifyingAstVisitor; | |
23 import 'package:analyzer/src/generated/constant.dart' show DartObjectImpl; | 25 import 'package:analyzer/src/generated/constant.dart' show DartObjectImpl; |
24 import 'package:analyzer/src/generated/element.dart'; | 26 import 'package:analyzer/src/generated/element.dart'; |
25 import 'package:analyzer/src/generated/engine.dart' | 27 import 'package:analyzer/src/generated/engine.dart' |
26 show ParseDartTask, AnalysisContext; | 28 show ParseDartTask, AnalysisContext; |
27 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; | 29 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; |
28 import 'package:analyzer/src/generated/source.dart' show Source; | 30 import 'package:analyzer/src/generated/source.dart' show Source; |
29 import 'package:analyzer/analyzer.dart' show parseDirectives; | 31 import 'package:analyzer/analyzer.dart' show parseDirectives; |
30 import 'package:crypto/crypto.dart' show CryptoUtils, MD5; | 32 import 'package:crypto/crypto.dart' show CryptoUtils, MD5; |
31 import 'package:source_span/source_span.dart'; | 33 import 'package:source_span/source_span.dart'; |
32 import 'package:yaml/yaml.dart'; | 34 import 'package:yaml/yaml.dart'; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 if (result.startsWith(new RegExp('[0-9]')) || invalidVariableName(result)) { | 74 if (result.startsWith(new RegExp('[0-9]')) || invalidVariableName(result)) { |
73 return '\$$result'; | 75 return '\$$result'; |
74 } | 76 } |
75 return result; | 77 return result; |
76 } | 78 } |
77 | 79 |
78 // Invalid characters for identifiers, which would need to be escaped. | 80 // Invalid characters for identifiers, which would need to be escaped. |
79 final _invalidCharInIdentifier = new RegExp(r'[^A-Za-z_$0-9]'); | 81 final _invalidCharInIdentifier = new RegExp(r'[^A-Za-z_$0-9]'); |
80 | 82 |
81 /// Returns all libraries transitively imported or exported from [start]. | 83 /// Returns all libraries transitively imported or exported from [start]. |
82 Iterable<LibraryElement> reachableLibraries(LibraryElement start) { | 84 List<LibraryElement> reachableLibraries(LibraryElement start) { |
83 var results = <LibraryElement>[]; | 85 var results = <LibraryElement>[]; |
84 var seen = new Set(); | 86 var seen = new Set(); |
85 void find(LibraryElement lib) { | 87 void find(LibraryElement lib) { |
86 if (seen.contains(lib)) return; | 88 if (seen.contains(lib)) return; |
87 seen.add(lib); | 89 seen.add(lib); |
88 results.add(lib); | 90 results.add(lib); |
89 lib.importedLibraries.forEach(find); | 91 lib.importedLibraries.forEach(find); |
90 lib.exportedLibraries.forEach(find); | 92 lib.exportedLibraries.forEach(find); |
91 } | 93 } |
92 find(start); | 94 find(start); |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
462 lineInfo.getLocation(++lineEnd).lineNumber == lineNum); | 464 lineInfo.getLocation(++lineEnd).lineNumber == lineNum); |
463 | 465 |
464 var text = content.substring(start, end); | 466 var text = content.substring(start, end); |
465 var lineText = content.substring(lineStart, lineEnd); | 467 var lineText = content.substring(lineStart, lineEnd); |
466 return new SourceSpanWithContext(startLoc, endLoc, text, lineText); | 468 return new SourceSpanWithContext(startLoc, endLoc, text, lineText); |
467 } | 469 } |
468 | 470 |
469 bool isInlineJS(Element e) => e is FunctionElement && | 471 bool isInlineJS(Element e) => e is FunctionElement && |
470 e.library.source.uri.toString() == 'dart:_foreign_helper' && | 472 e.library.source.uri.toString() == 'dart:_foreign_helper' && |
471 e.name == 'JS'; | 473 e.name == 'JS'; |
OLD | NEW |