weapp-tailwindcss 4.7.2 → 4.7.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 (46) hide show
  1. package/dist/{chunk-Z2H7M33Z.mjs → chunk-6IYMPBCH.mjs} +107 -31
  2. package/dist/{chunk-5BW6X6AJ.mjs → chunk-FPX2BD2A.mjs} +2 -2
  3. package/dist/{chunk-2SI3KT2H.js → chunk-HMTZ4JJN.js} +2 -2
  4. package/dist/{chunk-GNWJEIZZ.js → chunk-I6FBWASF.js} +114 -38
  5. package/dist/{chunk-Q6PLZCM6.mjs → chunk-JII7EQ6K.mjs} +1 -1
  6. package/dist/{chunk-FPDJ3BCM.js → chunk-QA6SPWSQ.js} +120 -100
  7. package/dist/chunk-R7GWRQDJ.js +15 -0
  8. package/dist/chunk-SCOGAO45.mjs +18 -0
  9. package/dist/{chunk-OPTIAB5G.js → chunk-SIZNRUIV.js} +4 -4
  10. package/dist/{chunk-QZRXYCOQ.js → chunk-T5BSWDY2.js} +5 -5
  11. package/dist/{chunk-JYCQWWYU.mjs → chunk-V35QS2PT.mjs} +116 -96
  12. package/dist/cli.js +383 -15
  13. package/dist/cli.mjs +382 -15
  14. package/dist/core.js +4 -4
  15. package/dist/core.mjs +2 -2
  16. package/dist/css-macro/postcss.js +1 -1
  17. package/dist/css-macro/postcss.mjs +1 -1
  18. package/dist/css-macro.js +1 -1
  19. package/dist/css-macro.mjs +1 -1
  20. package/dist/defaults.js +1 -1
  21. package/dist/defaults.mjs +1 -1
  22. package/dist/escape.js +1 -1
  23. package/dist/escape.mjs +1 -1
  24. package/dist/gulp.js +5 -5
  25. package/dist/gulp.mjs +3 -3
  26. package/dist/index.js +7 -7
  27. package/dist/index.mjs +5 -5
  28. package/dist/postcss-html-transform.js +1 -1
  29. package/dist/postcss-html-transform.mjs +1 -1
  30. package/dist/presets.d.mts +2 -0
  31. package/dist/presets.d.ts +2 -0
  32. package/dist/presets.js +9 -5
  33. package/dist/presets.mjs +7 -3
  34. package/dist/types.d.mts +6 -0
  35. package/dist/types.d.ts +6 -0
  36. package/dist/types.js +1 -1
  37. package/dist/types.mjs +1 -1
  38. package/dist/vite.js +5 -5
  39. package/dist/vite.mjs +3 -3
  40. package/dist/webpack.js +5 -5
  41. package/dist/webpack.mjs +3 -3
  42. package/dist/webpack4.js +7 -7
  43. package/dist/webpack4.mjs +2 -2
  44. package/package.json +5 -3
  45. package/dist/chunk-4EUTRMUC.mjs +0 -10
  46. package/dist/chunk-QXSBMK2W.js +0 -7
@@ -3,7 +3,7 @@
3
3
  var _chunkDWAEHRHNjs = require('./chunk-DWAEHRHN.js');
4
4
 
5
5
 
6
- var _chunkOPTIAB5Gjs = require('./chunk-OPTIAB5G.js');
6
+ var _chunkSIZNRUIVjs = require('./chunk-SIZNRUIV.js');
7
7
 
8
8
 
9
9
  var _chunkWXBFAARRjs = require('./chunk-WXBFAARR.js');
@@ -130,6 +130,9 @@ function initializeCache(cacheConfig) {
130
130
 
131
131
  // src/context/custom-attributes.ts
132
132
  function toCustomAttributesEntities(customAttributes) {
133
+ if (!customAttributes) {
134
+ return [];
135
+ }
133
136
  if (_chunkUW3WHSZ5js.isMap.call(void 0, customAttributes)) {
134
137
  return [
135
138
  ...customAttributes.entries()
@@ -1129,6 +1132,8 @@ function createTaggedTemplateIgnore({ matcher, names }) {
1129
1132
  }
1130
1133
 
1131
1134
  // src/js/babel.ts
1135
+ var EXPRESSION_WRAPPER_PREFIX = "(\n";
1136
+ var EXPRESSION_WRAPPER_SUFFIX = "\n)";
1132
1137
  var parseCache = new (0, _lrucache.LRUCache)(
1133
1138
  {
1134
1139
  max: 512
@@ -1271,9 +1276,11 @@ function processUpdatedSource(rawSource, options, analysis) {
1271
1276
  return ms;
1272
1277
  }
1273
1278
  function jsHandler(rawSource, options) {
1279
+ const shouldWrapExpression = Boolean(options.wrapExpression);
1280
+ const source = shouldWrapExpression ? `${EXPRESSION_WRAPPER_PREFIX}${rawSource}${EXPRESSION_WRAPPER_SUFFIX}` : rawSource;
1274
1281
  let ast;
1275
1282
  try {
1276
- ast = babelParse(rawSource, options.babelParserOptions);
1283
+ ast = babelParse(source, options.babelParserOptions);
1277
1284
  } catch (error) {
1278
1285
  return {
1279
1286
  code: rawSource,
@@ -1281,7 +1288,15 @@ function jsHandler(rawSource, options) {
1281
1288
  };
1282
1289
  }
1283
1290
  const analysis = analyzeSource(ast, options, jsHandler);
1284
- const ms = processUpdatedSource(rawSource, options, analysis);
1291
+ const ms = processUpdatedSource(source, options, analysis);
1292
+ if (shouldWrapExpression) {
1293
+ const start = 0;
1294
+ const end = source.length;
1295
+ const prefixLength = EXPRESSION_WRAPPER_PREFIX.length;
1296
+ const suffixLength = EXPRESSION_WRAPPER_SUFFIX.length;
1297
+ ms.remove(start, start + prefixLength);
1298
+ ms.remove(end - suffixLength, end);
1299
+ }
1285
1300
  const result = {
1286
1301
  code: ms.toString(),
1287
1302
  get map() {
@@ -1355,6 +1370,75 @@ var _types = require('@babel/types'); var t = _interopRequireWildcard(_types);
1355
1370
  var _htmlparser2 = require('htmlparser2');
1356
1371
 
1357
1372
 
1373
+ // src/wxml/custom-attributes.ts
1374
+ function regTest(reg, str) {
1375
+ reg.lastIndex = 0;
1376
+ return reg.test(str);
1377
+ }
1378
+ function isPropsMatch(props, attr) {
1379
+ if (Array.isArray(props)) {
1380
+ let lowerAttr;
1381
+ for (const prop of props) {
1382
+ if (typeof prop === "string") {
1383
+ _nullishCoalesce(lowerAttr, () => ( (lowerAttr = attr.toLowerCase())));
1384
+ if (prop.toLowerCase() === lowerAttr) {
1385
+ return true;
1386
+ }
1387
+ } else if (regTest(prop, attr)) {
1388
+ return true;
1389
+ }
1390
+ }
1391
+ return false;
1392
+ } else if (typeof props === "string") {
1393
+ return props === attr;
1394
+ } else {
1395
+ return regTest(props, attr);
1396
+ }
1397
+ }
1398
+ function createAttributeMatcher(entities) {
1399
+ if (!entities || entities.length === 0) {
1400
+ return void 0;
1401
+ }
1402
+ const wildcardAttributeRules = [];
1403
+ const tagAttributeRuleMap = /* @__PURE__ */ new Map();
1404
+ const regexpAttributeRules = [];
1405
+ for (const [selector, props] of entities) {
1406
+ if (selector === "*") {
1407
+ wildcardAttributeRules.push(props);
1408
+ } else if (typeof selector === "string") {
1409
+ const list = tagAttributeRuleMap.get(selector);
1410
+ if (list) {
1411
+ list.push(props);
1412
+ } else {
1413
+ tagAttributeRuleMap.set(selector, [props]);
1414
+ }
1415
+ } else {
1416
+ regexpAttributeRules.push([selector, props]);
1417
+ }
1418
+ }
1419
+ return (tag, attr) => {
1420
+ for (const props of wildcardAttributeRules) {
1421
+ if (isPropsMatch(props, attr)) {
1422
+ return true;
1423
+ }
1424
+ }
1425
+ const tagRules = tagAttributeRuleMap.get(tag);
1426
+ if (tagRules) {
1427
+ for (const props of tagRules) {
1428
+ if (isPropsMatch(props, attr)) {
1429
+ return true;
1430
+ }
1431
+ }
1432
+ }
1433
+ for (const [selector, props] of regexpAttributeRules) {
1434
+ if (regTest(selector, tag) && isPropsMatch(props, attr)) {
1435
+ return true;
1436
+ }
1437
+ }
1438
+ return false;
1439
+ };
1440
+ }
1441
+
1358
1442
  // src/wxml/whitespace.ts
1359
1443
  var WHITESPACE_CODES = /* @__PURE__ */ new Set([
1360
1444
  9,
@@ -1511,8 +1595,13 @@ function generateCode(match, options = {}) {
1511
1595
  try {
1512
1596
  const { jsHandler: jsHandler2, runtimeSet } = options;
1513
1597
  if (jsHandler2 && runtimeSet) {
1514
- const { code } = jsHandler2(match, runtimeSet);
1515
- return code;
1598
+ const runHandler = (wrap) => jsHandler2(match, runtimeSet, wrap ? { wrapExpression: true } : void 0);
1599
+ const initial = runHandler(options.wrapExpression);
1600
+ if (!initial.error || options.wrapExpression) {
1601
+ return initial.code;
1602
+ }
1603
+ const fallback = runHandler(true);
1604
+ return fallback.code;
1516
1605
  } else {
1517
1606
  const ms = new (0, _magicstring2.default)(match);
1518
1607
  const ast = _parser.parseExpression.call(void 0, match);
@@ -1612,30 +1701,6 @@ function templateReplacer(original, options = {}) {
1612
1701
  handleEachClassFragment(ms, tokens, options);
1613
1702
  return ms.toString();
1614
1703
  }
1615
- function regTest(reg, str) {
1616
- reg.lastIndex = 0;
1617
- return reg.test(str);
1618
- }
1619
- function isPropsMatch(props, attr) {
1620
- if (Array.isArray(props)) {
1621
- let lowerAttr;
1622
- for (const prop of props) {
1623
- if (typeof prop === "string") {
1624
- _nullishCoalesce(lowerAttr, () => ( (lowerAttr = attr.toLowerCase())));
1625
- if (prop.toLowerCase() === lowerAttr) {
1626
- return true;
1627
- }
1628
- } else if (regTest(prop, attr)) {
1629
- return true;
1630
- }
1631
- }
1632
- return false;
1633
- } else if (typeof props === "string") {
1634
- return props === attr;
1635
- } else {
1636
- return regTest(props, attr);
1637
- }
1638
- }
1639
1704
  async function customTemplateHandler(rawSource, options) {
1640
1705
  const {
1641
1706
  customAttributesEntities = [],
@@ -1644,23 +1709,7 @@ async function customTemplateHandler(rawSource, options) {
1644
1709
  runtimeSet,
1645
1710
  jsHandler: jsHandler2
1646
1711
  } = _nullishCoalesce(options, () => ( {}));
1647
- const wildcardAttributeRules = [];
1648
- const tagAttributeRuleMap = /* @__PURE__ */ new Map();
1649
- const regexpAttributeRules = [];
1650
- for (const [selector, props] of customAttributesEntities) {
1651
- if (selector === "*") {
1652
- wildcardAttributeRules.push(props);
1653
- } else if (typeof selector === "string") {
1654
- const list = tagAttributeRuleMap.get(selector);
1655
- if (list) {
1656
- list.push(props);
1657
- } else {
1658
- tagAttributeRuleMap.set(selector, [props]);
1659
- }
1660
- } else {
1661
- regexpAttributeRules.push([selector, props]);
1662
- }
1663
- }
1712
+ const matchCustomAttribute = createAttributeMatcher(customAttributesEntities);
1664
1713
  const s = new (0, _magicstring2.default)(rawSource);
1665
1714
  let tag = "";
1666
1715
  const wxsArray = [];
@@ -1670,58 +1719,27 @@ async function customTemplateHandler(rawSource, options) {
1670
1719
  tag = name;
1671
1720
  },
1672
1721
  onattribute(name, value, quote) {
1673
- if (value) {
1674
- const lowerName = name.toLowerCase();
1675
- let updated = false;
1676
- const update = () => {
1677
- if (updated) {
1678
- return;
1679
- }
1680
- updated = true;
1681
- s.update(
1682
- parser.startIndex + name.length + 2,
1683
- // !important
1684
- // htmlparser2 9.0.0: parser.endIndex
1685
- // htmlparser2 9.1.0: parser.endIndex - 1
1686
- // https://github.com/sonofmagic/weapp-tailwindcss/issues/269
1687
- parser.endIndex - 1,
1688
- templateReplacer(value, {
1689
- ...options,
1690
- quote
1691
- })
1692
- );
1693
- };
1694
- if (!disabledDefaultTemplateHandler && (lowerName === "class" || lowerName === "hover-class" || lowerName === "virtualhostclass")) {
1695
- update();
1696
- }
1697
- if (!updated) {
1698
- for (const props of wildcardAttributeRules) {
1699
- if (isPropsMatch(props, name)) {
1700
- update();
1701
- break;
1702
- }
1703
- }
1704
- }
1705
- if (!updated) {
1706
- const tagRules = tagAttributeRuleMap.get(tag);
1707
- if (tagRules) {
1708
- for (const props of tagRules) {
1709
- if (isPropsMatch(props, name)) {
1710
- update();
1711
- break;
1712
- }
1713
- }
1714
- }
1715
- }
1716
- if (!updated) {
1717
- for (const [selector, props] of regexpAttributeRules) {
1718
- if (regTest(selector, tag) && isPropsMatch(props, name)) {
1719
- update();
1720
- break;
1721
- }
1722
- }
1723
- }
1722
+ if (!value) {
1723
+ return;
1724
1724
  }
1725
+ const lowerName = name.toLowerCase();
1726
+ const shouldHandleDefault = !disabledDefaultTemplateHandler && (lowerName === "class" || lowerName === "hover-class" || lowerName === "virtualhostclass");
1727
+ const shouldHandleCustom = _nullishCoalesce(_optionalChain([matchCustomAttribute, 'optionalCall', _32 => _32(tag, name)]), () => ( false));
1728
+ if (!shouldHandleDefault && !shouldHandleCustom) {
1729
+ return;
1730
+ }
1731
+ s.update(
1732
+ parser.startIndex + name.length + 2,
1733
+ // !important
1734
+ // htmlparser2 9.0.0: parser.endIndex
1735
+ // htmlparser2 9.1.0: parser.endIndex - 1
1736
+ // https://github.com/sonofmagic/weapp-tailwindcss/issues/269
1737
+ parser.endIndex - 1,
1738
+ templateReplacer(value, {
1739
+ ...options,
1740
+ quote
1741
+ })
1742
+ );
1725
1743
  },
1726
1744
  ontext(data) {
1727
1745
  if (inlineWxs && tag === "wxs") {
@@ -1905,8 +1923,8 @@ function getCompilerContext(opts) {
1905
1923
  );
1906
1924
  ctx.escapeMap = ctx.customReplaceDictionary;
1907
1925
  applyLoggerLevel(ctx.logLevel);
1908
- const twPatcher = _chunkOPTIAB5Gjs.createTailwindcssPatcherFromContext.call(void 0, ctx);
1909
- if (_optionalChain([twPatcher, 'access', _32 => _32.packageInfo, 'optionalAccess', _33 => _33.version])) {
1926
+ const twPatcher = _chunkSIZNRUIVjs.createTailwindcssPatcherFromContext.call(void 0, ctx);
1927
+ if (_optionalChain([twPatcher, 'access', _33 => _33.packageInfo, 'optionalAccess', _34 => _34.version])) {
1910
1928
  _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)))}`);
1911
1929
  } else {
1912
1930
  _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`);
@@ -1936,4 +1954,6 @@ function getCompilerContext(opts) {
1936
1954
 
1937
1955
 
1938
1956
 
1939
- exports.pluginName = pluginName; exports.vitePluginName = vitePluginName; exports.WEAPP_TW_REQUIRED_NODE_VERSION = WEAPP_TW_REQUIRED_NODE_VERSION; exports.generateCode = generateCode; exports.getCompilerContext = getCompilerContext;
1957
+
1958
+
1959
+ exports.toCustomAttributesEntities = toCustomAttributesEntities; exports.pluginName = pluginName; exports.vitePluginName = vitePluginName; exports.WEAPP_TW_REQUIRED_NODE_VERSION = WEAPP_TW_REQUIRED_NODE_VERSION; exports.createAttributeMatcher = createAttributeMatcher; exports.generateCode = generateCode; exports.getCompilerContext = getCompilerContext;
@@ -0,0 +1,15 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
7
+
8
+ // ../../node_modules/.pnpm/tsup@8.5.0_@microsoft+api-extractor@7.53.1_@types+node@24.10.0__@swc+core@1.13.5_@swc+h_8e91b94b8823fbc789a279e500560541/node_modules/tsup/assets/cjs_shims.js
9
+ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
10
+ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
11
+
12
+
13
+
14
+
15
+ exports.__require = __require; exports.importMetaUrl = importMetaUrl;
@@ -0,0 +1,18 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
7
+
8
+ // ../../node_modules/.pnpm/tsup@8.5.0_@microsoft+api-extractor@7.53.1_@types+node@24.10.0__@swc+core@1.13.5_@swc+h_8e91b94b8823fbc789a279e500560541/node_modules/tsup/assets/esm_shims.js
9
+ import path from "path";
10
+ import { fileURLToPath } from "url";
11
+ var getFilename = () => fileURLToPath(import.meta.url);
12
+ var getDirname = () => path.dirname(getFilename());
13
+ var __dirname = /* @__PURE__ */ getDirname();
14
+
15
+ export {
16
+ __require,
17
+ __dirname
18
+ };
@@ -3,7 +3,7 @@
3
3
  var _chunkUW3WHSZ5js = require('./chunk-UW3WHSZ5.js');
4
4
 
5
5
 
6
- var _chunkQXSBMK2Wjs = require('./chunk-QXSBMK2W.js');
6
+ var _chunkR7GWRQDJjs = require('./chunk-R7GWRQDJ.js');
7
7
 
8
8
  // src/context/tailwindcss.ts
9
9
  var _module = require('module');
@@ -46,7 +46,7 @@ function resolveModuleFromPaths(specifier, paths) {
46
46
  return void 0;
47
47
  }
48
48
  try {
49
- const req = _module.createRequire.call(void 0, _chunkQXSBMK2Wjs.importMetaUrl);
49
+ const req = _module.createRequire.call(void 0, _chunkR7GWRQDJjs.importMetaUrl);
50
50
  return req.resolve(specifier, { paths });
51
51
  } catch (e) {
52
52
  return void 0;
@@ -155,11 +155,11 @@ function createDefaultResolvePaths(basedir) {
155
155
  const cwd = _process2.default.cwd();
156
156
  appendNodeModules(paths, cwd);
157
157
  try {
158
- const modulePath = _url.fileURLToPath.call(void 0, _chunkQXSBMK2Wjs.importMetaUrl);
158
+ const modulePath = _url.fileURLToPath.call(void 0, _chunkR7GWRQDJjs.importMetaUrl);
159
159
  const candidate = _fs.existsSync.call(void 0, modulePath) && !_path2.default.extname(modulePath) ? modulePath : _path2.default.dirname(modulePath);
160
160
  paths.add(candidate);
161
161
  } catch (e2) {
162
- paths.add(_chunkQXSBMK2Wjs.importMetaUrl);
162
+ paths.add(_chunkR7GWRQDJjs.importMetaUrl);
163
163
  }
164
164
  if (paths.size === 0) {
165
165
  fallbackCandidates = fallbackCandidates.filter(Boolean);
@@ -17,7 +17,7 @@ var _chunkBUMQQPAOjs = require('./chunk-BUMQQPAO.js');
17
17
 
18
18
 
19
19
 
20
- var _chunkFPDJ3BCMjs = require('./chunk-FPDJ3BCM.js');
20
+ var _chunkQA6SPWSQjs = require('./chunk-QA6SPWSQ.js');
21
21
 
22
22
 
23
23
  var _chunkUW3WHSZ5js = require('./chunk-UW3WHSZ5.js');
@@ -29,7 +29,7 @@ var _process = require('process'); var _process2 = _interopRequireDefault(_proce
29
29
  var debug = _chunkBUMQQPAOjs.createDebug.call(void 0, );
30
30
  var UnifiedWebpackPluginV5 = class {
31
31
  constructor(options = {}) {
32
- this.options = _chunkFPDJ3BCMjs.getCompilerContext.call(void 0, options);
32
+ this.options = _chunkQA6SPWSQjs.getCompilerContext.call(void 0, options);
33
33
  this.appType = this.options.appType;
34
34
  }
35
35
  apply(compiler) {
@@ -68,8 +68,8 @@ var UnifiedWebpackPluginV5 = class {
68
68
  ident: null,
69
69
  type: null
70
70
  };
71
- compiler.hooks.compilation.tap(_chunkFPDJ3BCMjs.pluginName, (compilation) => {
72
- NormalModule.getCompilationHooks(compilation).loader.tap(_chunkFPDJ3BCMjs.pluginName, (_loaderContext, module) => {
71
+ compiler.hooks.compilation.tap(_chunkQA6SPWSQjs.pluginName, (compilation) => {
72
+ NormalModule.getCompilationHooks(compilation).loader.tap(_chunkQA6SPWSQjs.pluginName, (_loaderContext, module) => {
73
73
  if (isExisted) {
74
74
  const idx = module.loaders.findIndex((x) => x.loader.includes("postcss-loader"));
75
75
  if (idx > -1) {
@@ -79,7 +79,7 @@ var UnifiedWebpackPluginV5 = class {
79
79
  });
80
80
  compilation.hooks.processAssets.tapPromise(
81
81
  {
82
- name: _chunkFPDJ3BCMjs.pluginName,
82
+ name: _chunkQA6SPWSQjs.pluginName,
83
83
  stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
84
84
  },
85
85
  async (assets) => {
@@ -130,6 +130,9 @@ function initializeCache(cacheConfig) {
130
130
 
131
131
  // src/context/custom-attributes.ts
132
132
  function toCustomAttributesEntities(customAttributes) {
133
+ if (!customAttributes) {
134
+ return [];
135
+ }
133
136
  if (isMap(customAttributes)) {
134
137
  return [
135
138
  ...customAttributes.entries()
@@ -1129,6 +1132,8 @@ function createTaggedTemplateIgnore({ matcher, names }) {
1129
1132
  }
1130
1133
 
1131
1134
  // src/js/babel.ts
1135
+ var EXPRESSION_WRAPPER_PREFIX = "(\n";
1136
+ var EXPRESSION_WRAPPER_SUFFIX = "\n)";
1132
1137
  var parseCache = new LRUCache2(
1133
1138
  {
1134
1139
  max: 512
@@ -1271,9 +1276,11 @@ function processUpdatedSource(rawSource, options, analysis) {
1271
1276
  return ms;
1272
1277
  }
1273
1278
  function jsHandler(rawSource, options) {
1279
+ const shouldWrapExpression = Boolean(options.wrapExpression);
1280
+ const source = shouldWrapExpression ? `${EXPRESSION_WRAPPER_PREFIX}${rawSource}${EXPRESSION_WRAPPER_SUFFIX}` : rawSource;
1274
1281
  let ast;
1275
1282
  try {
1276
- ast = babelParse(rawSource, options.babelParserOptions);
1283
+ ast = babelParse(source, options.babelParserOptions);
1277
1284
  } catch (error) {
1278
1285
  return {
1279
1286
  code: rawSource,
@@ -1281,7 +1288,15 @@ function jsHandler(rawSource, options) {
1281
1288
  };
1282
1289
  }
1283
1290
  const analysis = analyzeSource(ast, options, jsHandler);
1284
- const ms = processUpdatedSource(rawSource, options, analysis);
1291
+ const ms = processUpdatedSource(source, options, analysis);
1292
+ if (shouldWrapExpression) {
1293
+ const start = 0;
1294
+ const end = source.length;
1295
+ const prefixLength = EXPRESSION_WRAPPER_PREFIX.length;
1296
+ const suffixLength = EXPRESSION_WRAPPER_SUFFIX.length;
1297
+ ms.remove(start, start + prefixLength);
1298
+ ms.remove(end - suffixLength, end);
1299
+ }
1285
1300
  const result = {
1286
1301
  code: ms.toString(),
1287
1302
  get map() {
@@ -1355,6 +1370,75 @@ import * as t from "@babel/types";
1355
1370
  import { Parser } from "htmlparser2";
1356
1371
  import MagicString2 from "magic-string";
1357
1372
 
1373
+ // src/wxml/custom-attributes.ts
1374
+ function regTest(reg, str) {
1375
+ reg.lastIndex = 0;
1376
+ return reg.test(str);
1377
+ }
1378
+ function isPropsMatch(props, attr) {
1379
+ if (Array.isArray(props)) {
1380
+ let lowerAttr;
1381
+ for (const prop of props) {
1382
+ if (typeof prop === "string") {
1383
+ lowerAttr ?? (lowerAttr = attr.toLowerCase());
1384
+ if (prop.toLowerCase() === lowerAttr) {
1385
+ return true;
1386
+ }
1387
+ } else if (regTest(prop, attr)) {
1388
+ return true;
1389
+ }
1390
+ }
1391
+ return false;
1392
+ } else if (typeof props === "string") {
1393
+ return props === attr;
1394
+ } else {
1395
+ return regTest(props, attr);
1396
+ }
1397
+ }
1398
+ function createAttributeMatcher(entities) {
1399
+ if (!entities || entities.length === 0) {
1400
+ return void 0;
1401
+ }
1402
+ const wildcardAttributeRules = [];
1403
+ const tagAttributeRuleMap = /* @__PURE__ */ new Map();
1404
+ const regexpAttributeRules = [];
1405
+ for (const [selector, props] of entities) {
1406
+ if (selector === "*") {
1407
+ wildcardAttributeRules.push(props);
1408
+ } else if (typeof selector === "string") {
1409
+ const list = tagAttributeRuleMap.get(selector);
1410
+ if (list) {
1411
+ list.push(props);
1412
+ } else {
1413
+ tagAttributeRuleMap.set(selector, [props]);
1414
+ }
1415
+ } else {
1416
+ regexpAttributeRules.push([selector, props]);
1417
+ }
1418
+ }
1419
+ return (tag, attr) => {
1420
+ for (const props of wildcardAttributeRules) {
1421
+ if (isPropsMatch(props, attr)) {
1422
+ return true;
1423
+ }
1424
+ }
1425
+ const tagRules = tagAttributeRuleMap.get(tag);
1426
+ if (tagRules) {
1427
+ for (const props of tagRules) {
1428
+ if (isPropsMatch(props, attr)) {
1429
+ return true;
1430
+ }
1431
+ }
1432
+ }
1433
+ for (const [selector, props] of regexpAttributeRules) {
1434
+ if (regTest(selector, tag) && isPropsMatch(props, attr)) {
1435
+ return true;
1436
+ }
1437
+ }
1438
+ return false;
1439
+ };
1440
+ }
1441
+
1358
1442
  // src/wxml/whitespace.ts
1359
1443
  var WHITESPACE_CODES = /* @__PURE__ */ new Set([
1360
1444
  9,
@@ -1511,8 +1595,13 @@ function generateCode(match, options = {}) {
1511
1595
  try {
1512
1596
  const { jsHandler: jsHandler2, runtimeSet } = options;
1513
1597
  if (jsHandler2 && runtimeSet) {
1514
- const { code } = jsHandler2(match, runtimeSet);
1515
- return code;
1598
+ const runHandler = (wrap) => jsHandler2(match, runtimeSet, wrap ? { wrapExpression: true } : void 0);
1599
+ const initial = runHandler(options.wrapExpression);
1600
+ if (!initial.error || options.wrapExpression) {
1601
+ return initial.code;
1602
+ }
1603
+ const fallback = runHandler(true);
1604
+ return fallback.code;
1516
1605
  } else {
1517
1606
  const ms = new MagicString2(match);
1518
1607
  const ast = parseExpression(match);
@@ -1612,30 +1701,6 @@ function templateReplacer(original, options = {}) {
1612
1701
  handleEachClassFragment(ms, tokens, options);
1613
1702
  return ms.toString();
1614
1703
  }
1615
- function regTest(reg, str) {
1616
- reg.lastIndex = 0;
1617
- return reg.test(str);
1618
- }
1619
- function isPropsMatch(props, attr) {
1620
- if (Array.isArray(props)) {
1621
- let lowerAttr;
1622
- for (const prop of props) {
1623
- if (typeof prop === "string") {
1624
- lowerAttr ?? (lowerAttr = attr.toLowerCase());
1625
- if (prop.toLowerCase() === lowerAttr) {
1626
- return true;
1627
- }
1628
- } else if (regTest(prop, attr)) {
1629
- return true;
1630
- }
1631
- }
1632
- return false;
1633
- } else if (typeof props === "string") {
1634
- return props === attr;
1635
- } else {
1636
- return regTest(props, attr);
1637
- }
1638
- }
1639
1704
  async function customTemplateHandler(rawSource, options) {
1640
1705
  const {
1641
1706
  customAttributesEntities = [],
@@ -1644,23 +1709,7 @@ async function customTemplateHandler(rawSource, options) {
1644
1709
  runtimeSet,
1645
1710
  jsHandler: jsHandler2
1646
1711
  } = options ?? {};
1647
- const wildcardAttributeRules = [];
1648
- const tagAttributeRuleMap = /* @__PURE__ */ new Map();
1649
- const regexpAttributeRules = [];
1650
- for (const [selector, props] of customAttributesEntities) {
1651
- if (selector === "*") {
1652
- wildcardAttributeRules.push(props);
1653
- } else if (typeof selector === "string") {
1654
- const list = tagAttributeRuleMap.get(selector);
1655
- if (list) {
1656
- list.push(props);
1657
- } else {
1658
- tagAttributeRuleMap.set(selector, [props]);
1659
- }
1660
- } else {
1661
- regexpAttributeRules.push([selector, props]);
1662
- }
1663
- }
1712
+ const matchCustomAttribute = createAttributeMatcher(customAttributesEntities);
1664
1713
  const s = new MagicString2(rawSource);
1665
1714
  let tag = "";
1666
1715
  const wxsArray = [];
@@ -1670,58 +1719,27 @@ async function customTemplateHandler(rawSource, options) {
1670
1719
  tag = name;
1671
1720
  },
1672
1721
  onattribute(name, value, quote) {
1673
- if (value) {
1674
- const lowerName = name.toLowerCase();
1675
- let updated = false;
1676
- const update = () => {
1677
- if (updated) {
1678
- return;
1679
- }
1680
- updated = true;
1681
- s.update(
1682
- parser.startIndex + name.length + 2,
1683
- // !important
1684
- // htmlparser2 9.0.0: parser.endIndex
1685
- // htmlparser2 9.1.0: parser.endIndex - 1
1686
- // https://github.com/sonofmagic/weapp-tailwindcss/issues/269
1687
- parser.endIndex - 1,
1688
- templateReplacer(value, {
1689
- ...options,
1690
- quote
1691
- })
1692
- );
1693
- };
1694
- if (!disabledDefaultTemplateHandler && (lowerName === "class" || lowerName === "hover-class" || lowerName === "virtualhostclass")) {
1695
- update();
1696
- }
1697
- if (!updated) {
1698
- for (const props of wildcardAttributeRules) {
1699
- if (isPropsMatch(props, name)) {
1700
- update();
1701
- break;
1702
- }
1703
- }
1704
- }
1705
- if (!updated) {
1706
- const tagRules = tagAttributeRuleMap.get(tag);
1707
- if (tagRules) {
1708
- for (const props of tagRules) {
1709
- if (isPropsMatch(props, name)) {
1710
- update();
1711
- break;
1712
- }
1713
- }
1714
- }
1715
- }
1716
- if (!updated) {
1717
- for (const [selector, props] of regexpAttributeRules) {
1718
- if (regTest(selector, tag) && isPropsMatch(props, name)) {
1719
- update();
1720
- break;
1721
- }
1722
- }
1723
- }
1722
+ if (!value) {
1723
+ return;
1724
+ }
1725
+ const lowerName = name.toLowerCase();
1726
+ const shouldHandleDefault = !disabledDefaultTemplateHandler && (lowerName === "class" || lowerName === "hover-class" || lowerName === "virtualhostclass");
1727
+ const shouldHandleCustom = matchCustomAttribute?.(tag, name) ?? false;
1728
+ if (!shouldHandleDefault && !shouldHandleCustom) {
1729
+ return;
1724
1730
  }
1731
+ s.update(
1732
+ parser.startIndex + name.length + 2,
1733
+ // !important
1734
+ // htmlparser2 9.0.0: parser.endIndex
1735
+ // htmlparser2 9.1.0: parser.endIndex - 1
1736
+ // https://github.com/sonofmagic/weapp-tailwindcss/issues/269
1737
+ parser.endIndex - 1,
1738
+ templateReplacer(value, {
1739
+ ...options,
1740
+ quote
1741
+ })
1742
+ );
1725
1743
  },
1726
1744
  ontext(data) {
1727
1745
  if (inlineWxs && tag === "wxs") {
@@ -1931,9 +1949,11 @@ function getCompilerContext(opts) {
1931
1949
  }
1932
1950
 
1933
1951
  export {
1952
+ toCustomAttributesEntities,
1934
1953
  pluginName,
1935
1954
  vitePluginName,
1936
1955
  WEAPP_TW_REQUIRED_NODE_VERSION,
1956
+ createAttributeMatcher,
1937
1957
  generateCode,
1938
1958
  getCompilerContext
1939
1959
  };