Skip to content

Commit f22593b

Browse files
committed
adjust compiler
1 parent 4119b6a commit f22593b

2 files changed

Lines changed: 12 additions & 55 deletions

File tree

  • .agents/skills/mpx-development-guides
  • packages/webpack-plugin/lib/template-compiler

.agents/skills/mpx-development-guides/SKILL.md

Lines changed: 0 additions & 45 deletions
This file was deleted.

packages/webpack-plugin/lib/template-compiler/compiler.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2570,7 +2570,7 @@ function processTemplateReact (el, meta) {
25702570
}
25712571
meta.imports.push(el.attrsMap.src)
25722572
}
2573-
removeNode(el)
2573+
el.shouldRemove = true
25742574
return
25752575
}
25762576

@@ -2593,7 +2593,7 @@ function processTemplateReact (el, meta) {
25932593
}
25942594
// invalid template tag
25952595
error$1('Invalid template tag, should have valid is or name attr')
2596-
removeNode(el)
2596+
el.shouldRemove = true
25972597
}
25982598
}
25992599

@@ -2998,8 +2998,9 @@ function processMpxTagName (el) {
29982998

29992999
function processElement (el, root, options, meta) {
30003000
processAtMode(el)
3001-
// 如果已经标记了这个元素要被清除,直接return跳过后续处理步骤
30023001
if (el._matchStatus === statusEnum.MISMATCH) {
3002+
// 如果已经标记了这个元素要被清除,直接return跳过后续处理步骤
3003+
el.shouldRemove = true
30033004
return
30043005
}
30053006

@@ -3039,7 +3040,7 @@ function processElement (el, root, options, meta) {
30393040

30403041
if (isReact(mode)) {
30413042
const isTemplate = processTemplateReact(el, meta) || processingTemplate
3042-
if (el.isRemoved) return
3043+
if (el.shouldRemove) return
30433044
const isReactComponent$1 = isReactComponent(el, options)
30443045
// 收集内建组件
30453046
processBuiltInComponents(el, meta)
@@ -3090,18 +3091,19 @@ function processElement (el, root, options, meta) {
30903091
}
30913092

30923093
function closeElement (el, options, meta) {
3093-
postProcessAtMode(el)
30943094
postProcessWxs(el, meta)
30953095

30963096
if (isWeb(mode)) {
30973097
// 处理代码维度条件编译移除死分支
30983098
postProcessIf(el)
3099+
postProcessRemove(el)
30993100
return
31003101
}
31013102
if (isReact(mode)) {
31023103
postProcessForReact(el)
31033104
postProcessIfReact(el)
31043105
postProcessTemplateReact(el, meta)
3106+
postProcessRemove(el)
31053107
return
31063108
}
31073109

@@ -3130,15 +3132,16 @@ function closeElement (el, options, meta) {
31303132
postProcessIf(el)
31313133
}
31323134
postProcessTemplate(el)
3135+
postProcessRemove(el)
31333136
}
31343137

31353138
// 运行时组件的模版节点收集,最终注入到 mpx-custom-element-*.wxml 中
31363139
function collectDynamicInfo (el, options, meta) {
31373140
setBaseWxml(el, { mode, isComponentNode, options }, meta)
31383141
}
31393142

3140-
function postProcessAtMode (el) {
3141-
if (el._matchStatus === statusEnum.MISMATCH) {
3143+
function postProcessRemove (el) {
3144+
if (el.shouldRemove) {
31423145
removeNode(el)
31433146
}
31443147
}
@@ -3294,7 +3297,6 @@ function removeNode (node, reserveError) {
32943297
const index = parent.children.indexOf(node)
32953298
if (index !== -1) {
32963299
parent.children.splice(index, 1)
3297-
node.isRemoved = true
32983300
return true
32993301
}
33003302
}
@@ -3373,7 +3375,7 @@ function addIfConditionDynamic (el, condition) {
33733375
el.ifConditions.push(condition)
33743376
}
33753377

3376-
function processIfConditionsDynamic (el) {
3378+
function postProcessIfConditionsDynamic (el) {
33773379
const prevNode = findPrevNode(el)
33783380
if (prevNode && prevNode.if) {
33793381
addIfConditionDynamic(prevNode, {
@@ -3455,7 +3457,7 @@ function postProcessIfDynamic (vnode, config) {
34553457
? config.directive.elseif
34563458
: config.directive.else
34573459
getAndRemoveAttr(vnode, directive)
3458-
processIfConditionsDynamic(vnode)
3460+
postProcessIfConditionsDynamic(vnode)
34593461
delete vnode.elseif
34603462
delete vnode.else
34613463
}

0 commit comments

Comments
 (0)