@mpxjs/webpack-plugin 2.10.16-beta.9 → 2.10.16-xp.1

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 (256) hide show
  1. package/lib/config.js +0 -60
  2. package/lib/dependencies/AppEntryDependency.js +2 -2
  3. package/lib/dependencies/ResolveDependency.js +1 -1
  4. package/lib/file-loader.js +3 -13
  5. package/lib/helpers.js +0 -2
  6. package/lib/index.js +15 -40
  7. package/lib/json-compiler/helper.js +2 -72
  8. package/lib/json-compiler/index.js +56 -16
  9. package/lib/json-compiler/plugin.js +2 -2
  10. package/lib/loader.js +4 -10
  11. package/lib/native-loader.js +3 -6
  12. package/lib/platform/json/wx/index.js +29 -30
  13. package/lib/platform/style/wx/index.js +1 -8
  14. package/lib/platform/template/wx/component-config/ad.js +0 -5
  15. package/lib/platform/template/wx/component-config/button.js +5 -21
  16. package/lib/platform/template/wx/component-config/camera.js +3 -25
  17. package/lib/platform/template/wx/component-config/canvas.js +1 -8
  18. package/lib/platform/template/wx/component-config/component.js +33 -31
  19. package/lib/platform/template/wx/component-config/cover-image.js +2 -7
  20. package/lib/platform/template/wx/component-config/cover-view.js +1 -3
  21. package/lib/platform/template/wx/component-config/fix-component-name.js +2 -2
  22. package/lib/platform/template/wx/component-config/form.js +2 -27
  23. package/lib/platform/template/wx/component-config/image.js +0 -5
  24. package/lib/platform/template/wx/component-config/input.js +0 -10
  25. package/lib/platform/template/wx/component-config/label.js +2 -10
  26. package/lib/platform/template/wx/component-config/map.js +0 -11
  27. package/lib/platform/template/wx/component-config/movable-area.js +1 -4
  28. package/lib/platform/template/wx/component-config/movable-view.js +2 -17
  29. package/lib/platform/template/wx/component-config/navigator.js +0 -26
  30. package/lib/platform/template/wx/component-config/picker-view.js +0 -12
  31. package/lib/platform/template/wx/component-config/picker.js +1 -3
  32. package/lib/platform/template/wx/component-config/progress.js +1 -11
  33. package/lib/platform/template/wx/component-config/rich-text.js +0 -5
  34. package/lib/platform/template/wx/component-config/scroll-view.js +1 -12
  35. package/lib/platform/template/wx/component-config/slider.js +0 -8
  36. package/lib/platform/template/wx/component-config/swiper-item.js +2 -5
  37. package/lib/platform/template/wx/component-config/swiper.js +0 -10
  38. package/lib/platform/template/wx/component-config/text.js +0 -5
  39. package/lib/platform/template/wx/component-config/textarea.js +2 -19
  40. package/lib/platform/template/wx/component-config/unsupported.js +1 -10
  41. package/lib/platform/template/wx/component-config/video.js +0 -10
  42. package/lib/platform/template/wx/index.js +1 -21
  43. package/lib/react/index.js +0 -2
  44. package/lib/react/processJSON.js +71 -39
  45. package/lib/react/processStyles.js +2 -3
  46. package/lib/react/processTemplate.js +6 -8
  47. package/lib/react/script-helper.js +16 -6
  48. package/lib/react/style-helper.js +2 -10
  49. package/lib/runtime/components/react/context.ts +6 -13
  50. package/lib/runtime/components/react/dist/context.js +0 -1
  51. package/lib/runtime/components/react/dist/mpx-image.jsx +62 -100
  52. package/lib/runtime/components/react/dist/mpx-input.jsx +11 -37
  53. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +50 -61
  54. package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +3 -4
  55. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +18 -12
  56. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.jsx +11 -8
  57. package/lib/runtime/components/react/dist/mpx-portal/index.jsx +1 -5
  58. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +14 -6
  59. package/lib/runtime/components/react/dist/mpx-swiper.jsx +9 -5
  60. package/lib/runtime/components/react/dist/mpx-text.jsx +5 -33
  61. package/lib/runtime/components/react/dist/mpx-view.jsx +1 -1
  62. package/lib/runtime/components/react/dist/mpx-web-view.jsx +1 -1
  63. package/lib/runtime/components/react/dist/utils.jsx +6 -16
  64. package/lib/runtime/components/react/mpx-image.tsx +82 -123
  65. package/lib/runtime/components/react/mpx-input.tsx +17 -44
  66. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +49 -69
  67. package/lib/runtime/components/react/mpx-picker-view/index.tsx +2 -5
  68. package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +21 -26
  69. package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItem.tsx +12 -8
  70. package/lib/runtime/components/react/mpx-portal/index.tsx +2 -8
  71. package/lib/runtime/components/react/mpx-scroll-view.tsx +17 -6
  72. package/lib/runtime/components/react/mpx-swiper.tsx +9 -5
  73. package/lib/runtime/components/react/mpx-text.tsx +5 -38
  74. package/lib/runtime/components/react/mpx-view.tsx +1 -1
  75. package/lib/runtime/components/react/mpx-web-view.tsx +1 -1
  76. package/lib/runtime/components/react/types/common.d.ts +0 -19
  77. package/lib/runtime/components/react/utils.tsx +6 -15
  78. package/lib/runtime/stringify.wxs +2 -2
  79. package/lib/script-setup-compiler/index.js +2 -2
  80. package/lib/style-compiler/index.js +2 -3
  81. package/lib/style-compiler/load-postcss-config.js +1 -1
  82. package/lib/style-compiler/plugins/trans-special.js +2 -10
  83. package/lib/style-compiler/strip-conditional-loader.js +15 -178
  84. package/lib/template-compiler/bind-this.js +2 -2
  85. package/lib/template-compiler/compiler.js +71 -267
  86. package/lib/template-compiler/gen-node-react.js +6 -18
  87. package/lib/template-compiler/index.js +10 -12
  88. package/lib/template-compiler/parse-exps.js +1 -1
  89. package/lib/utils/const.js +1 -2
  90. package/lib/utils/dom-tag-config.js +6 -6
  91. package/lib/utils/env.js +1 -6
  92. package/lib/utils/pre-process-json.js +0 -5
  93. package/lib/web/index.js +0 -2
  94. package/lib/web/processJSON.js +16 -44
  95. package/lib/web/processScript.js +1 -1
  96. package/lib/web/processTemplate.js +4 -6
  97. package/lib/web/script-helper.js +9 -19
  98. package/lib/wxs/pre-loader.js +1 -1
  99. package/lib/wxss/loader.js +9 -1
  100. package/package.json +4 -15
  101. package/lib/dependencies/RecordModuleIdMapDependency.js +0 -49
  102. package/lib/runtime/components/react/dist/context.d.ts +0 -76
  103. package/lib/runtime/components/react/dist/context.d.ts.map +0 -1
  104. package/lib/runtime/components/react/dist/event.config.d.ts +0 -8
  105. package/lib/runtime/components/react/dist/event.config.d.ts.map +0 -1
  106. package/lib/runtime/components/react/dist/getInnerListeners.d.ts +0 -8
  107. package/lib/runtime/components/react/dist/getInnerListeners.d.ts.map +0 -1
  108. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +0 -13
  109. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts.map +0 -1
  110. package/lib/runtime/components/react/dist/mpx-button.d.ts +0 -69
  111. package/lib/runtime/components/react/dist/mpx-button.d.ts.map +0 -1
  112. package/lib/runtime/components/react/dist/mpx-camera.d.ts +0 -27
  113. package/lib/runtime/components/react/dist/mpx-camera.d.ts.map +0 -1
  114. package/lib/runtime/components/react/dist/mpx-camera.jsx +0 -197
  115. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +0 -24
  116. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts.map +0 -1
  117. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +0 -8
  118. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts.map +0 -1
  119. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +0 -7
  120. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts.map +0 -1
  121. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +0 -21
  122. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts.map +0 -1
  123. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +0 -9
  124. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts.map +0 -1
  125. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +0 -11
  126. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts.map +0 -1
  127. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +0 -3
  128. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts.map +0 -1
  129. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +0 -33
  130. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts.map +0 -1
  131. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +0 -53
  132. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts.map +0 -1
  133. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +0 -21
  134. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts.map +0 -1
  135. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +0 -33
  136. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts.map +0 -1
  137. package/lib/runtime/components/react/dist/mpx-form.d.ts +0 -28
  138. package/lib/runtime/components/react/dist/mpx-form.d.ts.map +0 -1
  139. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +0 -19
  140. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts.map +0 -1
  141. package/lib/runtime/components/react/dist/mpx-image.d.ts +0 -22
  142. package/lib/runtime/components/react/dist/mpx-image.d.ts.map +0 -1
  143. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +0 -8
  144. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts.map +0 -1
  145. package/lib/runtime/components/react/dist/mpx-input.d.ts +0 -51
  146. package/lib/runtime/components/react/dist/mpx-input.d.ts.map +0 -1
  147. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +0 -13
  148. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts.map +0 -1
  149. package/lib/runtime/components/react/dist/mpx-label.d.ts +0 -21
  150. package/lib/runtime/components/react/dist/mpx-label.d.ts.map +0 -1
  151. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +0 -21
  152. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts.map +0 -1
  153. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +0 -66
  154. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts.map +0 -1
  155. package/lib/runtime/components/react/dist/mpx-nav.d.ts +0 -9
  156. package/lib/runtime/components/react/dist/mpx-nav.d.ts.map +0 -1
  157. package/lib/runtime/components/react/dist/mpx-nav.jsx +0 -132
  158. package/lib/runtime/components/react/dist/mpx-navigator.d.ts +0 -10
  159. package/lib/runtime/components/react/dist/mpx-navigator.d.ts.map +0 -1
  160. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +0 -7
  161. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts.map +0 -1
  162. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +0 -8
  163. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts.map +0 -1
  164. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +0 -7
  165. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts.map +0 -1
  166. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +0 -7
  167. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts.map +0 -1
  168. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +0 -7
  169. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts.map +0 -1
  170. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +0 -3
  171. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts.map +0 -1
  172. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +0 -7
  173. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts.map +0 -1
  174. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +0 -7
  175. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts.map +0 -1
  176. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +0 -107
  177. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts.map +0 -1
  178. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +0 -33
  179. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts.map +0 -1
  180. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +0 -9
  181. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts.map +0 -1
  182. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +0 -24
  183. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts.map +0 -1
  184. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +0 -15
  185. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts.map +0 -1
  186. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts +0 -14
  187. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts.map +0 -1
  188. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.jsx +0 -20
  189. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +0 -17
  190. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts.map +0 -1
  191. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +0 -13
  192. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts.map +0 -1
  193. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +0 -12
  194. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts.map +0 -1
  195. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +0 -23
  196. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts.map +0 -1
  197. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +0 -17
  198. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts.map +0 -1
  199. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +0 -16
  200. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts.map +0 -1
  201. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +0 -30
  202. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts.map +0 -1
  203. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +0 -10
  204. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts.map +0 -1
  205. package/lib/runtime/components/react/dist/mpx-progress.d.ts +0 -24
  206. package/lib/runtime/components/react/dist/mpx-progress.d.ts.map +0 -1
  207. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +0 -21
  208. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts.map +0 -1
  209. package/lib/runtime/components/react/dist/mpx-radio.d.ts +0 -27
  210. package/lib/runtime/components/react/dist/mpx-radio.d.ts.map +0 -1
  211. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +0 -2
  212. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts.map +0 -1
  213. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +0 -25
  214. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts.map +0 -1
  215. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +0 -15
  216. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts.map +0 -1
  217. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +0 -55
  218. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts.map +0 -1
  219. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +0 -8
  220. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts.map +0 -1
  221. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +0 -8
  222. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts.map +0 -1
  223. package/lib/runtime/components/react/dist/mpx-slider.d.ts +0 -31
  224. package/lib/runtime/components/react/dist/mpx-slider.d.ts.map +0 -1
  225. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +0 -18
  226. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts.map +0 -1
  227. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +0 -16
  228. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts.map +0 -1
  229. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +0 -19
  230. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts.map +0 -1
  231. package/lib/runtime/components/react/dist/mpx-swiper.d.ts +0 -53
  232. package/lib/runtime/components/react/dist/mpx-swiper.d.ts.map +0 -1
  233. package/lib/runtime/components/react/dist/mpx-switch.d.ts +0 -27
  234. package/lib/runtime/components/react/dist/mpx-switch.d.ts.map +0 -1
  235. package/lib/runtime/components/react/dist/mpx-text.d.ts +0 -23
  236. package/lib/runtime/components/react/dist/mpx-text.d.ts.map +0 -1
  237. package/lib/runtime/components/react/dist/mpx-textarea.d.ts +0 -8
  238. package/lib/runtime/components/react/dist/mpx-textarea.d.ts.map +0 -1
  239. package/lib/runtime/components/react/dist/mpx-video.d.ts +0 -102
  240. package/lib/runtime/components/react/dist/mpx-video.d.ts.map +0 -1
  241. package/lib/runtime/components/react/dist/mpx-view.d.ts +0 -35
  242. package/lib/runtime/components/react/dist/mpx-view.d.ts.map +0 -1
  243. package/lib/runtime/components/react/dist/mpx-web-view.d.ts +0 -23
  244. package/lib/runtime/components/react/dist/mpx-web-view.d.ts.map +0 -1
  245. package/lib/runtime/components/react/dist/parser.d.ts +0 -40
  246. package/lib/runtime/components/react/dist/parser.d.ts.map +0 -1
  247. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +0 -33
  248. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts.map +0 -1
  249. package/lib/runtime/components/react/dist/useNodesRef.d.ts +0 -12
  250. package/lib/runtime/components/react/dist/useNodesRef.d.ts.map +0 -1
  251. package/lib/runtime/components/react/dist/utils.d.ts +0 -123
  252. package/lib/runtime/components/react/dist/utils.d.ts.map +0 -1
  253. package/lib/runtime/components/react/mpx-camera.tsx +0 -275
  254. package/lib/runtime/components/react/mpx-nav.tsx +0 -155
  255. package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItemLite.tsx +0 -55
  256. package/lib/utils/get-build-tag-component.js +0 -35
@@ -1,10 +1,5 @@
1
- const fs = require('fs/promises')
2
- const parseRequest = require('../utils/parse-request')
3
- const atImport = require('postcss-import')
4
- const { default: postcss } = require('postcss')
5
-
6
1
  class Node {
7
- constructor(type, condition = null) {
2
+ constructor (type, condition = null) {
8
3
  this.type = type // 'If', 'ElseIf', 'Else' 或 'Text'
9
4
  this.condition = condition // If 或 Elif 的条件
10
5
  this.children = []
@@ -13,7 +8,7 @@ class Node {
13
8
  }
14
9
 
15
10
  // 提取 css string 为 token
16
- function tokenize(cssString) {
11
+ function tokenize (cssString) {
17
12
  const regex = /\/\*\s*@mpx-(if|elif|else|endif)(?:\s*\((.*?)\))?\s*\*\//g
18
13
  const tokens = []
19
14
  let lastIndex = 0
@@ -42,12 +37,12 @@ function tokenize(cssString) {
42
37
  }
43
38
 
44
39
  // parse:将生成的 token 数组构造成嵌套的 AST
45
- function parse(cssString) {
40
+ function parse (cssString) {
46
41
  const tokens = tokenize(cssString)
47
42
  const ast = []
48
43
  const nodeStack = []
49
44
  let currentChildren = ast
50
- tokens.forEach((token) => {
45
+ tokens.forEach(token => {
51
46
  if (token.type === 'text') {
52
47
  const node = new Node('Text')
53
48
  node.value = token.content
@@ -59,7 +54,7 @@ function parse(cssString) {
59
54
  currentChildren = node.children
60
55
  } else if (token.type === 'elif') {
61
56
  if (nodeStack.length === 0) {
62
- throw new Error('[Mpx style error]: elif without a preceding if')
57
+ throw new Error('elif without a preceding if')
63
58
  }
64
59
  currentChildren = nodeStack[nodeStack.length - 1]
65
60
  const node = new Node('ElseIf', token.condition)
@@ -67,7 +62,7 @@ function parse(cssString) {
67
62
  currentChildren = node.children
68
63
  } else if (token.type === 'else') {
69
64
  if (nodeStack.length === 0) {
70
- throw new Error('[Mpx style error]: else without a preceding if')
65
+ throw new Error('else without a preceding if')
71
66
  }
72
67
  currentChildren = nodeStack[nodeStack.length - 1]
73
68
  const node = new Node('Else')
@@ -82,23 +77,23 @@ function parse(cssString) {
82
77
  return ast
83
78
  }
84
79
 
85
- function evaluateCondition(condition, defs) {
80
+ function evaluateCondition (condition, defs) {
86
81
  try {
87
82
  const keys = Object.keys(defs)
88
- const values = keys.map((key) => defs[key])
83
+ const values = keys.map(key => defs[key])
89
84
  /* eslint-disable no-new-func */
90
85
  const func = new Function(...keys, `return (${condition});`)
91
86
  return func(...values)
92
87
  } catch (e) {
93
- console.error(`[Mpx style error]:Error evaluating condition: ${condition}`, e)
88
+ console.error(`Error evaluating condition: ${condition}`, e)
94
89
  return false
95
90
  }
96
91
  }
97
92
 
98
- function traverseAndEvaluate(ast, defs) {
93
+ function traverseAndEvaluate (ast, defs) {
99
94
  let output = ''
100
95
  let batchedIf = false
101
- function traverse(nodes) {
96
+ function traverse (nodes) {
102
97
  for (const node of nodes) {
103
98
  if (node.type === 'Text') {
104
99
  output += node.value
@@ -123,168 +118,10 @@ function traverseAndEvaluate(ast, defs) {
123
118
  return output
124
119
  }
125
120
 
126
- /**
127
- *
128
- * @param {string} content
129
- * @param {Record<string, any>} defs
130
- * @returns
131
- */
132
- function stripCondition(content, defs) {
133
- const ast = parse(content)
134
- const result = traverseAndEvaluate(ast, defs)
135
- return result
136
- }
137
-
138
- /**
139
- * @typedef {Object} StripByPostcssOption
140
- * @property {string} lang 样式语法格式
141
- * @property {string} resourcePath 文件路径
142
- * @property {string} css 源文件
143
- * @property {Record<string, any>} defs 条件定义
144
- * @property {import('webpack').LoaderContext<any>['resolve']} resolve webpack resolve 方法
145
- */
146
-
147
- /**
148
- * @typedef {Object} AtImportConfig
149
- * @property {string} from 当前文件路径
150
- * @property {(filename: string) => Promise<string> | string;} load 加载文件内容的函数
151
- * @property {(id: string, base: string) => Promise<string | null> | string | null;} resolve 解析文件路径的函数
152
- */
153
-
154
- /**
155
- *
156
- * @param {Function} callback
157
- * @param {string} name
158
- * @returns
159
- */
160
- const shouldInstallWarning = (callback, name) => {
161
- return () => {
162
- try {
163
- return callback()
164
- } catch (error) {
165
- throw new Error(
166
- `[mpx-strip-conditional-loader]: ${name} is not installed, please install it first.\norginal Error: ${
167
- error?.message ?? error.toString()
168
- }`,
169
- {
170
- cause: error
171
- }
172
- )
173
- }
174
- }
175
- }
176
- /**
177
- *
178
- * @typedef {import('postcss').ProcessOptions} ProcessOptions
179
- * @typedef {import('postcss').Root} Root
180
- *
181
- * @type {Record<string, ProcessOptions['syntax']>}
182
- */
183
- const styleSyntaxProcesserMap = {
184
- stylus: shouldInstallWarning(() => require('postcss-styl'), 'postcss-styl'),
185
- less: shouldInstallWarning(() => require('postcss-less'), 'postcss-less'),
186
- scss: shouldInstallWarning(() => require('postcss-scss'), 'postcss-scss')
187
- }
188
-
189
- /**
190
- * @param {StripByPostcssOption} options
191
- */
192
- async function stripByPostcss(options) {
193
- const syntax = styleSyntaxProcesserMap[options.lang]?.()
194
- const defs = options.defs ?? {}
195
-
196
- function stripContentCondition(content) {
197
- content = stripCondition(content, defs)
198
-
199
- if (options.lang === 'stylus') {
200
- content = content.replace(/\t/g, ' ')
201
- }
202
-
203
- return content
204
- }
205
-
206
- const afterConditionStrip = stripContentCondition(options.css, defs)
207
-
208
- /**
209
- * @type {import('postcss').AcceptedPlugin[]}
210
- */
211
- const plugins = [
212
- atImport({
213
- async load(filename) {
214
- let content = await fs.readFile(filename, 'utf-8')
215
- const processer = postcss(plugins)
216
-
217
- content = stripContentCondition(content, defs)
218
-
219
- const { css } = await processer.process(content, {
220
- syntax,
221
- from: filename,
222
- to: options.resourcePath
223
- })
224
- return css
225
- },
226
- resolve: (id, base) => {
227
- return new Promise((resolve, reject) => {
228
- options.resolve(base, id, (err, res) => {
229
- if (err) return reject(err)
230
- if (typeof res !== 'string') {
231
- return reject(
232
- new Error(
233
- `[mpx-strip-conditional-loader]: Cannot resolve ${id} from ${base}`
234
- )
235
- )
236
- }
237
- resolve(res)
238
- })
239
- })
240
- }
241
- }),
242
- {
243
- // less/scss syntax 在 postcss 重新生成 css 后,`//` 注释后面不会保留换行,会和后续的 css 语句和注释连在一起,导致后续语法错误
244
- postcssPlugin: 'mpx-strip-conditional-loader-append-command',
245
- CommentExit(comment) {
246
- if (!comment.raws.right) {
247
- comment.raws.right = '\n'
248
- return
249
- }
250
-
251
- if (!comment.raws.right.startsWith('\n')) {
252
- comment.raws.right = '\n' + comment.raws.right
253
- }
254
- }
255
- }
256
- ]
257
-
258
- const processer = postcss(plugins)
259
- return processer.process(afterConditionStrip, {
260
- from: options.resourcePath,
261
- syntax
262
- })
263
- }
264
-
265
- /**
266
- *
267
- * @this {import('webpack').LoaderContext<any>}
268
- * @param {string} css
269
- */
270
- module.exports = async function (css) {
121
+ module.exports = function (css) {
271
122
  this.cacheable()
272
-
273
- const callback = this.async()
274
-
275
123
  const mpx = this.getMpx()
276
- const { resourcePath, queryObj } = parseRequest(this.resource)
277
-
278
- const result = await stripByPostcss({
279
- lang: queryObj.lang,
280
- resourcePath,
281
- css,
282
- defs: mpx.defs,
283
- resolve: this.resolve.bind(this)
284
- })
285
-
286
- callback(null, result.css, result.map)
124
+ const defs = mpx.defs
125
+ const ast = parse(css)
126
+ return traverseAndEvaluate(ast, defs)
287
127
  }
288
-
289
- module.exports.stripByPostcss = stripByPostcss
290
- module.exports.stripCondition = stripCondition
@@ -258,7 +258,7 @@ module.exports = {
258
258
  })
259
259
  return {
260
260
  code: pCollectKeys.map((key) => {
261
- return isSimpleKey(key) ? `mpx_sc(${JSON.stringify(key)});` : `mpx_c(${JSON.stringify(key)});`
261
+ return isSimpleKey(key) ? `_sc(${JSON.stringify(key)});` : `_c(${JSON.stringify(key)});`
262
262
  }).join('\n'),
263
263
  propKeys: [...propKeySet]
264
264
  }
@@ -436,7 +436,7 @@ module.exports = {
436
436
  exit (path) {
437
437
  if (path.collectInfo) {
438
438
  const { isSimple, key } = path.collectInfo
439
- const callee = isSimple ? t.identifier('mpx_sc') : t.identifier('mpx_c')
439
+ const callee = isSimple ? t.identifier('_sc') : t.identifier('_c')
440
440
  const replaceNode = renderReduce
441
441
  ? t.callExpression(callee, [key])
442
442
  : t.callExpression(callee, [key, path.node])