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 '../helpers/helpers.dart'; |
10 import '../io/code_output.dart' show CodeBuffer; | 11 import '../io/code_output.dart' show CodeBuffer; |
11 import '../io/source_information.dart' show SourceInformation; | 12 import '../io/source_information.dart' show SourceInformation; |
12 import '../js_emitter/js_emitter.dart' show USE_NEW_EMITTER; | 13 import '../js_emitter/js_emitter.dart' show USE_NEW_EMITTER; |
13 import '../dart2jslib.dart' as leg; | 14 import '../dart2jslib.dart' as leg; |
14 import '../util/util.dart' show NO_LOCATION_SPANNABLE; | 15 import '../util/util.dart' show NO_LOCATION_SPANNABLE; |
15 import '../dump_info.dart' show DumpInfoTask; | 16 import '../dump_info.dart' show DumpInfoTask; |
16 | 17 |
17 | 18 |
18 CodeBuffer prettyPrint(Node node, leg.Compiler compiler, | 19 CodeBuffer prettyPrint(Node node, leg.Compiler compiler, |
19 {DumpInfoTask monitor, | 20 {DumpInfoTask monitor, |
(...skipping 11 matching lines...) Expand all Loading... |
31 | 32 |
32 class Dart2JSJavaScriptPrintingContext implements JavaScriptPrintingContext { | 33 class Dart2JSJavaScriptPrintingContext implements JavaScriptPrintingContext { |
33 final leg.Compiler compiler; | 34 final leg.Compiler compiler; |
34 final DumpInfoTask monitor; | 35 final DumpInfoTask monitor; |
35 final CodeBuffer outBuffer = new CodeBuffer(); | 36 final CodeBuffer outBuffer = new CodeBuffer(); |
36 Node rootNode; | 37 Node rootNode; |
37 | 38 |
38 Dart2JSJavaScriptPrintingContext(leg.Compiler this.compiler, | 39 Dart2JSJavaScriptPrintingContext(leg.Compiler this.compiler, |
39 DumpInfoTask this.monitor); | 40 DumpInfoTask this.monitor); |
40 | 41 |
| 42 @override |
41 void error(String message) { | 43 void error(String message) { |
42 compiler.internalError(NO_LOCATION_SPANNABLE, message); | 44 compiler.internalError(NO_LOCATION_SPANNABLE, message); |
43 } | 45 } |
44 | 46 |
| 47 @override |
45 void emit(String string) { | 48 void emit(String string) { |
46 outBuffer.add(string); | 49 outBuffer.add(string); |
47 } | 50 } |
48 | 51 |
| 52 @override |
49 void enterNode(Node node, int startPosition) { | 53 void enterNode(Node node, int startPosition) { |
50 SourceInformation sourceInformation = node.sourceInformation; | 54 SourceInformation sourceInformation = node.sourceInformation; |
51 if (sourceInformation != null) { | 55 if (sourceInformation != null) { |
52 if (rootNode == null) { | 56 if (rootNode == null) { |
53 rootNode = node; | 57 rootNode = node; |
54 } | 58 } |
55 if (sourceInformation.startPosition != null) { | 59 if (sourceInformation.startPosition != null) { |
56 outBuffer.addSourceLocation( | 60 outBuffer.addSourceLocation( |
57 startPosition, sourceInformation.startPosition); | 61 startPosition, sourceInformation.startPosition); |
58 } | 62 } |
59 } | 63 } |
60 } | 64 } |
61 | 65 |
62 void exitNode(Node node, | 66 void exitNode(Node node, |
63 int startPosition, | 67 int startPosition, |
64 int endPosition, | 68 int endPosition, |
65 int closingPosition) { | 69 int closingPosition) { |
66 SourceInformation sourceInformation = node.sourceInformation; | 70 SourceInformation sourceInformation = node.sourceInformation; |
67 if (sourceInformation != null) { | 71 if (sourceInformation != null) { |
| 72 if (closingPosition != null && |
| 73 sourceInformation.closingPosition != null) { |
| 74 outBuffer.addSourceLocation( |
| 75 closingPosition, sourceInformation.closingPosition); |
| 76 } |
68 if (sourceInformation.endPosition != null) { | 77 if (sourceInformation.endPosition != null) { |
69 outBuffer.addSourceLocation(endPosition, sourceInformation.endPosition); | 78 outBuffer.addSourceLocation(endPosition, sourceInformation.endPosition); |
70 } | 79 } |
71 if (rootNode == node) { | 80 if (rootNode == node) { |
72 outBuffer.addSourceLocation(endPosition, null); | 81 outBuffer.addSourceLocation(endPosition, null); |
73 rootNode = null; | 82 rootNode = null; |
74 } | 83 } |
75 } | 84 } |
76 if (monitor != null) { | 85 if (monitor != null) { |
77 monitor.recordAstSize(node, endPosition - startPosition); | 86 monitor.recordAstSize(node, endPosition - startPosition); |
78 } | 87 } |
79 } | 88 } |
80 } | 89 } |
OLD | NEW |