Chromium Code Reviews| 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 import 'dart:collection' show HashMap, HashSet; | 5 import 'dart:collection' show HashMap, HashSet; |
| 6 | 6 |
| 7 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; | 7 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; |
| 8 import 'package:analyzer/dart/ast/ast.dart' hide ConstantEvaluator; | 8 import 'package:analyzer/dart/ast/ast.dart' hide ConstantEvaluator; |
| 9 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType; | 9 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType; |
| 10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
| (...skipping 3743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3754 // is exactly Future/Stream/Iterable. Handle the subtype case. | 3754 // is exactly Future/Stream/Iterable. Handle the subtype case. |
| 3755 return DynamicTypeImpl.instance; | 3755 return DynamicTypeImpl.instance; |
| 3756 } | 3756 } |
| 3757 } | 3757 } |
| 3758 } | 3758 } |
| 3759 | 3759 |
| 3760 /// Choose a canonical name from the library element. | 3760 /// Choose a canonical name from the library element. |
| 3761 /// This never uses the library's name (the identifier in the `library` | 3761 /// This never uses the library's name (the identifier in the `library` |
| 3762 /// declaration) as it doesn't have any meaningful rules enforced. | 3762 /// declaration) as it doesn't have any meaningful rules enforced. |
| 3763 String jsLibraryName(LibraryElement library) { | 3763 String jsLibraryName(LibraryElement library) { |
| 3764 var uri = library.source.uri; | |
| 3765 if (uri.scheme == 'package') { | |
| 3766 // Strip the package name. | |
| 3767 // TODO(vsm): This is not unique if an escaped '/'appears in a filename. | |
| 3768 // E.g., "foo/bar.dart" and "foo$47bar.dart" would collide. | |
| 3769 var packageRelativePath = uri.pathSegments.skip(1).join('/'); | |
|
Jennifer Messerly
2016/04/26 22:59:33
Yeah in general it's not going to be unique.
Also
| |
| 3770 return pathToJSIdentifier(packageRelativePath); | |
| 3771 } | |
| 3772 // TODO(vsm): This is not unique, but we're not in | |
| 3773 // a package. We need a mechanism for creating a unique library | |
| 3774 // name. | |
| 3764 return pathToJSIdentifier(library.source.uri.pathSegments.last); | 3775 return pathToJSIdentifier(library.source.uri.pathSegments.last); |
| 3765 } | 3776 } |
| 3766 | 3777 |
| 3767 /// Shorthand for identifier-like property names. | 3778 /// Shorthand for identifier-like property names. |
| 3768 /// For now, we emit them as strings and the printer restores them to | 3779 /// For now, we emit them as strings and the printer restores them to |
| 3769 /// identifiers if it can. | 3780 /// identifiers if it can. |
| 3770 // TODO(jmesserly): avoid the round tripping through quoted form. | 3781 // TODO(jmesserly): avoid the round tripping through quoted form. |
| 3771 JS.LiteralString _propertyName(String name) => js.string(name, "'"); | 3782 JS.LiteralString _propertyName(String name) => js.string(name, "'"); |
| 3772 | 3783 |
| 3773 // TODO(jacobr): we would like to do something like the following | 3784 // TODO(jacobr): we would like to do something like the following |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 3788 } | 3799 } |
| 3789 | 3800 |
| 3790 bool isLibraryPrefix(Expression node) => | 3801 bool isLibraryPrefix(Expression node) => |
| 3791 node is SimpleIdentifier && node.staticElement is PrefixElement; | 3802 node is SimpleIdentifier && node.staticElement is PrefixElement; |
| 3792 | 3803 |
| 3793 LibraryElement _getLibrary(AnalysisContext c, String uri) => | 3804 LibraryElement _getLibrary(AnalysisContext c, String uri) => |
| 3794 c.computeLibraryElement(c.sourceFactory.forUri(uri)); | 3805 c.computeLibraryElement(c.sourceFactory.forUri(uri)); |
| 3795 | 3806 |
| 3796 bool _isDartRuntime(LibraryElement l) => | 3807 bool _isDartRuntime(LibraryElement l) => |
| 3797 l.isInSdk && l.source.uri.toString() == 'dart:_runtime'; | 3808 l.isInSdk && l.source.uri.toString() == 'dart:_runtime'; |
| OLD | NEW |