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

Unified Diff: lib/src/codegen/js_codegen.dart

Issue 968273002: Fixing layout in js output (use full paths rather than just the library name) (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « lib/src/codegen/html_codegen.dart ('k') | test/codegen/expect/BenchmarkBase.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/codegen/js_codegen.dart
diff --git a/lib/src/codegen/js_codegen.dart b/lib/src/codegen/js_codegen.dart
index 1f69fefc77ace646444ca3f6ddc6c8f4f11fbdbb..839c6fe8335417dc3f6718f1eebd44a65ee62c7f 100644
--- a/lib/src/codegen/js_codegen.dart
+++ b/lib/src/codegen/js_codegen.dart
@@ -1716,7 +1716,7 @@ class JSGenerator extends CodeGenerator {
JS.Block jsTree =
new JSCodegenVisitor(info, rules).generateLibrary(units, reporter);
- var outputPath = path.join(outDir, jsOutputPath(info));
+ var outputPath = path.join(outDir, jsOutputPath(info, root));
new Directory(path.dirname(outputPath)).createSync(recursive: true);
if (options.emitSourceMaps) {
@@ -1758,11 +1758,21 @@ String debugJsNodeToString(JS.Node node) {
/// declaration) as it doesn't have any meaningful rules enforced.
String jsLibraryName(LibraryElement library) => canonicalLibraryName(library);
-/// Path to file that will be generated for [info].
-// TODO(jmesserly): library directory should be relative to its package
-// root. For example, "package:dev_compiler/src/codegen/js_codegen.dart" would be:
-// "ddc/src/codegen/js_codegen.js" under the output directory.
-String jsOutputPath(LibraryInfo info) => '${info.name}/${info.name}.js';
+/// Path to file that will be generated for [info]. In case it's url is a
+/// `file:` url, we use [root] to determine the relative path from the entry
+/// point file.
+String jsOutputPath(LibraryInfo info, Uri root) {
+ var uri = info.library.source.uri;
+ var filepath = '${path.withoutExtension(uri.path)}.js';
+ if (uri.scheme == 'dart') {
+ filepath = 'dart/$filepath';
+ } else if (uri.scheme == 'package') {
+ filepath = 'packages/$filepath';
Jennifer Messerly 2015/03/02 18:40:51 hmmm. I wonder about this. Does it make sense in a
Siggi Cherem (dart-lang) 2015/03/02 18:57:29 Good point - this also brings a related question a
Siggi Cherem (dart-lang) 2015/03/03 02:09:03 Done. I updated the CL to match Option A.
+ } else if (uri.scheme == 'file') {
+ filepath = path.relative(filepath, from: path.dirname(root.path));
+ }
+ return filepath;
+}
class SourceMapPrintingContext extends JS.JavaScriptPrintingContext {
final srcmaps.Printer printer;
« no previous file with comments | « lib/src/codegen/html_codegen.dart ('k') | test/codegen/expect/BenchmarkBase.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698