@mpxjs/webpack-plugin 2.9.13 → 2.9.15
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')
|
|
@@ -170,7 +169,7 @@ class MpxWebpackPlugin {
|
|
|
170
169
|
options.webConfig = options.webConfig || {}
|
|
171
170
|
options.partialCompile = options.mode !== 'web' && options.partialCompile
|
|
172
171
|
options.asyncSubpackageRules = options.asyncSubpackageRules || []
|
|
173
|
-
options.optimizeRenderRules = options.optimizeRenderRules
|
|
172
|
+
options.optimizeRenderRules = options.optimizeRenderRules ? (Array.isArray(options.optimizeRenderRules) ? options.optimizeRenderRules : [options.optimizeRenderRules]) : []
|
|
174
173
|
options.retryRequireAsync = options.retryRequireAsync || false
|
|
175
174
|
options.enableAliRequireAsync = options.enableAliRequireAsync || false
|
|
176
175
|
options.optimizeSize = options.optimizeSize || false
|
|
@@ -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
|
|
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,32 +95,32 @@
|
|
|
95
95
|
messageCallback (event) {
|
|
96
96
|
const hostValidate = this.hostValidate(event.origin)
|
|
97
97
|
const data = event.data
|
|
98
|
-
|
|
98
|
+
let value = data.payload
|
|
99
99
|
if (!hostValidate) {
|
|
100
100
|
return
|
|
101
101
|
}
|
|
102
102
|
let asyncCallback = null
|
|
103
103
|
switch (data.type) {
|
|
104
104
|
case 'postMessage':
|
|
105
|
-
this.messageList.push(value)
|
|
105
|
+
this.messageList.push(value.data || value)
|
|
106
106
|
asyncCallback = Promise.resolve({
|
|
107
107
|
errMsg: 'invokeWebappApi:ok'
|
|
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 =
|
|
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
|
|
@@ -32,7 +32,7 @@ function checkBindThis (path) {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
// 计算访问路径
|
|
35
|
-
function
|
|
35
|
+
function getCollectPath (path) {
|
|
36
36
|
let current = path.parentPath
|
|
37
37
|
let last = path
|
|
38
38
|
let keyPath = '' + path.node.name
|
|
@@ -75,28 +75,28 @@ function checkDelAndGetPath (path) {
|
|
|
75
75
|
let replace = false
|
|
76
76
|
|
|
77
77
|
// 确定删除路径
|
|
78
|
-
while (!t.isBlockStatement(current)) {
|
|
78
|
+
while (!t.isBlockStatement(current) && !t.isProgram(current)) {
|
|
79
79
|
// case: !!a
|
|
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
|
|
94
|
-
|
|
95
|
-
|
|
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.
|
|
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
|
|
@@ -113,36 +113,50 @@ function checkDelAndGetPath (path) {
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
// 确定是否可删除
|
|
116
|
-
while (!t.isBlockStatement(current) &&
|
|
117
|
-
const { key,
|
|
118
|
-
|
|
116
|
+
while (!t.isBlockStatement(current) && !t.isProgram(current)) {
|
|
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.
|
|
124
|
+
if (t.isCallExpression(parent) && listKey === 'arguments') {
|
|
125
|
+
canDel = false
|
|
126
|
+
break
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (t.isMemberExpression(parent) && parent.computed) {
|
|
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(
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
154
|
+
if (t.isBinaryExpression(parent)) { // 运算 a + b
|
|
155
|
+
replace = true // 不能break,case: if (a + b) {}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (t.isObjectProperty(parent) && key === 'value') { // ({ name: a })
|
|
144
159
|
replace = true
|
|
145
|
-
// 不能break,case: if (a + b) {}
|
|
146
160
|
}
|
|
147
161
|
|
|
148
162
|
current = current.parentPath
|
|
@@ -158,15 +172,16 @@ function checkDelAndGetPath (path) {
|
|
|
158
172
|
|
|
159
173
|
// 判断前缀是否存在(只判断前缀,全等的情况,会返回false)
|
|
160
174
|
function checkPrefix (keys, key) {
|
|
161
|
-
for (
|
|
162
|
-
|
|
163
|
-
if (key === str) continue
|
|
164
|
-
// 确保判断当前标识是完整的单词
|
|
165
|
-
if (key.startsWith(str) && (key[str.length] === '.' || key[str.length] === '[')) return true
|
|
175
|
+
for (const item of keys) {
|
|
176
|
+
if (checkBIsPrefixOfA(key, item)) return true
|
|
166
177
|
}
|
|
167
178
|
return false
|
|
168
179
|
}
|
|
169
180
|
|
|
181
|
+
function checkBIsPrefixOfA (a, b) {
|
|
182
|
+
return a.startsWith(b) && (a[b.length] === '.' || a[b.length] === '[')
|
|
183
|
+
}
|
|
184
|
+
|
|
170
185
|
function dealRemove (path, replace) {
|
|
171
186
|
try {
|
|
172
187
|
if (replace) {
|
|
@@ -181,10 +196,75 @@ function dealRemove (path, replace) {
|
|
|
181
196
|
}
|
|
182
197
|
delete path.needBind
|
|
183
198
|
delete path.collectInfo
|
|
184
|
-
} catch (e) {
|
|
199
|
+
} catch (e) {
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function isSimpleKey (key) {
|
|
204
|
+
return !/[[.]/.test(key)
|
|
185
205
|
}
|
|
186
206
|
|
|
187
207
|
module.exports = {
|
|
208
|
+
transformSimple (code, {
|
|
209
|
+
ignoreMap = {}
|
|
210
|
+
}) {
|
|
211
|
+
const ast = babylon.parse(code, {
|
|
212
|
+
plugins: [
|
|
213
|
+
'objectRestSpread'
|
|
214
|
+
]
|
|
215
|
+
})
|
|
216
|
+
const collectKeySet = new Set()
|
|
217
|
+
const propKeySet = new Set()
|
|
218
|
+
let isProps = false
|
|
219
|
+
const visitor = {
|
|
220
|
+
// 标记收集props数据
|
|
221
|
+
CallExpression: {
|
|
222
|
+
enter (path) {
|
|
223
|
+
const callee = path.node.callee
|
|
224
|
+
if (
|
|
225
|
+
t.isMemberExpression(callee) &&
|
|
226
|
+
t.isThisExpression(callee.object) &&
|
|
227
|
+
(callee.property.name === '_p' || callee.property.value === '_p')
|
|
228
|
+
) {
|
|
229
|
+
isProps = true
|
|
230
|
+
path.isProps = true
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
exit (path) {
|
|
234
|
+
if (path.isProps) {
|
|
235
|
+
isProps = false
|
|
236
|
+
delete path.isProps
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
Identifier (path) {
|
|
241
|
+
if (
|
|
242
|
+
checkBindThis(path) &&
|
|
243
|
+
!ignoreMap[path.node.name] &&
|
|
244
|
+
!path.scope.hasBinding(path.node.name)
|
|
245
|
+
) {
|
|
246
|
+
if (isProps) {
|
|
247
|
+
propKeySet.add(path.node.name)
|
|
248
|
+
}
|
|
249
|
+
const { keyPath } = getCollectPath(path)
|
|
250
|
+
collectKeySet.add(keyPath)
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
traverse(ast, visitor)
|
|
255
|
+
const collectKeys = [...collectKeySet]
|
|
256
|
+
const pCollectKeys = collectKeys.filter((keyA) => {
|
|
257
|
+
return collectKeys.every((keyB) => {
|
|
258
|
+
return !checkBIsPrefixOfA(keyA, keyB)
|
|
259
|
+
})
|
|
260
|
+
})
|
|
261
|
+
return {
|
|
262
|
+
code: pCollectKeys.map((key) => {
|
|
263
|
+
return isSimpleKey(key) ? `_sc(${JSON.stringify(key)});` : `_c(${JSON.stringify(key)});`
|
|
264
|
+
}).join('\n'),
|
|
265
|
+
propKeys: [...propKeySet]
|
|
266
|
+
}
|
|
267
|
+
},
|
|
188
268
|
transform (code, {
|
|
189
269
|
needCollect = false,
|
|
190
270
|
renderReduce = false,
|
|
@@ -199,22 +279,25 @@ module.exports = {
|
|
|
199
279
|
let currentBlock = null
|
|
200
280
|
const bindingsMap = new Map()
|
|
201
281
|
|
|
202
|
-
const
|
|
282
|
+
const propKeySet = new Set()
|
|
203
283
|
let isProps = false
|
|
204
284
|
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
currentBlock = path
|
|
213
|
-
},
|
|
214
|
-
exit (path) {
|
|
215
|
-
currentBlock = bindingsMap.get(path).parent
|
|
216
|
-
}
|
|
285
|
+
const blockCollectVisitor = {
|
|
286
|
+
enter (path) { // 收集作用域下所有变量(keyPath)
|
|
287
|
+
bindingsMap.set(path, {
|
|
288
|
+
parent: currentBlock,
|
|
289
|
+
bindings: {}
|
|
290
|
+
})
|
|
291
|
+
currentBlock = path
|
|
217
292
|
},
|
|
293
|
+
exit (path) {
|
|
294
|
+
currentBlock = bindingsMap.get(path).parent
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const collectVisitor = {
|
|
299
|
+
Program: blockCollectVisitor,
|
|
300
|
+
BlockStatement: blockCollectVisitor,
|
|
218
301
|
Identifier (path) {
|
|
219
302
|
if (
|
|
220
303
|
checkBindThis(path) &&
|
|
@@ -234,12 +317,12 @@ module.exports = {
|
|
|
234
317
|
}
|
|
235
318
|
return
|
|
236
319
|
}
|
|
237
|
-
const { last, keyPath } = calPropName(path)
|
|
238
320
|
path.needBind = true
|
|
321
|
+
const { last, keyPath } = getCollectPath(path)
|
|
239
322
|
if (needCollect) {
|
|
240
323
|
last.collectInfo = {
|
|
241
324
|
key: t.stringLiteral(keyPath),
|
|
242
|
-
isSimple:
|
|
325
|
+
isSimple: isSimpleKey(keyPath)
|
|
243
326
|
}
|
|
244
327
|
}
|
|
245
328
|
|
|
@@ -267,18 +350,21 @@ module.exports = {
|
|
|
267
350
|
}
|
|
268
351
|
}
|
|
269
352
|
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
currentBlock = path
|
|
277
|
-
},
|
|
278
|
-
exit (path) {
|
|
279
|
-
currentBlock = bindingsMap.get(path).parent
|
|
280
|
-
}
|
|
353
|
+
const blockBindVisitor = {
|
|
354
|
+
enter (path) {
|
|
355
|
+
const scope = bindingsMap.get(path)
|
|
356
|
+
const parentScope = bindingsMap.get(scope.parent)
|
|
357
|
+
scope.pBindings = parentScope ? Object.assign({}, parentScope.bindings, parentScope.pBindings) : {}
|
|
358
|
+
currentBlock = path
|
|
281
359
|
},
|
|
360
|
+
exit (path) {
|
|
361
|
+
currentBlock = bindingsMap.get(path).parent
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
const bindVisitor = {
|
|
366
|
+
Program: blockBindVisitor,
|
|
367
|
+
BlockStatement: blockBindVisitor,
|
|
282
368
|
// 标记收集props数据
|
|
283
369
|
CallExpression: {
|
|
284
370
|
enter (path) {
|
|
@@ -336,7 +422,7 @@ module.exports = {
|
|
|
336
422
|
const name = path.node.name
|
|
337
423
|
if (name) { // 确保path没有被删除 且 没有被替换成字符串
|
|
338
424
|
if (isProps) {
|
|
339
|
-
|
|
425
|
+
propKeySet.add(name)
|
|
340
426
|
}
|
|
341
427
|
path.replaceWith(t.memberExpression(t.thisExpression(), path.node))
|
|
342
428
|
}
|
|
@@ -359,11 +445,11 @@ module.exports = {
|
|
|
359
445
|
}
|
|
360
446
|
|
|
361
447
|
traverse(ast, collectVisitor)
|
|
362
|
-
traverse(ast,
|
|
448
|
+
traverse(ast, bindVisitor)
|
|
363
449
|
|
|
364
450
|
return {
|
|
365
451
|
code: generate(ast).code,
|
|
366
|
-
propKeys
|
|
452
|
+
propKeys: [...propKeySet]
|
|
367
453
|
}
|
|
368
454
|
}
|
|
369
455
|
}
|
|
@@ -1933,12 +1933,17 @@ function postProcessTemplate (el) {
|
|
|
1933
1933
|
|
|
1934
1934
|
const isValidMode = makeMap('wx,ali,swan,tt,qq,web,qa,jd,dd,tenon,noMode')
|
|
1935
1935
|
|
|
1936
|
+
function isValidModeP (i) {
|
|
1937
|
+
return isValidMode(i[0] === '_' ? i.slice(1) : i)
|
|
1938
|
+
}
|
|
1939
|
+
|
|
1936
1940
|
const wrapRE = /^\((.*)\)$/
|
|
1937
1941
|
|
|
1938
1942
|
function processAtMode (el) {
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1943
|
+
// 父节点的atMode匹配状态不应该影响子节点,atMode的影响范围应该限制在当前节点本身
|
|
1944
|
+
// if (el.parent && el.parent._atModeStatus) {
|
|
1945
|
+
// el._atModeStatus = el.parent._atModeStatus
|
|
1946
|
+
// }
|
|
1942
1947
|
|
|
1943
1948
|
const attrsListClone = cloneAttrsList(el.attrsList)
|
|
1944
1949
|
attrsListClone.forEach(item => {
|
|
@@ -1972,24 +1977,31 @@ function processAtMode (el) {
|
|
|
1972
1977
|
|
|
1973
1978
|
const modeArr = [...conditionMap.keys()]
|
|
1974
1979
|
|
|
1975
|
-
if (modeArr.every(i =>
|
|
1980
|
+
if (modeArr.every(i => isValidModeP(i))) {
|
|
1976
1981
|
const attrValue = getAndRemoveAttr(el, attrName).val
|
|
1977
1982
|
const replacedAttrName = attrArr.join('@')
|
|
1978
1983
|
const processedAttr = { name: replacedAttrName, value: attrValue }
|
|
1979
1984
|
|
|
1980
|
-
for (
|
|
1985
|
+
for (let [defineMode, defineEnvArr] of conditionMap.entries()) {
|
|
1986
|
+
const isImplicitMode = defineMode[0] === '_'
|
|
1987
|
+
if (isImplicitMode) defineMode = defineMode.slice(1)
|
|
1981
1988
|
if (defineMode === 'noMode' || defineMode === mode) {
|
|
1982
1989
|
// 命中 env 规则(没有定义env 或者定义的envArr包含当前env)
|
|
1983
1990
|
if (!defineEnvArr.length || defineEnvArr.includes(env)) {
|
|
1984
|
-
el._atModeStatus = ''
|
|
1985
1991
|
if (!replacedAttrName) {
|
|
1986
|
-
|
|
1987
|
-
|
|
1992
|
+
if (defineMode === 'noMode' || isImplicitMode) {
|
|
1993
|
+
// 若defineMode 为 noMode 或 implicitMode,则 element 都需要进行规则转换
|
|
1994
|
+
} else {
|
|
1988
1995
|
el._atModeStatus = 'match'
|
|
1989
1996
|
}
|
|
1990
1997
|
} else {
|
|
1991
|
-
|
|
1992
|
-
|
|
1998
|
+
if (defineMode === 'noMode' || isImplicitMode) {
|
|
1999
|
+
// 若defineMode 为 noMode 或 implicitMode,则直接将 attr 挂载回 el,进行规则转换
|
|
2000
|
+
addAttrs(el, [processedAttr])
|
|
2001
|
+
} else {
|
|
2002
|
+
// 如果命中了指定的mode,且当前 mode 不为 noMode 或 implicitMode,则把不需要转换的 attrs 暂存在 noTransAttrs 上,等规则转换后再挂载回去
|
|
2003
|
+
el.noTransAttrs ? el.noTransAttrs.push(processedAttr) : el.noTransAttrs = [processedAttr]
|
|
2004
|
+
}
|
|
1993
2005
|
}
|
|
1994
2006
|
// 命中mode,命中env,完成匹配,直接退出
|
|
1995
2007
|
break
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const compiler = require('./compiler')
|
|
2
|
-
const bindThis = require('./bind-this')
|
|
2
|
+
const bindThis = require('./bind-this')
|
|
3
3
|
const parseRequest = require('../utils/parse-request')
|
|
4
4
|
const { matchCondition } = require('../utils/match-condition')
|
|
5
5
|
const loaderUtils = require('loader-utils')
|
|
@@ -29,6 +29,13 @@ module.exports = function (raw) {
|
|
|
29
29
|
const hasScoped = queryObj.hasScoped
|
|
30
30
|
const moduleId = queryObj.moduleId || 'm' + mpx.pathHash(resourcePath)
|
|
31
31
|
|
|
32
|
+
let optimizeRenderLevel = 0
|
|
33
|
+
for (const rule of optimizeRenderRules) {
|
|
34
|
+
if (matchCondition(resourcePath, rule)) {
|
|
35
|
+
optimizeRenderLevel = rule.level || 1
|
|
36
|
+
break
|
|
37
|
+
}
|
|
38
|
+
}
|
|
32
39
|
const warn = (msg) => {
|
|
33
40
|
this.emitWarning(
|
|
34
41
|
new Error('[template compiler][' + this.resource + ']: ' + msg)
|
|
@@ -93,22 +100,27 @@ global.currentInject = {
|
|
|
93
100
|
|
|
94
101
|
const rawCode = compiler.genNode(ast)
|
|
95
102
|
if (rawCode) {
|
|
96
|
-
|
|
103
|
+
try {
|
|
104
|
+
const ignoreMap = Object.assign({
|
|
105
|
+
_i: true,
|
|
106
|
+
_c: true,
|
|
107
|
+
_sc: true,
|
|
108
|
+
_r: true
|
|
109
|
+
}, meta.wxsModuleMap)
|
|
110
|
+
const bindResult = optimizeRenderLevel === 2
|
|
111
|
+
? bindThis.transformSimple(rawCode, {
|
|
112
|
+
ignoreMap
|
|
113
|
+
})
|
|
114
|
+
: bindThis.transform(rawCode, {
|
|
115
|
+
needCollect: true,
|
|
116
|
+
renderReduce: optimizeRenderLevel === 1,
|
|
117
|
+
ignoreMap
|
|
118
|
+
})
|
|
119
|
+
resultSource += `
|
|
97
120
|
global.currentInject.render = function (_i, _c, _r, _sc) {
|
|
98
|
-
${
|
|
99
|
-
_r();
|
|
121
|
+
${bindResult.code}
|
|
122
|
+
_r(${optimizeRenderLevel === 2 ? 'true' : ''});
|
|
100
123
|
};\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
124
|
if ((mode === 'tt' || mode === 'swan') && bindResult.propKeys) {
|
|
113
125
|
resultSource += `global.currentInject.propKeys = ${JSON.stringify(bindResult.propKeys)};\n`
|
|
114
126
|
}
|
|
@@ -118,7 +130,7 @@ Invalid render function generated by the template, please check!\n
|
|
|
118
130
|
Template result:
|
|
119
131
|
${result}\n
|
|
120
132
|
Error code:
|
|
121
|
-
${
|
|
133
|
+
${rawCode}
|
|
122
134
|
Error Detail:
|
|
123
135
|
${e.stack}`)
|
|
124
136
|
return result
|
|
@@ -126,7 +138,7 @@ ${e.stack}`)
|
|
|
126
138
|
}
|
|
127
139
|
|
|
128
140
|
if (meta.computed) {
|
|
129
|
-
resultSource += bindThis(`
|
|
141
|
+
resultSource += bindThis.transform(`
|
|
130
142
|
global.currentInject.injectComputed = {
|
|
131
143
|
${meta.computed.join(',')}
|
|
132
144
|
};`).code + '\n'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.15",
|
|
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": "
|
|
86
|
+
"gitHead": "f3dcf3425dc3e0ad2378b2f35ca020aa9cdd1fb2"
|
|
87
87
|
}
|