@brighterly/lib-fe-codestyle 0.5.2 → 1.0.0

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.
@@ -71,7 +71,7 @@ export declare const findSharedMutables: (file: string, source: string) => Promi
71
71
  }[]>;
72
72
  /** One attribute or binding, normalised so a rule need not know the node types. */
73
73
  export interface TemplateAttr {
74
- /** Attribute name without the `:` / `v-bind:` prefix — `data-qa`, `class`, `title`. */
74
+ /** Attribute name without the `:` / `v-bind:` prefix — `data-qa`, `class`, `title`; `v-if` for the condition. */
75
75
  name: string;
76
76
  /** Static value, or the raw expression source for a binding. Null for a bare attribute. */
77
77
  value: string | null;
@@ -95,11 +95,6 @@ export interface TemplateEl {
95
95
  /** True when this element carries a `v-for`. */
96
96
  vFor: boolean;
97
97
  }
98
- /**
99
- * Root elements of a .vue file's <template>. Empty array when the file has no
100
- * template or the template does not parse — a rule must treat that as "nothing
101
- * to say", never as "compliant".
102
- */
103
98
  export declare const templateElements: (file: string, source: string) => Promise<TemplateEl[]>;
104
99
  /** Every element with the given tag, at any depth, in document order. */
105
100
  export declare const elementsByTag: (roots: TemplateEl[], tag: string) => TemplateEl[];
@@ -248,6 +248,12 @@ const normalise = (node) => {
248
248
  vFor = true;
249
249
  continue;
250
250
  }
251
+ // The condition is exposed as a bound attribute so a rule can read `v-if` through
252
+ // the AST instead of a tag regex, which an attribute holding `=>` or `>` defeats.
253
+ if (p.name === 'if') {
254
+ attrs.push({ name: 'v-if', value: p.exp?.content ?? p.exp?.loc?.source ?? null, bound: true, line });
255
+ continue;
256
+ }
251
257
  if (p.name === 'slot') {
252
258
  // `#title` → arg.content 'title'; `#[slotName]` → dynamic, keep the source
253
259
  slot = p.arg ? String(p.arg.content ?? p.arg.loc?.source ?? '') : 'default';
@@ -271,7 +277,18 @@ const normalise = (node) => {
271
277
  * template or the template does not parse — a rule must treat that as "nothing
272
278
  * to say", never as "compliant".
273
279
  */
274
- export const templateElements = async (file, source) => {
280
+ /** One parse per file and source per run: several registry rules read the same Views. */
281
+ const templateCache = new Map();
282
+ export const templateElements = (file, source) => {
283
+ const key = `${file}\0${source}`;
284
+ let hit = templateCache.get(key);
285
+ if (!hit) {
286
+ hit = parseTemplate(file, source);
287
+ templateCache.set(key, hit);
288
+ }
289
+ return hit;
290
+ };
291
+ const parseTemplate = async (file, source) => {
275
292
  if (!file.endsWith('.vue'))
276
293
  return [];
277
294
  const { parse } = await sfc();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brighterly/lib-fe-codestyle",
3
- "version": "0.5.2",
3
+ "version": "1.0.0",
4
4
  "type": "module",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Shared invariant-validator engine, rule pack and ESLint config for Brighterly Nuxt frontend apps",