Преглед изворни кода

use clone instead of stringToFrag for normal node in template parser (fix #760)

Evan You пре 11 година
родитељ
комит
de3b59fb7e
1 измењених фајлова са 13 додато и 3 уклоњено
  1. 13 3
      src/parsers/template.js

+ 13 - 3
src/parsers/template.js

@@ -126,9 +126,19 @@ function nodeToFragment (node) {
   ) {
     return node.content
   }
-  return tag === 'SCRIPT'
-    ? stringToFragment(node.textContent)
-    : stringToFragment(node.innerHTML)
+  // script template
+  if (tag === 'SCRIPT') {
+    return stringToFragment(node.textContent)
+  }
+  // normal node, clone it to avoid mutating the original
+  var clone = exports.clone(node)
+  var frag = document.createDocumentFragment()
+  var child
+  /* jshint boss:true */
+  while (child = clone.firstChild) {
+    frag.appendChild(child)
+  }
+  return frag
 }
 
 // Test for the presence of the Safari template cloning bug