@plumeria/compiler 18.2.12 → 18.2.13

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 (2) hide show
  1. package/dist/index.js +46 -38
  2. package/package.json +2 -2
package/dist/index.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
  function extractStylesFromExpression(expression, ctx) {
76
115
  let expr = expression;
77
116
  if (ctx.localStyleAliases &&
@@ -195,6 +234,7 @@ function compileCSS(options) {
195
234
  const keyframesImportMap = {};
196
235
  const viewTransitionImportMap = {};
197
236
  const createImportMap = {};
237
+ const createFunctionImportMap = {};
198
238
  const variantsImportMap = {};
199
239
  const createThemeImportMap = {};
200
240
  const createStaticImportMap = {};
@@ -249,6 +289,8 @@ function compileCSS(options) {
249
289
  if (scannedTables.createHashTable[uniqueKey])
250
290
  createImportMap[localName] =
251
291
  scannedTables.createHashTable[uniqueKey];
292
+ if (scannedTables.createFunctionTable[uniqueKey])
293
+ createFunctionImportMap[localName] = styleFunctionsOf(scannedTables.createFunctionTable[uniqueKey]);
252
294
  if (scannedTables.variantsHashTable[uniqueKey])
253
295
  variantsImportMap[localName] =
254
296
  scannedTables.variantsHashTable[uniqueKey];
@@ -353,6 +395,7 @@ function compileCSS(options) {
353
395
  mergedCreateTable,
354
396
  mergedVariantsTable,
355
397
  scannedTables,
398
+ createFunctionImportMap,
356
399
  localCreateStyles: {},
357
400
  sourceBuffer,
358
401
  baseByteOffset,
@@ -503,7 +546,8 @@ function compileCSS(options) {
503
546
  if (!utils_1.t.isIdentifier(callee.object) || !utils_1.t.isIdentifier(callee.property))
504
547
  return null;
505
548
  const styleInfo = ctx.localCreateStyles[callee.object.value];
506
- const func = styleInfo?.functions?.[callee.property.value];
549
+ const func = styleInfo?.functions?.[callee.property.value] ??
550
+ ctx.createFunctionImportMap[callee.object.value]?.[callee.property.value];
507
551
  if (!func)
508
552
  return null;
509
553
  const callArgs = expr.arguments;
@@ -833,43 +877,7 @@ function compileCSS(options) {
833
877
  if (pName === 'create') {
834
878
  const obj = (0, utils_1.objectExpressionToObject)(arg, ctx.mergedStaticTable, ctx.mergedKeyframesTable, ctx.mergedViewTransitionTable, ctx.mergedCreateThemeHashTable, ctx.scannedTables.createThemeObjectTable, ctx.mergedCreateTable, ctx.mergedCreateStaticHashTable, ctx.scannedTables.createStaticObjectTable, ctx.mergedVariantsTable, resolveVariable);
835
879
  if (obj) {
836
- const styleFunctions = {};
837
- arg.properties.forEach((prop) => {
838
- if (prop.type !== 'KeyValueProperty' ||
839
- prop.key.type !== 'Identifier')
840
- return;
841
- const func = prop.value;
842
- if (func.type !== 'ArrowFunctionExpression' &&
843
- func.type !== 'FunctionExpression')
844
- return;
845
- const params = func.params.map((p) => {
846
- if (utils_1.t.isIdentifier(p))
847
- return p.value;
848
- if (typeof p === 'object' &&
849
- p !== null &&
850
- 'pat' in p &&
851
- utils_1.t.isIdentifier(p.pat))
852
- return p.pat.value;
853
- return 'arg';
854
- });
855
- let actualBody = func.body;
856
- if (actualBody?.type === 'ParenthesisExpression')
857
- actualBody = actualBody.expression;
858
- if (actualBody?.type === 'BlockStatement') {
859
- const first = actualBody.stmts?.[0];
860
- if (first?.type === 'ReturnStatement')
861
- actualBody = first.argument;
862
- if (actualBody?.type === 'ParenthesisExpression')
863
- actualBody = actualBody.expression;
864
- }
865
- if (actualBody && actualBody.type === 'ObjectExpression') {
866
- styleFunctions[prop.key.value] = {
867
- params,
868
- named: namedParamsOf(func.params),
869
- body: actualBody,
870
- };
871
- }
872
- });
880
+ const styleFunctions = styleFunctionsOf(arg);
873
881
  ctx.localCreateStyles[node.id.value] = {
874
882
  type: 'create',
875
883
  obj,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/compiler",
3
- "version": "18.2.12",
3
+ "version": "18.2.13",
4
4
  "description": "Plumeria swc based compiler for statically extracting css",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",
@@ -21,7 +21,7 @@
21
21
  "dist/"
22
22
  ],
23
23
  "dependencies": {
24
- "@plumeria/utils": "^18.2.12"
24
+ "@plumeria/utils": "^18.2.13"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@rust-gear/glob": "1.1.0",