fix(runtime-core): should preserve props casing when component has no declared props
close #583
This commit is contained in:
		
							parent
							
								
									8aca71b354
								
							
						
					
					
						commit
						bb6a346996
					
				@ -32,7 +32,8 @@ describe('attribute fallthrough', () => {
 | 
				
			|||||||
            id: 'test',
 | 
					            id: 'test',
 | 
				
			||||||
            class: 'c' + count.value,
 | 
					            class: 'c' + count.value,
 | 
				
			||||||
            style: { color: count.value ? 'red' : 'green' },
 | 
					            style: { color: count.value ? 'red' : 'green' },
 | 
				
			||||||
            onClick: inc
 | 
					            onClick: inc,
 | 
				
			||||||
 | 
					            'data-id': 1
 | 
				
			||||||
          })
 | 
					          })
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -66,6 +67,7 @@ describe('attribute fallthrough', () => {
 | 
				
			|||||||
    expect(node.getAttribute('class')).toBe('c2 c0')
 | 
					    expect(node.getAttribute('class')).toBe('c2 c0')
 | 
				
			||||||
    expect(node.style.color).toBe('green')
 | 
					    expect(node.style.color).toBe('green')
 | 
				
			||||||
    expect(node.style.fontWeight).toBe('bold')
 | 
					    expect(node.style.fontWeight).toBe('bold')
 | 
				
			||||||
 | 
					    expect(node.dataset.id).toBe('1')
 | 
				
			||||||
    node.dispatchEvent(new CustomEvent('click'))
 | 
					    node.dispatchEvent(new CustomEvent('click'))
 | 
				
			||||||
    expect(click).toHaveBeenCalled()
 | 
					    expect(click).toHaveBeenCalled()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -127,13 +127,17 @@ export function resolveProps(
 | 
				
			|||||||
      if (key === 'key' || key === 'ref') continue
 | 
					      if (key === 'key' || key === 'ref') continue
 | 
				
			||||||
      // prop option names are camelized during normalization, so to support
 | 
					      // prop option names are camelized during normalization, so to support
 | 
				
			||||||
      // kebab -> camel conversion here we need to camelize the key.
 | 
					      // kebab -> camel conversion here we need to camelize the key.
 | 
				
			||||||
 | 
					      if (hasDeclaredProps) {
 | 
				
			||||||
        const camelKey = camelize(key)
 | 
					        const camelKey = camelize(key)
 | 
				
			||||||
      if (hasDeclaredProps && !hasOwn(options, camelKey)) {
 | 
					        if (hasOwn(options, camelKey)) {
 | 
				
			||||||
 | 
					          setProp(camelKey, rawProps[key])
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
          // Any non-declared props are put into a separate `attrs` object
 | 
					          // Any non-declared props are put into a separate `attrs` object
 | 
				
			||||||
          // for spreading. Make sure to preserve original key casing
 | 
					          // for spreading. Make sure to preserve original key casing
 | 
				
			||||||
          ;(attrs || (attrs = {}))[key] = rawProps[key]
 | 
					          ;(attrs || (attrs = {}))[key] = rawProps[key]
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
        setProp(camelKey, rawProps[key])
 | 
					        setProp(key, rawProps[key])
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user