@bamboocss/parser 1.28.1 → 1.30.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 +36 -11
- package/dist/index.d.cts +25 -15
- package/dist/index.d.mts +25 -15
- package/dist/index.mjs +36 -11
- package/package.json +10 -10
package/dist/index.cjs
CHANGED
|
@@ -65,7 +65,7 @@ function classifyProject(ctx, resultMap) {
|
|
|
65
65
|
const { item, kind, filepath, localMaps } = opts;
|
|
66
66
|
if (!item.box || _bamboocss_extractor.box.isUnresolvable(item.box)) return;
|
|
67
67
|
if (!item.data) return;
|
|
68
|
-
if (item.type === "cva-call" || item.type === "
|
|
68
|
+
if (item.type === "cva-call" || item.type === "tokenValue") return;
|
|
69
69
|
const componentReportItem = {
|
|
70
70
|
componentIndex: String(componentIndex++),
|
|
71
71
|
componentName: item.name,
|
|
@@ -963,10 +963,10 @@ var ParserResult = class {
|
|
|
963
963
|
if (unresolved.length) this.unresolved.push(...unresolved);
|
|
964
964
|
}
|
|
965
965
|
/**
|
|
966
|
-
* `kind` separates `token()` from `token.
|
|
967
|
-
*
|
|
968
|
-
* a result for the token *path* — `collectTokenReferences`, keeping a declaration
|
|
969
|
-
* through pruning — wants both, and only the fold cares which half was asked for.
|
|
966
|
+
* `kind` separates the variable reference — `token()` — from `token.value()`, the resolved
|
|
967
|
+
* literal. They share this set deliberately: everything that
|
|
968
|
+
* reads a result for the token *path* — `collectTokenReferences`, keeping a declaration
|
|
969
|
+
* alive through pruning — wants both, and only the fold cares which half was asked for.
|
|
970
970
|
*/
|
|
971
971
|
setToken(result, kind = "token") {
|
|
972
972
|
this.token.add(this.append(Object.assign({ type: kind }, result)));
|
|
@@ -1108,7 +1108,7 @@ function createParser(context) {
|
|
|
1108
1108
|
ast: sourceFile,
|
|
1109
1109
|
tokens: context.tokens ? {
|
|
1110
1110
|
view: context.tokens.view,
|
|
1111
|
-
isTokenFn: (fnName) => file.
|
|
1111
|
+
isTokenFn: (fnName) => file.isTokenFn(fnName)
|
|
1112
1112
|
} : void 0,
|
|
1113
1113
|
components: jsx.isEnabled ? {
|
|
1114
1114
|
matchTag: (prop) => {
|
|
@@ -1171,13 +1171,13 @@ function createParser(context) {
|
|
|
1171
1171
|
});
|
|
1172
1172
|
return;
|
|
1173
1173
|
}
|
|
1174
|
-
if (file.
|
|
1174
|
+
if (file.isTokenValueFn(alias)) {
|
|
1175
1175
|
result.queryList.forEach((query) => {
|
|
1176
1176
|
if (query.kind === "call-expression") parserResult.setToken({
|
|
1177
|
-
name: "token.
|
|
1177
|
+
name: "token.value",
|
|
1178
1178
|
box: query.box.value[0] ?? _bamboocss_extractor.box.fallback(query.box),
|
|
1179
1179
|
data: combineResult((0, _bamboocss_extractor.unbox)(query.box.value[0]))
|
|
1180
|
-
}, "
|
|
1180
|
+
}, "tokenValue");
|
|
1181
1181
|
});
|
|
1182
1182
|
return;
|
|
1183
1183
|
}
|
|
@@ -1276,6 +1276,31 @@ const createTsProject = (options) => new ts_morph.Project({
|
|
|
1276
1276
|
...normalizeCompilerOptions(options.compilerOptions)
|
|
1277
1277
|
}
|
|
1278
1278
|
});
|
|
1279
|
+
/**
|
|
1280
|
+
* How to parse a file, decided by its extension.
|
|
1281
|
+
*
|
|
1282
|
+
* Everything used to be `TSX`, which is not a superset of `TS`: the two disagree on exactly
|
|
1283
|
+
* the constructs where `<` is ambiguous. Under `TSX` a generic arrow `<T>(x: T) => x` and an
|
|
1284
|
+
* old-style assertion `<HTMLElement>node` parse as a *JSX element*, which then swallows the
|
|
1285
|
+
* rest of the file into its children. The file still reads fine and the bytes are unchanged;
|
|
1286
|
+
* the tree is simply wrong, and every `css()` call below the offending line stops existing as
|
|
1287
|
+
* far as extraction is concerned. It reports as styles that silently never got emitted.
|
|
1288
|
+
*
|
|
1289
|
+
* Only `.ts` moves. A `.ts` file cannot legally contain JSX — TypeScript requires `.tsx` for
|
|
1290
|
+
* that — so parsing one as `TSX` can only ever mis-parse, never accept something real.
|
|
1291
|
+
*
|
|
1292
|
+
* Everything else stays `TSX` deliberately:
|
|
1293
|
+
*
|
|
1294
|
+
* - `.js` and `.jsx` routinely carry JSX in projects that never adopted TypeScript, and `TSX`
|
|
1295
|
+
* accepts the type syntax they do not use anyway.
|
|
1296
|
+
* - a single-file component is stored under its own extension after `parser:before` rewrites
|
|
1297
|
+
* it to tsx, so `.vue` and `.svelte` have to keep parsing as tsx.
|
|
1298
|
+
* - an unknown extension is somebody's template that a hook may have compiled to jsx.
|
|
1299
|
+
*/
|
|
1300
|
+
const scriptKindFor = (filePath) => {
|
|
1301
|
+
const extension = filePath.slice(filePath.lastIndexOf(".")).toLowerCase();
|
|
1302
|
+
return extension === ".ts" || extension === ".mts" || extension === ".cts" ? ts_morph.ScriptKind.TS : ts_morph.ScriptKind.TSX;
|
|
1303
|
+
};
|
|
1279
1304
|
var Project = class {
|
|
1280
1305
|
options;
|
|
1281
1306
|
project;
|
|
@@ -1421,7 +1446,7 @@ var Project = class {
|
|
|
1421
1446
|
this.invalidate();
|
|
1422
1447
|
return this.project.createSourceFile(filePath, readFile(filePath), {
|
|
1423
1448
|
overwrite: true,
|
|
1424
|
-
scriptKind:
|
|
1449
|
+
scriptKind: scriptKindFor(filePath)
|
|
1425
1450
|
});
|
|
1426
1451
|
};
|
|
1427
1452
|
createSourceFiles = () => {
|
|
@@ -1432,7 +1457,7 @@ var Project = class {
|
|
|
1432
1457
|
this.invalidate(!(filePath.includes("/") && this.project.getSourceFile(filePath)));
|
|
1433
1458
|
return this.project.createSourceFile(filePath, content, {
|
|
1434
1459
|
overwrite: true,
|
|
1435
|
-
scriptKind:
|
|
1460
|
+
scriptKind: scriptKindFor(filePath)
|
|
1436
1461
|
});
|
|
1437
1462
|
};
|
|
1438
1463
|
removeSourceFile = (filePath) => {
|
package/dist/index.d.cts
CHANGED
|
@@ -95,18 +95,28 @@ declare class Generator extends Context {
|
|
|
95
95
|
*/
|
|
96
96
|
private getThemeTokenVars;
|
|
97
97
|
/**
|
|
98
|
-
*
|
|
99
|
-
* `token('colors.text')` hands those to the caller as a reference, so the declaration
|
|
100
|
-
* has to survive whether or not the generated css mentions it. Ordinary tokens resolve
|
|
101
|
-
* to a literal in javascript and need no such exemption.
|
|
98
|
+
* The token declarations held open so a runtime `token()` can answer for any path.
|
|
102
99
|
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
100
|
+
* `token()` hands javascript the *variable reference* for every token, so a path the build
|
|
101
|
+
* cannot resolve could name any of them and every declaration has to survive. That is a
|
|
102
|
+
* blunt instrument, and deliberately so: the alternative failure is a `var()` with no
|
|
103
|
+
* declaration behind it, which resolves to the guaranteed-invalid value and inherits
|
|
104
|
+
* rather than falling back — silently wrong, which is worse than visibly large.
|
|
105
105
|
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
106
|
+
* It used to be narrower, because `token()` used to return a *literal* for a plain token
|
|
107
|
+
* and only a `var()` for virtual, conditional and negative ones. That split is gone, and
|
|
108
|
+
* narrowing this to match it would now strand exactly the base tokens the old split made
|
|
109
|
+
* safe.
|
|
110
|
+
*
|
|
111
|
+
* So the gate below carries the whole saving. `styled-system/tokens` is generated into the
|
|
112
|
+
* project, so nothing outside it can import them -- if no file under `include` reaches for
|
|
113
|
+
* a token from javascript, no caller exists to serve and the declarations are as prunable
|
|
114
|
+
* as any other.
|
|
115
|
+
*
|
|
116
|
+
* That gate is all-or-nothing per project, which is the coarse part worth fixing next: a
|
|
117
|
+
* project whose token calls all resolve to string literals needs none of this, because
|
|
118
|
+
* `collectTokenReferences` already kept those paths by name. Deciding that needs the
|
|
119
|
+
* reference accounting the gate does not do yet -- see `tokensReachableFromJs`.
|
|
110
120
|
*/
|
|
111
121
|
private getAlwaysKeptTokenVars;
|
|
112
122
|
getParserCss: (decoder: StyleDecoder) => string;
|
|
@@ -230,12 +240,12 @@ declare class ParserResult implements ParserResultInterface {
|
|
|
230
240
|
*/
|
|
231
241
|
private reportUnresolvedRecipe;
|
|
232
242
|
/**
|
|
233
|
-
* `kind` separates `token()` from `token.
|
|
234
|
-
*
|
|
235
|
-
* a result for the token *path* — `collectTokenReferences`, keeping a declaration
|
|
236
|
-
* through pruning — wants both, and only the fold cares which half was asked for.
|
|
243
|
+
* `kind` separates the variable reference — `token()` — from `token.value()`, the resolved
|
|
244
|
+
* literal. They share this set deliberately: everything that
|
|
245
|
+
* reads a result for the token *path* — `collectTokenReferences`, keeping a declaration
|
|
246
|
+
* alive through pruning — wants both, and only the fold cares which half was asked for.
|
|
237
247
|
*/
|
|
238
|
-
setToken(result: ResultItem, kind?: 'token' | '
|
|
248
|
+
setToken(result: ResultItem, kind?: 'token' | 'tokenValue'): void;
|
|
239
249
|
setViewTransition(result: ResultItem): void;
|
|
240
250
|
setPattern(name: string, result: ResultItem): void;
|
|
241
251
|
setRecipe(recipeName: string, result: ResultItem): void;
|
package/dist/index.d.mts
CHANGED
|
@@ -95,18 +95,28 @@ declare class Generator extends Context {
|
|
|
95
95
|
*/
|
|
96
96
|
private getThemeTokenVars;
|
|
97
97
|
/**
|
|
98
|
-
*
|
|
99
|
-
* `token('colors.text')` hands those to the caller as a reference, so the declaration
|
|
100
|
-
* has to survive whether or not the generated css mentions it. Ordinary tokens resolve
|
|
101
|
-
* to a literal in javascript and need no such exemption.
|
|
98
|
+
* The token declarations held open so a runtime `token()` can answer for any path.
|
|
102
99
|
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
100
|
+
* `token()` hands javascript the *variable reference* for every token, so a path the build
|
|
101
|
+
* cannot resolve could name any of them and every declaration has to survive. That is a
|
|
102
|
+
* blunt instrument, and deliberately so: the alternative failure is a `var()` with no
|
|
103
|
+
* declaration behind it, which resolves to the guaranteed-invalid value and inherits
|
|
104
|
+
* rather than falling back — silently wrong, which is worse than visibly large.
|
|
105
105
|
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
106
|
+
* It used to be narrower, because `token()` used to return a *literal* for a plain token
|
|
107
|
+
* and only a `var()` for virtual, conditional and negative ones. That split is gone, and
|
|
108
|
+
* narrowing this to match it would now strand exactly the base tokens the old split made
|
|
109
|
+
* safe.
|
|
110
|
+
*
|
|
111
|
+
* So the gate below carries the whole saving. `styled-system/tokens` is generated into the
|
|
112
|
+
* project, so nothing outside it can import them -- if no file under `include` reaches for
|
|
113
|
+
* a token from javascript, no caller exists to serve and the declarations are as prunable
|
|
114
|
+
* as any other.
|
|
115
|
+
*
|
|
116
|
+
* That gate is all-or-nothing per project, which is the coarse part worth fixing next: a
|
|
117
|
+
* project whose token calls all resolve to string literals needs none of this, because
|
|
118
|
+
* `collectTokenReferences` already kept those paths by name. Deciding that needs the
|
|
119
|
+
* reference accounting the gate does not do yet -- see `tokensReachableFromJs`.
|
|
110
120
|
*/
|
|
111
121
|
private getAlwaysKeptTokenVars;
|
|
112
122
|
getParserCss: (decoder: StyleDecoder) => string;
|
|
@@ -230,12 +240,12 @@ declare class ParserResult implements ParserResultInterface {
|
|
|
230
240
|
*/
|
|
231
241
|
private reportUnresolvedRecipe;
|
|
232
242
|
/**
|
|
233
|
-
* `kind` separates `token()` from `token.
|
|
234
|
-
*
|
|
235
|
-
* a result for the token *path* — `collectTokenReferences`, keeping a declaration
|
|
236
|
-
* through pruning — wants both, and only the fold cares which half was asked for.
|
|
243
|
+
* `kind` separates the variable reference — `token()` — from `token.value()`, the resolved
|
|
244
|
+
* literal. They share this set deliberately: everything that
|
|
245
|
+
* reads a result for the token *path* — `collectTokenReferences`, keeping a declaration
|
|
246
|
+
* alive through pruning — wants both, and only the fold cares which half was asked for.
|
|
237
247
|
*/
|
|
238
|
-
setToken(result: ResultItem, kind?: 'token' | '
|
|
248
|
+
setToken(result: ResultItem, kind?: 'token' | 'tokenValue'): void;
|
|
239
249
|
setViewTransition(result: ResultItem): void;
|
|
240
250
|
setPattern(name: string, result: ResultItem): void;
|
|
241
251
|
setRecipe(recipeName: string, result: ResultItem): void;
|
package/dist/index.mjs
CHANGED
|
@@ -64,7 +64,7 @@ function classifyProject(ctx, resultMap) {
|
|
|
64
64
|
const { item, kind, filepath, localMaps } = opts;
|
|
65
65
|
if (!item.box || box.isUnresolvable(item.box)) return;
|
|
66
66
|
if (!item.data) return;
|
|
67
|
-
if (item.type === "cva-call" || item.type === "
|
|
67
|
+
if (item.type === "cva-call" || item.type === "tokenValue") return;
|
|
68
68
|
const componentReportItem = {
|
|
69
69
|
componentIndex: String(componentIndex++),
|
|
70
70
|
componentName: item.name,
|
|
@@ -962,10 +962,10 @@ var ParserResult = class {
|
|
|
962
962
|
if (unresolved.length) this.unresolved.push(...unresolved);
|
|
963
963
|
}
|
|
964
964
|
/**
|
|
965
|
-
* `kind` separates `token()` from `token.
|
|
966
|
-
*
|
|
967
|
-
* a result for the token *path* — `collectTokenReferences`, keeping a declaration
|
|
968
|
-
* through pruning — wants both, and only the fold cares which half was asked for.
|
|
965
|
+
* `kind` separates the variable reference — `token()` — from `token.value()`, the resolved
|
|
966
|
+
* literal. They share this set deliberately: everything that
|
|
967
|
+
* reads a result for the token *path* — `collectTokenReferences`, keeping a declaration
|
|
968
|
+
* alive through pruning — wants both, and only the fold cares which half was asked for.
|
|
969
969
|
*/
|
|
970
970
|
setToken(result, kind = "token") {
|
|
971
971
|
this.token.add(this.append(Object.assign({ type: kind }, result)));
|
|
@@ -1107,7 +1107,7 @@ function createParser(context) {
|
|
|
1107
1107
|
ast: sourceFile,
|
|
1108
1108
|
tokens: context.tokens ? {
|
|
1109
1109
|
view: context.tokens.view,
|
|
1110
|
-
isTokenFn: (fnName) => file.
|
|
1110
|
+
isTokenFn: (fnName) => file.isTokenFn(fnName)
|
|
1111
1111
|
} : void 0,
|
|
1112
1112
|
components: jsx.isEnabled ? {
|
|
1113
1113
|
matchTag: (prop) => {
|
|
@@ -1170,13 +1170,13 @@ function createParser(context) {
|
|
|
1170
1170
|
});
|
|
1171
1171
|
return;
|
|
1172
1172
|
}
|
|
1173
|
-
if (file.
|
|
1173
|
+
if (file.isTokenValueFn(alias)) {
|
|
1174
1174
|
result.queryList.forEach((query) => {
|
|
1175
1175
|
if (query.kind === "call-expression") parserResult.setToken({
|
|
1176
|
-
name: "token.
|
|
1176
|
+
name: "token.value",
|
|
1177
1177
|
box: query.box.value[0] ?? box.fallback(query.box),
|
|
1178
1178
|
data: combineResult(unbox(query.box.value[0]))
|
|
1179
|
-
}, "
|
|
1179
|
+
}, "tokenValue");
|
|
1180
1180
|
});
|
|
1181
1181
|
return;
|
|
1182
1182
|
}
|
|
@@ -1275,6 +1275,31 @@ const createTsProject = (options) => new Project$1({
|
|
|
1275
1275
|
...normalizeCompilerOptions(options.compilerOptions)
|
|
1276
1276
|
}
|
|
1277
1277
|
});
|
|
1278
|
+
/**
|
|
1279
|
+
* How to parse a file, decided by its extension.
|
|
1280
|
+
*
|
|
1281
|
+
* Everything used to be `TSX`, which is not a superset of `TS`: the two disagree on exactly
|
|
1282
|
+
* the constructs where `<` is ambiguous. Under `TSX` a generic arrow `<T>(x: T) => x` and an
|
|
1283
|
+
* old-style assertion `<HTMLElement>node` parse as a *JSX element*, which then swallows the
|
|
1284
|
+
* rest of the file into its children. The file still reads fine and the bytes are unchanged;
|
|
1285
|
+
* the tree is simply wrong, and every `css()` call below the offending line stops existing as
|
|
1286
|
+
* far as extraction is concerned. It reports as styles that silently never got emitted.
|
|
1287
|
+
*
|
|
1288
|
+
* Only `.ts` moves. A `.ts` file cannot legally contain JSX — TypeScript requires `.tsx` for
|
|
1289
|
+
* that — so parsing one as `TSX` can only ever mis-parse, never accept something real.
|
|
1290
|
+
*
|
|
1291
|
+
* Everything else stays `TSX` deliberately:
|
|
1292
|
+
*
|
|
1293
|
+
* - `.js` and `.jsx` routinely carry JSX in projects that never adopted TypeScript, and `TSX`
|
|
1294
|
+
* accepts the type syntax they do not use anyway.
|
|
1295
|
+
* - a single-file component is stored under its own extension after `parser:before` rewrites
|
|
1296
|
+
* it to tsx, so `.vue` and `.svelte` have to keep parsing as tsx.
|
|
1297
|
+
* - an unknown extension is somebody's template that a hook may have compiled to jsx.
|
|
1298
|
+
*/
|
|
1299
|
+
const scriptKindFor = (filePath) => {
|
|
1300
|
+
const extension = filePath.slice(filePath.lastIndexOf(".")).toLowerCase();
|
|
1301
|
+
return extension === ".ts" || extension === ".mts" || extension === ".cts" ? ScriptKind.TS : ScriptKind.TSX;
|
|
1302
|
+
};
|
|
1278
1303
|
var Project = class {
|
|
1279
1304
|
options;
|
|
1280
1305
|
project;
|
|
@@ -1420,7 +1445,7 @@ var Project = class {
|
|
|
1420
1445
|
this.invalidate();
|
|
1421
1446
|
return this.project.createSourceFile(filePath, readFile(filePath), {
|
|
1422
1447
|
overwrite: true,
|
|
1423
|
-
scriptKind:
|
|
1448
|
+
scriptKind: scriptKindFor(filePath)
|
|
1424
1449
|
});
|
|
1425
1450
|
};
|
|
1426
1451
|
createSourceFiles = () => {
|
|
@@ -1431,7 +1456,7 @@ var Project = class {
|
|
|
1431
1456
|
this.invalidate(!(filePath.includes("/") && this.project.getSourceFile(filePath)));
|
|
1432
1457
|
return this.project.createSourceFile(filePath, content, {
|
|
1433
1458
|
overwrite: true,
|
|
1434
|
-
scriptKind:
|
|
1459
|
+
scriptKind: scriptKindFor(filePath)
|
|
1435
1460
|
});
|
|
1436
1461
|
};
|
|
1437
1462
|
removeSourceFile = (filePath) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bamboocss/parser",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.30.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/
|
|
38
|
-
"@bamboocss/core": "^1.
|
|
39
|
-
"@bamboocss/
|
|
40
|
-
"@bamboocss/logger": "1.
|
|
41
|
-
"@bamboocss/shared": "1.
|
|
42
|
-
"@bamboocss/types": "1.
|
|
37
|
+
"@bamboocss/config": "^1.30.0",
|
|
38
|
+
"@bamboocss/core": "^1.30.0",
|
|
39
|
+
"@bamboocss/extractor": "1.30.0",
|
|
40
|
+
"@bamboocss/logger": "1.30.0",
|
|
41
|
+
"@bamboocss/shared": "1.30.0",
|
|
42
|
+
"@bamboocss/types": "1.30.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@bamboocss/generator": "1.
|
|
46
|
-
"@bamboocss/plugin-svelte": "1.
|
|
47
|
-
"@bamboocss/plugin-vue": "1.
|
|
45
|
+
"@bamboocss/generator": "1.30.0",
|
|
46
|
+
"@bamboocss/plugin-svelte": "1.30.0",
|
|
47
|
+
"@bamboocss/plugin-vue": "1.30.0"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "tsdown src/index.ts --format=esm,cjs --dts",
|