@plumeria/compiler 16.4.1 → 16.5.0

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 +12 -89
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -370,7 +370,6 @@ function compileCSS(options) {
370
370
  }
371
371
  });
372
372
  const conditionals = [];
373
- let groupIdCounter = 0;
374
373
  let baseStyle = {};
375
374
  const resolveStyleObject = (expr) => {
376
375
  if (utils_1.t.isObjectExpression(expr)) {
@@ -378,9 +377,18 @@ function compileCSS(options) {
378
377
  }
379
378
  else if (utils_1.t.isMemberExpression(expr) &&
380
379
  utils_1.t.isIdentifier(expr.object) &&
381
- utils_1.t.isIdentifier(expr.property)) {
380
+ (utils_1.t.isIdentifier(expr.property) || expr.property.type === 'Computed')) {
382
381
  const varName = expr.object.value;
383
- const propName = expr.property.value;
382
+ let propName;
383
+ if (expr.property.type === 'Computed') {
384
+ const keyExpr = expr.property.expression;
385
+ if (!utils_1.t.isStringLiteral(keyExpr))
386
+ return null;
387
+ propName = keyExpr.value;
388
+ }
389
+ else {
390
+ propName = expr.property.value;
391
+ }
384
392
  const styleInfo = ctx.localCreateStyles[varName];
385
393
  if (styleInfo && styleInfo.type === 'create') {
386
394
  const style = styleInfo.obj[propName];
@@ -562,81 +570,7 @@ function compileCSS(options) {
562
570
  }
563
571
  }
564
572
  if (utils_1.t.isCallExpression(expr)) {
565
- if (utils_1.t.isIdentifier(expr.callee)) {
566
- const varName = expr.callee.value;
567
- const styleInfo = ctx.localCreateStyles[varName];
568
- if (styleInfo && styleInfo.type === 'variant') {
569
- const variantObj = styleInfo.obj;
570
- const callArgs = expr.arguments;
571
- if (callArgs.length === 1 && !callArgs[0].spread) {
572
- const argExpr = callArgs[0].expression;
573
- if (argExpr.type === 'ObjectExpression') {
574
- for (const prop of argExpr.properties) {
575
- let groupName;
576
- let valExpr;
577
- if (prop.type === 'KeyValueProperty' &&
578
- prop.key.type === 'Identifier') {
579
- groupName = prop.key.value;
580
- valExpr = prop.value;
581
- }
582
- else if (prop.type === 'Identifier') {
583
- groupName = prop.value;
584
- valExpr = prop;
585
- }
586
- if (groupName && valExpr) {
587
- const groupVariants = variantObj[groupName];
588
- if (!groupVariants)
589
- continue;
590
- const currentGroupId = ++groupIdCounter;
591
- const valSource = getSource(valExpr);
592
- if (valExpr.type === 'StringLiteral') {
593
- const groupVariantsAsObj = groupVariants;
594
- if (groupVariantsAsObj[valExpr.value])
595
- baseStyle = (0, utils_1.deepMerge)(baseStyle, groupVariantsAsObj[valExpr.value]);
596
- continue;
597
- }
598
- Object.entries(groupVariants).forEach(([optionName, style]) => {
599
- conditionals.push({
600
- test: valExpr,
601
- testLHS: valSource,
602
- testString: `${valSource} === '${optionName}'`,
603
- truthy: style,
604
- falsy: {},
605
- groupId: currentGroupId,
606
- groupName,
607
- valueName: optionName,
608
- varName,
609
- });
610
- });
611
- }
612
- }
613
- continue;
614
- }
615
- const argSource = getSource(argExpr);
616
- if (utils_1.t.isStringLiteral(argExpr)) {
617
- if (variantObj[argExpr.value])
618
- baseStyle = (0, utils_1.deepMerge)(baseStyle, variantObj[argExpr.value]);
619
- continue;
620
- }
621
- const currentGroupId = ++groupIdCounter;
622
- Object.entries(variantObj).forEach(([key, style]) => {
623
- conditionals.push({
624
- test: argExpr,
625
- testLHS: argSource,
626
- testString: `${argSource} === '${key}'`,
627
- truthy: style,
628
- falsy: {},
629
- groupId: currentGroupId,
630
- groupName: undefined,
631
- valueName: key,
632
- varName,
633
- });
634
- });
635
- continue;
636
- }
637
- }
638
- }
639
- else if (utils_1.t.isMemberExpression(expr.callee)) {
573
+ if (utils_1.t.isMemberExpression(expr.callee)) {
640
574
  const callee = expr.callee;
641
575
  if (utils_1.t.isIdentifier(callee.object) &&
642
576
  utils_1.t.isIdentifier(callee.property)) {
@@ -840,17 +774,6 @@ function compileCSS(options) {
840
774
  };
841
775
  }
842
776
  }
843
- else if (pName === 'variants') {
844
- 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);
845
- if (obj) {
846
- const { hashMap } = (0, utils_1.processVariants)(obj);
847
- ctx.localCreateStyles[node.id.value] = {
848
- type: 'variant',
849
- obj,
850
- hashMap,
851
- };
852
- }
853
- }
854
777
  else if (pName === 'createTheme') {
855
778
  let selector = '';
856
779
  const selectorExpr = init.arguments[0].expression;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/compiler",
3
- "version": "16.4.1",
3
+ "version": "16.5.0",
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": "^16.4.1"
24
+ "@plumeria/utils": "^16.5.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@rust-gear/glob": "1.1.0",