@wcstack/typescript 1.32.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/README.ja.md +106 -0
- package/README.md +106 -0
- package/dist/index.d.ts +177 -0
- package/dist/index.esm.js +508 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/schema-core.cjs +6795 -0
- package/dist/tsc-core.cjs +545 -0
- package/dist/wcs-schema.mjs +682 -0
- package/dist/wcs-schema.mjs.map +1 -0
- package/dist/wcs-tsc.mjs +283 -0
- package/dist/wcs-tsc.mjs.map +1 -0
- package/package.json +84 -0
|
@@ -0,0 +1,545 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/tscCore.ts
|
|
21
|
+
var tscCore_exports = {};
|
|
22
|
+
__export(tscCore_exports, {
|
|
23
|
+
WCS_PREAMBLE: () => WCS_PREAMBLE,
|
|
24
|
+
WCS_PREAMBLE_LENGTH: () => WCS_PREAMBLE_LENGTH,
|
|
25
|
+
createWcsLanguagePlugin: () => createWcsLanguagePlugin,
|
|
26
|
+
stripWcsImport: () => stripWcsImport
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(tscCore_exports);
|
|
29
|
+
|
|
30
|
+
// src/language/htmlParse.ts
|
|
31
|
+
function parseWcsScriptBlocks(html, stateTagName = "wcs-state") {
|
|
32
|
+
const blocks = [];
|
|
33
|
+
let pos = 0;
|
|
34
|
+
const len = html.length;
|
|
35
|
+
while (pos < len) {
|
|
36
|
+
if (html.startsWith("<!--", pos)) {
|
|
37
|
+
const commentEnd = html.indexOf("-->", pos + 4);
|
|
38
|
+
if (commentEnd === -1) break;
|
|
39
|
+
pos = commentEnd + 3;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const wcsMatch = matchOpenTag(html, pos, stateTagName);
|
|
43
|
+
if (wcsMatch === null) {
|
|
44
|
+
pos++;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const stateName = extractAttribute(wcsMatch.tagContent, "name") ?? "default";
|
|
48
|
+
pos = wcsMatch.end;
|
|
49
|
+
const wcsCloseIdx = findCloseTag(html, pos, stateTagName);
|
|
50
|
+
const wcsEnd = wcsCloseIdx === -1 ? len : wcsCloseIdx;
|
|
51
|
+
while (pos < wcsEnd) {
|
|
52
|
+
if (html.startsWith("<!--", pos)) {
|
|
53
|
+
const commentEnd = html.indexOf("-->", pos + 4);
|
|
54
|
+
if (commentEnd === -1) break;
|
|
55
|
+
pos = commentEnd + 3;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const scriptMatch = matchOpenTag(html, pos, "script");
|
|
59
|
+
if (scriptMatch === null) {
|
|
60
|
+
pos++;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const typeAttr = extractAttribute(scriptMatch.tagContent, "type");
|
|
64
|
+
if (typeAttr?.toLowerCase() !== "module") {
|
|
65
|
+
pos = scriptMatch.end;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const contentStart = scriptMatch.end;
|
|
69
|
+
const scriptCloseIdx = findCloseTag(html, contentStart, "script");
|
|
70
|
+
if (scriptCloseIdx === -1) {
|
|
71
|
+
pos = contentStart;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
const contentEnd = scriptCloseIdx;
|
|
75
|
+
blocks.push({
|
|
76
|
+
contentStart,
|
|
77
|
+
contentEnd,
|
|
78
|
+
content: html.slice(contentStart, contentEnd),
|
|
79
|
+
stateName
|
|
80
|
+
});
|
|
81
|
+
pos = html.indexOf(">", scriptCloseIdx) + 1;
|
|
82
|
+
if (pos === 0) break;
|
|
83
|
+
}
|
|
84
|
+
pos = wcsEnd;
|
|
85
|
+
if (wcsCloseIdx !== -1) {
|
|
86
|
+
const closeEnd = html.indexOf(">", wcsCloseIdx);
|
|
87
|
+
if (closeEnd !== -1) pos = closeEnd + 1;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return blocks;
|
|
91
|
+
}
|
|
92
|
+
function matchOpenTag(html, pos, tagName) {
|
|
93
|
+
if (html[pos] !== "<") return null;
|
|
94
|
+
const nameStart = pos + 1;
|
|
95
|
+
const nameEnd = nameStart + tagName.length;
|
|
96
|
+
if (nameEnd > html.length) return null;
|
|
97
|
+
const slice = html.slice(nameStart, nameEnd);
|
|
98
|
+
if (slice.toLowerCase() !== tagName.toLowerCase()) return null;
|
|
99
|
+
const charAfter = html[nameEnd];
|
|
100
|
+
if (charAfter !== ">" && charAfter !== " " && charAfter !== " " && charAfter !== "\n" && charAfter !== "\r" && charAfter !== "/") {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
let i = nameEnd;
|
|
104
|
+
let inSingleQuote = false;
|
|
105
|
+
let inDoubleQuote = false;
|
|
106
|
+
while (i < html.length) {
|
|
107
|
+
const ch = html[i];
|
|
108
|
+
if (inSingleQuote) {
|
|
109
|
+
if (ch === "'") inSingleQuote = false;
|
|
110
|
+
} else if (inDoubleQuote) {
|
|
111
|
+
if (ch === '"') inDoubleQuote = false;
|
|
112
|
+
} else if (ch === "'") {
|
|
113
|
+
inSingleQuote = true;
|
|
114
|
+
} else if (ch === '"') {
|
|
115
|
+
inDoubleQuote = true;
|
|
116
|
+
} else if (ch === ">") {
|
|
117
|
+
return {
|
|
118
|
+
start: pos,
|
|
119
|
+
end: i + 1,
|
|
120
|
+
tagContent: html.slice(nameEnd, i)
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
i++;
|
|
124
|
+
}
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
function findCloseTag(html, startPos, tagName) {
|
|
128
|
+
const pattern = "</" + tagName;
|
|
129
|
+
const patternLower = pattern.toLowerCase();
|
|
130
|
+
const htmlLower = html.toLowerCase();
|
|
131
|
+
let pos = startPos;
|
|
132
|
+
while (pos < html.length) {
|
|
133
|
+
const idx = htmlLower.indexOf(patternLower, pos);
|
|
134
|
+
if (idx === -1) return -1;
|
|
135
|
+
const afterIdx = idx + pattern.length;
|
|
136
|
+
if (afterIdx < html.length) {
|
|
137
|
+
const ch = html[afterIdx];
|
|
138
|
+
if (ch === ">" || ch === " " || ch === " " || ch === "\n" || ch === "\r") {
|
|
139
|
+
return idx;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
pos = idx + 1;
|
|
143
|
+
}
|
|
144
|
+
return -1;
|
|
145
|
+
}
|
|
146
|
+
function extractAttribute(tagContent, attrName) {
|
|
147
|
+
const regex = new RegExp(
|
|
148
|
+
`(?:^|\\s)${attrName}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|(\\S+))`,
|
|
149
|
+
"i"
|
|
150
|
+
);
|
|
151
|
+
const match = tagContent.match(regex);
|
|
152
|
+
if (!match) return null;
|
|
153
|
+
return match[1] ?? match[2] ?? match[3] ?? null;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// src/language/preamble.ts
|
|
157
|
+
var WCS_PREAMBLE = `
|
|
158
|
+
// --- @wcstack/state type preamble (auto-injected by vscode-wcs) ---
|
|
159
|
+
type _IsAny<T> = 0 extends (1 & T) ? true : false;
|
|
160
|
+
type _IsPlainObject<T> =
|
|
161
|
+
_IsAny<T> extends true ? false :
|
|
162
|
+
T extends
|
|
163
|
+
| string | number | boolean | null | undefined | symbol | bigint
|
|
164
|
+
| Function | Date | RegExp | Error
|
|
165
|
+
| Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any>
|
|
166
|
+
| Promise<any> | readonly any[]
|
|
167
|
+
? false
|
|
168
|
+
: T extends Record<string, any> ? true : false;
|
|
169
|
+
type _DataKeys<T> = {
|
|
170
|
+
[K in keyof T & string]:
|
|
171
|
+
K extends \`$\${string}\` ? never :
|
|
172
|
+
_IsAny<T[K]> extends true ? K : T[K] extends Function ? never : K;
|
|
173
|
+
}[keyof T & string];
|
|
174
|
+
type _WcsPaths<T, D extends readonly any[] = []> =
|
|
175
|
+
D["length"] extends 4 ? never :
|
|
176
|
+
{ [K in _DataKeys<T>]:
|
|
177
|
+
| K
|
|
178
|
+
| (T[K] extends readonly (infer E)[]
|
|
179
|
+
? _IsPlainObject<E> extends true
|
|
180
|
+
? \`\${K}.*\` | _WcsSubPaths<E, \`\${K}.*.\`, [...D, 0]>
|
|
181
|
+
: \`\${K}.*\`
|
|
182
|
+
: _IsPlainObject<T[K]> extends true
|
|
183
|
+
? _WcsSubPaths<T[K], \`\${K}.\`, [...D, 0]>
|
|
184
|
+
: never)
|
|
185
|
+
}[_DataKeys<T>];
|
|
186
|
+
type _WcsSubPaths<T, P extends string, D extends readonly any[]> =
|
|
187
|
+
_WcsPaths<T, D> extends infer R extends string ? \`\${P}\${R}\` : never;
|
|
188
|
+
type _WcsPathValue<T, P extends string> =
|
|
189
|
+
P extends keyof T ? T[P]
|
|
190
|
+
: P extends \`\${infer K}.*\`
|
|
191
|
+
? K extends keyof T ? T[K] extends readonly (infer E)[] ? E : never : never
|
|
192
|
+
: P extends \`\${infer K}.\${infer R}\`
|
|
193
|
+
? K extends keyof T
|
|
194
|
+
? T[K] extends readonly (infer E)[]
|
|
195
|
+
? R extends \`*.\${infer S}\` ? _WcsPathValue<E, S> : R extends "*" ? E : never
|
|
196
|
+
: T[K] extends Record<string, any> ? _WcsPathValue<T[K], R> : never
|
|
197
|
+
: never
|
|
198
|
+
: never;
|
|
199
|
+
type _WcsPathAccessor<T> = { [P in _WcsPaths<T>]: _WcsPathValue<T, P> };
|
|
200
|
+
type _WcsStreamStatus = "idle" | "active" | "done" | "error";
|
|
201
|
+
interface WcsStateApi {
|
|
202
|
+
$getAll<V = any>(path: string, indexes?: number[]): V[];
|
|
203
|
+
$setAll<V = any>(path: string, indexes: number[], value: V | ((current: V, ...indexes: number[]) => V | undefined)): number;
|
|
204
|
+
$setAll<V = any>(path: string, indexes: number[], values: readonly V[], options: { spread: true }): number;
|
|
205
|
+
$postUpdate(path: string): void;
|
|
206
|
+
$resolve(path: string, indexes: number[], value?: any): any;
|
|
207
|
+
$trackDependency(path: string): void;
|
|
208
|
+
$untrackDependency<T>(fn: () => T): T;
|
|
209
|
+
readonly $stateElement: HTMLElement;
|
|
210
|
+
readonly $command: Record<string, { emit(...args: any[]): any }>;
|
|
211
|
+
readonly $streamStatus: Record<string, _WcsStreamStatus>;
|
|
212
|
+
readonly $streamError: Record<string, unknown>;
|
|
213
|
+
readonly [key: \`$streamStatus.\${string}\`]: _WcsStreamStatus;
|
|
214
|
+
readonly [key: \`$streamError.\${string}\`]: unknown;
|
|
215
|
+
readonly $1: number; readonly $2: number; readonly $3: number;
|
|
216
|
+
readonly $4: number; readonly $5: number; readonly $6: number;
|
|
217
|
+
readonly $7: number; readonly $8: number; readonly $9: number;
|
|
218
|
+
}
|
|
219
|
+
type _WcsThis<T> = T & WcsStateApi & _WcsPathAccessor<T>;
|
|
220
|
+
// $listKeys: { "<listPath>": "<field>" | (row) => key }\uFF08list/listKeys.ts\uFF09\u3002
|
|
221
|
+
// \u30AD\u30FC\u6307\u5B9A\u306E\u95A2\u6570\u5F15\u6570\u306B\u6587\u8108\u578B\u3092\u4E0E\u3048\u308B\u305F\u3081\u3060\u3051\u306E\u5BA3\u8A00\uFF08noImplicitAny \u4E0B\u306E\u507D\u30A8\u30E9\u30FC\u56DE\u907F\uFF09\u3002
|
|
222
|
+
type _WcsListKeys = Record<string, string | ((row: any) => unknown)>;
|
|
223
|
+
// $watch: { "<path>": (cur, prev, ...indexes) => void }\uFF08watch/processWatchDeclaration.ts\uFF09\u3002
|
|
224
|
+
// \u30CF\u30F3\u30C9\u30E9\u5F15\u6570\u306B\u6587\u8108\u578B\u3092\u4E0E\u3048\u308B\u305F\u3081\u3060\u3051\u306E\u5BA3\u8A00\uFF08$listKeys \u3068\u540C\u3058\u7406\u7531\uFF09\u3002
|
|
225
|
+
// this \u306F ThisType<_WcsThis<T>> \u306B\u3088\u308A state \u578B\u306B\u306A\u308B\u3002
|
|
226
|
+
type _WcsWatch = Record<string, (cur: any, prev: any, ...indexes: number[]) => void>;
|
|
227
|
+
function defineState<T extends Record<string, any>>(
|
|
228
|
+
def: T & { $listKeys?: _WcsListKeys; $watch?: _WcsWatch } & ThisType<_WcsThis<T>>
|
|
229
|
+
): T { return def; }
|
|
230
|
+
// --- end preamble ---
|
|
231
|
+
`;
|
|
232
|
+
var WCS_PREAMBLE_LENGTH = WCS_PREAMBLE.length;
|
|
233
|
+
|
|
234
|
+
// src/language/plugin.ts
|
|
235
|
+
var fullFeatures = {
|
|
236
|
+
verification: true,
|
|
237
|
+
completion: true,
|
|
238
|
+
semantic: true,
|
|
239
|
+
navigation: true,
|
|
240
|
+
structure: true,
|
|
241
|
+
format: true
|
|
242
|
+
};
|
|
243
|
+
function pathOfScriptId(id) {
|
|
244
|
+
return typeof id === "string" ? id : id.path;
|
|
245
|
+
}
|
|
246
|
+
function createWcsLanguagePlugin(stateTagName = "wcs-state", options = {}) {
|
|
247
|
+
const tscMode = options.mode === "tsc";
|
|
248
|
+
const build = (html) => {
|
|
249
|
+
const blocks = parseWcsScriptBlocks(html, stateTagName);
|
|
250
|
+
if (blocks.length === 0) return tscMode ? createWcsHtmlVirtualCodeForTsc([], html) : void 0;
|
|
251
|
+
return tscMode ? createWcsHtmlVirtualCodeForTsc(blocks, html) : createWcsHtmlVirtualCode(blocks, html);
|
|
252
|
+
};
|
|
253
|
+
return {
|
|
254
|
+
getLanguageId(id) {
|
|
255
|
+
const path = pathOfScriptId(id);
|
|
256
|
+
if (path.endsWith(".html") || path.endsWith(".htm")) {
|
|
257
|
+
return "html";
|
|
258
|
+
}
|
|
259
|
+
return void 0;
|
|
260
|
+
},
|
|
261
|
+
createVirtualCode(_id, languageId, snapshot, _ctx) {
|
|
262
|
+
if (languageId !== "html") return void 0;
|
|
263
|
+
return build(snapshot.getText(0, snapshot.getLength()));
|
|
264
|
+
},
|
|
265
|
+
updateVirtualCode(_id, _virtualCode, newSnapshot, _ctx) {
|
|
266
|
+
return build(newSnapshot.getText(0, newSnapshot.getLength()));
|
|
267
|
+
},
|
|
268
|
+
typescript: tscMode ? {
|
|
269
|
+
extraFileExtensions: [
|
|
270
|
+
{
|
|
271
|
+
extension: "html",
|
|
272
|
+
isMixedContent: true,
|
|
273
|
+
scriptKind: 7
|
|
274
|
+
/* ts.ScriptKind.Deferred */
|
|
275
|
+
}
|
|
276
|
+
],
|
|
277
|
+
// tsc: 合成スクリプト 1 本をこのファイルのサービススクリプトにする。
|
|
278
|
+
// getExtraServiceScripts は**定義しない** — proxyCreateProgram は存在するだけで
|
|
279
|
+
// 「not available in this use case」を出力する。
|
|
280
|
+
getServiceScript(root) {
|
|
281
|
+
const combined = root.embeddedCodes?.find((code) => code.id === COMBINED_SCRIPT_ID);
|
|
282
|
+
if (combined === void 0) return void 0;
|
|
283
|
+
return {
|
|
284
|
+
code: combined,
|
|
285
|
+
extension: ".ts",
|
|
286
|
+
scriptKind: 3
|
|
287
|
+
/* ts.ScriptKind.TS */
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
} : {
|
|
291
|
+
extraFileExtensions: [
|
|
292
|
+
{
|
|
293
|
+
extension: "html",
|
|
294
|
+
isMixedContent: true,
|
|
295
|
+
scriptKind: 7
|
|
296
|
+
/* ts.ScriptKind.Deferred */
|
|
297
|
+
}
|
|
298
|
+
],
|
|
299
|
+
getServiceScript(_root) {
|
|
300
|
+
return void 0;
|
|
301
|
+
},
|
|
302
|
+
getExtraServiceScripts(fileName, root) {
|
|
303
|
+
const scripts = [];
|
|
304
|
+
for (const embedded of root.embeddedCodes ?? []) {
|
|
305
|
+
if (embedded.id.startsWith("wcs-script-")) {
|
|
306
|
+
scripts.push({
|
|
307
|
+
fileName: fileName + ".__" + embedded.id + ".ts",
|
|
308
|
+
code: embedded,
|
|
309
|
+
extension: ".ts",
|
|
310
|
+
scriptKind: 3
|
|
311
|
+
// ts.ScriptKind.TS
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return scripts;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
var COMBINED_SCRIPT_ID = "wcs-combined";
|
|
321
|
+
function createWcsHtmlVirtualCodeForTsc(blocks, html) {
|
|
322
|
+
const { code, mappings } = blocks.length === 0 ? { code: "", mappings: [] } : buildCombinedScript(blocks);
|
|
323
|
+
const combined = {
|
|
324
|
+
id: COMBINED_SCRIPT_ID,
|
|
325
|
+
languageId: "typescript",
|
|
326
|
+
snapshot: {
|
|
327
|
+
getText(start, end) {
|
|
328
|
+
return code.slice(start, end);
|
|
329
|
+
},
|
|
330
|
+
getLength() {
|
|
331
|
+
return code.length;
|
|
332
|
+
},
|
|
333
|
+
getChangeRange() {
|
|
334
|
+
return void 0;
|
|
335
|
+
}
|
|
336
|
+
},
|
|
337
|
+
mappings
|
|
338
|
+
};
|
|
339
|
+
return {
|
|
340
|
+
id: "root",
|
|
341
|
+
languageId: "html",
|
|
342
|
+
snapshot: {
|
|
343
|
+
getText(start, end) {
|
|
344
|
+
return html.slice(start, end);
|
|
345
|
+
},
|
|
346
|
+
getLength() {
|
|
347
|
+
return html.length;
|
|
348
|
+
},
|
|
349
|
+
getChangeRange() {
|
|
350
|
+
return void 0;
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
mappings: [{
|
|
354
|
+
sourceOffsets: [0],
|
|
355
|
+
generatedOffsets: [0],
|
|
356
|
+
lengths: [html.length],
|
|
357
|
+
data: htmlFeatures
|
|
358
|
+
}],
|
|
359
|
+
embeddedCodes: [combined]
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
var IMPORT_STATEMENT_RE = /import\s+(?:[\s\S]*?\sfrom\s*)?['"][^'"]+['"]\s*;?/g;
|
|
363
|
+
function buildCombinedScript(blocks) {
|
|
364
|
+
let code = WCS_PREAMBLE;
|
|
365
|
+
const mappings = [];
|
|
366
|
+
const map = (sourceOffset, generatedOffset, length) => {
|
|
367
|
+
if (length <= 0) return;
|
|
368
|
+
mappings.push({ sourceOffsets: [sourceOffset], generatedOffsets: [generatedOffset], lengths: [length], data: fullFeatures });
|
|
369
|
+
};
|
|
370
|
+
const bodies = blocks.map((block) => {
|
|
371
|
+
const stripped = stripWcsImport(block.content);
|
|
372
|
+
const userCode = stripped.replace(IMPORT_STATEMENT_RE, (match, offset) => {
|
|
373
|
+
map(block.contentStart + offset, code.length, match.length);
|
|
374
|
+
code += match + "\n";
|
|
375
|
+
return " ".repeat(match.length);
|
|
376
|
+
});
|
|
377
|
+
return { block, userCode };
|
|
378
|
+
});
|
|
379
|
+
bodies.forEach(({ block, userCode }, index) => {
|
|
380
|
+
code += "{\n";
|
|
381
|
+
const decl = `const __wcs_state_${index} = `;
|
|
382
|
+
const exportMatch = /export\s+default\s+/.exec(userCode);
|
|
383
|
+
if (exportMatch === null) {
|
|
384
|
+
map(block.contentStart, code.length, userCode.length);
|
|
385
|
+
code += userCode;
|
|
386
|
+
} else {
|
|
387
|
+
const before = userCode.slice(0, exportMatch.index);
|
|
388
|
+
const afterExport = userCode.slice(exportMatch.index + exportMatch[0].length);
|
|
389
|
+
const afterExportSource = block.contentStart + exportMatch.index + exportMatch[0].length;
|
|
390
|
+
map(block.contentStart, code.length, before.length);
|
|
391
|
+
code += before + decl;
|
|
392
|
+
if (/\bdefineState\s*\(/.test(userCode)) {
|
|
393
|
+
map(afterExportSource, code.length, afterExport.length);
|
|
394
|
+
code += afterExport;
|
|
395
|
+
} else {
|
|
396
|
+
const trailingMatch = afterExport.match(/(\s*;?\s*)$/);
|
|
397
|
+
const trailing = trailingMatch ? trailingMatch[0] : "";
|
|
398
|
+
const objectPart = afterExport.slice(0, afterExport.length - trailing.length);
|
|
399
|
+
code += "defineState(";
|
|
400
|
+
map(afterExportSource, code.length, objectPart.length);
|
|
401
|
+
code += objectPart + ")";
|
|
402
|
+
map(afterExportSource + objectPart.length, code.length, trailing.length);
|
|
403
|
+
code += trailing;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
code += `
|
|
407
|
+
void __wcs_state_${index};
|
|
408
|
+
}
|
|
409
|
+
`;
|
|
410
|
+
});
|
|
411
|
+
return { code, mappings };
|
|
412
|
+
}
|
|
413
|
+
var htmlFeatures = {
|
|
414
|
+
verification: true,
|
|
415
|
+
completion: true,
|
|
416
|
+
semantic: true,
|
|
417
|
+
navigation: true,
|
|
418
|
+
structure: false,
|
|
419
|
+
format: false
|
|
420
|
+
};
|
|
421
|
+
function createWcsHtmlVirtualCode(blocks, html) {
|
|
422
|
+
const embeddedCodes = blocks.map(
|
|
423
|
+
(block, index) => createScriptVirtualCode(block, index)
|
|
424
|
+
);
|
|
425
|
+
return {
|
|
426
|
+
id: "root",
|
|
427
|
+
languageId: "html",
|
|
428
|
+
snapshot: {
|
|
429
|
+
getText(start, end) {
|
|
430
|
+
return html.slice(start, end);
|
|
431
|
+
},
|
|
432
|
+
getLength() {
|
|
433
|
+
return html.length;
|
|
434
|
+
},
|
|
435
|
+
getChangeRange() {
|
|
436
|
+
return void 0;
|
|
437
|
+
}
|
|
438
|
+
},
|
|
439
|
+
mappings: [{
|
|
440
|
+
sourceOffsets: [0],
|
|
441
|
+
generatedOffsets: [0],
|
|
442
|
+
lengths: [html.length],
|
|
443
|
+
data: htmlFeatures
|
|
444
|
+
}],
|
|
445
|
+
embeddedCodes
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
function createScriptVirtualCode(block, index) {
|
|
449
|
+
const userCode = stripWcsImport(block.content);
|
|
450
|
+
const { code: wrappedCode, mappings } = wrapWithDefineState(userCode, block);
|
|
451
|
+
return {
|
|
452
|
+
id: `wcs-script-${index}`,
|
|
453
|
+
languageId: "typescript",
|
|
454
|
+
snapshot: {
|
|
455
|
+
getText(start, end) {
|
|
456
|
+
return wrappedCode.slice(start, end);
|
|
457
|
+
},
|
|
458
|
+
getLength() {
|
|
459
|
+
return wrappedCode.length;
|
|
460
|
+
},
|
|
461
|
+
getChangeRange() {
|
|
462
|
+
return void 0;
|
|
463
|
+
}
|
|
464
|
+
},
|
|
465
|
+
mappings
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
function wrapWithDefineState(userCode, block) {
|
|
469
|
+
const alreadyWrapped = /\bdefineState\s*\(/.test(userCode);
|
|
470
|
+
if (alreadyWrapped) {
|
|
471
|
+
const code2 = WCS_PREAMBLE + userCode;
|
|
472
|
+
return {
|
|
473
|
+
code: code2,
|
|
474
|
+
mappings: [{
|
|
475
|
+
sourceOffsets: [block.contentStart],
|
|
476
|
+
generatedOffsets: [WCS_PREAMBLE_LENGTH],
|
|
477
|
+
lengths: [block.content.length],
|
|
478
|
+
data: fullFeatures
|
|
479
|
+
}]
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
const exportDefaultRe = /export\s+default\s+/;
|
|
483
|
+
const match = exportDefaultRe.exec(userCode);
|
|
484
|
+
if (!match) {
|
|
485
|
+
const code2 = WCS_PREAMBLE + userCode;
|
|
486
|
+
return {
|
|
487
|
+
code: code2,
|
|
488
|
+
mappings: [{
|
|
489
|
+
sourceOffsets: [block.contentStart],
|
|
490
|
+
generatedOffsets: [WCS_PREAMBLE_LENGTH],
|
|
491
|
+
lengths: [block.content.length],
|
|
492
|
+
data: fullFeatures
|
|
493
|
+
}]
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
const exportEnd = match.index + match[0].length;
|
|
497
|
+
const before = userCode.slice(0, exportEnd);
|
|
498
|
+
const after = userCode.slice(exportEnd);
|
|
499
|
+
const trailingMatch = after.match(/(\s*;?\s*)$/);
|
|
500
|
+
const objectPart = trailingMatch ? after.slice(0, after.length - trailingMatch[0].length) : after;
|
|
501
|
+
const trailing = trailingMatch ? trailingMatch[0] : "";
|
|
502
|
+
const wrapPrefix = "defineState(";
|
|
503
|
+
const wrapSuffix = ")";
|
|
504
|
+
const code = WCS_PREAMBLE + before + wrapPrefix + objectPart + wrapSuffix + trailing;
|
|
505
|
+
const preambleLen = WCS_PREAMBLE_LENGTH;
|
|
506
|
+
const mappings = [{
|
|
507
|
+
sourceOffsets: [
|
|
508
|
+
block.contentStart,
|
|
509
|
+
// before の HTML 開始位置
|
|
510
|
+
block.contentStart + exportEnd,
|
|
511
|
+
// objectPart の HTML 開始位置
|
|
512
|
+
block.contentStart + exportEnd + objectPart.length
|
|
513
|
+
// trailing の HTML 開始位置
|
|
514
|
+
],
|
|
515
|
+
generatedOffsets: [
|
|
516
|
+
preambleLen,
|
|
517
|
+
// before の仮想コード開始位置
|
|
518
|
+
preambleLen + before.length + wrapPrefix.length,
|
|
519
|
+
// objectPart の仮想コード開始位置
|
|
520
|
+
preambleLen + before.length + wrapPrefix.length + objectPart.length + wrapSuffix.length
|
|
521
|
+
// trailing
|
|
522
|
+
],
|
|
523
|
+
lengths: [
|
|
524
|
+
before.length,
|
|
525
|
+
objectPart.length,
|
|
526
|
+
trailing.length
|
|
527
|
+
],
|
|
528
|
+
data: fullFeatures
|
|
529
|
+
}];
|
|
530
|
+
return { code, mappings };
|
|
531
|
+
}
|
|
532
|
+
function stripWcsImport(code) {
|
|
533
|
+
return code.replace(
|
|
534
|
+
/import\s*\{[^}]*\}\s*from\s*['"](?:@wcstack\/state|https?:\/\/[^'"]*\/@wcstack\/state(?:@[^'"/]*)?(?:\/[^'"]*)?)['"];?[ \t]*/g,
|
|
535
|
+
(match) => match.replace(/[^\n]/g, " ")
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
539
|
+
0 && (module.exports = {
|
|
540
|
+
WCS_PREAMBLE,
|
|
541
|
+
WCS_PREAMBLE_LENGTH,
|
|
542
|
+
createWcsLanguagePlugin,
|
|
543
|
+
stripWcsImport
|
|
544
|
+
});
|
|
545
|
+
//# sourceMappingURL=tsc-core.cjs.map
|