Explorar el Código

template use innerHTML on normal nodes

Evan You hace 12 años
padre
commit
32318d9b3d
Se han modificado 2 ficheros con 6 adiciones y 4 borrados
  1. 3 1
      src/parse/template.js
  2. 3 3
      test/unit/template.js

+ 3 - 1
src/parse/template.js

@@ -20,6 +20,8 @@ map.colgroup =
 map.caption =
 map.caption =
 map.tfoot = [1, '<table>', '</table>']
 map.tfoot = [1, '<table>', '</table>']
 
 
+map.g =
+map.defs =
 map.text =
 map.text =
 map.circle =
 map.circle =
 map.ellipse =
 map.ellipse =
@@ -96,7 +98,7 @@ function nodeToFragment (node) {
   }
   }
   return tag === 'SCRIPT'
   return tag === 'SCRIPT'
     ? stringToFragment(node.textContent)
     ? stringToFragment(node.textContent)
-    : stringToFragment(node.outerHTML)
+    : stringToFragment(node.innerHTML)
 }
 }
 
 
 /**
 /**

+ 3 - 3
test/unit/template.js

@@ -35,13 +35,13 @@ describe('Template Parser', function () {
     expect(res.querySelector('.test').textContent).toBe('world')
     expect(res.querySelector('.test').textContent).toBe('world')
   })
   })
 
 
-  it('should parse outerHTML if argument is a normal node', function () {
+  it('should parse innerHTML if argument is a normal node', function () {
     var node = document.createElement('div')
     var node = document.createElement('div')
     node.innerHTML = testString
     node.innerHTML = testString
     var res = parse(node)
     var res = parse(node)
     expect(res instanceof DocumentFragment).toBeTruthy()
     expect(res instanceof DocumentFragment).toBeTruthy()
-    expect(res.childNodes.length).toBe(1)
-    expect(res.querySelector('div .test').textContent).toBe('world')
+    expect(res.childNodes.length).toBe(2)
+    expect(res.querySelector('.test').textContent).toBe('world')
   })
   })
 
 
   it('should retrieve and parse if argument is an id selector', function () {
   it('should retrieve and parse if argument is an id selector', function () {