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

Side by Side 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, 9 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 library ddc.src.codegen.js_codegen; 5 library ddc.src.codegen.js_codegen;
6 6
7 import 'dart:io' show Directory, File; 7 import 'dart:io' show Directory, File;
8 8
9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator;
10 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator; 10 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator;
(...skipping 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 visitThrowExpression(ThrowExpression node) { 1282 visitThrowExpression(ThrowExpression node) {
1283 var expr = _visit(node.expression); 1283 var expr = _visit(node.expression);
1284 if (node.parent is ExpressionStatement) { 1284 if (node.parent is ExpressionStatement) {
1285 return js.statement('throw #;', expr); 1285 return js.statement('throw #;', expr);
1286 } else { 1286 } else {
1287 return js.call('dart.throw_(#)', expr); 1287 return js.call('dart.throw_(#)', expr);
1288 } 1288 }
1289 } 1289 }
1290 1290
1291 @override 1291 @override
1292 visitRethrowExpression(RethrowExpression node){ 1292 visitRethrowExpression(RethrowExpression node) {
1293 if (node.parent is ExpressionStatement) { 1293 if (node.parent is ExpressionStatement) {
1294 return js.statement('throw #;', _catchParameter); 1294 return js.statement('throw #;', _catchParameter);
1295 } else { 1295 } else {
1296 return js.call('dart.throw_(#)', _catchParameter); 1296 return js.call('dart.throw_(#)', _catchParameter);
1297 } 1297 }
1298 } 1298 }
1299 1299
1300 @override 1300 @override
1301 JS.If visitIfStatement(IfStatement node) { 1301 JS.If visitIfStatement(IfStatement node) {
1302 return new JS.If(_visit(node.condition), _visit(node.thenStatement), 1302 return new JS.If(_visit(node.condition), _visit(node.thenStatement),
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1740 final JSCodeOptions options; 1740 final JSCodeOptions options;
1741 1741
1742 JSGenerator(String outDir, Uri root, TypeRules rules, this.options) 1742 JSGenerator(String outDir, Uri root, TypeRules rules, this.options)
1743 : super(outDir, root, rules); 1743 : super(outDir, root, rules);
1744 1744
1745 void generateLibrary(Iterable<CompilationUnit> units, LibraryInfo info, 1745 void generateLibrary(Iterable<CompilationUnit> units, LibraryInfo info,
1746 CheckerReporter reporter) { 1746 CheckerReporter reporter) {
1747 JS.Block jsTree = 1747 JS.Block jsTree =
1748 new JSCodegenVisitor(info, rules).generateLibrary(units, reporter); 1748 new JSCodegenVisitor(info, rules).generateLibrary(units, reporter);
1749 1749
1750 var outputPath = path.join(outDir, jsOutputPath(info)); 1750 var outputPath = path.join(outDir, jsOutputPath(info, root));
1751 new Directory(path.dirname(outputPath)).createSync(recursive: true); 1751 new Directory(path.dirname(outputPath)).createSync(recursive: true);
1752 1752
1753 if (options.emitSourceMaps) { 1753 if (options.emitSourceMaps) {
1754 var outFilename = path.basename(outputPath); 1754 var outFilename = path.basename(outputPath);
1755 var printer = new srcmaps.Printer(outFilename); 1755 var printer = new srcmaps.Printer(outFilename);
1756 var context = 1756 var context =
1757 new SourceMapPrintingContext(printer, path.dirname(outputPath)); 1757 new SourceMapPrintingContext(printer, path.dirname(outputPath));
1758 _writeLibrary(context, jsTree); 1758 _writeLibrary(context, jsTree);
1759 printer.add('//# sourceMappingURL=$outFilename.map'); 1759 printer.add('//# sourceMappingURL=$outFilename.map');
1760 // Write output file and source map 1760 // Write output file and source map
(...skipping 21 matching lines...) Expand all
1782 new JS.Printer(opts, context).visit(node); 1782 new JS.Printer(opts, context).visit(node);
1783 // Write output file and source map 1783 // Write output file and source map
1784 return context.getText(); 1784 return context.getText();
1785 } 1785 }
1786 1786
1787 /// Choose a canonical name from the library element. 1787 /// Choose a canonical name from the library element.
1788 /// This never uses the library's name (the identifier in the `library` 1788 /// This never uses the library's name (the identifier in the `library`
1789 /// declaration) as it doesn't have any meaningful rules enforced. 1789 /// declaration) as it doesn't have any meaningful rules enforced.
1790 String jsLibraryName(LibraryElement library) => canonicalLibraryName(library); 1790 String jsLibraryName(LibraryElement library) => canonicalLibraryName(library);
1791 1791
1792 /// Path to file that will be generated for [info]. 1792 /// Path to file that will be generated for [info]. In case it's url is a
1793 // TODO(jmesserly): library directory should be relative to its package 1793 /// `file:` url, we use [root] to determine the relative path from the entry
1794 // root. For example, "package:dev_compiler/src/codegen/js_codegen.dart" would b e: 1794 /// point file.
1795 // "ddc/src/codegen/js_codegen.js" under the output directory. 1795 String jsOutputPath(LibraryInfo info, Uri root) {
1796 String jsOutputPath(LibraryInfo info) => '${info.name}/${info.name}.js'; 1796 var uri = info.library.source.uri;
1797 var filepath = '${path.withoutExtension(uri.path)}.js';
1798 if (uri.scheme == 'dart') {
1799 filepath = 'dart/$filepath';
1800 } else if (uri.scheme == 'file') {
1801 filepath = path.relative(filepath, from: path.dirname(root.path));
1802 } else {
1803 assert(uri.scheme == 'package');
1804 // filepath is good here, we want the output to start with a directory
1805 // matching the package name.
1806 }
1807 return filepath;
1808 }
1797 1809
1798 class SourceMapPrintingContext extends JS.JavaScriptPrintingContext { 1810 class SourceMapPrintingContext extends JS.JavaScriptPrintingContext {
1799 final srcmaps.Printer printer; 1811 final srcmaps.Printer printer;
1800 final String outputDir; 1812 final String outputDir;
1801 1813
1802 CompilationUnit unit; 1814 CompilationUnit unit;
1803 Uri uri; 1815 Uri uri;
1804 1816
1805 SourceMapPrintingContext(this.printer, this.outputDir); 1817 SourceMapPrintingContext(this.printer, this.outputDir);
1806 1818
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1852 1864
1853 // TODO(jmesserly): in many cases marking the end will be unncessary. 1865 // TODO(jmesserly): in many cases marking the end will be unncessary.
1854 printer.mark(_location(node.end)); 1866 printer.mark(_location(node.end));
1855 } 1867 }
1856 1868
1857 String _getIdentifier(AstNode node) { 1869 String _getIdentifier(AstNode node) {
1858 if (node is SimpleIdentifier) return node.name; 1870 if (node is SimpleIdentifier) return node.name;
1859 return null; 1871 return null;
1860 } 1872 }
1861 } 1873 }
OLDNEW
« 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