@mpxjs/webpack-plugin 2.8.45 → 2.8.47

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.
@@ -193,14 +193,7 @@ module.exports = function getSpec ({ warn, error }) {
193
193
  // 不过滤的话每一个属性都要 parse
194
194
  el.attrsList.filter(item => this.test.test(item.name)).forEach((item) => {
195
195
  const parsed = parseMustache(item.value)
196
- if (item.name === 'wx:style') {
197
- styleBinding.push(parsed.result)
198
- // item.name === 'style'
199
- } else if (parsed.hasBinding || parsed.result.indexOf('rpx') > -1) {
200
- styleBinding.push(parsed.result)
201
- } else {
202
- styleBinding.push(JSON.stringify(item.value))
203
- }
196
+ styleBinding.push(parsed.result)
204
197
  })
205
198
  return {
206
199
  name: ':style',
@@ -295,18 +288,39 @@ module.exports = function getSpec ({ warn, error }) {
295
288
  },
296
289
  swan ({ name, value }, { eventRules }) {
297
290
  const match = this.test.exec(name)
291
+ const prefix = match[1]
298
292
  const eventName = match[2]
299
- runRules(eventRules, eventName, { mode: 'swan' })
293
+ const modifierStr = match[3] || ''
294
+ const rPrefix = runRules(spec.event.prefix, prefix, { mode: 'swan' })
295
+ const rEventName = runRules(eventRules, eventName, { mode: 'swan' })
296
+ return {
297
+ name: rPrefix + rEventName + modifierStr,
298
+ value
299
+ }
300
300
  },
301
301
  qq ({ name, value }, { eventRules }) {
302
302
  const match = this.test.exec(name)
303
+ const prefix = match[1]
303
304
  const eventName = match[2]
304
- runRules(eventRules, eventName, { mode: 'qq' })
305
+ const modifierStr = match[3] || ''
306
+ const rPrefix = runRules(spec.event.prefix, prefix, { mode: 'qq' })
307
+ const rEventName = runRules(eventRules, eventName, { mode: 'qq' })
308
+ return {
309
+ name: rPrefix + rEventName + modifierStr,
310
+ value
311
+ }
305
312
  },
306
313
  jd ({ name, value }, { eventRules }) {
307
314
  const match = this.test.exec(name)
315
+ const prefix = match[1]
308
316
  const eventName = match[2]
309
- runRules(eventRules, eventName, { mode: 'jd' })
317
+ const modifierStr = match[3] || ''
318
+ const rPrefix = runRules(spec.event.prefix, prefix, { mode: 'jd' })
319
+ const rEventName = runRules(eventRules, eventName, { mode: 'jd' })
320
+ return {
321
+ name: rPrefix + rEventName + modifierStr,
322
+ value
323
+ }
310
324
  },
311
325
  // tt ({ name, value }, { eventRules }) {
312
326
  // const match = this.test.exec(name)
@@ -322,15 +336,33 @@ module.exports = function getSpec ({ warn, error }) {
322
336
  // },
323
337
  tt ({ name, value }, { eventRules }) {
324
338
  const match = this.test.exec(name)
339
+ const prefix = match[1]
325
340
  const eventName = match[2]
326
- runRules(eventRules, eventName, { mode: 'tt' })
341
+ const modifierStr = match[3] || ''
342
+ const rPrefix = runRules(spec.event.prefix, prefix, { mode: 'tt' })
343
+ const rEventName = runRules(eventRules, eventName, { mode: 'tt' })
344
+ return {
345
+ name: rPrefix + rEventName + modifierStr,
346
+ value
347
+ }
327
348
  },
328
349
  dd ({ name, value }, { eventRules }) {
329
350
  const match = this.test.exec(name)
351
+ const prefix = match[1]
330
352
  const eventName = match[2]
331
- runRules(eventRules, eventName, { mode: 'dd' })
353
+ const modifierStr = match[3] || ''
354
+ const rPrefix = runRules(spec.event.prefix, prefix, { mode: 'dd' })
355
+ const rEventName = runRules(eventRules, eventName, { mode: 'dd' })
356
+ return {
357
+ name: rPrefix + rEventName + modifierStr,
358
+ value
359
+ }
332
360
  },
333
361
  web ({ name, value }, { eventRules, el }) {
362
+ if (parseMustache(value).hasBinding) {
363
+ error('Web environment does not support mustache binding in event props!')
364
+ return
365
+ }
334
366
  const match = this.test.exec(name)
335
367
  const prefix = match[1]
336
368
  const eventName = match[2]
@@ -30,9 +30,7 @@
30
30
  }
31
31
 
32
32
  function getVnodeKey (vnode) {
33
- if (vnode && vnode.componentOptions) {
34
- return vnode.componentOptions.Ctor.cid + (vnode.componentOptions.tag ? ('::' + (vnode.componentOptions.tag)) : '')
35
- }
33
+ return vnode.tag + (vnode.key ? `::${vnode.key}` : '')
36
34
  }
37
35
 
38
36
  export default {
@@ -44,12 +42,13 @@
44
42
  if (!isBrowser) {
45
43
  return vnode || (slot && slot[0])
46
44
  }
47
- const vnodeKey = getVnodeKey(vnode)
48
45
  const router = global.__mpxRouter
49
- if (vnodeKey && router && vnode.data.routerView) {
46
+ if (router) {
47
+ // 存在routeCount的情况下修改vnode.key避免patch时复用旧节点实例
48
+ if (router.currentRoute.query.routeCount) vnode.key = router.currentRoute.query.routeCount
49
+ const vnodeKey = getVnodeKey(vnode)
50
50
  if (router.needCache) {
51
51
  router.needCache.vnode = vnode
52
- router.needCache.vnodeKey = vnodeKey
53
52
  router.needCache = null
54
53
  }
55
54
 
@@ -69,25 +68,17 @@
69
68
 
70
69
  const stack = router.stack
71
70
  if (stack.length) {
72
- // 只要历史栈缓存中存在对应的页面存活实例,就进行复用
71
+ // 只要历史栈缓存中存在对应的页面存活实例且vnodeKey相同,就进行复用
73
72
  for (let i = stack.length; i > 0; i--) {
74
73
  const current = stack[i - 1]
75
- if (current.vnode && current.vnodeKey === vnodeKey && current.vnode.componentInstance) {
74
+ if (current.vnode && getVnodeKey(current.vnode) === vnodeKey && current.vnode.componentInstance) {
76
75
  vnode.componentInstance = current.vnode.componentInstance
77
- // 避免组件实例复用但是vnode.key不一致带来的bad case
78
- vnode.key = current.vnode.key
79
76
  break
80
77
  }
81
78
  }
82
79
  }
83
80
 
84
- if (router.__mpxAction) {
85
- if (router.__mpxAction.type === 'reLaunch') {
86
- // reLaunch时修改新vnode的key, 确保任何情况下都新创建组件实例
87
- vnode.key = (vnode.key || '') + router.__mpxAction.reLaunchCount
88
- }
89
- router.__mpxAction = null
90
- }
81
+ if (router.__mpxAction) router.__mpxAction = null
91
82
  vnode.data.keepAlive = true
92
83
  }
93
84
 
@@ -159,7 +159,7 @@ export default function processOption (
159
159
  return next({
160
160
  path: action.path,
161
161
  query: {
162
- reLaunchCount: action.reLaunchCount
162
+ routeCount: action.routeCount
163
163
  },
164
164
  replace: true
165
165
  })
@@ -878,6 +878,7 @@ function moveBaseDirective (target, from, isDelete = true) {
878
878
  }
879
879
 
880
880
  function stringify (str) {
881
+ if (mode === 'web') str = str.replace(/'/g, '"')
881
882
  return JSON.stringify(str)
882
883
  }
883
884
 
@@ -988,7 +989,7 @@ function parseFuncStr2 (str) {
988
989
  if (subIndex) {
989
990
  const index1 = ret.index + subIndex
990
991
  const index2 = index1 + 6
991
- args = args.substring(0, index1) + JSON.stringify(eventIdentifier) + args.substring(index2)
992
+ args = args.substring(0, index1) + stringify(eventIdentifier) + args.substring(index2)
992
993
  }
993
994
  }
994
995
  return {
@@ -1016,7 +1017,7 @@ function stringifyWithResolveComputed (modelValue) {
1016
1017
  computedStack.push(char)
1017
1018
  if (computedStack.length === 1) {
1018
1019
  fragment += '.'
1019
- result.push(JSON.stringify(fragment))
1020
+ result.push(stringify(fragment))
1020
1021
  fragment = ''
1021
1022
  continue
1022
1023
  }
@@ -1033,7 +1034,7 @@ function stringifyWithResolveComputed (modelValue) {
1033
1034
  fragment += char
1034
1035
  }
1035
1036
  if (fragment !== '') {
1036
- result.push(JSON.stringify(fragment))
1037
+ result.push(stringify(fragment))
1037
1038
  }
1038
1039
  return result.join('+')
1039
1040
  }
@@ -1696,7 +1697,7 @@ function processWebExternalClassesHack (el, options) {
1696
1697
  options.externalClasses.forEach((className) => {
1697
1698
  const index = classNames.indexOf(className)
1698
1699
  if (index > -1) {
1699
- replacements.push(`$attrs[${JSON.stringify(className)}]`)
1700
+ replacements.push(`$attrs[${stringify(className)}]`)
1700
1701
  classNames.splice(index, 1)
1701
1702
  }
1702
1703
  })
@@ -1730,13 +1731,13 @@ function processWebExternalClassesHack (el, options) {
1730
1731
  options.externalClasses.forEach((className) => {
1731
1732
  const index = classNames.indexOf(className)
1732
1733
  if (index > -1) {
1733
- replacements.push(`$attrs[${JSON.stringify(className)}]`)
1734
+ replacements.push(`$attrs[${stringify(className)}]`)
1734
1735
  classNames.splice(index, 1)
1735
1736
  }
1736
1737
  })
1737
1738
 
1738
1739
  if (classNames.length) {
1739
- replacements.unshift(JSON.stringify(classNames.join(' ')))
1740
+ replacements.unshift(stringify(classNames.join(' ')))
1740
1741
  }
1741
1742
 
1742
1743
  addAttrs(el, [{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.8.45",
3
+ "version": "2.8.47",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -82,5 +82,5 @@
82
82
  "engines": {
83
83
  "node": ">=14.14.0"
84
84
  },
85
- "gitHead": "b60613d3d5bfd85c7c7b28b81afbf4494c8b2c6f"
85
+ "gitHead": "9069d7f3931841a7e3acaf990464813a3b6ccb0c"
86
86
  }