@plumeria/turbopack-loader 13.1.5 → 13.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.
Files changed (2) hide show
  1. package/dist/index.js +30 -15
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -49,10 +49,10 @@ function cleanStaleThemeRules(currentCss, optInCss) {
49
49
  }
50
50
  let cleanedCss = currentCss;
51
51
  for (const hash of hashes) {
52
- const propRegex = new RegExp(`--${hash}-[a-zA-Z0-9-]+:[^;}]+(?:;|(?=\\}))`, 'g');
52
+ const propRegex = new RegExp(`--${hash}-[a-zA-Z0-9-]+:[^}]*?(?:;|(?=\\}))`, 'g');
53
53
  cleanedCss = cleanedCss.replace(propRegex, '');
54
54
  }
55
- const emptyBlockRegex = /(?<=^|[}])[^{}]*\{\s*\}/g;
55
+ const emptyBlockRegex = /(?<=^|[}{])[^{}]*\{\s*\}/g;
56
56
  let prevCss;
57
57
  do {
58
58
  prevCss = cleanedCss;
@@ -955,7 +955,7 @@ async function loader(source) {
955
955
  });
956
956
  const classParts = [];
957
957
  if (existingClass)
958
- classParts.push(JSON.stringify(existingClass));
958
+ classParts.push(existingClass);
959
959
  if (Object.keys(baseIndependent).length > 0) {
960
960
  const className = processStyleRecords(baseIndependent)
961
961
  .map((r) => r.hash)
@@ -1250,18 +1250,30 @@ async function loader(source) {
1250
1250
  const classNameAttr = attributes.find((attr) => attr.type === 'JSXAttribute' &&
1251
1251
  attr.name.type === 'Identifier' &&
1252
1252
  attr.name.value === 'className');
1253
- let existingClass = '';
1254
- if (classNameAttr?.value?.type === 'StringLiteral') {
1255
- existingClass = classNameAttr.value.value;
1253
+ let existingClassExpr = '';
1254
+ if (classNameAttr) {
1256
1255
  replacements.push({
1257
1256
  start: classNameAttr.span.start - baseByteOffset,
1258
1257
  end: classNameAttr.span.end - baseByteOffset,
1259
1258
  content: '',
1260
1259
  });
1260
+ if (classNameAttr.value?.type === 'StringLiteral') {
1261
+ existingClassExpr = JSON.stringify(classNameAttr.value.value);
1262
+ }
1263
+ else if (classNameAttr.value?.type === 'JSXExpressionContainer') {
1264
+ const start = classNameAttr.value.expression.span.start -
1265
+ baseByteOffset;
1266
+ const end = classNameAttr.value.expression.span.end -
1267
+ baseByteOffset;
1268
+ existingClassExpr = sourceBuffer
1269
+ .subarray(start, end)
1270
+ .toString('utf-8');
1271
+ }
1261
1272
  }
1262
1273
  const styleAttrExisting = attributes.find((attr) => attr.type === 'JSXAttribute' &&
1263
1274
  attr.name.type === 'Identifier' &&
1264
1275
  attr.name.value === 'style');
1276
+ let existingStyleExpr = '';
1265
1277
  if (styleAttrExisting) {
1266
1278
  replacements.push({
1267
1279
  start: styleAttrExisting.span.start - baseByteOffset,
@@ -1270,16 +1282,19 @@ async function loader(source) {
1270
1282
  });
1271
1283
  if (styleAttrExisting.value?.type === 'JSXExpressionContainer') {
1272
1284
  const innerExpr = styleAttrExisting.value?.expression;
1273
- if (innerExpr?.type === 'ObjectExpression') {
1274
- const start = innerExpr.span.start - baseByteOffset;
1275
- const end = innerExpr.span.end - baseByteOffset;
1276
- const innerSource = sourceBuffer
1277
- .subarray(start, end)
1278
- .toString('utf-8');
1285
+ const start = innerExpr.span.start - baseByteOffset;
1286
+ const end = innerExpr.span.end - baseByteOffset;
1287
+ const innerSource = sourceBuffer
1288
+ .subarray(start, end)
1289
+ .toString('utf-8');
1290
+ if (innerExpr.type === 'ObjectExpression') {
1279
1291
  const stripped = innerSource.slice(1, -1).trim();
1280
1292
  if (stripped)
1281
1293
  dynamicStyleParts.push(stripped);
1282
1294
  }
1295
+ else {
1296
+ existingStyleExpr = `...(${innerSource})`;
1297
+ }
1283
1298
  }
1284
1299
  }
1285
1300
  args = args.filter((arg) => {
@@ -1364,10 +1379,10 @@ async function loader(source) {
1364
1379
  }
1365
1380
  return true;
1366
1381
  });
1367
- const styleAttr = dynamicStyleParts.length > 0
1368
- ? ` style={{${dynamicStyleParts.join(', ')}}}`
1382
+ const styleAttr = dynamicStyleParts.length > 0 || existingStyleExpr
1383
+ ? ` style={{ ${existingStyleExpr ? existingStyleExpr + ', ' : ''}${dynamicStyleParts.join(', ')} }}`
1369
1384
  : '';
1370
- const { classParts, isOptimizable, baseStyle } = buildClassParts(args, dynamicClassParts, existingClass);
1385
+ const { classParts, isOptimizable, baseStyle } = buildClassParts(args, dynamicClassParts, existingClassExpr);
1371
1386
  if (isOptimizable &&
1372
1387
  (args.length > 0 ||
1373
1388
  Object.keys(baseStyle).length > 0 ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/turbopack-loader",
3
- "version": "13.1.5",
3
+ "version": "13.2.1",
4
4
  "description": "Plumeria Turbopack-loader",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",
@@ -22,7 +22,7 @@
22
22
  "zero-virtual.css"
23
23
  ],
24
24
  "dependencies": {
25
- "@plumeria/utils": "^13.1.5"
25
+ "@plumeria/utils": "^13.2.1"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@swc/core": "1.15.40",