@mpxjs/webpack-plugin 2.8.59 → 2.8.60

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.
package/lib/index.js CHANGED
@@ -125,7 +125,6 @@ class MpxWebpackPlugin {
125
125
  options.resolveMode = options.resolveMode || 'webpack'
126
126
  options.writeMode = options.writeMode || 'changed'
127
127
  options.autoScopeRules = options.autoScopeRules || {}
128
- options.renderOptimizeRules = options.renderOptimizeRules || {}
129
128
  options.autoVirtualHostRules = options.autoVirtualHostRules || {}
130
129
  options.forceDisableProxyCtor = options.forceDisableProxyCtor || false
131
130
  options.transMpxRules = options.transMpxRules || {
@@ -169,7 +168,8 @@ class MpxWebpackPlugin {
169
168
  }, options.nativeConfig)
170
169
  options.webConfig = options.webConfig || {}
171
170
  options.partialCompile = options.mode !== 'web' && options.partialCompile
172
- options.asyncSubpackageRules = options.asyncSubpackageRules || null
171
+ options.asyncSubpackageRules = options.asyncSubpackageRules || []
172
+ options.optimizeRenderRules = options.optimizeRenderRules || {}
173
173
  options.retryRequireAsync = options.retryRequireAsync || false
174
174
  options.enableAliRequireAsync = options.enableAliRequireAsync || false
175
175
  options.optimizeSize = options.optimizeSize || false
@@ -633,13 +633,13 @@ class MpxWebpackPlugin {
633
633
  appTitle: 'Mpx homepage',
634
634
  attributes: this.options.attributes,
635
635
  externals: this.options.externals,
636
- renderOptimizeRules: this.options.renderOptimizeRules,
637
636
  useRelativePath: this.options.useRelativePath,
638
637
  removedChunks: [],
639
638
  forceProxyEventRules: this.options.forceProxyEventRules,
640
639
  enableRequireAsync: this.options.mode === 'wx' || (this.options.mode === 'ali' && this.options.enableAliRequireAsync),
641
640
  partialCompile: this.options.partialCompile,
642
641
  asyncSubpackageRules: this.options.asyncSubpackageRules,
642
+ optimizeRenderRules: this.options.optimizeRenderRules,
643
643
  pathHash: (resourcePath) => {
644
644
  if (this.options.pathHashMode === 'relative' && this.options.projectRoot) {
645
645
  return hash(path.relative(this.options.projectRoot, resourcePath))
@@ -85,7 +85,7 @@ function checkDelAndGetPath (path) {
85
85
  if (args.length === 1) {
86
86
  delPath = current.parentPath
87
87
  } else {
88
- // case: this._i(a, function() {})
88
+ // case: _i(a, function() {})
89
89
  canDel = false
90
90
  break
91
91
  }
@@ -169,7 +169,10 @@ function dealRemove (path, replace) {
169
169
  t.validate(path, path.key, null)
170
170
  path.remove()
171
171
  }
172
- } catch (e) {}
172
+ delete path.needBind
173
+ delete path.collectPath
174
+ } catch (e) {
175
+ }
173
176
  }
174
177
 
175
178
  module.exports = {
@@ -305,14 +308,12 @@ module.exports = {
305
308
  // 优先判断前缀,再判断全等
306
309
  if (checkPrefix(Object.keys(allBindings), keyPath) || pBindings[keyPath]) {
307
310
  dealRemove(path, replace)
308
- return
309
311
  } else {
310
312
  const currentBlockVars = bindings[keyPath]
311
313
  if (currentBlockVars.length > 1) {
312
314
  const index = currentBlockVars.findIndex(item => !item.canDel)
313
315
  if (index !== -1 || currentBlockVars[0].path !== path) { // 当前block中存在不可删除的变量 || 不是第一个可删除变量,即可删除该变量
314
316
  dealRemove(path, replace)
315
- return
316
317
  }
317
318
  }
318
319
  }
@@ -334,7 +335,10 @@ module.exports = {
334
335
  MemberExpression: {
335
336
  exit (path) {
336
337
  if (path.collectPath) {
337
- path.node && path.replaceWith(t.callExpression(t.memberExpression(t.thisExpression(), t.identifier('_c')), [path.collectPath, path.node]))
338
+ const replaceNode = renderReduce
339
+ ? t.callExpression(t.identifier('_c'), [path.collectPath])
340
+ : t.callExpression(t.identifier('_c'), [path.collectPath, path.node])
341
+ path.node && path.replaceWith(replaceNode)
338
342
  delete path.collectPath
339
343
  }
340
344
  }
@@ -1091,6 +1091,7 @@ function processBindEvent (el, options) {
1091
1091
  for (const type in eventConfigMap) {
1092
1092
  let needBind = false
1093
1093
  let { configs, rawName, proxy } = eventConfigMap[type]
1094
+ delete eventConfigMap[type]
1094
1095
  if (proxy) {
1095
1096
  needBind = true
1096
1097
  } else if (configs.length > 1) {
@@ -1098,11 +1099,14 @@ function processBindEvent (el, options) {
1098
1099
  } else if (configs.length === 1) {
1099
1100
  needBind = !!configs[0].hasArgs
1100
1101
  }
1102
+
1103
+ const escapedType = dash2hump(type)
1101
1104
  // 排除特殊情况
1102
- if (needBind && !isValidIdentifierStr(type)) {
1105
+ if (!isValidIdentifierStr(escapedType)) {
1103
1106
  warn$1(`EventName ${type} which need be framework proxy processed must be a valid identifier!`)
1104
1107
  needBind = false
1105
1108
  }
1109
+
1106
1110
  if (needBind) {
1107
1111
  if (rawName) {
1108
1112
  // 清空原始事件绑定
@@ -1120,11 +1124,9 @@ function processBindEvent (el, options) {
1120
1124
  value: '__invoke'
1121
1125
  }
1122
1126
  ])
1123
- eventConfigMap[type] = configs.map((item) => {
1127
+ eventConfigMap[escapedType] = configs.map((item) => {
1124
1128
  return item.expStr
1125
1129
  })
1126
- } else {
1127
- delete eventConfigMap[type]
1128
1130
  }
1129
1131
  }
1130
1132
 
@@ -2321,7 +2323,7 @@ function genFor (node) {
2321
2323
  node.forProcessed = true
2322
2324
  const index = node.for.index || 'index'
2323
2325
  const item = node.for.item || 'item'
2324
- return `this._i(${node.for.exp}, function(${item},${index}){\n${genNode(node)}});\n`
2326
+ return `_i(${node.for.exp}, function(${item},${index}){\n${genNode(node)}});\n`
2325
2327
  }
2326
2328
 
2327
2329
  function genNode (node) {
@@ -21,7 +21,7 @@ module.exports = function (raw) {
21
21
  const componentsMap = mpx.componentsMap[packageName]
22
22
  const pagesMap = mpx.pagesMap
23
23
  const wxsContentMap = mpx.wxsContentMap
24
- const renderOptimizeRules = mpx.renderOptimizeRules
24
+ const optimizeRenderRules = mpx.optimizeRenderRules
25
25
  const usingComponents = queryObj.usingComponents || []
26
26
  const componentPlaceholder = queryObj.componentPlaceholder || []
27
27
  const hasComment = queryObj.hasComment
@@ -86,39 +86,43 @@ module.exports = function (raw) {
86
86
  return result
87
87
  }
88
88
 
89
- const rawCode = `
89
+ resultSource += `
90
90
  global.currentInject = {
91
- moduleId: ${JSON.stringify(moduleId)},
92
- render: function () {
93
- ${compiler.genNode(ast)}
94
- this._r();
95
- }
91
+ moduleId: ${JSON.stringify(moduleId)}
96
92
  };\n`
97
93
 
98
- let bindResult
99
-
100
- try {
101
- bindResult = bindThis(rawCode, {
102
- needCollect: true,
103
- renderReduce: matchCondition(resourcePath, renderOptimizeRules),
104
- ignoreMap: meta.wxsModuleMap
105
- })
106
- } catch (e) {
107
- error(`
94
+ const rawCode = compiler.genNode(ast)
95
+ if (rawCode) {
96
+ const renderCode = `
97
+ global.currentInject.render = function (_i, _c, _r) {
98
+ ${rawCode}
99
+ _r();
100
+ };\n`
101
+ try {
102
+ const bindResult = bindThis(renderCode, {
103
+ needCollect: true,
104
+ renderReduce: matchCondition(resourcePath, optimizeRenderRules),
105
+ ignoreMap: Object.assign({
106
+ _i: true,
107
+ _c: true,
108
+ _r: true
109
+ }, meta.wxsModuleMap)
110
+ })
111
+ resultSource += bindResult.code
112
+ if ((mode === 'tt' || mode === 'swan') && bindResult.propKeys) {
113
+ resultSource += `global.currentInject.propKeys = ${JSON.stringify(bindResult.propKeys)};\n`
114
+ }
115
+ } catch (e) {
116
+ error(`
108
117
  Invalid render function generated by the template, please check!\n
109
118
  Template result:
110
119
  ${result}\n
111
120
  Error code:
112
- ${rawCode}
121
+ ${renderCode}
113
122
  Error Detail:
114
123
  ${e.stack}`)
115
- return result
116
- }
117
-
118
- resultSource += bindResult.code + '\n'
119
-
120
- if ((mode === 'tt' || mode === 'swan') && bindResult.propKeys) {
121
- resultSource += `global.currentInject.propKeys = ${JSON.stringify(bindResult.propKeys)};\n`
124
+ return result
125
+ }
122
126
  }
123
127
 
124
128
  if (meta.computed) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.8.59",
3
+ "version": "2.8.60",
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": "4e014ea355bb2d659c6fd6a3040b6b88245da9e5"
85
+ "gitHead": "02a77bf602744c35703b2fdc27171edbec09edcb"
86
86
  }