@mpxjs/webpack-plugin 2.10.16-beta.7 → 2.10.17-beta.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 (58) hide show
  1. package/lib/config.js +0 -60
  2. package/lib/file-loader.js +3 -13
  3. package/lib/json-compiler/index.js +2 -2
  4. package/lib/platform/json/wx/index.js +0 -6
  5. package/lib/platform/template/wx/component-config/ad.js +0 -5
  6. package/lib/platform/template/wx/component-config/button.js +2 -9
  7. package/lib/platform/template/wx/component-config/camera.js +3 -25
  8. package/lib/platform/template/wx/component-config/canvas.js +1 -8
  9. package/lib/platform/template/wx/component-config/cover-image.js +2 -7
  10. package/lib/platform/template/wx/component-config/cover-view.js +1 -3
  11. package/lib/platform/template/wx/component-config/form.js +2 -27
  12. package/lib/platform/template/wx/component-config/image.js +0 -5
  13. package/lib/platform/template/wx/component-config/input.js +0 -10
  14. package/lib/platform/template/wx/component-config/label.js +2 -10
  15. package/lib/platform/template/wx/component-config/map.js +0 -11
  16. package/lib/platform/template/wx/component-config/movable-area.js +1 -4
  17. package/lib/platform/template/wx/component-config/movable-view.js +2 -17
  18. package/lib/platform/template/wx/component-config/navigator.js +0 -26
  19. package/lib/platform/template/wx/component-config/picker-view.js +0 -12
  20. package/lib/platform/template/wx/component-config/picker.js +1 -3
  21. package/lib/platform/template/wx/component-config/progress.js +1 -11
  22. package/lib/platform/template/wx/component-config/rich-text.js +0 -5
  23. package/lib/platform/template/wx/component-config/scroll-view.js +1 -12
  24. package/lib/platform/template/wx/component-config/slider.js +0 -8
  25. package/lib/platform/template/wx/component-config/swiper-item.js +2 -5
  26. package/lib/platform/template/wx/component-config/swiper.js +0 -10
  27. package/lib/platform/template/wx/component-config/text.js +0 -5
  28. package/lib/platform/template/wx/component-config/textarea.js +2 -19
  29. package/lib/platform/template/wx/component-config/unsupported.js +1 -10
  30. package/lib/platform/template/wx/component-config/video.js +0 -10
  31. package/lib/platform/template/wx/index.js +1 -21
  32. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +1 -1
  33. package/lib/runtime/components/react/dist/mpx-image.d.ts.map +1 -1
  34. package/lib/runtime/components/react/dist/mpx-image.jsx +26 -20
  35. package/lib/runtime/components/react/dist/mpx-input.d.ts.map +1 -1
  36. package/lib/runtime/components/react/dist/mpx-input.jsx +1 -3
  37. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +1 -1
  38. package/lib/runtime/components/react/dist/mpx-web-view.d.ts.map +1 -1
  39. package/lib/runtime/components/react/dist/mpx-web-view.jsx +11 -3
  40. package/lib/runtime/components/react/mpx-canvas/index.tsx +1 -1
  41. package/lib/runtime/components/react/mpx-image.tsx +41 -35
  42. package/lib/runtime/components/react/mpx-input.tsx +1 -3
  43. package/lib/runtime/components/react/mpx-rich-text/index.tsx +1 -1
  44. package/lib/runtime/components/react/mpx-web-view.tsx +14 -5
  45. package/lib/runtime/stringify.wxs +2 -2
  46. package/lib/style-compiler/strip-conditional-loader.js +142 -90
  47. package/lib/template-compiler/bind-this.js +2 -2
  48. package/lib/template-compiler/compiler.js +3 -4
  49. package/lib/template-compiler/index.js +6 -6
  50. package/lib/utils/dom-tag-config.js +1 -1
  51. package/lib/utils/merge-visitors.js +55 -0
  52. package/lib/wxs/pre-loader.js +8 -5
  53. package/package.json +3 -12
  54. package/lib/runtime/components/react/dist/mpx-camera.d.ts +0 -28
  55. package/lib/runtime/components/react/dist/mpx-camera.d.ts.map +0 -1
  56. package/lib/runtime/components/react/dist/mpx-camera.jsx +0 -102
  57. package/lib/runtime/components/react/mpx-camera.tsx +0 -167
  58. package/lib/utils/chain-assign.js +0 -47
@@ -127,8 +127,16 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
127
127
  style: defaultWebViewStyle
128
128
  })
129
129
 
130
+ const getHostFromUrl = function (url: string): string {
131
+ if (!url) return ''
132
+ // 匹配协议://主机名(:端口) 的模式
133
+ const regex = /^(?:https?|ftp):\/\/([^/?:#]+)(?::(\d+))?/i
134
+ const match = url.match(regex)
135
+ return match ? match[1] : ''
136
+ }
137
+
130
138
  const hostValidate = (url: string) => {
131
- const host = url && new URL(url).host
139
+ const host = url && getHostFromUrl(url)
132
140
  const hostWhitelists = mpx.config.rnConfig?.webviewConfig?.hostWhitelists || []
133
141
  if (hostWhitelists.length) {
134
142
  return hostWhitelists.some((item: string) => {
@@ -226,7 +234,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
226
234
  }
227
235
  break
228
236
  case 'postMessage':
229
- bindmessage && bindmessage(getCustomEvent('message', {}, { // RN组件销毁顺序与小程序不一致,所以改成和支付宝消息一致
237
+ bindmessage && bindmessage(getCustomEvent('messsage', {}, { // RN组件销毁顺序与小程序不一致,所以改成和支付宝消息一致
230
238
  detail: {
231
239
  data: params[0]?.data
232
240
  }
@@ -343,8 +351,9 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
343
351
  <View style={styles.loadErrorButton} onTouchEnd={_reload}><Text style={{ fontSize: 12, color: '#666666' }}>{currentErrorText.button}</Text></View>
344
352
  </View>
345
353
  )
346
- : (<WebView
347
- style={ defaultWebViewStyle }
354
+ : (
355
+ <WebView
356
+ containerStyle={ defaultWebViewStyle }
348
357
  source={{ uri: src }}
349
358
  ref={webViewRef}
350
359
  javaScriptEnabled={true}
@@ -356,7 +365,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
356
365
  onHttpError={onHttpError}
357
366
  onError={onError}
358
367
  allowsBackForwardNavigationGestures={true}
359
- ></WebView>)}
368
+ ></WebView>)}
360
369
  </Portal>
361
370
  )
362
371
  })
@@ -45,7 +45,7 @@ function objectKeys (obj) {
45
45
  }
46
46
 
47
47
  function genRegExp (str, flags) {
48
- if (!__mpx_wxs__ || __mpx_mode__ === 'ks') {
48
+ if (!__mpx_wxs__) {
49
49
  return new RegExp(str, flags)
50
50
  } else {
51
51
  return getRegExp(str, flags)
@@ -234,4 +234,4 @@ module.exports = {
234
234
  var parsedStaticStyle = typeof staticStyle === 'string' ? parseStyleText(staticStyle) : {}
235
235
  return genStyleText(extend(parsedStaticStyle, normalizedDynamicStyle))
236
236
  }
237
- }
237
+ }
@@ -1,7 +1,7 @@
1
1
  const fs = require('fs/promises')
2
2
  const parseRequest = require('../utils/parse-request')
3
- const atImport = require('postcss-import')
4
- const { default: postcss } = require('postcss')
3
+ const path = require('path')
4
+ const loaderUtils = require('loader-utils')
5
5
 
6
6
  class Node {
7
7
  constructor(type, condition = null) {
@@ -47,7 +47,7 @@ function parse(cssString) {
47
47
  const ast = []
48
48
  const nodeStack = []
49
49
  let currentChildren = ast
50
- tokens.forEach((token) => {
50
+ tokens.forEach(token => {
51
51
  if (token.type === 'text') {
52
52
  const node = new Node('Text')
53
53
  node.value = token.content
@@ -85,7 +85,7 @@ function parse(cssString) {
85
85
  function evaluateCondition(condition, defs) {
86
86
  try {
87
87
  const keys = Object.keys(defs)
88
- const values = keys.map((key) => defs[key])
88
+ const values = keys.map(key => defs[key])
89
89
  /* eslint-disable no-new-func */
90
90
  const func = new Function(...keys, `return (${condition});`)
91
91
  return func(...values)
@@ -151,46 +151,109 @@ function stripCondition(content, defs) {
151
151
  * @property {(id: string, base: string) => Promise<string | null> | string | null;} resolve 解析文件路径的函数
152
152
  */
153
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
- )
154
+ async function atImport(options) {
155
+ let { css, load, resolve, from } = options
156
+ const fromParent = path.dirname(from)
157
+ const e1 = /\/\*[\s\S]*?\*\//g
158
+ // 匹配 // 单行注释,可能匹配到静态资源中的 http:// 的 //,不过影响不大, @import 不太可能出现在静态资源链接中
159
+ const e2 = /\/\/.*/g
160
+ // 使用正则匹配匹配出 多行注释和单行注释
161
+ const comments = []
162
+ let comment
163
+ while ((comment = e1.exec(css))) {
164
+ const [content] = comment
165
+ comments.push({
166
+ start: comment.index,
167
+ end: comment.index + content.length,
168
+ content: content
169
+ })
170
+ }
171
+
172
+ while ((comment = e2.exec(css))) {
173
+ const [content] = comment
174
+ comments.push({
175
+ start: comment.index,
176
+ end: comment.index + content.length,
177
+ content: content
178
+ })
179
+ }
180
+
181
+ // 排序方便二分
182
+ comments.sort((a, b) => (a.start > b.start ? 1 : -1))
183
+
184
+ function isInComments(index) {
185
+ let left = 0
186
+ let right = comments.length - 1
187
+
188
+ while (left <= right) {
189
+ const mid = Math.floor((left + right) / 2)
190
+ const comment = comments[mid]
191
+
192
+ if (index >= comment.start && index <= comment.end) {
193
+ return true
194
+ } else if (index < comment.start) {
195
+ right = mid - 1
196
+ } else {
197
+ left = mid + 1
198
+ }
173
199
  }
200
+
201
+ return false
174
202
  }
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
203
 
204
+ // 使用正则表达式匹配出所有 @import 语法,语法包含 @import "path", @import 'path', @import url("path"), @import url('path')
205
+ // 注意清理分号,否则留个分号会报错
206
+ const importRegex = /@import\s+(url\(['"]([^'"]+)['"]\)|['"]([^'"]+)['"])(\s*;)?/g
207
+ let importList = []
208
+ let importMatch
209
+ while ((importMatch = importRegex.exec(css))) {
210
+ const fullMatch = importMatch[0]
211
+ const importSyntax = fullMatch.trim()
212
+ importSyntax.startsWith('@import')
213
+ const importValue = importSyntax.slice(7).trim()
214
+ // 匹配 @import 后字符串格式
215
+ const importUrlRegex = /url\s*\(['"]([^'"]+)['"]\)/g
216
+ const importStrRegexp = /^(['"])([^'"]+)\1/
217
+
218
+ let urlMatch = null
219
+ if (importValue.startsWith('url')) {
220
+ urlMatch = importUrlRegex.exec(importValue)?.[1]
221
+ } else {
222
+ urlMatch = importStrRegexp.exec(importValue)?.[2]
223
+ }
224
+ if (!urlMatch) {
225
+ continue
226
+ }
227
+
228
+ importList.push({
229
+ start: importMatch.index,
230
+ end: importMatch.index + fullMatch.length,
231
+ content: fullMatch,
232
+ url: urlMatch
233
+ })
234
+ }
235
+
236
+ // 过滤掉在注释中的 @import 语法
237
+ importList = importList.filter(imp => !isInComments(imp.start))
238
+
239
+ // 逆序替换 import,避免修改内容导致的索引偏移问题
240
+ importList.sort((a, b) => (a.start > b.start ? -1 : 1))
241
+
242
+ for (const imp of importList) {
243
+ const importPath = imp.url
244
+ if (!importPath) continue
245
+ // 非法路径直接报错
246
+ const resolvedUrl = await resolve(importPath, fromParent)
247
+ const content = (await load(resolvedUrl)) ?? ''
248
+ css = css.slice(0, imp.start) + '\n' + content + '\n' + css.slice(imp.end)
249
+ }
250
+
251
+ return css
252
+ }
189
253
  /**
190
254
  * @param {StripByPostcssOption} options
191
255
  */
192
256
  async function stripByPostcss(options) {
193
- const syntax = styleSyntaxProcesserMap[options.lang]?.()
194
257
  const defs = options.defs ?? {}
195
258
 
196
259
  function stripContentCondition(content) {
@@ -203,63 +266,52 @@ async function stripByPostcss(options) {
203
266
  return content
204
267
  }
205
268
 
269
+ /**
270
+ * @type {string}
271
+ */
206
272
  const afterConditionStrip = stripContentCondition(options.css, defs)
207
273
 
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
- }
274
+ const atImportOptions = {
275
+ async load(filename) {
276
+ let content = await fs.readFile(filename, 'utf-8')
250
277
 
251
- if (!comment.raws.right.startsWith('\n')) {
252
- comment.raws.right = '\n' + comment.raws.right
253
- }
254
- }
278
+ content = stripContentCondition(content, defs)
279
+
280
+ return await atImport({
281
+ ...atImportOptions,
282
+ from: filename,
283
+ css: content
284
+ })
285
+ },
286
+ resolve: (id, base) => {
287
+ return new Promise((resolve, reject) => {
288
+ // 处理 ~ 开头的路径
289
+ options.resolve(base, id.startsWith('~') && !id.startsWith('~/') ? loaderUtils.urlToRequest(id) : id, (err, res) => {
290
+ if (err) return reject(err)
291
+ if (typeof res !== 'string') {
292
+ return reject(new Error(`[mpx-strip-conditional-loader]: Cannot resolve ${id} from ${base}`))
293
+ }
294
+ resolve(res)
295
+ })
296
+ })
255
297
  }
256
- ]
298
+ }
257
299
 
258
- const processer = postcss(plugins)
259
- return processer.process(afterConditionStrip, {
260
- from: options.resourcePath,
261
- syntax
262
- })
300
+ return {
301
+ css: await atImport({
302
+ ...atImportOptions,
303
+ from: options.resourcePath,
304
+ css: afterConditionStrip
305
+ })
306
+ }
307
+ }
308
+
309
+ const createResolver = (contetx, extensions) =>
310
+ contetx.getResolve({ mainFiles: ['index'], extensions: [...extensions, '.css'], preferRelative: true })
311
+ const resolver = {
312
+ stylus: contetx => createResolver(contetx, ['.styl']),
313
+ scss: contetx => createResolver(contetx, ['.scss']),
314
+ less: contetx => createResolver(contetx, ['.styl'])
263
315
  }
264
316
 
265
317
  /**
@@ -280,7 +332,7 @@ module.exports = async function (css) {
280
332
  resourcePath,
281
333
  css,
282
334
  defs: mpx.defs,
283
- resolve: this.resolve.bind(this)
335
+ resolve: resolver[queryObj.lang] ? resolver[queryObj.lang](this) : this.resolve.bind(this)
284
336
  })
285
337
 
286
338
  callback(null, result.css, result.map)
@@ -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])
@@ -1014,7 +1014,7 @@ function processComponentIs (el, options) {
1014
1014
  ranges = range.split(',').map(i => i.trim()).filter(i => i)
1015
1015
  } else {
1016
1016
  // 根据原始用户写的usingComponents字段生成ranges
1017
- ranges = options.originalUsingComponents
1017
+ ranges = options.originalUsingComponents || []
1018
1018
  }
1019
1019
 
1020
1020
  const rangeMap = new Map()
@@ -2247,7 +2247,6 @@ function postProcessIfReact (el) {
2247
2247
  delete el.elseif
2248
2248
  el._if = true
2249
2249
  addIfCondition(ifNode, {
2250
- exp: el.elseif.exp,
2251
2250
  block: el
2252
2251
  })
2253
2252
  removeNode(el, true)
@@ -2720,7 +2719,7 @@ function postProcessTemplate (el) {
2720
2719
  }
2721
2720
  }
2722
2721
 
2723
- const isValidMode = makeMap('wx,ali,swan,tt,qq,web,qa,jd,dd,tenon,ios,android,harmony,ks,noMode')
2722
+ const isValidMode = makeMap('wx,ali,swan,tt,qq,web,qa,jd,dd,tenon,ios,android,harmony,noMode')
2724
2723
 
2725
2724
  function isValidModeP (i) {
2726
2725
  return isValidMode(i[0] === '_' ? i.slice(1) : i)
@@ -3262,7 +3261,7 @@ function genFor (node) {
3262
3261
  node.forProcessed = true
3263
3262
  const index = node.for.index || 'index'
3264
3263
  const item = node.for.item || 'item'
3265
- return `mpx_i(${node.for.exp}, function(${item},${index}){\n${genNode(node)}});\n`
3264
+ return `_i(${node.for.exp}, function(${item},${index}){\n${genNode(node)}});\n`
3266
3265
  }
3267
3266
 
3268
3267
  function genNode (node) {
@@ -112,10 +112,10 @@ module.exports = function (raw) {
112
112
  if (rawCode) {
113
113
  try {
114
114
  const ignoreMap = Object.assign({
115
- mpx_i: true,
116
- mpx_c: true,
117
- mpx_sc: true,
118
- mpx_r: true
115
+ _i: true,
116
+ _c: true,
117
+ _sc: true,
118
+ _r: true
119
119
  }, meta.wxsModuleMap)
120
120
  const bindResult = optimizeRenderLevel === 2
121
121
  ? bindThis.transformSimple(rawCode, {
@@ -126,9 +126,9 @@ module.exports = function (raw) {
126
126
  renderReduce: optimizeRenderLevel === 1,
127
127
  ignoreMap
128
128
  })
129
- resultSource += `global.currentInject.render = function (mpx_i, mpx_c, mpx_r, mpx_sc) {
129
+ resultSource += `global.currentInject.render = function (_i, _c, _r, _sc) {
130
130
  ${bindResult.code}
131
- mpx_r(${optimizeRenderLevel === 2 ? 'true' : ''});
131
+ _r(${optimizeRenderLevel === 2 ? 'true' : ''});
132
132
  };\n`
133
133
  if ((mode === 'tt' || mode === 'swan') && bindResult.propKeys) {
134
134
  resultSource += `global.currentInject.propKeys = ${JSON.stringify(bindResult.propKeys)};\n`
@@ -91,7 +91,7 @@ const isBuildInReactTag = makeMap(
91
91
  'mpx-movable-area,mpx-label,mpx-input,' +
92
92
  'mpx-image,mpx-form,mpx-checkbox,mpx-checkbox-group,mpx-button,' +
93
93
  'mpx-rich-text,mpx-picker-view-column,mpx-picker-view,mpx-picker,' +
94
- 'mpx-icon,mpx-canvas,mpx-camera'
94
+ 'mpx-icon,mpx-canvas'
95
95
  )
96
96
 
97
97
  const isSpace = makeMap('ensp,emsp,nbsp')
@@ -0,0 +1,55 @@
1
+ /**
2
+ * 链式合并方法的工具函数
3
+ *
4
+ * 在多条件分支下使用 Object.assign 会导致同名方法被覆盖,
5
+ * 这个函数通过创建组合函数来确保所有方法都能按顺序执行。
6
+ *
7
+ * @param {Object} target - 目标 visitor 对象
8
+ * @param {Object} source - 要链式分配的 visitor 方法对象
9
+ **/
10
+
11
+ // 辅助函数:将 visitor 的所有钩子添加到结果中
12
+ function mergeVisitorHooks (result, visitor) {
13
+ result.enter = result.enter.concat(visitor.enter)
14
+ result.exit = result.exit.concat(visitor.exit)
15
+ return result
16
+ }
17
+
18
+ function normalizeVisitor(visitor) {
19
+ if (Array.isArray(visitor.enter) && Array.isArray(visitor.exit)) {
20
+ return visitor
21
+ }
22
+ if (typeof visitor === 'function') {
23
+ return { enter: [visitor], exit: [] }
24
+ }
25
+
26
+ if (visitor.enter) {
27
+ if (!Array.isArray(visitor.enter)) {
28
+ visitor.enter = [visitor.enter]
29
+ }
30
+ } else {
31
+ visitor.enter = []
32
+ }
33
+
34
+ if (visitor.exit) {
35
+ if (!Array.isArray(visitor.exit)) {
36
+ visitor.exit = [visitor.exit]
37
+ }
38
+ } else {
39
+ visitor.exit = []
40
+ }
41
+ return visitor
42
+ }
43
+
44
+ module.exports = function mergeVisitors (target, source) {
45
+ for (const [key, value] of Object.entries(source)) {
46
+ if (!target[key]) {
47
+ target[key] = normalizeVisitor(value)
48
+ } else {
49
+ // 合并现有值和新值
50
+ target[key] = mergeVisitorHooks(normalizeVisitor(target[key]), normalizeVisitor(value))
51
+ }
52
+ }
53
+
54
+ return target
55
+ }
@@ -4,7 +4,7 @@ const t = require('@babel/types')
4
4
  const generate = require('@babel/generator').default
5
5
  const parseRequest = require('../utils/parse-request')
6
6
  const isEmptyObject = require('../utils/is-empty-object')
7
- const chainAssign = require('../utils/chain-assign')
7
+ const mergeVisitors = require('../utils/merge-visitors')
8
8
  const parseQuery = require('loader-utils').parseQuery
9
9
 
10
10
  module.exports = function (content) {
@@ -31,7 +31,7 @@ module.exports = function (content) {
31
31
  ' __mpx_args__[i] = arguments[i];\n' +
32
32
  '}'
33
33
  ).program.body
34
- chainAssign(visitor, {
34
+ mergeVisitors(visitor, {
35
35
  Identifier (path) {
36
36
  if (path.node.name === 'arguments') {
37
37
  path.node.name = '__mpx_args__'
@@ -66,7 +66,7 @@ module.exports = function (content) {
66
66
  }
67
67
 
68
68
  if (mode !== 'wx') {
69
- chainAssign(visitor, {
69
+ mergeVisitors(visitor, {
70
70
  CallExpression (path) {
71
71
  const callee = path.node.callee
72
72
  if (t.isIdentifier(callee) && callee.name === 'getRegExp') {
@@ -81,7 +81,7 @@ module.exports = function (content) {
81
81
  }
82
82
 
83
83
  if (mode === 'dd') {
84
- chainAssign(visitor, {
84
+ mergeVisitors(visitor, {
85
85
  MemberExpression (path) {
86
86
  const property = path.node.property
87
87
  if (
@@ -96,8 +96,11 @@ module.exports = function (content) {
96
96
  }
97
97
 
98
98
  if (!module.wxs) {
99
- chainAssign(visitor, {
99
+ mergeVisitors(visitor, {
100
100
  MemberExpression (path) {
101
+ if (!t.isMemberExpression(path.node)) {
102
+ return
103
+ }
101
104
  const property = path.node.property
102
105
  if (
103
106
  property && (property.name === 'constructor' || property.value === 'constructor') &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.10.16-beta.7",
3
+ "version": "2.10.17-beta.1",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -29,10 +29,7 @@
29
29
  "@better-scroll/wheel": "^2.5.1",
30
30
  "@better-scroll/zoom": "^2.5.1",
31
31
  "@mpxjs/template-engine": "^2.8.7",
32
- "@mpxjs/utils": "^2.10.16-beta.7",
33
- "postcss-less": "^6.0.0",
34
- "postcss-scss": "^4.0.9",
35
- "postcss-styl": "^0.12.3",
32
+ "@mpxjs/utils": "^2.10.17",
36
33
  "acorn": "^8.11.3",
37
34
  "acorn-walk": "^7.2.0",
38
35
  "async": "^2.6.0",
@@ -54,7 +51,6 @@
54
51
  "mime": "^2.2.2",
55
52
  "object-assign": "^4.1.1",
56
53
  "postcss": "^8.4.5",
57
- "postcss-import": "^16.1.1",
58
54
  "postcss-load-config": "^3.1.1",
59
55
  "postcss-modules-extract-imports": "^3.0.0",
60
56
  "postcss-modules-local-by-default": "^4.0.0",
@@ -67,9 +63,6 @@
67
63
  "webpack-virtual-modules": "^0.6.0"
68
64
  },
69
65
  "peerDependencies": {
70
- "postcss-less": "^6.0.0",
71
- "postcss-scss": "^4.0.9",
72
- "postcss-styl": "^0.12.3",
73
66
  "webpack": "^5.75.0"
74
67
  },
75
68
  "publishConfig": {
@@ -91,11 +84,10 @@
91
84
  },
92
85
  "devDependencies": {
93
86
  "@d11/react-native-fast-image": "^8.6.12",
94
- "@mpxjs/api-proxy": "^2.10.16-beta.7",
87
+ "@mpxjs/api-proxy": "^2.10.17",
95
88
  "@types/babel-traverse": "^6.25.4",
96
89
  "@types/babel-types": "^7.0.4",
97
90
  "@types/glob": "^8.1.0",
98
- "@types/postcss-import": "^14.0.3",
99
91
  "@types/react": "^18.2.79",
100
92
  "glob": "^11.0.2",
101
93
  "react-native": "^0.74.5",
@@ -105,7 +97,6 @@
105
97
  "react-native-safe-area-context": "^4.12.0",
106
98
  "react-native-svg": "^15.8.0",
107
99
  "react-native-video": "^6.9.0",
108
- "react-native-vision-camera": "^4.7.2",
109
100
  "react-native-webview": "^13.12.2",
110
101
  "rimraf": "^6.0.1"
111
102
  },
@@ -1,28 +0,0 @@
1
- import React from 'react';
2
- import { Camera } from 'react-native-vision-camera';
3
- interface CameraProps {
4
- mode?: 'normal' | 'scanCode';
5
- resolution?: 'low' | 'medium' | 'high';
6
- devicePosition?: 'front' | 'back';
7
- flash?: 'auto' | 'on' | 'off';
8
- frameSize?: 'small' | 'medium' | 'large';
9
- style?: Record<string, any>;
10
- bindstop?: () => void;
11
- binderror?: (error: {
12
- message: string;
13
- }) => void;
14
- bindinitdone?: (result: {
15
- type: string;
16
- data: string;
17
- }) => void;
18
- bindscancode?: (result: {
19
- type: string;
20
- data: string;
21
- }) => void;
22
- }
23
- type HandlerRef<T, P> = {
24
- current: T | null;
25
- };
26
- declare const _camera: React.ForwardRefExoticComponent<CameraProps & React.RefAttributes<HandlerRef<Camera, CameraProps>>>;
27
- export default _camera;
28
- //# sourceMappingURL=mpx-camera.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mpx-camera.d.ts","sourceRoot":"","sources":["../mpx-camera.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2E,MAAM,OAAO,CAAA;AAC/F,OAAO,EAAE,MAAM,EAAuE,MAAM,4BAA4B,CAAA;AAIxH,UAAU,WAAW;IACnB,IAAI,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAA;IAC5B,UAAU,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAA;IACtC,cAAc,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IACjC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,KAAK,CAAA;IAC7B,SAAS,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAA;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC3B,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;IACrB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAA;IAChD,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAA;IAC/D,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAA;CAChE;AASD,KAAK,UAAU,CAAC,CAAC,EAAE,CAAC,IAAI;IAEtB,OAAO,EAAE,CAAC,GAAG,IAAI,CAAA;CAClB,CAAA;AAED,QAAA,MAAM,OAAO,qGAoIX,CAAA;AAIF,eAAe,OAAO,CAAA"}