Parcourir la source

fix static detection for built-ins

Evan You il y a 10 ans
Parent
commit
8c64a0eeec

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

@@ -28,9 +28,10 @@ function genElement (el) {
   } else {
     // if the element is potentially a component,
     // wrap its children as a thunk.
-    const children = genChildren(el, !isReservedTag(el.tag))
+    const children = genChildren(el, !isReservedTag(el.tag) /* asThunk */)
     const code = `__h__('${el.tag}', ${genData(el)}, ${children}, ${el.svg})`
     if (el.staticRoot) {
+      // hoist static sub-trees out
       staticRenderFns.push(`with(this){return ${code}}`)
       return `__static__(${staticRenderFns.length - 1})`
     } else {

+ 7 - 8
src/compiler/optimizer/index.js

@@ -1,4 +1,5 @@
 import { makeMap } from '../../shared/util'
+import { isReservedTag, isBuiltInTag } from '../../runtime/util/dom'
 
 /**
  * Goal of the optimizier: walk the generated template AST tree
@@ -50,12 +51,10 @@ const isStaticKey = makeMap(
 )
 
 function isStatic (node) {
-  return node.pre || node.text || (
-    !node.render &&
-    !node.slotName &&
-    !node.component &&
-    !node.expression && (
-      node.plain || Object.keys(node).every(isStaticKey)
-    )
-  )
+  return !!(node.pre || node.text || (
+    !node.expression && // not text with interpolation
+    (!node.tag || isReservedTag(node.tag)) && // not a component
+    !isBuiltInTag(node.tag) && // not a built-in
+    (node.plain || Object.keys(node).every(isStaticKey)) // no dynamic bindings
+  ))
 }

+ 0 - 1
src/entries/web-runtime-with-compiler.js

@@ -42,7 +42,6 @@ Vue.prototype.$mount = function (el) {
       }
     }
   }
-  console.log(this)
   mount.call(this)
 }
 

+ 5 - 1
src/runtime/util/dom.js

@@ -2,8 +2,12 @@ import { inBrowser } from './env'
 import { warn } from './debug'
 import { makeMap } from '../../shared/util'
 
+const builtInTags = 'slot,component,render'
+
+export const isBuiltInTag = makeMap(builtInTags)
+
 export const isReservedTag = makeMap(
-  'slot,component,render,' +
+  builtInTags +
   'html,base,head,link,meta,style,title,' +
   'address,article,footer,header,h1,h2,h3,h4,h5,h6,hgroup,nav,section,' +
   'div,dd,dl,dt,figcaption,figure,hr,li,main,ol,p,pre,ul,' +