@vizejs/native 0.575.0 → 0.577.0
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/index.d.ts +18 -4
- package/index.js +1 -0
- package/language-projection.d.ts +67 -0
- package/language-projection.js +201 -0
- package/package.json +11 -9
package/index.d.ts
CHANGED
|
@@ -1520,11 +1520,25 @@ export declare function transformViteCssVarsForPipeline(
|
|
|
1520
1520
|
productionFilename?: string | undefined | null,
|
|
1521
1521
|
): string;
|
|
1522
1522
|
|
|
1523
|
+
/** Explicit options for the shared Canon language projection. */
|
|
1524
|
+
export interface VueLanguageCodeOptions {
|
|
1525
|
+
filename: string;
|
|
1526
|
+
/** Explicit host-selected tsconfig; omitted performs no config file reads. */
|
|
1527
|
+
configFileName?: string;
|
|
1528
|
+
optionsApi?: boolean;
|
|
1529
|
+
checkJavaScript?: boolean;
|
|
1530
|
+
preserveUnusedDiagnostics?: boolean;
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
/** Canon's existing Content Mapper protocol JSON, with UTF-8 offsets. */
|
|
1534
|
+
export declare function generateVueLanguageCode(
|
|
1535
|
+
source: string,
|
|
1536
|
+
options: VueLanguageCodeOptions,
|
|
1537
|
+
): string;
|
|
1538
|
+
|
|
1523
1539
|
/**
|
|
1524
|
-
* Perform type checking on a Vue SFC
|
|
1525
|
-
*
|
|
1526
|
-
* This performs AST-based type analysis without requiring a TypeScript compiler.
|
|
1527
|
-
* For full type checking, use the CLI with Corsa integration.
|
|
1540
|
+
* Perform type checking on a Vue SFC.
|
|
1541
|
+
* This performs AST-based analysis. For full checking, use the CLI with Corsa.
|
|
1528
1542
|
*/
|
|
1529
1543
|
export declare function typeCheck(
|
|
1530
1544
|
source: string,
|
package/index.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
const nativeBinding = require("./native-binding");
|
|
6
6
|
|
|
7
7
|
module.exports = nativeBinding;
|
|
8
|
+
module.exports.generateVueLanguageCode = nativeBinding.generateVueLanguageCode;
|
|
8
9
|
module.exports.PluginDocumentHandle = nativeBinding.PluginDocumentHandle;
|
|
9
10
|
module.exports.applyOutputPlugins = nativeBinding.applyOutputPlugins;
|
|
10
11
|
module.exports.applyViteDefineReplacements = nativeBinding.applyViteDefineReplacements;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export interface LanguageProjection {
|
|
2
|
+
text: string;
|
|
3
|
+
extension: ".tsx";
|
|
4
|
+
/** Both coordinate spaces are UTF-16 after conversion. */
|
|
5
|
+
mappings: Array<[number, number, number, number, 0 | 1 | 2, number]>;
|
|
6
|
+
diagnostics: ProjectionDiagnostic[];
|
|
7
|
+
semanticLinks: Array<{
|
|
8
|
+
sourceStart: number;
|
|
9
|
+
sourceLength: number;
|
|
10
|
+
targetStart: number;
|
|
11
|
+
targetLength: number;
|
|
12
|
+
kind: string;
|
|
13
|
+
}>;
|
|
14
|
+
diagnosticDirectives?: {
|
|
15
|
+
directives: Array<[number, number, number, number, 0 | 1, number]>;
|
|
16
|
+
unusedExpectDirectiveDiagnostics: Array<{ code: number; messageText: string }>;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export interface ProjectionDiagnostic {
|
|
20
|
+
start: number;
|
|
21
|
+
length: number;
|
|
22
|
+
code: number;
|
|
23
|
+
messageText: string;
|
|
24
|
+
}
|
|
25
|
+
export declare const LanguageFeature: Readonly<
|
|
26
|
+
Record<
|
|
27
|
+
| "Hover"
|
|
28
|
+
| "SignatureHelp"
|
|
29
|
+
| "Completion"
|
|
30
|
+
| "Definition"
|
|
31
|
+
| "TypeDefinition"
|
|
32
|
+
| "Implementation"
|
|
33
|
+
| "References"
|
|
34
|
+
| "DocumentHighlights"
|
|
35
|
+
| "Rename"
|
|
36
|
+
| "CallHierarchy"
|
|
37
|
+
| "CodeActions"
|
|
38
|
+
| "Formatting"
|
|
39
|
+
| "InlayHints"
|
|
40
|
+
| "SemanticTokens"
|
|
41
|
+
| "FoldingRanges"
|
|
42
|
+
| "SelectionRanges"
|
|
43
|
+
| "LinkedEditing"
|
|
44
|
+
| "AutoInsert"
|
|
45
|
+
| "DocumentSymbols"
|
|
46
|
+
| "CodeLens",
|
|
47
|
+
number
|
|
48
|
+
>
|
|
49
|
+
>;
|
|
50
|
+
export declare function toUtf16LanguageProjection(
|
|
51
|
+
source: string,
|
|
52
|
+
rawTransformJSON: string,
|
|
53
|
+
): LanguageProjection;
|
|
54
|
+
export declare function applyDiagnosticDirectives<T extends { start?: number }>(
|
|
55
|
+
projection: LanguageProjection,
|
|
56
|
+
generatedDiagnostics: readonly T[],
|
|
57
|
+
): { diagnostics: T[]; sourceDiagnostics: ProjectionDiagnostic[] };
|
|
58
|
+
/** Diagnostic-only gap semantics from the native Content Mapper protocol. */
|
|
59
|
+
export declare function mapLanguageDiagnosticRange(
|
|
60
|
+
projection: LanguageProjection,
|
|
61
|
+
start: number,
|
|
62
|
+
length: number,
|
|
63
|
+
): {
|
|
64
|
+
start: number;
|
|
65
|
+
length: number;
|
|
66
|
+
fidelity: "exact" | "atom" | "approximate" | "none";
|
|
67
|
+
};
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// These are the existing native Content Mapper protocol bits, not Canon's
|
|
4
|
+
// different internal ProjectionFeatures bits. Keep the protocol tuple intact.
|
|
5
|
+
const LanguageFeature = Object.freeze({
|
|
6
|
+
Hover: 1 << 0,
|
|
7
|
+
SignatureHelp: 1 << 1,
|
|
8
|
+
Completion: 1 << 2,
|
|
9
|
+
Definition: 1 << 3,
|
|
10
|
+
TypeDefinition: 1 << 4,
|
|
11
|
+
Implementation: 1 << 5,
|
|
12
|
+
References: 1 << 6,
|
|
13
|
+
DocumentHighlights: 1 << 7,
|
|
14
|
+
Rename: 1 << 8,
|
|
15
|
+
CallHierarchy: 1 << 9,
|
|
16
|
+
CodeActions: 1 << 10,
|
|
17
|
+
Formatting: 1 << 11,
|
|
18
|
+
InlayHints: 1 << 12,
|
|
19
|
+
SemanticTokens: 1 << 13,
|
|
20
|
+
FoldingRanges: 1 << 14,
|
|
21
|
+
SelectionRanges: 1 << 15,
|
|
22
|
+
LinkedEditing: 1 << 16,
|
|
23
|
+
AutoInsert: 1 << 17,
|
|
24
|
+
DocumentSymbols: 1 << 18,
|
|
25
|
+
CodeLens: 1 << 19,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
function utf8Boundaries(text) {
|
|
29
|
+
if (Buffer.byteLength(text, "utf8") === text.length) {
|
|
30
|
+
return (offset) => {
|
|
31
|
+
if (!Number.isSafeInteger(offset) || offset < 0 || offset > text.length) {
|
|
32
|
+
throw new RangeError(`Native projection offset ${offset} is not a UTF-8 boundary`);
|
|
33
|
+
}
|
|
34
|
+
return offset;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const boundaries = new Map([[0, 0]]);
|
|
38
|
+
let bytes = 0;
|
|
39
|
+
let units = 0;
|
|
40
|
+
for (const scalar of text) {
|
|
41
|
+
bytes += Buffer.byteLength(scalar, "utf8");
|
|
42
|
+
units += scalar.length;
|
|
43
|
+
boundaries.set(bytes, units);
|
|
44
|
+
}
|
|
45
|
+
return (offset) => {
|
|
46
|
+
if (!Number.isSafeInteger(offset) || !boundaries.has(offset)) {
|
|
47
|
+
throw new RangeError(`Native projection offset ${offset} is not a UTF-8 boundary`);
|
|
48
|
+
}
|
|
49
|
+
return boundaries.get(offset);
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Convert both sides of a native projection; never reinterpret UTF-8 as UTF-16. */
|
|
54
|
+
function toUtf16LanguageProjection(source, rawTransformJSON) {
|
|
55
|
+
const raw = JSON.parse(rawTransformJSON);
|
|
56
|
+
if (typeof raw.text !== "string" || raw.extension !== ".tsx" || !Array.isArray(raw.mappings)) {
|
|
57
|
+
throw new TypeError("Invalid native language projection");
|
|
58
|
+
}
|
|
59
|
+
const original = utf8Boundaries(source);
|
|
60
|
+
const generated = utf8Boundaries(raw.text);
|
|
61
|
+
const range = (convert, start, length) => {
|
|
62
|
+
if (!Number.isSafeInteger(length) || length < 0)
|
|
63
|
+
throw new RangeError("Invalid projection length");
|
|
64
|
+
return [convert(start), convert(start + length) - convert(start)];
|
|
65
|
+
};
|
|
66
|
+
const mappings = raw.mappings.map((tuple) => {
|
|
67
|
+
if (!Array.isArray(tuple) || tuple.length !== 6) throw new TypeError("Invalid projection span");
|
|
68
|
+
const [start, length, sourceStart, sourceLength, kind, features] = tuple;
|
|
69
|
+
if (
|
|
70
|
+
![0, 1, 2].includes(kind) ||
|
|
71
|
+
!Number.isInteger(features) ||
|
|
72
|
+
features < 0 ||
|
|
73
|
+
features > 0xfffff
|
|
74
|
+
) {
|
|
75
|
+
throw new TypeError("Invalid projection span metadata");
|
|
76
|
+
}
|
|
77
|
+
return [
|
|
78
|
+
...range(generated, start, length),
|
|
79
|
+
...range(original, sourceStart, sourceLength),
|
|
80
|
+
kind,
|
|
81
|
+
features,
|
|
82
|
+
];
|
|
83
|
+
});
|
|
84
|
+
const diagnostics = raw.diagnostics.map((diagnostic) => {
|
|
85
|
+
const [start, length] = range(original, diagnostic.start, diagnostic.length);
|
|
86
|
+
return { ...diagnostic, start, length };
|
|
87
|
+
});
|
|
88
|
+
const semanticLinks = (raw.semanticLinks ?? []).map((link) => {
|
|
89
|
+
const [sourceStart, sourceLength] = range(generated, link.sourceStart, link.sourceLength);
|
|
90
|
+
const [targetStart, targetLength] = range(generated, link.targetStart, link.targetLength);
|
|
91
|
+
return { ...link, sourceStart, sourceLength, targetStart, targetLength };
|
|
92
|
+
});
|
|
93
|
+
const diagnosticDirectives = raw.diagnosticDirectives && {
|
|
94
|
+
...raw.diagnosticDirectives,
|
|
95
|
+
directives: raw.diagnosticDirectives.directives.map((tuple) => {
|
|
96
|
+
if (!Array.isArray(tuple) || tuple.length !== 6)
|
|
97
|
+
throw new TypeError("Invalid diagnostic directive");
|
|
98
|
+
const [start, length, virtualStart, virtualEnd, policy, index] = tuple;
|
|
99
|
+
if (![0, 1].includes(policy)) throw new TypeError("Invalid diagnostic directive policy");
|
|
100
|
+
return [
|
|
101
|
+
...range(original, start, length),
|
|
102
|
+
generated(virtualStart),
|
|
103
|
+
generated(virtualEnd),
|
|
104
|
+
policy,
|
|
105
|
+
index,
|
|
106
|
+
];
|
|
107
|
+
}),
|
|
108
|
+
};
|
|
109
|
+
return { ...raw, mappings, diagnostics, semanticLinks, diagnosticDirectives };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Apply native suppression/owner-copy intervals to one complete diagnostic collection. */
|
|
113
|
+
function applyDiagnosticDirectives(projection, generatedDiagnostics) {
|
|
114
|
+
const directives = projection.diagnosticDirectives?.directives ?? [];
|
|
115
|
+
const used = new Set();
|
|
116
|
+
const diagnostics = generatedDiagnostics.filter((diagnostic) => {
|
|
117
|
+
if (diagnostic.start === undefined) return true;
|
|
118
|
+
let suppressed = false;
|
|
119
|
+
for (let index = 0; index < directives.length; index++) {
|
|
120
|
+
const [, , start, end, policy] = directives[index];
|
|
121
|
+
if (start <= diagnostic.start && diagnostic.start < end) {
|
|
122
|
+
suppressed = true;
|
|
123
|
+
if (policy === 1) used.add(index);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return !suppressed;
|
|
127
|
+
});
|
|
128
|
+
const sourceDiagnostics = [...projection.diagnostics];
|
|
129
|
+
directives.forEach(([start, length, , , policy, tableIndex], index) => {
|
|
130
|
+
if (policy !== 1 || used.has(index)) return;
|
|
131
|
+
const diagnostic = projection.diagnosticDirectives.unusedExpectDirectiveDiagnostics[tableIndex];
|
|
132
|
+
if (!diagnostic) throw new TypeError("Missing unused expectation diagnostic");
|
|
133
|
+
sourceDiagnostics.push({ ...diagnostic, start, length });
|
|
134
|
+
});
|
|
135
|
+
return { diagnostics, sourceDiagnostics };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Content Mapper VirtualToOriginalSpan law in the normalized UTF-16 spaces.
|
|
140
|
+
* Diagnostic boundaries may surround mapped tokens with synthetic punctuation.
|
|
141
|
+
* This does not make those gaps eligible for navigation or edit write-back.
|
|
142
|
+
* Matches Canon's content_mapper/tests/diagnostic_origin.rs and upstream
|
|
143
|
+
* microsoft/TypeScript@d6c4afdd tsc/internal/spanmap/spanmap.go.
|
|
144
|
+
*/
|
|
145
|
+
function mapLanguageDiagnosticRange(projection, start, length) {
|
|
146
|
+
if (!Number.isSafeInteger(start) || start < 0 || !Number.isSafeInteger(length) || length < 0)
|
|
147
|
+
throw new RangeError("Invalid generated diagnostic range");
|
|
148
|
+
const rows = projection.mappings;
|
|
149
|
+
const at = (position) => {
|
|
150
|
+
let low = 0;
|
|
151
|
+
let high = rows.length;
|
|
152
|
+
while (low < high) {
|
|
153
|
+
const middle = (low + high) >>> 1;
|
|
154
|
+
if (rows[middle][0] <= position) low = middle + 1;
|
|
155
|
+
else high = middle;
|
|
156
|
+
}
|
|
157
|
+
const index = low - 1;
|
|
158
|
+
const row = rows[index];
|
|
159
|
+
const inside =
|
|
160
|
+
!!row &&
|
|
161
|
+
(position < row[0] + row[1] || (index === rows.length - 1 && position === row[0] + row[1]));
|
|
162
|
+
return { index, inside };
|
|
163
|
+
};
|
|
164
|
+
const boundary = (position, segment, high) => {
|
|
165
|
+
const row = rows[segment.index];
|
|
166
|
+
if (!segment.inside) return row ? row[2] + row[3] : 0;
|
|
167
|
+
if (row[4] !== 0) return row[2] + (high ? row[3] : 0);
|
|
168
|
+
return Math.min(row[2] + row[3], Math.max(row[2], row[2] + position - row[0]));
|
|
169
|
+
};
|
|
170
|
+
const first = at(start);
|
|
171
|
+
if (length === 0)
|
|
172
|
+
return {
|
|
173
|
+
start: boundary(start, first, false),
|
|
174
|
+
length: 0,
|
|
175
|
+
fidelity: !first.inside ? "none" : rows[first.index][4] === 0 ? "exact" : "atom",
|
|
176
|
+
};
|
|
177
|
+
const end = start + length;
|
|
178
|
+
const last = at(end - 1);
|
|
179
|
+
if (first.index === last.index && first.inside === last.inside) {
|
|
180
|
+
const originalStart = boundary(start, first, false);
|
|
181
|
+
if (!first.inside) return { start: originalStart, length: 0, fidelity: "none" };
|
|
182
|
+
return {
|
|
183
|
+
start: originalStart,
|
|
184
|
+
length: boundary(end, last, true) - originalStart,
|
|
185
|
+
fidelity: rows[first.index][4] === 0 ? "exact" : "atom",
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
const originalStart = boundary(start, first, false);
|
|
189
|
+
return {
|
|
190
|
+
start: originalStart,
|
|
191
|
+
length: Math.max(originalStart, boundary(end, last, true)) - originalStart,
|
|
192
|
+
fidelity: "approximate",
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
module.exports = {
|
|
197
|
+
LanguageFeature,
|
|
198
|
+
toUtf16LanguageProjection,
|
|
199
|
+
applyDiagnosticDirectives,
|
|
200
|
+
mapLanguageDiagnosticRange,
|
|
201
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vizejs/native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.577.0",
|
|
4
4
|
"description": "High-performance Vue.js compiler - Native bindings",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"compiler",
|
|
@@ -23,6 +23,8 @@
|
|
|
23
23
|
"files": [
|
|
24
24
|
"index.js",
|
|
25
25
|
"index.d.ts",
|
|
26
|
+
"language-projection.js",
|
|
27
|
+
"language-projection.d.ts",
|
|
26
28
|
"native-binding.js",
|
|
27
29
|
"native-binding-identity.js",
|
|
28
30
|
"native-targets.js"
|
|
@@ -36,14 +38,14 @@
|
|
|
36
38
|
"@napi-rs/cli": "3.6.2"
|
|
37
39
|
},
|
|
38
40
|
"optionalDependencies": {
|
|
39
|
-
"@vizejs/native-darwin-arm64": "0.
|
|
40
|
-
"@vizejs/native-darwin-x64": "0.
|
|
41
|
-
"@vizejs/native-linux-arm64-gnu": "0.
|
|
42
|
-
"@vizejs/native-linux-arm64-musl": "0.
|
|
43
|
-
"@vizejs/native-linux-x64-gnu": "0.
|
|
44
|
-
"@vizejs/native-linux-x64-musl": "0.
|
|
45
|
-
"@vizejs/native-win32-arm64-msvc": "0.
|
|
46
|
-
"@vizejs/native-win32-x64-msvc": "0.
|
|
41
|
+
"@vizejs/native-darwin-arm64": "0.577.0",
|
|
42
|
+
"@vizejs/native-darwin-x64": "0.577.0",
|
|
43
|
+
"@vizejs/native-linux-arm64-gnu": "0.577.0",
|
|
44
|
+
"@vizejs/native-linux-arm64-musl": "0.577.0",
|
|
45
|
+
"@vizejs/native-linux-x64-gnu": "0.577.0",
|
|
46
|
+
"@vizejs/native-linux-x64-musl": "0.577.0",
|
|
47
|
+
"@vizejs/native-win32-arm64-msvc": "0.577.0",
|
|
48
|
+
"@vizejs/native-win32-x64-msvc": "0.577.0"
|
|
47
49
|
},
|
|
48
50
|
"napi": {
|
|
49
51
|
"binaryName": "vize-vitrine",
|