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 | 2 |
3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
5 | 5 |
6 import 'dart:collection' show HashMap, HashSet; | 6 import 'dart:collection' show HashMap, HashSet; |
7 import 'dart:math' show min, max; | 7 import 'dart:math' show min, max; |
8 | 8 |
9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; | 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; |
10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
(...skipping 13 matching lines...) Expand all Loading... | |
24 import 'package:analyzer/src/summary/idl.dart' show UnlinkedUnit; | 24 import 'package:analyzer/src/summary/idl.dart' show UnlinkedUnit; |
25 import 'package:analyzer/src/summary/link.dart' as summary_link; | 25 import 'package:analyzer/src/summary/link.dart' as summary_link; |
26 import 'package:analyzer/src/summary/package_bundle_reader.dart'; | 26 import 'package:analyzer/src/summary/package_bundle_reader.dart'; |
27 import 'package:analyzer/src/summary/summarize_ast.dart' | 27 import 'package:analyzer/src/summary/summarize_ast.dart' |
28 show serializeAstUnlinked; | 28 show serializeAstUnlinked; |
29 import 'package:analyzer/src/summary/summarize_elements.dart' | 29 import 'package:analyzer/src/summary/summarize_elements.dart' |
30 show PackageBundleAssembler; | 30 show PackageBundleAssembler; |
31 import 'package:analyzer/src/summary/summary_sdk.dart'; | 31 import 'package:analyzer/src/summary/summary_sdk.dart'; |
32 import 'package:analyzer/src/task/strong/ast_properties.dart' | 32 import 'package:analyzer/src/task/strong/ast_properties.dart' |
33 show isDynamicInvoke, setIsDynamicInvoke, getImplicitAssignmentCast; | 33 show isDynamicInvoke, setIsDynamicInvoke, getImplicitAssignmentCast; |
34 import 'package:path/path.dart' show separator; | 34 import 'package:path/path.dart' show separator, isWithin, fromUri; |
35 | 35 |
36 import '../closure/closure_annotator.dart' show ClosureAnnotator; | 36 import '../closure/closure_annotator.dart' show ClosureAnnotator; |
37 import '../js_ast/js_ast.dart' as JS; | 37 import '../js_ast/js_ast.dart' as JS; |
38 import '../js_ast/js_ast.dart' show js; | 38 import '../js_ast/js_ast.dart' show js; |
39 import 'ast_builder.dart' show AstBuilder; | 39 import 'ast_builder.dart' show AstBuilder; |
40 import 'compiler.dart' show BuildUnit, CompilerOptions, JSModuleFile; | 40 import 'compiler.dart' show BuildUnit, CompilerOptions, JSModuleFile; |
41 import 'element_helpers.dart'; | 41 import 'element_helpers.dart'; |
42 import 'element_loader.dart' show ElementLoader; | 42 import 'element_loader.dart' show ElementLoader; |
43 import 'extension_types.dart' show ExtensionTypeSet; | 43 import 'extension_types.dart' show ExtensionTypeSet; |
44 import 'js_field_storage.dart' show checkForPropertyOverride, getSuperclasses; | 44 import 'js_field_storage.dart' show checkForPropertyOverride, getSuperclasses; |
(...skipping 5400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5445 /// Choose a canonical name from the [library] element. | 5445 /// Choose a canonical name from the [library] element. |
5446 /// | 5446 /// |
5447 /// This never uses the library's name (the identifier in the `library` | 5447 /// This never uses the library's name (the identifier in the `library` |
5448 /// declaration) as it doesn't have any meaningful rules enforced. | 5448 /// declaration) as it doesn't have any meaningful rules enforced. |
5449 String jsLibraryName(String libraryRoot, LibraryElement library) { | 5449 String jsLibraryName(String libraryRoot, LibraryElement library) { |
5450 var uri = library.source.uri; | 5450 var uri = library.source.uri; |
5451 if (uri.scheme == 'dart') { | 5451 if (uri.scheme == 'dart') { |
5452 return uri.path; | 5452 return uri.path; |
5453 } | 5453 } |
5454 // TODO(vsm): This is not necessarily unique if '__' appears in a file name. | 5454 // TODO(vsm): This is not necessarily unique if '__' appears in a file name. |
5455 var separator = '__'; | 5455 var customSeparator = '__'; |
5456 String qualifiedPath; | 5456 String qualifiedPath; |
5457 if (uri.scheme == 'package') { | 5457 if (uri.scheme == 'package') { |
5458 // Strip the package name. | 5458 // Strip the package name. |
5459 // TODO(vsm): This is not unique if an escaped '/'appears in a filename. | 5459 // TODO(vsm): This is not unique if an escaped '/'appears in a filename. |
5460 // E.g., "foo/bar.dart" and "foo$47bar.dart" would collide. | 5460 // E.g., "foo/bar.dart" and "foo$47bar.dart" would collide. |
5461 qualifiedPath = uri.pathSegments.skip(1).join(separator); | 5461 qualifiedPath = uri.pathSegments.skip(1).join(customSeparator); |
5462 } else if (uri.toFilePath().startsWith(libraryRoot)) { | 5462 } else if (isWithin(libraryRoot, uri.toFilePath())) { |
5463 qualifiedPath = | 5463 qualifiedPath = |
5464 uri.path.substring(libraryRoot.length).replaceAll('/', separator); | 5464 fromUri(uri).substring(libraryRoot.length).replaceAll(separator, customS eparator); |
vsm
2016/10/12 20:32:05
Can you run ./tool/format.sh ? It should fix the
| |
5465 } else { | 5465 } else { |
5466 // We don't have a unique name. | 5466 // We don't have a unique name. |
5467 throw 'Invalid library root. $libraryRoot does not contain ${uri | 5467 throw 'Invalid library root. $libraryRoot does not contain ${uri |
5468 .toFilePath()}'; | 5468 .toFilePath()}'; |
5469 } | 5469 } |
5470 return pathToJSIdentifier(qualifiedPath); | 5470 return pathToJSIdentifier(qualifiedPath); |
5471 } | 5471 } |
5472 | 5472 |
5473 /// Shorthand for identifier-like property names. | 5473 /// Shorthand for identifier-like property names. |
5474 /// For now, we emit them as strings and the printer restores them to | 5474 /// For now, we emit them as strings and the printer restores them to |
(...skipping 21 matching lines...) Expand all Loading... | |
5496 } | 5496 } |
5497 | 5497 |
5498 bool isLibraryPrefix(Expression node) => | 5498 bool isLibraryPrefix(Expression node) => |
5499 node is SimpleIdentifier && node.staticElement is PrefixElement; | 5499 node is SimpleIdentifier && node.staticElement is PrefixElement; |
5500 | 5500 |
5501 LibraryElement _getLibrary(AnalysisContext c, String uri) => | 5501 LibraryElement _getLibrary(AnalysisContext c, String uri) => |
5502 c.computeLibraryElement(c.sourceFactory.forUri(uri)); | 5502 c.computeLibraryElement(c.sourceFactory.forUri(uri)); |
5503 | 5503 |
5504 bool _isDartRuntime(LibraryElement l) => | 5504 bool _isDartRuntime(LibraryElement l) => |
5505 l.isInSdk && l.source.uri.toString() == 'dart:_runtime'; | 5505 l.isInSdk && l.source.uri.toString() == 'dart:_runtime'; |
OLD | NEW |