@volar/source-map 0.28.10 → 0.29.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/index.d.ts +43 -43
- package/out/index.js +94 -86
- package/package.json +3 -3
package/out/index.d.ts
CHANGED
|
@@ -63,65 +63,65 @@ export declare type Mapping<T> = MappingBase & {
|
|
|
63
63
|
data: T;
|
|
64
64
|
additional?: MappingBase[];
|
|
65
65
|
};
|
|
66
|
-
export declare class
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
data: Data;
|
|
72
|
-
start: vscode.Position;
|
|
73
|
-
end: vscode.Position;
|
|
74
|
-
}[]>;
|
|
75
|
-
cache2: Map<string, {
|
|
66
|
+
export declare class SourceMapBase<Data = undefined> {
|
|
67
|
+
mappings: Mapping<Data>[];
|
|
68
|
+
constructor(_mappings?: Mapping<Data>[]);
|
|
69
|
+
private cache;
|
|
70
|
+
getSourceRange(start: number, end?: number, filter?: (data: Data) => boolean): {
|
|
76
71
|
data: Data;
|
|
77
72
|
start: number;
|
|
78
73
|
end: number;
|
|
79
|
-
}[]>;
|
|
80
|
-
isSourceRange(start: vscode.Position, end?: vscode.Position): boolean;
|
|
81
|
-
isMappedRange(start: vscode.Position, end?: vscode.Position): boolean;
|
|
82
|
-
getSourceRange(start: vscode.Position, end?: vscode.Position): {
|
|
83
|
-
data: Data;
|
|
84
|
-
start: vscode.Position;
|
|
85
|
-
end: vscode.Position;
|
|
86
|
-
} | undefined;
|
|
87
|
-
getMappedRange(start: vscode.Position, end?: vscode.Position): {
|
|
88
|
-
data: Data;
|
|
89
|
-
start: vscode.Position;
|
|
90
|
-
end: vscode.Position;
|
|
91
74
|
} | undefined;
|
|
92
|
-
|
|
93
|
-
data: Data;
|
|
94
|
-
start: vscode.Position;
|
|
95
|
-
end: vscode.Position;
|
|
96
|
-
}[];
|
|
97
|
-
getMappedRanges(start: vscode.Position, end?: vscode.Position): {
|
|
98
|
-
data: Data;
|
|
99
|
-
start: vscode.Position;
|
|
100
|
-
end: vscode.Position;
|
|
101
|
-
}[];
|
|
102
|
-
private getRanges;
|
|
103
|
-
isSourceRange2(start: number, end?: number): boolean;
|
|
104
|
-
isMappedRange2(start: number, end?: number): boolean;
|
|
105
|
-
getSourceRange2(start: number, end?: number): {
|
|
75
|
+
getMappedRange(start: number, end?: number, filter?: (data: Data) => boolean): {
|
|
106
76
|
data: Data;
|
|
107
77
|
start: number;
|
|
108
78
|
end: number;
|
|
109
79
|
} | undefined;
|
|
110
|
-
|
|
80
|
+
getSourceRanges(start: number, end?: number, filter?: (data: Data) => boolean): Generator<{
|
|
111
81
|
data: Data;
|
|
112
82
|
start: number;
|
|
113
83
|
end: number;
|
|
114
|
-
}
|
|
115
|
-
|
|
84
|
+
}, void, unknown>;
|
|
85
|
+
getMappedRanges(start: number, end?: number, filter?: (data: Data) => boolean): Generator<{
|
|
116
86
|
data: Data;
|
|
117
87
|
start: number;
|
|
118
88
|
end: number;
|
|
119
|
-
}
|
|
120
|
-
|
|
89
|
+
}, void, unknown>;
|
|
90
|
+
protected getRanges(startOffset: number, endOffset: number, sourceToTarget: boolean, filter?: (data: Data) => boolean): Generator<{
|
|
121
91
|
data: Data;
|
|
122
92
|
start: number;
|
|
123
93
|
end: number;
|
|
124
|
-
}
|
|
125
|
-
private getRanges2;
|
|
94
|
+
}, void, unknown>;
|
|
126
95
|
private getRange;
|
|
127
96
|
}
|
|
97
|
+
export declare class SourceMap<Data = undefined> extends SourceMapBase<Data> {
|
|
98
|
+
sourceDocument: TextDocument;
|
|
99
|
+
mappedDocument: TextDocument;
|
|
100
|
+
_mappings?: Mapping<Data>[] | undefined;
|
|
101
|
+
constructor(sourceDocument: TextDocument, mappedDocument: TextDocument, _mappings?: Mapping<Data>[] | undefined);
|
|
102
|
+
getSourceRange<T extends number | vscode.Position>(start: T, end?: T, filter?: (data: Data) => boolean): {
|
|
103
|
+
data: Data;
|
|
104
|
+
start: T;
|
|
105
|
+
end: T;
|
|
106
|
+
} | undefined;
|
|
107
|
+
getMappedRange<T extends number | vscode.Position>(start: T, end?: T, filter?: (data: Data) => boolean): {
|
|
108
|
+
data: Data;
|
|
109
|
+
start: T;
|
|
110
|
+
end: T;
|
|
111
|
+
} | undefined;
|
|
112
|
+
getSourceRanges<T extends number | vscode.Position>(start: T, end?: T, filter?: (data: Data) => boolean): Generator<{
|
|
113
|
+
data: Data;
|
|
114
|
+
start: T;
|
|
115
|
+
end: T;
|
|
116
|
+
}, void, unknown>;
|
|
117
|
+
getMappedRanges<T extends number | vscode.Position>(start: T, end?: T, filter?: (data: Data) => boolean): Generator<{
|
|
118
|
+
data: Data;
|
|
119
|
+
start: T;
|
|
120
|
+
end: T;
|
|
121
|
+
}, void, unknown>;
|
|
122
|
+
protected getRanges<T extends number | vscode.Position>(start: T, end: T, sourceToTarget: boolean, filter?: (data: Data) => boolean): Generator<{
|
|
123
|
+
data: Data;
|
|
124
|
+
start: T;
|
|
125
|
+
end: T;
|
|
126
|
+
}, void, unknown>;
|
|
127
|
+
}
|
package/out/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SourceMap = exports.Mode = void 0;
|
|
3
|
+
exports.SourceMap = exports.SourceMapBase = exports.Mode = void 0;
|
|
4
4
|
var Mode;
|
|
5
5
|
(function (Mode) {
|
|
6
6
|
/**
|
|
@@ -52,103 +52,65 @@ var Mode;
|
|
|
52
52
|
*/
|
|
53
53
|
Mode[Mode["Overlap"] = 3] = "Overlap";
|
|
54
54
|
})(Mode = exports.Mode || (exports.Mode = {}));
|
|
55
|
-
class
|
|
56
|
-
constructor(
|
|
57
|
-
super(mappings);
|
|
58
|
-
this.sourceDocument = sourceDocument;
|
|
59
|
-
this.mappedDocument = mappedDocument;
|
|
55
|
+
class SourceMapBase {
|
|
56
|
+
constructor(_mappings) {
|
|
60
57
|
this.cache = new Map();
|
|
61
|
-
this.
|
|
62
|
-
}
|
|
63
|
-
// Range
|
|
64
|
-
isSourceRange(start, end) {
|
|
65
|
-
return this.getRanges(start, end !== null && end !== void 0 ? end : start, true, true).length > 0;
|
|
66
|
-
}
|
|
67
|
-
isMappedRange(start, end) {
|
|
68
|
-
return this.getRanges(start, end !== null && end !== void 0 ? end : start, false, true).length > 0;
|
|
69
|
-
}
|
|
70
|
-
getSourceRange(start, end) {
|
|
71
|
-
const result = this.getRanges(start, end !== null && end !== void 0 ? end : start, false, true);
|
|
72
|
-
if (result.length)
|
|
73
|
-
return result[0];
|
|
58
|
+
this.mappings = _mappings !== null && _mappings !== void 0 ? _mappings : [];
|
|
74
59
|
}
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
getSourceRanges(start, end) {
|
|
81
|
-
return this.getRanges(start, end !== null && end !== void 0 ? end : start, false);
|
|
82
|
-
}
|
|
83
|
-
getMappedRanges(start, end) {
|
|
84
|
-
return this.getRanges(start, end !== null && end !== void 0 ? end : start, true);
|
|
85
|
-
}
|
|
86
|
-
getRanges(start, end, sourceToTarget, returnFirstResult) {
|
|
87
|
-
const key = start.line + ':' + start.character + ':' + end.line + ':' + end.character + ':' + sourceToTarget + ':' + returnFirstResult;
|
|
88
|
-
if (this.cache.has(key))
|
|
89
|
-
return this.cache.get(key);
|
|
90
|
-
const toDoc = sourceToTarget ? this.mappedDocument : this.sourceDocument;
|
|
91
|
-
const fromDoc = sourceToTarget ? this.sourceDocument : this.mappedDocument;
|
|
92
|
-
const startOffset = fromDoc.offsetAt(start);
|
|
93
|
-
const endOffset = fromDoc.offsetAt(end);
|
|
94
|
-
const result = this
|
|
95
|
-
.getRanges2(startOffset, endOffset, sourceToTarget, returnFirstResult)
|
|
96
|
-
.map(result => ({
|
|
97
|
-
data: result.data,
|
|
98
|
-
start: toDoc.positionAt(result.start),
|
|
99
|
-
end: toDoc.positionAt(result.end),
|
|
100
|
-
}));
|
|
101
|
-
this.cache.set(key, result);
|
|
102
|
-
return result;
|
|
103
|
-
}
|
|
104
|
-
// MapedRange
|
|
105
|
-
isSourceRange2(start, end) {
|
|
106
|
-
return this.getRanges2(start, end !== null && end !== void 0 ? end : start, true, true).length > 0;
|
|
107
|
-
}
|
|
108
|
-
isMappedRange2(start, end) {
|
|
109
|
-
return this.getRanges2(start, end !== null && end !== void 0 ? end : start, false, true).length > 0;
|
|
110
|
-
}
|
|
111
|
-
getSourceRange2(start, end) {
|
|
112
|
-
const result = this.getRanges2(start, end !== null && end !== void 0 ? end : start, false, true);
|
|
113
|
-
if (result.length)
|
|
114
|
-
return result[0];
|
|
115
|
-
}
|
|
116
|
-
getMappedRange2(start, end) {
|
|
117
|
-
const result = this.getRanges2(start, end !== null && end !== void 0 ? end : start, true, true);
|
|
118
|
-
if (result.length)
|
|
119
|
-
return result[0];
|
|
120
|
-
}
|
|
121
|
-
getSourceRanges2(start, end) {
|
|
122
|
-
return this.getRanges2(start, end !== null && end !== void 0 ? end : start, false);
|
|
60
|
+
getSourceRange(start, end, filter) {
|
|
61
|
+
for (const maped of this.getRanges(start, end !== null && end !== void 0 ? end : start, false, filter)) {
|
|
62
|
+
return maped;
|
|
63
|
+
}
|
|
123
64
|
}
|
|
124
|
-
|
|
125
|
-
|
|
65
|
+
getMappedRange(start, end, filter) {
|
|
66
|
+
for (const maped of this.getRanges(start, end !== null && end !== void 0 ? end : start, true, filter)) {
|
|
67
|
+
return maped;
|
|
68
|
+
}
|
|
126
69
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
70
|
+
getSourceRanges(start, end, filter) {
|
|
71
|
+
return this.getRanges(start, end !== null && end !== void 0 ? end : start, false, filter);
|
|
72
|
+
}
|
|
73
|
+
getMappedRanges(start, end, filter) {
|
|
74
|
+
return this.getRanges(start, end !== null && end !== void 0 ? end : start, true, filter);
|
|
75
|
+
}
|
|
76
|
+
*getRanges(startOffset, endOffset, sourceToTarget, filter) {
|
|
77
|
+
const key = startOffset + ':' + endOffset + ':' + sourceToTarget;
|
|
78
|
+
let result = this.cache.get(key);
|
|
79
|
+
if (!result) {
|
|
80
|
+
result = {
|
|
81
|
+
index: 0,
|
|
82
|
+
mapeds: [],
|
|
83
|
+
};
|
|
84
|
+
this.cache.set(key, result);
|
|
85
|
+
}
|
|
86
|
+
for (const maped of result.mapeds) {
|
|
87
|
+
if (!filter || filter(maped.data)) {
|
|
88
|
+
yield getMaped(maped);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
while (result.index < this.mappings.length) {
|
|
92
|
+
const mapping = this.mappings[result.index++];
|
|
93
|
+
const maped = this.getRange(startOffset, endOffset, sourceToTarget, mapping.mode, mapping.sourceRange, mapping.mappedRange, mapping.data);
|
|
134
94
|
if (maped) {
|
|
135
|
-
result.push(maped);
|
|
136
|
-
if (
|
|
137
|
-
|
|
95
|
+
result.mapeds.push(maped);
|
|
96
|
+
if (!filter || filter(maped.data))
|
|
97
|
+
yield getMaped(maped);
|
|
138
98
|
}
|
|
139
|
-
if (mapping.additional) {
|
|
99
|
+
else if (mapping.additional) {
|
|
140
100
|
for (const other of mapping.additional) {
|
|
141
|
-
const maped = this.getRange(
|
|
101
|
+
const maped = this.getRange(startOffset, endOffset, sourceToTarget, other.mode, other.sourceRange, other.mappedRange, mapping.data);
|
|
142
102
|
if (maped) {
|
|
143
|
-
result.push(maped);
|
|
144
|
-
if (
|
|
145
|
-
|
|
103
|
+
result.mapeds.push(maped);
|
|
104
|
+
if (!filter || filter(maped.data))
|
|
105
|
+
yield getMaped(maped);
|
|
106
|
+
break; // only return first match additional range
|
|
146
107
|
}
|
|
147
108
|
}
|
|
148
109
|
}
|
|
149
110
|
}
|
|
150
|
-
|
|
151
|
-
|
|
111
|
+
function getMaped(maped) {
|
|
112
|
+
return maped;
|
|
113
|
+
}
|
|
152
114
|
}
|
|
153
115
|
getRange(start, end, sourceToTarget, mode, sourceRange, targetRange, data) {
|
|
154
116
|
const mapedToRange = sourceToTarget ? targetRange : sourceRange;
|
|
@@ -202,5 +164,51 @@ class SourceMap extends Set {
|
|
|
202
164
|
}
|
|
203
165
|
}
|
|
204
166
|
}
|
|
167
|
+
exports.SourceMapBase = SourceMapBase;
|
|
168
|
+
class SourceMap extends SourceMapBase {
|
|
169
|
+
constructor(sourceDocument, mappedDocument, _mappings) {
|
|
170
|
+
super(_mappings);
|
|
171
|
+
this.sourceDocument = sourceDocument;
|
|
172
|
+
this.mappedDocument = mappedDocument;
|
|
173
|
+
this._mappings = _mappings;
|
|
174
|
+
}
|
|
175
|
+
getSourceRange(start, end, filter) {
|
|
176
|
+
for (const maped of this.getRanges(start, end !== null && end !== void 0 ? end : start, false, filter)) {
|
|
177
|
+
return maped;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
getMappedRange(start, end, filter) {
|
|
181
|
+
for (const maped of this.getRanges(start, end !== null && end !== void 0 ? end : start, true, filter)) {
|
|
182
|
+
return maped;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
getSourceRanges(start, end, filter) {
|
|
186
|
+
return this.getRanges(start, end !== null && end !== void 0 ? end : start, false, filter);
|
|
187
|
+
}
|
|
188
|
+
getMappedRanges(start, end, filter) {
|
|
189
|
+
return this.getRanges(start, end !== null && end !== void 0 ? end : start, true, filter);
|
|
190
|
+
}
|
|
191
|
+
*getRanges(start, end, sourceToTarget, filter) {
|
|
192
|
+
const startIsNumber = typeof start === 'number';
|
|
193
|
+
const endIsNumber = typeof end === 'number';
|
|
194
|
+
const toDoc = sourceToTarget ? this.mappedDocument : this.sourceDocument;
|
|
195
|
+
const fromDoc = sourceToTarget ? this.sourceDocument : this.mappedDocument;
|
|
196
|
+
const startOffset = startIsNumber ? start : fromDoc.offsetAt(start);
|
|
197
|
+
const endOffset = endIsNumber ? end : fromDoc.offsetAt(end);
|
|
198
|
+
for (const maped of super.getRanges(startOffset, endOffset, sourceToTarget, filter)) {
|
|
199
|
+
yield getMaped(maped);
|
|
200
|
+
}
|
|
201
|
+
function getMaped(maped) {
|
|
202
|
+
if (startIsNumber) {
|
|
203
|
+
return maped;
|
|
204
|
+
}
|
|
205
|
+
return {
|
|
206
|
+
data: maped.data,
|
|
207
|
+
start: toDoc.positionAt(maped.start),
|
|
208
|
+
end: toDoc.positionAt(maped.end),
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
205
213
|
exports.SourceMap = SourceMap;
|
|
206
214
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/source-map",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.3",
|
|
4
4
|
"main": "out/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"directory": "packages/source-map"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@volar/shared": "0.
|
|
16
|
+
"@volar/shared": "0.29.3"
|
|
17
17
|
},
|
|
18
|
-
"gitHead": "
|
|
18
|
+
"gitHead": "9beca273314c6ffc765ac3bd590aa931b3d742b5"
|
|
19
19
|
}
|