@bamboocss/parser 1.30.1 → 1.32.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.
- package/dist/index.cjs +24 -6
- package/dist/index.d.cts +9 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.mjs +25 -7
- package/package.json +10 -10
package/dist/index.cjs
CHANGED
|
@@ -18,6 +18,7 @@ function classifyProject(ctx, resultMap) {
|
|
|
18
18
|
const byComponentInFilepath = /* @__PURE__ */ new Map();
|
|
19
19
|
const globalMaps = createReportMaps();
|
|
20
20
|
const byFilePathMaps = /* @__PURE__ */ new Map();
|
|
21
|
+
const patternHelpers = (0, _bamboocss_shared.createPatternFns)((path, fallback) => ctx.tokens.view.getVar(path) ?? fallback);
|
|
21
22
|
const conditions = new Map(Object.entries(ctx.conditions.values));
|
|
22
23
|
const { groupByProp } = getPropertyGroupMap(ctx);
|
|
23
24
|
let id = 0;
|
|
@@ -46,7 +47,7 @@ function classifyProject(ctx, resultMap) {
|
|
|
46
47
|
const name = item.componentName;
|
|
47
48
|
const pattern = ctx.patterns.details.find((p) => p.baseName === name);
|
|
48
49
|
if (!pattern) return;
|
|
49
|
-
const cssObj = pattern.config.transform?.(data || {},
|
|
50
|
+
const cssObj = pattern.config.transform?.(data || {}, patternHelpers) ?? {};
|
|
50
51
|
const newItem = {
|
|
51
52
|
name: "css",
|
|
52
53
|
type: "css",
|
|
@@ -263,12 +264,12 @@ function classifyProject(ctx, resultMap) {
|
|
|
263
264
|
recipe.compoundVariants?.forEach((v) => functionFn(v.css));
|
|
264
265
|
}
|
|
265
266
|
});
|
|
266
|
-
Object.values(ctx.config.
|
|
267
|
+
Object.values(ctx.config.global?.css ?? {}).forEach((styleObject) => {
|
|
267
268
|
if (!styleObject) return;
|
|
268
269
|
processMap({
|
|
269
270
|
map: _bamboocss_extractor.box.objectToMap(styleObject, null, []),
|
|
270
271
|
current: [],
|
|
271
|
-
filepath: "@config/
|
|
272
|
+
filepath: "@config/global.css",
|
|
272
273
|
skipRange: true,
|
|
273
274
|
localMaps: createReportMaps(),
|
|
274
275
|
componentReportItem: {
|
|
@@ -911,7 +912,8 @@ var ParserResult = class {
|
|
|
911
912
|
setCss(result) {
|
|
912
913
|
this.css.add(this.append(Object.assign({ type: "css" }, result)));
|
|
913
914
|
const encoder = this.encoder;
|
|
914
|
-
|
|
915
|
+
if (result.data.some(Array.isArray)) throw new _bamboocss_shared.BambooError("INVALID_STYLE_ARGUMENT", "An array is not a style argument.", { hint: "Spread it instead, e.g. css(...styles) rather than css(styles)." });
|
|
916
|
+
const data = result.data;
|
|
915
917
|
const unresolved = findUnresolvedStyles(result, "atomic").filter((entry) => entry.reason === "unenumerable-keys");
|
|
916
918
|
if (unresolved.length) this.unresolved.push(...unresolved);
|
|
917
919
|
data.forEach((obj) => encoder.processAtomic(obj));
|
|
@@ -983,19 +985,35 @@ var ParserResult = class {
|
|
|
983
985
|
}, result)));
|
|
984
986
|
result.data.forEach((obj) => this.encoder.processPattern(name, obj));
|
|
985
987
|
}
|
|
988
|
+
/**
|
|
989
|
+
* The variant axes a call site passed and the build could not read.
|
|
990
|
+
*
|
|
991
|
+
* `button({ size })` with a dynamic `size` and `button()` both unbox to `{}`, so the encoder
|
|
992
|
+
* cannot tell "you named an axis I could not resolve" from "you named nothing" — and the
|
|
993
|
+
* difference decides whether a class it is about to emit has a rule behind it. The box still
|
|
994
|
+
* holds the distinction: the key is present, carrying an `unresolvable`.
|
|
995
|
+
*/
|
|
996
|
+
unresolvedVariants(result) {
|
|
997
|
+
const boxNode = result.box;
|
|
998
|
+
if (!boxNode || !_bamboocss_extractor.box.isMap(boxNode)) return void 0;
|
|
999
|
+
const keys = /* @__PURE__ */ new Set();
|
|
1000
|
+
for (const [key, value] of boxNode.value.entries()) if (_bamboocss_extractor.box.isUnresolvable(value)) keys.add(key);
|
|
1001
|
+
return keys.size ? keys : void 0;
|
|
1002
|
+
}
|
|
986
1003
|
setRecipe(recipeName, result) {
|
|
987
1004
|
(0, _bamboocss_shared.getOrCreateSet)(this.recipe, recipeName).add(this.append(Object.assign({ type: "recipe" }, result)));
|
|
988
1005
|
const encoder = this.encoder;
|
|
989
1006
|
const recipes = this.context.recipes;
|
|
990
1007
|
if (!recipes.getConfig(recipeName)) return;
|
|
991
1008
|
const recipe = result;
|
|
1009
|
+
const unresolved = this.unresolvedVariants(result);
|
|
992
1010
|
if (result.type) recipe.data.forEach((data) => {
|
|
993
1011
|
const [recipeProps, styleProps] = recipes.splitProps(recipeName, data);
|
|
994
1012
|
encoder.processStyleProps(styleProps);
|
|
995
|
-
encoder.processRecipe(recipeName, recipeProps);
|
|
1013
|
+
encoder.processRecipe(recipeName, recipeProps, unresolved);
|
|
996
1014
|
});
|
|
997
1015
|
else recipe.data.forEach((data) => {
|
|
998
|
-
encoder.processRecipe(recipeName, data);
|
|
1016
|
+
encoder.processRecipe(recipeName, data, unresolved);
|
|
999
1017
|
});
|
|
1000
1018
|
}
|
|
1001
1019
|
isEmpty() {
|
package/dist/index.d.cts
CHANGED
|
@@ -248,6 +248,15 @@ declare class ParserResult implements ParserResultInterface {
|
|
|
248
248
|
setToken(result: ResultItem, kind?: 'token' | 'tokenValue'): void;
|
|
249
249
|
setViewTransition(result: ResultItem): void;
|
|
250
250
|
setPattern(name: string, result: ResultItem): void;
|
|
251
|
+
/**
|
|
252
|
+
* The variant axes a call site passed and the build could not read.
|
|
253
|
+
*
|
|
254
|
+
* `button({ size })` with a dynamic `size` and `button()` both unbox to `{}`, so the encoder
|
|
255
|
+
* cannot tell "you named an axis I could not resolve" from "you named nothing" — and the
|
|
256
|
+
* difference decides whether a class it is about to emit has a rule behind it. The box still
|
|
257
|
+
* holds the distinction: the key is present, carrying an `unresolvable`.
|
|
258
|
+
*/
|
|
259
|
+
private unresolvedVariants;
|
|
251
260
|
setRecipe(recipeName: string, result: ResultItem): void;
|
|
252
261
|
isEmpty(): boolean;
|
|
253
262
|
setFilePath(filePath: string): this;
|
package/dist/index.d.mts
CHANGED
|
@@ -248,6 +248,15 @@ declare class ParserResult implements ParserResultInterface {
|
|
|
248
248
|
setToken(result: ResultItem, kind?: 'token' | 'tokenValue'): void;
|
|
249
249
|
setViewTransition(result: ResultItem): void;
|
|
250
250
|
setPattern(name: string, result: ResultItem): void;
|
|
251
|
+
/**
|
|
252
|
+
* The variant axes a call site passed and the build could not read.
|
|
253
|
+
*
|
|
254
|
+
* `button({ size })` with a dynamic `size` and `button()` both unbox to `{}`, so the encoder
|
|
255
|
+
* cannot tell "you named an axis I could not resolve" from "you named nothing" — and the
|
|
256
|
+
* difference decides whether a class it is about to emit has a rule behind it. The box still
|
|
257
|
+
* holds the distinction: the key is present, carrying an `unresolvable`.
|
|
258
|
+
*/
|
|
259
|
+
private unresolvedVariants;
|
|
251
260
|
setRecipe(recipeName: string, result: ResultItem): void;
|
|
252
261
|
isEmpty(): boolean;
|
|
253
262
|
setFilePath(filePath: string): this;
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Node, Project as Project$1, ScriptKind, ts } from "ts-morph";
|
|
2
2
|
import { box, clearBoxNodeCache, extract, unbox, unwrapExpression } from "@bamboocss/extractor";
|
|
3
|
-
import { BambooError, compact,
|
|
3
|
+
import { BambooError, compact, createPatternFns, getOrCreateSet } from "@bamboocss/shared";
|
|
4
4
|
import { logger } from "@bamboocss/logger";
|
|
5
5
|
import { match } from "ts-pattern";
|
|
6
6
|
import { resolveTsPathPattern } from "@bamboocss/config/ts-path";
|
|
@@ -17,6 +17,7 @@ function classifyProject(ctx, resultMap) {
|
|
|
17
17
|
const byComponentInFilepath = /* @__PURE__ */ new Map();
|
|
18
18
|
const globalMaps = createReportMaps();
|
|
19
19
|
const byFilePathMaps = /* @__PURE__ */ new Map();
|
|
20
|
+
const patternHelpers = createPatternFns((path, fallback) => ctx.tokens.view.getVar(path) ?? fallback);
|
|
20
21
|
const conditions = new Map(Object.entries(ctx.conditions.values));
|
|
21
22
|
const { groupByProp } = getPropertyGroupMap(ctx);
|
|
22
23
|
let id = 0;
|
|
@@ -45,7 +46,7 @@ function classifyProject(ctx, resultMap) {
|
|
|
45
46
|
const name = item.componentName;
|
|
46
47
|
const pattern = ctx.patterns.details.find((p) => p.baseName === name);
|
|
47
48
|
if (!pattern) return;
|
|
48
|
-
const cssObj = pattern.config.transform?.(data || {},
|
|
49
|
+
const cssObj = pattern.config.transform?.(data || {}, patternHelpers) ?? {};
|
|
49
50
|
const newItem = {
|
|
50
51
|
name: "css",
|
|
51
52
|
type: "css",
|
|
@@ -262,12 +263,12 @@ function classifyProject(ctx, resultMap) {
|
|
|
262
263
|
recipe.compoundVariants?.forEach((v) => functionFn(v.css));
|
|
263
264
|
}
|
|
264
265
|
});
|
|
265
|
-
Object.values(ctx.config.
|
|
266
|
+
Object.values(ctx.config.global?.css ?? {}).forEach((styleObject) => {
|
|
266
267
|
if (!styleObject) return;
|
|
267
268
|
processMap({
|
|
268
269
|
map: box.objectToMap(styleObject, null, []),
|
|
269
270
|
current: [],
|
|
270
|
-
filepath: "@config/
|
|
271
|
+
filepath: "@config/global.css",
|
|
271
272
|
skipRange: true,
|
|
272
273
|
localMaps: createReportMaps(),
|
|
273
274
|
componentReportItem: {
|
|
@@ -910,7 +911,8 @@ var ParserResult = class {
|
|
|
910
911
|
setCss(result) {
|
|
911
912
|
this.css.add(this.append(Object.assign({ type: "css" }, result)));
|
|
912
913
|
const encoder = this.encoder;
|
|
913
|
-
|
|
914
|
+
if (result.data.some(Array.isArray)) throw new BambooError("INVALID_STYLE_ARGUMENT", "An array is not a style argument.", { hint: "Spread it instead, e.g. css(...styles) rather than css(styles)." });
|
|
915
|
+
const data = result.data;
|
|
914
916
|
const unresolved = findUnresolvedStyles(result, "atomic").filter((entry) => entry.reason === "unenumerable-keys");
|
|
915
917
|
if (unresolved.length) this.unresolved.push(...unresolved);
|
|
916
918
|
data.forEach((obj) => encoder.processAtomic(obj));
|
|
@@ -982,19 +984,35 @@ var ParserResult = class {
|
|
|
982
984
|
}, result)));
|
|
983
985
|
result.data.forEach((obj) => this.encoder.processPattern(name, obj));
|
|
984
986
|
}
|
|
987
|
+
/**
|
|
988
|
+
* The variant axes a call site passed and the build could not read.
|
|
989
|
+
*
|
|
990
|
+
* `button({ size })` with a dynamic `size` and `button()` both unbox to `{}`, so the encoder
|
|
991
|
+
* cannot tell "you named an axis I could not resolve" from "you named nothing" — and the
|
|
992
|
+
* difference decides whether a class it is about to emit has a rule behind it. The box still
|
|
993
|
+
* holds the distinction: the key is present, carrying an `unresolvable`.
|
|
994
|
+
*/
|
|
995
|
+
unresolvedVariants(result) {
|
|
996
|
+
const boxNode = result.box;
|
|
997
|
+
if (!boxNode || !box.isMap(boxNode)) return void 0;
|
|
998
|
+
const keys = /* @__PURE__ */ new Set();
|
|
999
|
+
for (const [key, value] of boxNode.value.entries()) if (box.isUnresolvable(value)) keys.add(key);
|
|
1000
|
+
return keys.size ? keys : void 0;
|
|
1001
|
+
}
|
|
985
1002
|
setRecipe(recipeName, result) {
|
|
986
1003
|
getOrCreateSet(this.recipe, recipeName).add(this.append(Object.assign({ type: "recipe" }, result)));
|
|
987
1004
|
const encoder = this.encoder;
|
|
988
1005
|
const recipes = this.context.recipes;
|
|
989
1006
|
if (!recipes.getConfig(recipeName)) return;
|
|
990
1007
|
const recipe = result;
|
|
1008
|
+
const unresolved = this.unresolvedVariants(result);
|
|
991
1009
|
if (result.type) recipe.data.forEach((data) => {
|
|
992
1010
|
const [recipeProps, styleProps] = recipes.splitProps(recipeName, data);
|
|
993
1011
|
encoder.processStyleProps(styleProps);
|
|
994
|
-
encoder.processRecipe(recipeName, recipeProps);
|
|
1012
|
+
encoder.processRecipe(recipeName, recipeProps, unresolved);
|
|
995
1013
|
});
|
|
996
1014
|
else recipe.data.forEach((data) => {
|
|
997
|
-
encoder.processRecipe(recipeName, data);
|
|
1015
|
+
encoder.processRecipe(recipeName, data, unresolved);
|
|
998
1016
|
});
|
|
999
1017
|
}
|
|
1000
1018
|
isEmpty() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bamboocss/parser",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.32.0",
|
|
4
4
|
"description": "The static parser for bamboo css",
|
|
5
5
|
"homepage": "https://bamboocss.com",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,17 +34,17 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"ts-morph": "28.0.0",
|
|
36
36
|
"ts-pattern": "5.9.0",
|
|
37
|
-
"@bamboocss/config": "^1.
|
|
38
|
-
"@bamboocss/core": "^1.
|
|
39
|
-
"@bamboocss/extractor": "1.
|
|
40
|
-
"@bamboocss/logger": "1.
|
|
41
|
-
"@bamboocss/shared": "1.
|
|
42
|
-
"@bamboocss/types": "1.
|
|
37
|
+
"@bamboocss/config": "^1.32.0",
|
|
38
|
+
"@bamboocss/core": "^1.32.0",
|
|
39
|
+
"@bamboocss/extractor": "1.32.0",
|
|
40
|
+
"@bamboocss/logger": "1.32.0",
|
|
41
|
+
"@bamboocss/shared": "1.32.0",
|
|
42
|
+
"@bamboocss/types": "1.32.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@bamboocss/generator": "1.
|
|
46
|
-
"@bamboocss/plugin-svelte": "1.
|
|
47
|
-
"@bamboocss/plugin-vue": "1.
|
|
45
|
+
"@bamboocss/generator": "1.32.0",
|
|
46
|
+
"@bamboocss/plugin-svelte": "1.32.0",
|
|
47
|
+
"@bamboocss/plugin-vue": "1.32.0"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "tsdown src/index.ts --format=esm,cjs --dts",
|