@pandacss/parser 0.0.0-dev-20230413135202 → 0.0.0-dev-20230413141731
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.d.ts +13 -2
- package/dist/index.js +38 -20
- package/dist/index.mjs +38 -20
- package/package.json +8 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
import * as _pandacss_types from '@pandacss/types';
|
|
2
|
+
import { RecipeConfig } from '@pandacss/types';
|
|
2
3
|
import * as ts_morph from 'ts-morph';
|
|
3
4
|
import { ProjectOptions as ProjectOptions$1 } from 'ts-morph';
|
|
4
5
|
|
|
5
|
-
type
|
|
6
|
+
type ParserPatternNode = {
|
|
6
7
|
name: string;
|
|
7
|
-
type: 'pattern'
|
|
8
|
+
type: 'pattern';
|
|
8
9
|
props?: string[];
|
|
9
10
|
baseName: string;
|
|
10
11
|
};
|
|
12
|
+
type ParserRecipeNode = {
|
|
13
|
+
name: string;
|
|
14
|
+
type: 'recipe';
|
|
15
|
+
props: string[];
|
|
16
|
+
baseName: string;
|
|
17
|
+
jsx: RecipeConfig['jsx'];
|
|
18
|
+
};
|
|
19
|
+
type ParserNodeOptions = ParserPatternNode | ParserRecipeNode;
|
|
11
20
|
type ParserOptions = {
|
|
12
21
|
importMap: Record<'css' | 'recipe' | 'pattern' | 'jsx', string>;
|
|
13
22
|
jsx?: {
|
|
@@ -15,6 +24,8 @@ type ParserOptions = {
|
|
|
15
24
|
nodes: ParserNodeOptions[];
|
|
16
25
|
isStyleProp: (prop: string) => boolean;
|
|
17
26
|
};
|
|
27
|
+
getRecipeName: (tagName: string) => string;
|
|
28
|
+
getRecipeByName: (name: string) => RecipeConfig | undefined;
|
|
18
29
|
};
|
|
19
30
|
|
|
20
31
|
type ProjectOptions = Partial<ProjectOptions$1> & {
|
package/dist/index.js
CHANGED
|
@@ -104,6 +104,7 @@ var createParserResult = () => ({
|
|
|
104
104
|
});
|
|
105
105
|
|
|
106
106
|
// src/parser.ts
|
|
107
|
+
var isNodeRecipe = (node) => node.type === "recipe";
|
|
107
108
|
function createImportMatcher(mod, values) {
|
|
108
109
|
const regex = values ? new RegExp(`^(${values.join("|")})$`) : /.*/;
|
|
109
110
|
return {
|
|
@@ -122,7 +123,7 @@ function createParser(options) {
|
|
|
122
123
|
if (!sourceFile)
|
|
123
124
|
return;
|
|
124
125
|
const filePath = sourceFile.getFilePath();
|
|
125
|
-
const { jsx, importMap } = options;
|
|
126
|
+
const { jsx, importMap, getRecipeByName } = options;
|
|
126
127
|
const importRegex = [
|
|
127
128
|
createImportMatcher(importMap.css, ["css", "cva"]),
|
|
128
129
|
createImportMatcher(importMap.recipe),
|
|
@@ -148,7 +149,6 @@ function createParser(options) {
|
|
|
148
149
|
const isValidStyleFn = (name) => name === jsx?.factory;
|
|
149
150
|
const jsxFactoryAlias = jsx ? imports.getAlias(jsx.factory) : "panda";
|
|
150
151
|
const jsxPatternNodes = new RegExp(`(${jsx?.nodes.map((node) => node.type === "pattern" && node.name).join("|")})$`);
|
|
151
|
-
const jsxRecipeNodes = new RegExp(`(${jsx?.nodes.map((node) => node.type === "recipe" && node.name).join("|")})$`);
|
|
152
152
|
const recipes = /* @__PURE__ */ new Map();
|
|
153
153
|
imports.value.forEach((importDeclaration) => {
|
|
154
154
|
const { name, alias } = importDeclaration;
|
|
@@ -160,6 +160,21 @@ function createParser(options) {
|
|
|
160
160
|
const functions = /* @__PURE__ */ new Map();
|
|
161
161
|
const components = /* @__PURE__ */ new Map();
|
|
162
162
|
const propertiesMap = new Map(confProperties.map((prop) => [prop, true]));
|
|
163
|
+
const recipePropertiesByName = /* @__PURE__ */ new Map();
|
|
164
|
+
const recipeJsxLists = (jsx?.nodes ?? []).filter(isNodeRecipe).reduce(
|
|
165
|
+
(acc, recipe) => {
|
|
166
|
+
recipePropertiesByName.set(recipe.baseName, new Set(recipe.props ?? []));
|
|
167
|
+
recipe.jsx?.forEach((jsx2) => {
|
|
168
|
+
if (typeof jsx2 === "string") {
|
|
169
|
+
acc.string.add(jsx2);
|
|
170
|
+
} else {
|
|
171
|
+
acc.regex.push(jsx2);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
return acc;
|
|
175
|
+
},
|
|
176
|
+
{ string: /* @__PURE__ */ new Set(), regex: [] }
|
|
177
|
+
);
|
|
163
178
|
const cvaAlias = imports.getAlias("cva");
|
|
164
179
|
const cssAlias = imports.getAlias("css");
|
|
165
180
|
if (options.jsx) {
|
|
@@ -167,18 +182,29 @@ function createParser(options) {
|
|
|
167
182
|
const properties = node.props ? new Map(propertiesMap) : propertiesMap;
|
|
168
183
|
const alias = imports.getAlias(node.name);
|
|
169
184
|
node.props?.forEach((prop) => properties.set(prop, true));
|
|
170
|
-
functions.set(node.baseName, properties);
|
|
171
185
|
functions.set(alias, properties);
|
|
172
186
|
components.set(alias, properties);
|
|
173
187
|
});
|
|
174
188
|
}
|
|
189
|
+
const getRecipeName = (0, import_shared2.memo)(options.getRecipeName);
|
|
190
|
+
const isJsxTagRecipe = (0, import_shared2.memo)(
|
|
191
|
+
(tagName) => recipeJsxLists.string.has(tagName) || recipeJsxLists.regex.some((regex) => regex.test(tagName))
|
|
192
|
+
);
|
|
175
193
|
const matchTag = (0, import_shared2.memo)((tagName) => {
|
|
176
|
-
return components.has(tagName) || isUpperCase(tagName) || tagName.startsWith(jsxFactoryAlias);
|
|
194
|
+
return components.has(tagName) || isUpperCase(tagName) || tagName.startsWith(jsxFactoryAlias) || isJsxTagRecipe(tagName);
|
|
177
195
|
});
|
|
178
196
|
const matchTagProp = (0, import_shared2.memo)((tagName, propName) => {
|
|
179
197
|
if (propertiesMap.size === 0)
|
|
180
198
|
return true;
|
|
181
|
-
|
|
199
|
+
if (Boolean(components.get(tagName)?.get(propName)) || propertiesMap.has(propName))
|
|
200
|
+
return true;
|
|
201
|
+
if (isJsxTagRecipe(tagName)) {
|
|
202
|
+
const recipe = getRecipeByName(getRecipeName(tagName));
|
|
203
|
+
if (recipe) {
|
|
204
|
+
return recipePropertiesByName.get(recipe.name)?.has(propName) ?? false;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return false;
|
|
182
208
|
});
|
|
183
209
|
const matchFn = (0, import_shared2.memo)((fnName) => {
|
|
184
210
|
if (recipes.has(fnName))
|
|
@@ -251,33 +277,25 @@ function createParser(options) {
|
|
|
251
277
|
result.queryList.forEach((query) => {
|
|
252
278
|
collector.setCva({
|
|
253
279
|
name,
|
|
254
|
-
box: query.box,
|
|
255
|
-
data: combineResult((0, import_extractor.unbox)(query.box))
|
|
280
|
+
box: query.box.value[1],
|
|
281
|
+
data: combineResult((0, import_extractor.unbox)(query.box.value[1]))
|
|
256
282
|
});
|
|
257
283
|
});
|
|
258
284
|
}).otherwise(() => {
|
|
259
285
|
});
|
|
260
286
|
} else if (result.kind === "component") {
|
|
261
287
|
result.queryList.forEach((query) => {
|
|
262
|
-
let type;
|
|
263
288
|
const data = combineResult((0, import_extractor.unbox)(query.box));
|
|
264
289
|
import_logger.logger.debug(`ast:jsx:${name}`, { filePath, result: data });
|
|
265
290
|
if (jsx && name.startsWith(jsxFactoryAlias)) {
|
|
266
|
-
type
|
|
291
|
+
collector.jsx.add({ name, box: query.box, type: "jsx-factory", data });
|
|
267
292
|
} else if (jsxPatternNodes.test(name)) {
|
|
268
|
-
type
|
|
269
|
-
} else if (
|
|
270
|
-
type
|
|
293
|
+
collector.setPattern(name, { type: "jsx-pattern", name, box: query.box, data });
|
|
294
|
+
} else if (recipeJsxLists.string.has(name) || recipeJsxLists.regex.some((regex) => regex.test(name))) {
|
|
295
|
+
collector.setRecipe(getRecipeName(name), { type: "jsx-recipe", name, box: query.box, data });
|
|
271
296
|
} else {
|
|
272
|
-
type
|
|
297
|
+
collector.jsx.add({ name, box: query.box, type: "jsx", data });
|
|
273
298
|
}
|
|
274
|
-
collector.jsx.add({
|
|
275
|
-
// from "panda.*" -> "panda.button"
|
|
276
|
-
name,
|
|
277
|
-
box: query.box,
|
|
278
|
-
type,
|
|
279
|
-
data
|
|
280
|
-
});
|
|
281
299
|
});
|
|
282
300
|
}
|
|
283
301
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -78,6 +78,7 @@ var createParserResult = () => ({
|
|
|
78
78
|
});
|
|
79
79
|
|
|
80
80
|
// src/parser.ts
|
|
81
|
+
var isNodeRecipe = (node) => node.type === "recipe";
|
|
81
82
|
function createImportMatcher(mod, values) {
|
|
82
83
|
const regex = values ? new RegExp(`^(${values.join("|")})$`) : /.*/;
|
|
83
84
|
return {
|
|
@@ -96,7 +97,7 @@ function createParser(options) {
|
|
|
96
97
|
if (!sourceFile)
|
|
97
98
|
return;
|
|
98
99
|
const filePath = sourceFile.getFilePath();
|
|
99
|
-
const { jsx, importMap } = options;
|
|
100
|
+
const { jsx, importMap, getRecipeByName } = options;
|
|
100
101
|
const importRegex = [
|
|
101
102
|
createImportMatcher(importMap.css, ["css", "cva"]),
|
|
102
103
|
createImportMatcher(importMap.recipe),
|
|
@@ -122,7 +123,6 @@ function createParser(options) {
|
|
|
122
123
|
const isValidStyleFn = (name) => name === jsx?.factory;
|
|
123
124
|
const jsxFactoryAlias = jsx ? imports.getAlias(jsx.factory) : "panda";
|
|
124
125
|
const jsxPatternNodes = new RegExp(`(${jsx?.nodes.map((node) => node.type === "pattern" && node.name).join("|")})$`);
|
|
125
|
-
const jsxRecipeNodes = new RegExp(`(${jsx?.nodes.map((node) => node.type === "recipe" && node.name).join("|")})$`);
|
|
126
126
|
const recipes = /* @__PURE__ */ new Map();
|
|
127
127
|
imports.value.forEach((importDeclaration) => {
|
|
128
128
|
const { name, alias } = importDeclaration;
|
|
@@ -134,6 +134,21 @@ function createParser(options) {
|
|
|
134
134
|
const functions = /* @__PURE__ */ new Map();
|
|
135
135
|
const components = /* @__PURE__ */ new Map();
|
|
136
136
|
const propertiesMap = new Map(confProperties.map((prop) => [prop, true]));
|
|
137
|
+
const recipePropertiesByName = /* @__PURE__ */ new Map();
|
|
138
|
+
const recipeJsxLists = (jsx?.nodes ?? []).filter(isNodeRecipe).reduce(
|
|
139
|
+
(acc, recipe) => {
|
|
140
|
+
recipePropertiesByName.set(recipe.baseName, new Set(recipe.props ?? []));
|
|
141
|
+
recipe.jsx?.forEach((jsx2) => {
|
|
142
|
+
if (typeof jsx2 === "string") {
|
|
143
|
+
acc.string.add(jsx2);
|
|
144
|
+
} else {
|
|
145
|
+
acc.regex.push(jsx2);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
return acc;
|
|
149
|
+
},
|
|
150
|
+
{ string: /* @__PURE__ */ new Set(), regex: [] }
|
|
151
|
+
);
|
|
137
152
|
const cvaAlias = imports.getAlias("cva");
|
|
138
153
|
const cssAlias = imports.getAlias("css");
|
|
139
154
|
if (options.jsx) {
|
|
@@ -141,18 +156,29 @@ function createParser(options) {
|
|
|
141
156
|
const properties = node.props ? new Map(propertiesMap) : propertiesMap;
|
|
142
157
|
const alias = imports.getAlias(node.name);
|
|
143
158
|
node.props?.forEach((prop) => properties.set(prop, true));
|
|
144
|
-
functions.set(node.baseName, properties);
|
|
145
159
|
functions.set(alias, properties);
|
|
146
160
|
components.set(alias, properties);
|
|
147
161
|
});
|
|
148
162
|
}
|
|
163
|
+
const getRecipeName = memo2(options.getRecipeName);
|
|
164
|
+
const isJsxTagRecipe = memo2(
|
|
165
|
+
(tagName) => recipeJsxLists.string.has(tagName) || recipeJsxLists.regex.some((regex) => regex.test(tagName))
|
|
166
|
+
);
|
|
149
167
|
const matchTag = memo2((tagName) => {
|
|
150
|
-
return components.has(tagName) || isUpperCase(tagName) || tagName.startsWith(jsxFactoryAlias);
|
|
168
|
+
return components.has(tagName) || isUpperCase(tagName) || tagName.startsWith(jsxFactoryAlias) || isJsxTagRecipe(tagName);
|
|
151
169
|
});
|
|
152
170
|
const matchTagProp = memo2((tagName, propName) => {
|
|
153
171
|
if (propertiesMap.size === 0)
|
|
154
172
|
return true;
|
|
155
|
-
|
|
173
|
+
if (Boolean(components.get(tagName)?.get(propName)) || propertiesMap.has(propName))
|
|
174
|
+
return true;
|
|
175
|
+
if (isJsxTagRecipe(tagName)) {
|
|
176
|
+
const recipe = getRecipeByName(getRecipeName(tagName));
|
|
177
|
+
if (recipe) {
|
|
178
|
+
return recipePropertiesByName.get(recipe.name)?.has(propName) ?? false;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return false;
|
|
156
182
|
});
|
|
157
183
|
const matchFn = memo2((fnName) => {
|
|
158
184
|
if (recipes.has(fnName))
|
|
@@ -225,33 +251,25 @@ function createParser(options) {
|
|
|
225
251
|
result.queryList.forEach((query) => {
|
|
226
252
|
collector.setCva({
|
|
227
253
|
name,
|
|
228
|
-
box: query.box,
|
|
229
|
-
data: combineResult(unbox(query.box))
|
|
254
|
+
box: query.box.value[1],
|
|
255
|
+
data: combineResult(unbox(query.box.value[1]))
|
|
230
256
|
});
|
|
231
257
|
});
|
|
232
258
|
}).otherwise(() => {
|
|
233
259
|
});
|
|
234
260
|
} else if (result.kind === "component") {
|
|
235
261
|
result.queryList.forEach((query) => {
|
|
236
|
-
let type;
|
|
237
262
|
const data = combineResult(unbox(query.box));
|
|
238
263
|
logger.debug(`ast:jsx:${name}`, { filePath, result: data });
|
|
239
264
|
if (jsx && name.startsWith(jsxFactoryAlias)) {
|
|
240
|
-
type
|
|
265
|
+
collector.jsx.add({ name, box: query.box, type: "jsx-factory", data });
|
|
241
266
|
} else if (jsxPatternNodes.test(name)) {
|
|
242
|
-
type
|
|
243
|
-
} else if (
|
|
244
|
-
type
|
|
267
|
+
collector.setPattern(name, { type: "jsx-pattern", name, box: query.box, data });
|
|
268
|
+
} else if (recipeJsxLists.string.has(name) || recipeJsxLists.regex.some((regex) => regex.test(name))) {
|
|
269
|
+
collector.setRecipe(getRecipeName(name), { type: "jsx-recipe", name, box: query.box, data });
|
|
245
270
|
} else {
|
|
246
|
-
type
|
|
271
|
+
collector.jsx.add({ name, box: query.box, type: "jsx", data });
|
|
247
272
|
}
|
|
248
|
-
collector.jsx.add({
|
|
249
|
-
// from "panda.*" -> "panda.button"
|
|
250
|
-
name,
|
|
251
|
-
box: query.box,
|
|
252
|
-
type,
|
|
253
|
-
data
|
|
254
|
-
});
|
|
255
273
|
});
|
|
256
274
|
}
|
|
257
275
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pandacss/parser",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20230413141731",
|
|
4
4
|
"description": "The static parser for panda css",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -14,14 +14,15 @@
|
|
|
14
14
|
"lil-fp": "1.4.5",
|
|
15
15
|
"ts-morph": "18.0.0",
|
|
16
16
|
"ts-pattern": "4.2.2",
|
|
17
|
-
"@pandacss/extractor": "0.0.0-dev-
|
|
18
|
-
"@pandacss/is-valid-prop": "0.0.0-dev-
|
|
19
|
-
"@pandacss/logger": "0.0.0-dev-
|
|
20
|
-
"@pandacss/shared": "0.0.0-dev-
|
|
21
|
-
"@pandacss/types": "0.0.0-dev-
|
|
17
|
+
"@pandacss/extractor": "0.0.0-dev-20230413141731",
|
|
18
|
+
"@pandacss/is-valid-prop": "0.0.0-dev-20230413141731",
|
|
19
|
+
"@pandacss/logger": "0.0.0-dev-20230413141731",
|
|
20
|
+
"@pandacss/shared": "0.0.0-dev-20230413141731",
|
|
21
|
+
"@pandacss/types": "0.0.0-dev-20230413141731"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@pandacss/fixture": "0.0.0-dev-
|
|
24
|
+
"@pandacss/fixture": "0.0.0-dev-20230413141731",
|
|
25
|
+
"@pandacss/generator": "0.0.0-dev-20230413141731"
|
|
25
26
|
},
|
|
26
27
|
"files": [
|
|
27
28
|
"dist"
|