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

Side by Side Diff: pkg/compiler/lib/src/js/js.dart

Issue 1081313003: Improve precision of JS printer callbacks (2nd try) (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Cleanup. Created 5 years, 8 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 | Annotate | Revision Log
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 js; 5 library js;
6 6
7 import 'package:js_ast/js_ast.dart'; 7 import 'package:js_ast/js_ast.dart';
8 export 'package:js_ast/js_ast.dart'; 8 export 'package:js_ast/js_ast.dart';
9 9
10 import '../io/code_output.dart' show CodeBuffer; 10 import '../io/code_output.dart' show CodeBuffer;
(...skipping 15 matching lines...) Expand all
26 new Dart2JSJavaScriptPrintingContext(compiler, monitor); 26 new Dart2JSJavaScriptPrintingContext(compiler, monitor);
27 Printer printer = new Printer(options, context); 27 Printer printer = new Printer(options, context);
28 printer.visit(node); 28 printer.visit(node);
29 return context.outBuffer; 29 return context.outBuffer;
30 } 30 }
31 31
32 class Dart2JSJavaScriptPrintingContext implements JavaScriptPrintingContext { 32 class Dart2JSJavaScriptPrintingContext implements JavaScriptPrintingContext {
33 final leg.Compiler compiler; 33 final leg.Compiler compiler;
34 final DumpInfoTask monitor; 34 final DumpInfoTask monitor;
35 final CodeBuffer outBuffer = new CodeBuffer(); 35 final CodeBuffer outBuffer = new CodeBuffer();
36 Node rootNode;
36 37
37 Dart2JSJavaScriptPrintingContext(leg.Compiler this.compiler, 38 Dart2JSJavaScriptPrintingContext(leg.Compiler this.compiler,
38 DumpInfoTask this.monitor); 39 DumpInfoTask this.monitor);
39 40
40 void error(String message) { 41 void error(String message) {
41 compiler.internalError(NO_LOCATION_SPANNABLE, message); 42 compiler.internalError(NO_LOCATION_SPANNABLE, message);
42 } 43 }
43 44
44 void emit(String string) { 45 void emit(String string) {
45 outBuffer.add(string); 46 outBuffer.add(string);
46 } 47 }
47 48
48 void enterNode(Node node) { 49 void enterNode(Node node, int start) {
49 SourceInformation sourceInformation = node.sourceInformation; 50 SourceInformation sourceInformation = node.sourceInformation;
50 if (sourceInformation != null) { 51 if (sourceInformation != null) {
51 sourceInformation.beginMapping(outBuffer); 52 if (rootNode == null) {
53 rootNode = node;
54 }
55 if (sourceInformation.startPosition != null) {
56 outBuffer.addSourceLocation(start, sourceInformation.startPosition);
57 }
52 } 58 }
53 if (monitor != null) monitor.enteringAst(node, outBuffer.length);
54 } 59 }
55 60
56 void exitNode(Node node) { 61 void exitNode(Node node, int start, int end, int delimiter) {
57 if (monitor != null) monitor.exitingAst(node, outBuffer.length);
58 SourceInformation sourceInformation = node.sourceInformation; 62 SourceInformation sourceInformation = node.sourceInformation;
59 if (sourceInformation != null) { 63 if (sourceInformation != null) {
60 sourceInformation.endMapping(outBuffer); 64 if (sourceInformation.endPosition != null) {
65 outBuffer.addSourceLocation(end, sourceInformation.endPosition);
66 }
67 if (rootNode == node) {
68 outBuffer.addSourceLocation(end, null);
69 rootNode = null;
70 }
71 }
72 if (monitor != null) {
73 monitor.recordAstSize(node, end - start);
61 } 74 }
62 } 75 }
63 } 76 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698