@kimesh/auto-import 0.2.38 → 0.2.39

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/index.d.mts CHANGED
@@ -163,6 +163,8 @@ interface UnresolvedReference {
163
163
  end: number;
164
164
  /** Is it used as a type? */
165
165
  isType: boolean;
166
+ /** Found in a template binding expression (e.g. :as="KmLink"), not a script block */
167
+ isTemplateExpression?: boolean;
166
168
  }
167
169
  /**
168
170
  * Transform result
@@ -294,6 +296,17 @@ declare class ReferenceDetector {
294
296
  * Detect unresolved references in Vue SFC
295
297
  */
296
298
  detectInVue(code: string, filePath: string): UnresolvedReference[];
299
+ /**
300
+ * Detect unresolved references in template binding expressions.
301
+ * Extracts expressions from v-bind (:attr="expr"), interpolations ({{ expr }}),
302
+ * and directives (v-if, v-show, etc.), then parses each to find identifiers.
303
+ */
304
+ private detectInTemplateExpressions;
305
+ /**
306
+ * Extract JavaScript expressions from Vue template content.
307
+ * Covers v-bind shorthand, full v-bind, interpolations, and directives.
308
+ */
309
+ private extractTemplateExpressions;
297
310
  /**
298
311
  * Detect unresolved references in parsed AST
299
312
  */
package/dist/index.mjs CHANGED
@@ -190,12 +190,54 @@ var ReferenceDetector = class {
190
190
  const scriptRefs = this.detectInScript(descriptor.script.content, filePath + ".ts");
191
191
  refs.push(...scriptRefs);
192
192
  }
193
+ if (descriptor.template) {
194
+ const templateRefs = this.detectInTemplateExpressions(descriptor.template.content, filePath);
195
+ refs.push(...templateRefs);
196
+ }
193
197
  return refs;
194
198
  } catch {
195
199
  return [];
196
200
  }
197
201
  }
198
202
  /**
203
+ * Detect unresolved references in template binding expressions.
204
+ * Extracts expressions from v-bind (:attr="expr"), interpolations ({{ expr }}),
205
+ * and directives (v-if, v-show, etc.), then parses each to find identifiers.
206
+ */
207
+ detectInTemplateExpressions(template, filePath) {
208
+ const expressions = this.extractTemplateExpressions(template);
209
+ const refs = [];
210
+ for (const expr of expressions) try {
211
+ const wrappedCode = `const __kimesh_expr = ${expr}`;
212
+ const exprRefs = this.detectInScript(wrappedCode, filePath + ".template-expr.ts");
213
+ for (const ref of exprRefs) refs.push({
214
+ ...ref,
215
+ isTemplateExpression: true
216
+ });
217
+ } catch {}
218
+ return refs;
219
+ }
220
+ /**
221
+ * Extract JavaScript expressions from Vue template content.
222
+ * Covers v-bind shorthand, full v-bind, interpolations, and directives.
223
+ */
224
+ extractTemplateExpressions(template) {
225
+ const expressions = [];
226
+ for (const regex of [
227
+ /(?::|v-bind:)[\w.-]+(?:\.[\w]+)*="([^"]+)"/g,
228
+ /\{\{([\s\S]*?)\}\}/g,
229
+ /v-(?:if|else-if|show|for|model)="([^"]+)"/g,
230
+ /(?:@|v-on:)[\w.-]+(?:\.[\w]+)*="([^"]+)"/g
231
+ ]) {
232
+ let match;
233
+ while ((match = regex.exec(template)) !== null) {
234
+ const expr = match[1].trim();
235
+ if (expr) expressions.push(expr);
236
+ }
237
+ }
238
+ return expressions;
239
+ }
240
+ /**
199
241
  * Detect unresolved references in parsed AST
200
242
  */
201
243
  detectInAST(program) {
@@ -423,8 +465,9 @@ var ImportInjector = class {
423
465
  if (match[2]) for (const name of match[2].split(",")) {
424
466
  const trimmed = name.trim();
425
467
  if (!trimmed) continue;
426
- const asMatch = trimmed.match(/(\w+)\s+as\s+(\w+)/);
427
- imported.add(asMatch ? asMatch[2] : trimmed);
468
+ const stripped = trimmed.replace(/^type\s+/, "");
469
+ const asMatch = stripped.match(/(\w+)\s+as\s+(\w+)/);
470
+ imported.add(asMatch ? asMatch[2] : stripped);
428
471
  }
429
472
  }
430
473
  return imported;
@@ -759,7 +802,7 @@ function createScriptPlugin(options) {
759
802
  const entry = registry.imports.get(ref.name);
760
803
  if (!entry) continue;
761
804
  if (ref.isType && !entry.isType) continue;
762
- if (registry.components.has(ref.name)) {
805
+ if (registry.components.has(ref.name) && !ref.isTemplateExpression) {
763
806
  if (debug) logger$1.debug(`Skipping component ${ref.name} for template plugin`);
764
807
  continue;
765
808
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kimesh/auto-import",
3
- "version": "0.2.38",
3
+ "version": "0.2.39",
4
4
  "description": "OXC-powered auto-import system for Kimesh framework with layer support",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,7 +25,7 @@
25
25
  "test": "vitest"
26
26
  },
27
27
  "dependencies": {
28
- "@kimesh/shared": "0.2.38",
28
+ "@kimesh/shared": "0.2.39",
29
29
  "@vue/compiler-sfc": "^3.5.26",
30
30
  "consola": "^3.4.2",
31
31
  "magic-string": "^0.30.21",