Skip to content

Commit d7f42cc

Browse files
committed
avoid IIFE deoptimization when using const/let inside if branches
1 parent 13ce3a2 commit d7f42cc

File tree

6 files changed

+35
-31
lines changed

6 files changed

+35
-31
lines changed

src/compiler/parser/html-parser.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ export function parseHTML (html, options) {
131131
options.chars(text)
132132
}
133133
} else {
134-
const stackedTag = lastTag.toLowerCase()
135-
const reStackedTag = reCache[stackedTag] || (reCache[stackedTag] = new RegExp('([\\s\\S]*?)(</' + stackedTag + '[^>]*>)', 'i'))
136-
let endTagLength = 0
137-
const rest = html.replace(reStackedTag, function (all, text, endTag) {
134+
var stackedTag = lastTag.toLowerCase()
135+
var reStackedTag = reCache[stackedTag] || (reCache[stackedTag] = new RegExp('([\\s\\S]*?)(</' + stackedTag + '[^>]*>)', 'i'))
136+
var endTagLength = 0
137+
var rest = html.replace(reStackedTag, function (all, text, endTag) {
138138
endTagLength = endTag.length
139139
if (stackedTag !== 'script' && stackedTag !== 'style' && stackedTag !== 'noscript') {
140140
text = text

src/core/util/env.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ export const nextTick = (function () {
5151

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

src/core/vdom/create-component.js

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,7 @@ export function createComponent (
5757

5858
// functional component
5959
if (Ctor.options.functional) {
60-
const props = {}
61-
const propOptions = Ctor.options.props
62-
if (propOptions) {
63-
Object.keys(propOptions).forEach(key => {
64-
props[key] = validateProp(key, propOptions, propsData)
65-
})
66-
}
67-
return Ctor.options.render.call(
68-
null,
69-
context.$createElement,
70-
{
71-
props,
72-
data,
73-
parent: context,
74-
children: normalizeChildren(children),
75-
slots: () => resolveSlots(children)
76-
}
77-
)
60+
return createFunctionalComponent(Ctor, propsData, data, context, children)
7861
}
7962

8063
// extract listeners, since these needs to be treated as
@@ -102,6 +85,27 @@ export function createComponent (
10285
return vnode
10386
}
10487

88+
function createFunctionalComponent (Ctor, propsData, data, context, children) {
89+
const props = {}
90+
const propOptions = Ctor.options.props
91+
if (propOptions) {
92+
for (const key in propOptions) {
93+
props[key] = validateProp(key, propOptions, propsData)
94+
}
95+
}
96+
return Ctor.options.render.call(
97+
null,
98+
context.$createElement,
99+
{
100+
props,
101+
data,
102+
parent: context,
103+
children: normalizeChildren(children),
104+
slots: () => resolveSlots(children)
105+
}
106+
)
107+
}
108+
105109
export function createComponentInstanceForVnode (
106110
vnode: any, // we know it's MountedComponentVNode but flow doesn't
107111
parent: any // activeInstance in lifecycle state

src/platforms/web/runtime/components/transition-group.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ export default {
120120

121121
children.forEach(c => {
122122
if (c.data.moved) {
123-
const el = c.elm
124-
const s = el.style
123+
var el = c.elm
124+
var s = el.style
125125
addTransitionClass(el, moveClass)
126126
s.transform = s.WebkitTransform = s.transitionDuration = ''
127127
el._moveDest = c.data.pos

src/platforms/web/runtime/components/transition.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ export default {
141141
})
142142
return placeholder(h, rawChild)
143143
} else if (mode === 'in-out') {
144-
let delayedLeave
145-
const performLeave = () => { delayedLeave() }
144+
var delayedLeave
145+
var performLeave = () => { delayedLeave() }
146146
mergeVNodeHook(data, 'afterEnter', performLeave)
147147
mergeVNodeHook(data, 'enterCancelled', performLeave)
148148
mergeVNodeHook(oldData, 'delayLeave', leave => {

src/platforms/web/runtime/modules/transition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export function enter (vnode: VNodeWithData) {
9494

9595
if (!vnode.data.show) {
9696
// remove pending leave element on enter by injecting an insert hook
97-
const hooks = vnode.data.hook || (vnode.data.hook = {})
97+
var hooks = vnode.data.hook || (vnode.data.hook = {})
9898
hooks._transitionInsert = () => {
9999
const parent = el.parentNode
100100
const pendingNode = parent && parent._pending && parent._pending[vnode.key]

0 commit comments

Comments
 (0)