@weapp-vite/web 2.0.0 → 2.1.0

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 (310) hide show
  1. package/dist/_virtual/_rolldown/runtime.mjs +1 -2
  2. package/dist/compiler/wxml/attributes.mjs +12 -4
  3. package/dist/compiler/wxml/attributes.mjs.map +1 -1
  4. package/dist/compiler/wxml/compile.mjs +33 -39
  5. package/dist/compiler/wxml/compile.mjs.map +1 -1
  6. package/dist/compiler/wxml/dependency.mjs +10 -3
  7. package/dist/compiler/wxml/dependency.mjs.map +1 -1
  8. package/dist/compiler/wxml/interpolation.mjs +13 -3
  9. package/dist/compiler/wxml/interpolation.mjs.map +1 -1
  10. package/dist/compiler/wxml/nativeTags.mjs +60 -0
  11. package/dist/compiler/wxml/nativeTags.mjs.map +1 -0
  12. package/dist/compiler/wxml/navigation.mjs +1 -2
  13. package/dist/compiler/wxml/parser.mjs +1 -2
  14. package/dist/compiler/wxml/prepare.mjs +42 -0
  15. package/dist/compiler/wxml/prepare.mjs.map +1 -0
  16. package/dist/compiler/wxml/renderer.mjs +1 -2
  17. package/dist/compiler/wxml/specialNodes.mjs +1 -2
  18. package/dist/compiler/wxml/types.d.mts +0 -2
  19. package/dist/compiler/wxml/unknownTags.mjs +33 -0
  20. package/dist/compiler/wxml/unknownTags.mjs.map +1 -0
  21. package/dist/compiler/wxs.mjs +1 -2
  22. package/dist/css/wxss.d.mts +2 -19
  23. package/dist/css/wxss.mjs +5 -12
  24. package/dist/css/wxss.mjs.map +1 -1
  25. package/dist/index.d.mts +8 -3
  26. package/dist/index.mjs +8 -5
  27. package/dist/plugin/assets.d.mts +1 -2
  28. package/dist/plugin/assets.mjs +1 -2
  29. package/dist/plugin/constants.mjs +5 -4
  30. package/dist/plugin/constants.mjs.map +1 -1
  31. package/dist/plugin/dependencyScan.mjs +1 -2
  32. package/dist/plugin/entry.mjs +6 -4
  33. package/dist/plugin/entry.mjs.map +1 -1
  34. package/dist/plugin/files.mjs +1 -2
  35. package/dist/plugin/hostTypes.d.mts +1 -2
  36. package/dist/plugin/index.d.mts +0 -2
  37. package/dist/plugin/index.mjs +29 -24
  38. package/dist/plugin/index.mjs.map +1 -1
  39. package/dist/plugin/layout.mjs +1 -2
  40. package/dist/plugin/navigation.mjs +1 -2
  41. package/dist/plugin/packageResolution.mjs +1 -2
  42. package/dist/plugin/path.mjs +1 -2
  43. package/dist/plugin/register.mjs +1 -2
  44. package/dist/plugin/scan.mjs +1 -2
  45. package/dist/plugin/scanConfig.mjs +1 -2
  46. package/dist/plugin/scanSfc.mjs +1 -2
  47. package/dist/plugin/sfcHmr.mjs +28 -10
  48. package/dist/plugin/sfcHmr.mjs.map +1 -1
  49. package/dist/plugin/state.mjs +1 -2
  50. package/dist/plugin/styleModule.mjs +1 -2
  51. package/dist/plugin/types.d.mts +2 -3
  52. package/dist/plugin/vueSfc.mjs +1 -2
  53. package/dist/runtime/appShell/container.mjs +1 -2
  54. package/dist/runtime/appShell/tabBar/index.mjs +1 -2
  55. package/dist/runtime/appShell/tabBar/style.mjs +1 -2
  56. package/dist/runtime/appStyle.mjs +1 -2
  57. package/dist/runtime/button/helpers.mjs +1 -2
  58. package/dist/runtime/button/index.d.mts +0 -2
  59. package/dist/runtime/button/index.mjs +1 -2
  60. package/dist/runtime/button/style.mjs +1 -2
  61. package/dist/runtime/component/behavior.mjs +1 -2
  62. package/dist/runtime/component/constants.mjs +1 -2
  63. package/dist/runtime/component/dom.mjs +1 -2
  64. package/dist/runtime/component/element.mjs +9 -2
  65. package/dist/runtime/component/element.mjs.map +1 -1
  66. package/dist/runtime/component/events.mjs +4 -4
  67. package/dist/runtime/component/events.mjs.map +1 -1
  68. package/dist/runtime/component/index.d.mts +0 -2
  69. package/dist/runtime/component/index.mjs +1 -2
  70. package/dist/runtime/component/observers.mjs +1 -2
  71. package/dist/runtime/component/publicInstance.mjs +1 -2
  72. package/dist/runtime/component/relations.mjs +1 -2
  73. package/dist/runtime/component/slots.mjs +1 -2
  74. package/dist/runtime/component/state.mjs +1 -2
  75. package/dist/runtime/component/types.d.mts +0 -2
  76. package/dist/runtime/component/utils.mjs +1 -2
  77. package/dist/runtime/component/virtualHost.mjs +1 -2
  78. package/dist/runtime/componentEvents.mjs +1 -2
  79. package/dist/runtime/dataset.mjs +49 -0
  80. package/dist/runtime/dataset.mjs.map +1 -0
  81. package/dist/runtime/datasetBinding.d.mts +13 -0
  82. package/dist/runtime/datasetBinding.mjs +40 -0
  83. package/dist/runtime/datasetBinding.mjs.map +1 -0
  84. package/dist/runtime/eventBinding.d.mts +1 -2
  85. package/dist/runtime/eventBinding.mjs +1 -2
  86. package/dist/runtime/execution.d.mts +0 -2
  87. package/dist/runtime/execution.mjs +1 -2
  88. package/dist/runtime/host/index.d.mts +0 -2
  89. package/dist/runtime/host/index.mjs +1 -2
  90. package/dist/runtime/host/types.d.mts +0 -2
  91. package/dist/runtime/hostGlobals.d.mts +1 -2
  92. package/dist/runtime/hostGlobals.mjs +1 -2
  93. package/dist/runtime/index.d.mts +8 -3
  94. package/dist/runtime/index.mjs +9 -7
  95. package/dist/runtime/index.mjs.map +1 -1
  96. package/dist/runtime/inlineStyle.d.mts +5 -0
  97. package/dist/runtime/inlineStyle.mjs +21 -0
  98. package/dist/runtime/inlineStyle.mjs.map +1 -0
  99. package/dist/runtime/inputHandlerResult.mjs +1 -2
  100. package/dist/runtime/legacyTemplate/dataset.mjs +53 -0
  101. package/dist/runtime/legacyTemplate/dataset.mjs.map +1 -0
  102. package/dist/runtime/legacyTemplate/dom.mjs +20 -5
  103. package/dist/runtime/legacyTemplate/dom.mjs.map +1 -1
  104. package/dist/runtime/legacyTemplate/expression.mjs +1 -2
  105. package/dist/runtime/legacyTemplate/index.d.mts +0 -2
  106. package/dist/runtime/legacyTemplate/index.mjs +23 -16
  107. package/dist/runtime/legacyTemplate/index.mjs.map +1 -1
  108. package/dist/runtime/legacyTemplate/types.d.mts +0 -2
  109. package/dist/runtime/nativeComponents/canvas/index.mjs +1 -2
  110. package/dist/runtime/nativeComponents/checkbox.mjs +1 -2
  111. package/dist/runtime/nativeComponents/cover/index.mjs +1 -2
  112. package/dist/runtime/nativeComponents/form.d.mts +0 -2
  113. package/dist/runtime/nativeComponents/form.mjs +1 -2
  114. package/dist/runtime/nativeComponents/formControl.mjs +1 -2
  115. package/dist/runtime/nativeComponents/helpers.mjs +1 -2
  116. package/dist/runtime/nativeComponents/icon/helpers.mjs +1 -2
  117. package/dist/runtime/nativeComponents/icon/index.mjs +1 -2
  118. package/dist/runtime/nativeComponents/icon/style.mjs +1 -2
  119. package/dist/runtime/nativeComponents/image.d.mts +0 -2
  120. package/dist/runtime/nativeComponents/image.mjs +1 -2
  121. package/dist/runtime/nativeComponents/index.d.mts +1 -3
  122. package/dist/runtime/nativeComponents/index.mjs +3 -4
  123. package/dist/runtime/nativeComponents/index.mjs.map +1 -1
  124. package/dist/runtime/nativeComponents/input.d.mts +0 -2
  125. package/dist/runtime/nativeComponents/input.mjs +1 -2
  126. package/dist/runtime/nativeComponents/label.mjs +1 -2
  127. package/dist/runtime/nativeComponents/mediaRegistry.mjs +1 -2
  128. package/dist/runtime/nativeComponents/movable/helpers.mjs +1 -2
  129. package/dist/runtime/nativeComponents/movable/index.mjs +1 -2
  130. package/dist/runtime/nativeComponents/navigator.mjs +1 -2
  131. package/dist/runtime/nativeComponents/picker/editors.mjs +1 -2
  132. package/dist/runtime/nativeComponents/picker/helpers.mjs +1 -2
  133. package/dist/runtime/nativeComponents/picker/index.mjs +1 -2
  134. package/dist/runtime/nativeComponents/picker/style.mjs +1 -2
  135. package/dist/runtime/nativeComponents/pickerView/column.mjs +1 -2
  136. package/dist/runtime/nativeComponents/pickerView/helpers.mjs +1 -2
  137. package/dist/runtime/nativeComponents/pickerView/index.mjs +1 -2
  138. package/dist/runtime/nativeComponents/pickerView/style.mjs +1 -2
  139. package/dist/runtime/nativeComponents/primitives.mjs +1 -2
  140. package/dist/runtime/nativeComponents/progress/helpers.mjs +1 -2
  141. package/dist/runtime/nativeComponents/progress/index.mjs +1 -2
  142. package/dist/runtime/nativeComponents/progress/style.mjs +1 -2
  143. package/dist/runtime/nativeComponents/radio.mjs +1 -2
  144. package/dist/runtime/nativeComponents/richText/index.mjs +3 -4
  145. package/dist/runtime/nativeComponents/richText/index.mjs.map +1 -1
  146. package/dist/runtime/nativeComponents/scrollView/boundaries.mjs +62 -0
  147. package/dist/runtime/nativeComponents/scrollView/boundaries.mjs.map +1 -0
  148. package/dist/runtime/nativeComponents/{scrollView.d.mts → scrollView/helpers.d.mts} +4 -5
  149. package/dist/runtime/nativeComponents/scrollView/helpers.mjs +14 -0
  150. package/dist/runtime/nativeComponents/scrollView/helpers.mjs.map +1 -0
  151. package/dist/runtime/nativeComponents/scrollView/index.mjs +193 -0
  152. package/dist/runtime/nativeComponents/scrollView/index.mjs.map +1 -0
  153. package/dist/runtime/nativeComponents/scrollView/position.mjs +43 -0
  154. package/dist/runtime/nativeComponents/scrollView/position.mjs.map +1 -0
  155. package/dist/runtime/nativeComponents/slider/helpers.mjs +1 -2
  156. package/dist/runtime/nativeComponents/slider/index.mjs +1 -2
  157. package/dist/runtime/nativeComponents/slider/style.mjs +1 -2
  158. package/dist/runtime/nativeComponents/style.mjs +1 -2
  159. package/dist/runtime/nativeComponents/swiper/helpers.mjs +1 -2
  160. package/dist/runtime/nativeComponents/swiper/index.mjs +1 -2
  161. package/dist/runtime/nativeComponents/swiper/item.mjs +1 -2
  162. package/dist/runtime/nativeComponents/swiper/style.mjs +1 -2
  163. package/dist/runtime/nativeComponents/switch.d.mts +0 -2
  164. package/dist/runtime/nativeComponents/switch.mjs +1 -2
  165. package/dist/runtime/nativeComponents/textarea.d.mts +0 -2
  166. package/dist/runtime/nativeComponents/textarea.mjs +1 -2
  167. package/dist/runtime/nativeComponents/video/helpers.d.mts +0 -2
  168. package/dist/runtime/nativeComponents/video/helpers.mjs +1 -2
  169. package/dist/runtime/nativeComponents/video/index.mjs +1 -2
  170. package/dist/runtime/nativeComponents/video/style.mjs +1 -2
  171. package/dist/runtime/navigationBar/index.d.mts +0 -2
  172. package/dist/runtime/navigationBar/index.mjs +1 -2
  173. package/dist/runtime/navigationBar/style.mjs +1 -2
  174. package/dist/runtime/pageLayout.d.mts +1 -2
  175. package/dist/runtime/pageLayout.mjs +1 -2
  176. package/dist/runtime/polyfill/ad.mjs +1 -2
  177. package/dist/runtime/polyfill/animation.mjs +1 -2
  178. package/dist/runtime/polyfill/appState.mjs +1 -2
  179. package/dist/runtime/polyfill/async.d.mts +0 -2
  180. package/dist/runtime/polyfill/async.mjs +1 -2
  181. package/dist/runtime/polyfill/auth.mjs +1 -2
  182. package/dist/runtime/polyfill/authApi.mjs +1 -2
  183. package/dist/runtime/polyfill/background.mjs +1 -2
  184. package/dist/runtime/polyfill/canvasContext.mjs +1 -2
  185. package/dist/runtime/polyfill/capability.mjs +1 -2
  186. package/dist/runtime/polyfill/cloud.mjs +1 -2
  187. package/dist/runtime/polyfill/device.mjs +1 -2
  188. package/dist/runtime/polyfill/deviceApi.mjs +1 -2
  189. package/dist/runtime/polyfill/deviceAuthSystemApi.d.mts +0 -2
  190. package/dist/runtime/polyfill/deviceAuthSystemApi.mjs +1 -2
  191. package/dist/runtime/polyfill/eventBus.mjs +1 -2
  192. package/dist/runtime/polyfill/filePicker.mjs +1 -2
  193. package/dist/runtime/polyfill/fileSystemManager.mjs +1 -2
  194. package/dist/runtime/polyfill/files.mjs +1 -2
  195. package/dist/runtime/polyfill/font.mjs +1 -2
  196. package/dist/runtime/polyfill/index.d.mts +4 -4
  197. package/dist/runtime/polyfill/index.mjs +12 -5
  198. package/dist/runtime/polyfill/index.mjs.map +1 -1
  199. package/dist/runtime/polyfill/interaction.mjs +1 -2
  200. package/dist/runtime/polyfill/interactionApi.mjs +1 -2
  201. package/dist/runtime/polyfill/intersectionObserver.mjs +4 -4
  202. package/dist/runtime/polyfill/intersectionObserver.mjs.map +1 -1
  203. package/dist/runtime/polyfill/lifecycleEvents.d.mts +12 -0
  204. package/dist/runtime/polyfill/lifecycleEvents.mjs +67 -0
  205. package/dist/runtime/polyfill/lifecycleEvents.mjs.map +1 -0
  206. package/dist/runtime/polyfill/locale.mjs +1 -2
  207. package/dist/runtime/polyfill/location.mjs +1 -2
  208. package/dist/runtime/polyfill/locationApi.mjs +1 -2
  209. package/dist/runtime/polyfill/mediaActions.mjs +1 -2
  210. package/dist/runtime/polyfill/mediaApi/file.mjs +1 -2
  211. package/dist/runtime/polyfill/mediaApi/info.mjs +1 -2
  212. package/dist/runtime/polyfill/mediaApi/picker.mjs +1 -2
  213. package/dist/runtime/polyfill/mediaApi/preview.mjs +1 -2
  214. package/dist/runtime/polyfill/mediaApi/process.mjs +1 -2
  215. package/dist/runtime/polyfill/mediaInfo.mjs +1 -2
  216. package/dist/runtime/polyfill/mediaPicker.mjs +1 -2
  217. package/dist/runtime/polyfill/mediaProcess.mjs +1 -2
  218. package/dist/runtime/polyfill/menuApi.mjs +5 -3
  219. package/dist/runtime/polyfill/menuApi.mjs.map +1 -1
  220. package/dist/runtime/polyfill/navigationBarRuntime.mjs +1 -2
  221. package/dist/runtime/polyfill/network/request.mjs +1 -2
  222. package/dist/runtime/polyfill/network/requestBridge.mjs +1 -2
  223. package/dist/runtime/polyfill/network/status.mjs +1 -2
  224. package/dist/runtime/polyfill/platformApi.mjs +1 -2
  225. package/dist/runtime/polyfill/platformRuntime.mjs +1 -2
  226. package/dist/runtime/polyfill/routeRuntime/appLifecycle.mjs +1 -2
  227. package/dist/runtime/polyfill/routeRuntime/dom.mjs +1 -2
  228. package/dist/runtime/polyfill/routeRuntime/events.d.mts +0 -2
  229. package/dist/runtime/polyfill/routeRuntime/events.mjs +1 -2
  230. package/dist/runtime/polyfill/routeRuntime/history.d.mts +0 -2
  231. package/dist/runtime/polyfill/routeRuntime/history.mjs +1 -2
  232. package/dist/runtime/polyfill/routeRuntime/lifecycle.mjs +1 -2
  233. package/dist/runtime/polyfill/routeRuntime/options.d.mts +1 -2
  234. package/dist/runtime/polyfill/routeRuntime/options.mjs +1 -2
  235. package/dist/runtime/polyfill/routeRuntime/result.mjs +1 -2
  236. package/dist/runtime/polyfill/routeRuntime/scroll.mjs +37 -6
  237. package/dist/runtime/polyfill/routeRuntime/scroll.mjs.map +1 -1
  238. package/dist/runtime/polyfill/routeRuntime/stack.mjs +1 -2
  239. package/dist/runtime/polyfill/routeRuntime/url.mjs +1 -2
  240. package/dist/runtime/polyfill/routeRuntime.d.mts +2 -2
  241. package/dist/runtime/polyfill/routeRuntime.mjs +14 -5
  242. package/dist/runtime/polyfill/routeRuntime.mjs.map +1 -1
  243. package/dist/runtime/polyfill/runtimeCapabilityApi.mjs +1 -2
  244. package/dist/runtime/polyfill/runtimeDataApi.d.mts +0 -2
  245. package/dist/runtime/polyfill/runtimeDataApi.mjs +1 -2
  246. package/dist/runtime/polyfill/runtimeInfra.mjs +1 -2
  247. package/dist/runtime/polyfill/runtimeOps.mjs +1 -2
  248. package/dist/runtime/polyfill/selectorQuery.mjs +3 -3
  249. package/dist/runtime/polyfill/selectorQuery.mjs.map +1 -1
  250. package/dist/runtime/polyfill/storage.mjs +1 -2
  251. package/dist/runtime/polyfill/storageAsync.mjs +1 -2
  252. package/dist/runtime/polyfill/subscribe.mjs +1 -2
  253. package/dist/runtime/polyfill/system.mjs +1 -2
  254. package/dist/runtime/polyfill/systemApi.mjs +1 -2
  255. package/dist/runtime/polyfill/types/base.d.mts +0 -2
  256. package/dist/runtime/polyfill/types/common.d.mts +0 -2
  257. package/dist/runtime/polyfill/types/lifecycle.d.mts +12 -0
  258. package/dist/runtime/polyfill/types/locationRuntime.d.mts +0 -2
  259. package/dist/runtime/polyfill/types/mediaAuth.d.mts +0 -2
  260. package/dist/runtime/polyfill/types/platformRuntime.d.mts +0 -2
  261. package/dist/runtime/polyfill/types/systemAuth.d.mts +0 -2
  262. package/dist/runtime/polyfill/types/tabBarRuntime.d.mts +0 -2
  263. package/dist/runtime/polyfill/ui.mjs +1 -2
  264. package/dist/runtime/polyfill/uiFeedback.mjs +19 -5
  265. package/dist/runtime/polyfill/uiFeedback.mjs.map +1 -1
  266. package/dist/runtime/polyfill/uiMediaApi.d.mts +8 -2
  267. package/dist/runtime/polyfill/uiMediaApi.mjs +20 -5
  268. package/dist/runtime/polyfill/uiMediaApi.mjs.map +1 -1
  269. package/dist/runtime/polyfill/videoContext.mjs +1 -2
  270. package/dist/runtime/polyfill/vkSession.mjs +1 -2
  271. package/dist/runtime/polyfill/windowResize.mjs +1 -2
  272. package/dist/runtime/polyfill/worker.mjs +1 -2
  273. package/dist/runtime/polyfill.d.mts +4 -2
  274. package/dist/runtime/renderContext.d.mts +0 -2
  275. package/dist/runtime/renderContext.mjs +5 -4
  276. package/dist/runtime/renderContext.mjs.map +1 -1
  277. package/dist/runtime/rpx.d.mts +0 -2
  278. package/dist/runtime/rpx.mjs +6 -6
  279. package/dist/runtime/rpx.mjs.map +1 -1
  280. package/dist/runtime/seo/index.d.mts +0 -2
  281. package/dist/runtime/seo/index.mjs +1 -2
  282. package/dist/runtime/style.d.mts +0 -2
  283. package/dist/runtime/style.mjs +1 -2
  284. package/dist/runtime/template.d.mts +0 -2
  285. package/dist/runtime/utils/object.mjs +1 -2
  286. package/dist/runtime/viewport/index.d.mts +0 -2
  287. package/dist/runtime/viewport/index.mjs +1 -2
  288. package/dist/runtime/viewport/style.mjs +2 -2
  289. package/dist/runtime/viewport/style.mjs.map +1 -1
  290. package/dist/runtime/viewport/types.d.mts +0 -2
  291. package/dist/runtime/warning.d.mts +0 -2
  292. package/dist/runtime/warning.mjs +1 -2
  293. package/dist/runtime/wevu.d.mts +1 -2
  294. package/dist/runtime/wevu.mjs +1 -2
  295. package/dist/shared/nativeComponents.mjs +10 -3
  296. package/dist/shared/nativeComponents.mjs.map +1 -1
  297. package/dist/shared/slugify.mjs +1 -2
  298. package/dist/shared/styleUnits/options.d.mts +24 -0
  299. package/dist/shared/styleUnits/options.mjs +13 -0
  300. package/dist/shared/styleUnits/options.mjs.map +1 -0
  301. package/dist/shared/styleUnits/value.mjs +63 -0
  302. package/dist/shared/styleUnits/value.mjs.map +1 -0
  303. package/dist/shared/tabBar.d.mts +0 -2
  304. package/dist/shared/tabBar.mjs +1 -2
  305. package/dist/shared/wxml.mjs +1 -2
  306. package/package.json +15 -13
  307. package/dist/runtime/nativeComponents/richText/helpers.mjs +0 -230
  308. package/dist/runtime/nativeComponents/richText/helpers.mjs.map +0 -1
  309. package/dist/runtime/nativeComponents/scrollView.mjs +0 -88
  310. package/dist/runtime/nativeComponents/scrollView.mjs.map +0 -1
@@ -1,4 +1,4 @@
1
- //#region \0rolldown/runtime.js
1
+ // \0rolldown/runtime.js
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -32,5 +32,4 @@ var __copyProps = (to, from, except, desc) => {
32
32
  };
33
33
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
34
34
 
35
- //#endregion
36
35
  export { __exportAll, __reExport };
@@ -1,7 +1,7 @@
1
1
  import { CONTROL_ATTRS, EVENT_KIND_ALIAS, EVENT_PREFIX_RE, hasControlAttribute, normalizeAttributeName, resolveControlAttributeValue } from "../../shared/wxml.mjs";
2
- import { buildExpression, parseInterpolations } from "./interpolation.mjs";
2
+ import { buildDatasetExpression, buildExpression, parseInterpolations } from "./interpolation.mjs";
3
3
 
4
- //#region src/compiler/wxml/attributes.ts
4
+ // src/compiler/wxml/attributes.ts
5
5
  function extractFor(attribs) {
6
6
  const expr = resolveControlAttributeValue(attribs, "for");
7
7
  const itemName = resolveControlAttributeValue(attribs, "for-item")?.trim() || "item";
@@ -84,12 +84,20 @@ function renderAttributes(attribs, scopeVar, wxsVar, options) {
84
84
  }
85
85
  const useProperty = shouldBindAsProperty(rawName) && (options?.preferProperty || options?.propertyAttributes?.includes(rawName));
86
86
  const name = useProperty ? normalizePropertyName(rawName) : normalizeAttributeName(rawName);
87
- const expr = buildExpression(parseInterpolations(rawValue ?? ""), scopeVar, wxsVar);
87
+ if (!useProperty && name.startsWith("data-")) {
88
+ const expr = buildDatasetExpression(rawValue ?? "", scopeVar, wxsVar);
89
+ buffer += ` \${bindRuntimeDataset(${JSON.stringify(name)}, ${expr})}`;
90
+ continue;
91
+ }
92
+ const parts = parseInterpolations(rawValue ?? "");
93
+ const trimmedParts = name === "style" ? parseInterpolations((rawValue ?? "").trim()) : parts;
94
+ const valueParts = trimmedParts.length === 1 && trimmedParts[0]?.type === "expr" ? trimmedParts : parts;
95
+ const rawExpr = buildExpression(valueParts, scopeVar, wxsVar);
96
+ const expr = name === "style" ? `__weappInlineStyle(${rawExpr})` : rawExpr;
88
97
  buffer += ` ${useProperty ? "." : ""}${name}=\${${expr}}`;
89
98
  }
90
99
  return buffer;
91
100
  }
92
101
 
93
- //#endregion
94
102
  export { extractFor, isConditionalElement, renderAttributes, resolveComponentTagName, stripControlAttributes };
95
103
  //# sourceMappingURL=attributes.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"attributes.mjs","names":[],"sources":["../../../src/compiler/wxml/attributes.ts"],"sourcesContent":["import type { RenderElementNode, RenderNode } from './types'\nimport {\n CONTROL_ATTRS,\n EVENT_KIND_ALIAS,\n EVENT_PREFIX_RE,\n hasControlAttribute,\n normalizeAttributeName,\n resolveControlAttributeValue,\n} from '../../shared/wxml'\nimport { buildExpression, parseInterpolations } from './interpolation'\n\nexport function extractFor(attribs: Record<string, string>) {\n const expr = resolveControlAttributeValue(attribs, 'for')\n const itemName = resolveControlAttributeValue(attribs, 'for-item')?.trim() || 'item'\n let indexName = resolveControlAttributeValue(attribs, 'for-index')?.trim() || 'index'\n const key = resolveControlAttributeValue(attribs, 'key')\n const restAttribs: Record<string, string> = {}\n for (const [name, value] of Object.entries(attribs)) {\n if (CONTROL_ATTRS.has(name)) {\n continue\n }\n restAttribs[name] = value\n }\n if (itemName === indexName) {\n indexName = `${indexName}Index`\n }\n return { expr, itemName, indexName, key, restAttribs }\n}\n\nexport function isConditionalElement(node: RenderNode): node is RenderElementNode {\n if (node.type !== 'element') {\n return false\n }\n const attribs = node.attribs ?? {}\n return hasControlAttribute(attribs, 'if')\n || hasControlAttribute(attribs, 'elif')\n || hasControlAttribute(attribs, 'else')\n}\n\nexport function stripControlAttributes(attribs: Record<string, string>) {\n const result: Record<string, string> = {}\n for (const [name, value] of Object.entries(attribs)) {\n if (!CONTROL_ATTRS.has(name)) {\n result[name] = value\n }\n }\n return result\n}\n\nfunction parseEventAttribute(name: string) {\n if (name.includes(':')) {\n const [prefix, rawEvent] = name.split(':', 2)\n return { prefix, rawEvent }\n }\n const match = EVENT_PREFIX_RE.exec(name)\n if (!match) {\n return undefined\n }\n return { prefix: name.slice(0, name.length - match[1].length), rawEvent: match[1] }\n}\n\nexport function resolveComponentTagName(name: string, componentTags?: Record<string, string>) {\n if (!componentTags) {\n return undefined\n }\n return componentTags[name] ?? componentTags[name.toLowerCase()]\n}\n\nconst PROPERTY_BIND_EXCLUSIONS = new Set(['class', 'style', 'id', 'slot'])\n\nfunction shouldBindAsProperty(name: string) {\n if (PROPERTY_BIND_EXCLUSIONS.has(name)) {\n return false\n }\n if (name.startsWith('data-') || name.startsWith('aria-')) {\n return false\n }\n return true\n}\n\nfunction normalizePropertyName(name: string) {\n return name.replace(/-([a-z])/g, (_, char: string) => char.toUpperCase())\n}\n\nexport function renderAttributes(\n attribs: Record<string, string>,\n scopeVar: string,\n wxsVar: string,\n options?: {\n skipControl?: boolean\n preferProperty?: boolean\n propertyAttributes?: readonly string[]\n },\n) {\n let buffer = ''\n for (const [rawName, rawValue] of Object.entries(attribs)) {\n if (options?.skipControl && CONTROL_ATTRS.has(rawName)) {\n continue\n }\n const eventInfo = parseEventAttribute(rawName)\n if (eventInfo) {\n const normalizedEvent = eventInfo.rawEvent.toLowerCase()\n const aliasedEvent = EVENT_KIND_ALIAS[normalizedEvent]\n const event = aliasedEvent ? normalizedEvent : eventInfo.rawEvent\n const domEvent = aliasedEvent ?? eventInfo.rawEvent\n const handlerExpr = buildExpression(parseInterpolations(rawValue ?? ''), scopeVar, wxsVar)\n const flags = {\n catch: eventInfo.prefix.includes('catch'),\n capture: eventInfo.prefix.includes('capture'),\n }\n buffer += ` \\${bindRuntimeEvent(${JSON.stringify(domEvent)}, ctx.event(${JSON.stringify(event)}, ${handlerExpr}, ${scopeVar}, ${wxsVar}, ${JSON.stringify(flags)}), ${JSON.stringify(flags)})}`\n continue\n }\n const useProperty = shouldBindAsProperty(rawName)\n && (options?.preferProperty || options?.propertyAttributes?.includes(rawName))\n const name = useProperty ? normalizePropertyName(rawName) : normalizeAttributeName(rawName)\n const expr = buildExpression(parseInterpolations(rawValue ?? ''), scopeVar, wxsVar)\n buffer += ` ${useProperty ? '.' : ''}${name}=\\${${expr}}`\n }\n return buffer\n}\n"],"mappings":";;;;AAWA,SAAgB,WAAW,SAAiC;CAC1D,MAAM,OAAO,6BAA6B,SAAS,KAAK;CACxD,MAAM,WAAW,6BAA6B,SAAS,UAAU,CAAC,EAAE,KAAK,KAAK;CAC9E,IAAI,YAAY,6BAA6B,SAAS,WAAW,CAAC,EAAE,KAAK,KAAK;CAC9E,MAAM,MAAM,6BAA6B,SAAS,KAAK;CACvD,MAAM,cAAsC,CAAC;CAC7C,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,OAAO,GAAG;EACnD,IAAI,cAAc,IAAI,IAAI,GACxB;EAEF,YAAY,QAAQ;CACtB;CACA,IAAI,aAAa,WACf,YAAY,GAAG,UAAU;CAE3B,OAAO;EAAE;EAAM;EAAU;EAAW;EAAK;CAAY;AACvD;AAEA,SAAgB,qBAAqB,MAA6C;CAChF,IAAI,KAAK,SAAS,WAChB,OAAO;CAET,MAAM,UAAU,KAAK,WAAW,CAAC;CACjC,OAAO,oBAAoB,SAAS,IAAI,KACnC,oBAAoB,SAAS,MAAM,KACnC,oBAAoB,S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AAiB;GACtC,MAAM,QAAQ,eAAe,kBAAkB,UAAU;GACzD,MAAM,WAAW,gBAAgB,UAAU;GAC3C,MAAM,cAAc,gBAAgB,oBAAoB,YAAY,EAAE,GAAG,UAAU,MAAM;GACzF,MAAM,QAAQ;IACZ,OAAO,UAAU,OAAO,SAAS,OAAO;IACxC,SAAS,UAAU,OAAO,SAAS,SAAS;GAC9C;GACA,UAAU,wBAAwB,KAAK,UAAU,QAAQ,EAAE,cAAc,KAAK,UAAU,KAAK,EAAE,IAAI,YAAY,IAAI,SAAS,IAAI,OAAO,IAAI,KAAK,UAAU,KAAK,EAAE,KAAK,KAAK,UAAU,KAAK,EAAE;GAC5L;EACF;EACA,MAAM,cAAc,qBAAqB,OAAO,MAC1C,SAAS,kBAAkB,SAAS,oBAAoB,SAAS,OAAO;EAC9E,MAAM,OAAO,cAAc,sBAAsB,OAAO,IAAI,uBAAuB,OAAO;EAC1F,MAAM,OAAO,gBAAgB,oBAAoB,YAAY,EAAE,GAAG,UAAU,MAAM;EAClF,UAAU,IAAI,cAAc,MAAM,KAAK,KAAK,MAAM,KAAK;CACzD;CACA,OAAO;AACT"}
1
+ {"version":3,"file":"attributes.mjs","names":[],"sources":["../../../src/compiler/wxml/attributes.ts"],"sourcesContent":["import type { RenderElementNode, RenderNode } from './types'\nimport {\n CONTROL_ATTRS,\n EVENT_KIND_ALIAS,\n EVENT_PREFIX_RE,\n hasControlAttribute,\n normalizeAttributeName,\n resolveControlAttributeValue,\n} from '../../shared/wxml'\nimport { buildDatasetExpression, buildExpression, parseInterpolations } from './interpolation'\n\nexport function extractFor(attribs: Record<string, string>) {\n const expr = resolveControlAttributeValue(attribs, 'for')\n const itemName = resolveControlAttributeValue(attribs, 'for-item')?.trim() || 'item'\n let indexName = resolveControlAttributeValue(attribs, 'for-index')?.trim() || 'index'\n const key = resolveControlAttributeValue(attribs, 'key')\n const restAttribs: Record<string, string> = {}\n for (const [name, value] of Object.entries(attribs)) {\n if (CONTROL_ATTRS.has(name)) {\n continue\n }\n restAttribs[name] = value\n }\n if (itemName === indexName) {\n indexName = `${indexName}Index`\n }\n return { expr, itemName, indexName, key, restAttribs }\n}\n\nexport function isConditionalElement(node: RenderNode): node is RenderElementNode {\n if (node.type !== 'element') {\n return false\n }\n const attribs = node.attribs ?? {}\n return hasControlAttribute(attribs, 'if')\n || hasControlAttribute(attribs, 'elif')\n || hasControlAttribute(attribs, 'else')\n}\n\nexport function stripControlAttributes(attribs: Record<string, string>) {\n const result: Record<string, string> = {}\n for (const [name, value] of Object.entries(attribs)) {\n if (!CONTROL_ATTRS.has(name)) {\n result[name] = value\n }\n }\n return result\n}\n\nfunction parseEventAttribute(name: string) {\n if (name.includes(':')) {\n const [prefix, rawEvent] = name.split(':', 2)\n return { prefix, rawEvent }\n }\n const match = EVENT_PREFIX_RE.exec(name)\n if (!match) {\n return undefined\n }\n return { prefix: name.slice(0, name.length - match[1].length), rawEvent: match[1] }\n}\n\nexport function resolveComponentTagName(name: string, componentTags?: Record<string, string>) {\n if (!componentTags) {\n return undefined\n }\n return componentTags[name] ?? componentTags[name.toLowerCase()]\n}\n\nconst PROPERTY_BIND_EXCLUSIONS = new Set(['class', 'style', 'id', 'slot'])\n\nfunction shouldBindAsProperty(name: string) {\n if (PROPERTY_BIND_EXCLUSIONS.has(name)) {\n return false\n }\n if (name.startsWith('data-') || name.startsWith('aria-')) {\n return false\n }\n return true\n}\n\nfunction normalizePropertyName(name: string) {\n return name.replace(/-([a-z])/g, (_, char: string) => char.toUpperCase())\n}\n\nexport function renderAttributes(\n attribs: Record<string, string>,\n scopeVar: string,\n wxsVar: string,\n options?: {\n skipControl?: boolean\n preferProperty?: boolean\n propertyAttributes?: readonly string[]\n },\n) {\n let buffer = ''\n for (const [rawName, rawValue] of Object.entries(attribs)) {\n if (options?.skipControl && CONTROL_ATTRS.has(rawName)) {\n continue\n }\n const eventInfo = parseEventAttribute(rawName)\n if (eventInfo) {\n const normalizedEvent = eventInfo.rawEvent.toLowerCase()\n const aliasedEvent = EVENT_KIND_ALIAS[normalizedEvent]\n const event = aliasedEvent ? normalizedEvent : eventInfo.rawEvent\n const domEvent = aliasedEvent ?? eventInfo.rawEvent\n const handlerExpr = buildExpression(parseInterpolations(rawValue ?? ''), scopeVar, wxsVar)\n const flags = {\n catch: eventInfo.prefix.includes('catch'),\n capture: eventInfo.prefix.includes('capture'),\n }\n buffer += ` \\${bindRuntimeEvent(${JSON.stringify(domEvent)}, ctx.event(${JSON.stringify(event)}, ${handlerExpr}, ${scopeVar}, ${wxsVar}, ${JSON.stringify(flags)}), ${JSON.stringify(flags)})}`\n continue\n }\n const useProperty = shouldBindAsProperty(rawName)\n && (options?.preferProperty || options?.propertyAttributes?.includes(rawName))\n const name = useProperty ? normalizePropertyName(rawName) : normalizeAttributeName(rawName)\n // DOM 属性保留字符串,完整表达式的值类型由运行时单独保存。\n if (!useProperty && name.startsWith('data-')) {\n const expr = buildDatasetExpression(rawValue ?? '', scopeVar, wxsVar)\n buffer += ` \\${bindRuntimeDataset(${JSON.stringify(name)}, ${expr})}`\n continue\n }\n const parts = parseInterpolations(rawValue ?? '')\n const trimmedParts = name === 'style' ? parseInterpolations((rawValue ?? '').trim()) : parts\n const valueParts = trimmedParts.length === 1 && trimmedParts[0]?.type === 'expr' ? trimmedParts : parts\n const rawExpr = buildExpression(valueParts, scopeVar, wxsVar)\n // WXML 内联 style 不经过 postcss 链路,rpx / vw / vh 需要在运行时换算,\n // 否则浏览器会丢弃整条声明(详见 inlineStyle.ts)。\n const expr = name === 'style' ? `__weappInlineStyle(${rawExpr})` : rawExpr\n buffer += ` ${useProperty ? '.' : ''}${name}=\\${${expr}}`\n }\n return buffer\n}\n"],"mappings":";;;;AAWA,SAAgB,WAAW,SAAiC;CAC1D,MAAM,OAAO,6BAA6B,SAAS,KAAK;CACxD,MAAM,WAAW,6BAA6B,SAAS,UAAU,CAAC,EAAE,KAAK,KAAK;CAC9E,IAAI,YAAY,6BAA6B,SAAS,WAAW,CAAC,EAAE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YAAY,EAAE;EAChD,MAAM,eAAe,SAAS,UAAU,qBAAqB,YAAY,GAAE,CAAE,KAAK,CAAC,IAAI;EACvF,MAAM,aAAa,aAAa,WAAW,KAAK,aAAa,EAAE,EAAE,SAAS,SAAS,eAAe;EAClG,MAAM,UAAU,gBAAgB,YAAY,UAAU,MAAM;EAG5D,MAAM,OAAO,SAAS,UAAU,sBAAsB,QAAQ,KAAK;EACnE,UAAU,IAAI,cAAc,MAAM,KAAK,KAAK,MAAM,KAAK;CACzD;CACA,OAAO;AACT"}
@@ -1,20 +1,26 @@
1
1
  import { RUNTIME_ID } from "../../plugin/constants.mjs";
2
- import { addDependency, createDependencyContext, warnCircularTemplate, warnReadTemplate } from "./dependency.mjs";
3
- import { buildNavigationBarAttrs, extractNavigationBarFromPageMeta } from "./navigation.mjs";
4
- import { parseWxml } from "./parser.mjs";
2
+ import { addDependency, collectDependencies, createDependencyContext, warnCircularTemplate, warnReadTemplate } from "./dependency.mjs";
3
+ import { buildNavigationBarAttrs } from "./navigation.mjs";
4
+ import { normalizeTemplatePath, shouldMarkWxsImport, toRelativeImport } from "./specialNodes.mjs";
5
+ import { prepareWxml } from "./prepare.mjs";
5
6
  import { renderer } from "./renderer.mjs";
6
- import { collectSpecialNodes, normalizeTemplatePath, shouldMarkWxsImport, toRelativeImport } from "./specialNodes.mjs";
7
+ import { collectUnknownTags, formatUnknownTagWarning } from "./unknownTags.mjs";
7
8
  import { readFileSync } from "node:fs";
8
9
 
9
- //#region src/compiler/wxml/compile.ts
10
+ // src/compiler/wxml/compile.ts
10
11
  const WEB_TEMPLATE_QUERY = "weapp-web-template";
11
12
  function appendTemplateQuery(pathname) {
12
13
  return `${pathname}${pathname.includes("?") ? "&" : "?"}${WEB_TEMPLATE_QUERY}`;
13
14
  }
14
- function compileWxml(options) {
15
+ function compileTemplate(options, diagnoseUnknownTags) {
15
16
  const dependencyContext = options.dependencyContext ?? createDependencyContext();
16
17
  const expandDependencies = options.expandDependencies ?? !options.dependencyContext;
17
18
  const warnings = dependencyContext.warnings;
19
+ const warnUnknownTags = (prepared, id) => {
20
+ if (!diagnoseUnknownTags) return;
21
+ const tags = collectUnknownTags(prepared.renderNodes, options.componentTags, prepared.templates.flatMap((template) => template.nodes));
22
+ if (tags.length > 0) warnings.push(formatUnknownTagWarning(tags, id));
23
+ };
18
24
  const expandDependencyTree = (dependencies, importer) => {
19
25
  for (const target of dependencies) {
20
26
  if (dependencyContext.active.has(target)) {
@@ -33,44 +39,24 @@ function compileWxml(options) {
33
39
  continue;
34
40
  }
35
41
  try {
36
- const result = compileWxml({
42
+ const result = prepareWxml({
37
43
  id: target,
38
44
  source,
39
45
  resolveTemplatePath: options.resolveTemplatePath,
40
- resolveWxsPath: options.resolveWxsPath,
41
- dependencyContext,
42
- expandDependencies: false
43
- });
44
- expandDependencyTree(result.dependencies, target);
46
+ resolveWxsPath: options.resolveWxsPath
47
+ }, dependencyContext);
48
+ warnUnknownTags(result, target);
49
+ collectDependencies(result, dependencyContext);
50
+ expandDependencyTree([...result.imports, ...result.includes].map((entry) => entry.id), target);
45
51
  } catch (error) {
46
52
  if (error instanceof Error && error.message) warnings.push(`[web] 无法解析模板依赖: ${target} ${error.message}`);
47
53
  }
48
54
  dependencyContext.active.delete(target);
49
55
  }
50
56
  };
51
- let nodes = parseWxml(options.source);
52
- let navigationBarAttrs;
53
- if (options.navigationBar) {
54
- const extracted = extractNavigationBarFromPageMeta(nodes);
55
- nodes = extracted.nodes;
56
- if (extracted.warnings.length > 0) warnings.push(...extracted.warnings);
57
- navigationBarAttrs = extracted.attrs;
58
- }
59
- const templates = [];
60
- const includes = [];
61
- const imports = [];
62
- const wxs = [];
63
- const renderNodesList = collectSpecialNodes(nodes, {
64
- templates,
65
- includes,
66
- imports,
67
- wxs,
68
- wxsModules: /* @__PURE__ */ new Map(),
69
- warnings,
70
- sourceId: options.id,
71
- resolveTemplate: (raw) => options.resolveTemplatePath(raw, options.id),
72
- resolveWxs: (raw) => options.resolveWxsPath(raw, options.id)
73
- });
57
+ const prepared = prepareWxml(options, dependencyContext);
58
+ warnUnknownTags(prepared, options.id);
59
+ const { renderNodes: renderNodesList, navigationBarAttrs, templates, includes, imports, wxs } = prepared;
74
60
  if (options.navigationBar && options.navigationBar.config.navigationStyle !== "custom") {
75
61
  const attrs = buildNavigationBarAttrs(options.navigationBar.config, navigationBarAttrs);
76
62
  renderNodesList.unshift({
@@ -82,7 +68,9 @@ function compileWxml(options) {
82
68
  const importLines = [
83
69
  `import { html } from 'lit'`,
84
70
  `import { repeat } from 'lit/directives/repeat.js'`,
85
- `import { bindRuntimeEvent } from '${RUNTIME_ID}'`
71
+ `import { bindRuntimeEvent } from '${RUNTIME_ID}'`,
72
+ `import { bindRuntimeDataset } from '${RUNTIME_ID}'`,
73
+ `import { transformInlineStyleValue as __weappInlineStyle } from '${RUNTIME_ID}'`
86
74
  ];
87
75
  const bodyLines = [];
88
76
  const directDependencies = [];
@@ -148,7 +136,7 @@ function compileWxml(options) {
148
136
  if (expandDependencies) {
149
137
  dependencyContext.visited.add(options.id);
150
138
  dependencyContext.active.add(options.id);
151
- expandDependencyTree(directDependencies, options.id);
139
+ expandDependencyTree([...imports, ...includes].map((entry) => entry.id), options.id);
152
140
  dependencyContext.active.delete(options.id);
153
141
  }
154
142
  return {
@@ -161,7 +149,13 @@ function compileWxml(options) {
161
149
  warnings: warnings.length > 0 ? warnings : void 0
162
150
  };
163
151
  }
152
+ function compileWxml(options) {
153
+ return compileTemplate(options, true);
154
+ }
155
+ /** 依赖模块的标签诊断由入口模板按其组件注册作用域统一收集。 */
156
+ function compileWxmlDependency(options) {
157
+ return compileTemplate(options, false);
158
+ }
164
159
 
165
- //#endregion
166
- export { compileWxml };
160
+ export { compileWxml, compileWxmlDependency };
167
161
  //# sourceMappingURL=compile.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"compile.mjs","names":[],"sources":["../../../src/compiler/wxml/compile.ts"],"sourcesContent":["import type {\n ImportEntry,\n IncludeEntry,\n TemplateDefinition,\n WxmlCompileOptions,\n WxmlCompileResult,\n WxsEntry,\n} from './types'\n\nimport { readFileSync } from 'node:fs'\nimport { RUNTIME_ID } from '../../plugin/constants'\nimport { addDependency, createDependencyContext, warnCircularTemplate, warnReadTemplate } from './dependency'\nimport { buildNavigationBarAttrs, extractNavigationBarFromPageMeta } from './navigation'\nimport { parseWxml } from './parser'\nimport { renderer } from './renderer'\nimport { collectSpecialNodes, normalizeTemplatePath, shouldMarkWxsImport, toRelativeImport } from './specialNodes'\n\nconst WEB_TEMPLATE_QUERY = 'weapp-web-template'\n\nfunction appendTemplateQuery(pathname: string) {\n return `${pathname}${pathname.includes('?') ? '&' : '?'}${WEB_TEMPLATE_QUERY}`\n}\n\nexport function compileWxml(options: WxmlCompileOptions): WxmlCompileResult {\n const dependencyContext = options.dependencyContext ?? createDependencyContext()\n const expandDependencies = options.expandDependencies ?? !options.dependencyContext\n const warnings = dependencyContext.warnings\n\n const expandDependencyTree = (dependencies: string[], importer: string) => {\n for (const target of dependencies) {\n if (dependencyContext.active.has(target)) {\n warnCircularTemplate(dependencyContext, importer, target)\n continue\n }\n if (dependencyContext.visited.has(target)) {\n continue\n }\n dependencyContext.visited.add(target)\n dependencyContext.active.add(target)\n let source: string\n try {\n source = readFileSync(target, 'utf8')\n }\n catch {\n warnReadTemplate(dependencyContext, target)\n dependencyContext.active.delete(target)\n continue\n }\n try {\n const result = compileWxml({\n id: target,\n source,\n resolveTemplatePath: options.resolveTemplatePath,\n resolveWxsPath: options.resolveWxsPath,\n dependencyContext,\n expandDependencies: false,\n })\n expandDependencyTree(result.dependencies, target)\n }\n catch (error) {\n if (error instanceof Error && error.message) {\n warnings.push(`[web] 无法解析模板依赖: ${target} ${error.message}`)\n }\n }\n dependencyContext.active.delete(target)\n }\n }\n\n let nodes = parseWxml(options.source)\n let navigationBarAttrs: Record<string, string> | undefined\n if (options.navigationBar) {\n const extracted = extractNavigationBarFromPageMeta(nodes)\n nodes = extracted.nodes\n if (extracted.warnings.length > 0) {\n warnings.push(...extracted.warnings)\n }\n navigationBarAttrs = extracted.attrs\n }\n\n const templates: TemplateDefinition[] = []\n const includes: IncludeEntry[] = []\n const imports: ImportEntry[] = []\n const wxs: WxsEntry[] = []\n const wxsModules = new Map<string, string>()\n\n const renderNodesList = collectSpecialNodes(nodes, {\n templates,\n includes,\n imports,\n wxs,\n wxsModules,\n warnings,\n sourceId: options.id,\n resolveTemplate: (raw: string) => options.resolveTemplatePath(raw, options.id),\n resolveWxs: (raw: string) => options.resolveWxsPath(raw, options.id),\n })\n\n if (options.navigationBar && options.navigationBar.config.navigationStyle !== 'custom') {\n const attrs = buildNavigationBarAttrs(options.navigationBar.config, navigationBarAttrs)\n renderNodesList.unshift({\n type: 'element',\n name: 'weapp-navigation-bar',\n attribs: attrs,\n })\n }\n\n const importLines: string[] = [\n `import { html } from 'lit'`,\n `import { repeat } from 'lit/directives/repeat.js'`,\n `import { bindRuntimeEvent } from '${RUNTIME_ID}'`,\n ]\n const bodyLines: string[] = []\n const directDependencies: string[] = []\n\n for (const entry of imports) {\n const importPath = normalizeTemplatePath(toRelativeImport(options.id, entry.id))\n importLines.push(`import { templates as ${entry.importName} } from '${appendTemplateQuery(importPath)}'`)\n addDependency(entry.id, dependencyContext, directDependencies)\n }\n\n for (const entry of includes) {\n const importPath = normalizeTemplatePath(toRelativeImport(options.id, entry.id))\n importLines.push(`import { render as ${entry.importName} } from '${appendTemplateQuery(importPath)}'`)\n addDependency(entry.id, dependencyContext, directDependencies)\n }\n\n for (const entry of wxs) {\n if (entry.kind === 'src') {\n const baseImport = normalizeTemplatePath(toRelativeImport(options.id, entry.value))\n const importPath = shouldMarkWxsImport(entry.value)\n ? `${baseImport}?wxs`\n : baseImport\n importLines.push(`import ${entry.importName} from '${importPath}'`)\n addDependency(entry.value, dependencyContext, directDependencies)\n }\n }\n\n if (templates.length > 0 || imports.length > 0) {\n const templatePairs: string[] = []\n for (const entry of imports) {\n templatePairs.push(`...${entry.importName}`)\n }\n for (const template of templates) {\n const rendered = renderer.renderNodes(template.nodes, 'scope', '__wxs_modules', options.componentTags)\n templatePairs.push(`${JSON.stringify(template.name)}: (scope, ctx) => ${rendered}`)\n }\n bodyLines.push(`const __templates = { ${templatePairs.join(', ')} }`)\n }\n else {\n bodyLines.push(`const __templates = {}`)\n }\n\n if (wxs.length > 0) {\n bodyLines.push(`const __wxs_inline_cache = Object.create(null)`)\n bodyLines.push(`let __wxs_modules = {}`)\n const wxsMapEntries: string[] = []\n for (const entry of wxs) {\n if (entry.kind === 'inline') {\n const inlineCode = entry.value.trim()\n const cacheKey = JSON.stringify(entry.module)\n if (inlineCode) {\n bodyLines.push(`function ${entry.importName}(ctx) {`)\n bodyLines.push(` if (!__wxs_inline_cache[${cacheKey}]) {`)\n bodyLines.push(` __wxs_inline_cache[${cacheKey}] = ctx.createWxsModule(${JSON.stringify(inlineCode)}, ${JSON.stringify(options.id)})`)\n bodyLines.push(` }`)\n bodyLines.push(` return __wxs_inline_cache[${cacheKey}]`)\n bodyLines.push(`}`)\n }\n else {\n bodyLines.push(`function ${entry.importName}() { return {} }`)\n }\n wxsMapEntries.push(`${JSON.stringify(entry.module)}: ${entry.importName}(ctx)`)\n continue\n }\n wxsMapEntries.push(`${JSON.stringify(entry.module)}: ${entry.importName}`)\n }\n bodyLines.push(`function __resolveWxsModules(ctx) {`)\n bodyLines.push(` return { ${wxsMapEntries.join(', ')} }`)\n bodyLines.push(`}`)\n }\n else {\n bodyLines.push(`const __wxs_modules = {}`)\n }\n\n const includesRender = includes.map(entry => `${entry.importName}(scope, ctx)`)\n const renderContent = renderer.renderNodes(renderNodesList, 'scope', '__wxs_modules', options.componentTags)\n const contentExpr = includesRender.length > 0\n ? `[${[...includesRender, renderContent].join(', ')}]`\n : renderContent\n\n bodyLines.push(`export function render(scope, ctx) {`)\n if (wxs.length > 0) {\n bodyLines.push(` __wxs_modules = __resolveWxsModules(ctx)`)\n }\n bodyLines.push(` return ${contentExpr}`)\n bodyLines.push(`}`)\n bodyLines.push(`export const templates = __templates`)\n bodyLines.push(`export default render`)\n\n if (expandDependencies) {\n dependencyContext.visited.add(options.id)\n dependencyContext.active.add(options.id)\n expandDependencyTree(directDependencies, options.id)\n dependencyContext.active.delete(options.id)\n }\n\n const code = [...importLines, '', ...bodyLines].join('\\n')\n const dependencies = expandDependencies ? dependencyContext.dependencies : directDependencies\n return {\n code,\n dependencies,\n warnings: warnings.length > 0 ? warnings : undefined,\n }\n}\n"],"mappings":";;;;;;;;;AAiBA,MAAM,qBAAqB;AAE3B,SAAS,oBAAoB,UAAkB;CAC7C,OAAO,GAAG,WAAW,SAAS,SAAS,GAAG,IAAI,MAAM,MAAM;AAC5D;AAEA,SAAgB,YAAY,SAAgD;CAC1E,MAAM,oBAAoB,QAAQ,qBAAqB,wBAAwB;CAC/E,MAAM,qBAAqB,QAAQ,sBAAsB,CAAC,QAAQ;CAClE,MAAM,WAAW,kBAAkB;CAEnC,MAAM,wBAAwB,cAAwB,aAAqB;EACzE,KAAK,MAAM,UAAU,cAAc;GACjC,IAAI,kBAAkB,OAAO,IAAI,MAAM,GAAG;IACxC,qBAAqB,mBAAmB,UAAU,MAAM;IACxD;GACF;GACA,IAAI,kBAAkB,QAAQ,IAAI,MAAM,GACtC;GAEF,kBAAkB,QAAQ,IAAI,MAAM;GACpC,kBAAkB,OAAO,IAAI,MAAM;GACnC,IAAI;GACJ,IAAI;IACF,SAAS,aAAa,QAAQ,MAAM;GACtC,QACM;IACJ,iBAAiB,mBAAmB,MAAM;IAC1C,kBAAkB,OAAO,OAAO,MAAM;IACtC;GACF;GACA,IAAI;IACF,MAAM,SAAS,YAAY;KACzB,IAAI;KACJ;KACA,qBAAqB,QAAQ;KAC7B,gBAAgB,QAAQ;KACxB;KACA,oBAAoB;IACtB,CAAC;IACD,qBAAqB,OAAO,cAAc,MAAM;GAClD,SACO,OAAO;IACZ,IAAI,iBAAiB,SAAS,MAAM,SAClC,SAAS,KAAK,mBAAmB,OAAO,GAAG,MAAM,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ACF"}
1
+ {"version":3,"file":"compile.mjs","names":[],"sources":["../../../src/compiler/wxml/compile.ts"],"sourcesContent":["import type { WxmlCompileOptions, WxmlCompileResult } from './types'\n\nimport { readFileSync } from 'node:fs'\nimport { RUNTIME_ID } from '../../plugin/constants'\nimport { addDependency, collectDependencies, createDependencyContext, warnCircularTemplate, warnReadTemplate } from './dependency'\nimport { buildNavigationBarAttrs } from './navigation'\nimport { prepareWxml } from './prepare'\nimport { renderer } from './renderer'\nimport { normalizeTemplatePath, shouldMarkWxsImport, toRelativeImport } from './specialNodes'\nimport { collectUnknownTags, formatUnknownTagWarning } from './unknownTags'\n\nconst WEB_TEMPLATE_QUERY = 'weapp-web-template'\n\nfunction appendTemplateQuery(pathname: string) {\n return `${pathname}${pathname.includes('?') ? '&' : '?'}${WEB_TEMPLATE_QUERY}`\n}\n\nfunction compileTemplate(options: WxmlCompileOptions, diagnoseUnknownTags: boolean): WxmlCompileResult {\n const dependencyContext = options.dependencyContext ?? createDependencyContext()\n const expandDependencies = options.expandDependencies ?? !options.dependencyContext\n const warnings = dependencyContext.warnings\n\n const warnUnknownTags = (prepared: ReturnType<typeof prepareWxml>, id: string) => {\n if (!diagnoseUnknownTags) {\n return\n }\n const tags = collectUnknownTags(prepared.renderNodes, options.componentTags, prepared.templates.flatMap(template => template.nodes))\n if (tags.length > 0) {\n warnings.push(formatUnknownTagWarning(tags, id))\n }\n }\n\n const expandDependencyTree = (dependencies: string[], importer: string) => {\n for (const target of dependencies) {\n if (dependencyContext.active.has(target)) {\n warnCircularTemplate(dependencyContext, importer, target)\n continue\n }\n if (dependencyContext.visited.has(target)) {\n continue\n }\n dependencyContext.visited.add(target)\n dependencyContext.active.add(target)\n let source: string\n try {\n source = readFileSync(target, 'utf8')\n }\n catch {\n warnReadTemplate(dependencyContext, target)\n dependencyContext.active.delete(target)\n continue\n }\n try {\n const result = prepareWxml({\n id: target,\n source,\n resolveTemplatePath: options.resolveTemplatePath,\n resolveWxsPath: options.resolveWxsPath,\n }, dependencyContext)\n warnUnknownTags(result, target)\n collectDependencies(result, dependencyContext)\n expandDependencyTree([...result.imports, ...result.includes].map(entry => entry.id), target)\n }\n catch (error) {\n if (error instanceof Error && error.message) {\n warnings.push(`[web] 无法解析模板依赖: ${target} ${error.message}`)\n }\n }\n dependencyContext.active.delete(target)\n }\n }\n\n const prepared = prepareWxml(options, dependencyContext)\n warnUnknownTags(prepared, options.id)\n const {\n renderNodes: renderNodesList,\n navigationBarAttrs,\n templates,\n includes,\n imports,\n wxs,\n } = prepared\n\n if (options.navigationBar && options.navigationBar.config.navigationStyle !== 'custom') {\n const attrs = buildNavigationBarAttrs(options.navigationBar.config, navigationBarAttrs)\n renderNodesList.unshift({\n type: 'element',\n name: 'weapp-navigation-bar',\n attribs: attrs,\n })\n }\n\n const importLines: string[] = [\n `import { html } from 'lit'`,\n `import { repeat } from 'lit/directives/repeat.js'`,\n `import { bindRuntimeEvent } from '${RUNTIME_ID}'`,\n `import { bindRuntimeDataset } from '${RUNTIME_ID}'`,\n `import { transformInlineStyleValue as __weappInlineStyle } from '${RUNTIME_ID}'`,\n ]\n const bodyLines: string[] = []\n const directDependencies: string[] = []\n\n for (const entry of imports) {\n const importPath = normalizeTemplatePath(toRelativeImport(options.id, entry.id))\n importLines.push(`import { templates as ${entry.importName} } from '${appendTemplateQuery(importPath)}'`)\n addDependency(entry.id, dependencyContext, directDependencies)\n }\n\n for (const entry of includes) {\n const importPath = normalizeTemplatePath(toRelativeImport(options.id, entry.id))\n importLines.push(`import { render as ${entry.importName} } from '${appendTemplateQuery(importPath)}'`)\n addDependency(entry.id, dependencyContext, directDependencies)\n }\n\n for (const entry of wxs) {\n if (entry.kind === 'src') {\n const baseImport = normalizeTemplatePath(toRelativeImport(options.id, entry.value))\n const importPath = shouldMarkWxsImport(entry.value)\n ? `${baseImport}?wxs`\n : baseImport\n importLines.push(`import ${entry.importName} from '${importPath}'`)\n addDependency(entry.value, dependencyContext, directDependencies)\n }\n }\n\n if (templates.length > 0 || imports.length > 0) {\n const templatePairs: string[] = []\n for (const entry of imports) {\n templatePairs.push(`...${entry.importName}`)\n }\n for (const template of templates) {\n const rendered = renderer.renderNodes(template.nodes, 'scope', '__wxs_modules', options.componentTags)\n templatePairs.push(`${JSON.stringify(template.name)}: (scope, ctx) => ${rendered}`)\n }\n bodyLines.push(`const __templates = { ${templatePairs.join(', ')} }`)\n }\n else {\n bodyLines.push(`const __templates = {}`)\n }\n\n if (wxs.length > 0) {\n bodyLines.push(`const __wxs_inline_cache = Object.create(null)`)\n bodyLines.push(`let __wxs_modules = {}`)\n const wxsMapEntries: string[] = []\n for (const entry of wxs) {\n if (entry.kind === 'inline') {\n const inlineCode = entry.value.trim()\n const cacheKey = JSON.stringify(entry.module)\n if (inlineCode) {\n bodyLines.push(`function ${entry.importName}(ctx) {`)\n bodyLines.push(` if (!__wxs_inline_cache[${cacheKey}]) {`)\n bodyLines.push(` __wxs_inline_cache[${cacheKey}] = ctx.createWxsModule(${JSON.stringify(inlineCode)}, ${JSON.stringify(options.id)})`)\n bodyLines.push(` }`)\n bodyLines.push(` return __wxs_inline_cache[${cacheKey}]`)\n bodyLines.push(`}`)\n }\n else {\n bodyLines.push(`function ${entry.importName}() { return {} }`)\n }\n wxsMapEntries.push(`${JSON.stringify(entry.module)}: ${entry.importName}(ctx)`)\n continue\n }\n wxsMapEntries.push(`${JSON.stringify(entry.module)}: ${entry.importName}`)\n }\n bodyLines.push(`function __resolveWxsModules(ctx) {`)\n bodyLines.push(` return { ${wxsMapEntries.join(', ')} }`)\n bodyLines.push(`}`)\n }\n else {\n bodyLines.push(`const __wxs_modules = {}`)\n }\n\n const includesRender = includes.map(entry => `${entry.importName}(scope, ctx)`)\n const renderContent = renderer.renderNodes(renderNodesList, 'scope', '__wxs_modules', options.componentTags)\n const contentExpr = includesRender.length > 0\n ? `[${[...includesRender, renderContent].join(', ')}]`\n : renderContent\n\n bodyLines.push(`export function render(scope, ctx) {`)\n if (wxs.length > 0) {\n bodyLines.push(` __wxs_modules = __resolveWxsModules(ctx)`)\n }\n bodyLines.push(` return ${contentExpr}`)\n bodyLines.push(`}`)\n bodyLines.push(`export const templates = __templates`)\n bodyLines.push(`export default render`)\n\n if (expandDependencies) {\n dependencyContext.visited.add(options.id)\n dependencyContext.active.add(options.id)\n expandDependencyTree([...imports, ...includes].map(entry => entry.id), options.id)\n dependencyContext.active.delete(options.id)\n }\n\n const code = [...importLines, '', ...bodyLines].join('\\n')\n const dependencies = expandDependencies ? dependencyContext.dependencies : directDependencies\n return {\n code,\n dependencies,\n warnings: warnings.length > 0 ? warnings : undefined,\n }\n}\n\nexport function compileWxml(options: WxmlCompileOptions): WxmlCompileResult {\n return compileTemplate(options, true)\n}\n\n/** 依赖模块的标签诊断由入口模板按其组件注册作用域统一收集。 */\nexport function compileWxmlDependency(options: WxmlCompileOptions): WxmlCompileResult {\n return compileTemplate(options, false)\n}\n"],"mappings":";;;;;;;;;;AAWA,MAAM,qBAAqB;AAE3B,SAAS,oBAAoB,UAAkB;CAC7C,OAAO,GAAG,WAAW,SAAS,SAAS,GAAG,IAAI,MAAM,MAAM;AAC5D;AAEA,SAAS,gBAAgB,SAA6B,qBAAiD;CACrG,MAAM,oBAAoB,QAAQ,qBAAqB,wBAAwB;CAC/E,MAAM,qBAAqB,QAAQ,sBAAsB,CAAC,QAAQ;CAClE,MAAM,WAAW,kBAAkB;CAEnC,MAAM,mBAAmB,UAA0C,OAAe;EAChF,IAAI,CAAC,qBACH;EAEF,MAAM,OAAO,mBAAmB,SAAS,aAAa,QAAQ,eAAe,SAAS,UAAU,SAAQ,aAAY,SAAS,KAAK,CAAC;EACnI,IAAI,KAAK,SAAS,GAChB,SAAS,KAAK,wBAAwB,MAAM,EAAE,CAAC;CAEnD;CAEA,MAAM,wBAAwB,cAAwB,aAAqB;EACzE,KAAK,MAAM,UAAU,cAAc;GACjC,IAAI,kBAAkB,OAAO,IAAI,MAAM,GAAG;IACxC,qBAAqB,mBAAmB,UAAU,MAAM;IACx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AAQ,EAAE;EACvC,qBAAqB,CAAC,GAAG,SAAS,GAAG,QAAQ,CAAC,CAAC,KAAI,UAAS,MAAM,EAAE,GAAG,QAAQ,EAAE;EACjF,kBAAkB,OAAO,OAAO,QAAQ,EAAE;CAC5C;CAIA,OAAO;EACL,MAHW;GAAC,GAAG;GAAa;GAAI,GAAG;EAAS,CAAC,CAAC,KAAK,IAGhD;EACH,cAHmB,qBAAqB,kBAAkB,eAAe;EAIzE,UAAU,SAAS,SAAS,IAAI,WAAW;CAC7C;AACF;AAEA,SAAgB,YAAY,SAAgD;CAC1E,OAAO,gBAAgB,SAAS,IAAI;AACtC;;AAGA,SAAgB,sBAAsB,SAAgD;CACpF,OAAO,gBAAgB,SAAS,KAAK;AACvC"}
@@ -1,4 +1,4 @@
1
- //#region src/compiler/wxml/dependency.ts
1
+ // src/compiler/wxml/dependency.ts
2
2
  function createDependencyContext() {
3
3
  return {
4
4
  warnings: [],
@@ -16,6 +16,14 @@ function addDependency(value, context, direct) {
16
16
  direct?.push(value);
17
17
  }
18
18
  }
19
+ /** 依赖扫描完成分析后,按编译器的分组顺序登记直接依赖。 */
20
+ function collectDependencies(entries, context) {
21
+ const dependencies = [];
22
+ for (const entry of entries.imports) addDependency(entry.id, context, dependencies);
23
+ for (const entry of entries.includes) addDependency(entry.id, context, dependencies);
24
+ for (const entry of entries.wxs) if (entry.kind === "src") addDependency(entry.value, context, dependencies);
25
+ return dependencies;
26
+ }
19
27
  function warnReadTemplate(context, target) {
20
28
  context.warnings.push(`[web] 无法读取模板依赖: ${target}`);
21
29
  }
@@ -26,6 +34,5 @@ function warnCircularTemplate(context, from, target) {
26
34
  context.warnings.push(`[web] WXML 循环引用: ${from} -> ${target}`);
27
35
  }
28
36
 
29
- //#endregion
30
- export { addDependency, createDependencyContext, warnCircularTemplate, warnReadTemplate };
37
+ export { addDependency, collectDependencies, createDependencyContext, warnCircularTemplate, warnReadTemplate };
31
38
  //# sourceMappingURL=dependency.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"dependency.mjs","names":[],"sources":["../../../src/compiler/wxml/dependency.ts"],"sourcesContent":["import type { WxmlDependencyContext } from './types'\n\nexport function createDependencyContext(): WxmlDependencyContext {\n return {\n warnings: [],\n dependencies: [],\n dependencySet: new Set(),\n visited: new Set(),\n active: new Set(),\n circularWarnings: new Set(),\n }\n}\n\nexport function addDependency(\n value: string,\n context: WxmlDependencyContext,\n direct?: string[],\n) {\n if (!context.dependencySet.has(value)) {\n context.dependencySet.add(value)\n context.dependencies.push(value)\n direct?.push(value)\n }\n}\n\nexport function warnReadTemplate(context: WxmlDependencyContext, target: string) {\n context.warnings.push(`[web] 无法读取模板依赖: ${target}`)\n}\n\nexport function warnCircularTemplate(\n context: WxmlDependencyContext,\n from: string,\n target: string,\n) {\n const key = `${from}=>${target}`\n if (context.circularWarnings.has(key)) {\n return\n }\n context.circularWarnings.add(key)\n context.warnings.push(`[web] WXML 循环引用: ${from} -> ${target}`)\n}\n"],"mappings":";AAEA,SAAgB,0BAAiD;CAC/D,OAAO;EACL,UAAU,CAAC;EACX,cAAc,CAAC;EACf,+BAAe,IAAI,IAAI;EACvB,yBAAS,IAAI,IAAI;EACjB,wBAAQ,IAAI,IAAI;EAChB,kCAAkB,IAAI,IAAI;CAC5B;AACF;AAEA,SAAgB,cACd,OACA,SACA,QACA;CACA,IAAI,CAAC,QAAQ,cAAc,IAAI,KAAK,GAAG;EACrC,QAAQ,cAAc,IAAI,KAAK;EAC/B,QAAQ,aAAa,KAAK,KAAK;EAC/B,QAAQ,KAAK,KAAK;CACpB;AACF;AAEA,SAAgB,iBAAiB,SAAgC,QAAgB;CAC/E,QAAQ,SAAS,KAAK,mBAAmB,QAAQ;AACnD;AAEA,SAAgB,qBACd,SACA,MACA,QACA;CACA,MAAM,MAAM,GAAG,KAAK,IAAI;CACxB,IAAI,QAAQ,iBAAiB,IAAI,GAAG,GAClC;CAEF,QAAQ,iBAAiB,IAAI,GAAG;CAChC,QAAQ,SAAS,KAAK,oBAAoB,KAAK,MAAM,QAAQ;AAC/D"}
1
+ {"version":3,"file":"dependency.mjs","names":[],"sources":["../../../src/compiler/wxml/dependency.ts"],"sourcesContent":["import type { ImportEntry, IncludeEntry, WxmlDependencyContext, WxsEntry } from './types'\n\nexport function createDependencyContext(): WxmlDependencyContext {\n return {\n warnings: [],\n dependencies: [],\n dependencySet: new Set(),\n visited: new Set(),\n active: new Set(),\n circularWarnings: new Set(),\n }\n}\n\nexport function addDependency(\n value: string,\n context: WxmlDependencyContext,\n direct?: string[],\n) {\n if (!context.dependencySet.has(value)) {\n context.dependencySet.add(value)\n context.dependencies.push(value)\n direct?.push(value)\n }\n}\n\n/** 依赖扫描完成分析后,按编译器的分组顺序登记直接依赖。 */\nexport function collectDependencies(\n entries: { imports: ImportEntry[], includes: IncludeEntry[], wxs: WxsEntry[] },\n context: WxmlDependencyContext,\n) {\n const dependencies: string[] = []\n for (const entry of entries.imports) {\n addDependency(entry.id, context, dependencies)\n }\n for (const entry of entries.includes) {\n addDependency(entry.id, context, dependencies)\n }\n for (const entry of entries.wxs) {\n if (entry.kind === 'src') {\n addDependency(entry.value, context, dependencies)\n }\n }\n return dependencies\n}\n\nexport function warnReadTemplate(context: WxmlDependencyContext, target: string) {\n context.warnings.push(`[web] 无法读取模板依赖: ${target}`)\n}\n\nexport function warnCircularTemplate(\n context: WxmlDependencyContext,\n from: string,\n target: string,\n) {\n const key = `${from}=>${target}`\n if (context.circularWarnings.has(key)) {\n return\n }\n context.circularWarnings.add(key)\n context.warnings.push(`[web] WXML 循环引用: ${from} -> ${target}`)\n}\n"],"mappings":";AAEA,SAAgB,0BAAiD;CAC/D,OAAO;EACL,UAAU,CAAC;EACX,cAAc,CAAC;EACf,+BAAe,IAAI,IAAI;EACvB,yBAAS,IAAI,IAAI;EACjB,wBAAQ,IAAI,IAAI;EAChB,kCAAkB,IAAI,IAAI;CAC5B;AACF;AAEA,SAAgB,cACd,OACA,SACA,QACA;CACA,IAAI,CAAC,QAAQ,cAAc,IAAI,KAAK,GAAG;EACrC,QAAQ,cAAc,IAAI,KAAK;EAC/B,QAAQ,aAAa,KAAK,KAAK;EAC/B,QAAQ,KAAK,KAAK;CACpB;AACF;;AAGA,SAAgB,oBACd,SACA,SACA;CACA,MAAM,eAAyB,CAAC;CAChC,KAAK,MAAM,SAAS,QAAQ,SAC1B,cAAc,MAAM,IAAI,SAAS,YAAY;CAE/C,KAAK,MAAM,SAAS,QAAQ,UAC1B,cAAc,MAAM,IAAI,SAAS,YAAY;CAE/C,KAAK,MAAM,SAAS,QAAQ,KAC1B,IAAI,MAAM,SAAS,OACjB,cAAc,MAAM,OAAO,SAAS,YAAY;CAGpD,OAAO;AACT;AAEA,SAAgB,iBAAiB,SAAgC,QAAgB;CAC/E,QAAQ,SAAS,KAAK,mBAAmB,QAAQ;AACnD;AAEA,SAAgB,qBACd,SACA,MACA,QACA;CACA,MAAM,MAAM,GAAG,KAAK,IAAI;CACxB,IAAI,QAAQ,iBAAiB,IAAI,GAAG,GAClC;CAEF,QAAQ,iBAAiB,IAAI,GAAG;CAChC,QAAQ,SAAS,KAAK,oBAAoB,KAAK,MAAM,QAAQ;AAC/D"}
@@ -1,4 +1,4 @@
1
- //#region src/compiler/wxml/interpolation.ts
1
+ // src/compiler/wxml/interpolation.ts
2
2
  function parseInterpolations(value) {
3
3
  const parts = [];
4
4
  if (!value.includes("{{")) return [{
@@ -45,6 +45,17 @@ function buildExpression(parts, scopeVar, wxsVar) {
45
45
  return `ctx.eval(${JSON.stringify(part.value)}, ${scopeVar}, ${wxsVar})`;
46
46
  }).join(" + ")})`;
47
47
  }
48
+ /** 完整表达式保留原值,混合插值逐段转为字符串,避免相邻数字执行加法。 */
49
+ function buildDatasetExpression(value, scopeVar, wxsVar) {
50
+ const trimmedParts = parseInterpolations(value.trim());
51
+ if (trimmedParts.length === 1 && trimmedParts[0]?.type === "expr") return buildExpression(trimmedParts, scopeVar, wxsVar);
52
+ const parts = parseInterpolations(value);
53
+ if (parts.length <= 1) return buildExpression(parts, scopeVar, wxsVar);
54
+ return `(${parts.map((part) => {
55
+ const expression = buildExpression([part], scopeVar, wxsVar);
56
+ return part.type === "text" ? expression : `String(${expression} ?? '')`;
57
+ }).join(" + ")})`;
58
+ }
48
59
  function hasTopLevelColon(expression) {
49
60
  let depth = 0;
50
61
  let inSingleQuote = false;
@@ -136,6 +147,5 @@ function buildTemplateDataExpression(raw, scopeVar, wxsVar) {
136
147
  return buildExpression(parseInterpolations(raw), scopeVar, wxsVar);
137
148
  }
138
149
 
139
- //#endregion
140
- export { buildExpression, buildTemplateDataExpression, parseInterpolations };
150
+ export { buildDatasetExpression, buildExpression, buildTemplateDataExpression, parseInterpolations };
141
151
  //# sourceMappingURL=interpolation.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"interpolation.mjs","names":[],"sources":["../../../src/compiler/wxml/interpolation.ts"],"sourcesContent":["import type { InterpolationPart } from './types'\n\nexport function parseInterpolations(value: string): InterpolationPart[] {\n const parts: InterpolationPart[] = []\n if (!value.includes('{{')) {\n return [{ type: 'text', value }]\n }\n let cursor = 0\n while (cursor < value.length) {\n const start = value.indexOf('{{', cursor)\n if (start === -1) {\n parts.push({ type: 'text', value: value.slice(cursor) })\n break\n }\n if (start > cursor) {\n parts.push({ type: 'text', value: value.slice(cursor, start) })\n }\n const end = value.indexOf('}}', start + 2)\n if (end === -1) {\n parts.push({ type: 'text', value: value.slice(start) })\n break\n }\n const expr = value.slice(start + 2, end).trim()\n if (expr) {\n parts.push({ type: 'expr', value: expr })\n }\n cursor = end + 2\n }\n return parts\n}\n\nexport function buildExpression(parts: InterpolationPart[], scopeVar: string, wxsVar: string) {\n if (parts.length === 0) {\n return '\"\"'\n }\n if (parts.length === 1 && parts[0]?.type === 'text') {\n return JSON.stringify(parts[0].value)\n }\n if (parts.length === 1 && parts[0]?.type === 'expr') {\n return `ctx.eval(${JSON.stringify(parts[0].value)}, ${scopeVar}, ${wxsVar})`\n }\n const segments = parts.map((part) => {\n if (part.type === 'text') {\n return JSON.stringify(part.value)\n }\n return `ctx.eval(${JSON.stringify(part.value)}, ${scopeVar}, ${wxsVar})`\n })\n return `(${segments.join(' + ')})`\n}\n\nfunction hasTopLevelColon(expression: string) {\n let depth = 0\n let inSingleQuote = false\n let inDoubleQuote = false\n let inTemplate = false\n let escaped = false\n let sawTopLevelQuestion = false\n\n for (let index = 0; index < expression.length; index += 1) {\n const char = expression[index]!\n\n if (inSingleQuote) {\n if (escaped) {\n escaped = false\n continue\n }\n if (char === '\\\\') {\n escaped = true\n continue\n }\n if (char === '\\'') {\n inSingleQuote = false\n }\n continue\n }\n if (inDoubleQuote) {\n if (escaped) {\n escaped = false\n continue\n }\n if (char === '\\\\') {\n escaped = true\n continue\n }\n if (char === '\"') {\n inDoubleQuote = false\n }\n continue\n }\n if (inTemplate) {\n if (escaped) {\n escaped = false\n continue\n }\n if (char === '\\\\') {\n escaped = true\n continue\n }\n if (char === '`') {\n inTemplate = false\n }\n continue\n }\n\n if (char === '\\'') {\n inSingleQuote = true\n continue\n }\n if (char === '\"') {\n inDoubleQuote = true\n continue\n }\n if (char === '`') {\n inTemplate = true\n continue\n }\n\n if (char === '(' || char === '[' || char === '{') {\n depth += 1\n continue\n }\n if (char === ')' || char === ']' || char === '}') {\n depth = Math.max(0, depth - 1)\n continue\n }\n\n if (depth !== 0) {\n continue\n }\n\n if (char === '?') {\n sawTopLevelQuestion = true\n continue\n }\n if (char === ':') {\n return !sawTopLevelQuestion\n }\n }\n\n return false\n}\n\nfunction shouldWrapShorthandObject(expression: string) {\n const trimmed = expression.trim()\n if (trimmed.startsWith('{') || trimmed.startsWith('[') || trimmed.startsWith('(')) {\n return false\n }\n return hasTopLevelColon(trimmed)\n}\n\nexport function buildTemplateDataExpression(raw: string, scopeVar: string, wxsVar: string) {\n const trimmed = raw.trim()\n const parts = parseInterpolations(trimmed)\n if (parts.length === 1 && parts[0]?.type === 'expr') {\n const expr = parts[0].value.trim()\n const normalizedExpr = shouldWrapShorthandObject(expr) ? `{ ${expr} }` : expr\n return buildExpression([{ type: 'expr', value: normalizedExpr }], scopeVar, wxsVar)\n }\n return buildExpression(parseInterpolations(raw), scopeVar, wxsVar)\n}\n"],"mappings":";AAEA,SAAgB,oBAAoB,OAAoC;CACtE,MAAM,QAA6B,CAAC;CACpC,IAAI,CAAC,MAAM,SAAS,IAAI,GACtB,OAAO,CAAC;EAAE,MAAM;EAAQ;CAAM,CAAC;CAEjC,IAAI,SAAS;CACb,OAAO,SAAS,MAAM,QAAQ;EAC5B,MAAM,QAAQ,MAAM,QAAQ,MAAM,MAAM;EACxC,IAAI,UAAU,IAAI;GAChB,MAAM,KAAK;IAAE,MAAM;IAAQ,OAAO,MAAM,MAAM,MAAM;GAAE,CAAC;GACvD;EACF;EACA,IAAI,QAAQ,QACV,MAAM,KAAK;GAAE,MAAM;GAAQ,OAAO,MAAM,MAAM,QAAQ,KAAK;EAAE,CAAC;EAEhE,MAAM,MAAM,MAAM,QAAQ,MAAM,QAAQ,CAAC;EACzC,IAAI,QAAQ,IAAI;GACd,MAAM,KAAK;IAAE,MAAM;IAAQ,OAAO,MAAM,MAAM,KAAK;GAAE,CAAC;GACtD;EACF;EACA,MAAM,OAAO,MAAM,MAAM,QAAQ,GAAG,GAAG,CAAC,CAAC,KAAK;EAC9C,IAAI,MACF,MAAM,KAAK;GAAE,MAAM;GAAQ,OAAO;EAAK,CAAC;EAE1C,SAAS,MAAM;CACjB;CACA,OAAO;AACT;AAEA,SAAgB,gBAAgB,OAA4B,UAAkB,QAAgB;CAC5F,IAAI,MAAM,WAAW,GACnB,OAAO;CAET,IAAI,MAAM,WAAW,KAAK,MAAM,EAAE,EAAE,SAAS,QAC3C,OAAO,KAAK,UAAU,MAAM,EAAE,CAAC,KAAK;CAEtC,IAAI,MAAM,WAAW,KAAK,MAAM,EAAE,EAAE,SAAS,QAC3C,OAAO,YAAY,KAAK,UAAU,MAAM,EAAE,CAAC,KAAK,EAAE,IAAI,SAAS,IAAI,OAAO;CA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GAChB,sBAAsB;GACtB;EACF;EACA,IAAI,SAAS,KACX,OAAO,CAAC;CAEZ;CAEA,OAAO;AACT;AAEA,SAAS,0BAA0B,YAAoB;CACrD,MAAM,UAAU,WAAW,KAAK;CAChC,IAAI,QAAQ,WAAW,GAAG,KAAK,QAAQ,WAAW,GAAG,KAAK,QAAQ,WAAW,GAAG,GAC9E,OAAO;CAET,OAAO,iBAAiB,OAAO;AACjC;AAEA,SAAgB,4BAA4B,KAAa,UAAkB,QAAgB;CAEzF,MAAM,QAAQ,oBADE,IAAI,KACoB,CAAC;CACzC,IAAI,MAAM,WAAW,KAAK,MAAM,EAAE,EAAE,SAAS,QAAQ;EACnD,MAAM,OAAO,MAAM,EAAE,CAAC,MAAM,KAAK;EAEjC,OAAO,gBAAgB,CAAC;GAAE,MAAM;GAAQ,OADjB,0BAA0B,IAAI,IAAI,KAAK,KAAK,MAAM;EACX,CAAC,GAAG,UAAU,MAAM;CACpF;CACA,OAAO,gBAAgB,oBAAoB,GAAG,GAAG,UAAU,MAAM;AACnE"}
1
+ {"version":3,"file":"interpolation.mjs","names":[],"sources":["../../../src/compiler/wxml/interpolation.ts"],"sourcesContent":["import type { InterpolationPart } from './types'\n\nexport function parseInterpolations(value: string): InterpolationPart[] {\n const parts: InterpolationPart[] = []\n if (!value.includes('{{')) {\n return [{ type: 'text', value }]\n }\n let cursor = 0\n while (cursor < value.length) {\n const start = value.indexOf('{{', cursor)\n if (start === -1) {\n parts.push({ type: 'text', value: value.slice(cursor) })\n break\n }\n if (start > cursor) {\n parts.push({ type: 'text', value: value.slice(cursor, start) })\n }\n const end = value.indexOf('}}', start + 2)\n if (end === -1) {\n parts.push({ type: 'text', value: value.slice(start) })\n break\n }\n const expr = value.slice(start + 2, end).trim()\n if (expr) {\n parts.push({ type: 'expr', value: expr })\n }\n cursor = end + 2\n }\n return parts\n}\n\nexport function buildExpression(parts: InterpolationPart[], scopeVar: string, wxsVar: string) {\n if (parts.length === 0) {\n return '\"\"'\n }\n if (parts.length === 1 && parts[0]?.type === 'text') {\n return JSON.stringify(parts[0].value)\n }\n if (parts.length === 1 && parts[0]?.type === 'expr') {\n return `ctx.eval(${JSON.stringify(parts[0].value)}, ${scopeVar}, ${wxsVar})`\n }\n const segments = parts.map((part) => {\n if (part.type === 'text') {\n return JSON.stringify(part.value)\n }\n return `ctx.eval(${JSON.stringify(part.value)}, ${scopeVar}, ${wxsVar})`\n })\n return `(${segments.join(' + ')})`\n}\n\n/** 完整表达式保留原值,混合插值逐段转为字符串,避免相邻数字执行加法。 */\nexport function buildDatasetExpression(value: string, scopeVar: string, wxsVar: string) {\n const trimmedParts = parseInterpolations(value.trim())\n if (trimmedParts.length === 1 && trimmedParts[0]?.type === 'expr') {\n return buildExpression(trimmedParts, scopeVar, wxsVar)\n }\n const parts = parseInterpolations(value)\n if (parts.length <= 1) {\n return buildExpression(parts, scopeVar, wxsVar)\n }\n const segments = parts.map((part) => {\n const expression = buildExpression([part], scopeVar, wxsVar)\n return part.type === 'text' ? expression : `String(${expression} ?? '')`\n })\n return `(${segments.join(' + ')})`\n}\n\nfunction hasTopLevelColon(expression: string) {\n let depth = 0\n let inSingleQuote = false\n let inDoubleQuote = false\n let inTemplate = false\n let escaped = false\n let sawTopLevelQuestion = false\n\n for (let index = 0; index < expression.length; index += 1) {\n const char = expression[index]!\n\n if (inSingleQuote) {\n if (escaped) {\n escaped = false\n continue\n }\n if (char === '\\\\') {\n escaped = true\n continue\n }\n if (char === '\\'') {\n inSingleQuote = false\n }\n continue\n }\n if (inDoubleQuote) {\n if (escaped) {\n escaped = false\n continue\n }\n if (char === '\\\\') {\n escaped = true\n continue\n }\n if (char === '\"') {\n inDoubleQuote = false\n }\n continue\n }\n if (inTemplate) {\n if (escaped) {\n escaped = false\n continue\n }\n if (char === '\\\\') {\n escaped = true\n continue\n }\n if (char === '`') {\n inTemplate = false\n }\n continue\n }\n\n if (char === '\\'') {\n inSingleQuote = true\n continue\n }\n if (char === '\"') {\n inDoubleQuote = true\n continue\n }\n if (char === '`') {\n inTemplate = true\n continue\n }\n\n if (char === '(' || char === '[' || char === '{') {\n depth += 1\n continue\n }\n if (char === ')' || char === ']' || char === '}') {\n depth = Math.max(0, depth - 1)\n continue\n }\n\n if (depth !== 0) {\n continue\n }\n\n if (char === '?') {\n sawTopLevelQuestion = true\n continue\n }\n if (char === ':') {\n return !sawTopLevelQuestion\n }\n }\n\n return false\n}\n\nfunction shouldWrapShorthandObject(expression: string) {\n const trimmed = expression.trim()\n if (trimmed.startsWith('{') || trimmed.startsWith('[') || trimmed.startsWith('(')) {\n return false\n }\n return hasTopLevelColon(trimmed)\n}\n\nexport function buildTemplateDataExpression(raw: string, scopeVar: string, wxsVar: string) {\n const trimmed = raw.trim()\n const parts = parseInterpolations(trimmed)\n if (parts.length === 1 && parts[0]?.type === 'expr') {\n const expr = parts[0].value.trim()\n const normalizedExpr = shouldWrapShorthandObject(expr) ? `{ ${expr} }` : expr\n return buildExpression([{ type: 'expr', value: normalizedExpr }], scopeVar, wxsVar)\n }\n return buildExpression(parseInterpolations(raw), scopeVar, wxsVar)\n}\n"],"mappings":";AAEA,SAAgB,oBAAoB,OAAoC;CACtE,MAAM,QAA6B,CAAC;CACpC,IAAI,CAAC,MAAM,SAAS,IAAI,GACtB,OAAO,CAAC;EAAE,MAAM;EAAQ;CAAM,CAAC;CAEjC,IAAI,SAAS;CACb,OAAO,SAAS,MAAM,QAAQ;EAC5B,MAAM,QAAQ,MAAM,QAAQ,MAAM,MAAM;EACxC,IAAI,UAAU,IAAI;GAChB,MAAM,KAAK;IAAE,MAAM;IAAQ,OAAO,MAAM,MAAM,MAAM;GAAE,CAAC;GACvD;EACF;EACA,IAAI,QAAQ,QACV,MAAM,KAAK;GAAE,MAAM;GAAQ,OAAO,MAAM,MAAM,QAAQ,KAAK;EAAE,CAAC;EAEhE,MAAM,MAAM,MAAM,QAAQ,MAAM,QAAQ,CAAC;EACzC,IAAI,QAAQ,IAAI;GACd,MAAM,KAAK;IAAE,MA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AAQ,WAAW,GAAG,GAC9E,OAAO;CAET,OAAO,iBAAiB,OAAO;AACjC;AAEA,SAAgB,4BAA4B,KAAa,UAAkB,QAAgB;CAEzF,MAAM,QAAQ,oBADE,IAAI,KACoB,CAAC;CACzC,IAAI,MAAM,WAAW,KAAK,MAAM,EAAE,EAAE,SAAS,QAAQ;EACnD,MAAM,OAAO,MAAM,EAAE,CAAC,MAAM,KAAK;EAEjC,OAAO,gBAAgB,CAAC;GAAE,MAAM;GAAQ,OADjB,0BAA0B,IAAI,IAAI,KAAK,KAAK,MAAM;EACX,CAAC,GAAG,UAAU,MAAM;CACpF;CACA,OAAO,gBAAgB,oBAAoB,GAAG,GAAG,UAAU,MAAM;AACnE"}
@@ -0,0 +1,60 @@
1
+ // src/compiler/wxml/nativeTags.ts
2
+ const NATIVE_COMPONENT_NAMES = /* @__PURE__ */ new Set([
3
+ "ad",
4
+ "ad-custom",
5
+ "audio",
6
+ "block",
7
+ "button",
8
+ "camera",
9
+ "canvas",
10
+ "checkbox",
11
+ "checkbox-group",
12
+ "cover-image",
13
+ "cover-view",
14
+ "editor",
15
+ "form",
16
+ "functional-page-navigator",
17
+ "icon",
18
+ "image",
19
+ "import",
20
+ "include",
21
+ "input",
22
+ "keyboard-accessory",
23
+ "label",
24
+ "live-player",
25
+ "live-pusher",
26
+ "map",
27
+ "match-media",
28
+ "movable-area",
29
+ "movable-view",
30
+ "navigation-bar",
31
+ "navigator",
32
+ "official-account",
33
+ "open-data",
34
+ "page-container",
35
+ "page-meta",
36
+ "picker",
37
+ "picker-view",
38
+ "picker-view-column",
39
+ "progress",
40
+ "radio",
41
+ "radio-group",
42
+ "rich-text",
43
+ "scroll-view",
44
+ "share-element",
45
+ "slider",
46
+ "slot",
47
+ "swiper",
48
+ "swiper-item",
49
+ "switch",
50
+ "template",
51
+ "text",
52
+ "textarea",
53
+ "video",
54
+ "view",
55
+ "voip-room",
56
+ "web-view"
57
+ ]);
58
+
59
+ export { NATIVE_COMPONENT_NAMES };
60
+ //# sourceMappingURL=nativeTags.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nativeTags.mjs","names":[],"sources":["../../../src/compiler/wxml/nativeTags.ts"],"sourcesContent":["// 本文件由 components.weapp.json 生成,请运行 node packages-runtime/web/scripts/generate-native-tags.mjs。\nexport const NATIVE_COMPONENT_NAMES = new Set([\n 'ad',\n 'ad-custom',\n 'audio',\n 'block',\n 'button',\n 'camera',\n 'canvas',\n 'checkbox',\n 'checkbox-group',\n 'cover-image',\n 'cover-view',\n 'editor',\n 'form',\n 'functional-page-navigator',\n 'icon',\n 'image',\n 'import',\n 'include',\n 'input',\n 'keyboard-accessory',\n 'label',\n 'live-player',\n 'live-pusher',\n 'map',\n 'match-media',\n 'movable-area',\n 'movable-view',\n 'navigation-bar',\n 'navigator',\n 'official-account',\n 'open-data',\n 'page-container',\n 'page-meta',\n 'picker',\n 'picker-view',\n 'picker-view-column',\n 'progress',\n 'radio',\n 'radio-group',\n 'rich-text',\n 'scroll-view',\n 'share-element',\n 'slider',\n 'slot',\n 'swiper',\n 'swiper-item',\n 'switch',\n 'template',\n 'text',\n 'textarea',\n 'video',\n 'view',\n 'voip-room',\n 'web-view',\n])\n"],"mappings":";AACA,MAAa,yCAAyB,IAAI,IAAI;CAC5C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
@@ -1,4 +1,4 @@
1
- //#region src/compiler/wxml/navigation.ts
1
+ // src/compiler/wxml/navigation.ts
2
2
  const NAVIGATION_BAR_ATTRS = /* @__PURE__ */ new Set([
3
3
  "title",
4
4
  "background-color",
@@ -78,6 +78,5 @@ function buildNavigationBarAttrs(config, overrides) {
78
78
  return attrs;
79
79
  }
80
80
 
81
- //#endregion
82
81
  export { buildNavigationBarAttrs, extractNavigationBarFromPageMeta };
83
82
  //# sourceMappingURL=navigation.mjs.map
@@ -1,6 +1,6 @@
1
1
  import { parseDocument } from "htmlparser2";
2
2
 
3
- //#region src/compiler/wxml/parser.ts
3
+ // src/compiler/wxml/parser.ts
4
4
  function isRenderableNode(node) {
5
5
  if (node.type === "directive" || node.type === "comment") return false;
6
6
  if (node.type === "text") return node.data.trim().length > 0;
@@ -36,6 +36,5 @@ function parseWxml(source) {
36
36
  }).children.filter(isRenderableNode).map((node) => convertNode(node)).filter((node) => Boolean(node));
37
37
  }
38
38
 
39
- //#endregion
40
39
  export { parseWxml };
41
40
  //# sourceMappingURL=parser.mjs.map
@@ -0,0 +1,42 @@
1
+ import { extractNavigationBarFromPageMeta } from "./navigation.mjs";
2
+ import { parseWxml } from "./parser.mjs";
3
+ import { collectSpecialNodes } from "./specialNodes.mjs";
4
+
5
+ // src/compiler/wxml/prepare.ts
6
+ /** 共享模板分析阶段,依赖扫描复用其结果而不生成渲染代码。 */
7
+ function prepareWxml(options, dependencyContext) {
8
+ const warnings = dependencyContext.warnings;
9
+ let nodes = parseWxml(options.source);
10
+ let navigationBarAttrs;
11
+ if (options.navigationBar) {
12
+ const extracted = extractNavigationBarFromPageMeta(nodes);
13
+ nodes = extracted.nodes;
14
+ if (extracted.warnings.length > 0) warnings.push(...extracted.warnings);
15
+ navigationBarAttrs = extracted.attrs;
16
+ }
17
+ const templates = [];
18
+ const includes = [];
19
+ const imports = [];
20
+ const wxs = [];
21
+ return {
22
+ renderNodes: collectSpecialNodes(nodes, {
23
+ templates,
24
+ includes,
25
+ imports,
26
+ wxs,
27
+ wxsModules: /* @__PURE__ */ new Map(),
28
+ warnings,
29
+ sourceId: options.id,
30
+ resolveTemplate: (raw) => options.resolveTemplatePath(raw, options.id),
31
+ resolveWxs: (raw) => options.resolveWxsPath(raw, options.id)
32
+ }),
33
+ navigationBarAttrs,
34
+ templates,
35
+ includes,
36
+ imports,
37
+ wxs
38
+ };
39
+ }
40
+
41
+ export { prepareWxml };
42
+ //# sourceMappingURL=prepare.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepare.mjs","names":[],"sources":["../../../src/compiler/wxml/prepare.ts"],"sourcesContent":["import type {\n ImportEntry,\n IncludeEntry,\n TemplateDefinition,\n WxmlCompileOptions,\n WxmlDependencyContext,\n WxsEntry,\n} from './types'\nimport { extractNavigationBarFromPageMeta } from './navigation'\nimport { parseWxml } from './parser'\nimport { collectSpecialNodes } from './specialNodes'\n\n/** 共享模板分析阶段,依赖扫描复用其结果而不生成渲染代码。 */\nexport function prepareWxml(options: WxmlCompileOptions, dependencyContext: WxmlDependencyContext) {\n const warnings = dependencyContext.warnings\n let nodes = parseWxml(options.source)\n let navigationBarAttrs: Record<string, string> | undefined\n if (options.navigationBar) {\n const extracted = extractNavigationBarFromPageMeta(nodes)\n nodes = extracted.nodes\n if (extracted.warnings.length > 0) {\n warnings.push(...extracted.warnings)\n }\n navigationBarAttrs = extracted.attrs\n }\n\n const templates: TemplateDefinition[] = []\n const includes: IncludeEntry[] = []\n const imports: ImportEntry[] = []\n const wxs: WxsEntry[] = []\n const renderNodes = collectSpecialNodes(nodes, {\n templates,\n includes,\n imports,\n wxs,\n wxsModules: new Map<string, string>(),\n warnings,\n sourceId: options.id,\n resolveTemplate: (raw: string) => options.resolveTemplatePath(raw, options.id),\n resolveWxs: (raw: string) => options.resolveWxsPath(raw, options.id),\n })\n\n return { renderNodes, navigationBarAttrs, templates, includes, imports, wxs }\n}\n"],"mappings":";;;;;;AAaA,SAAgB,YAAY,SAA6B,mBAA0C;CACjG,MAAM,WAAW,kBAAkB;CACnC,IAAI,QAAQ,UAAU,QAAQ,MAAM;CACpC,IAAI;CACJ,IAAI,QAAQ,eAAe;EACzB,MAAM,YAAY,iCAAiC,KAAK;EACxD,QAAQ,UAAU;EAClB,IAAI,UAAU,SAAS,SAAS,GAC9B,SAAS,KAAK,GAAG,UAAU,QAAQ;EAErC,qBAAqB,UAAU;CACjC;CAEA,MAAM,YAAkC,CAAC;CACzC,MAAM,WAA2B,CAAC;CAClC,MAAM,UAAyB,CAAC;CAChC,MAAM,MAAkB,CAAC;CAazB,OAAO;EAAE,aAZW,oBAAoB,OAAO;GAC7C;GACA;GACA;GACA;GACA,4BAAY,IAAI,IAAoB;GACpC;GACA,UAAU,QAAQ;GAClB,kBAAkB,QAAgB,QAAQ,oBAAoB,KAAK,QAAQ,EAAE;GAC7E,aAAa,QAAgB,QAAQ,eAAe,KAAK,QAAQ,EAAE;EACrE,CAEmB;EAAG;EAAoB;EAAW;EAAU;EAAS;CAAI;AAC9E"}
@@ -3,7 +3,7 @@ import { SELF_CLOSING_TAGS, hasControlAttribute, normalizeTagName, resolveContro
3
3
  import { buildExpression, buildTemplateDataExpression, parseInterpolations } from "./interpolation.mjs";
4
4
  import { extractFor, isConditionalElement, renderAttributes, resolveComponentTagName, stripControlAttributes } from "./attributes.mjs";
5
5
 
6
- //#region src/compiler/wxml/renderer.ts
6
+ // src/compiler/wxml/renderer.ts
7
7
  var Renderer = class {
8
8
  renderNodes(nodes, scopeVar, wxsVar, componentTags) {
9
9
  const parts = [];
@@ -113,6 +113,5 @@ var Renderer = class {
113
113
  };
114
114
  const renderer = new Renderer();
115
115
 
116
- //#endregion
117
116
  export { Renderer, renderer };
118
117
  //# sourceMappingURL=renderer.mjs.map
@@ -2,7 +2,7 @@ import { isKnownUnsupportedNativeComponent } from "../../shared/nativeComponents
2
2
  import { TEMPLATE_IMPORT_TAG_NAMES, TEMPLATE_INCLUDE_TAG_NAMES } from "../../shared/wxml.mjs";
3
3
  import { dirname, relative } from "pathe";
4
4
 
5
- //#region src/compiler/wxml/specialNodes.ts
5
+ // src/compiler/wxml/specialNodes.ts
6
6
  function shouldMarkWxsImport(pathname) {
7
7
  const lower = pathname.toLowerCase();
8
8
  if (lower.endsWith(".wxs") || lower.endsWith(".wxs.ts") || lower.endsWith(".wxs.js")) return false;
@@ -86,6 +86,5 @@ function toRelativeImport(from, target) {
86
86
  return `./${rel}`;
87
87
  }
88
88
 
89
- //#endregion
90
89
  export { collectSpecialNodes, normalizeTemplatePath, shouldMarkWxsImport, toRelativeImport };
91
90
  //# sourceMappingURL=specialNodes.mjs.map
@@ -1,4 +1,3 @@
1
- //#region src/compiler/wxml/types.d.ts
2
1
  export interface NavigationBarConfig {
3
2
  title?: string;
4
3
  backgroundColor?: string;
@@ -7,5 +6,4 @@ export interface NavigationBarConfig {
7
6
  loading?: boolean;
8
7
  navigationStyle?: string;
9
8
  }
10
- //#endregion
11
9
  //# sourceMappingURL=types.d.mts.map
@@ -0,0 +1,33 @@
1
+ import { isKnownUnsupportedNativeComponent, resolveNativeComponentWebTag } from "../../shared/nativeComponents.mjs";
2
+ import { NATIVE_COMPONENT_NAMES } from "./nativeTags.mjs";
3
+ import { isHTMLTag, isMathMLTag, isSVGTag } from "@vue/shared";
4
+
5
+ // src/compiler/wxml/unknownTags.ts
6
+ const CONTROL_TAGS = /* @__PURE__ */ new Set(["wxs"]);
7
+ function isKnownTag(name, componentTags) {
8
+ const normalized = name.toLowerCase();
9
+ const isRegistered = (tag) => componentTags && Object.hasOwn(componentTags, tag) && typeof componentTags[tag] === "string" && Boolean(componentTags[tag]);
10
+ if (!normalized || isRegistered(name) || isRegistered(normalized)) return true;
11
+ return CONTROL_TAGS.has(normalized) || NATIVE_COMPONENT_NAMES.has(normalized) || isHTMLTag(normalized) || isSVGTag(name) || isMathMLTag(normalized) || Boolean(resolveNativeComponentWebTag(normalized)) || isKnownUnsupportedNativeComponent(normalized);
12
+ }
13
+ function collectFromNodes(nodes, unknown, componentTags) {
14
+ for (const node of nodes ?? []) {
15
+ if (node.type !== "element") continue;
16
+ const name = node.name ?? "";
17
+ if (name && !isKnownTag(name, componentTags)) unknown.add(name);
18
+ collectFromNodes(node.children, unknown, componentTags);
19
+ }
20
+ }
21
+ /** 收集用户模板中可能拼写错误或尚未注册的标签,不改变渲染结果。 */
22
+ function collectUnknownTags(nodes, componentTags, extraNodes = []) {
23
+ const unknown = /* @__PURE__ */ new Set();
24
+ collectFromNodes(nodes, unknown, componentTags);
25
+ collectFromNodes(extraNodes, unknown, componentTags);
26
+ return [...unknown];
27
+ }
28
+ function formatUnknownTagWarning(tags, filename) {
29
+ return `[web] 模板中使用了未知标签${filename ? ` (${filename})` : ""}:${tags.map((tag) => `<${tag}>`).join("、")}。这些标签可能尚未在 usingComponents 中注册或存在拼写错误,请检查组件注册和标签名称。`;
30
+ }
31
+
32
+ export { collectUnknownTags, formatUnknownTagWarning };
33
+ //# sourceMappingURL=unknownTags.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unknownTags.mjs","names":[],"sources":["../../../src/compiler/wxml/unknownTags.ts"],"sourcesContent":["import type { RenderNode } from './types'\nimport { isHTMLTag, isMathMLTag, isSVGTag } from '@vue/shared'\nimport { isKnownUnsupportedNativeComponent, resolveNativeComponentWebTag } from '../../shared/nativeComponents'\nimport { NATIVE_COMPONENT_NAMES } from './nativeTags'\n\nconst CONTROL_TAGS = new Set(['wxs'])\n\nfunction isKnownTag(name: string, componentTags?: Record<string, string>) {\n const normalized = name.toLowerCase()\n const isRegistered = (tag: string) => componentTags\n && Object.hasOwn(componentTags, tag)\n && typeof componentTags[tag] === 'string'\n && Boolean(componentTags[tag])\n if (!normalized || isRegistered(name) || isRegistered(normalized)) {\n return true\n }\n return CONTROL_TAGS.has(normalized)\n || NATIVE_COMPONENT_NAMES.has(normalized)\n || isHTMLTag(normalized)\n || isSVGTag(name)\n || isMathMLTag(normalized)\n || Boolean(resolveNativeComponentWebTag(normalized))\n || isKnownUnsupportedNativeComponent(normalized)\n}\n\nfunction collectFromNodes(nodes: RenderNode[] | undefined, unknown: Set<string>, componentTags?: Record<string, string>) {\n for (const node of nodes ?? []) {\n if (node.type !== 'element') {\n continue\n }\n const name = node.name ?? ''\n if (name && !isKnownTag(name, componentTags)) {\n unknown.add(name)\n }\n collectFromNodes(node.children, unknown, componentTags)\n }\n}\n\n/** 收集用户模板中可能拼写错误或尚未注册的标签,不改变渲染结果。 */\nexport function collectUnknownTags(\n nodes: RenderNode[] | undefined,\n componentTags?: Record<string, string>,\n extraNodes: RenderNode[] = [],\n) {\n const unknown = new Set<string>()\n collectFromNodes(nodes, unknown, componentTags)\n collectFromNodes(extraNodes, unknown, componentTags)\n return [...unknown]\n}\n\nexport function formatUnknownTagWarning(tags: string[], filename?: string) {\n const location = filename ? ` (${filename})` : ''\n const list = tags.map(tag => `<${tag}>`).join('、')\n return `[web] 模板中使用了未知标签${location}:${list}。`\n + '这些标签可能尚未在 usingComponents 中注册或存在拼写错误,请检查组件注册和标签名称。'\n}\n"],"mappings":";;;;;AAKA,MAAM,+BAAe,IAAI,IAAI,CAAC,KAAK,CAAC;AAEpC,SAAS,WAAW,MAAc,eAAwC;CACxE,MAAM,aAAa,KAAK,YAAY;CACpC,MAAM,gBAAgB,QAAgB,iBACjC,OAAO,OAAO,eAAe,GAAG,KAChC,OAAO,cAAc,SAAS,YAC9B,QAAQ,cAAc,IAAI;CAC/B,IAAI,CAAC,cAAc,aAAa,IAAI,KAAK,aAAa,UAAU,GAC9D,OAAO;CAET,OAAO,aAAa,IAAI,UAAU,KAC7B,uBAAuB,IAAI,UAAU,KACrC,UAAU,UAAU,KACpB,SAAS,IAAI,KACb,YAAY,UAAU,KACtB,QAAQ,6BAA6B,UAAU,CAAC,KAChD,kCAAkC,UAAU;AACnD;AAEA,SAAS,iBAAiB,OAAiC,SAAsB,eAAwC;CACvH,KAAK,MAAM,QAAQ,SAAS,CAAC,GAAG;EAC9B,IAAI,KAAK,SAAS,WAChB;EAEF,MAAM,OAAO,KAAK,QAAQ;EAC1B,IAAI,QAAQ,CAAC,WAAW,MAAM,aAAa,GACzC,QAAQ,IAAI,IAAI;EAElB,iBAAiB,KAAK,UAAU,SAAS,aAAa;CACxD;AACF;;AAGA,SAAgB,mBACd,OACA,eACA,aAA2B,CAAC,GAC5B;CACA,MAAM,0BAAU,IAAI,IAAY;CAChC,iBAAiB,OAAO,SAAS,aAAa;CAC9C,iBAAiB,YAAY,SAAS,aAAa;CACnD,OAAO,CAAC,GAAG,OAAO;AACpB;AAEA,SAAgB,wBAAwB,MAAgB,UAAmB;CAGzE,OAAO,mBAFU,WAAW,KAAK,SAAS,KAAK,GAEZ,GADtB,KAAK,KAAI,QAAO,IAAI,IAAI,EAAE,CAAC,CAAC,KAAK,GACL,EAAE;AAE7C"}
@@ -1,4 +1,4 @@
1
- //#region src/compiler/wxs.ts
1
+ // src/compiler/wxs.ts
2
2
  const REQUIRE_RE = /require\(\s*['"]([^'"]+)['"]\s*\)/g;
3
3
  function normalizePath(p) {
4
4
  return p.replace(/\\/g, "/");
@@ -78,6 +78,5 @@ function transformWxsToEsm(code, id, options) {
78
78
  };
79
79
  }
80
80
 
81
- //#endregion
82
81
  export { transformWxsToEsm };
83
82
  //# sourceMappingURL=wxs.mjs.map