@plumeria/unplugin 11.1.3 → 11.2.1

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/core.mjs CHANGED
@@ -254,6 +254,325 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
254
254
  const processedDecls = new Set();
255
255
  const idSpans = new Set();
256
256
  const excludedSpans = new Set();
257
+ const checkVariantAssignment = (decl) => {
258
+ const init = decl.init;
259
+ if (init && t.isCallExpression(init) && t.isIdentifier(init.callee)) {
260
+ const varName = init.callee.value;
261
+ if ((localCreateStyles[varName] &&
262
+ localCreateStyles[varName].type === 'variant') ||
263
+ mergedVariantsTable[varName]) {
264
+ throw new Error(`Plumeria: Assigning the return value of "css.variants" to a variable is not supported.\nPlease pass the variant function directly to "css.use". Found assignment to: ${t.isIdentifier(decl.id) ? decl.id.value : 'unknown'}`);
265
+ }
266
+ }
267
+ };
268
+ const registerStyle = (node, declSpan, isExported) => {
269
+ let propName;
270
+ const init = node.init;
271
+ if (t.isIdentifier(node.id) &&
272
+ init &&
273
+ t.isCallExpression(init) &&
274
+ init.arguments.length >= 1) {
275
+ const callee = init.callee;
276
+ if (t.isMemberExpression(callee) &&
277
+ t.isIdentifier(callee.object) &&
278
+ t.isIdentifier(callee.property)) {
279
+ const objectName = callee.object.value;
280
+ const propertyName = callee.property.value;
281
+ const alias = plumeriaAliases[objectName];
282
+ if (alias === 'NAMESPACE') {
283
+ propName = propertyName;
284
+ }
285
+ }
286
+ else if (t.isIdentifier(callee)) {
287
+ const calleeName = callee.value;
288
+ const originalName = plumeriaAliases[calleeName];
289
+ if (originalName) {
290
+ propName = originalName;
291
+ }
292
+ }
293
+ }
294
+ if (propName && init && t.isCallExpression(init)) {
295
+ if (propName === 'create' &&
296
+ t.isObjectExpression(init.arguments[0].expression)) {
297
+ const obj = objectExpressionToObject(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
298
+ if (obj) {
299
+ const hashMap = {};
300
+ Object.entries(obj).forEach(([key, style]) => {
301
+ if (typeof style !== 'object' || style === null)
302
+ return;
303
+ const records = getStyleRecords(style);
304
+ const atomMap = {};
305
+ records.forEach((r) => (atomMap[r.key] = r.hash));
306
+ hashMap[key] = atomMap;
307
+ });
308
+ const styleFunctions = {};
309
+ const objExpr = init.arguments[0].expression;
310
+ objExpr.properties.forEach((prop) => {
311
+ if (prop.type !== 'KeyValueProperty' ||
312
+ prop.key.type !== 'Identifier')
313
+ return;
314
+ const func = prop.value;
315
+ if (func.type !== 'ArrowFunctionExpression' &&
316
+ func.type !== 'FunctionExpression')
317
+ return;
318
+ const params = func.params.map((p) => {
319
+ if (t.isIdentifier(p))
320
+ return p.value;
321
+ if (typeof p === 'object' &&
322
+ p !== null &&
323
+ 'pat' in p &&
324
+ t.isIdentifier(p.pat))
325
+ return p.pat.value;
326
+ return 'arg';
327
+ });
328
+ let actualBody = func.body;
329
+ if (actualBody?.type === 'ParenthesisExpression')
330
+ actualBody = actualBody.expression;
331
+ if (actualBody?.type === 'BlockStatement') {
332
+ const first = actualBody.stmts?.[0];
333
+ if (first?.type === 'ReturnStatement')
334
+ actualBody = first.argument;
335
+ if (actualBody?.type === 'ParenthesisExpression')
336
+ actualBody = actualBody.expression;
337
+ }
338
+ if (actualBody && actualBody.type === 'ObjectExpression') {
339
+ styleFunctions[prop.key.value] = {
340
+ params,
341
+ body: actualBody,
342
+ };
343
+ }
344
+ });
345
+ if (t.isIdentifier(node.id)) {
346
+ idSpans.add(node.id.span.start);
347
+ }
348
+ if (t.isIdentifier(node.id)) {
349
+ localCreateStyles[node.id.value] = {
350
+ name: node.id.value,
351
+ type: 'create',
352
+ obj,
353
+ hashMap,
354
+ isExported,
355
+ initSpan: {
356
+ start: init.span.start - baseByteOffset,
357
+ end: init.span.end - baseByteOffset,
358
+ },
359
+ declSpan: {
360
+ start: declSpan.start - baseByteOffset,
361
+ end: declSpan.end - baseByteOffset,
362
+ },
363
+ functions: styleFunctions,
364
+ };
365
+ }
366
+ }
367
+ }
368
+ else if (propName === 'variants' &&
369
+ t.isObjectExpression(init.arguments[0].expression)) {
370
+ if (t.isIdentifier(node.id)) {
371
+ idSpans.add(node.id.span.start);
372
+ }
373
+ const obj = objectExpressionToObject(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable, (name) => {
374
+ if (localCreateStyles[name]) {
375
+ return localCreateStyles[name].obj;
376
+ }
377
+ if (mergedCreateTable[name]) {
378
+ const hash = mergedCreateTable[name];
379
+ if (scannedTables.createObjectTable[hash]) {
380
+ return scannedTables.createObjectTable[hash];
381
+ }
382
+ }
383
+ return undefined;
384
+ });
385
+ const { hashMap } = processVariants(obj);
386
+ if (t.isIdentifier(node.id)) {
387
+ localCreateStyles[node.id.value] = {
388
+ name: node.id.value,
389
+ type: 'variant',
390
+ obj,
391
+ hashMap,
392
+ isExported,
393
+ initSpan: {
394
+ start: init.span.start - baseByteOffset,
395
+ end: init.span.end - baseByteOffset,
396
+ },
397
+ declSpan: {
398
+ start: declSpan.start - baseByteOffset,
399
+ end: declSpan.end - baseByteOffset,
400
+ },
401
+ };
402
+ }
403
+ }
404
+ else if (propName === 'createTheme' &&
405
+ t.isObjectExpression(init.arguments[0].expression)) {
406
+ if (t.isIdentifier(node.id)) {
407
+ idSpans.add(node.id.span.start);
408
+ }
409
+ const obj = objectExpressionToObject(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
410
+ const hash = genBase36Hash(obj, 1, 8);
411
+ if (t.isIdentifier(node.id)) {
412
+ const uniqueKey = `${resourcePath}-${node.id.value}`;
413
+ scannedTables.createThemeHashTable[uniqueKey] = hash;
414
+ scannedTables.createThemeObjectTable[hash] = obj;
415
+ mergedCreateThemeHashTable[node.id.value] = hash;
416
+ const themeHashMap = {};
417
+ for (const [key] of Object.entries(obj)) {
418
+ const cssVarName = camelToKebabCase(key);
419
+ themeHashMap[key] = `var(--${hash}-${cssVarName})`;
420
+ }
421
+ localCreateStyles[node.id.value] = {
422
+ name: node.id.value,
423
+ type: 'constant',
424
+ obj,
425
+ hashMap: themeHashMap,
426
+ isExported,
427
+ initSpan: {
428
+ start: init.span.start - baseByteOffset,
429
+ end: init.span.end - baseByteOffset,
430
+ },
431
+ declSpan: {
432
+ start: declSpan.start - baseByteOffset,
433
+ end: declSpan.end - baseByteOffset,
434
+ },
435
+ };
436
+ }
437
+ }
438
+ }
439
+ };
440
+ traverse(ast, {
441
+ ImportDeclaration({ node }) {
442
+ if (node.source.value === '@plumeria/core') {
443
+ if (node.typeOnly)
444
+ return;
445
+ const typeOnlySpecs = node.specifiers.filter((s) => s.type === 'ImportSpecifier' && s.isTypeOnly);
446
+ if (typeOnlySpecs.length > 0) {
447
+ const names = typeOnlySpecs
448
+ .map((s) => {
449
+ if (s.type !== 'ImportSpecifier')
450
+ return;
451
+ const imported = s.imported
452
+ ? s.imported.value
453
+ : s.local.value;
454
+ const local = s.local.value;
455
+ return imported === local
456
+ ? imported
457
+ : `${imported} as ${local}`;
458
+ })
459
+ .join(', ');
460
+ replacements.push({
461
+ start: node.span.start - baseByteOffset,
462
+ end: node.span.end - baseByteOffset,
463
+ content: `import type { ${names} } from '@plumeria/core'`,
464
+ });
465
+ }
466
+ else {
467
+ replacements.push({
468
+ start: node.span.start - baseByteOffset,
469
+ end: node.span.end - baseByteOffset,
470
+ content: '',
471
+ });
472
+ }
473
+ }
474
+ node.specifiers.forEach((specifier) => {
475
+ if (specifier.local) {
476
+ excludedSpans.add(specifier.local.span.start);
477
+ }
478
+ if (specifier.type === 'ImportSpecifier' && specifier.imported) {
479
+ excludedSpans.add(specifier.imported.span.start);
480
+ }
481
+ });
482
+ },
483
+ ExportDeclaration({ node }) {
484
+ if (t.isVariableDeclaration(node.declaration)) {
485
+ processedDecls.add(node.declaration);
486
+ node.declaration.declarations.forEach((decl) => {
487
+ checkVariantAssignment(decl);
488
+ registerStyle(decl, node.span, true);
489
+ });
490
+ }
491
+ },
492
+ VariableDeclaration({ node }) {
493
+ if (processedDecls.has(node))
494
+ return;
495
+ node.declarations.forEach((decl) => {
496
+ checkVariantAssignment(decl);
497
+ registerStyle(decl, node.span, false);
498
+ });
499
+ },
500
+ CallExpression({ node }) {
501
+ const callee = node.callee;
502
+ let propName;
503
+ if (t.isMemberExpression(callee) &&
504
+ t.isIdentifier(callee.object) &&
505
+ t.isIdentifier(callee.property)) {
506
+ const objectName = callee.object.value;
507
+ const propertyName = callee.property.value;
508
+ const alias = plumeriaAliases[objectName];
509
+ if (alias === 'NAMESPACE') {
510
+ propName = propertyName;
511
+ }
512
+ }
513
+ else if (t.isIdentifier(callee)) {
514
+ const calleeName = callee.value;
515
+ const originalName = plumeriaAliases[calleeName];
516
+ if (originalName) {
517
+ propName = originalName;
518
+ }
519
+ }
520
+ if (propName) {
521
+ const args = node.arguments;
522
+ if (propName === 'keyframes') {
523
+ const expr = args[0].expression;
524
+ if (t.isObjectExpression(expr)) {
525
+ const obj = objectExpressionToObject(expr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
526
+ const hash = genBase36Hash(obj, 1, 8);
527
+ scannedTables.keyframesObjectTable[hash] = obj;
528
+ replacements.push({
529
+ start: node.span.start - baseByteOffset,
530
+ end: node.span.end - baseByteOffset,
531
+ content: JSON.stringify(`kf-${hash}`),
532
+ });
533
+ }
534
+ }
535
+ else if (propName === 'viewTransition' &&
536
+ args.length > 0 &&
537
+ t.isObjectExpression(args[0].expression)) {
538
+ const obj = objectExpressionToObject(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
539
+ const hash = genBase36Hash(obj, 1, 8);
540
+ scannedTables.viewTransitionObjectTable[hash] = obj;
541
+ replacements.push({
542
+ start: node.span.start - baseByteOffset,
543
+ end: node.span.end - baseByteOffset,
544
+ content: JSON.stringify(`vt-${hash}`),
545
+ });
546
+ }
547
+ else if ((propName === 'createTheme' || propName === 'createStatic') &&
548
+ args.length > 0 &&
549
+ t.isObjectExpression(args[0].expression)) {
550
+ const obj = objectExpressionToObject(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
551
+ const hash = genBase36Hash(obj, 1, 8);
552
+ if (propName === 'createTheme') {
553
+ scannedTables.createThemeObjectTable[hash] = obj;
554
+ }
555
+ else {
556
+ scannedTables.createStaticObjectTable[hash] = obj;
557
+ }
558
+ const prefix = propName === 'createTheme' ? 'tm-' : 'st-';
559
+ replacements.push({
560
+ start: node.span.start - baseByteOffset,
561
+ end: node.span.end - baseByteOffset,
562
+ content: JSON.stringify(`${prefix}${hash}`),
563
+ });
564
+ }
565
+ else if (propName === 'create' &&
566
+ args.length > 0 &&
567
+ t.isObjectExpression(args[0].expression)) {
568
+ const obj = objectExpressionToObject(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
569
+ const hash = genBase36Hash(obj, 1, 8);
570
+ scannedTables.createObjectTable[hash] = obj;
571
+ }
572
+ }
573
+ },
574
+ });
575
+ const jsxOpeningElementMap = new Map();
257
576
  const getSource = (node) => {
258
577
  const start = node.span.start - baseByteOffset;
259
578
  const end = node.span.end - baseByteOffset;
@@ -380,9 +699,9 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
380
699
  if (variantObj) {
381
700
  const callArgs = expr.arguments;
382
701
  if (callArgs.length === 1 && !callArgs[0].spread) {
383
- const innerArg = callArgs[0].expression;
384
- if (innerArg.type === 'ObjectExpression') {
385
- for (const prop of innerArg.properties) {
702
+ const arg = callArgs[0].expression;
703
+ if (arg.type === 'ObjectExpression') {
704
+ for (const prop of arg.properties) {
386
705
  let groupName;
387
706
  let valExpr;
388
707
  if (prop.type === 'KeyValueProperty' &&
@@ -423,16 +742,16 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
423
742
  }
424
743
  continue;
425
744
  }
426
- const argSource = getSource(innerArg);
427
- if (t.isStringLiteral(innerArg)) {
428
- if (variantObj[innerArg.value])
429
- baseStyle = deepMerge(baseStyle, variantObj[innerArg.value]);
745
+ const argSource = getSource(arg);
746
+ if (t.isStringLiteral(arg)) {
747
+ if (variantObj[arg.value])
748
+ baseStyle = deepMerge(baseStyle, variantObj[arg.value]);
430
749
  continue;
431
750
  }
432
751
  const currentGroupId = ++groupIdCounter;
433
752
  Object.entries(variantObj).forEach(([key, style]) => {
434
753
  conditionals.push({
435
- test: innerArg,
754
+ test: arg,
436
755
  testLHS: argSource,
437
756
  testString: `${argSource} === '${key}'`,
438
757
  truthy: style,
@@ -608,10 +927,12 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
608
927
  indepVarGroups[c.groupId].push(c);
609
928
  }
610
929
  });
611
- Object.values(indepVarGroups).forEach((opts) => {
612
- const commonTestExpr = opts[0].testLHS ?? opts[0].testString ?? getSource(opts[0].test);
930
+ Object.values(indepVarGroups).forEach((options) => {
931
+ const commonTestExpr = options[0].testLHS ??
932
+ options[0].testString ??
933
+ getSource(options[0].test);
613
934
  const lookupMap = {};
614
- opts.forEach((opt) => {
935
+ options.forEach((opt) => {
615
936
  if (opt.valueName && opt.truthy) {
616
937
  const className = processStyleRecords(opt.truthy)
617
938
  .map((r) => r.hash)
@@ -694,193 +1015,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
694
1015
  classParts.push(...dynamicClassParts);
695
1016
  return { classParts, isOptimizable, baseStyle };
696
1017
  };
697
- const registerStyle = (node, declSpan, isExported) => {
698
- let propName;
699
- const init = node.init;
700
- if (t.isIdentifier(node.id) &&
701
- init &&
702
- t.isCallExpression(init) &&
703
- init.arguments.length >= 1) {
704
- const callee = init.callee;
705
- if (t.isMemberExpression(callee) &&
706
- t.isIdentifier(callee.object) &&
707
- t.isIdentifier(callee.property)) {
708
- const objectName = callee.object.value;
709
- const propertyName = callee.property.value;
710
- const alias = plumeriaAliases[objectName];
711
- if (alias === 'NAMESPACE')
712
- propName = propertyName;
713
- }
714
- else if (t.isIdentifier(callee)) {
715
- const calleeName = callee.value;
716
- const originalName = plumeriaAliases[calleeName];
717
- if (originalName)
718
- propName = originalName;
719
- }
720
- }
721
- if (propName && init && t.isCallExpression(init)) {
722
- if (propName === 'create' &&
723
- t.isObjectExpression(init.arguments[0].expression)) {
724
- const obj = objectExpressionToObject(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
725
- if (obj) {
726
- const hashMap = {};
727
- Object.entries(obj).forEach(([key, style]) => {
728
- if (typeof style !== 'object' || style === null)
729
- return;
730
- const records = getStyleRecords(style);
731
- const atomMap = {};
732
- records.forEach((r) => (atomMap[r.key] = r.hash));
733
- hashMap[key] = atomMap;
734
- });
735
- const styleFunctions = {};
736
- const objExpr = init.arguments[0].expression;
737
- objExpr.properties.forEach((prop) => {
738
- if (prop.type !== 'KeyValueProperty' ||
739
- prop.key.type !== 'Identifier')
740
- return;
741
- const func = prop.value;
742
- if (func.type !== 'ArrowFunctionExpression' &&
743
- func.type !== 'FunctionExpression')
744
- return;
745
- const params = func.params.map((p) => {
746
- if (t.isIdentifier(p))
747
- return p.value;
748
- if (typeof p === 'object' &&
749
- p !== null &&
750
- 'pat' in p &&
751
- t.isIdentifier(p.pat))
752
- return p.pat.value;
753
- return 'arg';
754
- });
755
- let actualBody = func.body;
756
- if (actualBody?.type === 'ParenthesisExpression')
757
- actualBody = actualBody.expression;
758
- if (actualBody?.type === 'BlockStatement') {
759
- const first = actualBody.stmts?.[0];
760
- if (first?.type === 'ReturnStatement')
761
- actualBody = first.argument;
762
- if (actualBody?.type === 'ParenthesisExpression')
763
- actualBody = actualBody.expression;
764
- }
765
- if (actualBody && actualBody.type === 'ObjectExpression') {
766
- styleFunctions[prop.key.value] = {
767
- params,
768
- body: actualBody,
769
- };
770
- }
771
- });
772
- if (t.isIdentifier(node.id)) {
773
- idSpans.add(node.id.span.start);
774
- localCreateStyles[node.id.value] = {
775
- name: node.id.value,
776
- type: 'create',
777
- obj,
778
- hashMap,
779
- isExported,
780
- initSpan: {
781
- start: init.span.start - baseByteOffset,
782
- end: init.span.end - baseByteOffset,
783
- },
784
- declSpan: {
785
- start: declSpan.start - baseByteOffset,
786
- end: declSpan.end - baseByteOffset,
787
- },
788
- functions: styleFunctions,
789
- };
790
- }
791
- }
792
- }
793
- else if (propName === 'variants' &&
794
- t.isObjectExpression(init.arguments[0].expression)) {
795
- if (t.isIdentifier(node.id))
796
- idSpans.add(node.id.span.start);
797
- const obj = objectExpressionToObject(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable, (name) => {
798
- if (localCreateStyles[name])
799
- return localCreateStyles[name].obj;
800
- if (mergedCreateTable[name]) {
801
- const hash = mergedCreateTable[name];
802
- if (scannedTables.createObjectTable[hash])
803
- return scannedTables.createObjectTable[hash];
804
- }
805
- return undefined;
806
- });
807
- const { hashMap } = processVariants(obj);
808
- if (t.isIdentifier(node.id)) {
809
- localCreateStyles[node.id.value] = {
810
- name: node.id.value,
811
- type: 'variant',
812
- obj,
813
- hashMap,
814
- isExported,
815
- initSpan: {
816
- start: init.span.start - baseByteOffset,
817
- end: init.span.end - baseByteOffset,
818
- },
819
- declSpan: {
820
- start: declSpan.start - baseByteOffset,
821
- end: declSpan.end - baseByteOffset,
822
- },
823
- };
824
- }
825
- }
826
- else if (propName === 'createTheme' &&
827
- t.isObjectExpression(init.arguments[0].expression)) {
828
- if (t.isIdentifier(node.id))
829
- idSpans.add(node.id.span.start);
830
- const obj = objectExpressionToObject(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
831
- const hash = genBase36Hash(obj, 1, 8);
832
- if (t.isIdentifier(node.id)) {
833
- const uniqueKey = `${resourcePath}-${node.id.value}`;
834
- scannedTables.createThemeHashTable[uniqueKey] = hash;
835
- scannedTables.createThemeObjectTable[hash] = obj;
836
- mergedCreateThemeHashTable[node.id.value] = hash;
837
- const themeHashMap = {};
838
- for (const [key] of Object.entries(obj)) {
839
- const cssVarName = camelToKebabCase(key);
840
- themeHashMap[key] = `var(--${hash}-${cssVarName})`;
841
- }
842
- localCreateStyles[node.id.value] = {
843
- name: node.id.value,
844
- type: 'constant',
845
- obj,
846
- hashMap: themeHashMap,
847
- isExported,
848
- initSpan: {
849
- start: init.span.start - baseByteOffset,
850
- end: init.span.end - baseByteOffset,
851
- },
852
- declSpan: {
853
- start: declSpan.start - baseByteOffset,
854
- end: declSpan.end - baseByteOffset,
855
- },
856
- };
857
- }
858
- }
859
- }
860
- };
861
- const jsxOpeningElementMap = new Map();
862
1018
  traverse(ast, {
863
- ImportDeclaration({ node }) {
864
- if (node.specifiers) {
865
- node.specifiers.forEach((specifier) => {
866
- if (specifier.local)
867
- excludedSpans.add(specifier.local.span.start);
868
- if (specifier.type === 'ImportSpecifier' && specifier.imported)
869
- excludedSpans.add(specifier.imported.span.start);
870
- });
871
- }
872
- },
873
- ExportDeclaration({ node }) {
874
- if (t.isVariableDeclaration(node.declaration)) {
875
- processedDecls.add(node.declaration);
876
- node.declaration.declarations.forEach((decl) => registerStyle(decl, node.span, true));
877
- }
878
- },
879
- VariableDeclaration({ node }) {
880
- if (processedDecls.has(node))
881
- return;
882
- node.declarations.forEach((decl) => registerStyle(decl, node.span, false));
883
- },
884
1019
  JSXOpeningElement({ node }) {
885
1020
  jsxOpeningElementMap.set(node.span.start, node.attributes);
886
1021
  },
@@ -890,42 +1025,49 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
890
1025
  const propName = node.property.value;
891
1026
  const uniqueKey = `${resourcePath}-${varName}`;
892
1027
  let hash = scannedTables.createHashTable[uniqueKey];
893
- if (!hash)
1028
+ if (!hash) {
894
1029
  hash = mergedCreateTable[varName];
1030
+ }
895
1031
  if (hash) {
896
1032
  let atomMap;
897
- if (scannedTables.createAtomicMapTable[hash])
1033
+ if (scannedTables.createAtomicMapTable[hash]) {
898
1034
  atomMap = scannedTables.createAtomicMapTable[hash][propName];
899
- if (atomMap)
1035
+ }
1036
+ if (atomMap) {
900
1037
  replacements.push({
901
1038
  start: node.span.start - baseByteOffset,
902
1039
  end: node.span.end - baseByteOffset,
903
1040
  content: `(${JSON.stringify(atomMap)})`,
904
1041
  });
1042
+ }
905
1043
  }
906
1044
  let themeHash = scannedTables.createThemeHashTable[uniqueKey];
907
- if (!themeHash)
1045
+ if (!themeHash) {
908
1046
  themeHash = mergedCreateThemeHashTable[varName];
1047
+ }
909
1048
  if (themeHash) {
910
1049
  const atomicMap = scannedTables.createAtomicMapTable[themeHash];
911
- if (atomicMap && atomicMap[propName])
1050
+ if (atomicMap && atomicMap && atomicMap[propName]) {
912
1051
  replacements.push({
913
1052
  start: node.span.start - baseByteOffset,
914
1053
  end: node.span.end - baseByteOffset,
915
1054
  content: `(${JSON.stringify(atomicMap[propName])})`,
916
1055
  });
1056
+ }
917
1057
  }
918
1058
  let staticHash = scannedTables.createStaticHashTable[uniqueKey];
919
- if (!staticHash)
1059
+ if (!staticHash) {
920
1060
  staticHash = mergedCreateStaticHashTable[varName];
1061
+ }
921
1062
  if (staticHash) {
922
1063
  const staticObj = scannedTables.createStaticObjectTable[staticHash];
923
- if (staticObj && staticObj[propName] !== undefined)
1064
+ if (staticObj && staticObj[propName] !== undefined) {
924
1065
  replacements.push({
925
1066
  start: node.span.start - baseByteOffset,
926
1067
  end: node.span.end - baseByteOffset,
927
1068
  content: `(${JSON.stringify(staticObj[propName])})`,
928
1069
  });
1070
+ }
929
1071
  }
930
1072
  }
931
1073
  },
@@ -946,16 +1088,18 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
946
1088
  const varName = node.value;
947
1089
  const uniqueKey = `${resourcePath}-${varName}`;
948
1090
  let hash = scannedTables.createHashTable[uniqueKey];
949
- if (!hash)
1091
+ if (!hash) {
950
1092
  hash = mergedCreateTable[varName];
1093
+ }
951
1094
  if (hash) {
952
1095
  const obj = scannedTables.createObjectTable[hash];
953
1096
  const atomicMap = scannedTables.createAtomicMapTable[hash];
954
1097
  if (obj && atomicMap) {
955
1098
  const hashMap = {};
956
1099
  Object.keys(obj).forEach((key) => {
957
- if (atomicMap[key])
1100
+ if (atomicMap[key]) {
958
1101
  hashMap[key] = atomicMap[key];
1102
+ }
959
1103
  });
960
1104
  replacements.push({
961
1105
  start: node.span.start - baseByteOffset,
@@ -965,29 +1109,33 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
965
1109
  }
966
1110
  }
967
1111
  let themeHash = scannedTables.createThemeHashTable[uniqueKey];
968
- if (!themeHash)
1112
+ if (!themeHash) {
969
1113
  themeHash = mergedCreateThemeHashTable[varName];
1114
+ }
970
1115
  if (themeHash) {
971
1116
  const atomicMap = scannedTables.createAtomicMapTable[themeHash];
972
- if (atomicMap)
1117
+ if (atomicMap) {
973
1118
  replacements.push({
974
1119
  start: node.span.start - baseByteOffset,
975
1120
  end: node.span.end - baseByteOffset,
976
1121
  content: `(${JSON.stringify(atomicMap)})`,
977
1122
  });
978
- return;
1123
+ return;
1124
+ }
979
1125
  }
980
1126
  let staticHash = scannedTables.createStaticHashTable[uniqueKey];
981
- if (!staticHash)
1127
+ if (!staticHash) {
982
1128
  staticHash = mergedCreateStaticHashTable[varName];
1129
+ }
983
1130
  if (staticHash) {
984
1131
  const staticObj = scannedTables.createStaticObjectTable[staticHash];
985
- if (staticObj)
1132
+ if (staticObj) {
986
1133
  replacements.push({
987
1134
  start: node.span.start - baseByteOffset,
988
1135
  end: node.span.end - baseByteOffset,
989
1136
  content: `(${JSON.stringify(staticObj)})`,
990
1137
  });
1138
+ }
991
1139
  }
992
1140
  },
993
1141
  JSXAttribute({ node }) {
@@ -1050,11 +1198,10 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
1050
1198
  }
1051
1199
  }
1052
1200
  args = args.filter((arg) => {
1053
- const innerExpr = arg.expression;
1054
- if (!t.isCallExpression(innerExpr) ||
1055
- !t.isMemberExpression(innerExpr.callee))
1201
+ const expr = arg.expression;
1202
+ if (!t.isCallExpression(expr) || !t.isMemberExpression(expr.callee))
1056
1203
  return true;
1057
- const callee = innerExpr.callee;
1204
+ const callee = expr.callee;
1058
1205
  if (!t.isIdentifier(callee.object) ||
1059
1206
  !t.isIdentifier(callee.property))
1060
1207
  return true;
@@ -1063,7 +1210,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
1063
1210
  const styleInfo = localCreateStyles[varName];
1064
1211
  if (styleInfo?.functions?.[propKey]) {
1065
1212
  const func = styleInfo.functions[propKey];
1066
- const callArgs = innerExpr.arguments;
1213
+ const callArgs = expr.arguments;
1067
1214
  const hasSpread = callArgs.some((a) => a.spread);
1068
1215
  if (!hasSpread && callArgs.length >= 1) {
1069
1216
  const tempStaticTable = { ...mergedStaticTable };
@@ -1164,32 +1311,33 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
1164
1311
  const objectName = callee.object.value;
1165
1312
  const propertyName = callee.property.value;
1166
1313
  const alias = plumeriaAliases[objectName];
1167
- if (alias === 'NAMESPACE' && propertyName === 'use')
1314
+ if (alias === 'NAMESPACE' && propertyName === 'use') {
1168
1315
  isUseCall = true;
1316
+ }
1169
1317
  }
1170
1318
  else if (t.isIdentifier(callee)) {
1171
1319
  const calleeName = callee.value;
1172
1320
  const originalName = plumeriaAliases[calleeName];
1173
- if (originalName === 'use')
1321
+ if (originalName === 'use') {
1174
1322
  isUseCall = true;
1323
+ }
1175
1324
  }
1176
1325
  if (!isUseCall)
1177
1326
  return;
1178
1327
  const args = node.arguments;
1179
1328
  for (const arg of args) {
1180
- const innerExpr = arg.expression;
1181
- if (!t.isCallExpression(innerExpr) ||
1182
- !t.isMemberExpression(innerExpr.callee))
1329
+ const expr = arg.expression;
1330
+ if (!t.isCallExpression(expr) || !t.isMemberExpression(expr.callee))
1183
1331
  continue;
1184
- const innerCallee = innerExpr.callee;
1185
- if (!t.isIdentifier(innerCallee.object) ||
1186
- !t.isIdentifier(innerCallee.property))
1332
+ const callee = expr.callee;
1333
+ if (!t.isIdentifier(callee.object) ||
1334
+ !t.isIdentifier(callee.property))
1187
1335
  continue;
1188
- const varName = innerCallee.object.value;
1189
- const propKey = innerCallee.property.value;
1336
+ const varName = callee.object.value;
1337
+ const propKey = callee.property.value;
1190
1338
  const styleInfo = localCreateStyles[varName];
1191
1339
  if (styleInfo?.functions?.[propKey]) {
1192
- throw new Error(`Plumeria: css.use(${getSource(innerExpr)}) does not support dynamic function keys.\n`);
1340
+ throw new Error(`Plumeria: css.use(${getSource(expr)}) does not support dynamic function keys.\n`);
1193
1341
  }
1194
1342
  }
1195
1343
  const { classParts, isOptimizable, baseStyle } = buildClassParts(args);
@@ -1205,8 +1353,9 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
1205
1353
  },
1206
1354
  });
1207
1355
  Object.values(localCreateStyles).forEach((info) => {
1208
- if (info.type === 'constant')
1356
+ if (info.type === 'constant') {
1209
1357
  return;
1358
+ }
1210
1359
  if (info.isExported) {
1211
1360
  replacements.push({
1212
1361
  start: info.declSpan.start,
@@ -1222,7 +1371,6 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
1222
1371
  });
1223
1372
  }
1224
1373
  });
1225
- const optInCSS = await optimizer(extractedSheets.join(''));
1226
1374
  const buffer = Buffer.from(source);
1227
1375
  let offset = 0;
1228
1376
  const parts = [];
@@ -1237,6 +1385,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
1237
1385
  });
1238
1386
  parts.push(buffer.subarray(offset));
1239
1387
  const transformedSource = Buffer.concat(parts).toString();
1388
+ const optInCSS = await optimizer(extractedSheets.join(''));
1240
1389
  if (extractedSheets.length > 0) {
1241
1390
  const baseId = id.replace(EXTENSION_PATTERN, '');
1242
1391
  const cssFilename = `${baseId}.zero.css`;