OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 source_map_builder; | 5 library source_map_builder; |
6 | 6 |
7 | 7 |
8 import 'util/util.dart'; | 8 import 'util/util.dart'; |
9 import 'scanner/scannerlib.dart' show Token; | 9 import 'scanner/scannerlib.dart' show Token; |
10 import 'source_file.dart'; | 10 import 'source_file.dart'; |
11 import 'util/uri_extras.dart' show relativize; | 11 import 'util/uri_extras.dart' show relativize; |
12 | 12 |
13 class SourceMapBuilder { | 13 class SourceMapBuilder { |
14 static const int VLQ_BASE_SHIFT = 5; | 14 static const int VLQ_BASE_SHIFT = 5; |
15 static const int VLQ_BASE_MASK = (1 << 5) - 1; | 15 static const int VLQ_BASE_MASK = (1 << 5) - 1; |
16 static const int VLQ_CONTINUATION_BIT = 1 << 5; | 16 static const int VLQ_CONTINUATION_BIT = 1 << 5; |
17 static const int VLQ_CONTINUATION_MASK = 1 << 5; | 17 static const int VLQ_CONTINUATION_MASK = 1 << 5; |
18 static const String BASE64_DIGITS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn' | 18 static const String BASE64_DIGITS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn' |
19 'opqrstuvwxyz0123456789+/'; | 19 'opqrstuvwxyz0123456789+/'; |
20 | 20 |
21 final Uri uri; | 21 final Uri uri; |
| 22 final Uri fileUri; |
22 | 23 |
23 List<SourceMapEntry> entries; | 24 List<SourceMapEntry> entries; |
24 | 25 |
25 Map<String, int> sourceUrlMap; | 26 Map<String, int> sourceUrlMap; |
26 List<String> sourceUrlList; | 27 List<String> sourceUrlList; |
27 Map<String, int> sourceNameMap; | 28 Map<String, int> sourceNameMap; |
28 List<String> sourceNameList; | 29 List<String> sourceNameList; |
29 | 30 |
30 int previousTargetLine; | 31 int previousTargetLine; |
31 int previousTargetColumn; | 32 int previousTargetColumn; |
32 int previousSourceUrlIndex; | 33 int previousSourceUrlIndex; |
33 int previousSourceLine; | 34 int previousSourceLine; |
34 int previousSourceColumn; | 35 int previousSourceColumn; |
35 int previousSourceNameIndex; | 36 int previousSourceNameIndex; |
36 bool firstEntryInLine; | 37 bool firstEntryInLine; |
37 | 38 |
38 SourceMapBuilder(this.uri) { | 39 SourceMapBuilder(this.uri, this.fileUri) { |
39 entries = new List<SourceMapEntry>(); | 40 entries = new List<SourceMapEntry>(); |
40 | 41 |
41 sourceUrlMap = new Map<String, int>(); | 42 sourceUrlMap = new Map<String, int>(); |
42 sourceUrlList = new List<String>(); | 43 sourceUrlList = new List<String>(); |
43 sourceNameMap = new Map<String, int>(); | 44 sourceNameMap = new Map<String, int>(); |
44 sourceNameList = new List<String>(); | 45 sourceNameList = new List<String>(); |
45 | 46 |
46 previousTargetLine = 0; | 47 previousTargetLine = 0; |
47 previousTargetColumn = 0; | 48 previousTargetColumn = 0; |
48 previousSourceUrlIndex = 0; | 49 previousSourceUrlIndex = 0; |
(...skipping 20 matching lines...) Expand all Loading... |
69 buffer.write(']'); | 70 buffer.write(']'); |
70 } | 71 } |
71 | 72 |
72 String build(SourceFile targetFile) { | 73 String build(SourceFile targetFile) { |
73 StringBuffer mappingsBuffer = new StringBuffer(); | 74 StringBuffer mappingsBuffer = new StringBuffer(); |
74 entries.forEach((SourceMapEntry entry) => writeEntry(entry, targetFile, | 75 entries.forEach((SourceMapEntry entry) => writeEntry(entry, targetFile, |
75 mappingsBuffer)); | 76 mappingsBuffer)); |
76 StringBuffer buffer = new StringBuffer(); | 77 StringBuffer buffer = new StringBuffer(); |
77 buffer.write('{\n'); | 78 buffer.write('{\n'); |
78 buffer.write(' "version": 3,\n'); | 79 buffer.write(' "version": 3,\n'); |
| 80 if (uri != null && fileUri != null) { |
| 81 buffer.write(' "file": "${relativize(uri, fileUri, false)}",\n'); |
| 82 } |
79 buffer.write(' "sourceRoot": "",\n'); | 83 buffer.write(' "sourceRoot": "",\n'); |
80 buffer.write(' "sources": '); | 84 buffer.write(' "sources": '); |
81 if (uri != null) { | 85 if (uri != null) { |
82 sourceUrlList = | 86 sourceUrlList = |
83 sourceUrlList.map((url) => relativize(uri, Uri.parse(url), false)) | 87 sourceUrlList.map((url) => relativize(uri, Uri.parse(url), false)) |
84 .toList(); | 88 .toList(); |
85 } | 89 } |
86 printStringListOn(sourceUrlList, buffer); | 90 printStringListOn(sourceUrlList, buffer); |
87 buffer.write(',\n'); | 91 buffer.write(',\n'); |
88 buffer.write(' "names": '); | 92 buffer.write(' "names": '); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 } | 217 } |
214 | 218 |
215 class OffsetSourceFileLocation extends SourceFileLocation { | 219 class OffsetSourceFileLocation extends SourceFileLocation { |
216 final int offset; | 220 final int offset; |
217 final String sourceName; | 221 final String sourceName; |
218 OffsetSourceFileLocation(SourceFile sourceFile, this.offset, | 222 OffsetSourceFileLocation(SourceFile sourceFile, this.offset, |
219 [this.sourceName]) : super(sourceFile); | 223 [this.sourceName]) : super(sourceFile); |
220 | 224 |
221 String getSourceName() => sourceName; | 225 String getSourceName() => sourceName; |
222 } | 226 } |
OLD | NEW |