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

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

Issue 960353003: cleanup: js_codegen now returns a js_ast.Program (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 | « no previous file | lib/src/js/nodes.dart » ('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 33868aa5ae61916873abf083cf9ce39b7a0c7418..848f9b8aabf42bf2727c4ea9504d25c07c9f631d 100644
--- a/lib/src/codegen/js_codegen.dart
+++ b/lib/src/codegen/js_codegen.dart
@@ -58,7 +58,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
Element get currentLibrary => libraryInfo.library;
- JS.Block generateLibrary(
+ JS.Program generateLibrary(
Iterable<CompilationUnit> units, CheckerReporter reporter) {
var body = <JS.Statement>[];
for (var unit in units) {
@@ -80,7 +80,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
}
var name = jsLibraryName(libraryInfo.library);
- return new JS.Block([
+ return new JS.Program([
js.statement('var #;', name),
js.statement("(function($_EXPORTS) { 'use strict'; #; })(# || (# = {}));",
[body, name, name])
@@ -1927,7 +1927,7 @@ class JSGenerator extends CodeGenerator {
void generateLibrary(Iterable<CompilationUnit> units, LibraryInfo info,
CheckerReporter reporter) {
- JS.Block jsTree =
+ JS.Program jsTree =
new JSCodegenVisitor(info, rules).generateLibrary(units, reporter);
var outputPath = path.join(outDir, jsOutputPath(info, root));
@@ -1936,34 +1936,28 @@ class JSGenerator extends CodeGenerator {
if (options.emitSourceMaps) {
var outFilename = path.basename(outputPath);
var printer = new srcmaps.Printer(outFilename);
- var context =
- new SourceMapPrintingContext(printer, path.dirname(outputPath));
- _writeLibrary(context, jsTree);
+ _writeNode(
+ new SourceMapPrintingContext(printer, path.dirname(outputPath)),
+ jsTree);
printer.add('//# sourceMappingURL=$outFilename.map');
// Write output file and source map
new File(outputPath).writeAsStringSync(printer.text);
new File('$outputPath.map').writeAsStringSync(printer.map);
} else {
- var context = new JS.SimpleJavaScriptPrintingContext();
- _writeLibrary(context, jsTree);
- // Write output file and source map
- new File(outputPath).writeAsStringSync(context.getText());
+ new File(outputPath).writeAsStringSync(jsNodeToString(jsTree));
}
}
+}
- void _writeLibrary(JS.JavaScriptPrintingContext context, JS.Block jsTree) {
- var opts =
- new JS.JavaScriptPrintingOptions(avoidKeywordsInIdentifiers: true);
- new JS.Printer(opts, context).blockOutWithoutBraces(jsTree);
- }
+void _writeNode(JS.JavaScriptPrintingContext context, JS.Node node) {
+ var opts = new JS.JavaScriptPrintingOptions(avoidKeywordsInIdentifiers: true);
+ node.accept(new JS.Printer(opts, context));
}
/// This is a debugging helper to print a JS node.
-String debugJsNodeToString(JS.Node node) {
+String jsNodeToString(JS.Node node) {
var context = new JS.SimpleJavaScriptPrintingContext();
- var opts = new JS.JavaScriptPrintingOptions(avoidKeywordsInIdentifiers: true);
- new JS.Printer(opts, context).visit(node);
- // Write output file and source map
+ _writeNode(context, node);
return context.getText();
}
« no previous file with comments | « no previous file | lib/src/js/nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698