weapp-tailwindcss 4.9.2 → 4.9.4

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 (54) hide show
  1. package/dist/{chunk-WGBJY2H3.mjs → chunk-3IXWQT3G.mjs} +646 -565
  2. package/dist/{chunk-5O6237HX.js → chunk-4RUFPPI6.js} +400 -377
  3. package/dist/{chunk-2L6NDZIQ.mjs → chunk-6HOLMRXS.mjs} +2 -2
  4. package/dist/{chunk-ZE7JKKFT.mjs → chunk-7D27E7TU.mjs} +438 -415
  5. package/dist/chunk-AJDZJQNR.mjs +444 -0
  6. package/dist/{chunk-U7BH6QHE.js → chunk-DKX737YI.js} +277 -236
  7. package/dist/{chunk-VU2GIXVH.js → chunk-EZWWOZAH.js} +7 -7
  8. package/dist/{chunk-3SKEY32E.mjs → chunk-F2CKKG6Q.mjs} +67 -67
  9. package/dist/{chunk-DNRNFN4I.js → chunk-KHBSYJ76.js} +44 -44
  10. package/dist/{chunk-XXJNXESJ.js → chunk-MVOIVNKL.js} +635 -554
  11. package/dist/{chunk-G5OV7IOU.mjs → chunk-QAEALIIZ.mjs} +2 -2
  12. package/dist/{chunk-FFGR5V3H.mjs → chunk-SPH6SCTM.mjs} +1 -1
  13. package/dist/{chunk-2WPTDMN3.js → chunk-VPHA77FH.js} +61 -61
  14. package/dist/{chunk-DSD5JRCQ.mjs → chunk-WCM6ODS4.mjs} +265 -224
  15. package/dist/{chunk-CBOVUIXD.mjs → chunk-XI2H73CF.mjs} +41 -41
  16. package/dist/{chunk-UAEME5HT.js → chunk-Y6F6NBA7.js} +1 -1
  17. package/dist/chunk-Z3A2XYUL.js +441 -0
  18. package/dist/{chunk-W3MTTQ5M.js → chunk-ZQ7ET56G.js} +5 -5
  19. package/dist/cli.js +182 -136
  20. package/dist/cli.mjs +194 -148
  21. package/dist/core.js +10 -10
  22. package/dist/core.mjs +4 -4
  23. package/dist/css-macro/postcss.js +1 -1
  24. package/dist/css-macro/postcss.mjs +1 -1
  25. package/dist/css-macro.js +1 -1
  26. package/dist/css-macro.mjs +1 -1
  27. package/dist/defaults.js +1 -1
  28. package/dist/defaults.mjs +1 -1
  29. package/dist/gulp.js +6 -6
  30. package/dist/gulp.mjs +5 -5
  31. package/dist/index.js +10 -10
  32. package/dist/index.mjs +9 -9
  33. package/dist/postcss-html-transform.js +1 -1
  34. package/dist/postcss-html-transform.mjs +1 -1
  35. package/dist/presets.js +5 -5
  36. package/dist/presets.mjs +2 -2
  37. package/dist/reset.d.mts +2 -1
  38. package/dist/reset.d.ts +2 -1
  39. package/dist/reset.js +25 -21
  40. package/dist/reset.mjs +25 -21
  41. package/dist/types.d.mts +503 -474
  42. package/dist/types.d.ts +503 -474
  43. package/dist/types.js +1 -1
  44. package/dist/types.mjs +1 -1
  45. package/dist/vite.js +7 -7
  46. package/dist/vite.mjs +6 -6
  47. package/dist/weapp-tw-css-import-rewrite-loader.js +2 -4
  48. package/dist/webpack.js +8 -8
  49. package/dist/webpack.mjs +7 -7
  50. package/dist/webpack4.js +351 -307
  51. package/dist/webpack4.mjs +341 -297
  52. package/package.json +10 -10
  53. package/dist/chunk-5AKI6FQP.mjs +0 -397
  54. package/dist/chunk-SNEMGP42.js +0 -394
@@ -3,7 +3,7 @@
3
3
 
4
4
 
5
5
 
6
- var _chunk5O6237HXjs = require('./chunk-5O6237HX.js');
6
+ var _chunk4RUFPPI6js = require('./chunk-4RUFPPI6.js');
7
7
 
8
8
 
9
9
  var _chunkFYYBY3VKjs = require('./chunk-FYYBY3VK.js');
@@ -12,9 +12,6 @@ var _chunkFYYBY3VKjs = require('./chunk-FYYBY3VK.js');
12
12
 
13
13
  var _chunkDYLQ6UOIjs = require('./chunk-DYLQ6UOI.js');
14
14
 
15
- // src/tailwindcss/runtime.ts
16
- var _fs = require('fs');
17
-
18
15
  // src/debug/index.ts
19
16
  var _debug2 = require('debug'); var _debug3 = _interopRequireDefault(_debug2);
20
17
  var _debug = _debug3.default.call(void 0, "weapp-tw");
@@ -25,9 +22,8 @@ function createDebug(prefix) {
25
22
  return debug2;
26
23
  }
27
24
 
28
- // src/tailwindcss/runtime.ts
29
- var debug = createDebug("[tailwindcss:runtime] ");
30
- var refreshTailwindcssPatcherSymbol = /* @__PURE__ */ Symbol.for("weapp-tailwindcss.refreshTailwindcssPatcher");
25
+ // src/tailwindcss/runtime/cache.ts
26
+ var _fs = require('fs');
31
27
  var runtimeClassSetCache = /* @__PURE__ */ new WeakMap();
32
28
  function getCacheEntry(twPatcher) {
33
29
  let entry = runtimeClassSetCache.get(twPatcher);
@@ -55,8 +51,18 @@ function invalidateRuntimeClassSet(twPatcher) {
55
51
  }
56
52
  runtimeClassSetCache.delete(twPatcher);
57
53
  }
54
+ function getRuntimeClassSetCacheEntry(twPatcher) {
55
+ return getCacheEntry(twPatcher);
56
+ }
57
+ function getRuntimeClassSetSignature(twPatcher) {
58
+ return getTailwindConfigSignature(twPatcher);
59
+ }
60
+
61
+ // src/tailwindcss/runtime.ts
62
+ var debug = createDebug("[tailwindcss:runtime] ");
63
+ var refreshTailwindcssPatcherSymbol = /* @__PURE__ */ Symbol.for("weapp-tailwindcss.refreshTailwindcssPatcher");
58
64
  function createTailwindPatchPromise(twPatcher, onPatched) {
59
- return Promise.resolve(twPatcher.patch()).then(async (result) => {
65
+ return Promise.resolve(twPatcher.patch()).then(async () => {
60
66
  invalidateRuntimeClassSet(twPatcher);
61
67
  if (onPatched) {
62
68
  try {
@@ -65,7 +71,6 @@ function createTailwindPatchPromise(twPatcher, onPatched) {
65
71
  debug("failed to persist patch target after patch(): %O", error);
66
72
  }
67
73
  }
68
- return result;
69
74
  });
70
75
  }
71
76
  async function refreshTailwindRuntimeState(state, force) {
@@ -135,8 +140,8 @@ async function collectRuntimeClassSet(twPatcher, options = {}) {
135
140
  }
136
141
  }
137
142
  }
138
- const entry = getCacheEntry(activePatcher);
139
- const signature = getTailwindConfigSignature(activePatcher);
143
+ const entry = getRuntimeClassSetCacheEntry(activePatcher);
144
+ const signature = getRuntimeClassSetSignature(activePatcher);
140
145
  if (!options.force) {
141
146
  if (entry.value && entry.signature === signature) {
142
147
  return entry.value;
@@ -187,7 +192,7 @@ async function collectRuntimeClassSet(twPatcher, options = {}) {
187
192
  // package.json
188
193
  var package_default = {
189
194
  name: "weapp-tailwindcss",
190
- version: "4.9.2",
195
+ version: "4.9.4",
191
196
  description: "\u628A tailwindcss \u539F\u5B50\u5316\u6837\u5F0F\u601D\u60F3\uFF0C\u5E26\u7ED9\u5C0F\u7A0B\u5E8F\u5F00\u53D1\u8005\u4EEC! bring tailwindcss to miniprogram developers!",
192
197
  author: "ice breaker <1324318532@qq.com>",
193
198
  license: "MIT",
@@ -343,7 +348,7 @@ var package_default = {
343
348
  "with-layer.css"
344
349
  ],
345
350
  engines: {
346
- node: "^18.17.0 || >=20.5.0"
351
+ node: "^20.19.0 || >=22.12.0"
347
352
  },
348
353
  scripts: {
349
354
  dev: "tsup --watch --sourcemap",
@@ -374,9 +379,9 @@ var package_default = {
374
379
  },
375
380
  dependencies: {
376
381
  "@ast-core/escape": "~1.0.1",
377
- "@babel/parser": "~7.28.5",
378
- "@babel/traverse": "~7.28.5",
379
- "@babel/types": "~7.28.5",
382
+ "@babel/parser": "~7.28.6",
383
+ "@babel/traverse": "~7.28.6",
384
+ "@babel/types": "~7.28.6",
380
385
  "@tailwindcss-mangle/config": "^6.1.0",
381
386
  "@vue/compiler-dom": "catalog:vue3",
382
387
  "@vue/compiler-sfc": "catalog:vue3",
@@ -388,7 +393,7 @@ var package_default = {
388
393
  cac: "^6.7.14",
389
394
  debug: "~4.4.3",
390
395
  "fast-glob": "^3.3.3",
391
- htmlparser2: "10.0.0",
396
+ htmlparser2: "10.1.0",
392
397
  "loader-utils": "2.0.4",
393
398
  "local-pkg": "^1.1.2",
394
399
  "lru-cache": "10.4.3",
@@ -519,15 +524,15 @@ function initializeCache(cacheConfig) {
519
524
  }
520
525
 
521
526
  // src/tailwindcss/targets.ts
527
+ var _process = require('process'); var _process2 = _interopRequireDefault(_process);
522
528
 
523
529
 
524
- var _path = require('path'); var _path2 = _interopRequireDefault(_path);
525
- var _process = require('process'); var _process2 = _interopRequireDefault(_process);
530
+ // src/tailwindcss/targets/paths.ts
526
531
 
532
+ var _path = require('path'); var _path2 = _interopRequireDefault(_path);
527
533
  var PATCH_INFO_FILENAME = "tailwindcss-target.json";
528
534
  var PATCH_INFO_CACHE_RELATIVE_PATH = _path2.default.join("node_modules", ".cache", "weapp-tailwindcss", PATCH_INFO_FILENAME);
529
535
  var PATCH_INFO_LEGACY_RELATIVE_PATH = _path2.default.join(".tw-patch", PATCH_INFO_FILENAME);
530
- var loggedInvalidPatchRecords = /* @__PURE__ */ new Set();
531
536
  function formatRelativeToBase(targetPath, baseDir) {
532
537
  if (!baseDir) {
533
538
  return _path2.default.normalize(targetPath);
@@ -543,7 +548,7 @@ function formatRelativeToBase(targetPath, baseDir) {
543
548
  }
544
549
  function resolveRecordLocation(baseDir) {
545
550
  const normalizedBase = _path2.default.normalize(baseDir);
546
- const packageRoot = _nullishCoalesce(_chunk5O6237HXjs.findNearestPackageRoot.call(void 0, normalizedBase), () => ( normalizedBase));
551
+ const packageRoot = _nullishCoalesce(_chunk4RUFPPI6js.findNearestPackageRoot.call(void 0, normalizedBase), () => ( normalizedBase));
547
552
  const packageJsonPath = _path2.default.join(packageRoot, "package.json");
548
553
  const hasPackageJson = _fs.existsSync.call(void 0, packageJsonPath);
549
554
  const recordKeySource = hasPackageJson ? packageJsonPath : normalizedBase;
@@ -569,21 +574,14 @@ function getRecordFileCandidates(baseDir) {
569
574
  ]);
570
575
  return [...candidates];
571
576
  }
572
- function logTailwindcssTarget(kind, patcher, baseDir) {
573
- const packageInfo = _optionalChain([patcher, 'optionalAccess', _8 => _8.packageInfo]);
574
- const label = kind === "cli" ? "weapp-tw patch" : "tailwindcss-patcher";
575
- if (!_optionalChain([packageInfo, 'optionalAccess', _9 => _9.rootPath])) {
576
- _logger.logger.warn(
577
- "%s \u672A\u627E\u5230 Tailwind CSS \u4F9D\u8D56\uFF0C\u8BF7\u68C0\u67E5\u5728 %s \u662F\u5426\u5DF2\u5B89\u88C5 tailwindcss",
578
- label,
579
- _nullishCoalesce(baseDir, () => ( _process2.default.cwd()))
580
- );
581
- return;
582
- }
583
- const displayPath = formatRelativeToBase(packageInfo.rootPath, baseDir);
584
- const version = packageInfo.version ? ` (v${packageInfo.version})` : "";
585
- _logger.logger.info("%s \u7ED1\u5B9A Tailwind CSS -> %s%s", label, displayPath, version);
586
- }
577
+
578
+ // src/tailwindcss/targets/record-io.ts
579
+
580
+
581
+
582
+
583
+
584
+ var loggedInvalidPatchRecords = /* @__PURE__ */ new Set();
587
585
  function warnInvalidPatchTargetRecord(baseDir, recordPath, reason) {
588
586
  const normalizedPath = _path2.default.normalize(recordPath);
589
587
  if (loggedInvalidPatchRecords.has(normalizedPath)) {
@@ -627,22 +625,22 @@ function readPatchTargetRecord(baseDir) {
627
625
  return void 0;
628
626
  }
629
627
  async function saveCliPatchTargetRecord(baseDir, patcher, options) {
630
- if (!baseDir || !_optionalChain([patcher, 'optionalAccess', _10 => _10.packageInfo, 'optionalAccess', _11 => _11.rootPath])) {
628
+ if (!baseDir || !_optionalChain([patcher, 'optionalAccess', _8 => _8.packageInfo, 'optionalAccess', _9 => _9.rootPath])) {
631
629
  return void 0;
632
630
  }
633
631
  const normalizedBase = _path2.default.normalize(baseDir);
634
632
  const location = resolveRecordLocation(normalizedBase);
635
- const recordPath = _optionalChain([options, 'optionalAccess', _12 => _12.recordPath]) ? _path2.default.normalize(options.recordPath) : location.recordPath;
633
+ const recordPath = _optionalChain([options, 'optionalAccess', _10 => _10.recordPath]) ? _path2.default.normalize(options.recordPath) : location.recordPath;
636
634
  const record = {
637
635
  tailwindPackagePath: _path2.default.normalize(patcher.packageInfo.rootPath),
638
636
  packageVersion: patcher.packageInfo.version,
639
637
  recordedAt: (/* @__PURE__ */ new Date()).toISOString(),
640
- source: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _13 => _13.source]), () => ( "cli")),
638
+ source: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _11 => _11.source]), () => ( "cli")),
641
639
  tailwindcssBasedir: normalizedBase,
642
- cwd: _optionalChain([options, 'optionalAccess', _14 => _14.cwd]) ? _path2.default.normalize(options.cwd) : normalizedBase,
640
+ cwd: _optionalChain([options, 'optionalAccess', _12 => _12.cwd]) ? _path2.default.normalize(options.cwd) : normalizedBase,
643
641
  patchVersion: WEAPP_TW_VERSION,
644
- packageJsonPath: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _15 => _15.packageJsonPath]), () => ( location.packageJsonPath)),
645
- recordKey: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _16 => _16.recordKey]), () => ( location.recordKey))
642
+ packageJsonPath: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _13 => _13.packageJsonPath]), () => ( location.packageJsonPath)),
643
+ recordKey: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _14 => _14.recordKey]), () => ( location.recordKey))
646
644
  };
647
645
  try {
648
646
  await _promises.mkdir.call(void 0, _path2.default.dirname(recordPath), { recursive: true });
@@ -660,6 +658,10 @@ async function saveCliPatchTargetRecord(baseDir, patcher, options) {
660
658
  return void 0;
661
659
  }
662
660
  }
661
+
662
+ // src/tailwindcss/targets/recorder.ts
663
+
664
+
663
665
  function findPatchTargetRecord(baseDir) {
664
666
  const visited = /* @__PURE__ */ new Set();
665
667
  const fallback = _nullishCoalesce(baseDir, () => ( _process2.default.cwd()));
@@ -679,7 +681,7 @@ function findPatchTargetRecord(baseDir) {
679
681
  return void 0;
680
682
  }
681
683
  function createPatchTargetRecorder(baseDir, patcher, options) {
682
- if (!baseDir || !_optionalChain([patcher, 'optionalAccess', _17 => _17.packageInfo, 'optionalAccess', _18 => _18.rootPath]) || _optionalChain([options, 'optionalAccess', _19 => _19.recordTarget]) === false) {
684
+ if (!baseDir || !_optionalChain([patcher, 'optionalAccess', _15 => _15.packageInfo, 'optionalAccess', _16 => _16.rootPath]) || _optionalChain([options, 'optionalAccess', _17 => _17.recordTarget]) === false) {
683
685
  return void 0;
684
686
  }
685
687
  const normalizedBase = _path2.default.normalize(baseDir);
@@ -697,13 +699,13 @@ function createPatchTargetRecorder(baseDir, patcher, options) {
697
699
  reason = "migrate";
698
700
  } else if (!recorded.record.patchVersion || recorded.record.patchVersion !== WEAPP_TW_VERSION) {
699
701
  reason = "stale";
700
- } else if (_optionalChain([options, 'optionalAccess', _20 => _20.cwd]) && recorded.record.cwd && _path2.default.normalize(recorded.record.cwd) !== _path2.default.normalize(options.cwd)) {
702
+ } else if (_optionalChain([options, 'optionalAccess', _18 => _18.cwd]) && recorded.record.cwd && _path2.default.normalize(recorded.record.cwd) !== _path2.default.normalize(options.cwd)) {
701
703
  reason = "metadata";
702
- } else if (!recorded.record.cwd && _optionalChain([options, 'optionalAccess', _21 => _21.cwd])) {
704
+ } else if (!recorded.record.cwd && _optionalChain([options, 'optionalAccess', _19 => _19.cwd])) {
703
705
  reason = "metadata";
704
706
  }
705
707
  }
706
- const shouldPersist = _optionalChain([options, 'optionalAccess', _22 => _22.alwaysRecord]) || !recorded || Boolean(reason);
708
+ const shouldPersist = _optionalChain([options, 'optionalAccess', _20 => _20.alwaysRecord]) || !recorded || Boolean(reason);
707
709
  if (!shouldPersist) {
708
710
  return void 0;
709
711
  }
@@ -723,8 +725,8 @@ function createPatchTargetRecorder(baseDir, patcher, options) {
723
725
  break;
724
726
  }
725
727
  const onPatched = async () => saveCliPatchTargetRecord(normalizedBase, patcher, {
726
- cwd: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _23 => _23.cwd]), () => ( normalizedBase)),
727
- source: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _24 => _24.source]), () => ( "cli")),
728
+ cwd: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _21 => _21.cwd]), () => ( normalizedBase)),
729
+ source: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _22 => _22.source]), () => ( "cli")),
728
730
  recordPath: location.recordPath,
729
731
  recordKey: location.recordKey,
730
732
  packageJsonPath: location.packageJsonPath
@@ -737,6 +739,23 @@ function createPatchTargetRecorder(baseDir, patcher, options) {
737
739
  };
738
740
  }
739
741
 
742
+ // src/tailwindcss/targets.ts
743
+ function logTailwindcssTarget(kind, patcher, baseDir) {
744
+ const packageInfo = _optionalChain([patcher, 'optionalAccess', _23 => _23.packageInfo]);
745
+ const label = kind === "cli" ? "weapp-tw patch" : "tailwindcss-patcher";
746
+ if (!_optionalChain([packageInfo, 'optionalAccess', _24 => _24.rootPath])) {
747
+ _logger.logger.warn(
748
+ "%s \u672A\u627E\u5230 Tailwind CSS \u4F9D\u8D56\uFF0C\u8BF7\u68C0\u67E5\u5728 %s \u662F\u5426\u5DF2\u5B89\u88C5 tailwindcss",
749
+ label,
750
+ _nullishCoalesce(baseDir, () => ( _process2.default.cwd()))
751
+ );
752
+ return;
753
+ }
754
+ const displayPath = formatRelativeToBase(packageInfo.rootPath, baseDir);
755
+ const version = packageInfo.version ? ` (v${packageInfo.version})` : "";
756
+ _logger.logger.info("%s \u7ED1\u5B9A Tailwind CSS -> %s%s", label, displayPath, version);
757
+ }
758
+
740
759
  // src/context/compiler-context-cache.ts
741
760
  var _buffer = require('buffer');
742
761
 
@@ -924,10 +943,6 @@ function toCustomAttributesEntities(customAttributes) {
924
943
  // src/context/handlers.ts
925
944
  var _postcss = require('@weapp-tailwindcss/postcss');
926
945
 
927
- // src/js/babel.ts
928
-
929
- var _magicstring = require('magic-string'); var _magicstring2 = _interopRequireDefault(_magicstring);
930
-
931
946
  // src/babel/index.ts
932
947
  var _traverse = require('@babel/traverse'); var _traverse2 = _interopRequireDefault(_traverse);
933
948
  var _parser = require('@babel/parser');
@@ -991,132 +1006,41 @@ function createNameMatcher(list, { exact = false } = {}) {
991
1006
  };
992
1007
  }
993
1008
 
994
- // src/js/evalTransforms.ts
995
- var _escape = require('@ast-core/escape');
996
- function isEvalPath(path2) {
997
- if (path2.isCallExpression()) {
998
- const calleePath = path2.get("callee");
999
- return calleePath.isIdentifier({ name: "eval" });
1000
- }
1001
- return false;
1002
- }
1003
- function createEvalReplacementToken(path2, updated) {
1004
- const node = path2.node;
1005
- let offset = 0;
1006
- let original;
1007
- if (path2.isStringLiteral()) {
1008
- offset = 1;
1009
- original = path2.node.value;
1010
- } else if (path2.isTemplateElement()) {
1011
- original = path2.node.value.raw;
1012
- } else {
1013
- original = "";
1014
- }
1015
- if (typeof node.start !== "number" || typeof node.end !== "number") {
1016
- return void 0;
1017
- }
1018
- const start = node.start + offset;
1019
- const end = node.end - offset;
1020
- if (start >= end) {
1021
- return void 0;
1022
- }
1023
- if (original === updated) {
1024
- return void 0;
1025
- }
1026
- const value = path2.isStringLiteral() ? _escape.jsStringEscape.call(void 0, updated) : updated;
1027
- return {
1028
- start,
1029
- end,
1030
- value,
1031
- path: path2
1032
- };
1033
- }
1034
- function handleEvalStringLiteral(path2, options, updater, handler) {
1035
- const { code } = handler(path2.node.value, {
1036
- ...options,
1037
- needEscaped: false,
1038
- generateMap: false
1039
- });
1040
- if (!code) {
1041
- return;
1042
- }
1043
- const token = createEvalReplacementToken(path2, code);
1044
- if (token) {
1045
- updater.addToken(token);
1046
- }
1047
- }
1048
- function handleEvalTemplateElement(path2, options, updater, handler) {
1049
- const { code } = handler(path2.node.value.raw, {
1050
- ...options,
1051
- generateMap: false
1052
- });
1053
- if (!code) {
1054
- return;
1009
+ // src/js/babel/parse.ts
1010
+
1011
+ var parseCache = new (0, _lrucache.LRUCache)(
1012
+ {
1013
+ max: 1024
1055
1014
  }
1056
- const token = createEvalReplacementToken(path2, code);
1057
- if (token) {
1058
- updater.addToken(token);
1015
+ );
1016
+ function genCacheKey(source, options) {
1017
+ if (typeof options === "string") {
1018
+ return source + options;
1059
1019
  }
1020
+ return source + JSON.stringify(options, (_, val) => typeof val === "function" ? val.toString() : val);
1060
1021
  }
1061
- function walkEvalExpression(path2, options, updater, handler) {
1062
- const maybeTraverse = _optionalChain([path2, 'optionalAccess', _30 => _30.traverse]);
1063
- if (typeof maybeTraverse === "function") {
1064
- try {
1065
- return maybeTraverse.call(path2, {
1066
- StringLiteral(innerPath) {
1067
- handleEvalStringLiteral(innerPath, options, updater, handler);
1068
- },
1069
- TemplateElement(innerPath) {
1070
- handleEvalTemplateElement(innerPath, options, updater, handler);
1071
- }
1072
- });
1073
- } catch (error) {
1074
- const msg = _nullishCoalesce(_optionalChain([error, 'optionalAccess', _31 => _31.message]), () => ( ""));
1075
- const scopeError = /pass a scope and parentPath|traversing a Program\/File/i.test(msg);
1076
- if (!scopeError) {
1077
- throw error;
1078
- }
1079
- }
1080
- }
1081
- const getArgs = _optionalChain([path2, 'optionalAccess', _32 => _32.get, 'optionalCall', _33 => _33("arguments")]);
1082
- if (Array.isArray(getArgs)) {
1083
- for (const arg of getArgs) {
1084
- if (_optionalChain([arg, 'optionalAccess', _34 => _34.isStringLiteral, 'optionalCall', _35 => _35()])) {
1085
- handleEvalStringLiteral(arg, options, updater, handler);
1086
- continue;
1087
- }
1088
- if (_optionalChain([arg, 'optionalAccess', _36 => _36.isTemplateLiteral, 'optionalCall', _37 => _37()])) {
1089
- for (const quasi of arg.get("quasis")) {
1090
- handleEvalTemplateElement(quasi, options, updater, handler);
1091
- }
1092
- }
1093
- }
1094
- return;
1022
+ function babelParse(code, opts = {}) {
1023
+ const { cache, cacheKey, ...rest } = opts;
1024
+ const cacheKeyString = genCacheKey(code, _nullishCoalesce(cacheKey, () => ( rest)));
1025
+ let result;
1026
+ if (cache) {
1027
+ result = parseCache.get(cacheKeyString);
1095
1028
  }
1096
- const nodeArgs = _optionalChain([path2, 'optionalAccess', _38 => _38.node, 'optionalAccess', _39 => _39.arguments]);
1097
- if (Array.isArray(nodeArgs)) {
1098
- for (const n of nodeArgs) {
1099
- if (_optionalChain([n, 'optionalAccess', _40 => _40.type]) === "StringLiteral") {
1100
- const stub = {
1101
- node: n,
1102
- isStringLiteral: () => true
1103
- };
1104
- handleEvalStringLiteral(stub, options, updater, handler);
1105
- } else if (_optionalChain([n, 'optionalAccess', _41 => _41.type]) === "TemplateLiteral" && Array.isArray(n.quasis)) {
1106
- for (const q of n.quasis) {
1107
- const stub = {
1108
- node: q,
1109
- isTemplateElement: () => true
1110
- };
1111
- handleEvalTemplateElement(stub, options, updater, handler);
1112
- }
1113
- }
1029
+ if (!result) {
1030
+ const { cache: _cache, cacheKey: _cacheKey, ...parseOptions } = opts;
1031
+ result = _parser.parse.call(void 0, code, parseOptions);
1032
+ if (cache) {
1033
+ parseCache.set(cacheKeyString, result);
1114
1034
  }
1115
1035
  }
1036
+ return result;
1116
1037
  }
1117
1038
 
1118
- // src/js/handlers.ts
1039
+ // src/js/babel/process.ts
1040
+ var _magicstring = require('magic-string'); var _magicstring2 = _interopRequireDefault(_magicstring);
1119
1041
 
1042
+ // src/js/handlers.ts
1043
+ var _escape = require('@ast-core/escape');
1120
1044
 
1121
1045
  var _extractors = require('@weapp-tailwindcss/shared/extractors');
1122
1046
 
@@ -1211,17 +1135,17 @@ function shouldTransformClassName(candidate, {
1211
1135
  if (!classNameSet.has(candidate)) {
1212
1136
  return false;
1213
1137
  }
1214
- return !_optionalChain([jsPreserveClass, 'optionalCall', _42 => _42(candidate)]);
1138
+ return !_optionalChain([jsPreserveClass, 'optionalCall', _30 => _30(candidate)]);
1215
1139
  }
1216
- function extractLiteralValue(path2, { unescapeUnicode, arbitraryValues }) {
1217
- const allowDoubleQuotes = _optionalChain([arbitraryValues, 'optionalAccess', _43 => _43.allowDoubleQuotes]);
1140
+ function extractLiteralValue(path4, { unescapeUnicode, arbitraryValues }) {
1141
+ const allowDoubleQuotes = _optionalChain([arbitraryValues, 'optionalAccess', _31 => _31.allowDoubleQuotes]);
1218
1142
  let offset = 0;
1219
1143
  let original;
1220
- if (path2.isStringLiteral()) {
1144
+ if (path4.isStringLiteral()) {
1221
1145
  offset = 1;
1222
- original = path2.node.value;
1223
- } else if (path2.isTemplateElement()) {
1224
- original = path2.node.value.raw;
1146
+ original = path4.node.value;
1147
+ } else if (path4.isTemplateElement()) {
1148
+ original = path4.node.value.raw;
1225
1149
  } else {
1226
1150
  original = "";
1227
1151
  }
@@ -1236,7 +1160,7 @@ function extractLiteralValue(path2, { unescapeUnicode, arbitraryValues }) {
1236
1160
  original
1237
1161
  };
1238
1162
  }
1239
- function replaceHandleValue(path2, options) {
1163
+ function replaceHandleValue(path4, options) {
1240
1164
  const {
1241
1165
  escapeMap,
1242
1166
  needEscaped = false
@@ -1245,8 +1169,8 @@ function replaceHandleValue(path2, options) {
1245
1169
  if (!alwaysEscape && (!classNameSet || classNameSet.size === 0)) {
1246
1170
  return void 0;
1247
1171
  }
1248
- const { literal, original, allowDoubleQuotes, offset } = extractLiteralValue(path2, options);
1249
- if (hasIgnoreComment(path2.node)) {
1172
+ const { literal, original, allowDoubleQuotes, offset } = extractLiteralValue(path4, options);
1173
+ if (hasIgnoreComment(path4.node)) {
1250
1174
  return void 0;
1251
1175
  }
1252
1176
  const candidates = _extractors.splitCode.call(void 0, literal, allowDoubleQuotes);
@@ -1270,7 +1194,7 @@ function replaceHandleValue(path2, options) {
1270
1194
  mutated = true;
1271
1195
  }
1272
1196
  }
1273
- const node = path2.node;
1197
+ const node = path4.node;
1274
1198
  if (!mutated || typeof node.start !== "number" || typeof node.end !== "number") {
1275
1199
  return void 0;
1276
1200
  }
@@ -1284,88 +1208,266 @@ function replaceHandleValue(path2, options) {
1284
1208
  start,
1285
1209
  end,
1286
1210
  value,
1287
- path: path2
1211
+ path: path4
1288
1212
  };
1289
1213
  }
1290
1214
 
1291
- // src/js/JsTokenUpdater.ts
1292
- var JsTokenUpdater = class {
1293
- constructor({ value } = {}) {
1294
- this.tokens = value ? [...value] : [];
1215
+ // src/js/sourceAnalysis.ts
1216
+ function createModuleSpecifierReplacementToken(path4, replacement) {
1217
+ const node = path4.node;
1218
+ if (node.value === replacement) {
1219
+ return void 0;
1295
1220
  }
1296
- addToken(token) {
1297
- if (token) {
1298
- this.tokens.push(token);
1299
- }
1221
+ if (typeof node.start !== "number" || typeof node.end !== "number") {
1222
+ return void 0;
1300
1223
  }
1301
- push(...args) {
1302
- this.tokens.push(...args);
1303
- return this;
1224
+ const start = node.start + 1;
1225
+ const end = node.end - 1;
1226
+ if (start >= end) {
1227
+ return void 0;
1304
1228
  }
1305
- /**
1306
- * 待写入的 token 数量。
1307
- */
1308
- get length() {
1309
- return this.tokens.length;
1229
+ return {
1230
+ start,
1231
+ end,
1232
+ value: replacement,
1233
+ path: path4
1234
+ };
1235
+ }
1236
+ function collectModuleSpecifierReplacementTokens(analysis, replacements) {
1237
+ const tokens = [];
1238
+ const applyReplacement = (path4) => {
1239
+ const replacement = replacements[path4.node.value];
1240
+ if (!replacement) {
1241
+ return;
1242
+ }
1243
+ const token = createModuleSpecifierReplacementToken(path4, replacement);
1244
+ if (token) {
1245
+ tokens.push(token);
1246
+ }
1247
+ };
1248
+ for (const importPath of analysis.importDeclarations) {
1249
+ const source = importPath.get("source");
1250
+ if (source.isStringLiteral()) {
1251
+ applyReplacement(source);
1252
+ }
1310
1253
  }
1311
- map(callbackfn) {
1312
- this.tokens = this.tokens.map(callbackfn);
1313
- return this;
1254
+ for (const exportPath of analysis.exportDeclarations) {
1255
+ if (exportPath.isExportNamedDeclaration() || exportPath.isExportAllDeclaration()) {
1256
+ const source = exportPath.get("source");
1257
+ if (source && !Array.isArray(source) && source.isStringLiteral()) {
1258
+ applyReplacement(source);
1259
+ }
1260
+ }
1314
1261
  }
1315
- filter(callbackfn) {
1316
- this.tokens = this.tokens.filter(callbackfn);
1317
- return this;
1262
+ for (const literalPath of analysis.requireCallPaths) {
1263
+ applyReplacement(literalPath);
1318
1264
  }
1319
- updateMagicString(ms) {
1320
- for (const { start, end, value } of this.tokens) {
1321
- ms.update(start, end, value);
1265
+ for (const token of analysis.walker.imports) {
1266
+ const replacement = replacements[token.source];
1267
+ if (replacement) {
1268
+ token.source = replacement;
1322
1269
  }
1323
- return ms;
1324
1270
  }
1325
- };
1271
+ return tokens;
1272
+ }
1326
1273
 
1327
- // src/js/ModuleGraph.ts
1328
- var JsModuleGraph = class {
1329
- constructor(entry, graphOptions) {
1330
- this.modules = /* @__PURE__ */ new Map();
1331
- this.queue = [];
1332
- this.ignoredExportNames = /* @__PURE__ */ new Map();
1333
- this.resolve = graphOptions.resolve;
1334
- this.load = graphOptions.load;
1335
- this.filter = graphOptions.filter;
1336
- this.maxDepth = _nullishCoalesce(graphOptions.maxDepth, () => ( Number.POSITIVE_INFINITY));
1337
- const { moduleGraph: _moduleGraph, filename: _ignoredFilename, ...rest } = entry.handlerOptions;
1338
- this.baseOptions = {
1339
- ...rest,
1340
- filename: entry.filename
1341
- };
1342
- this.parserOptions = entry.handlerOptions.babelParserOptions;
1343
- this.rootFilename = entry.filename;
1344
- this.modules.set(entry.filename, {
1345
- filename: entry.filename,
1346
- source: entry.source,
1347
- analysis: entry.analysis
1348
- });
1349
- this.queue.push({ filename: entry.filename, depth: 0 });
1274
+ // src/js/babel/process.ts
1275
+ function processUpdatedSource(rawSource, options, analysis) {
1276
+ const { targetPaths, jsTokenUpdater, ignoredPaths } = analysis;
1277
+ const replacementTokens = [];
1278
+ for (const path4 of targetPaths) {
1279
+ if (ignoredPaths.has(path4)) {
1280
+ continue;
1281
+ }
1282
+ const token = replaceHandleValue(
1283
+ path4,
1284
+ {
1285
+ ...options,
1286
+ needEscaped: path4.isStringLiteral() ? _nullishCoalesce(options.needEscaped, () => ( true)) : false
1287
+ }
1288
+ );
1289
+ if (token) {
1290
+ replacementTokens.push(token);
1291
+ }
1350
1292
  }
1351
- build() {
1352
- this.collectDependencies();
1353
- const linked = {};
1354
- for (const [filename, state] of this.modules) {
1355
- if (filename === this.rootFilename) {
1293
+ if (options.moduleSpecifierReplacements) {
1294
+ replacementTokens.push(
1295
+ ...collectModuleSpecifierReplacementTokens(analysis, options.moduleSpecifierReplacements)
1296
+ );
1297
+ }
1298
+ if (jsTokenUpdater.length + replacementTokens.length === 0) {
1299
+ return new (0, _magicstring2.default)(rawSource);
1300
+ }
1301
+ const ms = new (0, _magicstring2.default)(rawSource);
1302
+ jsTokenUpdater.push(...replacementTokens).filter((token) => !ignoredPaths.has(token.path)).updateMagicString(ms);
1303
+ return ms;
1304
+ }
1305
+
1306
+ // src/js/evalTransforms.ts
1307
+
1308
+ function isEvalPath(path4) {
1309
+ if (path4.isCallExpression()) {
1310
+ const calleePath = path4.get("callee");
1311
+ return calleePath.isIdentifier({ name: "eval" });
1312
+ }
1313
+ return false;
1314
+ }
1315
+ function createEvalReplacementToken(path4, updated) {
1316
+ const node = path4.node;
1317
+ let offset = 0;
1318
+ let original;
1319
+ if (path4.isStringLiteral()) {
1320
+ offset = 1;
1321
+ original = path4.node.value;
1322
+ } else if (path4.isTemplateElement()) {
1323
+ original = path4.node.value.raw;
1324
+ } else {
1325
+ original = "";
1326
+ }
1327
+ if (typeof node.start !== "number" || typeof node.end !== "number") {
1328
+ return void 0;
1329
+ }
1330
+ const start = node.start + offset;
1331
+ const end = node.end - offset;
1332
+ if (start >= end) {
1333
+ return void 0;
1334
+ }
1335
+ if (original === updated) {
1336
+ return void 0;
1337
+ }
1338
+ const value = path4.isStringLiteral() ? _escape.jsStringEscape.call(void 0, updated) : updated;
1339
+ return {
1340
+ start,
1341
+ end,
1342
+ value,
1343
+ path: path4
1344
+ };
1345
+ }
1346
+ function handleEvalStringLiteral(path4, options, updater, handler) {
1347
+ const { code } = handler(path4.node.value, {
1348
+ ...options,
1349
+ needEscaped: false,
1350
+ generateMap: false
1351
+ });
1352
+ if (!code) {
1353
+ return;
1354
+ }
1355
+ const token = createEvalReplacementToken(path4, code);
1356
+ if (token) {
1357
+ updater.addToken(token);
1358
+ }
1359
+ }
1360
+ function handleEvalTemplateElement(path4, options, updater, handler) {
1361
+ const { code } = handler(path4.node.value.raw, {
1362
+ ...options,
1363
+ generateMap: false
1364
+ });
1365
+ if (!code) {
1366
+ return;
1367
+ }
1368
+ const token = createEvalReplacementToken(path4, code);
1369
+ if (token) {
1370
+ updater.addToken(token);
1371
+ }
1372
+ }
1373
+ function walkEvalExpression(path4, options, updater, handler) {
1374
+ const maybeTraverse = _optionalChain([path4, 'optionalAccess', _32 => _32.traverse]);
1375
+ if (typeof maybeTraverse === "function") {
1376
+ try {
1377
+ return maybeTraverse.call(path4, {
1378
+ StringLiteral(innerPath) {
1379
+ handleEvalStringLiteral(innerPath, options, updater, handler);
1380
+ },
1381
+ TemplateElement(innerPath) {
1382
+ handleEvalTemplateElement(innerPath, options, updater, handler);
1383
+ }
1384
+ });
1385
+ } catch (error) {
1386
+ const msg = _nullishCoalesce(_optionalChain([error, 'optionalAccess', _33 => _33.message]), () => ( ""));
1387
+ const scopeError = /pass a scope and parentPath|traversing a Program\/File/i.test(msg);
1388
+ if (!scopeError) {
1389
+ throw error;
1390
+ }
1391
+ }
1392
+ }
1393
+ const getArgs = _optionalChain([path4, 'optionalAccess', _34 => _34.get, 'optionalCall', _35 => _35("arguments")]);
1394
+ if (Array.isArray(getArgs)) {
1395
+ for (const arg of getArgs) {
1396
+ if (_optionalChain([arg, 'optionalAccess', _36 => _36.isStringLiteral, 'optionalCall', _37 => _37()])) {
1397
+ handleEvalStringLiteral(arg, options, updater, handler);
1356
1398
  continue;
1357
1399
  }
1358
- const childOptions = {
1359
- ...this.baseOptions,
1360
- filename
1361
- };
1362
- const ms = processUpdatedSource(state.source, childOptions, state.analysis);
1363
- const code = ms.toString();
1364
- if (code !== state.source) {
1365
- linked[filename] = { code };
1400
+ if (_optionalChain([arg, 'optionalAccess', _38 => _38.isTemplateLiteral, 'optionalCall', _39 => _39()])) {
1401
+ for (const quasi of arg.get("quasis")) {
1402
+ handleEvalTemplateElement(quasi, options, updater, handler);
1403
+ }
1404
+ }
1405
+ }
1406
+ return;
1407
+ }
1408
+ const nodeArgs = _optionalChain([path4, 'optionalAccess', _40 => _40.node, 'optionalAccess', _41 => _41.arguments]);
1409
+ if (Array.isArray(nodeArgs)) {
1410
+ for (const n of nodeArgs) {
1411
+ if (_optionalChain([n, 'optionalAccess', _42 => _42.type]) === "StringLiteral") {
1412
+ const stub = {
1413
+ node: n,
1414
+ isStringLiteral: () => true
1415
+ };
1416
+ handleEvalStringLiteral(stub, options, updater, handler);
1417
+ } else if (_optionalChain([n, 'optionalAccess', _43 => _43.type]) === "TemplateLiteral" && Array.isArray(n.quasis)) {
1418
+ for (const q of n.quasis) {
1419
+ const stub = {
1420
+ node: q,
1421
+ isTemplateElement: () => true
1422
+ };
1423
+ handleEvalTemplateElement(stub, options, updater, handler);
1424
+ }
1366
1425
  }
1367
1426
  }
1368
- return linked;
1427
+ }
1428
+ }
1429
+
1430
+ // src/js/JsTokenUpdater.ts
1431
+ var JsTokenUpdater = class {
1432
+ constructor({ value } = {}) {
1433
+ this.tokens = value ? [...value] : [];
1434
+ }
1435
+ addToken(token) {
1436
+ if (token) {
1437
+ this.tokens.push(token);
1438
+ }
1439
+ }
1440
+ push(...args) {
1441
+ this.tokens.push(...args);
1442
+ return this;
1443
+ }
1444
+ /**
1445
+ * 待写入的 token 数量。
1446
+ */
1447
+ get length() {
1448
+ return this.tokens.length;
1449
+ }
1450
+ map(callbackfn) {
1451
+ this.tokens = this.tokens.map(callbackfn);
1452
+ return this;
1453
+ }
1454
+ filter(callbackfn) {
1455
+ this.tokens = this.tokens.filter(callbackfn);
1456
+ return this;
1457
+ }
1458
+ updateMagicString(ms) {
1459
+ for (const { start, end, value } of this.tokens) {
1460
+ ms.update(start, end, value);
1461
+ }
1462
+ return ms;
1463
+ }
1464
+ };
1465
+
1466
+ // src/js/module-graph/ignored-exports.ts
1467
+ var IgnoredExportsTracker = class {
1468
+ constructor(options) {
1469
+ this.options = options;
1470
+ this.ignoredExportNames = /* @__PURE__ */ new Map();
1369
1471
  }
1370
1472
  addIgnoredExport(filename, exportName) {
1371
1473
  if (!exportName) {
@@ -1380,7 +1482,7 @@ var JsModuleGraph = class {
1380
1482
  return;
1381
1483
  }
1382
1484
  pending.add(exportName);
1383
- const existing = this.modules.get(filename);
1485
+ const existing = this.options.modules.get(filename);
1384
1486
  if (existing) {
1385
1487
  this.applyIgnoredExportsToAnalysis(filename, existing.analysis);
1386
1488
  }
@@ -1496,7 +1598,7 @@ var JsModuleGraph = class {
1496
1598
  for (const { specifier, exportName } of propagate) {
1497
1599
  let resolved;
1498
1600
  try {
1499
- resolved = this.resolve(specifier, filename);
1601
+ resolved = this.options.resolve(specifier, filename);
1500
1602
  } catch (e3) {
1501
1603
  resolved = void 0;
1502
1604
  }
@@ -1504,7 +1606,7 @@ var JsModuleGraph = class {
1504
1606
  pending.add(exportName);
1505
1607
  continue;
1506
1608
  }
1507
- if (this.filter && !this.filter(resolved, specifier, filename)) {
1609
+ if (this.options.filter && !this.options.filter(resolved, specifier, filename)) {
1508
1610
  pending.add(exportName);
1509
1611
  continue;
1510
1612
  }
@@ -1514,6 +1616,55 @@ var JsModuleGraph = class {
1514
1616
  pending.add(name);
1515
1617
  }
1516
1618
  }
1619
+ };
1620
+
1621
+ // src/js/ModuleGraph.ts
1622
+ var JsModuleGraph = class {
1623
+ constructor(entry, graphOptions) {
1624
+ this.modules = /* @__PURE__ */ new Map();
1625
+ this.queue = [];
1626
+ this.resolve = graphOptions.resolve;
1627
+ this.load = graphOptions.load;
1628
+ this.filter = graphOptions.filter;
1629
+ this.maxDepth = _nullishCoalesce(graphOptions.maxDepth, () => ( Number.POSITIVE_INFINITY));
1630
+ const { moduleGraph: _moduleGraph, filename: _ignoredFilename, ...rest } = entry.handlerOptions;
1631
+ this.baseOptions = {
1632
+ ...rest,
1633
+ filename: entry.filename
1634
+ };
1635
+ this.parserOptions = entry.handlerOptions.babelParserOptions;
1636
+ this.rootFilename = entry.filename;
1637
+ this.ignoredExports = new IgnoredExportsTracker({
1638
+ resolve: this.resolve,
1639
+ filter: this.filter,
1640
+ modules: this.modules
1641
+ });
1642
+ this.modules.set(entry.filename, {
1643
+ filename: entry.filename,
1644
+ source: entry.source,
1645
+ analysis: entry.analysis
1646
+ });
1647
+ this.queue.push({ filename: entry.filename, depth: 0 });
1648
+ }
1649
+ build() {
1650
+ this.collectDependencies();
1651
+ const linked = {};
1652
+ for (const [filename, state] of this.modules) {
1653
+ if (filename === this.rootFilename) {
1654
+ continue;
1655
+ }
1656
+ const childOptions = {
1657
+ ...this.baseOptions,
1658
+ filename
1659
+ };
1660
+ const ms = processUpdatedSource(state.source, childOptions, state.analysis);
1661
+ const code = ms.toString();
1662
+ if (code !== state.source) {
1663
+ linked[filename] = { code };
1664
+ }
1665
+ }
1666
+ return linked;
1667
+ }
1517
1668
  collectDependencies() {
1518
1669
  while (this.queue.length > 0) {
1519
1670
  const { filename, depth } = this.queue.shift();
@@ -1553,7 +1704,7 @@ var JsModuleGraph = class {
1553
1704
  continue;
1554
1705
  }
1555
1706
  if (tokens.length > 0) {
1556
- this.registerIgnoredExportsFromTokens(resolved, tokens);
1707
+ this.ignoredExports.registerIgnoredExportsFromTokens(resolved, tokens);
1557
1708
  }
1558
1709
  if (this.modules.has(resolved)) {
1559
1710
  continue;
@@ -1577,7 +1728,7 @@ var JsModuleGraph = class {
1577
1728
  ...this.baseOptions,
1578
1729
  filename: resolved
1579
1730
  });
1580
- this.applyIgnoredExportsToAnalysis(resolved, analysis);
1731
+ this.ignoredExports.applyIgnoredExportsToAnalysis(resolved, analysis);
1581
1732
  } catch (e6) {
1582
1733
  continue;
1583
1734
  }
@@ -1592,6 +1743,93 @@ var JsModuleGraph = class {
1592
1743
  }
1593
1744
  };
1594
1745
 
1746
+ // src/js/node-path-walker/export-handlers.ts
1747
+ function walkExportDeclaration(ctx, path4) {
1748
+ if (path4.isExportDeclaration()) {
1749
+ if (path4.isExportNamedDeclaration()) {
1750
+ walkExportNamedDeclaration(ctx, path4);
1751
+ } else if (path4.isExportDefaultDeclaration()) {
1752
+ walkExportDefaultDeclaration(ctx, path4);
1753
+ } else if (path4.isExportAllDeclaration()) {
1754
+ walkExportAllDeclaration(ctx, path4);
1755
+ }
1756
+ }
1757
+ }
1758
+ function walkExportNamedDeclaration(ctx, path4) {
1759
+ const declaration = path4.get("declaration");
1760
+ if (declaration.isVariableDeclaration()) {
1761
+ for (const decl of declaration.get("declarations")) {
1762
+ ctx.walkNode(decl);
1763
+ }
1764
+ }
1765
+ const specifiers = path4.get("specifiers");
1766
+ for (const spec of specifiers) {
1767
+ if (spec.isExportSpecifier()) {
1768
+ const local = spec.get("local");
1769
+ if (local.isIdentifier()) {
1770
+ ctx.walkNode(local);
1771
+ }
1772
+ }
1773
+ }
1774
+ }
1775
+ function walkExportDefaultDeclaration(ctx, path4) {
1776
+ const decl = path4.get("declaration");
1777
+ if (decl.isIdentifier()) {
1778
+ ctx.walkNode(decl);
1779
+ } else {
1780
+ ctx.walkNode(decl);
1781
+ }
1782
+ }
1783
+ function walkExportAllDeclaration(ctx, path4) {
1784
+ const source = path4.get("source");
1785
+ if (source.isStringLiteral()) {
1786
+ ctx.imports.add(
1787
+ {
1788
+ declaration: path4,
1789
+ source: source.node.value,
1790
+ type: "ExportAllDeclaration"
1791
+ }
1792
+ );
1793
+ }
1794
+ }
1795
+
1796
+ // src/js/node-path-walker/import-tokens.ts
1797
+ function maybeAddImportToken(imports, arg) {
1798
+ if (!(arg.isImportSpecifier() && arg.node.importKind !== "type" || arg.isImportDefaultSpecifier())) {
1799
+ return false;
1800
+ }
1801
+ const importDeclaration = arg.parentPath;
1802
+ if (!importDeclaration.isImportDeclaration() || importDeclaration.node.importKind === "type") {
1803
+ return false;
1804
+ }
1805
+ if (arg.isImportSpecifier()) {
1806
+ const imported = arg.get("imported");
1807
+ if (imported.isIdentifier()) {
1808
+ imports.add(
1809
+ {
1810
+ declaration: importDeclaration,
1811
+ specifier: arg,
1812
+ imported: imported.node.name,
1813
+ local: arg.node.local.name,
1814
+ source: importDeclaration.node.source.value,
1815
+ type: "ImportSpecifier"
1816
+ }
1817
+ );
1818
+ }
1819
+ return true;
1820
+ }
1821
+ imports.add(
1822
+ {
1823
+ declaration: importDeclaration,
1824
+ specifier: arg,
1825
+ local: arg.node.local.name,
1826
+ source: importDeclaration.node.source.value,
1827
+ type: "ImportDefaultSpecifier"
1828
+ }
1829
+ );
1830
+ return true;
1831
+ }
1832
+
1595
1833
  // src/js/NodePathWalker.ts
1596
1834
  var NodePathWalker = class {
1597
1835
  constructor({ ignoreCallExpressionIdentifiers, callback } = {}) {
@@ -1602,35 +1840,35 @@ var NodePathWalker = class {
1602
1840
  this.visited = /* @__PURE__ */ new WeakSet();
1603
1841
  this.isIgnoredCallIdentifier = createNameMatcher(this.ignoreCallExpressionIdentifiers, { exact: true });
1604
1842
  }
1605
- walkVariableDeclarator(path2) {
1606
- const init = path2.get("init");
1843
+ walkVariableDeclarator(path4) {
1844
+ const init = path4.get("init");
1607
1845
  this.walkNode(init);
1608
1846
  }
1609
- walkTemplateLiteral(path2) {
1610
- for (const exp of path2.get("expressions")) {
1847
+ walkTemplateLiteral(path4) {
1848
+ for (const exp of path4.get("expressions")) {
1611
1849
  this.walkNode(exp);
1612
1850
  }
1613
- for (const quasis of path2.get("quasis")) {
1851
+ for (const quasis of path4.get("quasis")) {
1614
1852
  this.callback(quasis);
1615
1853
  }
1616
1854
  }
1617
- walkStringLiteral(path2) {
1618
- this.callback(path2);
1855
+ walkStringLiteral(path4) {
1856
+ this.callback(path4);
1619
1857
  }
1620
- walkBinaryExpression(path2) {
1621
- const left = path2.get("left");
1858
+ walkBinaryExpression(path4) {
1859
+ const left = path4.get("left");
1622
1860
  this.walkNode(left);
1623
- const right = path2.get("right");
1861
+ const right = path4.get("right");
1624
1862
  this.walkNode(right);
1625
1863
  }
1626
- walkLogicalExpression(path2) {
1627
- const left = path2.get("left");
1864
+ walkLogicalExpression(path4) {
1865
+ const left = path4.get("left");
1628
1866
  this.walkNode(left);
1629
- const right = path2.get("right");
1867
+ const right = path4.get("right");
1630
1868
  this.walkNode(right);
1631
1869
  }
1632
- walkObjectExpression(path2) {
1633
- const props = path2.get("properties");
1870
+ walkObjectExpression(path4) {
1871
+ const props = path4.get("properties");
1634
1872
  for (const prop of props) {
1635
1873
  if (prop.isObjectProperty()) {
1636
1874
  const key = prop.get("key");
@@ -1640,8 +1878,8 @@ var NodePathWalker = class {
1640
1878
  }
1641
1879
  }
1642
1880
  }
1643
- walkArrayExpression(path2) {
1644
- const elements = path2.get("elements");
1881
+ walkArrayExpression(path4) {
1882
+ const elements = path4.get("elements");
1645
1883
  for (const element of elements) {
1646
1884
  this.walkNode(element);
1647
1885
  }
@@ -1680,157 +1918,34 @@ var NodePathWalker = class {
1680
1918
  this.walkArrayExpression(arg);
1681
1919
  } else if (arg.isVariableDeclarator()) {
1682
1920
  this.walkVariableDeclarator(arg);
1683
- } else if (arg.isImportSpecifier() && arg.node.importKind !== "type" || arg.isImportDefaultSpecifier()) {
1684
- const importDeclaration = arg.parentPath;
1685
- if (importDeclaration.isImportDeclaration() && importDeclaration.node.importKind !== "type") {
1686
- if (arg.isImportSpecifier()) {
1687
- const imported = arg.get("imported");
1688
- if (imported.isIdentifier()) {
1689
- this.imports.add(
1690
- {
1691
- declaration: importDeclaration,
1692
- specifier: arg,
1693
- imported: imported.node.name,
1694
- local: arg.node.local.name,
1695
- source: importDeclaration.node.source.value,
1696
- type: "ImportSpecifier"
1697
- }
1698
- );
1699
- }
1700
- } else if (arg.isImportDefaultSpecifier()) {
1701
- this.imports.add(
1702
- {
1703
- declaration: importDeclaration,
1704
- specifier: arg,
1705
- local: arg.node.local.name,
1706
- source: importDeclaration.node.source.value,
1707
- type: "ImportDefaultSpecifier"
1708
- }
1709
- );
1710
- }
1711
- }
1921
+ } else if (maybeAddImportToken(this.imports, arg)) {
1712
1922
  }
1713
1923
  }
1714
1924
  /**
1715
1925
  * Walk the arguments of a desired call expression so their bindings can be analysed.
1716
1926
  */
1717
- walkCallExpression(path2) {
1718
- const calleePath = path2.get("callee");
1927
+ walkCallExpression(path4) {
1928
+ const calleePath = path4.get("callee");
1719
1929
  if (calleePath.isIdentifier() && this.isIgnoredCallIdentifier(calleePath.node.name)) {
1720
- for (const arg of path2.get("arguments")) {
1930
+ for (const arg of path4.get("arguments")) {
1721
1931
  this.walkNode(arg);
1722
1932
  }
1723
1933
  }
1724
1934
  }
1725
- walkExportDeclaration(path2) {
1726
- if (path2.isExportDeclaration()) {
1727
- if (path2.isExportNamedDeclaration()) {
1728
- this.walkExportNamedDeclaration(path2);
1729
- } else if (path2.isExportDefaultDeclaration()) {
1730
- this.walkExportDefaultDeclaration(path2);
1731
- } else if (path2.isExportAllDeclaration()) {
1732
- this.walkExportAllDeclaration(path2);
1733
- }
1734
- }
1935
+ walkExportDeclaration(path4) {
1936
+ walkExportDeclaration(this, path4);
1735
1937
  }
1736
- walkExportNamedDeclaration(path2) {
1737
- const declaration = path2.get("declaration");
1738
- if (declaration.isVariableDeclaration()) {
1739
- for (const decl of declaration.get("declarations")) {
1740
- this.walkNode(decl);
1741
- }
1742
- }
1743
- const specifiers = path2.get("specifiers");
1744
- for (const spec of specifiers) {
1745
- if (spec.isExportSpecifier()) {
1746
- const local = spec.get("local");
1747
- if (local.isIdentifier()) {
1748
- this.walkNode(local);
1749
- }
1750
- }
1751
- }
1938
+ walkExportNamedDeclaration(path4) {
1939
+ walkExportNamedDeclaration(this, path4);
1752
1940
  }
1753
- walkExportDefaultDeclaration(path2) {
1754
- const decl = path2.get("declaration");
1755
- if (decl.isIdentifier()) {
1756
- this.walkNode(decl);
1757
- } else {
1758
- this.walkNode(decl);
1759
- }
1941
+ walkExportDefaultDeclaration(path4) {
1942
+ walkExportDefaultDeclaration(this, path4);
1760
1943
  }
1761
- walkExportAllDeclaration(path2) {
1762
- const source = path2.get("source");
1763
- if (source.isStringLiteral()) {
1764
- this.imports.add(
1765
- {
1766
- declaration: path2,
1767
- source: source.node.value,
1768
- type: "ExportAllDeclaration"
1769
- }
1770
- );
1771
- }
1944
+ walkExportAllDeclaration(path4) {
1945
+ walkExportAllDeclaration(this, path4);
1772
1946
  }
1773
1947
  };
1774
1948
 
1775
- // src/js/sourceAnalysis.ts
1776
- function createModuleSpecifierReplacementToken(path2, replacement) {
1777
- const node = path2.node;
1778
- if (node.value === replacement) {
1779
- return void 0;
1780
- }
1781
- if (typeof node.start !== "number" || typeof node.end !== "number") {
1782
- return void 0;
1783
- }
1784
- const start = node.start + 1;
1785
- const end = node.end - 1;
1786
- if (start >= end) {
1787
- return void 0;
1788
- }
1789
- return {
1790
- start,
1791
- end,
1792
- value: replacement,
1793
- path: path2
1794
- };
1795
- }
1796
- function collectModuleSpecifierReplacementTokens(analysis, replacements) {
1797
- const tokens = [];
1798
- const applyReplacement = (path2) => {
1799
- const replacement = replacements[path2.node.value];
1800
- if (!replacement) {
1801
- return;
1802
- }
1803
- const token = createModuleSpecifierReplacementToken(path2, replacement);
1804
- if (token) {
1805
- tokens.push(token);
1806
- }
1807
- };
1808
- for (const importPath of analysis.importDeclarations) {
1809
- const source = importPath.get("source");
1810
- if (source.isStringLiteral()) {
1811
- applyReplacement(source);
1812
- }
1813
- }
1814
- for (const exportPath of analysis.exportDeclarations) {
1815
- if (exportPath.isExportNamedDeclaration() || exportPath.isExportAllDeclaration()) {
1816
- const source = exportPath.get("source");
1817
- if (source && !Array.isArray(source) && source.isStringLiteral()) {
1818
- applyReplacement(source);
1819
- }
1820
- }
1821
- }
1822
- for (const literalPath of analysis.requireCallPaths) {
1823
- applyReplacement(literalPath);
1824
- }
1825
- for (const token of analysis.walker.imports) {
1826
- const replacement = replacements[token.source];
1827
- if (replacement) {
1828
- token.source = replacement;
1829
- }
1830
- }
1831
- return tokens;
1832
- }
1833
-
1834
1949
  // src/js/taggedTemplateIgnore.ts
1835
1950
  function createTaggedTemplateIgnore({ matcher, names }) {
1836
1951
  const bindingIgnoreCache = /* @__PURE__ */ new Map();
@@ -1852,12 +1967,12 @@ function createTaggedTemplateIgnore({ matcher, names }) {
1852
1967
  }
1853
1968
  return false;
1854
1969
  };
1855
- const resolvesMemberExpressionToIgnore = (path2, seen) => {
1856
- const propertyPath = path2.get("property");
1970
+ const resolvesMemberExpressionToIgnore = (path4, seen) => {
1971
+ const propertyPath = path4.get("property");
1857
1972
  if (propertyMatches(propertyPath)) {
1858
1973
  return true;
1859
1974
  }
1860
- const objectPath = path2.get("object");
1975
+ const objectPath = path4.get("object");
1861
1976
  if (objectPath.isIdentifier()) {
1862
1977
  const scope = _optionalChain([objectPath, 'optionalAccess', _59 => _59.scope]);
1863
1978
  const binding = _optionalChain([scope, 'optionalAccess', _60 => _60.getBinding, 'optionalCall', _61 => _61(objectPath.node.name)]);
@@ -1985,42 +2100,15 @@ function createTaggedTemplateIgnore({ matcher, names }) {
1985
2100
  // src/js/babel.ts
1986
2101
  var EXPRESSION_WRAPPER_PREFIX = "(\n";
1987
2102
  var EXPRESSION_WRAPPER_SUFFIX = "\n)";
1988
- var parseCache = new (0, _lrucache.LRUCache)(
1989
- {
1990
- max: 1024
1991
- }
1992
- );
1993
- function genCacheKey(source, options) {
1994
- if (typeof options === "string") {
1995
- return source + options;
1996
- }
1997
- return source + JSON.stringify(options, (_, val) => typeof val === "function" ? val.toString() : val);
1998
- }
1999
- function babelParse(code, opts = {}) {
2000
- const { cache, cacheKey, ...rest } = opts;
2001
- const cacheKeyString = genCacheKey(code, _nullishCoalesce(cacheKey, () => ( rest)));
2002
- let result;
2003
- if (cache) {
2004
- result = parseCache.get(cacheKeyString);
2005
- }
2006
- if (!result) {
2007
- const { cache: _cache, cacheKey: _cacheKey, ...parseOptions } = opts;
2008
- result = _parser.parse.call(void 0, code, parseOptions);
2009
- if (cache) {
2010
- parseCache.set(cacheKeyString, result);
2011
- }
2012
- }
2013
- return result;
2014
- }
2015
2103
  function analyzeSource(ast, options, handler) {
2016
2104
  const jsTokenUpdater = new JsTokenUpdater();
2017
2105
  const ignoredPaths = /* @__PURE__ */ new WeakSet();
2018
2106
  const walker = new NodePathWalker(
2019
2107
  {
2020
2108
  ignoreCallExpressionIdentifiers: options.ignoreCallExpressionIdentifiers,
2021
- callback(path2) {
2022
- if (path2.isStringLiteral() || path2.isTemplateElement()) {
2023
- ignoredPaths.add(path2);
2109
+ callback(path4) {
2110
+ if (path4.isStringLiteral() || path4.isTemplateElement()) {
2111
+ ignoredPaths.add(path4);
2024
2112
  }
2025
2113
  }
2026
2114
  }
@@ -2107,36 +2195,6 @@ function analyzeSource(ast, options, handler) {
2107
2195
  ignoredPaths
2108
2196
  };
2109
2197
  }
2110
- function processUpdatedSource(rawSource, options, analysis) {
2111
- const { targetPaths, jsTokenUpdater, ignoredPaths } = analysis;
2112
- const replacementTokens = [];
2113
- for (const path2 of targetPaths) {
2114
- if (ignoredPaths.has(path2)) {
2115
- continue;
2116
- }
2117
- const token = replaceHandleValue(
2118
- path2,
2119
- {
2120
- ...options,
2121
- needEscaped: path2.isStringLiteral() ? _nullishCoalesce(options.needEscaped, () => ( true)) : false
2122
- }
2123
- );
2124
- if (token) {
2125
- replacementTokens.push(token);
2126
- }
2127
- }
2128
- if (options.moduleSpecifierReplacements) {
2129
- replacementTokens.push(
2130
- ...collectModuleSpecifierReplacementTokens(analysis, options.moduleSpecifierReplacements)
2131
- );
2132
- }
2133
- if (jsTokenUpdater.length + replacementTokens.length === 0) {
2134
- return new (0, _magicstring2.default)(rawSource);
2135
- }
2136
- const ms = new (0, _magicstring2.default)(rawSource);
2137
- jsTokenUpdater.push(...replacementTokens).filter((token) => !ignoredPaths.has(token.path)).updateMagicString(ms);
2138
- return ms;
2139
- }
2140
2198
  function jsHandler(rawSource, options) {
2141
2199
  const shouldWrapExpression = Boolean(options.wrapExpression);
2142
2200
  const source = shouldWrapExpression ? `${EXPRESSION_WRAPPER_PREFIX}${rawSource}${EXPRESSION_WRAPPER_SUFFIX}` : rawSource;
@@ -2227,11 +2285,6 @@ function createJsHandler(options) {
2227
2285
  return handler;
2228
2286
  }
2229
2287
 
2230
- // src/wxml/utils.ts
2231
- var _types = require('@babel/types'); var t = _interopRequireWildcard(_types);
2232
- var _htmlparser2 = require('htmlparser2');
2233
-
2234
-
2235
2288
  // src/wxml/custom-attributes.ts
2236
2289
  function regTest(reg, str) {
2237
2290
  reg.lastIndex = 0;
@@ -2301,6 +2354,78 @@ function createAttributeMatcher(entities) {
2301
2354
  };
2302
2355
  }
2303
2356
 
2357
+ // src/wxml/utils/codegen/legacy-rewriter.ts
2358
+
2359
+
2360
+ // src/wxml/utils/codegen/legacy-visitor.ts
2361
+ var _types = require('@babel/types'); var t = _interopRequireWildcard(_types);
2362
+ function shouldSkipLegacyStringLiteral(path4) {
2363
+ if (t.isMemberExpression(path4.parent)) {
2364
+ return true;
2365
+ }
2366
+ return Boolean(
2367
+ t.isBinaryExpression(path4.parent) && (t.isConditionalExpression(_optionalChain([path4, 'access', _81 => _81.parentPath, 'optionalAccess', _82 => _82.parent])) || t.isLogicalExpression(_optionalChain([path4, 'access', _83 => _83.parentPath, 'optionalAccess', _84 => _84.parent])))
2368
+ );
2369
+ }
2370
+ function createLegacyTraverseOptions(options, jsTokenUpdater) {
2371
+ return {
2372
+ StringLiteral(path4) {
2373
+ if (shouldSkipLegacyStringLiteral(path4)) {
2374
+ return;
2375
+ }
2376
+ jsTokenUpdater.addToken(
2377
+ replaceHandleValue(
2378
+ path4,
2379
+ {
2380
+ escapeMap: options.escapeMap,
2381
+ classNameSet: options.runtimeSet,
2382
+ needEscaped: true,
2383
+ alwaysEscape: true
2384
+ }
2385
+ )
2386
+ );
2387
+ },
2388
+ noScope: true
2389
+ };
2390
+ }
2391
+
2392
+ // src/wxml/utils/codegen/legacy-rewriter.ts
2393
+ function rewriteLegacyExpression(match, options) {
2394
+ const ms = new (0, _magicstring2.default)(match);
2395
+ const ast = _parser.parseExpression.call(void 0, match);
2396
+ const jsTokenUpdater = new JsTokenUpdater();
2397
+ traverse(ast, createLegacyTraverseOptions(options, jsTokenUpdater));
2398
+ jsTokenUpdater.updateMagicString(ms);
2399
+ return ms.toString();
2400
+ }
2401
+
2402
+ // src/wxml/utils/codegen.ts
2403
+ function generateCode(match, options = {}) {
2404
+ try {
2405
+ const { jsHandler: jsHandler2, runtimeSet } = options;
2406
+ if (jsHandler2 && runtimeSet) {
2407
+ const runHandler = (wrap) => jsHandler2(match, runtimeSet, wrap ? { wrapExpression: true } : void 0);
2408
+ const initial = runHandler(options.wrapExpression);
2409
+ if (!initial.error || options.wrapExpression) {
2410
+ return initial.code;
2411
+ }
2412
+ const fallback = runHandler(true);
2413
+ return fallback.code;
2414
+ } else {
2415
+ return rewriteLegacyExpression(match, options);
2416
+ }
2417
+ } catch (e7) {
2418
+ return match;
2419
+ }
2420
+ }
2421
+
2422
+ // src/wxml/utils/custom-template.ts
2423
+ var _htmlparser2 = require('htmlparser2');
2424
+
2425
+
2426
+ // src/wxml/utils/template-fragments.ts
2427
+
2428
+
2304
2429
  // src/wxml/whitespace.ts
2305
2430
  var WHITESPACE_CODES = /* @__PURE__ */ new Set([
2306
2431
  9,
@@ -2452,110 +2577,62 @@ var Tokenizer = class {
2452
2577
  }
2453
2578
  };
2454
2579
 
2455
- // src/wxml/utils.ts
2456
- function generateCode(match, options = {}) {
2457
- try {
2458
- const { jsHandler: jsHandler2, runtimeSet } = options;
2459
- if (jsHandler2 && runtimeSet) {
2460
- const runHandler = (wrap) => jsHandler2(match, runtimeSet, wrap ? { wrapExpression: true } : void 0);
2461
- const initial = runHandler(options.wrapExpression);
2462
- if (!initial.error || options.wrapExpression) {
2463
- return initial.code;
2464
- }
2465
- const fallback = runHandler(true);
2466
- return fallback.code;
2467
- } else {
2468
- const ms = new (0, _magicstring2.default)(match);
2469
- const ast = _parser.parseExpression.call(void 0, match);
2470
- const jsTokenUpdater = new JsTokenUpdater();
2471
- traverse(ast, {
2472
- StringLiteral(path2) {
2473
- if (t.isMemberExpression(path2.parent)) {
2474
- return;
2475
- }
2476
- if (t.isBinaryExpression(path2.parent) && (t.isConditionalExpression(_optionalChain([path2, 'access', _81 => _81.parentPath, 'optionalAccess', _82 => _82.parent])) || t.isLogicalExpression(_optionalChain([path2, 'access', _83 => _83.parentPath, 'optionalAccess', _84 => _84.parent])))) {
2477
- return;
2478
- }
2479
- jsTokenUpdater.addToken(
2480
- replaceHandleValue(
2481
- path2,
2482
- {
2483
- escapeMap: options.escapeMap,
2484
- classNameSet: options.runtimeSet,
2485
- needEscaped: true,
2486
- alwaysEscape: true
2487
- }
2488
- )
2489
- );
2490
- },
2491
- noScope: true
2492
- });
2493
- jsTokenUpdater.updateMagicString(ms);
2494
- return ms.toString();
2495
- }
2496
- } catch (e7) {
2497
- return match;
2498
- }
2580
+ // src/wxml/utils/fragment-helpers.ts
2581
+ function updateWhitespaceGap(ms, start, end, options) {
2582
+ const gap = ms.slice(start, end);
2583
+ if (isAllWhitespace(gap)) {
2584
+ ms.update(start, end, replaceWxml(gap, {
2585
+ keepEOL: false,
2586
+ escapeMap: options.escapeMap,
2587
+ ignoreHead: true
2588
+ }));
2589
+ }
2590
+ }
2591
+ function updateWxmlSegment(ms, start, end, options, keepEOL, ignoreHead) {
2592
+ ms.update(start, end, replaceWxml(ms.slice(start, end), {
2593
+ keepEOL,
2594
+ escapeMap: options.escapeMap,
2595
+ ignoreHead
2596
+ }));
2499
2597
  }
2598
+ function updateExpressionSegment(ms, exp, options) {
2599
+ const code = `{{${generateCode(exp.value.slice(2, -2), options)}}}`;
2600
+ ms.update(exp.start, exp.end, code);
2601
+ }
2602
+
2603
+ // src/wxml/utils/fragment-updater.ts
2500
2604
  function handleEachClassFragment(ms, tokens, options = {}) {
2501
2605
  let previousEnd = 0;
2502
2606
  for (const token of tokens) {
2503
2607
  if (token.start > previousEnd) {
2504
- const gap = ms.slice(previousEnd, token.start);
2505
- if (isAllWhitespace(gap)) {
2506
- ms.update(previousEnd, token.start, replaceWxml(gap, {
2507
- keepEOL: false,
2508
- escapeMap: options.escapeMap,
2509
- ignoreHead: true
2510
- }));
2511
- }
2608
+ updateWhitespaceGap(ms, previousEnd, token.start, options);
2512
2609
  }
2513
2610
  let p = token.start;
2514
2611
  if (token.expressions.length > 0) {
2515
2612
  for (const exp of token.expressions) {
2516
2613
  if (exp.start > token.start && p < exp.start) {
2517
- ms.update(p, exp.start, replaceWxml(ms.slice(p, exp.start), {
2518
- keepEOL: true,
2519
- escapeMap: options.escapeMap,
2520
- // 首的str才会被转译
2521
- // example: 2xl:xx 2x{{y}}
2522
- ignoreHead: p > 0
2523
- }));
2614
+ updateWxmlSegment(ms, p, exp.start, options, true, p > 0);
2524
2615
  }
2525
- const code = `{{${generateCode(exp.value.slice(2, -2), options)}}}`;
2526
- ms.update(exp.start, exp.end, code);
2616
+ updateExpressionSegment(ms, exp, options);
2527
2617
  p = exp.end;
2528
2618
  }
2529
2619
  if (token.end > p) {
2530
- ms.update(p, token.end, replaceWxml(ms.slice(p, token.end), {
2531
- keepEOL: false,
2532
- escapeMap: options.escapeMap,
2533
- ignoreHead: true
2534
- }));
2620
+ updateWxmlSegment(ms, p, token.end, options, false, true);
2535
2621
  }
2536
2622
  } else {
2537
- ms.update(token.start, token.end, replaceWxml(token.value, {
2538
- keepEOL: false,
2539
- escapeMap: options.escapeMap,
2540
- ignoreHead: false
2541
- }));
2623
+ updateWxmlSegment(ms, token.start, token.end, options, false, false);
2542
2624
  }
2543
2625
  previousEnd = token.end;
2544
2626
  }
2545
2627
  if (tokens.length > 0) {
2546
2628
  const lastToken = tokens[tokens.length - 1];
2547
2629
  if (lastToken.end < ms.original.length) {
2548
- const gap = ms.slice(lastToken.end, ms.original.length);
2549
- if (isAllWhitespace(gap)) {
2550
- ms.update(lastToken.end, ms.original.length, replaceWxml(gap, {
2551
- keepEOL: false,
2552
- escapeMap: options.escapeMap,
2553
- ignoreHead: true
2554
- }));
2555
- }
2630
+ updateWhitespaceGap(ms, lastToken.end, ms.original.length, options);
2556
2631
  }
2557
2632
  }
2558
2633
  }
2634
+
2635
+ // src/wxml/utils/template-fragments.ts
2559
2636
  function templateReplacer(original, options = {}) {
2560
2637
  const ms = new (0, _magicstring2.default)(original);
2561
2638
  const tokenizer = new Tokenizer();
@@ -2563,6 +2640,8 @@ function templateReplacer(original, options = {}) {
2563
2640
  handleEachClassFragment(ms, tokens, options);
2564
2641
  return ms.toString();
2565
2642
  }
2643
+
2644
+ // src/wxml/utils/custom-template.ts
2566
2645
  async function customTemplateHandler(rawSource, options) {
2567
2646
  const {
2568
2647
  customAttributesEntities = [],
@@ -2628,6 +2707,8 @@ async function customTemplateHandler(rawSource, options) {
2628
2707
  }
2629
2708
  return s.toString();
2630
2709
  }
2710
+
2711
+ // src/wxml/utils.ts
2631
2712
  function createTemplateHandler(options = {}) {
2632
2713
  return (rawSource, opt = {}) => {
2633
2714
  return customTemplateHandler(rawSource, _chunkDYLQ6UOIjs.defuOverrideArray.call(void 0, opt, options));
@@ -2771,15 +2852,15 @@ function createInternalCompilerContext(opts) {
2771
2852
  );
2772
2853
  ctx.escapeMap = ctx.customReplaceDictionary;
2773
2854
  applyLoggerLevel(ctx.logLevel);
2774
- const twPatcher = _chunk5O6237HXjs.createTailwindcssPatcherFromContext.call(void 0, ctx);
2855
+ const twPatcher = _chunk4RUFPPI6js.createTailwindcssPatcherFromContext.call(void 0, ctx);
2775
2856
  logTailwindcssTarget("runtime", twPatcher, ctx.tailwindcssBasedir);
2776
2857
  if (_optionalChain([twPatcher, 'access', _95 => _95.packageInfo, 'optionalAccess', _96 => _96.version])) {
2777
2858
  _logger.logger.success(`\u5F53\u524D\u4F7F\u7528 ${_logger.pc.cyanBright("Tailwind CSS")} \u7248\u672C\u4E3A: ${_logger.pc.underline(_logger.pc.bold(_logger.pc.green(twPatcher.packageInfo.version)))}`);
2778
2859
  } else {
2779
2860
  _logger.logger.warn(`${_logger.pc.cyanBright("Tailwind CSS")} \u672A\u5B89\u88C5\uFF0C\u5DF2\u8DF3\u8FC7\u7248\u672C\u68C0\u6D4B\u4E0E\u8865\u4E01\u5E94\u7528\u3002`);
2780
2861
  }
2781
- _chunk5O6237HXjs.warnMissingCssEntries.call(void 0, ctx, twPatcher);
2782
- const cssCalcOptions = _chunk5O6237HXjs.applyV4CssCalcDefaults.call(void 0, ctx.cssCalc, twPatcher);
2862
+ _chunk4RUFPPI6js.warnMissingCssEntries.call(void 0, ctx, twPatcher);
2863
+ const cssCalcOptions = _chunk4RUFPPI6js.applyV4CssCalcDefaults.call(void 0, ctx.cssCalc, twPatcher);
2783
2864
  ctx.cssCalc = cssCalcOptions;
2784
2865
  const customAttributesEntities = toCustomAttributesEntities(ctx.customAttributes);
2785
2866
  const { styleHandler, jsHandler: jsHandler2, templateHandler } = createHandlersFromContext(
@@ -2798,7 +2879,7 @@ function createInternalCompilerContext(opts) {
2798
2879
  await clearTailwindcssPatcherCache(previousPatcher);
2799
2880
  }
2800
2881
  invalidateRuntimeClassSet(previousPatcher);
2801
- const nextPatcher = _chunk5O6237HXjs.createTailwindcssPatcherFromContext.call(void 0, ctx);
2882
+ const nextPatcher = _chunk4RUFPPI6js.createTailwindcssPatcherFromContext.call(void 0, ctx);
2802
2883
  Object.assign(previousPatcher, nextPatcher);
2803
2884
  ctx.twPatcher = previousPatcher;
2804
2885
  return previousPatcher;
@@ -2830,4 +2911,4 @@ function getCompilerContext(opts) {
2830
2911
 
2831
2912
 
2832
2913
 
2833
- exports.createDebug = createDebug; exports.createTailwindPatchPromise = createTailwindPatchPromise; exports.refreshTailwindRuntimeState = refreshTailwindRuntimeState; exports.collectRuntimeClassSet = collectRuntimeClassSet; exports.pluginName = pluginName; exports.vitePluginName = vitePluginName; exports.WEAPP_TW_REQUIRED_NODE_VERSION = WEAPP_TW_REQUIRED_NODE_VERSION; exports.logTailwindcssTarget = logTailwindcssTarget; exports.createPatchTargetRecorder = createPatchTargetRecorder; exports.toCustomAttributesEntities = toCustomAttributesEntities; exports.replaceWxml = replaceWxml; exports.createAttributeMatcher = createAttributeMatcher; exports.generateCode = generateCode; exports.clearTailwindcssPatcherCache = clearTailwindcssPatcherCache; exports.getCompilerContext = getCompilerContext;
2914
+ exports.createDebug = createDebug; exports.createTailwindPatchPromise = createTailwindPatchPromise; exports.refreshTailwindRuntimeState = refreshTailwindRuntimeState; exports.collectRuntimeClassSet = collectRuntimeClassSet; exports.pluginName = pluginName; exports.vitePluginName = vitePluginName; exports.WEAPP_TW_REQUIRED_NODE_VERSION = WEAPP_TW_REQUIRED_NODE_VERSION; exports.createPatchTargetRecorder = createPatchTargetRecorder; exports.logTailwindcssTarget = logTailwindcssTarget; exports.toCustomAttributesEntities = toCustomAttributesEntities; exports.replaceWxml = replaceWxml; exports.createAttributeMatcher = createAttributeMatcher; exports.generateCode = generateCode; exports.clearTailwindcssPatcherCache = clearTailwindcssPatcherCache; exports.getCompilerContext = getCompilerContext;