From 56b6f8aac6fde1accae0a75772b6ca54bd9116f7 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 26 Apr 2017 18:32:30 +0800 Subject: [PATCH] [build] 2.3.0-beta.1 --- dist/vue.common.js | 1430 ++-- dist/vue.esm.js | 1430 ++-- dist/vue.js | 1424 ++-- dist/vue.min.js | 8 +- dist/vue.runtime.common.js | 1359 ++-- dist/vue.runtime.esm.js | 1359 ++-- dist/vue.runtime.js | 1353 ++-- dist/vue.runtime.min.js | 6 +- packages/vue-server-renderer/build.js | 6438 +++++++---------- packages/vue-server-renderer/client-plugin.js | 82 + packages/vue-server-renderer/package.json | 2 +- packages/vue-server-renderer/server-plugin.js | 92 + packages/vue-template-compiler/build.js | 3604 ++------- packages/vue-template-compiler/package.json | 2 +- 14 files changed, 8244 insertions(+), 10345 deletions(-) create mode 100644 packages/vue-server-renderer/client-plugin.js create mode 100644 packages/vue-server-renderer/server-plugin.js diff --git a/dist/vue.common.js b/dist/vue.common.js index 63f2709c..a8ae5169 100644 --- a/dist/vue.common.js +++ b/dist/vue.common.js @@ -1,5 +1,5 @@ /*! - * Vue.js v2.2.6 + * Vue.js v2.3.0-beta.1 * (c) 2014-2017 Evan You * Released under the MIT License. */ @@ -7,6 +7,50 @@ /* */ +// these helpers produces better vm code in JS engines due to their +// explicitness and function inlining +function isUndef (v) { + return v === undefined || v === null +} + +function isDef (v) { + return v !== undefined && v !== null +} + +function isTrue (v) { + return v === true +} + +/** + * Check if value is primitive + */ +function isPrimitive (value) { + return typeof value === 'string' || typeof value === 'number' +} + +/** + * Quick object check - this is primarily used to tell + * Objects from primitive values when we know the value + * is a JSON-compliant type. + */ +function isObject (obj) { + return obj !== null && typeof obj === 'object' +} + +var toString = Object.prototype.toString; + +/** + * Strict object type check. Only returns true + * for plain JavaScript objects. + */ +function isPlainObject (obj) { + return toString.call(obj) === '[object Object]' +} + +function isRegExp (v) { + return toString.call(v) === '[object RegExp]' +} + /** * Convert a value to a string that is actually rendered. */ @@ -70,13 +114,6 @@ function hasOwn (obj, key) { return hasOwnProperty.call(obj, key) } -/** - * Check if value is primitive - */ -function isPrimitive (value) { - return typeof value === 'string' || typeof value === 'number' -} - /** * Create a cached version of a pure function. */ @@ -154,25 +191,6 @@ function extend (to, _from) { return to } -/** - * Quick object check - this is primarily used to tell - * Objects from primitive values when we know the value - * is a JSON-compliant type. - */ -function isObject (obj) { - return obj !== null && typeof obj === 'object' -} - -/** - * Strict object type check. Only returns true - * for plain JavaScript objects. - */ -var toString = Object.prototype.toString; -var OBJECT_STRING = '[object Object]'; -function isPlainObject (obj) { - return toString.call(obj) === OBJECT_STRING -} - /** * Merge an Array of Objects into a single Object. */ @@ -246,14 +264,35 @@ function once (fn) { return function () { if (!called) { called = true; - fn(); + fn.apply(this, arguments); } } } +var SSR_ATTR = 'data-server-rendered'; + +var ASSET_TYPES = [ + 'component', + 'directive', + 'filter' +]; + +var LIFECYCLE_HOOKS = [ + 'beforeCreate', + 'created', + 'beforeMount', + 'mounted', + 'beforeUpdate', + 'updated', + 'beforeDestroy', + 'destroyed', + 'activated', + 'deactivated' +]; + /* */ -var config = { +var config = ({ /** * Option merge strategies (used in core/util/options) */ @@ -300,6 +339,12 @@ var config = { */ isReservedTag: no, + /** + * Check if an attribute is reserved so that it cannot be used as a component + * prop. This is platform-dependent and may be overwritten. + */ + isReservedAttr: no, + /** * Check if a tag is an unknown element. * Platform-dependent. @@ -323,35 +368,10 @@ var config = { mustUseProp: no, /** - * List of asset types that a component can own. + * Exposed for legacy reasons */ - _assetTypes: [ - 'component', - 'directive', - 'filter' - ], - - /** - * List of lifecycle hooks. - */ - _lifecycleHooks: [ - 'beforeCreate', - 'created', - 'beforeMount', - 'mounted', - 'beforeUpdate', - 'updated', - 'beforeDestroy', - 'destroyed', - 'activated', - 'deactivated' - ], - - /** - * Max circular updates allowed in a scheduler flush cycle. - */ - _maxUpdateCount: 100 -}; + _lifecycleHooks: LIFECYCLE_HOOKS +}); /* */ @@ -395,6 +415,113 @@ function parsePath (path) { } } +var warn = noop; +var tip = noop; +var formatComponentName; + +if (process.env.NODE_ENV !== 'production') { + var hasConsole = typeof console !== 'undefined'; + var classifyRE = /(?:^|[-_])(\w)/g; + var classify = function (str) { return str + .replace(classifyRE, function (c) { return c.toUpperCase(); }) + .replace(/[-_]/g, ''); }; + + warn = function (msg, vm) { + if (hasConsole && (!config.silent)) { + console.error("[Vue warn]: " + msg + ( + vm ? generateComponentTrace(vm) : '' + )); + } + }; + + tip = function (msg, vm) { + if (hasConsole && (!config.silent)) { + console.warn("[Vue tip]: " + msg + ( + vm ? generateComponentTrace(vm) : '' + )); + } + }; + + formatComponentName = function (vm, includeFile) { + 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; + if (!name && file) { + var match = file.match(/([^/\\]+)\.vue$/); + name = match && match[1]; + } + + return ( + (name ? ("<" + (classify(name)) + ">") : "") + + (file && includeFile !== false ? (" at " + file) : '') + ) + }; + + var repeat = function (str, n) { + var res = ''; + while (n) { + if (n % 2 === 1) { res += str; } + if (n > 1) { str += str; } + n >>= 1; + } + return res + }; + + var generateComponentTrace = function (vm) { + if (vm._isVue && vm.$parent) { + var tree = []; + var currentRecursiveSequence = 0; + while (vm) { + if (tree.length > 0) { + var last = tree[tree.length - 1]; + if (last.constructor === vm.constructor) { + currentRecursiveSequence++; + vm = vm.$parent; + continue + } else if (currentRecursiveSequence > 0) { + tree[tree.length - 1] = [last, currentRecursiveSequence]; + currentRecursiveSequence = 0; + } + } + tree.push(vm); + vm = vm.$parent; + } + return '\n\nfound in\n\n' + tree + .map(function (vm, i) { return ("" + (i === 0 ? '---> ' : repeat(' ', 5 + i * 2)) + (Array.isArray(vm) + ? ((formatComponentName(vm[0])) + "... (" + (vm[1]) + " recursive calls)") + : formatComponentName(vm))); }) + .join('\n') + } else { + return ("\n\n(found in " + (formatComponentName(vm)) + ")") + } + }; +} + +function handleError (err, vm, info) { + if (config.errorHandler) { + config.errorHandler.call(null, err, vm, info); + } else { + if (process.env.NODE_ENV !== 'production') { + warn(("Error in " + info + ": \"" + (err.toString()) + "\""), vm); + } + /* istanbul ignore else */ + if (inBrowser && typeof console !== 'undefined') { + console.error(err); + } else { + throw err + } + } +} + /* */ /* globals MutationObserver */ @@ -411,6 +538,20 @@ var isAndroid = UA && UA.indexOf('android') > 0; var isIOS = UA && /iphone|ipad|ipod|ios/.test(UA); var isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge; +var supportsPassive = false; +if (inBrowser) { + try { + var opts = {}; + Object.defineProperty(opts, 'passive', ({ + get: function get () { + /* istanbul ignore next */ + supportsPassive = true; + } + } )); // https://github.com/facebook/flow/issues/285 + window.addEventListener('test-passive', null, opts); + } catch (e) {} +} + // this needs to be lazy-evaled because vue may be required before // vue-server-renderer can set VUE_ENV var _isServer; @@ -433,7 +574,7 @@ var devtools = inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__; /* istanbul ignore next */ function isNative (Ctor) { - return /native code/.test(Ctor.toString()) + return typeof Ctor === 'function' && /native code/.test(Ctor.toString()) } var hasSymbol = @@ -504,15 +645,22 @@ var nextTick = (function () { return function queueNextTick (cb, ctx) { var _resolve; callbacks.push(function () { - if (cb) { cb.call(ctx); } - if (_resolve) { _resolve(ctx); } + if (cb) { + try { + cb.call(ctx); + } catch (e) { + handleError(e, ctx, 'nextTick'); + } + } else if (_resolve) { + _resolve(ctx); + } }); if (!pending) { pending = true; timerFunc(); } if (!cb && typeof Promise !== 'undefined') { - return new Promise(function (resolve) { + return new Promise(function (resolve, reject) { _resolve = resolve; }) } @@ -544,76 +692,17 @@ if (typeof Set !== 'undefined' && isNative(Set)) { }()); } -var warn = noop; -var tip = noop; -var formatComponentName; - -if (process.env.NODE_ENV !== 'production') { - var hasConsole = typeof console !== 'undefined'; - var classifyRE = /(?:^|[-_])(\w)/g; - var classify = function (str) { return str - .replace(classifyRE, function (c) { return c.toUpperCase(); }) - .replace(/[-_]/g, ''); }; - - warn = function (msg, vm) { - if (hasConsole && (!config.silent)) { - console.error("[Vue warn]: " + msg + " " + ( - vm ? formatLocation(formatComponentName(vm)) : '' - )); - } - }; - - tip = function (msg, vm) { - if (hasConsole && (!config.silent)) { - console.warn("[Vue tip]: " + msg + " " + ( - vm ? formatLocation(formatComponentName(vm)) : '' - )); - } - }; - - formatComponentName = function (vm, includeFile) { - 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; - if (!name && file) { - var match = file.match(/([^/\\]+)\.vue$/); - name = match && match[1]; - } - - return ( - (name ? ("<" + (classify(name)) + ">") : "") + - (file && includeFile !== false ? (" at " + file) : '') - ) - }; - - var formatLocation = function (str) { - if (str === "") { - str += " - use the \"name\" option for better debugging messages."; - } - return ("\n(found in " + str + ")") - }; -} - /* */ -var uid$1 = 0; +var uid = 0; /** * A dep is an observable that can have multiple * directives subscribing to it. */ var Dep = function Dep () { - this.id = uid$1++; + this.id = uid++; this.subs = []; }; @@ -1056,7 +1145,7 @@ function mergeHook ( : parentVal } -config._lifecycleHooks.forEach(function (hook) { +LIFECYCLE_HOOKS.forEach(function (hook) { strats[hook] = mergeHook; }); @@ -1074,7 +1163,7 @@ function mergeAssets (parentVal, childVal) { : res } -config._assetTypes.forEach(function (type) { +ASSET_TYPES.forEach(function (type) { strats[type + 's'] = mergeAssets; }); @@ -1200,21 +1289,20 @@ function mergeOptions ( if (process.env.NODE_ENV !== 'production') { checkComponents(child); } + + if (typeof child === 'function') { + child = child.options; + } + normalizeProps(child); normalizeDirectives(child); var extendsFrom = child.extends; if (extendsFrom) { - parent = typeof extendsFrom === 'function' - ? mergeOptions(parent, extendsFrom.options, vm) - : mergeOptions(parent, extendsFrom, vm); + parent = mergeOptions(parent, extendsFrom, vm); } if (child.mixins) { for (var i = 0, l = child.mixins.length; i < l; i++) { - var mixin = child.mixins[i]; - if (mixin.prototype instanceof Vue$3) { - mixin = mixin.options; - } - parent = mergeOptions(parent, mixin, vm); + parent = mergeOptions(parent, child.mixins[i], vm); } } var options = {}; @@ -1387,20 +1475,13 @@ function assertProp ( } } -/** - * Assert the type of a value - */ +var simpleCheckRE = /^(String|Number|Boolean|Function|Symbol)$/; + function assertType (value, type) { var valid; var expectedType = getType(type); - if (expectedType === 'String') { - valid = typeof value === (expectedType = 'string'); - } else if (expectedType === 'Number') { - valid = typeof value === (expectedType = 'number'); - } else if (expectedType === 'Boolean') { - valid = typeof value === (expectedType = 'boolean'); - } else if (expectedType === 'Function') { - valid = typeof value === (expectedType = 'function'); + if (simpleCheckRE.test(expectedType)) { + valid = typeof value === expectedType.toLowerCase(); } else if (expectedType === 'Object') { valid = isPlainObject(value); } else if (expectedType === 'Array') { @@ -1421,7 +1502,7 @@ function assertType (value, type) { */ function getType (fn) { var match = fn && fn.toString().match(/^\s*function (\w+)/); - return match && match[1] + return match ? match[1] : '' } function isType (type, fn) { @@ -1437,19 +1518,26 @@ function isType (type, fn) { return false } -function handleError (err, vm, info) { - if (config.errorHandler) { - config.errorHandler.call(null, err, vm, info); - } else { - if (process.env.NODE_ENV !== 'production') { - warn(("Error in " + info + ":"), vm); - } - /* istanbul ignore else */ - if (inBrowser && typeof console !== 'undefined') { - console.error(err); - } else { - throw err - } +var mark; +var measure; + +if (process.env.NODE_ENV !== 'production') { + var perf = inBrowser && window.performance; + /* istanbul ignore if */ + if ( + perf && + perf.mark && + perf.measure && + perf.clearMarks && + perf.clearMeasures + ) { + mark = function (tag) { return perf.mark(tag); }; + measure = function (name, startTag, endTag) { + perf.measure(name, startTag, endTag); + perf.clearMarks(startTag); + perf.clearMarks(endTag); + perf.clearMeasures(name); + }; } } @@ -1527,29 +1615,6 @@ if (process.env.NODE_ENV !== 'production') { }; } -var mark; -var measure; - -if (process.env.NODE_ENV !== 'production') { - var perf = inBrowser && window.performance; - /* istanbul ignore if */ - if ( - perf && - perf.mark && - perf.measure && - perf.clearMarks && - perf.clearMeasures - ) { - mark = function (tag) { return perf.mark(tag); }; - measure = function (name, startTag, endTag) { - perf.measure(name, startTag, endTag); - perf.clearMarks(startTag); - perf.clearMarks(endTag); - perf.clearMeasures(name); - }; - } -} - /* */ var VNode = function VNode ( @@ -1635,6 +1700,8 @@ function cloneVNodes (vnodes) { /* */ var normalizeEvent = cached(function (name) { + var passive = name.charAt(0) === '&'; + name = passive ? name.slice(1) : name; var once$$1 = name.charAt(0) === '~'; // Prefixed last, checked first name = once$$1 ? name.slice(1) : name; var capture = name.charAt(0) === '!'; @@ -1642,7 +1709,8 @@ var normalizeEvent = cached(function (name) { return { name: name, once: once$$1, - capture: capture + capture: capture, + passive: passive } }); @@ -1676,23 +1744,23 @@ function updateListeners ( cur = on[name]; old = oldOn[name]; event = normalizeEvent(name); - if (!cur) { + if (isUndef(cur)) { process.env.NODE_ENV !== 'production' && warn( "Invalid handler for event \"" + (event.name) + "\": got " + String(cur), vm ); - } else if (!old) { - if (!cur.fns) { + } else if (isUndef(old)) { + if (isUndef(cur.fns)) { cur = on[name] = createFnInvoker(cur); } - add(event.name, cur, event.once, event.capture); + add(event.name, cur, event.once, event.capture, event.passive); } else if (cur !== old) { old.fns = cur; on[name] = old; } } for (name in oldOn) { - if (!on[name]) { + if (isUndef(on[name])) { event = normalizeEvent(name); remove$$1(event.name, oldOn[name], event.capture); } @@ -1712,12 +1780,12 @@ function mergeVNodeHook (def, hookKey, hook) { remove(invoker.fns, wrappedHook); } - if (!oldHook) { + if (isUndef(oldHook)) { // no existing hook invoker = createFnInvoker([wrappedHook]); } else { /* istanbul ignore if */ - if (oldHook.fns && oldHook.merged) { + if (isDef(oldHook.fns) && isTrue(oldHook.merged)) { // already a merged invoker invoker = oldHook; invoker.fns.push(wrappedHook); @@ -1733,6 +1801,74 @@ function mergeVNodeHook (def, hookKey, hook) { /* */ +function extractPropsFromVNodeData ( + data, + Ctor, + tag +) { + // we are only extracting raw values here. + // validation and default values are handled in the child + // component itself. + var propOptions = Ctor.options.props; + if (isUndef(propOptions)) { + return + } + var res = {}; + var attrs = data.attrs; + var props = data.props; + if (isDef(attrs) || isDef(props)) { + for (var key in propOptions) { + var altKey = hyphenate(key); + if (process.env.NODE_ENV !== 'production') { + var keyInLowerCase = key.toLowerCase(); + if ( + key !== keyInLowerCase && + attrs && hasOwn(attrs, keyInLowerCase) + ) { + tip( + "Prop \"" + keyInLowerCase + "\" is passed to component " + + (formatComponentName(tag || Ctor)) + ", but the declared prop name is" + + " \"" + key + "\". " + + "Note that HTML attributes are case-insensitive and camelCased " + + "props need to use their kebab-case equivalents when using in-DOM " + + "templates. You should probably use \"" + altKey + "\" instead of \"" + key + "\"." + ); + } + } + checkProp(res, props, key, altKey, true) || + checkProp(res, attrs, key, altKey, false); + } + } + return res +} + +function checkProp ( + res, + hash, + key, + altKey, + preserve +) { + if (isDef(hash)) { + if (hasOwn(hash, key)) { + res[key] = hash[key]; + if (!preserve) { + delete hash[key]; + } + return true + } else if (hasOwn(hash, altKey)) { + res[key] = hash[altKey]; + if (!preserve) { + delete hash[altKey]; + } + return true + } + } + return false +} + +/* */ + // The template compiler attempts to minimize the need for normalization by // statically analyzing the template at compile time. // @@ -1771,25 +1907,25 @@ function normalizeArrayChildren (children, nestedIndex) { var i, c, last; for (i = 0; i < children.length; i++) { c = children[i]; - if (c == null || typeof c === 'boolean') { continue } + if (isUndef(c) || typeof c === 'boolean') { continue } last = res[res.length - 1]; // nested if (Array.isArray(c)) { res.push.apply(res, normalizeArrayChildren(c, ((nestedIndex || '') + "_" + i))); } else if (isPrimitive(c)) { - if (last && last.text) { - last.text += String(c); + if (isDef(last) && isDef(last.text)) { + (last).text += String(c); } else if (c !== '') { // convert primitive to vnode res.push(createTextVNode(c)); } } else { - if (c.text && last && last.text) { + if (isDef(c.text) && isDef(last) && isDef(last.text)) { res[res.length - 1] = createTextVNode(last.text + c.text); } else { // default key for nested array children (likely generated by v-for) - if (c.tag && c.key == null && nestedIndex != null) { - c.key = "__vlist" + nestedIndex + "_" + i + "__"; + if (isDef(c.tag) && isUndef(c.key) && isDef(nestedIndex)) { + c.key = "__vlist" + ((nestedIndex)) + "_" + i + "__"; } res.push(c); } @@ -1800,10 +1936,127 @@ function normalizeArrayChildren (children, nestedIndex) { /* */ -function getFirstComponentChild (children) { - return children && children.filter(function (c) { return c && c.componentOptions; })[0] +function ensureCtor (comp, base) { + return isObject(comp) + ? base.extend(comp) + : comp } +function resolveAsyncComponent ( + factory, + baseCtor, + context +) { + if (isTrue(factory.error) && isDef(factory.errorComp)) { + return factory.errorComp + } + + if (isDef(factory.resolved)) { + return factory.resolved + } + + if (isTrue(factory.loading) && isDef(factory.loadingComp)) { + return factory.loadingComp + } + + if (isDef(factory.contexts)) { + // already pending + factory.contexts.push(context); + } else { + var contexts = factory.contexts = [context]; + var sync = true; + + var forceRender = function () { + for (var i = 0, l = contexts.length; i < l; i++) { + contexts[i].$forceUpdate(); + } + }; + + var resolve = once(function (res) { + // cache resolved + factory.resolved = ensureCtor(res, baseCtor); + // invoke callbacks only if this is not a synchronous resolve + // (async resolves are shimmed as synchronous during SSR) + if (!sync) { + forceRender(); + } + }); + + var reject = once(function (reason) { + process.env.NODE_ENV !== 'production' && warn( + "Failed to resolve async component: " + (String(factory)) + + (reason ? ("\nReason: " + reason) : '') + ); + if (isDef(factory.errorComp)) { + factory.error = true; + forceRender(); + } + }); + + var res = factory(resolve, reject); + + if (isObject(res)) { + if (typeof res.then === 'function') { + // () => Promise + if (isUndef(factory.resolved)) { + res.then(resolve, reject); + } + } else if (isDef(res.component) && typeof res.component.then === 'function') { + res.component.then(resolve, reject); + + if (isDef(res.error)) { + factory.errorComp = ensureCtor(res.error, baseCtor); + } + + if (isDef(res.loading)) { + factory.loadingComp = ensureCtor(res.loading, baseCtor); + if (res.delay === 0) { + factory.loading = true; + } else { + setTimeout(function () { + if (isUndef(factory.resolved) && isUndef(factory.error)) { + factory.loading = true; + forceRender(); + } + }, res.delay || 200); + } + } + + if (isDef(res.timeout)) { + setTimeout(function () { + reject( + process.env.NODE_ENV !== 'production' + ? ("timeout (" + (res.timeout) + "ms)") + : null + ); + }, res.timeout); + } + } + } + + sync = false; + // return in case resolved synchronously + return factory.loading + ? factory.loadingComp + : factory.resolved + } +} + +/* */ + +function getFirstComponentChild (children) { + if (Array.isArray(children)) { + for (var i = 0; i < children.length; i++) { + var c = children[i]; + if (isDef(c) && isDef(c.componentOptions)) { + return c + } + } + } +} + +/* */ + /* */ function initEvents (vm) { @@ -1949,13 +2202,13 @@ function resolveSlots ( return slots } var defaultSlot = []; - var name, child; for (var i = 0, l = children.length; i < l; i++) { - child = children[i]; + var child = children[i]; // named slots should only be respected if the vnode was rendered in the // same context. if ((child.context === context || child.functionalContext === context) && - child.data && (name = child.data.slot)) { + child.data && child.data.slot != null) { + var name = child.data.slot; var slot = (slots[name] || (slots[name] = [])); if (child.tag === 'template') { slot.push.apply(slot, child.children); @@ -2242,7 +2495,7 @@ function activateChildComponent (vm, direct) { } else if (vm._directInactive) { return } - if (vm._inactive || vm._inactive == null) { + if (vm._inactive || vm._inactive === null) { vm._inactive = false; for (var i = 0; i < vm.$children.length; i++) { activateChildComponent(vm.$children[i]); @@ -2286,7 +2539,10 @@ function callHook (vm, hook) { /* */ +var MAX_UPDATE_COUNT = 100; + var queue = []; +var activatedChildren = []; var has = {}; var circular = {}; var waiting = false; @@ -2297,7 +2553,7 @@ var index = 0; * Reset the scheduler's state. */ function resetSchedulerState () { - queue.length = 0; + queue.length = activatedChildren.length = 0; has = {}; if (process.env.NODE_ENV !== 'production') { circular = {}; @@ -2310,7 +2566,7 @@ function resetSchedulerState () { */ function flushSchedulerQueue () { flushing = true; - var watcher, id, vm; + var watcher, id; // Sort queue before flush. // This ensures that: @@ -2332,7 +2588,7 @@ function flushSchedulerQueue () { // in dev build, check and stop circular updates. if (process.env.NODE_ENV !== 'production' && has[id] != null) { circular[id] = (circular[id] || 0) + 1; - if (circular[id] > config._maxUpdateCount) { + if (circular[id] > MAX_UPDATE_COUNT) { warn( 'You may have an infinite update loop ' + ( watcher.user @@ -2346,19 +2602,15 @@ function flushSchedulerQueue () { } } - // reset scheduler before updated hook called - var oldQueue = queue.slice(); + // keep copies of post queues before resetting state + var activatedQueue = activatedChildren.slice(); + var updatedQueue = queue.slice(); + resetSchedulerState(); - // call updated hooks - index = oldQueue.length; - while (index--) { - watcher = oldQueue[index]; - vm = watcher.vm; - if (vm._watcher === watcher && vm._isMounted) { - callHook(vm, 'updated'); - } - } + // call component updated and activated hooks + callActivatedHooks(activatedQueue); + callUpdateHooks(updatedQueue); // devtool hook /* istanbul ignore if */ @@ -2367,6 +2619,35 @@ function flushSchedulerQueue () { } } +function callUpdateHooks (queue) { + var i = queue.length; + while (i--) { + var watcher = queue[i]; + var vm = watcher.vm; + if (vm._watcher === watcher && vm._isMounted) { + callHook(vm, 'updated'); + } + } +} + +/** + * Queue a kept-alive component that was activated during patch. + * The queue will be processed after the entire tree has been patched. + */ +function queueActivatedComponent (vm) { + // setting _inactive to false here so that a render function can + // rely on checking whether it's in an inactive tree (e.g. router-view) + vm._inactive = false; + activatedChildren.push(vm); +} + +function callActivatedHooks (queue) { + for (var i = 0; i < queue.length; i++) { + queue[i]._inactive = true; + activateChildComponent(queue[i], true /* true */); + } +} + /** * Push a watcher into the watcher queue. * Jobs with duplicate IDs will be skipped unless it's @@ -2670,7 +2951,11 @@ function initState (vm) { if (opts.watch) { initWatch(vm, opts.watch); } } -var isReservedProp = { key: 1, ref: 1, slot: 1 }; +var isReservedProp = { + key: 1, + ref: 1, + slot: 1 +}; function initProps (vm, propsOptions) { var propsData = vm.$options.propsData || {}; @@ -2686,7 +2971,7 @@ function initProps (vm, propsOptions) { var value = validateProp(key, propsOptions, propsData, vm); /* istanbul ignore else */ if (process.env.NODE_ENV !== 'production') { - if (isReservedProp[key]) { + if (isReservedProp[key] || config.isReservedAttr(key)) { warn( ("\"" + key + "\" is a reserved attribute and cannot be used as component prop."), vm @@ -2784,6 +3069,12 @@ function initComputed (vm, computed) { // at instantiation here. if (!(key in vm)) { defineComputed(vm, key, userDef); + } else if (process.env.NODE_ENV !== 'production') { + if (key in vm.$data) { + warn(("The computed property \"" + key + "\" is already defined in data."), vm); + } else if (vm.$options.props && key in vm.$options.props) { + warn(("The computed property \"" + key + "\" is already defined as a prop."), vm); + } } } } @@ -2913,6 +3204,113 @@ function stateMixin (Vue) { /* */ +function initProvide (vm) { + var provide = vm.$options.provide; + if (provide) { + vm._provided = typeof provide === 'function' + ? provide.call(vm) + : provide; + } +} + +function initInjections (vm) { + var result = resolveInject(vm.$options.inject, vm); + if (result) { + Object.keys(result).forEach(function (key) { + /* istanbul ignore else */ + if (process.env.NODE_ENV !== 'production') { + defineReactive$$1(vm, key, result[key], function () { + warn( + "Avoid mutating an injected value directly since the changes will be " + + "overwritten whenever the provided component re-renders. " + + "injection being mutated: \"" + key + "\"", + vm + ); + }); + } else { + defineReactive$$1(vm, key, result[key]); + } + }); + } +} + +function resolveInject (inject, vm) { + if (inject) { + // inject is :any because flow is not smart enough to figure out cached + // isArray here + var isArray = Array.isArray(inject); + var result = Object.create(null); + var keys = isArray + ? inject + : hasSymbol + ? Reflect.ownKeys(inject) + : Object.keys(inject); + + for (var i = 0; i < keys.length; i++) { + var key = keys[i]; + var provideKey = isArray ? key : inject[key]; + var source = vm; + while (source) { + if (source._provided && provideKey in source._provided) { + result[key] = source._provided[provideKey]; + break + } + source = source.$parent; + } + } + return result + } +} + +/* */ + +function createFunctionalComponent ( + Ctor, + propsData, + data, + context, + children +) { + var props = {}; + var propOptions = Ctor.options.props; + if (isDef(propOptions)) { + for (var key in propOptions) { + props[key] = validateProp(key, propOptions, propsData); + } + } else { + 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 || {}, + injections: resolveInject(Ctor.options.inject, context), + slots: function () { return resolveSlots(children, context); } + }); + if (vnode instanceof VNode) { + vnode.functionalContext = context; + if (data.slot) { + (vnode.data || (vnode.data = {})).slot = data.slot; + } + } + return vnode +} + +function mergeProps (to, from) { + for (var key in from) { + to[camelize(key)] = from[key]; + } +} + +/* */ + // hooks to be invoked on component VNodes during patch var componentVNodeHooks = { init: function init ( @@ -2949,21 +3347,33 @@ var componentVNodeHooks = { }, insert: function insert (vnode) { - if (!vnode.componentInstance._isMounted) { - vnode.componentInstance._isMounted = true; - callHook(vnode.componentInstance, 'mounted'); + var context = vnode.context; + var componentInstance = vnode.componentInstance; + if (!componentInstance._isMounted) { + componentInstance._isMounted = true; + callHook(componentInstance, 'mounted'); } if (vnode.data.keepAlive) { - activateChildComponent(vnode.componentInstance, true /* direct */); + if (context._isMounted) { + // vue-router#1212 + // During updates, a kept-alive component's child components may + // change, so directly walking the tree here may call activated hooks + // on incorrect children. Instead we push them into a queue which will + // be processed after the whole patch process ended. + queueActivatedComponent(componentInstance); + } else { + activateChildComponent(componentInstance, true /* direct */); + } } }, destroy: function destroy (vnode) { - if (!vnode.componentInstance._isDestroyed) { + var componentInstance = vnode.componentInstance; + if (!componentInstance._isDestroyed) { if (!vnode.data.keepAlive) { - vnode.componentInstance.$destroy(); + componentInstance.$destroy(); } else { - deactivateChildComponent(vnode.componentInstance, true /* direct */); + deactivateChildComponent(componentInstance, true /* direct */); } } } @@ -2978,15 +3388,19 @@ function createComponent ( children, tag ) { - if (!Ctor) { + if (isUndef(Ctor)) { return } var baseCtor = context.$options._base; + + // plain options object: turn it into a constructor if (isObject(Ctor)) { Ctor = baseCtor.extend(Ctor); } + // if at this stage it's not a constructor or an async component factory, + // reject. if (typeof Ctor !== 'function') { if (process.env.NODE_ENV !== 'production') { warn(("Invalid Component definition: " + (String(Ctor))), context); @@ -2995,20 +3409,12 @@ function createComponent ( } // async component - if (!Ctor.cid) { - if (Ctor.resolved) { - Ctor = Ctor.resolved; - } else { - Ctor = resolveAsyncComponent(Ctor, baseCtor, function () { - // it's ok to queue this on every render because - // $forceUpdate is buffered by the scheduler. - context.$forceUpdate(); - }); - if (!Ctor) { - // return nothing if this is indeed an async component - // wait for the callback to trigger parent update. - return - } + if (isUndef(Ctor.cid)) { + Ctor = resolveAsyncComponent(Ctor, baseCtor, context); + if (Ctor === undefined) { + // return nothing if this is indeed an async component + // wait for the callback to trigger parent update. + return } } @@ -3019,15 +3425,15 @@ function createComponent ( data = data || {}; // transform component v-model data into props & events - if (data.model) { + if (isDef(data.model)) { transformModel(Ctor.options, data); } // extract props - var propsData = extractProps(data, Ctor, tag); + var propsData = extractPropsFromVNodeData(data, Ctor, tag); // functional component - if (Ctor.options.functional) { + if (isTrue(Ctor.options.functional)) { return createFunctionalComponent(Ctor, propsData, data, context, children) } @@ -3037,7 +3443,7 @@ function createComponent ( // replace with listeners with .native modifier data.on = data.nativeOn; - if (Ctor.options.abstract) { + if (isTrue(Ctor.options.abstract)) { // abstract components do not keep anything // other than props & listeners data = {}; @@ -3056,40 +3462,6 @@ function createComponent ( return vnode } -function createFunctionalComponent ( - Ctor, - propsData, - data, - context, - children -) { - var props = {}; - var propOptions = Ctor.options.props; - if (propOptions) { - for (var key in propOptions) { - props[key] = validateProp(key, propOptions, propsData); - } - } - // 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, { - props: props, - data: data, - parent: context, - children: children, - slots: function () { return resolveSlots(children, context); } - }); - if (vnode instanceof VNode) { - vnode.functionalContext = context; - if (data.slot) { - (vnode.data || (vnode.data = {})).slot = data.slot; - } - } - return vnode -} - function createComponentInstanceForVnode ( vnode, // we know it's MountedComponentVNode but flow doesn't parent, // activeInstance in lifecycle state @@ -3110,125 +3482,13 @@ function createComponentInstanceForVnode ( }; // check inline-template render functions var inlineTemplate = vnode.data.inlineTemplate; - if (inlineTemplate) { + if (isDef(inlineTemplate)) { options.render = inlineTemplate.render; options.staticRenderFns = inlineTemplate.staticRenderFns; } return new vnodeComponentOptions.Ctor(options) } -function resolveAsyncComponent ( - factory, - baseCtor, - cb -) { - if (factory.requested) { - // pool callbacks - factory.pendingCallbacks.push(cb); - } else { - factory.requested = true; - var cbs = factory.pendingCallbacks = [cb]; - var sync = true; - - var resolve = function (res) { - if (isObject(res)) { - res = baseCtor.extend(res); - } - // cache resolved - factory.resolved = res; - // invoke callbacks only if this is not a synchronous resolve - // (async resolves are shimmed as synchronous during SSR) - if (!sync) { - for (var i = 0, l = cbs.length; i < l; i++) { - cbs[i](res); - } - } - }; - - var reject = function (reason) { - process.env.NODE_ENV !== 'production' && warn( - "Failed to resolve async component: " + (String(factory)) + - (reason ? ("\nReason: " + reason) : '') - ); - }; - - var res = factory(resolve, reject); - - // handle promise - if (res && typeof res.then === 'function' && !factory.resolved) { - res.then(resolve, reject); - } - - sync = false; - // return in case resolved synchronously - return factory.resolved - } -} - -function extractProps (data, Ctor, tag) { - // we are only extracting raw values here. - // validation and default values are handled in the child - // component itself. - var propOptions = Ctor.options.props; - if (!propOptions) { - return - } - var res = {}; - var attrs = data.attrs; - var props = data.props; - var domProps = data.domProps; - if (attrs || props || domProps) { - for (var key in propOptions) { - var altKey = hyphenate(key); - if (process.env.NODE_ENV !== 'production') { - var keyInLowerCase = key.toLowerCase(); - if ( - key !== keyInLowerCase && - attrs && attrs.hasOwnProperty(keyInLowerCase) - ) { - tip( - "Prop \"" + keyInLowerCase + "\" is passed to component " + - (formatComponentName(tag || Ctor)) + ", but the declared prop name is" + - " \"" + key + "\". " + - "Note that HTML attributes are case-insensitive and camelCased " + - "props need to use their kebab-case equivalents when using in-DOM " + - "templates. You should probably use \"" + altKey + "\" instead of \"" + key + "\"." - ); - } - } - checkProp(res, props, key, altKey, true) || - checkProp(res, attrs, key, altKey) || - checkProp(res, domProps, key, altKey); - } - } - return res -} - -function checkProp ( - res, - hash, - key, - altKey, - preserve -) { - if (hash) { - if (hasOwn(hash, key)) { - res[key] = hash[key]; - if (!preserve) { - delete hash[key]; - } - return true - } else if (hasOwn(hash, altKey)) { - res[key] = hash[altKey]; - if (!preserve) { - delete hash[altKey]; - } - return true - } - } - return false -} - function mergeHooks (data) { if (!data.hook) { data.hook = {}; @@ -3254,7 +3514,7 @@ function transformModel (options, data) { var prop = (options.model && options.model.prop) || 'value'; var event = (options.model && options.model.event) || 'input';(data.props || (data.props = {}))[prop] = data.model.value; var on = data.on || (data.on = {}); - if (on[event]) { + if (isDef(on[event])) { on[event] = [data.model.callback].concat(on[event]); } else { on[event] = data.model.callback; @@ -3281,7 +3541,9 @@ function createElement ( children = data; data = undefined; } - if (alwaysNormalize) { normalizationType = ALWAYS_NORMALIZE; } + if (isTrue(alwaysNormalize)) { + normalizationType = ALWAYS_NORMALIZE; + } return _createElement(context, tag, data, children, normalizationType) } @@ -3292,7 +3554,7 @@ function _createElement ( children, normalizationType ) { - if (data && data.__ob__) { + if (isDef(data) && isDef((data).__ob__)) { process.env.NODE_ENV !== 'production' && warn( "Avoid using observed data object as vnode data: " + (JSON.stringify(data)) + "\n" + 'Always create fresh vnode data objects in each render!', @@ -3326,7 +3588,7 @@ function _createElement ( config.parsePlatformTagName(tag), data, children, undefined, undefined, context ); - } else if ((Ctor = resolveAsset(context.$options, 'components', tag))) { + } else if (isDef(Ctor = resolveAsset(context.$options, 'components', tag))) { // component vnode = createComponent(Ctor, data, context, children, tag); } else { @@ -3342,7 +3604,7 @@ function _createElement ( // direct component options / constructor vnode = createComponent(tag, data, context, children); } - if (vnode) { + if (vnode !== undefined) { if (ns) { applyNS(vnode, ns); } return vnode } else { @@ -3356,10 +3618,10 @@ function applyNS (vnode, ns) { // use default namespace inside foreignObject return } - if (vnode.children) { + if (Array.isArray(vnode.children)) { for (var i = 0, l = vnode.children.length; i < l; i++) { var child = vnode.children[i]; - if (child.tag && !child.ns) { + if (isDef(child.tag) && isUndef(child.ns)) { applyNS(child, ns); } } @@ -3559,10 +3821,9 @@ function markStaticNode (node, key, isOnce) { /* */ function initRender (vm) { - vm.$vnode = null; // the placeholder node in parent tree vm._vnode = null; // the root of the child tree vm._staticTrees = null; - var parentVnode = vm.$options._parentVnode; + var parentVnode = vm.$vnode = vm.$options._parentVnode; // the placeholder node in parent tree var renderContext = parentVnode && parentVnode.context; vm.$slots = resolveSlots(vm.$options._renderChildren, renderContext); vm.$scopedSlots = emptyObject; @@ -3657,65 +3918,13 @@ function renderMixin (Vue) { /* */ -function initProvide (vm) { - var provide = vm.$options.provide; - if (provide) { - vm._provided = typeof provide === 'function' - ? provide.call(vm) - : provide; - } -} - -function initInjections (vm) { - var inject = vm.$options.inject; - if (inject) { - // inject is :any because flow is not smart enough to figure out cached - // isArray here - var isArray = Array.isArray(inject); - var keys = isArray - ? inject - : hasSymbol - ? Reflect.ownKeys(inject) - : Object.keys(inject); - - var loop = function ( i ) { - var key = keys[i]; - var provideKey = isArray ? key : inject[key]; - var source = vm; - while (source) { - if (source._provided && provideKey in source._provided) { - /* istanbul ignore else */ - if (process.env.NODE_ENV !== 'production') { - defineReactive$$1(vm, key, source._provided[provideKey], function () { - warn( - "Avoid mutating an injected value directly since the changes will be " + - "overwritten whenever the provided component re-renders. " + - "injection being mutated: \"" + key + "\"", - vm - ); - }); - } else { - defineReactive$$1(vm, key, source._provided[provideKey]); - } - break - } - source = source.$parent; - } - }; - - for (var i = 0; i < keys.length; i++) loop( i ); - } -} - -/* */ - -var uid = 0; +var uid$1 = 0; function initMixin (Vue) { Vue.prototype._init = function (options) { var vm = this; // a uid - vm._uid = uid++; + vm._uid = uid$1++; var startTag, endTag; /* istanbul ignore if */ @@ -3814,24 +4023,27 @@ function resolveConstructorOptions (Ctor) { function resolveModifiedOptions (Ctor) { var modified; var latest = Ctor.options; + var extended = Ctor.extendOptions; var sealed = Ctor.sealedOptions; for (var key in latest) { if (latest[key] !== sealed[key]) { if (!modified) { modified = {}; } - modified[key] = dedupe(latest[key], sealed[key]); + modified[key] = dedupe(latest[key], extended[key], sealed[key]); } } return modified } -function dedupe (latest, sealed) { +function dedupe (latest, extended, sealed) { // compare latest and sealed to ensure lifecycle hooks won't be duplicated // between merges if (Array.isArray(latest)) { var res = []; sealed = Array.isArray(sealed) ? sealed : [sealed]; + extended = Array.isArray(extended) ? extended : [extended]; for (var i = 0; i < latest.length; i++) { - if (sealed.indexOf(latest[i]) < 0) { + // push original options and not sealed options to exclude duplicated options + if (extended.indexOf(latest[i]) >= 0 || sealed.indexOf(latest[i]) < 0) { res.push(latest[i]); } } @@ -3947,7 +4159,7 @@ function initExtend (Vue) { // create asset registers, so extended classes // can have their private assets too. - config._assetTypes.forEach(function (type) { + ASSET_TYPES.forEach(function (type) { Sub[type] = Super[type]; }); // enable recursive self-lookup @@ -3988,7 +4200,7 @@ function initAssetRegisters (Vue) { /** * Create asset registration methods. */ - config._assetTypes.forEach(function (type) { + ASSET_TYPES.forEach(function (type) { Vue[type] = function ( id, definition @@ -4030,20 +4242,22 @@ function getComponentName (opts) { function matches (pattern, name) { if (typeof pattern === 'string') { return pattern.split(',').indexOf(name) > -1 - } else if (pattern instanceof RegExp) { + } else if (isRegExp(pattern)) { return pattern.test(name) } /* istanbul ignore next */ return false } -function pruneCache (cache, filter) { +function pruneCache (cache, current, filter) { for (var key in cache) { var cachedNode = cache[key]; if (cachedNode) { var name = getComponentName(cachedNode.componentOptions); if (name && !filter(name)) { - pruneCacheEntry(cachedNode); + if (cachedNode !== current) { + pruneCacheEntry(cachedNode); + } cache[key] = null; } } @@ -4052,9 +4266,6 @@ function pruneCache (cache, filter) { function pruneCacheEntry (vnode) { if (vnode) { - if (!vnode.componentInstance._inactive) { - callHook(vnode.componentInstance, 'deactivated'); - } vnode.componentInstance.$destroy(); } } @@ -4082,10 +4293,10 @@ var KeepAlive = { watch: { include: function include (val) { - pruneCache(this.cache, function (name) { return matches(val, name); }); + pruneCache(this.cache, this._vnode, function (name) { return matches(val, name); }); }, exclude: function exclude (val) { - pruneCache(this.cache, function (name) { return !matches(val, name); }); + pruneCache(this.cache, this._vnode, function (name) { return !matches(val, name); }); } }, @@ -4151,7 +4362,7 @@ function initGlobalAPI (Vue) { Vue.nextTick = nextTick; Vue.options = Object.create(null); - config._assetTypes.forEach(function (type) { + ASSET_TYPES.forEach(function (type) { Vue.options[type + 's'] = Object.create(null); }); @@ -4173,10 +4384,14 @@ Object.defineProperty(Vue$3.prototype, '$isServer', { get: isServerRendering }); -Vue$3.version = '2.2.6'; +Vue$3.version = '2.3.0-beta.1'; /* */ +// these are reserved for web because they are directly compiled away +// during template compilation +var isReservedAttr = makeMap('style,class'); + // attributes that should be using props for binding var acceptValue = makeMap('input,textarea,option,select'); var mustUseProp = function (tag, type, attr) { @@ -4219,13 +4434,13 @@ function genClassForVnode (vnode) { var data = vnode.data; var parentNode = vnode; var childNode = vnode; - while (childNode.componentInstance) { + while (isDef(childNode.componentInstance)) { childNode = childNode.componentInstance._vnode; if (childNode.data) { data = mergeClassData(childNode.data, data); } } - while ((parentNode = parentNode.parent)) { + while (isDef(parentNode = parentNode.parent)) { if (parentNode.data) { data = mergeClassData(data, parentNode.data); } @@ -4236,7 +4451,7 @@ function genClassForVnode (vnode) { function mergeClassData (child, parent) { return { staticClass: concat(child.staticClass, parent.staticClass), - class: child.class + class: isDef(child.class) ? [child.class, parent.class] : parent.class } @@ -4245,7 +4460,7 @@ function mergeClassData (child, parent) { function genClassFromData (data) { var dynamicClass = data.class; var staticClass = data.staticClass; - if (staticClass || dynamicClass) { + if (isDef(staticClass) || isDef(dynamicClass)) { return concat(staticClass, stringifyClass(dynamicClass)) } /* istanbul ignore next */ @@ -4257,18 +4472,18 @@ function concat (a, b) { } function stringifyClass (value) { - var res = ''; - if (!value) { - return res + if (isUndef(value)) { + return '' } if (typeof value === 'string') { return value } + var res = ''; if (Array.isArray(value)) { var stringified; for (var i = 0, l = value.length; i < l; i++) { - if (value[i]) { - if ((stringified = stringifyClass(value[i]))) { + if (isDef(value[i])) { + if (isDef(stringified = stringifyClass(value[i])) && stringified !== '') { res += stringified + ' '; } } @@ -4513,18 +4728,6 @@ var emptyNode = new VNode('', {}, []); var hooks = ['create', 'activate', 'update', 'remove', 'destroy']; -function isUndef (v) { - return v === undefined || v === null -} - -function isDef (v) { - return v !== undefined && v !== null -} - -function isTrue (v) { - return v === true -} - function sameVnode (a, b) { return ( a.key === b.key && @@ -4711,7 +4914,9 @@ function createPatchFunction (backend) { function insert (parent, elm, ref) { if (isDef(parent)) { if (isDef(ref)) { - nodeOps.insertBefore(parent, elm, ref); + if (ref.parentNode === parent) { + nodeOps.insertBefore(parent, elm, ref); + } } else { nodeOps.appendChild(parent, elm); } @@ -4802,6 +5007,7 @@ function createPatchFunction (backend) { function removeAndInvokeRemoveHook (vnode, rm) { if (isDef(rm) || isDef(vnode.data)) { + var i; var listeners = cbs.remove.length + 1; if (isDef(rm)) { // we have a recursively passed down rm callback @@ -5063,8 +5269,8 @@ function createPatchFunction (backend) { // mounting to a real element // check if this is server-rendered content and if we can perform // a successful hydration. - if (oldVnode.nodeType === 1 && oldVnode.hasAttribute('server-rendered')) { - oldVnode.removeAttribute('server-rendered'); + if (oldVnode.nodeType === 1 && oldVnode.hasAttribute(SSR_ATTR)) { + oldVnode.removeAttribute(SSR_ATTR); hydrating = true; } if (isTrue(hydrating)) { @@ -5231,7 +5437,11 @@ function getRawDirName (dir) { function callHook$1 (dir, hook, vnode, oldVnode, isDestroy) { var fn = dir.def && dir.def[hook]; if (fn) { - fn(vnode.elm, dir, vnode, oldVnode, isDestroy); + try { + fn(vnode.elm, dir, vnode, oldVnode, isDestroy); + } catch (e) { + handleError(e, vnode.context, ("directive " + (dir.name) + " " + hook + " hook")); + } } } @@ -5243,7 +5453,7 @@ var baseModules = [ /* */ function updateAttrs (oldVnode, vnode) { - if (!oldVnode.data.attrs && !vnode.data.attrs) { + if (isUndef(oldVnode.data.attrs) && isUndef(vnode.data.attrs)) { return } var key, cur, old; @@ -5251,7 +5461,7 @@ function updateAttrs (oldVnode, vnode) { var oldAttrs = oldVnode.data.attrs || {}; var attrs = vnode.data.attrs || {}; // clone observed objects, as the user probably wants to mutate it - if (attrs.__ob__) { + if (isDef(attrs.__ob__)) { attrs = vnode.data.attrs = extend({}, attrs); } @@ -5268,7 +5478,7 @@ function updateAttrs (oldVnode, vnode) { setAttr(elm, 'value', attrs.value); } for (key in oldAttrs) { - if (attrs[key] == null) { + if (isUndef(attrs[key])) { if (isXlink(key)) { elm.removeAttributeNS(xlinkNS, getXlinkProp(key)); } else if (!isEnumeratedAttr(key)) { @@ -5315,8 +5525,15 @@ function updateClass (oldVnode, vnode) { var el = vnode.elm; var data = vnode.data; var oldData = oldVnode.data; - if (!data.staticClass && !data.class && - (!oldData || (!oldData.staticClass && !oldData.class))) { + if ( + isUndef(data.staticClass) && + isUndef(data.class) && ( + isUndef(oldData) || ( + isUndef(oldData.staticClass) && + isUndef(oldData.class) + ) + ) + ) { return } @@ -5324,7 +5541,7 @@ function updateClass (oldVnode, vnode) { // handle transition classes var transitionClass = el._transitionClasses; - if (transitionClass) { + if (isDef(transitionClass)) { cls = concat(cls, stringifyClass(transitionClass)); } @@ -5477,8 +5694,20 @@ function addHandler ( name, value, modifiers, - important + important, + warn ) { + // warn prevent and passive modifier + /* istanbul ignore if */ + if ( + process.env.NODE_ENV !== 'production' && warn && + modifiers && modifiers.prevent && modifiers.passive + ) { + warn( + 'passive and prevent can\'t be used together. ' + + 'Passive handler can\'t prevent default event.' + ); + } // check capture modifier if (modifiers && modifiers.capture) { delete modifiers.capture; @@ -5488,6 +5717,11 @@ function addHandler ( delete modifiers.once; name = '~' + name; // mark the event as once } + /* istanbul ignore if */ + if (modifiers && modifiers.passive) { + delete modifiers.passive; + name = '&' + name; // mark the event as passive + } var events; if (modifiers && modifiers.native) { delete modifiers.native; @@ -5769,7 +6003,7 @@ function genCheckboxModel ( '$$i=_i($$a,$$v);' + "if($$c){$$i<0&&(" + value + "=$$a.concat($$v))}" + "else{$$i>-1&&(" + value + "=$$a.slice(0,$$i).concat($$a.slice($$i+1)))}" + - "}else{" + value + "=$$c}", + "}else{" + (genAssignmentCode(value, '$$c')) + "}", null, true ); } @@ -5849,13 +6083,13 @@ function genDefaultModel ( function normalizeEvents (on) { var event; /* istanbul ignore if */ - if (on[RANGE_TOKEN]) { + if (isDef(on[RANGE_TOKEN])) { // IE input[type=range] only supports `change` event event = isIE ? 'change' : 'input'; on[event] = [].concat(on[RANGE_TOKEN], on[event] || []); delete on[RANGE_TOKEN]; } - if (on[CHECKBOX_RADIO_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] || []); @@ -5868,10 +6102,11 @@ var target$1; function add$1 ( event, handler, - once, - capture + once$$1, + capture, + passive ) { - if (once) { + if (once$$1) { var oldHandler = handler; var _target = target$1; // save current target element in closure handler = function (ev) { @@ -5883,7 +6118,13 @@ function add$1 ( } }; } - target$1.addEventListener(event, handler, capture); + target$1.addEventListener( + event, + handler, + supportsPassive + ? { capture: capture, passive: passive } + : capture + ); } function remove$2 ( @@ -5896,7 +6137,7 @@ function remove$2 ( } function updateDOMListeners (oldVnode, vnode) { - if (!oldVnode.data.on && !vnode.data.on) { + if (isUndef(oldVnode.data.on) && isUndef(vnode.data.on)) { return } var on = vnode.data.on || {}; @@ -5914,7 +6155,7 @@ var events = { /* */ function updateDOMProps (oldVnode, vnode) { - if (!oldVnode.data.domProps && !vnode.data.domProps) { + if (isUndef(oldVnode.data.domProps) && isUndef(vnode.data.domProps)) { return } var key, cur; @@ -5922,12 +6163,12 @@ function updateDOMProps (oldVnode, vnode) { var oldProps = oldVnode.data.domProps || {}; var props = vnode.data.domProps || {}; // clone observed objects, as the user probably wants to mutate it - if (props.__ob__) { + if (isDef(props.__ob__)) { props = vnode.data.domProps = extend({}, props); } for (key in oldProps) { - if (props[key] == null) { + if (isUndef(props[key])) { elm[key] = ''; } } @@ -5979,10 +6220,10 @@ function isDirty (elm, checkVal) { function isInputChanged (elm, newVal) { var value = elm.value; var modifiers = elm._vModifiers; // injected by v-model runtime - if ((modifiers && modifiers.number) || elm.type === 'number') { + if ((isDef(modifiers) && modifiers.number) || elm.type === 'number') { return toNumber(value) !== toNumber(newVal) } - if (modifiers && modifiers.trim) { + if (isDef(modifiers) && modifiers.trim) { return value.trim() !== newVal.trim() } return value !== newVal @@ -6071,7 +6312,17 @@ var setProp = function (el, name, val) { } else if (importantRE.test(val)) { el.style.setProperty(name, val.replace(importantRE, ''), 'important'); } else { - el.style[normalize(name)] = val; + var normalizedName = normalize(name); + if (Array.isArray(val)) { + // Support values array created by autoprefixer, e.g. + // {display: ["-webkit-box", "-ms-flexbox", "flex"]} + // Set them one by one, and the browser will only set those it can recognize + for (var i = 0, len = val.length; i < len; i++) { + el.style[normalizedName] = val[i]; + } + } else { + el.style[normalizedName] = val; + } } }; @@ -6097,27 +6348,32 @@ function updateStyle (oldVnode, vnode) { var data = vnode.data; var oldData = oldVnode.data; - if (!data.staticStyle && !data.style && - !oldData.staticStyle && !oldData.style) { + if (isUndef(data.staticStyle) && isUndef(data.style) && + isUndef(oldData.staticStyle) && isUndef(oldData.style)) { return } var cur, name; var el = vnode.elm; - var oldStaticStyle = oldVnode.data.staticStyle; - var oldStyleBinding = oldVnode.data.style || {}; + var oldStaticStyle = oldData.staticStyle; + var oldStyleBinding = oldData.normalizedStyle || oldData.style || {}; // if static style exists, stylebinding already merged into it when doing normalizeStyleData var oldStyle = oldStaticStyle || oldStyleBinding; var style = normalizeStyleBinding(vnode.data.style) || {}; - vnode.data.style = style.__ob__ ? extend({}, style) : style; + // store normalized style under a different key for next diff + // make sure to clone it if it's reactive, since the user likley wants + // to mutate it. + vnode.data.normalizedStyle = isDef(style.__ob__) + ? extend({}, style) + : style; var newStyle = getStyle(vnode, true); for (name in oldStyle) { - if (newStyle[name] == null) { + if (isUndef(newStyle[name])) { setProp(el, name, ''); } } @@ -6368,38 +6624,39 @@ function enter (vnode, toggleDisplay) { var el = vnode.elm; // call leave callback now - if (el._leaveCb) { + if (isDef(el._leaveCb)) { el._leaveCb.cancelled = true; el._leaveCb(); } var data = resolveTransition(vnode.data.transition); - if (!data) { + if (isUndef(data)) { return } /* istanbul ignore if */ - if (el._enterCb || el.nodeType !== 1) { + if (isDef(el._enterCb) || el.nodeType !== 1) { return } - var css = data.css; - var type = data.type; - var enterClass = data.enterClass; - var enterToClass = data.enterToClass; - var enterActiveClass = data.enterActiveClass; - var appearClass = data.appearClass; - var appearToClass = data.appearToClass; - var appearActiveClass = data.appearActiveClass; - var beforeEnter = data.beforeEnter; - var enter = data.enter; - var afterEnter = data.afterEnter; - var enterCancelled = data.enterCancelled; - var beforeAppear = data.beforeAppear; - var appear = data.appear; - var afterAppear = data.afterAppear; - var appearCancelled = data.appearCancelled; - var duration = data.duration; + var ref = (data); + var css = ref.css; + var type = ref.type; + var enterClass = ref.enterClass; + var enterToClass = ref.enterToClass; + var enterActiveClass = ref.enterActiveClass; + var appearClass = ref.appearClass; + var appearToClass = ref.appearToClass; + var appearActiveClass = ref.appearActiveClass; + var beforeEnter = ref.beforeEnter; + var enter = ref.enter; + var afterEnter = ref.afterEnter; + var enterCancelled = ref.enterCancelled; + var beforeAppear = ref.beforeAppear; + var appear = ref.appear; + var afterAppear = ref.afterAppear; + var appearCancelled = ref.appearCancelled; + var duration = ref.duration; // activeInstance will always be the component managing this // transition. One edge case to check is when the is placed @@ -6516,32 +6773,33 @@ function leave (vnode, rm) { var el = vnode.elm; // call enter callback now - if (el._enterCb) { + if (isDef(el._enterCb)) { el._enterCb.cancelled = true; el._enterCb(); } var data = resolveTransition(vnode.data.transition); - if (!data) { + if (isUndef(data)) { return rm() } /* istanbul ignore if */ - if (el._leaveCb || el.nodeType !== 1) { + if (isDef(el._leaveCb) || el.nodeType !== 1) { return } - var css = data.css; - var type = data.type; - var leaveClass = data.leaveClass; - var leaveToClass = data.leaveToClass; - var leaveActiveClass = data.leaveActiveClass; - var beforeLeave = data.beforeLeave; - var leave = data.leave; - var afterLeave = data.afterLeave; - var leaveCancelled = data.leaveCancelled; - var delayLeave = data.delayLeave; - var duration = data.duration; + var ref = (data); + var css = ref.css; + var type = ref.type; + var leaveClass = ref.leaveClass; + var leaveToClass = ref.leaveToClass; + var leaveActiveClass = ref.leaveActiveClass; + var beforeLeave = ref.beforeLeave; + var leave = ref.leave; + var afterLeave = ref.afterLeave; + var leaveCancelled = ref.leaveCancelled; + var delayLeave = ref.delayLeave; + var duration = ref.duration; var expectsCSS = css !== false && !isIE9; var userWantsControl = getHookArgumentsLength(leave); @@ -6642,9 +6900,11 @@ function isValidDuration (val) { * - a plain function (.length) */ function getHookArgumentsLength (fn) { - if (!fn) { return false } + if (isUndef(fn)) { + return false + } var invokerFns = fn.fns; - if (invokerFns) { + if (isDef(invokerFns)) { // invoker return getHookArgumentsLength( Array.isArray(invokerFns) @@ -6657,7 +6917,7 @@ function getHookArgumentsLength (fn) { } function _enter (_, vnode) { - if (!vnode.data.show) { + if (vnode.data.show !== true) { enter(vnode); } } @@ -6667,7 +6927,7 @@ var transition = inBrowser ? { activate: _enter, remove: function remove$$1 (vnode, rm) { /* istanbul ignore else */ - if (!vnode.data.show) { + if (vnode.data.show !== true) { leave(vnode, rm); } else { rm(); @@ -6722,6 +6982,11 @@ var model$1 = { } else if (vnode.tag === 'textarea' || el.type === 'text' || el.type === 'password') { el._vModifiers = binding.modifiers; if (!binding.modifiers.lazy) { + // Safari < 10.2 & UIWebView doesn't fire compositionend when + // switching focus before confirming composition choice + // this also fixes the issue where some browsers e.g. iOS Chrome + // fires "change" instead of "input" on autocomplete. + el.addEventListener('change', onCompositionEnd); if (!isAndroid) { el.addEventListener('compositionstart', onCompositionStart); el.addEventListener('compositionend', onCompositionEnd); @@ -6933,9 +7198,11 @@ function extractTransitionData (comp) { } function placeholder (h, rawChild) { - return /\d-keep-alive$/.test(rawChild.tag) - ? h('keep-alive') - : null + if (/\d-keep-alive$/.test(rawChild.tag)) { + return h('keep-alive', { + props: rawChild.componentOptions.propsData + }) + } } function hasParentTransition (vnode) { @@ -7233,6 +7500,7 @@ var platformComponents = { // install platform specific utils Vue$3.config.mustUseProp = mustUseProp; Vue$3.config.isReservedTag = isReservedTag; +Vue$3.config.isReservedAttr = isReservedAttr; Vue$3.config.getTagNamespace = getTagNamespace; Vue$3.config.isUnknownElement = isUnknownElement; @@ -8113,6 +8381,13 @@ function processAttrs (el) { if (modifiers.camel) { name = camelize(name); } + if (modifiers.sync) { + addHandler( + el, + ("update:" + (camelize(name))), + genAssignmentCode(value, "$event") + ); + } } if (isProp || platformMustUseProp(el.tag, el.attrsMap.type, name)) { addProp(el, name, value); @@ -8121,7 +8396,7 @@ function processAttrs (el) { } } else if (onRE.test(name)) { // v-on name = name.replace(onRE, ''); - addHandler(el, name, value, modifiers); + addHandler(el, name, value, modifiers, false, warn$2); } else { // normal directives name = name.replace(dirRE, ''); // parse arg @@ -8176,7 +8451,10 @@ function parseModifiers (name) { function makeAttrsMap (attrs) { var map = {}; for (var i = 0, l = attrs.length; i < l; i++) { - if (process.env.NODE_ENV !== 'production' && map[attrs[i].name] && !isIE) { + if ( + process.env.NODE_ENV !== 'production' && + map[attrs[i].name] && !isIE && !isEdge + ) { warn$2('duplicate attribute: ' + attrs[i].name); } map[attrs[i].name] = attrs[i].value; @@ -8384,10 +8662,25 @@ var modifierCode = { right: genGuard("'button' in $event && $event.button !== 2") }; -function genHandlers (events, native) { +function genHandlers ( + events, + native, + warn +) { var res = native ? 'nativeOn:{' : 'on:{'; for (var name in events) { - res += "\"" + name + "\":" + (genHandler(name, events[name])) + ","; + var handler = events[name]; + // #5330: warn click.right, since right clicks do not actually fire click events. + if (process.env.NODE_ENV !== 'production' && + name === 'click' && + handler && handler.modifiers && handler.modifiers.right + ) { + warn( + "Use \"contextmenu\" instead of \"click.right\" since right clicks " + + "do not actually fire \"click\" events." + ); + } + res += "\"" + name + "\":" + (genHandler(name, handler)) + ","; } return res.slice(0, -1) + '}' } @@ -8661,10 +8954,10 @@ function genData (el) { } // event handlers if (el.events) { - data += (genHandlers(el.events)) + ","; + data += (genHandlers(el.events, false, warn$3)) + ","; } if (el.nativeEvents) { - data += (genHandlers(el.nativeEvents, true)) + ","; + data += (genHandlers(el.nativeEvents, true, warn$3)) + ","; } // slot target if (el.slotTarget) { @@ -8901,8 +9194,9 @@ function checkNode (node, errors) { } function checkEvent (exp, text, errors) { - var keywordMatch = exp.replace(stripStringRE, '').match(unaryOperatorsRE); - if (keywordMatch) { + var stipped = exp.replace(stripStringRE, ''); + var keywordMatch = stipped.match(unaryOperatorsRE); + if (keywordMatch && stipped.charAt(keywordMatch.index - 1) !== '$') { errors.push( "avoid using JavaScript unary operator as property name: " + "\"" + (keywordMatch[0]) + "\" in expression " + (text.trim()) diff --git a/dist/vue.esm.js b/dist/vue.esm.js index 86a3c509..077e60b7 100644 --- a/dist/vue.esm.js +++ b/dist/vue.esm.js @@ -1,10 +1,54 @@ /*! - * Vue.js v2.2.6 + * Vue.js v2.3.0-beta.1 * (c) 2014-2017 Evan You * Released under the MIT License. */ /* */ +// these helpers produces better vm code in JS engines due to their +// explicitness and function inlining +function isUndef (v) { + return v === undefined || v === null +} + +function isDef (v) { + return v !== undefined && v !== null +} + +function isTrue (v) { + return v === true +} + +/** + * Check if value is primitive + */ +function isPrimitive (value) { + return typeof value === 'string' || typeof value === 'number' +} + +/** + * Quick object check - this is primarily used to tell + * Objects from primitive values when we know the value + * is a JSON-compliant type. + */ +function isObject (obj) { + return obj !== null && typeof obj === 'object' +} + +var toString = Object.prototype.toString; + +/** + * Strict object type check. Only returns true + * for plain JavaScript objects. + */ +function isPlainObject (obj) { + return toString.call(obj) === '[object Object]' +} + +function isRegExp (v) { + return toString.call(v) === '[object RegExp]' +} + /** * Convert a value to a string that is actually rendered. */ @@ -68,13 +112,6 @@ function hasOwn (obj, key) { return hasOwnProperty.call(obj, key) } -/** - * Check if value is primitive - */ -function isPrimitive (value) { - return typeof value === 'string' || typeof value === 'number' -} - /** * Create a cached version of a pure function. */ @@ -152,25 +189,6 @@ function extend (to, _from) { return to } -/** - * Quick object check - this is primarily used to tell - * Objects from primitive values when we know the value - * is a JSON-compliant type. - */ -function isObject (obj) { - return obj !== null && typeof obj === 'object' -} - -/** - * Strict object type check. Only returns true - * for plain JavaScript objects. - */ -var toString = Object.prototype.toString; -var OBJECT_STRING = '[object Object]'; -function isPlainObject (obj) { - return toString.call(obj) === OBJECT_STRING -} - /** * Merge an Array of Objects into a single Object. */ @@ -244,14 +262,35 @@ function once (fn) { return function () { if (!called) { called = true; - fn(); + fn.apply(this, arguments); } } } +var SSR_ATTR = 'data-server-rendered'; + +var ASSET_TYPES = [ + 'component', + 'directive', + 'filter' +]; + +var LIFECYCLE_HOOKS = [ + 'beforeCreate', + 'created', + 'beforeMount', + 'mounted', + 'beforeUpdate', + 'updated', + 'beforeDestroy', + 'destroyed', + 'activated', + 'deactivated' +]; + /* */ -var config = { +var config = ({ /** * Option merge strategies (used in core/util/options) */ @@ -298,6 +337,12 @@ var config = { */ isReservedTag: no, + /** + * Check if an attribute is reserved so that it cannot be used as a component + * prop. This is platform-dependent and may be overwritten. + */ + isReservedAttr: no, + /** * Check if a tag is an unknown element. * Platform-dependent. @@ -321,35 +366,10 @@ var config = { mustUseProp: no, /** - * List of asset types that a component can own. + * Exposed for legacy reasons */ - _assetTypes: [ - 'component', - 'directive', - 'filter' - ], - - /** - * List of lifecycle hooks. - */ - _lifecycleHooks: [ - 'beforeCreate', - 'created', - 'beforeMount', - 'mounted', - 'beforeUpdate', - 'updated', - 'beforeDestroy', - 'destroyed', - 'activated', - 'deactivated' - ], - - /** - * Max circular updates allowed in a scheduler flush cycle. - */ - _maxUpdateCount: 100 -}; + _lifecycleHooks: LIFECYCLE_HOOKS +}); /* */ @@ -393,6 +413,113 @@ function parsePath (path) { } } +var warn = noop; +var tip = noop; +var formatComponentName; + +if (process.env.NODE_ENV !== 'production') { + var hasConsole = typeof console !== 'undefined'; + var classifyRE = /(?:^|[-_])(\w)/g; + var classify = function (str) { return str + .replace(classifyRE, function (c) { return c.toUpperCase(); }) + .replace(/[-_]/g, ''); }; + + warn = function (msg, vm) { + if (hasConsole && (!config.silent)) { + console.error("[Vue warn]: " + msg + ( + vm ? generateComponentTrace(vm) : '' + )); + } + }; + + tip = function (msg, vm) { + if (hasConsole && (!config.silent)) { + console.warn("[Vue tip]: " + msg + ( + vm ? generateComponentTrace(vm) : '' + )); + } + }; + + formatComponentName = function (vm, includeFile) { + 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; + if (!name && file) { + var match = file.match(/([^/\\]+)\.vue$/); + name = match && match[1]; + } + + return ( + (name ? ("<" + (classify(name)) + ">") : "") + + (file && includeFile !== false ? (" at " + file) : '') + ) + }; + + var repeat = function (str, n) { + var res = ''; + while (n) { + if (n % 2 === 1) { res += str; } + if (n > 1) { str += str; } + n >>= 1; + } + return res + }; + + var generateComponentTrace = function (vm) { + if (vm._isVue && vm.$parent) { + var tree = []; + var currentRecursiveSequence = 0; + while (vm) { + if (tree.length > 0) { + var last = tree[tree.length - 1]; + if (last.constructor === vm.constructor) { + currentRecursiveSequence++; + vm = vm.$parent; + continue + } else if (currentRecursiveSequence > 0) { + tree[tree.length - 1] = [last, currentRecursiveSequence]; + currentRecursiveSequence = 0; + } + } + tree.push(vm); + vm = vm.$parent; + } + return '\n\nfound in\n\n' + tree + .map(function (vm, i) { return ("" + (i === 0 ? '---> ' : repeat(' ', 5 + i * 2)) + (Array.isArray(vm) + ? ((formatComponentName(vm[0])) + "... (" + (vm[1]) + " recursive calls)") + : formatComponentName(vm))); }) + .join('\n') + } else { + return ("\n\n(found in " + (formatComponentName(vm)) + ")") + } + }; +} + +function handleError (err, vm, info) { + if (config.errorHandler) { + config.errorHandler.call(null, err, vm, info); + } else { + if (process.env.NODE_ENV !== 'production') { + warn(("Error in " + info + ": \"" + (err.toString()) + "\""), vm); + } + /* istanbul ignore else */ + if (inBrowser && typeof console !== 'undefined') { + console.error(err); + } else { + throw err + } + } +} + /* */ /* globals MutationObserver */ @@ -409,6 +536,20 @@ var isAndroid = UA && UA.indexOf('android') > 0; var isIOS = UA && /iphone|ipad|ipod|ios/.test(UA); var isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge; +var supportsPassive = false; +if (inBrowser) { + try { + var opts = {}; + Object.defineProperty(opts, 'passive', ({ + get: function get () { + /* istanbul ignore next */ + supportsPassive = true; + } + } )); // https://github.com/facebook/flow/issues/285 + window.addEventListener('test-passive', null, opts); + } catch (e) {} +} + // this needs to be lazy-evaled because vue may be required before // vue-server-renderer can set VUE_ENV var _isServer; @@ -431,7 +572,7 @@ var devtools = inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__; /* istanbul ignore next */ function isNative (Ctor) { - return /native code/.test(Ctor.toString()) + return typeof Ctor === 'function' && /native code/.test(Ctor.toString()) } var hasSymbol = @@ -502,15 +643,22 @@ var nextTick = (function () { return function queueNextTick (cb, ctx) { var _resolve; callbacks.push(function () { - if (cb) { cb.call(ctx); } - if (_resolve) { _resolve(ctx); } + if (cb) { + try { + cb.call(ctx); + } catch (e) { + handleError(e, ctx, 'nextTick'); + } + } else if (_resolve) { + _resolve(ctx); + } }); if (!pending) { pending = true; timerFunc(); } if (!cb && typeof Promise !== 'undefined') { - return new Promise(function (resolve) { + return new Promise(function (resolve, reject) { _resolve = resolve; }) } @@ -542,76 +690,17 @@ if (typeof Set !== 'undefined' && isNative(Set)) { }()); } -var warn = noop; -var tip = noop; -var formatComponentName; - -if (process.env.NODE_ENV !== 'production') { - var hasConsole = typeof console !== 'undefined'; - var classifyRE = /(?:^|[-_])(\w)/g; - var classify = function (str) { return str - .replace(classifyRE, function (c) { return c.toUpperCase(); }) - .replace(/[-_]/g, ''); }; - - warn = function (msg, vm) { - if (hasConsole && (!config.silent)) { - console.error("[Vue warn]: " + msg + " " + ( - vm ? formatLocation(formatComponentName(vm)) : '' - )); - } - }; - - tip = function (msg, vm) { - if (hasConsole && (!config.silent)) { - console.warn("[Vue tip]: " + msg + " " + ( - vm ? formatLocation(formatComponentName(vm)) : '' - )); - } - }; - - formatComponentName = function (vm, includeFile) { - 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; - if (!name && file) { - var match = file.match(/([^/\\]+)\.vue$/); - name = match && match[1]; - } - - return ( - (name ? ("<" + (classify(name)) + ">") : "") + - (file && includeFile !== false ? (" at " + file) : '') - ) - }; - - var formatLocation = function (str) { - if (str === "") { - str += " - use the \"name\" option for better debugging messages."; - } - return ("\n(found in " + str + ")") - }; -} - /* */ -var uid$1 = 0; +var uid = 0; /** * A dep is an observable that can have multiple * directives subscribing to it. */ var Dep = function Dep () { - this.id = uid$1++; + this.id = uid++; this.subs = []; }; @@ -1054,7 +1143,7 @@ function mergeHook ( : parentVal } -config._lifecycleHooks.forEach(function (hook) { +LIFECYCLE_HOOKS.forEach(function (hook) { strats[hook] = mergeHook; }); @@ -1072,7 +1161,7 @@ function mergeAssets (parentVal, childVal) { : res } -config._assetTypes.forEach(function (type) { +ASSET_TYPES.forEach(function (type) { strats[type + 's'] = mergeAssets; }); @@ -1198,21 +1287,20 @@ function mergeOptions ( if (process.env.NODE_ENV !== 'production') { checkComponents(child); } + + if (typeof child === 'function') { + child = child.options; + } + normalizeProps(child); normalizeDirectives(child); var extendsFrom = child.extends; if (extendsFrom) { - parent = typeof extendsFrom === 'function' - ? mergeOptions(parent, extendsFrom.options, vm) - : mergeOptions(parent, extendsFrom, vm); + parent = mergeOptions(parent, extendsFrom, vm); } if (child.mixins) { for (var i = 0, l = child.mixins.length; i < l; i++) { - var mixin = child.mixins[i]; - if (mixin.prototype instanceof Vue$3) { - mixin = mixin.options; - } - parent = mergeOptions(parent, mixin, vm); + parent = mergeOptions(parent, child.mixins[i], vm); } } var options = {}; @@ -1385,20 +1473,13 @@ function assertProp ( } } -/** - * Assert the type of a value - */ +var simpleCheckRE = /^(String|Number|Boolean|Function|Symbol)$/; + function assertType (value, type) { var valid; var expectedType = getType(type); - if (expectedType === 'String') { - valid = typeof value === (expectedType = 'string'); - } else if (expectedType === 'Number') { - valid = typeof value === (expectedType = 'number'); - } else if (expectedType === 'Boolean') { - valid = typeof value === (expectedType = 'boolean'); - } else if (expectedType === 'Function') { - valid = typeof value === (expectedType = 'function'); + if (simpleCheckRE.test(expectedType)) { + valid = typeof value === expectedType.toLowerCase(); } else if (expectedType === 'Object') { valid = isPlainObject(value); } else if (expectedType === 'Array') { @@ -1419,7 +1500,7 @@ function assertType (value, type) { */ function getType (fn) { var match = fn && fn.toString().match(/^\s*function (\w+)/); - return match && match[1] + return match ? match[1] : '' } function isType (type, fn) { @@ -1435,19 +1516,26 @@ function isType (type, fn) { return false } -function handleError (err, vm, info) { - if (config.errorHandler) { - config.errorHandler.call(null, err, vm, info); - } else { - if (process.env.NODE_ENV !== 'production') { - warn(("Error in " + info + ":"), vm); - } - /* istanbul ignore else */ - if (inBrowser && typeof console !== 'undefined') { - console.error(err); - } else { - throw err - } +var mark; +var measure; + +if (process.env.NODE_ENV !== 'production') { + var perf = inBrowser && window.performance; + /* istanbul ignore if */ + if ( + perf && + perf.mark && + perf.measure && + perf.clearMarks && + perf.clearMeasures + ) { + mark = function (tag) { return perf.mark(tag); }; + measure = function (name, startTag, endTag) { + perf.measure(name, startTag, endTag); + perf.clearMarks(startTag); + perf.clearMarks(endTag); + perf.clearMeasures(name); + }; } } @@ -1525,29 +1613,6 @@ if (process.env.NODE_ENV !== 'production') { }; } -var mark; -var measure; - -if (process.env.NODE_ENV !== 'production') { - var perf = inBrowser && window.performance; - /* istanbul ignore if */ - if ( - perf && - perf.mark && - perf.measure && - perf.clearMarks && - perf.clearMeasures - ) { - mark = function (tag) { return perf.mark(tag); }; - measure = function (name, startTag, endTag) { - perf.measure(name, startTag, endTag); - perf.clearMarks(startTag); - perf.clearMarks(endTag); - perf.clearMeasures(name); - }; - } -} - /* */ var VNode = function VNode ( @@ -1633,6 +1698,8 @@ function cloneVNodes (vnodes) { /* */ var normalizeEvent = cached(function (name) { + var passive = name.charAt(0) === '&'; + name = passive ? name.slice(1) : name; var once$$1 = name.charAt(0) === '~'; // Prefixed last, checked first name = once$$1 ? name.slice(1) : name; var capture = name.charAt(0) === '!'; @@ -1640,7 +1707,8 @@ var normalizeEvent = cached(function (name) { return { name: name, once: once$$1, - capture: capture + capture: capture, + passive: passive } }); @@ -1674,23 +1742,23 @@ function updateListeners ( cur = on[name]; old = oldOn[name]; event = normalizeEvent(name); - if (!cur) { + if (isUndef(cur)) { process.env.NODE_ENV !== 'production' && warn( "Invalid handler for event \"" + (event.name) + "\": got " + String(cur), vm ); - } else if (!old) { - if (!cur.fns) { + } else if (isUndef(old)) { + if (isUndef(cur.fns)) { cur = on[name] = createFnInvoker(cur); } - add(event.name, cur, event.once, event.capture); + add(event.name, cur, event.once, event.capture, event.passive); } else if (cur !== old) { old.fns = cur; on[name] = old; } } for (name in oldOn) { - if (!on[name]) { + if (isUndef(on[name])) { event = normalizeEvent(name); remove$$1(event.name, oldOn[name], event.capture); } @@ -1710,12 +1778,12 @@ function mergeVNodeHook (def, hookKey, hook) { remove(invoker.fns, wrappedHook); } - if (!oldHook) { + if (isUndef(oldHook)) { // no existing hook invoker = createFnInvoker([wrappedHook]); } else { /* istanbul ignore if */ - if (oldHook.fns && oldHook.merged) { + if (isDef(oldHook.fns) && isTrue(oldHook.merged)) { // already a merged invoker invoker = oldHook; invoker.fns.push(wrappedHook); @@ -1731,6 +1799,74 @@ function mergeVNodeHook (def, hookKey, hook) { /* */ +function extractPropsFromVNodeData ( + data, + Ctor, + tag +) { + // we are only extracting raw values here. + // validation and default values are handled in the child + // component itself. + var propOptions = Ctor.options.props; + if (isUndef(propOptions)) { + return + } + var res = {}; + var attrs = data.attrs; + var props = data.props; + if (isDef(attrs) || isDef(props)) { + for (var key in propOptions) { + var altKey = hyphenate(key); + if (process.env.NODE_ENV !== 'production') { + var keyInLowerCase = key.toLowerCase(); + if ( + key !== keyInLowerCase && + attrs && hasOwn(attrs, keyInLowerCase) + ) { + tip( + "Prop \"" + keyInLowerCase + "\" is passed to component " + + (formatComponentName(tag || Ctor)) + ", but the declared prop name is" + + " \"" + key + "\". " + + "Note that HTML attributes are case-insensitive and camelCased " + + "props need to use their kebab-case equivalents when using in-DOM " + + "templates. You should probably use \"" + altKey + "\" instead of \"" + key + "\"." + ); + } + } + checkProp(res, props, key, altKey, true) || + checkProp(res, attrs, key, altKey, false); + } + } + return res +} + +function checkProp ( + res, + hash, + key, + altKey, + preserve +) { + if (isDef(hash)) { + if (hasOwn(hash, key)) { + res[key] = hash[key]; + if (!preserve) { + delete hash[key]; + } + return true + } else if (hasOwn(hash, altKey)) { + res[key] = hash[altKey]; + if (!preserve) { + delete hash[altKey]; + } + return true + } + } + return false +} + +/* */ + // The template compiler attempts to minimize the need for normalization by // statically analyzing the template at compile time. // @@ -1769,25 +1905,25 @@ function normalizeArrayChildren (children, nestedIndex) { var i, c, last; for (i = 0; i < children.length; i++) { c = children[i]; - if (c == null || typeof c === 'boolean') { continue } + if (isUndef(c) || typeof c === 'boolean') { continue } last = res[res.length - 1]; // nested if (Array.isArray(c)) { res.push.apply(res, normalizeArrayChildren(c, ((nestedIndex || '') + "_" + i))); } else if (isPrimitive(c)) { - if (last && last.text) { - last.text += String(c); + if (isDef(last) && isDef(last.text)) { + (last).text += String(c); } else if (c !== '') { // convert primitive to vnode res.push(createTextVNode(c)); } } else { - if (c.text && last && last.text) { + if (isDef(c.text) && isDef(last) && isDef(last.text)) { res[res.length - 1] = createTextVNode(last.text + c.text); } else { // default key for nested array children (likely generated by v-for) - if (c.tag && c.key == null && nestedIndex != null) { - c.key = "__vlist" + nestedIndex + "_" + i + "__"; + if (isDef(c.tag) && isUndef(c.key) && isDef(nestedIndex)) { + c.key = "__vlist" + ((nestedIndex)) + "_" + i + "__"; } res.push(c); } @@ -1798,10 +1934,127 @@ function normalizeArrayChildren (children, nestedIndex) { /* */ -function getFirstComponentChild (children) { - return children && children.filter(function (c) { return c && c.componentOptions; })[0] +function ensureCtor (comp, base) { + return isObject(comp) + ? base.extend(comp) + : comp } +function resolveAsyncComponent ( + factory, + baseCtor, + context +) { + if (isTrue(factory.error) && isDef(factory.errorComp)) { + return factory.errorComp + } + + if (isDef(factory.resolved)) { + return factory.resolved + } + + if (isTrue(factory.loading) && isDef(factory.loadingComp)) { + return factory.loadingComp + } + + if (isDef(factory.contexts)) { + // already pending + factory.contexts.push(context); + } else { + var contexts = factory.contexts = [context]; + var sync = true; + + var forceRender = function () { + for (var i = 0, l = contexts.length; i < l; i++) { + contexts[i].$forceUpdate(); + } + }; + + var resolve = once(function (res) { + // cache resolved + factory.resolved = ensureCtor(res, baseCtor); + // invoke callbacks only if this is not a synchronous resolve + // (async resolves are shimmed as synchronous during SSR) + if (!sync) { + forceRender(); + } + }); + + var reject = once(function (reason) { + process.env.NODE_ENV !== 'production' && warn( + "Failed to resolve async component: " + (String(factory)) + + (reason ? ("\nReason: " + reason) : '') + ); + if (isDef(factory.errorComp)) { + factory.error = true; + forceRender(); + } + }); + + var res = factory(resolve, reject); + + if (isObject(res)) { + if (typeof res.then === 'function') { + // () => Promise + if (isUndef(factory.resolved)) { + res.then(resolve, reject); + } + } else if (isDef(res.component) && typeof res.component.then === 'function') { + res.component.then(resolve, reject); + + if (isDef(res.error)) { + factory.errorComp = ensureCtor(res.error, baseCtor); + } + + if (isDef(res.loading)) { + factory.loadingComp = ensureCtor(res.loading, baseCtor); + if (res.delay === 0) { + factory.loading = true; + } else { + setTimeout(function () { + if (isUndef(factory.resolved) && isUndef(factory.error)) { + factory.loading = true; + forceRender(); + } + }, res.delay || 200); + } + } + + if (isDef(res.timeout)) { + setTimeout(function () { + reject( + process.env.NODE_ENV !== 'production' + ? ("timeout (" + (res.timeout) + "ms)") + : null + ); + }, res.timeout); + } + } + } + + sync = false; + // return in case resolved synchronously + return factory.loading + ? factory.loadingComp + : factory.resolved + } +} + +/* */ + +function getFirstComponentChild (children) { + if (Array.isArray(children)) { + for (var i = 0; i < children.length; i++) { + var c = children[i]; + if (isDef(c) && isDef(c.componentOptions)) { + return c + } + } + } +} + +/* */ + /* */ function initEvents (vm) { @@ -1947,13 +2200,13 @@ function resolveSlots ( return slots } var defaultSlot = []; - var name, child; for (var i = 0, l = children.length; i < l; i++) { - child = children[i]; + var child = children[i]; // named slots should only be respected if the vnode was rendered in the // same context. if ((child.context === context || child.functionalContext === context) && - child.data && (name = child.data.slot)) { + child.data && child.data.slot != null) { + var name = child.data.slot; var slot = (slots[name] || (slots[name] = [])); if (child.tag === 'template') { slot.push.apply(slot, child.children); @@ -2240,7 +2493,7 @@ function activateChildComponent (vm, direct) { } else if (vm._directInactive) { return } - if (vm._inactive || vm._inactive == null) { + if (vm._inactive || vm._inactive === null) { vm._inactive = false; for (var i = 0; i < vm.$children.length; i++) { activateChildComponent(vm.$children[i]); @@ -2284,7 +2537,10 @@ function callHook (vm, hook) { /* */ +var MAX_UPDATE_COUNT = 100; + var queue = []; +var activatedChildren = []; var has = {}; var circular = {}; var waiting = false; @@ -2295,7 +2551,7 @@ var index = 0; * Reset the scheduler's state. */ function resetSchedulerState () { - queue.length = 0; + queue.length = activatedChildren.length = 0; has = {}; if (process.env.NODE_ENV !== 'production') { circular = {}; @@ -2308,7 +2564,7 @@ function resetSchedulerState () { */ function flushSchedulerQueue () { flushing = true; - var watcher, id, vm; + var watcher, id; // Sort queue before flush. // This ensures that: @@ -2330,7 +2586,7 @@ function flushSchedulerQueue () { // in dev build, check and stop circular updates. if (process.env.NODE_ENV !== 'production' && has[id] != null) { circular[id] = (circular[id] || 0) + 1; - if (circular[id] > config._maxUpdateCount) { + if (circular[id] > MAX_UPDATE_COUNT) { warn( 'You may have an infinite update loop ' + ( watcher.user @@ -2344,19 +2600,15 @@ function flushSchedulerQueue () { } } - // reset scheduler before updated hook called - var oldQueue = queue.slice(); + // keep copies of post queues before resetting state + var activatedQueue = activatedChildren.slice(); + var updatedQueue = queue.slice(); + resetSchedulerState(); - // call updated hooks - index = oldQueue.length; - while (index--) { - watcher = oldQueue[index]; - vm = watcher.vm; - if (vm._watcher === watcher && vm._isMounted) { - callHook(vm, 'updated'); - } - } + // call component updated and activated hooks + callActivatedHooks(activatedQueue); + callUpdateHooks(updatedQueue); // devtool hook /* istanbul ignore if */ @@ -2365,6 +2617,35 @@ function flushSchedulerQueue () { } } +function callUpdateHooks (queue) { + var i = queue.length; + while (i--) { + var watcher = queue[i]; + var vm = watcher.vm; + if (vm._watcher === watcher && vm._isMounted) { + callHook(vm, 'updated'); + } + } +} + +/** + * Queue a kept-alive component that was activated during patch. + * The queue will be processed after the entire tree has been patched. + */ +function queueActivatedComponent (vm) { + // setting _inactive to false here so that a render function can + // rely on checking whether it's in an inactive tree (e.g. router-view) + vm._inactive = false; + activatedChildren.push(vm); +} + +function callActivatedHooks (queue) { + for (var i = 0; i < queue.length; i++) { + queue[i]._inactive = true; + activateChildComponent(queue[i], true /* true */); + } +} + /** * Push a watcher into the watcher queue. * Jobs with duplicate IDs will be skipped unless it's @@ -2668,7 +2949,11 @@ function initState (vm) { if (opts.watch) { initWatch(vm, opts.watch); } } -var isReservedProp = { key: 1, ref: 1, slot: 1 }; +var isReservedProp = { + key: 1, + ref: 1, + slot: 1 +}; function initProps (vm, propsOptions) { var propsData = vm.$options.propsData || {}; @@ -2684,7 +2969,7 @@ function initProps (vm, propsOptions) { var value = validateProp(key, propsOptions, propsData, vm); /* istanbul ignore else */ if (process.env.NODE_ENV !== 'production') { - if (isReservedProp[key]) { + if (isReservedProp[key] || config.isReservedAttr(key)) { warn( ("\"" + key + "\" is a reserved attribute and cannot be used as component prop."), vm @@ -2782,6 +3067,12 @@ function initComputed (vm, computed) { // at instantiation here. if (!(key in vm)) { defineComputed(vm, key, userDef); + } else if (process.env.NODE_ENV !== 'production') { + if (key in vm.$data) { + warn(("The computed property \"" + key + "\" is already defined in data."), vm); + } else if (vm.$options.props && key in vm.$options.props) { + warn(("The computed property \"" + key + "\" is already defined as a prop."), vm); + } } } } @@ -2911,6 +3202,113 @@ function stateMixin (Vue) { /* */ +function initProvide (vm) { + var provide = vm.$options.provide; + if (provide) { + vm._provided = typeof provide === 'function' + ? provide.call(vm) + : provide; + } +} + +function initInjections (vm) { + var result = resolveInject(vm.$options.inject, vm); + if (result) { + Object.keys(result).forEach(function (key) { + /* istanbul ignore else */ + if (process.env.NODE_ENV !== 'production') { + defineReactive$$1(vm, key, result[key], function () { + warn( + "Avoid mutating an injected value directly since the changes will be " + + "overwritten whenever the provided component re-renders. " + + "injection being mutated: \"" + key + "\"", + vm + ); + }); + } else { + defineReactive$$1(vm, key, result[key]); + } + }); + } +} + +function resolveInject (inject, vm) { + if (inject) { + // inject is :any because flow is not smart enough to figure out cached + // isArray here + var isArray = Array.isArray(inject); + var result = Object.create(null); + var keys = isArray + ? inject + : hasSymbol + ? Reflect.ownKeys(inject) + : Object.keys(inject); + + for (var i = 0; i < keys.length; i++) { + var key = keys[i]; + var provideKey = isArray ? key : inject[key]; + var source = vm; + while (source) { + if (source._provided && provideKey in source._provided) { + result[key] = source._provided[provideKey]; + break + } + source = source.$parent; + } + } + return result + } +} + +/* */ + +function createFunctionalComponent ( + Ctor, + propsData, + data, + context, + children +) { + var props = {}; + var propOptions = Ctor.options.props; + if (isDef(propOptions)) { + for (var key in propOptions) { + props[key] = validateProp(key, propOptions, propsData); + } + } else { + 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 || {}, + injections: resolveInject(Ctor.options.inject, context), + slots: function () { return resolveSlots(children, context); } + }); + if (vnode instanceof VNode) { + vnode.functionalContext = context; + if (data.slot) { + (vnode.data || (vnode.data = {})).slot = data.slot; + } + } + return vnode +} + +function mergeProps (to, from) { + for (var key in from) { + to[camelize(key)] = from[key]; + } +} + +/* */ + // hooks to be invoked on component VNodes during patch var componentVNodeHooks = { init: function init ( @@ -2947,21 +3345,33 @@ var componentVNodeHooks = { }, insert: function insert (vnode) { - if (!vnode.componentInstance._isMounted) { - vnode.componentInstance._isMounted = true; - callHook(vnode.componentInstance, 'mounted'); + var context = vnode.context; + var componentInstance = vnode.componentInstance; + if (!componentInstance._isMounted) { + componentInstance._isMounted = true; + callHook(componentInstance, 'mounted'); } if (vnode.data.keepAlive) { - activateChildComponent(vnode.componentInstance, true /* direct */); + if (context._isMounted) { + // vue-router#1212 + // During updates, a kept-alive component's child components may + // change, so directly walking the tree here may call activated hooks + // on incorrect children. Instead we push them into a queue which will + // be processed after the whole patch process ended. + queueActivatedComponent(componentInstance); + } else { + activateChildComponent(componentInstance, true /* direct */); + } } }, destroy: function destroy (vnode) { - if (!vnode.componentInstance._isDestroyed) { + var componentInstance = vnode.componentInstance; + if (!componentInstance._isDestroyed) { if (!vnode.data.keepAlive) { - vnode.componentInstance.$destroy(); + componentInstance.$destroy(); } else { - deactivateChildComponent(vnode.componentInstance, true /* direct */); + deactivateChildComponent(componentInstance, true /* direct */); } } } @@ -2976,15 +3386,19 @@ function createComponent ( children, tag ) { - if (!Ctor) { + if (isUndef(Ctor)) { return } var baseCtor = context.$options._base; + + // plain options object: turn it into a constructor if (isObject(Ctor)) { Ctor = baseCtor.extend(Ctor); } + // if at this stage it's not a constructor or an async component factory, + // reject. if (typeof Ctor !== 'function') { if (process.env.NODE_ENV !== 'production') { warn(("Invalid Component definition: " + (String(Ctor))), context); @@ -2993,20 +3407,12 @@ function createComponent ( } // async component - if (!Ctor.cid) { - if (Ctor.resolved) { - Ctor = Ctor.resolved; - } else { - Ctor = resolveAsyncComponent(Ctor, baseCtor, function () { - // it's ok to queue this on every render because - // $forceUpdate is buffered by the scheduler. - context.$forceUpdate(); - }); - if (!Ctor) { - // return nothing if this is indeed an async component - // wait for the callback to trigger parent update. - return - } + if (isUndef(Ctor.cid)) { + Ctor = resolveAsyncComponent(Ctor, baseCtor, context); + if (Ctor === undefined) { + // return nothing if this is indeed an async component + // wait for the callback to trigger parent update. + return } } @@ -3017,15 +3423,15 @@ function createComponent ( data = data || {}; // transform component v-model data into props & events - if (data.model) { + if (isDef(data.model)) { transformModel(Ctor.options, data); } // extract props - var propsData = extractProps(data, Ctor, tag); + var propsData = extractPropsFromVNodeData(data, Ctor, tag); // functional component - if (Ctor.options.functional) { + if (isTrue(Ctor.options.functional)) { return createFunctionalComponent(Ctor, propsData, data, context, children) } @@ -3035,7 +3441,7 @@ function createComponent ( // replace with listeners with .native modifier data.on = data.nativeOn; - if (Ctor.options.abstract) { + if (isTrue(Ctor.options.abstract)) { // abstract components do not keep anything // other than props & listeners data = {}; @@ -3054,40 +3460,6 @@ function createComponent ( return vnode } -function createFunctionalComponent ( - Ctor, - propsData, - data, - context, - children -) { - var props = {}; - var propOptions = Ctor.options.props; - if (propOptions) { - for (var key in propOptions) { - props[key] = validateProp(key, propOptions, propsData); - } - } - // 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, { - props: props, - data: data, - parent: context, - children: children, - slots: function () { return resolveSlots(children, context); } - }); - if (vnode instanceof VNode) { - vnode.functionalContext = context; - if (data.slot) { - (vnode.data || (vnode.data = {})).slot = data.slot; - } - } - return vnode -} - function createComponentInstanceForVnode ( vnode, // we know it's MountedComponentVNode but flow doesn't parent, // activeInstance in lifecycle state @@ -3108,125 +3480,13 @@ function createComponentInstanceForVnode ( }; // check inline-template render functions var inlineTemplate = vnode.data.inlineTemplate; - if (inlineTemplate) { + if (isDef(inlineTemplate)) { options.render = inlineTemplate.render; options.staticRenderFns = inlineTemplate.staticRenderFns; } return new vnodeComponentOptions.Ctor(options) } -function resolveAsyncComponent ( - factory, - baseCtor, - cb -) { - if (factory.requested) { - // pool callbacks - factory.pendingCallbacks.push(cb); - } else { - factory.requested = true; - var cbs = factory.pendingCallbacks = [cb]; - var sync = true; - - var resolve = function (res) { - if (isObject(res)) { - res = baseCtor.extend(res); - } - // cache resolved - factory.resolved = res; - // invoke callbacks only if this is not a synchronous resolve - // (async resolves are shimmed as synchronous during SSR) - if (!sync) { - for (var i = 0, l = cbs.length; i < l; i++) { - cbs[i](res); - } - } - }; - - var reject = function (reason) { - process.env.NODE_ENV !== 'production' && warn( - "Failed to resolve async component: " + (String(factory)) + - (reason ? ("\nReason: " + reason) : '') - ); - }; - - var res = factory(resolve, reject); - - // handle promise - if (res && typeof res.then === 'function' && !factory.resolved) { - res.then(resolve, reject); - } - - sync = false; - // return in case resolved synchronously - return factory.resolved - } -} - -function extractProps (data, Ctor, tag) { - // we are only extracting raw values here. - // validation and default values are handled in the child - // component itself. - var propOptions = Ctor.options.props; - if (!propOptions) { - return - } - var res = {}; - var attrs = data.attrs; - var props = data.props; - var domProps = data.domProps; - if (attrs || props || domProps) { - for (var key in propOptions) { - var altKey = hyphenate(key); - if (process.env.NODE_ENV !== 'production') { - var keyInLowerCase = key.toLowerCase(); - if ( - key !== keyInLowerCase && - attrs && attrs.hasOwnProperty(keyInLowerCase) - ) { - tip( - "Prop \"" + keyInLowerCase + "\" is passed to component " + - (formatComponentName(tag || Ctor)) + ", but the declared prop name is" + - " \"" + key + "\". " + - "Note that HTML attributes are case-insensitive and camelCased " + - "props need to use their kebab-case equivalents when using in-DOM " + - "templates. You should probably use \"" + altKey + "\" instead of \"" + key + "\"." - ); - } - } - checkProp(res, props, key, altKey, true) || - checkProp(res, attrs, key, altKey) || - checkProp(res, domProps, key, altKey); - } - } - return res -} - -function checkProp ( - res, - hash, - key, - altKey, - preserve -) { - if (hash) { - if (hasOwn(hash, key)) { - res[key] = hash[key]; - if (!preserve) { - delete hash[key]; - } - return true - } else if (hasOwn(hash, altKey)) { - res[key] = hash[altKey]; - if (!preserve) { - delete hash[altKey]; - } - return true - } - } - return false -} - function mergeHooks (data) { if (!data.hook) { data.hook = {}; @@ -3252,7 +3512,7 @@ function transformModel (options, data) { var prop = (options.model && options.model.prop) || 'value'; var event = (options.model && options.model.event) || 'input';(data.props || (data.props = {}))[prop] = data.model.value; var on = data.on || (data.on = {}); - if (on[event]) { + if (isDef(on[event])) { on[event] = [data.model.callback].concat(on[event]); } else { on[event] = data.model.callback; @@ -3279,7 +3539,9 @@ function createElement ( children = data; data = undefined; } - if (alwaysNormalize) { normalizationType = ALWAYS_NORMALIZE; } + if (isTrue(alwaysNormalize)) { + normalizationType = ALWAYS_NORMALIZE; + } return _createElement(context, tag, data, children, normalizationType) } @@ -3290,7 +3552,7 @@ function _createElement ( children, normalizationType ) { - if (data && data.__ob__) { + if (isDef(data) && isDef((data).__ob__)) { process.env.NODE_ENV !== 'production' && warn( "Avoid using observed data object as vnode data: " + (JSON.stringify(data)) + "\n" + 'Always create fresh vnode data objects in each render!', @@ -3324,7 +3586,7 @@ function _createElement ( config.parsePlatformTagName(tag), data, children, undefined, undefined, context ); - } else if ((Ctor = resolveAsset(context.$options, 'components', tag))) { + } else if (isDef(Ctor = resolveAsset(context.$options, 'components', tag))) { // component vnode = createComponent(Ctor, data, context, children, tag); } else { @@ -3340,7 +3602,7 @@ function _createElement ( // direct component options / constructor vnode = createComponent(tag, data, context, children); } - if (vnode) { + if (vnode !== undefined) { if (ns) { applyNS(vnode, ns); } return vnode } else { @@ -3354,10 +3616,10 @@ function applyNS (vnode, ns) { // use default namespace inside foreignObject return } - if (vnode.children) { + if (Array.isArray(vnode.children)) { for (var i = 0, l = vnode.children.length; i < l; i++) { var child = vnode.children[i]; - if (child.tag && !child.ns) { + if (isDef(child.tag) && isUndef(child.ns)) { applyNS(child, ns); } } @@ -3557,10 +3819,9 @@ function markStaticNode (node, key, isOnce) { /* */ function initRender (vm) { - vm.$vnode = null; // the placeholder node in parent tree vm._vnode = null; // the root of the child tree vm._staticTrees = null; - var parentVnode = vm.$options._parentVnode; + var parentVnode = vm.$vnode = vm.$options._parentVnode; // the placeholder node in parent tree var renderContext = parentVnode && parentVnode.context; vm.$slots = resolveSlots(vm.$options._renderChildren, renderContext); vm.$scopedSlots = emptyObject; @@ -3655,65 +3916,13 @@ function renderMixin (Vue) { /* */ -function initProvide (vm) { - var provide = vm.$options.provide; - if (provide) { - vm._provided = typeof provide === 'function' - ? provide.call(vm) - : provide; - } -} - -function initInjections (vm) { - var inject = vm.$options.inject; - if (inject) { - // inject is :any because flow is not smart enough to figure out cached - // isArray here - var isArray = Array.isArray(inject); - var keys = isArray - ? inject - : hasSymbol - ? Reflect.ownKeys(inject) - : Object.keys(inject); - - var loop = function ( i ) { - var key = keys[i]; - var provideKey = isArray ? key : inject[key]; - var source = vm; - while (source) { - if (source._provided && provideKey in source._provided) { - /* istanbul ignore else */ - if (process.env.NODE_ENV !== 'production') { - defineReactive$$1(vm, key, source._provided[provideKey], function () { - warn( - "Avoid mutating an injected value directly since the changes will be " + - "overwritten whenever the provided component re-renders. " + - "injection being mutated: \"" + key + "\"", - vm - ); - }); - } else { - defineReactive$$1(vm, key, source._provided[provideKey]); - } - break - } - source = source.$parent; - } - }; - - for (var i = 0; i < keys.length; i++) loop( i ); - } -} - -/* */ - -var uid = 0; +var uid$1 = 0; function initMixin (Vue) { Vue.prototype._init = function (options) { var vm = this; // a uid - vm._uid = uid++; + vm._uid = uid$1++; var startTag, endTag; /* istanbul ignore if */ @@ -3812,24 +4021,27 @@ function resolveConstructorOptions (Ctor) { function resolveModifiedOptions (Ctor) { var modified; var latest = Ctor.options; + var extended = Ctor.extendOptions; var sealed = Ctor.sealedOptions; for (var key in latest) { if (latest[key] !== sealed[key]) { if (!modified) { modified = {}; } - modified[key] = dedupe(latest[key], sealed[key]); + modified[key] = dedupe(latest[key], extended[key], sealed[key]); } } return modified } -function dedupe (latest, sealed) { +function dedupe (latest, extended, sealed) { // compare latest and sealed to ensure lifecycle hooks won't be duplicated // between merges if (Array.isArray(latest)) { var res = []; sealed = Array.isArray(sealed) ? sealed : [sealed]; + extended = Array.isArray(extended) ? extended : [extended]; for (var i = 0; i < latest.length; i++) { - if (sealed.indexOf(latest[i]) < 0) { + // push original options and not sealed options to exclude duplicated options + if (extended.indexOf(latest[i]) >= 0 || sealed.indexOf(latest[i]) < 0) { res.push(latest[i]); } } @@ -3945,7 +4157,7 @@ function initExtend (Vue) { // create asset registers, so extended classes // can have their private assets too. - config._assetTypes.forEach(function (type) { + ASSET_TYPES.forEach(function (type) { Sub[type] = Super[type]; }); // enable recursive self-lookup @@ -3986,7 +4198,7 @@ function initAssetRegisters (Vue) { /** * Create asset registration methods. */ - config._assetTypes.forEach(function (type) { + ASSET_TYPES.forEach(function (type) { Vue[type] = function ( id, definition @@ -4028,20 +4240,22 @@ function getComponentName (opts) { function matches (pattern, name) { if (typeof pattern === 'string') { return pattern.split(',').indexOf(name) > -1 - } else if (pattern instanceof RegExp) { + } else if (isRegExp(pattern)) { return pattern.test(name) } /* istanbul ignore next */ return false } -function pruneCache (cache, filter) { +function pruneCache (cache, current, filter) { for (var key in cache) { var cachedNode = cache[key]; if (cachedNode) { var name = getComponentName(cachedNode.componentOptions); if (name && !filter(name)) { - pruneCacheEntry(cachedNode); + if (cachedNode !== current) { + pruneCacheEntry(cachedNode); + } cache[key] = null; } } @@ -4050,9 +4264,6 @@ function pruneCache (cache, filter) { function pruneCacheEntry (vnode) { if (vnode) { - if (!vnode.componentInstance._inactive) { - callHook(vnode.componentInstance, 'deactivated'); - } vnode.componentInstance.$destroy(); } } @@ -4080,10 +4291,10 @@ var KeepAlive = { watch: { include: function include (val) { - pruneCache(this.cache, function (name) { return matches(val, name); }); + pruneCache(this.cache, this._vnode, function (name) { return matches(val, name); }); }, exclude: function exclude (val) { - pruneCache(this.cache, function (name) { return !matches(val, name); }); + pruneCache(this.cache, this._vnode, function (name) { return !matches(val, name); }); } }, @@ -4149,7 +4360,7 @@ function initGlobalAPI (Vue) { Vue.nextTick = nextTick; Vue.options = Object.create(null); - config._assetTypes.forEach(function (type) { + ASSET_TYPES.forEach(function (type) { Vue.options[type + 's'] = Object.create(null); }); @@ -4171,10 +4382,14 @@ Object.defineProperty(Vue$3.prototype, '$isServer', { get: isServerRendering }); -Vue$3.version = '2.2.6'; +Vue$3.version = '2.3.0-beta.1'; /* */ +// these are reserved for web because they are directly compiled away +// during template compilation +var isReservedAttr = makeMap('style,class'); + // attributes that should be using props for binding var acceptValue = makeMap('input,textarea,option,select'); var mustUseProp = function (tag, type, attr) { @@ -4217,13 +4432,13 @@ function genClassForVnode (vnode) { var data = vnode.data; var parentNode = vnode; var childNode = vnode; - while (childNode.componentInstance) { + while (isDef(childNode.componentInstance)) { childNode = childNode.componentInstance._vnode; if (childNode.data) { data = mergeClassData(childNode.data, data); } } - while ((parentNode = parentNode.parent)) { + while (isDef(parentNode = parentNode.parent)) { if (parentNode.data) { data = mergeClassData(data, parentNode.data); } @@ -4234,7 +4449,7 @@ function genClassForVnode (vnode) { function mergeClassData (child, parent) { return { staticClass: concat(child.staticClass, parent.staticClass), - class: child.class + class: isDef(child.class) ? [child.class, parent.class] : parent.class } @@ -4243,7 +4458,7 @@ function mergeClassData (child, parent) { function genClassFromData (data) { var dynamicClass = data.class; var staticClass = data.staticClass; - if (staticClass || dynamicClass) { + if (isDef(staticClass) || isDef(dynamicClass)) { return concat(staticClass, stringifyClass(dynamicClass)) } /* istanbul ignore next */ @@ -4255,18 +4470,18 @@ function concat (a, b) { } function stringifyClass (value) { - var res = ''; - if (!value) { - return res + if (isUndef(value)) { + return '' } if (typeof value === 'string') { return value } + var res = ''; if (Array.isArray(value)) { var stringified; for (var i = 0, l = value.length; i < l; i++) { - if (value[i]) { - if ((stringified = stringifyClass(value[i]))) { + if (isDef(value[i])) { + if (isDef(stringified = stringifyClass(value[i])) && stringified !== '') { res += stringified + ' '; } } @@ -4511,18 +4726,6 @@ var emptyNode = new VNode('', {}, []); var hooks = ['create', 'activate', 'update', 'remove', 'destroy']; -function isUndef (v) { - return v === undefined || v === null -} - -function isDef (v) { - return v !== undefined && v !== null -} - -function isTrue (v) { - return v === true -} - function sameVnode (a, b) { return ( a.key === b.key && @@ -4709,7 +4912,9 @@ function createPatchFunction (backend) { function insert (parent, elm, ref) { if (isDef(parent)) { if (isDef(ref)) { - nodeOps.insertBefore(parent, elm, ref); + if (ref.parentNode === parent) { + nodeOps.insertBefore(parent, elm, ref); + } } else { nodeOps.appendChild(parent, elm); } @@ -4800,6 +5005,7 @@ function createPatchFunction (backend) { function removeAndInvokeRemoveHook (vnode, rm) { if (isDef(rm) || isDef(vnode.data)) { + var i; var listeners = cbs.remove.length + 1; if (isDef(rm)) { // we have a recursively passed down rm callback @@ -5061,8 +5267,8 @@ function createPatchFunction (backend) { // mounting to a real element // check if this is server-rendered content and if we can perform // a successful hydration. - if (oldVnode.nodeType === 1 && oldVnode.hasAttribute('server-rendered')) { - oldVnode.removeAttribute('server-rendered'); + if (oldVnode.nodeType === 1 && oldVnode.hasAttribute(SSR_ATTR)) { + oldVnode.removeAttribute(SSR_ATTR); hydrating = true; } if (isTrue(hydrating)) { @@ -5229,7 +5435,11 @@ function getRawDirName (dir) { function callHook$1 (dir, hook, vnode, oldVnode, isDestroy) { var fn = dir.def && dir.def[hook]; if (fn) { - fn(vnode.elm, dir, vnode, oldVnode, isDestroy); + try { + fn(vnode.elm, dir, vnode, oldVnode, isDestroy); + } catch (e) { + handleError(e, vnode.context, ("directive " + (dir.name) + " " + hook + " hook")); + } } } @@ -5241,7 +5451,7 @@ var baseModules = [ /* */ function updateAttrs (oldVnode, vnode) { - if (!oldVnode.data.attrs && !vnode.data.attrs) { + if (isUndef(oldVnode.data.attrs) && isUndef(vnode.data.attrs)) { return } var key, cur, old; @@ -5249,7 +5459,7 @@ function updateAttrs (oldVnode, vnode) { var oldAttrs = oldVnode.data.attrs || {}; var attrs = vnode.data.attrs || {}; // clone observed objects, as the user probably wants to mutate it - if (attrs.__ob__) { + if (isDef(attrs.__ob__)) { attrs = vnode.data.attrs = extend({}, attrs); } @@ -5266,7 +5476,7 @@ function updateAttrs (oldVnode, vnode) { setAttr(elm, 'value', attrs.value); } for (key in oldAttrs) { - if (attrs[key] == null) { + if (isUndef(attrs[key])) { if (isXlink(key)) { elm.removeAttributeNS(xlinkNS, getXlinkProp(key)); } else if (!isEnumeratedAttr(key)) { @@ -5313,8 +5523,15 @@ function updateClass (oldVnode, vnode) { var el = vnode.elm; var data = vnode.data; var oldData = oldVnode.data; - if (!data.staticClass && !data.class && - (!oldData || (!oldData.staticClass && !oldData.class))) { + if ( + isUndef(data.staticClass) && + isUndef(data.class) && ( + isUndef(oldData) || ( + isUndef(oldData.staticClass) && + isUndef(oldData.class) + ) + ) + ) { return } @@ -5322,7 +5539,7 @@ function updateClass (oldVnode, vnode) { // handle transition classes var transitionClass = el._transitionClasses; - if (transitionClass) { + if (isDef(transitionClass)) { cls = concat(cls, stringifyClass(transitionClass)); } @@ -5475,8 +5692,20 @@ function addHandler ( name, value, modifiers, - important + important, + warn ) { + // warn prevent and passive modifier + /* istanbul ignore if */ + if ( + process.env.NODE_ENV !== 'production' && warn && + modifiers && modifiers.prevent && modifiers.passive + ) { + warn( + 'passive and prevent can\'t be used together. ' + + 'Passive handler can\'t prevent default event.' + ); + } // check capture modifier if (modifiers && modifiers.capture) { delete modifiers.capture; @@ -5486,6 +5715,11 @@ function addHandler ( delete modifiers.once; name = '~' + name; // mark the event as once } + /* istanbul ignore if */ + if (modifiers && modifiers.passive) { + delete modifiers.passive; + name = '&' + name; // mark the event as passive + } var events; if (modifiers && modifiers.native) { delete modifiers.native; @@ -5767,7 +6001,7 @@ function genCheckboxModel ( '$$i=_i($$a,$$v);' + "if($$c){$$i<0&&(" + value + "=$$a.concat($$v))}" + "else{$$i>-1&&(" + value + "=$$a.slice(0,$$i).concat($$a.slice($$i+1)))}" + - "}else{" + value + "=$$c}", + "}else{" + (genAssignmentCode(value, '$$c')) + "}", null, true ); } @@ -5847,13 +6081,13 @@ function genDefaultModel ( function normalizeEvents (on) { var event; /* istanbul ignore if */ - if (on[RANGE_TOKEN]) { + if (isDef(on[RANGE_TOKEN])) { // IE input[type=range] only supports `change` event event = isIE ? 'change' : 'input'; on[event] = [].concat(on[RANGE_TOKEN], on[event] || []); delete on[RANGE_TOKEN]; } - if (on[CHECKBOX_RADIO_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] || []); @@ -5866,10 +6100,11 @@ var target$1; function add$1 ( event, handler, - once, - capture + once$$1, + capture, + passive ) { - if (once) { + if (once$$1) { var oldHandler = handler; var _target = target$1; // save current target element in closure handler = function (ev) { @@ -5881,7 +6116,13 @@ function add$1 ( } }; } - target$1.addEventListener(event, handler, capture); + target$1.addEventListener( + event, + handler, + supportsPassive + ? { capture: capture, passive: passive } + : capture + ); } function remove$2 ( @@ -5894,7 +6135,7 @@ function remove$2 ( } function updateDOMListeners (oldVnode, vnode) { - if (!oldVnode.data.on && !vnode.data.on) { + if (isUndef(oldVnode.data.on) && isUndef(vnode.data.on)) { return } var on = vnode.data.on || {}; @@ -5912,7 +6153,7 @@ var events = { /* */ function updateDOMProps (oldVnode, vnode) { - if (!oldVnode.data.domProps && !vnode.data.domProps) { + if (isUndef(oldVnode.data.domProps) && isUndef(vnode.data.domProps)) { return } var key, cur; @@ -5920,12 +6161,12 @@ function updateDOMProps (oldVnode, vnode) { var oldProps = oldVnode.data.domProps || {}; var props = vnode.data.domProps || {}; // clone observed objects, as the user probably wants to mutate it - if (props.__ob__) { + if (isDef(props.__ob__)) { props = vnode.data.domProps = extend({}, props); } for (key in oldProps) { - if (props[key] == null) { + if (isUndef(props[key])) { elm[key] = ''; } } @@ -5977,10 +6218,10 @@ function isDirty (elm, checkVal) { function isInputChanged (elm, newVal) { var value = elm.value; var modifiers = elm._vModifiers; // injected by v-model runtime - if ((modifiers && modifiers.number) || elm.type === 'number') { + if ((isDef(modifiers) && modifiers.number) || elm.type === 'number') { return toNumber(value) !== toNumber(newVal) } - if (modifiers && modifiers.trim) { + if (isDef(modifiers) && modifiers.trim) { return value.trim() !== newVal.trim() } return value !== newVal @@ -6069,7 +6310,17 @@ var setProp = function (el, name, val) { } else if (importantRE.test(val)) { el.style.setProperty(name, val.replace(importantRE, ''), 'important'); } else { - el.style[normalize(name)] = val; + var normalizedName = normalize(name); + if (Array.isArray(val)) { + // Support values array created by autoprefixer, e.g. + // {display: ["-webkit-box", "-ms-flexbox", "flex"]} + // Set them one by one, and the browser will only set those it can recognize + for (var i = 0, len = val.length; i < len; i++) { + el.style[normalizedName] = val[i]; + } + } else { + el.style[normalizedName] = val; + } } }; @@ -6095,27 +6346,32 @@ function updateStyle (oldVnode, vnode) { var data = vnode.data; var oldData = oldVnode.data; - if (!data.staticStyle && !data.style && - !oldData.staticStyle && !oldData.style) { + if (isUndef(data.staticStyle) && isUndef(data.style) && + isUndef(oldData.staticStyle) && isUndef(oldData.style)) { return } var cur, name; var el = vnode.elm; - var oldStaticStyle = oldVnode.data.staticStyle; - var oldStyleBinding = oldVnode.data.style || {}; + var oldStaticStyle = oldData.staticStyle; + var oldStyleBinding = oldData.normalizedStyle || oldData.style || {}; // if static style exists, stylebinding already merged into it when doing normalizeStyleData var oldStyle = oldStaticStyle || oldStyleBinding; var style = normalizeStyleBinding(vnode.data.style) || {}; - vnode.data.style = style.__ob__ ? extend({}, style) : style; + // store normalized style under a different key for next diff + // make sure to clone it if it's reactive, since the user likley wants + // to mutate it. + vnode.data.normalizedStyle = isDef(style.__ob__) + ? extend({}, style) + : style; var newStyle = getStyle(vnode, true); for (name in oldStyle) { - if (newStyle[name] == null) { + if (isUndef(newStyle[name])) { setProp(el, name, ''); } } @@ -6366,38 +6622,39 @@ function enter (vnode, toggleDisplay) { var el = vnode.elm; // call leave callback now - if (el._leaveCb) { + if (isDef(el._leaveCb)) { el._leaveCb.cancelled = true; el._leaveCb(); } var data = resolveTransition(vnode.data.transition); - if (!data) { + if (isUndef(data)) { return } /* istanbul ignore if */ - if (el._enterCb || el.nodeType !== 1) { + if (isDef(el._enterCb) || el.nodeType !== 1) { return } - var css = data.css; - var type = data.type; - var enterClass = data.enterClass; - var enterToClass = data.enterToClass; - var enterActiveClass = data.enterActiveClass; - var appearClass = data.appearClass; - var appearToClass = data.appearToClass; - var appearActiveClass = data.appearActiveClass; - var beforeEnter = data.beforeEnter; - var enter = data.enter; - var afterEnter = data.afterEnter; - var enterCancelled = data.enterCancelled; - var beforeAppear = data.beforeAppear; - var appear = data.appear; - var afterAppear = data.afterAppear; - var appearCancelled = data.appearCancelled; - var duration = data.duration; + var ref = (data); + var css = ref.css; + var type = ref.type; + var enterClass = ref.enterClass; + var enterToClass = ref.enterToClass; + var enterActiveClass = ref.enterActiveClass; + var appearClass = ref.appearClass; + var appearToClass = ref.appearToClass; + var appearActiveClass = ref.appearActiveClass; + var beforeEnter = ref.beforeEnter; + var enter = ref.enter; + var afterEnter = ref.afterEnter; + var enterCancelled = ref.enterCancelled; + var beforeAppear = ref.beforeAppear; + var appear = ref.appear; + var afterAppear = ref.afterAppear; + var appearCancelled = ref.appearCancelled; + var duration = ref.duration; // activeInstance will always be the component managing this // transition. One edge case to check is when the is placed @@ -6514,32 +6771,33 @@ function leave (vnode, rm) { var el = vnode.elm; // call enter callback now - if (el._enterCb) { + if (isDef(el._enterCb)) { el._enterCb.cancelled = true; el._enterCb(); } var data = resolveTransition(vnode.data.transition); - if (!data) { + if (isUndef(data)) { return rm() } /* istanbul ignore if */ - if (el._leaveCb || el.nodeType !== 1) { + if (isDef(el._leaveCb) || el.nodeType !== 1) { return } - var css = data.css; - var type = data.type; - var leaveClass = data.leaveClass; - var leaveToClass = data.leaveToClass; - var leaveActiveClass = data.leaveActiveClass; - var beforeLeave = data.beforeLeave; - var leave = data.leave; - var afterLeave = data.afterLeave; - var leaveCancelled = data.leaveCancelled; - var delayLeave = data.delayLeave; - var duration = data.duration; + var ref = (data); + var css = ref.css; + var type = ref.type; + var leaveClass = ref.leaveClass; + var leaveToClass = ref.leaveToClass; + var leaveActiveClass = ref.leaveActiveClass; + var beforeLeave = ref.beforeLeave; + var leave = ref.leave; + var afterLeave = ref.afterLeave; + var leaveCancelled = ref.leaveCancelled; + var delayLeave = ref.delayLeave; + var duration = ref.duration; var expectsCSS = css !== false && !isIE9; var userWantsControl = getHookArgumentsLength(leave); @@ -6640,9 +6898,11 @@ function isValidDuration (val) { * - a plain function (.length) */ function getHookArgumentsLength (fn) { - if (!fn) { return false } + if (isUndef(fn)) { + return false + } var invokerFns = fn.fns; - if (invokerFns) { + if (isDef(invokerFns)) { // invoker return getHookArgumentsLength( Array.isArray(invokerFns) @@ -6655,7 +6915,7 @@ function getHookArgumentsLength (fn) { } function _enter (_, vnode) { - if (!vnode.data.show) { + if (vnode.data.show !== true) { enter(vnode); } } @@ -6665,7 +6925,7 @@ var transition = inBrowser ? { activate: _enter, remove: function remove$$1 (vnode, rm) { /* istanbul ignore else */ - if (!vnode.data.show) { + if (vnode.data.show !== true) { leave(vnode, rm); } else { rm(); @@ -6720,6 +6980,11 @@ var model$1 = { } else if (vnode.tag === 'textarea' || el.type === 'text' || el.type === 'password') { el._vModifiers = binding.modifiers; if (!binding.modifiers.lazy) { + // Safari < 10.2 & UIWebView doesn't fire compositionend when + // switching focus before confirming composition choice + // this also fixes the issue where some browsers e.g. iOS Chrome + // fires "change" instead of "input" on autocomplete. + el.addEventListener('change', onCompositionEnd); if (!isAndroid) { el.addEventListener('compositionstart', onCompositionStart); el.addEventListener('compositionend', onCompositionEnd); @@ -6931,9 +7196,11 @@ function extractTransitionData (comp) { } function placeholder (h, rawChild) { - return /\d-keep-alive$/.test(rawChild.tag) - ? h('keep-alive') - : null + if (/\d-keep-alive$/.test(rawChild.tag)) { + return h('keep-alive', { + props: rawChild.componentOptions.propsData + }) + } } function hasParentTransition (vnode) { @@ -7231,6 +7498,7 @@ var platformComponents = { // install platform specific utils Vue$3.config.mustUseProp = mustUseProp; Vue$3.config.isReservedTag = isReservedTag; +Vue$3.config.isReservedAttr = isReservedAttr; Vue$3.config.getTagNamespace = getTagNamespace; Vue$3.config.isUnknownElement = isUnknownElement; @@ -8111,6 +8379,13 @@ function processAttrs (el) { if (modifiers.camel) { name = camelize(name); } + if (modifiers.sync) { + addHandler( + el, + ("update:" + (camelize(name))), + genAssignmentCode(value, "$event") + ); + } } if (isProp || platformMustUseProp(el.tag, el.attrsMap.type, name)) { addProp(el, name, value); @@ -8119,7 +8394,7 @@ function processAttrs (el) { } } else if (onRE.test(name)) { // v-on name = name.replace(onRE, ''); - addHandler(el, name, value, modifiers); + addHandler(el, name, value, modifiers, false, warn$2); } else { // normal directives name = name.replace(dirRE, ''); // parse arg @@ -8174,7 +8449,10 @@ function parseModifiers (name) { function makeAttrsMap (attrs) { var map = {}; for (var i = 0, l = attrs.length; i < l; i++) { - if (process.env.NODE_ENV !== 'production' && map[attrs[i].name] && !isIE) { + if ( + process.env.NODE_ENV !== 'production' && + map[attrs[i].name] && !isIE && !isEdge + ) { warn$2('duplicate attribute: ' + attrs[i].name); } map[attrs[i].name] = attrs[i].value; @@ -8382,10 +8660,25 @@ var modifierCode = { right: genGuard("'button' in $event && $event.button !== 2") }; -function genHandlers (events, native) { +function genHandlers ( + events, + native, + warn +) { var res = native ? 'nativeOn:{' : 'on:{'; for (var name in events) { - res += "\"" + name + "\":" + (genHandler(name, events[name])) + ","; + var handler = events[name]; + // #5330: warn click.right, since right clicks do not actually fire click events. + if (process.env.NODE_ENV !== 'production' && + name === 'click' && + handler && handler.modifiers && handler.modifiers.right + ) { + warn( + "Use \"contextmenu\" instead of \"click.right\" since right clicks " + + "do not actually fire \"click\" events." + ); + } + res += "\"" + name + "\":" + (genHandler(name, handler)) + ","; } return res.slice(0, -1) + '}' } @@ -8659,10 +8952,10 @@ function genData (el) { } // event handlers if (el.events) { - data += (genHandlers(el.events)) + ","; + data += (genHandlers(el.events, false, warn$3)) + ","; } if (el.nativeEvents) { - data += (genHandlers(el.nativeEvents, true)) + ","; + data += (genHandlers(el.nativeEvents, true, warn$3)) + ","; } // slot target if (el.slotTarget) { @@ -8899,8 +9192,9 @@ function checkNode (node, errors) { } function checkEvent (exp, text, errors) { - var keywordMatch = exp.replace(stripStringRE, '').match(unaryOperatorsRE); - if (keywordMatch) { + var stipped = exp.replace(stripStringRE, ''); + var keywordMatch = stipped.match(unaryOperatorsRE); + if (keywordMatch && stipped.charAt(keywordMatch.index - 1) !== '$') { errors.push( "avoid using JavaScript unary operator as property name: " + "\"" + (keywordMatch[0]) + "\" in expression " + (text.trim()) diff --git a/dist/vue.js b/dist/vue.js index 6270df24..88fa82ea 100644 --- a/dist/vue.js +++ b/dist/vue.js @@ -1,5 +1,5 @@ /*! - * Vue.js v2.2.6 + * Vue.js v2.3.0-beta.1 * (c) 2014-2017 Evan You * Released under the MIT License. */ @@ -11,6 +11,50 @@ /* */ +// these helpers produces better vm code in JS engines due to their +// explicitness and function inlining +function isUndef (v) { + return v === undefined || v === null +} + +function isDef (v) { + return v !== undefined && v !== null +} + +function isTrue (v) { + return v === true +} + +/** + * Check if value is primitive + */ +function isPrimitive (value) { + return typeof value === 'string' || typeof value === 'number' +} + +/** + * Quick object check - this is primarily used to tell + * Objects from primitive values when we know the value + * is a JSON-compliant type. + */ +function isObject (obj) { + return obj !== null && typeof obj === 'object' +} + +var toString = Object.prototype.toString; + +/** + * Strict object type check. Only returns true + * for plain JavaScript objects. + */ +function isPlainObject (obj) { + return toString.call(obj) === '[object Object]' +} + +function isRegExp (v) { + return toString.call(v) === '[object RegExp]' +} + /** * Convert a value to a string that is actually rendered. */ @@ -74,13 +118,6 @@ function hasOwn (obj, key) { return hasOwnProperty.call(obj, key) } -/** - * Check if value is primitive - */ -function isPrimitive (value) { - return typeof value === 'string' || typeof value === 'number' -} - /** * Create a cached version of a pure function. */ @@ -158,25 +195,6 @@ function extend (to, _from) { return to } -/** - * Quick object check - this is primarily used to tell - * Objects from primitive values when we know the value - * is a JSON-compliant type. - */ -function isObject (obj) { - return obj !== null && typeof obj === 'object' -} - -/** - * Strict object type check. Only returns true - * for plain JavaScript objects. - */ -var toString = Object.prototype.toString; -var OBJECT_STRING = '[object Object]'; -function isPlainObject (obj) { - return toString.call(obj) === OBJECT_STRING -} - /** * Merge an Array of Objects into a single Object. */ @@ -250,14 +268,35 @@ function once (fn) { return function () { if (!called) { called = true; - fn(); + fn.apply(this, arguments); } } } +var SSR_ATTR = 'data-server-rendered'; + +var ASSET_TYPES = [ + 'component', + 'directive', + 'filter' +]; + +var LIFECYCLE_HOOKS = [ + 'beforeCreate', + 'created', + 'beforeMount', + 'mounted', + 'beforeUpdate', + 'updated', + 'beforeDestroy', + 'destroyed', + 'activated', + 'deactivated' +]; + /* */ -var config = { +var config = ({ /** * Option merge strategies (used in core/util/options) */ @@ -304,6 +343,12 @@ var config = { */ isReservedTag: no, + /** + * Check if an attribute is reserved so that it cannot be used as a component + * prop. This is platform-dependent and may be overwritten. + */ + isReservedAttr: no, + /** * Check if a tag is an unknown element. * Platform-dependent. @@ -327,35 +372,10 @@ var config = { mustUseProp: no, /** - * List of asset types that a component can own. + * Exposed for legacy reasons */ - _assetTypes: [ - 'component', - 'directive', - 'filter' - ], - - /** - * List of lifecycle hooks. - */ - _lifecycleHooks: [ - 'beforeCreate', - 'created', - 'beforeMount', - 'mounted', - 'beforeUpdate', - 'updated', - 'beforeDestroy', - 'destroyed', - 'activated', - 'deactivated' - ], - - /** - * Max circular updates allowed in a scheduler flush cycle. - */ - _maxUpdateCount: 100 -}; + _lifecycleHooks: LIFECYCLE_HOOKS +}); /* */ @@ -399,6 +419,113 @@ function parsePath (path) { } } +var warn = noop; +var tip = noop; +var formatComponentName; + +{ + var hasConsole = typeof console !== 'undefined'; + var classifyRE = /(?:^|[-_])(\w)/g; + var classify = function (str) { return str + .replace(classifyRE, function (c) { return c.toUpperCase(); }) + .replace(/[-_]/g, ''); }; + + warn = function (msg, vm) { + if (hasConsole && (!config.silent)) { + console.error("[Vue warn]: " + msg + ( + vm ? generateComponentTrace(vm) : '' + )); + } + }; + + tip = function (msg, vm) { + if (hasConsole && (!config.silent)) { + console.warn("[Vue tip]: " + msg + ( + vm ? generateComponentTrace(vm) : '' + )); + } + }; + + formatComponentName = function (vm, includeFile) { + 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; + if (!name && file) { + var match = file.match(/([^/\\]+)\.vue$/); + name = match && match[1]; + } + + return ( + (name ? ("<" + (classify(name)) + ">") : "") + + (file && includeFile !== false ? (" at " + file) : '') + ) + }; + + var repeat = function (str, n) { + var res = ''; + while (n) { + if (n % 2 === 1) { res += str; } + if (n > 1) { str += str; } + n >>= 1; + } + return res + }; + + var generateComponentTrace = function (vm) { + if (vm._isVue && vm.$parent) { + var tree = []; + var currentRecursiveSequence = 0; + while (vm) { + if (tree.length > 0) { + var last = tree[tree.length - 1]; + if (last.constructor === vm.constructor) { + currentRecursiveSequence++; + vm = vm.$parent; + continue + } else if (currentRecursiveSequence > 0) { + tree[tree.length - 1] = [last, currentRecursiveSequence]; + currentRecursiveSequence = 0; + } + } + tree.push(vm); + vm = vm.$parent; + } + return '\n\nfound in\n\n' + tree + .map(function (vm, i) { return ("" + (i === 0 ? '---> ' : repeat(' ', 5 + i * 2)) + (Array.isArray(vm) + ? ((formatComponentName(vm[0])) + "... (" + (vm[1]) + " recursive calls)") + : formatComponentName(vm))); }) + .join('\n') + } else { + return ("\n\n(found in " + (formatComponentName(vm)) + ")") + } + }; +} + +function handleError (err, vm, info) { + if (config.errorHandler) { + config.errorHandler.call(null, err, vm, info); + } else { + { + warn(("Error in " + info + ": \"" + (err.toString()) + "\""), vm); + } + /* istanbul ignore else */ + if (inBrowser && typeof console !== 'undefined') { + console.error(err); + } else { + throw err + } + } +} + /* */ /* globals MutationObserver */ @@ -415,6 +542,20 @@ var isAndroid = UA && UA.indexOf('android') > 0; var isIOS = UA && /iphone|ipad|ipod|ios/.test(UA); var isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge; +var supportsPassive = false; +if (inBrowser) { + try { + var opts = {}; + Object.defineProperty(opts, 'passive', ({ + get: function get () { + /* istanbul ignore next */ + supportsPassive = true; + } + } )); // https://github.com/facebook/flow/issues/285 + window.addEventListener('test-passive', null, opts); + } catch (e) {} +} + // this needs to be lazy-evaled because vue may be required before // vue-server-renderer can set VUE_ENV var _isServer; @@ -437,7 +578,7 @@ var devtools = inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__; /* istanbul ignore next */ function isNative (Ctor) { - return /native code/.test(Ctor.toString()) + return typeof Ctor === 'function' && /native code/.test(Ctor.toString()) } var hasSymbol = @@ -508,15 +649,22 @@ var nextTick = (function () { return function queueNextTick (cb, ctx) { var _resolve; callbacks.push(function () { - if (cb) { cb.call(ctx); } - if (_resolve) { _resolve(ctx); } + if (cb) { + try { + cb.call(ctx); + } catch (e) { + handleError(e, ctx, 'nextTick'); + } + } else if (_resolve) { + _resolve(ctx); + } }); if (!pending) { pending = true; timerFunc(); } if (!cb && typeof Promise !== 'undefined') { - return new Promise(function (resolve) { + return new Promise(function (resolve, reject) { _resolve = resolve; }) } @@ -548,76 +696,17 @@ if (typeof Set !== 'undefined' && isNative(Set)) { }()); } -var warn = noop; -var tip = noop; -var formatComponentName; - -{ - var hasConsole = typeof console !== 'undefined'; - var classifyRE = /(?:^|[-_])(\w)/g; - var classify = function (str) { return str - .replace(classifyRE, function (c) { return c.toUpperCase(); }) - .replace(/[-_]/g, ''); }; - - warn = function (msg, vm) { - if (hasConsole && (!config.silent)) { - console.error("[Vue warn]: " + msg + " " + ( - vm ? formatLocation(formatComponentName(vm)) : '' - )); - } - }; - - tip = function (msg, vm) { - if (hasConsole && (!config.silent)) { - console.warn("[Vue tip]: " + msg + " " + ( - vm ? formatLocation(formatComponentName(vm)) : '' - )); - } - }; - - formatComponentName = function (vm, includeFile) { - 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; - if (!name && file) { - var match = file.match(/([^/\\]+)\.vue$/); - name = match && match[1]; - } - - return ( - (name ? ("<" + (classify(name)) + ">") : "") + - (file && includeFile !== false ? (" at " + file) : '') - ) - }; - - var formatLocation = function (str) { - if (str === "") { - str += " - use the \"name\" option for better debugging messages."; - } - return ("\n(found in " + str + ")") - }; -} - /* */ -var uid$1 = 0; +var uid = 0; /** * A dep is an observable that can have multiple * directives subscribing to it. */ var Dep = function Dep () { - this.id = uid$1++; + this.id = uid++; this.subs = []; }; @@ -1060,7 +1149,7 @@ function mergeHook ( : parentVal } -config._lifecycleHooks.forEach(function (hook) { +LIFECYCLE_HOOKS.forEach(function (hook) { strats[hook] = mergeHook; }); @@ -1078,7 +1167,7 @@ function mergeAssets (parentVal, childVal) { : res } -config._assetTypes.forEach(function (type) { +ASSET_TYPES.forEach(function (type) { strats[type + 's'] = mergeAssets; }); @@ -1204,21 +1293,20 @@ function mergeOptions ( { checkComponents(child); } + + if (typeof child === 'function') { + child = child.options; + } + normalizeProps(child); normalizeDirectives(child); var extendsFrom = child.extends; if (extendsFrom) { - parent = typeof extendsFrom === 'function' - ? mergeOptions(parent, extendsFrom.options, vm) - : mergeOptions(parent, extendsFrom, vm); + parent = mergeOptions(parent, extendsFrom, vm); } if (child.mixins) { for (var i = 0, l = child.mixins.length; i < l; i++) { - var mixin = child.mixins[i]; - if (mixin.prototype instanceof Vue$3) { - mixin = mixin.options; - } - parent = mergeOptions(parent, mixin, vm); + parent = mergeOptions(parent, child.mixins[i], vm); } } var options = {}; @@ -1391,20 +1479,13 @@ function assertProp ( } } -/** - * Assert the type of a value - */ +var simpleCheckRE = /^(String|Number|Boolean|Function|Symbol)$/; + function assertType (value, type) { var valid; var expectedType = getType(type); - if (expectedType === 'String') { - valid = typeof value === (expectedType = 'string'); - } else if (expectedType === 'Number') { - valid = typeof value === (expectedType = 'number'); - } else if (expectedType === 'Boolean') { - valid = typeof value === (expectedType = 'boolean'); - } else if (expectedType === 'Function') { - valid = typeof value === (expectedType = 'function'); + if (simpleCheckRE.test(expectedType)) { + valid = typeof value === expectedType.toLowerCase(); } else if (expectedType === 'Object') { valid = isPlainObject(value); } else if (expectedType === 'Array') { @@ -1425,7 +1506,7 @@ function assertType (value, type) { */ function getType (fn) { var match = fn && fn.toString().match(/^\s*function (\w+)/); - return match && match[1] + return match ? match[1] : '' } function isType (type, fn) { @@ -1441,19 +1522,26 @@ function isType (type, fn) { return false } -function handleError (err, vm, info) { - if (config.errorHandler) { - config.errorHandler.call(null, err, vm, info); - } else { - { - warn(("Error in " + info + ":"), vm); - } - /* istanbul ignore else */ - if (inBrowser && typeof console !== 'undefined') { - console.error(err); - } else { - throw err - } +var mark; +var measure; + +{ + var perf = inBrowser && window.performance; + /* istanbul ignore if */ + if ( + perf && + perf.mark && + perf.measure && + perf.clearMarks && + perf.clearMeasures + ) { + mark = function (tag) { return perf.mark(tag); }; + measure = function (name, startTag, endTag) { + perf.measure(name, startTag, endTag); + perf.clearMarks(startTag); + perf.clearMarks(endTag); + perf.clearMeasures(name); + }; } } @@ -1531,29 +1619,6 @@ var initProxy; }; } -var mark; -var measure; - -{ - var perf = inBrowser && window.performance; - /* istanbul ignore if */ - if ( - perf && - perf.mark && - perf.measure && - perf.clearMarks && - perf.clearMeasures - ) { - mark = function (tag) { return perf.mark(tag); }; - measure = function (name, startTag, endTag) { - perf.measure(name, startTag, endTag); - perf.clearMarks(startTag); - perf.clearMarks(endTag); - perf.clearMeasures(name); - }; - } -} - /* */ var VNode = function VNode ( @@ -1639,6 +1704,8 @@ function cloneVNodes (vnodes) { /* */ var normalizeEvent = cached(function (name) { + var passive = name.charAt(0) === '&'; + name = passive ? name.slice(1) : name; var once$$1 = name.charAt(0) === '~'; // Prefixed last, checked first name = once$$1 ? name.slice(1) : name; var capture = name.charAt(0) === '!'; @@ -1646,7 +1713,8 @@ var normalizeEvent = cached(function (name) { return { name: name, once: once$$1, - capture: capture + capture: capture, + passive: passive } }); @@ -1680,23 +1748,23 @@ function updateListeners ( cur = on[name]; old = oldOn[name]; event = normalizeEvent(name); - if (!cur) { + if (isUndef(cur)) { "development" !== 'production' && warn( "Invalid handler for event \"" + (event.name) + "\": got " + String(cur), vm ); - } else if (!old) { - if (!cur.fns) { + } else if (isUndef(old)) { + if (isUndef(cur.fns)) { cur = on[name] = createFnInvoker(cur); } - add(event.name, cur, event.once, event.capture); + add(event.name, cur, event.once, event.capture, event.passive); } else if (cur !== old) { old.fns = cur; on[name] = old; } } for (name in oldOn) { - if (!on[name]) { + if (isUndef(on[name])) { event = normalizeEvent(name); remove$$1(event.name, oldOn[name], event.capture); } @@ -1716,12 +1784,12 @@ function mergeVNodeHook (def, hookKey, hook) { remove(invoker.fns, wrappedHook); } - if (!oldHook) { + if (isUndef(oldHook)) { // no existing hook invoker = createFnInvoker([wrappedHook]); } else { /* istanbul ignore if */ - if (oldHook.fns && oldHook.merged) { + if (isDef(oldHook.fns) && isTrue(oldHook.merged)) { // already a merged invoker invoker = oldHook; invoker.fns.push(wrappedHook); @@ -1737,6 +1805,74 @@ function mergeVNodeHook (def, hookKey, hook) { /* */ +function extractPropsFromVNodeData ( + data, + Ctor, + tag +) { + // we are only extracting raw values here. + // validation and default values are handled in the child + // component itself. + var propOptions = Ctor.options.props; + if (isUndef(propOptions)) { + return + } + var res = {}; + var attrs = data.attrs; + var props = data.props; + if (isDef(attrs) || isDef(props)) { + for (var key in propOptions) { + var altKey = hyphenate(key); + { + var keyInLowerCase = key.toLowerCase(); + if ( + key !== keyInLowerCase && + attrs && hasOwn(attrs, keyInLowerCase) + ) { + tip( + "Prop \"" + keyInLowerCase + "\" is passed to component " + + (formatComponentName(tag || Ctor)) + ", but the declared prop name is" + + " \"" + key + "\". " + + "Note that HTML attributes are case-insensitive and camelCased " + + "props need to use their kebab-case equivalents when using in-DOM " + + "templates. You should probably use \"" + altKey + "\" instead of \"" + key + "\"." + ); + } + } + checkProp(res, props, key, altKey, true) || + checkProp(res, attrs, key, altKey, false); + } + } + return res +} + +function checkProp ( + res, + hash, + key, + altKey, + preserve +) { + if (isDef(hash)) { + if (hasOwn(hash, key)) { + res[key] = hash[key]; + if (!preserve) { + delete hash[key]; + } + return true + } else if (hasOwn(hash, altKey)) { + res[key] = hash[altKey]; + if (!preserve) { + delete hash[altKey]; + } + return true + } + } + return false +} + +/* */ + // The template compiler attempts to minimize the need for normalization by // statically analyzing the template at compile time. // @@ -1775,25 +1911,25 @@ function normalizeArrayChildren (children, nestedIndex) { var i, c, last; for (i = 0; i < children.length; i++) { c = children[i]; - if (c == null || typeof c === 'boolean') { continue } + if (isUndef(c) || typeof c === 'boolean') { continue } last = res[res.length - 1]; // nested if (Array.isArray(c)) { res.push.apply(res, normalizeArrayChildren(c, ((nestedIndex || '') + "_" + i))); } else if (isPrimitive(c)) { - if (last && last.text) { - last.text += String(c); + if (isDef(last) && isDef(last.text)) { + (last).text += String(c); } else if (c !== '') { // convert primitive to vnode res.push(createTextVNode(c)); } } else { - if (c.text && last && last.text) { + if (isDef(c.text) && isDef(last) && isDef(last.text)) { res[res.length - 1] = createTextVNode(last.text + c.text); } else { // default key for nested array children (likely generated by v-for) - if (c.tag && c.key == null && nestedIndex != null) { - c.key = "__vlist" + nestedIndex + "_" + i + "__"; + if (isDef(c.tag) && isUndef(c.key) && isDef(nestedIndex)) { + c.key = "__vlist" + ((nestedIndex)) + "_" + i + "__"; } res.push(c); } @@ -1804,10 +1940,125 @@ function normalizeArrayChildren (children, nestedIndex) { /* */ -function getFirstComponentChild (children) { - return children && children.filter(function (c) { return c && c.componentOptions; })[0] +function ensureCtor (comp, base) { + return isObject(comp) + ? base.extend(comp) + : comp } +function resolveAsyncComponent ( + factory, + baseCtor, + context +) { + if (isTrue(factory.error) && isDef(factory.errorComp)) { + return factory.errorComp + } + + if (isDef(factory.resolved)) { + return factory.resolved + } + + if (isTrue(factory.loading) && isDef(factory.loadingComp)) { + return factory.loadingComp + } + + if (isDef(factory.contexts)) { + // already pending + factory.contexts.push(context); + } else { + var contexts = factory.contexts = [context]; + var sync = true; + + var forceRender = function () { + for (var i = 0, l = contexts.length; i < l; i++) { + contexts[i].$forceUpdate(); + } + }; + + var resolve = once(function (res) { + // cache resolved + factory.resolved = ensureCtor(res, baseCtor); + // invoke callbacks only if this is not a synchronous resolve + // (async resolves are shimmed as synchronous during SSR) + if (!sync) { + forceRender(); + } + }); + + var reject = once(function (reason) { + "development" !== 'production' && warn( + "Failed to resolve async component: " + (String(factory)) + + (reason ? ("\nReason: " + reason) : '') + ); + if (isDef(factory.errorComp)) { + factory.error = true; + forceRender(); + } + }); + + var res = factory(resolve, reject); + + if (isObject(res)) { + if (typeof res.then === 'function') { + // () => Promise + if (isUndef(factory.resolved)) { + res.then(resolve, reject); + } + } else if (isDef(res.component) && typeof res.component.then === 'function') { + res.component.then(resolve, reject); + + if (isDef(res.error)) { + factory.errorComp = ensureCtor(res.error, baseCtor); + } + + if (isDef(res.loading)) { + factory.loadingComp = ensureCtor(res.loading, baseCtor); + if (res.delay === 0) { + factory.loading = true; + } else { + setTimeout(function () { + if (isUndef(factory.resolved) && isUndef(factory.error)) { + factory.loading = true; + forceRender(); + } + }, res.delay || 200); + } + } + + if (isDef(res.timeout)) { + setTimeout(function () { + reject( + "timeout (" + (res.timeout) + "ms)" + ); + }, res.timeout); + } + } + } + + sync = false; + // return in case resolved synchronously + return factory.loading + ? factory.loadingComp + : factory.resolved + } +} + +/* */ + +function getFirstComponentChild (children) { + if (Array.isArray(children)) { + for (var i = 0; i < children.length; i++) { + var c = children[i]; + if (isDef(c) && isDef(c.componentOptions)) { + return c + } + } + } +} + +/* */ + /* */ function initEvents (vm) { @@ -1953,13 +2204,13 @@ function resolveSlots ( return slots } var defaultSlot = []; - var name, child; for (var i = 0, l = children.length; i < l; i++) { - child = children[i]; + var child = children[i]; // named slots should only be respected if the vnode was rendered in the // same context. if ((child.context === context || child.functionalContext === context) && - child.data && (name = child.data.slot)) { + child.data && child.data.slot != null) { + var name = child.data.slot; var slot = (slots[name] || (slots[name] = [])); if (child.tag === 'template') { slot.push.apply(slot, child.children); @@ -2246,7 +2497,7 @@ function activateChildComponent (vm, direct) { } else if (vm._directInactive) { return } - if (vm._inactive || vm._inactive == null) { + if (vm._inactive || vm._inactive === null) { vm._inactive = false; for (var i = 0; i < vm.$children.length; i++) { activateChildComponent(vm.$children[i]); @@ -2290,7 +2541,10 @@ function callHook (vm, hook) { /* */ +var MAX_UPDATE_COUNT = 100; + var queue = []; +var activatedChildren = []; var has = {}; var circular = {}; var waiting = false; @@ -2301,7 +2555,7 @@ var index = 0; * Reset the scheduler's state. */ function resetSchedulerState () { - queue.length = 0; + queue.length = activatedChildren.length = 0; has = {}; { circular = {}; @@ -2314,7 +2568,7 @@ function resetSchedulerState () { */ function flushSchedulerQueue () { flushing = true; - var watcher, id, vm; + var watcher, id; // Sort queue before flush. // This ensures that: @@ -2336,7 +2590,7 @@ function flushSchedulerQueue () { // in dev build, check and stop circular updates. if ("development" !== 'production' && has[id] != null) { circular[id] = (circular[id] || 0) + 1; - if (circular[id] > config._maxUpdateCount) { + if (circular[id] > MAX_UPDATE_COUNT) { warn( 'You may have an infinite update loop ' + ( watcher.user @@ -2350,19 +2604,15 @@ function flushSchedulerQueue () { } } - // reset scheduler before updated hook called - var oldQueue = queue.slice(); + // keep copies of post queues before resetting state + var activatedQueue = activatedChildren.slice(); + var updatedQueue = queue.slice(); + resetSchedulerState(); - // call updated hooks - index = oldQueue.length; - while (index--) { - watcher = oldQueue[index]; - vm = watcher.vm; - if (vm._watcher === watcher && vm._isMounted) { - callHook(vm, 'updated'); - } - } + // call component updated and activated hooks + callActivatedHooks(activatedQueue); + callUpdateHooks(updatedQueue); // devtool hook /* istanbul ignore if */ @@ -2371,6 +2621,35 @@ function flushSchedulerQueue () { } } +function callUpdateHooks (queue) { + var i = queue.length; + while (i--) { + var watcher = queue[i]; + var vm = watcher.vm; + if (vm._watcher === watcher && vm._isMounted) { + callHook(vm, 'updated'); + } + } +} + +/** + * Queue a kept-alive component that was activated during patch. + * The queue will be processed after the entire tree has been patched. + */ +function queueActivatedComponent (vm) { + // setting _inactive to false here so that a render function can + // rely on checking whether it's in an inactive tree (e.g. router-view) + vm._inactive = false; + activatedChildren.push(vm); +} + +function callActivatedHooks (queue) { + for (var i = 0; i < queue.length; i++) { + queue[i]._inactive = true; + activateChildComponent(queue[i], true /* true */); + } +} + /** * Push a watcher into the watcher queue. * Jobs with duplicate IDs will be skipped unless it's @@ -2672,7 +2951,11 @@ function initState (vm) { if (opts.watch) { initWatch(vm, opts.watch); } } -var isReservedProp = { key: 1, ref: 1, slot: 1 }; +var isReservedProp = { + key: 1, + ref: 1, + slot: 1 +}; function initProps (vm, propsOptions) { var propsData = vm.$options.propsData || {}; @@ -2688,7 +2971,7 @@ function initProps (vm, propsOptions) { var value = validateProp(key, propsOptions, propsData, vm); /* istanbul ignore else */ { - if (isReservedProp[key]) { + if (isReservedProp[key] || config.isReservedAttr(key)) { warn( ("\"" + key + "\" is a reserved attribute and cannot be used as component prop."), vm @@ -2784,6 +3067,12 @@ function initComputed (vm, computed) { // at instantiation here. if (!(key in vm)) { defineComputed(vm, key, userDef); + } else { + if (key in vm.$data) { + warn(("The computed property \"" + key + "\" is already defined in data."), vm); + } else if (vm.$options.props && key in vm.$options.props) { + warn(("The computed property \"" + key + "\" is already defined as a prop."), vm); + } } } } @@ -2913,6 +3202,111 @@ function stateMixin (Vue) { /* */ +function initProvide (vm) { + var provide = vm.$options.provide; + if (provide) { + vm._provided = typeof provide === 'function' + ? provide.call(vm) + : provide; + } +} + +function initInjections (vm) { + var result = resolveInject(vm.$options.inject, vm); + if (result) { + Object.keys(result).forEach(function (key) { + /* istanbul ignore else */ + { + defineReactive$$1(vm, key, result[key], function () { + warn( + "Avoid mutating an injected value directly since the changes will be " + + "overwritten whenever the provided component re-renders. " + + "injection being mutated: \"" + key + "\"", + vm + ); + }); + } + }); + } +} + +function resolveInject (inject, vm) { + if (inject) { + // inject is :any because flow is not smart enough to figure out cached + // isArray here + var isArray = Array.isArray(inject); + var result = Object.create(null); + var keys = isArray + ? inject + : hasSymbol + ? Reflect.ownKeys(inject) + : Object.keys(inject); + + for (var i = 0; i < keys.length; i++) { + var key = keys[i]; + var provideKey = isArray ? key : inject[key]; + var source = vm; + while (source) { + if (source._provided && provideKey in source._provided) { + result[key] = source._provided[provideKey]; + break + } + source = source.$parent; + } + } + return result + } +} + +/* */ + +function createFunctionalComponent ( + Ctor, + propsData, + data, + context, + children +) { + var props = {}; + var propOptions = Ctor.options.props; + if (isDef(propOptions)) { + for (var key in propOptions) { + props[key] = validateProp(key, propOptions, propsData); + } + } else { + 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 || {}, + injections: resolveInject(Ctor.options.inject, context), + slots: function () { return resolveSlots(children, context); } + }); + if (vnode instanceof VNode) { + vnode.functionalContext = context; + if (data.slot) { + (vnode.data || (vnode.data = {})).slot = data.slot; + } + } + return vnode +} + +function mergeProps (to, from) { + for (var key in from) { + to[camelize(key)] = from[key]; + } +} + +/* */ + // hooks to be invoked on component VNodes during patch var componentVNodeHooks = { init: function init ( @@ -2949,21 +3343,33 @@ var componentVNodeHooks = { }, insert: function insert (vnode) { - if (!vnode.componentInstance._isMounted) { - vnode.componentInstance._isMounted = true; - callHook(vnode.componentInstance, 'mounted'); + var context = vnode.context; + var componentInstance = vnode.componentInstance; + if (!componentInstance._isMounted) { + componentInstance._isMounted = true; + callHook(componentInstance, 'mounted'); } if (vnode.data.keepAlive) { - activateChildComponent(vnode.componentInstance, true /* direct */); + if (context._isMounted) { + // vue-router#1212 + // During updates, a kept-alive component's child components may + // change, so directly walking the tree here may call activated hooks + // on incorrect children. Instead we push them into a queue which will + // be processed after the whole patch process ended. + queueActivatedComponent(componentInstance); + } else { + activateChildComponent(componentInstance, true /* direct */); + } } }, destroy: function destroy (vnode) { - if (!vnode.componentInstance._isDestroyed) { + var componentInstance = vnode.componentInstance; + if (!componentInstance._isDestroyed) { if (!vnode.data.keepAlive) { - vnode.componentInstance.$destroy(); + componentInstance.$destroy(); } else { - deactivateChildComponent(vnode.componentInstance, true /* direct */); + deactivateChildComponent(componentInstance, true /* direct */); } } } @@ -2978,15 +3384,19 @@ function createComponent ( children, tag ) { - if (!Ctor) { + if (isUndef(Ctor)) { return } var baseCtor = context.$options._base; + + // plain options object: turn it into a constructor if (isObject(Ctor)) { Ctor = baseCtor.extend(Ctor); } + // if at this stage it's not a constructor or an async component factory, + // reject. if (typeof Ctor !== 'function') { { warn(("Invalid Component definition: " + (String(Ctor))), context); @@ -2995,20 +3405,12 @@ function createComponent ( } // async component - if (!Ctor.cid) { - if (Ctor.resolved) { - Ctor = Ctor.resolved; - } else { - Ctor = resolveAsyncComponent(Ctor, baseCtor, function () { - // it's ok to queue this on every render because - // $forceUpdate is buffered by the scheduler. - context.$forceUpdate(); - }); - if (!Ctor) { - // return nothing if this is indeed an async component - // wait for the callback to trigger parent update. - return - } + if (isUndef(Ctor.cid)) { + Ctor = resolveAsyncComponent(Ctor, baseCtor, context); + if (Ctor === undefined) { + // return nothing if this is indeed an async component + // wait for the callback to trigger parent update. + return } } @@ -3019,15 +3421,15 @@ function createComponent ( data = data || {}; // transform component v-model data into props & events - if (data.model) { + if (isDef(data.model)) { transformModel(Ctor.options, data); } // extract props - var propsData = extractProps(data, Ctor, tag); + var propsData = extractPropsFromVNodeData(data, Ctor, tag); // functional component - if (Ctor.options.functional) { + if (isTrue(Ctor.options.functional)) { return createFunctionalComponent(Ctor, propsData, data, context, children) } @@ -3037,7 +3439,7 @@ function createComponent ( // replace with listeners with .native modifier data.on = data.nativeOn; - if (Ctor.options.abstract) { + if (isTrue(Ctor.options.abstract)) { // abstract components do not keep anything // other than props & listeners data = {}; @@ -3056,40 +3458,6 @@ function createComponent ( return vnode } -function createFunctionalComponent ( - Ctor, - propsData, - data, - context, - children -) { - var props = {}; - var propOptions = Ctor.options.props; - if (propOptions) { - for (var key in propOptions) { - props[key] = validateProp(key, propOptions, propsData); - } - } - // 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, { - props: props, - data: data, - parent: context, - children: children, - slots: function () { return resolveSlots(children, context); } - }); - if (vnode instanceof VNode) { - vnode.functionalContext = context; - if (data.slot) { - (vnode.data || (vnode.data = {})).slot = data.slot; - } - } - return vnode -} - function createComponentInstanceForVnode ( vnode, // we know it's MountedComponentVNode but flow doesn't parent, // activeInstance in lifecycle state @@ -3110,125 +3478,13 @@ function createComponentInstanceForVnode ( }; // check inline-template render functions var inlineTemplate = vnode.data.inlineTemplate; - if (inlineTemplate) { + if (isDef(inlineTemplate)) { options.render = inlineTemplate.render; options.staticRenderFns = inlineTemplate.staticRenderFns; } return new vnodeComponentOptions.Ctor(options) } -function resolveAsyncComponent ( - factory, - baseCtor, - cb -) { - if (factory.requested) { - // pool callbacks - factory.pendingCallbacks.push(cb); - } else { - factory.requested = true; - var cbs = factory.pendingCallbacks = [cb]; - var sync = true; - - var resolve = function (res) { - if (isObject(res)) { - res = baseCtor.extend(res); - } - // cache resolved - factory.resolved = res; - // invoke callbacks only if this is not a synchronous resolve - // (async resolves are shimmed as synchronous during SSR) - if (!sync) { - for (var i = 0, l = cbs.length; i < l; i++) { - cbs[i](res); - } - } - }; - - var reject = function (reason) { - "development" !== 'production' && warn( - "Failed to resolve async component: " + (String(factory)) + - (reason ? ("\nReason: " + reason) : '') - ); - }; - - var res = factory(resolve, reject); - - // handle promise - if (res && typeof res.then === 'function' && !factory.resolved) { - res.then(resolve, reject); - } - - sync = false; - // return in case resolved synchronously - return factory.resolved - } -} - -function extractProps (data, Ctor, tag) { - // we are only extracting raw values here. - // validation and default values are handled in the child - // component itself. - var propOptions = Ctor.options.props; - if (!propOptions) { - return - } - var res = {}; - var attrs = data.attrs; - var props = data.props; - var domProps = data.domProps; - if (attrs || props || domProps) { - for (var key in propOptions) { - var altKey = hyphenate(key); - { - var keyInLowerCase = key.toLowerCase(); - if ( - key !== keyInLowerCase && - attrs && attrs.hasOwnProperty(keyInLowerCase) - ) { - tip( - "Prop \"" + keyInLowerCase + "\" is passed to component " + - (formatComponentName(tag || Ctor)) + ", but the declared prop name is" + - " \"" + key + "\". " + - "Note that HTML attributes are case-insensitive and camelCased " + - "props need to use their kebab-case equivalents when using in-DOM " + - "templates. You should probably use \"" + altKey + "\" instead of \"" + key + "\"." - ); - } - } - checkProp(res, props, key, altKey, true) || - checkProp(res, attrs, key, altKey) || - checkProp(res, domProps, key, altKey); - } - } - return res -} - -function checkProp ( - res, - hash, - key, - altKey, - preserve -) { - if (hash) { - if (hasOwn(hash, key)) { - res[key] = hash[key]; - if (!preserve) { - delete hash[key]; - } - return true - } else if (hasOwn(hash, altKey)) { - res[key] = hash[altKey]; - if (!preserve) { - delete hash[altKey]; - } - return true - } - } - return false -} - function mergeHooks (data) { if (!data.hook) { data.hook = {}; @@ -3254,7 +3510,7 @@ function transformModel (options, data) { var prop = (options.model && options.model.prop) || 'value'; var event = (options.model && options.model.event) || 'input';(data.props || (data.props = {}))[prop] = data.model.value; var on = data.on || (data.on = {}); - if (on[event]) { + if (isDef(on[event])) { on[event] = [data.model.callback].concat(on[event]); } else { on[event] = data.model.callback; @@ -3281,7 +3537,9 @@ function createElement ( children = data; data = undefined; } - if (alwaysNormalize) { normalizationType = ALWAYS_NORMALIZE; } + if (isTrue(alwaysNormalize)) { + normalizationType = ALWAYS_NORMALIZE; + } return _createElement(context, tag, data, children, normalizationType) } @@ -3292,7 +3550,7 @@ function _createElement ( children, normalizationType ) { - if (data && data.__ob__) { + if (isDef(data) && isDef((data).__ob__)) { "development" !== 'production' && warn( "Avoid using observed data object as vnode data: " + (JSON.stringify(data)) + "\n" + 'Always create fresh vnode data objects in each render!', @@ -3326,7 +3584,7 @@ function _createElement ( config.parsePlatformTagName(tag), data, children, undefined, undefined, context ); - } else if ((Ctor = resolveAsset(context.$options, 'components', tag))) { + } else if (isDef(Ctor = resolveAsset(context.$options, 'components', tag))) { // component vnode = createComponent(Ctor, data, context, children, tag); } else { @@ -3342,7 +3600,7 @@ function _createElement ( // direct component options / constructor vnode = createComponent(tag, data, context, children); } - if (vnode) { + if (vnode !== undefined) { if (ns) { applyNS(vnode, ns); } return vnode } else { @@ -3356,10 +3614,10 @@ function applyNS (vnode, ns) { // use default namespace inside foreignObject return } - if (vnode.children) { + if (Array.isArray(vnode.children)) { for (var i = 0, l = vnode.children.length; i < l; i++) { var child = vnode.children[i]; - if (child.tag && !child.ns) { + if (isDef(child.tag) && isUndef(child.ns)) { applyNS(child, ns); } } @@ -3559,10 +3817,9 @@ function markStaticNode (node, key, isOnce) { /* */ function initRender (vm) { - vm.$vnode = null; // the placeholder node in parent tree vm._vnode = null; // the root of the child tree vm._staticTrees = null; - var parentVnode = vm.$options._parentVnode; + var parentVnode = vm.$vnode = vm.$options._parentVnode; // the placeholder node in parent tree var renderContext = parentVnode && parentVnode.context; vm.$slots = resolveSlots(vm.$options._renderChildren, renderContext); vm.$scopedSlots = emptyObject; @@ -3655,63 +3912,13 @@ function renderMixin (Vue) { /* */ -function initProvide (vm) { - var provide = vm.$options.provide; - if (provide) { - vm._provided = typeof provide === 'function' - ? provide.call(vm) - : provide; - } -} - -function initInjections (vm) { - var inject = vm.$options.inject; - if (inject) { - // inject is :any because flow is not smart enough to figure out cached - // isArray here - var isArray = Array.isArray(inject); - var keys = isArray - ? inject - : hasSymbol - ? Reflect.ownKeys(inject) - : Object.keys(inject); - - var loop = function ( i ) { - var key = keys[i]; - var provideKey = isArray ? key : inject[key]; - var source = vm; - while (source) { - if (source._provided && provideKey in source._provided) { - /* istanbul ignore else */ - { - defineReactive$$1(vm, key, source._provided[provideKey], function () { - warn( - "Avoid mutating an injected value directly since the changes will be " + - "overwritten whenever the provided component re-renders. " + - "injection being mutated: \"" + key + "\"", - vm - ); - }); - } - break - } - source = source.$parent; - } - }; - - for (var i = 0; i < keys.length; i++) loop( i ); - } -} - -/* */ - -var uid = 0; +var uid$1 = 0; function initMixin (Vue) { Vue.prototype._init = function (options) { var vm = this; // a uid - vm._uid = uid++; + vm._uid = uid$1++; var startTag, endTag; /* istanbul ignore if */ @@ -3808,24 +4015,27 @@ function resolveConstructorOptions (Ctor) { function resolveModifiedOptions (Ctor) { var modified; var latest = Ctor.options; + var extended = Ctor.extendOptions; var sealed = Ctor.sealedOptions; for (var key in latest) { if (latest[key] !== sealed[key]) { if (!modified) { modified = {}; } - modified[key] = dedupe(latest[key], sealed[key]); + modified[key] = dedupe(latest[key], extended[key], sealed[key]); } } return modified } -function dedupe (latest, sealed) { +function dedupe (latest, extended, sealed) { // compare latest and sealed to ensure lifecycle hooks won't be duplicated // between merges if (Array.isArray(latest)) { var res = []; sealed = Array.isArray(sealed) ? sealed : [sealed]; + extended = Array.isArray(extended) ? extended : [extended]; for (var i = 0; i < latest.length; i++) { - if (sealed.indexOf(latest[i]) < 0) { + // push original options and not sealed options to exclude duplicated options + if (extended.indexOf(latest[i]) >= 0 || sealed.indexOf(latest[i]) < 0) { res.push(latest[i]); } } @@ -3941,7 +4151,7 @@ function initExtend (Vue) { // create asset registers, so extended classes // can have their private assets too. - config._assetTypes.forEach(function (type) { + ASSET_TYPES.forEach(function (type) { Sub[type] = Super[type]; }); // enable recursive self-lookup @@ -3982,7 +4192,7 @@ function initAssetRegisters (Vue) { /** * Create asset registration methods. */ - config._assetTypes.forEach(function (type) { + ASSET_TYPES.forEach(function (type) { Vue[type] = function ( id, definition @@ -4024,20 +4234,22 @@ function getComponentName (opts) { function matches (pattern, name) { if (typeof pattern === 'string') { return pattern.split(',').indexOf(name) > -1 - } else if (pattern instanceof RegExp) { + } else if (isRegExp(pattern)) { return pattern.test(name) } /* istanbul ignore next */ return false } -function pruneCache (cache, filter) { +function pruneCache (cache, current, filter) { for (var key in cache) { var cachedNode = cache[key]; if (cachedNode) { var name = getComponentName(cachedNode.componentOptions); if (name && !filter(name)) { - pruneCacheEntry(cachedNode); + if (cachedNode !== current) { + pruneCacheEntry(cachedNode); + } cache[key] = null; } } @@ -4046,9 +4258,6 @@ function pruneCache (cache, filter) { function pruneCacheEntry (vnode) { if (vnode) { - if (!vnode.componentInstance._inactive) { - callHook(vnode.componentInstance, 'deactivated'); - } vnode.componentInstance.$destroy(); } } @@ -4076,10 +4285,10 @@ var KeepAlive = { watch: { include: function include (val) { - pruneCache(this.cache, function (name) { return matches(val, name); }); + pruneCache(this.cache, this._vnode, function (name) { return matches(val, name); }); }, exclude: function exclude (val) { - pruneCache(this.cache, function (name) { return !matches(val, name); }); + pruneCache(this.cache, this._vnode, function (name) { return !matches(val, name); }); } }, @@ -4145,7 +4354,7 @@ function initGlobalAPI (Vue) { Vue.nextTick = nextTick; Vue.options = Object.create(null); - config._assetTypes.forEach(function (type) { + ASSET_TYPES.forEach(function (type) { Vue.options[type + 's'] = Object.create(null); }); @@ -4167,10 +4376,14 @@ Object.defineProperty(Vue$3.prototype, '$isServer', { get: isServerRendering }); -Vue$3.version = '2.2.6'; +Vue$3.version = '2.3.0-beta.1'; /* */ +// these are reserved for web because they are directly compiled away +// during template compilation +var isReservedAttr = makeMap('style,class'); + // attributes that should be using props for binding var acceptValue = makeMap('input,textarea,option,select'); var mustUseProp = function (tag, type, attr) { @@ -4213,13 +4426,13 @@ function genClassForVnode (vnode) { var data = vnode.data; var parentNode = vnode; var childNode = vnode; - while (childNode.componentInstance) { + while (isDef(childNode.componentInstance)) { childNode = childNode.componentInstance._vnode; if (childNode.data) { data = mergeClassData(childNode.data, data); } } - while ((parentNode = parentNode.parent)) { + while (isDef(parentNode = parentNode.parent)) { if (parentNode.data) { data = mergeClassData(data, parentNode.data); } @@ -4230,7 +4443,7 @@ function genClassForVnode (vnode) { function mergeClassData (child, parent) { return { staticClass: concat(child.staticClass, parent.staticClass), - class: child.class + class: isDef(child.class) ? [child.class, parent.class] : parent.class } @@ -4239,7 +4452,7 @@ function mergeClassData (child, parent) { function genClassFromData (data) { var dynamicClass = data.class; var staticClass = data.staticClass; - if (staticClass || dynamicClass) { + if (isDef(staticClass) || isDef(dynamicClass)) { return concat(staticClass, stringifyClass(dynamicClass)) } /* istanbul ignore next */ @@ -4251,18 +4464,18 @@ function concat (a, b) { } function stringifyClass (value) { - var res = ''; - if (!value) { - return res + if (isUndef(value)) { + return '' } if (typeof value === 'string') { return value } + var res = ''; if (Array.isArray(value)) { var stringified; for (var i = 0, l = value.length; i < l; i++) { - if (value[i]) { - if ((stringified = stringifyClass(value[i]))) { + if (isDef(value[i])) { + if (isDef(stringified = stringifyClass(value[i])) && stringified !== '') { res += stringified + ' '; } } @@ -4507,18 +4720,6 @@ var emptyNode = new VNode('', {}, []); var hooks = ['create', 'activate', 'update', 'remove', 'destroy']; -function isUndef (v) { - return v === undefined || v === null -} - -function isDef (v) { - return v !== undefined && v !== null -} - -function isTrue (v) { - return v === true -} - function sameVnode (a, b) { return ( a.key === b.key && @@ -4705,7 +4906,9 @@ function createPatchFunction (backend) { function insert (parent, elm, ref) { if (isDef(parent)) { if (isDef(ref)) { - nodeOps.insertBefore(parent, elm, ref); + if (ref.parentNode === parent) { + nodeOps.insertBefore(parent, elm, ref); + } } else { nodeOps.appendChild(parent, elm); } @@ -4796,6 +4999,7 @@ function createPatchFunction (backend) { function removeAndInvokeRemoveHook (vnode, rm) { if (isDef(rm) || isDef(vnode.data)) { + var i; var listeners = cbs.remove.length + 1; if (isDef(rm)) { // we have a recursively passed down rm callback @@ -5057,8 +5261,8 @@ function createPatchFunction (backend) { // mounting to a real element // check if this is server-rendered content and if we can perform // a successful hydration. - if (oldVnode.nodeType === 1 && oldVnode.hasAttribute('server-rendered')) { - oldVnode.removeAttribute('server-rendered'); + if (oldVnode.nodeType === 1 && oldVnode.hasAttribute(SSR_ATTR)) { + oldVnode.removeAttribute(SSR_ATTR); hydrating = true; } if (isTrue(hydrating)) { @@ -5225,7 +5429,11 @@ function getRawDirName (dir) { function callHook$1 (dir, hook, vnode, oldVnode, isDestroy) { var fn = dir.def && dir.def[hook]; if (fn) { - fn(vnode.elm, dir, vnode, oldVnode, isDestroy); + try { + fn(vnode.elm, dir, vnode, oldVnode, isDestroy); + } catch (e) { + handleError(e, vnode.context, ("directive " + (dir.name) + " " + hook + " hook")); + } } } @@ -5237,7 +5445,7 @@ var baseModules = [ /* */ function updateAttrs (oldVnode, vnode) { - if (!oldVnode.data.attrs && !vnode.data.attrs) { + if (isUndef(oldVnode.data.attrs) && isUndef(vnode.data.attrs)) { return } var key, cur, old; @@ -5245,7 +5453,7 @@ function updateAttrs (oldVnode, vnode) { var oldAttrs = oldVnode.data.attrs || {}; var attrs = vnode.data.attrs || {}; // clone observed objects, as the user probably wants to mutate it - if (attrs.__ob__) { + if (isDef(attrs.__ob__)) { attrs = vnode.data.attrs = extend({}, attrs); } @@ -5262,7 +5470,7 @@ function updateAttrs (oldVnode, vnode) { setAttr(elm, 'value', attrs.value); } for (key in oldAttrs) { - if (attrs[key] == null) { + if (isUndef(attrs[key])) { if (isXlink(key)) { elm.removeAttributeNS(xlinkNS, getXlinkProp(key)); } else if (!isEnumeratedAttr(key)) { @@ -5309,8 +5517,15 @@ function updateClass (oldVnode, vnode) { var el = vnode.elm; var data = vnode.data; var oldData = oldVnode.data; - if (!data.staticClass && !data.class && - (!oldData || (!oldData.staticClass && !oldData.class))) { + if ( + isUndef(data.staticClass) && + isUndef(data.class) && ( + isUndef(oldData) || ( + isUndef(oldData.staticClass) && + isUndef(oldData.class) + ) + ) + ) { return } @@ -5318,7 +5533,7 @@ function updateClass (oldVnode, vnode) { // handle transition classes var transitionClass = el._transitionClasses; - if (transitionClass) { + if (isDef(transitionClass)) { cls = concat(cls, stringifyClass(transitionClass)); } @@ -5471,8 +5686,20 @@ function addHandler ( name, value, modifiers, - important + important, + warn ) { + // warn prevent and passive modifier + /* istanbul ignore if */ + if ( + "development" !== 'production' && warn && + modifiers && modifiers.prevent && modifiers.passive + ) { + warn( + 'passive and prevent can\'t be used together. ' + + 'Passive handler can\'t prevent default event.' + ); + } // check capture modifier if (modifiers && modifiers.capture) { delete modifiers.capture; @@ -5482,6 +5709,11 @@ function addHandler ( delete modifiers.once; name = '~' + name; // mark the event as once } + /* istanbul ignore if */ + if (modifiers && modifiers.passive) { + delete modifiers.passive; + name = '&' + name; // mark the event as passive + } var events; if (modifiers && modifiers.native) { delete modifiers.native; @@ -5763,7 +5995,7 @@ function genCheckboxModel ( '$$i=_i($$a,$$v);' + "if($$c){$$i<0&&(" + value + "=$$a.concat($$v))}" + "else{$$i>-1&&(" + value + "=$$a.slice(0,$$i).concat($$a.slice($$i+1)))}" + - "}else{" + value + "=$$c}", + "}else{" + (genAssignmentCode(value, '$$c')) + "}", null, true ); } @@ -5843,13 +6075,13 @@ function genDefaultModel ( function normalizeEvents (on) { var event; /* istanbul ignore if */ - if (on[RANGE_TOKEN]) { + if (isDef(on[RANGE_TOKEN])) { // IE input[type=range] only supports `change` event event = isIE ? 'change' : 'input'; on[event] = [].concat(on[RANGE_TOKEN], on[event] || []); delete on[RANGE_TOKEN]; } - if (on[CHECKBOX_RADIO_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] || []); @@ -5862,10 +6094,11 @@ var target$1; function add$1 ( event, handler, - once, - capture + once$$1, + capture, + passive ) { - if (once) { + if (once$$1) { var oldHandler = handler; var _target = target$1; // save current target element in closure handler = function (ev) { @@ -5877,7 +6110,13 @@ function add$1 ( } }; } - target$1.addEventListener(event, handler, capture); + target$1.addEventListener( + event, + handler, + supportsPassive + ? { capture: capture, passive: passive } + : capture + ); } function remove$2 ( @@ -5890,7 +6129,7 @@ function remove$2 ( } function updateDOMListeners (oldVnode, vnode) { - if (!oldVnode.data.on && !vnode.data.on) { + if (isUndef(oldVnode.data.on) && isUndef(vnode.data.on)) { return } var on = vnode.data.on || {}; @@ -5908,7 +6147,7 @@ var events = { /* */ function updateDOMProps (oldVnode, vnode) { - if (!oldVnode.data.domProps && !vnode.data.domProps) { + if (isUndef(oldVnode.data.domProps) && isUndef(vnode.data.domProps)) { return } var key, cur; @@ -5916,12 +6155,12 @@ function updateDOMProps (oldVnode, vnode) { var oldProps = oldVnode.data.domProps || {}; var props = vnode.data.domProps || {}; // clone observed objects, as the user probably wants to mutate it - if (props.__ob__) { + if (isDef(props.__ob__)) { props = vnode.data.domProps = extend({}, props); } for (key in oldProps) { - if (props[key] == null) { + if (isUndef(props[key])) { elm[key] = ''; } } @@ -5973,10 +6212,10 @@ function isDirty (elm, checkVal) { function isInputChanged (elm, newVal) { var value = elm.value; var modifiers = elm._vModifiers; // injected by v-model runtime - if ((modifiers && modifiers.number) || elm.type === 'number') { + if ((isDef(modifiers) && modifiers.number) || elm.type === 'number') { return toNumber(value) !== toNumber(newVal) } - if (modifiers && modifiers.trim) { + if (isDef(modifiers) && modifiers.trim) { return value.trim() !== newVal.trim() } return value !== newVal @@ -6065,7 +6304,17 @@ var setProp = function (el, name, val) { } else if (importantRE.test(val)) { el.style.setProperty(name, val.replace(importantRE, ''), 'important'); } else { - el.style[normalize(name)] = val; + var normalizedName = normalize(name); + if (Array.isArray(val)) { + // Support values array created by autoprefixer, e.g. + // {display: ["-webkit-box", "-ms-flexbox", "flex"]} + // Set them one by one, and the browser will only set those it can recognize + for (var i = 0, len = val.length; i < len; i++) { + el.style[normalizedName] = val[i]; + } + } else { + el.style[normalizedName] = val; + } } }; @@ -6091,27 +6340,32 @@ function updateStyle (oldVnode, vnode) { var data = vnode.data; var oldData = oldVnode.data; - if (!data.staticStyle && !data.style && - !oldData.staticStyle && !oldData.style) { + if (isUndef(data.staticStyle) && isUndef(data.style) && + isUndef(oldData.staticStyle) && isUndef(oldData.style)) { return } var cur, name; var el = vnode.elm; - var oldStaticStyle = oldVnode.data.staticStyle; - var oldStyleBinding = oldVnode.data.style || {}; + var oldStaticStyle = oldData.staticStyle; + var oldStyleBinding = oldData.normalizedStyle || oldData.style || {}; // if static style exists, stylebinding already merged into it when doing normalizeStyleData var oldStyle = oldStaticStyle || oldStyleBinding; var style = normalizeStyleBinding(vnode.data.style) || {}; - vnode.data.style = style.__ob__ ? extend({}, style) : style; + // store normalized style under a different key for next diff + // make sure to clone it if it's reactive, since the user likley wants + // to mutate it. + vnode.data.normalizedStyle = isDef(style.__ob__) + ? extend({}, style) + : style; var newStyle = getStyle(vnode, true); for (name in oldStyle) { - if (newStyle[name] == null) { + if (isUndef(newStyle[name])) { setProp(el, name, ''); } } @@ -6362,38 +6616,39 @@ function enter (vnode, toggleDisplay) { var el = vnode.elm; // call leave callback now - if (el._leaveCb) { + if (isDef(el._leaveCb)) { el._leaveCb.cancelled = true; el._leaveCb(); } var data = resolveTransition(vnode.data.transition); - if (!data) { + if (isUndef(data)) { return } /* istanbul ignore if */ - if (el._enterCb || el.nodeType !== 1) { + if (isDef(el._enterCb) || el.nodeType !== 1) { return } - var css = data.css; - var type = data.type; - var enterClass = data.enterClass; - var enterToClass = data.enterToClass; - var enterActiveClass = data.enterActiveClass; - var appearClass = data.appearClass; - var appearToClass = data.appearToClass; - var appearActiveClass = data.appearActiveClass; - var beforeEnter = data.beforeEnter; - var enter = data.enter; - var afterEnter = data.afterEnter; - var enterCancelled = data.enterCancelled; - var beforeAppear = data.beforeAppear; - var appear = data.appear; - var afterAppear = data.afterAppear; - var appearCancelled = data.appearCancelled; - var duration = data.duration; + var ref = (data); + var css = ref.css; + var type = ref.type; + var enterClass = ref.enterClass; + var enterToClass = ref.enterToClass; + var enterActiveClass = ref.enterActiveClass; + var appearClass = ref.appearClass; + var appearToClass = ref.appearToClass; + var appearActiveClass = ref.appearActiveClass; + var beforeEnter = ref.beforeEnter; + var enter = ref.enter; + var afterEnter = ref.afterEnter; + var enterCancelled = ref.enterCancelled; + var beforeAppear = ref.beforeAppear; + var appear = ref.appear; + var afterAppear = ref.afterAppear; + var appearCancelled = ref.appearCancelled; + var duration = ref.duration; // activeInstance will always be the component managing this // transition. One edge case to check is when the is placed @@ -6510,32 +6765,33 @@ function leave (vnode, rm) { var el = vnode.elm; // call enter callback now - if (el._enterCb) { + if (isDef(el._enterCb)) { el._enterCb.cancelled = true; el._enterCb(); } var data = resolveTransition(vnode.data.transition); - if (!data) { + if (isUndef(data)) { return rm() } /* istanbul ignore if */ - if (el._leaveCb || el.nodeType !== 1) { + if (isDef(el._leaveCb) || el.nodeType !== 1) { return } - var css = data.css; - var type = data.type; - var leaveClass = data.leaveClass; - var leaveToClass = data.leaveToClass; - var leaveActiveClass = data.leaveActiveClass; - var beforeLeave = data.beforeLeave; - var leave = data.leave; - var afterLeave = data.afterLeave; - var leaveCancelled = data.leaveCancelled; - var delayLeave = data.delayLeave; - var duration = data.duration; + var ref = (data); + var css = ref.css; + var type = ref.type; + var leaveClass = ref.leaveClass; + var leaveToClass = ref.leaveToClass; + var leaveActiveClass = ref.leaveActiveClass; + var beforeLeave = ref.beforeLeave; + var leave = ref.leave; + var afterLeave = ref.afterLeave; + var leaveCancelled = ref.leaveCancelled; + var delayLeave = ref.delayLeave; + var duration = ref.duration; var expectsCSS = css !== false && !isIE9; var userWantsControl = getHookArgumentsLength(leave); @@ -6636,9 +6892,11 @@ function isValidDuration (val) { * - a plain function (.length) */ function getHookArgumentsLength (fn) { - if (!fn) { return false } + if (isUndef(fn)) { + return false + } var invokerFns = fn.fns; - if (invokerFns) { + if (isDef(invokerFns)) { // invoker return getHookArgumentsLength( Array.isArray(invokerFns) @@ -6651,7 +6909,7 @@ function getHookArgumentsLength (fn) { } function _enter (_, vnode) { - if (!vnode.data.show) { + if (vnode.data.show !== true) { enter(vnode); } } @@ -6661,7 +6919,7 @@ var transition = inBrowser ? { activate: _enter, remove: function remove$$1 (vnode, rm) { /* istanbul ignore else */ - if (!vnode.data.show) { + if (vnode.data.show !== true) { leave(vnode, rm); } else { rm(); @@ -6716,6 +6974,11 @@ var model$1 = { } else if (vnode.tag === 'textarea' || el.type === 'text' || el.type === 'password') { el._vModifiers = binding.modifiers; if (!binding.modifiers.lazy) { + // Safari < 10.2 & UIWebView doesn't fire compositionend when + // switching focus before confirming composition choice + // this also fixes the issue where some browsers e.g. iOS Chrome + // fires "change" instead of "input" on autocomplete. + el.addEventListener('change', onCompositionEnd); if (!isAndroid) { el.addEventListener('compositionstart', onCompositionStart); el.addEventListener('compositionend', onCompositionEnd); @@ -6927,9 +7190,11 @@ function extractTransitionData (comp) { } function placeholder (h, rawChild) { - return /\d-keep-alive$/.test(rawChild.tag) - ? h('keep-alive') - : null + if (/\d-keep-alive$/.test(rawChild.tag)) { + return h('keep-alive', { + props: rawChild.componentOptions.propsData + }) + } } function hasParentTransition (vnode) { @@ -7227,6 +7492,7 @@ var platformComponents = { // install platform specific utils Vue$3.config.mustUseProp = mustUseProp; Vue$3.config.isReservedTag = isReservedTag; +Vue$3.config.isReservedAttr = isReservedAttr; Vue$3.config.getTagNamespace = getTagNamespace; Vue$3.config.isUnknownElement = isUnknownElement; @@ -8107,6 +8373,13 @@ function processAttrs (el) { if (modifiers.camel) { name = camelize(name); } + if (modifiers.sync) { + addHandler( + el, + ("update:" + (camelize(name))), + genAssignmentCode(value, "$event") + ); + } } if (isProp || platformMustUseProp(el.tag, el.attrsMap.type, name)) { addProp(el, name, value); @@ -8115,7 +8388,7 @@ function processAttrs (el) { } } else if (onRE.test(name)) { // v-on name = name.replace(onRE, ''); - addHandler(el, name, value, modifiers); + addHandler(el, name, value, modifiers, false, warn$2); } else { // normal directives name = name.replace(dirRE, ''); // parse arg @@ -8170,7 +8443,10 @@ function parseModifiers (name) { function makeAttrsMap (attrs) { var map = {}; for (var i = 0, l = attrs.length; i < l; i++) { - if ("development" !== 'production' && map[attrs[i].name] && !isIE) { + if ( + "development" !== 'production' && + map[attrs[i].name] && !isIE && !isEdge + ) { warn$2('duplicate attribute: ' + attrs[i].name); } map[attrs[i].name] = attrs[i].value; @@ -8378,10 +8654,25 @@ var modifierCode = { right: genGuard("'button' in $event && $event.button !== 2") }; -function genHandlers (events, native) { +function genHandlers ( + events, + native, + warn +) { var res = native ? 'nativeOn:{' : 'on:{'; for (var name in events) { - res += "\"" + name + "\":" + (genHandler(name, events[name])) + ","; + var handler = events[name]; + // #5330: warn click.right, since right clicks do not actually fire click events. + if ("development" !== 'production' && + name === 'click' && + handler && handler.modifiers && handler.modifiers.right + ) { + warn( + "Use \"contextmenu\" instead of \"click.right\" since right clicks " + + "do not actually fire \"click\" events." + ); + } + res += "\"" + name + "\":" + (genHandler(name, handler)) + ","; } return res.slice(0, -1) + '}' } @@ -8655,10 +8946,10 @@ function genData (el) { } // event handlers if (el.events) { - data += (genHandlers(el.events)) + ","; + data += (genHandlers(el.events, false, warn$3)) + ","; } if (el.nativeEvents) { - data += (genHandlers(el.nativeEvents, true)) + ","; + data += (genHandlers(el.nativeEvents, true, warn$3)) + ","; } // slot target if (el.slotTarget) { @@ -8895,8 +9186,9 @@ function checkNode (node, errors) { } function checkEvent (exp, text, errors) { - var keywordMatch = exp.replace(stripStringRE, '').match(unaryOperatorsRE); - if (keywordMatch) { + var stipped = exp.replace(stripStringRE, ''); + var keywordMatch = stipped.match(unaryOperatorsRE); + if (keywordMatch && stipped.charAt(keywordMatch.index - 1) !== '$') { errors.push( "avoid using JavaScript unary operator as property name: " + "\"" + (keywordMatch[0]) + "\" in expression " + (text.trim()) diff --git a/dist/vue.min.js b/dist/vue.min.js index d079a741..f856bf33 100644 --- a/dist/vue.min.js +++ b/dist/vue.min.js @@ -1,8 +1,8 @@ /*! - * Vue.js v2.2.6 + * Vue.js v2.3.0-beta.1 * (c) 2014-2017 Evan You * Released under the MIT License. */ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.Vue=t()}(this,function(){"use strict";function e(e){return null==e?"":"object"==typeof e?JSON.stringify(e,null,2):String(e)}function t(e){var t=parseFloat(e);return isNaN(t)?e:t}function n(e,t){for(var n=Object.create(null),r=e.split(","),i=0;i-1)return e.splice(n,1)}}function i(e,t){return $i.call(e,t)}function o(e){return"string"==typeof e||"number"==typeof e}function a(e){var t=Object.create(null);return function(n){return t[n]||(t[n]=e(n))}}function s(e,t){function n(n){var r=arguments.length;return r?r>1?e.apply(t,arguments):e.call(t,n):e.call(t)}return n._length=e.length,n}function c(e,t){t=t||0;for(var n=e.length-t,r=new Array(n);n--;)r[n]=e[n+t];return r}function u(e,t){for(var n in t)e[n]=t[n];return e}function l(e){return null!==e&&"object"==typeof e}function f(e){return ki.call(e)===Ai}function p(e){for(var t={},n=0;n=0&&co[n].id>e.id;)n--;co.splice(Math.max(n,po)+1,0,e)}else co.push(e);lo||(lo=!0,zi(de))}}function he(e){mo.clear(),me(e,mo)}function me(e,t){var n,r,i=Array.isArray(e);if((i||l(e))&&Object.isExtensible(e)){if(e.__ob__){var o=e.__ob__.dep.id;if(t.has(o))return;t.add(o)}if(i)for(n=e.length;n--;)me(e[n],t);else for(r=Object.keys(e),n=r.length;n--;)me(e[r[n]],t)}}function ge(e,t,n){go.get=function(){return this[t][n]},go.set=function(e){this[t][n]=e},Object.defineProperty(e,n,go)}function ye(e){e._watchers=[];var t=e.$options;t.props&&_e(e,t.props),t.methods&&ke(e,t.methods),t.data?be(e):k(e._data={},!0),t.computed&&we(e,t.computed),t.watch&&Ae(e,t.watch)}function _e(e,t){var n=e.$options.propsData||{},r=e._props={},i=e.$options._propKeys=[],o=!e.$parent;Qi.shouldConvert=o;for(var a in t)!function(o){i.push(o);var a=P(o,t,n,e);A(r,o,a),o in e||ge(e,"_props",o)}(a);Qi.shouldConvert=!0}function be(e){var t=e.$options.data;t=e._data="function"==typeof t?$e(t,e):t||{},f(t)||(t={});for(var n=Object.keys(t),r=e.$options.props,o=n.length;o--;)r&&i(r,n[o])||g(n[o])||ge(e,"_data",n[o]);k(t,!0)}function $e(e,t){try{return e.call(t)}catch(e){return U(e,t,"data()"),{}}}function we(e,t){var n=e._computedWatchers=Object.create(null);for(var r in t){var i=t[r],o="function"==typeof i?i:i.get;n[r]=new ho(e,o,d,yo),r in e||xe(e,r,i)}}function xe(e,t,n){"function"==typeof n?(go.get=Ce(t),go.set=d):(go.get=n.get?n.cache!==!1?Ce(t):n.get:d,go.set=n.set?n.set:d),Object.defineProperty(e,t,go)}function Ce(e){return function(){var t=this._computedWatchers&&this._computedWatchers[e];if(t)return t.dirty&&t.evaluate(),qi.target&&t.depend(),t.value}}function ke(e,t){e.$options.props;for(var n in t)e[n]=null==t[n]?d:s(t[n],e)}function Ae(e,t){for(var n in t){var r=t[n];if(Array.isArray(r))for(var i=0;i-1:e instanceof RegExp&&e.test(t)}function ft(e,t){for(var n in e){var r=e[n];if(r){var i=ut(r.componentOptions);i&&!t(i)&&(pt(r),e[n]=null)}}}function pt(e){e&&(e.componentInstance._inactive||fe(e.componentInstance,"deactivated"),e.componentInstance.$destroy())}function dt(e){for(var t=e.data,n=e,r=e;r.componentInstance;)r=r.componentInstance._vnode,r.data&&(t=vt(r.data,t));for(;n=n.parent;)n.data&&(t=vt(t,n.data));return ht(t)}function vt(e,t){return{staticClass:mt(e.staticClass,t.staticClass),class:e.class?[e.class,t.class]:t.class}}function ht(e){var t=e.class,n=e.staticClass;return n||t?mt(n,gt(t)):""}function mt(e,t){return e?t?e+" "+t:e:t||""}function gt(e){var t="";if(!e)return t;if("string"==typeof e)return e;if(Array.isArray(e)){for(var n,r=0,i=e.length;r-1?Zo[e]=t.constructor===window.HTMLUnknownElement||t.constructor===window.HTMLElement:Zo[e]=/HTMLUnknownElement/.test(t.toString())}function bt(e){if("string"==typeof e){var t=document.querySelector(e);return t?t:document.createElement("div")}return e}function $t(e,t){var n=document.createElement(e);return"select"!==e?n:(t.data&&t.data.attrs&&void 0!==t.data.attrs.multiple&&n.setAttribute("multiple","multiple"),n)}function wt(e,t){return document.createElementNS(zo[e],t)}function xt(e){return document.createTextNode(e)}function Ct(e){return document.createComment(e)}function kt(e,t,n){e.insertBefore(t,n)}function At(e,t){e.removeChild(t)}function Ot(e,t){e.appendChild(t)}function Tt(e){return e.parentNode}function St(e){return e.nextSibling}function Et(e){return e.tagName}function jt(e,t){e.textContent=t}function Nt(e,t,n){e.setAttribute(t,n)}function It(e,t){var n=e.data.ref;if(n){var i=e.context,o=e.componentInstance||e.elm,a=i.$refs;t?Array.isArray(a[n])?r(a[n],o):a[n]===o&&(a[n]=void 0):e.data.refInFor?Array.isArray(a[n])&&a[n].indexOf(o)<0?a[n].push(o):a[n]=[o]:a[n]=o}}function Lt(e){return void 0===e||null===e}function Dt(e){return void 0!==e&&null!==e}function Mt(e){return e===!0}function Pt(e,t){return e.key===t.key&&e.tag===t.tag&&e.isComment===t.isComment&&Dt(e.data)===Dt(t.data)&&Rt(e,t)}function Rt(e,t){if("input"!==e.tag)return!0;var n;return(Dt(n=e.data)&&Dt(n=n.attrs)&&n.type)===(Dt(n=t.data)&&Dt(n=n.attrs)&&n.type)}function Ft(e,t,n){var r,i,o={};for(r=t;r<=n;++r)i=e[r].key,Dt(i)&&(o[i]=r);return o}function Ht(e,t){(e.data.directives||t.data.directives)&&Ut(e,t)}function Ut(e,t){var n,r,i,o=e===Qo,a=t===Qo,s=Bt(e.data.directives,e.context),c=Bt(t.data.directives,t.context),u=[],l=[];for(n in c)r=s[n],i=c[n],r?(i.oldValue=r.value,zt(i,"update",t,e),i.def&&i.def.componentUpdated&&l.push(i)):(zt(i,"bind",t,e),i.def&&i.def.inserted&&u.push(i));if(u.length){var f=function(){for(var n=0;n=0&&" "===(m=e.charAt(h));h--);m&&oa.test(m)||(l=!0)}}else void 0===o?(v=i+1,o=e.slice(0,i).trim()):t();if(void 0===o?o=e.slice(0,i).trim():0!==v&&t(),a)for(i=0;i=Oo}function ln(e){return 34===e||39===e}function fn(e){var t=1;for(jo=Eo;!un();)if(e=cn(),ln(e))pn(e);else if(91===e&&t++,93===e&&t--,0===t){No=Eo;break}}function pn(e){for(var t=e;!un()&&(e=cn())!==t;);}function dn(e,t,n){Io=n;var r=t.value,i=t.modifiers,o=e.tag,a=e.attrsMap.type;if("select"===o)mn(e,r,i);else if("input"===o&&"checkbox"===a)vn(e,r,i);else if("input"===o&&"radio"===a)hn(e,r,i);else if("input"===o||"textarea"===o)gn(e,r,i);else if(!Si.isReservedTag(o))return on(e,r,i),!1;return!0}function vn(e,t,n){var r=n&&n.number,i=nn(e,"value")||"null",o=nn(e,"true-value")||"true",a=nn(e,"false-value")||"false";Qt(e,"checked","Array.isArray("+t+")?_i("+t+","+i+")>-1"+("true"===o?":("+t+")":":_q("+t+","+o+")")),tn(e,sa,"var $$a="+t+",$$el=$event.target,$$c=$$el.checked?("+o+"):("+a+");if(Array.isArray($$a)){var $$v="+(r?"_n("+i+")":i)+",$$i=_i($$a,$$v);if($$c){$$i<0&&("+t+"=$$a.concat($$v))}else{$$i>-1&&("+t+"=$$a.slice(0,$$i).concat($$a.slice($$i+1)))}}else{"+t+"=$$c}",null,!0)}function hn(e,t,n){var r=n&&n.number,i=nn(e,"value")||"null";i=r?"_n("+i+")":i,Qt(e,"checked","_q("+t+","+i+")"),tn(e,sa,an(t,i),null,!0)}function mn(e,t,n){var r=n&&n.number,i='Array.prototype.filter.call($event.target.options,function(o){return o.selected}).map(function(o){var val = "_value" in o ? o._value : o.value;return '+(r?"_n(val)":"val")+"})",o="var $$selectedVal = "+i+";";o=o+" "+an(t,"$event.target.multiple ? $$selectedVal : $$selectedVal[0]"),tn(e,"change",o,null,!0)}function gn(e,t,n){var r=e.attrsMap.type,i=n||{},o=i.lazy,a=i.number,s=i.trim,c=!o&&"range"!==r,u=o?"change":"range"===r?aa:"input",l="$event.target.value";s&&(l="$event.target.value.trim()"),a&&(l="_n("+l+")");var f=an(t,l);c&&(f="if($event.target.composing)return;"+f),Qt(e,"value","("+t+")"),tn(e,u,f,null,!0),(s||a||"number"===r)&&tn(e,"blur","$forceUpdate()")}function yn(e){var t;e[aa]&&(t=Di?"change":"input",e[t]=[].concat(e[aa],e[t]||[]),delete e[aa]),e[sa]&&(t=Hi?"click":"change",e[t]=[].concat(e[sa],e[t]||[]),delete e[sa])}function _n(e,t,n,r){if(n){var i=t,o=Lo;t=function(n){null!==(1===arguments.length?i(n):i.apply(null,arguments))&&bn(e,t,r,o)}}Lo.addEventListener(e,t,r)}function bn(e,t,n,r){(r||Lo).removeEventListener(e,t,n)}function $n(e,t){if(e.data.on||t.data.on){var n=t.data.on||{},r=e.data.on||{};Lo=t.elm,yn(n),K(n,r,_n,bn,t.context)}}function wn(e,t){if(e.data.domProps||t.data.domProps){var n,r,i=t.elm,o=e.data.domProps||{},a=t.data.domProps||{};a.__ob__&&(a=t.data.domProps=u({},a));for(n in o)null==a[n]&&(i[n]="");for(n in a)if(r=a[n],"textContent"!==n&&"innerHTML"!==n||(t.children&&(t.children.length=0),r!==o[n]))if("value"===n){i._value=r;var s=null==r?"":String(r);xn(i,t,s)&&(i.value=s)}else i[n]=r}}function xn(e,t,n){return!e.composing&&("option"===t.tag||Cn(e,n)||kn(e,n))}function Cn(e,t){return document.activeElement!==e&&e.value!==t}function kn(e,n){var r=e.value,i=e._vModifiers;return i&&i.number||"number"===e.type?t(r)!==t(n):i&&i.trim?r.trim()!==n.trim():r!==n}function An(e){var t=On(e.style);return e.staticStyle?u(e.staticStyle,t):t}function On(e){return Array.isArray(e)?p(e):"string"==typeof e?la(e):e}function Tn(e,t){var n,r={};if(t)for(var i=e;i.componentInstance;)i=i.componentInstance._vnode,i.data&&(n=An(i.data))&&u(r,n);(n=An(e.data))&&u(r,n);for(var o=e;o=o.parent;)o.data&&(n=An(o.data))&&u(r,n);return r}function Sn(e,t){var n=t.data,r=e.data;if(n.staticStyle||n.style||r.staticStyle||r.style){var i,o,a=t.elm,s=e.data.staticStyle,c=e.data.style||{},l=s||c,f=On(t.data.style)||{};t.data.style=f.__ob__?u({},f):f;var p=Tn(t,!0);for(o in l)null==p[o]&&da(a,o,"");for(o in p)(i=p[o])!==l[o]&&da(a,o,null==i?"":i)}}function En(e,t){if(t&&(t=t.trim()))if(e.classList)t.indexOf(" ")>-1?t.split(/\s+/).forEach(function(t){return e.classList.add(t)}):e.classList.add(t);else{var n=" "+(e.getAttribute("class")||"")+" ";n.indexOf(" "+t+" ")<0&&e.setAttribute("class",(n+t).trim())}}function jn(e,t){if(t&&(t=t.trim()))if(e.classList)t.indexOf(" ")>-1?t.split(/\s+/).forEach(function(t){return e.classList.remove(t)}):e.classList.remove(t);else{for(var n=" "+(e.getAttribute("class")||"")+" ",r=" "+t+" ";n.indexOf(r)>=0;)n=n.replace(r," ");e.setAttribute("class",n.trim())}}function Nn(e){if(e){if("object"==typeof e){var t={};return e.css!==!1&&u(t,ga(e.name||"v")),u(t,e),t}return"string"==typeof e?ga(e):void 0}}function In(e){ka(function(){ka(e)})}function Ln(e,t){(e._transitionClasses||(e._transitionClasses=[])).push(t),En(e,t)}function Dn(e,t){e._transitionClasses&&r(e._transitionClasses,t),jn(e,t)}function Mn(e,t,n){var r=Pn(e,t),i=r.type,o=r.timeout,a=r.propCount;if(!i)return n();var s=i===_a?wa:Ca,c=0,u=function(){e.removeEventListener(s,l),n()},l=function(t){t.target===e&&++c>=a&&u()};setTimeout(function(){c0&&(n=_a,l=a,f=o.length):t===ba?u>0&&(n=ba,l=u,f=c.length):(l=Math.max(a,u),n=l>0?a>u?_a:ba:null,f=n?n===_a?o.length:c.length:0),{type:n,timeout:l,propCount:f,hasTransform:n===_a&&Aa.test(r[$a+"Property"])}}function Rn(e,t){for(;e.length1}function zn(e,t){t.data.show||Hn(t)}function Jn(e,t,n){var r=t.value,i=e.multiple;if(!i||Array.isArray(r)){for(var o,a,s=0,c=e.options.length;s-1,a.selected!==o&&(a.selected=o);else if(v(qn(a),r))return void(e.selectedIndex!==s&&(e.selectedIndex=s));i||(e.selectedIndex=-1)}}function Kn(e,t){for(var n=0,r=t.length;n=0&&a[i].lowerCasedTag!==s;i--);else i=0;if(i>=0){for(var c=a.length-1;c>=i;c--)t.end&&t.end(a[c].tag,n,r);a.length=i,o=i&&a[i-1].tag}else"br"===s?t.start&&t.start(e,[],!0,n,r):"p"===s&&(t.start&&t.start(e,[],!1,n,r),t.end&&t.end(e,n,r))}for(var i,o,a=[],s=t.expectHTML,c=t.isUnaryTag||Oi,u=t.canBeLeftOpenTag||Oi,l=0;e;){if(i=e,o&&ys(o)){var f=o.toLowerCase(),p=_s[f]||(_s[f]=new RegExp("([\\s\\S]*?)(]*>)","i")),d=0,v=e.replace(p,function(e,n,r){return d=r.length,ys(f)||"noscript"===f||(n=n.replace(//g,"$1").replace(//g,"$1")),t.chars&&t.chars(n),""});l+=e.length-v.length,e=v,r(f,l-d,l)}else{var h=e.indexOf("<");if(0===h){if(Ya.test(e)){var m=e.indexOf("-->");if(m>=0){n(m+3);continue}}if(Qa.test(e)){var g=e.indexOf("]>");if(g>=0){n(g+2);continue}}var y=e.match(Ga);if(y){n(y[0].length);continue}var _=e.match(Za);if(_){var b=l;n(_[0].length),r(_[1],b,l);continue}var $=function(){var t=e.match(qa);if(t){var r={tagName:t[1],attrs:[],start:l};n(t[0].length);for(var i,o;!(i=e.match(Wa))&&(o=e.match(Ja));)n(o[0].length),r.attrs.push(o);if(i)return r.unarySlash=i[1],n(i[0].length),r.end=l,r}}();if($){!function(e){var n=e.tagName,i=e.unarySlash;s&&("p"===o&&Va(n)&&r(o),u(n)&&o===n&&r(n));for(var l=c(n)||"html"===n&&"head"===o||!!i,f=e.attrs.length,p=new Array(f),d=0;d=0){for(x=e.slice(h);!(Za.test(x)||qa.test(x)||Ya.test(x)||Qa.test(x)||(C=x.indexOf("<",1))<0);)h+=C,x=e.slice(h);w=e.substring(0,h),n(h)}h<0&&(w=e,e=""),t.chars&&w&&t.chars(w)}if(e===i){t.chars&&t.chars(e);break}}r()}function ur(e,t){var n=t?Cs(t):xs;if(n.test(e)){for(var r,i,o=[],a=n.lastIndex=0;r=n.exec(e);){i=r.index,i>a&&o.push(JSON.stringify(e.slice(a,i)));var s=Wt(r[1].trim());o.push("_s("+s+")"),a=i+r[0].length}return a0,Pi=Li&&Li.indexOf("edge/")>0,Ri=Li&&Li.indexOf("android")>0,Fi=Li&&/iphone|ipad|ipod|ios/.test(Li),Hi=Li&&/chrome\/\d+/.test(Li)&&!Pi,Ui=function(){return void 0===yi&&(yi=!Ii&&"undefined"!=typeof global&&"server"===global.process.env.VUE_ENV),yi},Bi=Ii&&window.__VUE_DEVTOOLS_GLOBAL_HOOK__,Vi="undefined"!=typeof Symbol&&b(Symbol)&&"undefined"!=typeof Reflect&&b(Reflect.ownKeys),zi=function(){function e(){r=!1;var e=n.slice(0);n.length=0;for(var t=0;t1?c(n):n;for(var r=c(arguments,1),i=0,o=n.length;i1&&(t[n[0].trim()]=n[1].trim())}}),t}),fa=/^--/,pa=/\s*!important$/,da=function(e,t,n){fa.test(t)?e.style.setProperty(t,n):pa.test(n)?e.style.setProperty(t,n.replace(pa,""),"important"):e.style[ha(t)]=n},va=["Webkit","Moz","ms"],ha=a(function(e){if(Do=Do||document.createElement("div"),"filter"!==(e=wi(e))&&e in Do.style)return e;for(var t=e.charAt(0).toUpperCase()+e.slice(1),n=0;np?(u=Lt(n[m+1])?null:n[m+1].elm,h(e,u,n,f,m,r)):f>m&&g(e,t,l,p)}function b(e,t,n,r){if(e!==t){if(Mt(t.isStatic)&&Mt(e.isStatic)&&t.key===e.key&&(Mt(t.isCloned)||Mt(t.isOnce)))return t.elm=e.elm,void(t.componentInstance=e.componentInstance);var i,o=t.data;Dt(o)&&Dt(i=o.hook)&&Dt(i=i.prepatch)&&i(e,t);var a=t.elm=e.elm,s=e.children,c=t.children;if(Dt(o)&&p(t)){for(i=0;i',n.innerHTML.indexOf(t)>0}("\n"," "),Ua=n("area,base,br,col,embed,frame,hr,img,input,isindex,keygen,link,meta,param,source,track,wbr"),Ba=n("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source"),Va=n("address,article,aside,base,blockquote,body,caption,col,colgroup,dd,details,dialog,div,dl,dt,fieldset,figcaption,figure,footer,form,h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,legend,li,menuitem,meta,optgroup,option,param,rp,rt,source,style,summary,tbody,td,tfoot,th,thead,title,tr,track"),za=[/"([^"]*)"+/.source,/'([^']*)'+/.source,/([^\s"'=<>`]+)/.source],Ja=new RegExp("^\\s*"+/([^\s"'<>\/=]+)/.source+"(?:\\s*("+/(?:=)/.source+")\\s*(?:"+za.join("|")+"))?"),Ka="[a-zA-Z_][\\w\\-\\.]*",qa=new RegExp("^<((?:"+Ka+"\\:)?"+Ka+")"),Wa=/^\s*(\/?)>/,Za=new RegExp("^<\\/((?:"+Ka+"\\:)?"+Ka+")[^>]*>"),Ga=/^]+>/i,Ya=/^/g,"$1").replace(//g,"$1")),t.chars&&t.chars(n),""});l+=e.length-v.length,e=v,r(f,l-d,l)}else{var h=e.indexOf("<");if(0===h){if(ls.test(e)){var m=e.indexOf("--\x3e");if(m>=0){n(m+3);continue}}if(fs.test(e)){var g=e.indexOf("]>");if(g>=0){n(g+2);continue}}var y=e.match(us);if(y){n(y[0].length);continue}var _=e.match(cs);if(_){var b=l;n(_[0].length),r(_[1],b,l);continue}var $=function(){var t=e.match(as);if(t){var r={tagName:t[1],attrs:[],start:l};n(t[0].length);for(var i,o;!(i=e.match(ss))&&(o=e.match(is));)n(o[0].length),r.attrs.push(o);if(i)return r.unarySlash=i[1],n(i[0].length),r.end=l,r}}();if($){!function(e){var n=e.tagName,i=e.unarySlash;s&&("p"===o&&ns(n)&&r(o),u(n)&&o===n&&r(n));for(var l=c(n)||"html"===n&&"head"===o||!!i,f=e.attrs.length,p=new Array(f),d=0;d=0){for(w=e.slice(h);!(cs.test(w)||as.test(w)||ls.test(w)||fs.test(w)||(C=w.indexOf("<",1))<0);)h+=C,w=e.slice(h);x=e.substring(0,h),n(h)}h<0&&(x=e,e=""),t.chars&&x&&t.chars(x)}if(e===i){t.chars&&t.chars(e);break}}r()}function mr(e,t){var n=t?Ps(t):Ms;if(n.test(e)){for(var r,i,o=[],a=n.lastIndex=0;r=n.exec(e);){i=r.index,i>a&&o.push(JSON.stringify(e.slice(a,i)));var s=tn(r[1].trim());o.push("_s("+s+")"),a=i+r[0].length}return a0,Ji=Ui&&Ui.indexOf("edge/")>0,Ki=Ui&&Ui.indexOf("android")>0,qi=Ui&&/iphone|ipad|ipod|ios/.test(Ui),Wi=Ui&&/chrome\/\d+/.test(Ui)&&!Ji,Zi=!1;if(Hi)try{var Gi={};Object.defineProperty(Gi,"passive",{get:function(){Zi=!0}}),window.addEventListener("test-passive",null,Gi)}catch(e){}var Yi,Qi,Xi=function(){return void 0===Yi&&(Yi=!Hi&&"undefined"!=typeof global&&"server"===global.process.env.VUE_ENV),Yi},eo=Hi&&window.__VUE_DEVTOOLS_GLOBAL_HOOK__,to="undefined"!=typeof Symbol&&k(Symbol)&&"undefined"!=typeof Reflect&&k(Reflect.ownKeys),no=function(){function e(){r=!1;var e=n.slice(0);n.length=0;for(var t=0;t1?v(n):n;for(var r=v(arguments,1),i=0,o=n.length;i1&&(t[n[0].trim()]=n[1].trim())}}),t +}),Ca=/^--/,ka=/\s*!important$/,Aa=function(e,t,n){if(Ca.test(t))e.style.setProperty(t,n);else if(ka.test(n))e.style.setProperty(t,n.replace(ka,""),"important");else{var r=Sa(t);if(Array.isArray(n))for(var i=0,o=n.length;iv?(f=e(i[g+1])?null:i[g+1].elm,y(n,f,i,d,g,o)):d>g&&b(n,r,p,v)}function w(r,i,o,a){if(r!==i){if(n(i.isStatic)&&n(r.isStatic)&&i.key===r.key&&(n(i.isCloned)||n(i.isOnce)))return i.elm=r.elm,void(i.componentInstance=r.componentInstance);var s,c=i.data;t(c)&&t(s=c.hook)&&t(s=s.prepatch)&&s(r,i);var u=i.elm=r.elm,l=r.children,f=i.children;if(t(c)&&h(i)){for(s=0;s',n.innerHTML.indexOf(t)>0}("\n"," "),es=u("area,base,br,col,embed,frame,hr,img,input,isindex,keygen,link,meta,param,source,track,wbr"),ts=u("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source"),ns=u("address,article,aside,base,blockquote,body,caption,col,colgroup,dd,details,dialog,div,dl,dt,fieldset,figcaption,figure,footer,form,h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,legend,li,menuitem,meta,optgroup,option,param,rp,rt,source,style,summary,tbody,td,tfoot,th,thead,title,tr,track"),rs=[/"([^"]*)"+/.source,/'([^']*)'+/.source,/([^\s"'=<>`]+)/.source],is=new RegExp("^\\s*"+/([^\s"'<>\/=]+)/.source+"(?:\\s*("+/(?:=)/.source+")\\s*(?:"+rs.join("|")+"))?"),os="[a-zA-Z_][\\w\\-\\.]*",as=new RegExp("^<((?:"+os+"\\:)?"+os+")"),ss=/^\s*(\/?)>/,cs=new RegExp("^<\\/((?:"+os+"\\:)?"+os+")[^>]*>"),us=/^]+>/i,ls=/^ ' : repeat(' ', 5 + i * 2)) + (Array.isArray(vm) + ? ((formatComponentName(vm[0])) + "... (" + (vm[1]) + " recursive calls)") + : formatComponentName(vm))); }) + .join('\n') + } else { + return ("\n\n(found in " + (formatComponentName(vm)) + ")") + } + }; +} + +function handleError (err, vm, info) { + if (config.errorHandler) { + config.errorHandler.call(null, err, vm, info); + } else { + if (process.env.NODE_ENV !== 'production') { + warn(("Error in " + info + ": \"" + (err.toString()) + "\""), vm); + } + /* istanbul ignore else */ + if (inBrowser && typeof console !== 'undefined') { + console.error(err); + } else { + throw err + } + } +} + /* */ /* globals MutationObserver */ @@ -407,6 +534,20 @@ var isAndroid = UA && UA.indexOf('android') > 0; var isIOS = UA && /iphone|ipad|ipod|ios/.test(UA); var isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge; +var supportsPassive = false; +if (inBrowser) { + try { + var opts = {}; + Object.defineProperty(opts, 'passive', ({ + get: function get () { + /* istanbul ignore next */ + supportsPassive = true; + } + } )); // https://github.com/facebook/flow/issues/285 + window.addEventListener('test-passive', null, opts); + } catch (e) {} +} + // this needs to be lazy-evaled because vue may be required before // vue-server-renderer can set VUE_ENV var _isServer; @@ -429,7 +570,7 @@ var devtools = inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__; /* istanbul ignore next */ function isNative (Ctor) { - return /native code/.test(Ctor.toString()) + return typeof Ctor === 'function' && /native code/.test(Ctor.toString()) } var hasSymbol = @@ -500,15 +641,22 @@ var nextTick = (function () { return function queueNextTick (cb, ctx) { var _resolve; callbacks.push(function () { - if (cb) { cb.call(ctx); } - if (_resolve) { _resolve(ctx); } + if (cb) { + try { + cb.call(ctx); + } catch (e) { + handleError(e, ctx, 'nextTick'); + } + } else if (_resolve) { + _resolve(ctx); + } }); if (!pending) { pending = true; timerFunc(); } if (!cb && typeof Promise !== 'undefined') { - return new Promise(function (resolve) { + return new Promise(function (resolve, reject) { _resolve = resolve; }) } @@ -540,65 +688,6 @@ if (typeof Set !== 'undefined' && isNative(Set)) { }()); } -var warn = noop; -var tip = noop; -var formatComponentName; - -if (process.env.NODE_ENV !== 'production') { - var hasConsole = typeof console !== 'undefined'; - var classifyRE = /(?:^|[-_])(\w)/g; - var classify = function (str) { return str - .replace(classifyRE, function (c) { return c.toUpperCase(); }) - .replace(/[-_]/g, ''); }; - - warn = function (msg, vm) { - if (hasConsole && (!config.silent)) { - console.error("[Vue warn]: " + msg + " " + ( - vm ? formatLocation(formatComponentName(vm)) : '' - )); - } - }; - - tip = function (msg, vm) { - if (hasConsole && (!config.silent)) { - console.warn("[Vue tip]: " + msg + " " + ( - vm ? formatLocation(formatComponentName(vm)) : '' - )); - } - }; - - formatComponentName = function (vm, includeFile) { - 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; - if (!name && file) { - var match = file.match(/([^/\\]+)\.vue$/); - name = match && match[1]; - } - - return ( - (name ? ("<" + (classify(name)) + ">") : "") + - (file && includeFile !== false ? (" at " + file) : '') - ) - }; - - var formatLocation = function (str) { - if (str === "") { - str += " - use the \"name\" option for better debugging messages."; - } - return ("\n(found in " + str + ")") - }; -} - /* */ @@ -1052,7 +1141,7 @@ function mergeHook ( : parentVal } -config._lifecycleHooks.forEach(function (hook) { +LIFECYCLE_HOOKS.forEach(function (hook) { strats[hook] = mergeHook; }); @@ -1070,7 +1159,7 @@ function mergeAssets (parentVal, childVal) { : res } -config._assetTypes.forEach(function (type) { +ASSET_TYPES.forEach(function (type) { strats[type + 's'] = mergeAssets; }); @@ -1196,21 +1285,20 @@ function mergeOptions ( if (process.env.NODE_ENV !== 'production') { checkComponents(child); } + + if (typeof child === 'function') { + child = child.options; + } + normalizeProps(child); normalizeDirectives(child); var extendsFrom = child.extends; if (extendsFrom) { - parent = typeof extendsFrom === 'function' - ? mergeOptions(parent, extendsFrom.options, vm) - : mergeOptions(parent, extendsFrom, vm); + parent = mergeOptions(parent, extendsFrom, vm); } if (child.mixins) { for (var i = 0, l = child.mixins.length; i < l; i++) { - var mixin = child.mixins[i]; - if (mixin.prototype instanceof Vue$2) { - mixin = mixin.options; - } - parent = mergeOptions(parent, mixin, vm); + parent = mergeOptions(parent, child.mixins[i], vm); } } var options = {}; @@ -1383,20 +1471,13 @@ function assertProp ( } } -/** - * Assert the type of a value - */ +var simpleCheckRE = /^(String|Number|Boolean|Function|Symbol)$/; + function assertType (value, type) { var valid; var expectedType = getType(type); - if (expectedType === 'String') { - valid = typeof value === (expectedType = 'string'); - } else if (expectedType === 'Number') { - valid = typeof value === (expectedType = 'number'); - } else if (expectedType === 'Boolean') { - valid = typeof value === (expectedType = 'boolean'); - } else if (expectedType === 'Function') { - valid = typeof value === (expectedType = 'function'); + if (simpleCheckRE.test(expectedType)) { + valid = typeof value === expectedType.toLowerCase(); } else if (expectedType === 'Object') { valid = isPlainObject(value); } else if (expectedType === 'Array') { @@ -1417,7 +1498,7 @@ function assertType (value, type) { */ function getType (fn) { var match = fn && fn.toString().match(/^\s*function (\w+)/); - return match && match[1] + return match ? match[1] : '' } function isType (type, fn) { @@ -1433,22 +1514,6 @@ function isType (type, fn) { return false } -function handleError (err, vm, info) { - if (config.errorHandler) { - config.errorHandler.call(null, err, vm, info); - } else { - if (process.env.NODE_ENV !== 'production') { - warn(("Error in " + info + ":"), vm); - } - /* istanbul ignore else */ - if (inBrowser && typeof console !== 'undefined') { - console.error(err); - } else { - throw err - } - } -} - /* not type checking this file because flow doesn't play well with Proxy */ var initProxy; @@ -1631,6 +1696,8 @@ function cloneVNodes (vnodes) { /* */ var normalizeEvent = cached(function (name) { + var passive = name.charAt(0) === '&'; + name = passive ? name.slice(1) : name; var once$$1 = name.charAt(0) === '~'; // Prefixed last, checked first name = once$$1 ? name.slice(1) : name; var capture = name.charAt(0) === '!'; @@ -1638,7 +1705,8 @@ var normalizeEvent = cached(function (name) { return { name: name, once: once$$1, - capture: capture + capture: capture, + passive: passive } }); @@ -1672,23 +1740,23 @@ function updateListeners ( cur = on[name]; old = oldOn[name]; event = normalizeEvent(name); - if (!cur) { + if (isUndef(cur)) { process.env.NODE_ENV !== 'production' && warn( "Invalid handler for event \"" + (event.name) + "\": got " + String(cur), vm ); - } else if (!old) { - if (!cur.fns) { + } else if (isUndef(old)) { + if (isUndef(cur.fns)) { cur = on[name] = createFnInvoker(cur); } - add(event.name, cur, event.once, event.capture); + add(event.name, cur, event.once, event.capture, event.passive); } else if (cur !== old) { old.fns = cur; on[name] = old; } } for (name in oldOn) { - if (!on[name]) { + if (isUndef(on[name])) { event = normalizeEvent(name); remove$$1(event.name, oldOn[name], event.capture); } @@ -1708,12 +1776,12 @@ function mergeVNodeHook (def, hookKey, hook) { remove(invoker.fns, wrappedHook); } - if (!oldHook) { + if (isUndef(oldHook)) { // no existing hook invoker = createFnInvoker([wrappedHook]); } else { /* istanbul ignore if */ - if (oldHook.fns && oldHook.merged) { + if (isDef(oldHook.fns) && isTrue(oldHook.merged)) { // already a merged invoker invoker = oldHook; invoker.fns.push(wrappedHook); @@ -1729,6 +1797,74 @@ function mergeVNodeHook (def, hookKey, hook) { /* */ +function extractPropsFromVNodeData ( + data, + Ctor, + tag +) { + // we are only extracting raw values here. + // validation and default values are handled in the child + // component itself. + var propOptions = Ctor.options.props; + if (isUndef(propOptions)) { + return + } + var res = {}; + var attrs = data.attrs; + var props = data.props; + if (isDef(attrs) || isDef(props)) { + for (var key in propOptions) { + var altKey = hyphenate(key); + if (process.env.NODE_ENV !== 'production') { + var keyInLowerCase = key.toLowerCase(); + if ( + key !== keyInLowerCase && + attrs && hasOwn(attrs, keyInLowerCase) + ) { + tip( + "Prop \"" + keyInLowerCase + "\" is passed to component " + + (formatComponentName(tag || Ctor)) + ", but the declared prop name is" + + " \"" + key + "\". " + + "Note that HTML attributes are case-insensitive and camelCased " + + "props need to use their kebab-case equivalents when using in-DOM " + + "templates. You should probably use \"" + altKey + "\" instead of \"" + key + "\"." + ); + } + } + checkProp(res, props, key, altKey, true) || + checkProp(res, attrs, key, altKey, false); + } + } + return res +} + +function checkProp ( + res, + hash, + key, + altKey, + preserve +) { + if (isDef(hash)) { + if (hasOwn(hash, key)) { + res[key] = hash[key]; + if (!preserve) { + delete hash[key]; + } + return true + } else if (hasOwn(hash, altKey)) { + res[key] = hash[altKey]; + if (!preserve) { + delete hash[altKey]; + } + return true + } + } + return false +} + +/* */ + // The template compiler attempts to minimize the need for normalization by // statically analyzing the template at compile time. // @@ -1767,25 +1903,25 @@ function normalizeArrayChildren (children, nestedIndex) { var i, c, last; for (i = 0; i < children.length; i++) { c = children[i]; - if (c == null || typeof c === 'boolean') { continue } + if (isUndef(c) || typeof c === 'boolean') { continue } last = res[res.length - 1]; // nested if (Array.isArray(c)) { res.push.apply(res, normalizeArrayChildren(c, ((nestedIndex || '') + "_" + i))); } else if (isPrimitive(c)) { - if (last && last.text) { - last.text += String(c); + if (isDef(last) && isDef(last.text)) { + (last).text += String(c); } else if (c !== '') { // convert primitive to vnode res.push(createTextVNode(c)); } } else { - if (c.text && last && last.text) { + if (isDef(c.text) && isDef(last) && isDef(last.text)) { res[res.length - 1] = createTextVNode(last.text + c.text); } else { // default key for nested array children (likely generated by v-for) - if (c.tag && c.key == null && nestedIndex != null) { - c.key = "__vlist" + nestedIndex + "_" + i + "__"; + if (isDef(c.tag) && isUndef(c.key) && isDef(nestedIndex)) { + c.key = "__vlist" + ((nestedIndex)) + "_" + i + "__"; } res.push(c); } @@ -1796,10 +1932,127 @@ function normalizeArrayChildren (children, nestedIndex) { /* */ -function getFirstComponentChild (children) { - return children && children.filter(function (c) { return c && c.componentOptions; })[0] +function ensureCtor (comp, base) { + return isObject(comp) + ? base.extend(comp) + : comp } +function resolveAsyncComponent ( + factory, + baseCtor, + context +) { + if (isTrue(factory.error) && isDef(factory.errorComp)) { + return factory.errorComp + } + + if (isDef(factory.resolved)) { + return factory.resolved + } + + if (isTrue(factory.loading) && isDef(factory.loadingComp)) { + return factory.loadingComp + } + + if (isDef(factory.contexts)) { + // already pending + factory.contexts.push(context); + } else { + var contexts = factory.contexts = [context]; + var sync = true; + + var forceRender = function () { + for (var i = 0, l = contexts.length; i < l; i++) { + contexts[i].$forceUpdate(); + } + }; + + var resolve = once(function (res) { + // cache resolved + factory.resolved = ensureCtor(res, baseCtor); + // invoke callbacks only if this is not a synchronous resolve + // (async resolves are shimmed as synchronous during SSR) + if (!sync) { + forceRender(); + } + }); + + var reject = once(function (reason) { + process.env.NODE_ENV !== 'production' && warn( + "Failed to resolve async component: " + (String(factory)) + + (reason ? ("\nReason: " + reason) : '') + ); + if (isDef(factory.errorComp)) { + factory.error = true; + forceRender(); + } + }); + + var res = factory(resolve, reject); + + if (isObject(res)) { + if (typeof res.then === 'function') { + // () => Promise + if (isUndef(factory.resolved)) { + res.then(resolve, reject); + } + } else if (isDef(res.component) && typeof res.component.then === 'function') { + res.component.then(resolve, reject); + + if (isDef(res.error)) { + factory.errorComp = ensureCtor(res.error, baseCtor); + } + + if (isDef(res.loading)) { + factory.loadingComp = ensureCtor(res.loading, baseCtor); + if (res.delay === 0) { + factory.loading = true; + } else { + setTimeout(function () { + if (isUndef(factory.resolved) && isUndef(factory.error)) { + factory.loading = true; + forceRender(); + } + }, res.delay || 200); + } + } + + if (isDef(res.timeout)) { + setTimeout(function () { + reject( + process.env.NODE_ENV !== 'production' + ? ("timeout (" + (res.timeout) + "ms)") + : null + ); + }, res.timeout); + } + } + } + + sync = false; + // return in case resolved synchronously + return factory.loading + ? factory.loadingComp + : factory.resolved + } +} + +/* */ + +function getFirstComponentChild (children) { + if (Array.isArray(children)) { + for (var i = 0; i < children.length; i++) { + var c = children[i]; + if (isDef(c) && isDef(c.componentOptions)) { + return c + } + } + } +} + +/* */ + /* */ function initEvents (vm) { @@ -1945,13 +2198,13 @@ function resolveSlots ( return slots } var defaultSlot = []; - var name, child; for (var i = 0, l = children.length; i < l; i++) { - child = children[i]; + var child = children[i]; // named slots should only be respected if the vnode was rendered in the // same context. if ((child.context === context || child.functionalContext === context) && - child.data && (name = child.data.slot)) { + child.data && child.data.slot != null) { + var name = child.data.slot; var slot = (slots[name] || (slots[name] = [])); if (child.tag === 'template') { slot.push.apply(slot, child.children); @@ -2238,7 +2491,7 @@ function activateChildComponent (vm, direct) { } else if (vm._directInactive) { return } - if (vm._inactive || vm._inactive == null) { + if (vm._inactive || vm._inactive === null) { vm._inactive = false; for (var i = 0; i < vm.$children.length; i++) { activateChildComponent(vm.$children[i]); @@ -2282,7 +2535,10 @@ function callHook (vm, hook) { /* */ +var MAX_UPDATE_COUNT = 100; + var queue = []; +var activatedChildren = []; var has = {}; var circular = {}; var waiting = false; @@ -2293,7 +2549,7 @@ var index = 0; * Reset the scheduler's state. */ function resetSchedulerState () { - queue.length = 0; + queue.length = activatedChildren.length = 0; has = {}; if (process.env.NODE_ENV !== 'production') { circular = {}; @@ -2306,7 +2562,7 @@ function resetSchedulerState () { */ function flushSchedulerQueue () { flushing = true; - var watcher, id, vm; + var watcher, id; // Sort queue before flush. // This ensures that: @@ -2328,7 +2584,7 @@ function flushSchedulerQueue () { // in dev build, check and stop circular updates. if (process.env.NODE_ENV !== 'production' && has[id] != null) { circular[id] = (circular[id] || 0) + 1; - if (circular[id] > config._maxUpdateCount) { + if (circular[id] > MAX_UPDATE_COUNT) { warn( 'You may have an infinite update loop ' + ( watcher.user @@ -2342,19 +2598,15 @@ function flushSchedulerQueue () { } } - // reset scheduler before updated hook called - var oldQueue = queue.slice(); + // keep copies of post queues before resetting state + var activatedQueue = activatedChildren.slice(); + var updatedQueue = queue.slice(); + resetSchedulerState(); - // call updated hooks - index = oldQueue.length; - while (index--) { - watcher = oldQueue[index]; - vm = watcher.vm; - if (vm._watcher === watcher && vm._isMounted) { - callHook(vm, 'updated'); - } - } + // call component updated and activated hooks + callActivatedHooks(activatedQueue); + callUpdateHooks(updatedQueue); // devtool hook /* istanbul ignore if */ @@ -2363,6 +2615,35 @@ function flushSchedulerQueue () { } } +function callUpdateHooks (queue) { + var i = queue.length; + while (i--) { + var watcher = queue[i]; + var vm = watcher.vm; + if (vm._watcher === watcher && vm._isMounted) { + callHook(vm, 'updated'); + } + } +} + +/** + * Queue a kept-alive component that was activated during patch. + * The queue will be processed after the entire tree has been patched. + */ +function queueActivatedComponent (vm) { + // setting _inactive to false here so that a render function can + // rely on checking whether it's in an inactive tree (e.g. router-view) + vm._inactive = false; + activatedChildren.push(vm); +} + +function callActivatedHooks (queue) { + for (var i = 0; i < queue.length; i++) { + queue[i]._inactive = true; + activateChildComponent(queue[i], true /* true */); + } +} + /** * Push a watcher into the watcher queue. * Jobs with duplicate IDs will be skipped unless it's @@ -2666,7 +2947,11 @@ function initState (vm) { if (opts.watch) { initWatch(vm, opts.watch); } } -var isReservedProp = { key: 1, ref: 1, slot: 1 }; +var isReservedProp = { + key: 1, + ref: 1, + slot: 1 +}; function initProps (vm, propsOptions) { var propsData = vm.$options.propsData || {}; @@ -2682,7 +2967,7 @@ function initProps (vm, propsOptions) { var value = validateProp(key, propsOptions, propsData, vm); /* istanbul ignore else */ if (process.env.NODE_ENV !== 'production') { - if (isReservedProp[key]) { + if (isReservedProp[key] || config.isReservedAttr(key)) { warn( ("\"" + key + "\" is a reserved attribute and cannot be used as component prop."), vm @@ -2780,6 +3065,12 @@ function initComputed (vm, computed) { // at instantiation here. if (!(key in vm)) { defineComputed(vm, key, userDef); + } else if (process.env.NODE_ENV !== 'production') { + if (key in vm.$data) { + warn(("The computed property \"" + key + "\" is already defined in data."), vm); + } else if (vm.$options.props && key in vm.$options.props) { + warn(("The computed property \"" + key + "\" is already defined as a prop."), vm); + } } } } @@ -2909,6 +3200,113 @@ function stateMixin (Vue) { /* */ +function initProvide (vm) { + var provide = vm.$options.provide; + if (provide) { + vm._provided = typeof provide === 'function' + ? provide.call(vm) + : provide; + } +} + +function initInjections (vm) { + var result = resolveInject(vm.$options.inject, vm); + if (result) { + Object.keys(result).forEach(function (key) { + /* istanbul ignore else */ + if (process.env.NODE_ENV !== 'production') { + defineReactive$$1(vm, key, result[key], function () { + warn( + "Avoid mutating an injected value directly since the changes will be " + + "overwritten whenever the provided component re-renders. " + + "injection being mutated: \"" + key + "\"", + vm + ); + }); + } else { + defineReactive$$1(vm, key, result[key]); + } + }); + } +} + +function resolveInject (inject, vm) { + if (inject) { + // inject is :any because flow is not smart enough to figure out cached + // isArray here + var isArray = Array.isArray(inject); + var result = Object.create(null); + var keys = isArray + ? inject + : hasSymbol + ? Reflect.ownKeys(inject) + : Object.keys(inject); + + for (var i = 0; i < keys.length; i++) { + var key = keys[i]; + var provideKey = isArray ? key : inject[key]; + var source = vm; + while (source) { + if (source._provided && provideKey in source._provided) { + result[key] = source._provided[provideKey]; + break + } + source = source.$parent; + } + } + return result + } +} + +/* */ + +function createFunctionalComponent ( + Ctor, + propsData, + data, + context, + children +) { + var props = {}; + var propOptions = Ctor.options.props; + if (isDef(propOptions)) { + for (var key in propOptions) { + props[key] = validateProp(key, propOptions, propsData); + } + } else { + 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 || {}, + injections: resolveInject(Ctor.options.inject, context), + slots: function () { return resolveSlots(children, context); } + }); + if (vnode instanceof VNode) { + vnode.functionalContext = context; + if (data.slot) { + (vnode.data || (vnode.data = {})).slot = data.slot; + } + } + return vnode +} + +function mergeProps (to, from) { + for (var key in from) { + to[camelize(key)] = from[key]; + } +} + +/* */ + // hooks to be invoked on component VNodes during patch var componentVNodeHooks = { init: function init ( @@ -2945,21 +3343,33 @@ var componentVNodeHooks = { }, insert: function insert (vnode) { - if (!vnode.componentInstance._isMounted) { - vnode.componentInstance._isMounted = true; - callHook(vnode.componentInstance, 'mounted'); + var context = vnode.context; + var componentInstance = vnode.componentInstance; + if (!componentInstance._isMounted) { + componentInstance._isMounted = true; + callHook(componentInstance, 'mounted'); } if (vnode.data.keepAlive) { - activateChildComponent(vnode.componentInstance, true /* direct */); + if (context._isMounted) { + // vue-router#1212 + // During updates, a kept-alive component's child components may + // change, so directly walking the tree here may call activated hooks + // on incorrect children. Instead we push them into a queue which will + // be processed after the whole patch process ended. + queueActivatedComponent(componentInstance); + } else { + activateChildComponent(componentInstance, true /* direct */); + } } }, destroy: function destroy (vnode) { - if (!vnode.componentInstance._isDestroyed) { + var componentInstance = vnode.componentInstance; + if (!componentInstance._isDestroyed) { if (!vnode.data.keepAlive) { - vnode.componentInstance.$destroy(); + componentInstance.$destroy(); } else { - deactivateChildComponent(vnode.componentInstance, true /* direct */); + deactivateChildComponent(componentInstance, true /* direct */); } } } @@ -2974,15 +3384,19 @@ function createComponent ( children, tag ) { - if (!Ctor) { + if (isUndef(Ctor)) { return } var baseCtor = context.$options._base; + + // plain options object: turn it into a constructor if (isObject(Ctor)) { Ctor = baseCtor.extend(Ctor); } + // if at this stage it's not a constructor or an async component factory, + // reject. if (typeof Ctor !== 'function') { if (process.env.NODE_ENV !== 'production') { warn(("Invalid Component definition: " + (String(Ctor))), context); @@ -2991,20 +3405,12 @@ function createComponent ( } // async component - if (!Ctor.cid) { - if (Ctor.resolved) { - Ctor = Ctor.resolved; - } else { - Ctor = resolveAsyncComponent(Ctor, baseCtor, function () { - // it's ok to queue this on every render because - // $forceUpdate is buffered by the scheduler. - context.$forceUpdate(); - }); - if (!Ctor) { - // return nothing if this is indeed an async component - // wait for the callback to trigger parent update. - return - } + if (isUndef(Ctor.cid)) { + Ctor = resolveAsyncComponent(Ctor, baseCtor, context); + if (Ctor === undefined) { + // return nothing if this is indeed an async component + // wait for the callback to trigger parent update. + return } } @@ -3015,15 +3421,15 @@ function createComponent ( data = data || {}; // transform component v-model data into props & events - if (data.model) { + if (isDef(data.model)) { transformModel(Ctor.options, data); } // extract props - var propsData = extractProps(data, Ctor, tag); + var propsData = extractPropsFromVNodeData(data, Ctor, tag); // functional component - if (Ctor.options.functional) { + if (isTrue(Ctor.options.functional)) { return createFunctionalComponent(Ctor, propsData, data, context, children) } @@ -3033,7 +3439,7 @@ function createComponent ( // replace with listeners with .native modifier data.on = data.nativeOn; - if (Ctor.options.abstract) { + if (isTrue(Ctor.options.abstract)) { // abstract components do not keep anything // other than props & listeners data = {}; @@ -3052,40 +3458,6 @@ function createComponent ( return vnode } -function createFunctionalComponent ( - Ctor, - propsData, - data, - context, - children -) { - var props = {}; - var propOptions = Ctor.options.props; - if (propOptions) { - for (var key in propOptions) { - props[key] = validateProp(key, propOptions, propsData); - } - } - // 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, { - props: props, - data: data, - parent: context, - children: children, - slots: function () { return resolveSlots(children, context); } - }); - if (vnode instanceof VNode) { - vnode.functionalContext = context; - if (data.slot) { - (vnode.data || (vnode.data = {})).slot = data.slot; - } - } - return vnode -} - function createComponentInstanceForVnode ( vnode, // we know it's MountedComponentVNode but flow doesn't parent, // activeInstance in lifecycle state @@ -3106,125 +3478,13 @@ function createComponentInstanceForVnode ( }; // check inline-template render functions var inlineTemplate = vnode.data.inlineTemplate; - if (inlineTemplate) { + if (isDef(inlineTemplate)) { options.render = inlineTemplate.render; options.staticRenderFns = inlineTemplate.staticRenderFns; } return new vnodeComponentOptions.Ctor(options) } -function resolveAsyncComponent ( - factory, - baseCtor, - cb -) { - if (factory.requested) { - // pool callbacks - factory.pendingCallbacks.push(cb); - } else { - factory.requested = true; - var cbs = factory.pendingCallbacks = [cb]; - var sync = true; - - var resolve = function (res) { - if (isObject(res)) { - res = baseCtor.extend(res); - } - // cache resolved - factory.resolved = res; - // invoke callbacks only if this is not a synchronous resolve - // (async resolves are shimmed as synchronous during SSR) - if (!sync) { - for (var i = 0, l = cbs.length; i < l; i++) { - cbs[i](res); - } - } - }; - - var reject = function (reason) { - process.env.NODE_ENV !== 'production' && warn( - "Failed to resolve async component: " + (String(factory)) + - (reason ? ("\nReason: " + reason) : '') - ); - }; - - var res = factory(resolve, reject); - - // handle promise - if (res && typeof res.then === 'function' && !factory.resolved) { - res.then(resolve, reject); - } - - sync = false; - // return in case resolved synchronously - return factory.resolved - } -} - -function extractProps (data, Ctor, tag) { - // we are only extracting raw values here. - // validation and default values are handled in the child - // component itself. - var propOptions = Ctor.options.props; - if (!propOptions) { - return - } - var res = {}; - var attrs = data.attrs; - var props = data.props; - var domProps = data.domProps; - if (attrs || props || domProps) { - for (var key in propOptions) { - var altKey = hyphenate(key); - if (process.env.NODE_ENV !== 'production') { - var keyInLowerCase = key.toLowerCase(); - if ( - key !== keyInLowerCase && - attrs && attrs.hasOwnProperty(keyInLowerCase) - ) { - tip( - "Prop \"" + keyInLowerCase + "\" is passed to component " + - (formatComponentName(tag || Ctor)) + ", but the declared prop name is" + - " \"" + key + "\". " + - "Note that HTML attributes are case-insensitive and camelCased " + - "props need to use their kebab-case equivalents when using in-DOM " + - "templates. You should probably use \"" + altKey + "\" instead of \"" + key + "\"." - ); - } - } - checkProp(res, props, key, altKey, true) || - checkProp(res, attrs, key, altKey) || - checkProp(res, domProps, key, altKey); - } - } - return res -} - -function checkProp ( - res, - hash, - key, - altKey, - preserve -) { - if (hash) { - if (hasOwn(hash, key)) { - res[key] = hash[key]; - if (!preserve) { - delete hash[key]; - } - return true - } else if (hasOwn(hash, altKey)) { - res[key] = hash[altKey]; - if (!preserve) { - delete hash[altKey]; - } - return true - } - } - return false -} - function mergeHooks (data) { if (!data.hook) { data.hook = {}; @@ -3250,7 +3510,7 @@ function transformModel (options, data) { var prop = (options.model && options.model.prop) || 'value'; var event = (options.model && options.model.event) || 'input';(data.props || (data.props = {}))[prop] = data.model.value; var on = data.on || (data.on = {}); - if (on[event]) { + if (isDef(on[event])) { on[event] = [data.model.callback].concat(on[event]); } else { on[event] = data.model.callback; @@ -3277,7 +3537,9 @@ function createElement ( children = data; data = undefined; } - if (alwaysNormalize) { normalizationType = ALWAYS_NORMALIZE; } + if (isTrue(alwaysNormalize)) { + normalizationType = ALWAYS_NORMALIZE; + } return _createElement(context, tag, data, children, normalizationType) } @@ -3288,7 +3550,7 @@ function _createElement ( children, normalizationType ) { - if (data && data.__ob__) { + if (isDef(data) && isDef((data).__ob__)) { process.env.NODE_ENV !== 'production' && warn( "Avoid using observed data object as vnode data: " + (JSON.stringify(data)) + "\n" + 'Always create fresh vnode data objects in each render!', @@ -3322,7 +3584,7 @@ function _createElement ( config.parsePlatformTagName(tag), data, children, undefined, undefined, context ); - } else if ((Ctor = resolveAsset(context.$options, 'components', tag))) { + } else if (isDef(Ctor = resolveAsset(context.$options, 'components', tag))) { // component vnode = createComponent(Ctor, data, context, children, tag); } else { @@ -3338,7 +3600,7 @@ function _createElement ( // direct component options / constructor vnode = createComponent(tag, data, context, children); } - if (vnode) { + if (vnode !== undefined) { if (ns) { applyNS(vnode, ns); } return vnode } else { @@ -3352,10 +3614,10 @@ function applyNS (vnode, ns) { // use default namespace inside foreignObject return } - if (vnode.children) { + if (Array.isArray(vnode.children)) { for (var i = 0, l = vnode.children.length; i < l; i++) { var child = vnode.children[i]; - if (child.tag && !child.ns) { + if (isDef(child.tag) && isUndef(child.ns)) { applyNS(child, ns); } } @@ -3555,10 +3817,9 @@ function markStaticNode (node, key, isOnce) { /* */ function initRender (vm) { - vm.$vnode = null; // the placeholder node in parent tree vm._vnode = null; // the root of the child tree vm._staticTrees = null; - var parentVnode = vm.$options._parentVnode; + var parentVnode = vm.$vnode = vm.$options._parentVnode; // the placeholder node in parent tree var renderContext = parentVnode && parentVnode.context; vm.$slots = resolveSlots(vm.$options._renderChildren, renderContext); vm.$scopedSlots = emptyObject; @@ -3653,58 +3914,6 @@ function renderMixin (Vue) { /* */ -function initProvide (vm) { - var provide = vm.$options.provide; - if (provide) { - vm._provided = typeof provide === 'function' - ? provide.call(vm) - : provide; - } -} - -function initInjections (vm) { - var inject = vm.$options.inject; - if (inject) { - // inject is :any because flow is not smart enough to figure out cached - // isArray here - var isArray = Array.isArray(inject); - var keys = isArray - ? inject - : hasSymbol - ? Reflect.ownKeys(inject) - : Object.keys(inject); - - var loop = function ( i ) { - var key = keys[i]; - var provideKey = isArray ? key : inject[key]; - var source = vm; - while (source) { - if (source._provided && provideKey in source._provided) { - /* istanbul ignore else */ - if (process.env.NODE_ENV !== 'production') { - defineReactive$$1(vm, key, source._provided[provideKey], function () { - warn( - "Avoid mutating an injected value directly since the changes will be " + - "overwritten whenever the provided component re-renders. " + - "injection being mutated: \"" + key + "\"", - vm - ); - }); - } else { - defineReactive$$1(vm, key, source._provided[provideKey]); - } - break - } - source = source.$parent; - } - }; - - for (var i = 0; i < keys.length; i++) loop( i ); - } -} - -/* */ - var uid = 0; function initMixin (Vue) { @@ -3810,24 +4019,27 @@ function resolveConstructorOptions (Ctor) { function resolveModifiedOptions (Ctor) { var modified; var latest = Ctor.options; + var extended = Ctor.extendOptions; var sealed = Ctor.sealedOptions; for (var key in latest) { if (latest[key] !== sealed[key]) { if (!modified) { modified = {}; } - modified[key] = dedupe(latest[key], sealed[key]); + modified[key] = dedupe(latest[key], extended[key], sealed[key]); } } return modified } -function dedupe (latest, sealed) { +function dedupe (latest, extended, sealed) { // compare latest and sealed to ensure lifecycle hooks won't be duplicated // between merges if (Array.isArray(latest)) { var res = []; sealed = Array.isArray(sealed) ? sealed : [sealed]; + extended = Array.isArray(extended) ? extended : [extended]; for (var i = 0; i < latest.length; i++) { - if (sealed.indexOf(latest[i]) < 0) { + // push original options and not sealed options to exclude duplicated options + if (extended.indexOf(latest[i]) >= 0 || sealed.indexOf(latest[i]) < 0) { res.push(latest[i]); } } @@ -3837,19 +4049,19 @@ function dedupe (latest, sealed) { } } -function Vue$2 (options) { +function Vue$3 (options) { if (process.env.NODE_ENV !== 'production' && - !(this instanceof Vue$2)) { + !(this instanceof Vue$3)) { warn('Vue is a constructor and should be called with the `new` keyword'); } this._init(options); } -initMixin(Vue$2); -stateMixin(Vue$2); -eventsMixin(Vue$2); -lifecycleMixin(Vue$2); -renderMixin(Vue$2); +initMixin(Vue$3); +stateMixin(Vue$3); +eventsMixin(Vue$3); +lifecycleMixin(Vue$3); +renderMixin(Vue$3); /* */ @@ -3943,7 +4155,7 @@ function initExtend (Vue) { // create asset registers, so extended classes // can have their private assets too. - config._assetTypes.forEach(function (type) { + ASSET_TYPES.forEach(function (type) { Sub[type] = Super[type]; }); // enable recursive self-lookup @@ -3984,7 +4196,7 @@ function initAssetRegisters (Vue) { /** * Create asset registration methods. */ - config._assetTypes.forEach(function (type) { + ASSET_TYPES.forEach(function (type) { Vue[type] = function ( id, definition @@ -4026,20 +4238,22 @@ function getComponentName (opts) { function matches (pattern, name) { if (typeof pattern === 'string') { return pattern.split(',').indexOf(name) > -1 - } else if (pattern instanceof RegExp) { + } else if (isRegExp(pattern)) { return pattern.test(name) } /* istanbul ignore next */ return false } -function pruneCache (cache, filter) { +function pruneCache (cache, current, filter) { for (var key in cache) { var cachedNode = cache[key]; if (cachedNode) { var name = getComponentName(cachedNode.componentOptions); if (name && !filter(name)) { - pruneCacheEntry(cachedNode); + if (cachedNode !== current) { + pruneCacheEntry(cachedNode); + } cache[key] = null; } } @@ -4048,9 +4262,6 @@ function pruneCache (cache, filter) { function pruneCacheEntry (vnode) { if (vnode) { - if (!vnode.componentInstance._inactive) { - callHook(vnode.componentInstance, 'deactivated'); - } vnode.componentInstance.$destroy(); } } @@ -4078,10 +4289,10 @@ var KeepAlive = { watch: { include: function include (val) { - pruneCache(this.cache, function (name) { return matches(val, name); }); + pruneCache(this.cache, this._vnode, function (name) { return matches(val, name); }); }, exclude: function exclude (val) { - pruneCache(this.cache, function (name) { return !matches(val, name); }); + pruneCache(this.cache, this._vnode, function (name) { return !matches(val, name); }); } }, @@ -4147,7 +4358,7 @@ function initGlobalAPI (Vue) { Vue.nextTick = nextTick; Vue.options = Object.create(null); - config._assetTypes.forEach(function (type) { + ASSET_TYPES.forEach(function (type) { Vue.options[type + 's'] = Object.create(null); }); @@ -4163,16 +4374,20 @@ function initGlobalAPI (Vue) { initAssetRegisters(Vue); } -initGlobalAPI(Vue$2); +initGlobalAPI(Vue$3); -Object.defineProperty(Vue$2.prototype, '$isServer', { +Object.defineProperty(Vue$3.prototype, '$isServer', { get: isServerRendering }); -Vue$2.version = '2.2.6'; +Vue$3.version = '2.3.0-beta.1'; /* */ +// these are reserved for web because they are directly compiled away +// during template compilation +var isReservedAttr = makeMap('style,class'); + // attributes that should be using props for binding var acceptValue = makeMap('input,textarea,option,select'); var mustUseProp = function (tag, type, attr) { @@ -4215,13 +4430,13 @@ function genClassForVnode (vnode) { var data = vnode.data; var parentNode = vnode; var childNode = vnode; - while (childNode.componentInstance) { + while (isDef(childNode.componentInstance)) { childNode = childNode.componentInstance._vnode; if (childNode.data) { data = mergeClassData(childNode.data, data); } } - while ((parentNode = parentNode.parent)) { + while (isDef(parentNode = parentNode.parent)) { if (parentNode.data) { data = mergeClassData(data, parentNode.data); } @@ -4232,7 +4447,7 @@ function genClassForVnode (vnode) { function mergeClassData (child, parent) { return { staticClass: concat(child.staticClass, parent.staticClass), - class: child.class + class: isDef(child.class) ? [child.class, parent.class] : parent.class } @@ -4241,7 +4456,7 @@ function mergeClassData (child, parent) { function genClassFromData (data) { var dynamicClass = data.class; var staticClass = data.staticClass; - if (staticClass || dynamicClass) { + if (isDef(staticClass) || isDef(dynamicClass)) { return concat(staticClass, stringifyClass(dynamicClass)) } /* istanbul ignore next */ @@ -4253,18 +4468,18 @@ function concat (a, b) { } function stringifyClass (value) { - var res = ''; - if (!value) { - return res + if (isUndef(value)) { + return '' } if (typeof value === 'string') { return value } + var res = ''; if (Array.isArray(value)) { var stringified; for (var i = 0, l = value.length; i < l; i++) { - if (value[i]) { - if ((stringified = stringifyClass(value[i]))) { + if (isDef(value[i])) { + if (isDef(stringified = stringifyClass(value[i])) && stringified !== '') { res += stringified + ' '; } } @@ -4509,18 +4724,6 @@ var emptyNode = new VNode('', {}, []); var hooks = ['create', 'activate', 'update', 'remove', 'destroy']; -function isUndef (v) { - return v === undefined || v === null -} - -function isDef (v) { - return v !== undefined && v !== null -} - -function isTrue (v) { - return v === true -} - function sameVnode (a, b) { return ( a.key === b.key && @@ -4707,7 +4910,9 @@ function createPatchFunction (backend) { function insert (parent, elm, ref) { if (isDef(parent)) { if (isDef(ref)) { - nodeOps.insertBefore(parent, elm, ref); + if (ref.parentNode === parent) { + nodeOps.insertBefore(parent, elm, ref); + } } else { nodeOps.appendChild(parent, elm); } @@ -4798,6 +5003,7 @@ function createPatchFunction (backend) { function removeAndInvokeRemoveHook (vnode, rm) { if (isDef(rm) || isDef(vnode.data)) { + var i; var listeners = cbs.remove.length + 1; if (isDef(rm)) { // we have a recursively passed down rm callback @@ -5059,8 +5265,8 @@ function createPatchFunction (backend) { // mounting to a real element // check if this is server-rendered content and if we can perform // a successful hydration. - if (oldVnode.nodeType === 1 && oldVnode.hasAttribute('server-rendered')) { - oldVnode.removeAttribute('server-rendered'); + if (oldVnode.nodeType === 1 && oldVnode.hasAttribute(SSR_ATTR)) { + oldVnode.removeAttribute(SSR_ATTR); hydrating = true; } if (isTrue(hydrating)) { @@ -5227,7 +5433,11 @@ function getRawDirName (dir) { function callHook$1 (dir, hook, vnode, oldVnode, isDestroy) { var fn = dir.def && dir.def[hook]; if (fn) { - fn(vnode.elm, dir, vnode, oldVnode, isDestroy); + try { + fn(vnode.elm, dir, vnode, oldVnode, isDestroy); + } catch (e) { + handleError(e, vnode.context, ("directive " + (dir.name) + " " + hook + " hook")); + } } } @@ -5239,7 +5449,7 @@ var baseModules = [ /* */ function updateAttrs (oldVnode, vnode) { - if (!oldVnode.data.attrs && !vnode.data.attrs) { + if (isUndef(oldVnode.data.attrs) && isUndef(vnode.data.attrs)) { return } var key, cur, old; @@ -5247,7 +5457,7 @@ function updateAttrs (oldVnode, vnode) { var oldAttrs = oldVnode.data.attrs || {}; var attrs = vnode.data.attrs || {}; // clone observed objects, as the user probably wants to mutate it - if (attrs.__ob__) { + if (isDef(attrs.__ob__)) { attrs = vnode.data.attrs = extend({}, attrs); } @@ -5264,7 +5474,7 @@ function updateAttrs (oldVnode, vnode) { setAttr(elm, 'value', attrs.value); } for (key in oldAttrs) { - if (attrs[key] == null) { + if (isUndef(attrs[key])) { if (isXlink(key)) { elm.removeAttributeNS(xlinkNS, getXlinkProp(key)); } else if (!isEnumeratedAttr(key)) { @@ -5311,8 +5521,15 @@ function updateClass (oldVnode, vnode) { var el = vnode.elm; var data = vnode.data; var oldData = oldVnode.data; - if (!data.staticClass && !data.class && - (!oldData || (!oldData.staticClass && !oldData.class))) { + if ( + isUndef(data.staticClass) && + isUndef(data.class) && ( + isUndef(oldData) || ( + isUndef(oldData.staticClass) && + isUndef(oldData.class) + ) + ) + ) { return } @@ -5320,7 +5537,7 @@ function updateClass (oldVnode, vnode) { // handle transition classes var transitionClass = el._transitionClasses; - if (transitionClass) { + if (isDef(transitionClass)) { cls = concat(cls, stringifyClass(transitionClass)); } @@ -5401,13 +5618,13 @@ var CHECKBOX_RADIO_TOKEN = '__c'; function normalizeEvents (on) { var event; /* istanbul ignore if */ - if (on[RANGE_TOKEN]) { + if (isDef(on[RANGE_TOKEN])) { // IE input[type=range] only supports `change` event event = isIE ? 'change' : 'input'; on[event] = [].concat(on[RANGE_TOKEN], on[event] || []); delete on[RANGE_TOKEN]; } - if (on[CHECKBOX_RADIO_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] || []); @@ -5420,10 +5637,11 @@ var target$1; function add$1 ( event, handler, - once, - capture + once$$1, + capture, + passive ) { - if (once) { + if (once$$1) { var oldHandler = handler; var _target = target$1; // save current target element in closure handler = function (ev) { @@ -5435,7 +5653,13 @@ function add$1 ( } }; } - target$1.addEventListener(event, handler, capture); + target$1.addEventListener( + event, + handler, + supportsPassive + ? { capture: capture, passive: passive } + : capture + ); } function remove$2 ( @@ -5448,7 +5672,7 @@ function remove$2 ( } function updateDOMListeners (oldVnode, vnode) { - if (!oldVnode.data.on && !vnode.data.on) { + if (isUndef(oldVnode.data.on) && isUndef(vnode.data.on)) { return } var on = vnode.data.on || {}; @@ -5466,7 +5690,7 @@ var events = { /* */ function updateDOMProps (oldVnode, vnode) { - if (!oldVnode.data.domProps && !vnode.data.domProps) { + if (isUndef(oldVnode.data.domProps) && isUndef(vnode.data.domProps)) { return } var key, cur; @@ -5474,12 +5698,12 @@ function updateDOMProps (oldVnode, vnode) { var oldProps = oldVnode.data.domProps || {}; var props = vnode.data.domProps || {}; // clone observed objects, as the user probably wants to mutate it - if (props.__ob__) { + if (isDef(props.__ob__)) { props = vnode.data.domProps = extend({}, props); } for (key in oldProps) { - if (props[key] == null) { + if (isUndef(props[key])) { elm[key] = ''; } } @@ -5531,10 +5755,10 @@ function isDirty (elm, checkVal) { function isInputChanged (elm, newVal) { var value = elm.value; var modifiers = elm._vModifiers; // injected by v-model runtime - if ((modifiers && modifiers.number) || elm.type === 'number') { + if ((isDef(modifiers) && modifiers.number) || elm.type === 'number') { return toNumber(value) !== toNumber(newVal) } - if (modifiers && modifiers.trim) { + if (isDef(modifiers) && modifiers.trim) { return value.trim() !== newVal.trim() } return value !== newVal @@ -5623,7 +5847,17 @@ var setProp = function (el, name, val) { } else if (importantRE.test(val)) { el.style.setProperty(name, val.replace(importantRE, ''), 'important'); } else { - el.style[normalize(name)] = val; + var normalizedName = normalize(name); + if (Array.isArray(val)) { + // Support values array created by autoprefixer, e.g. + // {display: ["-webkit-box", "-ms-flexbox", "flex"]} + // Set them one by one, and the browser will only set those it can recognize + for (var i = 0, len = val.length; i < len; i++) { + el.style[normalizedName] = val[i]; + } + } else { + el.style[normalizedName] = val; + } } }; @@ -5649,27 +5883,32 @@ function updateStyle (oldVnode, vnode) { var data = vnode.data; var oldData = oldVnode.data; - if (!data.staticStyle && !data.style && - !oldData.staticStyle && !oldData.style) { + if (isUndef(data.staticStyle) && isUndef(data.style) && + isUndef(oldData.staticStyle) && isUndef(oldData.style)) { return } var cur, name; var el = vnode.elm; - var oldStaticStyle = oldVnode.data.staticStyle; - var oldStyleBinding = oldVnode.data.style || {}; + var oldStaticStyle = oldData.staticStyle; + var oldStyleBinding = oldData.normalizedStyle || oldData.style || {}; // if static style exists, stylebinding already merged into it when doing normalizeStyleData var oldStyle = oldStaticStyle || oldStyleBinding; var style = normalizeStyleBinding(vnode.data.style) || {}; - vnode.data.style = style.__ob__ ? extend({}, style) : style; + // store normalized style under a different key for next diff + // make sure to clone it if it's reactive, since the user likley wants + // to mutate it. + vnode.data.normalizedStyle = isDef(style.__ob__) + ? extend({}, style) + : style; var newStyle = getStyle(vnode, true); for (name in oldStyle) { - if (newStyle[name] == null) { + if (isUndef(newStyle[name])) { setProp(el, name, ''); } } @@ -5920,38 +6159,39 @@ function enter (vnode, toggleDisplay) { var el = vnode.elm; // call leave callback now - if (el._leaveCb) { + if (isDef(el._leaveCb)) { el._leaveCb.cancelled = true; el._leaveCb(); } var data = resolveTransition(vnode.data.transition); - if (!data) { + if (isUndef(data)) { return } /* istanbul ignore if */ - if (el._enterCb || el.nodeType !== 1) { + if (isDef(el._enterCb) || el.nodeType !== 1) { return } - var css = data.css; - var type = data.type; - var enterClass = data.enterClass; - var enterToClass = data.enterToClass; - var enterActiveClass = data.enterActiveClass; - var appearClass = data.appearClass; - var appearToClass = data.appearToClass; - var appearActiveClass = data.appearActiveClass; - var beforeEnter = data.beforeEnter; - var enter = data.enter; - var afterEnter = data.afterEnter; - var enterCancelled = data.enterCancelled; - var beforeAppear = data.beforeAppear; - var appear = data.appear; - var afterAppear = data.afterAppear; - var appearCancelled = data.appearCancelled; - var duration = data.duration; + var ref = (data); + var css = ref.css; + var type = ref.type; + var enterClass = ref.enterClass; + var enterToClass = ref.enterToClass; + var enterActiveClass = ref.enterActiveClass; + var appearClass = ref.appearClass; + var appearToClass = ref.appearToClass; + var appearActiveClass = ref.appearActiveClass; + var beforeEnter = ref.beforeEnter; + var enter = ref.enter; + var afterEnter = ref.afterEnter; + var enterCancelled = ref.enterCancelled; + var beforeAppear = ref.beforeAppear; + var appear = ref.appear; + var afterAppear = ref.afterAppear; + var appearCancelled = ref.appearCancelled; + var duration = ref.duration; // activeInstance will always be the component managing this // transition. One edge case to check is when the is placed @@ -6068,32 +6308,33 @@ function leave (vnode, rm) { var el = vnode.elm; // call enter callback now - if (el._enterCb) { + if (isDef(el._enterCb)) { el._enterCb.cancelled = true; el._enterCb(); } var data = resolveTransition(vnode.data.transition); - if (!data) { + if (isUndef(data)) { return rm() } /* istanbul ignore if */ - if (el._leaveCb || el.nodeType !== 1) { + if (isDef(el._leaveCb) || el.nodeType !== 1) { return } - var css = data.css; - var type = data.type; - var leaveClass = data.leaveClass; - var leaveToClass = data.leaveToClass; - var leaveActiveClass = data.leaveActiveClass; - var beforeLeave = data.beforeLeave; - var leave = data.leave; - var afterLeave = data.afterLeave; - var leaveCancelled = data.leaveCancelled; - var delayLeave = data.delayLeave; - var duration = data.duration; + var ref = (data); + var css = ref.css; + var type = ref.type; + var leaveClass = ref.leaveClass; + var leaveToClass = ref.leaveToClass; + var leaveActiveClass = ref.leaveActiveClass; + var beforeLeave = ref.beforeLeave; + var leave = ref.leave; + var afterLeave = ref.afterLeave; + var leaveCancelled = ref.leaveCancelled; + var delayLeave = ref.delayLeave; + var duration = ref.duration; var expectsCSS = css !== false && !isIE9; var userWantsControl = getHookArgumentsLength(leave); @@ -6194,9 +6435,11 @@ function isValidDuration (val) { * - a plain function (.length) */ function getHookArgumentsLength (fn) { - if (!fn) { return false } + if (isUndef(fn)) { + return false + } var invokerFns = fn.fns; - if (invokerFns) { + if (isDef(invokerFns)) { // invoker return getHookArgumentsLength( Array.isArray(invokerFns) @@ -6209,7 +6452,7 @@ function getHookArgumentsLength (fn) { } function _enter (_, vnode) { - if (!vnode.data.show) { + if (vnode.data.show !== true) { enter(vnode); } } @@ -6219,7 +6462,7 @@ var transition = inBrowser ? { activate: _enter, remove: function remove$$1 (vnode, rm) { /* istanbul ignore else */ - if (!vnode.data.show) { + if (vnode.data.show !== true) { leave(vnode, rm); } else { rm(); @@ -6274,6 +6517,11 @@ var model$1 = { } else if (vnode.tag === 'textarea' || el.type === 'text' || el.type === 'password') { el._vModifiers = binding.modifiers; if (!binding.modifiers.lazy) { + // Safari < 10.2 & UIWebView doesn't fire compositionend when + // switching focus before confirming composition choice + // this also fixes the issue where some browsers e.g. iOS Chrome + // fires "change" instead of "input" on autocomplete. + el.addEventListener('change', onCompositionEnd); if (!isAndroid) { el.addEventListener('compositionstart', onCompositionStart); el.addEventListener('compositionend', onCompositionEnd); @@ -6485,9 +6733,11 @@ function extractTransitionData (comp) { } function placeholder (h, rawChild) { - return /\d-keep-alive$/.test(rawChild.tag) - ? h('keep-alive') - : null + if (/\d-keep-alive$/.test(rawChild.tag)) { + return h('keep-alive', { + props: rawChild.componentOptions.propsData + }) + } } function hasParentTransition (vnode) { @@ -6783,20 +7033,21 @@ var platformComponents = { /* */ // install platform specific utils -Vue$2.config.mustUseProp = mustUseProp; -Vue$2.config.isReservedTag = isReservedTag; -Vue$2.config.getTagNamespace = getTagNamespace; -Vue$2.config.isUnknownElement = isUnknownElement; +Vue$3.config.mustUseProp = mustUseProp; +Vue$3.config.isReservedTag = isReservedTag; +Vue$3.config.isReservedAttr = isReservedAttr; +Vue$3.config.getTagNamespace = getTagNamespace; +Vue$3.config.isUnknownElement = isUnknownElement; // install platform runtime directives & components -extend(Vue$2.options.directives, platformDirectives); -extend(Vue$2.options.components, platformComponents); +extend(Vue$3.options.directives, platformDirectives); +extend(Vue$3.options.components, platformComponents); // install platform patch function -Vue$2.prototype.__patch__ = inBrowser ? patch : noop; +Vue$3.prototype.__patch__ = inBrowser ? patch : noop; // public mount method -Vue$2.prototype.$mount = function ( +Vue$3.prototype.$mount = function ( el, hydrating ) { @@ -6809,7 +7060,7 @@ Vue$2.prototype.$mount = function ( setTimeout(function () { if (config.devtools) { if (devtools) { - devtools.emit('init', Vue$2); + devtools.emit('init', Vue$3); } else if (process.env.NODE_ENV !== 'production' && isChrome) { console[console.info ? 'info' : 'log']( 'Download the Vue Devtools extension for a better development experience:\n' + @@ -6828,4 +7079,6 @@ setTimeout(function () { } }, 0); -module.exports = Vue$2; +/* */ + +module.exports = Vue$3; diff --git a/dist/vue.runtime.esm.js b/dist/vue.runtime.esm.js index 724b9411..c420a7a5 100644 --- a/dist/vue.runtime.esm.js +++ b/dist/vue.runtime.esm.js @@ -1,10 +1,54 @@ /*! - * Vue.js v2.2.6 + * Vue.js v2.3.0-beta.1 * (c) 2014-2017 Evan You * Released under the MIT License. */ /* */ +// these helpers produces better vm code in JS engines due to their +// explicitness and function inlining +function isUndef (v) { + return v === undefined || v === null +} + +function isDef (v) { + return v !== undefined && v !== null +} + +function isTrue (v) { + return v === true +} + +/** + * Check if value is primitive + */ +function isPrimitive (value) { + return typeof value === 'string' || typeof value === 'number' +} + +/** + * Quick object check - this is primarily used to tell + * Objects from primitive values when we know the value + * is a JSON-compliant type. + */ +function isObject (obj) { + return obj !== null && typeof obj === 'object' +} + +var toString = Object.prototype.toString; + +/** + * Strict object type check. Only returns true + * for plain JavaScript objects. + */ +function isPlainObject (obj) { + return toString.call(obj) === '[object Object]' +} + +function isRegExp (v) { + return toString.call(v) === '[object RegExp]' +} + /** * Convert a value to a string that is actually rendered. */ @@ -68,13 +112,6 @@ function hasOwn (obj, key) { return hasOwnProperty.call(obj, key) } -/** - * Check if value is primitive - */ -function isPrimitive (value) { - return typeof value === 'string' || typeof value === 'number' -} - /** * Create a cached version of a pure function. */ @@ -152,25 +189,6 @@ function extend (to, _from) { return to } -/** - * Quick object check - this is primarily used to tell - * Objects from primitive values when we know the value - * is a JSON-compliant type. - */ -function isObject (obj) { - return obj !== null && typeof obj === 'object' -} - -/** - * Strict object type check. Only returns true - * for plain JavaScript objects. - */ -var toString = Object.prototype.toString; -var OBJECT_STRING = '[object Object]'; -function isPlainObject (obj) { - return toString.call(obj) === OBJECT_STRING -} - /** * Merge an Array of Objects into a single Object. */ @@ -240,14 +258,35 @@ function once (fn) { return function () { if (!called) { called = true; - fn(); + fn.apply(this, arguments); } } } +var SSR_ATTR = 'data-server-rendered'; + +var ASSET_TYPES = [ + 'component', + 'directive', + 'filter' +]; + +var LIFECYCLE_HOOKS = [ + 'beforeCreate', + 'created', + 'beforeMount', + 'mounted', + 'beforeUpdate', + 'updated', + 'beforeDestroy', + 'destroyed', + 'activated', + 'deactivated' +]; + /* */ -var config = { +var config = ({ /** * Option merge strategies (used in core/util/options) */ @@ -294,6 +333,12 @@ var config = { */ isReservedTag: no, + /** + * Check if an attribute is reserved so that it cannot be used as a component + * prop. This is platform-dependent and may be overwritten. + */ + isReservedAttr: no, + /** * Check if a tag is an unknown element. * Platform-dependent. @@ -317,35 +362,10 @@ var config = { mustUseProp: no, /** - * List of asset types that a component can own. + * Exposed for legacy reasons */ - _assetTypes: [ - 'component', - 'directive', - 'filter' - ], - - /** - * List of lifecycle hooks. - */ - _lifecycleHooks: [ - 'beforeCreate', - 'created', - 'beforeMount', - 'mounted', - 'beforeUpdate', - 'updated', - 'beforeDestroy', - 'destroyed', - 'activated', - 'deactivated' - ], - - /** - * Max circular updates allowed in a scheduler flush cycle. - */ - _maxUpdateCount: 100 -}; + _lifecycleHooks: LIFECYCLE_HOOKS +}); /* */ @@ -389,6 +409,113 @@ function parsePath (path) { } } +var warn = noop; +var tip = noop; +var formatComponentName; + +if (process.env.NODE_ENV !== 'production') { + var hasConsole = typeof console !== 'undefined'; + var classifyRE = /(?:^|[-_])(\w)/g; + var classify = function (str) { return str + .replace(classifyRE, function (c) { return c.toUpperCase(); }) + .replace(/[-_]/g, ''); }; + + warn = function (msg, vm) { + if (hasConsole && (!config.silent)) { + console.error("[Vue warn]: " + msg + ( + vm ? generateComponentTrace(vm) : '' + )); + } + }; + + tip = function (msg, vm) { + if (hasConsole && (!config.silent)) { + console.warn("[Vue tip]: " + msg + ( + vm ? generateComponentTrace(vm) : '' + )); + } + }; + + formatComponentName = function (vm, includeFile) { + 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; + if (!name && file) { + var match = file.match(/([^/\\]+)\.vue$/); + name = match && match[1]; + } + + return ( + (name ? ("<" + (classify(name)) + ">") : "") + + (file && includeFile !== false ? (" at " + file) : '') + ) + }; + + var repeat = function (str, n) { + var res = ''; + while (n) { + if (n % 2 === 1) { res += str; } + if (n > 1) { str += str; } + n >>= 1; + } + return res + }; + + var generateComponentTrace = function (vm) { + if (vm._isVue && vm.$parent) { + var tree = []; + var currentRecursiveSequence = 0; + while (vm) { + if (tree.length > 0) { + var last = tree[tree.length - 1]; + if (last.constructor === vm.constructor) { + currentRecursiveSequence++; + vm = vm.$parent; + continue + } else if (currentRecursiveSequence > 0) { + tree[tree.length - 1] = [last, currentRecursiveSequence]; + currentRecursiveSequence = 0; + } + } + tree.push(vm); + vm = vm.$parent; + } + return '\n\nfound in\n\n' + tree + .map(function (vm, i) { return ("" + (i === 0 ? '---> ' : repeat(' ', 5 + i * 2)) + (Array.isArray(vm) + ? ((formatComponentName(vm[0])) + "... (" + (vm[1]) + " recursive calls)") + : formatComponentName(vm))); }) + .join('\n') + } else { + return ("\n\n(found in " + (formatComponentName(vm)) + ")") + } + }; +} + +function handleError (err, vm, info) { + if (config.errorHandler) { + config.errorHandler.call(null, err, vm, info); + } else { + if (process.env.NODE_ENV !== 'production') { + warn(("Error in " + info + ": \"" + (err.toString()) + "\""), vm); + } + /* istanbul ignore else */ + if (inBrowser && typeof console !== 'undefined') { + console.error(err); + } else { + throw err + } + } +} + /* */ /* globals MutationObserver */ @@ -405,6 +532,20 @@ var isAndroid = UA && UA.indexOf('android') > 0; var isIOS = UA && /iphone|ipad|ipod|ios/.test(UA); var isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge; +var supportsPassive = false; +if (inBrowser) { + try { + var opts = {}; + Object.defineProperty(opts, 'passive', ({ + get: function get () { + /* istanbul ignore next */ + supportsPassive = true; + } + } )); // https://github.com/facebook/flow/issues/285 + window.addEventListener('test-passive', null, opts); + } catch (e) {} +} + // this needs to be lazy-evaled because vue may be required before // vue-server-renderer can set VUE_ENV var _isServer; @@ -427,7 +568,7 @@ var devtools = inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__; /* istanbul ignore next */ function isNative (Ctor) { - return /native code/.test(Ctor.toString()) + return typeof Ctor === 'function' && /native code/.test(Ctor.toString()) } var hasSymbol = @@ -498,15 +639,22 @@ var nextTick = (function () { return function queueNextTick (cb, ctx) { var _resolve; callbacks.push(function () { - if (cb) { cb.call(ctx); } - if (_resolve) { _resolve(ctx); } + if (cb) { + try { + cb.call(ctx); + } catch (e) { + handleError(e, ctx, 'nextTick'); + } + } else if (_resolve) { + _resolve(ctx); + } }); if (!pending) { pending = true; timerFunc(); } if (!cb && typeof Promise !== 'undefined') { - return new Promise(function (resolve) { + return new Promise(function (resolve, reject) { _resolve = resolve; }) } @@ -538,65 +686,6 @@ if (typeof Set !== 'undefined' && isNative(Set)) { }()); } -var warn = noop; -var tip = noop; -var formatComponentName; - -if (process.env.NODE_ENV !== 'production') { - var hasConsole = typeof console !== 'undefined'; - var classifyRE = /(?:^|[-_])(\w)/g; - var classify = function (str) { return str - .replace(classifyRE, function (c) { return c.toUpperCase(); }) - .replace(/[-_]/g, ''); }; - - warn = function (msg, vm) { - if (hasConsole && (!config.silent)) { - console.error("[Vue warn]: " + msg + " " + ( - vm ? formatLocation(formatComponentName(vm)) : '' - )); - } - }; - - tip = function (msg, vm) { - if (hasConsole && (!config.silent)) { - console.warn("[Vue tip]: " + msg + " " + ( - vm ? formatLocation(formatComponentName(vm)) : '' - )); - } - }; - - formatComponentName = function (vm, includeFile) { - 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; - if (!name && file) { - var match = file.match(/([^/\\]+)\.vue$/); - name = match && match[1]; - } - - return ( - (name ? ("<" + (classify(name)) + ">") : "") + - (file && includeFile !== false ? (" at " + file) : '') - ) - }; - - var formatLocation = function (str) { - if (str === "") { - str += " - use the \"name\" option for better debugging messages."; - } - return ("\n(found in " + str + ")") - }; -} - /* */ @@ -1050,7 +1139,7 @@ function mergeHook ( : parentVal } -config._lifecycleHooks.forEach(function (hook) { +LIFECYCLE_HOOKS.forEach(function (hook) { strats[hook] = mergeHook; }); @@ -1068,7 +1157,7 @@ function mergeAssets (parentVal, childVal) { : res } -config._assetTypes.forEach(function (type) { +ASSET_TYPES.forEach(function (type) { strats[type + 's'] = mergeAssets; }); @@ -1194,21 +1283,20 @@ function mergeOptions ( if (process.env.NODE_ENV !== 'production') { checkComponents(child); } + + if (typeof child === 'function') { + child = child.options; + } + normalizeProps(child); normalizeDirectives(child); var extendsFrom = child.extends; if (extendsFrom) { - parent = typeof extendsFrom === 'function' - ? mergeOptions(parent, extendsFrom.options, vm) - : mergeOptions(parent, extendsFrom, vm); + parent = mergeOptions(parent, extendsFrom, vm); } if (child.mixins) { for (var i = 0, l = child.mixins.length; i < l; i++) { - var mixin = child.mixins[i]; - if (mixin.prototype instanceof Vue$2) { - mixin = mixin.options; - } - parent = mergeOptions(parent, mixin, vm); + parent = mergeOptions(parent, child.mixins[i], vm); } } var options = {}; @@ -1381,20 +1469,13 @@ function assertProp ( } } -/** - * Assert the type of a value - */ +var simpleCheckRE = /^(String|Number|Boolean|Function|Symbol)$/; + function assertType (value, type) { var valid; var expectedType = getType(type); - if (expectedType === 'String') { - valid = typeof value === (expectedType = 'string'); - } else if (expectedType === 'Number') { - valid = typeof value === (expectedType = 'number'); - } else if (expectedType === 'Boolean') { - valid = typeof value === (expectedType = 'boolean'); - } else if (expectedType === 'Function') { - valid = typeof value === (expectedType = 'function'); + if (simpleCheckRE.test(expectedType)) { + valid = typeof value === expectedType.toLowerCase(); } else if (expectedType === 'Object') { valid = isPlainObject(value); } else if (expectedType === 'Array') { @@ -1415,7 +1496,7 @@ function assertType (value, type) { */ function getType (fn) { var match = fn && fn.toString().match(/^\s*function (\w+)/); - return match && match[1] + return match ? match[1] : '' } function isType (type, fn) { @@ -1431,22 +1512,6 @@ function isType (type, fn) { return false } -function handleError (err, vm, info) { - if (config.errorHandler) { - config.errorHandler.call(null, err, vm, info); - } else { - if (process.env.NODE_ENV !== 'production') { - warn(("Error in " + info + ":"), vm); - } - /* istanbul ignore else */ - if (inBrowser && typeof console !== 'undefined') { - console.error(err); - } else { - throw err - } - } -} - /* not type checking this file because flow doesn't play well with Proxy */ var initProxy; @@ -1629,6 +1694,8 @@ function cloneVNodes (vnodes) { /* */ var normalizeEvent = cached(function (name) { + var passive = name.charAt(0) === '&'; + name = passive ? name.slice(1) : name; var once$$1 = name.charAt(0) === '~'; // Prefixed last, checked first name = once$$1 ? name.slice(1) : name; var capture = name.charAt(0) === '!'; @@ -1636,7 +1703,8 @@ var normalizeEvent = cached(function (name) { return { name: name, once: once$$1, - capture: capture + capture: capture, + passive: passive } }); @@ -1670,23 +1738,23 @@ function updateListeners ( cur = on[name]; old = oldOn[name]; event = normalizeEvent(name); - if (!cur) { + if (isUndef(cur)) { process.env.NODE_ENV !== 'production' && warn( "Invalid handler for event \"" + (event.name) + "\": got " + String(cur), vm ); - } else if (!old) { - if (!cur.fns) { + } else if (isUndef(old)) { + if (isUndef(cur.fns)) { cur = on[name] = createFnInvoker(cur); } - add(event.name, cur, event.once, event.capture); + add(event.name, cur, event.once, event.capture, event.passive); } else if (cur !== old) { old.fns = cur; on[name] = old; } } for (name in oldOn) { - if (!on[name]) { + if (isUndef(on[name])) { event = normalizeEvent(name); remove$$1(event.name, oldOn[name], event.capture); } @@ -1706,12 +1774,12 @@ function mergeVNodeHook (def, hookKey, hook) { remove(invoker.fns, wrappedHook); } - if (!oldHook) { + if (isUndef(oldHook)) { // no existing hook invoker = createFnInvoker([wrappedHook]); } else { /* istanbul ignore if */ - if (oldHook.fns && oldHook.merged) { + if (isDef(oldHook.fns) && isTrue(oldHook.merged)) { // already a merged invoker invoker = oldHook; invoker.fns.push(wrappedHook); @@ -1727,6 +1795,74 @@ function mergeVNodeHook (def, hookKey, hook) { /* */ +function extractPropsFromVNodeData ( + data, + Ctor, + tag +) { + // we are only extracting raw values here. + // validation and default values are handled in the child + // component itself. + var propOptions = Ctor.options.props; + if (isUndef(propOptions)) { + return + } + var res = {}; + var attrs = data.attrs; + var props = data.props; + if (isDef(attrs) || isDef(props)) { + for (var key in propOptions) { + var altKey = hyphenate(key); + if (process.env.NODE_ENV !== 'production') { + var keyInLowerCase = key.toLowerCase(); + if ( + key !== keyInLowerCase && + attrs && hasOwn(attrs, keyInLowerCase) + ) { + tip( + "Prop \"" + keyInLowerCase + "\" is passed to component " + + (formatComponentName(tag || Ctor)) + ", but the declared prop name is" + + " \"" + key + "\". " + + "Note that HTML attributes are case-insensitive and camelCased " + + "props need to use their kebab-case equivalents when using in-DOM " + + "templates. You should probably use \"" + altKey + "\" instead of \"" + key + "\"." + ); + } + } + checkProp(res, props, key, altKey, true) || + checkProp(res, attrs, key, altKey, false); + } + } + return res +} + +function checkProp ( + res, + hash, + key, + altKey, + preserve +) { + if (isDef(hash)) { + if (hasOwn(hash, key)) { + res[key] = hash[key]; + if (!preserve) { + delete hash[key]; + } + return true + } else if (hasOwn(hash, altKey)) { + res[key] = hash[altKey]; + if (!preserve) { + delete hash[altKey]; + } + return true + } + } + return false +} + +/* */ + // The template compiler attempts to minimize the need for normalization by // statically analyzing the template at compile time. // @@ -1765,25 +1901,25 @@ function normalizeArrayChildren (children, nestedIndex) { var i, c, last; for (i = 0; i < children.length; i++) { c = children[i]; - if (c == null || typeof c === 'boolean') { continue } + if (isUndef(c) || typeof c === 'boolean') { continue } last = res[res.length - 1]; // nested if (Array.isArray(c)) { res.push.apply(res, normalizeArrayChildren(c, ((nestedIndex || '') + "_" + i))); } else if (isPrimitive(c)) { - if (last && last.text) { - last.text += String(c); + if (isDef(last) && isDef(last.text)) { + (last).text += String(c); } else if (c !== '') { // convert primitive to vnode res.push(createTextVNode(c)); } } else { - if (c.text && last && last.text) { + if (isDef(c.text) && isDef(last) && isDef(last.text)) { res[res.length - 1] = createTextVNode(last.text + c.text); } else { // default key for nested array children (likely generated by v-for) - if (c.tag && c.key == null && nestedIndex != null) { - c.key = "__vlist" + nestedIndex + "_" + i + "__"; + if (isDef(c.tag) && isUndef(c.key) && isDef(nestedIndex)) { + c.key = "__vlist" + ((nestedIndex)) + "_" + i + "__"; } res.push(c); } @@ -1794,10 +1930,127 @@ function normalizeArrayChildren (children, nestedIndex) { /* */ -function getFirstComponentChild (children) { - return children && children.filter(function (c) { return c && c.componentOptions; })[0] +function ensureCtor (comp, base) { + return isObject(comp) + ? base.extend(comp) + : comp } +function resolveAsyncComponent ( + factory, + baseCtor, + context +) { + if (isTrue(factory.error) && isDef(factory.errorComp)) { + return factory.errorComp + } + + if (isDef(factory.resolved)) { + return factory.resolved + } + + if (isTrue(factory.loading) && isDef(factory.loadingComp)) { + return factory.loadingComp + } + + if (isDef(factory.contexts)) { + // already pending + factory.contexts.push(context); + } else { + var contexts = factory.contexts = [context]; + var sync = true; + + var forceRender = function () { + for (var i = 0, l = contexts.length; i < l; i++) { + contexts[i].$forceUpdate(); + } + }; + + var resolve = once(function (res) { + // cache resolved + factory.resolved = ensureCtor(res, baseCtor); + // invoke callbacks only if this is not a synchronous resolve + // (async resolves are shimmed as synchronous during SSR) + if (!sync) { + forceRender(); + } + }); + + var reject = once(function (reason) { + process.env.NODE_ENV !== 'production' && warn( + "Failed to resolve async component: " + (String(factory)) + + (reason ? ("\nReason: " + reason) : '') + ); + if (isDef(factory.errorComp)) { + factory.error = true; + forceRender(); + } + }); + + var res = factory(resolve, reject); + + if (isObject(res)) { + if (typeof res.then === 'function') { + // () => Promise + if (isUndef(factory.resolved)) { + res.then(resolve, reject); + } + } else if (isDef(res.component) && typeof res.component.then === 'function') { + res.component.then(resolve, reject); + + if (isDef(res.error)) { + factory.errorComp = ensureCtor(res.error, baseCtor); + } + + if (isDef(res.loading)) { + factory.loadingComp = ensureCtor(res.loading, baseCtor); + if (res.delay === 0) { + factory.loading = true; + } else { + setTimeout(function () { + if (isUndef(factory.resolved) && isUndef(factory.error)) { + factory.loading = true; + forceRender(); + } + }, res.delay || 200); + } + } + + if (isDef(res.timeout)) { + setTimeout(function () { + reject( + process.env.NODE_ENV !== 'production' + ? ("timeout (" + (res.timeout) + "ms)") + : null + ); + }, res.timeout); + } + } + } + + sync = false; + // return in case resolved synchronously + return factory.loading + ? factory.loadingComp + : factory.resolved + } +} + +/* */ + +function getFirstComponentChild (children) { + if (Array.isArray(children)) { + for (var i = 0; i < children.length; i++) { + var c = children[i]; + if (isDef(c) && isDef(c.componentOptions)) { + return c + } + } + } +} + +/* */ + /* */ function initEvents (vm) { @@ -1943,13 +2196,13 @@ function resolveSlots ( return slots } var defaultSlot = []; - var name, child; for (var i = 0, l = children.length; i < l; i++) { - child = children[i]; + var child = children[i]; // named slots should only be respected if the vnode was rendered in the // same context. if ((child.context === context || child.functionalContext === context) && - child.data && (name = child.data.slot)) { + child.data && child.data.slot != null) { + var name = child.data.slot; var slot = (slots[name] || (slots[name] = [])); if (child.tag === 'template') { slot.push.apply(slot, child.children); @@ -2236,7 +2489,7 @@ function activateChildComponent (vm, direct) { } else if (vm._directInactive) { return } - if (vm._inactive || vm._inactive == null) { + if (vm._inactive || vm._inactive === null) { vm._inactive = false; for (var i = 0; i < vm.$children.length; i++) { activateChildComponent(vm.$children[i]); @@ -2280,7 +2533,10 @@ function callHook (vm, hook) { /* */ +var MAX_UPDATE_COUNT = 100; + var queue = []; +var activatedChildren = []; var has = {}; var circular = {}; var waiting = false; @@ -2291,7 +2547,7 @@ var index = 0; * Reset the scheduler's state. */ function resetSchedulerState () { - queue.length = 0; + queue.length = activatedChildren.length = 0; has = {}; if (process.env.NODE_ENV !== 'production') { circular = {}; @@ -2304,7 +2560,7 @@ function resetSchedulerState () { */ function flushSchedulerQueue () { flushing = true; - var watcher, id, vm; + var watcher, id; // Sort queue before flush. // This ensures that: @@ -2326,7 +2582,7 @@ function flushSchedulerQueue () { // in dev build, check and stop circular updates. if (process.env.NODE_ENV !== 'production' && has[id] != null) { circular[id] = (circular[id] || 0) + 1; - if (circular[id] > config._maxUpdateCount) { + if (circular[id] > MAX_UPDATE_COUNT) { warn( 'You may have an infinite update loop ' + ( watcher.user @@ -2340,19 +2596,15 @@ function flushSchedulerQueue () { } } - // reset scheduler before updated hook called - var oldQueue = queue.slice(); + // keep copies of post queues before resetting state + var activatedQueue = activatedChildren.slice(); + var updatedQueue = queue.slice(); + resetSchedulerState(); - // call updated hooks - index = oldQueue.length; - while (index--) { - watcher = oldQueue[index]; - vm = watcher.vm; - if (vm._watcher === watcher && vm._isMounted) { - callHook(vm, 'updated'); - } - } + // call component updated and activated hooks + callActivatedHooks(activatedQueue); + callUpdateHooks(updatedQueue); // devtool hook /* istanbul ignore if */ @@ -2361,6 +2613,35 @@ function flushSchedulerQueue () { } } +function callUpdateHooks (queue) { + var i = queue.length; + while (i--) { + var watcher = queue[i]; + var vm = watcher.vm; + if (vm._watcher === watcher && vm._isMounted) { + callHook(vm, 'updated'); + } + } +} + +/** + * Queue a kept-alive component that was activated during patch. + * The queue will be processed after the entire tree has been patched. + */ +function queueActivatedComponent (vm) { + // setting _inactive to false here so that a render function can + // rely on checking whether it's in an inactive tree (e.g. router-view) + vm._inactive = false; + activatedChildren.push(vm); +} + +function callActivatedHooks (queue) { + for (var i = 0; i < queue.length; i++) { + queue[i]._inactive = true; + activateChildComponent(queue[i], true /* true */); + } +} + /** * Push a watcher into the watcher queue. * Jobs with duplicate IDs will be skipped unless it's @@ -2664,7 +2945,11 @@ function initState (vm) { if (opts.watch) { initWatch(vm, opts.watch); } } -var isReservedProp = { key: 1, ref: 1, slot: 1 }; +var isReservedProp = { + key: 1, + ref: 1, + slot: 1 +}; function initProps (vm, propsOptions) { var propsData = vm.$options.propsData || {}; @@ -2680,7 +2965,7 @@ function initProps (vm, propsOptions) { var value = validateProp(key, propsOptions, propsData, vm); /* istanbul ignore else */ if (process.env.NODE_ENV !== 'production') { - if (isReservedProp[key]) { + if (isReservedProp[key] || config.isReservedAttr(key)) { warn( ("\"" + key + "\" is a reserved attribute and cannot be used as component prop."), vm @@ -2778,6 +3063,12 @@ function initComputed (vm, computed) { // at instantiation here. if (!(key in vm)) { defineComputed(vm, key, userDef); + } else if (process.env.NODE_ENV !== 'production') { + if (key in vm.$data) { + warn(("The computed property \"" + key + "\" is already defined in data."), vm); + } else if (vm.$options.props && key in vm.$options.props) { + warn(("The computed property \"" + key + "\" is already defined as a prop."), vm); + } } } } @@ -2907,6 +3198,113 @@ function stateMixin (Vue) { /* */ +function initProvide (vm) { + var provide = vm.$options.provide; + if (provide) { + vm._provided = typeof provide === 'function' + ? provide.call(vm) + : provide; + } +} + +function initInjections (vm) { + var result = resolveInject(vm.$options.inject, vm); + if (result) { + Object.keys(result).forEach(function (key) { + /* istanbul ignore else */ + if (process.env.NODE_ENV !== 'production') { + defineReactive$$1(vm, key, result[key], function () { + warn( + "Avoid mutating an injected value directly since the changes will be " + + "overwritten whenever the provided component re-renders. " + + "injection being mutated: \"" + key + "\"", + vm + ); + }); + } else { + defineReactive$$1(vm, key, result[key]); + } + }); + } +} + +function resolveInject (inject, vm) { + if (inject) { + // inject is :any because flow is not smart enough to figure out cached + // isArray here + var isArray = Array.isArray(inject); + var result = Object.create(null); + var keys = isArray + ? inject + : hasSymbol + ? Reflect.ownKeys(inject) + : Object.keys(inject); + + for (var i = 0; i < keys.length; i++) { + var key = keys[i]; + var provideKey = isArray ? key : inject[key]; + var source = vm; + while (source) { + if (source._provided && provideKey in source._provided) { + result[key] = source._provided[provideKey]; + break + } + source = source.$parent; + } + } + return result + } +} + +/* */ + +function createFunctionalComponent ( + Ctor, + propsData, + data, + context, + children +) { + var props = {}; + var propOptions = Ctor.options.props; + if (isDef(propOptions)) { + for (var key in propOptions) { + props[key] = validateProp(key, propOptions, propsData); + } + } else { + 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 || {}, + injections: resolveInject(Ctor.options.inject, context), + slots: function () { return resolveSlots(children, context); } + }); + if (vnode instanceof VNode) { + vnode.functionalContext = context; + if (data.slot) { + (vnode.data || (vnode.data = {})).slot = data.slot; + } + } + return vnode +} + +function mergeProps (to, from) { + for (var key in from) { + to[camelize(key)] = from[key]; + } +} + +/* */ + // hooks to be invoked on component VNodes during patch var componentVNodeHooks = { init: function init ( @@ -2943,21 +3341,33 @@ var componentVNodeHooks = { }, insert: function insert (vnode) { - if (!vnode.componentInstance._isMounted) { - vnode.componentInstance._isMounted = true; - callHook(vnode.componentInstance, 'mounted'); + var context = vnode.context; + var componentInstance = vnode.componentInstance; + if (!componentInstance._isMounted) { + componentInstance._isMounted = true; + callHook(componentInstance, 'mounted'); } if (vnode.data.keepAlive) { - activateChildComponent(vnode.componentInstance, true /* direct */); + if (context._isMounted) { + // vue-router#1212 + // During updates, a kept-alive component's child components may + // change, so directly walking the tree here may call activated hooks + // on incorrect children. Instead we push them into a queue which will + // be processed after the whole patch process ended. + queueActivatedComponent(componentInstance); + } else { + activateChildComponent(componentInstance, true /* direct */); + } } }, destroy: function destroy (vnode) { - if (!vnode.componentInstance._isDestroyed) { + var componentInstance = vnode.componentInstance; + if (!componentInstance._isDestroyed) { if (!vnode.data.keepAlive) { - vnode.componentInstance.$destroy(); + componentInstance.$destroy(); } else { - deactivateChildComponent(vnode.componentInstance, true /* direct */); + deactivateChildComponent(componentInstance, true /* direct */); } } } @@ -2972,15 +3382,19 @@ function createComponent ( children, tag ) { - if (!Ctor) { + if (isUndef(Ctor)) { return } var baseCtor = context.$options._base; + + // plain options object: turn it into a constructor if (isObject(Ctor)) { Ctor = baseCtor.extend(Ctor); } + // if at this stage it's not a constructor or an async component factory, + // reject. if (typeof Ctor !== 'function') { if (process.env.NODE_ENV !== 'production') { warn(("Invalid Component definition: " + (String(Ctor))), context); @@ -2989,20 +3403,12 @@ function createComponent ( } // async component - if (!Ctor.cid) { - if (Ctor.resolved) { - Ctor = Ctor.resolved; - } else { - Ctor = resolveAsyncComponent(Ctor, baseCtor, function () { - // it's ok to queue this on every render because - // $forceUpdate is buffered by the scheduler. - context.$forceUpdate(); - }); - if (!Ctor) { - // return nothing if this is indeed an async component - // wait for the callback to trigger parent update. - return - } + if (isUndef(Ctor.cid)) { + Ctor = resolveAsyncComponent(Ctor, baseCtor, context); + if (Ctor === undefined) { + // return nothing if this is indeed an async component + // wait for the callback to trigger parent update. + return } } @@ -3013,15 +3419,15 @@ function createComponent ( data = data || {}; // transform component v-model data into props & events - if (data.model) { + if (isDef(data.model)) { transformModel(Ctor.options, data); } // extract props - var propsData = extractProps(data, Ctor, tag); + var propsData = extractPropsFromVNodeData(data, Ctor, tag); // functional component - if (Ctor.options.functional) { + if (isTrue(Ctor.options.functional)) { return createFunctionalComponent(Ctor, propsData, data, context, children) } @@ -3031,7 +3437,7 @@ function createComponent ( // replace with listeners with .native modifier data.on = data.nativeOn; - if (Ctor.options.abstract) { + if (isTrue(Ctor.options.abstract)) { // abstract components do not keep anything // other than props & listeners data = {}; @@ -3050,40 +3456,6 @@ function createComponent ( return vnode } -function createFunctionalComponent ( - Ctor, - propsData, - data, - context, - children -) { - var props = {}; - var propOptions = Ctor.options.props; - if (propOptions) { - for (var key in propOptions) { - props[key] = validateProp(key, propOptions, propsData); - } - } - // 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, { - props: props, - data: data, - parent: context, - children: children, - slots: function () { return resolveSlots(children, context); } - }); - if (vnode instanceof VNode) { - vnode.functionalContext = context; - if (data.slot) { - (vnode.data || (vnode.data = {})).slot = data.slot; - } - } - return vnode -} - function createComponentInstanceForVnode ( vnode, // we know it's MountedComponentVNode but flow doesn't parent, // activeInstance in lifecycle state @@ -3104,125 +3476,13 @@ function createComponentInstanceForVnode ( }; // check inline-template render functions var inlineTemplate = vnode.data.inlineTemplate; - if (inlineTemplate) { + if (isDef(inlineTemplate)) { options.render = inlineTemplate.render; options.staticRenderFns = inlineTemplate.staticRenderFns; } return new vnodeComponentOptions.Ctor(options) } -function resolveAsyncComponent ( - factory, - baseCtor, - cb -) { - if (factory.requested) { - // pool callbacks - factory.pendingCallbacks.push(cb); - } else { - factory.requested = true; - var cbs = factory.pendingCallbacks = [cb]; - var sync = true; - - var resolve = function (res) { - if (isObject(res)) { - res = baseCtor.extend(res); - } - // cache resolved - factory.resolved = res; - // invoke callbacks only if this is not a synchronous resolve - // (async resolves are shimmed as synchronous during SSR) - if (!sync) { - for (var i = 0, l = cbs.length; i < l; i++) { - cbs[i](res); - } - } - }; - - var reject = function (reason) { - process.env.NODE_ENV !== 'production' && warn( - "Failed to resolve async component: " + (String(factory)) + - (reason ? ("\nReason: " + reason) : '') - ); - }; - - var res = factory(resolve, reject); - - // handle promise - if (res && typeof res.then === 'function' && !factory.resolved) { - res.then(resolve, reject); - } - - sync = false; - // return in case resolved synchronously - return factory.resolved - } -} - -function extractProps (data, Ctor, tag) { - // we are only extracting raw values here. - // validation and default values are handled in the child - // component itself. - var propOptions = Ctor.options.props; - if (!propOptions) { - return - } - var res = {}; - var attrs = data.attrs; - var props = data.props; - var domProps = data.domProps; - if (attrs || props || domProps) { - for (var key in propOptions) { - var altKey = hyphenate(key); - if (process.env.NODE_ENV !== 'production') { - var keyInLowerCase = key.toLowerCase(); - if ( - key !== keyInLowerCase && - attrs && attrs.hasOwnProperty(keyInLowerCase) - ) { - tip( - "Prop \"" + keyInLowerCase + "\" is passed to component " + - (formatComponentName(tag || Ctor)) + ", but the declared prop name is" + - " \"" + key + "\". " + - "Note that HTML attributes are case-insensitive and camelCased " + - "props need to use their kebab-case equivalents when using in-DOM " + - "templates. You should probably use \"" + altKey + "\" instead of \"" + key + "\"." - ); - } - } - checkProp(res, props, key, altKey, true) || - checkProp(res, attrs, key, altKey) || - checkProp(res, domProps, key, altKey); - } - } - return res -} - -function checkProp ( - res, - hash, - key, - altKey, - preserve -) { - if (hash) { - if (hasOwn(hash, key)) { - res[key] = hash[key]; - if (!preserve) { - delete hash[key]; - } - return true - } else if (hasOwn(hash, altKey)) { - res[key] = hash[altKey]; - if (!preserve) { - delete hash[altKey]; - } - return true - } - } - return false -} - function mergeHooks (data) { if (!data.hook) { data.hook = {}; @@ -3248,7 +3508,7 @@ function transformModel (options, data) { var prop = (options.model && options.model.prop) || 'value'; var event = (options.model && options.model.event) || 'input';(data.props || (data.props = {}))[prop] = data.model.value; var on = data.on || (data.on = {}); - if (on[event]) { + if (isDef(on[event])) { on[event] = [data.model.callback].concat(on[event]); } else { on[event] = data.model.callback; @@ -3275,7 +3535,9 @@ function createElement ( children = data; data = undefined; } - if (alwaysNormalize) { normalizationType = ALWAYS_NORMALIZE; } + if (isTrue(alwaysNormalize)) { + normalizationType = ALWAYS_NORMALIZE; + } return _createElement(context, tag, data, children, normalizationType) } @@ -3286,7 +3548,7 @@ function _createElement ( children, normalizationType ) { - if (data && data.__ob__) { + if (isDef(data) && isDef((data).__ob__)) { process.env.NODE_ENV !== 'production' && warn( "Avoid using observed data object as vnode data: " + (JSON.stringify(data)) + "\n" + 'Always create fresh vnode data objects in each render!', @@ -3320,7 +3582,7 @@ function _createElement ( config.parsePlatformTagName(tag), data, children, undefined, undefined, context ); - } else if ((Ctor = resolveAsset(context.$options, 'components', tag))) { + } else if (isDef(Ctor = resolveAsset(context.$options, 'components', tag))) { // component vnode = createComponent(Ctor, data, context, children, tag); } else { @@ -3336,7 +3598,7 @@ function _createElement ( // direct component options / constructor vnode = createComponent(tag, data, context, children); } - if (vnode) { + if (vnode !== undefined) { if (ns) { applyNS(vnode, ns); } return vnode } else { @@ -3350,10 +3612,10 @@ function applyNS (vnode, ns) { // use default namespace inside foreignObject return } - if (vnode.children) { + if (Array.isArray(vnode.children)) { for (var i = 0, l = vnode.children.length; i < l; i++) { var child = vnode.children[i]; - if (child.tag && !child.ns) { + if (isDef(child.tag) && isUndef(child.ns)) { applyNS(child, ns); } } @@ -3553,10 +3815,9 @@ function markStaticNode (node, key, isOnce) { /* */ function initRender (vm) { - vm.$vnode = null; // the placeholder node in parent tree vm._vnode = null; // the root of the child tree vm._staticTrees = null; - var parentVnode = vm.$options._parentVnode; + var parentVnode = vm.$vnode = vm.$options._parentVnode; // the placeholder node in parent tree var renderContext = parentVnode && parentVnode.context; vm.$slots = resolveSlots(vm.$options._renderChildren, renderContext); vm.$scopedSlots = emptyObject; @@ -3651,58 +3912,6 @@ function renderMixin (Vue) { /* */ -function initProvide (vm) { - var provide = vm.$options.provide; - if (provide) { - vm._provided = typeof provide === 'function' - ? provide.call(vm) - : provide; - } -} - -function initInjections (vm) { - var inject = vm.$options.inject; - if (inject) { - // inject is :any because flow is not smart enough to figure out cached - // isArray here - var isArray = Array.isArray(inject); - var keys = isArray - ? inject - : hasSymbol - ? Reflect.ownKeys(inject) - : Object.keys(inject); - - var loop = function ( i ) { - var key = keys[i]; - var provideKey = isArray ? key : inject[key]; - var source = vm; - while (source) { - if (source._provided && provideKey in source._provided) { - /* istanbul ignore else */ - if (process.env.NODE_ENV !== 'production') { - defineReactive$$1(vm, key, source._provided[provideKey], function () { - warn( - "Avoid mutating an injected value directly since the changes will be " + - "overwritten whenever the provided component re-renders. " + - "injection being mutated: \"" + key + "\"", - vm - ); - }); - } else { - defineReactive$$1(vm, key, source._provided[provideKey]); - } - break - } - source = source.$parent; - } - }; - - for (var i = 0; i < keys.length; i++) loop( i ); - } -} - -/* */ - var uid = 0; function initMixin (Vue) { @@ -3808,24 +4017,27 @@ function resolveConstructorOptions (Ctor) { function resolveModifiedOptions (Ctor) { var modified; var latest = Ctor.options; + var extended = Ctor.extendOptions; var sealed = Ctor.sealedOptions; for (var key in latest) { if (latest[key] !== sealed[key]) { if (!modified) { modified = {}; } - modified[key] = dedupe(latest[key], sealed[key]); + modified[key] = dedupe(latest[key], extended[key], sealed[key]); } } return modified } -function dedupe (latest, sealed) { +function dedupe (latest, extended, sealed) { // compare latest and sealed to ensure lifecycle hooks won't be duplicated // between merges if (Array.isArray(latest)) { var res = []; sealed = Array.isArray(sealed) ? sealed : [sealed]; + extended = Array.isArray(extended) ? extended : [extended]; for (var i = 0; i < latest.length; i++) { - if (sealed.indexOf(latest[i]) < 0) { + // push original options and not sealed options to exclude duplicated options + if (extended.indexOf(latest[i]) >= 0 || sealed.indexOf(latest[i]) < 0) { res.push(latest[i]); } } @@ -3835,19 +4047,19 @@ function dedupe (latest, sealed) { } } -function Vue$2 (options) { +function Vue$3 (options) { if (process.env.NODE_ENV !== 'production' && - !(this instanceof Vue$2)) { + !(this instanceof Vue$3)) { warn('Vue is a constructor and should be called with the `new` keyword'); } this._init(options); } -initMixin(Vue$2); -stateMixin(Vue$2); -eventsMixin(Vue$2); -lifecycleMixin(Vue$2); -renderMixin(Vue$2); +initMixin(Vue$3); +stateMixin(Vue$3); +eventsMixin(Vue$3); +lifecycleMixin(Vue$3); +renderMixin(Vue$3); /* */ @@ -3941,7 +4153,7 @@ function initExtend (Vue) { // create asset registers, so extended classes // can have their private assets too. - config._assetTypes.forEach(function (type) { + ASSET_TYPES.forEach(function (type) { Sub[type] = Super[type]; }); // enable recursive self-lookup @@ -3982,7 +4194,7 @@ function initAssetRegisters (Vue) { /** * Create asset registration methods. */ - config._assetTypes.forEach(function (type) { + ASSET_TYPES.forEach(function (type) { Vue[type] = function ( id, definition @@ -4024,20 +4236,22 @@ function getComponentName (opts) { function matches (pattern, name) { if (typeof pattern === 'string') { return pattern.split(',').indexOf(name) > -1 - } else if (pattern instanceof RegExp) { + } else if (isRegExp(pattern)) { return pattern.test(name) } /* istanbul ignore next */ return false } -function pruneCache (cache, filter) { +function pruneCache (cache, current, filter) { for (var key in cache) { var cachedNode = cache[key]; if (cachedNode) { var name = getComponentName(cachedNode.componentOptions); if (name && !filter(name)) { - pruneCacheEntry(cachedNode); + if (cachedNode !== current) { + pruneCacheEntry(cachedNode); + } cache[key] = null; } } @@ -4046,9 +4260,6 @@ function pruneCache (cache, filter) { function pruneCacheEntry (vnode) { if (vnode) { - if (!vnode.componentInstance._inactive) { - callHook(vnode.componentInstance, 'deactivated'); - } vnode.componentInstance.$destroy(); } } @@ -4076,10 +4287,10 @@ var KeepAlive = { watch: { include: function include (val) { - pruneCache(this.cache, function (name) { return matches(val, name); }); + pruneCache(this.cache, this._vnode, function (name) { return matches(val, name); }); }, exclude: function exclude (val) { - pruneCache(this.cache, function (name) { return !matches(val, name); }); + pruneCache(this.cache, this._vnode, function (name) { return !matches(val, name); }); } }, @@ -4145,7 +4356,7 @@ function initGlobalAPI (Vue) { Vue.nextTick = nextTick; Vue.options = Object.create(null); - config._assetTypes.forEach(function (type) { + ASSET_TYPES.forEach(function (type) { Vue.options[type + 's'] = Object.create(null); }); @@ -4161,16 +4372,20 @@ function initGlobalAPI (Vue) { initAssetRegisters(Vue); } -initGlobalAPI(Vue$2); +initGlobalAPI(Vue$3); -Object.defineProperty(Vue$2.prototype, '$isServer', { +Object.defineProperty(Vue$3.prototype, '$isServer', { get: isServerRendering }); -Vue$2.version = '2.2.6'; +Vue$3.version = '2.3.0-beta.1'; /* */ +// these are reserved for web because they are directly compiled away +// during template compilation +var isReservedAttr = makeMap('style,class'); + // attributes that should be using props for binding var acceptValue = makeMap('input,textarea,option,select'); var mustUseProp = function (tag, type, attr) { @@ -4213,13 +4428,13 @@ function genClassForVnode (vnode) { var data = vnode.data; var parentNode = vnode; var childNode = vnode; - while (childNode.componentInstance) { + while (isDef(childNode.componentInstance)) { childNode = childNode.componentInstance._vnode; if (childNode.data) { data = mergeClassData(childNode.data, data); } } - while ((parentNode = parentNode.parent)) { + while (isDef(parentNode = parentNode.parent)) { if (parentNode.data) { data = mergeClassData(data, parentNode.data); } @@ -4230,7 +4445,7 @@ function genClassForVnode (vnode) { function mergeClassData (child, parent) { return { staticClass: concat(child.staticClass, parent.staticClass), - class: child.class + class: isDef(child.class) ? [child.class, parent.class] : parent.class } @@ -4239,7 +4454,7 @@ function mergeClassData (child, parent) { function genClassFromData (data) { var dynamicClass = data.class; var staticClass = data.staticClass; - if (staticClass || dynamicClass) { + if (isDef(staticClass) || isDef(dynamicClass)) { return concat(staticClass, stringifyClass(dynamicClass)) } /* istanbul ignore next */ @@ -4251,18 +4466,18 @@ function concat (a, b) { } function stringifyClass (value) { - var res = ''; - if (!value) { - return res + if (isUndef(value)) { + return '' } if (typeof value === 'string') { return value } + var res = ''; if (Array.isArray(value)) { var stringified; for (var i = 0, l = value.length; i < l; i++) { - if (value[i]) { - if ((stringified = stringifyClass(value[i]))) { + if (isDef(value[i])) { + if (isDef(stringified = stringifyClass(value[i])) && stringified !== '') { res += stringified + ' '; } } @@ -4507,18 +4722,6 @@ var emptyNode = new VNode('', {}, []); var hooks = ['create', 'activate', 'update', 'remove', 'destroy']; -function isUndef (v) { - return v === undefined || v === null -} - -function isDef (v) { - return v !== undefined && v !== null -} - -function isTrue (v) { - return v === true -} - function sameVnode (a, b) { return ( a.key === b.key && @@ -4705,7 +4908,9 @@ function createPatchFunction (backend) { function insert (parent, elm, ref) { if (isDef(parent)) { if (isDef(ref)) { - nodeOps.insertBefore(parent, elm, ref); + if (ref.parentNode === parent) { + nodeOps.insertBefore(parent, elm, ref); + } } else { nodeOps.appendChild(parent, elm); } @@ -4796,6 +5001,7 @@ function createPatchFunction (backend) { function removeAndInvokeRemoveHook (vnode, rm) { if (isDef(rm) || isDef(vnode.data)) { + var i; var listeners = cbs.remove.length + 1; if (isDef(rm)) { // we have a recursively passed down rm callback @@ -5057,8 +5263,8 @@ function createPatchFunction (backend) { // mounting to a real element // check if this is server-rendered content and if we can perform // a successful hydration. - if (oldVnode.nodeType === 1 && oldVnode.hasAttribute('server-rendered')) { - oldVnode.removeAttribute('server-rendered'); + if (oldVnode.nodeType === 1 && oldVnode.hasAttribute(SSR_ATTR)) { + oldVnode.removeAttribute(SSR_ATTR); hydrating = true; } if (isTrue(hydrating)) { @@ -5225,7 +5431,11 @@ function getRawDirName (dir) { function callHook$1 (dir, hook, vnode, oldVnode, isDestroy) { var fn = dir.def && dir.def[hook]; if (fn) { - fn(vnode.elm, dir, vnode, oldVnode, isDestroy); + try { + fn(vnode.elm, dir, vnode, oldVnode, isDestroy); + } catch (e) { + handleError(e, vnode.context, ("directive " + (dir.name) + " " + hook + " hook")); + } } } @@ -5237,7 +5447,7 @@ var baseModules = [ /* */ function updateAttrs (oldVnode, vnode) { - if (!oldVnode.data.attrs && !vnode.data.attrs) { + if (isUndef(oldVnode.data.attrs) && isUndef(vnode.data.attrs)) { return } var key, cur, old; @@ -5245,7 +5455,7 @@ function updateAttrs (oldVnode, vnode) { var oldAttrs = oldVnode.data.attrs || {}; var attrs = vnode.data.attrs || {}; // clone observed objects, as the user probably wants to mutate it - if (attrs.__ob__) { + if (isDef(attrs.__ob__)) { attrs = vnode.data.attrs = extend({}, attrs); } @@ -5262,7 +5472,7 @@ function updateAttrs (oldVnode, vnode) { setAttr(elm, 'value', attrs.value); } for (key in oldAttrs) { - if (attrs[key] == null) { + if (isUndef(attrs[key])) { if (isXlink(key)) { elm.removeAttributeNS(xlinkNS, getXlinkProp(key)); } else if (!isEnumeratedAttr(key)) { @@ -5309,8 +5519,15 @@ function updateClass (oldVnode, vnode) { var el = vnode.elm; var data = vnode.data; var oldData = oldVnode.data; - if (!data.staticClass && !data.class && - (!oldData || (!oldData.staticClass && !oldData.class))) { + if ( + isUndef(data.staticClass) && + isUndef(data.class) && ( + isUndef(oldData) || ( + isUndef(oldData.staticClass) && + isUndef(oldData.class) + ) + ) + ) { return } @@ -5318,7 +5535,7 @@ function updateClass (oldVnode, vnode) { // handle transition classes var transitionClass = el._transitionClasses; - if (transitionClass) { + if (isDef(transitionClass)) { cls = concat(cls, stringifyClass(transitionClass)); } @@ -5399,13 +5616,13 @@ var CHECKBOX_RADIO_TOKEN = '__c'; function normalizeEvents (on) { var event; /* istanbul ignore if */ - if (on[RANGE_TOKEN]) { + if (isDef(on[RANGE_TOKEN])) { // IE input[type=range] only supports `change` event event = isIE ? 'change' : 'input'; on[event] = [].concat(on[RANGE_TOKEN], on[event] || []); delete on[RANGE_TOKEN]; } - if (on[CHECKBOX_RADIO_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] || []); @@ -5418,10 +5635,11 @@ var target$1; function add$1 ( event, handler, - once, - capture + once$$1, + capture, + passive ) { - if (once) { + if (once$$1) { var oldHandler = handler; var _target = target$1; // save current target element in closure handler = function (ev) { @@ -5433,7 +5651,13 @@ function add$1 ( } }; } - target$1.addEventListener(event, handler, capture); + target$1.addEventListener( + event, + handler, + supportsPassive + ? { capture: capture, passive: passive } + : capture + ); } function remove$2 ( @@ -5446,7 +5670,7 @@ function remove$2 ( } function updateDOMListeners (oldVnode, vnode) { - if (!oldVnode.data.on && !vnode.data.on) { + if (isUndef(oldVnode.data.on) && isUndef(vnode.data.on)) { return } var on = vnode.data.on || {}; @@ -5464,7 +5688,7 @@ var events = { /* */ function updateDOMProps (oldVnode, vnode) { - if (!oldVnode.data.domProps && !vnode.data.domProps) { + if (isUndef(oldVnode.data.domProps) && isUndef(vnode.data.domProps)) { return } var key, cur; @@ -5472,12 +5696,12 @@ function updateDOMProps (oldVnode, vnode) { var oldProps = oldVnode.data.domProps || {}; var props = vnode.data.domProps || {}; // clone observed objects, as the user probably wants to mutate it - if (props.__ob__) { + if (isDef(props.__ob__)) { props = vnode.data.domProps = extend({}, props); } for (key in oldProps) { - if (props[key] == null) { + if (isUndef(props[key])) { elm[key] = ''; } } @@ -5529,10 +5753,10 @@ function isDirty (elm, checkVal) { function isInputChanged (elm, newVal) { var value = elm.value; var modifiers = elm._vModifiers; // injected by v-model runtime - if ((modifiers && modifiers.number) || elm.type === 'number') { + if ((isDef(modifiers) && modifiers.number) || elm.type === 'number') { return toNumber(value) !== toNumber(newVal) } - if (modifiers && modifiers.trim) { + if (isDef(modifiers) && modifiers.trim) { return value.trim() !== newVal.trim() } return value !== newVal @@ -5621,7 +5845,17 @@ var setProp = function (el, name, val) { } else if (importantRE.test(val)) { el.style.setProperty(name, val.replace(importantRE, ''), 'important'); } else { - el.style[normalize(name)] = val; + var normalizedName = normalize(name); + if (Array.isArray(val)) { + // Support values array created by autoprefixer, e.g. + // {display: ["-webkit-box", "-ms-flexbox", "flex"]} + // Set them one by one, and the browser will only set those it can recognize + for (var i = 0, len = val.length; i < len; i++) { + el.style[normalizedName] = val[i]; + } + } else { + el.style[normalizedName] = val; + } } }; @@ -5647,27 +5881,32 @@ function updateStyle (oldVnode, vnode) { var data = vnode.data; var oldData = oldVnode.data; - if (!data.staticStyle && !data.style && - !oldData.staticStyle && !oldData.style) { + if (isUndef(data.staticStyle) && isUndef(data.style) && + isUndef(oldData.staticStyle) && isUndef(oldData.style)) { return } var cur, name; var el = vnode.elm; - var oldStaticStyle = oldVnode.data.staticStyle; - var oldStyleBinding = oldVnode.data.style || {}; + var oldStaticStyle = oldData.staticStyle; + var oldStyleBinding = oldData.normalizedStyle || oldData.style || {}; // if static style exists, stylebinding already merged into it when doing normalizeStyleData var oldStyle = oldStaticStyle || oldStyleBinding; var style = normalizeStyleBinding(vnode.data.style) || {}; - vnode.data.style = style.__ob__ ? extend({}, style) : style; + // store normalized style under a different key for next diff + // make sure to clone it if it's reactive, since the user likley wants + // to mutate it. + vnode.data.normalizedStyle = isDef(style.__ob__) + ? extend({}, style) + : style; var newStyle = getStyle(vnode, true); for (name in oldStyle) { - if (newStyle[name] == null) { + if (isUndef(newStyle[name])) { setProp(el, name, ''); } } @@ -5918,38 +6157,39 @@ function enter (vnode, toggleDisplay) { var el = vnode.elm; // call leave callback now - if (el._leaveCb) { + if (isDef(el._leaveCb)) { el._leaveCb.cancelled = true; el._leaveCb(); } var data = resolveTransition(vnode.data.transition); - if (!data) { + if (isUndef(data)) { return } /* istanbul ignore if */ - if (el._enterCb || el.nodeType !== 1) { + if (isDef(el._enterCb) || el.nodeType !== 1) { return } - var css = data.css; - var type = data.type; - var enterClass = data.enterClass; - var enterToClass = data.enterToClass; - var enterActiveClass = data.enterActiveClass; - var appearClass = data.appearClass; - var appearToClass = data.appearToClass; - var appearActiveClass = data.appearActiveClass; - var beforeEnter = data.beforeEnter; - var enter = data.enter; - var afterEnter = data.afterEnter; - var enterCancelled = data.enterCancelled; - var beforeAppear = data.beforeAppear; - var appear = data.appear; - var afterAppear = data.afterAppear; - var appearCancelled = data.appearCancelled; - var duration = data.duration; + var ref = (data); + var css = ref.css; + var type = ref.type; + var enterClass = ref.enterClass; + var enterToClass = ref.enterToClass; + var enterActiveClass = ref.enterActiveClass; + var appearClass = ref.appearClass; + var appearToClass = ref.appearToClass; + var appearActiveClass = ref.appearActiveClass; + var beforeEnter = ref.beforeEnter; + var enter = ref.enter; + var afterEnter = ref.afterEnter; + var enterCancelled = ref.enterCancelled; + var beforeAppear = ref.beforeAppear; + var appear = ref.appear; + var afterAppear = ref.afterAppear; + var appearCancelled = ref.appearCancelled; + var duration = ref.duration; // activeInstance will always be the component managing this // transition. One edge case to check is when the is placed @@ -6066,32 +6306,33 @@ function leave (vnode, rm) { var el = vnode.elm; // call enter callback now - if (el._enterCb) { + if (isDef(el._enterCb)) { el._enterCb.cancelled = true; el._enterCb(); } var data = resolveTransition(vnode.data.transition); - if (!data) { + if (isUndef(data)) { return rm() } /* istanbul ignore if */ - if (el._leaveCb || el.nodeType !== 1) { + if (isDef(el._leaveCb) || el.nodeType !== 1) { return } - var css = data.css; - var type = data.type; - var leaveClass = data.leaveClass; - var leaveToClass = data.leaveToClass; - var leaveActiveClass = data.leaveActiveClass; - var beforeLeave = data.beforeLeave; - var leave = data.leave; - var afterLeave = data.afterLeave; - var leaveCancelled = data.leaveCancelled; - var delayLeave = data.delayLeave; - var duration = data.duration; + var ref = (data); + var css = ref.css; + var type = ref.type; + var leaveClass = ref.leaveClass; + var leaveToClass = ref.leaveToClass; + var leaveActiveClass = ref.leaveActiveClass; + var beforeLeave = ref.beforeLeave; + var leave = ref.leave; + var afterLeave = ref.afterLeave; + var leaveCancelled = ref.leaveCancelled; + var delayLeave = ref.delayLeave; + var duration = ref.duration; var expectsCSS = css !== false && !isIE9; var userWantsControl = getHookArgumentsLength(leave); @@ -6192,9 +6433,11 @@ function isValidDuration (val) { * - a plain function (.length) */ function getHookArgumentsLength (fn) { - if (!fn) { return false } + if (isUndef(fn)) { + return false + } var invokerFns = fn.fns; - if (invokerFns) { + if (isDef(invokerFns)) { // invoker return getHookArgumentsLength( Array.isArray(invokerFns) @@ -6207,7 +6450,7 @@ function getHookArgumentsLength (fn) { } function _enter (_, vnode) { - if (!vnode.data.show) { + if (vnode.data.show !== true) { enter(vnode); } } @@ -6217,7 +6460,7 @@ var transition = inBrowser ? { activate: _enter, remove: function remove$$1 (vnode, rm) { /* istanbul ignore else */ - if (!vnode.data.show) { + if (vnode.data.show !== true) { leave(vnode, rm); } else { rm(); @@ -6272,6 +6515,11 @@ var model$1 = { } else if (vnode.tag === 'textarea' || el.type === 'text' || el.type === 'password') { el._vModifiers = binding.modifiers; if (!binding.modifiers.lazy) { + // Safari < 10.2 & UIWebView doesn't fire compositionend when + // switching focus before confirming composition choice + // this also fixes the issue where some browsers e.g. iOS Chrome + // fires "change" instead of "input" on autocomplete. + el.addEventListener('change', onCompositionEnd); if (!isAndroid) { el.addEventListener('compositionstart', onCompositionStart); el.addEventListener('compositionend', onCompositionEnd); @@ -6483,9 +6731,11 @@ function extractTransitionData (comp) { } function placeholder (h, rawChild) { - return /\d-keep-alive$/.test(rawChild.tag) - ? h('keep-alive') - : null + if (/\d-keep-alive$/.test(rawChild.tag)) { + return h('keep-alive', { + props: rawChild.componentOptions.propsData + }) + } } function hasParentTransition (vnode) { @@ -6781,20 +7031,21 @@ var platformComponents = { /* */ // install platform specific utils -Vue$2.config.mustUseProp = mustUseProp; -Vue$2.config.isReservedTag = isReservedTag; -Vue$2.config.getTagNamespace = getTagNamespace; -Vue$2.config.isUnknownElement = isUnknownElement; +Vue$3.config.mustUseProp = mustUseProp; +Vue$3.config.isReservedTag = isReservedTag; +Vue$3.config.isReservedAttr = isReservedAttr; +Vue$3.config.getTagNamespace = getTagNamespace; +Vue$3.config.isUnknownElement = isUnknownElement; // install platform runtime directives & components -extend(Vue$2.options.directives, platformDirectives); -extend(Vue$2.options.components, platformComponents); +extend(Vue$3.options.directives, platformDirectives); +extend(Vue$3.options.components, platformComponents); // install platform patch function -Vue$2.prototype.__patch__ = inBrowser ? patch : noop; +Vue$3.prototype.__patch__ = inBrowser ? patch : noop; // public mount method -Vue$2.prototype.$mount = function ( +Vue$3.prototype.$mount = function ( el, hydrating ) { @@ -6807,7 +7058,7 @@ Vue$2.prototype.$mount = function ( setTimeout(function () { if (config.devtools) { if (devtools) { - devtools.emit('init', Vue$2); + devtools.emit('init', Vue$3); } else if (process.env.NODE_ENV !== 'production' && isChrome) { console[console.info ? 'info' : 'log']( 'Download the Vue Devtools extension for a better development experience:\n' + @@ -6826,4 +7077,6 @@ setTimeout(function () { } }, 0); -export default Vue$2; +/* */ + +export default Vue$3; diff --git a/dist/vue.runtime.js b/dist/vue.runtime.js index 453ab6e2..875ead6d 100644 --- a/dist/vue.runtime.js +++ b/dist/vue.runtime.js @@ -1,5 +1,5 @@ /*! - * Vue.js v2.2.6 + * Vue.js v2.3.0-beta.1 * (c) 2014-2017 Evan You * Released under the MIT License. */ @@ -11,6 +11,50 @@ /* */ +// these helpers produces better vm code in JS engines due to their +// explicitness and function inlining +function isUndef (v) { + return v === undefined || v === null +} + +function isDef (v) { + return v !== undefined && v !== null +} + +function isTrue (v) { + return v === true +} + +/** + * Check if value is primitive + */ +function isPrimitive (value) { + return typeof value === 'string' || typeof value === 'number' +} + +/** + * Quick object check - this is primarily used to tell + * Objects from primitive values when we know the value + * is a JSON-compliant type. + */ +function isObject (obj) { + return obj !== null && typeof obj === 'object' +} + +var toString = Object.prototype.toString; + +/** + * Strict object type check. Only returns true + * for plain JavaScript objects. + */ +function isPlainObject (obj) { + return toString.call(obj) === '[object Object]' +} + +function isRegExp (v) { + return toString.call(v) === '[object RegExp]' +} + /** * Convert a value to a string that is actually rendered. */ @@ -74,13 +118,6 @@ function hasOwn (obj, key) { return hasOwnProperty.call(obj, key) } -/** - * Check if value is primitive - */ -function isPrimitive (value) { - return typeof value === 'string' || typeof value === 'number' -} - /** * Create a cached version of a pure function. */ @@ -158,25 +195,6 @@ function extend (to, _from) { return to } -/** - * Quick object check - this is primarily used to tell - * Objects from primitive values when we know the value - * is a JSON-compliant type. - */ -function isObject (obj) { - return obj !== null && typeof obj === 'object' -} - -/** - * Strict object type check. Only returns true - * for plain JavaScript objects. - */ -var toString = Object.prototype.toString; -var OBJECT_STRING = '[object Object]'; -function isPlainObject (obj) { - return toString.call(obj) === OBJECT_STRING -} - /** * Merge an Array of Objects into a single Object. */ @@ -246,14 +264,35 @@ function once (fn) { return function () { if (!called) { called = true; - fn(); + fn.apply(this, arguments); } } } +var SSR_ATTR = 'data-server-rendered'; + +var ASSET_TYPES = [ + 'component', + 'directive', + 'filter' +]; + +var LIFECYCLE_HOOKS = [ + 'beforeCreate', + 'created', + 'beforeMount', + 'mounted', + 'beforeUpdate', + 'updated', + 'beforeDestroy', + 'destroyed', + 'activated', + 'deactivated' +]; + /* */ -var config = { +var config = ({ /** * Option merge strategies (used in core/util/options) */ @@ -300,6 +339,12 @@ var config = { */ isReservedTag: no, + /** + * Check if an attribute is reserved so that it cannot be used as a component + * prop. This is platform-dependent and may be overwritten. + */ + isReservedAttr: no, + /** * Check if a tag is an unknown element. * Platform-dependent. @@ -323,35 +368,10 @@ var config = { mustUseProp: no, /** - * List of asset types that a component can own. + * Exposed for legacy reasons */ - _assetTypes: [ - 'component', - 'directive', - 'filter' - ], - - /** - * List of lifecycle hooks. - */ - _lifecycleHooks: [ - 'beforeCreate', - 'created', - 'beforeMount', - 'mounted', - 'beforeUpdate', - 'updated', - 'beforeDestroy', - 'destroyed', - 'activated', - 'deactivated' - ], - - /** - * Max circular updates allowed in a scheduler flush cycle. - */ - _maxUpdateCount: 100 -}; + _lifecycleHooks: LIFECYCLE_HOOKS +}); /* */ @@ -395,6 +415,113 @@ function parsePath (path) { } } +var warn = noop; +var tip = noop; +var formatComponentName; + +{ + var hasConsole = typeof console !== 'undefined'; + var classifyRE = /(?:^|[-_])(\w)/g; + var classify = function (str) { return str + .replace(classifyRE, function (c) { return c.toUpperCase(); }) + .replace(/[-_]/g, ''); }; + + warn = function (msg, vm) { + if (hasConsole && (!config.silent)) { + console.error("[Vue warn]: " + msg + ( + vm ? generateComponentTrace(vm) : '' + )); + } + }; + + tip = function (msg, vm) { + if (hasConsole && (!config.silent)) { + console.warn("[Vue tip]: " + msg + ( + vm ? generateComponentTrace(vm) : '' + )); + } + }; + + formatComponentName = function (vm, includeFile) { + 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; + if (!name && file) { + var match = file.match(/([^/\\]+)\.vue$/); + name = match && match[1]; + } + + return ( + (name ? ("<" + (classify(name)) + ">") : "") + + (file && includeFile !== false ? (" at " + file) : '') + ) + }; + + var repeat = function (str, n) { + var res = ''; + while (n) { + if (n % 2 === 1) { res += str; } + if (n > 1) { str += str; } + n >>= 1; + } + return res + }; + + var generateComponentTrace = function (vm) { + if (vm._isVue && vm.$parent) { + var tree = []; + var currentRecursiveSequence = 0; + while (vm) { + if (tree.length > 0) { + var last = tree[tree.length - 1]; + if (last.constructor === vm.constructor) { + currentRecursiveSequence++; + vm = vm.$parent; + continue + } else if (currentRecursiveSequence > 0) { + tree[tree.length - 1] = [last, currentRecursiveSequence]; + currentRecursiveSequence = 0; + } + } + tree.push(vm); + vm = vm.$parent; + } + return '\n\nfound in\n\n' + tree + .map(function (vm, i) { return ("" + (i === 0 ? '---> ' : repeat(' ', 5 + i * 2)) + (Array.isArray(vm) + ? ((formatComponentName(vm[0])) + "... (" + (vm[1]) + " recursive calls)") + : formatComponentName(vm))); }) + .join('\n') + } else { + return ("\n\n(found in " + (formatComponentName(vm)) + ")") + } + }; +} + +function handleError (err, vm, info) { + if (config.errorHandler) { + config.errorHandler.call(null, err, vm, info); + } else { + { + warn(("Error in " + info + ": \"" + (err.toString()) + "\""), vm); + } + /* istanbul ignore else */ + if (inBrowser && typeof console !== 'undefined') { + console.error(err); + } else { + throw err + } + } +} + /* */ /* globals MutationObserver */ @@ -411,6 +538,20 @@ var isAndroid = UA && UA.indexOf('android') > 0; var isIOS = UA && /iphone|ipad|ipod|ios/.test(UA); var isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge; +var supportsPassive = false; +if (inBrowser) { + try { + var opts = {}; + Object.defineProperty(opts, 'passive', ({ + get: function get () { + /* istanbul ignore next */ + supportsPassive = true; + } + } )); // https://github.com/facebook/flow/issues/285 + window.addEventListener('test-passive', null, opts); + } catch (e) {} +} + // this needs to be lazy-evaled because vue may be required before // vue-server-renderer can set VUE_ENV var _isServer; @@ -433,7 +574,7 @@ var devtools = inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__; /* istanbul ignore next */ function isNative (Ctor) { - return /native code/.test(Ctor.toString()) + return typeof Ctor === 'function' && /native code/.test(Ctor.toString()) } var hasSymbol = @@ -504,15 +645,22 @@ var nextTick = (function () { return function queueNextTick (cb, ctx) { var _resolve; callbacks.push(function () { - if (cb) { cb.call(ctx); } - if (_resolve) { _resolve(ctx); } + if (cb) { + try { + cb.call(ctx); + } catch (e) { + handleError(e, ctx, 'nextTick'); + } + } else if (_resolve) { + _resolve(ctx); + } }); if (!pending) { pending = true; timerFunc(); } if (!cb && typeof Promise !== 'undefined') { - return new Promise(function (resolve) { + return new Promise(function (resolve, reject) { _resolve = resolve; }) } @@ -544,65 +692,6 @@ if (typeof Set !== 'undefined' && isNative(Set)) { }()); } -var warn = noop; -var tip = noop; -var formatComponentName; - -{ - var hasConsole = typeof console !== 'undefined'; - var classifyRE = /(?:^|[-_])(\w)/g; - var classify = function (str) { return str - .replace(classifyRE, function (c) { return c.toUpperCase(); }) - .replace(/[-_]/g, ''); }; - - warn = function (msg, vm) { - if (hasConsole && (!config.silent)) { - console.error("[Vue warn]: " + msg + " " + ( - vm ? formatLocation(formatComponentName(vm)) : '' - )); - } - }; - - tip = function (msg, vm) { - if (hasConsole && (!config.silent)) { - console.warn("[Vue tip]: " + msg + " " + ( - vm ? formatLocation(formatComponentName(vm)) : '' - )); - } - }; - - formatComponentName = function (vm, includeFile) { - 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; - if (!name && file) { - var match = file.match(/([^/\\]+)\.vue$/); - name = match && match[1]; - } - - return ( - (name ? ("<" + (classify(name)) + ">") : "") + - (file && includeFile !== false ? (" at " + file) : '') - ) - }; - - var formatLocation = function (str) { - if (str === "") { - str += " - use the \"name\" option for better debugging messages."; - } - return ("\n(found in " + str + ")") - }; -} - /* */ @@ -1056,7 +1145,7 @@ function mergeHook ( : parentVal } -config._lifecycleHooks.forEach(function (hook) { +LIFECYCLE_HOOKS.forEach(function (hook) { strats[hook] = mergeHook; }); @@ -1074,7 +1163,7 @@ function mergeAssets (parentVal, childVal) { : res } -config._assetTypes.forEach(function (type) { +ASSET_TYPES.forEach(function (type) { strats[type + 's'] = mergeAssets; }); @@ -1200,21 +1289,20 @@ function mergeOptions ( { checkComponents(child); } + + if (typeof child === 'function') { + child = child.options; + } + normalizeProps(child); normalizeDirectives(child); var extendsFrom = child.extends; if (extendsFrom) { - parent = typeof extendsFrom === 'function' - ? mergeOptions(parent, extendsFrom.options, vm) - : mergeOptions(parent, extendsFrom, vm); + parent = mergeOptions(parent, extendsFrom, vm); } if (child.mixins) { for (var i = 0, l = child.mixins.length; i < l; i++) { - var mixin = child.mixins[i]; - if (mixin.prototype instanceof Vue$2) { - mixin = mixin.options; - } - parent = mergeOptions(parent, mixin, vm); + parent = mergeOptions(parent, child.mixins[i], vm); } } var options = {}; @@ -1387,20 +1475,13 @@ function assertProp ( } } -/** - * Assert the type of a value - */ +var simpleCheckRE = /^(String|Number|Boolean|Function|Symbol)$/; + function assertType (value, type) { var valid; var expectedType = getType(type); - if (expectedType === 'String') { - valid = typeof value === (expectedType = 'string'); - } else if (expectedType === 'Number') { - valid = typeof value === (expectedType = 'number'); - } else if (expectedType === 'Boolean') { - valid = typeof value === (expectedType = 'boolean'); - } else if (expectedType === 'Function') { - valid = typeof value === (expectedType = 'function'); + if (simpleCheckRE.test(expectedType)) { + valid = typeof value === expectedType.toLowerCase(); } else if (expectedType === 'Object') { valid = isPlainObject(value); } else if (expectedType === 'Array') { @@ -1421,7 +1502,7 @@ function assertType (value, type) { */ function getType (fn) { var match = fn && fn.toString().match(/^\s*function (\w+)/); - return match && match[1] + return match ? match[1] : '' } function isType (type, fn) { @@ -1437,22 +1518,6 @@ function isType (type, fn) { return false } -function handleError (err, vm, info) { - if (config.errorHandler) { - config.errorHandler.call(null, err, vm, info); - } else { - { - warn(("Error in " + info + ":"), vm); - } - /* istanbul ignore else */ - if (inBrowser && typeof console !== 'undefined') { - console.error(err); - } else { - throw err - } - } -} - /* not type checking this file because flow doesn't play well with Proxy */ var initProxy; @@ -1635,6 +1700,8 @@ function cloneVNodes (vnodes) { /* */ var normalizeEvent = cached(function (name) { + var passive = name.charAt(0) === '&'; + name = passive ? name.slice(1) : name; var once$$1 = name.charAt(0) === '~'; // Prefixed last, checked first name = once$$1 ? name.slice(1) : name; var capture = name.charAt(0) === '!'; @@ -1642,7 +1709,8 @@ var normalizeEvent = cached(function (name) { return { name: name, once: once$$1, - capture: capture + capture: capture, + passive: passive } }); @@ -1676,23 +1744,23 @@ function updateListeners ( cur = on[name]; old = oldOn[name]; event = normalizeEvent(name); - if (!cur) { + if (isUndef(cur)) { "development" !== 'production' && warn( "Invalid handler for event \"" + (event.name) + "\": got " + String(cur), vm ); - } else if (!old) { - if (!cur.fns) { + } else if (isUndef(old)) { + if (isUndef(cur.fns)) { cur = on[name] = createFnInvoker(cur); } - add(event.name, cur, event.once, event.capture); + add(event.name, cur, event.once, event.capture, event.passive); } else if (cur !== old) { old.fns = cur; on[name] = old; } } for (name in oldOn) { - if (!on[name]) { + if (isUndef(on[name])) { event = normalizeEvent(name); remove$$1(event.name, oldOn[name], event.capture); } @@ -1712,12 +1780,12 @@ function mergeVNodeHook (def, hookKey, hook) { remove(invoker.fns, wrappedHook); } - if (!oldHook) { + if (isUndef(oldHook)) { // no existing hook invoker = createFnInvoker([wrappedHook]); } else { /* istanbul ignore if */ - if (oldHook.fns && oldHook.merged) { + if (isDef(oldHook.fns) && isTrue(oldHook.merged)) { // already a merged invoker invoker = oldHook; invoker.fns.push(wrappedHook); @@ -1733,6 +1801,74 @@ function mergeVNodeHook (def, hookKey, hook) { /* */ +function extractPropsFromVNodeData ( + data, + Ctor, + tag +) { + // we are only extracting raw values here. + // validation and default values are handled in the child + // component itself. + var propOptions = Ctor.options.props; + if (isUndef(propOptions)) { + return + } + var res = {}; + var attrs = data.attrs; + var props = data.props; + if (isDef(attrs) || isDef(props)) { + for (var key in propOptions) { + var altKey = hyphenate(key); + { + var keyInLowerCase = key.toLowerCase(); + if ( + key !== keyInLowerCase && + attrs && hasOwn(attrs, keyInLowerCase) + ) { + tip( + "Prop \"" + keyInLowerCase + "\" is passed to component " + + (formatComponentName(tag || Ctor)) + ", but the declared prop name is" + + " \"" + key + "\". " + + "Note that HTML attributes are case-insensitive and camelCased " + + "props need to use their kebab-case equivalents when using in-DOM " + + "templates. You should probably use \"" + altKey + "\" instead of \"" + key + "\"." + ); + } + } + checkProp(res, props, key, altKey, true) || + checkProp(res, attrs, key, altKey, false); + } + } + return res +} + +function checkProp ( + res, + hash, + key, + altKey, + preserve +) { + if (isDef(hash)) { + if (hasOwn(hash, key)) { + res[key] = hash[key]; + if (!preserve) { + delete hash[key]; + } + return true + } else if (hasOwn(hash, altKey)) { + res[key] = hash[altKey]; + if (!preserve) { + delete hash[altKey]; + } + return true + } + } + return false +} + +/* */ + // The template compiler attempts to minimize the need for normalization by // statically analyzing the template at compile time. // @@ -1771,25 +1907,25 @@ function normalizeArrayChildren (children, nestedIndex) { var i, c, last; for (i = 0; i < children.length; i++) { c = children[i]; - if (c == null || typeof c === 'boolean') { continue } + if (isUndef(c) || typeof c === 'boolean') { continue } last = res[res.length - 1]; // nested if (Array.isArray(c)) { res.push.apply(res, normalizeArrayChildren(c, ((nestedIndex || '') + "_" + i))); } else if (isPrimitive(c)) { - if (last && last.text) { - last.text += String(c); + if (isDef(last) && isDef(last.text)) { + (last).text += String(c); } else if (c !== '') { // convert primitive to vnode res.push(createTextVNode(c)); } } else { - if (c.text && last && last.text) { + if (isDef(c.text) && isDef(last) && isDef(last.text)) { res[res.length - 1] = createTextVNode(last.text + c.text); } else { // default key for nested array children (likely generated by v-for) - if (c.tag && c.key == null && nestedIndex != null) { - c.key = "__vlist" + nestedIndex + "_" + i + "__"; + if (isDef(c.tag) && isUndef(c.key) && isDef(nestedIndex)) { + c.key = "__vlist" + ((nestedIndex)) + "_" + i + "__"; } res.push(c); } @@ -1800,10 +1936,125 @@ function normalizeArrayChildren (children, nestedIndex) { /* */ -function getFirstComponentChild (children) { - return children && children.filter(function (c) { return c && c.componentOptions; })[0] +function ensureCtor (comp, base) { + return isObject(comp) + ? base.extend(comp) + : comp } +function resolveAsyncComponent ( + factory, + baseCtor, + context +) { + if (isTrue(factory.error) && isDef(factory.errorComp)) { + return factory.errorComp + } + + if (isDef(factory.resolved)) { + return factory.resolved + } + + if (isTrue(factory.loading) && isDef(factory.loadingComp)) { + return factory.loadingComp + } + + if (isDef(factory.contexts)) { + // already pending + factory.contexts.push(context); + } else { + var contexts = factory.contexts = [context]; + var sync = true; + + var forceRender = function () { + for (var i = 0, l = contexts.length; i < l; i++) { + contexts[i].$forceUpdate(); + } + }; + + var resolve = once(function (res) { + // cache resolved + factory.resolved = ensureCtor(res, baseCtor); + // invoke callbacks only if this is not a synchronous resolve + // (async resolves are shimmed as synchronous during SSR) + if (!sync) { + forceRender(); + } + }); + + var reject = once(function (reason) { + "development" !== 'production' && warn( + "Failed to resolve async component: " + (String(factory)) + + (reason ? ("\nReason: " + reason) : '') + ); + if (isDef(factory.errorComp)) { + factory.error = true; + forceRender(); + } + }); + + var res = factory(resolve, reject); + + if (isObject(res)) { + if (typeof res.then === 'function') { + // () => Promise + if (isUndef(factory.resolved)) { + res.then(resolve, reject); + } + } else if (isDef(res.component) && typeof res.component.then === 'function') { + res.component.then(resolve, reject); + + if (isDef(res.error)) { + factory.errorComp = ensureCtor(res.error, baseCtor); + } + + if (isDef(res.loading)) { + factory.loadingComp = ensureCtor(res.loading, baseCtor); + if (res.delay === 0) { + factory.loading = true; + } else { + setTimeout(function () { + if (isUndef(factory.resolved) && isUndef(factory.error)) { + factory.loading = true; + forceRender(); + } + }, res.delay || 200); + } + } + + if (isDef(res.timeout)) { + setTimeout(function () { + reject( + "timeout (" + (res.timeout) + "ms)" + ); + }, res.timeout); + } + } + } + + sync = false; + // return in case resolved synchronously + return factory.loading + ? factory.loadingComp + : factory.resolved + } +} + +/* */ + +function getFirstComponentChild (children) { + if (Array.isArray(children)) { + for (var i = 0; i < children.length; i++) { + var c = children[i]; + if (isDef(c) && isDef(c.componentOptions)) { + return c + } + } + } +} + +/* */ + /* */ function initEvents (vm) { @@ -1949,13 +2200,13 @@ function resolveSlots ( return slots } var defaultSlot = []; - var name, child; for (var i = 0, l = children.length; i < l; i++) { - child = children[i]; + var child = children[i]; // named slots should only be respected if the vnode was rendered in the // same context. if ((child.context === context || child.functionalContext === context) && - child.data && (name = child.data.slot)) { + child.data && child.data.slot != null) { + var name = child.data.slot; var slot = (slots[name] || (slots[name] = [])); if (child.tag === 'template') { slot.push.apply(slot, child.children); @@ -2242,7 +2493,7 @@ function activateChildComponent (vm, direct) { } else if (vm._directInactive) { return } - if (vm._inactive || vm._inactive == null) { + if (vm._inactive || vm._inactive === null) { vm._inactive = false; for (var i = 0; i < vm.$children.length; i++) { activateChildComponent(vm.$children[i]); @@ -2286,7 +2537,10 @@ function callHook (vm, hook) { /* */ +var MAX_UPDATE_COUNT = 100; + var queue = []; +var activatedChildren = []; var has = {}; var circular = {}; var waiting = false; @@ -2297,7 +2551,7 @@ var index = 0; * Reset the scheduler's state. */ function resetSchedulerState () { - queue.length = 0; + queue.length = activatedChildren.length = 0; has = {}; { circular = {}; @@ -2310,7 +2564,7 @@ function resetSchedulerState () { */ function flushSchedulerQueue () { flushing = true; - var watcher, id, vm; + var watcher, id; // Sort queue before flush. // This ensures that: @@ -2332,7 +2586,7 @@ function flushSchedulerQueue () { // in dev build, check and stop circular updates. if ("development" !== 'production' && has[id] != null) { circular[id] = (circular[id] || 0) + 1; - if (circular[id] > config._maxUpdateCount) { + if (circular[id] > MAX_UPDATE_COUNT) { warn( 'You may have an infinite update loop ' + ( watcher.user @@ -2346,19 +2600,15 @@ function flushSchedulerQueue () { } } - // reset scheduler before updated hook called - var oldQueue = queue.slice(); + // keep copies of post queues before resetting state + var activatedQueue = activatedChildren.slice(); + var updatedQueue = queue.slice(); + resetSchedulerState(); - // call updated hooks - index = oldQueue.length; - while (index--) { - watcher = oldQueue[index]; - vm = watcher.vm; - if (vm._watcher === watcher && vm._isMounted) { - callHook(vm, 'updated'); - } - } + // call component updated and activated hooks + callActivatedHooks(activatedQueue); + callUpdateHooks(updatedQueue); // devtool hook /* istanbul ignore if */ @@ -2367,6 +2617,35 @@ function flushSchedulerQueue () { } } +function callUpdateHooks (queue) { + var i = queue.length; + while (i--) { + var watcher = queue[i]; + var vm = watcher.vm; + if (vm._watcher === watcher && vm._isMounted) { + callHook(vm, 'updated'); + } + } +} + +/** + * Queue a kept-alive component that was activated during patch. + * The queue will be processed after the entire tree has been patched. + */ +function queueActivatedComponent (vm) { + // setting _inactive to false here so that a render function can + // rely on checking whether it's in an inactive tree (e.g. router-view) + vm._inactive = false; + activatedChildren.push(vm); +} + +function callActivatedHooks (queue) { + for (var i = 0; i < queue.length; i++) { + queue[i]._inactive = true; + activateChildComponent(queue[i], true /* true */); + } +} + /** * Push a watcher into the watcher queue. * Jobs with duplicate IDs will be skipped unless it's @@ -2668,7 +2947,11 @@ function initState (vm) { if (opts.watch) { initWatch(vm, opts.watch); } } -var isReservedProp = { key: 1, ref: 1, slot: 1 }; +var isReservedProp = { + key: 1, + ref: 1, + slot: 1 +}; function initProps (vm, propsOptions) { var propsData = vm.$options.propsData || {}; @@ -2684,7 +2967,7 @@ function initProps (vm, propsOptions) { var value = validateProp(key, propsOptions, propsData, vm); /* istanbul ignore else */ { - if (isReservedProp[key]) { + if (isReservedProp[key] || config.isReservedAttr(key)) { warn( ("\"" + key + "\" is a reserved attribute and cannot be used as component prop."), vm @@ -2780,6 +3063,12 @@ function initComputed (vm, computed) { // at instantiation here. if (!(key in vm)) { defineComputed(vm, key, userDef); + } else { + if (key in vm.$data) { + warn(("The computed property \"" + key + "\" is already defined in data."), vm); + } else if (vm.$options.props && key in vm.$options.props) { + warn(("The computed property \"" + key + "\" is already defined as a prop."), vm); + } } } } @@ -2909,6 +3198,111 @@ function stateMixin (Vue) { /* */ +function initProvide (vm) { + var provide = vm.$options.provide; + if (provide) { + vm._provided = typeof provide === 'function' + ? provide.call(vm) + : provide; + } +} + +function initInjections (vm) { + var result = resolveInject(vm.$options.inject, vm); + if (result) { + Object.keys(result).forEach(function (key) { + /* istanbul ignore else */ + { + defineReactive$$1(vm, key, result[key], function () { + warn( + "Avoid mutating an injected value directly since the changes will be " + + "overwritten whenever the provided component re-renders. " + + "injection being mutated: \"" + key + "\"", + vm + ); + }); + } + }); + } +} + +function resolveInject (inject, vm) { + if (inject) { + // inject is :any because flow is not smart enough to figure out cached + // isArray here + var isArray = Array.isArray(inject); + var result = Object.create(null); + var keys = isArray + ? inject + : hasSymbol + ? Reflect.ownKeys(inject) + : Object.keys(inject); + + for (var i = 0; i < keys.length; i++) { + var key = keys[i]; + var provideKey = isArray ? key : inject[key]; + var source = vm; + while (source) { + if (source._provided && provideKey in source._provided) { + result[key] = source._provided[provideKey]; + break + } + source = source.$parent; + } + } + return result + } +} + +/* */ + +function createFunctionalComponent ( + Ctor, + propsData, + data, + context, + children +) { + var props = {}; + var propOptions = Ctor.options.props; + if (isDef(propOptions)) { + for (var key in propOptions) { + props[key] = validateProp(key, propOptions, propsData); + } + } else { + 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 || {}, + injections: resolveInject(Ctor.options.inject, context), + slots: function () { return resolveSlots(children, context); } + }); + if (vnode instanceof VNode) { + vnode.functionalContext = context; + if (data.slot) { + (vnode.data || (vnode.data = {})).slot = data.slot; + } + } + return vnode +} + +function mergeProps (to, from) { + for (var key in from) { + to[camelize(key)] = from[key]; + } +} + +/* */ + // hooks to be invoked on component VNodes during patch var componentVNodeHooks = { init: function init ( @@ -2945,21 +3339,33 @@ var componentVNodeHooks = { }, insert: function insert (vnode) { - if (!vnode.componentInstance._isMounted) { - vnode.componentInstance._isMounted = true; - callHook(vnode.componentInstance, 'mounted'); + var context = vnode.context; + var componentInstance = vnode.componentInstance; + if (!componentInstance._isMounted) { + componentInstance._isMounted = true; + callHook(componentInstance, 'mounted'); } if (vnode.data.keepAlive) { - activateChildComponent(vnode.componentInstance, true /* direct */); + if (context._isMounted) { + // vue-router#1212 + // During updates, a kept-alive component's child components may + // change, so directly walking the tree here may call activated hooks + // on incorrect children. Instead we push them into a queue which will + // be processed after the whole patch process ended. + queueActivatedComponent(componentInstance); + } else { + activateChildComponent(componentInstance, true /* direct */); + } } }, destroy: function destroy (vnode) { - if (!vnode.componentInstance._isDestroyed) { + var componentInstance = vnode.componentInstance; + if (!componentInstance._isDestroyed) { if (!vnode.data.keepAlive) { - vnode.componentInstance.$destroy(); + componentInstance.$destroy(); } else { - deactivateChildComponent(vnode.componentInstance, true /* direct */); + deactivateChildComponent(componentInstance, true /* direct */); } } } @@ -2974,15 +3380,19 @@ function createComponent ( children, tag ) { - if (!Ctor) { + if (isUndef(Ctor)) { return } var baseCtor = context.$options._base; + + // plain options object: turn it into a constructor if (isObject(Ctor)) { Ctor = baseCtor.extend(Ctor); } + // if at this stage it's not a constructor or an async component factory, + // reject. if (typeof Ctor !== 'function') { { warn(("Invalid Component definition: " + (String(Ctor))), context); @@ -2991,20 +3401,12 @@ function createComponent ( } // async component - if (!Ctor.cid) { - if (Ctor.resolved) { - Ctor = Ctor.resolved; - } else { - Ctor = resolveAsyncComponent(Ctor, baseCtor, function () { - // it's ok to queue this on every render because - // $forceUpdate is buffered by the scheduler. - context.$forceUpdate(); - }); - if (!Ctor) { - // return nothing if this is indeed an async component - // wait for the callback to trigger parent update. - return - } + if (isUndef(Ctor.cid)) { + Ctor = resolveAsyncComponent(Ctor, baseCtor, context); + if (Ctor === undefined) { + // return nothing if this is indeed an async component + // wait for the callback to trigger parent update. + return } } @@ -3015,15 +3417,15 @@ function createComponent ( data = data || {}; // transform component v-model data into props & events - if (data.model) { + if (isDef(data.model)) { transformModel(Ctor.options, data); } // extract props - var propsData = extractProps(data, Ctor, tag); + var propsData = extractPropsFromVNodeData(data, Ctor, tag); // functional component - if (Ctor.options.functional) { + if (isTrue(Ctor.options.functional)) { return createFunctionalComponent(Ctor, propsData, data, context, children) } @@ -3033,7 +3435,7 @@ function createComponent ( // replace with listeners with .native modifier data.on = data.nativeOn; - if (Ctor.options.abstract) { + if (isTrue(Ctor.options.abstract)) { // abstract components do not keep anything // other than props & listeners data = {}; @@ -3052,40 +3454,6 @@ function createComponent ( return vnode } -function createFunctionalComponent ( - Ctor, - propsData, - data, - context, - children -) { - var props = {}; - var propOptions = Ctor.options.props; - if (propOptions) { - for (var key in propOptions) { - props[key] = validateProp(key, propOptions, propsData); - } - } - // 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, { - props: props, - data: data, - parent: context, - children: children, - slots: function () { return resolveSlots(children, context); } - }); - if (vnode instanceof VNode) { - vnode.functionalContext = context; - if (data.slot) { - (vnode.data || (vnode.data = {})).slot = data.slot; - } - } - return vnode -} - function createComponentInstanceForVnode ( vnode, // we know it's MountedComponentVNode but flow doesn't parent, // activeInstance in lifecycle state @@ -3106,125 +3474,13 @@ function createComponentInstanceForVnode ( }; // check inline-template render functions var inlineTemplate = vnode.data.inlineTemplate; - if (inlineTemplate) { + if (isDef(inlineTemplate)) { options.render = inlineTemplate.render; options.staticRenderFns = inlineTemplate.staticRenderFns; } return new vnodeComponentOptions.Ctor(options) } -function resolveAsyncComponent ( - factory, - baseCtor, - cb -) { - if (factory.requested) { - // pool callbacks - factory.pendingCallbacks.push(cb); - } else { - factory.requested = true; - var cbs = factory.pendingCallbacks = [cb]; - var sync = true; - - var resolve = function (res) { - if (isObject(res)) { - res = baseCtor.extend(res); - } - // cache resolved - factory.resolved = res; - // invoke callbacks only if this is not a synchronous resolve - // (async resolves are shimmed as synchronous during SSR) - if (!sync) { - for (var i = 0, l = cbs.length; i < l; i++) { - cbs[i](res); - } - } - }; - - var reject = function (reason) { - "development" !== 'production' && warn( - "Failed to resolve async component: " + (String(factory)) + - (reason ? ("\nReason: " + reason) : '') - ); - }; - - var res = factory(resolve, reject); - - // handle promise - if (res && typeof res.then === 'function' && !factory.resolved) { - res.then(resolve, reject); - } - - sync = false; - // return in case resolved synchronously - return factory.resolved - } -} - -function extractProps (data, Ctor, tag) { - // we are only extracting raw values here. - // validation and default values are handled in the child - // component itself. - var propOptions = Ctor.options.props; - if (!propOptions) { - return - } - var res = {}; - var attrs = data.attrs; - var props = data.props; - var domProps = data.domProps; - if (attrs || props || domProps) { - for (var key in propOptions) { - var altKey = hyphenate(key); - { - var keyInLowerCase = key.toLowerCase(); - if ( - key !== keyInLowerCase && - attrs && attrs.hasOwnProperty(keyInLowerCase) - ) { - tip( - "Prop \"" + keyInLowerCase + "\" is passed to component " + - (formatComponentName(tag || Ctor)) + ", but the declared prop name is" + - " \"" + key + "\". " + - "Note that HTML attributes are case-insensitive and camelCased " + - "props need to use their kebab-case equivalents when using in-DOM " + - "templates. You should probably use \"" + altKey + "\" instead of \"" + key + "\"." - ); - } - } - checkProp(res, props, key, altKey, true) || - checkProp(res, attrs, key, altKey) || - checkProp(res, domProps, key, altKey); - } - } - return res -} - -function checkProp ( - res, - hash, - key, - altKey, - preserve -) { - if (hash) { - if (hasOwn(hash, key)) { - res[key] = hash[key]; - if (!preserve) { - delete hash[key]; - } - return true - } else if (hasOwn(hash, altKey)) { - res[key] = hash[altKey]; - if (!preserve) { - delete hash[altKey]; - } - return true - } - } - return false -} - function mergeHooks (data) { if (!data.hook) { data.hook = {}; @@ -3250,7 +3506,7 @@ function transformModel (options, data) { var prop = (options.model && options.model.prop) || 'value'; var event = (options.model && options.model.event) || 'input';(data.props || (data.props = {}))[prop] = data.model.value; var on = data.on || (data.on = {}); - if (on[event]) { + if (isDef(on[event])) { on[event] = [data.model.callback].concat(on[event]); } else { on[event] = data.model.callback; @@ -3277,7 +3533,9 @@ function createElement ( children = data; data = undefined; } - if (alwaysNormalize) { normalizationType = ALWAYS_NORMALIZE; } + if (isTrue(alwaysNormalize)) { + normalizationType = ALWAYS_NORMALIZE; + } return _createElement(context, tag, data, children, normalizationType) } @@ -3288,7 +3546,7 @@ function _createElement ( children, normalizationType ) { - if (data && data.__ob__) { + if (isDef(data) && isDef((data).__ob__)) { "development" !== 'production' && warn( "Avoid using observed data object as vnode data: " + (JSON.stringify(data)) + "\n" + 'Always create fresh vnode data objects in each render!', @@ -3322,7 +3580,7 @@ function _createElement ( config.parsePlatformTagName(tag), data, children, undefined, undefined, context ); - } else if ((Ctor = resolveAsset(context.$options, 'components', tag))) { + } else if (isDef(Ctor = resolveAsset(context.$options, 'components', tag))) { // component vnode = createComponent(Ctor, data, context, children, tag); } else { @@ -3338,7 +3596,7 @@ function _createElement ( // direct component options / constructor vnode = createComponent(tag, data, context, children); } - if (vnode) { + if (vnode !== undefined) { if (ns) { applyNS(vnode, ns); } return vnode } else { @@ -3352,10 +3610,10 @@ function applyNS (vnode, ns) { // use default namespace inside foreignObject return } - if (vnode.children) { + if (Array.isArray(vnode.children)) { for (var i = 0, l = vnode.children.length; i < l; i++) { var child = vnode.children[i]; - if (child.tag && !child.ns) { + if (isDef(child.tag) && isUndef(child.ns)) { applyNS(child, ns); } } @@ -3555,10 +3813,9 @@ function markStaticNode (node, key, isOnce) { /* */ function initRender (vm) { - vm.$vnode = null; // the placeholder node in parent tree vm._vnode = null; // the root of the child tree vm._staticTrees = null; - var parentVnode = vm.$options._parentVnode; + var parentVnode = vm.$vnode = vm.$options._parentVnode; // the placeholder node in parent tree var renderContext = parentVnode && parentVnode.context; vm.$slots = resolveSlots(vm.$options._renderChildren, renderContext); vm.$scopedSlots = emptyObject; @@ -3651,56 +3908,6 @@ function renderMixin (Vue) { /* */ -function initProvide (vm) { - var provide = vm.$options.provide; - if (provide) { - vm._provided = typeof provide === 'function' - ? provide.call(vm) - : provide; - } -} - -function initInjections (vm) { - var inject = vm.$options.inject; - if (inject) { - // inject is :any because flow is not smart enough to figure out cached - // isArray here - var isArray = Array.isArray(inject); - var keys = isArray - ? inject - : hasSymbol - ? Reflect.ownKeys(inject) - : Object.keys(inject); - - var loop = function ( i ) { - var key = keys[i]; - var provideKey = isArray ? key : inject[key]; - var source = vm; - while (source) { - if (source._provided && provideKey in source._provided) { - /* istanbul ignore else */ - { - defineReactive$$1(vm, key, source._provided[provideKey], function () { - warn( - "Avoid mutating an injected value directly since the changes will be " + - "overwritten whenever the provided component re-renders. " + - "injection being mutated: \"" + key + "\"", - vm - ); - }); - } - break - } - source = source.$parent; - } - }; - - for (var i = 0; i < keys.length; i++) loop( i ); - } -} - -/* */ - var uid = 0; function initMixin (Vue) { @@ -3804,24 +4011,27 @@ function resolveConstructorOptions (Ctor) { function resolveModifiedOptions (Ctor) { var modified; var latest = Ctor.options; + var extended = Ctor.extendOptions; var sealed = Ctor.sealedOptions; for (var key in latest) { if (latest[key] !== sealed[key]) { if (!modified) { modified = {}; } - modified[key] = dedupe(latest[key], sealed[key]); + modified[key] = dedupe(latest[key], extended[key], sealed[key]); } } return modified } -function dedupe (latest, sealed) { +function dedupe (latest, extended, sealed) { // compare latest and sealed to ensure lifecycle hooks won't be duplicated // between merges if (Array.isArray(latest)) { var res = []; sealed = Array.isArray(sealed) ? sealed : [sealed]; + extended = Array.isArray(extended) ? extended : [extended]; for (var i = 0; i < latest.length; i++) { - if (sealed.indexOf(latest[i]) < 0) { + // push original options and not sealed options to exclude duplicated options + if (extended.indexOf(latest[i]) >= 0 || sealed.indexOf(latest[i]) < 0) { res.push(latest[i]); } } @@ -3831,19 +4041,19 @@ function dedupe (latest, sealed) { } } -function Vue$2 (options) { +function Vue$3 (options) { if ("development" !== 'production' && - !(this instanceof Vue$2)) { + !(this instanceof Vue$3)) { warn('Vue is a constructor and should be called with the `new` keyword'); } this._init(options); } -initMixin(Vue$2); -stateMixin(Vue$2); -eventsMixin(Vue$2); -lifecycleMixin(Vue$2); -renderMixin(Vue$2); +initMixin(Vue$3); +stateMixin(Vue$3); +eventsMixin(Vue$3); +lifecycleMixin(Vue$3); +renderMixin(Vue$3); /* */ @@ -3937,7 +4147,7 @@ function initExtend (Vue) { // create asset registers, so extended classes // can have their private assets too. - config._assetTypes.forEach(function (type) { + ASSET_TYPES.forEach(function (type) { Sub[type] = Super[type]; }); // enable recursive self-lookup @@ -3978,7 +4188,7 @@ function initAssetRegisters (Vue) { /** * Create asset registration methods. */ - config._assetTypes.forEach(function (type) { + ASSET_TYPES.forEach(function (type) { Vue[type] = function ( id, definition @@ -4020,20 +4230,22 @@ function getComponentName (opts) { function matches (pattern, name) { if (typeof pattern === 'string') { return pattern.split(',').indexOf(name) > -1 - } else if (pattern instanceof RegExp) { + } else if (isRegExp(pattern)) { return pattern.test(name) } /* istanbul ignore next */ return false } -function pruneCache (cache, filter) { +function pruneCache (cache, current, filter) { for (var key in cache) { var cachedNode = cache[key]; if (cachedNode) { var name = getComponentName(cachedNode.componentOptions); if (name && !filter(name)) { - pruneCacheEntry(cachedNode); + if (cachedNode !== current) { + pruneCacheEntry(cachedNode); + } cache[key] = null; } } @@ -4042,9 +4254,6 @@ function pruneCache (cache, filter) { function pruneCacheEntry (vnode) { if (vnode) { - if (!vnode.componentInstance._inactive) { - callHook(vnode.componentInstance, 'deactivated'); - } vnode.componentInstance.$destroy(); } } @@ -4072,10 +4281,10 @@ var KeepAlive = { watch: { include: function include (val) { - pruneCache(this.cache, function (name) { return matches(val, name); }); + pruneCache(this.cache, this._vnode, function (name) { return matches(val, name); }); }, exclude: function exclude (val) { - pruneCache(this.cache, function (name) { return !matches(val, name); }); + pruneCache(this.cache, this._vnode, function (name) { return !matches(val, name); }); } }, @@ -4141,7 +4350,7 @@ function initGlobalAPI (Vue) { Vue.nextTick = nextTick; Vue.options = Object.create(null); - config._assetTypes.forEach(function (type) { + ASSET_TYPES.forEach(function (type) { Vue.options[type + 's'] = Object.create(null); }); @@ -4157,16 +4366,20 @@ function initGlobalAPI (Vue) { initAssetRegisters(Vue); } -initGlobalAPI(Vue$2); +initGlobalAPI(Vue$3); -Object.defineProperty(Vue$2.prototype, '$isServer', { +Object.defineProperty(Vue$3.prototype, '$isServer', { get: isServerRendering }); -Vue$2.version = '2.2.6'; +Vue$3.version = '2.3.0-beta.1'; /* */ +// these are reserved for web because they are directly compiled away +// during template compilation +var isReservedAttr = makeMap('style,class'); + // attributes that should be using props for binding var acceptValue = makeMap('input,textarea,option,select'); var mustUseProp = function (tag, type, attr) { @@ -4209,13 +4422,13 @@ function genClassForVnode (vnode) { var data = vnode.data; var parentNode = vnode; var childNode = vnode; - while (childNode.componentInstance) { + while (isDef(childNode.componentInstance)) { childNode = childNode.componentInstance._vnode; if (childNode.data) { data = mergeClassData(childNode.data, data); } } - while ((parentNode = parentNode.parent)) { + while (isDef(parentNode = parentNode.parent)) { if (parentNode.data) { data = mergeClassData(data, parentNode.data); } @@ -4226,7 +4439,7 @@ function genClassForVnode (vnode) { function mergeClassData (child, parent) { return { staticClass: concat(child.staticClass, parent.staticClass), - class: child.class + class: isDef(child.class) ? [child.class, parent.class] : parent.class } @@ -4235,7 +4448,7 @@ function mergeClassData (child, parent) { function genClassFromData (data) { var dynamicClass = data.class; var staticClass = data.staticClass; - if (staticClass || dynamicClass) { + if (isDef(staticClass) || isDef(dynamicClass)) { return concat(staticClass, stringifyClass(dynamicClass)) } /* istanbul ignore next */ @@ -4247,18 +4460,18 @@ function concat (a, b) { } function stringifyClass (value) { - var res = ''; - if (!value) { - return res + if (isUndef(value)) { + return '' } if (typeof value === 'string') { return value } + var res = ''; if (Array.isArray(value)) { var stringified; for (var i = 0, l = value.length; i < l; i++) { - if (value[i]) { - if ((stringified = stringifyClass(value[i]))) { + if (isDef(value[i])) { + if (isDef(stringified = stringifyClass(value[i])) && stringified !== '') { res += stringified + ' '; } } @@ -4503,18 +4716,6 @@ var emptyNode = new VNode('', {}, []); var hooks = ['create', 'activate', 'update', 'remove', 'destroy']; -function isUndef (v) { - return v === undefined || v === null -} - -function isDef (v) { - return v !== undefined && v !== null -} - -function isTrue (v) { - return v === true -} - function sameVnode (a, b) { return ( a.key === b.key && @@ -4701,7 +4902,9 @@ function createPatchFunction (backend) { function insert (parent, elm, ref) { if (isDef(parent)) { if (isDef(ref)) { - nodeOps.insertBefore(parent, elm, ref); + if (ref.parentNode === parent) { + nodeOps.insertBefore(parent, elm, ref); + } } else { nodeOps.appendChild(parent, elm); } @@ -4792,6 +4995,7 @@ function createPatchFunction (backend) { function removeAndInvokeRemoveHook (vnode, rm) { if (isDef(rm) || isDef(vnode.data)) { + var i; var listeners = cbs.remove.length + 1; if (isDef(rm)) { // we have a recursively passed down rm callback @@ -5053,8 +5257,8 @@ function createPatchFunction (backend) { // mounting to a real element // check if this is server-rendered content and if we can perform // a successful hydration. - if (oldVnode.nodeType === 1 && oldVnode.hasAttribute('server-rendered')) { - oldVnode.removeAttribute('server-rendered'); + if (oldVnode.nodeType === 1 && oldVnode.hasAttribute(SSR_ATTR)) { + oldVnode.removeAttribute(SSR_ATTR); hydrating = true; } if (isTrue(hydrating)) { @@ -5221,7 +5425,11 @@ function getRawDirName (dir) { function callHook$1 (dir, hook, vnode, oldVnode, isDestroy) { var fn = dir.def && dir.def[hook]; if (fn) { - fn(vnode.elm, dir, vnode, oldVnode, isDestroy); + try { + fn(vnode.elm, dir, vnode, oldVnode, isDestroy); + } catch (e) { + handleError(e, vnode.context, ("directive " + (dir.name) + " " + hook + " hook")); + } } } @@ -5233,7 +5441,7 @@ var baseModules = [ /* */ function updateAttrs (oldVnode, vnode) { - if (!oldVnode.data.attrs && !vnode.data.attrs) { + if (isUndef(oldVnode.data.attrs) && isUndef(vnode.data.attrs)) { return } var key, cur, old; @@ -5241,7 +5449,7 @@ function updateAttrs (oldVnode, vnode) { var oldAttrs = oldVnode.data.attrs || {}; var attrs = vnode.data.attrs || {}; // clone observed objects, as the user probably wants to mutate it - if (attrs.__ob__) { + if (isDef(attrs.__ob__)) { attrs = vnode.data.attrs = extend({}, attrs); } @@ -5258,7 +5466,7 @@ function updateAttrs (oldVnode, vnode) { setAttr(elm, 'value', attrs.value); } for (key in oldAttrs) { - if (attrs[key] == null) { + if (isUndef(attrs[key])) { if (isXlink(key)) { elm.removeAttributeNS(xlinkNS, getXlinkProp(key)); } else if (!isEnumeratedAttr(key)) { @@ -5305,8 +5513,15 @@ function updateClass (oldVnode, vnode) { var el = vnode.elm; var data = vnode.data; var oldData = oldVnode.data; - if (!data.staticClass && !data.class && - (!oldData || (!oldData.staticClass && !oldData.class))) { + if ( + isUndef(data.staticClass) && + isUndef(data.class) && ( + isUndef(oldData) || ( + isUndef(oldData.staticClass) && + isUndef(oldData.class) + ) + ) + ) { return } @@ -5314,7 +5529,7 @@ function updateClass (oldVnode, vnode) { // handle transition classes var transitionClass = el._transitionClasses; - if (transitionClass) { + if (isDef(transitionClass)) { cls = concat(cls, stringifyClass(transitionClass)); } @@ -5395,13 +5610,13 @@ var CHECKBOX_RADIO_TOKEN = '__c'; function normalizeEvents (on) { var event; /* istanbul ignore if */ - if (on[RANGE_TOKEN]) { + if (isDef(on[RANGE_TOKEN])) { // IE input[type=range] only supports `change` event event = isIE ? 'change' : 'input'; on[event] = [].concat(on[RANGE_TOKEN], on[event] || []); delete on[RANGE_TOKEN]; } - if (on[CHECKBOX_RADIO_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] || []); @@ -5414,10 +5629,11 @@ var target$1; function add$1 ( event, handler, - once, - capture + once$$1, + capture, + passive ) { - if (once) { + if (once$$1) { var oldHandler = handler; var _target = target$1; // save current target element in closure handler = function (ev) { @@ -5429,7 +5645,13 @@ function add$1 ( } }; } - target$1.addEventListener(event, handler, capture); + target$1.addEventListener( + event, + handler, + supportsPassive + ? { capture: capture, passive: passive } + : capture + ); } function remove$2 ( @@ -5442,7 +5664,7 @@ function remove$2 ( } function updateDOMListeners (oldVnode, vnode) { - if (!oldVnode.data.on && !vnode.data.on) { + if (isUndef(oldVnode.data.on) && isUndef(vnode.data.on)) { return } var on = vnode.data.on || {}; @@ -5460,7 +5682,7 @@ var events = { /* */ function updateDOMProps (oldVnode, vnode) { - if (!oldVnode.data.domProps && !vnode.data.domProps) { + if (isUndef(oldVnode.data.domProps) && isUndef(vnode.data.domProps)) { return } var key, cur; @@ -5468,12 +5690,12 @@ function updateDOMProps (oldVnode, vnode) { var oldProps = oldVnode.data.domProps || {}; var props = vnode.data.domProps || {}; // clone observed objects, as the user probably wants to mutate it - if (props.__ob__) { + if (isDef(props.__ob__)) { props = vnode.data.domProps = extend({}, props); } for (key in oldProps) { - if (props[key] == null) { + if (isUndef(props[key])) { elm[key] = ''; } } @@ -5525,10 +5747,10 @@ function isDirty (elm, checkVal) { function isInputChanged (elm, newVal) { var value = elm.value; var modifiers = elm._vModifiers; // injected by v-model runtime - if ((modifiers && modifiers.number) || elm.type === 'number') { + if ((isDef(modifiers) && modifiers.number) || elm.type === 'number') { return toNumber(value) !== toNumber(newVal) } - if (modifiers && modifiers.trim) { + if (isDef(modifiers) && modifiers.trim) { return value.trim() !== newVal.trim() } return value !== newVal @@ -5617,7 +5839,17 @@ var setProp = function (el, name, val) { } else if (importantRE.test(val)) { el.style.setProperty(name, val.replace(importantRE, ''), 'important'); } else { - el.style[normalize(name)] = val; + var normalizedName = normalize(name); + if (Array.isArray(val)) { + // Support values array created by autoprefixer, e.g. + // {display: ["-webkit-box", "-ms-flexbox", "flex"]} + // Set them one by one, and the browser will only set those it can recognize + for (var i = 0, len = val.length; i < len; i++) { + el.style[normalizedName] = val[i]; + } + } else { + el.style[normalizedName] = val; + } } }; @@ -5643,27 +5875,32 @@ function updateStyle (oldVnode, vnode) { var data = vnode.data; var oldData = oldVnode.data; - if (!data.staticStyle && !data.style && - !oldData.staticStyle && !oldData.style) { + if (isUndef(data.staticStyle) && isUndef(data.style) && + isUndef(oldData.staticStyle) && isUndef(oldData.style)) { return } var cur, name; var el = vnode.elm; - var oldStaticStyle = oldVnode.data.staticStyle; - var oldStyleBinding = oldVnode.data.style || {}; + var oldStaticStyle = oldData.staticStyle; + var oldStyleBinding = oldData.normalizedStyle || oldData.style || {}; // if static style exists, stylebinding already merged into it when doing normalizeStyleData var oldStyle = oldStaticStyle || oldStyleBinding; var style = normalizeStyleBinding(vnode.data.style) || {}; - vnode.data.style = style.__ob__ ? extend({}, style) : style; + // store normalized style under a different key for next diff + // make sure to clone it if it's reactive, since the user likley wants + // to mutate it. + vnode.data.normalizedStyle = isDef(style.__ob__) + ? extend({}, style) + : style; var newStyle = getStyle(vnode, true); for (name in oldStyle) { - if (newStyle[name] == null) { + if (isUndef(newStyle[name])) { setProp(el, name, ''); } } @@ -5914,38 +6151,39 @@ function enter (vnode, toggleDisplay) { var el = vnode.elm; // call leave callback now - if (el._leaveCb) { + if (isDef(el._leaveCb)) { el._leaveCb.cancelled = true; el._leaveCb(); } var data = resolveTransition(vnode.data.transition); - if (!data) { + if (isUndef(data)) { return } /* istanbul ignore if */ - if (el._enterCb || el.nodeType !== 1) { + if (isDef(el._enterCb) || el.nodeType !== 1) { return } - var css = data.css; - var type = data.type; - var enterClass = data.enterClass; - var enterToClass = data.enterToClass; - var enterActiveClass = data.enterActiveClass; - var appearClass = data.appearClass; - var appearToClass = data.appearToClass; - var appearActiveClass = data.appearActiveClass; - var beforeEnter = data.beforeEnter; - var enter = data.enter; - var afterEnter = data.afterEnter; - var enterCancelled = data.enterCancelled; - var beforeAppear = data.beforeAppear; - var appear = data.appear; - var afterAppear = data.afterAppear; - var appearCancelled = data.appearCancelled; - var duration = data.duration; + var ref = (data); + var css = ref.css; + var type = ref.type; + var enterClass = ref.enterClass; + var enterToClass = ref.enterToClass; + var enterActiveClass = ref.enterActiveClass; + var appearClass = ref.appearClass; + var appearToClass = ref.appearToClass; + var appearActiveClass = ref.appearActiveClass; + var beforeEnter = ref.beforeEnter; + var enter = ref.enter; + var afterEnter = ref.afterEnter; + var enterCancelled = ref.enterCancelled; + var beforeAppear = ref.beforeAppear; + var appear = ref.appear; + var afterAppear = ref.afterAppear; + var appearCancelled = ref.appearCancelled; + var duration = ref.duration; // activeInstance will always be the component managing this // transition. One edge case to check is when the is placed @@ -6062,32 +6300,33 @@ function leave (vnode, rm) { var el = vnode.elm; // call enter callback now - if (el._enterCb) { + if (isDef(el._enterCb)) { el._enterCb.cancelled = true; el._enterCb(); } var data = resolveTransition(vnode.data.transition); - if (!data) { + if (isUndef(data)) { return rm() } /* istanbul ignore if */ - if (el._leaveCb || el.nodeType !== 1) { + if (isDef(el._leaveCb) || el.nodeType !== 1) { return } - var css = data.css; - var type = data.type; - var leaveClass = data.leaveClass; - var leaveToClass = data.leaveToClass; - var leaveActiveClass = data.leaveActiveClass; - var beforeLeave = data.beforeLeave; - var leave = data.leave; - var afterLeave = data.afterLeave; - var leaveCancelled = data.leaveCancelled; - var delayLeave = data.delayLeave; - var duration = data.duration; + var ref = (data); + var css = ref.css; + var type = ref.type; + var leaveClass = ref.leaveClass; + var leaveToClass = ref.leaveToClass; + var leaveActiveClass = ref.leaveActiveClass; + var beforeLeave = ref.beforeLeave; + var leave = ref.leave; + var afterLeave = ref.afterLeave; + var leaveCancelled = ref.leaveCancelled; + var delayLeave = ref.delayLeave; + var duration = ref.duration; var expectsCSS = css !== false && !isIE9; var userWantsControl = getHookArgumentsLength(leave); @@ -6188,9 +6427,11 @@ function isValidDuration (val) { * - a plain function (.length) */ function getHookArgumentsLength (fn) { - if (!fn) { return false } + if (isUndef(fn)) { + return false + } var invokerFns = fn.fns; - if (invokerFns) { + if (isDef(invokerFns)) { // invoker return getHookArgumentsLength( Array.isArray(invokerFns) @@ -6203,7 +6444,7 @@ function getHookArgumentsLength (fn) { } function _enter (_, vnode) { - if (!vnode.data.show) { + if (vnode.data.show !== true) { enter(vnode); } } @@ -6213,7 +6454,7 @@ var transition = inBrowser ? { activate: _enter, remove: function remove$$1 (vnode, rm) { /* istanbul ignore else */ - if (!vnode.data.show) { + if (vnode.data.show !== true) { leave(vnode, rm); } else { rm(); @@ -6268,6 +6509,11 @@ var model$1 = { } else if (vnode.tag === 'textarea' || el.type === 'text' || el.type === 'password') { el._vModifiers = binding.modifiers; if (!binding.modifiers.lazy) { + // Safari < 10.2 & UIWebView doesn't fire compositionend when + // switching focus before confirming composition choice + // this also fixes the issue where some browsers e.g. iOS Chrome + // fires "change" instead of "input" on autocomplete. + el.addEventListener('change', onCompositionEnd); if (!isAndroid) { el.addEventListener('compositionstart', onCompositionStart); el.addEventListener('compositionend', onCompositionEnd); @@ -6479,9 +6725,11 @@ function extractTransitionData (comp) { } function placeholder (h, rawChild) { - return /\d-keep-alive$/.test(rawChild.tag) - ? h('keep-alive') - : null + if (/\d-keep-alive$/.test(rawChild.tag)) { + return h('keep-alive', { + props: rawChild.componentOptions.propsData + }) + } } function hasParentTransition (vnode) { @@ -6777,20 +7025,21 @@ var platformComponents = { /* */ // install platform specific utils -Vue$2.config.mustUseProp = mustUseProp; -Vue$2.config.isReservedTag = isReservedTag; -Vue$2.config.getTagNamespace = getTagNamespace; -Vue$2.config.isUnknownElement = isUnknownElement; +Vue$3.config.mustUseProp = mustUseProp; +Vue$3.config.isReservedTag = isReservedTag; +Vue$3.config.isReservedAttr = isReservedAttr; +Vue$3.config.getTagNamespace = getTagNamespace; +Vue$3.config.isUnknownElement = isUnknownElement; // install platform runtime directives & components -extend(Vue$2.options.directives, platformDirectives); -extend(Vue$2.options.components, platformComponents); +extend(Vue$3.options.directives, platformDirectives); +extend(Vue$3.options.components, platformComponents); // install platform patch function -Vue$2.prototype.__patch__ = inBrowser ? patch : noop; +Vue$3.prototype.__patch__ = inBrowser ? patch : noop; // public mount method -Vue$2.prototype.$mount = function ( +Vue$3.prototype.$mount = function ( el, hydrating ) { @@ -6803,7 +7052,7 @@ Vue$2.prototype.$mount = function ( setTimeout(function () { if (config.devtools) { if (devtools) { - devtools.emit('init', Vue$2); + devtools.emit('init', Vue$3); } else if ("development" !== 'production' && isChrome) { console[console.info ? 'info' : 'log']( 'Download the Vue Devtools extension for a better development experience:\n' + @@ -6822,6 +7071,8 @@ setTimeout(function () { } }, 0); -return Vue$2; +/* */ + +return Vue$3; }))); diff --git a/dist/vue.runtime.min.js b/dist/vue.runtime.min.js index e2373c1c..cc08954b 100644 --- a/dist/vue.runtime.min.js +++ b/dist/vue.runtime.min.js @@ -1,7 +1,7 @@ /*! - * Vue.js v2.2.6 + * Vue.js v2.3.0-beta.1 * (c) 2014-2017 Evan You * Released under the MIT License. */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.Vue=e()}(this,function(){"use strict";function t(t){return null==t?"":"object"==typeof t?JSON.stringify(t,null,2):String(t)}function e(t){var e=parseFloat(t);return isNaN(e)?t:e}function n(t,e){for(var n=Object.create(null),r=t.split(","),o=0;o-1)return t.splice(n,1)}}function o(t,e){return Rn.call(t,e)}function i(t){return"string"==typeof t||"number"==typeof t}function a(t){var e=Object.create(null);return function(n){return e[n]||(e[n]=t(n))}}function s(t,e){function n(n){var r=arguments.length;return r?r>1?t.apply(e,arguments):t.call(e,n):t.call(e)}return n._length=t.length,n}function c(t,e){e=e||0;for(var n=t.length-e,r=new Array(n);n--;)r[n]=t[n+e];return r}function u(t,e){for(var n in e)t[n]=e[n];return t}function l(t){return null!==t&&"object"==typeof t}function f(t){return zn.call(t)===Fn}function p(t){for(var e={},n=0;n=0&&xr[n].id>t.id;)n--;xr.splice(Math.max(n,Tr)+1,0,t)}else xr.push(t);Sr||(Sr=!0,cr(dt))}}function ht(t){Dr.clear(),mt(t,Dr)}function mt(t,e){var n,r,o=Array.isArray(t);if((o||l(t))&&Object.isExtensible(t)){if(t.__ob__){var i=t.__ob__.dep.id;if(e.has(i))return;e.add(i)}if(o)for(n=t.length;n--;)mt(t[n],e);else for(r=Object.keys(t),n=r.length;n--;)mt(t[r[n]],e)}}function yt(t,e,n){Nr.get=function(){return this[e][n]},Nr.set=function(t){this[e][n]=t},Object.defineProperty(t,n,Nr)}function _t(t){t._watchers=[];var e=t.$options;e.props&>(t,e.props),e.methods&&kt(t,e.methods),e.data?bt(t):k(t._data={},!0),e.computed&&wt(t,e.computed),e.watch&&xt(t,e.watch)}function gt(t,e){var n=t.$options.propsData||{},r=t._props={},o=t.$options._propKeys=[],i=!t.$parent;mr.shouldConvert=i;for(var a in e)!function(i){o.push(i);var a=M(i,e,n,t);x(r,i,a),i in t||yt(t,"_props",i)}(a);mr.shouldConvert=!0}function bt(t){var e=t.$options.data;e=t._data="function"==typeof e?Ct(e,t):e||{},f(e)||(e={});for(var n=Object.keys(e),r=t.$options.props,i=n.length;i--;)r&&o(r,n[i])||y(n[i])||yt(t,"_data",n[i]);k(e,!0)}function Ct(t,e){try{return t.call(e)}catch(t){return B(t,e,"data()"),{}}}function wt(t,e){var n=t._computedWatchers=Object.create(null);for(var r in e){var o=e[r],i="function"==typeof o?o:o.get;n[r]=new jr(t,i,d,Lr),r in t||$t(t,r,o)}}function $t(t,e,n){"function"==typeof n?(Nr.get=At(e),Nr.set=d):(Nr.get=n.get?n.cache!==!1?At(e):n.get:d,Nr.set=n.set?n.set:d),Object.defineProperty(t,e,Nr)}function At(t){return function(){var e=this._computedWatchers&&this._computedWatchers[t];if(e)return e.dirty&&e.evaluate(),fr.target&&e.depend(),e.value}}function kt(t,e){t.$options.props;for(var n in e)t[n]=null==e[n]?d:s(e[n],t)}function xt(t,e){for(var n in e){var r=e[n];if(Array.isArray(r))for(var o=0;o-1:t instanceof RegExp&&t.test(e)}function fe(t,e){for(var n in t){var r=t[n];if(r){var o=ue(r.componentOptions);o&&!e(o)&&(pe(r),t[n]=null)}}}function pe(t){t&&(t.componentInstance._inactive||ft(t.componentInstance,"deactivated"),t.componentInstance.$destroy())}function de(t){for(var e=t.data,n=t,r=t;r.componentInstance;)r=r.componentInstance._vnode,r.data&&(e=ve(r.data,e));for(;n=n.parent;)n.data&&(e=ve(e,n.data));return he(e)}function ve(t,e){return{staticClass:me(t.staticClass,e.staticClass),class:t.class?[t.class,e.class]:e.class}}function he(t){var e=t.class,n=t.staticClass;return n||e?me(n,ye(e)):""}function me(t,e){return t?e?t+" "+e:t:e||""}function ye(t){var e="";if(!t)return e;if("string"==typeof t)return t;if(Array.isArray(t)){for(var n,r=0,o=t.length;r-1?oo[t]=e.constructor===window.HTMLUnknownElement||e.constructor===window.HTMLElement:oo[t]=/HTMLUnknownElement/.test(e.toString())}function be(t){if("string"==typeof t){var e=document.querySelector(t);return e?e:document.createElement("div")}return t}function Ce(t,e){var n=document.createElement(t);return"select"!==t?n:(e.data&&e.data.attrs&&void 0!==e.data.attrs.multiple&&n.setAttribute("multiple","multiple"),n)}function we(t,e){return document.createElementNS(to[t],e)}function $e(t){return document.createTextNode(t)}function Ae(t){return document.createComment(t)}function ke(t,e,n){t.insertBefore(e,n)}function xe(t,e){t.removeChild(e)}function Oe(t,e){t.appendChild(e)}function Se(t){return t.parentNode}function Ee(t){return t.nextSibling}function Te(t){return t.tagName}function Ie(t,e){t.textContent=e}function je(t,e,n){t.setAttribute(e,n)}function De(t,e){var n=t.data.ref;if(n){var o=t.context,i=t.componentInstance||t.elm,a=o.$refs;e?Array.isArray(a[n])?r(a[n],i):a[n]===i&&(a[n]=void 0):t.data.refInFor?Array.isArray(a[n])&&a[n].indexOf(i)<0?a[n].push(i):a[n]=[i]:a[n]=i}}function Ne(t){return void 0===t||null===t}function Le(t){return void 0!==t&&null!==t}function Pe(t){return t===!0}function Me(t,e){return t.key===e.key&&t.tag===e.tag&&t.isComment===e.isComment&&Le(t.data)===Le(e.data)&&Ue(t,e)}function Ue(t,e){if("input"!==t.tag)return!0;var n;return(Le(n=t.data)&&Le(n=n.attrs)&&n.type)===(Le(n=e.data)&&Le(n=n.attrs)&&n.type)}function Re(t,e,n){var r,o,i={};for(r=e;r<=n;++r)o=t[r].key,Le(o)&&(i[o]=r);return i}function Ve(t,e){(t.data.directives||e.data.directives)&&Be(t,e)}function Be(t,e){var n,r,o,i=t===so,a=e===so,s=He(t.data.directives,t.context),c=He(e.data.directives,e.context),u=[],l=[];for(n in c)r=s[n],o=c[n],r?(o.oldValue=r.value,Fe(o,"update",e,t),o.def&&o.def.componentUpdated&&l.push(o)):(Fe(o,"bind",e,t),o.def&&o.def.inserted&&u.push(o));if(u.length){var f=function(){for(var n=0;n-1?e.split(/\s+/).forEach(function(e){return t.classList.add(e)}):t.classList.add(e);else{var n=" "+(t.getAttribute("class")||"")+" ";n.indexOf(" "+e+" ")<0&&t.setAttribute("class",(n+e).trim())}}function cn(t,e){if(e&&(e=e.trim()))if(t.classList)e.indexOf(" ")>-1?e.split(/\s+/).forEach(function(e){return t.classList.remove(e)}):t.classList.remove(e);else{for(var n=" "+(t.getAttribute("class")||"")+" ",r=" "+e+" ";n.indexOf(r)>=0;)n=n.replace(r," ");t.setAttribute("class",n.trim())}}function un(t){if(t){if("object"==typeof t){var e={};return t.css!==!1&&u(e,xo(t.name||"v")),u(e,t),e}return"string"==typeof t?xo(t):void 0}}function ln(t){No(function(){No(t)})}function fn(t,e){(t._transitionClasses||(t._transitionClasses=[])).push(e),sn(t,e)}function pn(t,e){t._transitionClasses&&r(t._transitionClasses,e),cn(t,e)}function dn(t,e,n){var r=vn(t,e),o=r.type,i=r.timeout,a=r.propCount;if(!o)return n();var s=o===So?Io:Do,c=0,u=function(){t.removeEventListener(s,l),n()},l=function(e){e.target===t&&++c>=a&&u()};setTimeout(function(){c0&&(n=So,l=a,f=i.length):e===Eo?u>0&&(n=Eo,l=u,f=c.length):(l=Math.max(a,u),n=l>0?a>u?So:Eo:null,f=n?n===So?i.length:c.length:0),{type:n,timeout:l,propCount:f,hasTransform:n===So&&Lo.test(r[To+"Property"])}}function hn(t,e){for(;t.length1}function Cn(t,e){e.data.show||yn(e)}function wn(t,e,n){var r=e.value,o=t.multiple;if(!o||Array.isArray(r)){for(var i,a,s=0,c=t.options.length;s-1,a.selected!==i&&(a.selected=i);else if(v(An(a),r))return void(t.selectedIndex!==s&&(t.selectedIndex=s));o||(t.selectedIndex=-1)}}function $n(t,e){for(var n=0,r=e.length;n0,er=Xn&&Xn.indexOf("edge/")>0,nr=Xn&&Xn.indexOf("android")>0,rr=Xn&&/iphone|ipad|ipod|ios/.test(Xn),or=Xn&&/chrome\/\d+/.test(Xn)&&!er,ir=function(){return void 0===Mn&&(Mn=!Qn&&"undefined"!=typeof global&&"server"===global.process.env.VUE_ENV),Mn},ar=Qn&&window.__VUE_DEVTOOLS_GLOBAL_HOOK__,sr="undefined"!=typeof Symbol&&b(Symbol)&&"undefined"!=typeof Reflect&&b(Reflect.ownKeys),cr=function(){function t(){r=!1;var t=n.slice(0);n.length=0;for(var e=0;e1?c(n):n;for(var r=c(arguments,1),o=0,i=n.length;o1&&(e[n[0].trim()]=n[1].trim())}}),e}),bo=/^--/,Co=/\s*!important$/,wo=function(t,e,n){bo.test(e)?t.style.setProperty(e,n):Co.test(n)?t.style.setProperty(e,n.replace(Co,""),"important"):t.style[Ao(e)]=n},$o=["Webkit","Moz","ms"],Ao=a(function(t){if(qr=qr||document.createElement("div"),"filter"!==(t=Vn(t))&&t in qr.style)return t;for(var e=t.charAt(0).toUpperCase()+t.slice(1),n=0;n<$o.length;n++){var r=$o[n]+e;if(r in qr.style)return r}}),ko={create:an,update:an},xo=a(function(t){return{enterClass:t+"-enter",enterToClass:t+"-enter-to",enterActiveClass:t+"-enter-active",leaveClass:t+"-leave",leaveToClass:t+"-leave-to",leaveActiveClass:t+"-leave-active"}}),Oo=Qn&&!tr,So="transition",Eo="animation",To="transition",Io="transitionend",jo="animation",Do="animationend";Oo&&(void 0===window.ontransitionend&&void 0!==window.onwebkittransitionend&&(To="WebkitTransition",Io="webkitTransitionEnd"),void 0===window.onanimationend&&void 0!==window.onwebkitanimationend&&(jo="WebkitAnimation",Do="webkitAnimationEnd"));var No=Qn&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):setTimeout,Lo=/\b(transform|all)(,|$)/,Po=Qn?{create:Cn,activate:Cn,remove:function(t,e){t.data.show?e():_n(t,e)}}:{},Mo=[po,vo,yo,_o,ko,Po],Uo=Mo.concat(fo),Ro=function(t){function e(t){return new br(O.tagName(t).toLowerCase(),{},[],void 0,t)}function r(t,e){function n(){0==--n.listeners&&o(t)}return n.listeners=e,n}function o(t){var e=O.parentNode(t);Le(e)&&O.removeChild(e,t)}function a(t,e,n,r,o){if(t.isRootInsert=!o,!s(t,e,n,r)){var i=t.data,a=t.children,c=t.tag;Le(c)?(t.elm=t.ns?O.createElementNS(t.ns,c):O.createElement(c,t),v(t),f(t,a,e),Le(i)&&d(t,e),l(n,t.elm,r)):Pe(t.isComment)?(t.elm=O.createComment(t.text),l(n,t.elm,r)):(t.elm=O.createTextNode(t.text),l(n,t.elm,r))}}function s(t,e,n,r){var o=t.data;if(Le(o)){var i=Le(t.componentInstance)&&o.keepAlive;if(Le(o=o.hook)&&Le(o=o.init)&&o(t,!1,n,r),Le(t.componentInstance))return c(t,e),Pe(i)&&u(t,e,n,r),!0}}function c(t,e){Le(t.data.pendingInsert)&&e.push.apply(e,t.data.pendingInsert),t.elm=t.componentInstance.$el,p(t)?(d(t,e),v(t)):(De(t),e.push(t))}function u(t,e,n,r){for(var o,i=t;i.componentInstance;)if(i=i.componentInstance._vnode,Le(o=i.data)&&Le(o=o.transition)){for(o=0;op?(u=Ne(n[m+1])?null:n[m+1].elm,h(t,u,n,f,m,r)):f>m&&y(t,e,l,p)}function b(t,e,n,r){if(t!==e){if(Pe(e.isStatic)&&Pe(t.isStatic)&&e.key===t.key&&(Pe(e.isCloned)||Pe(e.isOnce)))return e.elm=t.elm,void(e.componentInstance=t.componentInstance);var o,i=e.data;Le(i)&&Le(o=i.hook)&&Le(o=o.prepatch)&&o(t,e);var a=e.elm=t.elm,s=t.children,c=e.children;if(Le(i)&&p(e)){for(o=0;o-1)return t.splice(n,1)}}function f(t,e){return Wn.call(t,e)}function p(t){var e=Object.create(null);return function(n){return e[n]||(e[n]=t(n))}}function d(t,e){function n(n){var r=arguments.length;return r?r>1?t.apply(e,arguments):t.call(e,n):t.call(e)}return n._length=t.length,n}function v(t,e){e=e||0;for(var n=t.length-e,r=new Array(n);n--;)r[n]=t[n+e];return r}function h(t,e){for(var n in e)t[n]=e[n];return t}function m(t){for(var e={},n=0;n=0&&Mr[n].id>t.id;)n--;Mr.splice(Math.max(n,zr)+1,0,t)}else Mr.push(t);Vr||(Vr=!0,br(Ct))}}function kt(t){Wr.clear(),Ot(t,Wr)}function Ot(t,e){var n,r,i=Array.isArray(t);if((i||o(t))&&Object.isExtensible(t)){if(t.__ob__){var a=t.__ob__.dep.id;if(e.has(a))return;e.add(a)}if(i)for(n=t.length;n--;)Ot(t[n],e);else for(r=Object.keys(t),n=r.length;n--;)Ot(t[r[n]],e)}}function St(t,e,n){qr.get=function(){return this[e][n]},qr.set=function(t){this[e][n]=t},Object.defineProperty(t,n,qr)}function Et(t){t._watchers=[];var e=t.$options;e.props&&jt(t,e.props),e.methods&&Pt(t,e.methods),e.data?Tt(t):j(t._data={},!0),e.computed&&Dt(t,e.computed),e.watch&&Mt(t,e.watch)}function jt(t,e){var n=t.$options.propsData||{},r=t._props={},o=t.$options._propKeys=[],i=!t.$parent;Or.shouldConvert=i;for(var a in e)!function(i){o.push(i);var a=z(i,e,n,t);T(r,i,a),i in t||St(t,"_props",i)}(a);Or.shouldConvert=!0}function Tt(t){var e=t.$options.data;e=t._data="function"==typeof e?It(e,t):e||{},i(e)||(e={});for(var n=Object.keys(e),r=t.$options.props,o=n.length;o--;)r&&f(r,n[o])||C(n[o])||St(t,"_data",n[o]);j(e,!0)}function It(t,e){try{return t.call(e)}catch(t){return $(t,e,"data()"),{}}}function Dt(t,e){var n=t._computedWatchers=Object.create(null);for(var r in e){var o=e[r],i="function"==typeof o?o:o.get;n[r]=new Fr(t,i,y,Kr),r in t||Nt(t,r,o)}}function Nt(t,e,n){"function"==typeof n?(qr.get=Lt(e),qr.set=y):(qr.get=n.get?!1!==n.cache?Lt(e):n.get:y,qr.set=n.set?n.set:y),Object.defineProperty(t,e,qr)}function Lt(t){return function(){var e=this._computedWatchers&&this._computedWatchers[t];if(e)return e.dirty&&e.evaluate(),wr.target&&e.depend(),e.value}}function Pt(t,e){t.$options.props;for(var n in e)t[n]=null==e[n]?y:d(e[n],t)}function Mt(t,e){for(var n in e){var r=e[n];if(Array.isArray(r))for(var o=0;o=0||n.indexOf(t[o])<0)&&r.push(t[o]);return r}return t}function pe(t){this._init(t)}function de(t){t.use=function(t){if(!t.installed){var e=v(arguments,1);return e.unshift(this),"function"==typeof t.install?t.install.apply(t,e):"function"==typeof t&&t.apply(null,e),t.installed=!0,this}}}function ve(t){t.mixin=function(t){this.options=V(this.options,t)}}function he(t){t.cid=0;var e=1;t.extend=function(t){t=t||{};var n=this,r=n.cid,o=t._Ctor||(t._Ctor={});if(o[r])return o[r];var i=t.name||n.options.name,a=function(t){this._init(t)};return a.prototype=Object.create(n.prototype),a.prototype.constructor=a,a.cid=e++,a.options=V(n.options,t),a.super=n,a.options.props&&me(a),a.options.computed&&ye(a),a.extend=n.extend,a.mixin=n.mixin,a.use=n.use,Xn.forEach(function(t){a[t]=n[t]}),i&&(a.options.components[i]=a),a.superOptions=n.options,a.extendOptions=t,a.sealedOptions=h({},a.options),o[r]=a,a}}function me(t){var e=t.options.props;for(var n in e)St(t.prototype,"_props",n)}function ye(t){var e=t.options.computed;for(var n in e)Nt(t.prototype,n,e[n])}function _e(t){Xn.forEach(function(e){t[e]=function(t,n){return n?("component"===e&&i(n)&&(n.name=n.name||t,n=this.options._base.extend(n)),"directive"===e&&"function"==typeof n&&(n={bind:n,update:n}),this.options[e+"s"][t]=n,n):this.options[e+"s"][t]}})}function ge(t){return t&&(t.Ctor.options.name||t.tag)}function be(t,e){return"string"==typeof t?t.split(",").indexOf(e)>-1:!!a(t)&&t.test(e)}function Ce(t,e,n){for(var r in t){var o=t[r];if(o){var i=ge(o.componentOptions);i&&!n(i)&&(o!==e&&we(o),t[r]=null)}}}function we(t){t&&t.componentInstance.$destroy()}function Ae(t){for(var n=t.data,r=t,o=t;e(o.componentInstance);)o=o.componentInstance._vnode,o.data&&(n=$e(o.data,n));for(;e(r=r.parent);)r.data&&(n=$e(n,r.data));return xe(n)}function $e(t,n){return{staticClass:ke(t.staticClass,n.staticClass),class:e(t.class)?[t.class,n.class]:n.class}}function xe(t){var n=t.class,r=t.staticClass;return e(r)||e(n)?ke(r,Oe(n)):""}function ke(t,e){return t?e?t+" "+e:t:e||""}function Oe(n){if(t(n))return"";if("string"==typeof n)return n;var r="";if(Array.isArray(n)){for(var i,a=0,s=n.length;a-1?_o[t]=e.constructor===window.HTMLUnknownElement||e.constructor===window.HTMLElement:_o[t]=/HTMLUnknownElement/.test(e.toString())}function je(t){if("string"==typeof t){var e=document.querySelector(t);return e||document.createElement("div")}return t}function Te(t,e){var n=document.createElement(t);return"select"!==t?n:(e.data&&e.data.attrs&&void 0!==e.data.attrs.multiple&&n.setAttribute("multiple","multiple"),n)}function Ie(t,e){return document.createElementNS(vo[t],e)}function De(t){return document.createTextNode(t)}function Ne(t){return document.createComment(t)}function Le(t,e,n){t.insertBefore(e,n)}function Pe(t,e){t.removeChild(e)}function Me(t,e){t.appendChild(e)}function Re(t){return t.parentNode}function Ue(t){return t.nextSibling}function Ve(t){return t.tagName}function Be(t,e){t.textContent=e}function ze(t,e,n){t.setAttribute(e,n)}function He(t,e){var n=t.data.ref;if(n){var r=t.context,o=t.componentInstance||t.elm,i=r.$refs;e?Array.isArray(i[n])?l(i[n],o):i[n]===o&&(i[n]=void 0):t.data.refInFor?Array.isArray(i[n])&&i[n].indexOf(o)<0?i[n].push(o):i[n]=[o]:i[n]=o}}function Fe(t,n){return t.key===n.key&&t.tag===n.tag&&t.isComment===n.isComment&&e(t.data)===e(n.data)&&We(t,n)}function We(t,n){if("input"!==t.tag)return!0;var r;return(e(r=t.data)&&e(r=r.attrs)&&r.type)===(e(r=n.data)&&e(r=r.attrs)&&r.type)}function qe(t,n,r){var o,i,a={};for(o=n;o<=r;++o)i=t[o].key,e(i)&&(a[i]=o);return a}function Ke(t,e){(t.data.directives||e.data.directives)&&Je(t,e)}function Je(t,e){var n,r,o,i=t===Co,a=e===Co,s=Ge(t.data.directives,t.context),c=Ge(e.data.directives,e.context),u=[],l=[];for(n in c)r=s[n],o=c[n],r?(o.oldValue=r.value,Qe(o,"update",e,t),o.def&&o.def.componentUpdated&&l.push(o)):(Qe(o,"bind",e,t),o.def&&o.def.inserted&&u.push(o));if(u.length){var f=function(){for(var n=0;n-1?e.split(/\s+/).forEach(function(e){return t.classList.add(e)}):t.classList.add(e);else{var n=" "+(t.getAttribute("class")||"")+" ";n.indexOf(" "+e+" ")<0&&t.setAttribute("class",(n+e).trim())}}function hn(t,e){if(e&&(e=e.trim()))if(t.classList)e.indexOf(" ")>-1?e.split(/\s+/).forEach(function(e){return t.classList.remove(e)}):t.classList.remove(e);else{for(var n=" "+(t.getAttribute("class")||"")+" ",r=" "+e+" ";n.indexOf(r)>=0;)n=n.replace(r," ");t.setAttribute("class",n.trim())}}function mn(t){if(t){if("object"==typeof t){var e={};return!1!==t.css&&h(e,Uo(t.name||"v")),h(e,t),e}return"string"==typeof t?Uo(t):void 0}}function yn(t){Ko(function(){Ko(t)})}function _n(t,e){(t._transitionClasses||(t._transitionClasses=[])).push(e),vn(t,e)}function gn(t,e){t._transitionClasses&&l(t._transitionClasses,e),hn(t,e)}function bn(t,e,n){var r=Cn(t,e),o=r.type,i=r.timeout,a=r.propCount;if(!o)return n();var s=o===Bo?Fo:qo,c=0,u=function(){t.removeEventListener(s,l),n()},l=function(e){e.target===t&&++c>=a&&u()};setTimeout(function(){c0&&(n=Bo,l=a,f=i.length):e===zo?u>0&&(n=zo,l=u,f=c.length):(l=Math.max(a,u),n=l>0?a>u?Bo:zo:null,f=n?n===Bo?i.length:c.length:0),{type:n,timeout:l,propCount:f,hasTransform:n===Bo&&Jo.test(r[Ho+"Property"])}}function wn(t,e){for(;t.length1}function Sn(t,e){!0!==e.data.show&&$n(e)}function En(t,e,n){var r=e.value,o=t.multiple;if(!o||Array.isArray(r)){for(var i,a,s=0,c=t.options.length;s-1,a.selected!==i&&(a.selected=i);else if(_(Tn(a),r))return void(t.selectedIndex!==s&&(t.selectedIndex=s));o||(t.selectedIndex=-1)}}function jn(t,e){for(var n=0,r=e.length;n0,ur=ar&&ar.indexOf("edge/")>0,lr=ar&&ar.indexOf("android")>0,fr=ar&&/iphone|ipad|ipod|ios/.test(ar),pr=ar&&/chrome\/\d+/.test(ar)&&!ur,dr=!1;if(ir)try{var vr={};Object.defineProperty(vr,"passive",{get:function(){dr=!0}}),window.addEventListener("test-passive",null,vr)}catch(t){}var hr,mr,yr=function(){return void 0===hr&&(hr=!ir&&"undefined"!=typeof global&&"server"===global.process.env.VUE_ENV),hr},_r=ir&&window.__VUE_DEVTOOLS_GLOBAL_HOOK__,gr="undefined"!=typeof Symbol&&x(Symbol)&&"undefined"!=typeof Reflect&&x(Reflect.ownKeys),br=function(){function t(){r=!1;var t=n.slice(0);n.length=0;for(var e=0;e1?v(n):n;for(var r=v(arguments,1),o=0,i=n.length;o1&&(e[n[0].trim()]=n[1].trim())}}),e}),Do=/^--/,No=/\s*!important$/,Lo=function(t,e,n){if(Do.test(e))t.style.setProperty(e,n);else if(No.test(n))t.style.setProperty(e,n.replace(No,""),"important");else{var r=Mo(e);if(Array.isArray(n))for(var o=0,i=n.length;ov?(f=t(o[y+1])?null:o[y+1].elm,_(n,f,o,d,y,i)):d>y&&b(n,r,p,v)}function A(r,o,i,a){if(r!==o){if(n(o.isStatic)&&n(r.isStatic)&&o.key===r.key&&(n(o.isCloned)||n(o.isOnce)))return o.elm=r.elm,void(o.componentInstance=r.componentInstance);var s,c=o.data;e(c)&&e(s=c.hook)&&e(s=s.prepatch)&&s(r,o);var u=o.elm=r.elm,l=r.children,f=o.children;if(e(c)&&h(o)){for(s=0;s= MAX_STACK_DEPTH) { - process.nextTick(function () { - try { next(); } catch (e) { - onError(e); - } - }); - } else { - stackDepth++; - next(); - stackDepth--; - } - } - }; - cachedWrite.caching = false; - cachedWrite.cacheBuffer = []; - return cachedWrite +// these helpers produces better vm code in JS engines due to their +// explicitness and function inlining +function isUndef (v) { + return v === undefined || v === null } -/* */ +function isDef (v) { + return v !== undefined && v !== null +} + +function isTrue (v) { + return v === true +} /** - * Original RenderStream implementation by Sasha Aickin (@aickin) - * Licensed under the Apache License, Version 2.0 - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Modified by Evan You (@yyx990803) + * Check if value is primitive */ -var stream = require('stream'); -var RenderStream = (function (superclass) { - function RenderStream (render) { - var this$1 = this; - - superclass.call(this); - this.buffer = ''; - this.render = render; - this.expectedSize = 0; - - this.write = createWriteFunction(function (text, next) { - var n = this$1.expectedSize; - this$1.buffer += text; - if (this$1.buffer.length >= n) { - this$1.next = next; - this$1.pushBySize(n); - return true // we will decide when to call next - } - }, function (err) { - this$1.emit('error', err); - }); - - this.end = function () { - // the rendering is finished; we should push out the last of the buffer. - this$1.done = true; - this$1.push(this$1.buffer); - }; - } - - if ( superclass ) RenderStream.__proto__ = superclass; - RenderStream.prototype = Object.create( superclass && superclass.prototype ); - RenderStream.prototype.constructor = RenderStream; - - RenderStream.prototype.pushBySize = function pushBySize (n) { - var bufferToPush = this.buffer.substring(0, n); - this.buffer = this.buffer.substring(n); - this.push(bufferToPush); - }; - - RenderStream.prototype.tryRender = function tryRender () { - try { - this.render(this.write, this.end); - } catch (e) { - this.emit('error', e); - } - }; - - RenderStream.prototype.tryNext = function tryNext () { - try { - this.next(); - } catch (e) { - this.emit('error', e); - } - }; - - RenderStream.prototype._read = function _read (n) { - this.expectedSize = n; - // it's possible that the last chunk added bumped the buffer up to > 2 * n, - // which means we will need to go through multiple read calls to drain it - // down to < n. - if (this.done) { - this.push(null); - return - } - if (this.buffer.length >= n) { - this.pushBySize(n); - return - } - if (!this.next) { - // start the rendering chain. - this.tryRender(); - } else { - // continue with the rendering. - this.tryNext(); - } - }; - - return RenderStream; -}(stream.Readable)); - -/* */ - - - -var RenderContext = function RenderContext (options) { - this.activeInstance = options.activeInstance; - this.renderStates = []; - - this.write = options.write; - this.done = options.done; - this.renderNode = options.renderNode; - - this.isUnaryTag = options.isUnaryTag; - this.modules = options.modules; - this.directives = options.directives; - - var cache = options.cache; - if (cache && (!cache.get || !cache.set)) { - throw new Error('renderer cache must implement at least get & set.') - } - this.cache = cache; - this.get = cache && normalizeAsync(cache, 'get'); - this.has = cache && normalizeAsync(cache, 'has'); - - this.next = this.next.bind(this); -}; - -RenderContext.prototype.next = function next () { - var lastState = this.renderStates[this.renderStates.length - 1]; - if (!lastState) { - return this.done() - } - switch (lastState.type) { - case 'Element': - var children = lastState.children; - var total = lastState.total; - var rendered = lastState.rendered++; - if (rendered < total) { - this.renderNode(children[rendered], false, this); - } else { - this.renderStates.pop(); - this.write(lastState.endTag, this.next); - } - break - case 'Component': - this.renderStates.pop(); - this.activeInstance = lastState.prevActive; - this.next(); - break - case 'ComponentWithCache': - this.renderStates.pop(); - var buffer = lastState.buffer; - var bufferIndex = lastState.bufferIndex; - var key = lastState.key; - var result = buffer[bufferIndex]; - this.cache.set(key, result); - if (bufferIndex === 0) { - // this is a top-level cached component, - // exit caching mode. - this.write.caching = false; - } else { - // parent component is also being cached, - // merge self into parent's result - buffer[bufferIndex - 1] += result; - } - buffer.length = bufferIndex; - this.next(); - break - } -}; - -function normalizeAsync (cache, method) { - var fn = cache[method]; - if (!fn) { - return - } else if (fn.length > 1) { - return function (key, cb) { return fn.call(cache, key, cb); } - } else { - return function (key, cb) { return cb(fn.call(cache, key)); } - } +/** + * Quick object check - this is primarily used to tell + * Objects from primitive values when we know the value + * is a JSON-compliant type. + */ +function isObject (obj) { + return obj !== null && typeof obj === 'object' } -/* */ +var toString = Object.prototype.toString; + +/** + * Strict object type check. Only returns true + * for plain JavaScript objects. + */ +function isPlainObject (obj) { + return toString.call(obj) === '[object Object]' +} + + /** * Convert a value to a string that is actually rendered. */ -function _toString (val) { - return val == null - ? '' - : typeof val === 'object' - ? JSON.stringify(val, null, 2) - : String(val) -} + /** * Convert a input value to a number for persistence. * If the conversion fails, return original string. */ -function toNumber (val) { - var n = parseFloat(val); - return isNaN(n) ? val : n -} + /** * Make a map and return a function for checking if a key @@ -275,13 +100,6 @@ function hasOwn (obj, key) { return hasOwnProperty.call(obj, key) } -/** - * Check if value is primitive - */ -function isPrimitive (value) { - return typeof value === 'string' || typeof value === 'number' -} - /** * Create a cached version of a pure function. */ @@ -304,9 +122,7 @@ var camelize = cached(function (str) { /** * Capitalize a string. */ -var capitalize = cached(function (str) { - return str.charAt(0).toUpperCase() + str.slice(1) -}); + /** * Hyphenate a camelCase string. @@ -322,32 +138,12 @@ var hyphenate = cached(function (str) { /** * Simple bind, faster than native */ -function bind (fn, ctx) { - function boundFn (a) { - var l = arguments.length; - return l - ? l > 1 - ? fn.apply(ctx, arguments) - : fn.call(ctx, a) - : fn.call(ctx) - } - // record original fn length - boundFn._length = fn.length; - return boundFn -} + /** * Convert an Array-like object to a real Array. */ -function toArray (list, start) { - start = start || 0; - var i = list.length - start; - var ret = new Array(i); - while (i--) { - ret[i] = list[i + start]; - } - return ret -} + /** * Mix properties into target object. @@ -359,25 +155,6 @@ function extend (to, _from) { return to } -/** - * Quick object check - this is primarily used to tell - * Objects from primitive values when we know the value - * is a JSON-compliant type. - */ -function isObject (obj) { - return obj !== null && typeof obj === 'object' -} - -/** - * Strict object type check. Only returns true - * for plain JavaScript objects. - */ -var toString = Object.prototype.toString; -var OBJECT_STRING = '[object Object]'; -function isPlainObject (obj) { - return toString.call(obj) === OBJECT_STRING -} - /** * Merge an Array of Objects into a single Object. */ @@ -419,29 +196,9 @@ function genStaticKeys (modules) { * Check if two values are loosely equal - that is, * if they are plain objects, do they have the same shape? */ -function looseEqual (a, b) { - var isObjectA = isObject(a); - var isObjectB = isObject(b); - if (isObjectA && isObjectB) { - try { - return JSON.stringify(a) === JSON.stringify(b) - } catch (e) { - // possible circular reference - return a === b - } - } else if (!isObjectA && !isObjectB) { - return String(a) === String(b) - } else { - return false - } -} -function looseIndexOf (arr, val) { - for (var i = 0; i < arr.length; i++) { - if (looseEqual(arr[i], val)) { return i } - } - return -1 -} + + /** * Ensure a function is called only once. @@ -449,6 +206,1393 @@ function looseIndexOf (arr, val) { /* */ +// these are reserved for web because they are directly compiled away +// during template compilation +var isReservedAttr = makeMap('style,class'); + +// attributes that should be using props for binding +var acceptValue = makeMap('input,textarea,option,select'); +var mustUseProp = function (tag, type, attr) { + return ( + (attr === 'value' && acceptValue(tag)) && type !== 'button' || + (attr === 'selected' && tag === 'option') || + (attr === 'checked' && tag === 'input') || + (attr === 'muted' && tag === 'video') + ) +}; + +var isEnumeratedAttr = makeMap('contenteditable,draggable,spellcheck'); + +var isBooleanAttr = makeMap( + 'allowfullscreen,async,autofocus,autoplay,checked,compact,controls,declare,' + + 'default,defaultchecked,defaultmuted,defaultselected,defer,disabled,' + + 'enabled,formnovalidate,hidden,indeterminate,inert,ismap,itemscope,loop,multiple,' + + 'muted,nohref,noresize,noshade,novalidate,nowrap,open,pauseonexit,readonly,' + + 'required,reversed,scoped,seamless,selected,sortable,translate,' + + 'truespeed,typemustmatch,visible' +); + + + + + + + +var isFalsyAttrValue = function (val) { + return val == null || val === false +}; + +/* */ + +function renderAttrs (node) { + var attrs = node.data.attrs; + var res = ''; + + var parent = node.parent; + while (isDef(parent)) { + if (isDef(parent.data) && isDef(parent.data.attrs)) { + attrs = Object.assign({}, attrs, parent.data.attrs); + } + parent = parent.parent; + } + + if (isUndef(attrs)) { + return res + } + + for (var key in attrs) { + if (key === 'style') { + // leave it to the style module + continue + } + res += renderAttr(key, attrs[key]); + } + return res +} + +function renderAttr (key, value) { + if (isBooleanAttr(key)) { + if (!isFalsyAttrValue(value)) { + return (" " + key + "=\"" + key + "\"") + } + } else if (isEnumeratedAttr(key)) { + return (" " + key + "=\"" + (isFalsyAttrValue(value) || value === 'false' ? 'false' : 'true') + "\"") + } else if (!isFalsyAttrValue(value)) { + return (" " + key + "=\"" + (typeof value === 'string' ? he.escape(value) : value) + "\"") + } + return '' +} + +/* */ + +var VNode = function VNode ( + tag, + data, + children, + text, + elm, + context, + componentOptions +) { + 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; +}; + +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 ); + + + + + +// 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. + +/* */ + +var isAttr = makeMap( + 'accept,accept-charset,accesskey,action,align,alt,async,autocomplete,' + + 'autofocus,autoplay,autosave,bgcolor,border,buffered,challenge,charset,' + + 'checked,cite,class,code,codebase,color,cols,colspan,content,http-equiv,' + + 'name,contenteditable,contextmenu,controls,coords,data,datetime,default,' + + 'defer,dir,dirname,disabled,download,draggable,dropzone,enctype,method,for,' + + 'form,formaction,headers,height,hidden,high,href,hreflang,http-equiv,' + + 'icon,id,ismap,itemprop,keytype,kind,label,lang,language,list,loop,low,' + + 'manifest,max,maxlength,media,method,GET,POST,min,multiple,email,file,' + + 'muted,name,novalidate,open,optimum,pattern,ping,placeholder,poster,' + + 'preload,radiogroup,readonly,rel,required,reversed,rows,rowspan,sandbox,' + + 'scope,scoped,seamless,selected,shape,size,type,text,password,sizes,span,' + + 'spellcheck,src,srcdoc,srclang,srcset,start,step,style,summary,tabindex,' + + 'target,title,type,usemap,value,width,wrap' +); + +/* istanbul ignore next */ +var isRenderableAttr = function (name) { + return ( + isAttr(name) || + name.indexOf('data-') === 0 || + name.indexOf('aria-') === 0 + ) +}; +var propsToAttrMap = { + acceptCharset: 'accept-charset', + className: 'class', + htmlFor: 'for', + httpEquiv: 'http-equiv' +}; + +/* */ + +function renderDOMProps (node) { + var props = node.data.domProps; + var res = ''; + + var parent = node.parent; + while (isDef(parent)) { + if (parent.data && parent.data.domProps) { + props = Object.assign({}, props, parent.data.domProps); + } + parent = parent.parent; + } + + if (isUndef(props)) { + return res + } + + var attrs = node.data.attrs; + for (var key in props) { + if (key === 'innerHTML') { + setText(node, props[key], true); + } else if (key === 'textContent') { + setText(node, props[key], false); + } else { + var attr = propsToAttrMap[key] || key.toLowerCase(); + if (isRenderableAttr(attr) && + // avoid rendering double-bound props/attrs twice + !(isDef(attrs) && isDef(attrs[attr]))) { + res += renderAttr(attr, props[key]); + } + } + } + return res +} + +function setText (node, text, raw) { + var child = new VNode(undefined, undefined, undefined, text); + child.raw = raw; + node.children = [child]; +} + +/* */ + +var emptyObject = Object.freeze({}); + +/** + * Check if a string starts with $ or _ + */ +function isReserved (str) { + var c = (str + '').charCodeAt(0); + return c === 0x24 || c === 0x5F +} + +/** + * Define a property. + */ +function def (obj, key, val, enumerable) { + Object.defineProperty(obj, key, { + value: val, + enumerable: !!enumerable, + writable: true, + configurable: true + }); +} + +/** + * Parse simple path. + */ +var bailRE = /[^\w.$]/; +function parsePath (path) { + if (bailRE.test(path)) { + return + } + var segments = path.split('.'); + return function (obj) { + for (var i = 0; i < segments.length; i++) { + if (!obj) { return } + obj = obj[segments[i]]; + } + return obj + } +} + +var SSR_ATTR = 'data-server-rendered'; + +var ASSET_TYPES = [ + 'component', + 'directive', + 'filter' +]; + +var LIFECYCLE_HOOKS = [ + 'beforeCreate', + 'created', + 'beforeMount', + 'mounted', + 'beforeUpdate', + 'updated', + 'beforeDestroy', + 'destroyed', + 'activated', + 'deactivated' +]; + +/* */ + +var config = ({ + /** + * Option merge strategies (used in core/util/options) + */ + optionMergeStrategies: Object.create(null), + + /** + * Whether to suppress warnings. + */ + silent: false, + + /** + * Show production mode tip message on boot? + */ + productionTip: process.env.NODE_ENV !== 'production', + + /** + * Whether to enable devtools + */ + devtools: process.env.NODE_ENV !== 'production', + + /** + * Whether to record perf + */ + performance: false, + + /** + * Error handler for watcher errors + */ + errorHandler: null, + + /** + * Ignore certain custom elements + */ + ignoredElements: [], + + /** + * Custom user key aliases for v-on + */ + keyCodes: Object.create(null), + + /** + * Check if a tag is reserved so that it cannot be registered as a + * component. This is platform-dependent and may be overwritten. + */ + isReservedTag: no, + + /** + * Check if an attribute is reserved so that it cannot be used as a component + * prop. This is platform-dependent and may be overwritten. + */ + isReservedAttr: no, + + /** + * Check if a tag is an unknown element. + * Platform-dependent. + */ + isUnknownElement: no, + + /** + * Get the namespace of an element + */ + getTagNamespace: noop, + + /** + * Parse the real tag name for the specific platform. + */ + parsePlatformTagName: identity, + + /** + * Check if an attribute must be bound using property, e.g. value + * Platform-dependent. + */ + mustUseProp: no, + + /** + * Exposed for legacy reasons + */ + _lifecycleHooks: LIFECYCLE_HOOKS +}); + +var warn = noop; +var tip = noop; +var formatComponentName; + +if (process.env.NODE_ENV !== 'production') { + var hasConsole = typeof console !== 'undefined'; + var classifyRE = /(?:^|[-_])(\w)/g; + var classify = function (str) { return str + .replace(classifyRE, function (c) { return c.toUpperCase(); }) + .replace(/[-_]/g, ''); }; + + warn = function (msg, vm) { + if (hasConsole && (!config.silent)) { + console.error("[Vue warn]: " + msg + ( + vm ? generateComponentTrace(vm) : '' + )); + } + }; + + tip = function (msg, vm) { + if (hasConsole && (!config.silent)) { + console.warn("[Vue tip]: " + msg + ( + vm ? generateComponentTrace(vm) : '' + )); + } + }; + + formatComponentName = function (vm, includeFile) { + 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; + if (!name && file) { + var match = file.match(/([^/\\]+)\.vue$/); + name = match && match[1]; + } + + return ( + (name ? ("<" + (classify(name)) + ">") : "") + + (file && includeFile !== false ? (" at " + file) : '') + ) + }; + + var repeat = function (str, n) { + var res = ''; + while (n) { + if (n % 2 === 1) { res += str; } + if (n > 1) { str += str; } + n >>= 1; + } + return res + }; + + var generateComponentTrace = function (vm) { + if (vm._isVue && vm.$parent) { + var tree = []; + var currentRecursiveSequence = 0; + while (vm) { + if (tree.length > 0) { + var last = tree[tree.length - 1]; + if (last.constructor === vm.constructor) { + currentRecursiveSequence++; + vm = vm.$parent; + continue + } else if (currentRecursiveSequence > 0) { + tree[tree.length - 1] = [last, currentRecursiveSequence]; + currentRecursiveSequence = 0; + } + } + tree.push(vm); + vm = vm.$parent; + } + return '\n\nfound in\n\n' + tree + .map(function (vm, i) { return ("" + (i === 0 ? '---> ' : repeat(' ', 5 + i * 2)) + (Array.isArray(vm) + ? ((formatComponentName(vm[0])) + "... (" + (vm[1]) + " recursive calls)") + : formatComponentName(vm))); }) + .join('\n') + } else { + return ("\n\n(found in " + (formatComponentName(vm)) + ")") + } + }; +} + +function handleError (err, vm, info) { + if (config.errorHandler) { + config.errorHandler.call(null, err, vm, info); + } else { + if (process.env.NODE_ENV !== 'production') { + warn(("Error in " + info + ": \"" + (err.toString()) + "\""), vm); + } + /* istanbul ignore else */ + if (inBrowser && typeof console !== 'undefined') { + console.error(err); + } else { + throw err + } + } +} + +/* */ +/* globals MutationObserver */ + +// can we use __proto__? +var hasProto = '__proto__' in {}; + +// Browser environment sniffing +var inBrowser = typeof window !== 'undefined'; +var UA = inBrowser && window.navigator.userAgent.toLowerCase(); +var isIE = UA && /msie|trident/.test(UA); +var isIE9 = UA && UA.indexOf('msie 9.0') > 0; +var isEdge = UA && UA.indexOf('edge/') > 0; +var isAndroid = UA && UA.indexOf('android') > 0; +var isIOS = UA && /iphone|ipad|ipod|ios/.test(UA); +var isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge; + +var supportsPassive = false; +if (inBrowser) { + try { + var opts = {}; + Object.defineProperty(opts, 'passive', ({ + get: function get () { + /* istanbul ignore next */ + supportsPassive = true; + } + } )); // https://github.com/facebook/flow/issues/285 + window.addEventListener('test-passive', null, opts); + } catch (e) {} +} + +// this needs to be lazy-evaled because vue may be required before +// vue-server-renderer can set VUE_ENV +var _isServer; +var isServerRendering = function () { + if (_isServer === undefined) { + /* istanbul ignore if */ + if (!inBrowser && typeof global !== 'undefined') { + // detect presence of vue-server-renderer and avoid + // Webpack shimming the process + _isServer = global['process'].env.VUE_ENV === 'server'; + } else { + _isServer = false; + } + } + return _isServer +}; + +// detect devtools +var devtools = inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__; + +/* istanbul ignore next */ +function isNative (Ctor) { + return typeof Ctor === 'function' && /native code/.test(Ctor.toString()) +} + +var hasSymbol = + typeof Symbol !== 'undefined' && isNative(Symbol) && + typeof Reflect !== 'undefined' && isNative(Reflect.ownKeys); + +/** + * Defer a task to execute it asynchronously. + */ +var nextTick = (function () { + var callbacks = []; + var pending = false; + var timerFunc; + + function nextTickHandler () { + pending = false; + var copies = callbacks.slice(0); + callbacks.length = 0; + for (var i = 0; i < copies.length; i++) { + copies[i](); + } + } + + // 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: + /* istanbul ignore if */ + if (typeof Promise !== 'undefined' && isNative(Promise)) { + var p = Promise.resolve(); + var logError = function (err) { console.error(err); }; + 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); } + }; + } else if (typeof MutationObserver !== 'undefined' && ( + isNative(MutationObserver) || + // PhantomJS and iOS 7.x + MutationObserver.toString() === '[object MutationObserverConstructor]' + )) { + // use MutationObserver where native Promise is not available, + // e.g. PhantomJS IE11, iOS7, Android 4.4 + var counter = 1; + var observer = new MutationObserver(nextTickHandler); + var textNode = document.createTextNode(String(counter)); + observer.observe(textNode, { + characterData: true + }); + timerFunc = function () { + counter = (counter + 1) % 2; + textNode.data = String(counter); + }; + } else { + // fallback to setTimeout + /* istanbul ignore next */ + timerFunc = function () { + setTimeout(nextTickHandler, 0); + }; + } + + return function queueNextTick (cb, ctx) { + var _resolve; + callbacks.push(function () { + if (cb) { + try { + cb.call(ctx); + } catch (e) { + handleError(e, ctx, 'nextTick'); + } + } else if (_resolve) { + _resolve(ctx); + } + }); + if (!pending) { + pending = true; + timerFunc(); + } + if (!cb && typeof Promise !== 'undefined') { + return new Promise(function (resolve, reject) { + _resolve = resolve; + }) + } + } +})(); + +var _Set; +/* istanbul ignore if */ +if (typeof Set !== 'undefined' && isNative(Set)) { + // use native Set when available. + _Set = Set; +} else { + // a non-standard Set polyfill that only works with primitive keys. + _Set = (function () { + function Set () { + this.set = Object.create(null); + } + Set.prototype.has = function has (key) { + return this.set[key] === true + }; + Set.prototype.add = function add (key) { + this.set[key] = true; + }; + Set.prototype.clear = function clear () { + this.set = Object.create(null); + }; + + return Set; + }()); +} + +/* */ + + +var uid = 0; + +/** + * A dep is an observable that can have multiple + * directives subscribing to it. + */ +var Dep = function Dep () { + this.id = uid++; + this.subs = []; +}; + +Dep.prototype.addSub = function addSub (sub) { + this.subs.push(sub); +}; + +Dep.prototype.removeSub = function removeSub (sub) { + remove(this.subs, sub); +}; + +Dep.prototype.depend = function depend () { + if (Dep.target) { + Dep.target.addDep(this); + } +}; + +Dep.prototype.notify = function notify () { + // stabilize the subscriber list first + var subs = this.subs.slice(); + for (var i = 0, l = subs.length; i < l; i++) { + subs[i].update(); + } +}; + +// the current target watcher being evaluated. +// this is globally unique because there could be only one +// watcher being evaluated at any time. +Dep.target = null; +var targetStack = []; + +function pushTarget (_target) { + if (Dep.target) { targetStack.push(Dep.target); } + Dep.target = _target; +} + +function popTarget () { + Dep.target = targetStack.pop(); +} + +/* + * not type checking this file because flow doesn't play well with + * dynamically accessing methods on Array prototype + */ + +var arrayProto = Array.prototype; +var arrayMethods = Object.create(arrayProto);[ + 'push', + 'pop', + 'shift', + 'unshift', + 'splice', + 'sort', + 'reverse' +] +.forEach(function (method) { + // cache original method + var original = arrayProto[method]; + def(arrayMethods, method, function mutator () { + var arguments$1 = arguments; + + // avoid leaking arguments: + // http://jsperf.com/closure-with-arguments + var i = arguments.length; + var args = new Array(i); + while (i--) { + args[i] = arguments$1[i]; + } + var result = original.apply(this, args); + var ob = this.__ob__; + var inserted; + switch (method) { + case 'push': + inserted = args; + break + case 'unshift': + inserted = args; + break + case 'splice': + inserted = args.slice(2); + break + } + if (inserted) { ob.observeArray(inserted); } + // notify change + ob.dep.notify(); + return result + }); +}); + +/* */ + +var arrayKeys = Object.getOwnPropertyNames(arrayMethods); + +/** + * By default, when a reactive property is set, the new value is + * also converted to become reactive. However when passing down props, + * we don't want to force conversion because the value may be a nested value + * under a frozen data structure. Converting it would defeat the optimization. + */ +var observerState = { + shouldConvert: true, + isSettingProps: false +}; + +/** + * Observer class that are attached to each observed + * object. Once attached, the observer converts target + * object's property keys into getter/setters that + * collect dependencies and dispatches updates. + */ +var Observer = function Observer (value) { + this.value = value; + this.dep = new Dep(); + this.vmCount = 0; + def(value, '__ob__', this); + if (Array.isArray(value)) { + var augment = hasProto + ? protoAugment + : copyAugment; + augment(value, arrayMethods, arrayKeys); + this.observeArray(value); + } else { + this.walk(value); + } +}; + +/** + * Walk through each property and convert them into + * getter/setters. This method should only be called when + * value type is Object. + */ +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]]); + } +}; + +/** + * Observe a list of Array items. + */ +Observer.prototype.observeArray = function observeArray (items) { + for (var i = 0, l = items.length; i < l; i++) { + observe(items[i]); + } +}; + +// helpers + +/** + * Augment an target Object or Array by intercepting + * the prototype chain using __proto__ + */ +function protoAugment (target, src) { + /* eslint-disable no-proto */ + target.__proto__ = src; + /* eslint-enable no-proto */ +} + +/** + * Augment an target Object or Array by defining + * hidden properties. + */ +/* istanbul ignore next */ +function copyAugment (target, src, keys) { + for (var i = 0, l = keys.length; i < l; i++) { + var key = keys[i]; + def(target, key, src[key]); + } +} + +/** + * Attempt to create an observer instance for a value, + * returns the new observer if successfully observed, + * or the existing observer if the value already has one. + */ +function observe (value, asRootData) { + if (!isObject(value)) { + return + } + var ob; + if (hasOwn(value, '__ob__') && value.__ob__ instanceof Observer) { + ob = value.__ob__; + } else if ( + observerState.shouldConvert && + !isServerRendering() && + (Array.isArray(value) || isPlainObject(value)) && + Object.isExtensible(value) && + !value._isVue + ) { + ob = new Observer(value); + } + if (asRootData && ob) { + ob.vmCount++; + } + return ob +} + +/** + * Define a reactive property on an Object. + */ +function defineReactive$$1 ( + obj, + key, + val, + customSetter +) { + var dep = new Dep(); + + var property = Object.getOwnPropertyDescriptor(obj, key); + if (property && property.configurable === false) { + return + } + + // cater for pre-defined getter/setters + var getter = property && property.get; + var setter = property && property.set; + + var childOb = observe(val); + Object.defineProperty(obj, key, { + enumerable: true, + configurable: true, + get: function reactiveGetter () { + var value = getter ? getter.call(obj) : val; + if (Dep.target) { + dep.depend(); + if (childOb) { + childOb.dep.depend(); + } + if (Array.isArray(value)) { + dependArray(value); + } + } + return value + }, + set: function reactiveSetter (newVal) { + var value = getter ? getter.call(obj) : val; + /* eslint-disable no-self-compare */ + if (newVal === value || (newVal !== newVal && value !== value)) { + return + } + /* eslint-enable no-self-compare */ + if (process.env.NODE_ENV !== 'production' && customSetter) { + customSetter(); + } + if (setter) { + setter.call(obj, newVal); + } else { + val = newVal; + } + childOb = observe(newVal); + dep.notify(); + } + }); +} + +/** + * Set a property on an object. Adds the new property and + * triggers change notification if the property doesn't + * already exist. + */ +function set (target, key, val) { + if (Array.isArray(target) && typeof key === 'number') { + target.length = Math.max(target.length, key); + target.splice(key, 1, val); + return val + } + if (hasOwn(target, key)) { + target[key] = val; + return val + } + var ob = (target ).__ob__; + if (target._isVue || (ob && ob.vmCount)) { + process.env.NODE_ENV !== 'production' && warn( + 'Avoid adding reactive properties to a Vue instance or its root $data ' + + 'at runtime - declare it upfront in the data option.' + ); + return val + } + if (!ob) { + target[key] = val; + return val + } + defineReactive$$1(ob.value, key, val); + ob.dep.notify(); + return val +} + +/** + * Delete a property and trigger change if necessary. + */ + + +/** + * Collect dependencies on array elements when the array is touched, since + * we cannot intercept array element access like property getters. + */ +function dependArray (value) { + for (var e = (void 0), i = 0, l = value.length; i < l; i++) { + e = value[i]; + e && e.__ob__ && e.__ob__.dep.depend(); + if (Array.isArray(e)) { + dependArray(e); + } + } +} + +/* */ + +/** + * Option overwriting strategies are functions that handle + * how to merge a parent option value and a child option + * value into the final value. + */ +var strats = config.optionMergeStrategies; + +/** + * Options with restrictions + */ +if (process.env.NODE_ENV !== 'production') { + strats.el = strats.propsData = function (parent, child, vm, key) { + if (!vm) { + warn( + "option \"" + key + "\" can only be used during instance " + + 'creation with the `new` keyword.' + ); + } + return defaultStrat(parent, child) + }; +} + +/** + * Helper that recursively merges two data objects together. + */ +function mergeData (to, from) { + if (!from) { return to } + var key, toVal, fromVal; + var keys = Object.keys(from); + for (var i = 0; i < keys.length; i++) { + key = keys[i]; + toVal = to[key]; + fromVal = from[key]; + if (!hasOwn(to, key)) { + set(to, key, fromVal); + } else if (isPlainObject(toVal) && isPlainObject(fromVal)) { + mergeData(toVal, fromVal); + } + } + return to +} + +/** + * Data + */ +strats.data = function ( + parentVal, + childVal, + vm +) { + if (!vm) { + // in a Vue.extend merge, both should be functions + if (!childVal) { + return parentVal + } + if (typeof childVal !== 'function') { + process.env.NODE_ENV !== 'production' && warn( + 'The "data" option should be a function ' + + 'that returns a per-instance value in component ' + + 'definitions.', + vm + ); + return parentVal + } + if (!parentVal) { + return childVal + } + // when parentVal & childVal are both present, + // we need to return a function that returns the + // merged result of both functions... no need to + // check if parentVal is a function here because + // it has to be a function to pass previous merges. + return function mergedDataFn () { + return mergeData( + childVal.call(this), + parentVal.call(this) + ) + } + } else if (parentVal || childVal) { + return function mergedInstanceDataFn () { + // instance merge + var instanceData = typeof childVal === 'function' + ? childVal.call(vm) + : childVal; + var defaultData = typeof parentVal === 'function' + ? parentVal.call(vm) + : undefined; + if (instanceData) { + return mergeData(instanceData, defaultData) + } else { + return defaultData + } + } + } +}; + +/** + * Hooks and props are merged as arrays. + */ +function mergeHook ( + parentVal, + childVal +) { + return childVal + ? parentVal + ? parentVal.concat(childVal) + : Array.isArray(childVal) + ? childVal + : [childVal] + : parentVal +} + +LIFECYCLE_HOOKS.forEach(function (hook) { + strats[hook] = mergeHook; +}); + +/** + * Assets + * + * When a vm is present (instance creation), we need to do + * a three-way merge between constructor options, instance + * options and parent options. + */ +function mergeAssets (parentVal, childVal) { + var res = Object.create(parentVal || null); + return childVal + ? extend(res, childVal) + : res +} + +ASSET_TYPES.forEach(function (type) { + strats[type + 's'] = mergeAssets; +}); + +/** + * Watchers. + * + * Watchers hashes should not overwrite one + * another, so we merge them as arrays. + */ +strats.watch = function (parentVal, childVal) { + /* istanbul ignore if */ + if (!childVal) { return Object.create(parentVal || null) } + if (!parentVal) { return childVal } + var ret = {}; + extend(ret, parentVal); + for (var key in childVal) { + var parent = ret[key]; + var child = childVal[key]; + if (parent && !Array.isArray(parent)) { + parent = [parent]; + } + ret[key] = parent + ? parent.concat(child) + : [child]; + } + return ret +}; + +/** + * Other object hashes. + */ +strats.props = +strats.methods = +strats.computed = function (parentVal, childVal) { + if (!childVal) { return Object.create(parentVal || null) } + if (!parentVal) { return childVal } + var ret = Object.create(null); + extend(ret, parentVal); + extend(ret, childVal); + return ret +}; + +/** + * Default strategy. + */ +var defaultStrat = function (parentVal, childVal) { + return childVal === undefined + ? parentVal + : childVal +}; + +/** + * Merge two option objects into a new one. + * Core utility used in both instantiation and inheritance. + */ + + +/** + * Resolve an asset. + * This function is used because child instances need access + * to assets defined in its ancestor chain. + */ + +/* */ + +/* */ + +function genClassForVnode (vnode) { + var data = vnode.data; + var parentNode = vnode; + var childNode = vnode; + while (isDef(childNode.componentInstance)) { + childNode = childNode.componentInstance._vnode; + if (childNode.data) { + data = mergeClassData(childNode.data, data); + } + } + while (isDef(parentNode = parentNode.parent)) { + if (parentNode.data) { + data = mergeClassData(data, parentNode.data); + } + } + return genClassFromData(data) +} + +function mergeClassData (child, parent) { + return { + staticClass: concat(child.staticClass, parent.staticClass), + class: isDef(child.class) + ? [child.class, parent.class] + : parent.class + } +} + +function genClassFromData (data) { + var dynamicClass = data.class; + var staticClass = data.staticClass; + if (isDef(staticClass) || isDef(dynamicClass)) { + return concat(staticClass, stringifyClass(dynamicClass)) + } + /* istanbul ignore next */ + return '' +} + +function concat (a, b) { + return a ? b ? (a + ' ' + b) : a : (b || '') +} + +function stringifyClass (value) { + if (isUndef(value)) { + return '' + } + if (typeof value === 'string') { + return value + } + var res = ''; + if (Array.isArray(value)) { + var stringified; + for (var i = 0, l = value.length; i < l; i++) { + if (isDef(value[i])) { + if (isDef(stringified = stringifyClass(value[i])) && stringified !== '') { + res += stringified + ' '; + } + } + } + return res.slice(0, -1) + } + if (isObject(value)) { + for (var key in value) { + if (value[key]) { res += key + ' '; } + } + return res.slice(0, -1) + } + /* istanbul ignore next */ + return res +} + +/* */ + + + +var isHTMLTag = makeMap( + 'html,body,base,head,link,meta,style,title,' + + 'address,article,aside,footer,header,h1,h2,h3,h4,h5,h6,hgroup,nav,section,' + + 'div,dd,dl,dt,figcaption,figure,hr,img,li,main,ol,p,pre,ul,' + + 'a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,rtc,ruby,' + + 's,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,' + + 'embed,object,param,source,canvas,script,noscript,del,ins,' + + 'caption,col,colgroup,table,thead,tbody,td,th,tr,' + + 'button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,' + + 'output,progress,select,textarea,' + + 'details,dialog,menu,menuitem,summary,' + + 'content,element,shadow,template' +); + +// this map is intentionally selective, only covering SVG elements that may +// contain child elements. +var isSVG = makeMap( + 'svg,animate,circle,clippath,cursor,defs,desc,ellipse,filter,font-face,' + + 'foreignObject,g,glyph,image,line,marker,mask,missing-glyph,path,pattern,' + + 'polygon,polyline,rect,switch,symbol,text,textpath,tspan,use,view', + true +); + +var isPreTag = function (tag) { return tag === 'pre'; }; + +var isReservedTag = function (tag) { + return isHTMLTag(tag) || isSVG(tag) +}; + +function getTagNamespace (tag) { + if (isSVG(tag)) { + return 'svg' + } + // basic support for MathML + // note it doesn't support other MathML elements being component roots + if (tag === 'math') { + return 'math' + } +} + +/* */ + +/** + * Query an element selector if it's not an element already. + */ + +/* */ + +function renderClass (node) { + var classList = genClassForVnode(node); + if (classList !== '') { + return (" class=\"" + (he.escape(classList)) + "\"") + } +} + +/* */ + +var parseStyleText = cached(function (cssText) { + var res = {}; + var listDelimiter = /;(?![^(]*\))/g; + var propertyDelimiter = /:(.+)/; + cssText.split(listDelimiter).forEach(function (item) { + if (item) { + var tmp = item.split(propertyDelimiter); + tmp.length > 1 && (res[tmp[0].trim()] = tmp[1].trim()); + } + }); + return res +}); + +// merge static and dynamic style data on the same vnode +function normalizeStyleData (data) { + var style = normalizeStyleBinding(data.style); + // static style is pre-processed into an object during compilation + // and is always a fresh object, so it's safe to merge into it + return data.staticStyle + ? extend(data.staticStyle, style) + : style +} + +// normalize possible array / string values into Object +function normalizeStyleBinding (bindingStyle) { + if (Array.isArray(bindingStyle)) { + return toObject(bindingStyle) + } + if (typeof bindingStyle === 'string') { + return parseStyleText(bindingStyle) + } + return bindingStyle +} + +/** + * parent component style should be after child's + * so that parent component's style could override it + */ +function getStyle (vnode, checkChild) { + var res = {}; + var styleData; + + if (checkChild) { + var childNode = vnode; + while (childNode.componentInstance) { + childNode = childNode.componentInstance._vnode; + if (childNode.data && (styleData = normalizeStyleData(childNode.data))) { + extend(res, styleData); + } + } + } + + if ((styleData = normalizeStyleData(vnode.data))) { + extend(res, styleData); + } + + var parentNode = vnode; + while ((parentNode = parentNode.parent)) { + if (parentNode.data && (styleData = normalizeStyleData(parentNode.data))) { + extend(res, styleData); + } + } + return res +} + +/* */ + +function genStyleText (vnode) { + var styleText = ''; + var style = getStyle(vnode, false); + for (var key in style) { + var value = style[key]; + var hyphenatedKey = hyphenate(key); + if (Array.isArray(value)) { + for (var i = 0, len = value.length; i < len; i++) { + styleText += hyphenatedKey + ":" + (value[i]) + ";"; + } + } else { + styleText += hyphenatedKey + ":" + value + ";"; + } + } + return styleText +} + +function renderStyle (vnode) { + var styleText = genStyleText(vnode); + if (styleText !== '') { + return (" style=" + (JSON.stringify(he.escape(styleText)))) + } +} + +var modules = [ + renderAttrs, + renderDOMProps, + renderClass, + renderStyle +]; + +/* */ + +function show (node, dir) { + if (!dir.value) { + var style = node.data.style || (node.data.style = {}); + style.display = 'none'; + } +} + +var baseDirectives = { + show: show +}; + +/* */ + var isUnaryTag = makeMap( 'area,base,br,col,embed,frame,hr,img,input,isindex,keygen,' + 'link,meta,param,source,track,wbr' @@ -470,6 +1614,611 @@ var isNonPhrasingTag = makeMap( 'title,tr,track' ); +/* */ + +var MAX_STACK_DEPTH = 1000; + +function createWriteFunction ( + write, + onError +) { + var stackDepth = 0; + var cachedWrite = function (text, next) { + if (text && cachedWrite.caching) { + cachedWrite.cacheBuffer[cachedWrite.cacheBuffer.length - 1] += text; + } + var waitForNext = write(text, next); + if (waitForNext !== true) { + if (stackDepth >= MAX_STACK_DEPTH) { + process.nextTick(function () { + try { next(); } catch (e) { + onError(e); + } + }); + } else { + stackDepth++; + next(); + stackDepth--; + } + } + }; + cachedWrite.caching = false; + cachedWrite.cacheBuffer = []; + cachedWrite.componentBuffer = []; + return cachedWrite +} + +/* */ + +/** + * Original RenderStream implementation by Sasha Aickin (@aickin) + * Licensed under the Apache License, Version 2.0 + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Modified by Evan You (@yyx990803) + */ + +var stream = require('stream'); + +var RenderStream = (function (superclass) { + function RenderStream (render) { + var this$1 = this; + + superclass.call(this); + this.buffer = ''; + this.render = render; + this.expectedSize = 0; + + this.write = createWriteFunction(function (text, next) { + var n = this$1.expectedSize; + this$1.buffer += text; + if (this$1.buffer.length >= n) { + this$1.next = next; + this$1.pushBySize(n); + return true // we will decide when to call next + } + return false + }, function (err) { + this$1.emit('error', err); + }); + + this.end = function () { + // the rendering is finished; we should push out the last of the buffer. + this$1.done = true; + this$1.push(this$1.buffer); + }; + } + + if ( superclass ) RenderStream.__proto__ = superclass; + RenderStream.prototype = Object.create( superclass && superclass.prototype ); + RenderStream.prototype.constructor = RenderStream; + + RenderStream.prototype.pushBySize = function pushBySize (n) { + var bufferToPush = this.buffer.substring(0, n); + this.buffer = this.buffer.substring(n); + this.push(bufferToPush); + }; + + RenderStream.prototype.tryRender = function tryRender () { + try { + this.render(this.write, this.end); + } catch (e) { + this.emit('error', e); + } + }; + + RenderStream.prototype.tryNext = function tryNext () { + try { + this.next(); + } catch (e) { + this.emit('error', e); + } + }; + + RenderStream.prototype._read = function _read (n) { + this.expectedSize = n; + // it's possible that the last chunk added bumped the buffer up to > 2 * n, + // which means we will need to go through multiple read calls to drain it + // down to < n. + if (isTrue(this.done)) { + this.push(null); + return + } + if (this.buffer.length >= n) { + this.pushBySize(n); + return + } + if (isUndef(this.next)) { + // start the rendering chain. + this.tryRender(); + } else { + // continue with the rendering. + this.tryNext(); + } + }; + + return RenderStream; +}(stream.Readable)); + +/* */ + +var isJS = function (file) { return /\.js(\?[^.]+)?$/.test(file); }; + +var isCSS = function (file) { return /\.css(\?[^.]+)?$/.test(file); }; + +/* */ + +var Transform = require('stream').Transform; + + + +var TemplateStream = (function (Transform) { + function TemplateStream ( + renderer, + template, + context + ) { + Transform.call(this); + this.started = false; + this.renderer = renderer; + this.template = template; + this.context = context || {}; + this.inject = renderer.inject; + } + + if ( Transform ) TemplateStream.__proto__ = Transform; + TemplateStream.prototype = Object.create( Transform && Transform.prototype ); + TemplateStream.prototype.constructor = TemplateStream; + + TemplateStream.prototype._transform = function _transform (data, encoding, done) { + if (!this.started) { + this.emit('beforeStart'); + this.start(); + } + this.push(data); + done(); + }; + + TemplateStream.prototype.start = function start () { + this.started = true; + this.push(this.template.head(this.context)); + + if (this.inject) { + // inline server-rendered head meta information + if (this.context.head) { + this.push(this.context.head); + } + + // inline preload/prefetch directives for initial/async chunks + var links = this.renderer.renderResourceHints(this.context); + if (links) { + this.push(links); + } + + // CSS files and inline server-rendered CSS collected by vue-style-loader + var styles = this.renderer.renderStyles(this.context); + if (styles) { + this.push(styles); + } + } + + this.push(this.template.neck(this.context)); + }; + + TemplateStream.prototype._flush = function _flush (done) { + this.emit('beforeEnd'); + + if (this.inject) { + // inline initial store state + var state = this.renderer.renderState(this.context); + if (state) { + this.push(state); + } + + // embed scripts needed + var scripts = this.renderer.renderScripts(this.context); + if (scripts) { + this.push(scripts); + } + } + + this.push(this.template.tail(this.context)); + done(); + }; + + return TemplateStream; +}(Transform)); + +/* */ + +var compile = require('lodash.template'); +var compileOptions = { + escape: /{{[^{]([\s\S]+?)[^}]}}/g, + interpolate: /{{{([\s\S]+?)}}}/g +}; + + + +function parseTemplate ( + template, + contentPlaceholder +) { + if ( contentPlaceholder === void 0 ) contentPlaceholder = ''; + + if (typeof template === 'object') { + return template + } + + var i = template.indexOf(''); + var j = template.indexOf(contentPlaceholder); + + if (j < 0) { + throw new Error("Content placeholder not found in template.") + } + + if (i < 0) { + i = template.indexOf(''); + if (i < 0) { + i = j; + } + } + + return { + head: compile(template.slice(0, i), compileOptions), + neck: compile(template.slice(i, j), compileOptions), + tail: compile(template.slice(j + contentPlaceholder.length), compileOptions) + } +} + +/* */ + +/** + * Creates a mapper that maps components used during a server-side render + * to async chunk files in the client-side build, so that we can inline them + * directly in the rendered HTML to avoid waterfall requests. + */ + + + + + +function createMapper ( + clientManifest +) { + var map = createMap(clientManifest); + // map server-side moduleIds to client-side files + return function mapper (moduleIds) { + var res = new Set(); + for (var i = 0; i < moduleIds.length; i++) { + var mapped = map.get(moduleIds[i]); + if (mapped) { + for (var j = 0; j < mapped.length; j++) { + res.add(mapped[j]); + } + } + } + return Array.from(res) + } +} + +function createMap (clientManifest) { + var map = new Map(); + Object.keys(clientManifest.modules).forEach(function (id) { + map.set(id, mapIdToFile(id, clientManifest)); + }); + return map +} + +function mapIdToFile (id, clientManifest) { + var files = []; + var fileIndices = clientManifest.modules[id]; + if (fileIndices) { + fileIndices.forEach(function (index) { + var file = clientManifest.all[index]; + // only include async files or non-js assets + if (clientManifest.async.indexOf(file) > -1 || !(/\.js($|\?)/.test(file))) { + files.push(file); + } + }); + } + return files +} + +/* */ + +var path = require('path'); +var serialize = require('serialize-javascript'); + +var TemplateRenderer = function TemplateRenderer (options) { + this.options = options; + this.inject = options.inject !== false; + // if no template option is provided, the renderer is created + // as a utility object for rendering assets like preload links and scripts. + this.parsedTemplate = options.template + ? parseTemplate(options.template) + : null; + + // extra functionality with client manifest + if (options.clientManifest) { + var clientManifest = this.clientManifest = options.clientManifest; + this.publicPath = clientManifest.publicPath.replace(/\/$/, ''); + // preload/prefetch drectives + this.preloadFiles = clientManifest.initial; + this.prefetchFiles = clientManifest.async; + // initial async chunk mapping + this.mapFiles = createMapper(clientManifest); + } +}; + +TemplateRenderer.prototype.bindRenderFns = function bindRenderFns (context) { + var renderer = this;['ResourceHints', 'State', 'Scripts', 'Styles'].forEach(function (type) { + context[("render" + type)] = renderer[("render" + type)].bind(renderer, context); + }); + // also expose getPreloadFiles, useful for HTTP/2 push + context.getPreloadFiles = renderer.getPreloadFiles.bind(renderer, context); +}; + +// render synchronously given rendered app content and render context +TemplateRenderer.prototype.renderSync = function renderSync (content, context) { + var template = this.parsedTemplate; + if (!template) { + throw new Error('renderSync cannot be called without a template.') + } + context = context || {}; + if (this.inject) { + return ( + template.head(context) + + (context.head || '') + + this.renderResourceHints(context) + + this.renderStyles(context) + + template.neck(context) + + content + + this.renderState(context) + + this.renderScripts(context) + + template.tail(context) + ) + } else { + return ( + template.head(context) + + template.neck(context) + + content + + template.tail(context) + ) + } +}; + +TemplateRenderer.prototype.renderStyles = function renderStyles (context) { + var this$1 = this; + + var cssFiles = this.clientManifest + ? this.clientManifest.all.filter(isCSS) + : []; + return ( + // render links for css files + (cssFiles.length + ? cssFiles.map(function (file) { return (""); }).join('') + : '') + + // context.styles is a getter exposed by vue-style-loader which contains + // the inline component styles collected during SSR + (context.styles || '') + ) +}; + +TemplateRenderer.prototype.renderResourceHints = function renderResourceHints (context) { + return this.renderPreloadLinks(context) + this.renderPrefetchLinks(context) +}; + +TemplateRenderer.prototype.getPreloadFiles = function getPreloadFiles (context) { + var usedAsyncFiles = this.getUsedAsyncFiles(context); + if (this.preloadFiles || usedAsyncFiles) { + return (this.preloadFiles || []).concat(usedAsyncFiles || []).map(function (file) { + var withoutQuery = file.replace(/\?.*/, ''); + var extension = path.extname(withoutQuery).slice(1); + return { + file: file, + extension: extension, + fileWithoutQuery: withoutQuery, + asType: getPreloadType(extension) + } + }) + } else { + return [] + } +}; + +TemplateRenderer.prototype.renderPreloadLinks = function renderPreloadLinks (context) { + var this$1 = this; + + var files = this.getPreloadFiles(context); + if (files.length) { + return files.map(function (ref) { + var file = ref.file; + var extension = ref.extension; + var fileWithoutQuery = ref.fileWithoutQuery; + var asType = ref.asType; + + var extra = ''; + var shouldPreload = this$1.options.shouldPreload; + // by default, we only preload scripts or css + if (!shouldPreload && asType !== 'script' && asType !== 'style') { + return '' + } + // user wants to explicitly control what to preload + if (shouldPreload && !shouldPreload(fileWithoutQuery, asType)) { + return '' + } + if (asType === 'font') { + extra = " type=\"font/" + extension + "\" crossorigin"; + } + return ("") + }).join('') + } else { + return '' + } +}; + +TemplateRenderer.prototype.renderPrefetchLinks = function renderPrefetchLinks (context) { + var this$1 = this; + + if (this.prefetchFiles) { + var usedAsyncFiles = this.getUsedAsyncFiles(context); + var alreadyRendered = function (file) { + return usedAsyncFiles && usedAsyncFiles.some(function (f) { return f === file; }) + }; + return this.prefetchFiles.map(function (file) { + if (!alreadyRendered(file)) { + return ("") + } else { + return '' + } + }).join('') + } else { + return '' + } +}; + +TemplateRenderer.prototype.renderState = function renderState (context, options) { + var ref = options || {}; + var contextKey = ref.contextKey; if ( contextKey === void 0 ) contextKey = 'state'; + var windowKey = ref.windowKey; if ( windowKey === void 0 ) windowKey = '__INITIAL_STATE__'; + return context[contextKey] + ? ("") + : '' +}; + +TemplateRenderer.prototype.renderScripts = function renderScripts (context) { + var this$1 = this; + + if (this.clientManifest) { + var initial = this.clientManifest.initial; + var async = this.getUsedAsyncFiles(context); + var needed = [initial[0]].concat(async || [], initial.slice(1)); + return needed.filter(isJS).map(function (file) { + return ("") + }).join('') + } else { + return '' + } +}; + +TemplateRenderer.prototype.getUsedAsyncFiles = function getUsedAsyncFiles (context) { + if (!context._mappedfiles && context._registeredComponents && this.mapFiles) { + context._mappedFiles = this.mapFiles(Array.from(context._registeredComponents)); + } + return context._mappedFiles +}; + +// create a transform stream +TemplateRenderer.prototype.createStream = function createStream (context) { + if (!this.parsedTemplate) { + throw new Error('createStream cannot be called without a template.') + } + return new TemplateStream(this, this.parsedTemplate, context || {}) +}; + +function getPreloadType (ext) { + if (ext === 'js') { + return 'script' + } else if (ext === 'css') { + return 'style' + } else if (/jpe?g|png|svg|gif|webp|ico/.test(ext)) { + return 'image' + } else if (/woff2?|ttf|otf|eot/.test(ext)) { + return 'font' + } else { + // not exhausting all possbilities here, but above covers common cases + return '' + } +} + +/* */ + +var RenderContext = function RenderContext (options) { + this.userContext = options.userContext; + this.activeInstance = options.activeInstance; + this.renderStates = []; + + this.write = options.write; + this.done = options.done; + this.renderNode = options.renderNode; + + this.isUnaryTag = options.isUnaryTag; + this.modules = options.modules; + this.directives = options.directives; + + var cache = options.cache; + if (cache && (!cache.get || !cache.set)) { + throw new Error('renderer cache must implement at least get & set.') + } + this.cache = cache; + this.get = cache && normalizeAsync(cache, 'get'); + this.has = cache && normalizeAsync(cache, 'has'); + + this.next = this.next.bind(this); +}; + +RenderContext.prototype.next = function next () { + var lastState = this.renderStates[this.renderStates.length - 1]; + if (isUndef(lastState)) { + return this.done() + } + switch (lastState.type) { + case 'Element': + var children = lastState.children; + var total = lastState.total; + var rendered = lastState.rendered++; + if (rendered < total) { + this.renderNode(children[rendered], false, this); + } else { + this.renderStates.pop(); + this.write(lastState.endTag, this.next); + } + break + case 'Component': + this.renderStates.pop(); + this.activeInstance = lastState.prevActive; + this.next(); + break + case 'ComponentWithCache': + this.renderStates.pop(); + var buffer = lastState.buffer; + var bufferIndex = lastState.bufferIndex; + var componentBuffer = lastState.componentBuffer; + var key = lastState.key; + var result = { + html: buffer[bufferIndex], + components: componentBuffer[bufferIndex] + }; + this.cache.set(key, result); + if (bufferIndex === 0) { + // this is a top-level cached component, + // exit caching mode. + this.write.caching = false; + } else { + // parent component is also being cached, + // merge self into parent's result + buffer[bufferIndex - 1] += result.html; + var prev = componentBuffer[bufferIndex - 1]; + result.components.forEach(function (c) { return prev.add(c); }); + } + buffer.length = bufferIndex; + componentBuffer.length = bufferIndex; + this.next(); + break + } +}; + +function normalizeAsync (cache, method) { + var fn = cache[method]; + if (isUndef(fn)) { + return + } else if (fn.length > 1) { + return function (key, cb) { return fn.call(cache, key, cb); } + } else { + return function (key, cb) { return cb(fn.call(cache, key)); } + } +} + /** * Not type-checking this file because it's mostly vendor code. */ @@ -915,152 +2664,144 @@ function parseText ( } /* */ -/* globals MutationObserver */ - -// can we use __proto__? -var hasProto = '__proto__' in {}; - -// Browser environment sniffing -var inBrowser = typeof window !== 'undefined'; -var UA = inBrowser && window.navigator.userAgent.toLowerCase(); -var isIE = UA && /msie|trident/.test(UA); -var isIE9 = UA && UA.indexOf('msie 9.0') > 0; -var isEdge = UA && UA.indexOf('edge/') > 0; -var isAndroid = UA && UA.indexOf('android') > 0; -var isIOS = UA && /iphone|ipad|ipod|ios/.test(UA); -var isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge; - -// this needs to be lazy-evaled because vue may be required before -// vue-server-renderer can set VUE_ENV -var _isServer; -var isServerRendering = function () { - if (_isServer === undefined) { - /* istanbul ignore if */ - if (!inBrowser && typeof global !== 'undefined') { - // detect presence of vue-server-renderer and avoid - // Webpack shimming the process - _isServer = global['process'].env.VUE_ENV === 'server'; - } else { - _isServer = false; - } - } - return _isServer -}; - -// detect devtools -var devtools = inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__; - -/* istanbul ignore next */ -function isNative (Ctor) { - return /native code/.test(Ctor.toString()) -} - -var hasSymbol = - typeof Symbol !== 'undefined' && isNative(Symbol) && - typeof Reflect !== 'undefined' && isNative(Reflect.ownKeys); /** - * Defer a task to execute it asynchronously. + * Cross-platform code generation for component v-model */ -var nextTick = (function () { - var callbacks = []; - var pending = false; - var timerFunc; +function genComponentModel ( + el, + value, + modifiers +) { + var ref = modifiers || {}; + var number = ref.number; + var trim = ref.trim; - function nextTickHandler () { - pending = false; - var copies = callbacks.slice(0); - callbacks.length = 0; - for (var i = 0; i < copies.length; i++) { - copies[i](); - } + var baseValueExpression = '$$v'; + var valueExpression = baseValueExpression; + if (trim) { + valueExpression = + "(typeof " + baseValueExpression + " === 'string'" + + "? " + baseValueExpression + ".trim()" + + ": " + baseValueExpression + ")"; } + if (number) { + valueExpression = "_n(" + valueExpression + ")"; + } + var assignment = genAssignmentCode(value, valueExpression); - // 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: - /* istanbul ignore if */ - if (typeof Promise !== 'undefined' && isNative(Promise)) { - var p = Promise.resolve(); - var logError = function (err) { console.error(err); }; - 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); } - }; - } else if (typeof MutationObserver !== 'undefined' && ( - isNative(MutationObserver) || - // PhantomJS and iOS 7.x - MutationObserver.toString() === '[object MutationObserverConstructor]' - )) { - // use MutationObserver where native Promise is not available, - // e.g. PhantomJS IE11, iOS7, Android 4.4 - var counter = 1; - var observer = new MutationObserver(nextTickHandler); - var textNode = document.createTextNode(String(counter)); - observer.observe(textNode, { - characterData: true - }); - timerFunc = function () { - counter = (counter + 1) % 2; - textNode.data = String(counter); - }; + el.model = { + value: ("(" + value + ")"), + expression: ("\"" + value + "\""), + callback: ("function (" + baseValueExpression + ") {" + assignment + "}") + }; +} + +/** + * Cross-platform codegen helper for generating v-model value assignment code. + */ +function genAssignmentCode ( + value, + assignment +) { + var modelRs = parseModel(value); + if (modelRs.idx === null) { + return (value + "=" + assignment) } else { - // fallback to setTimeout - /* istanbul ignore next */ - timerFunc = function () { - setTimeout(nextTickHandler, 0); - }; + return "var $$exp = " + (modelRs.exp) + ", $$idx = " + (modelRs.idx) + ";" + + "if (!Array.isArray($$exp)){" + + value + "=" + assignment + "}" + + "else{$$exp.splice($$idx, 1, " + assignment + ")}" + } +} + +/** + * parse directive model to do the array update transform. a[idx] = val => $$a.splice($$idx, 1, val) + * + * for loop possible cases: + * + * - test + * - test[idx] + * - test[test1[idx]] + * - test["a"][idx] + * - xxx.test[a[a].test1[idx]] + * - test.xxx.a["asa"][test1[idx]] + * + */ + +var len; +var str; +var chr; +var index; +var expressionPos; +var expressionEndPos; + +function parseModel (val) { + str = val; + len = str.length; + index = expressionPos = expressionEndPos = 0; + + if (val.indexOf('[') < 0 || val.lastIndexOf(']') < len - 1) { + return { + exp: val, + idx: null + } } - return function queueNextTick (cb, ctx) { - var _resolve; - callbacks.push(function () { - if (cb) { cb.call(ctx); } - if (_resolve) { _resolve(ctx); } - }); - if (!pending) { - pending = true; - timerFunc(); - } - if (!cb && typeof Promise !== 'undefined') { - return new Promise(function (resolve) { - _resolve = resolve; - }) + while (!eof()) { + chr = next(); + /* istanbul ignore if */ + if (isStringStart(chr)) { + parseString(chr); + } else if (chr === 0x5B) { + parseBracket(chr); } } -})(); -var _Set; -/* istanbul ignore if */ -if (typeof Set !== 'undefined' && isNative(Set)) { - // use native Set when available. - _Set = Set; -} else { - // a non-standard Set polyfill that only works with primitive keys. - _Set = (function () { - function Set () { - this.set = Object.create(null); + return { + exp: val.substring(0, expressionPos), + idx: val.substring(expressionPos + 1, expressionEndPos) + } +} + +function next () { + return str.charCodeAt(++index) +} + +function eof () { + return index >= len +} + +function isStringStart (chr) { + return chr === 0x22 || chr === 0x27 +} + +function parseBracket (chr) { + var inBracket = 1; + expressionPos = index; + while (!eof()) { + chr = next(); + if (isStringStart(chr)) { + parseString(chr); + continue } - Set.prototype.has = function has (key) { - return this.set[key] === true - }; - Set.prototype.add = function add (key) { - this.set[key] = true; - }; - Set.prototype.clear = function clear () { - this.set = Object.create(null); - }; + if (chr === 0x5B) { inBracket++; } + if (chr === 0x5D) { inBracket--; } + if (inBracket === 0) { + expressionEndPos = index; + break + } + } +} - return Set; - }()); +function parseString (chr) { + var stringQuote = chr; + while (!eof()) { + chr = next(); + if (chr === stringQuote) { + break + } + } } /* */ @@ -1102,8 +2843,20 @@ function addHandler ( name, value, modifiers, - important + important, + warn ) { + // warn prevent and passive modifier + /* istanbul ignore if */ + if ( + process.env.NODE_ENV !== 'production' && warn && + modifiers && modifiers.prevent && modifiers.passive + ) { + warn( + 'passive and prevent can\'t be used together. ' + + 'Passive handler can\'t prevent default event.' + ); + } // check capture modifier if (modifiers && modifiers.capture) { delete modifiers.capture; @@ -1113,6 +2866,11 @@ function addHandler ( delete modifiers.once; name = '~' + name; // mark the event as once } + /* istanbul ignore if */ + if (modifiers && modifiers.passive) { + delete modifiers.passive; + name = '&' + name; // mark the event as passive + } var events; if (modifiers && modifiers.native) { delete modifiers.native; @@ -1178,7 +2936,7 @@ var modifierRE = /\.[^.]+/g; var decodeHTMLCached = cached(he.decode); // configurable state -var warn; +var warn$1; var delimiters; var transforms; var preTransforms; @@ -1194,7 +2952,7 @@ function parse ( template, options ) { - warn = options.warn || baseWarn; + warn$1 = options.warn || baseWarn; platformGetTagNamespace = options.getTagNamespace || no; platformMustUseProp = options.mustUseProp || no; platformIsPreTag = options.isPreTag || no; @@ -1214,7 +2972,7 @@ function parse ( function warnOnce (msg) { if (!warned) { warned = true; - warn(msg); + warn$1(msg); } } @@ -1229,7 +2987,7 @@ function parse ( } parseHTML(template, { - warn: warn, + warn: warn$1, expectHTML: options.expectHTML, isUnaryTag: options.isUnaryTag, canBeLeftOpenTag: options.canBeLeftOpenTag, @@ -1259,7 +3017,7 @@ function parse ( if (isForbiddenTag(element) && !isServerRendering()) { element.forbidden = true; - process.env.NODE_ENV !== 'production' && warn( + process.env.NODE_ENV !== 'production' && warn$1( 'Templates should only be responsible for mapping the state to the ' + 'UI. Avoid placing tags with side-effects in your templates, such as ' + "<" + tag + ">" + ', as they will not be parsed.' @@ -1447,7 +3205,7 @@ function processKey (el) { var exp = getBindingAttr(el, 'key'); if (exp) { if (process.env.NODE_ENV !== 'production' && el.tag === 'template') { - warn("