avoid IIFE deoptimization when using const/let inside if branches

This commit is contained in:
Evan You 2016-08-18 14:22:53 -04:00
parent 13ce3a2559
commit d7f42cc5c3
6 changed files with 35 additions and 31 deletions

View File

@ -131,10 +131,10 @@ export function parseHTML (html, options) {
options.chars(text)
}
} else {
const stackedTag = lastTag.toLowerCase()
const reStackedTag = reCache[stackedTag] || (reCache[stackedTag] = new RegExp('([\\s\\S]*?)(</' + stackedTag + '[^>]*>)', 'i'))
let endTagLength = 0
const rest = html.replace(reStackedTag, function (all, text, endTag) {
var stackedTag = lastTag.toLowerCase()
var reStackedTag = reCache[stackedTag] || (reCache[stackedTag] = new RegExp('([\\s\\S]*?)(</' + stackedTag + '[^>]*>)', 'i'))
var endTagLength = 0
var rest = html.replace(reStackedTag, function (all, text, endTag) {
endTagLength = endTag.length
if (stackedTag !== 'script' && stackedTag !== 'style' && stackedTag !== 'noscript') {
text = text

View File

@ -51,9 +51,9 @@ export const nextTick = (function () {
/* istanbul ignore else */
if (typeof MutationObserver !== 'undefined' && !hasMutationObserverBug) {
let counter = 1
const observer = new MutationObserver(nextTickHandler)
const textNode = document.createTextNode(String(counter))
var counter = 1
var observer = new MutationObserver(nextTickHandler)
var textNode = document.createTextNode(String(counter))
observer.observe(textNode, {
characterData: true
})
@ -65,7 +65,7 @@ export const nextTick = (function () {
// webpack attempts to inject a shim for setImmediate
// if it is used as a global, so we have to work around that to
// avoid bundling unnecessary code.
const context = inBrowser
var context = inBrowser
? window
: typeof global !== 'undefined' ? global : {}
timerFunc = context.setImmediate || setTimeout

View File

@ -57,24 +57,7 @@ export function createComponent (
// functional component
if (Ctor.options.functional) {
const props = {}
const propOptions = Ctor.options.props
if (propOptions) {
Object.keys(propOptions).forEach(key => {
props[key] = validateProp(key, propOptions, propsData)
})
}
return Ctor.options.render.call(
null,
context.$createElement,
{
props,
data,
parent: context,
children: normalizeChildren(children),
slots: () => resolveSlots(children)
}
)
return createFunctionalComponent(Ctor, propsData, data, context, children)
}
// extract listeners, since these needs to be treated as
@ -102,6 +85,27 @@ export function createComponent (
return vnode
}
function createFunctionalComponent (Ctor, propsData, data, context, children) {
const props = {}
const propOptions = Ctor.options.props
if (propOptions) {
for (const key in propOptions) {
props[key] = validateProp(key, propOptions, propsData)
}
}
return Ctor.options.render.call(
null,
context.$createElement,
{
props,
data,
parent: context,
children: normalizeChildren(children),
slots: () => resolveSlots(children)
}
)
}
export function createComponentInstanceForVnode (
vnode: any, // we know it's MountedComponentVNode but flow doesn't
parent: any // activeInstance in lifecycle state

View File

@ -120,8 +120,8 @@ export default {
children.forEach(c => {
if (c.data.moved) {
const el = c.elm
const s = el.style
var el = c.elm
var s = el.style
addTransitionClass(el, moveClass)
s.transform = s.WebkitTransform = s.transitionDuration = ''
el._moveDest = c.data.pos

View File

@ -141,8 +141,8 @@ export default {
})
return placeholder(h, rawChild)
} else if (mode === 'in-out') {
let delayedLeave
const performLeave = () => { delayedLeave() }
var delayedLeave
var performLeave = () => { delayedLeave() }
mergeVNodeHook(data, 'afterEnter', performLeave)
mergeVNodeHook(data, 'enterCancelled', performLeave)
mergeVNodeHook(oldData, 'delayLeave', leave => {

View File

@ -94,7 +94,7 @@ export function enter (vnode: VNodeWithData) {
if (!vnode.data.show) {
// remove pending leave element on enter by injecting an insert hook
const hooks = vnode.data.hook || (vnode.data.hook = {})
var hooks = vnode.data.hook || (vnode.data.hook = {})
hooks._transitionInsert = () => {
const parent = el.parentNode
const pendingNode = parent && parent._pending && parent._pending[vnode.key]