@plumeria/turbopack-loader 4.1.0 → 4.1.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 +48 -3
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -196,11 +196,10 @@ async function loader(source) {
196
196
  if (styleInfo && !styleInfo.hasDynamicAccess) {
197
197
  const atomMap = styleInfo.hashMap[node.property.value];
198
198
  if (atomMap) {
199
- const combinedHash = Object.values(atomMap).join(' ');
200
199
  replacements.push({
201
200
  start: node.span.start - ast.span.start,
202
201
  end: node.span.end - ast.span.start,
203
- content: JSON.stringify(combinedHash),
202
+ content: JSON.stringify(atomMap),
204
203
  });
205
204
  }
206
205
  }
@@ -251,7 +250,31 @@ async function loader(source) {
251
250
  }
252
251
  return false;
253
252
  };
253
+ const hasDynamicAccess = (expr) => {
254
+ if (utils_1.t.isMemberExpression(expr) && utils_1.t.isIdentifier(expr.object)) {
255
+ const info = localCreateStyles[expr.object.value];
256
+ if (info && info.hasDynamicAccess)
257
+ return true;
258
+ }
259
+ if (utils_1.t.isIdentifier(expr)) {
260
+ const info = localCreateStyles[expr.value];
261
+ if (info && info.hasDynamicAccess)
262
+ return true;
263
+ }
264
+ if (utils_1.t.isConditionalExpression(expr)) {
265
+ return (hasDynamicAccess(expr.consequent) ||
266
+ hasDynamicAccess(expr.alternate));
267
+ }
268
+ if (utils_1.t.isBinaryExpression(expr) &&
269
+ (expr.operator === '&&' ||
270
+ expr.operator === '||' ||
271
+ expr.operator === '??')) {
272
+ return hasDynamicAccess(expr.left) || hasDynamicAccess(expr.right);
273
+ }
274
+ return false;
275
+ };
254
276
  const allStatic = args.every((arg) => checkStatic(arg.expression));
277
+ const anyDynamic = args.some((arg) => hasDynamicAccess(arg.expression));
255
278
  if (allStatic && args.length > 0) {
256
279
  const merged = args.reduce((acc, arg) => {
257
280
  const expr = arg.expression;
@@ -288,6 +311,28 @@ async function loader(source) {
288
311
  });
289
312
  }
290
313
  }
314
+ else if (anyDynamic) {
315
+ const processExpr = (expr) => {
316
+ if (utils_1.t.isIdentifier(expr)) {
317
+ const info = localCreateStyles[expr.value];
318
+ if (info && info.hasDynamicAccess) {
319
+ excludedSpans.add(expr.span.start);
320
+ }
321
+ }
322
+ else if (utils_1.t.isConditionalExpression(expr)) {
323
+ processExpr(expr.consequent);
324
+ processExpr(expr.alternate);
325
+ }
326
+ else if (utils_1.t.isBinaryExpression(expr) &&
327
+ (expr.operator === '&&' ||
328
+ expr.operator === '||' ||
329
+ expr.operator === '??')) {
330
+ processExpr(expr.left);
331
+ processExpr(expr.right);
332
+ }
333
+ };
334
+ args.forEach((arg) => processExpr(arg.expression));
335
+ }
291
336
  else {
292
337
  const processExpr = (expr) => {
293
338
  if (utils_1.t.isMemberExpression(expr) &&
@@ -309,7 +354,6 @@ async function loader(source) {
309
354
  else if (utils_1.t.isIdentifier(expr)) {
310
355
  const info = localCreateStyles[expr.value];
311
356
  if (info) {
312
- info.hasDynamicAccess = true;
313
357
  excludedSpans.add(expr.span.start);
314
358
  replacements.push({
315
359
  start: expr.span.start - ast.span.start,
@@ -393,6 +437,7 @@ async function loader(source) {
393
437
  }
394
438
  const virtualCssRequest = stringifyRequest(this, `${VIRTUAL_CSS_PATH}`);
395
439
  const postfix = `\nimport ${virtualCssRequest};`;
440
+ console.log(transformedSource);
396
441
  if (process.env.NODE_ENV === 'production')
397
442
  return callback(null, transformedSource);
398
443
  if (extractedSheets.length > 0 && process.env.NODE_ENV === 'development') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/turbopack-loader",
3
- "version": "4.1.0",
3
+ "version": "4.1.2",
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": "^4.1.0"
25
+ "@plumeria/utils": "^4.1.2"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@swc/core": "1.15.8",