@plumeria/turbopack-loader 18.1.1 → 18.1.3

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 +36 -12
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -822,15 +822,15 @@ async function loader(source) {
822
822
  const obj = resolveCreateObject(varName);
823
823
  return obj ? { varName, keyExpr: node.property.expression, obj } : null;
824
824
  };
825
- const buildDecision = (node, prefix, off, counter) => {
825
+ const buildDecision = (node, prefix, off, counter, scoped) => {
826
826
  if (node.type === 'ParenthesisExpression') {
827
- return buildDecision(node.expression, prefix, off, counter);
827
+ return buildDecision(node.expression, prefix, off, counter, scoped);
828
828
  }
829
829
  if (node.type === 'ConditionalExpression') {
830
- const a = buildDecision(node.consequent, prefix, off, counter);
830
+ const a = buildDecision(node.consequent, prefix, off, counter, scoped);
831
831
  if (!a)
832
832
  return null;
833
- const b = buildDecision(node.alternate, prefix, off, counter);
833
+ const b = buildDecision(node.alternate, prefix, off, counter, scoped);
834
834
  if (!b)
835
835
  return null;
836
836
  return {
@@ -841,7 +841,7 @@ async function loader(source) {
841
841
  };
842
842
  }
843
843
  if (node.type === 'BinaryExpression' && node.operator === '&&') {
844
- const right = buildDecision(node.right, prefix, off, counter);
844
+ const right = buildDecision(node.right, prefix, off, counter, scoped);
845
845
  if (!right)
846
846
  return null;
847
847
  return {
@@ -853,10 +853,14 @@ async function loader(source) {
853
853
  }
854
854
  const group = resolveBracketGroup(node);
855
855
  if (group) {
856
+ const tag = scoped ? `${counter.n++}:` : '';
857
+ const keySource = getSource(group.keyExpr);
856
858
  return {
857
- keyExpr: getSource(group.keyExpr),
859
+ keyExpr: tag
860
+ ? `(${JSON.stringify(tag)} + ${keySource})`
861
+ : keySource,
858
862
  options: Object.entries(group.obj).map(([value, style]) => ({
859
- value,
863
+ value: `${tag}${value}`,
860
864
  style: style,
861
865
  })),
862
866
  leaves: 1,
@@ -888,17 +892,23 @@ async function loader(source) {
888
892
  else {
889
893
  const group = resolveBracketGroup(node);
890
894
  if (group)
891
- Object.keys(group.obj).forEach((k) => acc.add(k));
895
+ Object.entries(group.obj).forEach(([key, style]) => {
896
+ let styles = acc.get(key);
897
+ if (!styles)
898
+ acc.set(key, (styles = new Set()));
899
+ styles.add(style);
900
+ });
892
901
  }
893
902
  };
894
903
  const resolveDecision = (node) => {
895
- const groupKeys = new Set();
904
+ const groupKeys = new Map();
896
905
  collectGroupKeys(node, groupKeys);
897
906
  let prefix = '#';
898
- while ([...groupKeys].some((k) => k.startsWith(prefix)))
907
+ while ([...groupKeys.keys()].some((k) => k.startsWith(prefix)))
899
908
  prefix += '#';
900
- const off = groupKeys.has('') ? `${prefix}off` : '';
901
- return buildDecision(node, prefix, off, { n: 0 });
909
+ const scoped = [...groupKeys.values()].some((styles) => styles.size > 1);
910
+ const off = !scoped && groupKeys.has('') ? `${prefix}off` : '';
911
+ return buildDecision(node, prefix, off, { n: 0 }, scoped);
902
912
  };
903
913
  const collectConditions = (node, currentTestStrings = []) => {
904
914
  const staticStyle = resolveStyleObject(node);
@@ -1174,6 +1184,7 @@ async function loader(source) {
1174
1184
  groupName: undefined,
1175
1185
  valueName: optionName,
1176
1186
  varName,
1187
+ ownKeys: true,
1177
1188
  });
1178
1189
  });
1179
1190
  continue;
@@ -1194,6 +1205,7 @@ async function loader(source) {
1194
1205
  groupName: undefined,
1195
1206
  valueName: value,
1196
1207
  varName: undefined,
1208
+ ownKeys: true,
1197
1209
  }));
1198
1210
  continue;
1199
1211
  }
@@ -1407,11 +1419,23 @@ async function loader(source) {
1407
1419
  style: opt.truthy,
1408
1420
  label: opt.valueName || 'default',
1409
1421
  })),
1422
+ ownKeys: opts[0].ownKeys,
1410
1423
  },
1411
1424
  });
1412
1425
  });
1413
1426
  ordered.sort((a, b) => a.order - b.order);
1414
1427
  const dimensions = ordered.map((o) => o.dimension);
1428
+ const joined = dimensions.filter((dim) => dim.type !== 'const').length > 1;
1429
+ dimensions.forEach((dim) => {
1430
+ if (!joined || dim.type !== 'var' || !dim.ownKeys)
1431
+ return;
1432
+ const numbers = {};
1433
+ dim.options.forEach((opt, index) => {
1434
+ numbers[String(opt.value)] = String(index);
1435
+ opt.value = String(index);
1436
+ });
1437
+ dim.testExpr = `(${JSON.stringify(numbers)}[${dim.testExpr}] || "")`;
1438
+ });
1415
1439
  const results = {};
1416
1440
  const recurse = (dimIndex, currentStyle, keyParts) => {
1417
1441
  if (dimIndex >= dimensions.length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/turbopack-loader",
3
- "version": "18.1.1",
3
+ "version": "18.1.3",
4
4
  "description": "Plumeria Turbopack-loader",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",
@@ -22,11 +22,11 @@
22
22
  "zero-virtual.css"
23
23
  ],
24
24
  "dependencies": {
25
- "@plumeria/compiler": "^18.1.1",
26
- "@plumeria/utils": "^18.1.1"
25
+ "@plumeria/compiler": "^18.1.3",
26
+ "@plumeria/utils": "^18.1.3"
27
27
  },
28
28
  "devDependencies": {
29
- "@swc/core": "1.15.43",
29
+ "@swc/core": "1.15.47",
30
30
  "zss-engine": "2.3.2"
31
31
  },
32
32
  "publishConfig": {