@plumeria/compiler 6.0.0 → 6.0.2

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 +50 -10
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -214,6 +214,9 @@ function compileCSS(options) {
214
214
  results.push(...extractStylesFromExpression(expr.left));
215
215
  results.push(...extractStylesFromExpression(expr.right));
216
216
  }
217
+ else if (expr.type === 'ParenthesisExpression') {
218
+ results.push(...extractStylesFromExpression(expr.expression));
219
+ }
217
220
  return results;
218
221
  };
219
222
  const processStyle = (style) => {
@@ -307,6 +310,25 @@ function compileCSS(options) {
307
310
  break;
308
311
  }
309
312
  }
313
+ if (utils_1.t.isBinaryExpression(expr) && expr.operator === '&&') {
314
+ const truthyStyle = resolveStyleObject(expr.right);
315
+ if (truthyStyle !== null) {
316
+ conditionals.push({
317
+ test: expr.left,
318
+ truthy: truthyStyle,
319
+ falsy: {},
320
+ });
321
+ continue;
322
+ }
323
+ }
324
+ else if (expr.type === 'ParenthesisExpression') {
325
+ const inner = expr.expression;
326
+ const innerStatic = resolveStyleObject(inner);
327
+ if (innerStatic) {
328
+ baseStyle = (0, utils_1.deepMerge)(baseStyle, innerStatic);
329
+ continue;
330
+ }
331
+ }
310
332
  const staticStyle = resolveStyleObject(expr);
311
333
  if (staticStyle) {
312
334
  baseStyle = (0, utils_1.deepMerge)(baseStyle, staticStyle);
@@ -330,20 +352,38 @@ function compileCSS(options) {
330
352
  continue;
331
353
  }
332
354
  }
333
- if (Object.keys(baseStyle).length > 0) {
355
+ if (Object.keys(baseStyle).length > 0 &&
356
+ conditionals.length === 0) {
334
357
  processStyle(baseStyle);
335
358
  }
336
- if (conditionals.length > 0) {
337
- const allStyles = [];
338
- conditionals.forEach((cond) => {
339
- if (Object.keys(cond.truthy).length > 0) {
340
- allStyles.push(cond.truthy);
359
+ else if (conditionals.length > 0) {
360
+ const combinations = 1 << conditionals.length;
361
+ for (let i = 0; i < combinations; i++) {
362
+ let currentStyle = { ...baseStyle };
363
+ const seenGroups = new Set();
364
+ let impossible = false;
365
+ for (let j = 0; j < conditionals.length; j++) {
366
+ if ((i >> j) & 1) {
367
+ if (conditionals[j].groupId !== undefined) {
368
+ if (seenGroups.has(conditionals[j].groupId)) {
369
+ impossible = true;
370
+ break;
371
+ }
372
+ seenGroups.add(conditionals[j].groupId);
373
+ }
374
+ currentStyle = (0, utils_1.deepMerge)(currentStyle, conditionals[j].truthy);
375
+ }
376
+ else {
377
+ currentStyle = (0, utils_1.deepMerge)(currentStyle, conditionals[j].falsy);
378
+ }
341
379
  }
342
- if (Object.keys(cond.falsy).length > 0) {
343
- allStyles.push(cond.falsy);
380
+ if (impossible) {
381
+ continue;
344
382
  }
345
- });
346
- allStyles.forEach(processStyle);
383
+ if (Object.keys(currentStyle).length > 0) {
384
+ processStyle(currentStyle);
385
+ }
386
+ }
347
387
  }
348
388
  }
349
389
  else if (callee.property.value === 'keyframes' &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/compiler",
3
- "version": "6.0.0",
3
+ "version": "6.0.2",
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": "^6.0.0"
24
+ "@plumeria/utils": "^6.0.2"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@swc/core": "1.15.8",