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.
@@ -1,10 +1,10 @@
1
- import { resolveMetadataInheritance, resolvePackageResourceDir } from './chunk-QC6VTSA3.mjs';
1
+ import { resolveMetadataInheritance, resolvePackageResourceDir, resolvePackageRoot } from './chunk-QC6VTSA3.mjs';
2
2
  import { __commonJS, __toESM } from './chunk-UJCSKKID.mjs';
3
3
  import * as fs from 'fs/promises';
4
- import * as fsSync from 'fs';
5
- import * as path from 'path';
4
+ import * as fs3 from 'fs';
5
+ import * as path3 from 'path';
6
6
  import { parse } from '@vue/compiler-sfc';
7
- import * as ts from 'typescript';
7
+ import * as ts2 from 'typescript';
8
8
 
9
9
  // node_modules/@vue/shared/dist/shared.cjs.prod.js
10
10
  var require_shared_cjs_prod = __commonJS({
@@ -16806,27 +16806,27 @@ var require_util = __commonJS({
16806
16806
  };
16807
16807
  }
16808
16808
  var normalize = lruMemoize(function normalize2(aPath) {
16809
- var path3 = aPath;
16809
+ var path4 = aPath;
16810
16810
  var url = urlParse(aPath);
16811
16811
  if (url) {
16812
16812
  if (!url.path) {
16813
16813
  return aPath;
16814
16814
  }
16815
- path3 = url.path;
16815
+ path4 = url.path;
16816
16816
  }
16817
- var isAbsolute = exports$1.isAbsolute(path3);
16817
+ var isAbsolute = exports$1.isAbsolute(path4);
16818
16818
  var parts = [];
16819
16819
  var start = 0;
16820
16820
  var i = 0;
16821
16821
  while (true) {
16822
16822
  start = i;
16823
- i = path3.indexOf("/", start);
16823
+ i = path4.indexOf("/", start);
16824
16824
  if (i === -1) {
16825
- parts.push(path3.slice(start));
16825
+ parts.push(path4.slice(start));
16826
16826
  break;
16827
16827
  } else {
16828
- parts.push(path3.slice(start, i));
16829
- while (i < path3.length && path3[i] === "/") {
16828
+ parts.push(path4.slice(start, i));
16829
+ while (i < path4.length && path4[i] === "/") {
16830
16830
  i++;
16831
16831
  }
16832
16832
  }
@@ -16847,18 +16847,18 @@ var require_util = __commonJS({
16847
16847
  }
16848
16848
  }
16849
16849
  }
16850
- path3 = parts.join("/");
16851
- if (path3 === "") {
16852
- path3 = isAbsolute ? "/" : ".";
16850
+ path4 = parts.join("/");
16851
+ if (path4 === "") {
16852
+ path4 = isAbsolute ? "/" : ".";
16853
16853
  }
16854
16854
  if (url) {
16855
- url.path = path3;
16855
+ url.path = path4;
16856
16856
  return urlGenerate(url);
16857
16857
  }
16858
- return path3;
16858
+ return path4;
16859
16859
  });
16860
16860
  exports$1.normalize = normalize;
16861
- function join3(aRoot, aPath) {
16861
+ function join4(aRoot, aPath) {
16862
16862
  if (aRoot === "") {
16863
16863
  aRoot = ".";
16864
16864
  }
@@ -16890,7 +16890,7 @@ var require_util = __commonJS({
16890
16890
  }
16891
16891
  return joined;
16892
16892
  }
16893
- exports$1.join = join3;
16893
+ exports$1.join = join4;
16894
16894
  exports$1.isAbsolute = function(aPath) {
16895
16895
  return aPath.charAt(0) === "/" || urlRegexp.test(aPath);
16896
16896
  };
@@ -17104,7 +17104,7 @@ var require_util = __commonJS({
17104
17104
  parsed.path = parsed.path.substring(0, index + 1);
17105
17105
  }
17106
17106
  }
17107
- sourceURL = join3(urlGenerate(parsed), sourceURL);
17107
+ sourceURL = join4(urlGenerate(parsed), sourceURL);
17108
17108
  }
17109
17109
  return normalize(sourceURL);
17110
17110
  }
@@ -20492,14 +20492,14 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
20492
20492
  var whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
20493
20493
  var getExpSource = (exp) => exp.type === 4 ? exp.content : exp.loc.source;
20494
20494
  var isMemberExpressionBrowser = (exp) => {
20495
- const path3 = getExpSource(exp).trim().replace(whitespaceRE, (s) => s.trim());
20495
+ const path4 = getExpSource(exp).trim().replace(whitespaceRE, (s) => s.trim());
20496
20496
  let state = 0;
20497
20497
  let stateStack = [];
20498
20498
  let currentOpenBracketCount = 0;
20499
20499
  let currentOpenParensCount = 0;
20500
20500
  let currentStringType = null;
20501
- for (let i = 0; i < path3.length; i++) {
20502
- const char = path3.charAt(i);
20501
+ for (let i = 0; i < path4.length; i++) {
20502
+ const char = path4.charAt(i);
20503
20503
  switch (state) {
20504
20504
  case 0:
20505
20505
  if (char === "[") {
@@ -20535,7 +20535,7 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
20535
20535
  } else if (char === `(`) {
20536
20536
  currentOpenParensCount++;
20537
20537
  } else if (char === `)`) {
20538
- if (i === path3.length - 1) {
20538
+ if (i === path4.length - 1) {
20539
20539
  return false;
20540
20540
  }
20541
20541
  if (!--currentOpenParensCount) {
@@ -27262,14 +27262,14 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
27262
27262
  var whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
27263
27263
  var getExpSource = (exp) => exp.type === 4 ? exp.content : exp.loc.source;
27264
27264
  var isMemberExpressionBrowser = (exp) => {
27265
- const path3 = getExpSource(exp).trim().replace(whitespaceRE, (s) => s.trim());
27265
+ const path4 = getExpSource(exp).trim().replace(whitespaceRE, (s) => s.trim());
27266
27266
  let state = 0;
27267
27267
  let stateStack = [];
27268
27268
  let currentOpenBracketCount = 0;
27269
27269
  let currentOpenParensCount = 0;
27270
27270
  let currentStringType = null;
27271
- for (let i = 0; i < path3.length; i++) {
27272
- const char = path3.charAt(i);
27271
+ for (let i = 0; i < path4.length; i++) {
27272
+ const char = path4.charAt(i);
27273
27273
  switch (state) {
27274
27274
  case 0:
27275
27275
  if (char === "[") {
@@ -27305,7 +27305,7 @@ Use a v-bind binding combined with a v-on listener that emits update:x event ins
27305
27305
  } else if (char === `(`) {
27306
27306
  currentOpenParensCount++;
27307
27307
  } else if (char === `)`) {
27308
- if (i === path3.length - 1) {
27308
+ if (i === path4.length - 1) {
27309
27309
  return false;
27310
27310
  }
27311
27311
  if (!--currentOpenParensCount) {
@@ -32208,6 +32208,11 @@ var require_compiler_core = __commonJS({
32208
32208
  function resolveComponentsPath() {
32209
32209
  return resolvePackageResourceDir("components");
32210
32210
  }
32211
+ function extractImportSource(importStatement) {
32212
+ if (!importStatement) return void 0;
32213
+ const match = importStatement.match(/from\s+['"]([^'"]+)['"]/);
32214
+ return match?.[1];
32215
+ }
32211
32216
  var ComponentRegistry = class {
32212
32217
  constructor() {
32213
32218
  this.components = /* @__PURE__ */ new Map();
@@ -32235,18 +32240,27 @@ var ComponentRegistry = class {
32235
32240
  const files = await fs.readdir(this.metadataPath);
32236
32241
  for (const file of files) {
32237
32242
  if (!file.endsWith(".json")) continue;
32238
- const content = await fs.readFile(path.join(this.metadataPath, file), "utf-8");
32243
+ const content = await fs.readFile(path3.join(this.metadataPath, file), "utf-8");
32239
32244
  const data = JSON.parse(content);
32240
- rawComponents[data.name] = data;
32245
+ const importSource = data.importSource || data.source || extractImportSource(data.importStatement);
32246
+ const normalizedData = {
32247
+ ...data,
32248
+ fileName: data.fileName || file.replace(/\.json$/, ""),
32249
+ importSource,
32250
+ source: data.source || importSource
32251
+ };
32252
+ rawComponents[`${normalizedData.fileName}:${normalizedData.name}:${normalizedData.importSource || ""}`] = normalizedData;
32241
32253
  }
32242
32254
  for (const data of Object.values(rawComponents)) {
32243
32255
  const resolvedData = resolveMetadataInheritance(data, rawComponents);
32244
- newComponents.set(resolvedData.name, resolvedData);
32256
+ this.appendComponent(newComponents, resolvedData);
32245
32257
  if (resolvedData.subComponents) {
32246
32258
  for (const sub of resolvedData.subComponents) {
32247
- newComponents.set(sub.name, {
32259
+ this.appendComponent(newComponents, {
32248
32260
  id: sub.name,
32249
32261
  name: sub.name,
32262
+ source: resolvedData.source,
32263
+ importSource: resolvedData.importSource,
32250
32264
  props: sub.props || [],
32251
32265
  events: sub.events || [],
32252
32266
  slots: sub.slots || [],
@@ -32256,11 +32270,17 @@ var ComponentRegistry = class {
32256
32270
  }
32257
32271
  }
32258
32272
  this.components = newComponents;
32259
- console.log(`[ComponentRegistry] ${this.loaded ? "Reloaded" : "Loaded"} ${this.components.size} components.`);
32273
+ const totalEntries = Array.from(this.components.values()).reduce((sum, items) => sum + items.length, 0);
32274
+ console.log(`[ComponentRegistry] ${this.loaded ? "Reloaded" : "Loaded"} ${totalEntries} components.`);
32260
32275
  } catch (error) {
32261
32276
  console.error("[ComponentRegistry] Failed to load metadata:", error);
32262
32277
  }
32263
32278
  }
32279
+ appendComponent(target, metadata) {
32280
+ const current = target.get(metadata.name) || [];
32281
+ current.push(metadata);
32282
+ target.set(metadata.name, current);
32283
+ }
32264
32284
  /**
32265
32285
  * 开始监听文件变化
32266
32286
  */
@@ -32268,7 +32288,7 @@ var ComponentRegistry = class {
32268
32288
  if (this.watcher) return;
32269
32289
  try {
32270
32290
  let reloadTimeout = null;
32271
- this.watcher = fsSync.watch(this.metadataPath, (eventType, filename) => {
32291
+ this.watcher = fs3.watch(this.metadataPath, (eventType, filename) => {
32272
32292
  if (!filename?.endsWith(".json")) return;
32273
32293
  console.log(`[ComponentRegistry] Detected change: ${filename} (${eventType})`);
32274
32294
  if (reloadTimeout) {
@@ -32293,14 +32313,28 @@ var ComponentRegistry = class {
32293
32313
  console.log("[ComponentRegistry] Hot reload disabled.");
32294
32314
  }
32295
32315
  }
32296
- getComponent(name) {
32297
- return this.components.get(name);
32316
+ getComponent(name, importSource) {
32317
+ const candidates = this.components.get(name) || [];
32318
+ if (!importSource) return candidates[0];
32319
+ return candidates.find((item) => {
32320
+ const expectedSource = item.importSource || item.source || extractImportSource(item.importStatement);
32321
+ return expectedSource === importSource;
32322
+ }) || candidates[0];
32323
+ }
32324
+ getComponents(name) {
32325
+ return this.components.get(name) || [];
32298
32326
  }
32299
32327
  getAllComponentNames() {
32300
32328
  return Array.from(this.components.keys());
32301
32329
  }
32302
- isKnownComponent(name) {
32303
- return this.components.has(name);
32330
+ isKnownComponent(name, importSource) {
32331
+ if (!importSource) {
32332
+ return this.components.has(name);
32333
+ }
32334
+ return this.getComponents(name).some((item) => {
32335
+ const expectedSource = item.importSource || item.source || extractImportSource(item.importStatement);
32336
+ return expectedSource === importSource;
32337
+ });
32304
32338
  }
32305
32339
  };
32306
32340
  var componentRegistry = new ComponentRegistry();
@@ -32335,7 +32369,7 @@ var HooksRegistry = class {
32335
32369
  const files = await fs.readdir(this.metadataPath);
32336
32370
  for (const file of files) {
32337
32371
  if (!file.endsWith(".json")) continue;
32338
- const content = await fs.readFile(path.join(this.metadataPath, file), "utf-8");
32372
+ const content = await fs.readFile(path3.join(this.metadataPath, file), "utf-8");
32339
32373
  const data = JSON.parse(content);
32340
32374
  newHooks.set(data.name, data);
32341
32375
  }
@@ -32356,7 +32390,7 @@ var HooksRegistry = class {
32356
32390
  if (this.watcher) return;
32357
32391
  try {
32358
32392
  let reloadTimeout = null;
32359
- this.watcher = fsSync.watch(this.metadataPath, (eventType, filename) => {
32393
+ this.watcher = fs3.watch(this.metadataPath, (eventType, filename) => {
32360
32394
  if (!filename?.endsWith(".json")) return;
32361
32395
  console.log(`[HooksRegistry] Detected change: ${filename} (${eventType})`);
32362
32396
  if (reloadTimeout) {
@@ -32405,6 +32439,104 @@ var HooksRegistry = class {
32405
32439
  }
32406
32440
  };
32407
32441
  var hooksRegistry = new HooksRegistry();
32442
+ function packagePathSegments(moduleSpecifier) {
32443
+ if (moduleSpecifier.startsWith("@")) {
32444
+ return moduleSpecifier.split("/").slice(0, 2);
32445
+ }
32446
+ return [moduleSpecifier.split("/")[0]];
32447
+ }
32448
+ function resolveInstalledPackageDir(moduleSpecifier) {
32449
+ const packageRoot = resolvePackageRoot();
32450
+ const segments = packagePathSegments(moduleSpecifier);
32451
+ const cwd = process.cwd();
32452
+ const candidates = [
32453
+ path3.join(cwd, "node_modules", ...segments),
32454
+ path3.join(cwd, "web", "node_modules", ...segments),
32455
+ packageRoot ? path3.join(packageRoot, "node_modules", ...segments) : null,
32456
+ packageRoot ? path3.join(packageRoot, "web", "node_modules", ...segments) : null
32457
+ ].filter((candidate) => Boolean(candidate));
32458
+ return candidates.find((candidate) => fs3.existsSync(candidate)) || null;
32459
+ }
32460
+ function resolvePackageTypesEntry(moduleSpecifier) {
32461
+ const packageDir = resolveInstalledPackageDir(moduleSpecifier);
32462
+ if (!packageDir) return null;
32463
+ const packageJsonPath = path3.join(packageDir, "package.json");
32464
+ if (fs3.existsSync(packageJsonPath)) {
32465
+ try {
32466
+ const packageJson = JSON.parse(fs3.readFileSync(packageJsonPath, "utf-8"));
32467
+ const declaredEntry = packageJson.types || packageJson.typings;
32468
+ if (declaredEntry) {
32469
+ const resolved = path3.join(packageDir, declaredEntry);
32470
+ if (fs3.existsSync(resolved)) {
32471
+ return resolved;
32472
+ }
32473
+ }
32474
+ } catch {
32475
+ }
32476
+ }
32477
+ const fallbackEntry = path3.join(packageDir, "index.d.ts");
32478
+ return fs3.existsSync(fallbackEntry) ? fallbackEntry : null;
32479
+ }
32480
+ function inferExportKind(exportName, declarationFile) {
32481
+ if (!declarationFile) return /^[A-Z]/.test(exportName) ? "component" : "value";
32482
+ const normalizedFile = declarationFile.replace(/\\/g, "/");
32483
+ if (normalizedFile.includes("/components/") && /^[A-Z]/.test(exportName)) {
32484
+ return "component";
32485
+ }
32486
+ return "value";
32487
+ }
32488
+ var PackageExportRegistry = class {
32489
+ constructor() {
32490
+ this.exportsByModule = /* @__PURE__ */ new Map();
32491
+ this.loadedModules = /* @__PURE__ */ new Set();
32492
+ }
32493
+ async load(moduleSpecifier) {
32494
+ if (this.loadedModules.has(moduleSpecifier)) {
32495
+ return;
32496
+ }
32497
+ const entry = resolvePackageTypesEntry(moduleSpecifier);
32498
+ if (!entry) {
32499
+ this.loadedModules.add(moduleSpecifier);
32500
+ this.exportsByModule.set(moduleSpecifier, /* @__PURE__ */ new Map());
32501
+ return;
32502
+ }
32503
+ const program = ts2.createProgram([entry], {
32504
+ target: ts2.ScriptTarget.ES2020,
32505
+ module: ts2.ModuleKind.ESNext,
32506
+ moduleResolution: ts2.ModuleResolutionKind.NodeJs,
32507
+ skipLibCheck: true
32508
+ });
32509
+ const checker = program.getTypeChecker();
32510
+ const sourceFile = program.getSourceFile(entry);
32511
+ if (!sourceFile) {
32512
+ this.loadedModules.add(moduleSpecifier);
32513
+ this.exportsByModule.set(moduleSpecifier, /* @__PURE__ */ new Map());
32514
+ return;
32515
+ }
32516
+ const moduleSymbol = checker.getSymbolAtLocation(sourceFile);
32517
+ const exportsMap = /* @__PURE__ */ new Map();
32518
+ if (moduleSymbol) {
32519
+ for (const symbol of checker.getExportsOfModule(moduleSymbol)) {
32520
+ const declarationFile = symbol.declarations?.[0]?.getSourceFile().fileName;
32521
+ exportsMap.set(symbol.getName(), {
32522
+ name: symbol.getName(),
32523
+ moduleSpecifier,
32524
+ declarationFile,
32525
+ kind: inferExportKind(symbol.getName(), declarationFile)
32526
+ });
32527
+ }
32528
+ }
32529
+ this.exportsByModule.set(moduleSpecifier, exportsMap);
32530
+ this.loadedModules.add(moduleSpecifier);
32531
+ }
32532
+ getExport(name, moduleSpecifier) {
32533
+ return this.exportsByModule.get(moduleSpecifier)?.get(name);
32534
+ }
32535
+ isKnownExport(name, moduleSpecifier) {
32536
+ return this.exportsByModule.get(moduleSpecifier)?.has(name) || false;
32537
+ }
32538
+ };
32539
+ var packageExportRegistry = new PackageExportRegistry();
32408
32540
 
32409
32541
  // src/analysis/astReviewer.ts
32410
32542
  var VUE_BUILTINS = /* @__PURE__ */ new Set([
@@ -32743,27 +32875,30 @@ var NESTING_RULES = {
32743
32875
  async function analyzeCodeWithAST(code) {
32744
32876
  await componentRegistry.load();
32745
32877
  await hooksRegistry.load();
32878
+ await packageExportRegistry.load("@king-design/vue");
32879
+ await packageExportRegistry.load("@ksyun-internal/versatile");
32746
32880
  const violations = [];
32881
+ const componentImportContext = /* @__PURE__ */ new Map();
32747
32882
  const { descriptor, errors } = parse(code);
32748
32883
  if (errors.length > 0) {
32749
32884
  return violations;
32750
32885
  }
32751
32886
  const scriptContent = descriptor.scriptSetup?.content || descriptor.script?.content || "";
32752
32887
  if (scriptContent) {
32753
- const sourceFile = ts.createSourceFile(
32888
+ const sourceFile = ts2.createSourceFile(
32754
32889
  "temp.ts",
32755
32890
  scriptContent,
32756
- ts.ScriptTarget.Latest,
32891
+ ts2.ScriptTarget.Latest,
32757
32892
  true
32758
32893
  );
32759
- ts.forEachChild(sourceFile, (node) => {
32760
- if (ts.isImportDeclaration(node)) {
32761
- checkImport(node, violations, sourceFile);
32894
+ ts2.forEachChild(sourceFile, (node) => {
32895
+ if (ts2.isImportDeclaration(node)) {
32896
+ checkImport(node, violations, sourceFile, componentImportContext);
32762
32897
  }
32763
32898
  });
32764
32899
  }
32765
32900
  if (descriptor.template?.ast) {
32766
- checkTemplate(descriptor.template.ast, violations, []);
32901
+ checkTemplate(descriptor.template.ast, violations, [], componentImportContext);
32767
32902
  }
32768
32903
  if (scriptContent && descriptor.template) {
32769
32904
  const scriptBindings = extractScriptBindings(scriptContent);
@@ -32781,25 +32916,25 @@ function extractScriptBindings(scriptContent) {
32781
32916
  JS_GLOBALS.forEach((b) => bindings.add(b));
32782
32917
  try {
32783
32918
  let extractNames2 = function(name) {
32784
- if (ts.isIdentifier(name)) {
32919
+ if (ts2.isIdentifier(name)) {
32785
32920
  bindings.add(name.text);
32786
- } else if (ts.isObjectBindingPattern(name) || ts.isArrayBindingPattern(name)) {
32921
+ } else if (ts2.isObjectBindingPattern(name) || ts2.isArrayBindingPattern(name)) {
32787
32922
  name.elements.forEach((element) => {
32788
- if (ts.isBindingElement(element)) {
32923
+ if (ts2.isBindingElement(element)) {
32789
32924
  extractNames2(element.name);
32790
32925
  }
32791
32926
  });
32792
32927
  }
32793
32928
  }, visit2 = function(node) {
32794
- if (ts.isVariableStatement(node)) {
32929
+ if (ts2.isVariableStatement(node)) {
32795
32930
  node.declarationList.declarations.forEach((decl) => extractNames2(decl.name));
32796
- } else if (ts.isFunctionDeclaration(node) && node.name) {
32931
+ } else if (ts2.isFunctionDeclaration(node) && node.name) {
32797
32932
  bindings.add(node.name.text);
32798
- } else if (ts.isClassDeclaration(node) && node.name) {
32933
+ } else if (ts2.isClassDeclaration(node) && node.name) {
32799
32934
  bindings.add(node.name.text);
32800
- } else if (ts.isImportDeclaration(node)) {
32935
+ } else if (ts2.isImportDeclaration(node)) {
32801
32936
  const namedBindings = node.importClause?.namedBindings;
32802
- if (namedBindings && ts.isNamedImports(namedBindings)) {
32937
+ if (namedBindings && ts2.isNamedImports(namedBindings)) {
32803
32938
  namedBindings.elements.forEach((element) => {
32804
32939
  bindings.add(element.name.text);
32805
32940
  });
@@ -32810,10 +32945,10 @@ function extractScriptBindings(scriptContent) {
32810
32945
  }
32811
32946
  };
32812
32947
  var extractNames = extractNames2, visit = visit2;
32813
- const sourceFile = ts.createSourceFile(
32948
+ const sourceFile = ts2.createSourceFile(
32814
32949
  "temp.ts",
32815
32950
  scriptContent,
32816
- ts.ScriptTarget.Latest,
32951
+ ts2.ScriptTarget.Latest,
32817
32952
  true
32818
32953
  );
32819
32954
  sourceFile.statements.forEach(visit2);
@@ -32825,9 +32960,9 @@ function extractScriptBindings(scriptContent) {
32825
32960
  function checkScriptFunctionCalls(scriptContent, bindings, violations) {
32826
32961
  try {
32827
32962
  let visit2 = function(node) {
32828
- if (ts.isCallExpression(node)) {
32963
+ if (ts2.isCallExpression(node)) {
32829
32964
  const callee = node.expression;
32830
- if (ts.isIdentifier(callee)) {
32965
+ if (ts2.isIdentifier(callee)) {
32831
32966
  const funcName = callee.text;
32832
32967
  const isHookCall = funcName.startsWith("use") && funcName.length > 3 && funcName[3] === funcName[3].toUpperCase();
32833
32968
  if (isHookCall) {
@@ -32841,16 +32976,16 @@ function checkScriptFunctionCalls(scriptContent, bindings, violations) {
32841
32976
  }
32842
32977
  }
32843
32978
  }
32844
- ts.forEachChild(node, visit2);
32979
+ ts2.forEachChild(node, visit2);
32845
32980
  };
32846
32981
  var visit = visit2;
32847
- const sourceFile = ts.createSourceFile(
32982
+ const sourceFile = ts2.createSourceFile(
32848
32983
  "temp.ts",
32849
32984
  scriptContent,
32850
- ts.ScriptTarget.Latest,
32985
+ ts2.ScriptTarget.Latest,
32851
32986
  true
32852
32987
  );
32853
- ts.forEachChild(sourceFile, visit2);
32988
+ ts2.forEachChild(sourceFile, visit2);
32854
32989
  } catch (err) {
32855
32990
  }
32856
32991
  }
@@ -32963,7 +33098,7 @@ function extractIdentifiersFromExpression(expression) {
32963
33098
  }
32964
33099
  }
32965
33100
  const cleanExpr = expression.replace(/'[^']*'/g, "").replace(/"[^"]*"/g, "").replace(/`[^`]*`/g, "");
32966
- const idRegex = /(?:^|[^.\w$])([a-zA-Z_$][\w$]*)\b(?!\s*:)/g;
33101
+ const idRegex = /(?:^|[^.\w$])([a-zA-Z_$][\w$]*)(?![\w$])(?!\s*:)/g;
32967
33102
  let match;
32968
33103
  while ((match = idRegex.exec(cleanExpr)) !== null) {
32969
33104
  const id = match[1];
@@ -32980,6 +33115,7 @@ function isJsKeyword(id) {
32980
33115
  return JS_KEYWORDS.has(id);
32981
33116
  }
32982
33117
  function resolveExpectedImportSource(metadata) {
33118
+ if (metadata.importSource) return metadata.importSource;
32983
33119
  const importStatement = metadata.importStatement || "";
32984
33120
  if (importStatement.includes("@ksyun-internal/versatile")) {
32985
33121
  return "@ksyun-internal/versatile";
@@ -32989,11 +33125,11 @@ function resolveExpectedImportSource(metadata) {
32989
33125
  }
32990
33126
  return null;
32991
33127
  }
32992
- function checkImport(node, violations, sourceFile) {
33128
+ function checkImport(node, violations, sourceFile, componentImportContext) {
32993
33129
  const moduleSpecifier = node.moduleSpecifier.getText(sourceFile).replace(/['\"]/g, "");
32994
33130
  if (moduleSpecifier === "@king-design/vue" || moduleSpecifier === "@ksyun-internal/versatile") {
32995
33131
  const namedBindings = node.importClause?.namedBindings;
32996
- if (namedBindings && ts.isNamedImports(namedBindings)) {
33132
+ if (namedBindings && ts2.isNamedImports(namedBindings)) {
32997
33133
  namedBindings.elements.forEach((element) => {
32998
33134
  const originalName = element.propertyName ? element.propertyName.text : element.name.text;
32999
33135
  const localName = element.name.text;
@@ -33025,14 +33161,16 @@ function checkImport(node, violations, sourceFile) {
33025
33161
  }
33026
33162
  return;
33027
33163
  }
33028
- if (isAlias) {
33164
+ componentImportContext.set(localName, moduleSpecifier);
33165
+ const metadata = componentRegistry.getComponent(originalName, moduleSpecifier);
33166
+ const packageExport = packageExportRegistry.getExport(originalName, moduleSpecifier);
33167
+ if (isAlias && (metadata || packageExport?.kind === "component")) {
33029
33168
  violations.push({
33030
33169
  rule: `\u7981\u6B62\u5BF9\u7EC4\u4EF6 ${originalName} \u4F7F\u7528\u522B\u540D\u5BFC\u5165`,
33031
33170
  match: `${originalName} as ${localName}`,
33032
33171
  suggestion: `\u76F4\u63A5\u4F7F\u7528\u539F\u540D: import { ${originalName} } from '${moduleSpecifier}'`
33033
33172
  });
33034
33173
  }
33035
- const metadata = componentRegistry.getComponent(originalName);
33036
33174
  if (metadata) {
33037
33175
  const expectedPackage = resolveExpectedImportSource(metadata);
33038
33176
  if (expectedPackage && expectedPackage !== moduleSpecifier) {
@@ -33043,11 +33181,24 @@ function checkImport(node, violations, sourceFile) {
33043
33181
  });
33044
33182
  }
33045
33183
  } else {
33046
- violations.push({
33047
- rule: "\u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684\u7EC4\u4EF6/\u5BFC\u51FA",
33048
- match: originalName,
33049
- suggestion: `\u8BF7\u786E\u8BA4 ${originalName} \u662F\u5426\u5B58\u5728\u4E8E ${moduleSpecifier}\u3002\u5EFA\u8BAE\u67E5\u770B\u6587\u6863\u3002`
33050
- });
33184
+ if (packageExport) {
33185
+ return;
33186
+ }
33187
+ const knownMetadata = componentRegistry.getComponent(originalName);
33188
+ if (knownMetadata) {
33189
+ const expectedPackage = resolveExpectedImportSource(knownMetadata);
33190
+ violations.push({
33191
+ rule: `\u7EC4\u4EF6 ${originalName} \u5BFC\u5165\u6E90\u9519\u8BEF`,
33192
+ match: `import { ... } from '${moduleSpecifier}'`,
33193
+ suggestion: expectedPackage ? `\u5E94\u4ECE '${expectedPackage}' \u5BFC\u5165` : `\u8BF7\u786E\u8BA4 ${originalName} \u7684\u5BFC\u5165\u6765\u6E90`
33194
+ });
33195
+ } else {
33196
+ violations.push({
33197
+ rule: "\u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684\u7EC4\u4EF6/\u5BFC\u51FA",
33198
+ match: originalName,
33199
+ suggestion: `\u8BF7\u786E\u8BA4 ${originalName} \u662F\u5426\u5B58\u5728\u4E8E ${moduleSpecifier}\u3002\u5EFA\u8BAE\u67E5\u770B\u6587\u6863\u3002`
33200
+ });
33201
+ }
33051
33202
  }
33052
33203
  });
33053
33204
  }
@@ -33296,14 +33447,16 @@ function checkEvents(tagName, node, metadata, violations) {
33296
33447
  function kebabTagToPascalTag(tag) {
33297
33448
  return tag.split("-").map((part) => part.length ? part.charAt(0).toUpperCase() + part.slice(1).toLowerCase() : "").join("");
33298
33449
  }
33299
- function resolveRegisteredComponent(tag) {
33300
- if (componentRegistry.isKnownComponent(tag)) {
33301
- return componentRegistry.getComponent(tag);
33450
+ function resolveRegisteredComponent(tag, componentImportContext) {
33451
+ const directImportSource = componentImportContext?.get(tag);
33452
+ if (componentRegistry.isKnownComponent(tag, directImportSource)) {
33453
+ return componentRegistry.getComponent(tag, directImportSource);
33302
33454
  }
33303
33455
  if (tag.includes("-")) {
33304
33456
  const pascal = kebabTagToPascalTag(tag);
33305
- if (componentRegistry.isKnownComponent(pascal)) {
33306
- return componentRegistry.getComponent(pascal);
33457
+ const pascalImportSource = componentImportContext?.get(pascal);
33458
+ if (componentRegistry.isKnownComponent(pascal, pascalImportSource)) {
33459
+ return componentRegistry.getComponent(pascal, pascalImportSource);
33307
33460
  }
33308
33461
  }
33309
33462
  return void 0;
@@ -33350,11 +33503,11 @@ function checkSlots(tagName, node, metadata, violations) {
33350
33503
  });
33351
33504
  }
33352
33505
  }
33353
- function checkTemplate(node, violations, ancestors) {
33506
+ function checkTemplate(node, violations, ancestors, componentImportContext) {
33354
33507
  if (node.type === 1) {
33355
33508
  const elementNode = node;
33356
33509
  const tagName = elementNode.tag;
33357
- const metadata = resolveRegisteredComponent(tagName);
33510
+ const metadata = resolveRegisteredComponent(tagName, componentImportContext);
33358
33511
  const displayTag = metadata?.name ?? tagName;
33359
33512
  if (metadata) {
33360
33513
  checkNestingRules(displayTag, metadata, ancestors, violations);
@@ -33370,12 +33523,12 @@ function checkTemplate(node, violations, ancestors) {
33370
33523
  let newAncestors = ancestors;
33371
33524
  if (node.type === 1 && "tag" in node) {
33372
33525
  const el = node;
33373
- const meta = resolveRegisteredComponent(el.tag);
33526
+ const meta = resolveRegisteredComponent(el.tag, componentImportContext);
33374
33527
  newAncestors = [...ancestors, meta?.name ?? el.tag];
33375
33528
  }
33376
33529
  node.children.forEach((child) => {
33377
33530
  if (typeof child === "object" && child !== null && "type" in child) {
33378
- checkTemplate(child, violations, newAncestors);
33531
+ checkTemplate(child, violations, newAncestors, componentImportContext);
33379
33532
  }
33380
33533
  });
33381
33534
  }
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunkHARQRI4F_js = require('../chunk-HARQRI4F.js');
4
- require('../chunk-XPHDD6XR.js');
3
+ var chunkGCHRZSCK_js = require('../chunk-GCHRZSCK.js');
4
+ require('../chunk-4ZZ6E4RS.js');
5
5
  require('../chunk-V5N65MRP.js');
6
6
  require('../chunk-DHLWNT53.js');
7
7
  require('../chunk-KF5YBEM5.js');
@@ -11,9 +11,9 @@ require('../chunk-JSBRDJBE.js');
11
11
 
12
12
  Object.defineProperty(exports, "validateCode", {
13
13
  enumerable: true,
14
- get: function () { return chunkHARQRI4F_js.validateCode; }
14
+ get: function () { return chunkGCHRZSCK_js.validateCode; }
15
15
  });
16
16
  Object.defineProperty(exports, "validateCodeSync", {
17
17
  enumerable: true,
18
- get: function () { return chunkHARQRI4F_js.validateCodeSync; }
18
+ get: function () { return chunkGCHRZSCK_js.validateCodeSync; }
19
19
  });
@@ -1,5 +1,5 @@
1
- export { validateCode, validateCodeSync } from '../chunk-BSCASJTV.mjs';
2
- import '../chunk-YRGYDK2I.mjs';
1
+ export { validateCode, validateCodeSync } from '../chunk-SCECUJGJ.mjs';
2
+ import '../chunk-ZW3HD2OD.mjs';
3
3
  import '../chunk-6HOIRUQB.mjs';
4
4
  import '../chunk-4OTQAQ6J.mjs';
5
5
  import '../chunk-QC6VTSA3.mjs';