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

Unified Diff: lib/src/compiler/code_generator.dart

Issue 1917863005: Qualify library names in packages (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Use restoreAbsolute Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: lib/src/compiler/code_generator.dart
diff --git a/lib/src/compiler/code_generator.dart b/lib/src/compiler/code_generator.dart
index 2c19b39ef6f2c7ac0a9af6e10978145d953ec503..f3ae615334cd509fc4ff537b6b0086fcb8a7a755 100644
--- a/lib/src/compiler/code_generator.dart
+++ b/lib/src/compiler/code_generator.dart
@@ -10,6 +10,10 @@ import 'package:analyzer/dart/ast/token.dart' show Token, TokenType;
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/src/dart/ast/token.dart' show StringToken;
+
+// TODO(vsm): Delete
+import 'package:analyzer/src/context/source.dart' show SourceFactoryImpl;
+
//TODO(leafp): Remove deprecated dependency
//ignore: DEPRECATED_MEMBER_USE
import 'package:analyzer/src/generated/element.dart'
@@ -190,7 +194,7 @@ class CodeGenerator extends GeneralizingAstVisitor
var libraryTemp = _isDartRuntime(library)
? _runtimeLibVar
- : new JS.TemporaryId(jsLibraryName(library));
+ : new JS.TemporaryId(jsLibraryName(context, library));
_libraries[library] = libraryTemp;
items.add(new JS.ExportDeclaration(
js.call('const # = Object.create(null)', [libraryTemp])));
@@ -3684,7 +3688,7 @@ class CodeGenerator extends GeneralizingAstVisitor
// It's either one of the libraries in this module, or it's an import.
return _libraries[library] ??
_imports.putIfAbsent(
- library, () => new JS.TemporaryId(jsLibraryName(library)));
+ library, () => new JS.TemporaryId(jsLibraryName(context, library)));
}
JS.Node annotate(JS.Node node, AstNode original, [Element element]) {
@@ -3760,7 +3764,21 @@ class CodeGenerator extends GeneralizingAstVisitor
/// Choose a canonical name from the library element.
/// This never uses the library's name (the identifier in the `library`
/// declaration) as it doesn't have any meaningful rules enforced.
-String jsLibraryName(LibraryElement library) {
+String jsLibraryName(AnalysisContext context, LibraryElement library) {
+ var sourceFactory = context.sourceFactory as SourceFactoryImpl;
vsm 2016/04/27 18:24:35 sourceFactory has it's own restoreAbsolute that wa
Jennifer Messerly 2016/04/27 18:30:05 Oh crazy! Is that hard coded? You could change the
Paul Berry 2016/04/27 19:19:57 Are you sure about this? Looking at the definitio
vsm 2016/04/27 20:56:08 yep, just need to set in the right order! will fi
+ for (var resolver in sourceFactory.resolvers) {
+ var uri = resolver.restoreAbsolute(library.source);
Paul Berry 2016/04/27 19:19:57 Why not just: var uri = library.source.uri; This
Jennifer Messerly 2016/04/27 19:24:21 ah, thanks, I wondered that too! Figured maybe I w
vsm 2016/04/27 20:56:08 that should actually work for the bazel use case.
Paul Berry 2016/04/27 21:13:49 Ah, fair point. Ok, I see why this is a use case
Jennifer Messerly 2016/04/27 21:52:51 yeah +1 to all that @Vijay -- the DDC spot to fix
+ if (uri?.scheme == 'package') {
+ // Strip the package name.
+ // TODO(vsm): This is not unique if an escaped '/'appears in a filename.
+ // E.g., "foo/bar.dart" and "foo$47bar.dart" would collide.
+ var packageRelativePath = uri.pathSegments.skip(1).join('/');
+ return pathToJSIdentifier(packageRelativePath);
+ }
+ }
+ // TODO(vsm): This is not unique, but we're not in
+ // a package. We need a mechanism for creating a unique library
+ // name.
return pathToJSIdentifier(library.source.uri.pathSegments.last);
}

Powered by Google App Engine
This is Rietveld 408576698