@bamboocss/node 1.44.1 → 1.45.1

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.cjs CHANGED
@@ -2557,9 +2557,8 @@ function accountFile(ctx, sourceFile, filePath, paths, prefixes, declined) {
2557
2557
  if (ts_morph.Node.isStringLiteral(argument) ? isTokensEntrypoint(ctx, argument.getLiteralValue()) : true) decline(call, isRequire ? "require" : "dynamic-import");
2558
2558
  }
2559
2559
  const shadows = shadowedScopes(sourceFile);
2560
- for (const identifier of sourceFile.getDescendantsOfKind(ts_morph.SyntaxKind.Identifier)) {
2560
+ for (const identifier of identifiersNamed(sourceFile, (name) => bindings.has(name) || name === "token")) {
2561
2561
  const text = nameOf(identifier);
2562
- if (!bindings.has(text) && text !== "token") continue;
2563
2562
  const parent = identifier.getParent();
2564
2563
  if (ts_morph.Node.isExportSpecifier(parent)) {
2565
2564
  const declaration = parent.getFirstAncestorByKind(ts_morph.SyntaxKind.ExportDeclaration);
@@ -2608,6 +2607,38 @@ function usesTokenMember(sourceFile, namespace) {
2608
2607
  * `token` is the identifier `token`; reading `getText()` returns the escape and compares
2609
2608
  * unequal, which let an import of the artifact's export past the checks that key on the name.
2610
2609
  */
2610
+ /**
2611
+ * Every `Identifier` in the file whose name passes `wanted`, in document order.
2612
+ *
2613
+ * Not `getDescendantsOfKind(SyntaxKind.Identifier)`. `Identifier` is kind 80 and sorts *below*
2614
+ * `SyntaxKind.FirstNode` (167), which is the boundary between tokens and parse-tree nodes — so
2615
+ * ts-morph cannot search the parse tree for it and falls back to materializing the whole
2616
+ * **token** tree. Measured at 27x this walk for the same 21,466 identifiers across 178 real
2617
+ * files, and `usedAsValue` below pays it once per name, so the file was re-scanned in full for
2618
+ * every binding it asked about.
2619
+ *
2620
+ * The name is tested on the compiler node, before any ts-morph wrapper is built, because the
2621
+ * wrapper is the expensive half and almost every identifier in a file is not one of the handful
2622
+ * this pass cares about. `nameOf` reads the same `escapedText` for an identifier, so the two
2623
+ * agree by construction.
2624
+ *
2625
+ * The JSDoc walk is load-bearing rather than defensive: `ts.forEachChild` does not descend into
2626
+ * JSDoc, but `getDescendantsOfKind` reaches it, and 72 of 1,116 files in this repository carry
2627
+ * an identifier visible only that way. Dropping those reads as "this token is never used" and
2628
+ * prunes a rule that is live — the silent direction, with no failing test to catch it.
2629
+ */
2630
+ function* identifiersNamed(sourceFile, wanted) {
2631
+ const found = [];
2632
+ const collect = (node) => {
2633
+ if (node.kind === ts_morph.SyntaxKind.Identifier && wanted(String(node.escapedText))) found.push(node);
2634
+ const jsDoc = node.jsDoc;
2635
+ if (jsDoc) for (const doc of jsDoc) collect(doc);
2636
+ ts_morph.ts.forEachChild(node, collect);
2637
+ };
2638
+ collect(sourceFile.compilerNode);
2639
+ const wrap = sourceFile;
2640
+ for (const node of found) yield wrap._getNodeFromCompilerNode(node);
2641
+ }
2611
2642
  const nameOf = (node) => ts_morph.Node.isIdentifier(node) ? String(node.compilerNode.escapedText) : node.getText();
2612
2643
  /** Every name a binding name binds, following object and array destructuring. */
2613
2644
  function boundNames(name, bound) {
@@ -2789,11 +2820,11 @@ function literalPath(call) {
2789
2820
  * matching the specifier test could re-export `token` under it.
2790
2821
  */
2791
2822
  function usedAsValue(sourceFile, name, declaration) {
2792
- return sourceFile.getDescendantsOfKind(ts_morph.SyntaxKind.Identifier).some((identifier) => {
2793
- if (nameOf(identifier) !== name) return false;
2794
- if (identifier.getFirstAncestor((ancestor) => ancestor === declaration)) return false;
2795
- return !identifier.getFirstAncestor((ancestor) => ts_morph.Node.isTypeNode(ancestor));
2796
- });
2823
+ for (const identifier of identifiersNamed(sourceFile, (candidate) => candidate === name)) {
2824
+ if (identifier.getFirstAncestor((ancestor) => ancestor === declaration)) continue;
2825
+ if (!identifier.getFirstAncestor((ancestor) => ts_morph.Node.isTypeNode(ancestor))) return true;
2826
+ }
2827
+ return false;
2797
2828
  }
2798
2829
  /**
2799
2830
  * Strip the wrappers that carry no runtime meaning.
package/dist/index.mjs CHANGED
@@ -23,7 +23,7 @@ import isGlob from "is-glob";
23
23
  import globParent from "glob-parent";
24
24
  import { isMatch } from "matcher";
25
25
  import { resolveTsPathPattern } from "@bamboocss/config/ts-path";
26
- import { Node, SyntaxKind } from "ts-morph";
26
+ import { Node, SyntaxKind, ts } from "ts-morph";
27
27
  import readline from "node:readline";
28
28
  import { lookItUpSync } from "look-it-up";
29
29
  import outdent$1, { outdent } from "outdent";
@@ -2543,9 +2543,8 @@ function accountFile(ctx, sourceFile, filePath, paths, prefixes, declined) {
2543
2543
  if (Node.isStringLiteral(argument) ? isTokensEntrypoint(ctx, argument.getLiteralValue()) : true) decline(call, isRequire ? "require" : "dynamic-import");
2544
2544
  }
2545
2545
  const shadows = shadowedScopes(sourceFile);
2546
- for (const identifier of sourceFile.getDescendantsOfKind(SyntaxKind.Identifier)) {
2546
+ for (const identifier of identifiersNamed(sourceFile, (name) => bindings.has(name) || name === "token")) {
2547
2547
  const text = nameOf(identifier);
2548
- if (!bindings.has(text) && text !== "token") continue;
2549
2548
  const parent = identifier.getParent();
2550
2549
  if (Node.isExportSpecifier(parent)) {
2551
2550
  const declaration = parent.getFirstAncestorByKind(SyntaxKind.ExportDeclaration);
@@ -2594,6 +2593,38 @@ function usesTokenMember(sourceFile, namespace) {
2594
2593
  * `token` is the identifier `token`; reading `getText()` returns the escape and compares
2595
2594
  * unequal, which let an import of the artifact's export past the checks that key on the name.
2596
2595
  */
2596
+ /**
2597
+ * Every `Identifier` in the file whose name passes `wanted`, in document order.
2598
+ *
2599
+ * Not `getDescendantsOfKind(SyntaxKind.Identifier)`. `Identifier` is kind 80 and sorts *below*
2600
+ * `SyntaxKind.FirstNode` (167), which is the boundary between tokens and parse-tree nodes — so
2601
+ * ts-morph cannot search the parse tree for it and falls back to materializing the whole
2602
+ * **token** tree. Measured at 27x this walk for the same 21,466 identifiers across 178 real
2603
+ * files, and `usedAsValue` below pays it once per name, so the file was re-scanned in full for
2604
+ * every binding it asked about.
2605
+ *
2606
+ * The name is tested on the compiler node, before any ts-morph wrapper is built, because the
2607
+ * wrapper is the expensive half and almost every identifier in a file is not one of the handful
2608
+ * this pass cares about. `nameOf` reads the same `escapedText` for an identifier, so the two
2609
+ * agree by construction.
2610
+ *
2611
+ * The JSDoc walk is load-bearing rather than defensive: `ts.forEachChild` does not descend into
2612
+ * JSDoc, but `getDescendantsOfKind` reaches it, and 72 of 1,116 files in this repository carry
2613
+ * an identifier visible only that way. Dropping those reads as "this token is never used" and
2614
+ * prunes a rule that is live — the silent direction, with no failing test to catch it.
2615
+ */
2616
+ function* identifiersNamed(sourceFile, wanted) {
2617
+ const found = [];
2618
+ const collect = (node) => {
2619
+ if (node.kind === SyntaxKind.Identifier && wanted(String(node.escapedText))) found.push(node);
2620
+ const jsDoc = node.jsDoc;
2621
+ if (jsDoc) for (const doc of jsDoc) collect(doc);
2622
+ ts.forEachChild(node, collect);
2623
+ };
2624
+ collect(sourceFile.compilerNode);
2625
+ const wrap = sourceFile;
2626
+ for (const node of found) yield wrap._getNodeFromCompilerNode(node);
2627
+ }
2597
2628
  const nameOf = (node) => Node.isIdentifier(node) ? String(node.compilerNode.escapedText) : node.getText();
2598
2629
  /** Every name a binding name binds, following object and array destructuring. */
2599
2630
  function boundNames(name, bound) {
@@ -2775,11 +2806,11 @@ function literalPath(call) {
2775
2806
  * matching the specifier test could re-export `token` under it.
2776
2807
  */
2777
2808
  function usedAsValue(sourceFile, name, declaration) {
2778
- return sourceFile.getDescendantsOfKind(SyntaxKind.Identifier).some((identifier) => {
2779
- if (nameOf(identifier) !== name) return false;
2780
- if (identifier.getFirstAncestor((ancestor) => ancestor === declaration)) return false;
2781
- return !identifier.getFirstAncestor((ancestor) => Node.isTypeNode(ancestor));
2782
- });
2809
+ for (const identifier of identifiersNamed(sourceFile, (candidate) => candidate === name)) {
2810
+ if (identifier.getFirstAncestor((ancestor) => ancestor === declaration)) continue;
2811
+ if (!identifier.getFirstAncestor((ancestor) => Node.isTypeNode(ancestor))) return true;
2812
+ }
2813
+ return false;
2783
2814
  }
2784
2815
  /**
2785
2816
  * Strip the wrappers that carry no runtime meaning.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bamboocss/node",
3
- "version": "1.44.1",
3
+ "version": "1.45.1",
4
4
  "description": "The core css bamboo library",
5
5
  "homepage": "https://bamboocss.com",
6
6
  "license": "MIT",
@@ -52,17 +52,17 @@
52
52
  "postcss": "8.5.26",
53
53
  "ts-morph": "28.0.0",
54
54
  "ts-pattern": "5.9.0",
55
- "@bamboocss/config": "1.44.1",
56
- "@bamboocss/generator": "1.44.1",
57
- "@bamboocss/core": "1.44.1",
58
- "@bamboocss/logger": "1.44.1",
59
- "@bamboocss/parser": "1.44.1",
60
- "@bamboocss/plugin-svelte": "1.44.1",
61
- "@bamboocss/plugin-vue": "1.44.1",
62
- "@bamboocss/reporter": "1.44.1",
63
- "@bamboocss/shared": "1.44.1",
64
- "@bamboocss/token-dictionary": "1.44.1",
65
- "@bamboocss/types": "1.44.1"
55
+ "@bamboocss/config": "1.45.1",
56
+ "@bamboocss/core": "1.45.1",
57
+ "@bamboocss/generator": "1.45.1",
58
+ "@bamboocss/logger": "1.45.1",
59
+ "@bamboocss/parser": "1.45.1",
60
+ "@bamboocss/plugin-svelte": "1.45.1",
61
+ "@bamboocss/plugin-vue": "1.45.1",
62
+ "@bamboocss/reporter": "1.45.1",
63
+ "@bamboocss/shared": "1.45.1",
64
+ "@bamboocss/token-dictionary": "1.45.1",
65
+ "@bamboocss/types": "1.45.1"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@types/fs-extra": "11.0.4",