| Index: pkg/dev_compiler/lib/src/compiler/code_generator.dart
|
| diff --git a/pkg/dev_compiler/lib/src/compiler/code_generator.dart b/pkg/dev_compiler/lib/src/compiler/code_generator.dart
|
| index 24aac39abbdb4c5e7b1c3bd363f5bee5d8bb218b..6b8a2ca65ae86d6a04ab558a71df4ba1b8911ef8 100644
|
| --- a/pkg/dev_compiler/lib/src/compiler/code_generator.dart
|
| +++ b/pkg/dev_compiler/lib/src/compiler/code_generator.dart
|
| @@ -191,7 +191,7 @@ class CodeGenerator extends GeneralizingAstVisitor
|
| _libraryRoot += separator;
|
| }
|
|
|
| - var module = _emitModule(compilationUnits);
|
| + var module = _emitModule(compilationUnits, unit.name);
|
| var dartApiSummary = _summarizeModule(compilationUnits);
|
|
|
| return new JSModuleFile(unit.name, errors, options, module, dartApiSummary);
|
| @@ -237,7 +237,7 @@ class CodeGenerator extends GeneralizingAstVisitor
|
| return bundle.toBuffer();
|
| }
|
|
|
| - JS.Program _emitModule(List<CompilationUnit> compilationUnits) {
|
| + JS.Program _emitModule(List<CompilationUnit> compilationUnits, String name) {
|
| if (_moduleItems.isNotEmpty) {
|
| throw new StateError('Can only call emitModule once.');
|
| }
|
| @@ -320,6 +320,11 @@ class CodeGenerator extends GeneralizingAstVisitor
|
| // hoisted definitions.
|
| items.addAll(_typeTable.discharge());
|
|
|
| + // Track the module name for each library in the module.
|
| + // This data is only required for debugging.
|
| + _moduleItems.add(js.statement('#.trackLibraries(#, #);',
|
| + [_runtimeModule, js.string(name), _librariesDebuggerObject()]));
|
| +
|
| // Add the module's code (produced by visiting compilation units, above)
|
| _copyAndFlattenBlocks(items, _moduleItems);
|
|
|
| @@ -327,6 +332,17 @@ class CodeGenerator extends GeneralizingAstVisitor
|
| return new JS.Program(items, name: _buildUnit.name);
|
| }
|
|
|
| + JS.ObjectInitializer _librariesDebuggerObject() {
|
| + var properties = <JS.Property>[];
|
| + _libraries.forEach((library, value) {
|
| + // TODO(jacobr): we could specify a short library name instead of the
|
| + // full library uri if we wanted to save space.
|
| + properties.add(new JS.Property(
|
| + js.string(jsLibraryDebuggerName(_libraryRoot, library)), value));
|
| + });
|
| + return new JS.ObjectInitializer(properties);
|
| + }
|
| +
|
| List<String> _getJSName(Element e) {
|
| if (e.library == null ||
|
| findAnnotation(e.library, isPublicJSAnnotation) == null) {
|
| @@ -457,6 +473,7 @@ class CodeGenerator extends GeneralizingAstVisitor
|
| imports.add(new JS.NameSpecifier(_runtimeModule));
|
| imports.add(new JS.NameSpecifier(_extensionSymbolsModule));
|
| }
|
| +
|
| items.add(new JS.ImportDeclaration(
|
| namedImports: imports, from: js.string(module, "'")));
|
| });
|
| @@ -5853,6 +5870,44 @@ String jsLibraryName(String libraryRoot, LibraryElement library) {
|
| return pathToJSIdentifier(qualifiedPath);
|
| }
|
|
|
| +/// Debugger friendly name for a Dart Library.
|
| +String jsLibraryDebuggerName(String libraryRoot, LibraryElement library) {
|
| + var uri = library.source.uri;
|
| + // For package: and dart: uris show the entire
|
| + if (uri.scheme == 'dart' || uri.scheme == 'package') return uri.toString();
|
| +
|
| + if (!uri.toFilePath().startsWith(libraryRoot)) {
|
| + throw 'Invalid library root. $libraryRoot does not contain ${uri
|
| + .toFilePath()}';
|
| + }
|
| + // Relative path to the library.
|
| + return uri.path.substring(libraryRoot.length);
|
| +}
|
| +
|
| +String jsDebuggingLibraryName(String libraryRoot, LibraryElement library) {
|
| + var uri = library.source.uri;
|
| + if (uri.scheme == 'dart') {
|
| + return uri.path;
|
| + }
|
| + // TODO(vsm): This is not necessarily unique if '__' appears in a file name.
|
| + var separator = '__';
|
| + String qualifiedPath;
|
| + 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.
|
| + qualifiedPath = uri.pathSegments.skip(1).join(separator);
|
| + } else if (uri.toFilePath().startsWith(libraryRoot)) {
|
| + qualifiedPath =
|
| + uri.path.substring(libraryRoot.length).replaceAll('/', separator);
|
| + } else {
|
| + // We don't have a unique name.
|
| + throw 'Invalid library root. $libraryRoot does not contain ${uri
|
| + .toFilePath()}';
|
| + }
|
| + return pathToJSIdentifier(qualifiedPath);
|
| +}
|
| +
|
| /// Shorthand for identifier-like property names.
|
| /// For now, we emit them as strings and the printer restores them to
|
| /// identifiers if it can.
|
|
|