fix(compiler-core): template v-if should never be treated as dev root fragment
close #5189
This commit is contained in:
		
							parent
							
								
									b7025d24f1
								
							
						
					
					
						commit
						51f3d386de
					
				@ -16,7 +16,7 @@ return function render(_ctx, _cache) {
 | 
				
			|||||||
        ? (_openBlock(), _createElementBlock(\\"div\\", { key: 0 }, \\"yes\\"))
 | 
					        ? (_openBlock(), _createElementBlock(\\"div\\", { key: 0 }, \\"yes\\"))
 | 
				
			||||||
        : (_openBlock(), _createElementBlock(_Fragment, { key: 1 }, [
 | 
					        : (_openBlock(), _createElementBlock(_Fragment, { key: 1 }, [
 | 
				
			||||||
            _createTextVNode(\\"no\\")
 | 
					            _createTextVNode(\\"no\\")
 | 
				
			||||||
          ], 2112 /* STABLE_FRAGMENT, DEV_ROOT_FRAGMENT */)),
 | 
					          ], 64 /* STABLE_FRAGMENT */)),
 | 
				
			||||||
      (_openBlock(true), _createElementBlock(_Fragment, null, _renderList(list, (value, index) => {
 | 
					      (_openBlock(true), _createElementBlock(_Fragment, null, _renderList(list, (value, index) => {
 | 
				
			||||||
        return (_openBlock(), _createElementBlock(\\"div\\", null, [
 | 
					        return (_openBlock(), _createElementBlock(\\"div\\", null, [
 | 
				
			||||||
          _createElementVNode(\\"span\\", null, _toDisplayString(value + index), 1 /* TEXT */)
 | 
					          _createElementVNode(\\"span\\", null, _toDisplayString(value + index), 1 /* TEXT */)
 | 
				
			||||||
@ -40,7 +40,7 @@ return function render(_ctx, _cache) {
 | 
				
			|||||||
      ? (_openBlock(), _createElementBlock(\\"div\\", { key: 0 }, \\"yes\\"))
 | 
					      ? (_openBlock(), _createElementBlock(\\"div\\", { key: 0 }, \\"yes\\"))
 | 
				
			||||||
      : (_openBlock(), _createElementBlock(_Fragment, { key: 1 }, [
 | 
					      : (_openBlock(), _createElementBlock(_Fragment, { key: 1 }, [
 | 
				
			||||||
          _createTextVNode(\\"no\\")
 | 
					          _createTextVNode(\\"no\\")
 | 
				
			||||||
        ], 2112 /* STABLE_FRAGMENT, DEV_ROOT_FRAGMENT */)),
 | 
					        ], 64 /* STABLE_FRAGMENT */)),
 | 
				
			||||||
    (_openBlock(true), _createElementBlock(_Fragment, null, _renderList(_ctx.list, (value, index) => {
 | 
					    (_openBlock(true), _createElementBlock(_Fragment, null, _renderList(_ctx.list, (value, index) => {
 | 
				
			||||||
      return (_openBlock(), _createElementBlock(\\"div\\", null, [
 | 
					      return (_openBlock(), _createElementBlock(\\"div\\", null, [
 | 
				
			||||||
        _createElementVNode(\\"span\\", null, _toDisplayString(value + index), 1 /* TEXT */)
 | 
					        _createElementVNode(\\"span\\", null, _toDisplayString(value + index), 1 /* TEXT */)
 | 
				
			||||||
@ -63,7 +63,7 @@ export function render(_ctx, _cache) {
 | 
				
			|||||||
      ? (_openBlock(), _createElementBlock(\\"div\\", { key: 0 }, \\"yes\\"))
 | 
					      ? (_openBlock(), _createElementBlock(\\"div\\", { key: 0 }, \\"yes\\"))
 | 
				
			||||||
      : (_openBlock(), _createElementBlock(_Fragment, { key: 1 }, [
 | 
					      : (_openBlock(), _createElementBlock(_Fragment, { key: 1 }, [
 | 
				
			||||||
          _createTextVNode(\\"no\\")
 | 
					          _createTextVNode(\\"no\\")
 | 
				
			||||||
        ], 2112 /* STABLE_FRAGMENT, DEV_ROOT_FRAGMENT */)),
 | 
					        ], 64 /* STABLE_FRAGMENT */)),
 | 
				
			||||||
    (_openBlock(true), _createElementBlock(_Fragment, null, _renderList(_ctx.list, (value, index) => {
 | 
					    (_openBlock(true), _createElementBlock(_Fragment, null, _renderList(_ctx.list, (value, index) => {
 | 
				
			||||||
      return (_openBlock(), _createElementBlock(\\"div\\", null, [
 | 
					      return (_openBlock(), _createElementBlock(\\"div\\", null, [
 | 
				
			||||||
        _createElementVNode(\\"span\\", null, _toDisplayString(value + index), 1 /* TEXT */)
 | 
					        _createElementVNode(\\"span\\", null, _toDisplayString(value + index), 1 /* TEXT */)
 | 
				
			||||||
 | 
				
			|||||||
@ -111,7 +111,7 @@ return function render(_ctx, _cache) {
 | 
				
			|||||||
      ? (_openBlock(), _createElementBlock(\\"div\\", { key: 0 }))
 | 
					      ? (_openBlock(), _createElementBlock(\\"div\\", { key: 0 }))
 | 
				
			||||||
      : orNot
 | 
					      : orNot
 | 
				
			||||||
        ? (_openBlock(), _createElementBlock(\\"p\\", { key: 1 }))
 | 
					        ? (_openBlock(), _createElementBlock(\\"p\\", { key: 1 }))
 | 
				
			||||||
        : (_openBlock(), _createElementBlock(_Fragment, { key: 2 }, [\\"fine\\"], 2112 /* STABLE_FRAGMENT, DEV_ROOT_FRAGMENT */))
 | 
					        : (_openBlock(), _createElementBlock(_Fragment, { key: 2 }, [\\"fine\\"], 64 /* STABLE_FRAGMENT */))
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}"
 | 
					}"
 | 
				
			||||||
`;
 | 
					`;
 | 
				
			||||||
 | 
				
			|||||||
@ -259,6 +259,7 @@ export interface IfBranchNode extends Node {
 | 
				
			|||||||
  condition: ExpressionNode | undefined // else
 | 
					  condition: ExpressionNode | undefined // else
 | 
				
			||||||
  children: TemplateChildNode[]
 | 
					  children: TemplateChildNode[]
 | 
				
			||||||
  userKey?: AttributeNode | DirectiveNode
 | 
					  userKey?: AttributeNode | DirectiveNode
 | 
				
			||||||
 | 
					  isTemplateIf?: boolean
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface ForNode extends Node {
 | 
					export interface ForNode extends Node {
 | 
				
			||||||
 | 
				
			|||||||
@ -209,15 +209,14 @@ export function processIf(
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function createIfBranch(node: ElementNode, dir: DirectiveNode): IfBranchNode {
 | 
					function createIfBranch(node: ElementNode, dir: DirectiveNode): IfBranchNode {
 | 
				
			||||||
 | 
					  const isTemplateIf = node.tagType === ElementTypes.TEMPLATE
 | 
				
			||||||
  return {
 | 
					  return {
 | 
				
			||||||
    type: NodeTypes.IF_BRANCH,
 | 
					    type: NodeTypes.IF_BRANCH,
 | 
				
			||||||
    loc: node.loc,
 | 
					    loc: node.loc,
 | 
				
			||||||
    condition: dir.name === 'else' ? undefined : dir.exp,
 | 
					    condition: dir.name === 'else' ? undefined : dir.exp,
 | 
				
			||||||
    children:
 | 
					    children: isTemplateIf && !findDir(node, 'for') ? node.children : [node],
 | 
				
			||||||
      node.tagType === ElementTypes.TEMPLATE && !findDir(node, 'for')
 | 
					    userKey: findProp(node, `key`),
 | 
				
			||||||
        ? node.children
 | 
					    isTemplateIf
 | 
				
			||||||
        : [node],
 | 
					 | 
				
			||||||
    userKey: findProp(node, `key`)
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -274,6 +273,7 @@ function createChildrenCodegenNode(
 | 
				
			|||||||
      // the rest being comments
 | 
					      // the rest being comments
 | 
				
			||||||
      if (
 | 
					      if (
 | 
				
			||||||
        __DEV__ &&
 | 
					        __DEV__ &&
 | 
				
			||||||
 | 
					        !branch.isTemplateIf &&
 | 
				
			||||||
        children.filter(c => c.type !== NodeTypes.COMMENT).length === 1
 | 
					        children.filter(c => c.type !== NodeTypes.COMMENT).length === 1
 | 
				
			||||||
      ) {
 | 
					      ) {
 | 
				
			||||||
        patchFlag |= PatchFlags.DEV_ROOT_FRAGMENT
 | 
					        patchFlag |= PatchFlags.DEV_ROOT_FRAGMENT
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user