@plumeria/unplugin 18.2.12 → 18.2.14

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.
Files changed (3) hide show
  1. package/dist/core.js +48 -40
  2. package/dist/core.mjs +48 -40
  3. package/package.json +2 -2
package/dist/core.js CHANGED
@@ -72,6 +72,45 @@ const namedParamsOf = (params) => {
72
72
  }
73
73
  return named.length > 0 ? named : undefined;
74
74
  };
75
+ const styleFunctionsOf = (objExpr) => {
76
+ const styleFunctions = {};
77
+ objExpr.properties.forEach((prop) => {
78
+ if (prop.type !== 'KeyValueProperty' || prop.key.type !== 'Identifier')
79
+ return;
80
+ const func = prop.value;
81
+ if (func.type !== 'ArrowFunctionExpression' &&
82
+ func.type !== 'FunctionExpression')
83
+ return;
84
+ const params = func.params.map((p) => {
85
+ if (utils_1.t.isIdentifier(p))
86
+ return p.value;
87
+ if (typeof p === 'object' &&
88
+ p !== null &&
89
+ 'pat' in p &&
90
+ utils_1.t.isIdentifier(p.pat))
91
+ return p.pat.value;
92
+ return 'arg';
93
+ });
94
+ let actualBody = func.body;
95
+ if (actualBody?.type === 'ParenthesisExpression')
96
+ actualBody = actualBody.expression;
97
+ if (actualBody?.type === 'BlockStatement') {
98
+ const first = actualBody.stmts?.[0];
99
+ if (first?.type === 'ReturnStatement')
100
+ actualBody = first.argument;
101
+ if (actualBody?.type === 'ParenthesisExpression')
102
+ actualBody = actualBody.expression;
103
+ }
104
+ if (actualBody && actualBody.type === 'ObjectExpression') {
105
+ styleFunctions[prop.key.value] = {
106
+ params,
107
+ named: namedParamsOf(func.params),
108
+ body: actualBody,
109
+ };
110
+ }
111
+ });
112
+ return styleFunctions;
113
+ };
75
114
  const foldDynamicVars = (vars) => {
76
115
  const grouped = new Map();
77
116
  [...vars]
@@ -297,6 +336,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
297
336
  const keyframesImportMap = {};
298
337
  const viewTransitionImportMap = {};
299
338
  const createImportMap = {};
339
+ const createFunctionImportMap = {};
300
340
  const variantsImportMap = {};
301
341
  const createThemeImportMap = {};
302
342
  const createStaticImportMap = {};
@@ -361,6 +401,9 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
361
401
  createImportMap[localName] =
362
402
  scannedTables.createHashTable[uniqueKey];
363
403
  }
404
+ if (scannedTables.createFunctionTable[uniqueKey]) {
405
+ createFunctionImportMap[localName] = styleFunctionsOf(scannedTables.createFunctionTable[uniqueKey]);
406
+ }
364
407
  if (scannedTables.variantsHashTable[uniqueKey]) {
365
408
  variantsImportMap[localName] =
366
409
  scannedTables.variantsHashTable[uniqueKey];
@@ -520,44 +563,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
520
563
  records.forEach((r) => (atomMap[r.key] = r.hash));
521
564
  hashMap[key] = atomMap;
522
565
  });
523
- const styleFunctions = {};
524
- const objExpr = init.arguments[0].expression;
525
- objExpr.properties.forEach((prop) => {
526
- if (prop.type !== 'KeyValueProperty' ||
527
- prop.key.type !== 'Identifier')
528
- return;
529
- const func = prop.value;
530
- if (func.type !== 'ArrowFunctionExpression' &&
531
- func.type !== 'FunctionExpression')
532
- return;
533
- const params = func.params.map((p) => {
534
- if (utils_1.t.isIdentifier(p))
535
- return p.value;
536
- if (typeof p === 'object' &&
537
- p !== null &&
538
- 'pat' in p &&
539
- utils_1.t.isIdentifier(p.pat))
540
- return p.pat.value;
541
- return 'arg';
542
- });
543
- let actualBody = func.body;
544
- if (actualBody?.type === 'ParenthesisExpression')
545
- actualBody = actualBody.expression;
546
- if (actualBody?.type === 'BlockStatement') {
547
- const first = actualBody.stmts?.[0];
548
- if (first?.type === 'ReturnStatement')
549
- actualBody = first.argument;
550
- if (actualBody?.type === 'ParenthesisExpression')
551
- actualBody = actualBody.expression;
552
- }
553
- if (actualBody && actualBody.type === 'ObjectExpression') {
554
- styleFunctions[prop.key.value] = {
555
- params,
556
- named: namedParamsOf(func.params),
557
- body: actualBody,
558
- };
559
- }
560
- });
566
+ const styleFunctions = styleFunctionsOf(init.arguments[0].expression);
561
567
  if (utils_1.t.isIdentifier(node.id)) {
562
568
  idSpans.add(node.id.span.start);
563
569
  }
@@ -901,7 +907,8 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
901
907
  if (!utils_1.t.isIdentifier(callee.object) || !utils_1.t.isIdentifier(callee.property))
902
908
  return null;
903
909
  const styleInfo = localCreateStyles[callee.object.value];
904
- const func = styleInfo?.functions?.[callee.property.value];
910
+ const func = styleInfo?.functions?.[callee.property.value] ??
911
+ createFunctionImportMap[callee.object.value]?.[callee.property.value];
905
912
  if (!func)
906
913
  return null;
907
914
  const callArgs = expr.arguments;
@@ -2043,7 +2050,8 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
2043
2050
  utils_1.t.isIdentifier(callee.property)) {
2044
2051
  const objectName = callee.object.value;
2045
2052
  const propertyName = callee.property.value;
2046
- if (localCreateStyles[objectName]?.functions?.[propertyName]) {
2053
+ if (localCreateStyles[objectName]?.functions?.[propertyName] ||
2054
+ createFunctionImportMap[objectName]?.[propertyName]) {
2047
2055
  dynamicFnCalls.push(node);
2048
2056
  }
2049
2057
  const alias = plumeriaAliases[objectName];
package/dist/core.mjs CHANGED
@@ -36,6 +36,45 @@ const namedParamsOf = (params) => {
36
36
  }
37
37
  return named.length > 0 ? named : undefined;
38
38
  };
39
+ const styleFunctionsOf = (objExpr) => {
40
+ const styleFunctions = {};
41
+ objExpr.properties.forEach((prop) => {
42
+ if (prop.type !== 'KeyValueProperty' || prop.key.type !== 'Identifier')
43
+ return;
44
+ const func = prop.value;
45
+ if (func.type !== 'ArrowFunctionExpression' &&
46
+ func.type !== 'FunctionExpression')
47
+ return;
48
+ const params = func.params.map((p) => {
49
+ if (t.isIdentifier(p))
50
+ return p.value;
51
+ if (typeof p === 'object' &&
52
+ p !== null &&
53
+ 'pat' in p &&
54
+ t.isIdentifier(p.pat))
55
+ return p.pat.value;
56
+ return 'arg';
57
+ });
58
+ let actualBody = func.body;
59
+ if (actualBody?.type === 'ParenthesisExpression')
60
+ actualBody = actualBody.expression;
61
+ if (actualBody?.type === 'BlockStatement') {
62
+ const first = actualBody.stmts?.[0];
63
+ if (first?.type === 'ReturnStatement')
64
+ actualBody = first.argument;
65
+ if (actualBody?.type === 'ParenthesisExpression')
66
+ actualBody = actualBody.expression;
67
+ }
68
+ if (actualBody && actualBody.type === 'ObjectExpression') {
69
+ styleFunctions[prop.key.value] = {
70
+ params,
71
+ named: namedParamsOf(func.params),
72
+ body: actualBody,
73
+ };
74
+ }
75
+ });
76
+ return styleFunctions;
77
+ };
39
78
  const foldDynamicVars = (vars) => {
40
79
  const grouped = new Map();
41
80
  [...vars]
@@ -261,6 +300,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
261
300
  const keyframesImportMap = {};
262
301
  const viewTransitionImportMap = {};
263
302
  const createImportMap = {};
303
+ const createFunctionImportMap = {};
264
304
  const variantsImportMap = {};
265
305
  const createThemeImportMap = {};
266
306
  const createStaticImportMap = {};
@@ -325,6 +365,9 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
325
365
  createImportMap[localName] =
326
366
  scannedTables.createHashTable[uniqueKey];
327
367
  }
368
+ if (scannedTables.createFunctionTable[uniqueKey]) {
369
+ createFunctionImportMap[localName] = styleFunctionsOf(scannedTables.createFunctionTable[uniqueKey]);
370
+ }
328
371
  if (scannedTables.variantsHashTable[uniqueKey]) {
329
372
  variantsImportMap[localName] =
330
373
  scannedTables.variantsHashTable[uniqueKey];
@@ -484,44 +527,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
484
527
  records.forEach((r) => (atomMap[r.key] = r.hash));
485
528
  hashMap[key] = atomMap;
486
529
  });
487
- const styleFunctions = {};
488
- const objExpr = init.arguments[0].expression;
489
- objExpr.properties.forEach((prop) => {
490
- if (prop.type !== 'KeyValueProperty' ||
491
- prop.key.type !== 'Identifier')
492
- return;
493
- const func = prop.value;
494
- if (func.type !== 'ArrowFunctionExpression' &&
495
- func.type !== 'FunctionExpression')
496
- return;
497
- const params = func.params.map((p) => {
498
- if (t.isIdentifier(p))
499
- return p.value;
500
- if (typeof p === 'object' &&
501
- p !== null &&
502
- 'pat' in p &&
503
- t.isIdentifier(p.pat))
504
- return p.pat.value;
505
- return 'arg';
506
- });
507
- let actualBody = func.body;
508
- if (actualBody?.type === 'ParenthesisExpression')
509
- actualBody = actualBody.expression;
510
- if (actualBody?.type === 'BlockStatement') {
511
- const first = actualBody.stmts?.[0];
512
- if (first?.type === 'ReturnStatement')
513
- actualBody = first.argument;
514
- if (actualBody?.type === 'ParenthesisExpression')
515
- actualBody = actualBody.expression;
516
- }
517
- if (actualBody && actualBody.type === 'ObjectExpression') {
518
- styleFunctions[prop.key.value] = {
519
- params,
520
- named: namedParamsOf(func.params),
521
- body: actualBody,
522
- };
523
- }
524
- });
530
+ const styleFunctions = styleFunctionsOf(init.arguments[0].expression);
525
531
  if (t.isIdentifier(node.id)) {
526
532
  idSpans.add(node.id.span.start);
527
533
  }
@@ -865,7 +871,8 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
865
871
  if (!t.isIdentifier(callee.object) || !t.isIdentifier(callee.property))
866
872
  return null;
867
873
  const styleInfo = localCreateStyles[callee.object.value];
868
- const func = styleInfo?.functions?.[callee.property.value];
874
+ const func = styleInfo?.functions?.[callee.property.value] ??
875
+ createFunctionImportMap[callee.object.value]?.[callee.property.value];
869
876
  if (!func)
870
877
  return null;
871
878
  const callArgs = expr.arguments;
@@ -2007,7 +2014,8 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
2007
2014
  t.isIdentifier(callee.property)) {
2008
2015
  const objectName = callee.object.value;
2009
2016
  const propertyName = callee.property.value;
2010
- if (localCreateStyles[objectName]?.functions?.[propertyName]) {
2017
+ if (localCreateStyles[objectName]?.functions?.[propertyName] ||
2018
+ createFunctionImportMap[objectName]?.[propertyName]) {
2011
2019
  dynamicFnCalls.push(node);
2012
2020
  }
2013
2021
  const alias = plumeriaAliases[objectName];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/unplugin",
3
- "version": "18.2.12",
3
+ "version": "18.2.14",
4
4
  "description": "Universal Plumeria plugin for various build tools",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",
@@ -89,7 +89,7 @@
89
89
  "dependencies": {
90
90
  "@rollup/pluginutils": "^5.4.0",
91
91
  "unplugin": "^3.0.0",
92
- "@plumeria/utils": "^18.2.12"
92
+ "@plumeria/utils": "^18.2.14"
93
93
  },
94
94
  "devDependencies": {
95
95
  "@swc/core": "1.15.47",