fix(compiler-dom): stringifyStatic should remove attribute bindings with null value (#3477)
				
					
				
			fix #3475
This commit is contained in:
		
							parent
							
								
									7cf143dd4f
								
							
						
					
					
						commit
						ca6aa01181
					
				@ -294,4 +294,26 @@ describe('stringify static html', () => {
 | 
			
		||||
      })
 | 
			
		||||
    })
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
  test('should remove attribute for `null`', () => {
 | 
			
		||||
    const { ast } = compileWithStringify(
 | 
			
		||||
      `<div>${repeat(
 | 
			
		||||
        `<span :title="null"></span>`,
 | 
			
		||||
        StringifyThresholds.ELEMENT_WITH_BINDING_COUNT
 | 
			
		||||
      )}</div>`
 | 
			
		||||
    )
 | 
			
		||||
    expect(ast.hoists[0]).toMatchObject({
 | 
			
		||||
      type: NodeTypes.JS_CALL_EXPRESSION,
 | 
			
		||||
      callee: CREATE_STATIC,
 | 
			
		||||
      arguments: [
 | 
			
		||||
        JSON.stringify(
 | 
			
		||||
          `${repeat(
 | 
			
		||||
            `<span></span>`,
 | 
			
		||||
            StringifyThresholds.ELEMENT_WITH_BINDING_COUNT
 | 
			
		||||
          )}`
 | 
			
		||||
        ),
 | 
			
		||||
        '5'
 | 
			
		||||
      ]
 | 
			
		||||
    })
 | 
			
		||||
  })
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
@ -264,6 +264,7 @@ function stringifyElement(
 | 
			
		||||
    } else if (p.type === NodeTypes.DIRECTIVE && p.name === 'bind') {
 | 
			
		||||
      // constant v-bind, e.g. :foo="1"
 | 
			
		||||
      let evaluated = evaluateConstant(p.exp as SimpleExpressionNode)
 | 
			
		||||
      if (evaluated != null) {
 | 
			
		||||
        const arg = p.arg && (p.arg as SimpleExpressionNode).content
 | 
			
		||||
        if (arg === 'class') {
 | 
			
		||||
          evaluated = normalizeClass(evaluated)
 | 
			
		||||
@ -275,6 +276,7 @@ function stringifyElement(
 | 
			
		||||
        )}"`
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  if (context.scopeId) {
 | 
			
		||||
    res += ` ${context.scopeId}`
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user