@pandacss/parser 0.30.1 → 0.31.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.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ParserOptions } from '@pandacss/core';
2
- import { ParserResultInterface, ResultItem, Runtime, PandaHooks, ConfigTsOptions } from '@pandacss/types';
2
+ import { ParserResultInterface, ResultItem, ParserResultConfigureOptions, Runtime, PandaHooks, ConfigTsOptions } from '@pandacss/types';
3
3
  import { SourceFile, ProjectOptions as ProjectOptions$1, Project as Project$1, FileSystemRefreshResult } from 'ts-morph';
4
4
  import { Generator } from '@pandacss/generator';
5
5
 
@@ -42,7 +42,7 @@ declare class ParserResult implements ParserResultInterface {
42
42
  };
43
43
  }
44
44
 
45
- declare function createParser(context: ParserOptions): (sourceFile: SourceFile | undefined, encoder?: Generator['encoder']) => ParserResult | undefined;
45
+ declare function createParser(context: ParserOptions): (sourceFile: SourceFile | undefined, encoder?: Generator['encoder'], options?: ParserResultConfigureOptions) => ParserResult | undefined;
46
46
 
47
47
  interface ProjectOptions extends ProjectOptions$1 {
48
48
  readFile: Runtime['fs']['readFileSync'];
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ParserOptions } from '@pandacss/core';
2
- import { ParserResultInterface, ResultItem, Runtime, PandaHooks, ConfigTsOptions } from '@pandacss/types';
2
+ import { ParserResultInterface, ResultItem, ParserResultConfigureOptions, Runtime, PandaHooks, ConfigTsOptions } from '@pandacss/types';
3
3
  import { SourceFile, ProjectOptions as ProjectOptions$1, Project as Project$1, FileSystemRefreshResult } from 'ts-morph';
4
4
  import { Generator } from '@pandacss/generator';
5
5
 
@@ -42,7 +42,7 @@ declare class ParserResult implements ParserResultInterface {
42
42
  };
43
43
  }
44
44
 
45
- declare function createParser(context: ParserOptions): (sourceFile: SourceFile | undefined, encoder?: Generator['encoder']) => ParserResult | undefined;
45
+ declare function createParser(context: ParserOptions): (sourceFile: SourceFile | undefined, encoder?: Generator['encoder'], options?: ParserResultConfigureOptions) => ParserResult | undefined;
46
46
 
47
47
  interface ProjectOptions extends ProjectOptions$1 {
48
48
  readFile: Runtime['fs']['readFileSync'];
package/dist/index.js CHANGED
@@ -216,7 +216,7 @@ var evaluateOptions = {
216
216
  };
217
217
  function createParser(context) {
218
218
  const { jsx, imports, recipes, syntax } = context;
219
- return function parse2(sourceFile, encoder) {
219
+ return function parse2(sourceFile, encoder, options) {
220
220
  if (!sourceFile)
221
221
  return;
222
222
  const importDeclarations = getImportDeclarations(context, sourceFile);
@@ -233,8 +233,20 @@ function createParser(context) {
233
233
  const extractResultByName = (0, import_extractor.extract)({
234
234
  ast: sourceFile,
235
235
  components: jsx.isEnabled ? {
236
- matchTag: (prop) => !!file.matchTag(prop.tagName),
237
- matchProp: (prop) => !!file.matchTagProp(prop.tagName, prop.propName)
236
+ matchTag: (prop) => {
237
+ if (options?.matchTag) {
238
+ const isPandaComponent = file.isPandaComponent(prop.tagName);
239
+ return isPandaComponent || options.matchTag(prop.tagName, isPandaComponent);
240
+ }
241
+ return !!file.matchTag(prop.tagName);
242
+ },
243
+ matchProp: (prop) => {
244
+ const isPandaProp = file.matchTagProp(prop.tagName, prop.propName);
245
+ if (options?.matchTagProp) {
246
+ return isPandaProp && options.matchTagProp(prop.tagName, prop.propName);
247
+ }
248
+ return isPandaProp;
249
+ }
238
250
  } : void 0,
239
251
  functions: {
240
252
  matchFn: (prop) => file.matchFn(prop.fnName),
@@ -332,8 +344,8 @@ function createParser(context) {
332
344
  } else {
333
345
  parserResult.set("css", result2);
334
346
  }
335
- const options = query.box.value[2];
336
- if (import_extractor.box.isUnresolvable(map) && options && import_extractor.box.isMap(options) && options.value.has("defaultProps")) {
347
+ const options2 = query.box.value[2];
348
+ if (import_extractor.box.isUnresolvable(map) && options2 && import_extractor.box.isMap(options2) && options2.value.has("defaultProps")) {
337
349
  const maybeIdentifier = map.getNode();
338
350
  if (import_ts_morph.Node.isIdentifier(maybeIdentifier)) {
339
351
  const name2 = maybeIdentifier.getText();
@@ -341,8 +353,8 @@ function createParser(context) {
341
353
  parserResult.setRecipe(recipeName, {
342
354
  type: "jsx-recipe",
343
355
  name: recipeName,
344
- box: options,
345
- data: combineResult((0, import_extractor.unbox)(options.value.get("defaultProps")))
356
+ box: options2,
357
+ data: combineResult((0, import_extractor.unbox)(options2.value.get("defaultProps")))
346
358
  });
347
359
  }
348
360
  }
@@ -579,12 +591,25 @@ var Project = class {
579
591
  if (!sourceFile)
580
592
  return;
581
593
  const original = sourceFile.getText();
582
- const custom = hooks["parser:before"]?.({ filePath, content: original });
594
+ const options = {};
595
+ const custom = hooks["parser:before"]?.({
596
+ filePath,
597
+ content: original,
598
+ configure(opts) {
599
+ const { matchTag, matchTagProp } = opts;
600
+ if (matchTag) {
601
+ options.matchTag = matchTag;
602
+ }
603
+ if (matchTagProp) {
604
+ options.matchTagProp = matchTagProp;
605
+ }
606
+ }
607
+ });
583
608
  const transformed = custom ?? this.transformFile(filePath, original);
584
609
  if (original !== transformed) {
585
610
  sourceFile.replaceWithText(transformed);
586
611
  }
587
- const result = this.parser(sourceFile, encoder)?.setFilePath(filePath);
612
+ const result = this.parser(sourceFile, encoder, options)?.setFilePath(filePath);
588
613
  hooks["parser:after"]?.({ filePath, result });
589
614
  return result;
590
615
  };
package/dist/index.mjs CHANGED
@@ -182,7 +182,7 @@ var evaluateOptions = {
182
182
  };
183
183
  function createParser(context) {
184
184
  const { jsx, imports, recipes, syntax } = context;
185
- return function parse2(sourceFile, encoder) {
185
+ return function parse2(sourceFile, encoder, options) {
186
186
  if (!sourceFile)
187
187
  return;
188
188
  const importDeclarations = getImportDeclarations(context, sourceFile);
@@ -199,8 +199,20 @@ function createParser(context) {
199
199
  const extractResultByName = extract({
200
200
  ast: sourceFile,
201
201
  components: jsx.isEnabled ? {
202
- matchTag: (prop) => !!file.matchTag(prop.tagName),
203
- matchProp: (prop) => !!file.matchTagProp(prop.tagName, prop.propName)
202
+ matchTag: (prop) => {
203
+ if (options?.matchTag) {
204
+ const isPandaComponent = file.isPandaComponent(prop.tagName);
205
+ return isPandaComponent || options.matchTag(prop.tagName, isPandaComponent);
206
+ }
207
+ return !!file.matchTag(prop.tagName);
208
+ },
209
+ matchProp: (prop) => {
210
+ const isPandaProp = file.matchTagProp(prop.tagName, prop.propName);
211
+ if (options?.matchTagProp) {
212
+ return isPandaProp && options.matchTagProp(prop.tagName, prop.propName);
213
+ }
214
+ return isPandaProp;
215
+ }
204
216
  } : void 0,
205
217
  functions: {
206
218
  matchFn: (prop) => file.matchFn(prop.fnName),
@@ -298,8 +310,8 @@ function createParser(context) {
298
310
  } else {
299
311
  parserResult.set("css", result2);
300
312
  }
301
- const options = query.box.value[2];
302
- if (box.isUnresolvable(map) && options && box.isMap(options) && options.value.has("defaultProps")) {
313
+ const options2 = query.box.value[2];
314
+ if (box.isUnresolvable(map) && options2 && box.isMap(options2) && options2.value.has("defaultProps")) {
303
315
  const maybeIdentifier = map.getNode();
304
316
  if (Node.isIdentifier(maybeIdentifier)) {
305
317
  const name2 = maybeIdentifier.getText();
@@ -307,8 +319,8 @@ function createParser(context) {
307
319
  parserResult.setRecipe(recipeName, {
308
320
  type: "jsx-recipe",
309
321
  name: recipeName,
310
- box: options,
311
- data: combineResult(unbox(options.value.get("defaultProps")))
322
+ box: options2,
323
+ data: combineResult(unbox(options2.value.get("defaultProps")))
312
324
  });
313
325
  }
314
326
  }
@@ -545,12 +557,25 @@ var Project = class {
545
557
  if (!sourceFile)
546
558
  return;
547
559
  const original = sourceFile.getText();
548
- const custom = hooks["parser:before"]?.({ filePath, content: original });
560
+ const options = {};
561
+ const custom = hooks["parser:before"]?.({
562
+ filePath,
563
+ content: original,
564
+ configure(opts) {
565
+ const { matchTag, matchTagProp } = opts;
566
+ if (matchTag) {
567
+ options.matchTag = matchTag;
568
+ }
569
+ if (matchTagProp) {
570
+ options.matchTagProp = matchTagProp;
571
+ }
572
+ }
573
+ });
549
574
  const transformed = custom ?? this.transformFile(filePath, original);
550
575
  if (original !== transformed) {
551
576
  sourceFile.replaceWithText(transformed);
552
577
  }
553
- const result = this.parser(sourceFile, encoder)?.setFilePath(filePath);
578
+ const result = this.parser(sourceFile, encoder, options)?.setFilePath(filePath);
554
579
  hooks["parser:after"]?.({ filePath, result });
555
580
  return result;
556
581
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pandacss/parser",
3
- "version": "0.30.1",
3
+ "version": "0.31.0",
4
4
  "description": "The static parser for panda css",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -29,19 +29,19 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@vue/compiler-sfc": "3.3.4",
32
- "magic-string": "0.30.6",
32
+ "magic-string": "0.30.7",
33
33
  "ts-morph": "19.0.0",
34
34
  "ts-pattern": "5.0.5",
35
- "@pandacss/config": "^0.30.1",
36
- "@pandacss/core": "^0.30.1",
37
- "@pandacss/extractor": "0.30.1",
38
- "@pandacss/logger": "0.30.1",
39
- "@pandacss/shared": "0.30.1",
40
- "@pandacss/types": "0.30.1"
35
+ "@pandacss/config": "^0.31.0",
36
+ "@pandacss/core": "^0.31.0",
37
+ "@pandacss/extractor": "0.31.0",
38
+ "@pandacss/logger": "0.31.0",
39
+ "@pandacss/shared": "0.31.0",
40
+ "@pandacss/types": "0.31.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@vue/compiler-core": "3.3.4",
44
- "@pandacss/generator": "0.30.1"
44
+ "@pandacss/generator": "0.31.0"
45
45
  },
46
46
  "files": [
47
47
  "dist"