@bamboocss/node 1.49.0 → 1.50.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 +137 -103
- package/dist/index.d.cts +700 -1
- package/dist/index.d.mts +700 -1
- package/dist/index.mjs +118 -84
- package/package.json +13 -13
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isStaticCompilerActive, markStaticCompilerActive } from "./static-compiler.mjs";
|
|
2
2
|
import { colors, logger, quote } from "@bamboocss/logger";
|
|
3
|
+
import { Node, SyntaxKind, childOf, forEachDescendant, getAliasNode, getDefaultImport, getDescendantsOfKind, getExportDeclarations, getFirstAncestor, getFirstAncestorByKind, getLineAndColumnAtPos, getLiteralText, getModuleSpecifierValue, getNamedImports, getNamespaceImport, isTypeOnly, nameNodeOf, stringLiteralValue, ts } from "@bamboocss/ts-ast";
|
|
3
4
|
import { convertTsPathsToRegexes, diffConfigs, findConfig, loadConfig, mergeHooks } from "@bamboocss/config";
|
|
4
5
|
import { BambooError, cssVarRefs, groupBy, truncateList, uniq } from "@bamboocss/shared";
|
|
5
6
|
import { createHash } from "node:crypto";
|
|
@@ -17,7 +18,6 @@ import os from "node:os";
|
|
|
17
18
|
import tty from "node:tty";
|
|
18
19
|
import fs, { promises } from "node:fs";
|
|
19
20
|
import path from "node:path";
|
|
20
|
-
import { Node, SyntaxKind, ts } from "ts-morph";
|
|
21
21
|
import chokidar from "chokidar";
|
|
22
22
|
import glob from "fast-glob";
|
|
23
23
|
import fsExtra from "fs-extra";
|
|
@@ -1659,7 +1659,7 @@ const collectReferenceGraph = async (rootPath, rootParsed, parseTsconfig, cache)
|
|
|
1659
1659
|
visited.add(referencedPath);
|
|
1660
1660
|
try {
|
|
1661
1661
|
const source = await promises.readFile(referencedPath, "utf8");
|
|
1662
|
-
|
|
1662
|
+
JSON.parse(source.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[^:])\/\/.*$/gm, "$1"));
|
|
1663
1663
|
queue.push({
|
|
1664
1664
|
parsed: parseTsconfig(referencedPath, cache),
|
|
1665
1665
|
path: referencedPath
|
|
@@ -1814,6 +1814,21 @@ function globDirname(globs) {
|
|
|
1814
1814
|
* mutated.
|
|
1815
1815
|
*/
|
|
1816
1816
|
const globIgnore = (exclude) => ["**/*.d.ts", ...exclude ?? []];
|
|
1817
|
+
/**
|
|
1818
|
+
* The order the source glob returns files in, made a decision rather than an accident.
|
|
1819
|
+
*
|
|
1820
|
+
* `fast-glob` hands back whatever `readdir` gave it, which is the filesystem's order and is not
|
|
1821
|
+
* the same on every machine. That order is not cosmetic: it is the order atoms enter the sheet,
|
|
1822
|
+
* and sheet order is what decides a conflict between two classes on one element — `cx` joins
|
|
1823
|
+
* them and the browser picks by position, not by the order they were passed. So an unsorted
|
|
1824
|
+
* glob lets two checkouts of the same commit build stylesheets that resolve the same conflict
|
|
1825
|
+
* differently, and makes the emitted bytes irreproducible, which is also what content-hashed
|
|
1826
|
+
* asset caching is keyed on.
|
|
1827
|
+
*
|
|
1828
|
+
* Sorted by code unit rather than `localeCompare`, whose answer depends on the host's locale —
|
|
1829
|
+
* the exact class of machine-dependence this exists to remove.
|
|
1830
|
+
*/
|
|
1831
|
+
const sortSources = (files) => files.sort();
|
|
1817
1832
|
const nodeRuntime = {
|
|
1818
1833
|
cwd() {
|
|
1819
1834
|
return process.cwd();
|
|
@@ -1840,11 +1855,11 @@ const nodeRuntime = {
|
|
|
1840
1855
|
},
|
|
1841
1856
|
glob(opts) {
|
|
1842
1857
|
if (!opts.include) return [];
|
|
1843
|
-
return glob.sync(opts.include, {
|
|
1858
|
+
return sortSources(glob.sync(opts.include, {
|
|
1844
1859
|
cwd: opts.cwd,
|
|
1845
1860
|
ignore: globIgnore(opts.exclude),
|
|
1846
1861
|
absolute: true
|
|
1847
|
-
});
|
|
1862
|
+
}));
|
|
1848
1863
|
},
|
|
1849
1864
|
writeFile: fsExtra.writeFile,
|
|
1850
1865
|
writeFileSync: fsExtra.writeFileSync,
|
|
@@ -1989,10 +2004,36 @@ var OutputEngine = class {
|
|
|
1989
2004
|
const absPath = this.path.join(...dir, file);
|
|
1990
2005
|
logger.debug("write:file", dir.slice(-1).concat(file).join("/"));
|
|
1991
2006
|
if (file === "package.json") return this.writePackageJson(absPath, code);
|
|
2007
|
+
if (this.isUnchanged(absPath, code)) {
|
|
2008
|
+
logger.debug("write:unchanged", dir.slice(-1).concat(file).join("/"));
|
|
2009
|
+
return;
|
|
2010
|
+
}
|
|
1992
2011
|
return this.fs.writeFile(absPath, code);
|
|
1993
2012
|
}));
|
|
1994
2013
|
};
|
|
1995
2014
|
/**
|
|
2015
|
+
* Whether the file on disk already holds exactly what codegen would write.
|
|
2016
|
+
*
|
|
2017
|
+
* Not for the write itself, which is cheap — 54 artifacts and 1.4 MB measure ~6ms, against
|
|
2018
|
+
* ~1.3ms to read them back and compare. It is for the mtime. Codegen rewrote every artifact
|
|
2019
|
+
* on every build whether or not a byte moved, and most builds move nothing: `csstype.d.ts` is
|
|
2020
|
+
* copied verbatim from a constant and accounts for 895 kB on its own. Everything downstream
|
|
2021
|
+
* watches those files — the dev server's module graph, `tsc --incremental`, any bundler with
|
|
2022
|
+
* the output directory in scope — and each of them re-does work for a file that is identical
|
|
2023
|
+
* to the one it already read.
|
|
2024
|
+
*
|
|
2025
|
+
* A read that throws is an answer, not a failure: the file is unreadable or absent, so it has
|
|
2026
|
+
* to be written.
|
|
2027
|
+
*/
|
|
2028
|
+
isUnchanged = (absPath, code) => {
|
|
2029
|
+
if (!this.fs.existsSync(absPath)) return false;
|
|
2030
|
+
try {
|
|
2031
|
+
return this.fs.readFileSync(absPath) === code;
|
|
2032
|
+
} catch {
|
|
2033
|
+
return false;
|
|
2034
|
+
}
|
|
2035
|
+
};
|
|
2036
|
+
/**
|
|
1996
2037
|
* Unlike the rest of the output, `package.json` is not exclusively ours: `emit-pkg`
|
|
1997
2038
|
* writes entrypoints to the same path, and consumers hand-edit it. Overwriting would
|
|
1998
2039
|
* drop that, so only keys that are absent get filled in — anything already declared,
|
|
@@ -2076,6 +2117,9 @@ var BambooContext = class extends Generator {
|
|
|
2076
2117
|
config.cwd ||= this.runtime.cwd();
|
|
2077
2118
|
if (config.logLevel) logger.level = config.logLevel;
|
|
2078
2119
|
this.project = new Project({
|
|
2120
|
+
cwd: config.cwd ?? this.runtime.cwd(),
|
|
2121
|
+
tsConfigFilePath: conf.tsconfigFile ?? `${config.cwd ?? this.runtime.cwd()}/tsconfig.json`,
|
|
2122
|
+
fs: { readFile: (filePath) => this.runtime.fs.readFileSync(filePath) },
|
|
2079
2123
|
...conf.tsconfig,
|
|
2080
2124
|
deferInitialSourceFiles: true,
|
|
2081
2125
|
resolutionConfigFiles: getTsConfigResolutionFiles(conf),
|
|
@@ -2517,7 +2561,7 @@ function accountSnapshot(ctx, snapshot, accounting) {
|
|
|
2517
2561
|
});
|
|
2518
2562
|
return;
|
|
2519
2563
|
}
|
|
2520
|
-
if (
|
|
2564
|
+
if (ctx.project.getSyntacticDiagnosticCount(filePath)) {
|
|
2521
2565
|
if (!mentionsToken(ctx, parsed)) return;
|
|
2522
2566
|
declined.push({
|
|
2523
2567
|
filePath,
|
|
@@ -2559,15 +2603,6 @@ const mentionsToken = (ctx, text) => {
|
|
|
2559
2603
|
if (ctx.imports.value.tokens.some((mod) => text.includes(mod))) return true;
|
|
2560
2604
|
return IMPORTING_CALL.test(text);
|
|
2561
2605
|
};
|
|
2562
|
-
/**
|
|
2563
|
-
* How many syntax errors the parse produced.
|
|
2564
|
-
*
|
|
2565
|
-
* `parseDiagnostics` is TypeScript-internal and absent from the public `SourceFile` type, so
|
|
2566
|
-
* it is reached through a cast. The alternative, `getPreEmitDiagnostics`, runs the type checker
|
|
2567
|
-
* over the whole program — orders of magnitude more work for a question about syntax, and it
|
|
2568
|
-
* would report type errors this pass has no business declining over.
|
|
2569
|
-
*/
|
|
2570
|
-
const parseErrorCount = (sourceFile) => sourceFile.compilerNode.parseDiagnostics?.length ?? 0;
|
|
2571
2606
|
/** Whether a module specifier resolves to the generated tokens artifact. */
|
|
2572
2607
|
const isTokensEntrypoint = (ctx, specifier) => {
|
|
2573
2608
|
const mods = ctx.imports.value.tokens;
|
|
@@ -2578,7 +2613,7 @@ const isTokensEntrypoint = (ctx, specifier) => {
|
|
|
2578
2613
|
if (!resolved) return false;
|
|
2579
2614
|
return mods.some((mod) => resolved.includes(mod) || resolved === mod);
|
|
2580
2615
|
};
|
|
2581
|
-
const lineOf = (node) => node.getSourceFile()
|
|
2616
|
+
const lineOf = (node) => getLineAndColumnAtPos(node.getSourceFile(), node.getStart()).line;
|
|
2582
2617
|
function accountFile(ctx, sourceFile, filePath, paths, prefixes, declined) {
|
|
2583
2618
|
const decline = (node, reason) => declined.push({
|
|
2584
2619
|
filePath,
|
|
@@ -2589,59 +2624,59 @@ function accountFile(ctx, sourceFile, filePath, paths, prefixes, declined) {
|
|
|
2589
2624
|
});
|
|
2590
2625
|
/** Local names bound to the artifact: the `token` export, and any namespace of it. */
|
|
2591
2626
|
const bindings = /* @__PURE__ */ new Set();
|
|
2592
|
-
for (const statement of sourceFile.
|
|
2627
|
+
for (const statement of sourceFile.statements) {
|
|
2593
2628
|
if (Node.isExportDeclaration(statement)) {
|
|
2594
|
-
const specifier =
|
|
2629
|
+
const specifier = getModuleSpecifierValue(statement);
|
|
2595
2630
|
if (specifier && isTokensEntrypoint(ctx, specifier)) decline(statement, "re-exported");
|
|
2596
2631
|
continue;
|
|
2597
2632
|
}
|
|
2598
2633
|
if (!Node.isImportDeclaration(statement)) continue;
|
|
2599
|
-
const specifier =
|
|
2634
|
+
const specifier = getModuleSpecifierValue(statement);
|
|
2600
2635
|
if (!specifier) continue;
|
|
2601
|
-
const clause = statement.
|
|
2602
|
-
if (!clause ||
|
|
2636
|
+
const clause = statement.importClause;
|
|
2637
|
+
if (!clause || isTypeOnly(statement)) continue;
|
|
2603
2638
|
if (!isTokensEntrypoint(ctx, specifier)) {
|
|
2604
|
-
for (const named of
|
|
2605
|
-
const foreignDefault =
|
|
2639
|
+
for (const named of getNamedImports(clause)) if (!isTypeOnly(named) && nameOf(nameNodeOf(named)) === "token") decline(named, "unclassified-import");
|
|
2640
|
+
const foreignDefault = getDefaultImport(clause);
|
|
2606
2641
|
if (foreignDefault && nameOf(foreignDefault) === "token") decline(foreignDefault, "unclassified-import");
|
|
2607
|
-
const foreignNamespace =
|
|
2642
|
+
const foreignNamespace = getNamespaceImport(clause);
|
|
2608
2643
|
if (foreignNamespace && usesTokenMember(sourceFile, foreignNamespace.getText())) decline(foreignNamespace, "unclassified-import");
|
|
2609
2644
|
continue;
|
|
2610
2645
|
}
|
|
2611
|
-
const defaultImport =
|
|
2646
|
+
const defaultImport = getDefaultImport(clause);
|
|
2612
2647
|
if (defaultImport) decline(defaultImport, "unsupported-import");
|
|
2613
|
-
const namespace =
|
|
2648
|
+
const namespace = getNamespaceImport(clause);
|
|
2614
2649
|
if (namespace) bindings.add(namespace.getText());
|
|
2615
|
-
for (const named of
|
|
2616
|
-
if (
|
|
2617
|
-
if (nameOf(named
|
|
2618
|
-
if (usedAsValue(sourceFile, (
|
|
2650
|
+
for (const named of getNamedImports(clause)) {
|
|
2651
|
+
if (isTypeOnly(named)) continue;
|
|
2652
|
+
if (nameOf(nameNodeOf(named)) !== "token") {
|
|
2653
|
+
if (usedAsValue(sourceFile, (getAliasNode(named) ?? nameNodeOf(named))?.getText() ?? "", named)) decline(named, "unsupported-import");
|
|
2619
2654
|
continue;
|
|
2620
2655
|
}
|
|
2621
|
-
bindings.add((
|
|
2656
|
+
bindings.add((getAliasNode(named) ?? nameNodeOf(named))?.getText() ?? "");
|
|
2622
2657
|
}
|
|
2623
2658
|
}
|
|
2624
|
-
for (const importEquals of
|
|
2625
|
-
for (const call of
|
|
2626
|
-
const callee = call
|
|
2627
|
-
const isRequire = Node.isIdentifier(callee) && callee.getText() === "require";
|
|
2628
|
-
const isDynamicImport = callee
|
|
2659
|
+
for (const importEquals of getDescendantsOfKind(sourceFile, SyntaxKind.ImportEqualsDeclaration)) if (importEquals.getText().includes("token")) decline(importEquals, "import-equals");
|
|
2660
|
+
for (const call of getDescendantsOfKind(sourceFile, SyntaxKind.CallExpression)) {
|
|
2661
|
+
const callee = childOf(call, "expression");
|
|
2662
|
+
const isRequire = callee !== void 0 && Node.isIdentifier(callee) && callee.getText() === "require";
|
|
2663
|
+
const isDynamicImport = callee?.kind === SyntaxKind.ImportKeyword;
|
|
2629
2664
|
if (!isRequire && !isDynamicImport) continue;
|
|
2630
|
-
const argument = call
|
|
2665
|
+
const argument = childOf(call, "arguments")?.[0];
|
|
2631
2666
|
if (!argument) continue;
|
|
2632
|
-
if (Node.isStringLiteral(argument) ? isTokensEntrypoint(ctx, argument
|
|
2667
|
+
if (Node.isStringLiteral(argument) ? isTokensEntrypoint(ctx, stringLiteralValue(argument)) : true) decline(call, isRequire ? "require" : "dynamic-import");
|
|
2633
2668
|
}
|
|
2634
2669
|
const shadows = shadowedScopes(sourceFile);
|
|
2635
2670
|
for (const identifier of identifiersNamed(sourceFile, (name) => bindings.has(name) || name === "token")) {
|
|
2636
2671
|
const text = nameOf(identifier);
|
|
2637
|
-
const parent = identifier.
|
|
2672
|
+
const parent = identifier.parent;
|
|
2638
2673
|
if (Node.isExportSpecifier(parent)) {
|
|
2639
|
-
const declaration =
|
|
2640
|
-
if (declaration && !declaration
|
|
2674
|
+
const declaration = getFirstAncestorByKind(parent, SyntaxKind.ExportDeclaration);
|
|
2675
|
+
if (declaration && !childOf(declaration, "moduleSpecifier")) decline(identifier, "re-exported");
|
|
2641
2676
|
continue;
|
|
2642
2677
|
}
|
|
2643
|
-
if (Node.isPropertyAccessExpression(parent) && parent.
|
|
2644
|
-
const object = parent.
|
|
2678
|
+
if (Node.isPropertyAccessExpression(parent) && parent.name === identifier) {
|
|
2679
|
+
const object = parent.expression;
|
|
2645
2680
|
const objectName = Node.isIdentifier(object) ? object.getText() : void 0;
|
|
2646
2681
|
if (objectName && bindings.has(objectName)) continue;
|
|
2647
2682
|
decline(identifier, "unresolved-reference");
|
|
@@ -2669,11 +2704,11 @@ function accountFile(ctx, sourceFile, filePath, paths, prefixes, declined) {
|
|
|
2669
2704
|
* property-access-only scan.
|
|
2670
2705
|
*/
|
|
2671
2706
|
function usesTokenMember(sourceFile, namespace) {
|
|
2672
|
-
if (
|
|
2673
|
-
return
|
|
2674
|
-
if (access
|
|
2675
|
-
const argument = access
|
|
2676
|
-
return argument != null && (!Node.isStringLiteral(argument) || argument
|
|
2707
|
+
if (getDescendantsOfKind(sourceFile, SyntaxKind.PropertyAccessExpression).some((access) => childOf(access, "expression")?.getText() === namespace && nameOf(nameNodeOf(access)) === "token")) return true;
|
|
2708
|
+
return getDescendantsOfKind(sourceFile, SyntaxKind.ElementAccessExpression).some((access) => {
|
|
2709
|
+
if (childOf(access, "expression")?.getText() !== namespace) return false;
|
|
2710
|
+
const argument = childOf(access, "argumentExpression");
|
|
2711
|
+
return argument != null && (!Node.isStringLiteral(argument) || stringLiteralValue(argument) === "token");
|
|
2677
2712
|
});
|
|
2678
2713
|
}
|
|
2679
2714
|
/**
|
|
@@ -2699,14 +2734,13 @@ function usesTokenMember(sourceFile, namespace) {
|
|
|
2699
2734
|
function* identifiersNamed(sourceFile, wanted) {
|
|
2700
2735
|
const found = [];
|
|
2701
2736
|
const collect = (node) => {
|
|
2702
|
-
if (node.kind === SyntaxKind.Identifier && wanted(String(node.
|
|
2737
|
+
if (node.kind === SyntaxKind.Identifier && wanted(String(node.text))) found.push(node);
|
|
2703
2738
|
const jsDoc = node.jsDoc;
|
|
2704
2739
|
if (jsDoc) for (const doc of jsDoc) collect(doc);
|
|
2705
2740
|
ts.forEachChild(node, collect);
|
|
2706
2741
|
};
|
|
2707
|
-
collect(sourceFile
|
|
2708
|
-
const
|
|
2709
|
-
for (const node of found) yield wrap._getNodeFromCompilerNode(node);
|
|
2742
|
+
collect(sourceFile);
|
|
2743
|
+
for (const node of found) yield node;
|
|
2710
2744
|
}
|
|
2711
2745
|
/**
|
|
2712
2746
|
* An identifier's name as the compiler resolves it, not as it is spelled.
|
|
@@ -2714,7 +2748,7 @@ function* identifiersNamed(sourceFile, wanted) {
|
|
|
2714
2748
|
* `token` is the identifier `token`; reading `getText()` returns the escape and compares
|
|
2715
2749
|
* unequal, which let an import of the artifact's export past the checks that key on the name.
|
|
2716
2750
|
*/
|
|
2717
|
-
const nameOf = (node) => Node.isIdentifier(node) ? String(node.
|
|
2751
|
+
const nameOf = (node) => Node.isIdentifier(node) ? String(node.text) : node.getText();
|
|
2718
2752
|
/** Every name a binding name binds, following object and array destructuring. */
|
|
2719
2753
|
function boundNames(name, bound) {
|
|
2720
2754
|
if (!name) return;
|
|
@@ -2723,7 +2757,7 @@ function boundNames(name, bound) {
|
|
|
2723
2757
|
return;
|
|
2724
2758
|
}
|
|
2725
2759
|
if (!Node.isObjectBindingPattern(name) && !Node.isArrayBindingPattern(name)) return;
|
|
2726
|
-
for (const element of name.
|
|
2760
|
+
for (const element of name.elements) if (Node.isBindingElement(element)) boundNames(element.name, bound);
|
|
2727
2761
|
}
|
|
2728
2762
|
/**
|
|
2729
2763
|
* Scopes that bind a name to something which cannot be the artifact, keyed by that name.
|
|
@@ -2759,23 +2793,23 @@ function shadowedScopes(sourceFile) {
|
|
|
2759
2793
|
else scopes.set(name, [scope]);
|
|
2760
2794
|
};
|
|
2761
2795
|
const variables = [];
|
|
2762
|
-
|
|
2796
|
+
forEachDescendant(sourceFile, (node) => {
|
|
2763
2797
|
if (Node.isParameterDeclaration(node)) {
|
|
2764
|
-
const scope = node.
|
|
2765
|
-
boundNames(node.
|
|
2798
|
+
const scope = node.parent;
|
|
2799
|
+
boundNames(node.name, (name) => add(name, scope));
|
|
2766
2800
|
return;
|
|
2767
2801
|
}
|
|
2768
2802
|
if (Node.isCatchClause(node)) {
|
|
2769
|
-
boundNames(node.
|
|
2803
|
+
boundNames(node.variableDeclaration?.name, (name) => add(name, node));
|
|
2770
2804
|
return;
|
|
2771
2805
|
}
|
|
2772
2806
|
if (Node.isFunctionDeclaration(node) || Node.isClassDeclaration(node)) {
|
|
2773
|
-
const name = node.
|
|
2774
|
-
if (name) add(nameOf(name), node.
|
|
2807
|
+
const name = node.name;
|
|
2808
|
+
if (name) add(nameOf(name), node.parent);
|
|
2775
2809
|
return;
|
|
2776
2810
|
}
|
|
2777
2811
|
if (Node.isFunctionExpression(node) || Node.isClassExpression(node)) {
|
|
2778
|
-
const name = node.
|
|
2812
|
+
const name = node.name;
|
|
2779
2813
|
if (name) add(nameOf(name), node);
|
|
2780
2814
|
return;
|
|
2781
2815
|
}
|
|
@@ -2783,10 +2817,10 @@ function shadowedScopes(sourceFile) {
|
|
|
2783
2817
|
});
|
|
2784
2818
|
for (const declaration of variables) {
|
|
2785
2819
|
if (!Node.isVariableDeclaration(declaration)) continue;
|
|
2786
|
-
const root = rootIdentifier(declaration.
|
|
2820
|
+
const root = rootIdentifier(declaration.initializer);
|
|
2787
2821
|
if (!root || !isShadowed(root, scopes.get(nameOf(root)))) continue;
|
|
2788
|
-
const scope =
|
|
2789
|
-
boundNames(declaration.
|
|
2822
|
+
const scope = getFirstAncestor(declaration, (ancestor) => Node.isBlock(ancestor) || Node.isSourceFile(ancestor) || Node.isModuleBlock(ancestor) || Node.isCaseClause(ancestor) || Node.isDefaultClause(ancestor) || Node.isForStatement(ancestor) || Node.isForOfStatement(ancestor) || Node.isForInStatement(ancestor));
|
|
2823
|
+
boundNames(declaration.name, (name) => add(name, scope));
|
|
2790
2824
|
}
|
|
2791
2825
|
return scopes;
|
|
2792
2826
|
}
|
|
@@ -2798,7 +2832,7 @@ function shadowedScopes(sourceFile) {
|
|
|
2798
2832
|
*/
|
|
2799
2833
|
function rootIdentifier(expression) {
|
|
2800
2834
|
let current = expression;
|
|
2801
|
-
while (current && (Node.isPropertyAccessExpression(current) || Node.isElementAccessExpression(current))) current = current.
|
|
2835
|
+
while (current && (Node.isPropertyAccessExpression(current) || Node.isElementAccessExpression(current))) current = current.expression;
|
|
2802
2836
|
return current && Node.isIdentifier(current) ? current : void 0;
|
|
2803
2837
|
}
|
|
2804
2838
|
/**
|
|
@@ -2813,7 +2847,7 @@ function rootIdentifier(expression) {
|
|
|
2813
2847
|
* the binding, so it is a reference like any other.
|
|
2814
2848
|
*/
|
|
2815
2849
|
function isDeclarationName(identifier, parent) {
|
|
2816
|
-
if (Node.isPropertyAssignment(parent) || Node.
|
|
2850
|
+
if (Node.isPropertyAssignment(parent) || Node.isPropertySignatureDeclaration(parent) || Node.isMethodSignatureDeclaration(parent) || Node.isPropertyDeclaration(parent) || Node.isMethodDeclaration(parent) || Node.isEnumMember(parent)) return nameNodeOf(parent) === identifier;
|
|
2817
2851
|
return false;
|
|
2818
2852
|
}
|
|
2819
2853
|
/**
|
|
@@ -2837,20 +2871,20 @@ function isShadowed(identifier, scopes) {
|
|
|
2837
2871
|
* (`useMemo(() => token)`), spread, or enumerated.
|
|
2838
2872
|
*/
|
|
2839
2873
|
function accountedPath(identifier) {
|
|
2840
|
-
const parent = identifier.
|
|
2874
|
+
const parent = identifier.parent;
|
|
2841
2875
|
if (!parent) return void 0;
|
|
2842
2876
|
if (Node.isImportSpecifier(parent) || Node.isNamespaceImport(parent) || Node.isImportClause(parent) || Node.isExportSpecifier(parent)) return { kind: "binding" };
|
|
2843
|
-
if (Node.isCallExpression(parent) && parent.
|
|
2844
|
-
if (!Node.isPropertyAccessExpression(parent) || parent.
|
|
2845
|
-
const property = parent.
|
|
2846
|
-
const grandParent = parent.
|
|
2847
|
-
if (property === "value") return Node.isCallExpression(grandParent) && grandParent.
|
|
2877
|
+
if (Node.isCallExpression(parent) && parent.expression === identifier) return literalPath(parent);
|
|
2878
|
+
if (!Node.isPropertyAccessExpression(parent) || parent.expression !== identifier) return void 0;
|
|
2879
|
+
const property = parent.name.getText();
|
|
2880
|
+
const grandParent = parent.parent;
|
|
2881
|
+
if (property === "value") return Node.isCallExpression(grandParent) && grandParent.expression === parent ? literalPath(grandParent) : void 0;
|
|
2848
2882
|
if (property !== "token") return void 0;
|
|
2849
|
-
if (Node.isCallExpression(grandParent) && grandParent.
|
|
2850
|
-
if (Node.isPropertyAccessExpression(grandParent) && grandParent.
|
|
2851
|
-
if (grandParent.
|
|
2852
|
-
const call = grandParent.
|
|
2853
|
-
return Node.isCallExpression(call) && call.
|
|
2883
|
+
if (Node.isCallExpression(grandParent) && grandParent.expression === parent) return literalPath(grandParent);
|
|
2884
|
+
if (Node.isPropertyAccessExpression(grandParent) && grandParent.expression === parent) {
|
|
2885
|
+
if (grandParent.name.getText() !== "value") return void 0;
|
|
2886
|
+
const call = grandParent.parent;
|
|
2887
|
+
return Node.isCallExpression(call) && call.expression === grandParent ? literalPath(call) : void 0;
|
|
2854
2888
|
}
|
|
2855
2889
|
}
|
|
2856
2890
|
/**
|
|
@@ -2869,18 +2903,18 @@ function accountedPath(identifier) {
|
|
|
2869
2903
|
*/
|
|
2870
2904
|
function literalPath(call) {
|
|
2871
2905
|
if (!Node.isCallExpression(call)) return void 0;
|
|
2872
|
-
const argument = unwrapAssertions(call.
|
|
2906
|
+
const argument = unwrapAssertions(call.arguments[0]);
|
|
2873
2907
|
if (!argument) return void 0;
|
|
2874
2908
|
if (Node.isStringLiteral(argument)) return {
|
|
2875
2909
|
kind: "path",
|
|
2876
|
-
value: argument
|
|
2910
|
+
value: stringLiteralValue(argument)
|
|
2877
2911
|
};
|
|
2878
2912
|
if (Node.isNoSubstitutionTemplateLiteral(argument)) return {
|
|
2879
2913
|
kind: "path",
|
|
2880
|
-
value: argument
|
|
2914
|
+
value: stringLiteralValue(argument)
|
|
2881
2915
|
};
|
|
2882
2916
|
if (Node.isTemplateExpression(argument)) {
|
|
2883
|
-
const head = argument.
|
|
2917
|
+
const head = getLiteralText(argument.head);
|
|
2884
2918
|
return head ? {
|
|
2885
2919
|
kind: "prefix",
|
|
2886
2920
|
value: head
|
|
@@ -2896,8 +2930,8 @@ function literalPath(call) {
|
|
|
2896
2930
|
*/
|
|
2897
2931
|
function usedAsValue(sourceFile, name, declaration) {
|
|
2898
2932
|
for (const identifier of identifiersNamed(sourceFile, (candidate) => candidate === name)) {
|
|
2899
|
-
if (
|
|
2900
|
-
if (!
|
|
2933
|
+
if (getFirstAncestor(identifier, (ancestor) => ancestor === declaration)) continue;
|
|
2934
|
+
if (!getFirstAncestor(identifier, (ancestor) => Node.isTypeNode(ancestor))) return true;
|
|
2901
2935
|
}
|
|
2902
2936
|
return false;
|
|
2903
2937
|
}
|
|
@@ -2915,7 +2949,7 @@ function usedAsValue(sourceFile, name, declaration) {
|
|
|
2915
2949
|
*/
|
|
2916
2950
|
function unwrapAssertions(node) {
|
|
2917
2951
|
let current = node;
|
|
2918
|
-
while (current && (Node.isAsExpression(current) || Node.isSatisfiesExpression(current) || Node.isNonNullExpression(current) || Node.isParenthesizedExpression(current) || Node.isTypeAssertion(current))) current = current.
|
|
2952
|
+
while (current && (Node.isAsExpression(current) || Node.isSatisfiesExpression(current) || Node.isNonNullExpression(current) || Node.isParenthesizedExpression(current) || Node.isTypeAssertion(current))) current = current.expression;
|
|
2919
2953
|
return current;
|
|
2920
2954
|
}
|
|
2921
2955
|
//#endregion
|
|
@@ -3763,7 +3797,7 @@ var Builder = class {
|
|
|
3763
3797
|
const recipes = [];
|
|
3764
3798
|
for (const set of [parserResult?.cva, parserResult?.sva]) for (const item of set ?? []) recipes.push([item.name ?? "", item.data]);
|
|
3765
3799
|
const sourceFile = ctx.project?.getSourceFile?.(file);
|
|
3766
|
-
const exports = sourceFile ?
|
|
3800
|
+
const exports = sourceFile ? getExportDeclarations(sourceFile).map((declaration) => declaration.getText()) : [];
|
|
3767
3801
|
const json = JSON.stringify([recipes, exports], (_key, value) => value === void 0 ? "bamboo:undefined" : value);
|
|
3768
3802
|
if (json === void 0) return void 0;
|
|
3769
3803
|
return createHash("sha256").update(json).digest("base64");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bamboocss/node",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.50.1",
|
|
4
4
|
"description": "The core css bamboo library",
|
|
5
5
|
"homepage": "https://bamboocss.com",
|
|
6
6
|
"license": "MIT",
|
|
@@ -60,19 +60,19 @@
|
|
|
60
60
|
"picomatch": "4.0.5",
|
|
61
61
|
"pkg-types": "2.3.0",
|
|
62
62
|
"pluralize": "8.0.0",
|
|
63
|
-
"ts-morph": "28.0.0",
|
|
64
63
|
"ts-pattern": "5.9.0",
|
|
65
|
-
"@bamboocss/
|
|
66
|
-
"@bamboocss/
|
|
67
|
-
"@bamboocss/generator": "1.
|
|
68
|
-
"@bamboocss/logger": "1.
|
|
69
|
-
"@bamboocss/parser": "1.
|
|
70
|
-
"@bamboocss/plugin-
|
|
71
|
-
"@bamboocss/
|
|
72
|
-
"@bamboocss/
|
|
73
|
-
"@bamboocss/shared": "1.
|
|
74
|
-
"@bamboocss/token-dictionary": "1.
|
|
75
|
-
"@bamboocss/
|
|
64
|
+
"@bamboocss/config": "1.50.1",
|
|
65
|
+
"@bamboocss/core": "1.50.1",
|
|
66
|
+
"@bamboocss/generator": "1.50.1",
|
|
67
|
+
"@bamboocss/logger": "1.50.1",
|
|
68
|
+
"@bamboocss/parser": "1.50.1",
|
|
69
|
+
"@bamboocss/plugin-svelte": "1.50.1",
|
|
70
|
+
"@bamboocss/plugin-vue": "1.50.1",
|
|
71
|
+
"@bamboocss/reporter": "1.50.1",
|
|
72
|
+
"@bamboocss/shared": "1.50.1",
|
|
73
|
+
"@bamboocss/token-dictionary": "1.50.1",
|
|
74
|
+
"@bamboocss/ts-ast": "1.50.1",
|
|
75
|
+
"@bamboocss/types": "1.50.1"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@types/fs-extra": "11.0.4",
|