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 dev_compiler.src.codegen.js_printer; | 5 library dev_compiler.src.codegen.js_printer; |
6 | 6 |
7 import 'dart:io' show Directory, File, Platform, Process; | 7 import 'dart:io' show Directory, File, Platform, Process; |
8 | 8 |
9 import 'package:analyzer/src/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
10 import 'package:path/path.dart' as path; | 10 import 'package:path/path.dart' as path; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 Uri uri; | 65 Uri uri; |
66 | 66 |
67 SourceMapPrintingContext(this.printer, this.outputDir); | 67 SourceMapPrintingContext(this.printer, this.outputDir); |
68 | 68 |
69 void emit(String string) { | 69 void emit(String string) { |
70 printer.add(string); | 70 printer.add(string); |
71 } | 71 } |
72 | 72 |
73 void enterNode(JS.Node jsNode) { | 73 void enterNode(JS.Node jsNode) { |
74 AstNode node = jsNode.sourceInformation; | 74 AstNode node = jsNode.sourceInformation; |
75 if (node is CompilationUnit) { | 75 if (node == null || node.offset == -1) return; |
76 unit = node; | 76 if (node.parent is CompilationUnit) { |
Jennifer Messerly
2015/11/09 18:38:46
We'll keep making the URI over and over, right? Si
vsm
2015/11/09 19:15:42
If there is a natural visit on the CompilationUnit
vsm
2015/11/09 19:15:42
BTW, I tested this with Angular - seems like we ha
| |
77 unit = node.parent; | |
77 uri = _makeRelativeUri(unit.element.source.uri); | 78 uri = _makeRelativeUri(unit.element.source.uri); |
78 return; | |
79 } | 79 } |
80 if (unit == null || node == null || node.offset == -1) return; | |
81 | 80 |
82 var loc = _location(node.offset); | 81 var loc = _location(node.offset); |
83 var name = _getIdentifier(node); | 82 var name = _getIdentifier(node); |
84 if (name != null) { | 83 if (name != null) { |
85 // TODO(jmesserly): mark only uses the beginning of the span, but | 84 // TODO(jmesserly): mark only uses the beginning of the span, but |
86 // we're required to pass this as a valid span. | 85 // we're required to pass this as a valid span. |
87 var end = _location(node.end); | 86 var end = _location(node.end); |
88 printer.mark(new SourceMapSpan(loc, end, name, isIdentifier: true)); | 87 printer.mark(new SourceMapSpan(loc, end, name, isIdentifier: true)); |
89 } else { | 88 } else { |
90 printer.mark(loc); | 89 printer.mark(loc); |
(...skipping 18 matching lines...) Expand all Loading... | |
109 | 108 |
110 // TODO(jmesserly): in many cases marking the end will be unnecessary. | 109 // TODO(jmesserly): in many cases marking the end will be unnecessary. |
111 printer.mark(_location(node.end)); | 110 printer.mark(_location(node.end)); |
112 } | 111 } |
113 | 112 |
114 String _getIdentifier(AstNode node) { | 113 String _getIdentifier(AstNode node) { |
115 if (node is SimpleIdentifier) return node.name; | 114 if (node is SimpleIdentifier) return node.name; |
116 return null; | 115 return null; |
117 } | 116 } |
118 } | 117 } |
OLD | NEW |