提交 532e580d 编写于 作者: fxy060608's avatar fxy060608

build(deps): bump vue from 3.0.5 to 3.0.7

上级 eb70ee06
import { isSymbol, extend, isMap, isObject, toRawType, def, isArray, isString, isFunction, isPromise, capitalize, toHandlerKey, remove, EMPTY_OBJ, NOOP, isGloballyWhitelisted, isIntegerKey, hasOwn, hasChanged, camelize, NO, invokeArrayFns, isSet, makeMap, toNumber, hyphenate, isReservedProp, EMPTY_ARR, toTypeString, isOn } from '@vue/shared';
import { isSymbol, extend, isMap, isObject, toRawType, def, isArray, isString, isFunction, isPromise, toHandlerKey, remove, EMPTY_OBJ, camelize, capitalize, normalizeClass, normalizeStyle, isOn, NOOP, isGloballyWhitelisted, isIntegerKey, hasOwn, hasChanged, NO, invokeArrayFns, makeMap, isSet, toNumber, hyphenate, isReservedProp, EMPTY_ARR, toTypeString } from '@vue/shared';
export { camelize } from '@vue/shared';
const targetMap = new WeakMap();
......@@ -190,6 +190,7 @@ function trigger(target, type, key, newValue, oldValue, oldTarget) {
effects.forEach(run);
}
const isNonTrackableKeys = /*#__PURE__*/ makeMap(`__proto__,__v_isRef,__isVue`);
const builtInSymbols = new Set(Object.getOwnPropertyNames(Symbol)
.map(key => Symbol[key])
.filter(isSymbol));
......@@ -244,7 +245,7 @@ function createGetter(isReadonly = false, shallow = false) {
const res = Reflect.get(target, key, receiver);
if (isSymbol(key)
? builtInSymbols.has(key)
: key === `__proto__` || key === `__v_isRef`) {
: isNonTrackableKeys(key)) {
return res;
}
if (!isReadonly) {
......@@ -393,8 +394,8 @@ function add(value) {
const target = toRaw(this);
const proto = getProto(target);
const hadKey = proto.has.call(target, value);
target.add(value);
if (!hadKey) {
target.add(value);
trigger(target, "add" /* ADD */, value, value);
}
return this;
......@@ -1096,6 +1097,22 @@ function nextTick(fn) {
const p = currentFlushPromise || resolvedPromise;
return fn ? p.then(this ? fn.bind(this) : fn) : p;
}
// #2768
// Use binary-search to find a suitable position in the queue,
// so that the queue maintains the increasing order of job's id,
// which can prevent the job from being skipped and also can avoid repeated patching.
function findInsertionIndex(job) {
// the start index should be `flushIndex + 1`
let start = flushIndex + 1;
let end = queue.length;
const jobId = getId(job);
while (start < end) {
const middle = (start + end) >>> 1;
const middleJobId = getId(queue[middle]);
middleJobId < jobId ? (start = middle + 1) : (end = middle);
}
return start;
}
function queueJob(job) {
// the dedupe search uses the startIndex argument of Array.includes()
// by default the search index includes the current job that is being run
......@@ -1106,7 +1123,13 @@ function queueJob(job) {
if ((!queue.length ||
!queue.includes(job, isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex)) &&
job !== currentPreFlushParentJob) {
queue.push(job);
const pos = findInsertionIndex(job);
if (pos > -1) {
queue.splice(pos, 0, job);
}
else {
queue.push(job);
}
queueFlush();
}
}
......@@ -1358,63 +1381,17 @@ function isEmitListener(options, key) {
hasOwn(options, key));
}
let isRenderingCompiledSlot = 0;
const setCompiledSlotRendering = (n) => (isRenderingCompiledSlot += n);
/**
* mark the current rendering instance for asset resolution (e.g.
* resolveComponent, resolveDirective) during render
*/
let currentRenderingInstance = null;
function markAttrsAccessed() {
}
let currentScopeId = null;
const COMPONENTS = 'components';
const DIRECTIVES = 'directives';
/**
* @private
*/
function resolveDirective(name) {
return resolveAsset(DIRECTIVES, name);
}
// implementation
function resolveAsset(type, name, warnMissing = true) {
const instance = currentInstance;
if (instance) {
const Component = instance.type;
// self name has highest priority
if (type === COMPONENTS) {
// special self referencing call generated by compiler
// inferred from SFC filename
if (name === `_self`) {
return Component;
}
const selfName = getComponentName(Component);
if (selfName &&
(selfName === name ||
selfName === camelize(name) ||
selfName === capitalize(camelize(name)))) {
return Component;
}
}
const res =
// local registration
// check instance[type] first for components with mixin or extends.
resolve(instance[type] || Component[type], name) ||
// global registration
resolve(instance.appContext[type], name);
if ((process.env.NODE_ENV !== 'production') && warnMissing && !res) {
warn(`Failed to resolve ${type.slice(0, -1)}: ${name}`);
}
return res;
}
else if ((process.env.NODE_ENV !== 'production')) {
warn(`resolve${capitalize(type.slice(0, -1))} ` +
`can only be used in render() or setup().`);
}
}
function resolve(registry, name) {
return (registry &&
(registry[name] ||
registry[camelize(name)] ||
registry[capitalize(camelize(name))]));
function markAttrsAccessed() {
}
function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison
......@@ -1650,7 +1627,7 @@ function validateProp(name, value, prop, isAbsent) {
warn('Invalid prop: custom validator check failed for prop "' + name + '".');
}
}
const isSimpleType = /*#__PURE__*/ makeMap('String,Number,Boolean,Function,Symbol');
const isSimpleType = /*#__PURE__*/ makeMap('String,Number,Boolean,Function,Symbol,BigInt');
/**
* dev only
*/
......@@ -1766,7 +1743,7 @@ function injectHook(type, hook, target = currentInstance, prepend = false) {
warn(`${apiName} is called when there is no active component instance to be ` +
`associated with. ` +
`Lifecycle injection APIs can only be used during execution of setup().` +
( ``));
(``));
}
}
const createHook = (lifecycle) => (hook, target = currentInstance) =>
......@@ -1784,6 +1761,211 @@ const onErrorCaptured = (hook, target = currentInstance) => {
injectHook("ec" /* ERROR_CAPTURED */, hook, target);
};
// Simple effect.
function watchEffect(effect, options) {
return doWatch(effect, null, options);
}
// initial value for watchers to trigger on undefined initial values
const INITIAL_WATCHER_VALUE = {};
// implementation
function watch(source, cb, options) {
if ((process.env.NODE_ENV !== 'production') && !isFunction(cb)) {
warn(`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
`Use \`watchEffect(fn, options?)\` instead. \`watch\` now only ` +
`supports \`watch(source, cb, options?) signature.`);
}
return doWatch(source, cb, options);
}
function doWatch(source, cb, { immediate, deep, flush, onTrack, onTrigger } = EMPTY_OBJ, instance = currentInstance) {
if ((process.env.NODE_ENV !== 'production') && !cb) {
if (immediate !== undefined) {
warn(`watch() "immediate" option is only respected when using the ` +
`watch(source, callback, options?) signature.`);
}
if (deep !== undefined) {
warn(`watch() "deep" option is only respected when using the ` +
`watch(source, callback, options?) signature.`);
}
}
const warnInvalidSource = (s) => {
warn(`Invalid watch source: `, s, `A watch source can only be a getter/effect function, a ref, ` +
`a reactive object, or an array of these types.`);
};
let getter;
let forceTrigger = false;
if (isRef(source)) {
getter = () => source.value;
forceTrigger = !!source._shallow;
}
else if (isReactive(source)) {
getter = () => source;
deep = true;
}
else if (isArray(source)) {
getter = () => source.map(s => {
if (isRef(s)) {
return s.value;
}
else if (isReactive(s)) {
return traverse(s);
}
else if (isFunction(s)) {
return callWithErrorHandling(s, instance, 2 /* WATCH_GETTER */, [
instance && instance.proxy
]);
}
else {
(process.env.NODE_ENV !== 'production') && warnInvalidSource(s);
}
});
}
else if (isFunction(source)) {
if (cb) {
// getter with cb
getter = () => callWithErrorHandling(source, instance, 2 /* WATCH_GETTER */, [
instance && instance.proxy
]);
}
else {
// no cb -> simple effect
getter = () => {
if (instance && instance.isUnmounted) {
return;
}
if (cleanup) {
cleanup();
}
return callWithErrorHandling(source, instance, 3 /* WATCH_CALLBACK */, [onInvalidate]);
};
}
}
else {
getter = NOOP;
(process.env.NODE_ENV !== 'production') && warnInvalidSource(source);
}
if (cb && deep) {
const baseGetter = getter;
getter = () => traverse(baseGetter());
}
let cleanup;
const onInvalidate = (fn) => {
cleanup = runner.options.onStop = () => {
callWithErrorHandling(fn, instance, 4 /* WATCH_CLEANUP */);
};
};
let oldValue = isArray(source) ? [] : INITIAL_WATCHER_VALUE;
const job = () => {
if (!runner.active) {
return;
}
if (cb) {
// watch(source, cb)
const newValue = runner();
if (deep || forceTrigger || hasChanged(newValue, oldValue)) {
// cleanup before running cb again
if (cleanup) {
cleanup();
}
callWithAsyncErrorHandling(cb, instance, 3 /* WATCH_CALLBACK */, [
newValue,
// pass undefined as the old value when it's changed for the first time
oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue,
onInvalidate
]);
oldValue = newValue;
}
}
else {
// watchEffect
runner();
}
};
// important: mark the job as a watcher callback so that scheduler knows
// it is allowed to self-trigger (#1727)
job.allowRecurse = !!cb;
let scheduler;
if (flush === 'sync') {
scheduler = job;
}
else if (flush === 'post') {
scheduler = () => queuePostRenderEffect(job, instance && instance.suspense);
}
else {
// default: 'pre'
scheduler = () => {
if (!instance || instance.isMounted) {
queuePreFlushCb(job);
}
else {
// with 'pre' option, the first call must happen before
// the component is mounted so it is called synchronously.
job();
}
};
}
const runner = effect(getter, {
lazy: true,
onTrack,
onTrigger,
scheduler
});
recordInstanceBoundEffect(runner, instance);
// initial run
if (cb) {
if (immediate) {
job();
}
else {
oldValue = runner();
}
}
else if (flush === 'post') {
queuePostRenderEffect(runner, instance && instance.suspense);
}
else {
runner();
}
return () => {
stop(runner);
if (instance) {
remove(instance.effects, runner);
}
};
}
// this.$watch
function instanceWatch(source, cb, options) {
const publicThis = this.proxy;
const getter = isString(source)
? () => publicThis[source]
: source.bind(publicThis);
return doWatch(getter, cb.bind(publicThis), options, this);
}
function traverse(value, seen = new Set()) {
if (!isObject(value) || seen.has(value)) {
return value;
}
seen.add(value);
if (isRef(value)) {
traverse(value.value, seen);
}
else if (isArray(value)) {
for (let i = 0; i < value.length; i++) {
traverse(value[i], seen);
}
}
else if (isSet(value) || isMap(value)) {
value.forEach((v) => {
traverse(v, seen);
});
}
else {
for (const key in value) {
traverse(value[key], seen);
}
}
return value;
}
const isKeepAlive = (vnode) => vnode.type.__isKeepAlive;
function onActivated(hook, target) {
registerKeepAliveHook(hook, "a" /* ACTIVATED */, target);
......@@ -1880,7 +2062,10 @@ function createAppContext() {
}
let uid$1 = 0;
// fixed by xxxxxx
function createAppAPI() {
function createAppAPI(
// render: RootRenderFunction,
// hydrate?: RootHydrateFunction
) {
return function createApp(rootComponent, rootProps = null) {
if (rootProps != null && !isObject(rootProps)) {
(process.env.NODE_ENV !== 'production') && warn(`root props passed to app.mount() must be an object.`);
......@@ -1993,207 +2178,349 @@ function defineComponent(options) {
return isFunction(options) ? { setup: options, name: options.name } : options;
}
const queuePostRenderEffect = queuePostFlushCb;
const queuePostRenderEffect = queuePostFlushCb;
// Simple effect.
function watchEffect(effect, options) {
return doWatch(effect, null, options);
const isTeleport = (type) => type.__isTeleport;
const COMPONENTS = 'components';
const DIRECTIVES = 'directives';
const NULL_DYNAMIC_COMPONENT = Symbol();
/**
* @private
*/
function resolveDirective(name) {
return resolveAsset(DIRECTIVES, name);
}
// initial value for watchers to trigger on undefined initial values
const INITIAL_WATCHER_VALUE = {};
// implementation
function watch(source, cb, options) {
if ((process.env.NODE_ENV !== 'production') && !isFunction(cb)) {
warn(`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
`Use \`watchEffect(fn, options?)\` instead. \`watch\` now only ` +
`supports \`watch(source, cb, options?) signature.`);
}
return doWatch(source, cb, options);
}
function doWatch(source, cb, { immediate, deep, flush, onTrack, onTrigger } = EMPTY_OBJ, instance = currentInstance) {
if ((process.env.NODE_ENV !== 'production') && !cb) {
if (immediate !== undefined) {
warn(`watch() "immediate" option is only respected when using the ` +
`watch(source, callback, options?) signature.`);
}
if (deep !== undefined) {
warn(`watch() "deep" option is only respected when using the ` +
`watch(source, callback, options?) signature.`);
}
}
const warnInvalidSource = (s) => {
warn(`Invalid watch source: `, s, `A watch source can only be a getter/effect function, a ref, ` +
`a reactive object, or an array of these types.`);
};
let getter;
let forceTrigger = false;
if (isRef(source)) {
getter = () => source.value;
forceTrigger = !!source._shallow;
}
else if (isReactive(source)) {
getter = () => source;
deep = true;
}
else if (isArray(source)) {
getter = () => source.map(s => {
if (isRef(s)) {
return s.value;
}
else if (isReactive(s)) {
return traverse(s);
}
else if (isFunction(s)) {
return callWithErrorHandling(s, instance, 2 /* WATCH_GETTER */);
function resolveAsset(type, name, warnMissing = true) {
const instance = currentInstance;
if (instance) {
const Component = instance.type;
// self name has highest priority
if (type === COMPONENTS) {
// special self referencing call generated by compiler
// inferred from SFC filename
if (name === `_self`) {
return Component;
}
else {
(process.env.NODE_ENV !== 'production') && warnInvalidSource(s);
const selfName = getComponentName(Component);
if (selfName &&
(selfName === name ||
selfName === camelize(name) ||
selfName === capitalize(camelize(name)))) {
return Component;
}
});
}
else if (isFunction(source)) {
if (cb) {
// getter with cb
getter = () => callWithErrorHandling(source, instance, 2 /* WATCH_GETTER */);
}
else {
// no cb -> simple effect
getter = () => {
if (instance && instance.isUnmounted) {
return;
}
if (cleanup) {
cleanup();
}
return callWithErrorHandling(source, instance, 3 /* WATCH_CALLBACK */, [onInvalidate]);
};
const res =
// local registration
// check instance[type] first for components with mixin or extends.
resolve(instance[type] || Component[type], name) ||
// global registration
resolve(instance.appContext[type], name);
if ((process.env.NODE_ENV !== 'production') && warnMissing && !res) {
warn(`Failed to resolve ${type.slice(0, -1)}: ${name}`);
}
return res;
}
else {
getter = NOOP;
(process.env.NODE_ENV !== 'production') && warnInvalidSource(source);
}
if (cb && deep) {
const baseGetter = getter;
getter = () => traverse(baseGetter());
else if ((process.env.NODE_ENV !== 'production')) {
warn(`resolve${capitalize(type.slice(0, -1))} ` +
`can only be used in render() or setup().`);
}
let cleanup;
const onInvalidate = (fn) => {
cleanup = runner.options.onStop = () => {
callWithErrorHandling(fn, instance, 4 /* WATCH_CLEANUP */);
};
}
function resolve(registry, name) {
return (registry &&
(registry[name] ||
registry[camelize(name)] ||
registry[capitalize(camelize(name))]));
}
const Fragment = Symbol((process.env.NODE_ENV !== 'production') ? 'Fragment' : undefined);
const Text = Symbol((process.env.NODE_ENV !== 'production') ? 'Text' : undefined);
const Comment = Symbol((process.env.NODE_ENV !== 'production') ? 'Comment' : undefined);
Symbol((process.env.NODE_ENV !== 'production') ? 'Static' : undefined);
let currentBlock = null;
function isVNode(value) {
return value ? value.__v_isVNode === true : false;
}
const createVNodeWithArgsTransform = (...args) => {
return _createVNode(...(args));
};
const InternalObjectKey = `__vInternal`;
const normalizeKey = ({ key }) => key != null ? key : null;
const normalizeRef = ({ ref }) => {
return (ref != null
? isString(ref) || isRef(ref) || isFunction(ref)
? { i: currentRenderingInstance, r: ref }
: ref
: null);
};
const createVNode = ((process.env.NODE_ENV !== 'production')
? createVNodeWithArgsTransform
: _createVNode);
function _createVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, isBlockNode = false) {
if (!type || type === NULL_DYNAMIC_COMPONENT) {
if ((process.env.NODE_ENV !== 'production') && !type) {
warn(`Invalid vnode type when creating vnode: ${type}.`);
}
type = Comment;
}
if (isVNode(type)) {
// createVNode receiving an existing vnode. This happens in cases like
// <component :is="vnode"/>
// #2078 make sure to merge refs during the clone instead of overwriting it
const cloned = cloneVNode(type, props, true /* mergeRef: true */);
if (children) {
normalizeChildren(cloned, children);
}
return cloned;
}
// class component normalization.
if (isClassComponent(type)) {
type = type.__vccOpts;
}
// class & style normalization.
if (props) {
// for reactive or proxy objects, we need to clone it to enable mutation.
if (isProxy(props) || InternalObjectKey in props) {
props = extend({}, props);
}
let { class: klass, style } = props;
if (klass && !isString(klass)) {
props.class = normalizeClass(klass);
}
if (isObject(style)) {
// reactive state objects need to be cloned since they are likely to be
// mutated
if (isProxy(style) && !isArray(style)) {
style = extend({}, style);
}
props.style = normalizeStyle(style);
}
}
// encode the vnode type information into a bitmap
const shapeFlag = isString(type)
? 1 /* ELEMENT */
: isTeleport(type)
? 64 /* TELEPORT */
: isObject(type)
? 4 /* STATEFUL_COMPONENT */
: isFunction(type)
? 2 /* FUNCTIONAL_COMPONENT */
: 0;
if ((process.env.NODE_ENV !== 'production') && shapeFlag & 4 /* STATEFUL_COMPONENT */ && isProxy(type)) {
type = toRaw(type);
warn(`Vue received a Component which was made a reactive object. This can ` +
`lead to unnecessary performance overhead, and should be avoided by ` +
`marking the component with \`markRaw\` or using \`shallowRef\` ` +
`instead of \`ref\`.`, `\nComponent that was made reactive: `, type);
}
const vnode = {
__v_isVNode: true,
["__v_skip" /* SKIP */]: true,
type,
props,
key: props && normalizeKey(props),
ref: props && normalizeRef(props),
scopeId: currentScopeId,
slotScopeIds: null,
children: null,
component: null,
suspense: null,
ssContent: null,
ssFallback: null,
dirs: null,
transition: null,
el: null,
anchor: null,
target: null,
targetAnchor: null,
staticCount: 0,
shapeFlag,
patchFlag,
dynamicProps,
dynamicChildren: null,
appContext: null
};
let oldValue = isArray(source) ? [] : INITIAL_WATCHER_VALUE;
const job = () => {
if (!runner.active) {
// validate key
if ((process.env.NODE_ENV !== 'production') && vnode.key !== vnode.key) {
warn(`VNode created with invalid key (NaN). VNode type:`, vnode.type);
}
normalizeChildren(vnode, children);
if (// avoid a block node from tracking itself
!isBlockNode &&
// has current parent block
currentBlock &&
// presence of a patch flag indicates this node needs patching on updates.
// component nodes also should always be patched, because even if the
// component doesn't need to update, it needs to persist the instance on to
// the next vnode so that it can be properly unmounted later.
(patchFlag > 0 || shapeFlag & 6 /* COMPONENT */) &&
// the EVENTS flag is only for hydration and if it is the only flag, the
// vnode should not be considered dynamic due to handler caching.
patchFlag !== 32 /* HYDRATE_EVENTS */) {
currentBlock.push(vnode);
}
return vnode;
}
function cloneVNode(vnode, extraProps, mergeRef = false) {
// This is intentionally NOT using spread or extend to avoid the runtime
// key enumeration cost.
const { props, ref, patchFlag, children } = vnode;
const mergedProps = extraProps ? mergeProps(props || {}, extraProps) : props;
return {
__v_isVNode: true,
["__v_skip" /* SKIP */]: true,
type: vnode.type,
props: mergedProps,
key: mergedProps && normalizeKey(mergedProps),
ref: extraProps && extraProps.ref
? // #2078 in the case of <component :is="vnode" ref="extra"/>
// if the vnode itself already has a ref, cloneVNode will need to merge
// the refs so the single vnode can be set on multiple refs
mergeRef && ref
? isArray(ref)
? ref.concat(normalizeRef(extraProps))
: [ref, normalizeRef(extraProps)]
: normalizeRef(extraProps)
: ref,
scopeId: vnode.scopeId,
slotScopeIds: vnode.slotScopeIds,
children: (process.env.NODE_ENV !== 'production') && patchFlag === -1 /* HOISTED */ && isArray(children)
? children.map(deepCloneVNode)
: children,
target: vnode.target,
targetAnchor: vnode.targetAnchor,
staticCount: vnode.staticCount,
shapeFlag: vnode.shapeFlag,
// if the vnode is cloned with extra props, we can no longer assume its
// existing patch flag to be reliable and need to add the FULL_PROPS flag.
// note: perserve flag for fragments since they use the flag for children
// fast paths only.
patchFlag: extraProps && vnode.type !== Fragment
? patchFlag === -1 // hoisted node
? 16 /* FULL_PROPS */
: patchFlag | 16 /* FULL_PROPS */
: patchFlag,
dynamicProps: vnode.dynamicProps,
dynamicChildren: vnode.dynamicChildren,
appContext: vnode.appContext,
dirs: vnode.dirs,
transition: vnode.transition,
// These should technically only be non-null on mounted VNodes. However,
// they *should* be copied for kept-alive vnodes. So we just always copy
// them since them being non-null during a mount doesn't affect the logic as
// they will simply be overwritten.
component: vnode.component,
suspense: vnode.suspense,
ssContent: vnode.ssContent && cloneVNode(vnode.ssContent),
ssFallback: vnode.ssFallback && cloneVNode(vnode.ssFallback),
el: vnode.el,
anchor: vnode.anchor
};
}
/**
* Dev only, for HMR of hoisted vnodes reused in v-for
* https://github.com/vitejs/vite/issues/2022
*/
function deepCloneVNode(vnode) {
const cloned = cloneVNode(vnode);
if (isArray(vnode.children)) {
cloned.children = vnode.children.map(deepCloneVNode);
}
return cloned;
}
/**
* @private
*/
function createTextVNode(text = ' ', flag = 0) {
return createVNode(Text, null, text, flag);
}
function normalizeChildren(vnode, children) {
let type = 0;
const { shapeFlag } = vnode;
if (children == null) {
children = null;
}
else if (isArray(children)) {
type = 16 /* ARRAY_CHILDREN */;
}
else if (typeof children === 'object') {
if (shapeFlag & 1 /* ELEMENT */ || shapeFlag & 64 /* TELEPORT */) {
// Normalize slot to plain children for plain element and Teleport
const slot = children.default;
if (slot) {
// _c marker is added by withCtx() indicating this is a compiled slot
slot._c && setCompiledSlotRendering(1);
normalizeChildren(vnode, slot());
slot._c && setCompiledSlotRendering(-1);
}
return;
}
if (cb) {
// watch(source, cb)
const newValue = runner();
if (deep || forceTrigger || hasChanged(newValue, oldValue)) {
// cleanup before running cb again
if (cleanup) {
cleanup();
else {
type = 32 /* SLOTS_CHILDREN */;
const slotFlag = children._;
if (!slotFlag && !(InternalObjectKey in children)) {
children._ctx = currentRenderingInstance;
}
else if (slotFlag === 3 /* FORWARDED */ && currentRenderingInstance) {
// a child component receives forwarded slots from the parent.
// its slot type is determined by its parent's slot type.
if (currentRenderingInstance.vnode.patchFlag & 1024 /* DYNAMIC_SLOTS */) {
children._ = 2 /* DYNAMIC */;
vnode.patchFlag |= 1024 /* DYNAMIC_SLOTS */;
}
else {
children._ = 1 /* STABLE */;
}
callWithAsyncErrorHandling(cb, instance, 3 /* WATCH_CALLBACK */, [
newValue,
// pass undefined as the old value when it's changed for the first time
oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue,
onInvalidate
]);
oldValue = newValue;
}
}
else {
// watchEffect
runner();
}
};
// important: mark the job as a watcher callback so that scheduler knows
// it is allowed to self-trigger (#1727)
job.allowRecurse = !!cb;
let scheduler;
if (flush === 'sync') {
scheduler = job;
}
else if (flush === 'post') {
scheduler = () => queuePostRenderEffect(job, instance && instance.suspense);
else if (isFunction(children)) {
children = { default: children, _ctx: currentRenderingInstance };
type = 32 /* SLOTS_CHILDREN */;
}
else {
// default: 'pre'
scheduler = () => {
if (!instance || instance.isMounted) {
queuePreFlushCb(job);
}
else {
// with 'pre' option, the first call must happen before
// the component is mounted so it is called synchronously.
job();
}
};
}
const runner = effect(getter, {
lazy: true,
onTrack,
onTrigger,
scheduler
});
recordInstanceBoundEffect(runner, instance);
// initial run
if (cb) {
if (immediate) {
job();
children = String(children);
// force teleport children to array so it can be moved around
if (shapeFlag & 64 /* TELEPORT */) {
type = 16 /* ARRAY_CHILDREN */;
children = [createTextVNode(children)];
}
else {
oldValue = runner();
type = 8 /* TEXT_CHILDREN */;
}
}
else if (flush === 'post') {
queuePostRenderEffect(runner, instance && instance.suspense);
}
else {
runner();
}
return () => {
stop(runner);
if (instance) {
remove(instance.effects, runner);
}
};
}
// this.$watch
function instanceWatch(source, cb, options) {
const publicThis = this.proxy;
const getter = isString(source)
? () => publicThis[source]
: source.bind(publicThis);
return doWatch(getter, cb.bind(publicThis), options, this);
vnode.children = children;
vnode.shapeFlag |= type;
}
function traverse(value, seen = new Set()) {
if (!isObject(value) || seen.has(value)) {
return value;
}
seen.add(value);
if (isRef(value)) {
traverse(value.value, seen);
}
else if (isArray(value)) {
for (let i = 0; i < value.length; i++) {
traverse(value[i], seen);
}
}
else if (isSet(value) || isMap(value)) {
value.forEach((v) => {
traverse(v, seen);
});
}
else {
for (const key in value) {
traverse(value[key], seen);
function mergeProps(...args) {
const ret = extend({}, args[0]);
for (let i = 1; i < args.length; i++) {
const toMerge = args[i];
for (const key in toMerge) {
if (key === 'class') {
if (ret.class !== toMerge.class) {
ret.class = normalizeClass([ret.class, toMerge.class]);
}
}
else if (key === 'style') {
ret.style = normalizeStyle([ret.style, toMerge.style]);
}
else if (isOn(key)) {
const existing = ret[key];
const incoming = toMerge[key];
if (existing !== incoming) {
ret[key] = existing
? [].concat(existing, toMerge[key])
: incoming;
}
}
else if (key !== '') {
ret[key] = toMerge[key];
}
}
}
return value;
return ret;
}
function provide(key, value) {
......@@ -2338,7 +2665,19 @@ function applyOptions(instance, options, deferredData = [], deferredWatch = [],
for (const key in methods) {
const methodHandler = methods[key];
if (isFunction(methodHandler)) {
ctx[key] = methodHandler.bind(publicThis);
// In dev mode, we use the `createRenderContext` function to define methods to the proxy target,
// and those are read-only but reconfigurable, so it needs to be redefined here
if ((process.env.NODE_ENV !== 'production')) {
Object.defineProperty(ctx, key, {
value: methodHandler.bind(publicThis),
configurable: true,
enumerable: true,
writable: true
});
}
else {
ctx[key] = methodHandler.bind(publicThis);
}
if ((process.env.NODE_ENV !== 'production')) {
checkDuplicateProperties("Methods" /* METHODS */, key);
}
......@@ -2660,7 +2999,13 @@ function mergeOptions(to, from, instance) {
* they exist in the internal parent chain. For code that relies on traversing
* public $parent chains, skip functional ones and go to the parent instead.
*/
const getPublicInstance = (i) => i && (i.proxy ? i.proxy : getPublicInstance(i.parent));
const getPublicInstance = (i) => {
if (!i)
return null;
if (isStatefulComponent(i))
return i.exposed ? i.exposed : i.proxy;
return getPublicInstance(i.parent);
};
const publicPropertiesMap = extend(Object.create(null), {
$: i => i,
$el: i => i.vnode.el,
......@@ -2670,7 +3015,7 @@ const publicPropertiesMap = extend(Object.create(null), {
$slots: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.slots) : i.slots),
$refs: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.refs) : i.refs),
$parent: i => getPublicInstance(i.parent),
$root: i => i.root && i.root.proxy,
$root: i => getPublicInstance(i.root),
$emit: i => i.emit,
$options: i => (__VUE_OPTIONS_API__ ? resolveMergedOptions(i) : i.type),
$forceUpdate: i => () => queueJob(i.update),
......@@ -2773,7 +3118,7 @@ const PublicInstanceProxyHandlers = {
warn(`Property ${JSON.stringify(key)} must be accessed via $data because it starts with a reserved ` +
`character ("$" or "_") and is not proxied on the render context.`);
}
else {
else if (instance === currentRenderingInstance) {
warn(`Property ${JSON.stringify(key)} was accessed during render ` +
`but is not defined on instance.`);
}
......@@ -2787,7 +3132,7 @@ const PublicInstanceProxyHandlers = {
else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
data[key] = value;
}
else if (key in instance.props) {
else if (hasOwn(instance.props, key)) {
(process.env.NODE_ENV !== 'production') &&
warn(`Attempting to mutate prop "${key}". Props are readonly.`, instance);
return false;
......@@ -2986,7 +3331,6 @@ function createComponentInstance(vnode, parent, suspense) {
}
instance.root = parent ? parent.root : instance;
instance.emit = emit.bind(null, instance);
if ((process.env.NODE_ENV !== 'production') || false) ;
return instance;
}
let currentInstance = null;
......@@ -3001,11 +3345,14 @@ function validateComponentName(name, config) {
warn('Do not use built-in or reserved HTML elements as component id: ' + name);
}
}
function isStatefulComponent(instance) {
return instance.vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */;
}
let isInSSRComponentSetup = false;
function setupComponent(instance, isSSR = false) {
isInSSRComponentSetup = isSSR;
const { props, /* children, */ shapeFlag } = instance.vnode;
const isStateful = shapeFlag & 4 /* STATEFUL_COMPONENT */;
const { props /*, children*/ } = instance.vnode;
const isStateful = isStatefulComponent(instance);
initProps(instance, props, isStateful, isSSR);
// initSlots(instance, children) // fixed by xxxxxx
const setupResult = isStateful
......@@ -3079,12 +3426,10 @@ function handleSetupResult(instance, setupResult, isSSR) {
}
}
else if (isObject(setupResult)) {
// if ((process.env.NODE_ENV !== 'production') && isVNode(setupResult)) {
// warn(
// `setup() should not return VNodes directly - ` +
// `return a render function instead.`
// )
// }
if ((process.env.NODE_ENV !== 'production') && isVNode(setupResult)) {
warn(`setup() should not return VNodes directly - ` +
`return a render function instead.`);
}
// setup returned bindings.
// assuming a render function compiled from template is present.
if ((process.env.NODE_ENV !== 'production') || false) {
......@@ -3123,10 +3468,10 @@ function finishComponentSetup(instance, isSSR) {
// warn missing template/render
if ((process.env.NODE_ENV !== 'production') && !Component.render && instance.render === NOOP) {
/* istanbul ignore if */
if ( Component.template) {
if (Component.template) {
warn(`Component provided template option but ` +
`runtime compilation is not supported in this build of Vue.` +
( ` Configure your bundler to alias "vue" to "vue/dist/vue.esm-bundler.js".`
(` Configure your bundler to alias "vue" to "vue/dist/vue.esm-bundler.js".`
) /* should not happen */);
}
else {
......@@ -3220,6 +3565,9 @@ function formatComponentName(instance, Component, isRoot = false) {
instance.parent.type.components) || inferFromRegistry(instance.appContext.components);
}
return name ? classify(name) : isRoot ? `App` : `Anonymous`;
}
function isClassComponent(value) {
return isFunction(value) && '__vccOpts' in value;
}
function computed$1(getterOrOptions) {
......@@ -3248,7 +3596,7 @@ function defineEmit() {
}
// Core API ------------------------------------------------------------------
const version = "3.0.5";
const version = "3.0.7";
// import deepCopy from './deepCopy'
/**
......
import { EMPTY_OBJ, isArray, isMap, isIntegerKey, isSymbol, extend, hasOwn, isObject, hasChanged, capitalize, toRawType, def, isFunction, NOOP, isString, isPromise, toHandlerKey, toNumber, hyphenate, camelize, isOn, isReservedProp, EMPTY_ARR, makeMap, remove, NO, isSet, isGloballyWhitelisted, toTypeString, invokeArrayFns } from '@vue/shared';
import { EMPTY_OBJ, isArray, isMap, isIntegerKey, isSymbol, extend, hasOwn, isObject, hasChanged, makeMap, capitalize, toRawType, def, isFunction, NOOP, isString, isPromise, toHandlerKey, toNumber, hyphenate, camelize, isOn, isReservedProp, EMPTY_ARR, remove, isSet, NO, normalizeClass, normalizeStyle, isGloballyWhitelisted, toTypeString, invokeArrayFns } from '@vue/shared';
export { camelize } from '@vue/shared';
const targetMap = new WeakMap();
......@@ -190,6 +190,7 @@ function trigger(target, type, key, newValue, oldValue, oldTarget) {
effects.forEach(run);
}
const isNonTrackableKeys = /*#__PURE__*/ makeMap(`__proto__,__v_isRef,__isVue`);
const builtInSymbols = new Set(Object.getOwnPropertyNames(Symbol)
.map(key => Symbol[key])
.filter(isSymbol));
......@@ -244,7 +245,7 @@ function createGetter(isReadonly = false, shallow = false) {
const res = Reflect.get(target, key, receiver);
if (isSymbol(key)
? builtInSymbols.has(key)
: key === `__proto__` || key === `__v_isRef`) {
: isNonTrackableKeys(key)) {
return res;
}
if (!isReadonly) {
......@@ -393,8 +394,8 @@ function add(value) {
const target = toRaw(this);
const proto = getProto(target);
const hadKey = proto.has.call(target, value);
target.add(value);
if (!hadKey) {
target.add(value);
trigger(target, "add" /* ADD */, value, value);
}
return this;
......@@ -1096,6 +1097,22 @@ function nextTick(fn) {
const p = currentFlushPromise || resolvedPromise;
return fn ? p.then(this ? fn.bind(this) : fn) : p;
}
// #2768
// Use binary-search to find a suitable position in the queue,
// so that the queue maintains the increasing order of job's id,
// which can prevent the job from being skipped and also can avoid repeated patching.
function findInsertionIndex(job) {
// the start index should be `flushIndex + 1`
let start = flushIndex + 1;
let end = queue.length;
const jobId = getId(job);
while (start < end) {
const middle = (start + end) >>> 1;
const middleJobId = getId(queue[middle]);
middleJobId < jobId ? (start = middle + 1) : (end = middle);
}
return start;
}
function queueJob(job) {
// the dedupe search uses the startIndex argument of Array.includes()
// by default the search index includes the current job that is being run
......@@ -1106,7 +1123,13 @@ function queueJob(job) {
if ((!queue.length ||
!queue.includes(job, isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex)) &&
job !== currentPreFlushParentJob) {
queue.push(job);
const pos = findInsertionIndex(job);
if (pos > -1) {
queue.splice(pos, 0, job);
}
else {
queue.push(job);
}
queueFlush();
}
}
......@@ -1358,63 +1381,17 @@ function isEmitListener(options, key) {
hasOwn(options, key));
}
let isRenderingCompiledSlot = 0;
const setCompiledSlotRendering = (n) => (isRenderingCompiledSlot += n);
/**
* mark the current rendering instance for asset resolution (e.g.
* resolveComponent, resolveDirective) during render
*/
let currentRenderingInstance = null;
function markAttrsAccessed() {
}
let currentScopeId = null;
const COMPONENTS = 'components';
const DIRECTIVES = 'directives';
/**
* @private
*/
function resolveDirective(name) {
return resolveAsset(DIRECTIVES, name);
}
// implementation
function resolveAsset(type, name, warnMissing = true) {
const instance = currentInstance;
if (instance) {
const Component = instance.type;
// self name has highest priority
if (type === COMPONENTS) {
// special self referencing call generated by compiler
// inferred from SFC filename
if (name === `_self`) {
return Component;
}
const selfName = getComponentName(Component);
if (selfName &&
(selfName === name ||
selfName === camelize(name) ||
selfName === capitalize(camelize(name)))) {
return Component;
}
}
const res =
// local registration
// check instance[type] first for components with mixin or extends.
resolve(instance[type] || Component[type], name) ||
// global registration
resolve(instance.appContext[type], name);
if ((process.env.NODE_ENV !== 'production') && warnMissing && !res) {
warn(`Failed to resolve ${type.slice(0, -1)}: ${name}`);
}
return res;
}
else if ((process.env.NODE_ENV !== 'production')) {
warn(`resolve${capitalize(type.slice(0, -1))} ` +
`can only be used in render() or setup().`);
}
}
function resolve(registry, name) {
return (registry &&
(registry[name] ||
registry[camelize(name)] ||
registry[capitalize(camelize(name))]));
function markAttrsAccessed() {
}
function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison
......@@ -1650,7 +1627,7 @@ function validateProp(name, value, prop, isAbsent) {
warn('Invalid prop: custom validator check failed for prop "' + name + '".');
}
}
const isSimpleType = /*#__PURE__*/ makeMap('String,Number,Boolean,Function,Symbol');
const isSimpleType = /*#__PURE__*/ makeMap('String,Number,Boolean,Function,Symbol,BigInt');
/**
* dev only
*/
......@@ -1766,7 +1743,7 @@ function injectHook(type, hook, target = currentInstance, prepend = false) {
warn(`${apiName} is called when there is no active component instance to be ` +
`associated with. ` +
`Lifecycle injection APIs can only be used during execution of setup().` +
( ``));
(``));
}
}
const createHook = (lifecycle) => (hook, target = currentInstance) =>
......@@ -1784,6 +1761,211 @@ const onErrorCaptured = (hook, target = currentInstance) => {
injectHook("ec" /* ERROR_CAPTURED */, hook, target);
};
// Simple effect.
function watchEffect(effect, options) {
return doWatch(effect, null, options);
}
// initial value for watchers to trigger on undefined initial values
const INITIAL_WATCHER_VALUE = {};
// implementation
function watch(source, cb, options) {
if ((process.env.NODE_ENV !== 'production') && !isFunction(cb)) {
warn(`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
`Use \`watchEffect(fn, options?)\` instead. \`watch\` now only ` +
`supports \`watch(source, cb, options?) signature.`);
}
return doWatch(source, cb, options);
}
function doWatch(source, cb, { immediate, deep, flush, onTrack, onTrigger } = EMPTY_OBJ, instance = currentInstance) {
if ((process.env.NODE_ENV !== 'production') && !cb) {
if (immediate !== undefined) {
warn(`watch() "immediate" option is only respected when using the ` +
`watch(source, callback, options?) signature.`);
}
if (deep !== undefined) {
warn(`watch() "deep" option is only respected when using the ` +
`watch(source, callback, options?) signature.`);
}
}
const warnInvalidSource = (s) => {
warn(`Invalid watch source: `, s, `A watch source can only be a getter/effect function, a ref, ` +
`a reactive object, or an array of these types.`);
};
let getter;
let forceTrigger = false;
if (isRef(source)) {
getter = () => source.value;
forceTrigger = !!source._shallow;
}
else if (isReactive(source)) {
getter = () => source;
deep = true;
}
else if (isArray(source)) {
getter = () => source.map(s => {
if (isRef(s)) {
return s.value;
}
else if (isReactive(s)) {
return traverse(s);
}
else if (isFunction(s)) {
return callWithErrorHandling(s, instance, 2 /* WATCH_GETTER */, [
instance && instance.proxy
]);
}
else {
(process.env.NODE_ENV !== 'production') && warnInvalidSource(s);
}
});
}
else if (isFunction(source)) {
if (cb) {
// getter with cb
getter = () => callWithErrorHandling(source, instance, 2 /* WATCH_GETTER */, [
instance && instance.proxy
]);
}
else {
// no cb -> simple effect
getter = () => {
if (instance && instance.isUnmounted) {
return;
}
if (cleanup) {
cleanup();
}
return callWithErrorHandling(source, instance, 3 /* WATCH_CALLBACK */, [onInvalidate]);
};
}
}
else {
getter = NOOP;
(process.env.NODE_ENV !== 'production') && warnInvalidSource(source);
}
if (cb && deep) {
const baseGetter = getter;
getter = () => traverse(baseGetter());
}
let cleanup;
const onInvalidate = (fn) => {
cleanup = runner.options.onStop = () => {
callWithErrorHandling(fn, instance, 4 /* WATCH_CLEANUP */);
};
};
let oldValue = isArray(source) ? [] : INITIAL_WATCHER_VALUE;
const job = () => {
if (!runner.active) {
return;
}
if (cb) {
// watch(source, cb)
const newValue = runner();
if (deep || forceTrigger || hasChanged(newValue, oldValue)) {
// cleanup before running cb again
if (cleanup) {
cleanup();
}
callWithAsyncErrorHandling(cb, instance, 3 /* WATCH_CALLBACK */, [
newValue,
// pass undefined as the old value when it's changed for the first time
oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue,
onInvalidate
]);
oldValue = newValue;
}
}
else {
// watchEffect
runner();
}
};
// important: mark the job as a watcher callback so that scheduler knows
// it is allowed to self-trigger (#1727)
job.allowRecurse = !!cb;
let scheduler;
if (flush === 'sync') {
scheduler = job;
}
else if (flush === 'post') {
scheduler = () => queuePostRenderEffect(job, instance && instance.suspense);
}
else {
// default: 'pre'
scheduler = () => {
if (!instance || instance.isMounted) {
queuePreFlushCb(job);
}
else {
// with 'pre' option, the first call must happen before
// the component is mounted so it is called synchronously.
job();
}
};
}
const runner = effect(getter, {
lazy: true,
onTrack,
onTrigger,
scheduler
});
recordInstanceBoundEffect(runner, instance);
// initial run
if (cb) {
if (immediate) {
job();
}
else {
oldValue = runner();
}
}
else if (flush === 'post') {
queuePostRenderEffect(runner, instance && instance.suspense);
}
else {
runner();
}
return () => {
stop(runner);
if (instance) {
remove(instance.effects, runner);
}
};
}
// this.$watch
function instanceWatch(source, cb, options) {
const publicThis = this.proxy;
const getter = isString(source)
? () => publicThis[source]
: source.bind(publicThis);
return doWatch(getter, cb.bind(publicThis), options, this);
}
function traverse(value, seen = new Set()) {
if (!isObject(value) || seen.has(value)) {
return value;
}
seen.add(value);
if (isRef(value)) {
traverse(value.value, seen);
}
else if (isArray(value)) {
for (let i = 0; i < value.length; i++) {
traverse(value[i], seen);
}
}
else if (isSet(value) || isMap(value)) {
value.forEach((v) => {
traverse(v, seen);
});
}
else {
for (const key in value) {
traverse(value[key], seen);
}
}
return value;
}
const isKeepAlive = (vnode) => vnode.type.__isKeepAlive;
function onActivated(hook, target) {
registerKeepAliveHook(hook, "a" /* ACTIVATED */, target);
......@@ -1880,7 +2062,10 @@ function createAppContext() {
}
let uid$1 = 0;
// fixed by xxxxxx
function createAppAPI() {
function createAppAPI(
// render: RootRenderFunction,
// hydrate?: RootHydrateFunction
) {
return function createApp(rootComponent, rootProps = null) {
if (rootProps != null && !isObject(rootProps)) {
(process.env.NODE_ENV !== 'production') && warn(`root props passed to app.mount() must be an object.`);
......@@ -1993,207 +2178,349 @@ function defineComponent(options) {
return isFunction(options) ? { setup: options, name: options.name } : options;
}
const queuePostRenderEffect = queuePostFlushCb;
const queuePostRenderEffect = queuePostFlushCb;
// Simple effect.
function watchEffect(effect, options) {
return doWatch(effect, null, options);
const isTeleport = (type) => type.__isTeleport;
const COMPONENTS = 'components';
const DIRECTIVES = 'directives';
const NULL_DYNAMIC_COMPONENT = Symbol();
/**
* @private
*/
function resolveDirective(name) {
return resolveAsset(DIRECTIVES, name);
}
// initial value for watchers to trigger on undefined initial values
const INITIAL_WATCHER_VALUE = {};
// implementation
function watch(source, cb, options) {
if ((process.env.NODE_ENV !== 'production') && !isFunction(cb)) {
warn(`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
`Use \`watchEffect(fn, options?)\` instead. \`watch\` now only ` +
`supports \`watch(source, cb, options?) signature.`);
}
return doWatch(source, cb, options);
}
function doWatch(source, cb, { immediate, deep, flush, onTrack, onTrigger } = EMPTY_OBJ, instance = currentInstance) {
if ((process.env.NODE_ENV !== 'production') && !cb) {
if (immediate !== undefined) {
warn(`watch() "immediate" option is only respected when using the ` +
`watch(source, callback, options?) signature.`);
}
if (deep !== undefined) {
warn(`watch() "deep" option is only respected when using the ` +
`watch(source, callback, options?) signature.`);
}
}
const warnInvalidSource = (s) => {
warn(`Invalid watch source: `, s, `A watch source can only be a getter/effect function, a ref, ` +
`a reactive object, or an array of these types.`);
};
let getter;
let forceTrigger = false;
if (isRef(source)) {
getter = () => source.value;
forceTrigger = !!source._shallow;
}
else if (isReactive(source)) {
getter = () => source;
deep = true;
}
else if (isArray(source)) {
getter = () => source.map(s => {
if (isRef(s)) {
return s.value;
}
else if (isReactive(s)) {
return traverse(s);
}
else if (isFunction(s)) {
return callWithErrorHandling(s, instance, 2 /* WATCH_GETTER */);
function resolveAsset(type, name, warnMissing = true) {
const instance = currentInstance;
if (instance) {
const Component = instance.type;
// self name has highest priority
if (type === COMPONENTS) {
// special self referencing call generated by compiler
// inferred from SFC filename
if (name === `_self`) {
return Component;
}
else {
(process.env.NODE_ENV !== 'production') && warnInvalidSource(s);
const selfName = getComponentName(Component);
if (selfName &&
(selfName === name ||
selfName === camelize(name) ||
selfName === capitalize(camelize(name)))) {
return Component;
}
});
}
else if (isFunction(source)) {
if (cb) {
// getter with cb
getter = () => callWithErrorHandling(source, instance, 2 /* WATCH_GETTER */);
}
else {
// no cb -> simple effect
getter = () => {
if (instance && instance.isUnmounted) {
return;
}
if (cleanup) {
cleanup();
}
return callWithErrorHandling(source, instance, 3 /* WATCH_CALLBACK */, [onInvalidate]);
};
const res =
// local registration
// check instance[type] first for components with mixin or extends.
resolve(instance[type] || Component[type], name) ||
// global registration
resolve(instance.appContext[type], name);
if ((process.env.NODE_ENV !== 'production') && warnMissing && !res) {
warn(`Failed to resolve ${type.slice(0, -1)}: ${name}`);
}
return res;
}
else {
getter = NOOP;
(process.env.NODE_ENV !== 'production') && warnInvalidSource(source);
}
if (cb && deep) {
const baseGetter = getter;
getter = () => traverse(baseGetter());
else if ((process.env.NODE_ENV !== 'production')) {
warn(`resolve${capitalize(type.slice(0, -1))} ` +
`can only be used in render() or setup().`);
}
let cleanup;
const onInvalidate = (fn) => {
cleanup = runner.options.onStop = () => {
callWithErrorHandling(fn, instance, 4 /* WATCH_CLEANUP */);
};
}
function resolve(registry, name) {
return (registry &&
(registry[name] ||
registry[camelize(name)] ||
registry[capitalize(camelize(name))]));
}
const Fragment = Symbol((process.env.NODE_ENV !== 'production') ? 'Fragment' : undefined);
const Text = Symbol((process.env.NODE_ENV !== 'production') ? 'Text' : undefined);
const Comment = Symbol((process.env.NODE_ENV !== 'production') ? 'Comment' : undefined);
Symbol((process.env.NODE_ENV !== 'production') ? 'Static' : undefined);
let currentBlock = null;
function isVNode(value) {
return value ? value.__v_isVNode === true : false;
}
const createVNodeWithArgsTransform = (...args) => {
return _createVNode(...(args));
};
const InternalObjectKey = `__vInternal`;
const normalizeKey = ({ key }) => key != null ? key : null;
const normalizeRef = ({ ref }) => {
return (ref != null
? isString(ref) || isRef(ref) || isFunction(ref)
? { i: currentRenderingInstance, r: ref }
: ref
: null);
};
const createVNode = ((process.env.NODE_ENV !== 'production')
? createVNodeWithArgsTransform
: _createVNode);
function _createVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, isBlockNode = false) {
if (!type || type === NULL_DYNAMIC_COMPONENT) {
if ((process.env.NODE_ENV !== 'production') && !type) {
warn(`Invalid vnode type when creating vnode: ${type}.`);
}
type = Comment;
}
if (isVNode(type)) {
// createVNode receiving an existing vnode. This happens in cases like
// <component :is="vnode"/>
// #2078 make sure to merge refs during the clone instead of overwriting it
const cloned = cloneVNode(type, props, true /* mergeRef: true */);
if (children) {
normalizeChildren(cloned, children);
}
return cloned;
}
// class component normalization.
if (isClassComponent(type)) {
type = type.__vccOpts;
}
// class & style normalization.
if (props) {
// for reactive or proxy objects, we need to clone it to enable mutation.
if (isProxy(props) || InternalObjectKey in props) {
props = extend({}, props);
}
let { class: klass, style } = props;
if (klass && !isString(klass)) {
props.class = normalizeClass(klass);
}
if (isObject(style)) {
// reactive state objects need to be cloned since they are likely to be
// mutated
if (isProxy(style) && !isArray(style)) {
style = extend({}, style);
}
props.style = normalizeStyle(style);
}
}
// encode the vnode type information into a bitmap
const shapeFlag = isString(type)
? 1 /* ELEMENT */
: isTeleport(type)
? 64 /* TELEPORT */
: isObject(type)
? 4 /* STATEFUL_COMPONENT */
: isFunction(type)
? 2 /* FUNCTIONAL_COMPONENT */
: 0;
if ((process.env.NODE_ENV !== 'production') && shapeFlag & 4 /* STATEFUL_COMPONENT */ && isProxy(type)) {
type = toRaw(type);
warn(`Vue received a Component which was made a reactive object. This can ` +
`lead to unnecessary performance overhead, and should be avoided by ` +
`marking the component with \`markRaw\` or using \`shallowRef\` ` +
`instead of \`ref\`.`, `\nComponent that was made reactive: `, type);
}
const vnode = {
__v_isVNode: true,
["__v_skip" /* SKIP */]: true,
type,
props,
key: props && normalizeKey(props),
ref: props && normalizeRef(props),
scopeId: currentScopeId,
slotScopeIds: null,
children: null,
component: null,
suspense: null,
ssContent: null,
ssFallback: null,
dirs: null,
transition: null,
el: null,
anchor: null,
target: null,
targetAnchor: null,
staticCount: 0,
shapeFlag,
patchFlag,
dynamicProps,
dynamicChildren: null,
appContext: null
};
let oldValue = isArray(source) ? [] : INITIAL_WATCHER_VALUE;
const job = () => {
if (!runner.active) {
// validate key
if ((process.env.NODE_ENV !== 'production') && vnode.key !== vnode.key) {
warn(`VNode created with invalid key (NaN). VNode type:`, vnode.type);
}
normalizeChildren(vnode, children);
if (// avoid a block node from tracking itself
!isBlockNode &&
// has current parent block
currentBlock &&
// presence of a patch flag indicates this node needs patching on updates.
// component nodes also should always be patched, because even if the
// component doesn't need to update, it needs to persist the instance on to
// the next vnode so that it can be properly unmounted later.
(patchFlag > 0 || shapeFlag & 6 /* COMPONENT */) &&
// the EVENTS flag is only for hydration and if it is the only flag, the
// vnode should not be considered dynamic due to handler caching.
patchFlag !== 32 /* HYDRATE_EVENTS */) {
currentBlock.push(vnode);
}
return vnode;
}
function cloneVNode(vnode, extraProps, mergeRef = false) {
// This is intentionally NOT using spread or extend to avoid the runtime
// key enumeration cost.
const { props, ref, patchFlag, children } = vnode;
const mergedProps = extraProps ? mergeProps(props || {}, extraProps) : props;
return {
__v_isVNode: true,
["__v_skip" /* SKIP */]: true,
type: vnode.type,
props: mergedProps,
key: mergedProps && normalizeKey(mergedProps),
ref: extraProps && extraProps.ref
? // #2078 in the case of <component :is="vnode" ref="extra"/>
// if the vnode itself already has a ref, cloneVNode will need to merge
// the refs so the single vnode can be set on multiple refs
mergeRef && ref
? isArray(ref)
? ref.concat(normalizeRef(extraProps))
: [ref, normalizeRef(extraProps)]
: normalizeRef(extraProps)
: ref,
scopeId: vnode.scopeId,
slotScopeIds: vnode.slotScopeIds,
children: (process.env.NODE_ENV !== 'production') && patchFlag === -1 /* HOISTED */ && isArray(children)
? children.map(deepCloneVNode)
: children,
target: vnode.target,
targetAnchor: vnode.targetAnchor,
staticCount: vnode.staticCount,
shapeFlag: vnode.shapeFlag,
// if the vnode is cloned with extra props, we can no longer assume its
// existing patch flag to be reliable and need to add the FULL_PROPS flag.
// note: perserve flag for fragments since they use the flag for children
// fast paths only.
patchFlag: extraProps && vnode.type !== Fragment
? patchFlag === -1 // hoisted node
? 16 /* FULL_PROPS */
: patchFlag | 16 /* FULL_PROPS */
: patchFlag,
dynamicProps: vnode.dynamicProps,
dynamicChildren: vnode.dynamicChildren,
appContext: vnode.appContext,
dirs: vnode.dirs,
transition: vnode.transition,
// These should technically only be non-null on mounted VNodes. However,
// they *should* be copied for kept-alive vnodes. So we just always copy
// them since them being non-null during a mount doesn't affect the logic as
// they will simply be overwritten.
component: vnode.component,
suspense: vnode.suspense,
ssContent: vnode.ssContent && cloneVNode(vnode.ssContent),
ssFallback: vnode.ssFallback && cloneVNode(vnode.ssFallback),
el: vnode.el,
anchor: vnode.anchor
};
}
/**
* Dev only, for HMR of hoisted vnodes reused in v-for
* https://github.com/vitejs/vite/issues/2022
*/
function deepCloneVNode(vnode) {
const cloned = cloneVNode(vnode);
if (isArray(vnode.children)) {
cloned.children = vnode.children.map(deepCloneVNode);
}
return cloned;
}
/**
* @private
*/
function createTextVNode(text = ' ', flag = 0) {
return createVNode(Text, null, text, flag);
}
function normalizeChildren(vnode, children) {
let type = 0;
const { shapeFlag } = vnode;
if (children == null) {
children = null;
}
else if (isArray(children)) {
type = 16 /* ARRAY_CHILDREN */;
}
else if (typeof children === 'object') {
if (shapeFlag & 1 /* ELEMENT */ || shapeFlag & 64 /* TELEPORT */) {
// Normalize slot to plain children for plain element and Teleport
const slot = children.default;
if (slot) {
// _c marker is added by withCtx() indicating this is a compiled slot
slot._c && setCompiledSlotRendering(1);
normalizeChildren(vnode, slot());
slot._c && setCompiledSlotRendering(-1);
}
return;
}
if (cb) {
// watch(source, cb)
const newValue = runner();
if (deep || forceTrigger || hasChanged(newValue, oldValue)) {
// cleanup before running cb again
if (cleanup) {
cleanup();
else {
type = 32 /* SLOTS_CHILDREN */;
const slotFlag = children._;
if (!slotFlag && !(InternalObjectKey in children)) {
children._ctx = currentRenderingInstance;
}
else if (slotFlag === 3 /* FORWARDED */ && currentRenderingInstance) {
// a child component receives forwarded slots from the parent.
// its slot type is determined by its parent's slot type.
if (currentRenderingInstance.vnode.patchFlag & 1024 /* DYNAMIC_SLOTS */) {
children._ = 2 /* DYNAMIC */;
vnode.patchFlag |= 1024 /* DYNAMIC_SLOTS */;
}
else {
children._ = 1 /* STABLE */;
}
callWithAsyncErrorHandling(cb, instance, 3 /* WATCH_CALLBACK */, [
newValue,
// pass undefined as the old value when it's changed for the first time
oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue,
onInvalidate
]);
oldValue = newValue;
}
}
else {
// watchEffect
runner();
}
};
// important: mark the job as a watcher callback so that scheduler knows
// it is allowed to self-trigger (#1727)
job.allowRecurse = !!cb;
let scheduler;
if (flush === 'sync') {
scheduler = job;
}
else if (flush === 'post') {
scheduler = () => queuePostRenderEffect(job, instance && instance.suspense);
else if (isFunction(children)) {
children = { default: children, _ctx: currentRenderingInstance };
type = 32 /* SLOTS_CHILDREN */;
}
else {
// default: 'pre'
scheduler = () => {
if (!instance || instance.isMounted) {
queuePreFlushCb(job);
}
else {
// with 'pre' option, the first call must happen before
// the component is mounted so it is called synchronously.
job();
}
};
}
const runner = effect(getter, {
lazy: true,
onTrack,
onTrigger,
scheduler
});
recordInstanceBoundEffect(runner, instance);
// initial run
if (cb) {
if (immediate) {
job();
children = String(children);
// force teleport children to array so it can be moved around
if (shapeFlag & 64 /* TELEPORT */) {
type = 16 /* ARRAY_CHILDREN */;
children = [createTextVNode(children)];
}
else {
oldValue = runner();
type = 8 /* TEXT_CHILDREN */;
}
}
else if (flush === 'post') {
queuePostRenderEffect(runner, instance && instance.suspense);
}
else {
runner();
}
return () => {
stop(runner);
if (instance) {
remove(instance.effects, runner);
}
};
}
// this.$watch
function instanceWatch(source, cb, options) {
const publicThis = this.proxy;
const getter = isString(source)
? () => publicThis[source]
: source.bind(publicThis);
return doWatch(getter, cb.bind(publicThis), options, this);
vnode.children = children;
vnode.shapeFlag |= type;
}
function traverse(value, seen = new Set()) {
if (!isObject(value) || seen.has(value)) {
return value;
}
seen.add(value);
if (isRef(value)) {
traverse(value.value, seen);
}
else if (isArray(value)) {
for (let i = 0; i < value.length; i++) {
traverse(value[i], seen);
}
}
else if (isSet(value) || isMap(value)) {
value.forEach((v) => {
traverse(v, seen);
});
}
else {
for (const key in value) {
traverse(value[key], seen);
function mergeProps(...args) {
const ret = extend({}, args[0]);
for (let i = 1; i < args.length; i++) {
const toMerge = args[i];
for (const key in toMerge) {
if (key === 'class') {
if (ret.class !== toMerge.class) {
ret.class = normalizeClass([ret.class, toMerge.class]);
}
}
else if (key === 'style') {
ret.style = normalizeStyle([ret.style, toMerge.style]);
}
else if (isOn(key)) {
const existing = ret[key];
const incoming = toMerge[key];
if (existing !== incoming) {
ret[key] = existing
? [].concat(existing, toMerge[key])
: incoming;
}
}
else if (key !== '') {
ret[key] = toMerge[key];
}
}
}
return value;
return ret;
}
function provide(key, value) {
......@@ -2338,7 +2665,19 @@ function applyOptions(instance, options, deferredData = [], deferredWatch = [],
for (const key in methods) {
const methodHandler = methods[key];
if (isFunction(methodHandler)) {
ctx[key] = methodHandler.bind(publicThis);
// In dev mode, we use the `createRenderContext` function to define methods to the proxy target,
// and those are read-only but reconfigurable, so it needs to be redefined here
if ((process.env.NODE_ENV !== 'production')) {
Object.defineProperty(ctx, key, {
value: methodHandler.bind(publicThis),
configurable: true,
enumerable: true,
writable: true
});
}
else {
ctx[key] = methodHandler.bind(publicThis);
}
if ((process.env.NODE_ENV !== 'production')) {
checkDuplicateProperties("Methods" /* METHODS */, key);
}
......@@ -2660,7 +2999,13 @@ function mergeOptions(to, from, instance) {
* they exist in the internal parent chain. For code that relies on traversing
* public $parent chains, skip functional ones and go to the parent instead.
*/
const getPublicInstance = (i) => i && (i.proxy ? i.proxy : getPublicInstance(i.parent));
const getPublicInstance = (i) => {
if (!i)
return null;
if (isStatefulComponent(i))
return i.exposed ? i.exposed : i.proxy;
return getPublicInstance(i.parent);
};
const publicPropertiesMap = extend(Object.create(null), {
$: i => i,
$el: i => i.vnode.el,
......@@ -2670,7 +3015,7 @@ const publicPropertiesMap = extend(Object.create(null), {
$slots: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.slots) : i.slots),
$refs: i => ((process.env.NODE_ENV !== 'production') ? shallowReadonly(i.refs) : i.refs),
$parent: i => getPublicInstance(i.parent),
$root: i => i.root && i.root.proxy,
$root: i => getPublicInstance(i.root),
$emit: i => i.emit,
$options: i => (__VUE_OPTIONS_API__ ? resolveMergedOptions(i) : i.type),
$forceUpdate: i => () => queueJob(i.update),
......@@ -2773,7 +3118,7 @@ const PublicInstanceProxyHandlers = {
warn(`Property ${JSON.stringify(key)} must be accessed via $data because it starts with a reserved ` +
`character ("$" or "_") and is not proxied on the render context.`);
}
else {
else if (instance === currentRenderingInstance) {
warn(`Property ${JSON.stringify(key)} was accessed during render ` +
`but is not defined on instance.`);
}
......@@ -2787,7 +3132,7 @@ const PublicInstanceProxyHandlers = {
else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
data[key] = value;
}
else if (key in instance.props) {
else if (hasOwn(instance.props, key)) {
(process.env.NODE_ENV !== 'production') &&
warn(`Attempting to mutate prop "${key}". Props are readonly.`, instance);
return false;
......@@ -2986,7 +3331,6 @@ function createComponentInstance(vnode, parent, suspense) {
}
instance.root = parent ? parent.root : instance;
instance.emit = emit.bind(null, instance);
if ((process.env.NODE_ENV !== 'production') || false) ;
return instance;
}
let currentInstance = null;
......@@ -3001,11 +3345,14 @@ function validateComponentName(name, config) {
warn('Do not use built-in or reserved HTML elements as component id: ' + name);
}
}
function isStatefulComponent(instance) {
return instance.vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */;
}
let isInSSRComponentSetup = false;
function setupComponent(instance, isSSR = false) {
isInSSRComponentSetup = isSSR;
const { props, /* children, */ shapeFlag } = instance.vnode;
const isStateful = shapeFlag & 4 /* STATEFUL_COMPONENT */;
const { props /*, children*/ } = instance.vnode;
const isStateful = isStatefulComponent(instance);
initProps(instance, props, isStateful, isSSR);
// initSlots(instance, children) // fixed by xxxxxx
const setupResult = isStateful
......@@ -3079,12 +3426,10 @@ function handleSetupResult(instance, setupResult, isSSR) {
}
}
else if (isObject(setupResult)) {
// if ((process.env.NODE_ENV !== 'production') && isVNode(setupResult)) {
// warn(
// `setup() should not return VNodes directly - ` +
// `return a render function instead.`
// )
// }
if ((process.env.NODE_ENV !== 'production') && isVNode(setupResult)) {
warn(`setup() should not return VNodes directly - ` +
`return a render function instead.`);
}
// setup returned bindings.
// assuming a render function compiled from template is present.
if ((process.env.NODE_ENV !== 'production') || false) {
......@@ -3123,10 +3468,10 @@ function finishComponentSetup(instance, isSSR) {
// warn missing template/render
if ((process.env.NODE_ENV !== 'production') && !Component.render && instance.render === NOOP) {
/* istanbul ignore if */
if ( Component.template) {
if (Component.template) {
warn(`Component provided template option but ` +
`runtime compilation is not supported in this build of Vue.` +
( ` Configure your bundler to alias "vue" to "vue/dist/vue.esm-bundler.js".`
(` Configure your bundler to alias "vue" to "vue/dist/vue.esm-bundler.js".`
) /* should not happen */);
}
else {
......@@ -3220,6 +3565,9 @@ function formatComponentName(instance, Component, isRoot = false) {
instance.parent.type.components) || inferFromRegistry(instance.appContext.components);
}
return name ? classify(name) : isRoot ? `App` : `Anonymous`;
}
function isClassComponent(value) {
return isFunction(value) && '__vccOpts' in value;
}
function computed$1(getterOrOptions) {
......@@ -3248,7 +3596,7 @@ function defineEmit() {
}
// Core API ------------------------------------------------------------------
const version = "3.0.5";
const version = "3.0.7";
// import deepCopy from './deepCopy'
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册