@plumeria/turbopack-loader 10.0.5 → 10.0.7

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 +144 -103
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -153,28 +153,40 @@ async function loader(source) {
153
153
  mergedKeyframesTable[key] = scannedTables.keyframesHashTable[key];
154
154
  }
155
155
  for (const key of Object.keys(importMap)) {
156
- mergedKeyframesTable[key] = importMap[key];
156
+ const val = importMap[key];
157
+ if (typeof val === 'string') {
158
+ mergedKeyframesTable[key] = val;
159
+ }
157
160
  }
158
161
  const mergedViewTransitionTable = {};
159
162
  for (const key of Object.keys(scannedTables.viewTransitionHashTable)) {
160
163
  mergedViewTransitionTable[key] = scannedTables.viewTransitionHashTable[key];
161
164
  }
162
165
  for (const key of Object.keys(importMap)) {
163
- mergedViewTransitionTable[key] = importMap[key];
166
+ const val = importMap[key];
167
+ if (typeof val === 'string') {
168
+ mergedViewTransitionTable[key] = val;
169
+ }
164
170
  }
165
171
  const mergedCreateTable = {};
166
172
  for (const key of Object.keys(scannedTables.createHashTable)) {
167
173
  mergedCreateTable[key] = scannedTables.createHashTable[key];
168
174
  }
169
175
  for (const key of Object.keys(importMap)) {
170
- mergedCreateTable[key] = importMap[key];
176
+ const val = importMap[key];
177
+ if (typeof val === 'string') {
178
+ mergedCreateTable[key] = val;
179
+ }
171
180
  }
172
181
  const mergedVariantsTable = {};
173
182
  for (const key of Object.keys(scannedTables.variantsHashTable)) {
174
183
  mergedVariantsTable[key] = scannedTables.variantsHashTable[key];
175
184
  }
176
185
  for (const key of Object.keys(importMap)) {
177
- mergedVariantsTable[key] = importMap[key];
186
+ const val = importMap[key];
187
+ if (typeof val === 'string') {
188
+ mergedVariantsTable[key] = val;
189
+ }
178
190
  }
179
191
  const mergedCreateThemeHashTable = {};
180
192
  for (const key of Object.keys(scannedTables.createThemeHashTable)) {
@@ -206,10 +218,9 @@ async function loader(source) {
206
218
  const idSpans = new Set();
207
219
  const excludedSpans = new Set();
208
220
  const checkVariantAssignment = (decl) => {
209
- if (decl.init &&
210
- utils_1.t.isCallExpression(decl.init) &&
211
- utils_1.t.isIdentifier(decl.init.callee)) {
212
- const varName = decl.init.callee.value;
221
+ const init = decl.init;
222
+ if (init && utils_1.t.isCallExpression(init) && utils_1.t.isIdentifier(init.callee)) {
223
+ const varName = init.callee.value;
213
224
  if ((localCreateStyles[varName] &&
214
225
  localCreateStyles[varName].type === 'variant') ||
215
226
  mergedVariantsTable[varName]) {
@@ -219,11 +230,12 @@ async function loader(source) {
219
230
  };
220
231
  const registerStyle = (node, declSpan, isExported) => {
221
232
  let propName;
233
+ const init = node.init;
222
234
  if (utils_1.t.isIdentifier(node.id) &&
223
- node.init &&
224
- utils_1.t.isCallExpression(node.init) &&
225
- node.init.arguments.length >= 1) {
226
- const callee = node.init.callee;
235
+ init &&
236
+ utils_1.t.isCallExpression(init) &&
237
+ init.arguments.length >= 1) {
238
+ const callee = init.callee;
227
239
  if (utils_1.t.isMemberExpression(callee) &&
228
240
  utils_1.t.isIdentifier(callee.object) &&
229
241
  utils_1.t.isIdentifier(callee.property)) {
@@ -242,10 +254,10 @@ async function loader(source) {
242
254
  }
243
255
  }
244
256
  }
245
- if (propName) {
257
+ if (propName && init && utils_1.t.isCallExpression(init)) {
246
258
  if (propName === 'create' &&
247
- utils_1.t.isObjectExpression(node.init.arguments[0].expression)) {
248
- const obj = (0, utils_1.objectExpressionToObject)(node.init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
259
+ utils_1.t.isObjectExpression(init.arguments[0].expression)) {
260
+ const obj = (0, utils_1.objectExpressionToObject)(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
249
261
  if (obj) {
250
262
  const hashMap = {};
251
263
  Object.entries(obj).forEach(([key, style]) => {
@@ -262,7 +274,7 @@ async function loader(source) {
262
274
  records.forEach((r) => (atomMap[r.key] = r.hash));
263
275
  hashMap[key] = atomMap;
264
276
  });
265
- const objExpr = node.init.arguments[0].expression;
277
+ const objExpr = init.arguments[0].expression;
266
278
  objExpr.properties.forEach((prop) => {
267
279
  if (prop.type !== 'KeyValueProperty' ||
268
280
  prop.key.type !== 'Identifier')
@@ -272,7 +284,20 @@ async function loader(source) {
272
284
  if (!isArrow && !isFunc)
273
285
  return;
274
286
  const key = prop.key.value;
275
- const params = prop.value.params.map((p) => p.type === 'Identifier' ? p.value : (p.pat?.value ?? 'arg'));
287
+ const func = prop.value;
288
+ if (func.type !== 'ArrowFunctionExpression' &&
289
+ func.type !== 'FunctionExpression')
290
+ return;
291
+ const params = func.params.map((p) => {
292
+ if (utils_1.t.isIdentifier(p))
293
+ return p.value;
294
+ if (typeof p === 'object' &&
295
+ p !== null &&
296
+ 'pat' in p &&
297
+ utils_1.t.isIdentifier(p.pat))
298
+ return p.pat.value;
299
+ return 'arg';
300
+ });
276
301
  const cssVarInfo = {};
277
302
  const tempStaticTable = { ...mergedStaticTable };
278
303
  const substitutedArgs = params.map((paramName) => {
@@ -283,7 +308,7 @@ async function loader(source) {
283
308
  params.forEach((paramName, i) => {
284
309
  tempStaticTable[paramName] = substitutedArgs[i];
285
310
  });
286
- let actualBody = prop.value.body;
311
+ let actualBody = func.body;
287
312
  if (actualBody?.type === 'ParenthesisExpression')
288
313
  actualBody = actualBody.expression;
289
314
  if (actualBody?.type === 'BlockStatement') {
@@ -316,29 +341,31 @@ async function loader(source) {
316
341
  if (utils_1.t.isIdentifier(node.id)) {
317
342
  idSpans.add(node.id.span.start);
318
343
  }
319
- localCreateStyles[node.id.value] = {
320
- name: node.id.value,
321
- type: 'create',
322
- obj,
323
- hashMap,
324
- isExported,
325
- initSpan: {
326
- start: node.init.span.start - baseByteOffset,
327
- end: node.init.span.end - baseByteOffset,
328
- },
329
- declSpan: {
330
- start: declSpan.start - baseByteOffset,
331
- end: declSpan.end - baseByteOffset,
332
- },
333
- };
344
+ if (utils_1.t.isIdentifier(node.id)) {
345
+ localCreateStyles[node.id.value] = {
346
+ name: node.id.value,
347
+ type: 'create',
348
+ obj,
349
+ hashMap,
350
+ isExported,
351
+ initSpan: {
352
+ start: init.span.start - baseByteOffset,
353
+ end: init.span.end - baseByteOffset,
354
+ },
355
+ declSpan: {
356
+ start: declSpan.start - baseByteOffset,
357
+ end: declSpan.end - baseByteOffset,
358
+ },
359
+ };
360
+ }
334
361
  }
335
362
  }
336
363
  else if (propName === 'variants' &&
337
- utils_1.t.isObjectExpression(node.init.arguments[0].expression)) {
364
+ utils_1.t.isObjectExpression(init.arguments[0].expression)) {
338
365
  if (utils_1.t.isIdentifier(node.id)) {
339
366
  idSpans.add(node.id.span.start);
340
367
  }
341
- const obj = (0, utils_1.objectExpressionToObject)(node.init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable, (name) => {
368
+ const obj = (0, utils_1.objectExpressionToObject)(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable, (name) => {
342
369
  if (localCreateStyles[name]) {
343
370
  return localCreateStyles[name].obj;
344
371
  }
@@ -351,47 +378,51 @@ async function loader(source) {
351
378
  return undefined;
352
379
  });
353
380
  const { hashMap } = (0, utils_1.processVariants)(obj);
354
- localCreateStyles[node.id.value] = {
355
- name: node.id.value,
356
- type: 'variant',
357
- obj,
358
- hashMap,
359
- isExported,
360
- initSpan: {
361
- start: node.init.span.start - baseByteOffset,
362
- end: node.init.span.end - baseByteOffset,
363
- },
364
- declSpan: {
365
- start: declSpan.start - baseByteOffset,
366
- end: declSpan.end - baseByteOffset,
367
- },
368
- };
381
+ if (utils_1.t.isIdentifier(node.id)) {
382
+ localCreateStyles[node.id.value] = {
383
+ name: node.id.value,
384
+ type: 'variant',
385
+ obj,
386
+ hashMap,
387
+ isExported,
388
+ initSpan: {
389
+ start: init.span.start - baseByteOffset,
390
+ end: init.span.end - baseByteOffset,
391
+ },
392
+ declSpan: {
393
+ start: declSpan.start - baseByteOffset,
394
+ end: declSpan.end - baseByteOffset,
395
+ },
396
+ };
397
+ }
369
398
  }
370
399
  else if (propName === 'createTheme' &&
371
- utils_1.t.isObjectExpression(node.init.arguments[0].expression)) {
400
+ utils_1.t.isObjectExpression(init.arguments[0].expression)) {
372
401
  if (utils_1.t.isIdentifier(node.id)) {
373
402
  idSpans.add(node.id.span.start);
374
403
  }
375
- const obj = (0, utils_1.objectExpressionToObject)(node.init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
404
+ const obj = (0, utils_1.objectExpressionToObject)(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
376
405
  const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
377
- const uniqueKey = `${resourcePath}-${node.id.value}`;
378
- scannedTables.createThemeHashTable[uniqueKey] = hash;
379
- scannedTables.createThemeObjectTable[hash] = obj;
380
- localCreateStyles[node.id.value] = {
381
- name: node.id.value,
382
- type: 'constant',
383
- obj,
384
- hashMap: scannedTables.createAtomicMapTable[hash],
385
- isExported,
386
- initSpan: {
387
- start: node.init.span.start - baseByteOffset,
388
- end: node.init.span.end - baseByteOffset,
389
- },
390
- declSpan: {
391
- start: declSpan.start - baseByteOffset,
392
- end: declSpan.end - baseByteOffset,
393
- },
394
- };
406
+ if (utils_1.t.isIdentifier(node.id)) {
407
+ const uniqueKey = `${resourcePath}-${node.id.value}`;
408
+ scannedTables.createThemeHashTable[uniqueKey] = hash;
409
+ scannedTables.createThemeObjectTable[hash] = obj;
410
+ localCreateStyles[node.id.value] = {
411
+ name: node.id.value,
412
+ type: 'constant',
413
+ obj,
414
+ hashMap: scannedTables.createAtomicMapTable[hash],
415
+ isExported,
416
+ initSpan: {
417
+ start: init.span.start - baseByteOffset,
418
+ end: init.span.end - baseByteOffset,
419
+ },
420
+ declSpan: {
421
+ start: declSpan.start - baseByteOffset,
422
+ end: declSpan.end - baseByteOffset,
423
+ },
424
+ };
425
+ }
395
426
  }
396
427
  }
397
428
  };
@@ -402,7 +433,7 @@ async function loader(source) {
402
433
  if (specifier.local) {
403
434
  excludedSpans.add(specifier.local.span.start);
404
435
  }
405
- if (specifier.imported) {
436
+ if (specifier.type === 'ImportSpecifier' && specifier.imported) {
406
437
  excludedSpans.add(specifier.imported.span.start);
407
438
  }
408
439
  });
@@ -447,17 +478,18 @@ async function loader(source) {
447
478
  }
448
479
  if (propName) {
449
480
  const args = node.arguments;
450
- if (propName === 'keyframes' &&
451
- args.length > 0 &&
452
- utils_1.t.isObjectExpression(args[0].expression)) {
453
- const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
454
- const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
455
- scannedTables.keyframesObjectTable[hash] = obj;
456
- replacements.push({
457
- start: node.span.start - baseByteOffset,
458
- end: node.span.end - baseByteOffset,
459
- content: JSON.stringify(`kf-${hash}`),
460
- });
481
+ if (propName === 'keyframes') {
482
+ const expr = args[0].expression;
483
+ if (utils_1.t.isObjectExpression(expr)) {
484
+ const obj = (0, utils_1.objectExpressionToObject)(expr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
485
+ const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
486
+ scannedTables.keyframesObjectTable[hash] = obj;
487
+ replacements.push({
488
+ start: node.span.start - baseByteOffset,
489
+ end: node.span.end - baseByteOffset,
490
+ content: JSON.stringify(`kf-${hash}`),
491
+ });
492
+ }
461
493
  }
462
494
  else if (propName === 'viewTransition' &&
463
495
  args.length > 0 &&
@@ -511,8 +543,7 @@ async function loader(source) {
511
543
  }
512
544
  else if (utils_1.t.isMemberExpression(expr) &&
513
545
  utils_1.t.isIdentifier(expr.object) &&
514
- (utils_1.t.isIdentifier(expr.property) ||
515
- expr.property.type === 'Computed')) {
546
+ (utils_1.t.isIdentifier(expr.property) || expr.property.type === 'Computed')) {
516
547
  if (expr.property.type === 'Computed')
517
548
  return {};
518
549
  const varName = expr.object.value;
@@ -647,8 +678,9 @@ async function loader(source) {
647
678
  const currentGroupId = ++groupIdCounter;
648
679
  const valSource = getSource(valExpr);
649
680
  if (valExpr.type === 'StringLiteral') {
650
- if (groupVariants[valExpr.value])
651
- baseStyle = (0, utils_1.deepMerge)(baseStyle, groupVariants[valExpr.value]);
681
+ const groupVariantsAsObj = groupVariants;
682
+ if (groupVariantsAsObj[valExpr.value])
683
+ baseStyle = (0, utils_1.deepMerge)(baseStyle, groupVariantsAsObj[valExpr.value]);
652
684
  continue;
653
685
  }
654
686
  Object.entries(groupVariants).forEach(([optionName, style]) => {
@@ -1066,20 +1098,24 @@ async function loader(source) {
1066
1098
  const expr = node.value.expression;
1067
1099
  let args = expr.type === 'ArrayExpression'
1068
1100
  ? expr.elements
1069
- .filter(Boolean)
1070
- .map((el) => ({ expression: el.expression ?? el }))
1101
+ .filter((el) => el !== undefined)
1102
+ .map((el) => ({ expression: el.expression }))
1071
1103
  : [{ expression: expr }];
1072
1104
  const dynamicClassParts = [];
1073
1105
  const dynamicStyleParts = [];
1074
1106
  let attributes = [];
1075
1107
  for (const [, attrs] of jsxOpeningElementMap) {
1076
- const found = attrs.find((a) => a.span?.start === node.span.start);
1108
+ const found = attrs
1109
+ .filter((a) => a.type === 'JSXAttribute')
1110
+ .find((a) => a.span.start === node.span.start);
1077
1111
  if (found) {
1078
1112
  attributes = attrs;
1079
1113
  break;
1080
1114
  }
1081
1115
  }
1082
- const classNameAttr = attributes.find((attr) => attr.name?.value === 'className');
1116
+ const classNameAttr = attributes.find((attr) => attr.type === 'JSXAttribute' &&
1117
+ attr.name.type === 'Identifier' &&
1118
+ attr.name.value === 'className');
1083
1119
  let existingClass = '';
1084
1120
  if (classNameAttr?.value?.type === 'StringLiteral') {
1085
1121
  existingClass = classNameAttr.value.value;
@@ -1089,23 +1125,27 @@ async function loader(source) {
1089
1125
  content: '',
1090
1126
  });
1091
1127
  }
1092
- const styleAttrExisting = attributes.find((attr) => attr.name?.value === 'style');
1128
+ const styleAttrExisting = attributes.find((attr) => attr.type === 'JSXAttribute' &&
1129
+ attr.name.type === 'Identifier' &&
1130
+ attr.name.value === 'style');
1093
1131
  if (styleAttrExisting) {
1094
1132
  replacements.push({
1095
1133
  start: styleAttrExisting.span.start - baseByteOffset,
1096
1134
  end: styleAttrExisting.span.end - baseByteOffset,
1097
1135
  content: '',
1098
1136
  });
1099
- const innerExpr = styleAttrExisting.value?.expression;
1100
- if (innerExpr?.type === 'ObjectExpression') {
1101
- const start = innerExpr.span.start - baseByteOffset;
1102
- const end = innerExpr.span.end - baseByteOffset;
1103
- const innerSource = sourceBuffer
1104
- .subarray(start, end)
1105
- .toString('utf-8');
1106
- const stripped = innerSource.slice(1, -1).trim();
1107
- if (stripped)
1108
- dynamicStyleParts.push(stripped);
1137
+ if (styleAttrExisting.value?.type === 'JSXExpressionContainer') {
1138
+ const innerExpr = styleAttrExisting.value?.expression;
1139
+ if (innerExpr?.type === 'ObjectExpression') {
1140
+ const start = innerExpr.span.start - baseByteOffset;
1141
+ const end = innerExpr.span.end - baseByteOffset;
1142
+ const innerSource = sourceBuffer
1143
+ .subarray(start, end)
1144
+ .toString('utf-8');
1145
+ const stripped = innerSource.slice(1, -1).trim();
1146
+ if (stripped)
1147
+ dynamicStyleParts.push(stripped);
1148
+ }
1109
1149
  }
1110
1150
  }
1111
1151
  args = args.filter((arg) => {
@@ -1133,8 +1173,9 @@ async function loader(source) {
1133
1173
  const callArg = callArgs[i];
1134
1174
  if (!callArg)
1135
1175
  return;
1136
- const argStart = callArg.expression.span.start - baseByteOffset;
1137
- const argEnd = callArg.expression.span.end - baseByteOffset;
1176
+ const argExpr = callArg.expression;
1177
+ const argStart = argExpr.span.start - baseByteOffset;
1178
+ const argEnd = argExpr.span.end - baseByteOffset;
1138
1179
  const argSource = sourceBuffer
1139
1180
  .subarray(argStart, argEnd)
1140
1181
  .toString('utf-8');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/turbopack-loader",
3
- "version": "10.0.5",
3
+ "version": "10.0.7",
4
4
  "description": "Plumeria Turbopack-loader",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",
@@ -22,10 +22,10 @@
22
22
  "zero-virtual.css"
23
23
  ],
24
24
  "dependencies": {
25
- "@plumeria/utils": "^10.0.5"
25
+ "@plumeria/utils": "^10.0.7"
26
26
  },
27
27
  "devDependencies": {
28
- "@swc/core": "1.15.18",
28
+ "@swc/core": "1.15.21",
29
29
  "zss-engine": "2.2.6"
30
30
  },
31
31
  "publishConfig": {