]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): custom-element: ensure number casting of camelCase props. (fix...
authorThorsten Lünborg <t.luenborg@googlemail.com>
Sat, 22 Oct 2022 09:20:46 +0000 (11:20 +0200)
committerGitHub <noreply@github.com>
Sat, 22 Oct 2022 09:20:46 +0000 (11:20 +0200)
packages/runtime-dom/__tests__/customElement.spec.ts
packages/runtime-dom/src/apiCustomElement.ts

index e29c36123f316c8b7df6bf7b58bb8bca75c2c7ac..300cc2322cec127a749e3ab63741f6b2490a6c1c 100644 (file)
@@ -135,14 +135,14 @@ describe('defineCustomElement', () => {
     test('attribute -> prop type casting', async () => {
       const E = defineCustomElement({
         props: {
-          foo: Number,
+          fooBar: Number, // test casting of camelCase prop names
           bar: Boolean,
           baz: String
         },
         render() {
           return [
-            this.foo,
-            typeof this.foo,
+            this.fooBar,
+            typeof this.fooBar,
             this.bar,
             typeof this.bar,
             this.baz,
@@ -151,7 +151,7 @@ describe('defineCustomElement', () => {
         }
       })
       customElements.define('my-el-props-cast', E)
-      container.innerHTML = `<my-el-props-cast foo="1" baz="12345"></my-el-props-cast>`
+      container.innerHTML = `<my-el-props-cast foo-bar="1" baz="12345"></my-el-props-cast>`
       const e = container.childNodes[0] as VueElement
       expect(e.shadowRoot!.innerHTML).toBe(
         `1 number false boolean 12345 string`
@@ -161,7 +161,7 @@ describe('defineCustomElement', () => {
       await nextTick()
       expect(e.shadowRoot!.innerHTML).toBe(`1 number true boolean 12345 string`)
 
-      e.setAttribute('foo', '2e1')
+      e.setAttribute('foo-bar', '2e1')
       await nextTick()
       expect(e.shadowRoot!.innerHTML).toBe(
         `20 number true boolean 12345 string`
index eabe83b6b9fff578c6c49a2c632f3e372d3327a2..5ff45d652f2100230effce8be10065d47bd26497 100644 (file)
@@ -268,10 +268,11 @@ export class VueElement extends BaseClass {
 
   protected _setAttr(key: string) {
     let value = this.getAttribute(key)
-    if (this._numberProps && this._numberProps[key]) {
+    const camelKey = camelize(key)
+    if (this._numberProps && this._numberProps[camelKey]) {
       value = toNumber(value)
     }
-    this._setProp(camelize(key), value, false)
+    this._setProp(camelKey, value, false)
   }
 
   /**