]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-test): output empty attrs without value in seralized output
authorEvan You <yyx990803@gmail.com>
Tue, 17 Dec 2019 16:50:10 +0000 (11:50 -0500)
committerEvan You <yyx990803@gmail.com>
Tue, 17 Dec 2019 17:31:38 +0000 (12:31 -0500)
packages/runtime-test/__tests__/testRuntime.spec.ts
packages/runtime-test/src/serialize.ts

index ce98d4d5ab0ccd60e505a236d9c99dc868a31fe4..ec7cbb21eea810d48ebf6e704a87cbaee2cfc84d 100644 (file)
@@ -126,7 +126,8 @@ describe('test renderer', () => {
         return h(
           'div',
           {
-            id: 'test'
+            id: 'test',
+            boolean: ''
           },
           [h('span', 'foo'), 'hello']
         )
@@ -135,12 +136,12 @@ describe('test renderer', () => {
     const root = nodeOps.createElement('div')
     render(h(App), root)
     expect(serialize(root)).toEqual(
-      `<div><div id="test"><span>foo</span>hello</div></div>`
+      `<div><div id="test" boolean><span>foo</span>hello</div></div>`
     )
     // indented output
     expect(serialize(root, 2)).toEqual(
       `<div>
-  <div id="test">
+  <div id="test" boolean>
     <span>
       foo
     </span>
index 57a3e7a5e21327b5215bff8e67e794f973618335..52c79b7d0d97763b5b6e914bfd7bae5010d6e41a 100644 (file)
@@ -40,7 +40,11 @@ function serializeElement(
   const props = Object.keys(node.props)
     .map(key => {
       const value = node.props[key]
-      return isOn(key) || value == null ? `` : `${key}=${JSON.stringify(value)}`
+      return isOn(key) || value == null
+        ? ``
+        : value === ``
+          ? key
+          : `${key}=${JSON.stringify(value)}`
     })
     .filter(Boolean)
     .join(' ')