@plumeria/compiler 10.0.6 → 10.0.7
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.js +56 -21
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -190,7 +190,10 @@ function compileCSS(options) {
|
|
|
190
190
|
mergedKeyframesTable[key] = scannedTables.keyframesHashTable[key];
|
|
191
191
|
}
|
|
192
192
|
for (const key of Object.keys(importMap)) {
|
|
193
|
-
|
|
193
|
+
const val = importMap[key];
|
|
194
|
+
if (typeof val === 'string') {
|
|
195
|
+
mergedKeyframesTable[key] = val;
|
|
196
|
+
}
|
|
194
197
|
}
|
|
195
198
|
const mergedViewTransitionTable = {};
|
|
196
199
|
for (const key of Object.keys(scannedTables.viewTransitionHashTable)) {
|
|
@@ -198,14 +201,20 @@ function compileCSS(options) {
|
|
|
198
201
|
scannedTables.viewTransitionHashTable[key];
|
|
199
202
|
}
|
|
200
203
|
for (const key of Object.keys(importMap)) {
|
|
201
|
-
|
|
204
|
+
const val = importMap[key];
|
|
205
|
+
if (typeof val === 'string') {
|
|
206
|
+
mergedViewTransitionTable[key] = val;
|
|
207
|
+
}
|
|
202
208
|
}
|
|
203
209
|
const mergedCreateThemeHashTable = {};
|
|
204
210
|
for (const key of Object.keys(scannedTables.createThemeHashTable)) {
|
|
205
211
|
mergedCreateThemeHashTable[key] = scannedTables.createThemeHashTable[key];
|
|
206
212
|
}
|
|
207
213
|
for (const key of Object.keys(importMap)) {
|
|
208
|
-
|
|
214
|
+
const val = importMap[key];
|
|
215
|
+
if (typeof val === 'string') {
|
|
216
|
+
mergedCreateThemeHashTable[key] = val;
|
|
217
|
+
}
|
|
209
218
|
}
|
|
210
219
|
const mergedCreateStaticHashTable = {};
|
|
211
220
|
for (const key of Object.keys(scannedTables.createStaticHashTable)) {
|
|
@@ -213,21 +222,30 @@ function compileCSS(options) {
|
|
|
213
222
|
scannedTables.createStaticHashTable[key];
|
|
214
223
|
}
|
|
215
224
|
for (const key of Object.keys(importMap)) {
|
|
216
|
-
|
|
225
|
+
const val = importMap[key];
|
|
226
|
+
if (typeof val === 'string') {
|
|
227
|
+
mergedCreateStaticHashTable[key] = val;
|
|
228
|
+
}
|
|
217
229
|
}
|
|
218
230
|
const mergedCreateTable = {};
|
|
219
231
|
for (const key of Object.keys(scannedTables.createHashTable)) {
|
|
220
232
|
mergedCreateTable[key] = scannedTables.createHashTable[key];
|
|
221
233
|
}
|
|
222
234
|
for (const key of Object.keys(importMap)) {
|
|
223
|
-
|
|
235
|
+
const val = importMap[key];
|
|
236
|
+
if (typeof val === 'string') {
|
|
237
|
+
mergedCreateTable[key] = val;
|
|
238
|
+
}
|
|
224
239
|
}
|
|
225
240
|
const mergedVariantsTable = {};
|
|
226
241
|
for (const key of Object.keys(scannedTables.variantsHashTable)) {
|
|
227
242
|
mergedVariantsTable[key] = scannedTables.variantsHashTable[key];
|
|
228
243
|
}
|
|
229
244
|
for (const key of Object.keys(importMap)) {
|
|
230
|
-
|
|
245
|
+
const val = importMap[key];
|
|
246
|
+
if (typeof val === 'string') {
|
|
247
|
+
mergedVariantsTable[key] = val;
|
|
248
|
+
}
|
|
231
249
|
}
|
|
232
250
|
const ctx = {
|
|
233
251
|
mergedStaticTable,
|
|
@@ -285,8 +303,7 @@ function compileCSS(options) {
|
|
|
285
303
|
]);
|
|
286
304
|
return true;
|
|
287
305
|
}
|
|
288
|
-
else if (node.type === 'BinaryExpression' &&
|
|
289
|
-
node.operator === '&&') {
|
|
306
|
+
else if (node.type === 'BinaryExpression' && node.operator === '&&') {
|
|
290
307
|
collectConditions(node.right, [
|
|
291
308
|
...testStrings,
|
|
292
309
|
`(${getSource(node.left)})`,
|
|
@@ -308,8 +325,10 @@ function compileCSS(options) {
|
|
|
308
325
|
const varName = node.callee.object.value;
|
|
309
326
|
const propKey = node.callee.property.value;
|
|
310
327
|
const styleInfo = ctx.localCreateStyles[varName];
|
|
311
|
-
const atomMap = styleInfo?.obj
|
|
312
|
-
if (atomMap
|
|
328
|
+
const atomMap = styleInfo?.obj[propKey];
|
|
329
|
+
if (typeof atomMap === 'object' &&
|
|
330
|
+
atomMap !== null &&
|
|
331
|
+
'__cssVars__' in atomMap) {
|
|
313
332
|
throw new Error(`[plumeria] css.use(${getSource(node)}) cannot handle dynamic style functions. Use styleName instead.\n`);
|
|
314
333
|
}
|
|
315
334
|
}
|
|
@@ -348,8 +367,11 @@ function compileCSS(options) {
|
|
|
348
367
|
processStyle(cond.falsy);
|
|
349
368
|
}
|
|
350
369
|
};
|
|
370
|
+
const processedNodes = new WeakSet();
|
|
351
371
|
const processCall = (node) => {
|
|
352
|
-
node
|
|
372
|
+
if (processedNodes.has(node))
|
|
373
|
+
return;
|
|
374
|
+
processedNodes.add(node);
|
|
353
375
|
const callee = node.callee;
|
|
354
376
|
let propName;
|
|
355
377
|
if (utils_1.t.isMemberExpression(callee) &&
|
|
@@ -412,12 +434,10 @@ function compileCSS(options) {
|
|
|
412
434
|
if (utils_1.t.isMemberExpression(callee) &&
|
|
413
435
|
utils_1.t.isIdentifier(callee.object) &&
|
|
414
436
|
utils_1.t.isIdentifier(callee.property)) {
|
|
415
|
-
if (plumeriaAliases[callee.object.value] ===
|
|
416
|
-
'NAMESPACE')
|
|
437
|
+
if (plumeriaAliases[callee.object.value] === 'NAMESPACE')
|
|
417
438
|
pName = callee.property.value;
|
|
418
439
|
}
|
|
419
|
-
else if (utils_1.t.isIdentifier(callee) &&
|
|
420
|
-
plumeriaAliases[callee.value]) {
|
|
440
|
+
else if (utils_1.t.isIdentifier(callee) && plumeriaAliases[callee.value]) {
|
|
421
441
|
pName = plumeriaAliases[callee.value];
|
|
422
442
|
}
|
|
423
443
|
if (pName &&
|
|
@@ -446,12 +466,25 @@ function compileCSS(options) {
|
|
|
446
466
|
if (!isArrow && !isFunc)
|
|
447
467
|
return;
|
|
448
468
|
const key = prop.key.value;
|
|
449
|
-
const
|
|
469
|
+
const func = prop.value;
|
|
470
|
+
if (func.type !== 'ArrowFunctionExpression' &&
|
|
471
|
+
func.type !== 'FunctionExpression')
|
|
472
|
+
return;
|
|
473
|
+
const params = func.params.map((p) => {
|
|
474
|
+
if (utils_1.t.isIdentifier(p))
|
|
475
|
+
return p.value;
|
|
476
|
+
if (typeof p === 'object' &&
|
|
477
|
+
p !== null &&
|
|
478
|
+
'pat' in p &&
|
|
479
|
+
utils_1.t.isIdentifier(p.pat))
|
|
480
|
+
return p.pat.value;
|
|
481
|
+
return 'arg';
|
|
482
|
+
});
|
|
450
483
|
const tempStaticTable = { ...ctx.mergedStaticTable };
|
|
451
484
|
params.forEach((paramName) => {
|
|
452
485
|
tempStaticTable[paramName] = `var(--${key}-${paramName})`;
|
|
453
486
|
});
|
|
454
|
-
let actualBody =
|
|
487
|
+
let actualBody = func.body;
|
|
455
488
|
if (actualBody?.type === 'ParenthesisExpression')
|
|
456
489
|
actualBody = actualBody.expression;
|
|
457
490
|
if (actualBody?.type === 'BlockStatement') {
|
|
@@ -498,19 +531,21 @@ function compileCSS(options) {
|
|
|
498
531
|
traverseInternal(node.body);
|
|
499
532
|
},
|
|
500
533
|
CallExpression: (path) => {
|
|
501
|
-
if (!path.node
|
|
534
|
+
if (!processedNodes.has(path.node))
|
|
502
535
|
processCall(path.node);
|
|
503
536
|
},
|
|
504
537
|
JSXAttribute({ node }) {
|
|
505
|
-
if (node.name
|
|
538
|
+
if (node.name.value !== 'styleName')
|
|
506
539
|
return;
|
|
507
540
|
if (!node.value || node.value.type !== 'JSXExpressionContainer')
|
|
508
541
|
return;
|
|
542
|
+
if (node.value.expression.type === 'JSXEmptyExpression')
|
|
543
|
+
return;
|
|
509
544
|
const expr = node.value.expression;
|
|
510
545
|
const args = expr.type === 'ArrayExpression'
|
|
511
546
|
? expr.elements
|
|
512
|
-
.filter(
|
|
513
|
-
.map((el) => ({ expression: el.expression
|
|
547
|
+
.filter((el) => el !== undefined)
|
|
548
|
+
.map((el) => ({ expression: el.expression }))
|
|
514
549
|
: [{ expression: expr }];
|
|
515
550
|
extractAndProcessConditionals(args, true);
|
|
516
551
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/compiler",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.7",
|
|
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": "^10.0.
|
|
24
|
+
"@plumeria/utils": "^10.0.7"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@rust-gear/glob": "1.0.0",
|