king-design-analyzer 1.0.1 → 1.0.2

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  'use strict';
2
2
 
3
3
  require('../chunk-YTEYDSDW.js');
4
- var chunk5IF32MBB_js = require('../chunk-5IF32MBB.js');
4
+ var chunkDVIHET2R_js = require('../chunk-DVIHET2R.js');
5
5
 
6
6
 
7
7
 
8
8
  Object.defineProperty(exports, "analyzeCodeWithAST", {
9
9
  enumerable: true,
10
- get: function () { return chunk5IF32MBB_js.analyzeCodeWithAST; }
10
+ get: function () { return chunkDVIHET2R_js.analyzeCodeWithAST; }
11
11
  });
12
12
  Object.defineProperty(exports, "componentRegistry", {
13
13
  enumerable: true,
14
- get: function () { return chunk5IF32MBB_js.componentRegistry; }
14
+ get: function () { return chunkDVIHET2R_js.componentRegistry; }
15
15
  });
@@ -1,2 +1,2 @@
1
1
  import '../chunk-5H7N2A5X.mjs';
2
- export { analyzeCodeWithAST, componentRegistry } from '../chunk-C3L4IXJC.mjs';
2
+ export { analyzeCodeWithAST, componentRegistry } from '../chunk-FT4HL7ZJ.mjs';
@@ -1,4 +1,4 @@
1
- import { compileSFC } from './chunk-TB6BF5TJ.mjs';
1
+ import { compileSFC } from './chunk-RPNK7QXK.mjs';
2
2
 
3
3
  // src/runtime/index.ts
4
4
  function validateRuntimePrecheck(code) {
@@ -1,4 +1,4 @@
1
- import { compileSFC } from './chunk-TB6BF5TJ.mjs';
1
+ import { compileSFC } from './chunk-RPNK7QXK.mjs';
2
2
 
3
3
  // src/static/index.ts
4
4
  function validateCompilation(code) {
@@ -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?.content) {
145
+ if (scriptContent && descriptor.template) {
146
146
  const scriptBindings = extractScriptBindings(scriptContent);
147
- checkTemplateVariables(descriptor.template.content, scriptBindings, violations);
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 visit2 = function(node) {
216
- if (ts__namespace.isVariableDeclaration(node) && ts__namespace.isIdentifier(node.name)) {
217
- bindings.add(node.name.text);
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(templateContent, bindings, violations) {
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 (!bindings.has(id) && !isTemplateBuiltin(id)) {
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 (!bindings.has(id) && !isTemplateBuiltin(id)) {
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
- if (expression.includes("(") || expression.includes("=")) continue;
286
- const identifiers = extractIdentifiersFromExpression(expression);
322
+ const { identifiers, locals } = extractIdentifiersFromExpression(expression);
323
+ const combinedBindings = /* @__PURE__ */ new Set([...allBindings, ...locals]);
287
324
  for (const id of identifiers) {
288
- if (!bindings.has(id) && !isTemplateBuiltin(id)) {
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\u51FD\u6570 ${id}`
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 idRegex = /\b([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g;
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(expression)) !== null) {
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"],
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkGNVCC37B_js = require('./chunk-GNVCC37B.js');
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 = chunkGNVCC37B_js.compileSFC(code, scopeId);
42
+ const result = chunkUIHTWWBN_js.compileSFC(code, scopeId);
43
43
  if (result.error) {
44
44
  return {
45
45
  name: "\u7F16\u8BD1\u68C0\u67E5",
@@ -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?.content) {
120
+ if (scriptContent && descriptor.template) {
121
121
  const scriptBindings = extractScriptBindings(scriptContent);
122
- checkTemplateVariables(descriptor.template.content, scriptBindings, violations);
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 visit2 = function(node) {
191
- if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name)) {
192
- bindings.add(node.name.text);
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(templateContent, bindings, violations) {
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 (!bindings.has(id) && !isTemplateBuiltin(id)) {
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 (!bindings.has(id) && !isTemplateBuiltin(id)) {
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
- if (expression.includes("(") || expression.includes("=")) continue;
261
- const identifiers = extractIdentifiersFromExpression(expression);
297
+ const { identifiers, locals } = extractIdentifiersFromExpression(expression);
298
+ const combinedBindings = /* @__PURE__ */ new Set([...allBindings, ...locals]);
262
299
  for (const id of identifiers) {
263
- if (!bindings.has(id) && !isTemplateBuiltin(id)) {
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\u51FD\u6570 ${id}`
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 idRegex = /\b([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g;
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(expression)) !== null) {
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"],
@@ -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
- const lines = cleanScript.split("\n");
39
- let baseIndent = -1;
40
- for (const line of lines) {
41
- if (line.trim()) {
42
- const match = line.match(/^(\s*)/);
43
- if (match && match[1] !== void 0) {
44
- baseIndent = match[1].length;
45
- break;
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
- const arrMatch = trimmed.match(/^(?:const|let|var)\s+\[([^\]]+)\]\s*=/);
72
- if (arrMatch && typeof arrMatch[1] === "string") {
73
- const content = arrMatch[1];
74
- const vars = content.split(",").map((v) => v.trim());
75
- vars.forEach((v) => {
76
- if (v && /^[a-zA-Z_$][\w$]*$/.test(v)) varNames.push(v);
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: [...new Set(varNames)]
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
- const lines = cleanScript.split("\n");
41
- let baseIndent = -1;
42
- for (const line of lines) {
43
- if (line.trim()) {
44
- const match = line.match(/^(\s*)/);
45
- if (match && match[1] !== void 0) {
46
- baseIndent = match[1].length;
47
- break;
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
- const arrMatch = trimmed.match(/^(?:const|let|var)\s+\[([^\]]+)\]\s*=/);
74
- if (arrMatch && typeof arrMatch[1] === "string") {
75
- const content = arrMatch[1];
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: [...new Set(varNames)]
95
+ bindings: [...varNames]
89
96
  };
90
97
  } catch (e) {
91
98
  return {
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
- var chunkGNVCC37B_js = require('./chunk-GNVCC37B.js');
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 } = chunkGNVCC37B_js.compileSFC(code, scopeId);
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,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunk5IF32MBB_js = require('./chunk-5IF32MBB.js');
4
- var chunkGNVCC37B_js = require('./chunk-GNVCC37B.js');
3
+ var chunkDVIHET2R_js = require('./chunk-DVIHET2R.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 = chunkGNVCC37B_js.compileSFC(code, scopeId);
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 chunk5IF32MBB_js.analyzeCodeWithAST(code);
66
+ const violations = await chunkDVIHET2R_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 } = chunkGNVCC37B_js.compileSFC(code, scopeId);
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,5 +1,5 @@
1
- import { analyzeCodeWithAST } from './chunk-C3L4IXJC.mjs';
2
- import { compileSFC } from './chunk-TB6BF5TJ.mjs';
1
+ import { analyzeCodeWithAST } from './chunk-FT4HL7ZJ.mjs';
2
+ import { compileSFC } from './chunk-RPNK7QXK.mjs';
3
3
 
4
4
  // src/tools/unifiedValidator.ts
5
5
  function validateCompilation(code) {
@@ -1,16 +1,16 @@
1
1
  'use strict';
2
2
 
3
- var chunkARWRNWDW_js = require('../chunk-ARWRNWDW.js');
4
- require('../chunk-5IF32MBB.js');
5
- require('../chunk-GNVCC37B.js');
3
+ var chunkWULARPGF_js = require('../chunk-WULARPGF.js');
4
+ require('../chunk-DVIHET2R.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 chunkARWRNWDW_js.validateCode; }
11
+ get: function () { return chunkWULARPGF_js.validateCode; }
12
12
  });
13
13
  Object.defineProperty(exports, "validateCodeSync", {
14
14
  enumerable: true,
15
- get: function () { return chunkARWRNWDW_js.validateCodeSync; }
15
+ get: function () { return chunkWULARPGF_js.validateCodeSync; }
16
16
  });
@@ -1,3 +1,3 @@
1
- export { validateCode, validateCodeSync } from '../chunk-RAMIBZAU.mjs';
2
- import '../chunk-C3L4IXJC.mjs';
3
- import '../chunk-TB6BF5TJ.mjs';
1
+ export { validateCode, validateCodeSync } from '../chunk-YP57ELM4.mjs';
2
+ import '../chunk-FT4HL7ZJ.mjs';
3
+ import '../chunk-RPNK7QXK.mjs';
package/dist/index.js CHANGED
@@ -1,43 +1,43 @@
1
1
  'use strict';
2
2
 
3
- var chunkRNQHI7YG_js = require('./chunk-RNQHI7YG.js');
3
+ var chunkFQBDUMJD_js = require('./chunk-FQBDUMJD.js');
4
4
  require('./chunk-YTEYDSDW.js');
5
- var chunkN4UIA6DN_js = require('./chunk-N4UIA6DN.js');
6
- var chunkARWRNWDW_js = require('./chunk-ARWRNWDW.js');
7
- var chunk5IF32MBB_js = require('./chunk-5IF32MBB.js');
8
- var chunkGNVCC37B_js = require('./chunk-GNVCC37B.js');
5
+ var chunkVF5B4PW7_js = require('./chunk-VF5B4PW7.js');
6
+ var chunkWULARPGF_js = require('./chunk-WULARPGF.js');
7
+ var chunkDVIHET2R_js = require('./chunk-DVIHET2R.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 chunkRNQHI7YG_js.validateCompilation; }
14
+ get: function () { return chunkFQBDUMJD_js.validateCompilation; }
15
15
  });
16
16
  Object.defineProperty(exports, "validateRuntimePrecheck", {
17
17
  enumerable: true,
18
- get: function () { return chunkN4UIA6DN_js.validateRuntimePrecheck; }
18
+ get: function () { return chunkVF5B4PW7_js.validateRuntimePrecheck; }
19
19
  });
20
20
  Object.defineProperty(exports, "validateCode", {
21
21
  enumerable: true,
22
- get: function () { return chunkARWRNWDW_js.validateCode; }
22
+ get: function () { return chunkWULARPGF_js.validateCode; }
23
23
  });
24
24
  Object.defineProperty(exports, "validateCodeSync", {
25
25
  enumerable: true,
26
- get: function () { return chunkARWRNWDW_js.validateCodeSync; }
26
+ get: function () { return chunkWULARPGF_js.validateCodeSync; }
27
27
  });
28
28
  Object.defineProperty(exports, "analyzeCodeWithAST", {
29
29
  enumerable: true,
30
- get: function () { return chunk5IF32MBB_js.analyzeCodeWithAST; }
30
+ get: function () { return chunkDVIHET2R_js.analyzeCodeWithAST; }
31
31
  });
32
32
  Object.defineProperty(exports, "componentRegistry", {
33
33
  enumerable: true,
34
- get: function () { return chunk5IF32MBB_js.componentRegistry; }
34
+ get: function () { return chunkDVIHET2R_js.componentRegistry; }
35
35
  });
36
36
  Object.defineProperty(exports, "compileSFC", {
37
37
  enumerable: true,
38
- get: function () { return chunkGNVCC37B_js.compileSFC; }
38
+ get: function () { return chunkUIHTWWBN_js.compileSFC; }
39
39
  });
40
40
  Object.defineProperty(exports, "scopeStyles", {
41
41
  enumerable: true,
42
- get: function () { return chunkGNVCC37B_js.scopeStyles; }
42
+ get: function () { return chunkUIHTWWBN_js.scopeStyles; }
43
43
  });
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
- export { validateCompilation } from './chunk-4BUGNH4F.mjs';
1
+ export { validateCompilation } from './chunk-DJVJXIT7.mjs';
2
2
  import './chunk-5H7N2A5X.mjs';
3
- export { validateRuntimePrecheck } from './chunk-UX7KGX45.mjs';
4
- export { validateCode, validateCodeSync } from './chunk-RAMIBZAU.mjs';
5
- export { analyzeCodeWithAST, componentRegistry } from './chunk-C3L4IXJC.mjs';
6
- export { compileSFC, scopeStyles } from './chunk-TB6BF5TJ.mjs';
3
+ export { validateRuntimePrecheck } from './chunk-DHO63GQC.mjs';
4
+ export { validateCode, validateCodeSync } from './chunk-YP57ELM4.mjs';
5
+ export { analyzeCodeWithAST, componentRegistry } from './chunk-FT4HL7ZJ.mjs';
6
+ export { compileSFC, scopeStyles } from './chunk-RPNK7QXK.mjs';
@@ -1,15 +1,15 @@
1
1
  'use strict';
2
2
 
3
- var chunkN4UIA6DN_js = require('../chunk-N4UIA6DN.js');
4
- var chunkGNVCC37B_js = require('../chunk-GNVCC37B.js');
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 chunkN4UIA6DN_js.validateRuntimePrecheck; }
10
+ get: function () { return chunkVF5B4PW7_js.validateRuntimePrecheck; }
11
11
  });
12
12
  Object.defineProperty(exports, "compileSFC", {
13
13
  enumerable: true,
14
- get: function () { return chunkGNVCC37B_js.compileSFC; }
14
+ get: function () { return chunkUIHTWWBN_js.compileSFC; }
15
15
  });
@@ -1,2 +1,2 @@
1
- export { validateRuntimePrecheck } from '../chunk-UX7KGX45.mjs';
2
- export { compileSFC } from '../chunk-TB6BF5TJ.mjs';
1
+ export { validateRuntimePrecheck } from '../chunk-DHO63GQC.mjs';
2
+ export { compileSFC } from '../chunk-RPNK7QXK.mjs';
@@ -1,19 +1,19 @@
1
1
  'use strict';
2
2
 
3
- var chunkRNQHI7YG_js = require('../chunk-RNQHI7YG.js');
4
- var chunkGNVCC37B_js = require('../chunk-GNVCC37B.js');
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 chunkRNQHI7YG_js.validateCompilation; }
10
+ get: function () { return chunkFQBDUMJD_js.validateCompilation; }
11
11
  });
12
12
  Object.defineProperty(exports, "compileSFC", {
13
13
  enumerable: true,
14
- get: function () { return chunkGNVCC37B_js.compileSFC; }
14
+ get: function () { return chunkUIHTWWBN_js.compileSFC; }
15
15
  });
16
16
  Object.defineProperty(exports, "scopeStyles", {
17
17
  enumerable: true,
18
- get: function () { return chunkGNVCC37B_js.scopeStyles; }
18
+ get: function () { return chunkUIHTWWBN_js.scopeStyles; }
19
19
  });
@@ -1,2 +1,2 @@
1
- export { validateCompilation } from '../chunk-4BUGNH4F.mjs';
2
- export { compileSFC, scopeStyles } from '../chunk-TB6BF5TJ.mjs';
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.1",
3
+ "version": "1.0.2",
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",