king-design-analyzer 2.2.0 → 2.2.1
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/components/actions.json +8 -0
- package/components/advancedset.json +1 -0
- package/components/affix.json +1 -0
- package/components/anchor.json +220 -0
- package/components/anchorlink.json +111 -0
- package/components/badge.json +1 -0
- package/components/breadcrumb.json +2 -1
- package/components/button.json +1 -0
- package/components/buttonlink.json +1 -0
- package/components/card.json +6 -3
- package/components/cardcontent.json +5 -0
- package/components/cascader.json +56 -0
- package/components/collapse.json +335 -348
- package/components/configprovider.json +96 -0
- package/components/copyrow.json +1 -0
- package/components/descriptions.json +10 -3
- package/components/diagram.json +295 -0
- package/components/dialog.json +4 -0
- package/components/divider.json +1 -0
- package/components/drawer.json +32 -0
- package/components/dropdown.json +4 -4
- package/components/flex.json +1 -0
- package/components/form.json +12 -3
- package/components/header.json +4 -0
- package/components/input.json +8 -4
- package/components/layoutcontent.json +9 -0
- package/components/layoutlistcontent.json +9 -0
- package/components/layoutpermissioncontent.json +1 -0
- package/components/layoutstandardlist.json +1 -0
- package/components/lazymount.json +1 -0
- package/components/lazyteleport.json +1 -0
- package/components/menu.json +4 -3
- package/components/notification.json +351 -0
- package/components/protable.json +2 -0
- package/components/rate.json +1 -0
- package/components/scrollselect.json +140 -0
- package/components/select.json +63 -0
- package/components/skeleton.json +1 -0
- package/components/slider.json +12 -2
- package/components/spin.json +2 -1
- package/components/spinner.json +419 -429
- package/components/split.json +3 -0
- package/components/switch.json +4 -2
- package/components/table.json +6 -1
- package/components/tabs.json +2 -2
- package/components/tag.json +8 -5
- package/components/timeline.json +3 -1
- package/components/tip.json +20 -0
- package/components/tooltip.json +8 -0
- package/components/transfer.json +52 -5
- package/components/tree.json +22 -1
- package/components/treeselect.json +56 -0
- package/components/vdialog.json +1 -0
- package/components/vdrawer.json +4 -0
- package/dist/ast/index.d.mts +30 -1
- package/dist/ast/index.d.ts +30 -1
- package/dist/ast/index.js +3 -3
- package/dist/ast/index.mjs +1 -1
- package/dist/{chunk-BI5TIQID.mjs → chunk-4OTQAQ6J.mjs} +13 -2
- package/dist/{chunk-CJGGFVQJ.js → chunk-4WXOYU2N.js} +31 -8
- package/dist/chunk-6HOIRUQB.mjs +409 -0
- package/dist/{chunk-CR3GC4H3.js → chunk-DHLWNT53.js} +13 -2
- package/dist/{chunk-KMIDURUR.mjs → chunk-IPJJMPOO.mjs} +113 -19
- package/dist/{chunk-TA3SV4SP.js → chunk-JJ6AB4ZH.js} +2 -2
- package/dist/{chunk-SZYVGYKK.js → chunk-JNRGUR3O.js} +113 -19
- package/dist/{chunk-XGPHQHLR.mjs → chunk-LRTDTFFQ.mjs} +27 -4
- package/dist/{chunk-3LYQ5XFM.mjs → chunk-NZL6T22V.mjs} +1 -1
- package/dist/chunk-V5N65MRP.js +411 -0
- package/dist/full/index.d.mts +2 -0
- package/dist/full/index.d.ts +2 -0
- package/dist/full/index.js +6 -6
- package/dist/full/index.mjs +4 -4
- package/dist/index.js +13 -13
- package/dist/index.mjs +5 -5
- package/dist/metadata/index.d.mts +17 -2
- package/dist/metadata/index.d.ts +17 -2
- package/dist/runtime/index.d.mts +2 -0
- package/dist/runtime/index.d.ts +2 -0
- 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/docs_for_llm/actions.doc.md +11 -1
- package/docs_for_llm/advancedset.doc.md +10 -1
- package/docs_for_llm/affix.doc.md +5 -0
- package/docs_for_llm/anchor.doc.md +155 -0
- package/docs_for_llm/anchorlink.doc.md +75 -0
- package/docs_for_llm/badge.doc.md +5 -0
- package/docs_for_llm/breadcrumb.doc.md +74 -1
- package/docs_for_llm/button.doc.md +57 -0
- package/docs_for_llm/buttonlink.doc.md +10 -1
- package/docs_for_llm/card.doc.md +50 -3
- package/docs_for_llm/cardcontent.doc.md +21 -0
- package/docs_for_llm/carousel.doc.md +71 -0
- package/docs_for_llm/cascader.doc.md +62 -0
- package/docs_for_llm/collapse.doc.md +138 -8
- package/docs_for_llm/configprovider.doc.md +77 -0
- package/docs_for_llm/copyrow.doc.md +10 -1
- package/docs_for_llm/datepicker.doc.md +19 -0
- package/docs_for_llm/descriptions.doc.md +113 -4
- package/docs_for_llm/diagram.doc.md +343 -0
- package/docs_for_llm/dialog.doc.md +49 -0
- package/docs_for_llm/divider.doc.md +5 -0
- package/docs_for_llm/drawer.doc.md +86 -0
- package/docs_for_llm/dropdown.doc.md +240 -3
- package/docs_for_llm/flex.doc.md +10 -1
- package/docs_for_llm/form.doc.md +163 -4
- package/docs_for_llm/formitemspinner.doc.md +1 -1
- package/docs_for_llm/grid.doc.md +71 -0
- package/docs_for_llm/header.doc.md +33 -4
- package/docs_for_llm/input.doc.md +109 -2
- package/docs_for_llm/layoutcontent.doc.md +37 -0
- package/docs_for_llm/layoutlistcontent.doc.md +82 -9
- package/docs_for_llm/layoutpermissioncontent.doc.md +10 -1
- package/docs_for_llm/layoutstandardlist.doc.md +10 -1
- package/docs_for_llm/lazymount.doc.md +10 -1
- package/docs_for_llm/lazyteleport.doc.md +10 -1
- package/docs_for_llm/menu.doc.md +125 -3
- package/docs_for_llm/message.doc.md +45 -0
- package/docs_for_llm/notification.doc.md +214 -0
- package/docs_for_llm/protable.doc.md +9 -0
- package/docs_for_llm/rate.doc.md +5 -0
- package/docs_for_llm/scrollselect.doc.md +90 -0
- package/docs_for_llm/select.doc.md +174 -0
- package/docs_for_llm/skeleton.doc.md +35 -0
- package/docs_for_llm/slider.doc.md +11 -1
- package/docs_for_llm/spin.doc.md +10 -1
- package/docs_for_llm/spinner.doc.md +1 -1
- package/docs_for_llm/split.doc.md +13 -0
- package/docs_for_llm/steps.doc.md +71 -0
- package/docs_for_llm/switch.doc.md +15 -2
- package/docs_for_llm/table.doc.md +199 -4
- package/docs_for_llm/tabs.doc.md +98 -2
- package/docs_for_llm/tag.doc.md +148 -5
- package/docs_for_llm/timeline.doc.md +80 -2
- package/docs_for_llm/timepicker.doc.md +19 -0
- package/docs_for_llm/tip.doc.md +30 -0
- package/docs_for_llm/tooltip.doc.md +46 -0
- package/docs_for_llm/tour.doc.md +78 -0
- package/docs_for_llm/transfer.doc.md +59 -4
- package/docs_for_llm/tree.doc.md +64 -1
- package/docs_for_llm/treeselect.doc.md +68 -0
- package/docs_for_llm/upload.doc.md +7 -0
- package/docs_for_llm/vdialog.doc.md +26 -1
- package/docs_for_llm/vdrawer.doc.md +33 -4
- package/docs_for_llm/virtuallist.doc.md +151 -0
- package/package.json +3 -3
- package/dist/chunk-D2SXGGTX.mjs +0 -162
- package/dist/chunk-EYKZY2F3.js +0 -164
|
@@ -32269,7 +32269,14 @@ var ComponentRegistry = class {
|
|
|
32269
32269
|
newComponents.set(resolvedData.name, resolvedData);
|
|
32270
32270
|
if (resolvedData.subComponents) {
|
|
32271
32271
|
for (const sub of resolvedData.subComponents) {
|
|
32272
|
-
newComponents.set(sub.name,
|
|
32272
|
+
newComponents.set(sub.name, {
|
|
32273
|
+
id: sub.name,
|
|
32274
|
+
name: sub.name,
|
|
32275
|
+
props: sub.props || [],
|
|
32276
|
+
events: sub.events || [],
|
|
32277
|
+
slots: sub.slots || [],
|
|
32278
|
+
methods: sub.methods || []
|
|
32279
|
+
});
|
|
32273
32280
|
}
|
|
32274
32281
|
}
|
|
32275
32282
|
}
|
|
@@ -33085,7 +33092,7 @@ function checkNestingRules(tagName, metadata, ancestors, violations) {
|
|
|
33085
33092
|
});
|
|
33086
33093
|
}
|
|
33087
33094
|
}
|
|
33088
|
-
function checkComponentSpecificRules(tagName, node, violations) {
|
|
33095
|
+
function checkComponentSpecificRules(tagName, node, metadata, violations) {
|
|
33089
33096
|
if (tagName === "Dropdown") {
|
|
33090
33097
|
node.children?.forEach((child) => {
|
|
33091
33098
|
if (child.type === 1 && child.tag === "template") {
|
|
@@ -33124,23 +33131,110 @@ function checkComponentSpecificRules(tagName, node, violations) {
|
|
|
33124
33131
|
}
|
|
33125
33132
|
});
|
|
33126
33133
|
}
|
|
33127
|
-
if (
|
|
33128
|
-
|
|
33129
|
-
|
|
33130
|
-
|
|
33131
|
-
|
|
33132
|
-
|
|
33133
|
-
|
|
33134
|
-
|
|
33135
|
-
|
|
33136
|
-
|
|
33137
|
-
|
|
33138
|
-
|
|
33139
|
-
|
|
33140
|
-
|
|
33141
|
-
|
|
33142
|
-
|
|
33134
|
+
if (!metadata?.slots?.length) {
|
|
33135
|
+
return;
|
|
33136
|
+
}
|
|
33137
|
+
const validateSlotBinding = (slotName, expression) => {
|
|
33138
|
+
if (!expression) return;
|
|
33139
|
+
const slot = metadata.slots.find((item) => item.name === slotName);
|
|
33140
|
+
if (!slot) return;
|
|
33141
|
+
const exp = expression.trim();
|
|
33142
|
+
const bindingType = resolveSlotBindingType(slot);
|
|
33143
|
+
if (!bindingType) return;
|
|
33144
|
+
if (bindingType === "none") {
|
|
33145
|
+
violations.push({
|
|
33146
|
+
rule: `${tagName} \u63D2\u69FD #${slotName} \u4E0D\u63D0\u4F9B\u53C2\u6570`,
|
|
33147
|
+
match: exp,
|
|
33148
|
+
suggestion: `\u8BF7\u79FB\u9664 ${slotName} \u63D2\u69FD\u4E0A\u7684\u53C2\u6570\u58F0\u660E`
|
|
33149
|
+
});
|
|
33150
|
+
return;
|
|
33151
|
+
}
|
|
33152
|
+
if (bindingType === "array" && isObjectDestructuringExpression(exp)) {
|
|
33153
|
+
violations.push({
|
|
33154
|
+
rule: `${tagName} \u63D2\u69FD\u53C2\u6570\u5E94\u4E3A\u6570\u7EC4\u7ED3\u6784`,
|
|
33155
|
+
match: exp,
|
|
33156
|
+
suggestion: `\u8BF7\u5C06 ${exp} \u6539\u4E3A ${getSlotBindingExample(slot, "array")}`
|
|
33157
|
+
});
|
|
33158
|
+
return;
|
|
33159
|
+
}
|
|
33160
|
+
if (bindingType === "object" && isArrayDestructuringExpression(exp)) {
|
|
33161
|
+
violations.push({
|
|
33162
|
+
rule: `${tagName} \u63D2\u69FD\u53C2\u6570\u5E94\u4E3A\u5BF9\u8C61\u7ED3\u6784`,
|
|
33163
|
+
match: exp,
|
|
33164
|
+
suggestion: `\u8BF7\u5C06 ${exp} \u6539\u4E3A ${getSlotBindingExample(slot, "object")}`
|
|
33165
|
+
});
|
|
33166
|
+
return;
|
|
33167
|
+
}
|
|
33168
|
+
if (bindingType === "single" && (isArrayDestructuringExpression(exp) || isObjectDestructuringExpression(exp))) {
|
|
33169
|
+
violations.push({
|
|
33170
|
+
rule: `${tagName} \u63D2\u69FD\u53C2\u6570\u5E94\u4E3A\u5355\u503C\u7ED3\u6784`,
|
|
33171
|
+
match: exp,
|
|
33172
|
+
suggestion: `\u8BF7\u5C06 ${exp} \u6539\u4E3A ${getSlotBindingExample(slot, "single")}`
|
|
33173
|
+
});
|
|
33174
|
+
}
|
|
33175
|
+
};
|
|
33176
|
+
node.props.forEach((prop) => {
|
|
33177
|
+
if (prop.type !== 7 || prop.name !== "slot") return;
|
|
33178
|
+
validateSlotBinding(slotNameFromVSlotDirective(prop), getDirectiveExpressionContent(prop.exp));
|
|
33179
|
+
});
|
|
33180
|
+
node.children?.forEach((child) => {
|
|
33181
|
+
if (child.type !== 1 || child.tag !== "template") return;
|
|
33182
|
+
const slotProp = child.props?.find((p) => p.type === 7 && p.name === "slot");
|
|
33183
|
+
if (!slotProp) return;
|
|
33184
|
+
validateSlotBinding(slotNameFromVSlotDirective(slotProp), getDirectiveExpressionContent(slotProp.exp));
|
|
33185
|
+
});
|
|
33186
|
+
}
|
|
33187
|
+
function isArrayDestructuringExpression(expression) {
|
|
33188
|
+
return expression.startsWith("[") && expression.endsWith("]");
|
|
33189
|
+
}
|
|
33190
|
+
function isObjectDestructuringExpression(expression) {
|
|
33191
|
+
return expression.startsWith("{") && expression.endsWith("}");
|
|
33192
|
+
}
|
|
33193
|
+
function extractBindingExpressionFromVueTemplate(vueTemplate) {
|
|
33194
|
+
if (!vueTemplate) return void 0;
|
|
33195
|
+
const match = vueTemplate.match(/=\s*"([^"]+)"/);
|
|
33196
|
+
return match?.[1]?.trim();
|
|
33197
|
+
}
|
|
33198
|
+
function getDirectiveExpressionContent(exp) {
|
|
33199
|
+
if (!exp || !("content" in exp)) return void 0;
|
|
33200
|
+
return typeof exp.content === "string" ? exp.content : void 0;
|
|
33201
|
+
}
|
|
33202
|
+
function resolveSlotBindingType(slot) {
|
|
33203
|
+
if (slot.bindingType) {
|
|
33204
|
+
return slot.bindingType;
|
|
33205
|
+
}
|
|
33206
|
+
const templateExpression = extractBindingExpressionFromVueTemplate(slot.vueTemplate);
|
|
33207
|
+
if (templateExpression) {
|
|
33208
|
+
if (isArrayDestructuringExpression(templateExpression)) return "array";
|
|
33209
|
+
if (isObjectDestructuringExpression(templateExpression)) return "object";
|
|
33210
|
+
}
|
|
33211
|
+
const destructuringExample = slot.slotProps?.find((prop) => prop.destructuringExample)?.destructuringExample?.trim();
|
|
33212
|
+
if (destructuringExample) {
|
|
33213
|
+
if (isArrayDestructuringExpression(destructuringExample)) return "array";
|
|
33214
|
+
if (isObjectDestructuringExpression(destructuringExample)) return "object";
|
|
33215
|
+
}
|
|
33216
|
+
return void 0;
|
|
33217
|
+
}
|
|
33218
|
+
function getSlotBindingExample(slot, fallbackType) {
|
|
33219
|
+
const templateExpression = extractBindingExpressionFromVueTemplate(slot.vueTemplate);
|
|
33220
|
+
if (templateExpression) {
|
|
33221
|
+
return templateExpression;
|
|
33222
|
+
}
|
|
33223
|
+
const destructuringExample = slot.slotProps?.find((prop) => prop.destructuringExample)?.destructuringExample?.trim();
|
|
33224
|
+
if (destructuringExample) {
|
|
33225
|
+
return destructuringExample;
|
|
33226
|
+
}
|
|
33227
|
+
const paramNames = slot.slotProps?.map((prop) => prop.name).filter(Boolean) || [];
|
|
33228
|
+
if (paramNames.length > 0) {
|
|
33229
|
+
if (fallbackType === "single") {
|
|
33230
|
+
return paramNames[0];
|
|
33231
|
+
}
|
|
33232
|
+
return fallbackType === "array" ? `[${paramNames.join(", ")}]` : `{ ${paramNames.join(", ")} }`;
|
|
33233
|
+
}
|
|
33234
|
+
if (fallbackType === "single") {
|
|
33235
|
+
return "slotProp";
|
|
33143
33236
|
}
|
|
33237
|
+
return fallbackType === "array" ? "[slotProps]" : "{ slotProps }";
|
|
33144
33238
|
}
|
|
33145
33239
|
function typeRawAllowsNumber(typeRaw) {
|
|
33146
33240
|
if (!typeRaw) return false;
|
|
@@ -33306,7 +33400,7 @@ function checkTemplate(node, violations, ancestors) {
|
|
|
33306
33400
|
if (metadata) {
|
|
33307
33401
|
checkNestingRules(displayTag, metadata, ancestors, violations);
|
|
33308
33402
|
}
|
|
33309
|
-
checkComponentSpecificRules(displayTag, elementNode, violations);
|
|
33403
|
+
checkComponentSpecificRules(displayTag, elementNode, metadata, violations);
|
|
33310
33404
|
if (metadata) {
|
|
33311
33405
|
checkProps(displayTag, elementNode, metadata, violations);
|
|
33312
33406
|
checkEvents(displayTag, elementNode, metadata, violations);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { analyzeCodeWithAST } from './chunk-
|
|
2
|
-
import { validateRuntimePrecheck } from './chunk-
|
|
3
|
-
import { compileSFC } from './chunk-
|
|
1
|
+
import { analyzeCodeWithAST } from './chunk-IPJJMPOO.mjs';
|
|
2
|
+
import { validateRuntimePrecheck } from './chunk-6HOIRUQB.mjs';
|
|
3
|
+
import { compileSFC } from './chunk-4OTQAQ6J.mjs';
|
|
4
4
|
|
|
5
5
|
// src/tools/unifiedValidator.ts
|
|
6
6
|
function validateCompilation(code) {
|
|
@@ -120,6 +120,28 @@ async function validateCode(code) {
|
|
|
120
120
|
summary: `\u274C \u8FD0\u884C\u65F6\u9519\u8BEF: ${runtimeResult.errors[0]}`
|
|
121
121
|
};
|
|
122
122
|
}
|
|
123
|
+
if (runtimeResult.status === "env_dependent") {
|
|
124
|
+
return {
|
|
125
|
+
passed: true,
|
|
126
|
+
layers: {
|
|
127
|
+
compilation: compilationResult,
|
|
128
|
+
ast: astResult,
|
|
129
|
+
runtime: runtimeResult
|
|
130
|
+
},
|
|
131
|
+
summary: "\u26A0\uFE0F \u8FD0\u884C\u65F6\u68C0\u67E5\u53D7\u73AF\u5883\u5F71\u54CD\uFF0C\u7ED3\u679C\u4F9D\u8D56 mock"
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
if (runtimeResult.status === "runtime_skipped") {
|
|
135
|
+
return {
|
|
136
|
+
passed: true,
|
|
137
|
+
layers: {
|
|
138
|
+
compilation: compilationResult,
|
|
139
|
+
ast: astResult,
|
|
140
|
+
runtime: runtimeResult
|
|
141
|
+
},
|
|
142
|
+
summary: "\u26A0\uFE0F \u8FD0\u884C\u65F6\u68C0\u67E5\u5DF2\u964D\u7EA7\u4E3A\u8DF3\u8FC7\u4E25\u683C\u5224\u5B9A"
|
|
143
|
+
};
|
|
144
|
+
}
|
|
123
145
|
return {
|
|
124
146
|
passed: true,
|
|
125
147
|
layers: {
|
|
@@ -143,13 +165,14 @@ function validateCodeSync(code) {
|
|
|
143
165
|
};
|
|
144
166
|
}
|
|
145
167
|
const runtimeResult = validateRuntimePrecheck(code);
|
|
168
|
+
const summary = runtimeResult.passed ? runtimeResult.status === "env_dependent" ? "\u26A0\uFE0F \u8FD0\u884C\u65F6\u68C0\u67E5\u53D7\u73AF\u5883\u5F71\u54CD" : runtimeResult.status === "runtime_skipped" ? "\u26A0\uFE0F \u8FD0\u884C\u65F6\u68C0\u67E5\u5DF2\u964D\u7EA7" : "\u2705 \u68C0\u67E5\u901A\u8FC7" : `\u274C ${runtimeResult.errors[0]}`;
|
|
146
169
|
return {
|
|
147
170
|
passed: runtimeResult.passed,
|
|
148
171
|
layers: {
|
|
149
172
|
compilation: compilationResult,
|
|
150
173
|
runtime: runtimeResult
|
|
151
174
|
},
|
|
152
|
-
summary
|
|
175
|
+
summary
|
|
153
176
|
};
|
|
154
177
|
}
|
|
155
178
|
|
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkDHLWNT53_js = require('./chunk-DHLWNT53.js');
|
|
4
|
+
|
|
5
|
+
// src/runtime/index.ts
|
|
6
|
+
var scopeIdCounter = 0;
|
|
7
|
+
var ENVIRONMENT_SENSITIVE_IDENTIFIERS = [
|
|
8
|
+
"window",
|
|
9
|
+
"document",
|
|
10
|
+
"location",
|
|
11
|
+
"navigator"
|
|
12
|
+
];
|
|
13
|
+
var ENVIRONMENT_SENSITIVE_CALLS = [
|
|
14
|
+
"getCurrentInstance",
|
|
15
|
+
"useRouter",
|
|
16
|
+
"useRoute",
|
|
17
|
+
"onBeforeRouteLeave",
|
|
18
|
+
"onBeforeRouteUpdate"
|
|
19
|
+
];
|
|
20
|
+
function createMockProxy(path) {
|
|
21
|
+
const target = function mockTarget() {
|
|
22
|
+
};
|
|
23
|
+
return new Proxy(target, {
|
|
24
|
+
get: (_target, prop, receiver) => {
|
|
25
|
+
const existing = Reflect.get(target, prop, receiver);
|
|
26
|
+
if (existing !== void 0) return existing;
|
|
27
|
+
if (prop === Symbol.toPrimitive) return () => 0;
|
|
28
|
+
if (prop === "then") return void 0;
|
|
29
|
+
if (prop === "toString") return () => `[MockProxy ${path}]`;
|
|
30
|
+
if (prop === "valueOf") return () => 0;
|
|
31
|
+
if (prop === "__path") return path;
|
|
32
|
+
return createMockProxy(`${path}.${String(prop)}`);
|
|
33
|
+
},
|
|
34
|
+
apply: () => createMockProxy(`${path}()`),
|
|
35
|
+
construct: () => createMockProxy(`new ${path}()`),
|
|
36
|
+
has: (_target, prop) => Reflect.has(target, prop),
|
|
37
|
+
set: (_target, prop, value, receiver) => Reflect.set(target, prop, value, receiver)
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function createWhitelistedModule(source, context) {
|
|
41
|
+
if (source === "vue" || source.startsWith("@vue/")) {
|
|
42
|
+
return context;
|
|
43
|
+
}
|
|
44
|
+
if (source === "vue-router") {
|
|
45
|
+
return context.__mockVueRouter;
|
|
46
|
+
}
|
|
47
|
+
return new Proxy({}, {
|
|
48
|
+
get: (_target, prop) => {
|
|
49
|
+
if (prop === "default") return createMockProxy(source);
|
|
50
|
+
if (typeof prop === "string" && prop in context) {
|
|
51
|
+
return context[prop];
|
|
52
|
+
}
|
|
53
|
+
return createMockProxy(`${source}.${String(prop)}`);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function createMockElement(path) {
|
|
58
|
+
const element = createMockProxy(path);
|
|
59
|
+
element.style = {};
|
|
60
|
+
element.classList = {
|
|
61
|
+
add: () => {
|
|
62
|
+
},
|
|
63
|
+
remove: () => {
|
|
64
|
+
},
|
|
65
|
+
contains: () => false
|
|
66
|
+
};
|
|
67
|
+
element.dataset = {};
|
|
68
|
+
element.getBoundingClientRect = () => ({
|
|
69
|
+
x: 0,
|
|
70
|
+
y: 0,
|
|
71
|
+
top: 0,
|
|
72
|
+
left: 0,
|
|
73
|
+
right: 0,
|
|
74
|
+
bottom: 0,
|
|
75
|
+
width: 0,
|
|
76
|
+
height: 0
|
|
77
|
+
});
|
|
78
|
+
return element;
|
|
79
|
+
}
|
|
80
|
+
var MOCK_LOCATION = {
|
|
81
|
+
href: "https://mock.local/",
|
|
82
|
+
pathname: "/",
|
|
83
|
+
search: "",
|
|
84
|
+
hash: "",
|
|
85
|
+
origin: "https://mock.local",
|
|
86
|
+
host: "mock.local",
|
|
87
|
+
hostname: "mock.local",
|
|
88
|
+
port: "",
|
|
89
|
+
protocol: "https:",
|
|
90
|
+
assign: () => {
|
|
91
|
+
},
|
|
92
|
+
replace: () => {
|
|
93
|
+
},
|
|
94
|
+
reload: () => {
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
var MOCK_NAVIGATOR = {
|
|
98
|
+
userAgent: "king-design-analyzer-runtime-mock",
|
|
99
|
+
language: "zh-CN",
|
|
100
|
+
languages: ["zh-CN"],
|
|
101
|
+
clipboard: {
|
|
102
|
+
writeText: async () => {
|
|
103
|
+
},
|
|
104
|
+
readText: async () => ""
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
var MOCK_DOCUMENT = {
|
|
108
|
+
body: createMockElement("document.body"),
|
|
109
|
+
head: createMockElement("document.head"),
|
|
110
|
+
documentElement: createMockElement("document.documentElement"),
|
|
111
|
+
createElement: (_tag) => createMockElement("document.createElement()"),
|
|
112
|
+
createTextNode: (_text) => createMockElement("document.createTextNode()"),
|
|
113
|
+
getElementById: (_id) => createMockElement("document.getElementById()"),
|
|
114
|
+
querySelector: (_selector) => createMockElement("document.querySelector()"),
|
|
115
|
+
querySelectorAll: () => [],
|
|
116
|
+
addEventListener: () => {
|
|
117
|
+
},
|
|
118
|
+
removeEventListener: () => {
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
var MOCK_WINDOW = {
|
|
122
|
+
document: MOCK_DOCUMENT,
|
|
123
|
+
navigator: MOCK_NAVIGATOR,
|
|
124
|
+
location: MOCK_LOCATION,
|
|
125
|
+
innerWidth: 1440,
|
|
126
|
+
innerHeight: 900,
|
|
127
|
+
addEventListener: () => {
|
|
128
|
+
},
|
|
129
|
+
removeEventListener: () => {
|
|
130
|
+
},
|
|
131
|
+
matchMedia: () => ({
|
|
132
|
+
matches: false,
|
|
133
|
+
media: "",
|
|
134
|
+
onchange: null,
|
|
135
|
+
addListener: () => {
|
|
136
|
+
},
|
|
137
|
+
removeListener: () => {
|
|
138
|
+
},
|
|
139
|
+
addEventListener: () => {
|
|
140
|
+
},
|
|
141
|
+
removeEventListener: () => {
|
|
142
|
+
},
|
|
143
|
+
dispatchEvent: () => false
|
|
144
|
+
}),
|
|
145
|
+
requestAnimationFrame: (cb) => {
|
|
146
|
+
cb(0);
|
|
147
|
+
return 0;
|
|
148
|
+
},
|
|
149
|
+
cancelAnimationFrame: () => {
|
|
150
|
+
},
|
|
151
|
+
setTimeout,
|
|
152
|
+
clearTimeout,
|
|
153
|
+
setInterval,
|
|
154
|
+
clearInterval,
|
|
155
|
+
open: () => createMockProxy("window.open()")
|
|
156
|
+
};
|
|
157
|
+
var MOCK_ROUTE = {
|
|
158
|
+
path: "/",
|
|
159
|
+
name: void 0,
|
|
160
|
+
fullPath: "/",
|
|
161
|
+
params: {},
|
|
162
|
+
query: {},
|
|
163
|
+
hash: "",
|
|
164
|
+
meta: {},
|
|
165
|
+
matched: []
|
|
166
|
+
};
|
|
167
|
+
var MOCK_ROUTER = {
|
|
168
|
+
currentRoute: { value: MOCK_ROUTE },
|
|
169
|
+
push: async () => void 0,
|
|
170
|
+
replace: async () => void 0,
|
|
171
|
+
back: () => {
|
|
172
|
+
},
|
|
173
|
+
go: () => {
|
|
174
|
+
},
|
|
175
|
+
forward: () => {
|
|
176
|
+
},
|
|
177
|
+
beforeEach: () => () => {
|
|
178
|
+
},
|
|
179
|
+
afterEach: () => () => {
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
function detectEnvironmentSensitivity(code, strippedImports = []) {
|
|
183
|
+
const warnings = [];
|
|
184
|
+
let status = "passed";
|
|
185
|
+
for (const identifier of ENVIRONMENT_SENSITIVE_IDENTIFIERS) {
|
|
186
|
+
if (new RegExp(`\\b${identifier}\\b`).test(code)) {
|
|
187
|
+
warnings.push(`\u68C0\u6D4B\u5230\u6D4F\u89C8\u5668\u73AF\u5883\u5BF9\u8C61 ${identifier}\uFF0C\u8FD0\u884C\u65F6\u7ED3\u679C\u4F9D\u8D56\u5BBF\u4E3B\u73AF\u5883 mock\u3002`);
|
|
188
|
+
status = "env_dependent";
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
for (const callee of ENVIRONMENT_SENSITIVE_CALLS) {
|
|
192
|
+
if (new RegExp(`\\b${callee}\\s*\\(`).test(code)) {
|
|
193
|
+
warnings.push(`\u68C0\u6D4B\u5230\u73AF\u5883\u654F\u611F\u8C03\u7528 ${callee}()\uFF0C\u8FD0\u884C\u65F6\u7ED3\u679C\u4F9D\u8D56 mock\u3002`);
|
|
194
|
+
status = "env_dependent";
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const skippedImports = strippedImports.filter(
|
|
198
|
+
(item) => item.reason === "unknown" && !item.source.startsWith(".")
|
|
199
|
+
);
|
|
200
|
+
if (skippedImports.length > 0) {
|
|
201
|
+
status = "runtime_skipped";
|
|
202
|
+
warnings.push(
|
|
203
|
+
`\u68C0\u6D4B\u5230\u7B2C\u4E09\u65B9\u5BFC\u5165 ${skippedImports.map((item) => item.source).join(", ")}\uFF0C\u5DF2\u4F7F\u7528\u6A21\u5757 mock\uFF0C\u8FD0\u884C\u65F6\u7ED3\u679C\u4EC5\u4F9B\u53C2\u8003\u3002`
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
return { status, warnings };
|
|
207
|
+
}
|
|
208
|
+
function isEnvironmentRelatedRuntimeError(message) {
|
|
209
|
+
return /(window|document|location|navigator|getCurrentInstance|useRouter|useRoute|route|router)/i.test(message);
|
|
210
|
+
}
|
|
211
|
+
var MOCK_VUE_CONTEXT = {
|
|
212
|
+
// Reactivity
|
|
213
|
+
ref: (v) => ({ value: v }),
|
|
214
|
+
reactive: (v) => v,
|
|
215
|
+
computed: (fn) => ({ value: typeof fn === "function" ? fn() : fn }),
|
|
216
|
+
readonly: (v) => v,
|
|
217
|
+
shallowRef: (v) => ({ value: v }),
|
|
218
|
+
shallowReactive: (v) => v,
|
|
219
|
+
toRef: () => ({ value: void 0 }),
|
|
220
|
+
toRefs: (obj) => Object.fromEntries(
|
|
221
|
+
Object.keys(obj || {}).map((k) => [k, { value: obj[k] }])
|
|
222
|
+
),
|
|
223
|
+
toRaw: (v) => v,
|
|
224
|
+
markRaw: (v) => v,
|
|
225
|
+
isRef: () => false,
|
|
226
|
+
isReactive: () => false,
|
|
227
|
+
isReadonly: () => false,
|
|
228
|
+
isProxy: () => false,
|
|
229
|
+
triggerRef: () => {
|
|
230
|
+
},
|
|
231
|
+
customRef: (factory) => factory(() => {
|
|
232
|
+
}, () => {
|
|
233
|
+
}),
|
|
234
|
+
// Lifecycle
|
|
235
|
+
onMounted: () => {
|
|
236
|
+
},
|
|
237
|
+
onUnmounted: () => {
|
|
238
|
+
},
|
|
239
|
+
onBeforeMount: () => {
|
|
240
|
+
},
|
|
241
|
+
onBeforeUnmount: () => {
|
|
242
|
+
},
|
|
243
|
+
onUpdated: () => {
|
|
244
|
+
},
|
|
245
|
+
onBeforeUpdate: () => {
|
|
246
|
+
},
|
|
247
|
+
onActivated: () => {
|
|
248
|
+
},
|
|
249
|
+
onDeactivated: () => {
|
|
250
|
+
},
|
|
251
|
+
onErrorCaptured: () => {
|
|
252
|
+
},
|
|
253
|
+
// Watchers
|
|
254
|
+
watch: () => () => {
|
|
255
|
+
},
|
|
256
|
+
watchEffect: () => () => {
|
|
257
|
+
},
|
|
258
|
+
watchPostEffect: () => () => {
|
|
259
|
+
},
|
|
260
|
+
watchSyncEffect: () => () => {
|
|
261
|
+
},
|
|
262
|
+
// Composition API
|
|
263
|
+
defineProps: () => ({}),
|
|
264
|
+
defineEmits: () => () => {
|
|
265
|
+
},
|
|
266
|
+
defineExpose: () => {
|
|
267
|
+
},
|
|
268
|
+
defineOptions: () => {
|
|
269
|
+
},
|
|
270
|
+
defineSlots: () => ({}),
|
|
271
|
+
defineModel: () => ({ value: void 0 }),
|
|
272
|
+
withDefaults: (_props, defaults) => defaults,
|
|
273
|
+
useSlots: () => ({}),
|
|
274
|
+
useAttrs: () => ({}),
|
|
275
|
+
// Dependency Injection
|
|
276
|
+
inject: () => void 0,
|
|
277
|
+
provide: () => {
|
|
278
|
+
},
|
|
279
|
+
// Utilities
|
|
280
|
+
nextTick: () => Promise.resolve(),
|
|
281
|
+
getCurrentInstance: () => ({
|
|
282
|
+
proxy: createMockProxy("instance.proxy"),
|
|
283
|
+
appContext: createMockProxy("instance.appContext"),
|
|
284
|
+
emit: () => {
|
|
285
|
+
},
|
|
286
|
+
attrs: {},
|
|
287
|
+
slots: {}
|
|
288
|
+
}),
|
|
289
|
+
h: () => ({}),
|
|
290
|
+
createVNode: () => ({}),
|
|
291
|
+
resolveComponent: () => ({}),
|
|
292
|
+
// Browser-ish globals
|
|
293
|
+
window: MOCK_WINDOW,
|
|
294
|
+
document: MOCK_DOCUMENT,
|
|
295
|
+
location: MOCK_LOCATION,
|
|
296
|
+
navigator: MOCK_NAVIGATOR,
|
|
297
|
+
self: MOCK_WINDOW,
|
|
298
|
+
globalThis: MOCK_WINDOW,
|
|
299
|
+
// vue-router
|
|
300
|
+
useRouter: () => MOCK_ROUTER,
|
|
301
|
+
useRoute: () => MOCK_ROUTE,
|
|
302
|
+
onBeforeRouteLeave: () => {
|
|
303
|
+
},
|
|
304
|
+
onBeforeRouteUpdate: () => {
|
|
305
|
+
},
|
|
306
|
+
RouterLink: createMockProxy("vue-router.RouterLink"),
|
|
307
|
+
RouterView: createMockProxy("vue-router.RouterView"),
|
|
308
|
+
__mockVueRouter: {
|
|
309
|
+
useRouter: () => MOCK_ROUTER,
|
|
310
|
+
useRoute: () => MOCK_ROUTE,
|
|
311
|
+
onBeforeRouteLeave: () => {
|
|
312
|
+
},
|
|
313
|
+
onBeforeRouteUpdate: () => {
|
|
314
|
+
},
|
|
315
|
+
RouterLink: createMockProxy("vue-router.RouterLink"),
|
|
316
|
+
RouterView: createMockProxy("vue-router.RouterView"),
|
|
317
|
+
createRouter: () => createMockProxy("vue-router.createRouter()"),
|
|
318
|
+
createWebHistory: () => createMockProxy("vue-router.createWebHistory()"),
|
|
319
|
+
createWebHashHistory: () => createMockProxy("vue-router.createWebHashHistory()")
|
|
320
|
+
},
|
|
321
|
+
// =========================================================================
|
|
322
|
+
// @ksyun-internal/versatile Hooks
|
|
323
|
+
// =========================================================================
|
|
324
|
+
useToState: (_props, _key, _emit, defaultValue) => ({ value: defaultValue ?? void 0 }),
|
|
325
|
+
useIdEntity: () => ({ value: void 0 }),
|
|
326
|
+
// =========================================================================
|
|
327
|
+
// Module Mocking
|
|
328
|
+
// =========================================================================
|
|
329
|
+
__mockModule: (modulePath) => createMockProxy(modulePath),
|
|
330
|
+
__getWhitelistedModule: (source) => createWhitelistedModule(source, MOCK_VUE_CONTEXT)
|
|
331
|
+
};
|
|
332
|
+
function validateRuntimePrecheck(code) {
|
|
333
|
+
const scopeId = `runtime-${Date.now()}-${++scopeIdCounter}`;
|
|
334
|
+
const { script, bindings, strippedImports, error } = chunkDHLWNT53_js.compileSFC(code, scopeId);
|
|
335
|
+
if (error) {
|
|
336
|
+
return {
|
|
337
|
+
name: "\u8FD0\u884C\u65F6\u9884\u68C0\u67E5",
|
|
338
|
+
passed: false,
|
|
339
|
+
status: "failed",
|
|
340
|
+
errors: [error]
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
const sensitivity = detectEnvironmentSensitivity(code, strippedImports);
|
|
344
|
+
try {
|
|
345
|
+
const funcBody = `
|
|
346
|
+
"use strict";
|
|
347
|
+
${script}
|
|
348
|
+
return { ${bindings.join(", ")} };
|
|
349
|
+
`;
|
|
350
|
+
const keys = Object.keys(MOCK_VUE_CONTEXT);
|
|
351
|
+
const values = Object.values(MOCK_VUE_CONTEXT);
|
|
352
|
+
const runner = new Function(...keys, funcBody);
|
|
353
|
+
const result = runner(...values);
|
|
354
|
+
const missingBindings = bindings.filter((binding) => !(binding in result));
|
|
355
|
+
if (missingBindings.length > 0) {
|
|
356
|
+
return {
|
|
357
|
+
name: "\u8FD0\u884C\u65F6\u9884\u68C0\u67E5",
|
|
358
|
+
passed: false,
|
|
359
|
+
status: "failed",
|
|
360
|
+
errors: missingBindings.map((b) => `\u53D8\u91CF ${b} \u672A\u6B63\u786E\u5BFC\u51FA`),
|
|
361
|
+
warnings: sensitivity.warnings.length > 0 ? sensitivity.warnings : void 0
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
return {
|
|
365
|
+
name: "\u8FD0\u884C\u65F6\u9884\u68C0\u67E5",
|
|
366
|
+
passed: true,
|
|
367
|
+
status: sensitivity.status,
|
|
368
|
+
errors: [],
|
|
369
|
+
warnings: sensitivity.warnings.length > 0 ? sensitivity.warnings : void 0
|
|
370
|
+
};
|
|
371
|
+
} catch (e) {
|
|
372
|
+
const errorMessage = e.message || String(e);
|
|
373
|
+
const errorLocation = e.stack?.split("\n")[1]?.trim() || "";
|
|
374
|
+
if (sensitivity.status === "runtime_skipped") {
|
|
375
|
+
return {
|
|
376
|
+
name: "\u8FD0\u884C\u65F6\u9884\u68C0\u67E5",
|
|
377
|
+
passed: true,
|
|
378
|
+
status: "runtime_skipped",
|
|
379
|
+
errors: [],
|
|
380
|
+
warnings: [
|
|
381
|
+
...sensitivity.warnings,
|
|
382
|
+
`\u8FD0\u884C\u65F6\u6267\u884C\u5DF2\u8DF3\u8FC7\u4E25\u683C\u5224\u5B9A: ${errorMessage}`
|
|
383
|
+
]
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
if (sensitivity.status === "env_dependent" && isEnvironmentRelatedRuntimeError(errorMessage)) {
|
|
387
|
+
return {
|
|
388
|
+
name: "\u8FD0\u884C\u65F6\u9884\u68C0\u67E5",
|
|
389
|
+
passed: true,
|
|
390
|
+
status: "env_dependent",
|
|
391
|
+
errors: [],
|
|
392
|
+
warnings: [
|
|
393
|
+
...sensitivity.warnings,
|
|
394
|
+
`\u8FD0\u884C\u65F6\u6267\u884C\u53D7\u5BBF\u4E3B\u73AF\u5883\u5F71\u54CD: ${errorMessage}`
|
|
395
|
+
]
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
return {
|
|
399
|
+
name: "\u8FD0\u884C\u65F6\u9884\u68C0\u67E5",
|
|
400
|
+
passed: false,
|
|
401
|
+
status: "failed",
|
|
402
|
+
errors: [
|
|
403
|
+
`JavaScript \u6267\u884C\u9519\u8BEF: ${errorMessage}`,
|
|
404
|
+
...errorLocation ? [`\u4F4D\u7F6E: ${errorLocation}`] : []
|
|
405
|
+
],
|
|
406
|
+
warnings: sensitivity.warnings.length > 0 ? sensitivity.warnings : void 0
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
exports.validateRuntimePrecheck = validateRuntimePrecheck;
|
package/dist/full/index.d.mts
CHANGED
package/dist/full/index.d.ts
CHANGED
package/dist/full/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-
|
|
5
|
-
require('../chunk-
|
|
6
|
-
require('../chunk-
|
|
3
|
+
var chunk4WXOYU2N_js = require('../chunk-4WXOYU2N.js');
|
|
4
|
+
require('../chunk-JNRGUR3O.js');
|
|
5
|
+
require('../chunk-V5N65MRP.js');
|
|
6
|
+
require('../chunk-DHLWNT53.js');
|
|
7
7
|
require('../chunk-KF5YBEM5.js');
|
|
8
8
|
require('../chunk-JSBRDJBE.js');
|
|
9
9
|
|
|
@@ -11,9 +11,9 @@ require('../chunk-JSBRDJBE.js');
|
|
|
11
11
|
|
|
12
12
|
Object.defineProperty(exports, "validateCode", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunk4WXOYU2N_js.validateCode; }
|
|
15
15
|
});
|
|
16
16
|
Object.defineProperty(exports, "validateCodeSync", {
|
|
17
17
|
enumerable: true,
|
|
18
|
-
get: function () { return
|
|
18
|
+
get: function () { return chunk4WXOYU2N_js.validateCodeSync; }
|
|
19
19
|
});
|
package/dist/full/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { validateCode, validateCodeSync } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
3
|
-
import '../chunk-
|
|
4
|
-
import '../chunk-
|
|
1
|
+
export { validateCode, validateCodeSync } from '../chunk-LRTDTFFQ.mjs';
|
|
2
|
+
import '../chunk-IPJJMPOO.mjs';
|
|
3
|
+
import '../chunk-6HOIRUQB.mjs';
|
|
4
|
+
import '../chunk-4OTQAQ6J.mjs';
|
|
5
5
|
import '../chunk-QC6VTSA3.mjs';
|
|
6
6
|
import '../chunk-UJCSKKID.mjs';
|