@weapp-vite/volar 2.0.5 → 2.0.6
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/dist/index.cjs +286 -349
- package/dist/index.d.ts +2 -4
- package/dist/index.mjs +270 -326
- package/dist/schema.d.ts +26 -0
- package/package.json +6 -6
- package/dist/index.d.mts +0 -8
package/dist/index.cjs
CHANGED
|
@@ -1,386 +1,323 @@
|
|
|
1
|
-
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
2
|
var __create = Object.create;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name2 in all)
|
|
10
|
-
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
11
|
-
};
|
|
12
8
|
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
default: () => index_default
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(index_exports);
|
|
36
|
-
var import_node_module = require("module");
|
|
37
|
-
var import_node_path = __toESM(require("path"));
|
|
38
|
-
var import_node_process = __toESM(require("process"));
|
|
39
|
-
|
|
40
|
-
// package.json
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
//#endregion
|
|
23
|
+
let node_module = require("node:module");
|
|
24
|
+
let node_path = require("node:path");
|
|
25
|
+
node_path = __toESM(node_path);
|
|
26
|
+
let node_process = require("node:process");
|
|
27
|
+
node_process = __toESM(node_process);
|
|
28
|
+
let _weapp_core_schematics = require("@weapp-core/schematics");
|
|
29
|
+
//#region package.json
|
|
41
30
|
var name = "@weapp-vite/volar";
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/schema.ts
|
|
33
|
+
/**
|
|
34
|
+
* 为小程序配置生成 JSON Schema
|
|
35
|
+
* 为支持 JSON Schema 的编辑器提供验证和自动补全
|
|
36
|
+
*
|
|
37
|
+
* 注意:JSON Schema 定义由 @weapp-core/schematics 统一维护
|
|
38
|
+
* 使用 Zod 定义并自动生成,确保单一数据源
|
|
39
|
+
*/
|
|
40
|
+
/**
|
|
41
|
+
* 根据文件类型获取对应的 JSON Schema
|
|
42
|
+
* Schema 定义来自 @weapp-core/schematics,使用 Zod 维护单一数据源
|
|
43
|
+
*/
|
|
45
44
|
function getSchemaForType(type) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
return definition.schema;
|
|
45
|
+
const definition = _weapp_core_schematics.JSON_SCHEMA_DEFINITIONS.find((d) => d.typeName === type);
|
|
46
|
+
if (!definition) return null;
|
|
47
|
+
return definition.schema;
|
|
51
48
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/index.ts
|
|
51
|
+
const BLOCK_TYPE = "json";
|
|
52
|
+
const JS_LANG = "js";
|
|
53
|
+
const JSONC_LANG = "jsonc";
|
|
54
|
+
const JSON_LANG = "json";
|
|
55
|
+
const JSON5_LANG = "json5";
|
|
56
|
+
const PLUGIN_VERSION = 2.2;
|
|
57
|
+
const TS_LANG = "ts";
|
|
58
|
+
const BACKSLASH_RE = /\\/g;
|
|
59
|
+
const NON_SPACE_RE = /\S/;
|
|
60
|
+
const WXS_MODULE_RE = /<wxs[\s\S]*?module\s*=\s*(?:"([^"]+)"|'([^']+)')[\s\S]*?\/?>/gi;
|
|
61
|
+
const FULL_CAPABILITIES = {
|
|
62
|
+
verification: true,
|
|
63
|
+
completion: true,
|
|
64
|
+
semantic: true,
|
|
65
|
+
navigation: true,
|
|
66
|
+
structure: true,
|
|
67
|
+
format: true
|
|
71
68
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
69
|
+
const VOID_CAPABILITIES = {
|
|
70
|
+
verification: false,
|
|
71
|
+
completion: false,
|
|
72
|
+
semantic: false,
|
|
73
|
+
navigation: false,
|
|
74
|
+
structure: false,
|
|
75
|
+
format: false
|
|
79
76
|
};
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
);
|
|
83
|
-
var hasSchematicsTypes = false;
|
|
77
|
+
const require$1 = (0, node_module.createRequire)(typeof module !== "undefined" && module.filename ? module.filename : node_path.default.join(node_process.default.cwd(), "weapp-vite-volar.cjs"));
|
|
78
|
+
let hasSchematicsTypes = false;
|
|
84
79
|
try {
|
|
85
|
-
|
|
86
|
-
|
|
80
|
+
require$1.resolve("@weapp-core/schematics");
|
|
81
|
+
hasSchematicsTypes = true;
|
|
87
82
|
} catch {
|
|
88
|
-
|
|
83
|
+
hasSchematicsTypes = false;
|
|
89
84
|
}
|
|
90
85
|
function parseVueSfc(content, filename = "component.vue") {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
86
|
+
try {
|
|
87
|
+
return require$1("@vue/compiler-sfc").parse(content, { filename });
|
|
88
|
+
} catch {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
97
91
|
}
|
|
98
92
|
function collectWxsModuleNames(templateContent) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
names.add(name2);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return [...names];
|
|
93
|
+
if (!templateContent) return [];
|
|
94
|
+
const names = /* @__PURE__ */ new Set();
|
|
95
|
+
for (const match of templateContent.matchAll(WXS_MODULE_RE)) {
|
|
96
|
+
const name = match[1] ?? match[2];
|
|
97
|
+
if (name) names.add(name);
|
|
98
|
+
}
|
|
99
|
+
return [...names];
|
|
110
100
|
}
|
|
111
101
|
function createWxsModuleDeclarations(moduleNames) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
return moduleNames.map((name2) => `const ${name2} = {} as Record<string, (...args: any[]) => any>`).join("\n");
|
|
102
|
+
if (!moduleNames.length) return "";
|
|
103
|
+
return moduleNames.map((name) => `const ${name} = {} as Record<string, (...args: any[]) => any>`).join("\n");
|
|
116
104
|
}
|
|
117
105
|
function appendWxsDeclarations(code, moduleNames) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
return code ? `${code}
|
|
123
|
-
|
|
124
|
-
${declarations}
|
|
125
|
-
` : `${declarations}
|
|
126
|
-
`;
|
|
106
|
+
const declarations = createWxsModuleDeclarations(moduleNames);
|
|
107
|
+
if (!declarations) return code;
|
|
108
|
+
return code ? `${code}\n\n${declarations}\n` : `${declarations}\n`;
|
|
127
109
|
}
|
|
128
110
|
function createSyntheticScriptSetup(moduleNames) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
111
|
+
const content = createWxsModuleDeclarations(moduleNames);
|
|
112
|
+
if (!content) return;
|
|
113
|
+
return {
|
|
114
|
+
type: "script",
|
|
115
|
+
content,
|
|
116
|
+
loc: {
|
|
117
|
+
source: `<script setup lang="ts">\n${content}\n<\/script>`,
|
|
118
|
+
start: {
|
|
119
|
+
column: 1,
|
|
120
|
+
line: 1,
|
|
121
|
+
offset: 0
|
|
122
|
+
},
|
|
123
|
+
end: {
|
|
124
|
+
column: 1,
|
|
125
|
+
line: 1,
|
|
126
|
+
offset: 0
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
attrs: {
|
|
130
|
+
setup: true,
|
|
131
|
+
lang: "ts"
|
|
132
|
+
},
|
|
133
|
+
lang: "ts",
|
|
134
|
+
setup: true,
|
|
135
|
+
name: "scriptSetup"
|
|
136
|
+
};
|
|
151
137
|
}
|
|
152
138
|
function normalizeFilename(filename) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
return filename.replace(BACKSLASH_RE, "/");
|
|
139
|
+
if (!filename) return "";
|
|
140
|
+
return filename.replace(BACKSLASH_RE, "/");
|
|
157
141
|
}
|
|
158
142
|
function inferConfigType(filename) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
if (normalized.includes("/components/")) {
|
|
167
|
-
return "Component";
|
|
168
|
-
}
|
|
169
|
-
if (normalized.includes("/theme/")) {
|
|
170
|
-
return "Theme";
|
|
171
|
-
}
|
|
172
|
-
if (normalized.includes("/sitemap")) {
|
|
173
|
-
return "Sitemap";
|
|
174
|
-
}
|
|
175
|
-
return "Page";
|
|
143
|
+
const normalized = normalizeFilename(filename);
|
|
144
|
+
if (normalized.endsWith("/app.vue")) return "App";
|
|
145
|
+
if (normalized.includes("/plugin/")) return "Plugin";
|
|
146
|
+
if (normalized.includes("/components/")) return "Component";
|
|
147
|
+
if (normalized.includes("/theme/")) return "Theme";
|
|
148
|
+
if (normalized.includes("/sitemap")) return "Sitemap";
|
|
149
|
+
return "Page";
|
|
176
150
|
}
|
|
177
151
|
function normalizeLang(lang) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
if (lower === "txt") {
|
|
183
|
-
return JSON_LANG;
|
|
184
|
-
}
|
|
185
|
-
return lower;
|
|
152
|
+
if (!lang) return JSON_LANG;
|
|
153
|
+
const lower = lang.toLowerCase();
|
|
154
|
+
if (lower === "txt") return JSON_LANG;
|
|
155
|
+
return lower;
|
|
186
156
|
}
|
|
187
157
|
function findExportDefaultExpression(code, tsModule, lang) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
return {
|
|
204
|
-
expression,
|
|
205
|
-
expressionStart,
|
|
206
|
-
expressionEnd,
|
|
207
|
-
leading,
|
|
208
|
-
trailing
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
return null;
|
|
158
|
+
const scriptKind = lang === TS_LANG ? tsModule.ScriptKind.TS : tsModule.ScriptKind.JS;
|
|
159
|
+
const sourceFile = tsModule.createSourceFile(`config.${lang}`, code, tsModule.ScriptTarget.Latest, true, scriptKind);
|
|
160
|
+
for (const statement of sourceFile.statements) if (tsModule.isExportAssignment(statement)) {
|
|
161
|
+
const expressionStart = statement.expression.getStart(sourceFile);
|
|
162
|
+
const expressionEnd = statement.expression.getEnd();
|
|
163
|
+
const leading = code.slice(0, statement.getStart(sourceFile));
|
|
164
|
+
return {
|
|
165
|
+
expression: code.slice(expressionStart, expressionEnd),
|
|
166
|
+
expressionStart,
|
|
167
|
+
expressionEnd,
|
|
168
|
+
leading,
|
|
169
|
+
trailing: code.slice(statement.getEnd())
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
213
173
|
}
|
|
214
174
|
function injectSchemaIntoJsonObject(content, schemaId) {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
const isEmptyObject = nextCharIndex >= 0 && content[nextCharIndex] === "}";
|
|
227
|
-
const schemaLine = ` "$schema": "${schemaId}"`;
|
|
228
|
-
const injected = isEmptyObject ? `{
|
|
229
|
-
${schemaLine}
|
|
230
|
-
}` : `{
|
|
231
|
-
${schemaLine},${content.slice(leftBraceIndex + 1)}`;
|
|
232
|
-
if (trimmed === content) {
|
|
233
|
-
return injected;
|
|
234
|
-
}
|
|
235
|
-
const leading = content.slice(0, content.indexOf(trimmed));
|
|
236
|
-
const trailing = content.slice(content.indexOf(trimmed) + trimmed.length);
|
|
237
|
-
return `${leading}${injected}${trailing}`;
|
|
175
|
+
const trimmed = content.trim();
|
|
176
|
+
if (!trimmed.startsWith("{")) return content;
|
|
177
|
+
const leftBraceIndex = content.indexOf("{");
|
|
178
|
+
if (leftBraceIndex < 0) return content;
|
|
179
|
+
const firstNonSpace = content.slice(leftBraceIndex + 1).match(NON_SPACE_RE);
|
|
180
|
+
const nextCharIndex = firstNonSpace ? leftBraceIndex + 1 + firstNonSpace.index : -1;
|
|
181
|
+
const isEmptyObject = nextCharIndex >= 0 && content[nextCharIndex] === "}";
|
|
182
|
+
const schemaLine = ` "$schema": "${schemaId}"`;
|
|
183
|
+
const injected = isEmptyObject ? `{\n${schemaLine}\n}` : `{\n${schemaLine},${content.slice(leftBraceIndex + 1)}`;
|
|
184
|
+
if (trimmed === content) return injected;
|
|
185
|
+
return `${content.slice(0, content.indexOf(trimmed))}${injected}${content.slice(content.indexOf(trimmed) + trimmed.length)}`;
|
|
238
186
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
FULL_CAPABILITIES
|
|
374
|
-
]);
|
|
375
|
-
return;
|
|
376
|
-
}
|
|
377
|
-
embeddedCode.content.push([
|
|
378
|
-
block.content,
|
|
379
|
-
block.name,
|
|
380
|
-
0,
|
|
381
|
-
FULL_CAPABILITIES
|
|
382
|
-
]);
|
|
383
|
-
}
|
|
384
|
-
};
|
|
187
|
+
/**
|
|
188
|
+
* Volar 语言插件:为 weapp 配置块提供类型与 schema 提示。
|
|
189
|
+
*/
|
|
190
|
+
const plugin = (ctx) => {
|
|
191
|
+
let tsModule = ctx?.modules?.typescript;
|
|
192
|
+
if (!tsModule) try {
|
|
193
|
+
tsModule = require$1("typescript");
|
|
194
|
+
} catch {
|
|
195
|
+
tsModule = void 0;
|
|
196
|
+
}
|
|
197
|
+
return {
|
|
198
|
+
name,
|
|
199
|
+
version: PLUGIN_VERSION,
|
|
200
|
+
order: -1,
|
|
201
|
+
parseSFC2(fileName, languageId, content) {
|
|
202
|
+
if (languageId !== "vue") return;
|
|
203
|
+
const parsed = parseVueSfc(content, fileName);
|
|
204
|
+
if (!parsed) return;
|
|
205
|
+
const descriptor = parsed.descriptor;
|
|
206
|
+
const wxsModuleNames = collectWxsModuleNames(descriptor.template?.content);
|
|
207
|
+
if (!wxsModuleNames.length) return parsed;
|
|
208
|
+
if (descriptor.scriptSetup) descriptor.scriptSetup.content = appendWxsDeclarations(descriptor.scriptSetup.content, wxsModuleNames);
|
|
209
|
+
else descriptor.scriptSetup = createSyntheticScriptSetup(wxsModuleNames);
|
|
210
|
+
return parsed;
|
|
211
|
+
},
|
|
212
|
+
getEmbeddedCodes(_, sfc) {
|
|
213
|
+
const names = [];
|
|
214
|
+
for (let i = 0; i < sfc.customBlocks.length; i++) {
|
|
215
|
+
const block = sfc.customBlocks[i];
|
|
216
|
+
if (block.type === BLOCK_TYPE) {
|
|
217
|
+
const normalizedLang = normalizeLang(block.lang);
|
|
218
|
+
if (normalizedLang === JS_LANG || normalizedLang === TS_LANG) {
|
|
219
|
+
names.push({
|
|
220
|
+
id: `${BLOCK_TYPE}_${i}`,
|
|
221
|
+
lang: TS_LANG
|
|
222
|
+
});
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
const embeddedLang = normalizedLang === JSON_LANG || normalizedLang === JSONC_LANG || normalizedLang === JSON5_LANG ? JSONC_LANG : JSON_LANG;
|
|
226
|
+
names.push({
|
|
227
|
+
id: `${BLOCK_TYPE}_${i}`,
|
|
228
|
+
lang: embeddedLang
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return names;
|
|
233
|
+
},
|
|
234
|
+
resolveEmbeddedCode(fileName, sfc, embeddedCode) {
|
|
235
|
+
const match = embeddedCode.id.match(new RegExp(`^${BLOCK_TYPE}_(\\d+)$`));
|
|
236
|
+
if (!match) return;
|
|
237
|
+
const index = Number.parseInt(match[1]);
|
|
238
|
+
const block = sfc.customBlocks[index];
|
|
239
|
+
if (!block) return;
|
|
240
|
+
const normalizedLang = normalizeLang(block.lang);
|
|
241
|
+
const configType = inferConfigType(fileName);
|
|
242
|
+
if (!hasSchematicsTypes) {
|
|
243
|
+
embeddedCode.content.push([
|
|
244
|
+
block.content,
|
|
245
|
+
block.name,
|
|
246
|
+
0,
|
|
247
|
+
FULL_CAPABILITIES
|
|
248
|
+
]);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
if (normalizedLang === JS_LANG || normalizedLang === TS_LANG) {
|
|
252
|
+
const parsed = tsModule && findExportDefaultExpression(block.content, tsModule, normalizedLang);
|
|
253
|
+
if (parsed && hasSchematicsTypes) {
|
|
254
|
+
const typeImport = `import type { ${configType} as __WeappConfig } from '@weapp-core/schematics'\n`;
|
|
255
|
+
embeddedCode.content.push([
|
|
256
|
+
`${typeImport}const __weapp_defineConfig = <T extends __WeappConfig>(config: T) => config
|
|
257
|
+
|
|
258
|
+
`,
|
|
259
|
+
void 0,
|
|
260
|
+
0,
|
|
261
|
+
VOID_CAPABILITIES
|
|
262
|
+
]);
|
|
263
|
+
if (parsed.leading) embeddedCode.content.push([
|
|
264
|
+
parsed.leading,
|
|
265
|
+
block.name,
|
|
266
|
+
0,
|
|
267
|
+
FULL_CAPABILITIES
|
|
268
|
+
]);
|
|
269
|
+
embeddedCode.content.push([
|
|
270
|
+
"export default __weapp_defineConfig(",
|
|
271
|
+
void 0,
|
|
272
|
+
parsed.expressionStart,
|
|
273
|
+
VOID_CAPABILITIES
|
|
274
|
+
]);
|
|
275
|
+
embeddedCode.content.push([
|
|
276
|
+
parsed.expression,
|
|
277
|
+
block.name,
|
|
278
|
+
parsed.expressionStart,
|
|
279
|
+
FULL_CAPABILITIES
|
|
280
|
+
]);
|
|
281
|
+
embeddedCode.content.push([
|
|
282
|
+
")",
|
|
283
|
+
void 0,
|
|
284
|
+
parsed.expressionEnd,
|
|
285
|
+
VOID_CAPABILITIES
|
|
286
|
+
]);
|
|
287
|
+
if (parsed.trailing) embeddedCode.content.push([
|
|
288
|
+
parsed.trailing,
|
|
289
|
+
block.name,
|
|
290
|
+
parsed.expressionEnd,
|
|
291
|
+
FULL_CAPABILITIES
|
|
292
|
+
]);
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
embeddedCode.content.push([
|
|
296
|
+
block.content,
|
|
297
|
+
block.name,
|
|
298
|
+
0,
|
|
299
|
+
FULL_CAPABILITIES
|
|
300
|
+
]);
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
const schema = getSchemaForType(configType);
|
|
304
|
+
if (schema && schema.$id && !block.content.includes("$schema")) {
|
|
305
|
+
embeddedCode.content.push([
|
|
306
|
+
injectSchemaIntoJsonObject(block.content, schema.$id),
|
|
307
|
+
block.name,
|
|
308
|
+
0,
|
|
309
|
+
FULL_CAPABILITIES
|
|
310
|
+
]);
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
embeddedCode.content.push([
|
|
314
|
+
block.content,
|
|
315
|
+
block.name,
|
|
316
|
+
0,
|
|
317
|
+
FULL_CAPABILITIES
|
|
318
|
+
]);
|
|
319
|
+
}
|
|
320
|
+
};
|
|
385
321
|
};
|
|
386
|
-
|
|
322
|
+
//#endregion
|
|
323
|
+
module.exports = plugin;
|