@volar/source-map 0.33.0 → 0.33.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/package.json +2 -6
- package/out/index.d.ts +0 -108
- package/out/index.js +0 -166
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/source-map",
|
|
3
|
-
"version": "0.33.
|
|
3
|
+
"version": "0.33.3",
|
|
4
4
|
"main": "out/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -12,9 +12,5 @@
|
|
|
12
12
|
"url": "https://github.com/johnsoncodehk/volar.git",
|
|
13
13
|
"directory": "packages/source-map"
|
|
14
14
|
},
|
|
15
|
-
"
|
|
16
|
-
"@volar/shared": "0.33.0",
|
|
17
|
-
"vscode-languageserver-textdocument": "^1.0.3"
|
|
18
|
-
},
|
|
19
|
-
"gitHead": "6f5f0e354fd2105e48de12fa67acdca2157202f4"
|
|
15
|
+
"gitHead": "bfc0d807da4448e1628048728950cdcf27582ae3"
|
|
20
16
|
}
|
package/out/index.d.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
2
|
-
export interface Range {
|
|
3
|
-
start: number;
|
|
4
|
-
end: number;
|
|
5
|
-
}
|
|
6
|
-
interface Position {
|
|
7
|
-
line: number;
|
|
8
|
-
character: number;
|
|
9
|
-
}
|
|
10
|
-
export declare enum Mode {
|
|
11
|
-
/**
|
|
12
|
-
* @case1
|
|
13
|
-
* 123456 -> abcdef
|
|
14
|
-
* ^ ^ ^ ^
|
|
15
|
-
* @case2
|
|
16
|
-
* 123456 -> abcdef
|
|
17
|
-
* ^ ^ ^ ^
|
|
18
|
-
* @case3
|
|
19
|
-
* 123456 -> abcdef
|
|
20
|
-
* ^^ ^^
|
|
21
|
-
*/
|
|
22
|
-
Offset = 0,
|
|
23
|
-
/**
|
|
24
|
-
* @case1
|
|
25
|
-
* 123456 -> abcdef
|
|
26
|
-
* ^ ^ ^ ^
|
|
27
|
-
* @case2
|
|
28
|
-
* 123456 -> abcdef
|
|
29
|
-
* ^ ^ NOT_MATCH
|
|
30
|
-
* @case3
|
|
31
|
-
* 123456 -> abcdef
|
|
32
|
-
* ^^ NOT_MATCH
|
|
33
|
-
*/
|
|
34
|
-
Totally = 1,
|
|
35
|
-
/**
|
|
36
|
-
* @case1
|
|
37
|
-
* 123456 -> abcdef
|
|
38
|
-
* ^ ^ ^ ^
|
|
39
|
-
* @case2
|
|
40
|
-
* 123456 -> abcdef
|
|
41
|
-
* ^ ^ ^ ^
|
|
42
|
-
* @case3
|
|
43
|
-
* 123456 -> abcdef
|
|
44
|
-
* ^^ ^ ^
|
|
45
|
-
*/
|
|
46
|
-
Expand = 2
|
|
47
|
-
}
|
|
48
|
-
export declare type MappingBase = {
|
|
49
|
-
mode: Mode;
|
|
50
|
-
sourceRange: Range;
|
|
51
|
-
mappedRange: Range;
|
|
52
|
-
};
|
|
53
|
-
export declare type Mapping<T> = MappingBase & {
|
|
54
|
-
data: T;
|
|
55
|
-
additional?: MappingBase[];
|
|
56
|
-
};
|
|
57
|
-
export declare class SourceMapBase<Data = undefined> {
|
|
58
|
-
mappings: Mapping<Data>[];
|
|
59
|
-
constructor(_mappings?: Mapping<Data>[]);
|
|
60
|
-
getSourceRange(start: number, end?: number, filter?: (data: Data) => boolean): [{
|
|
61
|
-
start: number;
|
|
62
|
-
end: number;
|
|
63
|
-
}, Data] | undefined;
|
|
64
|
-
getMappedRange(start: number, end?: number, filter?: (data: Data) => boolean): [{
|
|
65
|
-
start: number;
|
|
66
|
-
end: number;
|
|
67
|
-
}, Data] | undefined;
|
|
68
|
-
getSourceRanges(start: number, end?: number, filter?: (data: Data) => boolean): Generator<[{
|
|
69
|
-
start: number;
|
|
70
|
-
end: number;
|
|
71
|
-
}, Data], void, unknown>;
|
|
72
|
-
getMappedRanges(start: number, end?: number, filter?: (data: Data) => boolean): Generator<[{
|
|
73
|
-
start: number;
|
|
74
|
-
end: number;
|
|
75
|
-
}, Data], void, unknown>;
|
|
76
|
-
protected getRanges(startOffset: number, endOffset: number, sourceToTarget: boolean, filter?: (data: Data) => boolean): Generator<[{
|
|
77
|
-
start: number;
|
|
78
|
-
end: number;
|
|
79
|
-
}, Data], void, unknown>;
|
|
80
|
-
private getRange;
|
|
81
|
-
}
|
|
82
|
-
export declare class SourceMap<Data = undefined> extends SourceMapBase<Data> {
|
|
83
|
-
sourceDocument: TextDocument;
|
|
84
|
-
mappedDocument: TextDocument;
|
|
85
|
-
_mappings?: Mapping<Data>[] | undefined;
|
|
86
|
-
constructor(sourceDocument: TextDocument, mappedDocument: TextDocument, _mappings?: Mapping<Data>[] | undefined);
|
|
87
|
-
getSourceRange<T extends number | Position>(start: T, end?: T, filter?: (data: Data) => boolean): [{
|
|
88
|
-
start: T;
|
|
89
|
-
end: T;
|
|
90
|
-
}, Data] | undefined;
|
|
91
|
-
getMappedRange<T extends number | Position>(start: T, end?: T, filter?: (data: Data) => boolean): [{
|
|
92
|
-
start: T;
|
|
93
|
-
end: T;
|
|
94
|
-
}, Data] | undefined;
|
|
95
|
-
getSourceRanges<T extends number | Position>(start: T, end?: T, filter?: (data: Data) => boolean): Generator<[{
|
|
96
|
-
start: T;
|
|
97
|
-
end: T;
|
|
98
|
-
}, Data], void, unknown>;
|
|
99
|
-
getMappedRanges<T extends number | Position>(start: T, end?: T, filter?: (data: Data) => boolean): Generator<[{
|
|
100
|
-
start: T;
|
|
101
|
-
end: T;
|
|
102
|
-
}, Data], void, unknown>;
|
|
103
|
-
protected getRanges<T extends number | Position>(start: T, end: T, sourceToTarget: boolean, filter?: (data: Data) => boolean): Generator<[{
|
|
104
|
-
start: T;
|
|
105
|
-
end: T;
|
|
106
|
-
}, Data], void, unknown>;
|
|
107
|
-
}
|
|
108
|
-
export {};
|
package/out/index.js
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SourceMap = exports.SourceMapBase = exports.Mode = void 0;
|
|
4
|
-
var Mode;
|
|
5
|
-
(function (Mode) {
|
|
6
|
-
/**
|
|
7
|
-
* @case1
|
|
8
|
-
* 123456 -> abcdef
|
|
9
|
-
* ^ ^ ^ ^
|
|
10
|
-
* @case2
|
|
11
|
-
* 123456 -> abcdef
|
|
12
|
-
* ^ ^ ^ ^
|
|
13
|
-
* @case3
|
|
14
|
-
* 123456 -> abcdef
|
|
15
|
-
* ^^ ^^
|
|
16
|
-
*/
|
|
17
|
-
Mode[Mode["Offset"] = 0] = "Offset";
|
|
18
|
-
/**
|
|
19
|
-
* @case1
|
|
20
|
-
* 123456 -> abcdef
|
|
21
|
-
* ^ ^ ^ ^
|
|
22
|
-
* @case2
|
|
23
|
-
* 123456 -> abcdef
|
|
24
|
-
* ^ ^ NOT_MATCH
|
|
25
|
-
* @case3
|
|
26
|
-
* 123456 -> abcdef
|
|
27
|
-
* ^^ NOT_MATCH
|
|
28
|
-
*/
|
|
29
|
-
Mode[Mode["Totally"] = 1] = "Totally";
|
|
30
|
-
/**
|
|
31
|
-
* @case1
|
|
32
|
-
* 123456 -> abcdef
|
|
33
|
-
* ^ ^ ^ ^
|
|
34
|
-
* @case2
|
|
35
|
-
* 123456 -> abcdef
|
|
36
|
-
* ^ ^ ^ ^
|
|
37
|
-
* @case3
|
|
38
|
-
* 123456 -> abcdef
|
|
39
|
-
* ^^ ^ ^
|
|
40
|
-
*/
|
|
41
|
-
Mode[Mode["Expand"] = 2] = "Expand";
|
|
42
|
-
})(Mode = exports.Mode || (exports.Mode = {}));
|
|
43
|
-
class SourceMapBase {
|
|
44
|
-
constructor(_mappings) {
|
|
45
|
-
this.mappings = _mappings !== null && _mappings !== void 0 ? _mappings : [];
|
|
46
|
-
}
|
|
47
|
-
getSourceRange(start, end, filter) {
|
|
48
|
-
for (const maped of this.getRanges(start, end !== null && end !== void 0 ? end : start, false, filter)) {
|
|
49
|
-
return maped;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
getMappedRange(start, end, filter) {
|
|
53
|
-
for (const maped of this.getRanges(start, end !== null && end !== void 0 ? end : start, true, filter)) {
|
|
54
|
-
return maped;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
getSourceRanges(start, end, filter) {
|
|
58
|
-
return this.getRanges(start, end !== null && end !== void 0 ? end : start, false, filter);
|
|
59
|
-
}
|
|
60
|
-
getMappedRanges(start, end, filter) {
|
|
61
|
-
return this.getRanges(start, end !== null && end !== void 0 ? end : start, true, filter);
|
|
62
|
-
}
|
|
63
|
-
*getRanges(startOffset, endOffset, sourceToTarget, filter) {
|
|
64
|
-
for (const mapping of this.mappings) {
|
|
65
|
-
if (filter && !filter(mapping.data))
|
|
66
|
-
continue;
|
|
67
|
-
const maped = this.getRange(startOffset, endOffset, sourceToTarget, mapping.mode, mapping.sourceRange, mapping.mappedRange, mapping.data);
|
|
68
|
-
if (maped) {
|
|
69
|
-
yield getMaped(maped);
|
|
70
|
-
}
|
|
71
|
-
else if (mapping.additional) {
|
|
72
|
-
for (const other of mapping.additional) {
|
|
73
|
-
const maped = this.getRange(startOffset, endOffset, sourceToTarget, other.mode, other.sourceRange, other.mappedRange, mapping.data);
|
|
74
|
-
if (maped) {
|
|
75
|
-
yield getMaped(maped);
|
|
76
|
-
break; // only return first match additional range
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
function getMaped(maped) {
|
|
82
|
-
return maped;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
getRange(start, end, sourceToTarget, mode, sourceRange, targetRange, data) {
|
|
86
|
-
const mapedToRange = sourceToTarget ? targetRange : sourceRange;
|
|
87
|
-
const mapedFromRange = sourceToTarget ? sourceRange : targetRange;
|
|
88
|
-
if (mode === Mode.Totally) {
|
|
89
|
-
if (start === mapedFromRange.start && end === mapedFromRange.end) {
|
|
90
|
-
const _start = mapedToRange.start;
|
|
91
|
-
const _end = mapedToRange.end;
|
|
92
|
-
return [{
|
|
93
|
-
start: Math.min(_start, _end),
|
|
94
|
-
end: Math.max(_start, _end),
|
|
95
|
-
}, data];
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
else if (mode === Mode.Offset) {
|
|
99
|
-
if (start >= mapedFromRange.start && end <= mapedFromRange.end) {
|
|
100
|
-
const _start = mapedToRange.start + start - mapedFromRange.start;
|
|
101
|
-
const _end = mapedToRange.end + end - mapedFromRange.end;
|
|
102
|
-
return [{
|
|
103
|
-
start: Math.min(_start, _end),
|
|
104
|
-
end: Math.max(_start, _end),
|
|
105
|
-
}, data];
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
else if (mode === Mode.Expand) {
|
|
109
|
-
if (start >= mapedFromRange.start && end <= mapedFromRange.end) {
|
|
110
|
-
const _start = mapedToRange.start;
|
|
111
|
-
const _end = mapedToRange.end;
|
|
112
|
-
return [{
|
|
113
|
-
start: Math.min(_start, _end),
|
|
114
|
-
end: Math.max(_start, _end),
|
|
115
|
-
}, data];
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
exports.SourceMapBase = SourceMapBase;
|
|
121
|
-
class SourceMap extends SourceMapBase {
|
|
122
|
-
constructor(sourceDocument, mappedDocument, _mappings) {
|
|
123
|
-
super(_mappings);
|
|
124
|
-
this.sourceDocument = sourceDocument;
|
|
125
|
-
this.mappedDocument = mappedDocument;
|
|
126
|
-
this._mappings = _mappings;
|
|
127
|
-
}
|
|
128
|
-
getSourceRange(start, end, filter) {
|
|
129
|
-
for (const maped of this.getRanges(start, end !== null && end !== void 0 ? end : start, false, filter)) {
|
|
130
|
-
return maped;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
getMappedRange(start, end, filter) {
|
|
134
|
-
for (const maped of this.getRanges(start, end !== null && end !== void 0 ? end : start, true, filter)) {
|
|
135
|
-
return maped;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
getSourceRanges(start, end, filter) {
|
|
139
|
-
return this.getRanges(start, end !== null && end !== void 0 ? end : start, false, filter);
|
|
140
|
-
}
|
|
141
|
-
getMappedRanges(start, end, filter) {
|
|
142
|
-
return this.getRanges(start, end !== null && end !== void 0 ? end : start, true, filter);
|
|
143
|
-
}
|
|
144
|
-
*getRanges(start, end, sourceToTarget, filter) {
|
|
145
|
-
const startIsNumber = typeof start === 'number';
|
|
146
|
-
const endIsNumber = typeof end === 'number';
|
|
147
|
-
const toDoc = sourceToTarget ? this.mappedDocument : this.sourceDocument;
|
|
148
|
-
const fromDoc = sourceToTarget ? this.sourceDocument : this.mappedDocument;
|
|
149
|
-
const startOffset = startIsNumber ? start : fromDoc.offsetAt(start);
|
|
150
|
-
const endOffset = endIsNumber ? end : fromDoc.offsetAt(end);
|
|
151
|
-
for (const maped of super.getRanges(startOffset, endOffset, sourceToTarget, filter)) {
|
|
152
|
-
yield getMaped(maped);
|
|
153
|
-
}
|
|
154
|
-
function getMaped(maped) {
|
|
155
|
-
if (startIsNumber) {
|
|
156
|
-
return maped;
|
|
157
|
-
}
|
|
158
|
-
return [{
|
|
159
|
-
start: toDoc.positionAt(maped[0].start),
|
|
160
|
-
end: toDoc.positionAt(maped[0].end),
|
|
161
|
-
}, maped[1]];
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
exports.SourceMap = SourceMap;
|
|
166
|
-
//# sourceMappingURL=index.js.map
|