king-design-analyzer 2.2.2 → 2.2.4

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.
@@ -3,10 +3,10 @@
3
3
  var chunkKF5YBEM5_js = require('./chunk-KF5YBEM5.js');
4
4
  var chunkJSBRDJBE_js = require('./chunk-JSBRDJBE.js');
5
5
  var fs = require('fs/promises');
6
- var fsSync = require('fs');
7
- var path = require('path');
6
+ var fs3 = require('fs');
7
+ var path3 = require('path');
8
8
  var compilerSfc = require('@vue/compiler-sfc');
9
- var ts = require('typescript');
9
+ var ts2 = require('typescript');
10
10
 
11
11
  function _interopNamespace(e) {
12
12
  if (e && e.__esModule) return e;
@@ -27,9 +27,9 @@ function _interopNamespace(e) {
27
27
  }
28
28
 
29
29
  var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
30
- var fsSync__namespace = /*#__PURE__*/_interopNamespace(fsSync);
31
- var path__namespace = /*#__PURE__*/_interopNamespace(path);
32
- var ts__namespace = /*#__PURE__*/_interopNamespace(ts);
30
+ var fs3__namespace = /*#__PURE__*/_interopNamespace(fs3);
31
+ var path3__namespace = /*#__PURE__*/_interopNamespace(path3);
32
+ var ts2__namespace = /*#__PURE__*/_interopNamespace(ts2);
33
33
 
34
34
  // node_modules/@vue/shared/dist/shared.cjs.prod.js
35
35
  var require_shared_cjs_prod = chunkJSBRDJBE_js.__commonJS({
@@ -16831,27 +16831,27 @@ var require_util = chunkJSBRDJBE_js.__commonJS({
16831
16831
  };
16832
16832
  }
16833
16833
  var normalize = lruMemoize(function normalize2(aPath) {
16834
- var path3 = aPath;
16834
+ var path4 = aPath;
16835
16835
  var url = urlParse(aPath);
16836
16836
  if (url) {
16837
16837
  if (!url.path) {
16838
16838
  return aPath;
16839
16839
  }
16840
- path3 = url.path;
16840
+ path4 = url.path;
16841
16841
  }
16842
- var isAbsolute = exports$1.isAbsolute(path3);
16842
+ var isAbsolute = exports$1.isAbsolute(path4);
16843
16843
  var parts = [];
16844
16844
  var start = 0;
16845
16845
  var i = 0;
16846
16846
  while (true) {
16847
16847
  start = i;
16848
- i = path3.indexOf("/", start);
16848
+ i = path4.indexOf("/", start);
16849
16849
  if (i === -1) {
16850
- parts.push(path3.slice(start));
16850
+ parts.push(path4.slice(start));
16851
16851
  break;
16852
16852
  } else {
16853
- parts.push(path3.slice(start, i));
16854
- while (i < path3.length && path3[i] === "/") {
16853
+ parts.push(path4.slice(start, i));
16854
+ while (i < path4.length && path4[i] === "/") {
16855
16855
  i++;
16856
16856
  }
16857
16857
  }
@@ -16872,18 +16872,18 @@ var require_util = chunkJSBRDJBE_js.__commonJS({
16872
16872
  }
16873
16873
  }
16874
16874
  }
16875
- path3 = parts.join("/");
16876
- if (path3 === "") {
16877
- path3 = isAbsolute ? "/" : ".";
16875
+ path4 = parts.join("/");
16876
+ if (path4 === "") {
16877
+ path4 = isAbsolute ? "/" : ".";
16878
16878
  }
16879
16879
  if (url) {
16880
- url.path = path3;
16880
+ url.path = path4;
16881
16881
  return urlGenerate(url);
16882
16882
  }
16883
- return path3;
16883
+ return path4;
16884
16884
  });
16885
16885
  exports$1.normalize = normalize;
16886
- function join3(aRoot, aPath) {
16886
+ function join4(aRoot, aPath) {
16887
16887
  if (aRoot === "") {
16888
16888
  aRoot = ".";
16889
16889
  }
@@ -16915,7 +16915,7 @@ var require_util = chunkJSBRDJBE_js.__commonJS({
16915
16915
  }
16916
16916
  return joined;
16917
16917
  }
16918
- exports$1.join = join3;
16918
+ exports$1.join = join4;
16919
16919
  exports$1.isAbsolute = function(aPath) {
16920
16920
  return aPath.charAt(0) === "/" || urlRegexp.test(aPath);
16921
16921
  };
@@ -17129,7 +17129,7 @@ var require_util = chunkJSBRDJBE_js.__commonJS({
17129
17129
  parsed.path = parsed.path.substring(0, index + 1);
17130
17130
  }
17131
17131
  }
17132
- sourceURL = join3(urlGenerate(parsed), sourceURL);
17132
+ sourceURL = join4(urlGenerate(parsed), sourceURL);
17133
17133
  }
17134
17134
  return normalize(sourceURL);
17135
17135
  }
@@ -20517,14 +20517,14 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
20517
20517
  var whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
20518
20518
  var getExpSource = (exp) => exp.type === 4 ? exp.content : exp.loc.source;
20519
20519
  var isMemberExpressionBrowser = (exp) => {
20520
- const path3 = getExpSource(exp).trim().replace(whitespaceRE, (s) => s.trim());
20520
+ const path4 = getExpSource(exp).trim().replace(whitespaceRE, (s) => s.trim());
20521
20521
  let state = 0;
20522
20522
  let stateStack = [];
20523
20523
  let currentOpenBracketCount = 0;
20524
20524
  let currentOpenParensCount = 0;
20525
20525
  let currentStringType = null;
20526
- for (let i = 0; i < path3.length; i++) {
20527
- const char = path3.charAt(i);
20526
+ for (let i = 0; i < path4.length; i++) {
20527
+ const char = path4.charAt(i);
20528
20528
  switch (state) {
20529
20529
  case 0:
20530
20530
  if (char === "[") {
@@ -20560,7 +20560,7 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
20560
20560
  } else if (char === `(`) {
20561
20561
  currentOpenParensCount++;
20562
20562
  } else if (char === `)`) {
20563
- if (i === path3.length - 1) {
20563
+ if (i === path4.length - 1) {
20564
20564
  return false;
20565
20565
  }
20566
20566
  if (!--currentOpenParensCount) {
@@ -27287,14 +27287,14 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
27287
27287
  var whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
27288
27288
  var getExpSource = (exp) => exp.type === 4 ? exp.content : exp.loc.source;
27289
27289
  var isMemberExpressionBrowser = (exp) => {
27290
- const path3 = getExpSource(exp).trim().replace(whitespaceRE, (s) => s.trim());
27290
+ const path4 = getExpSource(exp).trim().replace(whitespaceRE, (s) => s.trim());
27291
27291
  let state = 0;
27292
27292
  let stateStack = [];
27293
27293
  let currentOpenBracketCount = 0;
27294
27294
  let currentOpenParensCount = 0;
27295
27295
  let currentStringType = null;
27296
- for (let i = 0; i < path3.length; i++) {
27297
- const char = path3.charAt(i);
27296
+ for (let i = 0; i < path4.length; i++) {
27297
+ const char = path4.charAt(i);
27298
27298
  switch (state) {
27299
27299
  case 0:
27300
27300
  if (char === "[") {
@@ -27330,7 +27330,7 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
27330
27330
  } else if (char === `(`) {
27331
27331
  currentOpenParensCount++;
27332
27332
  } else if (char === `)`) {
27333
- if (i === path3.length - 1) {
27333
+ if (i === path4.length - 1) {
27334
27334
  return false;
27335
27335
  }
27336
27336
  if (!--currentOpenParensCount) {
@@ -32233,6 +32233,11 @@ var require_compiler_core = chunkJSBRDJBE_js.__commonJS({
32233
32233
  function resolveComponentsPath() {
32234
32234
  return chunkKF5YBEM5_js.resolvePackageResourceDir("components");
32235
32235
  }
32236
+ function extractImportSource(importStatement) {
32237
+ if (!importStatement) return void 0;
32238
+ const match = importStatement.match(/from\s+['"]([^'"]+)['"]/);
32239
+ return match?.[1];
32240
+ }
32236
32241
  var ComponentRegistry = class {
32237
32242
  constructor() {
32238
32243
  this.components = /* @__PURE__ */ new Map();
@@ -32260,18 +32265,27 @@ var ComponentRegistry = class {
32260
32265
  const files = await fs__namespace.readdir(this.metadataPath);
32261
32266
  for (const file of files) {
32262
32267
  if (!file.endsWith(".json")) continue;
32263
- const content = await fs__namespace.readFile(path__namespace.join(this.metadataPath, file), "utf-8");
32268
+ const content = await fs__namespace.readFile(path3__namespace.join(this.metadataPath, file), "utf-8");
32264
32269
  const data = JSON.parse(content);
32265
- rawComponents[data.name] = data;
32270
+ const importSource = data.importSource || data.source || extractImportSource(data.importStatement);
32271
+ const normalizedData = {
32272
+ ...data,
32273
+ fileName: data.fileName || file.replace(/\.json$/, ""),
32274
+ importSource,
32275
+ source: data.source || importSource
32276
+ };
32277
+ rawComponents[`${normalizedData.fileName}:${normalizedData.name}:${normalizedData.importSource || ""}`] = normalizedData;
32266
32278
  }
32267
32279
  for (const data of Object.values(rawComponents)) {
32268
32280
  const resolvedData = chunkKF5YBEM5_js.resolveMetadataInheritance(data, rawComponents);
32269
- newComponents.set(resolvedData.name, resolvedData);
32281
+ this.appendComponent(newComponents, resolvedData);
32270
32282
  if (resolvedData.subComponents) {
32271
32283
  for (const sub of resolvedData.subComponents) {
32272
- newComponents.set(sub.name, {
32284
+ this.appendComponent(newComponents, {
32273
32285
  id: sub.name,
32274
32286
  name: sub.name,
32287
+ source: resolvedData.source,
32288
+ importSource: resolvedData.importSource,
32275
32289
  props: sub.props || [],
32276
32290
  events: sub.events || [],
32277
32291
  slots: sub.slots || [],
@@ -32281,11 +32295,17 @@ var ComponentRegistry = class {
32281
32295
  }
32282
32296
  }
32283
32297
  this.components = newComponents;
32284
- console.log(`[ComponentRegistry] ${this.loaded ? "Reloaded" : "Loaded"} ${this.components.size} components.`);
32298
+ const totalEntries = Array.from(this.components.values()).reduce((sum, items) => sum + items.length, 0);
32299
+ console.log(`[ComponentRegistry] ${this.loaded ? "Reloaded" : "Loaded"} ${totalEntries} components.`);
32285
32300
  } catch (error) {
32286
32301
  console.error("[ComponentRegistry] Failed to load metadata:", error);
32287
32302
  }
32288
32303
  }
32304
+ appendComponent(target, metadata) {
32305
+ const current = target.get(metadata.name) || [];
32306
+ current.push(metadata);
32307
+ target.set(metadata.name, current);
32308
+ }
32289
32309
  /**
32290
32310
  * 开始监听文件变化
32291
32311
  */
@@ -32293,7 +32313,7 @@ var ComponentRegistry = class {
32293
32313
  if (this.watcher) return;
32294
32314
  try {
32295
32315
  let reloadTimeout = null;
32296
- this.watcher = fsSync__namespace.watch(this.metadataPath, (eventType, filename) => {
32316
+ this.watcher = fs3__namespace.watch(this.metadataPath, (eventType, filename) => {
32297
32317
  if (!filename?.endsWith(".json")) return;
32298
32318
  console.log(`[ComponentRegistry] Detected change: ${filename} (${eventType})`);
32299
32319
  if (reloadTimeout) {
@@ -32318,14 +32338,28 @@ var ComponentRegistry = class {
32318
32338
  console.log("[ComponentRegistry] Hot reload disabled.");
32319
32339
  }
32320
32340
  }
32321
- getComponent(name) {
32322
- return this.components.get(name);
32341
+ getComponent(name, importSource) {
32342
+ const candidates = this.components.get(name) || [];
32343
+ if (!importSource) return candidates[0];
32344
+ return candidates.find((item) => {
32345
+ const expectedSource = item.importSource || item.source || extractImportSource(item.importStatement);
32346
+ return expectedSource === importSource;
32347
+ }) || candidates[0];
32348
+ }
32349
+ getComponents(name) {
32350
+ return this.components.get(name) || [];
32323
32351
  }
32324
32352
  getAllComponentNames() {
32325
32353
  return Array.from(this.components.keys());
32326
32354
  }
32327
- isKnownComponent(name) {
32328
- return this.components.has(name);
32355
+ isKnownComponent(name, importSource) {
32356
+ if (!importSource) {
32357
+ return this.components.has(name);
32358
+ }
32359
+ return this.getComponents(name).some((item) => {
32360
+ const expectedSource = item.importSource || item.source || extractImportSource(item.importStatement);
32361
+ return expectedSource === importSource;
32362
+ });
32329
32363
  }
32330
32364
  };
32331
32365
  var componentRegistry = new ComponentRegistry();
@@ -32360,7 +32394,7 @@ var HooksRegistry = class {
32360
32394
  const files = await fs__namespace.readdir(this.metadataPath);
32361
32395
  for (const file of files) {
32362
32396
  if (!file.endsWith(".json")) continue;
32363
- const content = await fs__namespace.readFile(path__namespace.join(this.metadataPath, file), "utf-8");
32397
+ const content = await fs__namespace.readFile(path3__namespace.join(this.metadataPath, file), "utf-8");
32364
32398
  const data = JSON.parse(content);
32365
32399
  newHooks.set(data.name, data);
32366
32400
  }
@@ -32381,7 +32415,7 @@ var HooksRegistry = class {
32381
32415
  if (this.watcher) return;
32382
32416
  try {
32383
32417
  let reloadTimeout = null;
32384
- this.watcher = fsSync__namespace.watch(this.metadataPath, (eventType, filename) => {
32418
+ this.watcher = fs3__namespace.watch(this.metadataPath, (eventType, filename) => {
32385
32419
  if (!filename?.endsWith(".json")) return;
32386
32420
  console.log(`[HooksRegistry] Detected change: ${filename} (${eventType})`);
32387
32421
  if (reloadTimeout) {
@@ -32430,6 +32464,104 @@ var HooksRegistry = class {
32430
32464
  }
32431
32465
  };
32432
32466
  var hooksRegistry = new HooksRegistry();
32467
+ function packagePathSegments(moduleSpecifier) {
32468
+ if (moduleSpecifier.startsWith("@")) {
32469
+ return moduleSpecifier.split("/").slice(0, 2);
32470
+ }
32471
+ return [moduleSpecifier.split("/")[0]];
32472
+ }
32473
+ function resolveInstalledPackageDir(moduleSpecifier) {
32474
+ const packageRoot = chunkKF5YBEM5_js.resolvePackageRoot();
32475
+ const segments = packagePathSegments(moduleSpecifier);
32476
+ const cwd = process.cwd();
32477
+ const candidates = [
32478
+ path3__namespace.join(cwd, "node_modules", ...segments),
32479
+ path3__namespace.join(cwd, "web", "node_modules", ...segments),
32480
+ packageRoot ? path3__namespace.join(packageRoot, "node_modules", ...segments) : null,
32481
+ packageRoot ? path3__namespace.join(packageRoot, "web", "node_modules", ...segments) : null
32482
+ ].filter((candidate) => Boolean(candidate));
32483
+ return candidates.find((candidate) => fs3__namespace.existsSync(candidate)) || null;
32484
+ }
32485
+ function resolvePackageTypesEntry(moduleSpecifier) {
32486
+ const packageDir = resolveInstalledPackageDir(moduleSpecifier);
32487
+ if (!packageDir) return null;
32488
+ const packageJsonPath = path3__namespace.join(packageDir, "package.json");
32489
+ if (fs3__namespace.existsSync(packageJsonPath)) {
32490
+ try {
32491
+ const packageJson = JSON.parse(fs3__namespace.readFileSync(packageJsonPath, "utf-8"));
32492
+ const declaredEntry = packageJson.types || packageJson.typings;
32493
+ if (declaredEntry) {
32494
+ const resolved = path3__namespace.join(packageDir, declaredEntry);
32495
+ if (fs3__namespace.existsSync(resolved)) {
32496
+ return resolved;
32497
+ }
32498
+ }
32499
+ } catch {
32500
+ }
32501
+ }
32502
+ const fallbackEntry = path3__namespace.join(packageDir, "index.d.ts");
32503
+ return fs3__namespace.existsSync(fallbackEntry) ? fallbackEntry : null;
32504
+ }
32505
+ function inferExportKind(exportName, declarationFile) {
32506
+ if (!declarationFile) return /^[A-Z]/.test(exportName) ? "component" : "value";
32507
+ const normalizedFile = declarationFile.replace(/\\/g, "/");
32508
+ if (normalizedFile.includes("/components/") && /^[A-Z]/.test(exportName)) {
32509
+ return "component";
32510
+ }
32511
+ return "value";
32512
+ }
32513
+ var PackageExportRegistry = class {
32514
+ constructor() {
32515
+ this.exportsByModule = /* @__PURE__ */ new Map();
32516
+ this.loadedModules = /* @__PURE__ */ new Set();
32517
+ }
32518
+ async load(moduleSpecifier) {
32519
+ if (this.loadedModules.has(moduleSpecifier)) {
32520
+ return;
32521
+ }
32522
+ const entry = resolvePackageTypesEntry(moduleSpecifier);
32523
+ if (!entry) {
32524
+ this.loadedModules.add(moduleSpecifier);
32525
+ this.exportsByModule.set(moduleSpecifier, /* @__PURE__ */ new Map());
32526
+ return;
32527
+ }
32528
+ const program = ts2__namespace.createProgram([entry], {
32529
+ target: ts2__namespace.ScriptTarget.ES2020,
32530
+ module: ts2__namespace.ModuleKind.ESNext,
32531
+ moduleResolution: ts2__namespace.ModuleResolutionKind.NodeJs,
32532
+ skipLibCheck: true
32533
+ });
32534
+ const checker = program.getTypeChecker();
32535
+ const sourceFile = program.getSourceFile(entry);
32536
+ if (!sourceFile) {
32537
+ this.loadedModules.add(moduleSpecifier);
32538
+ this.exportsByModule.set(moduleSpecifier, /* @__PURE__ */ new Map());
32539
+ return;
32540
+ }
32541
+ const moduleSymbol = checker.getSymbolAtLocation(sourceFile);
32542
+ const exportsMap = /* @__PURE__ */ new Map();
32543
+ if (moduleSymbol) {
32544
+ for (const symbol of checker.getExportsOfModule(moduleSymbol)) {
32545
+ const declarationFile = symbol.declarations?.[0]?.getSourceFile().fileName;
32546
+ exportsMap.set(symbol.getName(), {
32547
+ name: symbol.getName(),
32548
+ moduleSpecifier,
32549
+ declarationFile,
32550
+ kind: inferExportKind(symbol.getName(), declarationFile)
32551
+ });
32552
+ }
32553
+ }
32554
+ this.exportsByModule.set(moduleSpecifier, exportsMap);
32555
+ this.loadedModules.add(moduleSpecifier);
32556
+ }
32557
+ getExport(name, moduleSpecifier) {
32558
+ return this.exportsByModule.get(moduleSpecifier)?.get(name);
32559
+ }
32560
+ isKnownExport(name, moduleSpecifier) {
32561
+ return this.exportsByModule.get(moduleSpecifier)?.has(name) || false;
32562
+ }
32563
+ };
32564
+ var packageExportRegistry = new PackageExportRegistry();
32433
32565
 
32434
32566
  // src/analysis/astReviewer.ts
32435
32567
  var VUE_BUILTINS = /* @__PURE__ */ new Set([
@@ -32768,27 +32900,30 @@ var NESTING_RULES = {
32768
32900
  async function analyzeCodeWithAST(code) {
32769
32901
  await componentRegistry.load();
32770
32902
  await hooksRegistry.load();
32903
+ await packageExportRegistry.load("@king-design/vue");
32904
+ await packageExportRegistry.load("@ksyun-internal/versatile");
32771
32905
  const violations = [];
32906
+ const componentImportContext = /* @__PURE__ */ new Map();
32772
32907
  const { descriptor, errors } = compilerSfc.parse(code);
32773
32908
  if (errors.length > 0) {
32774
32909
  return violations;
32775
32910
  }
32776
32911
  const scriptContent = descriptor.scriptSetup?.content || descriptor.script?.content || "";
32777
32912
  if (scriptContent) {
32778
- const sourceFile = ts__namespace.createSourceFile(
32913
+ const sourceFile = ts2__namespace.createSourceFile(
32779
32914
  "temp.ts",
32780
32915
  scriptContent,
32781
- ts__namespace.ScriptTarget.Latest,
32916
+ ts2__namespace.ScriptTarget.Latest,
32782
32917
  true
32783
32918
  );
32784
- ts__namespace.forEachChild(sourceFile, (node) => {
32785
- if (ts__namespace.isImportDeclaration(node)) {
32786
- checkImport(node, violations, sourceFile);
32919
+ ts2__namespace.forEachChild(sourceFile, (node) => {
32920
+ if (ts2__namespace.isImportDeclaration(node)) {
32921
+ checkImport(node, violations, sourceFile, componentImportContext);
32787
32922
  }
32788
32923
  });
32789
32924
  }
32790
32925
  if (descriptor.template?.ast) {
32791
- checkTemplate(descriptor.template.ast, violations, []);
32926
+ checkTemplate(descriptor.template.ast, violations, [], componentImportContext);
32792
32927
  }
32793
32928
  if (scriptContent && descriptor.template) {
32794
32929
  const scriptBindings = extractScriptBindings(scriptContent);
@@ -32806,25 +32941,25 @@ function extractScriptBindings(scriptContent) {
32806
32941
  JS_GLOBALS.forEach((b) => bindings.add(b));
32807
32942
  try {
32808
32943
  let extractNames2 = function(name) {
32809
- if (ts__namespace.isIdentifier(name)) {
32944
+ if (ts2__namespace.isIdentifier(name)) {
32810
32945
  bindings.add(name.text);
32811
- } else if (ts__namespace.isObjectBindingPattern(name) || ts__namespace.isArrayBindingPattern(name)) {
32946
+ } else if (ts2__namespace.isObjectBindingPattern(name) || ts2__namespace.isArrayBindingPattern(name)) {
32812
32947
  name.elements.forEach((element) => {
32813
- if (ts__namespace.isBindingElement(element)) {
32948
+ if (ts2__namespace.isBindingElement(element)) {
32814
32949
  extractNames2(element.name);
32815
32950
  }
32816
32951
  });
32817
32952
  }
32818
32953
  }, visit2 = function(node) {
32819
- if (ts__namespace.isVariableStatement(node)) {
32954
+ if (ts2__namespace.isVariableStatement(node)) {
32820
32955
  node.declarationList.declarations.forEach((decl) => extractNames2(decl.name));
32821
- } else if (ts__namespace.isFunctionDeclaration(node) && node.name) {
32956
+ } else if (ts2__namespace.isFunctionDeclaration(node) && node.name) {
32822
32957
  bindings.add(node.name.text);
32823
- } else if (ts__namespace.isClassDeclaration(node) && node.name) {
32958
+ } else if (ts2__namespace.isClassDeclaration(node) && node.name) {
32824
32959
  bindings.add(node.name.text);
32825
- } else if (ts__namespace.isImportDeclaration(node)) {
32960
+ } else if (ts2__namespace.isImportDeclaration(node)) {
32826
32961
  const namedBindings = node.importClause?.namedBindings;
32827
- if (namedBindings && ts__namespace.isNamedImports(namedBindings)) {
32962
+ if (namedBindings && ts2__namespace.isNamedImports(namedBindings)) {
32828
32963
  namedBindings.elements.forEach((element) => {
32829
32964
  bindings.add(element.name.text);
32830
32965
  });
@@ -32835,10 +32970,10 @@ function extractScriptBindings(scriptContent) {
32835
32970
  }
32836
32971
  };
32837
32972
  var extractNames = extractNames2, visit = visit2;
32838
- const sourceFile = ts__namespace.createSourceFile(
32973
+ const sourceFile = ts2__namespace.createSourceFile(
32839
32974
  "temp.ts",
32840
32975
  scriptContent,
32841
- ts__namespace.ScriptTarget.Latest,
32976
+ ts2__namespace.ScriptTarget.Latest,
32842
32977
  true
32843
32978
  );
32844
32979
  sourceFile.statements.forEach(visit2);
@@ -32850,9 +32985,9 @@ function extractScriptBindings(scriptContent) {
32850
32985
  function checkScriptFunctionCalls(scriptContent, bindings, violations) {
32851
32986
  try {
32852
32987
  let visit2 = function(node) {
32853
- if (ts__namespace.isCallExpression(node)) {
32988
+ if (ts2__namespace.isCallExpression(node)) {
32854
32989
  const callee = node.expression;
32855
- if (ts__namespace.isIdentifier(callee)) {
32990
+ if (ts2__namespace.isIdentifier(callee)) {
32856
32991
  const funcName = callee.text;
32857
32992
  const isHookCall = funcName.startsWith("use") && funcName.length > 3 && funcName[3] === funcName[3].toUpperCase();
32858
32993
  if (isHookCall) {
@@ -32866,16 +33001,16 @@ function checkScriptFunctionCalls(scriptContent, bindings, violations) {
32866
33001
  }
32867
33002
  }
32868
33003
  }
32869
- ts__namespace.forEachChild(node, visit2);
33004
+ ts2__namespace.forEachChild(node, visit2);
32870
33005
  };
32871
33006
  var visit = visit2;
32872
- const sourceFile = ts__namespace.createSourceFile(
33007
+ const sourceFile = ts2__namespace.createSourceFile(
32873
33008
  "temp.ts",
32874
33009
  scriptContent,
32875
- ts__namespace.ScriptTarget.Latest,
33010
+ ts2__namespace.ScriptTarget.Latest,
32876
33011
  true
32877
33012
  );
32878
- ts__namespace.forEachChild(sourceFile, visit2);
33013
+ ts2__namespace.forEachChild(sourceFile, visit2);
32879
33014
  } catch (err) {
32880
33015
  }
32881
33016
  }
@@ -32988,7 +33123,7 @@ function extractIdentifiersFromExpression(expression) {
32988
33123
  }
32989
33124
  }
32990
33125
  const cleanExpr = expression.replace(/'[^']*'/g, "").replace(/"[^"]*"/g, "").replace(/`[^`]*`/g, "");
32991
- const idRegex = /(?:^|[^.\w$])([a-zA-Z_$][\w$]*)\b(?!\s*:)/g;
33126
+ const idRegex = /(?:^|[^.\w$])([a-zA-Z_$][\w$]*)(?![\w$])(?!\s*:)/g;
32992
33127
  let match;
32993
33128
  while ((match = idRegex.exec(cleanExpr)) !== null) {
32994
33129
  const id = match[1];
@@ -33005,6 +33140,7 @@ function isJsKeyword(id) {
33005
33140
  return JS_KEYWORDS.has(id);
33006
33141
  }
33007
33142
  function resolveExpectedImportSource(metadata) {
33143
+ if (metadata.importSource) return metadata.importSource;
33008
33144
  const importStatement = metadata.importStatement || "";
33009
33145
  if (importStatement.includes("@ksyun-internal/versatile")) {
33010
33146
  return "@ksyun-internal/versatile";
@@ -33014,11 +33150,11 @@ function resolveExpectedImportSource(metadata) {
33014
33150
  }
33015
33151
  return null;
33016
33152
  }
33017
- function checkImport(node, violations, sourceFile) {
33153
+ function checkImport(node, violations, sourceFile, componentImportContext) {
33018
33154
  const moduleSpecifier = node.moduleSpecifier.getText(sourceFile).replace(/['\"]/g, "");
33019
33155
  if (moduleSpecifier === "@king-design/vue" || moduleSpecifier === "@ksyun-internal/versatile") {
33020
33156
  const namedBindings = node.importClause?.namedBindings;
33021
- if (namedBindings && ts__namespace.isNamedImports(namedBindings)) {
33157
+ if (namedBindings && ts2__namespace.isNamedImports(namedBindings)) {
33022
33158
  namedBindings.elements.forEach((element) => {
33023
33159
  const originalName = element.propertyName ? element.propertyName.text : element.name.text;
33024
33160
  const localName = element.name.text;
@@ -33050,14 +33186,16 @@ function checkImport(node, violations, sourceFile) {
33050
33186
  }
33051
33187
  return;
33052
33188
  }
33053
- if (isAlias) {
33189
+ componentImportContext.set(localName, moduleSpecifier);
33190
+ const metadata = componentRegistry.getComponent(originalName, moduleSpecifier);
33191
+ const packageExport = packageExportRegistry.getExport(originalName, moduleSpecifier);
33192
+ if (isAlias && (metadata || packageExport?.kind === "component")) {
33054
33193
  violations.push({
33055
33194
  rule: `\u7981\u6B62\u5BF9\u7EC4\u4EF6 ${originalName} \u4F7F\u7528\u522B\u540D\u5BFC\u5165`,
33056
33195
  match: `${originalName} as ${localName}`,
33057
33196
  suggestion: `\u76F4\u63A5\u4F7F\u7528\u539F\u540D: import { ${originalName} } from '${moduleSpecifier}'`
33058
33197
  });
33059
33198
  }
33060
- const metadata = componentRegistry.getComponent(originalName);
33061
33199
  if (metadata) {
33062
33200
  const expectedPackage = resolveExpectedImportSource(metadata);
33063
33201
  if (expectedPackage && expectedPackage !== moduleSpecifier) {
@@ -33068,11 +33206,24 @@ function checkImport(node, violations, sourceFile) {
33068
33206
  });
33069
33207
  }
33070
33208
  } else {
33071
- violations.push({
33072
- rule: "\u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684\u7EC4\u4EF6/\u5BFC\u51FA",
33073
- match: originalName,
33074
- suggestion: `\u8BF7\u786E\u8BA4 ${originalName} \u662F\u5426\u5B58\u5728\u4E8E ${moduleSpecifier}\u3002\u5EFA\u8BAE\u67E5\u770B\u6587\u6863\u3002`
33075
- });
33209
+ if (packageExport) {
33210
+ return;
33211
+ }
33212
+ const knownMetadata = componentRegistry.getComponent(originalName);
33213
+ if (knownMetadata) {
33214
+ const expectedPackage = resolveExpectedImportSource(knownMetadata);
33215
+ violations.push({
33216
+ rule: `\u7EC4\u4EF6 ${originalName} \u5BFC\u5165\u6E90\u9519\u8BEF`,
33217
+ match: `import { ... } from '${moduleSpecifier}'`,
33218
+ suggestion: expectedPackage ? `\u5E94\u4ECE '${expectedPackage}' \u5BFC\u5165` : `\u8BF7\u786E\u8BA4 ${originalName} \u7684\u5BFC\u5165\u6765\u6E90`
33219
+ });
33220
+ } else {
33221
+ violations.push({
33222
+ rule: "\u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684\u7EC4\u4EF6/\u5BFC\u51FA",
33223
+ match: originalName,
33224
+ suggestion: `\u8BF7\u786E\u8BA4 ${originalName} \u662F\u5426\u5B58\u5728\u4E8E ${moduleSpecifier}\u3002\u5EFA\u8BAE\u67E5\u770B\u6587\u6863\u3002`
33225
+ });
33226
+ }
33076
33227
  }
33077
33228
  });
33078
33229
  }
@@ -33321,14 +33472,16 @@ function checkEvents(tagName, node, metadata, violations) {
33321
33472
  function kebabTagToPascalTag(tag) {
33322
33473
  return tag.split("-").map((part) => part.length ? part.charAt(0).toUpperCase() + part.slice(1).toLowerCase() : "").join("");
33323
33474
  }
33324
- function resolveRegisteredComponent(tag) {
33325
- if (componentRegistry.isKnownComponent(tag)) {
33326
- return componentRegistry.getComponent(tag);
33475
+ function resolveRegisteredComponent(tag, componentImportContext) {
33476
+ const directImportSource = componentImportContext?.get(tag);
33477
+ if (componentRegistry.isKnownComponent(tag, directImportSource)) {
33478
+ return componentRegistry.getComponent(tag, directImportSource);
33327
33479
  }
33328
33480
  if (tag.includes("-")) {
33329
33481
  const pascal = kebabTagToPascalTag(tag);
33330
- if (componentRegistry.isKnownComponent(pascal)) {
33331
- return componentRegistry.getComponent(pascal);
33482
+ const pascalImportSource = componentImportContext?.get(pascal);
33483
+ if (componentRegistry.isKnownComponent(pascal, pascalImportSource)) {
33484
+ return componentRegistry.getComponent(pascal, pascalImportSource);
33332
33485
  }
33333
33486
  }
33334
33487
  return void 0;
@@ -33375,11 +33528,11 @@ function checkSlots(tagName, node, metadata, violations) {
33375
33528
  });
33376
33529
  }
33377
33530
  }
33378
- function checkTemplate(node, violations, ancestors) {
33531
+ function checkTemplate(node, violations, ancestors, componentImportContext) {
33379
33532
  if (node.type === 1) {
33380
33533
  const elementNode = node;
33381
33534
  const tagName = elementNode.tag;
33382
- const metadata = resolveRegisteredComponent(tagName);
33535
+ const metadata = resolveRegisteredComponent(tagName, componentImportContext);
33383
33536
  const displayTag = metadata?.name ?? tagName;
33384
33537
  if (metadata) {
33385
33538
  checkNestingRules(displayTag, metadata, ancestors, violations);
@@ -33395,12 +33548,12 @@ function checkTemplate(node, violations, ancestors) {
33395
33548
  let newAncestors = ancestors;
33396
33549
  if (node.type === 1 && "tag" in node) {
33397
33550
  const el = node;
33398
- const meta = resolveRegisteredComponent(el.tag);
33551
+ const meta = resolveRegisteredComponent(el.tag, componentImportContext);
33399
33552
  newAncestors = [...ancestors, meta?.name ?? el.tag];
33400
33553
  }
33401
33554
  node.children.forEach((child) => {
33402
33555
  if (typeof child === "object" && child !== null && "type" in child) {
33403
- checkTemplate(child, violations, newAncestors);
33556
+ checkTemplate(child, violations, newAncestors, componentImportContext);
33404
33557
  }
33405
33558
  });
33406
33559
  }
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkXPHDD6XR_js = require('./chunk-XPHDD6XR.js');
3
+ var chunk4ZZ6E4RS_js = require('./chunk-4ZZ6E4RS.js');
4
4
  var chunkV5N65MRP_js = require('./chunk-V5N65MRP.js');
5
5
  var chunkDHLWNT53_js = require('./chunk-DHLWNT53.js');
6
6
 
@@ -64,7 +64,7 @@ function validateCompilation(code) {
64
64
  }
65
65
  async function validateAST(code) {
66
66
  try {
67
- const violations = await chunkXPHDD6XR_js.analyzeCodeWithAST(code);
67
+ const violations = await chunk4ZZ6E4RS_js.analyzeCodeWithAST(code);
68
68
  if (violations.length > 0) {
69
69
  return {
70
70
  name: "AST\u89C4\u5219\u68C0\u67E5",
@@ -1,4 +1,4 @@
1
- import { analyzeCodeWithAST } from './chunk-YRGYDK2I.mjs';
1
+ import { analyzeCodeWithAST } from './chunk-ZW3HD2OD.mjs';
2
2
  import { validateRuntimePrecheck } from './chunk-6HOIRUQB.mjs';
3
3
  import { compileSFC } from './chunk-4OTQAQ6J.mjs';
4
4