OLD | NEW |
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 Loading... |
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 startPosition) { |
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( |
| 57 startPosition, sourceInformation.startPosition); |
| 58 } |
52 } | 59 } |
53 if (monitor != null) monitor.enteringAst(node, outBuffer.length); | |
54 } | 60 } |
55 | 61 |
56 void exitNode(Node node) { | 62 void exitNode(Node node, |
57 if (monitor != null) monitor.exitingAst(node, outBuffer.length); | 63 int startPosition, |
| 64 int endPosition, |
| 65 int closingPosition) { |
58 SourceInformation sourceInformation = node.sourceInformation; | 66 SourceInformation sourceInformation = node.sourceInformation; |
59 if (sourceInformation != null) { | 67 if (sourceInformation != null) { |
60 sourceInformation.endMapping(outBuffer); | 68 if (sourceInformation.endPosition != null) { |
| 69 outBuffer.addSourceLocation(endPosition, sourceInformation.endPosition); |
| 70 } |
| 71 if (rootNode == node) { |
| 72 outBuffer.addSourceLocation(endPosition, null); |
| 73 rootNode = null; |
| 74 } |
| 75 } |
| 76 if (monitor != null) { |
| 77 monitor.recordAstSize(node, endPosition - startPosition); |
61 } | 78 } |
62 } | 79 } |
63 } | 80 } |
OLD | NEW |