@pandacss/parser 0.4.0 → 0.5.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.
@@ -0,0 +1,78 @@
1
+ import * as ts_morph from 'ts-morph';
2
+ import { ProjectOptions as ProjectOptions$1 } from 'ts-morph';
3
+ import { ResultItem, RecipeConfig, PandaHookable } from '@pandacss/types';
4
+
5
+ declare class ParserResult {
6
+ jsx: Set<ResultItem>;
7
+ css: Set<ResultItem>;
8
+ cva: Set<ResultItem>;
9
+ recipe: Map<string, Set<ResultItem>>;
10
+ pattern: Map<string, Set<ResultItem>>;
11
+ filePath: string | undefined;
12
+ set(name: 'cva' | 'css', result: ResultItem): void;
13
+ setCva(result: ResultItem): void;
14
+ setJsx(result: ResultItem): void;
15
+ setPattern(name: string, result: ResultItem): void;
16
+ setRecipe(name: string, result: ResultItem): void;
17
+ isEmpty(): boolean;
18
+ setFilePath(filePath: string): this;
19
+ toArray(): ResultItem[];
20
+ toJSON(): {
21
+ css: ResultItem[];
22
+ cva: ResultItem[];
23
+ recipe: {
24
+ [k: string]: ResultItem[];
25
+ };
26
+ pattern: {
27
+ [k: string]: ResultItem[];
28
+ };
29
+ jsx: ResultItem[];
30
+ };
31
+ merge(result: ParserResult): this;
32
+ static fromJSON(json: string): ParserResult;
33
+ }
34
+ declare const createParserResult: () => ParserResult;
35
+
36
+ type ParserPatternNode = {
37
+ name: string;
38
+ type: 'pattern';
39
+ props?: string[];
40
+ baseName: string;
41
+ };
42
+ type ParserRecipeNode = {
43
+ name: string;
44
+ type: 'recipe';
45
+ props: string[];
46
+ baseName: string;
47
+ jsx: RecipeConfig['jsx'];
48
+ };
49
+ type ParserNodeOptions = ParserPatternNode | ParserRecipeNode;
50
+ type ParserOptions = {
51
+ importMap: Record<'css' | 'recipe' | 'pattern' | 'jsx', string>;
52
+ jsx?: {
53
+ factory: string;
54
+ nodes: ParserNodeOptions[];
55
+ isStyleProp: (prop: string) => boolean;
56
+ };
57
+ getRecipeName: (tagName: string) => string;
58
+ getRecipeByName: (name: string) => RecipeConfig | undefined;
59
+ };
60
+
61
+ type ProjectOptions = Partial<ProjectOptions$1> & {
62
+ readFile: (filePath: string) => string;
63
+ getFiles: () => string[];
64
+ hooks: PandaHookable;
65
+ parserOptions: ParserOptions;
66
+ };
67
+ declare const createProject: ({ getFiles, readFile, parserOptions, hooks, ...projectOptions }: ProjectOptions) => {
68
+ getSourceFile: (filePath: string) => ts_morph.SourceFile | undefined;
69
+ removeSourceFile: (filePath: string) => void;
70
+ createSourceFile: (filePath: string) => ts_morph.SourceFile;
71
+ addSourceFile: (filePath: string, content: string) => ts_morph.SourceFile;
72
+ parseSourceFile: (filePath: string) => ParserResult | undefined;
73
+ reloadSourceFile: (filePath: string) => ts_morph.FileSystemRefreshResult | undefined;
74
+ reloadSourceFiles: () => void;
75
+ };
76
+ type Project = ReturnType<typeof createProject>;
77
+
78
+ export { ParserResult, Project, ProjectOptions, createParserResult, createProject };
package/dist/index.js CHANGED
@@ -97,7 +97,7 @@ function getImportDeclarations(file, options) {
97
97
  }
98
98
 
99
99
  // src/parser-result.ts
100
- var ParserResult = class {
100
+ var ParserResult = class _ParserResult {
101
101
  jsx = /* @__PURE__ */ new Set();
102
102
  css = /* @__PURE__ */ new Set();
103
103
  cva = /* @__PURE__ */ new Set();
@@ -162,7 +162,7 @@ var ParserResult = class {
162
162
  }
163
163
  static fromJSON(json) {
164
164
  const data = JSON.parse(json);
165
- const result = new ParserResult();
165
+ const result = new _ParserResult();
166
166
  result.css = new Set(data.css);
167
167
  result.cva = new Set(data.cva);
168
168
  result.recipe = new Map(Object.entries(data.recipe));
@@ -175,6 +175,8 @@ var createParserResult = () => new ParserResult();
175
175
 
176
176
  // src/parser.ts
177
177
  var isNodeRecipe = (node) => node.type === "recipe";
178
+ var cvaProps = ["compoundVariants", "defaultVariants", "variants", "base"];
179
+ var isCva = (map) => cvaProps.some((prop) => map.has(prop));
178
180
  function createImportMatcher(mod, values) {
179
181
  const regex = values ? new RegExp(`^(${values.join("|")})$`) : /.*/;
180
182
  return {
@@ -188,10 +190,10 @@ function createImportMatcher(mod, values) {
188
190
  var combineResult = (unboxed) => {
189
191
  return [...unboxed.conditions, unboxed.raw, ...unboxed.spreadConditions];
190
192
  };
191
- var fallback = (box) => ({
193
+ var fallback = (box2) => ({
192
194
  value: void 0,
193
- getNode: () => box.getNode(),
194
- getStack: () => box.getStack()
195
+ getNode: () => box2.getNode(),
196
+ getStack: () => box2.getStack()
195
197
  });
196
198
  var defaultEnv = { preset: "NONE" };
197
199
  function createParser(options) {
@@ -222,6 +224,7 @@ function createParser(options) {
222
224
  const isValidPattern = imports.createMatch(importMap.pattern);
223
225
  const isValidRecipe = imports.createMatch(importMap.recipe);
224
226
  const isValidStyleFn = (name) => name === jsx?.factory;
227
+ const isFactory = (name) => jsx && name.startsWith(jsx.factory);
225
228
  const jsxFactoryAlias = jsx ? imports.getAlias(jsx.factory) : "panda";
226
229
  const jsxPatternNodes = new RegExp(
227
230
  `^(${jsx?.nodes.map((node) => node.type === "pattern" && node.name).join("|")})$`
@@ -309,6 +312,9 @@ function createParser(options) {
309
312
  return true;
310
313
  }
311
314
  },
315
+ taggedTemplates: {
316
+ matchTaggedTemplate: (tag) => matchFn(tag.fnName)
317
+ },
312
318
  getEvaluateOptions: (node) => ({ node, environment: defaultEnv }),
313
319
  flags: { skipTraverseFiles: true }
314
320
  });
@@ -319,35 +325,86 @@ function createParser(options) {
319
325
  if (result.kind === "function") {
320
326
  (0, import_ts_pattern.match)(name).when(css.match, (name2) => {
321
327
  result.queryList.forEach((query) => {
322
- collector.set(name2, {
323
- name: name2,
324
- box: query.box.value[0] ?? fallback(query.box),
325
- data: combineResult((0, import_extractor.unbox)(query.box.value[0]))
326
- });
328
+ if (query.kind === "call-expression") {
329
+ collector.set(name2, {
330
+ name: name2,
331
+ box: query.box.value[0] ?? fallback(query.box),
332
+ data: combineResult((0, import_extractor.unbox)(query.box.value[0]))
333
+ });
334
+ } else if (query.kind === "tagged-template") {
335
+ const obj = (0, import_shared2.astish)(query.box.value);
336
+ collector.set(name2, {
337
+ name: name2,
338
+ box: query.box ?? fallback(query.box),
339
+ data: [obj]
340
+ });
341
+ }
327
342
  });
328
343
  }).when(isValidPattern, (name2) => {
329
344
  result.queryList.forEach((query) => {
330
- collector.setPattern(name2, {
331
- name: name2,
332
- box: query.box.value[0] ?? fallback(query.box),
333
- data: combineResult((0, import_extractor.unbox)(query.box.value[0]))
334
- });
345
+ if (query.kind === "call-expression") {
346
+ collector.setPattern(name2, {
347
+ name: name2,
348
+ box: query.box.value[0] ?? fallback(query.box),
349
+ data: combineResult((0, import_extractor.unbox)(query.box.value[0]))
350
+ });
351
+ }
335
352
  });
336
353
  }).when(isValidRecipe, (name2) => {
337
354
  result.queryList.forEach((query) => {
338
- collector.setRecipe(name2, {
339
- name: name2,
340
- box: query.box.value[0] ?? fallback(query.box),
341
- data: combineResult((0, import_extractor.unbox)(query.box.value[0]))
342
- });
355
+ if (query.kind === "call-expression") {
356
+ collector.setRecipe(name2, {
357
+ name: name2,
358
+ box: query.box.value[0] ?? fallback(query.box),
359
+ data: combineResult((0, import_extractor.unbox)(query.box.value[0]))
360
+ });
361
+ }
343
362
  });
344
363
  }).when(isValidStyleFn, () => {
345
364
  result.queryList.forEach((query) => {
346
- collector.setCva({
347
- name,
348
- box: query.box.value[1] ?? fallback(query.box),
349
- data: combineResult((0, import_extractor.unbox)(query.box.value[1]))
350
- });
365
+ if (query.kind === "call-expression" && query.box.value[1]) {
366
+ const map = query.box.value[1];
367
+ const result2 = {
368
+ name,
369
+ box: map ?? fallback(query.box),
370
+ data: combineResult((0, import_extractor.unbox)(map))
371
+ };
372
+ if (import_extractor.box.isMap(map) && isCva(map.value)) {
373
+ collector.setCva(result2);
374
+ } else {
375
+ collector.set("css", result2);
376
+ }
377
+ } else if (query.kind === "tagged-template") {
378
+ const obj = (0, import_shared2.astish)(query.box.value);
379
+ collector.set("css", {
380
+ name,
381
+ box: query.box ?? fallback(query.box),
382
+ data: [obj]
383
+ });
384
+ }
385
+ });
386
+ }).when(isFactory, (name2) => {
387
+ result.queryList.forEach((query) => {
388
+ if (query.kind === "call-expression") {
389
+ const map = query.box.value[0];
390
+ const result2 = {
391
+ name: name2,
392
+ box: map ?? fallback(query.box),
393
+ data: combineResult((0, import_extractor.unbox)(map))
394
+ };
395
+ if (import_extractor.box.isMap(map) && isCva(map.value)) {
396
+ collector.setCva(result2);
397
+ } else {
398
+ collector.set("css", result2);
399
+ }
400
+ } else if (query.kind === "tagged-template") {
401
+ const obj = (0, import_shared2.astish)(query.box.value);
402
+ collector.set("css", {
403
+ name: name2,
404
+ box: query.box ?? fallback(query.box),
405
+ data: [obj]
406
+ });
407
+ }
351
408
  });
352
409
  }).otherwise(() => {
353
410
  });
package/dist/index.mjs CHANGED
@@ -3,9 +3,9 @@ import { Obj, pipe, tap } from "lil-fp";
3
3
  import { Project as TsProject, ScriptKind } from "ts-morph";
4
4
 
5
5
  // src/parser.ts
6
- import { extract, unbox } from "@pandacss/extractor";
6
+ import { extract, unbox, box } from "@pandacss/extractor";
7
7
  import { logger } from "@pandacss/logger";
8
- import { memo as memo2 } from "@pandacss/shared";
8
+ import { astish, memo as memo2 } from "@pandacss/shared";
9
9
  import { Node } from "ts-morph";
10
10
  import { match } from "ts-pattern";
11
11
 
@@ -59,7 +59,7 @@ function getImportDeclarations(file, options) {
59
59
  }
60
60
 
61
61
  // src/parser-result.ts
62
- var ParserResult = class {
62
+ var ParserResult = class _ParserResult {
63
63
  jsx = /* @__PURE__ */ new Set();
64
64
  css = /* @__PURE__ */ new Set();
65
65
  cva = /* @__PURE__ */ new Set();
@@ -124,7 +124,7 @@ var ParserResult = class {
124
124
  }
125
125
  static fromJSON(json) {
126
126
  const data = JSON.parse(json);
127
- const result = new ParserResult();
127
+ const result = new _ParserResult();
128
128
  result.css = new Set(data.css);
129
129
  result.cva = new Set(data.cva);
130
130
  result.recipe = new Map(Object.entries(data.recipe));
@@ -137,6 +137,8 @@ var createParserResult = () => new ParserResult();
137
137
 
138
138
  // src/parser.ts
139
139
  var isNodeRecipe = (node) => node.type === "recipe";
140
+ var cvaProps = ["compoundVariants", "defaultVariants", "variants", "base"];
141
+ var isCva = (map) => cvaProps.some((prop) => map.has(prop));
140
142
  function createImportMatcher(mod, values) {
141
143
  const regex = values ? new RegExp(`^(${values.join("|")})$`) : /.*/;
142
144
  return {
@@ -150,10 +152,10 @@ function createImportMatcher(mod, values) {
150
152
  var combineResult = (unboxed) => {
151
153
  return [...unboxed.conditions, unboxed.raw, ...unboxed.spreadConditions];
152
154
  };
153
- var fallback = (box) => ({
155
+ var fallback = (box2) => ({
154
156
  value: void 0,
155
- getNode: () => box.getNode(),
156
- getStack: () => box.getStack()
157
+ getNode: () => box2.getNode(),
158
+ getStack: () => box2.getStack()
157
159
  });
158
160
  var defaultEnv = { preset: "NONE" };
159
161
  function createParser(options) {
@@ -184,6 +186,7 @@ function createParser(options) {
184
186
  const isValidPattern = imports.createMatch(importMap.pattern);
185
187
  const isValidRecipe = imports.createMatch(importMap.recipe);
186
188
  const isValidStyleFn = (name) => name === jsx?.factory;
189
+ const isFactory = (name) => jsx && name.startsWith(jsx.factory);
187
190
  const jsxFactoryAlias = jsx ? imports.getAlias(jsx.factory) : "panda";
188
191
  const jsxPatternNodes = new RegExp(
189
192
  `^(${jsx?.nodes.map((node) => node.type === "pattern" && node.name).join("|")})$`
@@ -271,6 +274,9 @@ function createParser(options) {
271
274
  return true;
272
275
  }
273
276
  },
277
+ taggedTemplates: {
278
+ matchTaggedTemplate: (tag) => matchFn(tag.fnName)
279
+ },
274
280
  getEvaluateOptions: (node) => ({ node, environment: defaultEnv }),
275
281
  flags: { skipTraverseFiles: true }
276
282
  });
@@ -281,35 +287,86 @@ function createParser(options) {
281
287
  if (result.kind === "function") {
282
288
  match(name).when(css.match, (name2) => {
283
289
  result.queryList.forEach((query) => {
284
- collector.set(name2, {
285
- name: name2,
286
- box: query.box.value[0] ?? fallback(query.box),
287
- data: combineResult(unbox(query.box.value[0]))
288
- });
290
+ if (query.kind === "call-expression") {
291
+ collector.set(name2, {
292
+ name: name2,
293
+ box: query.box.value[0] ?? fallback(query.box),
294
+ data: combineResult(unbox(query.box.value[0]))
295
+ });
296
+ } else if (query.kind === "tagged-template") {
297
+ const obj = astish(query.box.value);
298
+ collector.set(name2, {
299
+ name: name2,
300
+ box: query.box ?? fallback(query.box),
301
+ data: [obj]
302
+ });
303
+ }
289
304
  });
290
305
  }).when(isValidPattern, (name2) => {
291
306
  result.queryList.forEach((query) => {
292
- collector.setPattern(name2, {
293
- name: name2,
294
- box: query.box.value[0] ?? fallback(query.box),
295
- data: combineResult(unbox(query.box.value[0]))
296
- });
307
+ if (query.kind === "call-expression") {
308
+ collector.setPattern(name2, {
309
+ name: name2,
310
+ box: query.box.value[0] ?? fallback(query.box),
311
+ data: combineResult(unbox(query.box.value[0]))
312
+ });
313
+ }
297
314
  });
298
315
  }).when(isValidRecipe, (name2) => {
299
316
  result.queryList.forEach((query) => {
300
- collector.setRecipe(name2, {
301
- name: name2,
302
- box: query.box.value[0] ?? fallback(query.box),
303
- data: combineResult(unbox(query.box.value[0]))
304
- });
317
+ if (query.kind === "call-expression") {
318
+ collector.setRecipe(name2, {
319
+ name: name2,
320
+ box: query.box.value[0] ?? fallback(query.box),
321
+ data: combineResult(unbox(query.box.value[0]))
322
+ });
323
+ }
305
324
  });
306
325
  }).when(isValidStyleFn, () => {
307
326
  result.queryList.forEach((query) => {
308
- collector.setCva({
309
- name,
310
- box: query.box.value[1] ?? fallback(query.box),
311
- data: combineResult(unbox(query.box.value[1]))
312
- });
327
+ if (query.kind === "call-expression" && query.box.value[1]) {
328
+ const map = query.box.value[1];
329
+ const result2 = {
330
+ name,
331
+ box: map ?? fallback(query.box),
332
+ data: combineResult(unbox(map))
333
+ };
334
+ if (box.isMap(map) && isCva(map.value)) {
335
+ collector.setCva(result2);
336
+ } else {
337
+ collector.set("css", result2);
338
+ }
339
+ } else if (query.kind === "tagged-template") {
340
+ const obj = astish(query.box.value);
341
+ collector.set("css", {
342
+ name,
343
+ box: query.box ?? fallback(query.box),
344
+ data: [obj]
345
+ });
346
+ }
347
+ });
348
+ }).when(isFactory, (name2) => {
349
+ result.queryList.forEach((query) => {
350
+ if (query.kind === "call-expression") {
351
+ const map = query.box.value[0];
352
+ const result2 = {
353
+ name: name2,
354
+ box: map ?? fallback(query.box),
355
+ data: combineResult(unbox(map))
356
+ };
357
+ if (box.isMap(map) && isCva(map.value)) {
358
+ collector.setCva(result2);
359
+ } else {
360
+ collector.set("css", result2);
361
+ }
362
+ } else if (query.kind === "tagged-template") {
363
+ const obj = astish(query.box.value);
364
+ collector.set("css", {
365
+ name: name2,
366
+ box: query.box ?? fallback(query.box),
367
+ data: [obj]
368
+ });
369
+ }
313
370
  });
314
371
  }).otherwise(() => {
315
372
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pandacss/parser",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "The static parser for panda css",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -14,19 +14,19 @@
14
14
  "@vue/compiler-sfc": "^3.3.4",
15
15
  "lil-fp": "1.4.5",
16
16
  "magic-string": "^0.30.0",
17
- "svelte": "^3.59.1",
17
+ "svelte": "^4.0.0",
18
18
  "ts-morph": "18.0.0",
19
19
  "ts-pattern": "4.3.0",
20
- "@pandacss/extractor": "0.4.0",
21
- "@pandacss/logger": "0.4.0",
22
- "@pandacss/is-valid-prop": "0.4.0",
23
- "@pandacss/shared": "0.4.0",
24
- "@pandacss/types": "0.4.0"
20
+ "@pandacss/extractor": "0.5.0",
21
+ "@pandacss/is-valid-prop": "0.5.0",
22
+ "@pandacss/logger": "0.5.0",
23
+ "@pandacss/shared": "0.5.0",
24
+ "@pandacss/types": "0.5.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "hookable": "5.5.3",
28
- "@pandacss/fixture": "0.4.0",
29
- "@pandacss/generator": "0.4.0"
28
+ "@pandacss/fixture": "0.5.0",
29
+ "@pandacss/generator": "0.5.0"
30
30
  },
31
31
  "files": [
32
32
  "dist"