king-design-analyzer 1.0.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.md +151 -0
- package/components/affix.json +178 -0
- package/components/az.json +86 -0
- package/components/badge.json +162 -0
- package/components/billtypes.json +90 -0
- package/components/breadcrumb.json +220 -0
- package/components/button.json +511 -0
- package/components/card.json +334 -0
- package/components/cardcontent.json +144 -0
- package/components/carousel.json +207 -0
- package/components/cascader.json +373 -0
- package/components/checkbox.json +298 -0
- package/components/code.json +318 -0
- package/components/collapse.json +358 -0
- package/components/copy.json +220 -0
- package/components/datepicker.json +529 -0
- package/components/descriptions.json +309 -0
- package/components/dialog.json +460 -0
- package/components/divider.json +287 -0
- package/components/drawer.json +563 -0
- package/components/dropdown.json +407 -0
- package/components/editable.json +331 -0
- package/components/ellipsis.json +218 -0
- package/components/form.json +638 -0
- package/components/grid.json +377 -0
- package/components/icon.json +442 -0
- package/components/input.json +821 -0
- package/components/layoutcontent.json +210 -0
- package/components/menu.json +482 -0
- package/components/message.json +345 -0
- package/components/pagination.json +444 -0
- package/components/paginationplus.json +74 -0
- package/components/popover.json +456 -0
- package/components/progress.json +354 -0
- package/components/protable.json +132 -0
- package/components/radio.json +246 -0
- package/components/region.json +115 -0
- package/components/select.json +676 -0
- package/components/slider.json +422 -0
- package/components/spin.json +232 -0
- package/components/spinner.json +441 -0
- package/components/status.json +75 -0
- package/components/steps.json +292 -0
- package/components/switch.json +357 -0
- package/components/table.json +1057 -0
- package/components/tablecolumnid.json +217 -0
- package/components/tabs.json +363 -0
- package/components/tag.json +504 -0
- package/components/timepicker.json +447 -0
- package/components/tip.json +322 -0
- package/components/tooltip.json +416 -0
- package/components/tour.json +395 -0
- package/components/transfer.json +414 -0
- package/components/tree.json +480 -0
- package/components/treeselect.json +478 -0
- package/components/upload.json +499 -0
- package/components/virtuallist.json +178 -0
- package/dist/ast/index.d.mts +71 -0
- package/dist/ast/index.d.ts +71 -0
- package/dist/ast/index.js +15 -0
- package/dist/ast/index.mjs +2 -0
- package/dist/chunk-4BUGNH4F.mjs +62 -0
- package/dist/chunk-5H7N2A5X.mjs +1 -0
- package/dist/chunk-5IF32MBB.js +603 -0
- package/dist/chunk-ARWRNWDW.js +219 -0
- package/dist/chunk-C3L4IXJC.mjs +577 -0
- package/dist/chunk-GNVCC37B.js +102 -0
- package/dist/chunk-N4UIA6DN.js +68 -0
- package/dist/chunk-RAMIBZAU.mjs +216 -0
- package/dist/chunk-RNQHI7YG.js +64 -0
- package/dist/chunk-TB6BF5TJ.mjs +99 -0
- package/dist/chunk-UX7KGX45.mjs +66 -0
- package/dist/chunk-YTEYDSDW.js +2 -0
- package/dist/full/index.d.mts +29 -0
- package/dist/full/index.d.ts +29 -0
- package/dist/full/index.js +16 -0
- package/dist/full/index.mjs +3 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +43 -0
- package/dist/index.mjs +6 -0
- package/dist/runtime/index.d.mts +14 -0
- package/dist/runtime/index.d.ts +14 -0
- package/dist/runtime/index.js +15 -0
- package/dist/runtime/index.mjs +2 -0
- package/dist/sfcCompiler-m51JOfWs.d.mts +22 -0
- package/dist/sfcCompiler-m51JOfWs.d.ts +22 -0
- package/dist/static/index.d.mts +14 -0
- package/dist/static/index.d.ts +14 -0
- package/dist/static/index.js +19 -0
- package/dist/static/index.mjs +2 -0
- package/package.json +88 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk5IF32MBB_js = require('./chunk-5IF32MBB.js');
|
|
4
|
+
var chunkGNVCC37B_js = require('./chunk-GNVCC37B.js');
|
|
5
|
+
|
|
6
|
+
// src/tools/unifiedValidator.ts
|
|
7
|
+
function validateCompilation(code) {
|
|
8
|
+
const scopeId = `validate-${Date.now()}`;
|
|
9
|
+
const scriptOpenCount = (code.match(/<script[\s\S]*?>/g) || []).length;
|
|
10
|
+
const scriptCloseCount = (code.match(/<\/script>/g) || []).length;
|
|
11
|
+
const templateOpenCount = (code.match(/<template>/g) || []).length;
|
|
12
|
+
const templateCloseCount = (code.match(/<\/template>/g) || []).length;
|
|
13
|
+
if (scriptCloseCount > 0 && scriptOpenCount === 0) {
|
|
14
|
+
return {
|
|
15
|
+
name: "\u7F16\u8BD1\u68C0\u67E5",
|
|
16
|
+
passed: false,
|
|
17
|
+
errors: ["SFC \u7ED3\u6784\u9519\u8BEF: \u7F3A\u5C11 <script> \u5F00\u59CB\u6807\u7B7E"]
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
if (scriptOpenCount > scriptCloseCount) {
|
|
21
|
+
return {
|
|
22
|
+
name: "\u7F16\u8BD1\u68C0\u67E5",
|
|
23
|
+
passed: false,
|
|
24
|
+
errors: ["SFC \u7ED3\u6784\u9519\u8BEF: \u7F3A\u5C11 </script> \u7ED3\u675F\u6807\u7B7E"]
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
if (templateOpenCount > 0 && templateCloseCount === 0) {
|
|
28
|
+
return {
|
|
29
|
+
name: "\u7F16\u8BD1\u68C0\u67E5",
|
|
30
|
+
passed: false,
|
|
31
|
+
errors: ["SFC \u7ED3\u6784\u9519\u8BEF: \u7F3A\u5C11 </template> \u7ED3\u675F\u6807\u7B7E"]
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const hasValidScript = scriptOpenCount > 0 && scriptCloseCount > 0;
|
|
35
|
+
const hasValidTemplate = templateOpenCount > 0 && templateCloseCount > 0;
|
|
36
|
+
if (!hasValidScript && !hasValidTemplate) {
|
|
37
|
+
return {
|
|
38
|
+
name: "\u7F16\u8BD1\u68C0\u67E5",
|
|
39
|
+
passed: false,
|
|
40
|
+
errors: ["SFC \u7ED3\u6784\u9519\u8BEF: \u7F3A\u5C11 <template> \u6216 <script> \u6807\u7B7E"]
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const result = chunkGNVCC37B_js.compileSFC(code, scopeId);
|
|
44
|
+
if (result.error) {
|
|
45
|
+
return {
|
|
46
|
+
name: "\u7F16\u8BD1\u68C0\u67E5",
|
|
47
|
+
passed: false,
|
|
48
|
+
errors: [result.error]
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if (!result.template && !result.script) {
|
|
52
|
+
return {
|
|
53
|
+
name: "\u7F16\u8BD1\u68C0\u67E5",
|
|
54
|
+
passed: false,
|
|
55
|
+
errors: ["\u4EE3\u7801\u4E3A\u7A7A\u6216\u683C\u5F0F\u4E0D\u6B63\u786E"]
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
name: "\u7F16\u8BD1\u68C0\u67E5",
|
|
60
|
+
passed: true,
|
|
61
|
+
errors: []
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
async function validateAST(code) {
|
|
65
|
+
try {
|
|
66
|
+
const violations = await chunk5IF32MBB_js.analyzeCodeWithAST(code);
|
|
67
|
+
if (violations.length > 0) {
|
|
68
|
+
return {
|
|
69
|
+
name: "AST\u89C4\u5219\u68C0\u67E5",
|
|
70
|
+
passed: false,
|
|
71
|
+
errors: violations.map((v) => `${v.rule}: ${v.match} \u2192 ${v.suggestion}`)
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
name: "AST\u89C4\u5219\u68C0\u67E5",
|
|
76
|
+
passed: true,
|
|
77
|
+
errors: []
|
|
78
|
+
};
|
|
79
|
+
} catch (e) {
|
|
80
|
+
return {
|
|
81
|
+
name: "AST\u89C4\u5219\u68C0\u67E5",
|
|
82
|
+
passed: false,
|
|
83
|
+
errors: [`AST\u5206\u6790\u5F02\u5E38: ${String(e)}`]
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function validateRuntimePrecheck(code) {
|
|
88
|
+
const scopeId = `runtime-${Date.now()}`;
|
|
89
|
+
const { script, bindings, error } = chunkGNVCC37B_js.compileSFC(code, scopeId);
|
|
90
|
+
if (error) {
|
|
91
|
+
return {
|
|
92
|
+
name: "\u8FD0\u884C\u65F6\u9884\u68C0\u67E5",
|
|
93
|
+
passed: false,
|
|
94
|
+
errors: [error]
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
const funcBody = `
|
|
99
|
+
"use strict";
|
|
100
|
+
${script}
|
|
101
|
+
return { ${bindings.join(", ")} };
|
|
102
|
+
`;
|
|
103
|
+
const mockContext = {
|
|
104
|
+
ref: (v) => ({ value: v }),
|
|
105
|
+
reactive: (v) => v,
|
|
106
|
+
computed: (fn) => ({ value: fn() }),
|
|
107
|
+
onMounted: () => {
|
|
108
|
+
},
|
|
109
|
+
onUnmounted: () => {
|
|
110
|
+
},
|
|
111
|
+
watch: () => {
|
|
112
|
+
},
|
|
113
|
+
shallowRef: (v) => ({ value: v }),
|
|
114
|
+
nextTick: () => Promise.resolve(),
|
|
115
|
+
toRef: () => ({}),
|
|
116
|
+
toRefs: () => ({}),
|
|
117
|
+
watchEffect: () => {
|
|
118
|
+
},
|
|
119
|
+
readonly: (v) => v,
|
|
120
|
+
h: () => ({})
|
|
121
|
+
};
|
|
122
|
+
const keys = Object.keys(mockContext);
|
|
123
|
+
const values = Object.values(mockContext);
|
|
124
|
+
const runner = new Function(...keys, funcBody);
|
|
125
|
+
const result = runner(...values);
|
|
126
|
+
for (const binding of bindings) {
|
|
127
|
+
if (!(binding in result)) {
|
|
128
|
+
return {
|
|
129
|
+
name: "\u8FD0\u884C\u65F6\u9884\u68C0\u67E5",
|
|
130
|
+
passed: false,
|
|
131
|
+
errors: [`\u53D8\u91CF ${binding} \u672A\u6B63\u786E\u5BFC\u51FA`]
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
name: "\u8FD0\u884C\u65F6\u9884\u68C0\u67E5",
|
|
137
|
+
passed: true,
|
|
138
|
+
errors: []
|
|
139
|
+
};
|
|
140
|
+
} catch (e) {
|
|
141
|
+
return {
|
|
142
|
+
name: "\u8FD0\u884C\u65F6\u9884\u68C0\u67E5",
|
|
143
|
+
passed: false,
|
|
144
|
+
errors: [`JavaScript \u6267\u884C\u9519\u8BEF: ${e.message}`]
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
async function validateCode(code) {
|
|
149
|
+
const compilationResult = validateCompilation(code);
|
|
150
|
+
if (!compilationResult.passed) {
|
|
151
|
+
return {
|
|
152
|
+
passed: false,
|
|
153
|
+
layers: {
|
|
154
|
+
compilation: compilationResult,
|
|
155
|
+
ast: { name: "AST\u89C4\u5219\u68C0\u67E5", passed: false, errors: ["\u8DF3\u8FC7\uFF08\u7F16\u8BD1\u5931\u8D25\uFF09"] },
|
|
156
|
+
runtime: { name: "\u8FD0\u884C\u65F6\u9884\u68C0\u67E5", passed: false, errors: ["\u8DF3\u8FC7\uFF08\u7F16\u8BD1\u5931\u8D25\uFF09"] }
|
|
157
|
+
},
|
|
158
|
+
summary: `\u274C \u7F16\u8BD1\u5931\u8D25: ${compilationResult.errors[0]}`
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
const astResult = await validateAST(code);
|
|
162
|
+
if (!astResult.passed) {
|
|
163
|
+
return {
|
|
164
|
+
passed: false,
|
|
165
|
+
layers: {
|
|
166
|
+
compilation: compilationResult,
|
|
167
|
+
ast: astResult,
|
|
168
|
+
runtime: { name: "\u8FD0\u884C\u65F6\u9884\u68C0\u67E5", passed: false, errors: ["\u8DF3\u8FC7\uFF08AST\u68C0\u67E5\u5931\u8D25\uFF09"] }
|
|
169
|
+
},
|
|
170
|
+
summary: `\u274C AST\u89C4\u5219\u8FDD\u89C4 (${astResult.errors.length}\u9879)`
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
const runtimeResult = validateRuntimePrecheck(code);
|
|
174
|
+
if (!runtimeResult.passed) {
|
|
175
|
+
return {
|
|
176
|
+
passed: false,
|
|
177
|
+
layers: {
|
|
178
|
+
compilation: compilationResult,
|
|
179
|
+
ast: astResult,
|
|
180
|
+
runtime: runtimeResult
|
|
181
|
+
},
|
|
182
|
+
summary: `\u274C \u8FD0\u884C\u65F6\u9519\u8BEF: ${runtimeResult.errors[0]}`
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
passed: true,
|
|
187
|
+
layers: {
|
|
188
|
+
compilation: compilationResult,
|
|
189
|
+
ast: astResult,
|
|
190
|
+
runtime: runtimeResult
|
|
191
|
+
},
|
|
192
|
+
summary: "\u2705 \u5168\u90E8\u68C0\u67E5\u901A\u8FC7"
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function validateCodeSync(code) {
|
|
196
|
+
const compilationResult = validateCompilation(code);
|
|
197
|
+
if (!compilationResult.passed) {
|
|
198
|
+
return {
|
|
199
|
+
passed: false,
|
|
200
|
+
layers: {
|
|
201
|
+
compilation: compilationResult,
|
|
202
|
+
runtime: { name: "\u8FD0\u884C\u65F6\u9884\u68C0\u67E5", passed: false, errors: ["\u8DF3\u8FC7"] }
|
|
203
|
+
},
|
|
204
|
+
summary: `\u274C \u7F16\u8BD1\u5931\u8D25: ${compilationResult.errors[0]}`
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
const runtimeResult = validateRuntimePrecheck(code);
|
|
208
|
+
return {
|
|
209
|
+
passed: runtimeResult.passed,
|
|
210
|
+
layers: {
|
|
211
|
+
compilation: compilationResult,
|
|
212
|
+
runtime: runtimeResult
|
|
213
|
+
},
|
|
214
|
+
summary: runtimeResult.passed ? "\u2705 \u68C0\u67E5\u901A\u8FC7" : `\u274C ${runtimeResult.errors[0]}`
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
exports.validateCode = validateCode;
|
|
219
|
+
exports.validateCodeSync = validateCodeSync;
|