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

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: address review comments 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 628d7a1e95a80bb5c7a80475896653929a4c6611..1c221629cb166a0fb91048f69d92521a4cf08e59 100644
--- a/lib/src/codegen/js_codegen.dart
+++ b/lib/src/codegen/js_codegen.dart
@@ -1289,7 +1289,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
}
@override
- visitRethrowExpression(RethrowExpression node){
+ visitRethrowExpression(RethrowExpression node) {
if (node.parent is ExpressionStatement) {
return js.statement('throw #;', _catchParameter);
} else {
@@ -1747,7 +1747,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) {
@@ -1789,11 +1789,23 @@ 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 == 'file') {
+ filepath = path.relative(filepath, from: path.dirname(root.path));
+ } else {
+ assert(uri.scheme == 'package');
+ // filepath is good here, we want the output to start with a directory
+ // matching the package name.
+ }
+ 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