king-design-analyzer 1.0.1 → 1.0.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/dist/ast/index.js +3 -3
- package/dist/ast/index.mjs +1 -1
- package/dist/{chunk-C3L4IXJC.mjs → chunk-6QIOW6QE.mjs} +101 -35
- package/dist/{chunk-5IF32MBB.js → chunk-6S2QBZUD.js} +101 -35
- package/dist/{chunk-UX7KGX45.mjs → chunk-DHO63GQC.mjs} +1 -1
- package/dist/{chunk-4BUGNH4F.mjs → chunk-DJVJXIT7.mjs} +1 -1
- package/dist/{chunk-RNQHI7YG.js → chunk-FQBDUMJD.js} +2 -2
- package/dist/{chunk-ARWRNWDW.js → chunk-PH2WUQZA.js} +5 -5
- package/dist/{chunk-TB6BF5TJ.mjs → chunk-RPNK7QXK.mjs} +29 -42
- package/dist/{chunk-GNVCC37B.js → chunk-UIHTWWBN.js} +49 -42
- package/dist/{chunk-N4UIA6DN.js → chunk-VF5B4PW7.js} +2 -2
- package/dist/{chunk-RAMIBZAU.mjs → chunk-YCVB3UOP.mjs} +2 -2
- package/dist/full/index.js +5 -5
- package/dist/full/index.mjs +3 -3
- package/dist/index.js +13 -13
- package/dist/index.mjs +5 -5
- package/dist/runtime/index.js +4 -4
- package/dist/runtime/index.mjs +2 -2
- package/dist/static/index.js +5 -5
- package/dist/static/index.mjs +2 -2
- package/package.json +5 -2
package/dist/ast/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
require('../chunk-YTEYDSDW.js');
|
|
4
|
-
var
|
|
4
|
+
var chunk6S2QBZUD_js = require('../chunk-6S2QBZUD.js');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
Object.defineProperty(exports, "analyzeCodeWithAST", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
10
|
+
get: function () { return chunk6S2QBZUD_js.analyzeCodeWithAST; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "componentRegistry", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunk6S2QBZUD_js.componentRegistry; }
|
|
15
15
|
});
|
package/dist/ast/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import '../chunk-5H7N2A5X.mjs';
|
|
2
|
-
export { analyzeCodeWithAST, componentRegistry } from '../chunk-
|
|
2
|
+
export { analyzeCodeWithAST, componentRegistry } from '../chunk-6QIOW6QE.mjs';
|
|
@@ -117,9 +117,9 @@ async function analyzeCodeWithAST(code) {
|
|
|
117
117
|
suggestion: "\u8BF7\u79FB\u9664 <template #menu>\uFF0C\u5C06 DropdownMenu \u76F4\u63A5\u4F5C\u4E3A Dropdown \u7684\u7B2C\u4E8C\u4E2A\u5B50\u5143\u7D20"
|
|
118
118
|
});
|
|
119
119
|
}
|
|
120
|
-
if (scriptContent && descriptor.template
|
|
120
|
+
if (scriptContent && descriptor.template) {
|
|
121
121
|
const scriptBindings = extractScriptBindings(scriptContent);
|
|
122
|
-
checkTemplateVariables(descriptor.template
|
|
122
|
+
checkTemplateVariables(descriptor.template, scriptBindings, violations);
|
|
123
123
|
}
|
|
124
124
|
return violations;
|
|
125
125
|
}
|
|
@@ -187,9 +187,19 @@ function extractScriptBindings(scriptContent) {
|
|
|
187
187
|
"false"
|
|
188
188
|
].forEach((b) => bindings.add(b));
|
|
189
189
|
try {
|
|
190
|
-
let
|
|
191
|
-
if (ts.
|
|
192
|
-
bindings.add(
|
|
190
|
+
let extractNames2 = function(name) {
|
|
191
|
+
if (ts.isIdentifier(name)) {
|
|
192
|
+
bindings.add(name.text);
|
|
193
|
+
} else if (ts.isObjectBindingPattern(name) || ts.isArrayBindingPattern(name)) {
|
|
194
|
+
name.elements.forEach((element) => {
|
|
195
|
+
if (ts.isBindingElement(element)) {
|
|
196
|
+
extractNames2(element.name);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}, visit2 = function(node) {
|
|
201
|
+
if (ts.isVariableDeclaration(node)) {
|
|
202
|
+
extractNames2(node.name);
|
|
193
203
|
}
|
|
194
204
|
if (ts.isFunctionDeclaration(node) && node.name) {
|
|
195
205
|
bindings.add(node.name.text);
|
|
@@ -205,14 +215,9 @@ function extractScriptBindings(scriptContent) {
|
|
|
205
215
|
bindings.add(node.importClause.name.text);
|
|
206
216
|
}
|
|
207
217
|
}
|
|
208
|
-
if (ts.isCallExpression(node)) {
|
|
209
|
-
const expr = node.expression;
|
|
210
|
-
if (ts.isIdentifier(expr) && expr.text === "defineProps") {
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
218
|
ts.forEachChild(node, visit2);
|
|
214
219
|
};
|
|
215
|
-
var visit = visit2;
|
|
220
|
+
var extractNames = extractNames2, visit = visit2;
|
|
216
221
|
const sourceFile = ts.createSourceFile(
|
|
217
222
|
"temp.ts",
|
|
218
223
|
scriptContent,
|
|
@@ -220,18 +225,49 @@ function extractScriptBindings(scriptContent) {
|
|
|
220
225
|
true
|
|
221
226
|
);
|
|
222
227
|
visit2(sourceFile);
|
|
223
|
-
} catch {
|
|
228
|
+
} catch (err) {
|
|
229
|
+
return bindings;
|
|
224
230
|
}
|
|
225
231
|
return bindings;
|
|
226
232
|
}
|
|
227
|
-
function checkTemplateVariables(
|
|
233
|
+
function checkTemplateVariables(template, bindings, violations) {
|
|
234
|
+
const templateContent = template.content;
|
|
235
|
+
const templateAst = template.ast;
|
|
236
|
+
const localVariables = /* @__PURE__ */ new Set();
|
|
237
|
+
if (templateAst) {
|
|
238
|
+
let walk2 = function(node) {
|
|
239
|
+
if (node.type === 0 || node.type === 1) {
|
|
240
|
+
const vFor = node.props?.find((p) => p.type === 7 && p.name === "for");
|
|
241
|
+
if (vFor && vFor.exp) {
|
|
242
|
+
if (vFor.parseResult) {
|
|
243
|
+
const { value, key, index } = vFor.parseResult;
|
|
244
|
+
if (value) extractIdentifiersFromTemplateAST(value, localVariables);
|
|
245
|
+
if (key) extractIdentifiersFromTemplateAST(key, localVariables);
|
|
246
|
+
if (index) extractIdentifiersFromTemplateAST(index, localVariables);
|
|
247
|
+
} else if (vFor.exp.content) {
|
|
248
|
+
extractIdentifiersFromTemplateAST(vFor.exp, localVariables);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
const vSlot = node.props?.find((p) => p.type === 7 && p.name === "slot");
|
|
252
|
+
if (vSlot && vSlot.exp) {
|
|
253
|
+
extractIdentifiersFromTemplateAST(vSlot.exp, localVariables);
|
|
254
|
+
}
|
|
255
|
+
if (node.children) {
|
|
256
|
+
node.children.forEach(walk2);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
walk2(templateAst);
|
|
261
|
+
}
|
|
262
|
+
const allBindings = /* @__PURE__ */ new Set([...bindings, ...localVariables]);
|
|
228
263
|
const interpolationRegex = /\{\{\s*([^}]+)\s*\}\}/g;
|
|
229
264
|
let match;
|
|
230
265
|
while ((match = interpolationRegex.exec(templateContent)) !== null) {
|
|
231
266
|
const expression = match[1].trim();
|
|
232
|
-
const identifiers = extractIdentifiersFromExpression(expression);
|
|
267
|
+
const { identifiers, locals } = extractIdentifiersFromExpression(expression);
|
|
268
|
+
const combinedBindings = /* @__PURE__ */ new Set([...allBindings, ...locals]);
|
|
233
269
|
for (const id of identifiers) {
|
|
234
|
-
if (!
|
|
270
|
+
if (!combinedBindings.has(id) && !isTemplateBuiltin(id)) {
|
|
235
271
|
violations.push({
|
|
236
272
|
rule: `\u6A21\u677F\u5F15\u7528\u4E86\u672A\u5B9A\u4E49\u7684\u53D8\u91CF: ${id}`,
|
|
237
273
|
match: `{{ ${expression} }}`,
|
|
@@ -243,9 +279,10 @@ function checkTemplateVariables(templateContent, bindings, violations) {
|
|
|
243
279
|
const bindRegex = /(?::|v-bind:)[\w.-]+="([^"]+)"/g;
|
|
244
280
|
while ((match = bindRegex.exec(templateContent)) !== null) {
|
|
245
281
|
const expression = match[1].trim();
|
|
246
|
-
const identifiers = extractIdentifiersFromExpression(expression);
|
|
282
|
+
const { identifiers, locals } = extractIdentifiersFromExpression(expression);
|
|
283
|
+
const combinedBindings = /* @__PURE__ */ new Set([...allBindings, ...locals]);
|
|
247
284
|
for (const id of identifiers) {
|
|
248
|
-
if (!
|
|
285
|
+
if (!combinedBindings.has(id) && !isTemplateBuiltin(id)) {
|
|
249
286
|
violations.push({
|
|
250
287
|
rule: `\u7ED1\u5B9A\u5C5E\u6027\u5F15\u7528\u4E86\u672A\u5B9A\u4E49\u7684\u53D8\u91CF: ${id}`,
|
|
251
288
|
match: match[0],
|
|
@@ -257,31 +294,60 @@ function checkTemplateVariables(templateContent, bindings, violations) {
|
|
|
257
294
|
const eventRegex = /(?:@|v-on:)[\w.-]+="([^"]+)"/g;
|
|
258
295
|
while ((match = eventRegex.exec(templateContent)) !== null) {
|
|
259
296
|
const expression = match[1].trim();
|
|
260
|
-
|
|
261
|
-
const
|
|
297
|
+
const { identifiers, locals } = extractIdentifiersFromExpression(expression);
|
|
298
|
+
const combinedBindings = /* @__PURE__ */ new Set([...allBindings, ...locals]);
|
|
262
299
|
for (const id of identifiers) {
|
|
263
|
-
if (!
|
|
300
|
+
if (!combinedBindings.has(id) && !isTemplateBuiltin(id)) {
|
|
264
301
|
violations.push({
|
|
265
|
-
rule: `\u4E8B\u4EF6\u5904\u7406\u5668\u5F15\u7528\u4E86\u672A\u5B9A\u4E49\u7684\u51FD\u6570: ${id}`,
|
|
302
|
+
rule: `\u4E8B\u4EF6\u5904\u7406\u5668\u5F15\u7528\u4E86\u672A\u5B9A\u4E49\u7684\u51FD\u6570/\u53D8\u91CF: ${id}`,
|
|
266
303
|
match: match[0],
|
|
267
|
-
suggestion: `\u8BF7\u786E\u4FDD\u5728 <script setup> \u4E2D\u5B9A\u4E49
|
|
304
|
+
suggestion: `\u8BF7\u786E\u4FDD\u5728 <script setup> \u4E2D\u5B9A\u4E49 ${id}`
|
|
268
305
|
});
|
|
269
306
|
}
|
|
270
307
|
}
|
|
271
308
|
}
|
|
272
309
|
}
|
|
310
|
+
function extractIdentifiersFromTemplateAST(node, set) {
|
|
311
|
+
if (!node) return;
|
|
312
|
+
if (node.type === 4) {
|
|
313
|
+
const content = node.content;
|
|
314
|
+
const matches = content.match(/\b([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g);
|
|
315
|
+
if (matches) {
|
|
316
|
+
matches.forEach((m) => {
|
|
317
|
+
if (!isJsKeyword(m)) set.add(m);
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
} else if (node.type === 8) {
|
|
321
|
+
node.children.forEach((c) => extractIdentifiersFromTemplateAST(c, set));
|
|
322
|
+
}
|
|
323
|
+
}
|
|
273
324
|
function extractIdentifiersFromExpression(expression) {
|
|
274
|
-
expression = expression.replace(/'[^']*'/g, "").replace(/"[^"]*"/g, "").replace(/`[^`]*`/g, "");
|
|
275
325
|
const identifiers = [];
|
|
276
|
-
const
|
|
326
|
+
const locals = [];
|
|
327
|
+
const arrowFuncRegex = /(?:(?:\(([^)]+)\))|([a-zA-Z_$][\w$]*))\s*=>/g;
|
|
328
|
+
let arrowMatch;
|
|
329
|
+
while ((arrowMatch = arrowFuncRegex.exec(expression)) !== null) {
|
|
330
|
+
const params = arrowMatch[1] || arrowMatch[2];
|
|
331
|
+
if (params) {
|
|
332
|
+
const paramNames = params.split(",").map((p) => p.trim().split(":")[0].trim());
|
|
333
|
+
paramNames.forEach((p) => {
|
|
334
|
+
const subMatches = p.match(/\b([a-zA-Z_$][\w$]*)\b/g);
|
|
335
|
+
if (subMatches) subMatches.forEach((sm) => {
|
|
336
|
+
if (!isJsKeyword(sm)) locals.push(sm);
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
const cleanExpr = expression.replace(/'[^']*'/g, "").replace(/"[^"]*"/g, "").replace(/`[^`]*`/g, "");
|
|
342
|
+
const idRegex = /(?:^|[^.\w$])([a-zA-Z_$][\w$]*)\b(?!\s*:)/g;
|
|
277
343
|
let match;
|
|
278
|
-
while ((match = idRegex.exec(
|
|
344
|
+
while ((match = idRegex.exec(cleanExpr)) !== null) {
|
|
279
345
|
const id = match[1];
|
|
280
|
-
if (!isJsKeyword(id)) {
|
|
346
|
+
if (!isJsKeyword(id) && !locals.includes(id)) {
|
|
281
347
|
identifiers.push(id);
|
|
282
348
|
}
|
|
283
349
|
}
|
|
284
|
-
return identifiers;
|
|
350
|
+
return { identifiers: [...new Set(identifiers)], locals: [...new Set(locals)] };
|
|
285
351
|
}
|
|
286
352
|
function isTemplateBuiltin(id) {
|
|
287
353
|
const builtins = [
|
|
@@ -390,7 +456,7 @@ function checkImport(node, violations, sourceFile) {
|
|
|
390
456
|
var NESTING_RULES = {
|
|
391
457
|
"DropdownItem": ["DropdownMenu"],
|
|
392
458
|
"DropdownMenu": ["Dropdown"],
|
|
393
|
-
"TableColumn": ["Table"],
|
|
459
|
+
"TableColumn": ["Table", "ProTable"],
|
|
394
460
|
"FormItem": ["Form"],
|
|
395
461
|
"Tab": ["Tabs"],
|
|
396
462
|
"Step": ["Steps"],
|
|
@@ -460,12 +526,12 @@ function checkTemplate(node, violations, parentTagName) {
|
|
|
460
526
|
if (prop.type === 6) {
|
|
461
527
|
const propName = prop.name;
|
|
462
528
|
const camelCaseProp = propName.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
463
|
-
const isPropValid = metadata.props
|
|
529
|
+
const isPropValid = metadata.props?.some(
|
|
464
530
|
(p) => p.name === propName || p.name === camelCaseProp || p.name.toLowerCase() === propName.toLowerCase()
|
|
465
531
|
);
|
|
466
532
|
const isDynamicallyAllowed = dynamicAllowedProps.includes(propName);
|
|
467
533
|
if (!isPropValid && !isDynamicallyAllowed && !["class", "style", "key", "ref"].includes(propName) && !propName.startsWith("data-")) {
|
|
468
|
-
if (metadata.props.length > 0) {
|
|
534
|
+
if (metadata.props && metadata.props.length > 0) {
|
|
469
535
|
violations.push({
|
|
470
536
|
rule: `\u5C5E\u6027 ${propName} \u4E0D\u5B58\u5728\u4E8E ${tagName}`,
|
|
471
537
|
match: propName,
|
|
@@ -473,7 +539,7 @@ function checkTemplate(node, violations, parentTagName) {
|
|
|
473
539
|
});
|
|
474
540
|
}
|
|
475
541
|
}
|
|
476
|
-
if (isPropValid) {
|
|
542
|
+
if (isPropValid && metadata.props) {
|
|
477
543
|
const targetProp = metadata.props.find(
|
|
478
544
|
(p) => p.name === propName || p.name === camelCaseProp || p.name.toLowerCase() === propName.toLowerCase()
|
|
479
545
|
);
|
|
@@ -509,7 +575,7 @@ function checkTemplate(node, violations, parentTagName) {
|
|
|
509
575
|
return;
|
|
510
576
|
}
|
|
511
577
|
const camelCaseEvent = eventName.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
512
|
-
const isEventValid = metadata.events
|
|
578
|
+
const isEventValid = metadata.events?.some(
|
|
513
579
|
(e) => e.name === eventName || e.name === camelCaseEvent || e.name.toLowerCase() === eventName.toLowerCase()
|
|
514
580
|
);
|
|
515
581
|
const nativeEvents = [
|
|
@@ -536,7 +602,7 @@ function checkTemplate(node, violations, parentTagName) {
|
|
|
536
602
|
"touchmove"
|
|
537
603
|
];
|
|
538
604
|
const isNativeEvent = nativeEvents.includes(eventName);
|
|
539
|
-
if (!isEventValid && !isNativeEvent && metadata.events.length > 0) {
|
|
605
|
+
if (!isEventValid && !isNativeEvent && metadata.events && metadata.events.length > 0) {
|
|
540
606
|
violations.push({
|
|
541
607
|
rule: `\u4E8B\u4EF6 @${eventName} \u4E0D\u5B58\u5728\u4E8E ${tagName}`,
|
|
542
608
|
match: `@${eventName}`,
|
|
@@ -546,13 +612,13 @@ function checkTemplate(node, violations, parentTagName) {
|
|
|
546
612
|
}
|
|
547
613
|
}
|
|
548
614
|
});
|
|
549
|
-
if (node.children && metadata.slots
|
|
615
|
+
if (node.children && metadata.slots?.length > 0) {
|
|
550
616
|
node.children.forEach((child) => {
|
|
551
617
|
if (child.type === 1 && child.tag === "template") {
|
|
552
618
|
child.props.forEach((prop) => {
|
|
553
619
|
if (prop.type === 7 && prop.name === "slot") {
|
|
554
620
|
const slotName = prop.arg?.content || "default";
|
|
555
|
-
const isSlotValid = metadata.slots
|
|
621
|
+
const isSlotValid = metadata.slots?.some((s) => s.name === slotName);
|
|
556
622
|
if (!isSlotValid) {
|
|
557
623
|
violations.push({
|
|
558
624
|
rule: `\u63D2\u69FD #${slotName} \u4E0D\u5B58\u5728\u4E8E ${tagName}`,
|
|
@@ -142,9 +142,9 @@ async function analyzeCodeWithAST(code) {
|
|
|
142
142
|
suggestion: "\u8BF7\u79FB\u9664 <template #menu>\uFF0C\u5C06 DropdownMenu \u76F4\u63A5\u4F5C\u4E3A Dropdown \u7684\u7B2C\u4E8C\u4E2A\u5B50\u5143\u7D20"
|
|
143
143
|
});
|
|
144
144
|
}
|
|
145
|
-
if (scriptContent && descriptor.template
|
|
145
|
+
if (scriptContent && descriptor.template) {
|
|
146
146
|
const scriptBindings = extractScriptBindings(scriptContent);
|
|
147
|
-
checkTemplateVariables(descriptor.template
|
|
147
|
+
checkTemplateVariables(descriptor.template, scriptBindings, violations);
|
|
148
148
|
}
|
|
149
149
|
return violations;
|
|
150
150
|
}
|
|
@@ -212,9 +212,19 @@ function extractScriptBindings(scriptContent) {
|
|
|
212
212
|
"false"
|
|
213
213
|
].forEach((b) => bindings.add(b));
|
|
214
214
|
try {
|
|
215
|
-
let
|
|
216
|
-
if (ts__namespace.
|
|
217
|
-
bindings.add(
|
|
215
|
+
let extractNames2 = function(name) {
|
|
216
|
+
if (ts__namespace.isIdentifier(name)) {
|
|
217
|
+
bindings.add(name.text);
|
|
218
|
+
} else if (ts__namespace.isObjectBindingPattern(name) || ts__namespace.isArrayBindingPattern(name)) {
|
|
219
|
+
name.elements.forEach((element) => {
|
|
220
|
+
if (ts__namespace.isBindingElement(element)) {
|
|
221
|
+
extractNames2(element.name);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}, visit2 = function(node) {
|
|
226
|
+
if (ts__namespace.isVariableDeclaration(node)) {
|
|
227
|
+
extractNames2(node.name);
|
|
218
228
|
}
|
|
219
229
|
if (ts__namespace.isFunctionDeclaration(node) && node.name) {
|
|
220
230
|
bindings.add(node.name.text);
|
|
@@ -230,14 +240,9 @@ function extractScriptBindings(scriptContent) {
|
|
|
230
240
|
bindings.add(node.importClause.name.text);
|
|
231
241
|
}
|
|
232
242
|
}
|
|
233
|
-
if (ts__namespace.isCallExpression(node)) {
|
|
234
|
-
const expr = node.expression;
|
|
235
|
-
if (ts__namespace.isIdentifier(expr) && expr.text === "defineProps") {
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
243
|
ts__namespace.forEachChild(node, visit2);
|
|
239
244
|
};
|
|
240
|
-
var visit = visit2;
|
|
245
|
+
var extractNames = extractNames2, visit = visit2;
|
|
241
246
|
const sourceFile = ts__namespace.createSourceFile(
|
|
242
247
|
"temp.ts",
|
|
243
248
|
scriptContent,
|
|
@@ -245,18 +250,49 @@ function extractScriptBindings(scriptContent) {
|
|
|
245
250
|
true
|
|
246
251
|
);
|
|
247
252
|
visit2(sourceFile);
|
|
248
|
-
} catch {
|
|
253
|
+
} catch (err) {
|
|
254
|
+
return bindings;
|
|
249
255
|
}
|
|
250
256
|
return bindings;
|
|
251
257
|
}
|
|
252
|
-
function checkTemplateVariables(
|
|
258
|
+
function checkTemplateVariables(template, bindings, violations) {
|
|
259
|
+
const templateContent = template.content;
|
|
260
|
+
const templateAst = template.ast;
|
|
261
|
+
const localVariables = /* @__PURE__ */ new Set();
|
|
262
|
+
if (templateAst) {
|
|
263
|
+
let walk2 = function(node) {
|
|
264
|
+
if (node.type === 0 || node.type === 1) {
|
|
265
|
+
const vFor = node.props?.find((p) => p.type === 7 && p.name === "for");
|
|
266
|
+
if (vFor && vFor.exp) {
|
|
267
|
+
if (vFor.parseResult) {
|
|
268
|
+
const { value, key, index } = vFor.parseResult;
|
|
269
|
+
if (value) extractIdentifiersFromTemplateAST(value, localVariables);
|
|
270
|
+
if (key) extractIdentifiersFromTemplateAST(key, localVariables);
|
|
271
|
+
if (index) extractIdentifiersFromTemplateAST(index, localVariables);
|
|
272
|
+
} else if (vFor.exp.content) {
|
|
273
|
+
extractIdentifiersFromTemplateAST(vFor.exp, localVariables);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
const vSlot = node.props?.find((p) => p.type === 7 && p.name === "slot");
|
|
277
|
+
if (vSlot && vSlot.exp) {
|
|
278
|
+
extractIdentifiersFromTemplateAST(vSlot.exp, localVariables);
|
|
279
|
+
}
|
|
280
|
+
if (node.children) {
|
|
281
|
+
node.children.forEach(walk2);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
walk2(templateAst);
|
|
286
|
+
}
|
|
287
|
+
const allBindings = /* @__PURE__ */ new Set([...bindings, ...localVariables]);
|
|
253
288
|
const interpolationRegex = /\{\{\s*([^}]+)\s*\}\}/g;
|
|
254
289
|
let match;
|
|
255
290
|
while ((match = interpolationRegex.exec(templateContent)) !== null) {
|
|
256
291
|
const expression = match[1].trim();
|
|
257
|
-
const identifiers = extractIdentifiersFromExpression(expression);
|
|
292
|
+
const { identifiers, locals } = extractIdentifiersFromExpression(expression);
|
|
293
|
+
const combinedBindings = /* @__PURE__ */ new Set([...allBindings, ...locals]);
|
|
258
294
|
for (const id of identifiers) {
|
|
259
|
-
if (!
|
|
295
|
+
if (!combinedBindings.has(id) && !isTemplateBuiltin(id)) {
|
|
260
296
|
violations.push({
|
|
261
297
|
rule: `\u6A21\u677F\u5F15\u7528\u4E86\u672A\u5B9A\u4E49\u7684\u53D8\u91CF: ${id}`,
|
|
262
298
|
match: `{{ ${expression} }}`,
|
|
@@ -268,9 +304,10 @@ function checkTemplateVariables(templateContent, bindings, violations) {
|
|
|
268
304
|
const bindRegex = /(?::|v-bind:)[\w.-]+="([^"]+)"/g;
|
|
269
305
|
while ((match = bindRegex.exec(templateContent)) !== null) {
|
|
270
306
|
const expression = match[1].trim();
|
|
271
|
-
const identifiers = extractIdentifiersFromExpression(expression);
|
|
307
|
+
const { identifiers, locals } = extractIdentifiersFromExpression(expression);
|
|
308
|
+
const combinedBindings = /* @__PURE__ */ new Set([...allBindings, ...locals]);
|
|
272
309
|
for (const id of identifiers) {
|
|
273
|
-
if (!
|
|
310
|
+
if (!combinedBindings.has(id) && !isTemplateBuiltin(id)) {
|
|
274
311
|
violations.push({
|
|
275
312
|
rule: `\u7ED1\u5B9A\u5C5E\u6027\u5F15\u7528\u4E86\u672A\u5B9A\u4E49\u7684\u53D8\u91CF: ${id}`,
|
|
276
313
|
match: match[0],
|
|
@@ -282,31 +319,60 @@ function checkTemplateVariables(templateContent, bindings, violations) {
|
|
|
282
319
|
const eventRegex = /(?:@|v-on:)[\w.-]+="([^"]+)"/g;
|
|
283
320
|
while ((match = eventRegex.exec(templateContent)) !== null) {
|
|
284
321
|
const expression = match[1].trim();
|
|
285
|
-
|
|
286
|
-
const
|
|
322
|
+
const { identifiers, locals } = extractIdentifiersFromExpression(expression);
|
|
323
|
+
const combinedBindings = /* @__PURE__ */ new Set([...allBindings, ...locals]);
|
|
287
324
|
for (const id of identifiers) {
|
|
288
|
-
if (!
|
|
325
|
+
if (!combinedBindings.has(id) && !isTemplateBuiltin(id)) {
|
|
289
326
|
violations.push({
|
|
290
|
-
rule: `\u4E8B\u4EF6\u5904\u7406\u5668\u5F15\u7528\u4E86\u672A\u5B9A\u4E49\u7684\u51FD\u6570: ${id}`,
|
|
327
|
+
rule: `\u4E8B\u4EF6\u5904\u7406\u5668\u5F15\u7528\u4E86\u672A\u5B9A\u4E49\u7684\u51FD\u6570/\u53D8\u91CF: ${id}`,
|
|
291
328
|
match: match[0],
|
|
292
|
-
suggestion: `\u8BF7\u786E\u4FDD\u5728 <script setup> \u4E2D\u5B9A\u4E49
|
|
329
|
+
suggestion: `\u8BF7\u786E\u4FDD\u5728 <script setup> \u4E2D\u5B9A\u4E49 ${id}`
|
|
293
330
|
});
|
|
294
331
|
}
|
|
295
332
|
}
|
|
296
333
|
}
|
|
297
334
|
}
|
|
335
|
+
function extractIdentifiersFromTemplateAST(node, set) {
|
|
336
|
+
if (!node) return;
|
|
337
|
+
if (node.type === 4) {
|
|
338
|
+
const content = node.content;
|
|
339
|
+
const matches = content.match(/\b([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g);
|
|
340
|
+
if (matches) {
|
|
341
|
+
matches.forEach((m) => {
|
|
342
|
+
if (!isJsKeyword(m)) set.add(m);
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
} else if (node.type === 8) {
|
|
346
|
+
node.children.forEach((c) => extractIdentifiersFromTemplateAST(c, set));
|
|
347
|
+
}
|
|
348
|
+
}
|
|
298
349
|
function extractIdentifiersFromExpression(expression) {
|
|
299
|
-
expression = expression.replace(/'[^']*'/g, "").replace(/"[^"]*"/g, "").replace(/`[^`]*`/g, "");
|
|
300
350
|
const identifiers = [];
|
|
301
|
-
const
|
|
351
|
+
const locals = [];
|
|
352
|
+
const arrowFuncRegex = /(?:(?:\(([^)]+)\))|([a-zA-Z_$][\w$]*))\s*=>/g;
|
|
353
|
+
let arrowMatch;
|
|
354
|
+
while ((arrowMatch = arrowFuncRegex.exec(expression)) !== null) {
|
|
355
|
+
const params = arrowMatch[1] || arrowMatch[2];
|
|
356
|
+
if (params) {
|
|
357
|
+
const paramNames = params.split(",").map((p) => p.trim().split(":")[0].trim());
|
|
358
|
+
paramNames.forEach((p) => {
|
|
359
|
+
const subMatches = p.match(/\b([a-zA-Z_$][\w$]*)\b/g);
|
|
360
|
+
if (subMatches) subMatches.forEach((sm) => {
|
|
361
|
+
if (!isJsKeyword(sm)) locals.push(sm);
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
const cleanExpr = expression.replace(/'[^']*'/g, "").replace(/"[^"]*"/g, "").replace(/`[^`]*`/g, "");
|
|
367
|
+
const idRegex = /(?:^|[^.\w$])([a-zA-Z_$][\w$]*)\b(?!\s*:)/g;
|
|
302
368
|
let match;
|
|
303
|
-
while ((match = idRegex.exec(
|
|
369
|
+
while ((match = idRegex.exec(cleanExpr)) !== null) {
|
|
304
370
|
const id = match[1];
|
|
305
|
-
if (!isJsKeyword(id)) {
|
|
371
|
+
if (!isJsKeyword(id) && !locals.includes(id)) {
|
|
306
372
|
identifiers.push(id);
|
|
307
373
|
}
|
|
308
374
|
}
|
|
309
|
-
return identifiers;
|
|
375
|
+
return { identifiers: [...new Set(identifiers)], locals: [...new Set(locals)] };
|
|
310
376
|
}
|
|
311
377
|
function isTemplateBuiltin(id) {
|
|
312
378
|
const builtins = [
|
|
@@ -415,7 +481,7 @@ function checkImport(node, violations, sourceFile) {
|
|
|
415
481
|
var NESTING_RULES = {
|
|
416
482
|
"DropdownItem": ["DropdownMenu"],
|
|
417
483
|
"DropdownMenu": ["Dropdown"],
|
|
418
|
-
"TableColumn": ["Table"],
|
|
484
|
+
"TableColumn": ["Table", "ProTable"],
|
|
419
485
|
"FormItem": ["Form"],
|
|
420
486
|
"Tab": ["Tabs"],
|
|
421
487
|
"Step": ["Steps"],
|
|
@@ -485,12 +551,12 @@ function checkTemplate(node, violations, parentTagName) {
|
|
|
485
551
|
if (prop.type === 6) {
|
|
486
552
|
const propName = prop.name;
|
|
487
553
|
const camelCaseProp = propName.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
488
|
-
const isPropValid = metadata.props
|
|
554
|
+
const isPropValid = metadata.props?.some(
|
|
489
555
|
(p) => p.name === propName || p.name === camelCaseProp || p.name.toLowerCase() === propName.toLowerCase()
|
|
490
556
|
);
|
|
491
557
|
const isDynamicallyAllowed = dynamicAllowedProps.includes(propName);
|
|
492
558
|
if (!isPropValid && !isDynamicallyAllowed && !["class", "style", "key", "ref"].includes(propName) && !propName.startsWith("data-")) {
|
|
493
|
-
if (metadata.props.length > 0) {
|
|
559
|
+
if (metadata.props && metadata.props.length > 0) {
|
|
494
560
|
violations.push({
|
|
495
561
|
rule: `\u5C5E\u6027 ${propName} \u4E0D\u5B58\u5728\u4E8E ${tagName}`,
|
|
496
562
|
match: propName,
|
|
@@ -498,7 +564,7 @@ function checkTemplate(node, violations, parentTagName) {
|
|
|
498
564
|
});
|
|
499
565
|
}
|
|
500
566
|
}
|
|
501
|
-
if (isPropValid) {
|
|
567
|
+
if (isPropValid && metadata.props) {
|
|
502
568
|
const targetProp = metadata.props.find(
|
|
503
569
|
(p) => p.name === propName || p.name === camelCaseProp || p.name.toLowerCase() === propName.toLowerCase()
|
|
504
570
|
);
|
|
@@ -534,7 +600,7 @@ function checkTemplate(node, violations, parentTagName) {
|
|
|
534
600
|
return;
|
|
535
601
|
}
|
|
536
602
|
const camelCaseEvent = eventName.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
537
|
-
const isEventValid = metadata.events
|
|
603
|
+
const isEventValid = metadata.events?.some(
|
|
538
604
|
(e) => e.name === eventName || e.name === camelCaseEvent || e.name.toLowerCase() === eventName.toLowerCase()
|
|
539
605
|
);
|
|
540
606
|
const nativeEvents = [
|
|
@@ -561,7 +627,7 @@ function checkTemplate(node, violations, parentTagName) {
|
|
|
561
627
|
"touchmove"
|
|
562
628
|
];
|
|
563
629
|
const isNativeEvent = nativeEvents.includes(eventName);
|
|
564
|
-
if (!isEventValid && !isNativeEvent && metadata.events.length > 0) {
|
|
630
|
+
if (!isEventValid && !isNativeEvent && metadata.events && metadata.events.length > 0) {
|
|
565
631
|
violations.push({
|
|
566
632
|
rule: `\u4E8B\u4EF6 @${eventName} \u4E0D\u5B58\u5728\u4E8E ${tagName}`,
|
|
567
633
|
match: `@${eventName}`,
|
|
@@ -571,13 +637,13 @@ function checkTemplate(node, violations, parentTagName) {
|
|
|
571
637
|
}
|
|
572
638
|
}
|
|
573
639
|
});
|
|
574
|
-
if (node.children && metadata.slots
|
|
640
|
+
if (node.children && metadata.slots?.length > 0) {
|
|
575
641
|
node.children.forEach((child) => {
|
|
576
642
|
if (child.type === 1 && child.tag === "template") {
|
|
577
643
|
child.props.forEach((prop) => {
|
|
578
644
|
if (prop.type === 7 && prop.name === "slot") {
|
|
579
645
|
const slotName = prop.arg?.content || "default";
|
|
580
|
-
const isSlotValid = metadata.slots
|
|
646
|
+
const isSlotValid = metadata.slots?.some((s) => s.name === slotName);
|
|
581
647
|
if (!isSlotValid) {
|
|
582
648
|
violations.push({
|
|
583
649
|
rule: `\u63D2\u69FD #${slotName} \u4E0D\u5B58\u5728\u4E8E ${tagName}`,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkUIHTWWBN_js = require('./chunk-UIHTWWBN.js');
|
|
4
4
|
|
|
5
5
|
// src/static/index.ts
|
|
6
6
|
function validateCompilation(code) {
|
|
@@ -39,7 +39,7 @@ function validateCompilation(code) {
|
|
|
39
39
|
errors: ["SFC \u7ED3\u6784\u9519\u8BEF: \u7F3A\u5C11 <template> \u6216 <script> \u6807\u7B7E"]
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
const result =
|
|
42
|
+
const result = chunkUIHTWWBN_js.compileSFC(code, scopeId);
|
|
43
43
|
if (result.error) {
|
|
44
44
|
return {
|
|
45
45
|
name: "\u7F16\u8BD1\u68C0\u67E5",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunk6S2QBZUD_js = require('./chunk-6S2QBZUD.js');
|
|
4
|
+
var chunkUIHTWWBN_js = require('./chunk-UIHTWWBN.js');
|
|
5
5
|
|
|
6
6
|
// src/tools/unifiedValidator.ts
|
|
7
7
|
function validateCompilation(code) {
|
|
@@ -40,7 +40,7 @@ function validateCompilation(code) {
|
|
|
40
40
|
errors: ["SFC \u7ED3\u6784\u9519\u8BEF: \u7F3A\u5C11 <template> \u6216 <script> \u6807\u7B7E"]
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
|
-
const result =
|
|
43
|
+
const result = chunkUIHTWWBN_js.compileSFC(code, scopeId);
|
|
44
44
|
if (result.error) {
|
|
45
45
|
return {
|
|
46
46
|
name: "\u7F16\u8BD1\u68C0\u67E5",
|
|
@@ -63,7 +63,7 @@ function validateCompilation(code) {
|
|
|
63
63
|
}
|
|
64
64
|
async function validateAST(code) {
|
|
65
65
|
try {
|
|
66
|
-
const violations = await
|
|
66
|
+
const violations = await chunk6S2QBZUD_js.analyzeCodeWithAST(code);
|
|
67
67
|
if (violations.length > 0) {
|
|
68
68
|
return {
|
|
69
69
|
name: "AST\u89C4\u5219\u68C0\u67E5",
|
|
@@ -86,7 +86,7 @@ async function validateAST(code) {
|
|
|
86
86
|
}
|
|
87
87
|
function validateRuntimePrecheck(code) {
|
|
88
88
|
const scopeId = `runtime-${Date.now()}`;
|
|
89
|
-
const { script, bindings, error } =
|
|
89
|
+
const { script, bindings, error } = chunkUIHTWWBN_js.compileSFC(code, scopeId);
|
|
90
90
|
if (error) {
|
|
91
91
|
return {
|
|
92
92
|
name: "\u8FD0\u884C\u65F6\u9884\u68C0\u67E5",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { transform } from 'sucrase';
|
|
2
|
+
import * as ts from 'typescript';
|
|
2
3
|
|
|
3
4
|
// src/tools/sfcCompiler.ts
|
|
4
5
|
function scopeStyles(css, scopeClass) {
|
|
@@ -34,56 +35,42 @@ function compileSFC(code, scopeId) {
|
|
|
34
35
|
if (result && typeof result.code === "string") {
|
|
35
36
|
cleanScript = result.code;
|
|
36
37
|
}
|
|
37
|
-
const varNames =
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
if (baseIndent === -1) baseIndent = 0;
|
|
50
|
-
for (const line of lines) {
|
|
51
|
-
const lineIndentMatch = line.match(/^(\s*)/);
|
|
52
|
-
const lineIndent = lineIndentMatch && typeof lineIndentMatch[1] === "string" ? lineIndentMatch[1].length : 0;
|
|
53
|
-
if (!line.trim() || line.trim().startsWith("//")) continue;
|
|
54
|
-
if (lineIndent === baseIndent) {
|
|
55
|
-
const trimmed = line.trim();
|
|
56
|
-
const stdMatch = trimmed.match(/^(?:const|let|var|function)\s+(\w+)/);
|
|
57
|
-
if (stdMatch && stdMatch[1]) {
|
|
58
|
-
varNames.push(stdMatch[1]);
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
const objMatch = trimmed.match(/^(?:const|let|var)\s+\{([^}]+)\}\s*=/);
|
|
62
|
-
if (objMatch && typeof objMatch[1] === "string") {
|
|
63
|
-
const content = objMatch[1];
|
|
64
|
-
const vars = content.split(",").map((v) => (v.split(":")[0] || "").trim());
|
|
65
|
-
vars.forEach((v) => {
|
|
66
|
-
const cleanName = v.replace(/\s+as\s+\w+/, "").trim();
|
|
67
|
-
if (/^[a-zA-Z_$][\w$]*$/.test(cleanName)) varNames.push(cleanName);
|
|
38
|
+
const varNames = /* @__PURE__ */ new Set();
|
|
39
|
+
try {
|
|
40
|
+
let extractNames2 = function(name) {
|
|
41
|
+
if (ts.isIdentifier(name)) {
|
|
42
|
+
varNames.add(name.text);
|
|
43
|
+
} else if (ts.isObjectBindingPattern(name) || ts.isArrayBindingPattern(name)) {
|
|
44
|
+
name.elements.forEach((element) => {
|
|
45
|
+
if (ts.isBindingElement(element)) {
|
|
46
|
+
extractNames2(element.name);
|
|
47
|
+
}
|
|
68
48
|
});
|
|
69
|
-
continue;
|
|
70
49
|
}
|
|
71
|
-
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
});
|
|
78
|
-
continue;
|
|
50
|
+
}, visit2 = function(node) {
|
|
51
|
+
if (ts.isVariableDeclaration(node)) {
|
|
52
|
+
extractNames2(node.name);
|
|
53
|
+
}
|
|
54
|
+
if (ts.isFunctionDeclaration(node) && node.name) {
|
|
55
|
+
varNames.add(node.name.text);
|
|
79
56
|
}
|
|
80
|
-
|
|
57
|
+
ts.forEachChild(node, visit2);
|
|
58
|
+
};
|
|
59
|
+
var extractNames = extractNames2, visit = visit2;
|
|
60
|
+
const sourceFile = ts.createSourceFile(
|
|
61
|
+
"temp.ts",
|
|
62
|
+
cleanScript,
|
|
63
|
+
ts.ScriptTarget.Latest,
|
|
64
|
+
true
|
|
65
|
+
);
|
|
66
|
+
visit2(sourceFile);
|
|
67
|
+
} catch (e) {
|
|
81
68
|
}
|
|
82
69
|
return {
|
|
83
70
|
template,
|
|
84
71
|
script: cleanScript,
|
|
85
72
|
style,
|
|
86
|
-
bindings: [...
|
|
73
|
+
bindings: [...varNames]
|
|
87
74
|
};
|
|
88
75
|
} catch (e) {
|
|
89
76
|
return {
|
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var sucrase = require('sucrase');
|
|
4
|
+
var ts = require('typescript');
|
|
5
|
+
|
|
6
|
+
function _interopNamespace(e) {
|
|
7
|
+
if (e && e.__esModule) return e;
|
|
8
|
+
var n = Object.create(null);
|
|
9
|
+
if (e) {
|
|
10
|
+
Object.keys(e).forEach(function (k) {
|
|
11
|
+
if (k !== 'default') {
|
|
12
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return e[k]; }
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
n.default = e;
|
|
21
|
+
return Object.freeze(n);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var ts__namespace = /*#__PURE__*/_interopNamespace(ts);
|
|
4
25
|
|
|
5
26
|
// src/tools/sfcCompiler.ts
|
|
6
27
|
function scopeStyles(css, scopeClass) {
|
|
@@ -36,56 +57,42 @@ function compileSFC(code, scopeId) {
|
|
|
36
57
|
if (result && typeof result.code === "string") {
|
|
37
58
|
cleanScript = result.code;
|
|
38
59
|
}
|
|
39
|
-
const varNames =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
if (baseIndent === -1) baseIndent = 0;
|
|
52
|
-
for (const line of lines) {
|
|
53
|
-
const lineIndentMatch = line.match(/^(\s*)/);
|
|
54
|
-
const lineIndent = lineIndentMatch && typeof lineIndentMatch[1] === "string" ? lineIndentMatch[1].length : 0;
|
|
55
|
-
if (!line.trim() || line.trim().startsWith("//")) continue;
|
|
56
|
-
if (lineIndent === baseIndent) {
|
|
57
|
-
const trimmed = line.trim();
|
|
58
|
-
const stdMatch = trimmed.match(/^(?:const|let|var|function)\s+(\w+)/);
|
|
59
|
-
if (stdMatch && stdMatch[1]) {
|
|
60
|
-
varNames.push(stdMatch[1]);
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
const objMatch = trimmed.match(/^(?:const|let|var)\s+\{([^}]+)\}\s*=/);
|
|
64
|
-
if (objMatch && typeof objMatch[1] === "string") {
|
|
65
|
-
const content = objMatch[1];
|
|
66
|
-
const vars = content.split(",").map((v) => (v.split(":")[0] || "").trim());
|
|
67
|
-
vars.forEach((v) => {
|
|
68
|
-
const cleanName = v.replace(/\s+as\s+\w+/, "").trim();
|
|
69
|
-
if (/^[a-zA-Z_$][\w$]*$/.test(cleanName)) varNames.push(cleanName);
|
|
60
|
+
const varNames = /* @__PURE__ */ new Set();
|
|
61
|
+
try {
|
|
62
|
+
let extractNames2 = function(name) {
|
|
63
|
+
if (ts__namespace.isIdentifier(name)) {
|
|
64
|
+
varNames.add(name.text);
|
|
65
|
+
} else if (ts__namespace.isObjectBindingPattern(name) || ts__namespace.isArrayBindingPattern(name)) {
|
|
66
|
+
name.elements.forEach((element) => {
|
|
67
|
+
if (ts__namespace.isBindingElement(element)) {
|
|
68
|
+
extractNames2(element.name);
|
|
69
|
+
}
|
|
70
70
|
});
|
|
71
|
-
continue;
|
|
72
71
|
}
|
|
73
|
-
|
|
74
|
-
if (
|
|
75
|
-
|
|
76
|
-
const vars = content.split(",").map((v) => v.trim());
|
|
77
|
-
vars.forEach((v) => {
|
|
78
|
-
if (v && /^[a-zA-Z_$][\w$]*$/.test(v)) varNames.push(v);
|
|
79
|
-
});
|
|
80
|
-
continue;
|
|
72
|
+
}, visit2 = function(node) {
|
|
73
|
+
if (ts__namespace.isVariableDeclaration(node)) {
|
|
74
|
+
extractNames2(node.name);
|
|
81
75
|
}
|
|
82
|
-
|
|
76
|
+
if (ts__namespace.isFunctionDeclaration(node) && node.name) {
|
|
77
|
+
varNames.add(node.name.text);
|
|
78
|
+
}
|
|
79
|
+
ts__namespace.forEachChild(node, visit2);
|
|
80
|
+
};
|
|
81
|
+
var extractNames = extractNames2, visit = visit2;
|
|
82
|
+
const sourceFile = ts__namespace.createSourceFile(
|
|
83
|
+
"temp.ts",
|
|
84
|
+
cleanScript,
|
|
85
|
+
ts__namespace.ScriptTarget.Latest,
|
|
86
|
+
true
|
|
87
|
+
);
|
|
88
|
+
visit2(sourceFile);
|
|
89
|
+
} catch (e) {
|
|
83
90
|
}
|
|
84
91
|
return {
|
|
85
92
|
template,
|
|
86
93
|
script: cleanScript,
|
|
87
94
|
style,
|
|
88
|
-
bindings: [...
|
|
95
|
+
bindings: [...varNames]
|
|
89
96
|
};
|
|
90
97
|
} catch (e) {
|
|
91
98
|
return {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkUIHTWWBN_js = require('./chunk-UIHTWWBN.js');
|
|
4
4
|
|
|
5
5
|
// src/runtime/index.ts
|
|
6
6
|
function validateRuntimePrecheck(code) {
|
|
7
7
|
const scopeId = `runtime-${Date.now()}`;
|
|
8
|
-
const { script, bindings, error } =
|
|
8
|
+
const { script, bindings, error } = chunkUIHTWWBN_js.compileSFC(code, scopeId);
|
|
9
9
|
if (error) {
|
|
10
10
|
return {
|
|
11
11
|
name: "\u8FD0\u884C\u65F6\u9884\u68C0\u67E5",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { analyzeCodeWithAST } from './chunk-
|
|
2
|
-
import { compileSFC } from './chunk-
|
|
1
|
+
import { analyzeCodeWithAST } from './chunk-6QIOW6QE.mjs';
|
|
2
|
+
import { compileSFC } from './chunk-RPNK7QXK.mjs';
|
|
3
3
|
|
|
4
4
|
// src/tools/unifiedValidator.ts
|
|
5
5
|
function validateCompilation(code) {
|
package/dist/full/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-
|
|
5
|
-
require('../chunk-
|
|
3
|
+
var chunkPH2WUQZA_js = require('../chunk-PH2WUQZA.js');
|
|
4
|
+
require('../chunk-6S2QBZUD.js');
|
|
5
|
+
require('../chunk-UIHTWWBN.js');
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
Object.defineProperty(exports, "validateCode", {
|
|
10
10
|
enumerable: true,
|
|
11
|
-
get: function () { return
|
|
11
|
+
get: function () { return chunkPH2WUQZA_js.validateCode; }
|
|
12
12
|
});
|
|
13
13
|
Object.defineProperty(exports, "validateCodeSync", {
|
|
14
14
|
enumerable: true,
|
|
15
|
-
get: function () { return
|
|
15
|
+
get: function () { return chunkPH2WUQZA_js.validateCodeSync; }
|
|
16
16
|
});
|
package/dist/full/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { validateCode, validateCodeSync } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
3
|
-
import '../chunk-
|
|
1
|
+
export { validateCode, validateCodeSync } from '../chunk-YCVB3UOP.mjs';
|
|
2
|
+
import '../chunk-6QIOW6QE.mjs';
|
|
3
|
+
import '../chunk-RPNK7QXK.mjs';
|
package/dist/index.js
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkFQBDUMJD_js = require('./chunk-FQBDUMJD.js');
|
|
4
4
|
require('./chunk-YTEYDSDW.js');
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
5
|
+
var chunkVF5B4PW7_js = require('./chunk-VF5B4PW7.js');
|
|
6
|
+
var chunkPH2WUQZA_js = require('./chunk-PH2WUQZA.js');
|
|
7
|
+
var chunk6S2QBZUD_js = require('./chunk-6S2QBZUD.js');
|
|
8
|
+
var chunkUIHTWWBN_js = require('./chunk-UIHTWWBN.js');
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
Object.defineProperty(exports, "validateCompilation", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunkFQBDUMJD_js.validateCompilation; }
|
|
15
15
|
});
|
|
16
16
|
Object.defineProperty(exports, "validateRuntimePrecheck", {
|
|
17
17
|
enumerable: true,
|
|
18
|
-
get: function () { return
|
|
18
|
+
get: function () { return chunkVF5B4PW7_js.validateRuntimePrecheck; }
|
|
19
19
|
});
|
|
20
20
|
Object.defineProperty(exports, "validateCode", {
|
|
21
21
|
enumerable: true,
|
|
22
|
-
get: function () { return
|
|
22
|
+
get: function () { return chunkPH2WUQZA_js.validateCode; }
|
|
23
23
|
});
|
|
24
24
|
Object.defineProperty(exports, "validateCodeSync", {
|
|
25
25
|
enumerable: true,
|
|
26
|
-
get: function () { return
|
|
26
|
+
get: function () { return chunkPH2WUQZA_js.validateCodeSync; }
|
|
27
27
|
});
|
|
28
28
|
Object.defineProperty(exports, "analyzeCodeWithAST", {
|
|
29
29
|
enumerable: true,
|
|
30
|
-
get: function () { return
|
|
30
|
+
get: function () { return chunk6S2QBZUD_js.analyzeCodeWithAST; }
|
|
31
31
|
});
|
|
32
32
|
Object.defineProperty(exports, "componentRegistry", {
|
|
33
33
|
enumerable: true,
|
|
34
|
-
get: function () { return
|
|
34
|
+
get: function () { return chunk6S2QBZUD_js.componentRegistry; }
|
|
35
35
|
});
|
|
36
36
|
Object.defineProperty(exports, "compileSFC", {
|
|
37
37
|
enumerable: true,
|
|
38
|
-
get: function () { return
|
|
38
|
+
get: function () { return chunkUIHTWWBN_js.compileSFC; }
|
|
39
39
|
});
|
|
40
40
|
Object.defineProperty(exports, "scopeStyles", {
|
|
41
41
|
enumerable: true,
|
|
42
|
-
get: function () { return
|
|
42
|
+
get: function () { return chunkUIHTWWBN_js.scopeStyles; }
|
|
43
43
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { validateCompilation } from './chunk-
|
|
1
|
+
export { validateCompilation } from './chunk-DJVJXIT7.mjs';
|
|
2
2
|
import './chunk-5H7N2A5X.mjs';
|
|
3
|
-
export { validateRuntimePrecheck } from './chunk-
|
|
4
|
-
export { validateCode, validateCodeSync } from './chunk-
|
|
5
|
-
export { analyzeCodeWithAST, componentRegistry } from './chunk-
|
|
6
|
-
export { compileSFC, scopeStyles } from './chunk-
|
|
3
|
+
export { validateRuntimePrecheck } from './chunk-DHO63GQC.mjs';
|
|
4
|
+
export { validateCode, validateCodeSync } from './chunk-YCVB3UOP.mjs';
|
|
5
|
+
export { analyzeCodeWithAST, componentRegistry } from './chunk-6QIOW6QE.mjs';
|
|
6
|
+
export { compileSFC, scopeStyles } from './chunk-RPNK7QXK.mjs';
|
package/dist/runtime/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkVF5B4PW7_js = require('../chunk-VF5B4PW7.js');
|
|
4
|
+
var chunkUIHTWWBN_js = require('../chunk-UIHTWWBN.js');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
Object.defineProperty(exports, "validateRuntimePrecheck", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
10
|
+
get: function () { return chunkVF5B4PW7_js.validateRuntimePrecheck; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "compileSFC", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunkUIHTWWBN_js.compileSFC; }
|
|
15
15
|
});
|
package/dist/runtime/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { validateRuntimePrecheck } from '../chunk-
|
|
2
|
-
export { compileSFC } from '../chunk-
|
|
1
|
+
export { validateRuntimePrecheck } from '../chunk-DHO63GQC.mjs';
|
|
2
|
+
export { compileSFC } from '../chunk-RPNK7QXK.mjs';
|
package/dist/static/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkFQBDUMJD_js = require('../chunk-FQBDUMJD.js');
|
|
4
|
+
var chunkUIHTWWBN_js = require('../chunk-UIHTWWBN.js');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
Object.defineProperty(exports, "validateCompilation", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
10
|
+
get: function () { return chunkFQBDUMJD_js.validateCompilation; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "compileSFC", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunkUIHTWWBN_js.compileSFC; }
|
|
15
15
|
});
|
|
16
16
|
Object.defineProperty(exports, "scopeStyles", {
|
|
17
17
|
enumerable: true,
|
|
18
|
-
get: function () { return
|
|
18
|
+
get: function () { return chunkUIHTWWBN_js.scopeStyles; }
|
|
19
19
|
});
|
package/dist/static/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { validateCompilation } from '../chunk-
|
|
2
|
-
export { compileSFC, scopeStyles } from '../chunk-
|
|
1
|
+
export { validateCompilation } from '../chunk-DJVJXIT7.mjs';
|
|
2
|
+
export { compileSFC, scopeStyles } from '../chunk-RPNK7QXK.mjs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "king-design-analyzer",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "AST-based code analyzer for King Design Vue components with on-demand modular imports",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -46,7 +46,10 @@
|
|
|
46
46
|
"validate:unified": "npx ts-node src/tools/testUnifiedValidator.ts",
|
|
47
47
|
"test": "vitest run",
|
|
48
48
|
"test:watch": "vitest",
|
|
49
|
-
"prepublishOnly": "npm run build"
|
|
49
|
+
"prepublishOnly": "npm run build",
|
|
50
|
+
"release:patch": "npm version patch && npm publish",
|
|
51
|
+
"release:minor": "npm version minor && npm publish",
|
|
52
|
+
"release:major": "npm version major && npm publish"
|
|
50
53
|
},
|
|
51
54
|
"keywords": [
|
|
52
55
|
"king-design",
|