mirror of https://github.com/vuejs/vue.git
				
				
				
			avoid IIFE deoptimization when using const/let inside if branches
This commit is contained in:
		
							parent
							
								
									13ce3a2559
								
							
						
					
					
						commit
						d7f42cc5c3
					
				| 
						 | 
					@ -131,10 +131,10 @@ export function parseHTML (html, options) {
 | 
				
			||||||
        options.chars(text)
 | 
					        options.chars(text)
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      const stackedTag = lastTag.toLowerCase()
 | 
					      var stackedTag = lastTag.toLowerCase()
 | 
				
			||||||
      const reStackedTag = reCache[stackedTag] || (reCache[stackedTag] = new RegExp('([\\s\\S]*?)(</' + stackedTag + '[^>]*>)', 'i'))
 | 
					      var reStackedTag = reCache[stackedTag] || (reCache[stackedTag] = new RegExp('([\\s\\S]*?)(</' + stackedTag + '[^>]*>)', 'i'))
 | 
				
			||||||
      let endTagLength = 0
 | 
					      var endTagLength = 0
 | 
				
			||||||
      const rest = html.replace(reStackedTag, function (all, text, endTag) {
 | 
					      var rest = html.replace(reStackedTag, function (all, text, endTag) {
 | 
				
			||||||
        endTagLength = endTag.length
 | 
					        endTagLength = endTag.length
 | 
				
			||||||
        if (stackedTag !== 'script' && stackedTag !== 'style' && stackedTag !== 'noscript') {
 | 
					        if (stackedTag !== 'script' && stackedTag !== 'style' && stackedTag !== 'noscript') {
 | 
				
			||||||
          text = text
 | 
					          text = text
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -51,9 +51,9 @@ export const nextTick = (function () {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* istanbul ignore else */
 | 
					  /* istanbul ignore else */
 | 
				
			||||||
  if (typeof MutationObserver !== 'undefined' && !hasMutationObserverBug) {
 | 
					  if (typeof MutationObserver !== 'undefined' && !hasMutationObserverBug) {
 | 
				
			||||||
    let counter = 1
 | 
					    var counter = 1
 | 
				
			||||||
    const observer = new MutationObserver(nextTickHandler)
 | 
					    var observer = new MutationObserver(nextTickHandler)
 | 
				
			||||||
    const textNode = document.createTextNode(String(counter))
 | 
					    var textNode = document.createTextNode(String(counter))
 | 
				
			||||||
    observer.observe(textNode, {
 | 
					    observer.observe(textNode, {
 | 
				
			||||||
      characterData: true
 | 
					      characterData: true
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
| 
						 | 
					@ -65,7 +65,7 @@ export const nextTick = (function () {
 | 
				
			||||||
    // webpack attempts to inject a shim for setImmediate
 | 
					    // webpack attempts to inject a shim for setImmediate
 | 
				
			||||||
    // if it is used as a global, so we have to work around that to
 | 
					    // if it is used as a global, so we have to work around that to
 | 
				
			||||||
    // avoid bundling unnecessary code.
 | 
					    // avoid bundling unnecessary code.
 | 
				
			||||||
    const context = inBrowser
 | 
					    var context = inBrowser
 | 
				
			||||||
      ? window
 | 
					      ? window
 | 
				
			||||||
      : typeof global !== 'undefined' ? global : {}
 | 
					      : typeof global !== 'undefined' ? global : {}
 | 
				
			||||||
    timerFunc = context.setImmediate || setTimeout
 | 
					    timerFunc = context.setImmediate || setTimeout
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -57,24 +57,7 @@ export function createComponent (
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // functional component
 | 
					  // functional component
 | 
				
			||||||
  if (Ctor.options.functional) {
 | 
					  if (Ctor.options.functional) {
 | 
				
			||||||
    const props = {}
 | 
					    return createFunctionalComponent(Ctor, propsData, data, context, children)
 | 
				
			||||||
    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)
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // extract listeners, since these needs to be treated as
 | 
					  // extract listeners, since these needs to be treated as
 | 
				
			||||||
| 
						 | 
					@ -102,6 +85,27 @@ export function createComponent (
 | 
				
			||||||
  return vnode
 | 
					  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 (
 | 
					export function createComponentInstanceForVnode (
 | 
				
			||||||
  vnode: any, // we know it's MountedComponentVNode but flow doesn't
 | 
					  vnode: any, // we know it's MountedComponentVNode but flow doesn't
 | 
				
			||||||
  parent: any // activeInstance in lifecycle state
 | 
					  parent: any // activeInstance in lifecycle state
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -120,8 +120,8 @@ export default {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    children.forEach(c => {
 | 
					    children.forEach(c => {
 | 
				
			||||||
      if (c.data.moved) {
 | 
					      if (c.data.moved) {
 | 
				
			||||||
        const el = c.elm
 | 
					        var el = c.elm
 | 
				
			||||||
        const s = el.style
 | 
					        var s = el.style
 | 
				
			||||||
        addTransitionClass(el, moveClass)
 | 
					        addTransitionClass(el, moveClass)
 | 
				
			||||||
        s.transform = s.WebkitTransform = s.transitionDuration = ''
 | 
					        s.transform = s.WebkitTransform = s.transitionDuration = ''
 | 
				
			||||||
        el._moveDest = c.data.pos
 | 
					        el._moveDest = c.data.pos
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -141,8 +141,8 @@ export default {
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
        return placeholder(h, rawChild)
 | 
					        return placeholder(h, rawChild)
 | 
				
			||||||
      } else if (mode === 'in-out') {
 | 
					      } else if (mode === 'in-out') {
 | 
				
			||||||
        let delayedLeave
 | 
					        var delayedLeave
 | 
				
			||||||
        const performLeave = () => { delayedLeave() }
 | 
					        var performLeave = () => { delayedLeave() }
 | 
				
			||||||
        mergeVNodeHook(data, 'afterEnter', performLeave)
 | 
					        mergeVNodeHook(data, 'afterEnter', performLeave)
 | 
				
			||||||
        mergeVNodeHook(data, 'enterCancelled', performLeave)
 | 
					        mergeVNodeHook(data, 'enterCancelled', performLeave)
 | 
				
			||||||
        mergeVNodeHook(oldData, 'delayLeave', leave => {
 | 
					        mergeVNodeHook(oldData, 'delayLeave', leave => {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -94,7 +94,7 @@ export function enter (vnode: VNodeWithData) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!vnode.data.show) {
 | 
					  if (!vnode.data.show) {
 | 
				
			||||||
    // remove pending leave element on enter by injecting an insert hook
 | 
					    // 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 = () => {
 | 
					    hooks._transitionInsert = () => {
 | 
				
			||||||
      const parent = el.parentNode
 | 
					      const parent = el.parentNode
 | 
				
			||||||
      const pendingNode = parent && parent._pending && parent._pending[vnode.key]
 | 
					      const pendingNode = parent && parent._pending && parent._pending[vnode.key]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue