@plumeria/turbopack-loader 8.0.1 → 8.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 +69 -57
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -24,6 +24,10 @@ async function loader(source) {
24
24
  tsx: true,
25
25
  target: 'es2022',
26
26
  });
27
+ const leadingLen = (0, utils_1.getLeadingCommentLength)(source);
28
+ const sourceBuffer = Buffer.from(source, 'utf-8');
29
+ const leadingBytes = Buffer.byteLength(source.slice(0, leadingLen), 'utf-8');
30
+ const baseByteOffset = ast.span.start - leadingBytes;
27
31
  for (const node of ast.body) {
28
32
  if (node.type === 'ImportDeclaration') {
29
33
  const sourcePath = node.source.value;
@@ -236,12 +240,12 @@ async function loader(source) {
236
240
  hashMap,
237
241
  isExported,
238
242
  initSpan: {
239
- start: node.init.span.start - ast.span.start,
240
- end: node.init.span.end - ast.span.start,
243
+ start: node.init.span.start - baseByteOffset,
244
+ end: node.init.span.end - baseByteOffset,
241
245
  },
242
246
  declSpan: {
243
- start: declSpan.start - ast.span.start,
244
- end: declSpan.end - ast.span.start,
247
+ start: declSpan.start - baseByteOffset,
248
+ end: declSpan.end - baseByteOffset,
245
249
  },
246
250
  };
247
251
  }
@@ -271,12 +275,12 @@ async function loader(source) {
271
275
  hashMap,
272
276
  isExported,
273
277
  initSpan: {
274
- start: node.init.span.start - ast.span.start,
275
- end: node.init.span.end - ast.span.start,
278
+ start: node.init.span.start - baseByteOffset,
279
+ end: node.init.span.end - baseByteOffset,
276
280
  },
277
281
  declSpan: {
278
- start: declSpan.start - ast.span.start,
279
- end: declSpan.end - ast.span.start,
282
+ start: declSpan.start - baseByteOffset,
283
+ end: declSpan.end - baseByteOffset,
280
284
  },
281
285
  };
282
286
  }
@@ -297,12 +301,12 @@ async function loader(source) {
297
301
  hashMap: scannedTables.createAtomicMapTable[hash],
298
302
  isExported,
299
303
  initSpan: {
300
- start: node.init.span.start - ast.span.start,
301
- end: node.init.span.end - ast.span.start,
304
+ start: node.init.span.start - baseByteOffset,
305
+ end: node.init.span.end - baseByteOffset,
302
306
  },
303
307
  declSpan: {
304
- start: declSpan.start - ast.span.start,
305
- end: declSpan.end - ast.span.start,
308
+ start: declSpan.start - baseByteOffset,
309
+ end: declSpan.end - baseByteOffset,
306
310
  },
307
311
  };
308
312
  }
@@ -367,8 +371,8 @@ async function loader(source) {
367
371
  const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
368
372
  scannedTables.keyframesObjectTable[hash] = obj;
369
373
  replacements.push({
370
- start: node.span.start - ast.span.start,
371
- end: node.span.end - ast.span.start,
374
+ start: node.span.start - baseByteOffset,
375
+ end: node.span.end - baseByteOffset,
372
376
  content: JSON.stringify(`kf-${hash}`),
373
377
  });
374
378
  }
@@ -379,8 +383,8 @@ async function loader(source) {
379
383
  const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
380
384
  scannedTables.viewTransitionObjectTable[hash] = obj;
381
385
  replacements.push({
382
- start: node.span.start - ast.span.start,
383
- end: node.span.end - ast.span.start,
386
+ start: node.span.start - baseByteOffset,
387
+ end: node.span.end - baseByteOffset,
384
388
  content: JSON.stringify(`vt-${hash}`),
385
389
  });
386
390
  }
@@ -397,8 +401,8 @@ async function loader(source) {
397
401
  }
398
402
  const prefix = propName === 'createTheme' ? 'tm-' : 'st-';
399
403
  replacements.push({
400
- start: node.span.start - ast.span.start,
401
- end: node.span.end - ast.span.start,
404
+ start: node.span.start - baseByteOffset,
405
+ end: node.span.end - baseByteOffset,
402
406
  content: JSON.stringify(`${prefix}${hash}`),
403
407
  });
404
408
  }
@@ -429,8 +433,8 @@ async function loader(source) {
429
433
  }
430
434
  if (atomMap) {
431
435
  replacements.push({
432
- start: node.span.start - ast.span.start,
433
- end: node.span.end - ast.span.start,
436
+ start: node.span.start - baseByteOffset,
437
+ end: node.span.end - baseByteOffset,
434
438
  content: JSON.stringify(atomMap),
435
439
  });
436
440
  }
@@ -443,8 +447,8 @@ async function loader(source) {
443
447
  const atomicMap = scannedTables.createAtomicMapTable[themeHash];
444
448
  if (atomicMap && atomicMap && atomicMap[propName]) {
445
449
  replacements.push({
446
- start: node.span.start - ast.span.start,
447
- end: node.span.end - ast.span.start,
450
+ start: node.span.start - baseByteOffset,
451
+ end: node.span.end - baseByteOffset,
448
452
  content: JSON.stringify(atomicMap[propName]),
449
453
  });
450
454
  }
@@ -457,8 +461,8 @@ async function loader(source) {
457
461
  const staticObj = scannedTables.createStaticObjectTable[staticHash];
458
462
  if (staticObj && staticObj[propName] !== undefined) {
459
463
  replacements.push({
460
- start: node.span.start - ast.span.start,
461
- end: node.span.end - ast.span.start,
464
+ start: node.span.start - baseByteOffset,
465
+ end: node.span.end - baseByteOffset,
462
466
  content: JSON.stringify(staticObj[propName]),
463
467
  });
464
468
  }
@@ -473,8 +477,8 @@ async function loader(source) {
473
477
  const styleInfo = localCreateStyles[node.value];
474
478
  if (styleInfo) {
475
479
  replacements.push({
476
- start: node.span.start - ast.span.start,
477
- end: node.span.end - ast.span.start,
480
+ start: node.span.start - baseByteOffset,
481
+ end: node.span.end - baseByteOffset,
478
482
  content: JSON.stringify(styleInfo.hashMap),
479
483
  });
480
484
  return;
@@ -496,8 +500,8 @@ async function loader(source) {
496
500
  }
497
501
  });
498
502
  replacements.push({
499
- start: node.span.start - ast.span.start,
500
- end: node.span.end - ast.span.start,
503
+ start: node.span.start - baseByteOffset,
504
+ end: node.span.end - baseByteOffset,
501
505
  content: JSON.stringify(hashMap),
502
506
  });
503
507
  }
@@ -510,8 +514,8 @@ async function loader(source) {
510
514
  const atomicMap = scannedTables.createAtomicMapTable[themeHash];
511
515
  if (atomicMap) {
512
516
  replacements.push({
513
- start: node.span.start - ast.span.start,
514
- end: node.span.end - ast.span.start,
517
+ start: node.span.start - baseByteOffset,
518
+ end: node.span.end - baseByteOffset,
515
519
  content: JSON.stringify(atomicMap),
516
520
  });
517
521
  return;
@@ -525,8 +529,8 @@ async function loader(source) {
525
529
  const staticObj = scannedTables.createStaticObjectTable[staticHash];
526
530
  if (staticObj) {
527
531
  replacements.push({
528
- start: node.span.start - ast.span.start,
529
- end: node.span.end - ast.span.start,
532
+ start: node.span.start - baseByteOffset,
533
+ end: node.span.end - baseByteOffset,
530
534
  content: JSON.stringify(staticObj),
531
535
  });
532
536
  }
@@ -658,9 +662,11 @@ async function loader(source) {
658
662
  if (!groupVariants)
659
663
  continue;
660
664
  const currentGroupId = ++groupIdCounter;
661
- const valStart = valExpr.span.start - ast.span.start;
662
- const valEnd = valExpr.span.end - ast.span.start;
663
- const valSource = source.substring(valStart, valEnd);
665
+ const valStart = valExpr.span.start - baseByteOffset;
666
+ const valEnd = valExpr.span.end - baseByteOffset;
667
+ const valSource = sourceBuffer
668
+ .subarray(valStart, valEnd)
669
+ .toString('utf-8');
664
670
  if (valExpr.type === 'StringLiteral') {
665
671
  if (groupVariants[valExpr.value]) {
666
672
  baseStyle = (0, utils_1.deepMerge)(baseStyle, groupVariants[valExpr.value]);
@@ -684,9 +690,11 @@ async function loader(source) {
684
690
  }
685
691
  continue;
686
692
  }
687
- const argStart = arg.span.start - ast.span.start;
688
- const argEnd = arg.span.end - ast.span.start;
689
- const argSource = source.substring(argStart, argEnd);
693
+ const argStart = arg.span.start - baseByteOffset;
694
+ const argEnd = arg.span.end - baseByteOffset;
695
+ const argSource = sourceBuffer
696
+ .subarray(argStart, argEnd)
697
+ .toString('utf-8');
690
698
  if (utils_1.t.isStringLiteral(arg)) {
691
699
  if (variantObj[arg.value]) {
692
700
  baseStyle = (0, utils_1.deepMerge)(baseStyle, variantObj[arg.value]);
@@ -753,9 +761,9 @@ async function loader(source) {
753
761
  }
754
762
  }
755
763
  const getSource = (node) => {
756
- const start = node.span.start - ast.span.start;
757
- const end = node.span.end - ast.span.start;
758
- return source.substring(start, end);
764
+ const start = node.span.start - baseByteOffset;
765
+ const end = node.span.end - baseByteOffset;
766
+ return sourceBuffer.subarray(start, end).toString('utf-8');
759
767
  };
760
768
  const collectConditions = (node, currentTestStrings = []) => {
761
769
  const staticStyle = resolveStyleObject(node);
@@ -827,8 +835,8 @@ async function loader(source) {
827
835
  const records = (0, utils_1.getStyleRecords)(baseStyle);
828
836
  const className = records.map((r) => r.hash).join(' ');
829
837
  replacements.push({
830
- start: node.span.start - ast.span.start,
831
- end: node.span.end - ast.span.start,
838
+ start: node.span.start - baseByteOffset,
839
+ end: node.span.end - baseByteOffset,
832
840
  content: JSON.stringify(className),
833
841
  });
834
842
  }
@@ -951,9 +959,9 @@ async function loader(source) {
951
959
  const fClass = processBranch(c.falsy);
952
960
  let testStr = c.testString;
953
961
  if (!testStr && c.test) {
954
- const start = c.test.span.start - ast.span.start;
955
- const end = c.test.span.end - ast.span.start;
956
- testStr = source.substring(start, end);
962
+ const start = c.test.span.start - baseByteOffset;
963
+ const end = c.test.span.end - baseByteOffset;
964
+ testStr = sourceBuffer.subarray(start, end).toString('utf-8');
957
965
  }
958
966
  classParts.push(`(${testStr} ? ${tClass} : ${fClass})`);
959
967
  });
@@ -977,9 +985,11 @@ async function loader(source) {
977
985
  }
978
986
  else {
979
987
  const firstTest = options[0].test;
980
- const firstStart = firstTest.span.start - ast.span.start;
981
- const firstEnd = firstTest.span.end - ast.span.start;
982
- commonTestExpr = source.substring(firstStart, firstEnd);
988
+ const firstStart = firstTest.span.start - baseByteOffset;
989
+ const firstEnd = firstTest.span.end - baseByteOffset;
990
+ commonTestExpr = sourceBuffer
991
+ .subarray(firstStart, firstEnd)
992
+ .toString('utf-8');
983
993
  }
984
994
  options.forEach((opt) => {
985
995
  if (opt.valueName && opt.truthy) {
@@ -1013,9 +1023,9 @@ async function loader(source) {
1013
1023
  conflictStd.forEach((c) => {
1014
1024
  let testStr = c.testString;
1015
1025
  if (!testStr && c.test) {
1016
- const start = c.test.span.start - ast.span.start;
1017
- const end = c.test.span.end - ast.span.start;
1018
- testStr = source.substring(start, end);
1026
+ const start = c.test.span.start - baseByteOffset;
1027
+ const end = c.test.span.end - baseByteOffset;
1028
+ testStr = sourceBuffer.subarray(start, end).toString('utf-8');
1019
1029
  }
1020
1030
  dimensions.push({
1021
1031
  type: 'std',
@@ -1037,9 +1047,11 @@ async function loader(source) {
1037
1047
  }
1038
1048
  else {
1039
1049
  const firstTest = opts[0].test;
1040
- const firstStart = firstTest.span.start - ast.span.start;
1041
- const firstEnd = firstTest.span.end - ast.span.start;
1042
- commonTestExpr = source.substring(firstStart, firstEnd);
1050
+ const firstStart = firstTest.span.start - baseByteOffset;
1051
+ const firstEnd = firstTest.span.end - baseByteOffset;
1052
+ commonTestExpr = sourceBuffer
1053
+ .subarray(firstStart, firstEnd)
1054
+ .toString('utf-8');
1043
1055
  }
1044
1056
  }
1045
1057
  const options = opts.map((opt) => ({
@@ -1096,8 +1108,8 @@ async function loader(source) {
1096
1108
  }
1097
1109
  const replacement = classParts.length > 0 ? classParts.join(' + " " + ') : '""';
1098
1110
  replacements.push({
1099
- start: node.span.start - ast.span.start,
1100
- end: node.span.end - ast.span.start,
1111
+ start: node.span.start - baseByteOffset,
1112
+ end: node.span.end - baseByteOffset,
1101
1113
  content: replacement,
1102
1114
  });
1103
1115
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/turbopack-loader",
3
- "version": "8.0.1",
3
+ "version": "8.0.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": "^8.0.1"
25
+ "@plumeria/utils": "^8.0.2"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@swc/core": "1.15.8",