@mpxjs/webpack-plugin 2.9.13 → 2.9.14

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
@@ -9,7 +9,6 @@ const NullFactory = require('webpack/lib/NullFactory')
9
9
  const CommonJsVariableDependency = require('./dependencies/CommonJsVariableDependency')
10
10
  const CommonJsAsyncDependency = require('./dependencies/CommonJsAsyncDependency')
11
11
  const CommonJsExtractDependency = require('./dependencies/CommonJsExtractDependency')
12
- const harmonySpecifierTag = require('webpack/lib/dependencies/HarmonyImportDependencyParserPlugin').harmonySpecifierTag
13
12
  const NormalModule = require('webpack/lib/NormalModule')
14
13
  const EntryPlugin = require('webpack/lib/EntryPlugin')
15
14
  const JavascriptModulesPlugin = require('webpack/lib/javascript/JavascriptModulesPlugin')
@@ -1331,58 +1330,6 @@ class MpxWebpackPlugin {
1331
1330
  })
1332
1331
  }
1333
1332
  }
1334
-
1335
- // 为跨平台api调用注入srcMode参数指导api运行时转换
1336
- const apiBlackListMap = [
1337
- 'createApp',
1338
- 'createPage',
1339
- 'createComponent',
1340
- 'createStore',
1341
- 'createStoreWithThis',
1342
- 'mixin',
1343
- 'injectMixins',
1344
- 'toPureObject',
1345
- 'observable',
1346
- 'watch',
1347
- 'use',
1348
- 'set',
1349
- 'remove',
1350
- 'delete',
1351
- 'setConvertRule',
1352
- 'getMixin',
1353
- 'getComputed',
1354
- 'implement'
1355
- ].reduce((map, api) => {
1356
- map[api] = true
1357
- return map
1358
- }, {})
1359
-
1360
- const injectSrcModeForTransApi = (expr, members) => {
1361
- // members为空数组时,callee并不是memberExpression
1362
- if (!members.length) return
1363
- const callee = expr.callee
1364
- const args = expr.arguments
1365
- const name = callee.object.name
1366
- const { queryObj, resourcePath } = parseRequest(parser.state.module.resource)
1367
- const localSrcMode = queryObj.mode
1368
- const globalSrcMode = mpx.srcMode
1369
- const srcMode = localSrcMode || globalSrcMode
1370
-
1371
- if (srcMode === globalSrcMode || apiBlackListMap[callee.property.name || callee.property.value] || (name !== 'mpx' && name !== 'wx') || (name === 'wx' && !matchCondition(resourcePath, this.options.transMpxRules))) return
1372
-
1373
- const srcModeString = `__mpx_src_mode_${srcMode}__`
1374
- const dep = new InjectDependency({
1375
- content: args.length
1376
- ? `, ${JSON.stringify(srcModeString)}`
1377
- : JSON.stringify(srcModeString),
1378
- index: expr.end - 1
1379
- })
1380
- parser.state.current.addPresentationalDependency(dep)
1381
- }
1382
-
1383
- parser.hooks.callMemberChain.for(harmonySpecifierTag).tap('MpxWebpackPlugin', injectSrcModeForTransApi)
1384
- parser.hooks.callMemberChain.for('mpx').tap('MpxWebpackPlugin', injectSrcModeForTransApi)
1385
- parser.hooks.callMemberChain.for('wx').tap('MpxWebpackPlugin', injectSrcModeForTransApi)
1386
1333
  }
1387
1334
  }
1388
1335
  normalModuleFactory.hooks.parser.for('javascript/auto').tap('MpxWebpackPlugin', normalModuleFactoryParserCallback)
@@ -4,8 +4,8 @@
4
4
 
5
5
  <script>
6
6
  import { getCustomEvent } from './getInnerListeners'
7
- import { redirectTo, navigateTo, navigateBack, reLaunch, switchTab } from '@mpxjs/api-proxy/src/web/api/index'
8
-
7
+ import { promisify, redirectTo, navigateTo, navigateBack, reLaunch, switchTab } from '@mpxjs/api-proxy'
8
+ const navObj = promisify({ redirectTo, navigateTo, navigateBack, reLaunch, switchTab })
9
9
  const eventLoad = 'load'
10
10
  const eventError = 'error'
11
11
  const eventMessage = 'message'
@@ -95,7 +95,7 @@
95
95
  messageCallback (event) {
96
96
  const hostValidate = this.hostValidate(event.origin)
97
97
  const data = event.data
98
- const value = data.payload
98
+ let value = data.payload
99
99
  if (!hostValidate) {
100
100
  return
101
101
  }
@@ -108,19 +108,19 @@
108
108
  })
109
109
  break
110
110
  case 'navigateTo':
111
- asyncCallback = navigateTo(value)
111
+ asyncCallback = navObj.navigateTo(value)
112
112
  break
113
113
  case 'navigateBack':
114
- asyncCallback = value ? navigateBack(value) : navigateBack()
114
+ asyncCallback = navObj.navigateBack(value)
115
115
  break
116
116
  case 'redirectTo':
117
- asyncCallback = redirectTo(value)
117
+ asyncCallback = navObj.redirectTo(value)
118
118
  break
119
119
  case 'switchTab':
120
- asyncCallback = switchTab(value)
120
+ asyncCallback = navObj.switchTab(value)
121
121
  break
122
122
  case 'reLaunch':
123
- asyncCallback = reLaunch(value)
123
+ asyncCallback = navObj.reLaunch(value)
124
124
  break
125
125
  case 'getLocation':
126
126
  const getLocation = mpx.config.webviewConfig.apiImplementations && mpx.config.webviewConfig.apiImplementations.getLocation
@@ -80,23 +80,23 @@ function checkDelAndGetPath (path) {
80
80
  if (t.isUnaryExpression(current.parent) && current.key === 'argument') {
81
81
  delPath = current.parentPath
82
82
  } else if (t.isCallExpression(current.parent)) {
83
- // case: String(a) || this._p(a)
84
83
  const args = current.node.arguments || current.parent.arguments || []
85
- if (args.length === 1) {
84
+ if (args.length === 1) { // case: String(a) || this._p(a)
86
85
  delPath = current.parentPath
87
86
  } else {
88
- // case: _i(a, function() {})
89
- canDel = false
90
87
  break
91
88
  }
92
89
  } else if (t.isMemberExpression(current.parent)) { // case: String(a,'123').b.c
93
- if (current.parent.computed && !t.isLiteral(current.parent.property)) { // case: a[b] or a.b[c.d]
94
- canDel = false
95
- break
90
+ if (current.parent.computed) { // case: a['b'] or a.b['c.d']
91
+ if (t.isLiteral(current.parent.property)) {
92
+ delPath = current.parentPath
93
+ } else { // case: a[b]
94
+ break
95
+ }
96
96
  } else {
97
97
  delPath = current.parentPath
98
98
  }
99
- } else if (t.isLogicalExpression(current.container)) { // 只处理case: a || '' or '123' || a
99
+ } else if (t.isLogicalExpression(current.parent)) { // 只处理case: a || '' or '123' || a
100
100
  const key = current.key === 'left' ? 'right' : 'left'
101
101
  if (t.isLiteral(current.parent[key])) {
102
102
  delPath = current.parentPath
@@ -114,35 +114,49 @@ function checkDelAndGetPath (path) {
114
114
 
115
115
  // 确定是否可删除
116
116
  while (!t.isBlockStatement(current) && canDel) {
117
- const { key, container } = current
118
- if (t.isIfStatement(container) && key === 'test') { // if (a) {}
117
+ const { key, listKey, parent } = current
118
+
119
+ if (t.isIfStatement(parent) && key === 'test') {
119
120
  canDel = false
120
121
  break
121
122
  }
122
123
 
123
- if (t.isLogicalExpression(container)) { // case: a || ((b || c) && d)
124
+ if (listKey === 'arguments' && t.isCallExpression(parent)) {
125
+ canDel = false
126
+ break
127
+ }
128
+
129
+ if (parent.computed && t.isMemberExpression(parent)) {
130
+ if (key === 'property') {
131
+ replace = true
132
+ } else {
133
+ canDel = false
134
+ break
135
+ }
136
+ }
137
+
138
+ if (t.isLogicalExpression(parent)) { // case: a || ((b || c) && d)
124
139
  canDel = false
125
140
  ignore = true
126
141
  break
127
142
  }
128
143
 
129
- if (t.isConditionalExpression(container)) {
144
+ if (t.isConditionalExpression(parent)) {
130
145
  if (key === 'test') {
131
146
  canDel = false
132
147
  break
133
148
  } else {
134
149
  ignore = true
135
- replace = true
150
+ replace = true // 继续往上找,判断是否存在if条件等
136
151
  }
137
152
  }
138
153
 
139
- if (
140
- t.isBinaryExpression(container) || // 运算 a + b
141
- (key === 'value' && t.isObjectProperty(container) && canDel) // ({ name: a })
142
- ) {
143
- canDel = true
154
+ if (t.isBinaryExpression(parent)) { // 运算 a + b
155
+ replace = true // 不能break,case: if (a + b) {}
156
+ }
157
+
158
+ if (key === 'value' && t.isObjectProperty(parent)) { // ({ name: a })
144
159
  replace = true
145
- // 不能break,case: if (a + b) {}
146
160
  }
147
161
 
148
162
  current = current.parentPath
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.9.13",
3
+ "version": "2.9.14",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -83,5 +83,5 @@
83
83
  "engines": {
84
84
  "node": ">=14.14.0"
85
85
  },
86
- "gitHead": "2c67b32fe01ff15fc1b728f91b4b5652244c2f35"
86
+ "gitHead": "e8ab845a544d2db0619a6a7d6c04d9d384d1a6ca"
87
87
  }