Skip to content

Commit

Permalink
完善 ignore语义
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuzhh committed Dec 17, 2023
1 parent b94c798 commit 57efaeb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/webpack-plugin/lib/template-compiler/bind-this.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ module.exports = {
let isProps = false

const cacheIgnore = new Map()

// 把ignore的数据过滤出来
function filterIgnoreKey (bindings) {
if (cacheIgnore.has(bindings)) return cacheIgnore.get(bindings)
Expand Down Expand Up @@ -333,7 +332,7 @@ module.exports = {
delete path.delInfo

if (canDel) {
if (isLocal || ignore) { // 局部作用域或可忽略的变量,可直接删除
if (isLocal) { // 局部作用域里的变量,可直接删除
dealRemove(path, replace)
return
}
Expand All @@ -348,11 +347,15 @@ module.exports = {
if (checkPrefix(Object.keys(allBindings), keyPath) || pBindings[keyPath]) {
dealRemove(path, replace)
} else {
const currentBlockVars = bindings[keyPath] || [] // bindings[keyPath] 全是ignore,所以需要兜底一下
const currentBlockVars = bindings[keyPath] || [] // 避免bindings[keyPath] 全是ignore,所以需要兜底一下
if (currentBlockVars.length > 1) {
const index = currentBlockVars.findIndex(item => !item.canDel)
if (index !== -1 || currentBlockVars[0].path !== path) { // 当前block中存在不可删除的变量 || 不是第一个可删除变量,即可删除该变量
if (ignore) {
dealRemove(path, replace)
} else {
const index = currentBlockVars.findIndex(item => !item.canDel)
if (index !== -1 || currentBlockVars[0].path !== path) { // 当前block中存在不可删除的变量 || 不是第一个可删除变量,即可删除该变量
dealRemove(path, replace)
}
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions packages/webpack-plugin/test/platform/common/bind-this.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ global.currentInject.render = function (_i, _c, _r, _sc) {
if (a5 && b5) {}
if (a5 ? b5 : c5) {}
a6 ? b6 : c6 // b6 c6只出现一次,不会被删除
b7
a7 ? b7.name : c7
obj8
obj8 + 'rpx'
'height:' + obj8 + 'rpx'
Expand Down Expand Up @@ -225,6 +230,11 @@ global.currentInject.render = function (_i, _c, _r, _sc) {
if (_sc("a5") && _sc("b5")) {}
if (_sc("a5") ? _sc("b5") : _sc("c5")) {}
_sc("a6") ? _sc("b6") : _sc("c6"); // b6 c6只出现一次,不会被删除
_sc("b7");
_sc("a7") ? "" : _sc("c7");
_sc("obj8");
"" + 'rpx';
Expand Down

0 comments on commit 57efaeb

Please sign in to comment.