@bamboocss/node 1.45.0 → 1.45.2
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 +39 -8
- package/dist/index.mjs +40 -9
- package/package.json +12 -12
package/dist/index.cjs
CHANGED
|
@@ -1895,7 +1895,7 @@ var BambooContext = class extends _bamboocss_generator.Generator {
|
|
|
1895
1895
|
let result;
|
|
1896
1896
|
try {
|
|
1897
1897
|
const encoder = styleEncoder || this.parserOptions.encoder;
|
|
1898
|
-
result = this.project.parseSourceFile(file, encoder);
|
|
1898
|
+
result = encoder.withOwner("extract", file, () => this.project.parseSourceFile(file, encoder));
|
|
1899
1899
|
this.parseFailures.delete(file);
|
|
1900
1900
|
} catch (error) {
|
|
1901
1901
|
_bamboocss_logger.logger.caughtError("file:extract", `Failed to parse ${file}`, error);
|
|
@@ -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.
|
|
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);
|
|
@@ -2603,6 +2602,38 @@ function usesTokenMember(sourceFile, namespace) {
|
|
|
2603
2602
|
});
|
|
2604
2603
|
}
|
|
2605
2604
|
/**
|
|
2605
|
+
* Every `Identifier` in the file whose name passes `wanted`, in document order.
|
|
2606
|
+
*
|
|
2607
|
+
* Not `getDescendantsOfKind(SyntaxKind.Identifier)`. `Identifier` is kind 80 and sorts *below*
|
|
2608
|
+
* `SyntaxKind.FirstNode` (167), which is the boundary between tokens and parse-tree nodes — so
|
|
2609
|
+
* ts-morph cannot search the parse tree for it and falls back to materializing the whole
|
|
2610
|
+
* **token** tree. Measured at 27x this walk for the same 21,466 identifiers across 178 real
|
|
2611
|
+
* files, and `usedAsValue` below pays it once per name, so the file was re-scanned in full for
|
|
2612
|
+
* every binding it asked about.
|
|
2613
|
+
*
|
|
2614
|
+
* The name is tested on the compiler node, before any ts-morph wrapper is built, because the
|
|
2615
|
+
* wrapper is the expensive half and almost every identifier in a file is not one of the handful
|
|
2616
|
+
* this pass cares about. `nameOf` reads the same `escapedText` for an identifier, so the two
|
|
2617
|
+
* agree by construction.
|
|
2618
|
+
*
|
|
2619
|
+
* The JSDoc walk is load-bearing rather than defensive: `ts.forEachChild` does not descend into
|
|
2620
|
+
* JSDoc, but `getDescendantsOfKind` reaches it, and 72 of 1,116 files in this repository carry
|
|
2621
|
+
* an identifier visible only that way. Dropping those reads as "this token is never used" and
|
|
2622
|
+
* prunes a rule that is live — the silent direction, with no failing test to catch it.
|
|
2623
|
+
*/
|
|
2624
|
+
function* identifiersNamed(sourceFile, wanted) {
|
|
2625
|
+
const found = [];
|
|
2626
|
+
const collect = (node) => {
|
|
2627
|
+
if (node.kind === ts_morph.SyntaxKind.Identifier && wanted(String(node.escapedText))) found.push(node);
|
|
2628
|
+
const jsDoc = node.jsDoc;
|
|
2629
|
+
if (jsDoc) for (const doc of jsDoc) collect(doc);
|
|
2630
|
+
ts_morph.ts.forEachChild(node, collect);
|
|
2631
|
+
};
|
|
2632
|
+
collect(sourceFile.compilerNode);
|
|
2633
|
+
const wrap = sourceFile;
|
|
2634
|
+
for (const node of found) yield wrap._getNodeFromCompilerNode(node);
|
|
2635
|
+
}
|
|
2636
|
+
/**
|
|
2606
2637
|
* An identifier's name as the compiler resolves it, not as it is spelled.
|
|
2607
2638
|
*
|
|
2608
2639
|
* `token` is the identifier `token`; reading `getText()` returns the escape and compares
|
|
@@ -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
|
-
|
|
2793
|
-
if (
|
|
2794
|
-
if (identifier.getFirstAncestor((ancestor) => ancestor
|
|
2795
|
-
|
|
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";
|
|
@@ -1881,7 +1881,7 @@ var BambooContext = class extends Generator {
|
|
|
1881
1881
|
let result;
|
|
1882
1882
|
try {
|
|
1883
1883
|
const encoder = styleEncoder || this.parserOptions.encoder;
|
|
1884
|
-
result = this.project.parseSourceFile(file, encoder);
|
|
1884
|
+
result = encoder.withOwner("extract", file, () => this.project.parseSourceFile(file, encoder));
|
|
1885
1885
|
this.parseFailures.delete(file);
|
|
1886
1886
|
} catch (error) {
|
|
1887
1887
|
logger.caughtError("file:extract", `Failed to parse ${file}`, error);
|
|
@@ -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.
|
|
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);
|
|
@@ -2589,6 +2588,38 @@ function usesTokenMember(sourceFile, namespace) {
|
|
|
2589
2588
|
});
|
|
2590
2589
|
}
|
|
2591
2590
|
/**
|
|
2591
|
+
* Every `Identifier` in the file whose name passes `wanted`, in document order.
|
|
2592
|
+
*
|
|
2593
|
+
* Not `getDescendantsOfKind(SyntaxKind.Identifier)`. `Identifier` is kind 80 and sorts *below*
|
|
2594
|
+
* `SyntaxKind.FirstNode` (167), which is the boundary between tokens and parse-tree nodes — so
|
|
2595
|
+
* ts-morph cannot search the parse tree for it and falls back to materializing the whole
|
|
2596
|
+
* **token** tree. Measured at 27x this walk for the same 21,466 identifiers across 178 real
|
|
2597
|
+
* files, and `usedAsValue` below pays it once per name, so the file was re-scanned in full for
|
|
2598
|
+
* every binding it asked about.
|
|
2599
|
+
*
|
|
2600
|
+
* The name is tested on the compiler node, before any ts-morph wrapper is built, because the
|
|
2601
|
+
* wrapper is the expensive half and almost every identifier in a file is not one of the handful
|
|
2602
|
+
* this pass cares about. `nameOf` reads the same `escapedText` for an identifier, so the two
|
|
2603
|
+
* agree by construction.
|
|
2604
|
+
*
|
|
2605
|
+
* The JSDoc walk is load-bearing rather than defensive: `ts.forEachChild` does not descend into
|
|
2606
|
+
* JSDoc, but `getDescendantsOfKind` reaches it, and 72 of 1,116 files in this repository carry
|
|
2607
|
+
* an identifier visible only that way. Dropping those reads as "this token is never used" and
|
|
2608
|
+
* prunes a rule that is live — the silent direction, with no failing test to catch it.
|
|
2609
|
+
*/
|
|
2610
|
+
function* identifiersNamed(sourceFile, wanted) {
|
|
2611
|
+
const found = [];
|
|
2612
|
+
const collect = (node) => {
|
|
2613
|
+
if (node.kind === SyntaxKind.Identifier && wanted(String(node.escapedText))) found.push(node);
|
|
2614
|
+
const jsDoc = node.jsDoc;
|
|
2615
|
+
if (jsDoc) for (const doc of jsDoc) collect(doc);
|
|
2616
|
+
ts.forEachChild(node, collect);
|
|
2617
|
+
};
|
|
2618
|
+
collect(sourceFile.compilerNode);
|
|
2619
|
+
const wrap = sourceFile;
|
|
2620
|
+
for (const node of found) yield wrap._getNodeFromCompilerNode(node);
|
|
2621
|
+
}
|
|
2622
|
+
/**
|
|
2592
2623
|
* An identifier's name as the compiler resolves it, not as it is spelled.
|
|
2593
2624
|
*
|
|
2594
2625
|
* `token` is the identifier `token`; reading `getText()` returns the escape and compares
|
|
@@ -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
|
-
|
|
2779
|
-
if (
|
|
2780
|
-
if (identifier.getFirstAncestor((ancestor) => ancestor
|
|
2781
|
-
|
|
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.45.
|
|
3
|
+
"version": "1.45.2",
|
|
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.45.
|
|
56
|
-
"@bamboocss/core": "1.45.
|
|
57
|
-
"@bamboocss/generator": "1.45.
|
|
58
|
-
"@bamboocss/logger": "1.45.
|
|
59
|
-
"@bamboocss/parser": "1.45.
|
|
60
|
-
"@bamboocss/plugin-svelte": "1.45.
|
|
61
|
-
"@bamboocss/plugin-vue": "1.45.
|
|
62
|
-
"@bamboocss/reporter": "1.45.
|
|
63
|
-
"@bamboocss/shared": "1.45.
|
|
64
|
-
"@bamboocss/token-dictionary": "1.45.
|
|
65
|
-
"@bamboocss/types": "1.45.
|
|
55
|
+
"@bamboocss/config": "1.45.2",
|
|
56
|
+
"@bamboocss/core": "1.45.2",
|
|
57
|
+
"@bamboocss/generator": "1.45.2",
|
|
58
|
+
"@bamboocss/logger": "1.45.2",
|
|
59
|
+
"@bamboocss/parser": "1.45.2",
|
|
60
|
+
"@bamboocss/plugin-svelte": "1.45.2",
|
|
61
|
+
"@bamboocss/plugin-vue": "1.45.2",
|
|
62
|
+
"@bamboocss/reporter": "1.45.2",
|
|
63
|
+
"@bamboocss/shared": "1.45.2",
|
|
64
|
+
"@bamboocss/token-dictionary": "1.45.2",
|
|
65
|
+
"@bamboocss/types": "1.45.2"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@types/fs-extra": "11.0.4",
|