From 7cfb99725710ce1d389fac4b3d75a6be33623d1b Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 12 Oct 2017 23:19:22 -0400 Subject: [PATCH 0001/1057] build: 2.5 --- src/v2/guide/installation.md | 10 +- themes/vue/_config.yml | 2 +- themes/vue/source/js/vue.js | 1790 ++++++++++++++++++------------- themes/vue/source/js/vue.min.js | 4 +- 4 files changed, 1063 insertions(+), 743 deletions(-) diff --git a/src/v2/guide/installation.md b/src/v2/guide/installation.md index 4ce60c9259..1c726323dc 100644 --- a/src/v2/guide/installation.md +++ b/src/v2/guide/installation.md @@ -2,11 +2,11 @@ title: Installation type: guide order: 1 -vue_version: 2.4.4 -dev_size: "262.63" -min_size: "80.86" -gz_size: "29.40" -ro_gz_size: "20.70" +vue_version: 2.5.0 +dev_size: "270.61" +min_size: "83.02" +gz_size: "30.28" +ro_gz_size: "21.00" --- ### Compatibility Note diff --git a/themes/vue/_config.yml b/themes/vue/_config.yml index ada3214ee3..fba47625eb 100644 --- a/themes/vue/_config.yml +++ b/themes/vue/_config.yml @@ -1,4 +1,4 @@ site_description: "Vue.js - The Progressive JavaScript Framework" google_analytics: UA-46852172-1 root_domain: vuejs.org -vue_version: 2.4.4 +vue_version: 2.5.0 diff --git a/themes/vue/source/js/vue.js b/themes/vue/source/js/vue.js index 0b3bb9c304..0b4d59d287 100644 --- a/themes/vue/source/js/vue.js +++ b/themes/vue/source/js/vue.js @@ -1,5 +1,5 @@ /*! - * Vue.js v2.4.4 + * Vue.js v2.5.0 * (c) 2014-2017 Evan You * Released under the MIT License. */ @@ -49,8 +49,15 @@ function isObject (obj) { return obj !== null && typeof obj === 'object' } +/** + * Get the raw type string of a value e.g. [object Object] + */ var _toString = Object.prototype.toString; +function toRawType (value) { + return _toString.call(value).slice(8, -1) +} + /** * Strict object type check. Only returns true * for plain JavaScript objects. @@ -67,7 +74,7 @@ function isRegExp (v) { * Check if val is a valid array index. */ function isValidArrayIndex (val) { - var n = parseFloat(val); + var n = parseFloat(String(val)); return n >= 0 && Math.floor(n) === n && isFinite(val) } @@ -117,7 +124,7 @@ var isBuiltInTag = makeMap('slot,component', true); /** * Check if a attribute is a reserved attribute. */ -var isReservedAttribute = makeMap('key,ref,slot,is'); +var isReservedAttribute = makeMap('key,ref,slot,slot-scope,is'); /** * Remove an item from an array @@ -327,7 +334,8 @@ var LIFECYCLE_HOOKS = [ 'beforeDestroy', 'destroyed', 'activated', - 'deactivated' + 'deactivated', + 'errorCaptured' ]; /* */ @@ -464,7 +472,8 @@ function parsePath (path) { var warn = noop; var tip = noop; -var formatComponentName = (null); // work around flow check +var generateComponentTrace = (noop); // work around flow check +var formatComponentName = (noop); { var hasConsole = typeof console !== 'undefined'; @@ -495,15 +504,13 @@ var formatComponentName = (null); // work around flow check if (vm.$root === vm) { return '' } - var name = typeof vm === 'string' - ? vm - : typeof vm === 'function' && vm.options - ? vm.options.name - : vm._isVue - ? vm.$options.name || vm.$options._componentTag - : vm.name; - - var file = vm._isVue && vm.$options.__file; + var options = typeof vm === 'function' && vm.cid != null + ? vm.options + : vm._isVue + ? vm.$options || vm.constructor.options + : vm || {}; + var name = options.name || options._componentTag; + var file = options.__file; if (!name && file) { var match = file.match(/([^/\\]+)\.vue$/); name = match && match[1]; @@ -525,7 +532,7 @@ var formatComponentName = (null); // work around flow check return res }; - var generateComponentTrace = function (vm) { + generateComponentTrace = function (vm) { if (vm._isVue && vm.$parent) { var tree = []; var currentRecursiveSequence = 0; @@ -558,23 +565,50 @@ var formatComponentName = (null); // work around flow check /* */ function handleError (err, vm, info) { - if (config.errorHandler) { - config.errorHandler.call(null, err, vm, info); - } else { - { - warn(("Error in " + info + ": \"" + (err.toString()) + "\""), vm); + if (vm) { + var cur = vm; + while ((cur = cur.$parent)) { + var hooks = cur.$options.errorCaptured; + if (hooks) { + for (var i = 0; i < hooks.length; i++) { + try { + var capture = hooks[i].call(cur, err, vm, info) === false; + if (capture) { return } + } catch (e) { + globalHandleError(e, cur, 'errorCaptured hook'); + } + } + } } - /* istanbul ignore else */ - if (inBrowser && typeof console !== 'undefined') { - console.error(err); - } else { - throw err + } + globalHandleError(err, vm, info); +} + +function globalHandleError (err, vm, info) { + if (config.errorHandler) { + try { + return config.errorHandler.call(null, err, vm, info) + } catch (e) { + logError(e, null, 'config.errorHandler'); } } + logError(err, vm, info); +} + +function logError (err, vm, info) { + { + warn(("Error in " + info + ": \"" + (err.toString()) + "\""), vm); + } + /* istanbul ignore else */ + if (inBrowser && typeof console !== 'undefined') { + console.error(err); + } else { + throw err + } } /* */ -/* globals MutationObserver */ +/* globals MessageChannel */ // can we use __proto__? var hasProto = '__proto__' in {}; @@ -652,45 +686,40 @@ var nextTick = (function () { } } - // the nextTick behavior leverages the microtask queue, which can be accessed - // via either native Promise.then or MutationObserver. - // MutationObserver has wider support, however it is seriously bugged in - // UIWebView in iOS >= 9.3.3 when triggered in touch event handlers. It - // completely stops working after triggering a few times... so, if native - // Promise is available, we will use it: + // An asynchronous deferring mechanism. + // In pre 2.4, we used to use microtasks (Promise/MutationObserver) + // but microtasks actually has too high a priority and fires in between + // supposedly sequential events (e.g. #4521, #6690) or even between + // bubbling of the same event (#6566). Technically setImmediate should be + // the ideal choice, but it's not available everywhere; and the only polyfill + // that consistently queues the callback after all DOM events triggered in the + // same loop is by using MessageChannel. /* istanbul ignore if */ - if (typeof Promise !== 'undefined' && isNative(Promise)) { - var p = Promise.resolve(); - var logError = function (err) { console.error(err); }; + if (typeof setImmediate !== 'undefined' && isNative(setImmediate)) { timerFunc = function () { - p.then(nextTickHandler).catch(logError); - // in problematic UIWebViews, Promise.then doesn't completely break, but - // it can get stuck in a weird state where callbacks are pushed into the - // microtask queue but the queue isn't being flushed, until the browser - // needs to do some other work, e.g. handle a timer. Therefore we can - // "force" the microtask queue to be flushed by adding an empty timer. - if (isIOS) { setTimeout(noop); } + setImmediate(nextTickHandler); }; - } else if (!isIE && typeof MutationObserver !== 'undefined' && ( - isNative(MutationObserver) || - // PhantomJS and iOS 7.x - MutationObserver.toString() === '[object MutationObserverConstructor]' + } else if (typeof MessageChannel !== 'undefined' && ( + isNative(MessageChannel) || + // PhantomJS + MessageChannel.toString() === '[object MessageChannelConstructor]' )) { - // use MutationObserver where native Promise is not available, - // e.g. PhantomJS, iOS7, Android 4.4 - var counter = 1; - var observer = new MutationObserver(nextTickHandler); - var textNode = document.createTextNode(String(counter)); - observer.observe(textNode, { - characterData: true - }); + var channel = new MessageChannel(); + var port = channel.port2; + channel.port1.onmessage = nextTickHandler; + timerFunc = function () { + port.postMessage(1); + }; + } else + /* istanbul ignore next */ + if (typeof Promise !== 'undefined' && isNative(Promise)) { + // use microtask in non-DOM environments, e.g. Weex + var p = Promise.resolve(); timerFunc = function () { - counter = (counter + 1) % 2; - textNode.data = String(counter); + p.then(nextTickHandler); }; } else { // fallback to setTimeout - /* istanbul ignore next */ timerFunc = function () { setTimeout(nextTickHandler, 0); }; @@ -713,6 +742,7 @@ var nextTick = (function () { pending = true; timerFunc(); } + // $flow-disable-line if (!cb && typeof Promise !== 'undefined') { return new Promise(function (resolve, reject) { _resolve = resolve; @@ -722,7 +752,7 @@ var nextTick = (function () { })(); var _Set; -/* istanbul ignore if */ +/* istanbul ignore if */ // $flow-disable-line if (typeof Set !== 'undefined' && isNative(Set)) { // use native Set when available. _Set = Set; @@ -797,6 +827,101 @@ function popTarget () { Dep.target = targetStack.pop(); } +/* */ + +var VNode = function VNode ( + tag, + data, + children, + text, + elm, + context, + componentOptions, + asyncFactory +) { + this.tag = tag; + this.data = data; + this.children = children; + this.text = text; + this.elm = elm; + this.ns = undefined; + this.context = context; + this.functionalContext = undefined; + this.functionalOptions = undefined; + this.functionalScopeId = undefined; + this.key = data && data.key; + this.componentOptions = componentOptions; + this.componentInstance = undefined; + this.parent = undefined; + this.raw = false; + this.isStatic = false; + this.isRootInsert = true; + this.isComment = false; + this.isCloned = false; + this.isOnce = false; + this.asyncFactory = asyncFactory; + this.asyncMeta = undefined; + this.isAsyncPlaceholder = false; +}; + +var prototypeAccessors = { child: { configurable: true } }; + +// DEPRECATED: alias for componentInstance for backwards compat. +/* istanbul ignore next */ +prototypeAccessors.child.get = function () { + return this.componentInstance +}; + +Object.defineProperties( VNode.prototype, prototypeAccessors ); + +var createEmptyVNode = function (text) { + if ( text === void 0 ) text = ''; + + var node = new VNode(); + node.text = text; + node.isComment = true; + return node +}; + +function createTextVNode (val) { + return new VNode(undefined, undefined, undefined, String(val)) +} + +// optimized shallow clone +// used for static nodes and slot nodes because they may be reused across +// multiple renders, cloning them avoids errors when DOM manipulations rely +// on their elm reference. +function cloneVNode (vnode, deep) { + var cloned = new VNode( + vnode.tag, + vnode.data, + vnode.children, + vnode.text, + vnode.elm, + vnode.context, + vnode.componentOptions, + vnode.asyncFactory + ); + cloned.ns = vnode.ns; + cloned.isStatic = vnode.isStatic; + cloned.key = vnode.key; + cloned.isComment = vnode.isComment; + cloned.isCloned = true; + if (deep && vnode.children) { + cloned.children = cloneVNodes(vnode.children); + } + return cloned +} + +function cloneVNodes (vnodes, deep) { + var len = vnodes.length; + var res = new Array(len); + for (var i = 0; i < len; i++) { + res[i] = cloneVNode(vnodes[i], deep); + } + return res +} + /* * not type checking this file because flow doesn't play well with * dynamically accessing methods on Array prototype @@ -882,7 +1007,7 @@ var Observer = function Observer (value) { Observer.prototype.walk = function walk (obj) { var keys = Object.keys(obj); for (var i = 0; i < keys.length; i++) { - defineReactive$$1(obj, keys[i], obj[keys[i]]); + defineReactive(obj, keys[i], obj[keys[i]]); } }; @@ -925,7 +1050,7 @@ function copyAugment (target, src, keys) { * or the existing observer if the value already has one. */ function observe (value, asRootData) { - if (!isObject(value)) { + if (!isObject(value) || value instanceof VNode) { return } var ob; @@ -949,7 +1074,7 @@ function observe (value, asRootData) { /** * Define a reactive property on an Object. */ -function defineReactive$$1 ( +function defineReactive ( obj, key, val, @@ -1032,7 +1157,7 @@ function set (target, key, val) { target[key] = val; return val } - defineReactive$$1(ob.value, key, val); + defineReactive(ob.value, key, val); ob.dep.notify(); return val } @@ -1215,11 +1340,19 @@ LIFECYCLE_HOOKS.forEach(function (hook) { * a three-way merge between constructor options, instance * options and parent options. */ -function mergeAssets (parentVal, childVal) { +function mergeAssets ( + parentVal, + childVal, + vm, + key +) { var res = Object.create(parentVal || null); - return childVal - ? extend(res, childVal) - : res + if (childVal) { + "development" !== 'production' && assertObjectType(key, childVal, vm); + return extend(res, childVal) + } else { + return res + } } ASSET_TYPES.forEach(function (type) { @@ -1232,22 +1365,30 @@ ASSET_TYPES.forEach(function (type) { * Watchers hashes should not overwrite one * another, so we merge them as arrays. */ -strats.watch = function (parentVal, childVal) { +strats.watch = function ( + parentVal, + childVal, + vm, + key +) { // work around Firefox's Object.prototype.watch... if (parentVal === nativeWatch) { parentVal = undefined; } if (childVal === nativeWatch) { childVal = undefined; } /* istanbul ignore if */ if (!childVal) { return Object.create(parentVal || null) } + { + assertObjectType(key, childVal, vm); + } if (!parentVal) { return childVal } var ret = {}; extend(ret, parentVal); - for (var key in childVal) { - var parent = ret[key]; - var child = childVal[key]; + for (var key$1 in childVal) { + var parent = ret[key$1]; + var child = childVal[key$1]; if (parent && !Array.isArray(parent)) { parent = [parent]; } - ret[key] = parent + ret[key$1] = parent ? parent.concat(child) : Array.isArray(child) ? child : [child]; } @@ -1260,7 +1401,15 @@ strats.watch = function (parentVal, childVal) { strats.props = strats.methods = strats.inject = -strats.computed = function (parentVal, childVal) { +strats.computed = function ( + parentVal, + childVal, + vm, + key +) { + if (childVal && "development" !== 'production') { + assertObjectType(key, childVal, vm); + } if (!parentVal) { return childVal } var ret = Object.create(null); extend(ret, parentVal); @@ -1297,7 +1446,7 @@ function checkComponents (options) { * Ensure all props option syntax are normalized into the * Object-based format. */ -function normalizeProps (options) { +function normalizeProps (options, vm) { var props = options.props; if (!props) { return } var res = {}; @@ -1321,6 +1470,12 @@ function normalizeProps (options) { ? val : { type: val }; } + } else if ("development" !== 'production' && props) { + warn( + "Invalid value for option \"props\": expected an Array or an Object, " + + "but got " + (toRawType(props)) + ".", + vm + ); } options.props = res; } @@ -1328,13 +1483,26 @@ function normalizeProps (options) { /** * Normalize all injections into Object-based format */ -function normalizeInject (options) { +function normalizeInject (options, vm) { var inject = options.inject; + var normalized = options.inject = {}; if (Array.isArray(inject)) { - var normalized = options.inject = {}; for (var i = 0; i < inject.length; i++) { - normalized[inject[i]] = inject[i]; + normalized[inject[i]] = { from: inject[i] }; } + } else if (isPlainObject(inject)) { + for (var key in inject) { + var val = inject[key]; + normalized[key] = isPlainObject(val) + ? extend({ from: key }, val) + : { from: val }; + } + } else if ("development" !== 'production' && inject) { + warn( + "Invalid value for option \"inject\": expected an Array or an Object, " + + "but got " + (toRawType(inject)) + ".", + vm + ); } } @@ -1353,6 +1521,16 @@ function normalizeDirectives (options) { } } +function assertObjectType (name, value, vm) { + if (!isPlainObject(value)) { + warn( + "Invalid value for option \"" + name + "\": expected an Object, " + + "but got " + (toRawType(value)) + ".", + vm + ); + } +} + /** * Merge two option objects into a new one. * Core utility used in both instantiation and inheritance. @@ -1370,8 +1548,8 @@ function mergeOptions ( child = child.options; } - normalizeProps(child); - normalizeInject(child); + normalizeProps(child, vm); + normalizeInject(child, vm); normalizeDirectives(child); var extendsFrom = child.extends; if (extendsFrom) { @@ -1535,9 +1713,9 @@ function assertProp ( } if (!valid) { warn( - 'Invalid prop: type check failed for prop "' + name + '".' + - ' Expected ' + expectedTypes.map(capitalize).join(', ') + - ', got ' + Object.prototype.toString.call(value).slice(8, -1) + '.', + "Invalid prop: type check failed for prop \"" + name + "\"." + + " Expected " + (expectedTypes.map(capitalize).join(', ')) + + ", got " + (toRawType(value)) + ".", vm ); return @@ -1641,8 +1819,10 @@ var initProxy; var warnNonPresent = function (target, key) { warn( "Property or method \"" + key + "\" is not defined on the instance but " + - "referenced during render. Make sure to declare reactive data " + - "properties in the data option.", + 'referenced during render. Make sure that this property is reactive, ' + + 'either in the data option, or for class-based components, by ' + + 'initializing the property. ' + + 'See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.', target ); }; @@ -1652,7 +1832,7 @@ var initProxy; Proxy.toString().match(/native code/); if (hasProxy) { - var isBuiltInModifier = makeMap('stop,prevent,self,ctrl,shift,alt,meta'); + var isBuiltInModifier = makeMap('stop,prevent,self,ctrl,shift,alt,meta,exact'); config.keyCodes = new Proxy(config.keyCodes, { set: function set (target, key, value) { if (isBuiltInModifier(key)) { @@ -1702,99 +1882,6 @@ var initProxy; /* */ -var VNode = function VNode ( - tag, - data, - children, - text, - elm, - context, - componentOptions, - asyncFactory -) { - this.tag = tag; - this.data = data; - this.children = children; - this.text = text; - this.elm = elm; - this.ns = undefined; - this.context = context; - this.functionalContext = undefined; - this.key = data && data.key; - this.componentOptions = componentOptions; - this.componentInstance = undefined; - this.parent = undefined; - this.raw = false; - this.isStatic = false; - this.isRootInsert = true; - this.isComment = false; - this.isCloned = false; - this.isOnce = false; - this.asyncFactory = asyncFactory; - this.asyncMeta = undefined; - this.isAsyncPlaceholder = false; -}; - -var prototypeAccessors = { child: {} }; - -// DEPRECATED: alias for componentInstance for backwards compat. -/* istanbul ignore next */ -prototypeAccessors.child.get = function () { - return this.componentInstance -}; - -Object.defineProperties( VNode.prototype, prototypeAccessors ); - -var createEmptyVNode = function (text) { - if ( text === void 0 ) text = ''; - - var node = new VNode(); - node.text = text; - node.isComment = true; - return node -}; - -function createTextVNode (val) { - return new VNode(undefined, undefined, undefined, String(val)) -} - -// optimized shallow clone -// used for static nodes and slot nodes because they may be reused across -// multiple renders, cloning them avoids errors when DOM manipulations rely -// on their elm reference. -function cloneVNode (vnode, deep) { - var cloned = new VNode( - vnode.tag, - vnode.data, - vnode.children, - vnode.text, - vnode.elm, - vnode.context, - vnode.componentOptions, - vnode.asyncFactory - ); - cloned.ns = vnode.ns; - cloned.isStatic = vnode.isStatic; - cloned.key = vnode.key; - cloned.isComment = vnode.isComment; - cloned.isCloned = true; - if (deep && vnode.children) { - cloned.children = cloneVNodes(vnode.children); - } - return cloned -} - -function cloneVNodes (vnodes, deep) { - var len = vnodes.length; - var res = new Array(len); - for (var i = 0; i < len; i++) { - res[i] = cloneVNode(vnodes[i], deep); - } - return res -} - -/* */ - var normalizeEvent = cached(function (name) { var passive = name.charAt(0) === '&'; name = passive ? name.slice(1) : name; @@ -1802,10 +1889,8 @@ var normalizeEvent = cached(function (name) { name = once$$1 ? name.slice(1) : name; var capture = name.charAt(0) === '!'; name = capture ? name.slice(1) : name; - var plain = !(passive || once$$1 || capture); return { name: name, - plain: plain, once: once$$1, capture: capture, passive: passive @@ -1831,11 +1916,6 @@ function createFnInvoker (fns) { return invoker } -// #6552 -function prioritizePlainEvents (a, b) { - return a.plain ? -1 : b.plain ? 1 : 0 -} - function updateListeners ( on, oldOn, @@ -1844,13 +1924,10 @@ function updateListeners ( vm ) { var name, cur, old, event; - var toAdd = []; - var hasModifier = false; for (name in on) { cur = on[name]; old = oldOn[name]; event = normalizeEvent(name); - if (!event.plain) { hasModifier = true; } if (isUndef(cur)) { "development" !== 'production' && warn( "Invalid handler for event \"" + (event.name) + "\": got " + String(cur), @@ -1860,20 +1937,12 @@ function updateListeners ( if (isUndef(cur.fns)) { cur = on[name] = createFnInvoker(cur); } - event.handler = cur; - toAdd.push(event); + add(event.name, cur, event.once, event.capture, event.passive); } else if (cur !== old) { old.fns = cur; on[name] = old; } } - if (toAdd.length) { - if (hasModifier) { toAdd.sort(prioritizePlainEvents); } - for (var i = 0; i < toAdd.length; i++) { - var event$1 = toAdd[i]; - add(event$1.name, event$1.handler, event$1.once, event$1.capture, event$1.passive); - } - } for (name in oldOn) { if (isUndef(on[name])) { event = normalizeEvent(name); @@ -2023,20 +2092,27 @@ function isTextNode (node) { function normalizeArrayChildren (children, nestedIndex) { var res = []; - var i, c, last; + var i, c, lastIndex, last; for (i = 0; i < children.length; i++) { c = children[i]; if (isUndef(c) || typeof c === 'boolean') { continue } - last = res[res.length - 1]; + lastIndex = res.length - 1; + last = res[lastIndex]; // nested - if (Array.isArray(c)) { - res.push.apply(res, normalizeArrayChildren(c, ((nestedIndex || '') + "_" + i))); + if (Array.isArray(c) && c.length > 0) { + c = normalizeArrayChildren(c, ((nestedIndex || '') + "_" + i)); + // merge adjacent text nodes + if (isTextNode(c[0]) && isTextNode(last)) { + res[lastIndex] = createTextVNode(last.text + (c[0]).text); + c.shift(); + } + res.push.apply(res, c); } else if (isPrimitive(c)) { if (isTextNode(last)) { // merge adjacent text nodes // this is necessary for SSR hydration because text nodes are // essentially merged when rendered to HTML strings - (last).text += String(c); + res[lastIndex] = createTextVNode(last.text + c); } else if (c !== '') { // convert primitive to vnode res.push(createTextVNode(c)); @@ -2044,7 +2120,7 @@ function normalizeArrayChildren (children, nestedIndex) { } else { if (isTextNode(c) && isTextNode(last)) { // merge adjacent text nodes - res[res.length - 1] = createTextVNode(last.text + c.text); + res[lastIndex] = createTextVNode(last.text + c.text); } else { // default key for nested array children (likely generated by v-for) if (isTrue(children._isVList) && @@ -2063,7 +2139,10 @@ function normalizeArrayChildren (children, nestedIndex) { /* */ function ensureCtor (comp, base) { - if (comp.__esModule && comp.default) { + if ( + comp.__esModule || + (hasSymbol && comp[Symbol.toStringTag] === 'Module') + ) { comp = comp.default; } return isObject(comp) @@ -2219,8 +2298,8 @@ function initEvents (vm) { var target; -function add (event, fn, once$$1) { - if (once$$1) { +function add (event, fn, once) { + if (once) { target.$once(event, fn); } else { target.$on(event, fn); @@ -2523,6 +2602,10 @@ function lifecycleMixin (Vue) { if (vm.$el) { vm.$el.__vue__ = null; } + // release circular reference (#6759) + if (vm.$vnode) { + vm.$vnode.parent = null; + } }; } @@ -2566,12 +2649,12 @@ function mountComponent ( mark(startTag); var vnode = vm._render(); mark(endTag); - measure((name + " render"), startTag, endTag); + measure(("vue " + name + " render"), startTag, endTag); mark(startTag); vm._update(vnode, hydrating); mark(endTag); - measure((name + " patch"), startTag, endTag); + measure(("vue " + name + " patch"), startTag, endTag); }; } else { updateComponent = function () { @@ -3129,16 +3212,6 @@ function initState (vm) { } } -function checkOptionType (vm, name) { - var option = vm.$options[name]; - if (!isPlainObject(option)) { - warn( - ("component option \"" + name + "\" should be an object."), - vm - ); - } -} - function initProps (vm, propsOptions) { var propsData = vm.$options.propsData || {}; var props = vm._props = {}; @@ -3153,13 +3226,15 @@ function initProps (vm, propsOptions) { var value = validateProp(key, propsOptions, propsData, vm); /* istanbul ignore else */ { - if (isReservedAttribute(key) || config.isReservedAttr(key)) { + var hyphenatedKey = hyphenate(key); + if (isReservedAttribute(hyphenatedKey) || + config.isReservedAttr(hyphenatedKey)) { warn( - ("\"" + key + "\" is a reserved attribute and cannot be used as component prop."), + ("\"" + hyphenatedKey + "\" is a reserved attribute and cannot be used as component prop."), vm ); } - defineReactive$$1(props, key, value, function () { + defineReactive(props, key, value, function () { if (vm.$parent && !isUpdatingChildComponent) { warn( "Avoid mutating a prop directly since the value will be " + @@ -3227,7 +3302,7 @@ function initData (vm) { function getData (data, vm) { try { - return data.call(vm) + return data.call(vm, vm) } catch (e) { handleError(e, vm, "data()"); return {} @@ -3237,7 +3312,6 @@ function getData (data, vm) { var computedWatcherOptions = { lazy: true }; function initComputed (vm, computed) { - "development" !== 'production' && checkOptionType(vm, 'computed'); var watchers = vm._computedWatchers = Object.create(null); // computed properties are just getters during SSR var isSSR = isServerRendering(); @@ -3326,7 +3400,6 @@ function createComputedGetter (key) { } function initMethods (vm, methods) { - "development" !== 'production' && checkOptionType(vm, 'methods'); var props = vm.$options.props; for (var key in methods) { { @@ -3355,7 +3428,6 @@ function initMethods (vm, methods) { } function initWatch (vm, watch) { - "development" !== 'production' && checkOptionType(vm, 'watch'); for (var key in watch) { var handler = watch[key]; if (Array.isArray(handler)) { @@ -3449,7 +3521,7 @@ function initInjections (vm) { Object.keys(result).forEach(function (key) { /* istanbul ignore else */ { - defineReactive$$1(vm, key, result[key], function () { + defineReactive(vm, key, result[key], function () { warn( "Avoid mutating an injected value directly since the changes will be " + "overwritten whenever the provided component re-renders. " + @@ -3476,7 +3548,7 @@ function resolveInject (inject, vm) { for (var i = 0; i < keys.length; i++) { var key = keys[i]; - var provideKey = inject[key]; + var provideKey = inject[key].from; var source = vm; while (source) { if (source._provided && provideKey in source._provided) { @@ -3485,8 +3557,15 @@ function resolveInject (inject, vm) { } source = source.$parent; } - if ("development" !== 'production' && !source) { - warn(("Injection \"" + key + "\" not found"), vm); + if (!source) { + if ('default' in inject[key]) { + var provideDefault = inject[key].default; + result[key] = typeof provideDefault === 'function' + ? provideDefault.call(vm) + : provideDefault; + } else { + warn(("Injection \"" + key + "\" not found"), vm); + } } } return result @@ -3495,15 +3574,327 @@ function resolveInject (inject, vm) { /* */ +/** + * Runtime helper for rendering v-for lists. + */ +function renderList ( + val, + render +) { + var ret, i, l, keys, key; + if (Array.isArray(val) || typeof val === 'string') { + ret = new Array(val.length); + for (i = 0, l = val.length; i < l; i++) { + ret[i] = render(val[i], i); + } + } else if (typeof val === 'number') { + ret = new Array(val); + for (i = 0; i < val; i++) { + ret[i] = render(i + 1, i); + } + } else if (isObject(val)) { + keys = Object.keys(val); + ret = new Array(keys.length); + for (i = 0, l = keys.length; i < l; i++) { + key = keys[i]; + ret[i] = render(val[key], key, i); + } + } + if (isDef(ret)) { + (ret)._isVList = true; + } + return ret +} + +/* */ + +/** + * Runtime helper for rendering + */ +function renderSlot ( + name, + fallback, + props, + bindObject +) { + var scopedSlotFn = this.$scopedSlots[name]; + if (scopedSlotFn) { // scoped slot + props = props || {}; + if (bindObject) { + if ("development" !== 'production' && !isObject(bindObject)) { + warn( + 'slot v-bind without argument expects an Object', + this + ); + } + props = extend(extend({}, bindObject), props); + } + return scopedSlotFn(props) || fallback + } else { + var slotNodes = this.$slots[name]; + // warn duplicate slot usage + if (slotNodes && "development" !== 'production') { + slotNodes._rendered && warn( + "Duplicate presence of slot \"" + name + "\" found in the same render tree " + + "- this will likely cause render errors.", + this + ); + slotNodes._rendered = true; + } + return slotNodes || fallback + } +} + +/* */ + +/** + * Runtime helper for resolving filters + */ +function resolveFilter (id) { + return resolveAsset(this.$options, 'filters', id, true) || identity +} + +/* */ + +/** + * Runtime helper for checking keyCodes from config. + * exposed as Vue.prototype._k + * passing in eventKeyName as last argument separately for backwards compat + */ +function checkKeyCodes ( + eventKeyCode, + key, + builtInAlias, + eventKeyName +) { + var keyCodes = config.keyCodes[key] || builtInAlias; + if (keyCodes) { + if (Array.isArray(keyCodes)) { + return keyCodes.indexOf(eventKeyCode) === -1 + } else { + return keyCodes !== eventKeyCode + } + } else if (eventKeyName) { + return hyphenate(eventKeyName) !== key + } +} + +/* */ + +/** + * Runtime helper for merging v-bind="object" into a VNode's data. + */ +function bindObjectProps ( + data, + tag, + value, + asProp, + isSync +) { + if (value) { + if (!isObject(value)) { + "development" !== 'production' && warn( + 'v-bind without argument expects an Object or Array value', + this + ); + } else { + if (Array.isArray(value)) { + value = toObject(value); + } + var hash; + var loop = function ( key ) { + if ( + key === 'class' || + key === 'style' || + isReservedAttribute(key) + ) { + hash = data; + } else { + var type = data.attrs && data.attrs.type; + hash = asProp || config.mustUseProp(tag, type, key) + ? data.domProps || (data.domProps = {}) + : data.attrs || (data.attrs = {}); + } + if (!(key in hash)) { + hash[key] = value[key]; + + if (isSync) { + var on = data.on || (data.on = {}); + on[("update:" + key)] = function ($event) { + value[key] = $event; + }; + } + } + }; + + for (var key in value) loop( key ); + } + } + return data +} + +/* */ + +/** + * Runtime helper for rendering static trees. + */ +function renderStatic ( + index, + isInFor +) { + // static trees can be rendered once and cached on the contructor options + // so every instance shares the same cached trees + var renderFns = this.$options.staticRenderFns; + var cached = renderFns.cached || (renderFns.cached = []); + var tree = cached[index]; + // if has already-rendered static tree and not inside v-for, + // we can reuse the same tree by doing a shallow clone. + if (tree && !isInFor) { + return Array.isArray(tree) + ? cloneVNodes(tree) + : cloneVNode(tree) + } + // otherwise, render a fresh tree. + tree = cached[index] = renderFns[index].call(this._renderProxy, null, this); + markStatic(tree, ("__static__" + index), false); + return tree +} + +/** + * Runtime helper for v-once. + * Effectively it means marking the node as static with a unique key. + */ +function markOnce ( + tree, + index, + key +) { + markStatic(tree, ("__once__" + index + (key ? ("_" + key) : "")), true); + return tree +} + +function markStatic ( + tree, + key, + isOnce +) { + if (Array.isArray(tree)) { + for (var i = 0; i < tree.length; i++) { + if (tree[i] && typeof tree[i] !== 'string') { + markStaticNode(tree[i], (key + "_" + i), isOnce); + } + } + } else { + markStaticNode(tree, key, isOnce); + } +} + +function markStaticNode (node, key, isOnce) { + node.isStatic = true; + node.key = key; + node.isOnce = isOnce; +} + +/* */ + +function bindObjectListeners (data, value) { + if (value) { + if (!isPlainObject(value)) { + "development" !== 'production' && warn( + 'v-on without argument expects an Object value', + this + ); + } else { + var on = data.on = data.on ? extend({}, data.on) : {}; + for (var key in value) { + var existing = on[key]; + var ours = value[key]; + on[key] = existing ? [].concat(ours, existing) : ours; + } + } + } + return data +} + +/* */ + +function installRenderHelpers (target) { + target._o = markOnce; + target._n = toNumber; + target._s = toString; + target._l = renderList; + target._t = renderSlot; + target._q = looseEqual; + target._i = looseIndexOf; + target._m = renderStatic; + target._f = resolveFilter; + target._k = checkKeyCodes; + target._b = bindObjectProps; + target._v = createTextVNode; + target._e = createEmptyVNode; + target._u = resolveScopedSlots; + target._g = bindObjectListeners; +} + +/* */ + +function FunctionalRenderContext ( + data, + props, + children, + parent, + Ctor +) { + var options = Ctor.options; + this.data = data; + this.props = props; + this.children = children; + this.parent = parent; + this.listeners = data.on || emptyObject; + this.injections = resolveInject(options.inject, parent); + this.slots = function () { return resolveSlots(children, parent); }; + + // ensure the createElement function in functional components + // gets a unique context - this is necessary for correct named slot check + var contextVm = Object.create(parent); + var isCompiled = isTrue(options._compiled); + var needNormalization = !isCompiled; + + // support for compiled functional template + if (isCompiled) { + // exposing $options for renderStatic() + this.$options = options; + // pre-resolve slots for renderSlot() + this.$slots = this.slots(); + this.$scopedSlots = data.scopedSlots || emptyObject; + } + + if (options._scopeId) { + this._c = function (a, b, c, d) { + var vnode = createElement(contextVm, a, b, c, d, needNormalization); + if (vnode) { + vnode.functionalScopeId = options._scopeId; + vnode.functionalContext = parent; + } + return vnode + }; + } else { + this._c = function (a, b, c, d) { return createElement(contextVm, a, b, c, d, needNormalization); }; + } +} + +installRenderHelpers(FunctionalRenderContext.prototype); + function createFunctionalComponent ( Ctor, propsData, data, - context, + contextVm, children ) { + var options = Ctor.options; var props = {}; - var propOptions = Ctor.options.props; + var propOptions = options.props; if (isDef(propOptions)) { for (var key in propOptions) { props[key] = validateProp(key, propOptions, propsData || emptyObject); @@ -3512,26 +3903,25 @@ function createFunctionalComponent ( if (isDef(data.attrs)) { mergeProps(props, data.attrs); } if (isDef(data.props)) { mergeProps(props, data.props); } } - // ensure the createElement function in functional components - // gets a unique context - this is necessary for correct named slot check - var _context = Object.create(context); - var h = function (a, b, c, d) { return createElement(_context, a, b, c, d, true); }; - var vnode = Ctor.options.render.call(null, h, { - data: data, - props: props, - children: children, - parent: context, - listeners: data.on || emptyObject, - injections: resolveInject(Ctor.options.inject, context), - slots: function () { return resolveSlots(children, context); } - }); + + var renderContext = new FunctionalRenderContext( + data, + props, + children, + contextVm, + Ctor + ); + + var vnode = options.render.call(null, renderContext._c, renderContext); + if (vnode instanceof VNode) { - vnode.functionalContext = context; - vnode.functionalOptions = Ctor.options; + vnode.functionalContext = contextVm; + vnode.functionalOptions = options; if (data.slot) { (vnode.data || (vnode.data = {})).slot = data.slot; } } + return vnode } @@ -3841,293 +4231,66 @@ function _createElement ( children = normalizeChildren(children); } else if (normalizationType === SIMPLE_NORMALIZE) { children = simpleNormalizeChildren(children); - } - var vnode, ns; - if (typeof tag === 'string') { - var Ctor; - ns = (context.$vnode && context.$vnode.ns) || config.getTagNamespace(tag); - if (config.isReservedTag(tag)) { - // platform built-in elements - vnode = new VNode( - config.parsePlatformTagName(tag), data, children, - undefined, undefined, context - ); - } else if (isDef(Ctor = resolveAsset(context.$options, 'components', tag))) { - // component - vnode = createComponent(Ctor, data, context, children, tag); - } else { - // unknown or unlisted namespaced elements - // check at runtime because it may get assigned a namespace when its - // parent normalizes children - vnode = new VNode( - tag, data, children, - undefined, undefined, context - ); - } - } else { - // direct component options / constructor - vnode = createComponent(tag, data, context, children); - } - if (isDef(vnode)) { - if (ns) { applyNS(vnode, ns); } - return vnode - } else { - return createEmptyVNode() - } -} - -function applyNS (vnode, ns) { - vnode.ns = ns; - if (vnode.tag === 'foreignObject') { - // use default namespace inside foreignObject - return - } - if (isDef(vnode.children)) { - for (var i = 0, l = vnode.children.length; i < l; i++) { - var child = vnode.children[i]; - if (isDef(child.tag) && isUndef(child.ns)) { - applyNS(child, ns); - } - } - } -} - -/* */ - -/** - * Runtime helper for rendering v-for lists. - */ -function renderList ( - val, - render -) { - var ret, i, l, keys, key; - if (Array.isArray(val) || typeof val === 'string') { - ret = new Array(val.length); - for (i = 0, l = val.length; i < l; i++) { - ret[i] = render(val[i], i); - } - } else if (typeof val === 'number') { - ret = new Array(val); - for (i = 0; i < val; i++) { - ret[i] = render(i + 1, i); - } - } else if (isObject(val)) { - keys = Object.keys(val); - ret = new Array(keys.length); - for (i = 0, l = keys.length; i < l; i++) { - key = keys[i]; - ret[i] = render(val[key], key, i); - } - } - if (isDef(ret)) { - (ret)._isVList = true; - } - return ret -} - -/* */ - -/** - * Runtime helper for rendering - */ -function renderSlot ( - name, - fallback, - props, - bindObject -) { - var scopedSlotFn = this.$scopedSlots[name]; - if (scopedSlotFn) { // scoped slot - props = props || {}; - if (bindObject) { - props = extend(extend({}, bindObject), props); - } - return scopedSlotFn(props) || fallback - } else { - var slotNodes = this.$slots[name]; - // warn duplicate slot usage - if (slotNodes && "development" !== 'production') { - slotNodes._rendered && warn( - "Duplicate presence of slot \"" + name + "\" found in the same render tree " + - "- this will likely cause render errors.", - this - ); - slotNodes._rendered = true; - } - return slotNodes || fallback - } -} - -/* */ - -/** - * Runtime helper for resolving filters - */ -function resolveFilter (id) { - return resolveAsset(this.$options, 'filters', id, true) || identity -} - -/* */ - -/** - * Runtime helper for checking keyCodes from config. - */ -function checkKeyCodes ( - eventKeyCode, - key, - builtInAlias -) { - var keyCodes = config.keyCodes[key] || builtInAlias; - if (Array.isArray(keyCodes)) { - return keyCodes.indexOf(eventKeyCode) === -1 - } else { - return keyCodes !== eventKeyCode - } -} - -/* */ - -/** - * Runtime helper for merging v-bind="object" into a VNode's data. - */ -function bindObjectProps ( - data, - tag, - value, - asProp, - isSync -) { - if (value) { - if (!isObject(value)) { - "development" !== 'production' && warn( - 'v-bind without argument expects an Object or Array value', - this - ); - } else { - if (Array.isArray(value)) { - value = toObject(value); - } - var hash; - var loop = function ( key ) { - if ( - key === 'class' || - key === 'style' || - isReservedAttribute(key) - ) { - hash = data; - } else { - var type = data.attrs && data.attrs.type; - hash = asProp || config.mustUseProp(tag, type, key) - ? data.domProps || (data.domProps = {}) - : data.attrs || (data.attrs = {}); - } - if (!(key in hash)) { - hash[key] = value[key]; - - if (isSync) { - var on = data.on || (data.on = {}); - on[("update:" + key)] = function ($event) { - value[key] = $event; - }; - } - } - }; - - for (var key in value) loop( key ); - } - } - return data -} - -/* */ - -/** - * Runtime helper for rendering static trees. - */ -function renderStatic ( - index, - isInFor -) { - var tree = this._staticTrees[index]; - // if has already-rendered static tree and not inside v-for, - // we can reuse the same tree by doing a shallow clone. - if (tree && !isInFor) { - return Array.isArray(tree) - ? cloneVNodes(tree) - : cloneVNode(tree) - } - // otherwise, render a fresh tree. - tree = this._staticTrees[index] = - this.$options.staticRenderFns[index].call(this._renderProxy); - markStatic(tree, ("__static__" + index), false); - return tree -} - -/** - * Runtime helper for v-once. - * Effectively it means marking the node as static with a unique key. - */ -function markOnce ( - tree, - index, - key -) { - markStatic(tree, ("__once__" + index + (key ? ("_" + key) : "")), true); - return tree -} - -function markStatic ( - tree, - key, - isOnce -) { - if (Array.isArray(tree)) { - for (var i = 0; i < tree.length; i++) { - if (tree[i] && typeof tree[i] !== 'string') { - markStaticNode(tree[i], (key + "_" + i), isOnce); - } + } + var vnode, ns; + if (typeof tag === 'string') { + var Ctor; + ns = (context.$vnode && context.$vnode.ns) || config.getTagNamespace(tag); + if (config.isReservedTag(tag)) { + // platform built-in elements + vnode = new VNode( + config.parsePlatformTagName(tag), data, children, + undefined, undefined, context + ); + } else if (isDef(Ctor = resolveAsset(context.$options, 'components', tag))) { + // component + vnode = createComponent(Ctor, data, context, children, tag); + } else { + // unknown or unlisted namespaced elements + // check at runtime because it may get assigned a namespace when its + // parent normalizes children + vnode = new VNode( + tag, data, children, + undefined, undefined, context + ); } } else { - markStaticNode(tree, key, isOnce); + // direct component options / constructor + vnode = createComponent(tag, data, context, children); + } + if (isDef(vnode)) { + if (ns) { applyNS(vnode, ns); } + return vnode + } else { + return createEmptyVNode() } } -function markStaticNode (node, key, isOnce) { - node.isStatic = true; - node.key = key; - node.isOnce = isOnce; -} - -/* */ - -function bindObjectListeners (data, value) { - if (value) { - if (!isPlainObject(value)) { - "development" !== 'production' && warn( - 'v-on without argument expects an Object value', - this - ); - } else { - var on = data.on = data.on ? extend({}, data.on) : {}; - for (var key in value) { - var existing = on[key]; - var ours = value[key]; - on[key] = existing ? [].concat(ours, existing) : ours; +function applyNS (vnode, ns, force) { + vnode.ns = ns; + if (vnode.tag === 'foreignObject') { + // use default namespace inside foreignObject + ns = undefined; + force = true; + } + if (isDef(vnode.children)) { + for (var i = 0, l = vnode.children.length; i < l; i++) { + var child = vnode.children[i]; + if (isDef(child.tag) && (isUndef(child.ns) || isTrue(force))) { + applyNS(child, ns, force); } } } - return data } /* */ function initRender (vm) { vm._vnode = null; // the root of the child tree - vm._staticTrees = null; - var parentVnode = vm.$vnode = vm.$options._parentVnode; // the placeholder node in parent tree + var options = vm.$options; + var parentVnode = vm.$vnode = options._parentVnode; // the placeholder node in parent tree var renderContext = parentVnode && parentVnode.context; - vm.$slots = resolveSlots(vm.$options._renderChildren, renderContext); + vm.$slots = resolveSlots(options._renderChildren, renderContext); vm.$scopedSlots = emptyObject; // bind the createElement fn to this instance // so that we get proper render context inside it. @@ -4144,16 +4307,19 @@ function initRender (vm) { /* istanbul ignore else */ { - defineReactive$$1(vm, '$attrs', parentData && parentData.attrs || emptyObject, function () { + defineReactive(vm, '$attrs', parentData && parentData.attrs || emptyObject, function () { !isUpdatingChildComponent && warn("$attrs is readonly.", vm); }, true); - defineReactive$$1(vm, '$listeners', vm.$options._parentListeners || emptyObject, function () { + defineReactive(vm, '$listeners', options._parentListeners || emptyObject, function () { !isUpdatingChildComponent && warn("$listeners is readonly.", vm); }, true); } } function renderMixin (Vue) { + // install runtime convenience helpers + installRenderHelpers(Vue.prototype); + Vue.prototype.$nextTick = function (fn) { return nextTick(fn, this) }; @@ -4162,7 +4328,6 @@ function renderMixin (Vue) { var vm = this; var ref = vm.$options; var render = ref.render; - var staticRenderFns = ref.staticRenderFns; var _parentVnode = ref._parentVnode; if (vm._isMounted) { @@ -4178,9 +4343,6 @@ function renderMixin (Vue) { vm.$scopedSlots = (_parentVnode && _parentVnode.data.scopedSlots) || emptyObject; - if (staticRenderFns && !vm._staticTrees) { - vm._staticTrees = []; - } // set parent vnode. this allows render functions to have access // to the data on the placeholder node. vm.$vnode = _parentVnode; @@ -4189,14 +4351,21 @@ function renderMixin (Vue) { try { vnode = render.call(vm._renderProxy, vm.$createElement); } catch (e) { - handleError(e, vm, "render function"); + handleError(e, vm, "render"); // return error render result, // or previous vnode to prevent render error causing blank component /* istanbul ignore else */ { - vnode = vm.$options.renderError - ? vm.$options.renderError.call(vm._renderProxy, vm.$createElement, e) - : vm._vnode; + if (vm.$options.renderError) { + try { + vnode = vm.$options.renderError.call(vm._renderProxy, vm.$createElement, e); + } catch (e) { + handleError(e, vm, "renderError"); + vnode = vm._vnode; + } + } else { + vnode = vm._vnode; + } } } // return empty vnode in case the render function errored out @@ -4214,25 +4383,6 @@ function renderMixin (Vue) { vnode.parent = _parentVnode; return vnode }; - - // internal render helpers. - // these are exposed on the instance prototype to reduce generated render - // code size. - Vue.prototype._o = markOnce; - Vue.prototype._n = toNumber; - Vue.prototype._s = toString; - Vue.prototype._l = renderList; - Vue.prototype._t = renderSlot; - Vue.prototype._q = looseEqual; - Vue.prototype._i = looseIndexOf; - Vue.prototype._m = renderStatic; - Vue.prototype._f = resolveFilter; - Vue.prototype._k = checkKeyCodes; - Vue.prototype._b = bindObjectProps; - Vue.prototype._v = createTextVNode; - Vue.prototype._e = createEmptyVNode; - Vue.prototype._u = resolveScopedSlots; - Vue.prototype._g = bindObjectListeners; } /* */ @@ -4248,7 +4398,7 @@ function initMixin (Vue) { var startTag, endTag; /* istanbul ignore if */ if ("development" !== 'production' && config.performance && mark) { - startTag = "vue-perf-init:" + (vm._uid); + startTag = "vue-perf-start:" + (vm._uid); endTag = "vue-perf-end:" + (vm._uid); mark(startTag); } @@ -4287,7 +4437,7 @@ function initMixin (Vue) { if ("development" !== 'production' && config.performance && mark) { vm._name = formatComponentName(vm, false); mark(endTag); - measure(((vm._name) + " init"), startTag, endTag); + measure(("vue " + (vm._name) + " init"), startTag, endTag); } if (vm.$options.el) { @@ -4553,8 +4703,6 @@ function initAssetRegisters (Vue) { /* */ -var patternTypes = [String, RegExp, Array]; - function getComponentName (opts) { return opts && (opts.Ctor.options.name || opts.tag) } @@ -4571,54 +4719,66 @@ function matches (pattern, name) { return false } -function pruneCache (cache, current, filter) { +function pruneCache (keepAliveInstance, filter) { + var cache = keepAliveInstance.cache; + var keys = keepAliveInstance.keys; + var _vnode = keepAliveInstance._vnode; for (var key in cache) { var cachedNode = cache[key]; if (cachedNode) { var name = getComponentName(cachedNode.componentOptions); if (name && !filter(name)) { - if (cachedNode !== current) { - pruneCacheEntry(cachedNode); - } - cache[key] = null; + pruneCacheEntry(cache, key, keys, _vnode); } } } } -function pruneCacheEntry (vnode) { - if (vnode) { - vnode.componentInstance.$destroy(); +function pruneCacheEntry ( + cache, + key, + keys, + current +) { + var cached$$1 = cache[key]; + if (cached$$1 && cached$$1 !== current) { + cached$$1.componentInstance.$destroy(); } + cache[key] = null; + remove(keys, key); } +var patternTypes = [String, RegExp, Array]; + var KeepAlive = { name: 'keep-alive', abstract: true, props: { include: patternTypes, - exclude: patternTypes + exclude: patternTypes, + max: [String, Number] }, created: function created () { this.cache = Object.create(null); + this.keys = []; }, destroyed: function destroyed () { var this$1 = this; for (var key in this$1.cache) { - pruneCacheEntry(this$1.cache[key]); + pruneCacheEntry(this$1.cache, key, this$1.keys); } }, watch: { include: function include (val) { - pruneCache(this.cache, this._vnode, function (name) { return matches(val, name); }); + pruneCache(this, function (name) { return matches(val, name); }); }, exclude: function exclude (val) { - pruneCache(this.cache, this._vnode, function (name) { return !matches(val, name); }); + pruneCache(this, function (name) { return !matches(val, name); }); } }, @@ -4634,16 +4794,29 @@ var KeepAlive = { )) { return vnode } + + var ref = this; + var cache = ref.cache; + var keys = ref.keys; var key = vnode.key == null // same constructor may get registered as different local components // so cid alone is not enough (#3269) ? componentOptions.Ctor.cid + (componentOptions.tag ? ("::" + (componentOptions.tag)) : '') : vnode.key; - if (this.cache[key]) { - vnode.componentInstance = this.cache[key].componentInstance; + if (cache[key]) { + vnode.componentInstance = cache[key].componentInstance; + // make current key freshest + remove(keys, key); + keys.push(key); } else { - this.cache[key] = vnode; + cache[key] = vnode; + keys.push(key); + // prune oldest entry + if (this.max && keys.length > parseInt(this.max)) { + pruneCacheEntry(cache, keys[0], keys, this._vnode); + } } + vnode.data.keepAlive = true; } return vnode @@ -4676,7 +4849,7 @@ function initGlobalAPI (Vue) { warn: warn, extend: extend, mergeOptions: mergeOptions, - defineReactive: defineReactive$$1 + defineReactive: defineReactive }; Vue.set = set; @@ -4713,7 +4886,7 @@ Object.defineProperty(Vue$3.prototype, '$ssrContext', { } }); -Vue$3.version = '2.4.4'; +Vue$3.version = '2.5.0'; /* */ @@ -5123,13 +5296,13 @@ function createPatchFunction (backend) { } function createRmCb (childElm, listeners) { - function remove$$1 () { - if (--remove$$1.listeners === 0) { + function remove () { + if (--remove.listeners === 0) { removeNode(childElm); } } - remove$$1.listeners = listeners; - return remove$$1 + remove.listeners = listeners; + return remove } function removeNode (el) { @@ -5158,7 +5331,14 @@ function createPatchFunction (backend) { if ( !inPre && !vnode.ns && - !(config.ignoredElements.length && config.ignoredElements.indexOf(tag) > -1) && + !( + config.ignoredElements.length && + config.ignoredElements.some(function (ignore) { + return isRegExp(ignore) + ? ignore.test(tag) + : ignore === tag + }) + ) && config.isUnknownElement(tag) ) { warn( @@ -5301,16 +5481,21 @@ function createPatchFunction (backend) { // of going through the normal attribute patching process. function setScope (vnode) { var i; - var ancestor = vnode; - while (ancestor) { - if (isDef(i = ancestor.context) && isDef(i = i.$options._scopeId)) { - nodeOps.setAttribute(vnode.elm, i, ''); + if (isDef(i = vnode.functionalScopeId)) { + nodeOps.setAttribute(vnode.elm, i, ''); + } else { + var ancestor = vnode; + while (ancestor) { + if (isDef(i = ancestor.context) && isDef(i = i.$options._scopeId)) { + nodeOps.setAttribute(vnode.elm, i, ''); + } + ancestor = ancestor.parent; } - ancestor = ancestor.parent; } // for slot content they should also get the scopeId from the host instance. if (isDef(i = activeInstance) && i !== vnode.context && + i !== vnode.functionalContext && isDef(i = i.$options._scopeId) ) { nodeOps.setAttribute(vnode.elm, i, ''); @@ -5389,7 +5574,7 @@ function createPatchFunction (backend) { var newEndIdx = newCh.length - 1; var newStartVnode = newCh[0]; var newEndVnode = newCh[newEndIdx]; - var oldKeyToIdx, idxInOld, elmToMove, refElm; + var oldKeyToIdx, idxInOld, vnodeToMove, refElm; // removeOnly is a special flag used only by // to ensure removed elements stay in correct relative positions @@ -5427,18 +5612,18 @@ function createPatchFunction (backend) { if (isUndef(idxInOld)) { // New element createElm(newStartVnode, insertedVnodeQueue, parentElm, oldStartVnode.elm); } else { - elmToMove = oldCh[idxInOld]; + vnodeToMove = oldCh[idxInOld]; /* istanbul ignore if */ - if ("development" !== 'production' && !elmToMove) { + if ("development" !== 'production' && !vnodeToMove) { warn( 'It seems there are duplicate keys that is causing an update error. ' + 'Make sure each v-for item has a unique key.' ); } - if (sameVnode(elmToMove, newStartVnode)) { - patchVnode(elmToMove, newStartVnode, insertedVnodeQueue); + if (sameVnode(vnodeToMove, newStartVnode)) { + patchVnode(vnodeToMove, newStartVnode, insertedVnodeQueue); oldCh[idxInOld] = undefined; - canMove && nodeOps.insertBefore(parentElm, elmToMove.elm, oldStartVnode.elm); + canMove && nodeOps.insertBefore(parentElm, vnodeToMove.elm, oldStartVnode.elm); } else { // same key but different element. treat as new element createElm(newStartVnode, insertedVnodeQueue, parentElm, oldStartVnode.elm); @@ -5719,6 +5904,8 @@ function createPatchFunction (backend) { insert.fns[i$2](); } } + } else { + registerRef(ancestor); } ancestor = ancestor.parent; } @@ -5882,8 +6069,9 @@ function updateAttrs (oldVnode, vnode) { } } // #4391: in IE9, setting type can reset value for input[type=radio] + // #6666: IE/Edge forces progress value down to 1 before setting a max /* istanbul ignore if */ - if (isIE9 && attrs.value !== oldAttrs.value) { + if ((isIE9 || isEdge) && attrs.value !== oldAttrs.value) { setAttr(elm, 'value', attrs.value); } for (key in oldAttrs) { @@ -6173,7 +6361,15 @@ function getBindingAttr ( } } -function getAndRemoveAttr (el, name) { +// note: this only removes the attr from the Array (attrsList) so that it +// doesn't get processed by processAttrs. +// By default it does NOT remove it from the map (attrsMap) because the map is +// needed during codegen. +function getAndRemoveAttr ( + el, + name, + removeFromMap +) { var val; if ((val = el.attrsMap[name]) != null) { var list = el.attrsList; @@ -6184,6 +6380,9 @@ function getAndRemoveAttr (el, name) { } } } + if (removeFromMap) { + delete el.attrsMap[name]; + } return val } @@ -6228,25 +6427,26 @@ function genAssignmentCode ( value, assignment ) { - var modelRs = parseModel(value); - if (modelRs.idx === null) { + var res = parseModel(value); + if (res.key === null) { return (value + "=" + assignment) } else { - return ("$set(" + (modelRs.exp) + ", " + (modelRs.idx) + ", " + assignment + ")") + return ("$set(" + (res.exp) + ", " + (res.key) + ", " + assignment + ")") } } /** - * parse directive model to do the array update transform. a[idx] = val => $$a.splice($$idx, 1, val) + * Parse a v-model expression into a base path and a final key segment. + * Handles both dot-path and possible square brackets. * - * for loop possible cases: + * Possible cases: * * - test - * - test[idx] - * - test[test1[idx]] - * - test["a"][idx] - * - xxx.test[a[a].test1[idx]] - * - test.xxx.a["asa"][test1[idx]] + * - test[key] + * - test[test1[key]] + * - test["a"][key] + * - xxx.test[a[a].test1[key]] + * - test.xxx.a["asa"][test1[key]] * */ @@ -6257,18 +6457,29 @@ var index$1; var expressionPos; var expressionEndPos; + + function parseModel (val) { - str = val; - len = str.length; - index$1 = expressionPos = expressionEndPos = 0; + len = val.length; if (val.indexOf('[') < 0 || val.lastIndexOf(']') < len - 1) { - return { - exp: val, - idx: null + index$1 = val.lastIndexOf('.'); + if (index$1 > -1) { + return { + exp: val.slice(0, index$1), + key: '"' + val.slice(index$1 + 1) + '"' + } + } else { + return { + exp: val, + key: null + } } } + str = val; + index$1 = expressionPos = expressionEndPos = 0; + while (!eof()) { chr = next(); /* istanbul ignore if */ @@ -6280,8 +6491,8 @@ function parseModel (val) { } return { - exp: val.substring(0, expressionPos), - idx: val.substring(expressionPos + 1, expressionEndPos) + exp: val.slice(0, expressionPos), + key: val.slice(expressionPos + 1, expressionEndPos) } } @@ -6332,7 +6543,6 @@ var warn$1; // in some cases, the event used has to be determined at runtime // so we used some reserved tokens during compile. var RANGE_TOKEN = '__r'; -var CHECKBOX_RADIO_TOKEN = '__c'; function model ( el, @@ -6346,13 +6556,6 @@ function model ( var type = el.attrsMap.type; { - var dynamicType = el.attrsMap['v-bind:type'] || el.attrsMap[':type']; - if (tag === 'input' && dynamicType) { - warn$1( - ":\n" + - "v-model does not support dynamic input types. Use v-if branches instead." - ); - } // inputs with type="file" are read only and setting the input's // value will throw an error. if (tag === 'input' && type === 'file') { @@ -6409,7 +6612,7 @@ function genCheckboxModel ( : (":_q(" + value + "," + trueValueBinding + ")") ) ); - addHandler(el, CHECKBOX_RADIO_TOKEN, + addHandler(el, 'change', "var $$a=" + value + "," + '$$el=$event.target,' + "$$c=$$el.checked?(" + trueValueBinding + "):(" + falseValueBinding + ");" + @@ -6432,7 +6635,7 @@ function genRadioModel ( var valueBinding = getBindingAttr(el, 'value') || 'null'; valueBinding = number ? ("_n(" + valueBinding + ")") : valueBinding; addProp(el, 'checked', ("_q(" + value + "," + valueBinding + ")")); - addHandler(el, CHECKBOX_RADIO_TOKEN, genAssignmentCode(value, valueBinding), null, true); + addHandler(el, 'change', genAssignmentCode(value, valueBinding), null, true); } function genSelect ( @@ -6496,20 +6699,13 @@ function genDefaultModel ( // the whole point is ensuring the v-model callback gets called before // user-attached handlers. function normalizeEvents (on) { - var event; /* istanbul ignore if */ if (isDef(on[RANGE_TOKEN])) { // IE input[type=range] only supports `change` event - event = isIE ? 'change' : 'input'; + var event = isIE ? 'change' : 'input'; on[event] = [].concat(on[RANGE_TOKEN], on[event] || []); delete on[RANGE_TOKEN]; } - if (isDef(on[CHECKBOX_RADIO_TOKEN])) { - // Chrome fires microtasks in between click/change, leads to #4521 - event = isChrome ? 'click' : 'change'; - on[event] = [].concat(on[CHECKBOX_RADIO_TOKEN], on[event] || []); - delete on[CHECKBOX_RADIO_TOKEN]; - } } var target$1; @@ -6595,6 +6791,11 @@ function updateDOMProps (oldVnode, vnode) { if (key === 'textContent' || key === 'innerHTML') { if (vnode.children) { vnode.children.length = 0; } if (cur === oldProps[key]) { continue } + // #6601 work around Chrome version <= 55 bug where single textNode + // replaced by innerHTML/textContent retains its parentNode property + if (elm.childNodes.length === 1) { + elm.removeChild(elm.childNodes[0]); + } } if (key === 'value') { @@ -6603,7 +6804,7 @@ function updateDOMProps (oldVnode, vnode) { elm._value = cur; // avoid resetting cursor position when value is the same var strCur = isUndef(cur) ? '' : String(cur); - if (shouldUpdateValue(elm, vnode, strCur)) { + if (shouldUpdateValue(elm, strCur)) { elm.value = strCur; } } else { @@ -6615,13 +6816,9 @@ function updateDOMProps (oldVnode, vnode) { // check platforms/web/util/attrs.js acceptValue -function shouldUpdateValue ( - elm, - vnode, - checkVal -) { +function shouldUpdateValue (elm, checkVal) { return (!elm.composing && ( - vnode.tag === 'option' || + elm.tagName === 'OPTION' || isDirty(elm, checkVal) || isInputChanged(elm, checkVal) )) @@ -6876,20 +7073,20 @@ function removeClass (el, cls) { /* */ -function resolveTransition (def$$1) { - if (!def$$1) { +function resolveTransition (def) { + if (!def) { return } /* istanbul ignore else */ - if (typeof def$$1 === 'object') { + if (typeof def === 'object') { var res = {}; - if (def$$1.css !== false) { - extend(res, autoCssTransition(def$$1.name || 'v')); + if (def.css !== false) { + extend(res, autoCssTransition(def.name || 'v')); } - extend(res, def$$1); + extend(res, def); return res - } else if (typeof def$$1 === 'string') { - return autoCssTransition(def$$1) + } else if (typeof def === 'string') { + return autoCssTransition(def) } } @@ -6930,9 +7127,11 @@ if (hasTransition) { } // binding to window is necessary to make hot reload work in IE in strict mode -var raf = inBrowser && window.requestAnimationFrame - ? window.requestAnimationFrame.bind(window) - : setTimeout; +var raf = inBrowser + ? window.requestAnimationFrame + ? window.requestAnimationFrame.bind(window) + : setTimeout + : /* istanbul ignore next */ function (fn) { return fn(); }; function nextFrame (fn) { raf(function () { @@ -7748,7 +7947,7 @@ var Transition = { ) { // replace old child transition data with fresh one // important for dynamic transitions! - var oldData = oldChild && (oldChild.data.transition = extend({}, data)); + var oldData = oldChild.data.transition = extend({}, data); // handle transition mode if (mode === 'out-in') { // return placeholder node and queue update when leave finishes @@ -7865,9 +8064,6 @@ var TransitionGroup = { children.forEach(applyTranslation); // force reflow to put everything in position - var body = document.body; - var f = body.offsetHeight; // eslint-disable-line - children.forEach(function (c) { if (c.data.moved) { var el = c.elm; @@ -7974,7 +8170,7 @@ Vue$3.prototype.$mount = function ( // devtools global hook /* istanbul ignore next */ -setTimeout(function () { +Vue$3.nextTick(function () { if (config.devtools) { if (devtools) { devtools.emit('init', Vue$3); @@ -8135,31 +8331,16 @@ var style$1 = { genData: genData$1 }; -var modules$1 = [ - klass$1, - style$1 -]; - /* */ -function text (el, dir) { - if (dir.value) { - addProp(el, 'textContent', ("_s(" + (dir.value) + ")")); - } -} - -/* */ +var decoder; -function html (el, dir) { - if (dir.value) { - addProp(el, 'innerHTML', ("_s(" + (dir.value) + ")")); +var he = { + decode: function decode (html) { + decoder = decoder || document.createElement('div'); + decoder.innerHTML = html; + return decoder.textContent } -} - -var directives$1 = { - model: model, - text: text, - html: html }; /* */ @@ -8185,33 +8366,6 @@ var isNonPhrasingTag = makeMap( 'title,tr,track' ); -/* */ - -var baseOptions = { - expectHTML: true, - modules: modules$1, - directives: directives$1, - isPreTag: isPreTag, - isUnaryTag: isUnaryTag, - mustUseProp: mustUseProp, - canBeLeftOpenTag: canBeLeftOpenTag, - isReservedTag: isReservedTag, - getTagNamespace: getTagNamespace, - staticKeys: genStaticKeys(modules$1) -}; - -/* */ - -var decoder; - -var he = { - decode: function decode (html) { - decoder = decoder || document.createElement('div'); - decoder.innerHTML = html; - return decoder.textContent - } -}; - /** * Not type-checking this file because it's mostly vendor code. */ @@ -8541,6 +8695,23 @@ var platformIsPreTag; var platformMustUseProp; var platformGetTagNamespace; + + +function createASTElement ( + tag, + attrs, + parent +) { + return { + type: 1, + tag: tag, + attrsList: attrs, + attrsMap: makeAttrsMap(attrs), + parent: parent, + children: [] + } +} + /** * Convert HTML string to AST. */ @@ -8603,14 +8774,7 @@ function parse ( attrs = guardIESVGBug(attrs); } - var element = { - type: 1, - tag: tag, - attrsList: attrs, - attrsMap: makeAttrsMap(attrs), - parent: currentParent, - children: [] - }; + var element = createASTElement(tag, attrs, currentParent); if (ns) { element.ns = ns; } @@ -8626,7 +8790,7 @@ function parse ( // apply pre-transforms for (var i = 0; i < preTransforms.length; i++) { - preTransforms[i](element, options); + element = preTransforms[i](element, options) || element; } if (!inVPre) { @@ -8640,23 +8804,13 @@ function parse ( } if (inVPre) { processRawAttrs(element); - } else { + } else if (!element.processed) { + // structural directives processFor(element); processIf(element); processOnce(element); - processKey(element); - - // determine whether this is a plain element after - // removing structural attributes - element.plain = !element.key && !attrs.length; - - processRef(element); - processSlot(element); - processComponent(element); - for (var i$1 = 0; i$1 < transforms.length; i$1++) { - transforms[i$1](element, options); - } - processAttrs(element); + // element-scope stuff + processElement(element, options); } function checkRootConstraints (el) { @@ -8714,8 +8868,8 @@ function parse ( endPre(element); } // apply post-transforms - for (var i$2 = 0; i$2 < postTransforms.length; i$2++) { - postTransforms[i$2](element, options); + for (var i$1 = 0; i$1 < postTransforms.length; i$1++) { + postTransforms[i$1](element, options); } }, @@ -8809,6 +8963,22 @@ function processRawAttrs (el) { } } +function processElement (element, options) { + processKey(element); + + // determine whether this is a plain element after + // removing structural attributes + element.plain = !element.key && !element.attrsList.length; + + processRef(element); + processSlot(element); + processComponent(element); + for (var i = 0; i < transforms.length; i++) { + element = transforms[i](element, options) || element; + } + processAttrs(element); +} + function processKey (el) { var exp = getBindingAttr(el, 'key'); if (exp) { @@ -8928,14 +9098,31 @@ function processSlot (el) { ); } } else { + var slotScope; + if (el.tag === 'template') { + slotScope = getAndRemoveAttr(el, 'scope'); + /* istanbul ignore if */ + if ("development" !== 'production' && slotScope) { + warn$2( + "the \"scope\" attribute for scoped slots have been deprecated and " + + "replaced by \"slot-scope\" since 2.5. The new \"slot-scope\" attribute " + + "can also be used on plain elements in addition to