@vue/runtime-core 3.2.32 → 3.2.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -184,7 +184,7 @@ let preFlushIndex = 0;
184
184
  const pendingPostFlushCbs = [];
185
185
  let activePostFlushCbs = null;
186
186
  let postFlushIndex = 0;
187
- const resolvedPromise = Promise.resolve();
187
+ const resolvedPromise = /*#__PURE__*/ Promise.resolve();
188
188
  let currentFlushPromise = null;
189
189
  let currentPreFlushParentJob = null;
190
190
  function nextTick(fn) {
@@ -274,6 +274,8 @@ function flushPreFlushCbs(seen, parentJob = null) {
274
274
  }
275
275
  }
276
276
  function flushPostFlushCbs(seen) {
277
+ // flush any pre cbs queued during the flush (e.g. pre watchers)
278
+ flushPreFlushCbs();
277
279
  if (pendingPostFlushCbs.length) {
278
280
  const deduped = [...new Set(pendingPostFlushCbs)];
279
281
  pendingPostFlushCbs.length = 0;
@@ -338,7 +340,6 @@ function flushJobs(seen) {
338
340
 
339
341
  let buffer = [];
340
342
  function setDevtoolsHook(hook, target) {
341
- var _a, _b;
342
343
  exports.devtools = hook;
343
344
  if (exports.devtools) {
344
345
  exports.devtools.enabled = true;
@@ -349,12 +350,11 @@ function setDevtoolsHook(hook, target) {
349
350
  // handle late devtools injection - only do this if we are in an actual
350
351
  // browser environment to avoid the timer handle stalling test runner exit
351
352
  // (#4815)
352
- // eslint-disable-next-line no-restricted-globals
353
353
  typeof window !== 'undefined' &&
354
354
  // some envs mock window but not fully
355
355
  window.HTMLElement &&
356
356
  // also exclude jsdom
357
- !((_b = (_a = window.navigator) === null || _a === void 0 ? void 0 : _a.userAgent) === null || _b === void 0 ? void 0 : _b.includes('jsdom'))) {
357
+ !window.navigator?.userAgent?.includes('jsdom')) {
358
358
  const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ =
359
359
  target.__VUE_DEVTOOLS_HOOK_REPLAY__ || []);
360
360
  replay.push((newHook) => {
@@ -375,6 +375,8 @@ function setDevtoolsHook(hook, target) {
375
375
  }
376
376
 
377
377
  function emit(instance, event, ...rawArgs) {
378
+ if (instance.isUnmounted)
379
+ return;
378
380
  const props = instance.vnode.props || shared.EMPTY_OBJ;
379
381
  let args = rawArgs;
380
382
  const isModelListener = event.startsWith('update:');
@@ -386,7 +388,7 @@ function emit(instance, event, ...rawArgs) {
386
388
  if (trim) {
387
389
  args = rawArgs.map(a => a.trim());
388
390
  }
389
- else if (number) {
391
+ if (number) {
390
392
  args = rawArgs.map(shared.toNumber);
391
393
  }
392
394
  }
@@ -614,6 +616,8 @@ function renderComponentRoot(instance) {
614
616
  }
615
617
  // inherit directives
616
618
  if (vnode.dirs) {
619
+ // clone before mutating since the root may be a hoisted vnode
620
+ root = cloneVNode(root);
617
621
  root.dirs = root.dirs ? root.dirs.concat(vnode.dirs) : vnode.dirs;
618
622
  }
619
623
  // inherit transition data
@@ -1218,7 +1222,7 @@ function doWatch(source, cb, { immediate, deep, flush, onTrack, onTrigger } = sh
1218
1222
  }
1219
1223
  else if (shared.isArray(source)) {
1220
1224
  isMultiSource = true;
1221
- forceTrigger = source.some(reactivity.isReactive);
1225
+ forceTrigger = source.some(s => reactivity.isReactive(s) || reactivity.isShallow(s));
1222
1226
  getter = () => source.map(s => {
1223
1227
  if (reactivity.isRef(s)) {
1224
1228
  return s.value;
@@ -1324,16 +1328,7 @@ function doWatch(source, cb, { immediate, deep, flush, onTrack, onTrigger } = sh
1324
1328
  }
1325
1329
  else {
1326
1330
  // default: 'pre'
1327
- scheduler = () => {
1328
- if (!instance || instance.isMounted) {
1329
- queuePreFlushCb(job);
1330
- }
1331
- else {
1332
- // with 'pre' option, the first call must happen before
1333
- // the component is mounted so it is called synchronously.
1334
- job();
1335
- }
1336
- };
1331
+ scheduler = () => queuePreFlushCb(job);
1337
1332
  }
1338
1333
  const effect = new reactivity.ReactiveEffect(getter, scheduler);
1339
1334
  // initial run
@@ -1472,12 +1467,20 @@ const BaseTransitionImpl = {
1472
1467
  if (!children || !children.length) {
1473
1468
  return;
1474
1469
  }
1470
+ let child = children[0];
1471
+ if (children.length > 1) {
1472
+ // locate first non-comment child
1473
+ for (const c of children) {
1474
+ if (c.type !== Comment) {
1475
+ child = c;
1476
+ break;
1477
+ }
1478
+ }
1479
+ }
1475
1480
  // there's no need to track reactivity for these props so use the raw
1476
1481
  // props for a bit better perf
1477
1482
  const rawProps = reactivity.toRaw(props);
1478
1483
  const { mode } = rawProps;
1479
- // at this point children has a guaranteed length of 1.
1480
- const child = children[0];
1481
1484
  if (state.isLeaving) {
1482
1485
  return emptyPlaceholder(child);
1483
1486
  }
@@ -1560,6 +1563,17 @@ function resolveTransitionHooks(vnode, props, state, instance) {
1560
1563
  hook &&
1561
1564
  callWithAsyncErrorHandling(hook, instance, 9 /* TRANSITION_HOOK */, args);
1562
1565
  };
1566
+ const callAsyncHook = (hook, args) => {
1567
+ const done = args[1];
1568
+ callHook(hook, args);
1569
+ if (shared.isArray(hook)) {
1570
+ if (hook.every(hook => hook.length <= 1))
1571
+ done();
1572
+ }
1573
+ else if (hook.length <= 1) {
1574
+ done();
1575
+ }
1576
+ };
1563
1577
  const hooks = {
1564
1578
  mode,
1565
1579
  persisted,
@@ -1618,10 +1632,7 @@ function resolveTransitionHooks(vnode, props, state, instance) {
1618
1632
  el._enterCb = undefined;
1619
1633
  });
1620
1634
  if (hook) {
1621
- hook(el, done);
1622
- if (hook.length <= 1) {
1623
- done();
1624
- }
1635
+ callAsyncHook(hook, [el, done]);
1625
1636
  }
1626
1637
  else {
1627
1638
  done();
@@ -1655,10 +1666,7 @@ function resolveTransitionHooks(vnode, props, state, instance) {
1655
1666
  });
1656
1667
  leavingVNodesCache[key] = vnode;
1657
1668
  if (onLeave) {
1658
- onLeave(el, done);
1659
- if (onLeave.length <= 1) {
1660
- done();
1661
- }
1669
+ callAsyncHook(onLeave, [el, done]);
1662
1670
  }
1663
1671
  else {
1664
1672
  done();
@@ -1861,7 +1869,7 @@ function defineAsyncComponent(source) {
1861
1869
  }
1862
1870
  });
1863
1871
  }
1864
- function createInnerComp(comp, { vnode: { ref, props, children } }) {
1872
+ function createInnerComp(comp, { vnode: { ref, props, children, shapeFlag }, parent }) {
1865
1873
  const vnode = createVNode(comp, props, children);
1866
1874
  // ensure inner component inherits the async wrapper's ref owner
1867
1875
  vnode.ref = ref;
@@ -1891,7 +1899,10 @@ const KeepAliveImpl = {
1891
1899
  // if the internal renderer is not registered, it indicates that this is server-side rendering,
1892
1900
  // for KeepAlive, we just need to render its children
1893
1901
  if (!sharedContext.renderer) {
1894
- return slots.default;
1902
+ return () => {
1903
+ const children = slots.default && slots.default();
1904
+ return children && children.length === 1 ? children[0] : children;
1905
+ };
1895
1906
  }
1896
1907
  const cache = new Map();
1897
1908
  const keys = new Set();
@@ -2056,7 +2067,7 @@ const KeepAliveImpl = {
2056
2067
  // avoid vnode being unmounted
2057
2068
  vnode.shapeFlag |= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;
2058
2069
  current = vnode;
2059
- return rawVNode;
2070
+ return isSuspense(rawVNode.type) ? rawVNode : vnode;
2060
2071
  };
2061
2072
  }
2062
2073
  };
@@ -2185,796 +2196,1153 @@ function onErrorCaptured(hook, target = currentInstance) {
2185
2196
  injectHook("ec" /* ERROR_CAPTURED */, hook, target);
2186
2197
  }
2187
2198
 
2188
- let shouldCacheAccess = true;
2189
- function applyOptions(instance) {
2190
- const options = resolveMergedOptions(instance);
2191
- const publicThis = instance.proxy;
2192
- const ctx = instance.ctx;
2193
- // do not cache property access on public proxy during state initialization
2194
- shouldCacheAccess = false;
2195
- // call beforeCreate first before accessing other options since
2196
- // the hook may mutate resolved options (#2791)
2197
- if (options.beforeCreate) {
2198
- callHook(options.beforeCreate, instance, "bc" /* BEFORE_CREATE */);
2199
- }
2200
- const {
2201
- // state
2202
- data: dataOptions, computed: computedOptions, methods, watch: watchOptions, provide: provideOptions, inject: injectOptions,
2203
- // lifecycle
2204
- created, beforeMount, mounted, beforeUpdate, updated, activated, deactivated, beforeDestroy, beforeUnmount, destroyed, unmounted, render, renderTracked, renderTriggered, errorCaptured, serverPrefetch,
2205
- // public API
2206
- expose, inheritAttrs,
2207
- // assets
2208
- components, directives, filters } = options;
2209
- const checkDuplicateProperties = null;
2210
- // options initialization order (to be consistent with Vue 2):
2211
- // - props (already done outside of this function)
2212
- // - inject
2213
- // - methods
2214
- // - data (deferred since it relies on `this` access)
2215
- // - computed
2216
- // - watch (deferred since it relies on `this` access)
2217
- if (injectOptions) {
2218
- resolveInjections(injectOptions, ctx, checkDuplicateProperties, instance.appContext.config.unwrapInjectedRef);
2199
+ /**
2200
+ Runtime helper for applying directives to a vnode. Example usage:
2201
+
2202
+ const comp = resolveComponent('comp')
2203
+ const foo = resolveDirective('foo')
2204
+ const bar = resolveDirective('bar')
2205
+
2206
+ return withDirectives(h(comp), [
2207
+ [foo, this.x],
2208
+ [bar, this.y]
2209
+ ])
2210
+ */
2211
+ /**
2212
+ * Adds directives to a VNode.
2213
+ */
2214
+ function withDirectives(vnode, directives) {
2215
+ const internalInstance = currentRenderingInstance;
2216
+ if (internalInstance === null) {
2217
+ return vnode;
2219
2218
  }
2220
- if (methods) {
2221
- for (const key in methods) {
2222
- const methodHandler = methods[key];
2223
- if (shared.isFunction(methodHandler)) {
2224
- // In dev mode, we use the `createRenderContext` function to define
2225
- // methods to the proxy target, and those are read-only but
2226
- // reconfigurable, so it needs to be redefined here
2227
- {
2228
- ctx[key] = methodHandler.bind(publicThis);
2229
- }
2230
- }
2219
+ const instance = getExposeProxy(internalInstance) ||
2220
+ internalInstance.proxy;
2221
+ const bindings = vnode.dirs || (vnode.dirs = []);
2222
+ for (let i = 0; i < directives.length; i++) {
2223
+ let [dir, value, arg, modifiers = shared.EMPTY_OBJ] = directives[i];
2224
+ if (shared.isFunction(dir)) {
2225
+ dir = {
2226
+ mounted: dir,
2227
+ updated: dir
2228
+ };
2231
2229
  }
2232
- }
2233
- if (dataOptions) {
2234
- const data = dataOptions.call(publicThis, publicThis);
2235
- if (!shared.isObject(data)) ;
2236
- else {
2237
- instance.data = reactivity.reactive(data);
2230
+ if (dir.deep) {
2231
+ traverse(value);
2238
2232
  }
2233
+ bindings.push({
2234
+ dir,
2235
+ instance,
2236
+ value,
2237
+ oldValue: void 0,
2238
+ arg,
2239
+ modifiers
2240
+ });
2239
2241
  }
2240
- // state initialization complete at this point - start caching access
2241
- shouldCacheAccess = true;
2242
- if (computedOptions) {
2243
- for (const key in computedOptions) {
2244
- const opt = computedOptions[key];
2245
- const get = shared.isFunction(opt)
2246
- ? opt.bind(publicThis, publicThis)
2247
- : shared.isFunction(opt.get)
2248
- ? opt.get.bind(publicThis, publicThis)
2249
- : shared.NOOP;
2250
- const set = !shared.isFunction(opt) && shared.isFunction(opt.set)
2251
- ? opt.set.bind(publicThis)
2252
- : shared.NOOP;
2253
- const c = computed({
2254
- get,
2255
- set
2256
- });
2257
- Object.defineProperty(ctx, key, {
2258
- enumerable: true,
2259
- configurable: true,
2260
- get: () => c.value,
2261
- set: v => (c.value = v)
2262
- });
2242
+ return vnode;
2243
+ }
2244
+ function invokeDirectiveHook(vnode, prevVNode, instance, name) {
2245
+ const bindings = vnode.dirs;
2246
+ const oldBindings = prevVNode && prevVNode.dirs;
2247
+ for (let i = 0; i < bindings.length; i++) {
2248
+ const binding = bindings[i];
2249
+ if (oldBindings) {
2250
+ binding.oldValue = oldBindings[i].value;
2251
+ }
2252
+ let hook = binding.dir[name];
2253
+ if (hook) {
2254
+ // disable tracking inside all lifecycle hooks
2255
+ // since they can potentially be called inside effects.
2256
+ reactivity.pauseTracking();
2257
+ callWithAsyncErrorHandling(hook, instance, 8 /* DIRECTIVE_HOOK */, [
2258
+ vnode.el,
2259
+ binding,
2260
+ vnode,
2261
+ prevVNode
2262
+ ]);
2263
+ reactivity.resetTracking();
2263
2264
  }
2264
2265
  }
2265
- if (watchOptions) {
2266
- for (const key in watchOptions) {
2267
- createWatcher(watchOptions[key], ctx, publicThis, key);
2266
+ }
2267
+
2268
+ const COMPONENTS = 'components';
2269
+ const DIRECTIVES = 'directives';
2270
+ /**
2271
+ * @private
2272
+ */
2273
+ function resolveComponent(name, maybeSelfReference) {
2274
+ return resolveAsset(COMPONENTS, name, true, maybeSelfReference) || name;
2275
+ }
2276
+ const NULL_DYNAMIC_COMPONENT = Symbol();
2277
+ /**
2278
+ * @private
2279
+ */
2280
+ function resolveDynamicComponent(component) {
2281
+ if (shared.isString(component)) {
2282
+ return resolveAsset(COMPONENTS, component, false) || component;
2283
+ }
2284
+ else {
2285
+ // invalid types will fallthrough to createVNode and raise warning
2286
+ return (component || NULL_DYNAMIC_COMPONENT);
2287
+ }
2288
+ }
2289
+ /**
2290
+ * @private
2291
+ */
2292
+ function resolveDirective(name) {
2293
+ return resolveAsset(DIRECTIVES, name);
2294
+ }
2295
+ // implementation
2296
+ function resolveAsset(type, name, warnMissing = true, maybeSelfReference = false) {
2297
+ const instance = currentRenderingInstance || currentInstance;
2298
+ if (instance) {
2299
+ const Component = instance.type;
2300
+ // explicit self name has highest priority
2301
+ if (type === COMPONENTS) {
2302
+ const selfName = getComponentName(Component);
2303
+ if (selfName &&
2304
+ (selfName === name ||
2305
+ selfName === shared.camelize(name) ||
2306
+ selfName === shared.capitalize(shared.camelize(name)))) {
2307
+ return Component;
2308
+ }
2309
+ }
2310
+ const res =
2311
+ // local registration
2312
+ // check instance[type] first which is resolved for options API
2313
+ resolve(instance[type] || Component[type], name) ||
2314
+ // global registration
2315
+ resolve(instance.appContext[type], name);
2316
+ if (!res && maybeSelfReference) {
2317
+ // fallback to implicit self-reference
2318
+ return Component;
2268
2319
  }
2320
+ return res;
2269
2321
  }
2270
- if (provideOptions) {
2271
- const provides = shared.isFunction(provideOptions)
2272
- ? provideOptions.call(publicThis)
2273
- : provideOptions;
2274
- Reflect.ownKeys(provides).forEach(key => {
2275
- provide(key, provides[key]);
2276
- });
2322
+ }
2323
+ function resolve(registry, name) {
2324
+ return (registry &&
2325
+ (registry[name] ||
2326
+ registry[shared.camelize(name)] ||
2327
+ registry[shared.capitalize(shared.camelize(name))]));
2328
+ }
2329
+
2330
+ /**
2331
+ * Actual implementation
2332
+ */
2333
+ function renderList(source, renderItem, cache, index) {
2334
+ let ret;
2335
+ const cached = (cache && cache[index]);
2336
+ if (shared.isArray(source) || shared.isString(source)) {
2337
+ ret = new Array(source.length);
2338
+ for (let i = 0, l = source.length; i < l; i++) {
2339
+ ret[i] = renderItem(source[i], i, undefined, cached && cached[i]);
2340
+ }
2277
2341
  }
2278
- if (created) {
2279
- callHook(created, instance, "c" /* CREATED */);
2342
+ else if (typeof source === 'number') {
2343
+ ret = new Array(source);
2344
+ for (let i = 0; i < source; i++) {
2345
+ ret[i] = renderItem(i + 1, i, undefined, cached && cached[i]);
2346
+ }
2280
2347
  }
2281
- function registerLifecycleHook(register, hook) {
2282
- if (shared.isArray(hook)) {
2283
- hook.forEach(_hook => register(_hook.bind(publicThis)));
2348
+ else if (shared.isObject(source)) {
2349
+ if (source[Symbol.iterator]) {
2350
+ ret = Array.from(source, (item, i) => renderItem(item, i, undefined, cached && cached[i]));
2284
2351
  }
2285
- else if (hook) {
2286
- register(hook.bind(publicThis));
2352
+ else {
2353
+ const keys = Object.keys(source);
2354
+ ret = new Array(keys.length);
2355
+ for (let i = 0, l = keys.length; i < l; i++) {
2356
+ const key = keys[i];
2357
+ ret[i] = renderItem(source[key], key, i, cached && cached[i]);
2358
+ }
2287
2359
  }
2288
2360
  }
2289
- registerLifecycleHook(onBeforeMount, beforeMount);
2290
- registerLifecycleHook(onMounted, mounted);
2291
- registerLifecycleHook(onBeforeUpdate, beforeUpdate);
2292
- registerLifecycleHook(onUpdated, updated);
2293
- registerLifecycleHook(onActivated, activated);
2294
- registerLifecycleHook(onDeactivated, deactivated);
2295
- registerLifecycleHook(onErrorCaptured, errorCaptured);
2296
- registerLifecycleHook(onRenderTracked, renderTracked);
2297
- registerLifecycleHook(onRenderTriggered, renderTriggered);
2298
- registerLifecycleHook(onBeforeUnmount, beforeUnmount);
2299
- registerLifecycleHook(onUnmounted, unmounted);
2300
- registerLifecycleHook(onServerPrefetch, serverPrefetch);
2301
- if (shared.isArray(expose)) {
2302
- if (expose.length) {
2303
- const exposed = instance.exposed || (instance.exposed = {});
2304
- expose.forEach(key => {
2305
- Object.defineProperty(exposed, key, {
2306
- get: () => publicThis[key],
2307
- set: val => (publicThis[key] = val)
2308
- });
2309
- });
2361
+ else {
2362
+ ret = [];
2363
+ }
2364
+ if (cache) {
2365
+ cache[index] = ret;
2366
+ }
2367
+ return ret;
2368
+ }
2369
+
2370
+ /**
2371
+ * Compiler runtime helper for creating dynamic slots object
2372
+ * @private
2373
+ */
2374
+ function createSlots(slots, dynamicSlots) {
2375
+ for (let i = 0; i < dynamicSlots.length; i++) {
2376
+ const slot = dynamicSlots[i];
2377
+ // array of dynamic slot generated by <template v-for="..." #[...]>
2378
+ if (shared.isArray(slot)) {
2379
+ for (let j = 0; j < slot.length; j++) {
2380
+ slots[slot[j].name] = slot[j].fn;
2381
+ }
2310
2382
  }
2311
- else if (!instance.exposed) {
2312
- instance.exposed = {};
2383
+ else if (slot) {
2384
+ // conditional single slot generated by <template v-if="..." #foo>
2385
+ slots[slot.name] = slot.fn;
2313
2386
  }
2314
2387
  }
2315
- // options that are handled when creating the instance but also need to be
2316
- // applied from mixins
2317
- if (render && instance.render === shared.NOOP) {
2318
- instance.render = render;
2388
+ return slots;
2389
+ }
2390
+
2391
+ /**
2392
+ * Compiler runtime helper for rendering `<slot/>`
2393
+ * @private
2394
+ */
2395
+ function renderSlot(slots, name, props = {},
2396
+ // this is not a user-facing function, so the fallback is always generated by
2397
+ // the compiler and guaranteed to be a function returning an array
2398
+ fallback, noSlotted) {
2399
+ if (currentRenderingInstance.isCE ||
2400
+ (currentRenderingInstance.parent &&
2401
+ isAsyncWrapper(currentRenderingInstance.parent) &&
2402
+ currentRenderingInstance.parent.isCE)) {
2403
+ return createVNode('slot', name === 'default' ? null : { name }, fallback && fallback());
2319
2404
  }
2320
- if (inheritAttrs != null) {
2321
- instance.inheritAttrs = inheritAttrs;
2405
+ let slot = slots[name];
2406
+ // a compiled slot disables block tracking by default to avoid manual
2407
+ // invocation interfering with template-based block tracking, but in
2408
+ // `renderSlot` we can be sure that it's template-based so we can force
2409
+ // enable it.
2410
+ if (slot && slot._c) {
2411
+ slot._d = false;
2322
2412
  }
2323
- // asset options.
2324
- if (components)
2325
- instance.components = components;
2326
- if (directives)
2327
- instance.directives = directives;
2413
+ openBlock();
2414
+ const validSlotContent = slot && ensureValidVNode(slot(props));
2415
+ const rendered = createBlock(Fragment, { key: props.key || `_${name}` }, validSlotContent || (fallback ? fallback() : []), validSlotContent && slots._ === 1 /* STABLE */
2416
+ ? 64 /* STABLE_FRAGMENT */
2417
+ : -2 /* BAIL */);
2418
+ if (!noSlotted && rendered.scopeId) {
2419
+ rendered.slotScopeIds = [rendered.scopeId + '-s'];
2420
+ }
2421
+ if (slot && slot._c) {
2422
+ slot._d = true;
2423
+ }
2424
+ return rendered;
2328
2425
  }
2329
- function resolveInjections(injectOptions, ctx, checkDuplicateProperties = shared.NOOP, unwrapRef = false) {
2330
- if (shared.isArray(injectOptions)) {
2331
- injectOptions = normalizeInject(injectOptions);
2426
+ function ensureValidVNode(vnodes) {
2427
+ return vnodes.some(child => {
2428
+ if (!isVNode(child))
2429
+ return true;
2430
+ if (child.type === Comment)
2431
+ return false;
2432
+ if (child.type === Fragment &&
2433
+ !ensureValidVNode(child.children))
2434
+ return false;
2435
+ return true;
2436
+ })
2437
+ ? vnodes
2438
+ : null;
2439
+ }
2440
+
2441
+ /**
2442
+ * For prefixing keys in v-on="obj" with "on"
2443
+ * @private
2444
+ */
2445
+ function toHandlers(obj) {
2446
+ const ret = {};
2447
+ for (const key in obj) {
2448
+ ret[shared.toHandlerKey(key)] = obj[key];
2332
2449
  }
2333
- for (const key in injectOptions) {
2334
- const opt = injectOptions[key];
2335
- let injected;
2336
- if (shared.isObject(opt)) {
2337
- if ('default' in opt) {
2338
- injected = inject(opt.from || key, opt.default, true /* treat default function as factory */);
2450
+ return ret;
2451
+ }
2452
+
2453
+ /**
2454
+ * #2437 In Vue 3, functional components do not have a public instance proxy but
2455
+ * they exist in the internal parent chain. For code that relies on traversing
2456
+ * public $parent chains, skip functional ones and go to the parent instead.
2457
+ */
2458
+ const getPublicInstance = (i) => {
2459
+ if (!i)
2460
+ return null;
2461
+ if (isStatefulComponent(i))
2462
+ return getExposeProxy(i) || i.proxy;
2463
+ return getPublicInstance(i.parent);
2464
+ };
2465
+ const publicPropertiesMap =
2466
+ // Move PURE marker to new line to workaround compiler discarding it
2467
+ // due to type annotation
2468
+ /*#__PURE__*/ shared.extend(Object.create(null), {
2469
+ $: i => i,
2470
+ $el: i => i.vnode.el,
2471
+ $data: i => i.data,
2472
+ $props: i => (i.props),
2473
+ $attrs: i => (i.attrs),
2474
+ $slots: i => (i.slots),
2475
+ $refs: i => (i.refs),
2476
+ $parent: i => getPublicInstance(i.parent),
2477
+ $root: i => getPublicInstance(i.root),
2478
+ $emit: i => i.emit,
2479
+ $options: i => (resolveMergedOptions(i) ),
2480
+ $forceUpdate: i => i.f || (i.f = () => queueJob(i.update)),
2481
+ $nextTick: i => i.n || (i.n = nextTick.bind(i.proxy)),
2482
+ $watch: i => (instanceWatch.bind(i) )
2483
+ });
2484
+ const PublicInstanceProxyHandlers = {
2485
+ get({ _: instance }, key) {
2486
+ const { ctx, setupState, data, props, accessCache, type, appContext } = instance;
2487
+ // data / props / ctx
2488
+ // This getter gets called for every property access on the render context
2489
+ // during render and is a major hotspot. The most expensive part of this
2490
+ // is the multiple hasOwn() calls. It's much faster to do a simple property
2491
+ // access on a plain object, so we use an accessCache object (with null
2492
+ // prototype) to memoize what access type a key corresponds to.
2493
+ let normalizedProps;
2494
+ if (key[0] !== '$') {
2495
+ const n = accessCache[key];
2496
+ if (n !== undefined) {
2497
+ switch (n) {
2498
+ case 1 /* SETUP */:
2499
+ return setupState[key];
2500
+ case 2 /* DATA */:
2501
+ return data[key];
2502
+ case 4 /* CONTEXT */:
2503
+ return ctx[key];
2504
+ case 3 /* PROPS */:
2505
+ return props[key];
2506
+ // default: just fallthrough
2507
+ }
2339
2508
  }
2340
- else {
2341
- injected = inject(opt.from || key);
2509
+ else if (setupState !== shared.EMPTY_OBJ && shared.hasOwn(setupState, key)) {
2510
+ accessCache[key] = 1 /* SETUP */;
2511
+ return setupState[key];
2342
2512
  }
2343
- }
2344
- else {
2345
- injected = inject(opt);
2346
- }
2347
- if (reactivity.isRef(injected)) {
2348
- // TODO remove the check in 3.3
2349
- if (unwrapRef) {
2350
- Object.defineProperty(ctx, key, {
2351
- enumerable: true,
2352
- configurable: true,
2353
- get: () => injected.value,
2354
- set: v => (injected.value = v)
2355
- });
2513
+ else if (data !== shared.EMPTY_OBJ && shared.hasOwn(data, key)) {
2514
+ accessCache[key] = 2 /* DATA */;
2515
+ return data[key];
2356
2516
  }
2357
- else {
2358
- ctx[key] = injected;
2517
+ else if (
2518
+ // only cache other properties when instance has declared (thus stable)
2519
+ // props
2520
+ (normalizedProps = instance.propsOptions[0]) &&
2521
+ shared.hasOwn(normalizedProps, key)) {
2522
+ accessCache[key] = 3 /* PROPS */;
2523
+ return props[key];
2524
+ }
2525
+ else if (ctx !== shared.EMPTY_OBJ && shared.hasOwn(ctx, key)) {
2526
+ accessCache[key] = 4 /* CONTEXT */;
2527
+ return ctx[key];
2528
+ }
2529
+ else if (shouldCacheAccess) {
2530
+ accessCache[key] = 0 /* OTHER */;
2359
2531
  }
2360
2532
  }
2361
- else {
2362
- ctx[key] = injected;
2533
+ const publicGetter = publicPropertiesMap[key];
2534
+ let cssModule, globalProperties;
2535
+ // public $xxx properties
2536
+ if (publicGetter) {
2537
+ if (key === '$attrs') {
2538
+ reactivity.track(instance, "get" /* GET */, key);
2539
+ }
2540
+ return publicGetter(instance);
2363
2541
  }
2364
- }
2365
- }
2366
- function callHook(hook, instance, type) {
2367
- callWithAsyncErrorHandling(shared.isArray(hook)
2368
- ? hook.map(h => h.bind(instance.proxy))
2369
- : hook.bind(instance.proxy), instance, type);
2370
- }
2371
- function createWatcher(raw, ctx, publicThis, key) {
2372
- const getter = key.includes('.')
2373
- ? createPathGetter(publicThis, key)
2374
- : () => publicThis[key];
2375
- if (shared.isString(raw)) {
2376
- const handler = ctx[raw];
2377
- if (shared.isFunction(handler)) {
2378
- watch(getter, handler);
2542
+ else if (
2543
+ // css module (injected by vue-loader)
2544
+ (cssModule = type.__cssModules) &&
2545
+ (cssModule = cssModule[key])) {
2546
+ return cssModule;
2379
2547
  }
2380
- }
2381
- else if (shared.isFunction(raw)) {
2382
- watch(getter, raw.bind(publicThis));
2383
- }
2384
- else if (shared.isObject(raw)) {
2385
- if (shared.isArray(raw)) {
2386
- raw.forEach(r => createWatcher(r, ctx, publicThis, key));
2548
+ else if (ctx !== shared.EMPTY_OBJ && shared.hasOwn(ctx, key)) {
2549
+ // user may set custom properties to `this` that start with `$`
2550
+ accessCache[key] = 4 /* CONTEXT */;
2551
+ return ctx[key];
2387
2552
  }
2388
- else {
2389
- const handler = shared.isFunction(raw.handler)
2390
- ? raw.handler.bind(publicThis)
2391
- : ctx[raw.handler];
2392
- if (shared.isFunction(handler)) {
2393
- watch(getter, handler, raw);
2553
+ else if (
2554
+ // global properties
2555
+ ((globalProperties = appContext.config.globalProperties),
2556
+ shared.hasOwn(globalProperties, key))) {
2557
+ {
2558
+ return globalProperties[key];
2394
2559
  }
2395
2560
  }
2396
- }
2397
- else ;
2398
- }
2399
- /**
2400
- * Resolve merged options and cache it on the component.
2401
- * This is done only once per-component since the merging does not involve
2402
- * instances.
2403
- */
2404
- function resolveMergedOptions(instance) {
2405
- const base = instance.type;
2406
- const { mixins, extends: extendsOptions } = base;
2407
- const { mixins: globalMixins, optionsCache: cache, config: { optionMergeStrategies } } = instance.appContext;
2408
- const cached = cache.get(base);
2409
- let resolved;
2410
- if (cached) {
2411
- resolved = cached;
2412
- }
2413
- else if (!globalMixins.length && !mixins && !extendsOptions) {
2414
- {
2415
- resolved = base;
2561
+ else ;
2562
+ },
2563
+ set({ _: instance }, key, value) {
2564
+ const { data, setupState, ctx } = instance;
2565
+ if (setupState !== shared.EMPTY_OBJ && shared.hasOwn(setupState, key)) {
2566
+ setupState[key] = value;
2567
+ return true;
2416
2568
  }
2417
- }
2418
- else {
2419
- resolved = {};
2420
- if (globalMixins.length) {
2421
- globalMixins.forEach(m => mergeOptions(resolved, m, optionMergeStrategies, true));
2569
+ else if (data !== shared.EMPTY_OBJ && shared.hasOwn(data, key)) {
2570
+ data[key] = value;
2571
+ return true;
2572
+ }
2573
+ else if (shared.hasOwn(instance.props, key)) {
2574
+ return false;
2575
+ }
2576
+ if (key[0] === '$' && key.slice(1) in instance) {
2577
+ return false;
2422
2578
  }
2423
- mergeOptions(resolved, base, optionMergeStrategies);
2424
- }
2425
- cache.set(base, resolved);
2426
- return resolved;
2427
- }
2428
- function mergeOptions(to, from, strats, asMixin = false) {
2429
- const { mixins, extends: extendsOptions } = from;
2430
- if (extendsOptions) {
2431
- mergeOptions(to, extendsOptions, strats, true);
2432
- }
2433
- if (mixins) {
2434
- mixins.forEach((m) => mergeOptions(to, m, strats, true));
2435
- }
2436
- for (const key in from) {
2437
- if (asMixin && key === 'expose') ;
2438
2579
  else {
2439
- const strat = internalOptionMergeStrats[key] || (strats && strats[key]);
2440
- to[key] = strat ? strat(to[key], from[key]) : from[key];
2580
+ {
2581
+ ctx[key] = value;
2582
+ }
2583
+ }
2584
+ return true;
2585
+ },
2586
+ has({ _: { data, setupState, accessCache, ctx, appContext, propsOptions } }, key) {
2587
+ let normalizedProps;
2588
+ return (!!accessCache[key] ||
2589
+ (data !== shared.EMPTY_OBJ && shared.hasOwn(data, key)) ||
2590
+ (setupState !== shared.EMPTY_OBJ && shared.hasOwn(setupState, key)) ||
2591
+ ((normalizedProps = propsOptions[0]) && shared.hasOwn(normalizedProps, key)) ||
2592
+ shared.hasOwn(ctx, key) ||
2593
+ shared.hasOwn(publicPropertiesMap, key) ||
2594
+ shared.hasOwn(appContext.config.globalProperties, key));
2595
+ },
2596
+ defineProperty(target, key, descriptor) {
2597
+ if (descriptor.get != null) {
2598
+ // invalidate key cache of a getter based property #5417
2599
+ target._.accessCache[key] = 0;
2600
+ }
2601
+ else if (shared.hasOwn(descriptor, 'value')) {
2602
+ this.set(target, key, descriptor.value, null);
2441
2603
  }
2604
+ return Reflect.defineProperty(target, key, descriptor);
2442
2605
  }
2443
- return to;
2444
- }
2445
- const internalOptionMergeStrats = {
2446
- data: mergeDataFn,
2447
- props: mergeObjectOptions,
2448
- emits: mergeObjectOptions,
2449
- // objects
2450
- methods: mergeObjectOptions,
2451
- computed: mergeObjectOptions,
2452
- // lifecycle
2453
- beforeCreate: mergeAsArray,
2454
- created: mergeAsArray,
2455
- beforeMount: mergeAsArray,
2456
- mounted: mergeAsArray,
2457
- beforeUpdate: mergeAsArray,
2458
- updated: mergeAsArray,
2459
- beforeDestroy: mergeAsArray,
2460
- beforeUnmount: mergeAsArray,
2461
- destroyed: mergeAsArray,
2462
- unmounted: mergeAsArray,
2463
- activated: mergeAsArray,
2464
- deactivated: mergeAsArray,
2465
- errorCaptured: mergeAsArray,
2466
- serverPrefetch: mergeAsArray,
2467
- // assets
2468
- components: mergeObjectOptions,
2469
- directives: mergeObjectOptions,
2470
- // watch
2471
- watch: mergeWatchOptions,
2472
- // provide / inject
2473
- provide: mergeDataFn,
2474
- inject: mergeInject
2475
2606
  };
2476
- function mergeDataFn(to, from) {
2477
- if (!from) {
2478
- return to;
2479
- }
2480
- if (!to) {
2481
- return from;
2482
- }
2483
- return function mergedDataFn() {
2484
- return (shared.extend)(shared.isFunction(to) ? to.call(this, this) : to, shared.isFunction(from) ? from.call(this, this) : from);
2485
- };
2486
- }
2487
- function mergeInject(to, from) {
2488
- return mergeObjectOptions(normalizeInject(to), normalizeInject(from));
2489
- }
2490
- function normalizeInject(raw) {
2491
- if (shared.isArray(raw)) {
2492
- const res = {};
2493
- for (let i = 0; i < raw.length; i++) {
2494
- res[raw[i]] = raw[i];
2607
+ const RuntimeCompiledPublicInstanceProxyHandlers = /*#__PURE__*/ shared.extend({}, PublicInstanceProxyHandlers, {
2608
+ get(target, key) {
2609
+ // fast path for unscopables when using `with` block
2610
+ if (key === Symbol.unscopables) {
2611
+ return;
2495
2612
  }
2496
- return res;
2497
- }
2498
- return raw;
2499
- }
2500
- function mergeAsArray(to, from) {
2501
- return to ? [...new Set([].concat(to, from))] : from;
2502
- }
2503
- function mergeObjectOptions(to, from) {
2504
- return to ? shared.extend(shared.extend(Object.create(null), to), from) : from;
2505
- }
2506
- function mergeWatchOptions(to, from) {
2507
- if (!to)
2508
- return from;
2509
- if (!from)
2510
- return to;
2511
- const merged = shared.extend(Object.create(null), to);
2512
- for (const key in from) {
2513
- merged[key] = mergeAsArray(to[key], from[key]);
2613
+ return PublicInstanceProxyHandlers.get(target, key, target);
2614
+ },
2615
+ has(_, key) {
2616
+ const has = key[0] !== '_' && !shared.isGloballyWhitelisted(key);
2617
+ return has;
2514
2618
  }
2515
- return merged;
2516
- }
2619
+ });
2517
2620
 
2518
- function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison
2519
- isSSR = false) {
2520
- const props = {};
2521
- const attrs = {};
2522
- shared.def(attrs, InternalObjectKey, 1);
2523
- instance.propsDefaults = Object.create(null);
2524
- setFullProps(instance, rawProps, props, attrs);
2525
- // ensure all declared prop keys are present
2526
- for (const key in instance.propsOptions[0]) {
2527
- if (!(key in props)) {
2528
- props[key] = undefined;
2529
- }
2621
+ let shouldCacheAccess = true;
2622
+ function applyOptions(instance) {
2623
+ const options = resolveMergedOptions(instance);
2624
+ const publicThis = instance.proxy;
2625
+ const ctx = instance.ctx;
2626
+ // do not cache property access on public proxy during state initialization
2627
+ shouldCacheAccess = false;
2628
+ // call beforeCreate first before accessing other options since
2629
+ // the hook may mutate resolved options (#2791)
2630
+ if (options.beforeCreate) {
2631
+ callHook(options.beforeCreate, instance, "bc" /* BEFORE_CREATE */);
2530
2632
  }
2531
- if (isStateful) {
2532
- // stateful
2533
- instance.props = isSSR ? props : reactivity.shallowReactive(props);
2633
+ const {
2634
+ // state
2635
+ data: dataOptions, computed: computedOptions, methods, watch: watchOptions, provide: provideOptions, inject: injectOptions,
2636
+ // lifecycle
2637
+ created, beforeMount, mounted, beforeUpdate, updated, activated, deactivated, beforeDestroy, beforeUnmount, destroyed, unmounted, render, renderTracked, renderTriggered, errorCaptured, serverPrefetch,
2638
+ // public API
2639
+ expose, inheritAttrs,
2640
+ // assets
2641
+ components, directives, filters } = options;
2642
+ const checkDuplicateProperties = null;
2643
+ // options initialization order (to be consistent with Vue 2):
2644
+ // - props (already done outside of this function)
2645
+ // - inject
2646
+ // - methods
2647
+ // - data (deferred since it relies on `this` access)
2648
+ // - computed
2649
+ // - watch (deferred since it relies on `this` access)
2650
+ if (injectOptions) {
2651
+ resolveInjections(injectOptions, ctx, checkDuplicateProperties, instance.appContext.config.unwrapInjectedRef);
2534
2652
  }
2535
- else {
2536
- if (!instance.type.props) {
2537
- // functional w/ optional props, props === attrs
2538
- instance.props = attrs;
2653
+ if (methods) {
2654
+ for (const key in methods) {
2655
+ const methodHandler = methods[key];
2656
+ if (shared.isFunction(methodHandler)) {
2657
+ // In dev mode, we use the `createRenderContext` function to define
2658
+ // methods to the proxy target, and those are read-only but
2659
+ // reconfigurable, so it needs to be redefined here
2660
+ {
2661
+ ctx[key] = methodHandler.bind(publicThis);
2662
+ }
2663
+ }
2539
2664
  }
2665
+ }
2666
+ if (dataOptions) {
2667
+ const data = dataOptions.call(publicThis, publicThis);
2668
+ if (!shared.isObject(data)) ;
2540
2669
  else {
2541
- // functional w/ declared props
2542
- instance.props = props;
2670
+ instance.data = reactivity.reactive(data);
2543
2671
  }
2544
2672
  }
2545
- instance.attrs = attrs;
2546
- }
2547
- function updateProps(instance, rawProps, rawPrevProps, optimized) {
2548
- const { props, attrs, vnode: { patchFlag } } = instance;
2549
- const rawCurrentProps = reactivity.toRaw(props);
2550
- const [options] = instance.propsOptions;
2551
- let hasAttrsChanged = false;
2552
- if (
2553
- // always force full diff in dev
2554
- // - #1942 if hmr is enabled with sfc component
2555
- // - vite#872 non-sfc component used by sfc component
2556
- (optimized || patchFlag > 0) &&
2557
- !(patchFlag & 16 /* FULL_PROPS */)) {
2558
- if (patchFlag & 8 /* PROPS */) {
2559
- // Compiler-generated props & no keys change, just set the updated
2560
- // the props.
2561
- const propsToUpdate = instance.vnode.dynamicProps;
2562
- for (let i = 0; i < propsToUpdate.length; i++) {
2563
- let key = propsToUpdate[i];
2564
- // skip if the prop key is a declared emit event listener
2565
- if (isEmitListener(instance.emitsOptions, key)) {
2566
- continue;
2567
- }
2568
- // PROPS flag guarantees rawProps to be non-null
2569
- const value = rawProps[key];
2570
- if (options) {
2571
- // attr / props separation was done on init and will be consistent
2572
- // in this code path, so just check if attrs have it.
2573
- if (shared.hasOwn(attrs, key)) {
2574
- if (value !== attrs[key]) {
2575
- attrs[key] = value;
2576
- hasAttrsChanged = true;
2577
- }
2578
- }
2579
- else {
2580
- const camelizedKey = shared.camelize(key);
2581
- props[camelizedKey] = resolvePropValue(options, rawCurrentProps, camelizedKey, value, instance, false /* isAbsent */);
2582
- }
2583
- }
2584
- else {
2585
- if (value !== attrs[key]) {
2586
- attrs[key] = value;
2587
- hasAttrsChanged = true;
2588
- }
2589
- }
2590
- }
2673
+ // state initialization complete at this point - start caching access
2674
+ shouldCacheAccess = true;
2675
+ if (computedOptions) {
2676
+ for (const key in computedOptions) {
2677
+ const opt = computedOptions[key];
2678
+ const get = shared.isFunction(opt)
2679
+ ? opt.bind(publicThis, publicThis)
2680
+ : shared.isFunction(opt.get)
2681
+ ? opt.get.bind(publicThis, publicThis)
2682
+ : shared.NOOP;
2683
+ const set = !shared.isFunction(opt) && shared.isFunction(opt.set)
2684
+ ? opt.set.bind(publicThis)
2685
+ : shared.NOOP;
2686
+ const c = computed({
2687
+ get,
2688
+ set
2689
+ });
2690
+ Object.defineProperty(ctx, key, {
2691
+ enumerable: true,
2692
+ configurable: true,
2693
+ get: () => c.value,
2694
+ set: v => (c.value = v)
2695
+ });
2591
2696
  }
2592
2697
  }
2593
- else {
2594
- // full props update.
2595
- if (setFullProps(instance, rawProps, props, attrs)) {
2596
- hasAttrsChanged = true;
2597
- }
2598
- // in case of dynamic props, check if we need to delete keys from
2599
- // the props object
2600
- let kebabKey;
2601
- for (const key in rawCurrentProps) {
2602
- if (!rawProps ||
2603
- // for camelCase
2604
- (!shared.hasOwn(rawProps, key) &&
2605
- // it's possible the original props was passed in as kebab-case
2606
- // and converted to camelCase (#955)
2607
- ((kebabKey = shared.hyphenate(key)) === key || !shared.hasOwn(rawProps, kebabKey)))) {
2608
- if (options) {
2609
- if (rawPrevProps &&
2610
- // for camelCase
2611
- (rawPrevProps[key] !== undefined ||
2612
- // for kebab-case
2613
- rawPrevProps[kebabKey] !== undefined)) {
2614
- props[key] = resolvePropValue(options, rawCurrentProps, key, undefined, instance, true /* isAbsent */);
2615
- }
2616
- }
2617
- else {
2618
- delete props[key];
2619
- }
2620
- }
2621
- }
2622
- // in the case of functional component w/o props declaration, props and
2623
- // attrs point to the same object so it should already have been updated.
2624
- if (attrs !== rawCurrentProps) {
2625
- for (const key in attrs) {
2626
- if (!rawProps ||
2627
- (!shared.hasOwn(rawProps, key) &&
2628
- (!false ))) {
2629
- delete attrs[key];
2630
- hasAttrsChanged = true;
2631
- }
2632
- }
2698
+ if (watchOptions) {
2699
+ for (const key in watchOptions) {
2700
+ createWatcher(watchOptions[key], ctx, publicThis, key);
2633
2701
  }
2634
2702
  }
2635
- // trigger updates for $attrs in case it's used in component slots
2636
- if (hasAttrsChanged) {
2637
- reactivity.trigger(instance, "set" /* SET */, '$attrs');
2703
+ if (provideOptions) {
2704
+ const provides = shared.isFunction(provideOptions)
2705
+ ? provideOptions.call(publicThis)
2706
+ : provideOptions;
2707
+ Reflect.ownKeys(provides).forEach(key => {
2708
+ provide(key, provides[key]);
2709
+ });
2638
2710
  }
2639
- }
2640
- function setFullProps(instance, rawProps, props, attrs) {
2641
- const [options, needCastKeys] = instance.propsOptions;
2642
- let hasAttrsChanged = false;
2643
- let rawCastValues;
2644
- if (rawProps) {
2645
- for (let key in rawProps) {
2646
- // key, ref are reserved and never passed down
2647
- if (shared.isReservedProp(key)) {
2648
- continue;
2649
- }
2650
- const value = rawProps[key];
2651
- // prop option names are camelized during normalization, so to support
2652
- // kebab -> camel conversion here we need to camelize the key.
2653
- let camelKey;
2654
- if (options && shared.hasOwn(options, (camelKey = shared.camelize(key)))) {
2655
- if (!needCastKeys || !needCastKeys.includes(camelKey)) {
2656
- props[camelKey] = value;
2657
- }
2658
- else {
2659
- (rawCastValues || (rawCastValues = {}))[camelKey] = value;
2660
- }
2661
- }
2662
- else if (!isEmitListener(instance.emitsOptions, key)) {
2663
- if (!(key in attrs) || value !== attrs[key]) {
2664
- attrs[key] = value;
2665
- hasAttrsChanged = true;
2666
- }
2667
- }
2711
+ if (created) {
2712
+ callHook(created, instance, "c" /* CREATED */);
2713
+ }
2714
+ function registerLifecycleHook(register, hook) {
2715
+ if (shared.isArray(hook)) {
2716
+ hook.forEach(_hook => register(_hook.bind(publicThis)));
2717
+ }
2718
+ else if (hook) {
2719
+ register(hook.bind(publicThis));
2668
2720
  }
2669
2721
  }
2670
- if (needCastKeys) {
2671
- const rawCurrentProps = reactivity.toRaw(props);
2672
- const castValues = rawCastValues || shared.EMPTY_OBJ;
2673
- for (let i = 0; i < needCastKeys.length; i++) {
2674
- const key = needCastKeys[i];
2675
- props[key] = resolvePropValue(options, rawCurrentProps, key, castValues[key], instance, !shared.hasOwn(castValues, key));
2722
+ registerLifecycleHook(onBeforeMount, beforeMount);
2723
+ registerLifecycleHook(onMounted, mounted);
2724
+ registerLifecycleHook(onBeforeUpdate, beforeUpdate);
2725
+ registerLifecycleHook(onUpdated, updated);
2726
+ registerLifecycleHook(onActivated, activated);
2727
+ registerLifecycleHook(onDeactivated, deactivated);
2728
+ registerLifecycleHook(onErrorCaptured, errorCaptured);
2729
+ registerLifecycleHook(onRenderTracked, renderTracked);
2730
+ registerLifecycleHook(onRenderTriggered, renderTriggered);
2731
+ registerLifecycleHook(onBeforeUnmount, beforeUnmount);
2732
+ registerLifecycleHook(onUnmounted, unmounted);
2733
+ registerLifecycleHook(onServerPrefetch, serverPrefetch);
2734
+ if (shared.isArray(expose)) {
2735
+ if (expose.length) {
2736
+ const exposed = instance.exposed || (instance.exposed = {});
2737
+ expose.forEach(key => {
2738
+ Object.defineProperty(exposed, key, {
2739
+ get: () => publicThis[key],
2740
+ set: val => (publicThis[key] = val)
2741
+ });
2742
+ });
2743
+ }
2744
+ else if (!instance.exposed) {
2745
+ instance.exposed = {};
2676
2746
  }
2677
2747
  }
2678
- return hasAttrsChanged;
2748
+ // options that are handled when creating the instance but also need to be
2749
+ // applied from mixins
2750
+ if (render && instance.render === shared.NOOP) {
2751
+ instance.render = render;
2752
+ }
2753
+ if (inheritAttrs != null) {
2754
+ instance.inheritAttrs = inheritAttrs;
2755
+ }
2756
+ // asset options.
2757
+ if (components)
2758
+ instance.components = components;
2759
+ if (directives)
2760
+ instance.directives = directives;
2679
2761
  }
2680
- function resolvePropValue(options, props, key, value, instance, isAbsent) {
2681
- const opt = options[key];
2682
- if (opt != null) {
2683
- const hasDefault = shared.hasOwn(opt, 'default');
2684
- // default values
2685
- if (hasDefault && value === undefined) {
2686
- const defaultValue = opt.default;
2687
- if (opt.type !== Function && shared.isFunction(defaultValue)) {
2688
- const { propsDefaults } = instance;
2689
- if (key in propsDefaults) {
2690
- value = propsDefaults[key];
2691
- }
2692
- else {
2693
- setCurrentInstance(instance);
2694
- value = propsDefaults[key] = defaultValue.call(null, props);
2695
- unsetCurrentInstance();
2696
- }
2762
+ function resolveInjections(injectOptions, ctx, checkDuplicateProperties = shared.NOOP, unwrapRef = false) {
2763
+ if (shared.isArray(injectOptions)) {
2764
+ injectOptions = normalizeInject(injectOptions);
2765
+ }
2766
+ for (const key in injectOptions) {
2767
+ const opt = injectOptions[key];
2768
+ let injected;
2769
+ if (shared.isObject(opt)) {
2770
+ if ('default' in opt) {
2771
+ injected = inject(opt.from || key, opt.default, true /* treat default function as factory */);
2697
2772
  }
2698
2773
  else {
2699
- value = defaultValue;
2774
+ injected = inject(opt.from || key);
2700
2775
  }
2701
2776
  }
2702
- // boolean casting
2703
- if (opt[0 /* shouldCast */]) {
2704
- if (isAbsent && !hasDefault) {
2705
- value = false;
2777
+ else {
2778
+ injected = inject(opt);
2779
+ }
2780
+ if (reactivity.isRef(injected)) {
2781
+ // TODO remove the check in 3.3
2782
+ if (unwrapRef) {
2783
+ Object.defineProperty(ctx, key, {
2784
+ enumerable: true,
2785
+ configurable: true,
2786
+ get: () => injected.value,
2787
+ set: v => (injected.value = v)
2788
+ });
2706
2789
  }
2707
- else if (opt[1 /* shouldCastTrue */] &&
2708
- (value === '' || value === shared.hyphenate(key))) {
2709
- value = true;
2790
+ else {
2791
+ ctx[key] = injected;
2710
2792
  }
2711
2793
  }
2794
+ else {
2795
+ ctx[key] = injected;
2796
+ }
2712
2797
  }
2713
- return value;
2714
2798
  }
2715
- function normalizePropsOptions(comp, appContext, asMixin = false) {
2716
- const cache = appContext.propsCache;
2717
- const cached = cache.get(comp);
2718
- if (cached) {
2719
- return cached;
2720
- }
2721
- const raw = comp.props;
2722
- const normalized = {};
2723
- const needCastKeys = [];
2724
- // apply mixin/extends props
2725
- let hasExtends = false;
2726
- if (!shared.isFunction(comp)) {
2727
- const extendProps = (raw) => {
2728
- hasExtends = true;
2729
- const [props, keys] = normalizePropsOptions(raw, appContext, true);
2730
- shared.extend(normalized, props);
2731
- if (keys)
2732
- needCastKeys.push(...keys);
2733
- };
2734
- if (!asMixin && appContext.mixins.length) {
2735
- appContext.mixins.forEach(extendProps);
2799
+ function callHook(hook, instance, type) {
2800
+ callWithAsyncErrorHandling(shared.isArray(hook)
2801
+ ? hook.map(h => h.bind(instance.proxy))
2802
+ : hook.bind(instance.proxy), instance, type);
2803
+ }
2804
+ function createWatcher(raw, ctx, publicThis, key) {
2805
+ const getter = key.includes('.')
2806
+ ? createPathGetter(publicThis, key)
2807
+ : () => publicThis[key];
2808
+ if (shared.isString(raw)) {
2809
+ const handler = ctx[raw];
2810
+ if (shared.isFunction(handler)) {
2811
+ watch(getter, handler);
2736
2812
  }
2737
- if (comp.extends) {
2738
- extendProps(comp.extends);
2813
+ }
2814
+ else if (shared.isFunction(raw)) {
2815
+ watch(getter, raw.bind(publicThis));
2816
+ }
2817
+ else if (shared.isObject(raw)) {
2818
+ if (shared.isArray(raw)) {
2819
+ raw.forEach(r => createWatcher(r, ctx, publicThis, key));
2739
2820
  }
2740
- if (comp.mixins) {
2741
- comp.mixins.forEach(extendProps);
2821
+ else {
2822
+ const handler = shared.isFunction(raw.handler)
2823
+ ? raw.handler.bind(publicThis)
2824
+ : ctx[raw.handler];
2825
+ if (shared.isFunction(handler)) {
2826
+ watch(getter, handler, raw);
2827
+ }
2742
2828
  }
2743
2829
  }
2744
- if (!raw && !hasExtends) {
2745
- cache.set(comp, shared.EMPTY_ARR);
2746
- return shared.EMPTY_ARR;
2830
+ else ;
2831
+ }
2832
+ /**
2833
+ * Resolve merged options and cache it on the component.
2834
+ * This is done only once per-component since the merging does not involve
2835
+ * instances.
2836
+ */
2837
+ function resolveMergedOptions(instance) {
2838
+ const base = instance.type;
2839
+ const { mixins, extends: extendsOptions } = base;
2840
+ const { mixins: globalMixins, optionsCache: cache, config: { optionMergeStrategies } } = instance.appContext;
2841
+ const cached = cache.get(base);
2842
+ let resolved;
2843
+ if (cached) {
2844
+ resolved = cached;
2747
2845
  }
2748
- if (shared.isArray(raw)) {
2749
- for (let i = 0; i < raw.length; i++) {
2750
- const normalizedKey = shared.camelize(raw[i]);
2751
- if (validatePropName(normalizedKey)) {
2752
- normalized[normalizedKey] = shared.EMPTY_OBJ;
2753
- }
2846
+ else if (!globalMixins.length && !mixins && !extendsOptions) {
2847
+ {
2848
+ resolved = base;
2754
2849
  }
2755
2850
  }
2756
- else if (raw) {
2757
- for (const key in raw) {
2758
- const normalizedKey = shared.camelize(key);
2759
- if (validatePropName(normalizedKey)) {
2760
- const opt = raw[key];
2761
- const prop = (normalized[normalizedKey] =
2762
- shared.isArray(opt) || shared.isFunction(opt) ? { type: opt } : opt);
2763
- if (prop) {
2764
- const booleanIndex = getTypeIndex(Boolean, prop.type);
2765
- const stringIndex = getTypeIndex(String, prop.type);
2766
- prop[0 /* shouldCast */] = booleanIndex > -1;
2767
- prop[1 /* shouldCastTrue */] =
2768
- stringIndex < 0 || booleanIndex < stringIndex;
2769
- // if the prop needs boolean casting or default value
2770
- if (booleanIndex > -1 || shared.hasOwn(prop, 'default')) {
2771
- needCastKeys.push(normalizedKey);
2772
- }
2773
- }
2774
- }
2851
+ else {
2852
+ resolved = {};
2853
+ if (globalMixins.length) {
2854
+ globalMixins.forEach(m => mergeOptions(resolved, m, optionMergeStrategies, true));
2775
2855
  }
2856
+ mergeOptions(resolved, base, optionMergeStrategies);
2776
2857
  }
2777
- const res = [normalized, needCastKeys];
2778
- cache.set(comp, res);
2779
- return res;
2858
+ cache.set(base, resolved);
2859
+ return resolved;
2780
2860
  }
2781
- function validatePropName(key) {
2782
- if (key[0] !== '$') {
2783
- return true;
2861
+ function mergeOptions(to, from, strats, asMixin = false) {
2862
+ const { mixins, extends: extendsOptions } = from;
2863
+ if (extendsOptions) {
2864
+ mergeOptions(to, extendsOptions, strats, true);
2784
2865
  }
2785
- return false;
2866
+ if (mixins) {
2867
+ mixins.forEach((m) => mergeOptions(to, m, strats, true));
2868
+ }
2869
+ for (const key in from) {
2870
+ if (asMixin && key === 'expose') ;
2871
+ else {
2872
+ const strat = internalOptionMergeStrats[key] || (strats && strats[key]);
2873
+ to[key] = strat ? strat(to[key], from[key]) : from[key];
2874
+ }
2875
+ }
2876
+ return to;
2786
2877
  }
2787
- // use function string name to check type constructors
2788
- // so that it works across vms / iframes.
2789
- function getType(ctor) {
2790
- const match = ctor && ctor.toString().match(/^\s*function (\w+)/);
2791
- return match ? match[1] : ctor === null ? 'null' : '';
2878
+ const internalOptionMergeStrats = {
2879
+ data: mergeDataFn,
2880
+ props: mergeObjectOptions,
2881
+ emits: mergeObjectOptions,
2882
+ // objects
2883
+ methods: mergeObjectOptions,
2884
+ computed: mergeObjectOptions,
2885
+ // lifecycle
2886
+ beforeCreate: mergeAsArray,
2887
+ created: mergeAsArray,
2888
+ beforeMount: mergeAsArray,
2889
+ mounted: mergeAsArray,
2890
+ beforeUpdate: mergeAsArray,
2891
+ updated: mergeAsArray,
2892
+ beforeDestroy: mergeAsArray,
2893
+ beforeUnmount: mergeAsArray,
2894
+ destroyed: mergeAsArray,
2895
+ unmounted: mergeAsArray,
2896
+ activated: mergeAsArray,
2897
+ deactivated: mergeAsArray,
2898
+ errorCaptured: mergeAsArray,
2899
+ serverPrefetch: mergeAsArray,
2900
+ // assets
2901
+ components: mergeObjectOptions,
2902
+ directives: mergeObjectOptions,
2903
+ // watch
2904
+ watch: mergeWatchOptions,
2905
+ // provide / inject
2906
+ provide: mergeDataFn,
2907
+ inject: mergeInject
2908
+ };
2909
+ function mergeDataFn(to, from) {
2910
+ if (!from) {
2911
+ return to;
2912
+ }
2913
+ if (!to) {
2914
+ return from;
2915
+ }
2916
+ return function mergedDataFn() {
2917
+ return (shared.extend)(shared.isFunction(to) ? to.call(this, this) : to, shared.isFunction(from) ? from.call(this, this) : from);
2918
+ };
2792
2919
  }
2793
- function isSameType(a, b) {
2794
- return getType(a) === getType(b);
2920
+ function mergeInject(to, from) {
2921
+ return mergeObjectOptions(normalizeInject(to), normalizeInject(from));
2795
2922
  }
2796
- function getTypeIndex(type, expectedTypes) {
2797
- if (shared.isArray(expectedTypes)) {
2798
- return expectedTypes.findIndex(t => isSameType(t, type));
2923
+ function normalizeInject(raw) {
2924
+ if (shared.isArray(raw)) {
2925
+ const res = {};
2926
+ for (let i = 0; i < raw.length; i++) {
2927
+ res[raw[i]] = raw[i];
2928
+ }
2929
+ return res;
2799
2930
  }
2800
- else if (shared.isFunction(expectedTypes)) {
2801
- return isSameType(expectedTypes, type) ? 0 : -1;
2931
+ return raw;
2932
+ }
2933
+ function mergeAsArray(to, from) {
2934
+ return to ? [...new Set([].concat(to, from))] : from;
2935
+ }
2936
+ function mergeObjectOptions(to, from) {
2937
+ return to ? shared.extend(shared.extend(Object.create(null), to), from) : from;
2938
+ }
2939
+ function mergeWatchOptions(to, from) {
2940
+ if (!to)
2941
+ return from;
2942
+ if (!from)
2943
+ return to;
2944
+ const merged = shared.extend(Object.create(null), to);
2945
+ for (const key in from) {
2946
+ merged[key] = mergeAsArray(to[key], from[key]);
2802
2947
  }
2803
- return -1;
2948
+ return merged;
2804
2949
  }
2805
2950
 
2806
- const isInternalKey = (key) => key[0] === '_' || key === '$stable';
2807
- const normalizeSlotValue = (value) => shared.isArray(value)
2808
- ? value.map(normalizeVNode)
2809
- : [normalizeVNode(value)];
2810
- const normalizeSlot = (key, rawSlot, ctx) => {
2811
- const normalized = withCtx((...args) => {
2812
- return normalizeSlotValue(rawSlot(...args));
2813
- }, ctx);
2814
- normalized._c = false;
2815
- return normalized;
2816
- };
2817
- const normalizeObjectSlots = (rawSlots, slots, instance) => {
2818
- const ctx = rawSlots._ctx;
2819
- for (const key in rawSlots) {
2820
- if (isInternalKey(key))
2821
- continue;
2822
- const value = rawSlots[key];
2823
- if (shared.isFunction(value)) {
2824
- slots[key] = normalizeSlot(key, value, ctx);
2825
- }
2826
- else if (value != null) {
2827
- const normalized = normalizeSlotValue(value);
2828
- slots[key] = () => normalized;
2951
+ function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison
2952
+ isSSR = false) {
2953
+ const props = {};
2954
+ const attrs = {};
2955
+ shared.def(attrs, InternalObjectKey, 1);
2956
+ instance.propsDefaults = Object.create(null);
2957
+ setFullProps(instance, rawProps, props, attrs);
2958
+ // ensure all declared prop keys are present
2959
+ for (const key in instance.propsOptions[0]) {
2960
+ if (!(key in props)) {
2961
+ props[key] = undefined;
2829
2962
  }
2830
2963
  }
2831
- };
2832
- const normalizeVNodeSlots = (instance, children) => {
2833
- const normalized = normalizeSlotValue(children);
2834
- instance.slots.default = () => normalized;
2835
- };
2836
- const initSlots = (instance, children) => {
2837
- if (instance.vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
2838
- const type = children._;
2839
- if (type) {
2840
- // users can get the shallow readonly version of the slots object through `this.$slots`,
2841
- // we should avoid the proxy object polluting the slots of the internal instance
2842
- instance.slots = reactivity.toRaw(children);
2843
- // make compiler marker non-enumerable
2844
- shared.def(children, '_', type);
2845
- }
2846
- else {
2847
- normalizeObjectSlots(children, (instance.slots = {}));
2848
- }
2964
+ if (isStateful) {
2965
+ // stateful
2966
+ instance.props = isSSR ? props : reactivity.shallowReactive(props);
2849
2967
  }
2850
2968
  else {
2851
- instance.slots = {};
2852
- if (children) {
2853
- normalizeVNodeSlots(instance, children);
2969
+ if (!instance.type.props) {
2970
+ // functional w/ optional props, props === attrs
2971
+ instance.props = attrs;
2972
+ }
2973
+ else {
2974
+ // functional w/ declared props
2975
+ instance.props = props;
2854
2976
  }
2855
2977
  }
2856
- shared.def(instance.slots, InternalObjectKey, 1);
2857
- };
2858
- const updateSlots = (instance, children, optimized) => {
2859
- const { vnode, slots } = instance;
2860
- let needDeletionCheck = true;
2861
- let deletionComparisonTarget = shared.EMPTY_OBJ;
2862
- if (vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
2863
- const type = children._;
2864
- if (type) {
2865
- // compiled slots.
2866
- if (optimized && type === 1 /* STABLE */) {
2867
- // compiled AND stable.
2868
- // no need to update, and skip stale slots removal.
2869
- needDeletionCheck = false;
2978
+ instance.attrs = attrs;
2979
+ }
2980
+ function updateProps(instance, rawProps, rawPrevProps, optimized) {
2981
+ const { props, attrs, vnode: { patchFlag } } = instance;
2982
+ const rawCurrentProps = reactivity.toRaw(props);
2983
+ const [options] = instance.propsOptions;
2984
+ let hasAttrsChanged = false;
2985
+ if (
2986
+ // always force full diff in dev
2987
+ // - #1942 if hmr is enabled with sfc component
2988
+ // - vite#872 non-sfc component used by sfc component
2989
+ (optimized || patchFlag > 0) &&
2990
+ !(patchFlag & 16 /* FULL_PROPS */)) {
2991
+ if (patchFlag & 8 /* PROPS */) {
2992
+ // Compiler-generated props & no keys change, just set the updated
2993
+ // the props.
2994
+ const propsToUpdate = instance.vnode.dynamicProps;
2995
+ for (let i = 0; i < propsToUpdate.length; i++) {
2996
+ let key = propsToUpdate[i];
2997
+ // skip if the prop key is a declared emit event listener
2998
+ if (isEmitListener(instance.emitsOptions, key)) {
2999
+ continue;
3000
+ }
3001
+ // PROPS flag guarantees rawProps to be non-null
3002
+ const value = rawProps[key];
3003
+ if (options) {
3004
+ // attr / props separation was done on init and will be consistent
3005
+ // in this code path, so just check if attrs have it.
3006
+ if (shared.hasOwn(attrs, key)) {
3007
+ if (value !== attrs[key]) {
3008
+ attrs[key] = value;
3009
+ hasAttrsChanged = true;
3010
+ }
3011
+ }
3012
+ else {
3013
+ const camelizedKey = shared.camelize(key);
3014
+ props[camelizedKey] = resolvePropValue(options, rawCurrentProps, camelizedKey, value, instance, false /* isAbsent */);
3015
+ }
3016
+ }
3017
+ else {
3018
+ if (value !== attrs[key]) {
3019
+ attrs[key] = value;
3020
+ hasAttrsChanged = true;
3021
+ }
3022
+ }
2870
3023
  }
2871
- else {
2872
- // compiled but dynamic (v-if/v-for on slots) - update slots, but skip
2873
- // normalization.
2874
- shared.extend(slots, children);
2875
- // #2893
2876
- // when rendering the optimized slots by manually written render function,
2877
- // we need to delete the `slots._` flag if necessary to make subsequent updates reliable,
2878
- // i.e. let the `renderSlot` create the bailed Fragment
2879
- if (!optimized && type === 1 /* STABLE */) {
2880
- delete slots._;
3024
+ }
3025
+ }
3026
+ else {
3027
+ // full props update.
3028
+ if (setFullProps(instance, rawProps, props, attrs)) {
3029
+ hasAttrsChanged = true;
3030
+ }
3031
+ // in case of dynamic props, check if we need to delete keys from
3032
+ // the props object
3033
+ let kebabKey;
3034
+ for (const key in rawCurrentProps) {
3035
+ if (!rawProps ||
3036
+ // for camelCase
3037
+ (!shared.hasOwn(rawProps, key) &&
3038
+ // it's possible the original props was passed in as kebab-case
3039
+ // and converted to camelCase (#955)
3040
+ ((kebabKey = shared.hyphenate(key)) === key || !shared.hasOwn(rawProps, kebabKey)))) {
3041
+ if (options) {
3042
+ if (rawPrevProps &&
3043
+ // for camelCase
3044
+ (rawPrevProps[key] !== undefined ||
3045
+ // for kebab-case
3046
+ rawPrevProps[kebabKey] !== undefined)) {
3047
+ props[key] = resolvePropValue(options, rawCurrentProps, key, undefined, instance, true /* isAbsent */);
3048
+ }
3049
+ }
3050
+ else {
3051
+ delete props[key];
2881
3052
  }
2882
3053
  }
2883
3054
  }
2884
- else {
2885
- needDeletionCheck = !children.$stable;
2886
- normalizeObjectSlots(children, slots);
3055
+ // in the case of functional component w/o props declaration, props and
3056
+ // attrs point to the same object so it should already have been updated.
3057
+ if (attrs !== rawCurrentProps) {
3058
+ for (const key in attrs) {
3059
+ if (!rawProps ||
3060
+ (!shared.hasOwn(rawProps, key) &&
3061
+ (!false ))) {
3062
+ delete attrs[key];
3063
+ hasAttrsChanged = true;
3064
+ }
3065
+ }
2887
3066
  }
2888
- deletionComparisonTarget = children;
2889
3067
  }
2890
- else if (children) {
2891
- // non slot object children (direct value) passed to a component
2892
- normalizeVNodeSlots(instance, children);
2893
- deletionComparisonTarget = { default: 1 };
3068
+ // trigger updates for $attrs in case it's used in component slots
3069
+ if (hasAttrsChanged) {
3070
+ reactivity.trigger(instance, "set" /* SET */, '$attrs');
2894
3071
  }
2895
- // delete stale slots
2896
- if (needDeletionCheck) {
2897
- for (const key in slots) {
2898
- if (!isInternalKey(key) && !(key in deletionComparisonTarget)) {
2899
- delete slots[key];
3072
+ }
3073
+ function setFullProps(instance, rawProps, props, attrs) {
3074
+ const [options, needCastKeys] = instance.propsOptions;
3075
+ let hasAttrsChanged = false;
3076
+ let rawCastValues;
3077
+ if (rawProps) {
3078
+ for (let key in rawProps) {
3079
+ // key, ref are reserved and never passed down
3080
+ if (shared.isReservedProp(key)) {
3081
+ continue;
3082
+ }
3083
+ const value = rawProps[key];
3084
+ // prop option names are camelized during normalization, so to support
3085
+ // kebab -> camel conversion here we need to camelize the key.
3086
+ let camelKey;
3087
+ if (options && shared.hasOwn(options, (camelKey = shared.camelize(key)))) {
3088
+ if (!needCastKeys || !needCastKeys.includes(camelKey)) {
3089
+ props[camelKey] = value;
3090
+ }
3091
+ else {
3092
+ (rawCastValues || (rawCastValues = {}))[camelKey] = value;
3093
+ }
3094
+ }
3095
+ else if (!isEmitListener(instance.emitsOptions, key)) {
3096
+ if (!(key in attrs) || value !== attrs[key]) {
3097
+ attrs[key] = value;
3098
+ hasAttrsChanged = true;
3099
+ }
2900
3100
  }
2901
3101
  }
2902
3102
  }
2903
- };
2904
-
2905
- /**
2906
- Runtime helper for applying directives to a vnode. Example usage:
2907
-
2908
- const comp = resolveComponent('comp')
2909
- const foo = resolveDirective('foo')
2910
- const bar = resolveDirective('bar')
2911
-
2912
- return withDirectives(h(comp), [
2913
- [foo, this.x],
2914
- [bar, this.y]
2915
- ])
2916
- */
2917
- /**
2918
- * Adds directives to a VNode.
2919
- */
2920
- function withDirectives(vnode, directives) {
2921
- const internalInstance = currentRenderingInstance;
2922
- if (internalInstance === null) {
2923
- return vnode;
2924
- }
2925
- const instance = getExposeProxy(internalInstance) ||
2926
- internalInstance.proxy;
2927
- const bindings = vnode.dirs || (vnode.dirs = []);
2928
- for (let i = 0; i < directives.length; i++) {
2929
- let [dir, value, arg, modifiers = shared.EMPTY_OBJ] = directives[i];
2930
- if (shared.isFunction(dir)) {
2931
- dir = {
2932
- mounted: dir,
2933
- updated: dir
2934
- };
2935
- }
2936
- if (dir.deep) {
2937
- traverse(value);
3103
+ if (needCastKeys) {
3104
+ const rawCurrentProps = reactivity.toRaw(props);
3105
+ const castValues = rawCastValues || shared.EMPTY_OBJ;
3106
+ for (let i = 0; i < needCastKeys.length; i++) {
3107
+ const key = needCastKeys[i];
3108
+ props[key] = resolvePropValue(options, rawCurrentProps, key, castValues[key], instance, !shared.hasOwn(castValues, key));
2938
3109
  }
2939
- bindings.push({
2940
- dir,
2941
- instance,
2942
- value,
2943
- oldValue: void 0,
2944
- arg,
2945
- modifiers
2946
- });
2947
3110
  }
2948
- return vnode;
3111
+ return hasAttrsChanged;
2949
3112
  }
2950
- function invokeDirectiveHook(vnode, prevVNode, instance, name) {
2951
- const bindings = vnode.dirs;
2952
- const oldBindings = prevVNode && prevVNode.dirs;
2953
- for (let i = 0; i < bindings.length; i++) {
2954
- const binding = bindings[i];
2955
- if (oldBindings) {
2956
- binding.oldValue = oldBindings[i].value;
3113
+ function resolvePropValue(options, props, key, value, instance, isAbsent) {
3114
+ const opt = options[key];
3115
+ if (opt != null) {
3116
+ const hasDefault = shared.hasOwn(opt, 'default');
3117
+ // default values
3118
+ if (hasDefault && value === undefined) {
3119
+ const defaultValue = opt.default;
3120
+ if (opt.type !== Function && shared.isFunction(defaultValue)) {
3121
+ const { propsDefaults } = instance;
3122
+ if (key in propsDefaults) {
3123
+ value = propsDefaults[key];
3124
+ }
3125
+ else {
3126
+ setCurrentInstance(instance);
3127
+ value = propsDefaults[key] = defaultValue.call(null, props);
3128
+ unsetCurrentInstance();
3129
+ }
3130
+ }
3131
+ else {
3132
+ value = defaultValue;
3133
+ }
2957
3134
  }
2958
- let hook = binding.dir[name];
2959
- if (hook) {
2960
- // disable tracking inside all lifecycle hooks
2961
- // since they can potentially be called inside effects.
2962
- reactivity.pauseTracking();
2963
- callWithAsyncErrorHandling(hook, instance, 8 /* DIRECTIVE_HOOK */, [
2964
- vnode.el,
2965
- binding,
2966
- vnode,
2967
- prevVNode
2968
- ]);
2969
- reactivity.resetTracking();
3135
+ // boolean casting
3136
+ if (opt[0 /* shouldCast */]) {
3137
+ if (isAbsent && !hasDefault) {
3138
+ value = false;
3139
+ }
3140
+ else if (opt[1 /* shouldCastTrue */] &&
3141
+ (value === '' || value === shared.hyphenate(key))) {
3142
+ value = true;
3143
+ }
2970
3144
  }
2971
3145
  }
2972
- }
2973
-
2974
- function createAppContext() {
2975
- return {
2976
- app: null,
2977
- config: {
3146
+ return value;
3147
+ }
3148
+ function normalizePropsOptions(comp, appContext, asMixin = false) {
3149
+ const cache = appContext.propsCache;
3150
+ const cached = cache.get(comp);
3151
+ if (cached) {
3152
+ return cached;
3153
+ }
3154
+ const raw = comp.props;
3155
+ const normalized = {};
3156
+ const needCastKeys = [];
3157
+ // apply mixin/extends props
3158
+ let hasExtends = false;
3159
+ if (!shared.isFunction(comp)) {
3160
+ const extendProps = (raw) => {
3161
+ hasExtends = true;
3162
+ const [props, keys] = normalizePropsOptions(raw, appContext, true);
3163
+ shared.extend(normalized, props);
3164
+ if (keys)
3165
+ needCastKeys.push(...keys);
3166
+ };
3167
+ if (!asMixin && appContext.mixins.length) {
3168
+ appContext.mixins.forEach(extendProps);
3169
+ }
3170
+ if (comp.extends) {
3171
+ extendProps(comp.extends);
3172
+ }
3173
+ if (comp.mixins) {
3174
+ comp.mixins.forEach(extendProps);
3175
+ }
3176
+ }
3177
+ if (!raw && !hasExtends) {
3178
+ cache.set(comp, shared.EMPTY_ARR);
3179
+ return shared.EMPTY_ARR;
3180
+ }
3181
+ if (shared.isArray(raw)) {
3182
+ for (let i = 0; i < raw.length; i++) {
3183
+ const normalizedKey = shared.camelize(raw[i]);
3184
+ if (validatePropName(normalizedKey)) {
3185
+ normalized[normalizedKey] = shared.EMPTY_OBJ;
3186
+ }
3187
+ }
3188
+ }
3189
+ else if (raw) {
3190
+ for (const key in raw) {
3191
+ const normalizedKey = shared.camelize(key);
3192
+ if (validatePropName(normalizedKey)) {
3193
+ const opt = raw[key];
3194
+ const prop = (normalized[normalizedKey] =
3195
+ shared.isArray(opt) || shared.isFunction(opt) ? { type: opt } : opt);
3196
+ if (prop) {
3197
+ const booleanIndex = getTypeIndex(Boolean, prop.type);
3198
+ const stringIndex = getTypeIndex(String, prop.type);
3199
+ prop[0 /* shouldCast */] = booleanIndex > -1;
3200
+ prop[1 /* shouldCastTrue */] =
3201
+ stringIndex < 0 || booleanIndex < stringIndex;
3202
+ // if the prop needs boolean casting or default value
3203
+ if (booleanIndex > -1 || shared.hasOwn(prop, 'default')) {
3204
+ needCastKeys.push(normalizedKey);
3205
+ }
3206
+ }
3207
+ }
3208
+ }
3209
+ }
3210
+ const res = [normalized, needCastKeys];
3211
+ cache.set(comp, res);
3212
+ return res;
3213
+ }
3214
+ function validatePropName(key) {
3215
+ if (key[0] !== '$') {
3216
+ return true;
3217
+ }
3218
+ return false;
3219
+ }
3220
+ // use function string name to check type constructors
3221
+ // so that it works across vms / iframes.
3222
+ function getType(ctor) {
3223
+ const match = ctor && ctor.toString().match(/^\s*function (\w+)/);
3224
+ return match ? match[1] : ctor === null ? 'null' : '';
3225
+ }
3226
+ function isSameType(a, b) {
3227
+ return getType(a) === getType(b);
3228
+ }
3229
+ function getTypeIndex(type, expectedTypes) {
3230
+ if (shared.isArray(expectedTypes)) {
3231
+ return expectedTypes.findIndex(t => isSameType(t, type));
3232
+ }
3233
+ else if (shared.isFunction(expectedTypes)) {
3234
+ return isSameType(expectedTypes, type) ? 0 : -1;
3235
+ }
3236
+ return -1;
3237
+ }
3238
+
3239
+ const isInternalKey = (key) => key[0] === '_' || key === '$stable';
3240
+ const normalizeSlotValue = (value) => shared.isArray(value)
3241
+ ? value.map(normalizeVNode)
3242
+ : [normalizeVNode(value)];
3243
+ const normalizeSlot = (key, rawSlot, ctx) => {
3244
+ if (rawSlot._n) {
3245
+ // already normalized - #5353
3246
+ return rawSlot;
3247
+ }
3248
+ const normalized = withCtx((...args) => {
3249
+ return normalizeSlotValue(rawSlot(...args));
3250
+ }, ctx);
3251
+ normalized._c = false;
3252
+ return normalized;
3253
+ };
3254
+ const normalizeObjectSlots = (rawSlots, slots, instance) => {
3255
+ const ctx = rawSlots._ctx;
3256
+ for (const key in rawSlots) {
3257
+ if (isInternalKey(key))
3258
+ continue;
3259
+ const value = rawSlots[key];
3260
+ if (shared.isFunction(value)) {
3261
+ slots[key] = normalizeSlot(key, value, ctx);
3262
+ }
3263
+ else if (value != null) {
3264
+ const normalized = normalizeSlotValue(value);
3265
+ slots[key] = () => normalized;
3266
+ }
3267
+ }
3268
+ };
3269
+ const normalizeVNodeSlots = (instance, children) => {
3270
+ const normalized = normalizeSlotValue(children);
3271
+ instance.slots.default = () => normalized;
3272
+ };
3273
+ const initSlots = (instance, children) => {
3274
+ if (instance.vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
3275
+ const type = children._;
3276
+ if (type) {
3277
+ // users can get the shallow readonly version of the slots object through `this.$slots`,
3278
+ // we should avoid the proxy object polluting the slots of the internal instance
3279
+ instance.slots = reactivity.toRaw(children);
3280
+ // make compiler marker non-enumerable
3281
+ shared.def(children, '_', type);
3282
+ }
3283
+ else {
3284
+ normalizeObjectSlots(children, (instance.slots = {}));
3285
+ }
3286
+ }
3287
+ else {
3288
+ instance.slots = {};
3289
+ if (children) {
3290
+ normalizeVNodeSlots(instance, children);
3291
+ }
3292
+ }
3293
+ shared.def(instance.slots, InternalObjectKey, 1);
3294
+ };
3295
+ const updateSlots = (instance, children, optimized) => {
3296
+ const { vnode, slots } = instance;
3297
+ let needDeletionCheck = true;
3298
+ let deletionComparisonTarget = shared.EMPTY_OBJ;
3299
+ if (vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
3300
+ const type = children._;
3301
+ if (type) {
3302
+ // compiled slots.
3303
+ if (optimized && type === 1 /* STABLE */) {
3304
+ // compiled AND stable.
3305
+ // no need to update, and skip stale slots removal.
3306
+ needDeletionCheck = false;
3307
+ }
3308
+ else {
3309
+ // compiled but dynamic (v-if/v-for on slots) - update slots, but skip
3310
+ // normalization.
3311
+ shared.extend(slots, children);
3312
+ // #2893
3313
+ // when rendering the optimized slots by manually written render function,
3314
+ // we need to delete the `slots._` flag if necessary to make subsequent updates reliable,
3315
+ // i.e. let the `renderSlot` create the bailed Fragment
3316
+ if (!optimized && type === 1 /* STABLE */) {
3317
+ delete slots._;
3318
+ }
3319
+ }
3320
+ }
3321
+ else {
3322
+ needDeletionCheck = !children.$stable;
3323
+ normalizeObjectSlots(children, slots);
3324
+ }
3325
+ deletionComparisonTarget = children;
3326
+ }
3327
+ else if (children) {
3328
+ // non slot object children (direct value) passed to a component
3329
+ normalizeVNodeSlots(instance, children);
3330
+ deletionComparisonTarget = { default: 1 };
3331
+ }
3332
+ // delete stale slots
3333
+ if (needDeletionCheck) {
3334
+ for (const key in slots) {
3335
+ if (!isInternalKey(key) && !(key in deletionComparisonTarget)) {
3336
+ delete slots[key];
3337
+ }
3338
+ }
3339
+ }
3340
+ };
3341
+
3342
+ function createAppContext() {
3343
+ return {
3344
+ app: null,
3345
+ config: {
2978
3346
  isNativeTag: shared.NO,
2979
3347
  performance: false,
2980
3348
  globalProperties: {},
@@ -2996,7 +3364,7 @@ let uid = 0;
2996
3364
  function createAppAPI(render, hydrate) {
2997
3365
  return function createApp(rootComponent, rootProps = null) {
2998
3366
  if (!shared.isFunction(rootComponent)) {
2999
- rootComponent = Object.assign({}, rootComponent);
3367
+ rootComponent = { ...rootComponent };
3000
3368
  }
3001
3369
  if (rootProps != null && !shared.isObject(rootProps)) {
3002
3370
  rootProps = null;
@@ -3077,8 +3445,6 @@ function createAppAPI(render, hydrate) {
3077
3445
  }
3078
3446
  },
3079
3447
  provide(key, value) {
3080
- // TypeScript doesn't allow symbols as index type
3081
- // https://github.com/Microsoft/TypeScript/issues/24587
3082
3448
  context.provides[key] = value;
3083
3449
  return app;
3084
3450
  }
@@ -3185,7 +3551,7 @@ const isComment = (node) => node.nodeType === 8 /* COMMENT */;
3185
3551
  // Hydration also depends on some renderer internal logic which needs to be
3186
3552
  // passed in via arguments.
3187
3553
  function createHydrationFunctions(rendererInternals) {
3188
- const { mt: mountComponent, p: patch, o: { patchProp, nextSibling, parentNode, remove, insert, createComment } } = rendererInternals;
3554
+ const { mt: mountComponent, p: patch, o: { patchProp, createText, nextSibling, parentNode, remove, insert, createComment } } = rendererInternals;
3189
3555
  const hydrate = (vnode, container) => {
3190
3556
  if (!container.hasChildNodes()) {
3191
3557
  patch(null, vnode, container);
@@ -3203,14 +3569,26 @@ function createHydrationFunctions(rendererInternals) {
3203
3569
  const hydrateNode = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized = false) => {
3204
3570
  const isFragmentStart = isComment(node) && node.data === '[';
3205
3571
  const onMismatch = () => handleMismatch(node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragmentStart);
3206
- const { type, ref, shapeFlag } = vnode;
3572
+ const { type, ref, shapeFlag, patchFlag } = vnode;
3207
3573
  const domType = node.nodeType;
3208
3574
  vnode.el = node;
3575
+ if (patchFlag === -2 /* BAIL */) {
3576
+ optimized = false;
3577
+ vnode.dynamicChildren = null;
3578
+ }
3209
3579
  let nextNode = null;
3210
3580
  switch (type) {
3211
3581
  case Text:
3212
3582
  if (domType !== 3 /* TEXT */) {
3213
- nextNode = onMismatch();
3583
+ // #5728 empty text node inside a slot can cause hydration failure
3584
+ // because the server rendered HTML won't contain a text node
3585
+ if (vnode.children === '') {
3586
+ insert((vnode.el = createText('')), node.parentElement, node);
3587
+ nextNode = node;
3588
+ }
3589
+ else {
3590
+ nextNode = onMismatch();
3591
+ }
3214
3592
  }
3215
3593
  else {
3216
3594
  if (node.data !== vnode.children) {
@@ -3281,6 +3659,12 @@ function createHydrationFunctions(rendererInternals) {
3281
3659
  nextNode = isFragmentStart
3282
3660
  ? locateClosingAsyncAnchor(node)
3283
3661
  : nextSibling(node);
3662
+ // #4293 teleport as component root
3663
+ if (nextNode &&
3664
+ isComment(nextNode) &&
3665
+ nextNode.data === 'teleport end') {
3666
+ nextNode = nextSibling(nextNode);
3667
+ }
3284
3668
  // #3787
3285
3669
  // if component is async, it may get moved / unmounted before its
3286
3670
  // inner component is loaded, so we need to give it a placeholder
@@ -3946,7 +4330,6 @@ function baseCreateRenderer(options, createHydrationFns) {
3946
4330
  }
3947
4331
  else {
3948
4332
  // no update needed. just copy over properties
3949
- n2.component = n1.component;
3950
4333
  n2.el = n1.el;
3951
4334
  instance.vnode = n2;
3952
4335
  }
@@ -4005,7 +4388,10 @@ function baseCreateRenderer(options, createHydrationFns) {
4005
4388
  // activated hook for keep-alive roots.
4006
4389
  // #1742 activated hook must be accessed after first render
4007
4390
  // since the hook may be injected by a child keep-alive
4008
- if (initialVNode.shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
4391
+ if (initialVNode.shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */ ||
4392
+ (parent &&
4393
+ isAsyncWrapper(parent.vnode) &&
4394
+ parent.vnode.shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */)) {
4009
4395
  instance.a && queuePostRenderEffect(instance.a, parentSuspense);
4010
4396
  }
4011
4397
  instance.isMounted = true;
@@ -4063,9 +4449,9 @@ function baseCreateRenderer(options, createHydrationFns) {
4063
4449
  }
4064
4450
  };
4065
4451
  // create reactive effect for rendering
4066
- const effect = (instance.effect = new reactivity.ReactiveEffect(componentUpdateFn, () => queueJob(instance.update), instance.scope // track it in component's effect scope
4452
+ const effect = (instance.effect = new reactivity.ReactiveEffect(componentUpdateFn, () => queueJob(update), instance.scope // track it in component's effect scope
4067
4453
  ));
4068
- const update = (instance.update = effect.run.bind(effect));
4454
+ const update = (instance.update = () => effect.run());
4069
4455
  update.id = instance.uid;
4070
4456
  // allowRecurse
4071
4457
  // #1801, #2043 component render effects should allow recursive updates
@@ -4448,7 +4834,9 @@ function baseCreateRenderer(options, createHydrationFns) {
4448
4834
  const remove = vnode => {
4449
4835
  const { type, el, anchor, transition } = vnode;
4450
4836
  if (type === Fragment) {
4451
- removeFragment(el, anchor);
4837
+ {
4838
+ removeFragment(el, anchor);
4839
+ }
4452
4840
  return;
4453
4841
  }
4454
4842
  if (type === Static) {
@@ -4805,10 +5193,23 @@ function hydrateTeleport(node, vnode, parentComponent, parentSuspense, slotScope
4805
5193
  }
4806
5194
  else {
4807
5195
  vnode.anchor = nextSibling(node);
4808
- vnode.targetAnchor = hydrateChildren(targetNode, vnode, target, parentComponent, parentSuspense, slotScopeIds, optimized);
5196
+ // lookahead until we find the target anchor
5197
+ // we cannot rely on return value of hydrateChildren() because there
5198
+ // could be nested teleports
5199
+ let targetAnchor = targetNode;
5200
+ while (targetAnchor) {
5201
+ targetAnchor = nextSibling(targetAnchor);
5202
+ if (targetAnchor &&
5203
+ targetAnchor.nodeType === 8 &&
5204
+ targetAnchor.data === 'teleport anchor') {
5205
+ vnode.targetAnchor = targetAnchor;
5206
+ target._lpa =
5207
+ vnode.targetAnchor && nextSibling(vnode.targetAnchor);
5208
+ break;
5209
+ }
5210
+ }
5211
+ hydrateChildren(targetNode, vnode, target, parentComponent, parentSuspense, slotScopeIds, optimized);
4809
5212
  }
4810
- target._lpa =
4811
- vnode.targetAnchor && nextSibling(vnode.targetAnchor);
4812
5213
  }
4813
5214
  }
4814
5215
  return vnode.anchor && nextSibling(vnode.anchor);
@@ -4816,101 +5217,39 @@ function hydrateTeleport(node, vnode, parentComponent, parentSuspense, slotScope
4816
5217
  // Force-casted public typing for h and TSX props inference
4817
5218
  const Teleport = TeleportImpl;
4818
5219
 
4819
- const COMPONENTS = 'components';
4820
- const DIRECTIVES = 'directives';
5220
+ const Fragment = Symbol(undefined);
5221
+ const Text = Symbol(undefined);
5222
+ const Comment = Symbol(undefined);
5223
+ const Static = Symbol(undefined);
5224
+ // Since v-if and v-for are the two possible ways node structure can dynamically
5225
+ // change, once we consider v-if branches and each v-for fragment a block, we
5226
+ // can divide a template into nested blocks, and within each block the node
5227
+ // structure would be stable. This allows us to skip most children diffing
5228
+ // and only worry about the dynamic nodes (indicated by patch flags).
5229
+ const blockStack = [];
5230
+ let currentBlock = null;
4821
5231
  /**
5232
+ * Open a block.
5233
+ * This must be called before `createBlock`. It cannot be part of `createBlock`
5234
+ * because the children of the block are evaluated before `createBlock` itself
5235
+ * is called. The generated code typically looks like this:
5236
+ *
5237
+ * ```js
5238
+ * function render() {
5239
+ * return (openBlock(),createBlock('div', null, [...]))
5240
+ * }
5241
+ * ```
5242
+ * disableTracking is true when creating a v-for fragment block, since a v-for
5243
+ * fragment always diffs its children.
5244
+ *
4822
5245
  * @private
4823
5246
  */
4824
- function resolveComponent(name, maybeSelfReference) {
4825
- return resolveAsset(COMPONENTS, name, true, maybeSelfReference) || name;
5247
+ function openBlock(disableTracking = false) {
5248
+ blockStack.push((currentBlock = disableTracking ? null : []));
4826
5249
  }
4827
- const NULL_DYNAMIC_COMPONENT = Symbol();
4828
- /**
4829
- * @private
4830
- */
4831
- function resolveDynamicComponent(component) {
4832
- if (shared.isString(component)) {
4833
- return resolveAsset(COMPONENTS, component, false) || component;
4834
- }
4835
- else {
4836
- // invalid types will fallthrough to createVNode and raise warning
4837
- return (component || NULL_DYNAMIC_COMPONENT);
4838
- }
4839
- }
4840
- /**
4841
- * @private
4842
- */
4843
- function resolveDirective(name) {
4844
- return resolveAsset(DIRECTIVES, name);
4845
- }
4846
- // implementation
4847
- function resolveAsset(type, name, warnMissing = true, maybeSelfReference = false) {
4848
- const instance = currentRenderingInstance || currentInstance;
4849
- if (instance) {
4850
- const Component = instance.type;
4851
- // explicit self name has highest priority
4852
- if (type === COMPONENTS) {
4853
- const selfName = getComponentName(Component);
4854
- if (selfName &&
4855
- (selfName === name ||
4856
- selfName === shared.camelize(name) ||
4857
- selfName === shared.capitalize(shared.camelize(name)))) {
4858
- return Component;
4859
- }
4860
- }
4861
- const res =
4862
- // local registration
4863
- // check instance[type] first which is resolved for options API
4864
- resolve(instance[type] || Component[type], name) ||
4865
- // global registration
4866
- resolve(instance.appContext[type], name);
4867
- if (!res && maybeSelfReference) {
4868
- // fallback to implicit self-reference
4869
- return Component;
4870
- }
4871
- return res;
4872
- }
4873
- }
4874
- function resolve(registry, name) {
4875
- return (registry &&
4876
- (registry[name] ||
4877
- registry[shared.camelize(name)] ||
4878
- registry[shared.capitalize(shared.camelize(name))]));
4879
- }
4880
-
4881
- const Fragment = Symbol(undefined);
4882
- const Text = Symbol(undefined);
4883
- const Comment = Symbol(undefined);
4884
- const Static = Symbol(undefined);
4885
- // Since v-if and v-for are the two possible ways node structure can dynamically
4886
- // change, once we consider v-if branches and each v-for fragment a block, we
4887
- // can divide a template into nested blocks, and within each block the node
4888
- // structure would be stable. This allows us to skip most children diffing
4889
- // and only worry about the dynamic nodes (indicated by patch flags).
4890
- const blockStack = [];
4891
- let currentBlock = null;
4892
- /**
4893
- * Open a block.
4894
- * This must be called before `createBlock`. It cannot be part of `createBlock`
4895
- * because the children of the block are evaluated before `createBlock` itself
4896
- * is called. The generated code typically looks like this:
4897
- *
4898
- * ```js
4899
- * function render() {
4900
- * return (openBlock(),createBlock('div', null, [...]))
4901
- * }
4902
- * ```
4903
- * disableTracking is true when creating a v-for fragment block, since a v-for
4904
- * fragment always diffs its children.
4905
- *
4906
- * @private
4907
- */
4908
- function openBlock(disableTracking = false) {
4909
- blockStack.push((currentBlock = disableTracking ? null : []));
4910
- }
4911
- function closeBlock() {
4912
- blockStack.pop();
4913
- currentBlock = blockStack[blockStack.length - 1] || null;
5250
+ function closeBlock() {
5251
+ blockStack.pop();
5252
+ currentBlock = blockStack[blockStack.length - 1] || null;
4914
5253
  }
4915
5254
  // Whether we should be tracking dynamic child nodes inside a block.
4916
5255
  // Only tracks when this value is > 0
@@ -5061,6 +5400,15 @@ function _createVNode(type, props = null, children = null, patchFlag = 0, dynami
5061
5400
  if (children) {
5062
5401
  normalizeChildren(cloned, children);
5063
5402
  }
5403
+ if (isBlockTreeEnabled > 0 && !isBlockNode && currentBlock) {
5404
+ if (cloned.shapeFlag & 6 /* COMPONENT */) {
5405
+ currentBlock[currentBlock.indexOf(type)] = cloned;
5406
+ }
5407
+ else {
5408
+ currentBlock.push(cloned);
5409
+ }
5410
+ }
5411
+ cloned.patchFlag |= -2 /* BAIL */;
5064
5412
  return cloned;
5065
5413
  }
5066
5414
  // class component normalization.
@@ -5308,291 +5656,6 @@ function invokeVNodeHook(hook, instance, vnode, prevVNode = null) {
5308
5656
  ]);
5309
5657
  }
5310
5658
 
5311
- /**
5312
- * Actual implementation
5313
- */
5314
- function renderList(source, renderItem, cache, index) {
5315
- let ret;
5316
- const cached = (cache && cache[index]);
5317
- if (shared.isArray(source) || shared.isString(source)) {
5318
- ret = new Array(source.length);
5319
- for (let i = 0, l = source.length; i < l; i++) {
5320
- ret[i] = renderItem(source[i], i, undefined, cached && cached[i]);
5321
- }
5322
- }
5323
- else if (typeof source === 'number') {
5324
- ret = new Array(source);
5325
- for (let i = 0; i < source; i++) {
5326
- ret[i] = renderItem(i + 1, i, undefined, cached && cached[i]);
5327
- }
5328
- }
5329
- else if (shared.isObject(source)) {
5330
- if (source[Symbol.iterator]) {
5331
- ret = Array.from(source, (item, i) => renderItem(item, i, undefined, cached && cached[i]));
5332
- }
5333
- else {
5334
- const keys = Object.keys(source);
5335
- ret = new Array(keys.length);
5336
- for (let i = 0, l = keys.length; i < l; i++) {
5337
- const key = keys[i];
5338
- ret[i] = renderItem(source[key], key, i, cached && cached[i]);
5339
- }
5340
- }
5341
- }
5342
- else {
5343
- ret = [];
5344
- }
5345
- if (cache) {
5346
- cache[index] = ret;
5347
- }
5348
- return ret;
5349
- }
5350
-
5351
- /**
5352
- * Compiler runtime helper for creating dynamic slots object
5353
- * @private
5354
- */
5355
- function createSlots(slots, dynamicSlots) {
5356
- for (let i = 0; i < dynamicSlots.length; i++) {
5357
- const slot = dynamicSlots[i];
5358
- // array of dynamic slot generated by <template v-for="..." #[...]>
5359
- if (shared.isArray(slot)) {
5360
- for (let j = 0; j < slot.length; j++) {
5361
- slots[slot[j].name] = slot[j].fn;
5362
- }
5363
- }
5364
- else if (slot) {
5365
- // conditional single slot generated by <template v-if="..." #foo>
5366
- slots[slot.name] = slot.fn;
5367
- }
5368
- }
5369
- return slots;
5370
- }
5371
-
5372
- /**
5373
- * Compiler runtime helper for rendering `<slot/>`
5374
- * @private
5375
- */
5376
- function renderSlot(slots, name, props = {},
5377
- // this is not a user-facing function, so the fallback is always generated by
5378
- // the compiler and guaranteed to be a function returning an array
5379
- fallback, noSlotted) {
5380
- if (currentRenderingInstance.isCE) {
5381
- return createVNode('slot', name === 'default' ? null : { name }, fallback && fallback());
5382
- }
5383
- let slot = slots[name];
5384
- // a compiled slot disables block tracking by default to avoid manual
5385
- // invocation interfering with template-based block tracking, but in
5386
- // `renderSlot` we can be sure that it's template-based so we can force
5387
- // enable it.
5388
- if (slot && slot._c) {
5389
- slot._d = false;
5390
- }
5391
- openBlock();
5392
- const validSlotContent = slot && ensureValidVNode(slot(props));
5393
- const rendered = createBlock(Fragment, { key: props.key || `_${name}` }, validSlotContent || (fallback ? fallback() : []), validSlotContent && slots._ === 1 /* STABLE */
5394
- ? 64 /* STABLE_FRAGMENT */
5395
- : -2 /* BAIL */);
5396
- if (!noSlotted && rendered.scopeId) {
5397
- rendered.slotScopeIds = [rendered.scopeId + '-s'];
5398
- }
5399
- if (slot && slot._c) {
5400
- slot._d = true;
5401
- }
5402
- return rendered;
5403
- }
5404
- function ensureValidVNode(vnodes) {
5405
- return vnodes.some(child => {
5406
- if (!isVNode(child))
5407
- return true;
5408
- if (child.type === Comment)
5409
- return false;
5410
- if (child.type === Fragment &&
5411
- !ensureValidVNode(child.children))
5412
- return false;
5413
- return true;
5414
- })
5415
- ? vnodes
5416
- : null;
5417
- }
5418
-
5419
- /**
5420
- * For prefixing keys in v-on="obj" with "on"
5421
- * @private
5422
- */
5423
- function toHandlers(obj) {
5424
- const ret = {};
5425
- for (const key in obj) {
5426
- ret[shared.toHandlerKey(key)] = obj[key];
5427
- }
5428
- return ret;
5429
- }
5430
-
5431
- /**
5432
- * #2437 In Vue 3, functional components do not have a public instance proxy but
5433
- * they exist in the internal parent chain. For code that relies on traversing
5434
- * public $parent chains, skip functional ones and go to the parent instead.
5435
- */
5436
- const getPublicInstance = (i) => {
5437
- if (!i)
5438
- return null;
5439
- if (isStatefulComponent(i))
5440
- return getExposeProxy(i) || i.proxy;
5441
- return getPublicInstance(i.parent);
5442
- };
5443
- const publicPropertiesMap = shared.extend(Object.create(null), {
5444
- $: i => i,
5445
- $el: i => i.vnode.el,
5446
- $data: i => i.data,
5447
- $props: i => (i.props),
5448
- $attrs: i => (i.attrs),
5449
- $slots: i => (i.slots),
5450
- $refs: i => (i.refs),
5451
- $parent: i => getPublicInstance(i.parent),
5452
- $root: i => getPublicInstance(i.root),
5453
- $emit: i => i.emit,
5454
- $options: i => (resolveMergedOptions(i) ),
5455
- $forceUpdate: i => () => queueJob(i.update),
5456
- $nextTick: i => nextTick.bind(i.proxy),
5457
- $watch: i => (instanceWatch.bind(i) )
5458
- });
5459
- const PublicInstanceProxyHandlers = {
5460
- get({ _: instance }, key) {
5461
- const { ctx, setupState, data, props, accessCache, type, appContext } = instance;
5462
- // data / props / ctx
5463
- // This getter gets called for every property access on the render context
5464
- // during render and is a major hotspot. The most expensive part of this
5465
- // is the multiple hasOwn() calls. It's much faster to do a simple property
5466
- // access on a plain object, so we use an accessCache object (with null
5467
- // prototype) to memoize what access type a key corresponds to.
5468
- let normalizedProps;
5469
- if (key[0] !== '$') {
5470
- const n = accessCache[key];
5471
- if (n !== undefined) {
5472
- switch (n) {
5473
- case 1 /* SETUP */:
5474
- return setupState[key];
5475
- case 2 /* DATA */:
5476
- return data[key];
5477
- case 4 /* CONTEXT */:
5478
- return ctx[key];
5479
- case 3 /* PROPS */:
5480
- return props[key];
5481
- // default: just fallthrough
5482
- }
5483
- }
5484
- else if (setupState !== shared.EMPTY_OBJ && shared.hasOwn(setupState, key)) {
5485
- accessCache[key] = 1 /* SETUP */;
5486
- return setupState[key];
5487
- }
5488
- else if (data !== shared.EMPTY_OBJ && shared.hasOwn(data, key)) {
5489
- accessCache[key] = 2 /* DATA */;
5490
- return data[key];
5491
- }
5492
- else if (
5493
- // only cache other properties when instance has declared (thus stable)
5494
- // props
5495
- (normalizedProps = instance.propsOptions[0]) &&
5496
- shared.hasOwn(normalizedProps, key)) {
5497
- accessCache[key] = 3 /* PROPS */;
5498
- return props[key];
5499
- }
5500
- else if (ctx !== shared.EMPTY_OBJ && shared.hasOwn(ctx, key)) {
5501
- accessCache[key] = 4 /* CONTEXT */;
5502
- return ctx[key];
5503
- }
5504
- else if (shouldCacheAccess) {
5505
- accessCache[key] = 0 /* OTHER */;
5506
- }
5507
- }
5508
- const publicGetter = publicPropertiesMap[key];
5509
- let cssModule, globalProperties;
5510
- // public $xxx properties
5511
- if (publicGetter) {
5512
- if (key === '$attrs') {
5513
- reactivity.track(instance, "get" /* GET */, key);
5514
- }
5515
- return publicGetter(instance);
5516
- }
5517
- else if (
5518
- // css module (injected by vue-loader)
5519
- (cssModule = type.__cssModules) &&
5520
- (cssModule = cssModule[key])) {
5521
- return cssModule;
5522
- }
5523
- else if (ctx !== shared.EMPTY_OBJ && shared.hasOwn(ctx, key)) {
5524
- // user may set custom properties to `this` that start with `$`
5525
- accessCache[key] = 4 /* CONTEXT */;
5526
- return ctx[key];
5527
- }
5528
- else if (
5529
- // global properties
5530
- ((globalProperties = appContext.config.globalProperties),
5531
- shared.hasOwn(globalProperties, key))) {
5532
- {
5533
- return globalProperties[key];
5534
- }
5535
- }
5536
- else ;
5537
- },
5538
- set({ _: instance }, key, value) {
5539
- const { data, setupState, ctx } = instance;
5540
- if (setupState !== shared.EMPTY_OBJ && shared.hasOwn(setupState, key)) {
5541
- setupState[key] = value;
5542
- return true;
5543
- }
5544
- else if (data !== shared.EMPTY_OBJ && shared.hasOwn(data, key)) {
5545
- data[key] = value;
5546
- return true;
5547
- }
5548
- else if (shared.hasOwn(instance.props, key)) {
5549
- return false;
5550
- }
5551
- if (key[0] === '$' && key.slice(1) in instance) {
5552
- return false;
5553
- }
5554
- else {
5555
- {
5556
- ctx[key] = value;
5557
- }
5558
- }
5559
- return true;
5560
- },
5561
- has({ _: { data, setupState, accessCache, ctx, appContext, propsOptions } }, key) {
5562
- let normalizedProps;
5563
- return (!!accessCache[key] ||
5564
- (data !== shared.EMPTY_OBJ && shared.hasOwn(data, key)) ||
5565
- (setupState !== shared.EMPTY_OBJ && shared.hasOwn(setupState, key)) ||
5566
- ((normalizedProps = propsOptions[0]) && shared.hasOwn(normalizedProps, key)) ||
5567
- shared.hasOwn(ctx, key) ||
5568
- shared.hasOwn(publicPropertiesMap, key) ||
5569
- shared.hasOwn(appContext.config.globalProperties, key));
5570
- },
5571
- defineProperty(target, key, descriptor) {
5572
- if (descriptor.get != null) {
5573
- // invalidate key cache of a getter based property #5417
5574
- target.$.accessCache[key] = 0;
5575
- }
5576
- else if (shared.hasOwn(descriptor, 'value')) {
5577
- this.set(target, key, descriptor.value, null);
5578
- }
5579
- return Reflect.defineProperty(target, key, descriptor);
5580
- }
5581
- };
5582
- const RuntimeCompiledPublicInstanceProxyHandlers = /*#__PURE__*/ shared.extend({}, PublicInstanceProxyHandlers, {
5583
- get(target, key) {
5584
- // fast path for unscopables when using `with` block
5585
- if (key === Symbol.unscopables) {
5586
- return;
5587
- }
5588
- return PublicInstanceProxyHandlers.get(target, key, target);
5589
- },
5590
- has(_, key) {
5591
- const has = key[0] !== '_' && !shared.isGloballyWhitelisted(key);
5592
- return has;
5593
- }
5594
- });
5595
-
5596
5659
  const emptyAppContext = createAppContext();
5597
5660
  let uid$1 = 0;
5598
5661
  function createComponentInstance(vnode, parent, suspense) {
@@ -5619,7 +5682,7 @@ function createComponentInstance(vnode, parent, suspense) {
5619
5682
  provides: parent ? parent.provides : Object.create(appContext.provides),
5620
5683
  accessCache: null,
5621
5684
  renderCache: [],
5622
- // local resovled assets
5685
+ // local resolved assets
5623
5686
  components: null,
5624
5687
  directives: null,
5625
5688
  // resolved props and emits options
@@ -6085,7 +6148,7 @@ function isMemoSame(cached, memo) {
6085
6148
  return false;
6086
6149
  }
6087
6150
  for (let i = 0; i < prev.length; i++) {
6088
- if (prev[i] !== memo[i]) {
6151
+ if (shared.hasChanged(prev[i], memo[i])) {
6089
6152
  return false;
6090
6153
  }
6091
6154
  }
@@ -6097,7 +6160,7 @@ function isMemoSame(cached, memo) {
6097
6160
  }
6098
6161
 
6099
6162
  // Core API ------------------------------------------------------------------
6100
- const version = "3.2.32";
6163
+ const version = "3.2.34";
6101
6164
  const _ssrUtils = {
6102
6165
  createComponentInstance,
6103
6166
  setupComponent,