@pandacss/parser 0.0.0-dev-20231219220132 → 0.0.0-dev-20231220140705

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
@@ -48,6 +48,7 @@ interface ParserOptions {
48
48
  nodes: ParserNodeOptions[];
49
49
  isStyleProp: (prop: string) => boolean;
50
50
  };
51
+ isTemplateLiteralSyntax: boolean;
51
52
  patternKeys: string[];
52
53
  recipeKeys: string[];
53
54
  getRecipesByJsxName: (jsxName: string) => ParserRecipeNode[];
package/dist/index.d.ts CHANGED
@@ -48,6 +48,7 @@ interface ParserOptions {
48
48
  nodes: ParserNodeOptions[];
49
49
  isStyleProp: (prop: string) => boolean;
50
50
  };
51
+ isTemplateLiteralSyntax: boolean;
51
52
  patternKeys: string[];
52
53
  recipeKeys: string[];
53
54
  getRecipesByJsxName: (jsxName: string) => ParserRecipeNode[];
package/dist/index.js CHANGED
@@ -191,6 +191,7 @@ var isNodeRecipe = (node) => node.type === "recipe";
191
191
  var isNodePattern = (node) => node.type === "pattern";
192
192
  var cvaProps = ["compoundVariants", "defaultVariants", "variants", "base"];
193
193
  var isCva = (map) => cvaProps.some((prop) => map.has(prop));
194
+ var noop = (..._args) => void 0;
194
195
  function createImportMatcher(mod, values) {
195
196
  const regex = values ? new RegExp(`^(${values.join("|")})$`) : /.*/;
196
197
  return {
@@ -213,14 +214,15 @@ var defaultEnv = { preset: "ECMA" };
213
214
  var identityFn = (styles) => styles;
214
215
  var evaluateOptions = { environment: defaultEnv };
215
216
  function createParser(options) {
216
- const { jsx, getRecipesByJsxName, getPatternsByJsxName, tsOptions, join } = options;
217
+ const { jsx, getRecipesByJsxName, getPatternsByJsxName, tsOptions, join, isTemplateLiteralSyntax } = options;
217
218
  const importMap = Object.fromEntries(Object.entries(options.importMap).map(([key, value]) => [key, join(...value)]));
219
+ const isJsxEnabled = jsx.framework;
218
220
  const importRegex = [
219
221
  createImportMatcher(importMap.css, ["css", "cva", "sva"]),
220
222
  createImportMatcher(importMap.recipe),
221
223
  createImportMatcher(importMap.pattern)
222
224
  ];
223
- if (jsx.framework) {
225
+ if (isJsxEnabled) {
224
226
  importRegex.push(createImportMatcher(importMap.jsx, [jsx.factory, ...jsx.nodes.map((node) => node.jsxName)]));
225
227
  }
226
228
  return function parse2(sourceFile) {
@@ -253,31 +255,32 @@ function createParser(options) {
253
255
  "ast:import",
254
256
  imports.value.length ? `Found import { ${imports} } in ${filePath}` : `No import found in ${filePath}`
255
257
  );
258
+ if (!imports.value.length && !isJsxEnabled) {
259
+ return collector;
260
+ }
256
261
  const [css] = importRegex;
257
- const jsxFactoryAlias = jsx ? imports.getAlias(jsx.factory) : "styled";
262
+ const jsxFactoryAlias = isJsxEnabled ? imports.getAlias(jsx.factory) : "styled";
258
263
  const isValidPattern = imports.createMatch(importMap.pattern, options.patternKeys);
259
264
  const isValidRecipe = imports.createMatch(importMap.recipe, options.recipeKeys);
260
265
  const isValidStyleFn = (name) => name === jsx?.factory;
261
- const isFactory = (name) => Boolean(jsx && name.startsWith(jsxFactoryAlias));
266
+ const isFactory = (name) => Boolean(isJsxEnabled && name.startsWith(jsxFactoryAlias));
262
267
  const isRawFn = (fullName) => {
263
268
  const name = fullName.split(".raw")[0] ?? "";
264
269
  return name === "css" || isValidPattern(name) || isValidRecipe(name);
265
270
  };
266
271
  const patternPropertiesByName = /* @__PURE__ */ new Map();
267
- const patternJsxLists = (jsx?.nodes ?? []).filter(isNodePattern).reduce(
268
- (acc, pattern) => {
269
- patternPropertiesByName.set(pattern.jsxName, new Set(pattern.props ?? []));
270
- pattern.jsx?.forEach((jsx2) => {
271
- if (typeof jsx2 === "string") {
272
- acc.string.add(jsx2);
273
- } else if (jsx2) {
274
- acc.regex.push(jsx2);
275
- }
276
- });
277
- return acc;
278
- },
279
- { string: /* @__PURE__ */ new Set(), regex: [] }
280
- );
272
+ const initialpatterns = { string: /* @__PURE__ */ new Set(), regex: [] };
273
+ const patternJsxLists = isJsxEnabled ? (jsx?.nodes ?? []).filter(isNodePattern).reduce((acc, pattern) => {
274
+ patternPropertiesByName.set(pattern.jsxName, new Set(pattern.props ?? []));
275
+ pattern.jsx?.forEach((jsx2) => {
276
+ if (typeof jsx2 === "string") {
277
+ acc.string.add(jsx2);
278
+ } else if (jsx2) {
279
+ acc.regex.push(jsx2);
280
+ }
281
+ });
282
+ return acc;
283
+ }, initialpatterns) : initialpatterns;
281
284
  const recipes = /* @__PURE__ */ new Set();
282
285
  const patterns = /* @__PURE__ */ new Set();
283
286
  imports.value.forEach((importDeclaration) => {
@@ -293,20 +296,18 @@ function createParser(options) {
293
296
  const components = /* @__PURE__ */ new Map();
294
297
  const propertiesMap = /* @__PURE__ */ new Map();
295
298
  const recipePropertiesByJsxName = /* @__PURE__ */ new Map();
296
- const recipeJsxLists = (jsx?.nodes ?? []).filter(isNodeRecipe).reduce(
297
- (acc, recipe) => {
298
- recipePropertiesByJsxName.set(recipe.jsxName, new Set(recipe.props ?? []));
299
- recipe.jsx?.forEach((jsx2) => {
300
- if (typeof jsx2 === "string") {
301
- acc.string.add(jsx2);
302
- } else {
303
- acc.regex.push(jsx2);
304
- }
305
- });
306
- return acc;
307
- },
308
- { string: /* @__PURE__ */ new Set(), regex: [] }
309
- );
299
+ const initialRecipes = { string: /* @__PURE__ */ new Set(), regex: [] };
300
+ const recipeJsxLists = isJsxEnabled ? (jsx?.nodes ?? []).filter(isNodeRecipe).reduce((acc, recipe) => {
301
+ recipePropertiesByJsxName.set(recipe.jsxName, new Set(recipe.props ?? []));
302
+ recipe.jsx?.forEach((jsx2) => {
303
+ if (typeof jsx2 === "string") {
304
+ acc.string.add(jsx2);
305
+ } else {
306
+ acc.regex.push(jsx2);
307
+ }
308
+ });
309
+ return acc;
310
+ }, initialRecipes) : initialRecipes;
310
311
  const cvaAlias = imports.getAlias("cva");
311
312
  const cssAlias = imports.getAlias("css");
312
313
  const svaAlias = imports.getAlias("sva");
@@ -319,36 +320,36 @@ function createParser(options) {
319
320
  components.set(alias, propertiesMap);
320
321
  });
321
322
  }
322
- const isJsxTagRecipe = (0, import_shared2.memo)(
323
+ const isJsxTagRecipe = isJsxEnabled ? (0, import_shared2.memo)(
323
324
  (tagName) => recipeJsxLists.string.has(tagName) || recipeJsxLists.regex.some((regex) => regex.test(tagName))
324
- );
325
- const isJsxTagPattern = (0, import_shared2.memo)(
325
+ ) : noop;
326
+ const isJsxTagPattern = isJsxEnabled ? (0, import_shared2.memo)(
326
327
  (tagName) => patternJsxLists.string.has(tagName) || patternJsxLists.regex.some((regex) => regex.test(tagName))
327
- );
328
- const matchTag = (0, import_shared2.memo)((tagName) => {
328
+ ) : noop;
329
+ const matchTag = isJsxEnabled ? (0, import_shared2.memo)((tagName) => {
329
330
  if (!tagName)
330
331
  return false;
331
332
  return components.has(tagName) || isUpperCase(tagName) || isFactory(tagName) || isJsxTagRecipe(tagName) || isJsxTagPattern(tagName);
332
- });
333
+ }) : noop;
333
334
  const isRecipeOrPatternProp = (0, import_shared2.memo)((tagName, propName) => {
334
- if (isJsxTagRecipe(tagName)) {
335
+ if (isJsxEnabled && isJsxTagRecipe(tagName)) {
335
336
  const recipeList = getRecipesByJsxName(tagName);
336
337
  return recipeList.some((recipe) => recipePropertiesByJsxName.get(recipe.jsxName)?.has(propName));
337
338
  }
338
- if (isJsxTagPattern(tagName)) {
339
+ if (isJsxEnabled && isJsxTagPattern(tagName)) {
339
340
  const patternList = getPatternsByJsxName(tagName);
340
341
  return patternList.some((pattern) => patternPropertiesByName.get(pattern.baseName)?.has(propName));
341
342
  }
342
343
  return false;
343
344
  });
344
- const matchTagProp = (0, import_ts_pattern.match)(jsx?.styleProps).with(
345
+ const matchTagProp = isJsxEnabled ? (0, import_ts_pattern.match)(jsx?.styleProps).with(
345
346
  "all",
346
347
  () => (0, import_shared2.memo)((tagName, propName) => {
347
348
  return Boolean(components.get(tagName)?.has(propName)) || options.jsx?.isStyleProp(propName) || propertiesMap.has(propName) || isRecipeOrPatternProp(tagName, propName);
348
349
  })
349
350
  ).with("minimal", () => (tagName, propName) => {
350
351
  return propName === "css" || isRecipeOrPatternProp(tagName, propName);
351
- }).otherwise(() => (tagName, propName) => isRecipeOrPatternProp(tagName, propName));
352
+ }).otherwise(() => (tagName, propName) => isRecipeOrPatternProp(tagName, propName)) : noop;
352
353
  const matchFn = (0, import_shared2.memo)((fnName) => {
353
354
  if (recipes.has(fnName) || patterns.has(fnName))
354
355
  return true;
@@ -359,10 +360,10 @@ function createParser(options) {
359
360
  const measure = import_logger.logger.time.debug(`Tokens extracted from ${filePath}`);
360
361
  const extractResultByName = (0, import_extractor.extract)({
361
362
  ast: sourceFile,
362
- components: {
363
+ components: isJsxEnabled ? {
363
364
  matchTag: (prop) => matchTag(prop.tagName),
364
365
  matchProp: (prop) => matchTagProp(prop.tagName, prop.propName)
365
- },
366
+ } : void 0,
366
367
  functions: {
367
368
  matchFn: (prop) => matchFn(prop.fnName),
368
369
  matchProp: () => true,
@@ -372,9 +373,7 @@ function createParser(options) {
372
373
  return true;
373
374
  }
374
375
  },
375
- taggedTemplates: {
376
- matchTaggedTemplate: (tag) => matchFn(tag.fnName)
377
- },
376
+ taggedTemplates: isTemplateLiteralSyntax ? { matchTaggedTemplate: (tag) => matchFn(tag.fnName) } : void 0,
378
377
  getEvaluateOptions: (node) => {
379
378
  if (!import_ts_morph.Node.isCallExpression(node))
380
379
  return evaluateOptions;
@@ -504,7 +503,7 @@ function createParser(options) {
504
503
  });
505
504
  }).otherwise(() => {
506
505
  });
507
- } else if (result.kind === "component") {
506
+ } else if (isJsxEnabled && result.kind === "component") {
508
507
  result.queryList.forEach((query) => {
509
508
  const data = combineResult((0, import_extractor.unbox)(query.box));
510
509
  (0, import_ts_pattern.match)(name).when(isFactory, (jsxName) => {
package/dist/index.mjs CHANGED
@@ -153,6 +153,7 @@ var isNodeRecipe = (node) => node.type === "recipe";
153
153
  var isNodePattern = (node) => node.type === "pattern";
154
154
  var cvaProps = ["compoundVariants", "defaultVariants", "variants", "base"];
155
155
  var isCva = (map) => cvaProps.some((prop) => map.has(prop));
156
+ var noop = (..._args) => void 0;
156
157
  function createImportMatcher(mod, values) {
157
158
  const regex = values ? new RegExp(`^(${values.join("|")})$`) : /.*/;
158
159
  return {
@@ -175,14 +176,15 @@ var defaultEnv = { preset: "ECMA" };
175
176
  var identityFn = (styles) => styles;
176
177
  var evaluateOptions = { environment: defaultEnv };
177
178
  function createParser(options) {
178
- const { jsx, getRecipesByJsxName, getPatternsByJsxName, tsOptions, join } = options;
179
+ const { jsx, getRecipesByJsxName, getPatternsByJsxName, tsOptions, join, isTemplateLiteralSyntax } = options;
179
180
  const importMap = Object.fromEntries(Object.entries(options.importMap).map(([key, value]) => [key, join(...value)]));
181
+ const isJsxEnabled = jsx.framework;
180
182
  const importRegex = [
181
183
  createImportMatcher(importMap.css, ["css", "cva", "sva"]),
182
184
  createImportMatcher(importMap.recipe),
183
185
  createImportMatcher(importMap.pattern)
184
186
  ];
185
- if (jsx.framework) {
187
+ if (isJsxEnabled) {
186
188
  importRegex.push(createImportMatcher(importMap.jsx, [jsx.factory, ...jsx.nodes.map((node) => node.jsxName)]));
187
189
  }
188
190
  return function parse2(sourceFile) {
@@ -215,31 +217,32 @@ function createParser(options) {
215
217
  "ast:import",
216
218
  imports.value.length ? `Found import { ${imports} } in ${filePath}` : `No import found in ${filePath}`
217
219
  );
220
+ if (!imports.value.length && !isJsxEnabled) {
221
+ return collector;
222
+ }
218
223
  const [css] = importRegex;
219
- const jsxFactoryAlias = jsx ? imports.getAlias(jsx.factory) : "styled";
224
+ const jsxFactoryAlias = isJsxEnabled ? imports.getAlias(jsx.factory) : "styled";
220
225
  const isValidPattern = imports.createMatch(importMap.pattern, options.patternKeys);
221
226
  const isValidRecipe = imports.createMatch(importMap.recipe, options.recipeKeys);
222
227
  const isValidStyleFn = (name) => name === jsx?.factory;
223
- const isFactory = (name) => Boolean(jsx && name.startsWith(jsxFactoryAlias));
228
+ const isFactory = (name) => Boolean(isJsxEnabled && name.startsWith(jsxFactoryAlias));
224
229
  const isRawFn = (fullName) => {
225
230
  const name = fullName.split(".raw")[0] ?? "";
226
231
  return name === "css" || isValidPattern(name) || isValidRecipe(name);
227
232
  };
228
233
  const patternPropertiesByName = /* @__PURE__ */ new Map();
229
- const patternJsxLists = (jsx?.nodes ?? []).filter(isNodePattern).reduce(
230
- (acc, pattern) => {
231
- patternPropertiesByName.set(pattern.jsxName, new Set(pattern.props ?? []));
232
- pattern.jsx?.forEach((jsx2) => {
233
- if (typeof jsx2 === "string") {
234
- acc.string.add(jsx2);
235
- } else if (jsx2) {
236
- acc.regex.push(jsx2);
237
- }
238
- });
239
- return acc;
240
- },
241
- { string: /* @__PURE__ */ new Set(), regex: [] }
242
- );
234
+ const initialpatterns = { string: /* @__PURE__ */ new Set(), regex: [] };
235
+ const patternJsxLists = isJsxEnabled ? (jsx?.nodes ?? []).filter(isNodePattern).reduce((acc, pattern) => {
236
+ patternPropertiesByName.set(pattern.jsxName, new Set(pattern.props ?? []));
237
+ pattern.jsx?.forEach((jsx2) => {
238
+ if (typeof jsx2 === "string") {
239
+ acc.string.add(jsx2);
240
+ } else if (jsx2) {
241
+ acc.regex.push(jsx2);
242
+ }
243
+ });
244
+ return acc;
245
+ }, initialpatterns) : initialpatterns;
243
246
  const recipes = /* @__PURE__ */ new Set();
244
247
  const patterns = /* @__PURE__ */ new Set();
245
248
  imports.value.forEach((importDeclaration) => {
@@ -255,20 +258,18 @@ function createParser(options) {
255
258
  const components = /* @__PURE__ */ new Map();
256
259
  const propertiesMap = /* @__PURE__ */ new Map();
257
260
  const recipePropertiesByJsxName = /* @__PURE__ */ new Map();
258
- const recipeJsxLists = (jsx?.nodes ?? []).filter(isNodeRecipe).reduce(
259
- (acc, recipe) => {
260
- recipePropertiesByJsxName.set(recipe.jsxName, new Set(recipe.props ?? []));
261
- recipe.jsx?.forEach((jsx2) => {
262
- if (typeof jsx2 === "string") {
263
- acc.string.add(jsx2);
264
- } else {
265
- acc.regex.push(jsx2);
266
- }
267
- });
268
- return acc;
269
- },
270
- { string: /* @__PURE__ */ new Set(), regex: [] }
271
- );
261
+ const initialRecipes = { string: /* @__PURE__ */ new Set(), regex: [] };
262
+ const recipeJsxLists = isJsxEnabled ? (jsx?.nodes ?? []).filter(isNodeRecipe).reduce((acc, recipe) => {
263
+ recipePropertiesByJsxName.set(recipe.jsxName, new Set(recipe.props ?? []));
264
+ recipe.jsx?.forEach((jsx2) => {
265
+ if (typeof jsx2 === "string") {
266
+ acc.string.add(jsx2);
267
+ } else {
268
+ acc.regex.push(jsx2);
269
+ }
270
+ });
271
+ return acc;
272
+ }, initialRecipes) : initialRecipes;
272
273
  const cvaAlias = imports.getAlias("cva");
273
274
  const cssAlias = imports.getAlias("css");
274
275
  const svaAlias = imports.getAlias("sva");
@@ -281,36 +282,36 @@ function createParser(options) {
281
282
  components.set(alias, propertiesMap);
282
283
  });
283
284
  }
284
- const isJsxTagRecipe = memo2(
285
+ const isJsxTagRecipe = isJsxEnabled ? memo2(
285
286
  (tagName) => recipeJsxLists.string.has(tagName) || recipeJsxLists.regex.some((regex) => regex.test(tagName))
286
- );
287
- const isJsxTagPattern = memo2(
287
+ ) : noop;
288
+ const isJsxTagPattern = isJsxEnabled ? memo2(
288
289
  (tagName) => patternJsxLists.string.has(tagName) || patternJsxLists.regex.some((regex) => regex.test(tagName))
289
- );
290
- const matchTag = memo2((tagName) => {
290
+ ) : noop;
291
+ const matchTag = isJsxEnabled ? memo2((tagName) => {
291
292
  if (!tagName)
292
293
  return false;
293
294
  return components.has(tagName) || isUpperCase(tagName) || isFactory(tagName) || isJsxTagRecipe(tagName) || isJsxTagPattern(tagName);
294
- });
295
+ }) : noop;
295
296
  const isRecipeOrPatternProp = memo2((tagName, propName) => {
296
- if (isJsxTagRecipe(tagName)) {
297
+ if (isJsxEnabled && isJsxTagRecipe(tagName)) {
297
298
  const recipeList = getRecipesByJsxName(tagName);
298
299
  return recipeList.some((recipe) => recipePropertiesByJsxName.get(recipe.jsxName)?.has(propName));
299
300
  }
300
- if (isJsxTagPattern(tagName)) {
301
+ if (isJsxEnabled && isJsxTagPattern(tagName)) {
301
302
  const patternList = getPatternsByJsxName(tagName);
302
303
  return patternList.some((pattern) => patternPropertiesByName.get(pattern.baseName)?.has(propName));
303
304
  }
304
305
  return false;
305
306
  });
306
- const matchTagProp = match(jsx?.styleProps).with(
307
+ const matchTagProp = isJsxEnabled ? match(jsx?.styleProps).with(
307
308
  "all",
308
309
  () => memo2((tagName, propName) => {
309
310
  return Boolean(components.get(tagName)?.has(propName)) || options.jsx?.isStyleProp(propName) || propertiesMap.has(propName) || isRecipeOrPatternProp(tagName, propName);
310
311
  })
311
312
  ).with("minimal", () => (tagName, propName) => {
312
313
  return propName === "css" || isRecipeOrPatternProp(tagName, propName);
313
- }).otherwise(() => (tagName, propName) => isRecipeOrPatternProp(tagName, propName));
314
+ }).otherwise(() => (tagName, propName) => isRecipeOrPatternProp(tagName, propName)) : noop;
314
315
  const matchFn = memo2((fnName) => {
315
316
  if (recipes.has(fnName) || patterns.has(fnName))
316
317
  return true;
@@ -321,10 +322,10 @@ function createParser(options) {
321
322
  const measure = logger.time.debug(`Tokens extracted from ${filePath}`);
322
323
  const extractResultByName = extract({
323
324
  ast: sourceFile,
324
- components: {
325
+ components: isJsxEnabled ? {
325
326
  matchTag: (prop) => matchTag(prop.tagName),
326
327
  matchProp: (prop) => matchTagProp(prop.tagName, prop.propName)
327
- },
328
+ } : void 0,
328
329
  functions: {
329
330
  matchFn: (prop) => matchFn(prop.fnName),
330
331
  matchProp: () => true,
@@ -334,9 +335,7 @@ function createParser(options) {
334
335
  return true;
335
336
  }
336
337
  },
337
- taggedTemplates: {
338
- matchTaggedTemplate: (tag) => matchFn(tag.fnName)
339
- },
338
+ taggedTemplates: isTemplateLiteralSyntax ? { matchTaggedTemplate: (tag) => matchFn(tag.fnName) } : void 0,
340
339
  getEvaluateOptions: (node) => {
341
340
  if (!Node.isCallExpression(node))
342
341
  return evaluateOptions;
@@ -466,7 +465,7 @@ function createParser(options) {
466
465
  });
467
466
  }).otherwise(() => {
468
467
  });
469
- } else if (result.kind === "component") {
468
+ } else if (isJsxEnabled && result.kind === "component") {
470
469
  result.queryList.forEach((query) => {
471
470
  const data = combineResult(unbox(query.box));
472
471
  match(name).when(isFactory, (jsxName) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pandacss/parser",
3
- "version": "0.0.0-dev-20231219220132",
3
+ "version": "0.0.0-dev-20231220140705",
4
4
  "description": "The static parser for panda css",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -27,17 +27,17 @@
27
27
  "magic-string": "^0.30.2",
28
28
  "ts-morph": "19.0.0",
29
29
  "ts-pattern": "5.0.5",
30
- "@pandacss/config": "^0.0.0-dev-20231219220132",
31
- "@pandacss/extractor": "0.0.0-dev-20231219220132",
32
- "@pandacss/is-valid-prop": "0.0.0-dev-20231219220132",
33
- "@pandacss/logger": "0.0.0-dev-20231219220132",
34
- "@pandacss/shared": "0.0.0-dev-20231219220132",
35
- "@pandacss/types": "0.0.0-dev-20231219220132"
30
+ "@pandacss/config": "^0.0.0-dev-20231220140705",
31
+ "@pandacss/extractor": "0.0.0-dev-20231220140705",
32
+ "@pandacss/is-valid-prop": "0.0.0-dev-20231220140705",
33
+ "@pandacss/logger": "0.0.0-dev-20231220140705",
34
+ "@pandacss/shared": "0.0.0-dev-20231220140705",
35
+ "@pandacss/types": "0.0.0-dev-20231220140705"
36
36
  },
37
37
  "devDependencies": {
38
38
  "hookable": "5.5.3",
39
- "@pandacss/fixture": "0.0.0-dev-20231219220132",
40
- "@pandacss/generator": "0.0.0-dev-20231219220132"
39
+ "@pandacss/fixture": "0.0.0-dev-20231220140705",
40
+ "@pandacss/generator": "0.0.0-dev-20231220140705"
41
41
  },
42
42
  "files": [
43
43
  "dist"