@mpxjs/webpack-plugin 2.10.15 → 2.10.16-beta.11

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 (274) hide show
  1. package/lib/config.js +60 -0
  2. package/lib/dependencies/AppEntryDependency.js +2 -2
  3. package/lib/dependencies/DynamicEntryDependency.js +1 -1
  4. package/lib/dependencies/ImportDependency.js +102 -0
  5. package/lib/dependencies/RecordModuleIdMapDependency.js +49 -0
  6. package/lib/dependencies/ResolveDependency.js +1 -1
  7. package/lib/{retry-runtime-module.js → dependencies/RetryRuntimeModule.js} +1 -1
  8. package/lib/file-loader.js +13 -3
  9. package/lib/helpers.js +2 -0
  10. package/lib/index.js +51 -25
  11. package/lib/json-compiler/helper.js +72 -2
  12. package/lib/json-compiler/index.js +16 -56
  13. package/lib/json-compiler/plugin.js +2 -2
  14. package/lib/loader.js +10 -4
  15. package/lib/native-loader.js +6 -3
  16. package/lib/platform/json/wx/index.js +30 -29
  17. package/lib/platform/style/wx/index.js +8 -1
  18. package/lib/platform/template/wx/component-config/ad.js +5 -0
  19. package/lib/platform/template/wx/component-config/button.js +21 -5
  20. package/lib/platform/template/wx/component-config/camera.js +25 -3
  21. package/lib/platform/template/wx/component-config/canvas.js +8 -1
  22. package/lib/platform/template/wx/component-config/component.js +31 -33
  23. package/lib/platform/template/wx/component-config/cover-image.js +7 -2
  24. package/lib/platform/template/wx/component-config/cover-view.js +3 -1
  25. package/lib/platform/template/wx/component-config/fix-component-name.js +2 -2
  26. package/lib/platform/template/wx/component-config/form.js +27 -2
  27. package/lib/platform/template/wx/component-config/image.js +5 -0
  28. package/lib/platform/template/wx/component-config/input.js +10 -0
  29. package/lib/platform/template/wx/component-config/label.js +10 -2
  30. package/lib/platform/template/wx/component-config/map.js +11 -0
  31. package/lib/platform/template/wx/component-config/movable-area.js +4 -1
  32. package/lib/platform/template/wx/component-config/movable-view.js +17 -2
  33. package/lib/platform/template/wx/component-config/navigator.js +26 -0
  34. package/lib/platform/template/wx/component-config/picker-view.js +12 -0
  35. package/lib/platform/template/wx/component-config/picker.js +3 -1
  36. package/lib/platform/template/wx/component-config/progress.js +11 -1
  37. package/lib/platform/template/wx/component-config/rich-text.js +5 -0
  38. package/lib/platform/template/wx/component-config/scroll-view.js +12 -1
  39. package/lib/platform/template/wx/component-config/slider.js +20 -0
  40. package/lib/platform/template/wx/component-config/swiper-item.js +5 -2
  41. package/lib/platform/template/wx/component-config/swiper.js +10 -0
  42. package/lib/platform/template/wx/component-config/text.js +5 -0
  43. package/lib/platform/template/wx/component-config/textarea.js +19 -2
  44. package/lib/platform/template/wx/component-config/unsupported.js +10 -1
  45. package/lib/platform/template/wx/component-config/video.js +10 -0
  46. package/lib/platform/template/wx/index.js +21 -1
  47. package/lib/react/index.js +2 -0
  48. package/lib/react/processJSON.js +39 -71
  49. package/lib/react/processStyles.js +3 -2
  50. package/lib/react/processTemplate.js +8 -6
  51. package/lib/react/script-helper.js +6 -16
  52. package/lib/react/style-helper.js +10 -2
  53. package/lib/resolver/AddEnvPlugin.js +13 -0
  54. package/lib/resolver/AddModePlugin.js +18 -0
  55. package/lib/runtime/components/react/context.ts +13 -6
  56. package/lib/runtime/components/react/dist/context.d.ts +76 -0
  57. package/lib/runtime/components/react/dist/context.d.ts.map +1 -0
  58. package/lib/runtime/components/react/dist/context.js +1 -0
  59. package/lib/runtime/components/react/dist/event.config.d.ts +8 -0
  60. package/lib/runtime/components/react/dist/event.config.d.ts.map +1 -0
  61. package/lib/runtime/components/react/dist/getInnerListeners.d.ts +8 -0
  62. package/lib/runtime/components/react/dist/getInnerListeners.d.ts.map +1 -0
  63. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +13 -0
  64. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts.map +1 -0
  65. package/lib/runtime/components/react/dist/mpx-button.d.ts +69 -0
  66. package/lib/runtime/components/react/dist/mpx-button.d.ts.map +1 -0
  67. package/lib/runtime/components/react/dist/mpx-camera.d.ts +27 -0
  68. package/lib/runtime/components/react/dist/mpx-camera.d.ts.map +1 -0
  69. package/lib/runtime/components/react/dist/mpx-camera.jsx +197 -0
  70. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +24 -0
  71. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts.map +1 -0
  72. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +8 -0
  73. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts.map +1 -0
  74. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +7 -0
  75. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts.map +1 -0
  76. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +21 -0
  77. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts.map +1 -0
  78. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +9 -0
  79. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts.map +1 -0
  80. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +11 -0
  81. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts.map +1 -0
  82. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +3 -0
  83. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts.map +1 -0
  84. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +33 -0
  85. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts.map +1 -0
  86. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +53 -0
  87. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts.map +1 -0
  88. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +21 -0
  89. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts.map +1 -0
  90. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +33 -0
  91. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts.map +1 -0
  92. package/lib/runtime/components/react/dist/mpx-form.d.ts +28 -0
  93. package/lib/runtime/components/react/dist/mpx-form.d.ts.map +1 -0
  94. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +19 -0
  95. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts.map +1 -0
  96. package/lib/runtime/components/react/dist/mpx-image.d.ts +22 -0
  97. package/lib/runtime/components/react/dist/mpx-image.d.ts.map +1 -0
  98. package/lib/runtime/components/react/dist/mpx-image.jsx +81 -37
  99. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +8 -0
  100. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts.map +1 -0
  101. package/lib/runtime/components/react/dist/mpx-input.d.ts +51 -0
  102. package/lib/runtime/components/react/dist/mpx-input.d.ts.map +1 -0
  103. package/lib/runtime/components/react/dist/mpx-input.jsx +40 -12
  104. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +13 -0
  105. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts.map +1 -0
  106. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +61 -50
  107. package/lib/runtime/components/react/dist/mpx-label.d.ts +21 -0
  108. package/lib/runtime/components/react/dist/mpx-label.d.ts.map +1 -0
  109. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +21 -0
  110. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts.map +1 -0
  111. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +66 -0
  112. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts.map +1 -0
  113. package/lib/runtime/components/react/dist/mpx-nav.d.ts +9 -0
  114. package/lib/runtime/components/react/dist/mpx-nav.d.ts.map +1 -0
  115. package/lib/runtime/components/react/dist/mpx-nav.jsx +132 -0
  116. package/lib/runtime/components/react/dist/mpx-navigator.d.ts +10 -0
  117. package/lib/runtime/components/react/dist/mpx-navigator.d.ts.map +1 -0
  118. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +7 -0
  119. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts.map +1 -0
  120. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +8 -0
  121. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts.map +1 -0
  122. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +7 -0
  123. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts.map +1 -0
  124. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +7 -0
  125. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts.map +1 -0
  126. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +7 -0
  127. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts.map +1 -0
  128. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +3 -0
  129. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts.map +1 -0
  130. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +7 -0
  131. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts.map +1 -0
  132. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +7 -0
  133. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts.map +1 -0
  134. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +107 -0
  135. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts.map +1 -0
  136. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +33 -0
  137. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts.map +1 -0
  138. package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +4 -3
  139. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +9 -0
  140. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts.map +1 -0
  141. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +24 -0
  142. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts.map +1 -0
  143. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +12 -18
  144. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +15 -0
  145. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts.map +1 -0
  146. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.jsx +8 -11
  147. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts +14 -0
  148. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts.map +1 -0
  149. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.jsx +20 -0
  150. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +17 -0
  151. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts.map +1 -0
  152. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +13 -0
  153. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts.map +1 -0
  154. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +12 -0
  155. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts.map +1 -0
  156. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +23 -0
  157. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts.map +1 -0
  158. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +17 -0
  159. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts.map +1 -0
  160. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +16 -0
  161. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts.map +1 -0
  162. package/lib/runtime/components/react/dist/mpx-portal/index.jsx +5 -1
  163. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +30 -0
  164. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts.map +1 -0
  165. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +10 -0
  166. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts.map +1 -0
  167. package/lib/runtime/components/react/dist/mpx-progress.d.ts +24 -0
  168. package/lib/runtime/components/react/dist/mpx-progress.d.ts.map +1 -0
  169. package/lib/runtime/components/react/dist/mpx-progress.jsx +26 -22
  170. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +21 -0
  171. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts.map +1 -0
  172. package/lib/runtime/components/react/dist/mpx-radio.d.ts +27 -0
  173. package/lib/runtime/components/react/dist/mpx-radio.d.ts.map +1 -0
  174. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +2 -0
  175. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts.map +1 -0
  176. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +25 -0
  177. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts.map +1 -0
  178. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +15 -0
  179. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts.map +1 -0
  180. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +55 -0
  181. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts.map +1 -0
  182. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +6 -14
  183. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +8 -0
  184. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts.map +1 -0
  185. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +8 -0
  186. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts.map +1 -0
  187. package/lib/runtime/components/react/dist/mpx-slider.d.ts +31 -0
  188. package/lib/runtime/components/react/dist/mpx-slider.d.ts.map +1 -0
  189. package/lib/runtime/components/react/dist/mpx-slider.jsx +321 -0
  190. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +18 -0
  191. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts.map +1 -0
  192. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +16 -0
  193. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts.map +1 -0
  194. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +19 -0
  195. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts.map +1 -0
  196. package/lib/runtime/components/react/dist/mpx-swiper.d.ts +53 -0
  197. package/lib/runtime/components/react/dist/mpx-swiper.d.ts.map +1 -0
  198. package/lib/runtime/components/react/dist/mpx-swiper.jsx +9 -5
  199. package/lib/runtime/components/react/dist/mpx-switch.d.ts +27 -0
  200. package/lib/runtime/components/react/dist/mpx-switch.d.ts.map +1 -0
  201. package/lib/runtime/components/react/dist/mpx-text.d.ts +23 -0
  202. package/lib/runtime/components/react/dist/mpx-text.d.ts.map +1 -0
  203. package/lib/runtime/components/react/dist/mpx-text.jsx +33 -5
  204. package/lib/runtime/components/react/dist/mpx-textarea.d.ts +8 -0
  205. package/lib/runtime/components/react/dist/mpx-textarea.d.ts.map +1 -0
  206. package/lib/runtime/components/react/dist/mpx-video.d.ts +102 -0
  207. package/lib/runtime/components/react/dist/mpx-video.d.ts.map +1 -0
  208. package/lib/runtime/components/react/dist/mpx-view.d.ts +35 -0
  209. package/lib/runtime/components/react/dist/mpx-view.d.ts.map +1 -0
  210. package/lib/runtime/components/react/dist/mpx-view.jsx +8 -11
  211. package/lib/runtime/components/react/dist/mpx-web-view.d.ts +23 -0
  212. package/lib/runtime/components/react/dist/mpx-web-view.d.ts.map +1 -0
  213. package/lib/runtime/components/react/dist/mpx-web-view.jsx +1 -1
  214. package/lib/runtime/components/react/dist/parser.d.ts +40 -0
  215. package/lib/runtime/components/react/dist/parser.d.ts.map +1 -0
  216. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +33 -0
  217. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts.map +1 -0
  218. package/lib/runtime/components/react/dist/useNodesRef.d.ts +12 -0
  219. package/lib/runtime/components/react/dist/useNodesRef.d.ts.map +1 -0
  220. package/lib/runtime/components/react/dist/utils.d.ts +123 -0
  221. package/lib/runtime/components/react/dist/utils.d.ts.map +1 -0
  222. package/lib/runtime/components/react/dist/utils.jsx +16 -6
  223. package/lib/runtime/components/react/mpx-camera.tsx +275 -0
  224. package/lib/runtime/components/react/mpx-image.tsx +89 -42
  225. package/lib/runtime/components/react/mpx-input.tsx +50 -18
  226. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +69 -49
  227. package/lib/runtime/components/react/mpx-nav.tsx +155 -0
  228. package/lib/runtime/components/react/mpx-picker-view/index.tsx +5 -2
  229. package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +26 -21
  230. package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItem.tsx +8 -12
  231. package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItemLite.tsx +55 -0
  232. package/lib/runtime/components/react/mpx-portal/index.tsx +8 -2
  233. package/lib/runtime/components/react/mpx-progress.tsx +26 -24
  234. package/lib/runtime/components/react/mpx-scroll-view.tsx +6 -17
  235. package/lib/runtime/components/react/mpx-slider.tsx +444 -0
  236. package/lib/runtime/components/react/mpx-swiper.tsx +9 -5
  237. package/lib/runtime/components/react/mpx-text.tsx +38 -5
  238. package/lib/runtime/components/react/mpx-view.tsx +8 -11
  239. package/lib/runtime/components/react/mpx-web-view.tsx +1 -1
  240. package/lib/runtime/components/react/types/common.d.ts +19 -0
  241. package/lib/runtime/components/react/utils.tsx +15 -6
  242. package/lib/runtime/components/web/mpx-input.vue +1 -1
  243. package/lib/runtime/components/web/mpx-scroll-view.vue +7 -1
  244. package/lib/runtime/components/web/mpx-video.vue +12 -1
  245. package/lib/runtime/optionProcessor.js +3 -1
  246. package/lib/runtime/optionProcessorReact.js +4 -2
  247. package/lib/runtime/stringify.wxs +2 -2
  248. package/lib/script-setup-compiler/index.js +2 -2
  249. package/lib/style-compiler/index.js +3 -2
  250. package/lib/style-compiler/load-postcss-config.js +1 -1
  251. package/lib/style-compiler/plugins/trans-special.js +10 -2
  252. package/lib/style-compiler/strip-conditional-loader.js +178 -15
  253. package/lib/template-compiler/bind-this.js +2 -2
  254. package/lib/template-compiler/compiler.js +277 -77
  255. package/lib/template-compiler/gen-node-react.js +18 -6
  256. package/lib/template-compiler/index.js +12 -10
  257. package/lib/template-compiler/parse-exps.js +1 -1
  258. package/lib/utils/chain-assign.js +47 -0
  259. package/lib/utils/check-core-version-match.js +75 -15
  260. package/lib/utils/const.js +2 -1
  261. package/lib/utils/dom-tag-config.js +6 -6
  262. package/lib/utils/env.js +6 -1
  263. package/lib/utils/get-build-tag-component.js +35 -0
  264. package/lib/utils/pre-process-json.js +5 -0
  265. package/lib/web/index.js +2 -0
  266. package/lib/web/processJSON.js +44 -16
  267. package/lib/web/processScript.js +1 -1
  268. package/lib/web/processTemplate.js +6 -4
  269. package/lib/web/script-helper.js +19 -9
  270. package/lib/wxs/pre-loader.js +6 -6
  271. package/lib/wxss/loader.js +1 -9
  272. package/package.json +17 -5
  273. package/LICENSE +0 -433
  274. package/lib/dependencies/ImportDependencyTemplate.js +0 -50
@@ -1,7 +1,7 @@
1
1
  const JSON5 = require('json5')
2
2
  const he = require('he')
3
3
  const config = require('../config')
4
- const { MPX_ROOT_VIEW, MPX_APP_MODULE_ID, PARENT_MODULE_ID } = require('../utils/const')
4
+ const { MPX_ROOT_VIEW, MPX_APP_MODULE_ID, PARENT_MODULE_ID, MPX_TAG_PAGE_SELECTOR } = require('../utils/const')
5
5
  const normalize = require('../utils/normalize')
6
6
  const { normalizeCondition } = require('../utils/match-condition')
7
7
  const isValidIdentifierStr = require('../utils/is-valid-identifier-str')
@@ -15,7 +15,8 @@ const { isNonPhrasingTag } = require('../utils/dom-tag-config')
15
15
  const setBaseWxml = require('../runtime-render/base-wxml')
16
16
  const { parseExp } = require('./parse-exps')
17
17
  const shallowStringify = require('../utils/shallow-stringify')
18
- const { isReact, isWeb } = require('../utils/env')
18
+ const { isReact, isWeb, isNoMode } = require('../utils/env')
19
+ const { capitalToHyphen } = require('../utils/string')
19
20
 
20
21
  const no = function () {
21
22
  return false
@@ -119,6 +120,8 @@ const rulesResultMap = new Map()
119
120
  let usingComponents = []
120
121
  let usingComponentsInfo = {}
121
122
  let componentGenerics = {}
123
+ // 跨平台语法检测的配置,在模块加载时初始化一次
124
+ let crossPlatformConfig = null
122
125
 
123
126
  function updateForScopesMap () {
124
127
  forScopesMap = {}
@@ -147,11 +150,11 @@ const deleteErrorInResultMap = (node) => {
147
150
  }
148
151
 
149
152
  function baseWarn (msg) {
150
- console.warn(('[template compiler]: ' + msg))
153
+ console.warn(('[Mpx template warning]: ' + msg))
151
154
  }
152
155
 
153
156
  function baseError (msg) {
154
- console.error(('[template compiler]: ' + msg))
157
+ console.error(('[Mpx template error]: ' + msg))
155
158
  }
156
159
 
157
160
  const decodeMap = {
@@ -176,11 +179,11 @@ const i18nWxsPath = normalize.lib('runtime/i18n.wxs')
176
179
  const i18nWxsLoaderPath = normalize.lib('wxs/i18n-loader.js')
177
180
  // 添加~前缀避免wxs绝对路径在存在projectRoot时被拼接为错误路径
178
181
  const i18nWxsRequest = '~' + i18nWxsLoaderPath + '!' + i18nWxsPath
179
- const i18nModuleName = '_i'
182
+ const i18nModuleName = '_i_'
180
183
  const stringifyWxsPath = '~' + normalize.lib('runtime/stringify.wxs')
181
- const stringifyModuleName = '_s'
184
+ const stringifyModuleName = '_s_'
182
185
  const optionalChainWxsPath = '~' + normalize.lib('runtime/oc.wxs')
183
- const optionalChainWxsName = '_oc' // 改成_oc解决web下_o重名问题
186
+ const optionalChainWxsName = '_oc_' // 改成_oc解决web下_o重名问题
184
187
 
185
188
  const tagRES = /(\{\{(?:.|\n|\r)+?\}\})(?!})/
186
189
  const tagRE = /\{\{((?:.|\n|\r)+?)\}\}(?!})/
@@ -637,8 +640,9 @@ function parse (template, options) {
637
640
  processingTemplate = false
638
641
  rulesResultMap.clear()
639
642
  componentGenerics = options.componentGenerics || {}
643
+ // 初始化跨平台语法检测配置(每次解析时只初始化一次)
644
+ crossPlatformConfig = initCrossPlatformConfig()
640
645
 
641
- if (typeof options.usingComponentsInfo === 'string') options.usingComponentsInfo = JSON.parse(options.usingComponentsInfo)
642
646
  usingComponents = Object.keys(options.usingComponentsInfo)
643
647
  usingComponentsInfo = options.usingComponentsInfo
644
648
 
@@ -681,7 +685,6 @@ function parse (template, options) {
681
685
  meta.options.virtualHost = true
682
686
  }
683
687
  let currentParent
684
- let multiRootError
685
688
  // 用于记录模板用到的组件,匹配引用组件,看是否有冗余
686
689
  const tagNames = new Set()
687
690
 
@@ -760,6 +763,7 @@ function parse (template, options) {
760
763
  if (!currentParent) genTempRoot()
761
764
 
762
765
  const children = currentParent.children
766
+
763
767
  if (currentParent.tag !== 'text') {
764
768
  text = text.trim()
765
769
  } else {
@@ -793,9 +797,10 @@ function parse (template, options) {
793
797
  }
794
798
  })
795
799
 
796
- if (multiRootError) {
797
- error$1('Template fields should has one single root, considering wrapping your template content with <view> or <text> tag!')
798
- }
800
+ // multiRoot
801
+ // if (root.tag === 'temp-node' && root.children && root.children.filter(node => node.tag !== 'temp-node').length > 1) {
802
+ // error$1('Template fields should has one single root, considering wrapping your template content with <view> or <text> tag!')
803
+ // }
799
804
 
800
805
  if (hasI18n) {
801
806
  if (i18nInjectableComputed.length) {
@@ -1000,12 +1005,34 @@ function processComponentIs (el, options) {
1000
1005
  }
1001
1006
 
1002
1007
  const range = getAndRemoveAttr(el, 'range').val
1003
- const isInRange = makeMap(range || '')
1004
- el.components = (usingComponents).filter(i => {
1005
- if (!range) return true
1006
- return isInRange(i)
1008
+
1009
+ // Map<CurrentName, SourceName>
1010
+ let ranges
1011
+ if (range) {
1012
+ ranges = range.split(',').map(i => i.trim()).filter(i => i)
1013
+ } else {
1014
+ // 根据原始用户写的usingComponents字段生成ranges
1015
+ ranges = options.originalUsingComponents
1016
+ }
1017
+
1018
+ const rangeMap = new Map()
1019
+ ranges.forEach(name => {
1020
+ rangeMap.set(['ali', 'swan'].includes(mode) ? capitalToHyphen(name) : name, name)
1007
1021
  })
1008
- if (!el.components.length) {
1022
+
1023
+ // Map<CurrentName, SourceName>
1024
+ el.componentMap = new Map()
1025
+ usingComponents.forEach((name) => {
1026
+ if (rangeMap.size === 0) {
1027
+ el.componentMap.set(name, name)
1028
+ } else {
1029
+ if (rangeMap.has(name)) {
1030
+ el.componentMap.set(name, rangeMap.get(name))
1031
+ }
1032
+ }
1033
+ })
1034
+
1035
+ if (el.componentMap.size === 0) {
1009
1036
  warn$1('Component in which <component> tag is used must have a non blank usingComponents field')
1010
1037
  }
1011
1038
 
@@ -1383,7 +1410,11 @@ function processEvent (el, options) {
1383
1410
  const targetConfigs = isCapture ? eventConfigMap[type].captureConfigs : eventConfigMap[type].configs
1384
1411
  targetConfigs.push(Object.assign({ name }, parsedFunc))
1385
1412
  if (modifiers.indexOf('proxy') > -1 || options.forceProxyEvent) {
1386
- eventConfigMap[type].proxy = true
1413
+ if (isCapture) {
1414
+ eventConfigMap[type].captureProxy = true
1415
+ } else {
1416
+ eventConfigMap[type].proxy = true
1417
+ }
1387
1418
  }
1388
1419
  }
1389
1420
  }
@@ -1423,10 +1454,10 @@ function processEvent (el, options) {
1423
1454
  }
1424
1455
 
1425
1456
  for (const type in eventConfigMap) {
1426
- const { configs = [], captureConfigs = [], proxy } = eventConfigMap[type]
1457
+ const { configs = [], captureConfigs = [], proxy, captureProxy } = eventConfigMap[type]
1427
1458
 
1428
1459
  let needBubblingBind = isNeedBind(configs, proxy)
1429
- let needCaptureBind = isNeedBind(captureConfigs, proxy)
1460
+ let needCaptureBind = isNeedBind(captureConfigs, captureProxy)
1430
1461
 
1431
1462
  const escapedType = dash2hump(type)
1432
1463
  // 排除特殊情况
@@ -1588,7 +1619,7 @@ function parseOptionalChaining (str) {
1588
1619
  }
1589
1620
  if (grammarMap.checkState() && haveNotGetValue) {
1590
1621
  // 值查找结束但是语法未闭合或者处理到边界还未结束,抛异常
1591
- throw new Error('[optionChain] option value illegal!!!')
1622
+ throw new Error('[Mpx template error]: optionChain option value illegal!!!')
1592
1623
  }
1593
1624
  haveNotGetValue = true
1594
1625
  let keyValue = ''
@@ -1638,7 +1669,7 @@ function parseOptionalChaining (str) {
1638
1669
  }
1639
1670
  if (grammarMap.checkState() && haveNotGetValue) {
1640
1671
  // key值查找结束但是语法未闭合或者处理到边界还未结束,抛异常
1641
- throw new Error('[optionChain] option key illegal!!!')
1672
+ throw new Error('[Mpx template error]: optionChain option key illegal!!!')
1642
1673
  }
1643
1674
  if (keyValue) {
1644
1675
  chainKey += `,'${keyValue}'`
@@ -1851,24 +1882,25 @@ function processRefReact (el, meta) {
1851
1882
  /**
1852
1883
  * selectorsConf: [type, [[prefix, selector], [prefix, selector]]]
1853
1884
  */
1854
- if (!val) {
1855
- const rawId = el.attrsMap.id
1856
- const rawClass = el.attrsMap.class
1857
- const rawDynamicClass = el.attrsMap[config[mode].directive.dynamicClass]
1858
-
1859
- if (rawId) {
1860
- const staticId = parseMustacheWithContext(rawId).result
1861
- selectors.push({ prefix: '#', selector: `${staticId}` })
1862
- }
1863
- if (rawClass || rawDynamicClass) {
1864
- const staticClass = parseMustacheWithContext(rawClass).result
1865
- const dynamicClass = parseMustacheWithContext(rawDynamicClass).result
1866
- selectors.push({ prefix: '.', selector: `this.__getClass(${staticClass}, ${dynamicClass})` })
1867
- }
1868
- } else {
1885
+ if (val) {
1869
1886
  meta.refs.push(refConf)
1870
1887
  selectors.push({ prefix: '', selector: `"${refConf.key}"` })
1871
1888
  }
1889
+
1890
+ const rawId = el.attrsMap.id
1891
+ const rawClass = el.attrsMap.class
1892
+ const rawDynamicClass = el.attrsMap[config[mode].directive.dynamicClass]
1893
+
1894
+ if (rawId) {
1895
+ const staticId = parseMustacheWithContext(rawId).result
1896
+ selectors.push({ prefix: '#', selector: `${staticId}` })
1897
+ }
1898
+ if (rawClass || rawDynamicClass) {
1899
+ const staticClass = parseMustacheWithContext(rawClass).result
1900
+ const dynamicClass = parseMustacheWithContext(rawDynamicClass).result
1901
+ selectors.push({ prefix: '.', selector: `this.__getClass(${staticClass}, ${dynamicClass})` })
1902
+ }
1903
+
1872
1904
  const selectorsConf = selectors.map(item => `["${item.prefix}", ${item.selector}]`)
1873
1905
  const refFnId = forScopes.reduce((preV, curV) => {
1874
1906
  return `${preV} + "_" + ${curV.index}`
@@ -2080,13 +2112,24 @@ function postProcessIf (el) {
2080
2112
  replaceNode(el, getTempNode())._if = false
2081
2113
  }
2082
2114
  } else {
2115
+ el._if = null
2083
2116
  attrs = [{
2084
2117
  name: config[mode].directive.if,
2085
2118
  value: el.if.raw
2086
2119
  }]
2087
2120
  }
2088
2121
  } else if (el.elseif) {
2122
+ if (el.for) {
2123
+ error$1(`wx:elif (wx:elif="${el.elseif.raw}") invalidly used on the for-list <"${el.tag}"> which has a wx:for directive, please create a block element to wrap the for-list and move the elif-directive to it`)
2124
+ return
2125
+ }
2126
+
2089
2127
  prevNode = findPrevNode(el)
2128
+ if (!prevNode || prevNode._if === undefined) {
2129
+ error$1(`wx:elif="${el.elseif.raw}" used on element [${el.tag}] without corresponding wx:if or wx:elif.`)
2130
+ return
2131
+ }
2132
+
2090
2133
  if (prevNode._if === true) {
2091
2134
  removeNode(el)
2092
2135
  } else if (prevNode._if === false) {
@@ -2106,6 +2149,7 @@ function postProcessIf (el) {
2106
2149
  removeNode(el)
2107
2150
  }
2108
2151
  } else {
2152
+ el._if = null
2109
2153
  attrs = [{
2110
2154
  name: config[mode].directive.elseif,
2111
2155
  value: el.elseif.raw
@@ -2113,7 +2157,17 @@ function postProcessIf (el) {
2113
2157
  }
2114
2158
  }
2115
2159
  } else if (el.else) {
2160
+ if (el.for) {
2161
+ error$1(`wx:else invalidly used on the for-list <"${el.tag}"> which has a wx:for directive, please create a block element to wrap the for-list and move the else-directive to it`)
2162
+ return
2163
+ }
2164
+
2116
2165
  prevNode = findPrevNode(el)
2166
+ if (!prevNode || prevNode._if === undefined) {
2167
+ error$1(`wx:else used on element [${el.tag}] without corresponding wx:if or wx:elif.`)
2168
+ return
2169
+ }
2170
+
2117
2171
  if (prevNode._if === true) {
2118
2172
  removeNode(el)
2119
2173
  } else if (prevNode._if === false) {
@@ -2137,23 +2191,100 @@ function addIfCondition (el, condition) {
2137
2191
  el.ifConditions.push(condition)
2138
2192
  }
2139
2193
 
2194
+ function getIfConditions (el) {
2195
+ return el?.ifConditions || []
2196
+ }
2197
+
2140
2198
  function postProcessIfReact (el) {
2141
- let prevNode
2199
+ let prevNode, ifNode, result, ifConditions
2142
2200
  if (el.if) {
2143
- addIfCondition(el, {
2144
- exp: el.if.exp,
2145
- block: el
2146
- })
2147
- } else if (el.elseif || el.else) {
2148
- prevNode = findPrevNode(el)
2149
- if (prevNode && prevNode.if) {
2150
- addIfCondition(prevNode, {
2151
- exp: el.elseif && el.elseif.exp,
2201
+ // 取值
2202
+ // false -> 节点变为temp-node,并添加_if=false
2203
+ // true -> 添加_if=true,移除if
2204
+ // dynamic -> addIfCondition
2205
+ result = evalExp(el.if.exp)
2206
+ if (result.success) {
2207
+ if (result.result) {
2208
+ el._if = true
2209
+ delete el.if
2210
+ } else {
2211
+ replaceNode(el, getTempNode())._if = false
2212
+ }
2213
+ } else {
2214
+ el._if = null
2215
+ addIfCondition(el, {
2216
+ exp: el.if.exp,
2152
2217
  block: el
2153
2218
  })
2154
- removeNode(el, true)
2219
+ }
2220
+ } else if (el.elseif) {
2221
+ if (el.for) {
2222
+ error$1(`wx:elif (wx:elif="${el.elseif.raw}") invalidly used on the for-list <"${el.tag}"> which has a wx:for directive, please create a block element to wrap the for-list and move the elif-directive to it`)
2223
+ return
2224
+ }
2225
+
2226
+ ifNode = findPrevNode(el)
2227
+ ifConditions = getIfConditions(ifNode)
2228
+ prevNode = ifConditions.length > 0 ? ifConditions[ifConditions.length - 1].block : ifNode
2229
+
2230
+ if (!prevNode || prevNode._if === undefined) {
2231
+ error$1(`wx:elif="${el.elseif.raw}" used on element [${el.tag}] without corresponding wx:if or wx:elif.`)
2232
+ return
2233
+ }
2234
+
2235
+ if (prevNode._if === true) {
2236
+ removeNode(el)
2237
+ } else if (prevNode._if === false) {
2238
+ el.if = el.elseif
2239
+ delete el.elseif
2240
+ postProcessIfReact(el)
2155
2241
  } else {
2156
- warn$1(`wx:${el.elseif ? `elif="${el.elseif.raw}"` : 'else'} used on element [${el.tag}] without corresponding wx:if.`)
2242
+ result = evalExp(el.elseif.exp)
2243
+ if (result.success) {
2244
+ if (result.result) {
2245
+ delete el.elseif
2246
+ el._if = true
2247
+ addIfCondition(ifNode, {
2248
+ exp: el.elseif.exp,
2249
+ block: el
2250
+ })
2251
+ removeNode(el, true)
2252
+ } else {
2253
+ removeNode(el)
2254
+ }
2255
+ } else {
2256
+ el._if = null
2257
+ addIfCondition(ifNode, {
2258
+ exp: el.elseif.exp,
2259
+ block: el
2260
+ })
2261
+ removeNode(el, true)
2262
+ }
2263
+ }
2264
+ } else if (el.else) {
2265
+ if (el.for) {
2266
+ error$1(`wx:else invalidly used on the for-list <"${el.tag}"> which has a wx:for directive, please create a block element to wrap the for-list and move the else-directive to it`)
2267
+ return
2268
+ }
2269
+
2270
+ ifNode = findPrevNode(el)
2271
+ ifConditions = getIfConditions(ifNode)
2272
+ prevNode = ifConditions.length > 0 ? ifConditions[ifConditions.length - 1].block : ifNode
2273
+
2274
+ if (!prevNode || prevNode._if === undefined) {
2275
+ error$1(`wx:else used on element [${el.tag}] without corresponding wx:if or wx:elif.`)
2276
+ return
2277
+ }
2278
+
2279
+ if (prevNode._if === true) {
2280
+ removeNode(el)
2281
+ } else if (prevNode._if === false) {
2282
+ delete el.else
2283
+ } else {
2284
+ addIfCondition(ifNode, {
2285
+ block: el
2286
+ })
2287
+ removeNode(el, true)
2157
2288
  }
2158
2289
  }
2159
2290
  }
@@ -2520,6 +2651,16 @@ function getVirtualHostRoot (options, meta) {
2520
2651
  if (isWeb(mode) && ctorType === 'page') {
2521
2652
  return createASTElement('page')
2522
2653
  }
2654
+ if (isReact(mode) && ctorType === 'page') {
2655
+ const rootView = createASTElement('view', [
2656
+ {
2657
+ name: 'class',
2658
+ value: MPX_TAG_PAGE_SELECTOR
2659
+ }
2660
+ ])
2661
+ processElement(rootView, rootView, options, meta)
2662
+ return rootView
2663
+ }
2523
2664
  }
2524
2665
  return getTempNode()
2525
2666
  }
@@ -2577,7 +2718,7 @@ function postProcessTemplate (el) {
2577
2718
  }
2578
2719
  }
2579
2720
 
2580
- const isValidMode = makeMap('wx,ali,swan,tt,qq,web,qa,jd,dd,tenon,ios,android,harmony,noMode')
2721
+ const isValidMode = makeMap('wx,ali,swan,tt,qq,web,qa,jd,dd,tenon,ios,android,harmony,ks,noMode')
2581
2722
 
2582
2723
  function isValidModeP (i) {
2583
2724
  return isValidMode(i[0] === '_' ? i.slice(1) : i)
@@ -2713,6 +2854,78 @@ function processNoTransAttrs (el) {
2713
2854
  }
2714
2855
  }
2715
2856
 
2857
+ function initCrossPlatformConfig () {
2858
+ // 定义平台与前缀的双向映射关系
2859
+ const platformPrefixMap = {
2860
+ wx: 'wx:',
2861
+ ali: 'a:',
2862
+ swan: 's-',
2863
+ qq: 'qq:',
2864
+ tt: 'tt:',
2865
+ dd: 'dd:',
2866
+ jd: 'jd:',
2867
+ qa: 'qa:',
2868
+ web: 'v-'
2869
+ }
2870
+
2871
+ if (isNoMode(mode)) {
2872
+ return null
2873
+ }
2874
+
2875
+ return {
2876
+ currentPrefix: platformPrefixMap[mode] || 'wx:',
2877
+ platformPrefixMap
2878
+ }
2879
+ }
2880
+
2881
+ // 检测跨平台语法使用情况并给出警告
2882
+ function processCrossPlatformSyntaxWarning (el) {
2883
+ // 使用转换后的属性列表进行检查
2884
+ if (!el.attrsList || el.attrsList.length === 0) {
2885
+ return
2886
+ }
2887
+
2888
+ // 如果配置为空,说明不需要检测
2889
+ if (!crossPlatformConfig) {
2890
+ return
2891
+ }
2892
+
2893
+ const { currentPrefix, platformPrefixMap } = crossPlatformConfig
2894
+
2895
+ // 检查转换后的属性列表
2896
+ el.attrsList.forEach(attr => {
2897
+ const attrName = attr.name
2898
+
2899
+ // 检查是否使用了平台前缀
2900
+ for (const [platformName, prefix] of Object.entries(platformPrefixMap)) {
2901
+ if (attrName.startsWith(prefix)) {
2902
+ if (isReact(mode)) {
2903
+ // React Native 平台:只允许使用 wx: 前缀,其他前缀报错
2904
+ if (prefix !== 'wx:') {
2905
+ error$1(
2906
+ `React Native mode "${mode}" does not support "${prefix}" prefix. ` +
2907
+ `Use "wx:" prefix instead. Found: "${attrName}"`
2908
+ )
2909
+ }
2910
+ } else {
2911
+ // 小程序平台:检测跨平台语法使用
2912
+ if (platformName !== mode) {
2913
+ // 构建建议的正确属性名
2914
+ const suffixPart = attrName.substring(prefix.length)
2915
+ const suggestedAttr = currentPrefix + suffixPart
2916
+
2917
+ warn$1(
2918
+ `Your target mode is "${mode}", but used "${attrName}". ` +
2919
+ `Did you mean "${suggestedAttr}"?`
2920
+ )
2921
+ }
2922
+ }
2923
+ break
2924
+ }
2925
+ }
2926
+ })
2927
+ }
2928
+
2716
2929
  function processMpxTagName (el) {
2717
2930
  const mpxTagName = getAndRemoveAttr(el, 'mpxTagName').val
2718
2931
  if (mpxTagName) {
@@ -2742,6 +2955,9 @@ function processElement (el, root, options, meta) {
2742
2955
 
2743
2956
  processDuplicateAttrsList(el)
2744
2957
 
2958
+ // 检测跨平台语法使用情况并给出警告
2959
+ processCrossPlatformSyntaxWarning(el)
2960
+
2745
2961
  processInjectWxs(el, meta, options)
2746
2962
 
2747
2963
  const transAli = mode === 'ali' && srcMode === 'wx'
@@ -2886,7 +3102,7 @@ function cloneAttrsList (attrsList) {
2886
3102
  }
2887
3103
 
2888
3104
  function postProcessComponentIs (el, postProcessChild) {
2889
- if (el.is && el.components) {
3105
+ if (el.is && el.componentMap && el.componentMap.size > 0) {
2890
3106
  let tempNode
2891
3107
  if (el.for || el.if || el.elseif || el.else) {
2892
3108
  tempNode = createASTElement('block')
@@ -2896,11 +3112,12 @@ function postProcessComponentIs (el, postProcessChild) {
2896
3112
  replaceNode(el, tempNode, true)
2897
3113
  postMoveBaseDirective(tempNode, el)
2898
3114
 
2899
- el.components.forEach(function (component) {
2900
- const newChild = createASTElement(component, cloneAttrsList(el.attrsList), tempNode)
3115
+ // Map<CurrentName, SourceName>
3116
+ el.componentMap.forEach((source, name) => {
3117
+ const newChild = createASTElement(name, cloneAttrsList(el.attrsList), tempNode)
2901
3118
  newChild.if = {
2902
- raw: `{{${el.is} === ${stringify(component)}}}`,
2903
- exp: `${el.is} === ${stringify(component)}`
3119
+ raw: `{{${el.is} === ${stringify(source)}}}`,
3120
+ exp: `${el.is} === ${stringify(source)}`
2904
3121
  }
2905
3122
  el.children.forEach((child) => {
2906
3123
  addChild(newChild, cloneNode(child))
@@ -3025,30 +3242,12 @@ function genIf (node) {
3025
3242
 
3026
3243
  function genElseif (node) {
3027
3244
  node.elseifProcessed = true
3028
- if (node.for) {
3029
- error$1(`wx:elif (wx:elif="${node.elseif.raw}") invalidly used on the for-list <"${node.tag}"> which has a wx:for directive, please create a block element to wrap the for-list and move the if-directive to it`)
3030
- return
3031
- }
3032
- const preNode = findPrevNode(node)
3033
- if (preNode && (preNode.if || preNode.elseif)) {
3034
- return `else if(${node.elseif.exp}){\n${genNode(node)}}\n`
3035
- } else {
3036
- error$1(`wx:elif (wx:elif="${node.elseif.raw}") invalidly used on the element <"${node.tag}"> without corresponding wx:if or wx:elif.`)
3037
- }
3245
+ return `else if(${node.elseif.exp}){\n${genNode(node)}}\n`
3038
3246
  }
3039
3247
 
3040
3248
  function genElse (node) {
3041
3249
  node.elseProcessed = true
3042
- if (node.for) {
3043
- error$1(`wx:else invalidly used on the for-list <"${node.tag}"> which has a wx:for directive, please create a block element to wrap the for-list and move the if-directive to it`)
3044
- return
3045
- }
3046
- const preNode = findPrevNode(node)
3047
- if (preNode && (preNode.if || preNode.elseif)) {
3048
- return `else{\n${genNode(node)}}\n`
3049
- } else {
3050
- error$1(`wx:else invalidly used on the element <"${node.tag}"> without corresponding wx:if or wx:elif.`)
3051
- }
3250
+ return `else{\n${genNode(node)}}\n`
3052
3251
  }
3053
3252
 
3054
3253
  function genExps (node) {
@@ -3061,7 +3260,7 @@ function genFor (node) {
3061
3260
  node.forProcessed = true
3062
3261
  const index = node.for.index || 'index'
3063
3262
  const item = node.for.item || 'item'
3064
- return `_i(${node.for.exp}, function(${item},${index}){\n${genNode(node)}});\n`
3263
+ return `mpx_i(${node.for.exp}, function(${item},${index}){\n${genNode(node)}});\n`
3065
3264
  }
3066
3265
 
3067
3266
  function genNode (node) {
@@ -3259,5 +3458,6 @@ module.exports = {
3259
3458
  findPrevNode,
3260
3459
  removeNode,
3261
3460
  replaceNode,
3262
- createASTElement
3461
+ createASTElement,
3462
+ evalExp
3263
3463
  }
@@ -9,7 +9,8 @@ function genIfConditions (conditions) {
9
9
  if (!conditions.length) return 'null'
10
10
  const condition = conditions.shift()
11
11
  if (condition.exp) {
12
- return `(${condition.exp})?${genNode(condition.block)}:${genIfConditions(conditions)}`
12
+ // 此处 condition.exp 无需括号包裹,condition.exp本身已经包含括号
13
+ return `${condition.exp}?${genNode(condition.block)}:${genIfConditions(conditions)}`
13
14
  } else {
14
15
  return genNode(condition.block)
15
16
  }
@@ -30,7 +31,7 @@ function mapAttrName (name) {
30
31
  return name
31
32
  }
32
33
 
33
- function genNode (node) {
34
+ function genNode (node, isRoot = false) {
34
35
  let exp = ''
35
36
  if (node) {
36
37
  if (node.type === 3) {
@@ -72,18 +73,29 @@ function genNode (node) {
72
73
  }
73
74
 
74
75
  if (!node.unary && node.children.length) {
75
- exp += ','
76
- exp += node.children.map((child) => {
76
+ const childNode = node.children.map((child) => {
77
77
  return genNode(child)
78
78
  }).filter(fragment => fragment).join(',')
79
+
80
+ // child可能为temp-node等无效节点,所以增加判断确保存在childNode再添加逗号
81
+ if (childNode) {
82
+ exp += ','
83
+ exp += childNode
84
+ }
79
85
  }
80
86
  exp += ')'
81
87
  }
82
88
  }
83
89
  } else {
84
- exp += node.children.map((child) => {
90
+ const nodes = node.children.map((child) => {
85
91
  return genNode(child)
86
- }).filter(fragment => fragment).join(',')
92
+ }).filter(fragment => fragment && fragment !== 'null')
93
+ if (isRoot && nodes.length > 1) {
94
+ // 如果存在多个根节点,使用 block 包裹
95
+ exp = `createElement(getComponent("block"), null, ${nodes.join(',')})`
96
+ } else {
97
+ exp += nodes.join(',')
98
+ }
87
99
  }
88
100
  }
89
101
  }
@@ -24,14 +24,15 @@ module.exports = function (raw) {
24
24
  const packageName = queryObj.packageRoot || mpx.currentPackageRoot || 'main'
25
25
  const wxsContentMap = mpx.wxsContentMap
26
26
  const optimizeRenderRules = mpx.optimizeRenderRules
27
- const usingComponentsInfo = queryObj.usingComponentsInfo || {}
27
+ const usingComponentsInfo = queryObj.usingComponentsInfo ? JSON.parse(queryObj.usingComponentsInfo) : {}
28
+ const originalUsingComponents = queryObj.originalUsingComponents ? JSON.parse(queryObj.originalUsingComponents) : []
28
29
  const componentPlaceholder = queryObj.componentPlaceholder || []
29
30
  const hasComment = queryObj.hasComment
30
31
  const isNative = queryObj.isNative
31
32
  const ctorType = queryObj.ctorType
32
33
  const hasScoped = queryObj.hasScoped
33
34
  const runtimeCompile = queryObj.isDynamic
34
- const moduleId = queryObj.moduleId || mpx.getModuleId(resourcePath)
35
+ const moduleId = queryObj.moduleId || mpx.getModuleId(resourcePath, false, queryObj.moduleId ? null : this)
35
36
 
36
37
  let optimizeRenderLevel = 0
37
38
  for (const rule of optimizeRenderRules) {
@@ -43,13 +44,13 @@ module.exports = function (raw) {
43
44
 
44
45
  const warn = (msg) => {
45
46
  this.emitWarning(
46
- new Error('[template compiler][' + this.resource + ']: ' + msg)
47
+ new Error('[Mpx template warning][' + this.resource + ']: ' + msg)
47
48
  )
48
49
  }
49
50
 
50
51
  const error = (msg) => {
51
52
  this.emitError(
52
- new Error('[template compiler][' + this.resource + ']: ' + msg)
53
+ new Error('[Mpx template error][' + this.resource + ']: ' + msg)
53
54
  )
54
55
  }
55
56
 
@@ -70,6 +71,7 @@ module.exports = function (raw) {
70
71
  hasScoped,
71
72
  moduleId,
72
73
  usingComponentsInfo,
74
+ originalUsingComponents,
73
75
  // 这里需传递rawResourcePath和wxsContentMap保持一致
74
76
  filePath: rawResourcePath,
75
77
  i18n,
@@ -110,10 +112,10 @@ module.exports = function (raw) {
110
112
  if (rawCode) {
111
113
  try {
112
114
  const ignoreMap = Object.assign({
113
- _i: true,
114
- _c: true,
115
- _sc: true,
116
- _r: true
115
+ mpx_i: true,
116
+ mpx_c: true,
117
+ mpx_sc: true,
118
+ mpx_r: true
117
119
  }, meta.wxsModuleMap)
118
120
  const bindResult = optimizeRenderLevel === 2
119
121
  ? bindThis.transformSimple(rawCode, {
@@ -124,9 +126,9 @@ module.exports = function (raw) {
124
126
  renderReduce: optimizeRenderLevel === 1,
125
127
  ignoreMap
126
128
  })
127
- resultSource += `global.currentInject.render = function (_i, _c, _r, _sc) {
129
+ resultSource += `global.currentInject.render = function (mpx_i, mpx_c, mpx_r, mpx_sc) {
128
130
  ${bindResult.code}
129
- _r(${optimizeRenderLevel === 2 ? 'true' : ''});
131
+ mpx_r(${optimizeRenderLevel === 2 ? 'true' : ''});
130
132
  };\n`
131
133
  if ((mode === 'tt' || mode === 'swan') && bindResult.propKeys) {
132
134
  resultSource += `global.currentInject.propKeys = ${JSON.stringify(bindResult.propKeys)};\n`