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

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

Issue 1263593003: restore arrow function bind this workaround (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 5 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/js_codegen.dart ('k') | 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_printer.dart
diff --git a/lib/src/codegen/js_printer.dart b/lib/src/codegen/js_printer.dart
index 2fd19f05c1204a4a50f0bb31adbc79daffee0d77..e5545e6e42d39bfa9e387bc780796e658897c1c8 100644
--- a/lib/src/codegen/js_printer.dart
+++ b/lib/src/codegen/js_printer.dart
@@ -18,36 +18,37 @@ import 'package:dev_compiler/src/utils.dart'
import 'js_names.dart' show TemporaryNamer;
String writeJsLibrary(JS.Program jsTree, String outputPath,
- {bool emitSourceMaps: false}) {
- new Directory(path.dirname(outputPath)).createSync(recursive: true);
+ {bool emitSourceMaps: false, bool arrowFnBindThisWorkaround: false}) {
+ var outFilename = path.basename(outputPath);
+ var outDir = path.dirname(outputPath);
+ new Directory(outDir).createSync(recursive: true);
+
+ JS.JavaScriptPrintingContext context;
if (emitSourceMaps) {
- var outFilename = path.basename(outputPath);
var printer = new srcmaps.Printer(outFilename);
- writeNodeToContext(jsTree,
- new SourceMapPrintingContext(printer, path.dirname(outputPath)));
+ context = new SourceMapPrintingContext(printer, outDir);
+ } else {
+ context = new JS.SimpleJavaScriptPrintingContext();
+ }
+
+ var opts = new JS.JavaScriptPrintingOptions(
+ allowKeywordsInProperties: true,
+ arrowFnBindThisWorkaround: arrowFnBindThisWorkaround);
+ var jsNamer = new TemporaryNamer(jsTree);
+ jsTree.accept(new JS.Printer(opts, context, localNamer: jsNamer));
+
+ String text;
+ if (context is SourceMapPrintingContext) {
+ var printer = context.printer;
printer.add('//# sourceMappingURL=$outFilename.map');
// Write output file and source map
- var text = printer.text;
- new File(outputPath).writeAsStringSync(text);
+ text = printer.text;
new File('$outputPath.map').writeAsStringSync(printer.map);
- return computeHash(text);
} else {
- var text = jsNodeToString(jsTree);
- new File(outputPath).writeAsStringSync(text);
- return computeHash(text);
+ text = (context as JS.SimpleJavaScriptPrintingContext).getText();
}
-}
-
-void writeNodeToContext(JS.Node node, JS.JavaScriptPrintingContext context) {
- var opts = new JS.JavaScriptPrintingOptions(allowKeywordsInProperties: true);
- node.accept(
- new JS.Printer(opts, context, localNamer: new TemporaryNamer(node)));
-}
-
-String jsNodeToString(JS.Node node) {
- var context = new JS.SimpleJavaScriptPrintingContext();
- writeNodeToContext(node, context);
- return context.getText();
+ new File(outputPath).writeAsStringSync(text);
+ return computeHash(text);
}
class SourceMapPrintingContext extends JS.JavaScriptPrintingContext {
« no previous file with comments | « lib/src/codegen/js_codegen.dart ('k') | lib/src/js/nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698