Browse Source

tweak namespace changes

Evan You 10 years ago
parent
commit
ec5bcefca7

+ 1 - 1
src/compiler/codegen/index.js

@@ -29,7 +29,7 @@ function genElement (el) {
     // if the element is potentially a component,
     // wrap its children as a thunk.
     const children = genChildren(el, !isReservedTag(el.tag) /* asThunk */)
-    const code = `__h__('${el.tag}', ${genData(el)}, ${children}, '${el.namespace || ''}')`
+    const code = `__h__('${el.tag}', ${genData(el)}, ${children}, '${el.ns || ''}')`
     if (el.staticRoot) {
       // hoist static sub-trees out
       staticRenderFns.push(`with(this){return ${code}}`)

+ 10 - 4
src/compiler/parser/index.js

@@ -27,7 +27,13 @@ const decodeHTMLCached = cached(decodeHTML)
 const mustUseProp = makeMap('value,selected,checked,muted')
 
 // this map covers namespace elements that can appear as template root nodes
-const tagNamespace = makeMap('svg,g,defs,symbol,use,image,text,circle,ellipse,line,path,polygon,polyline,rect', true, 'svg')
+const isSVG = makeMap('svg,g,defs,symbol,use,image,text,circle,ellipse,line,path,polygon,polyline,rect', true)
+
+function getTagNamespace (tag) {
+  if (isSVG(tag)) {
+    return 'svg'
+  }
+}
 
 // make warning customizable depending on environment.
 let warn
@@ -75,11 +81,11 @@ export function parse (template, options) {
       }
 
       // check namespace
-      const namespace = tagNamespace(tag)
+      const namespace = getTagNamespace(tag)
       if (inNamespace) {
-        element.namespace = currentNamespace
+        element.ns = currentNamespace
       } else if (namespace) {
-        element.namespace = namespace
+        element.ns = namespace
         inNamespace = true
         currentNamespace = namespace
         namespaceIndex = stack.length

+ 2 - 2
src/runtime/vdom/patch.js

@@ -81,8 +81,8 @@ export default function createPatchFunction (backend) {
     const children = vnode.children
     const tag = vnode.tag
     if (isDef(tag)) {
-      elm = vnode.elm = vnode.namespace
-        ? nodeOps.createElementNS(vnode.namespace, tag)
+      elm = vnode.elm = vnode.ns
+        ? nodeOps.createElementNS(vnode.ns, tag)
         : nodeOps.createElement(tag)
       if (Array.isArray(children)) {
         for (i = 0; i < children.length; ++i) {

+ 2 - 2
src/runtime/vdom/vnode.js

@@ -1,11 +1,11 @@
-export default function VNode (tag, data, children, text, elm, namespace) {
+export default function VNode (tag, data, children, text, elm, ns) {
   return {
     tag,
     data,
     children,
     text,
     elm,
-    namespace,
+    ns,
     key: data && data.key
   }
 }

+ 2 - 2
src/shared/util.js

@@ -7,10 +7,10 @@
  * @return {Function}
  */
 
-export function makeMap (str, expectsLowerCase, defaultValue = true) {
+export function makeMap (str, expectsLowerCase) {
   const map = Object.create(null)
   str.split(',').forEach(key => {
-    map[key] = defaultValue
+    map[key] = true
   })
   return expectsLowerCase
     ? val => map[val.toLowerCase()]