@vue/runtime-core 3.1.1 → 3.1.5

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.
@@ -120,6 +120,7 @@ function formatProp(key, value, raw) {
120
120
  }
121
121
 
122
122
  const ErrorTypeStrings = {
123
+ ["sp" /* SERVER_PREFETCH */]: 'serverPrefetch hook',
123
124
  ["bc" /* BEFORE_CREATE */]: 'beforeCreate hook',
124
125
  ["c" /* CREATED */]: 'created hook',
125
126
  ["bm" /* BEFORE_MOUNT */]: 'beforeMount hook',
@@ -827,9 +828,10 @@ const deprecationData = {
827
828
  message: (comp) => {
828
829
  const configMsg = `opt-in to ` +
829
830
  `Vue 3 behavior on a per-component basis with \`compatConfig: { ${"COMPONENT_V_MODEL" /* COMPONENT_V_MODEL */}: false }\`.`;
830
- if (comp.props && shared.isArray(comp.props)
831
- ? comp.props.includes('modelValue')
832
- : shared.hasOwn(comp.props, 'modelValue')) {
831
+ if (comp.props &&
832
+ (shared.isArray(comp.props)
833
+ ? comp.props.includes('modelValue')
834
+ : shared.hasOwn(comp.props, 'modelValue'))) {
833
835
  return (`Component delcares "modelValue" prop, which is Vue 3 usage, but ` +
834
836
  `is running under Vue 2 compat v-model behavior. You can ${configMsg}`);
835
837
  }
@@ -985,11 +987,12 @@ function emit(instance, event, ...rawArgs) {
985
987
  const onceHandler = props[handlerName + `Once`];
986
988
  if (onceHandler) {
987
989
  if (!instance.emitted) {
988
- (instance.emitted = {})[handlerName] = true;
990
+ instance.emitted = {};
989
991
  }
990
992
  else if (instance.emitted[handlerName]) {
991
993
  return;
992
994
  }
995
+ instance.emitted[handlerName] = true;
993
996
  callWithAsyncErrorHandling(onceHandler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args);
994
997
  }
995
998
  }
@@ -1460,6 +1463,12 @@ const SuspenseImpl = {
1460
1463
  // Force-casted public typing for h and TSX props inference
1461
1464
  const Suspense = (SuspenseImpl
1462
1465
  );
1466
+ function triggerEvent(vnode, name) {
1467
+ const eventListener = vnode.props && vnode.props[name];
1468
+ if (shared.isFunction(eventListener)) {
1469
+ eventListener();
1470
+ }
1471
+ }
1463
1472
  function mountSuspense(vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals) {
1464
1473
  const { p: patch, o: { createElement } } = rendererInternals;
1465
1474
  const hiddenContainer = createElement('div');
@@ -1469,6 +1478,9 @@ function mountSuspense(vnode, container, anchor, parentComponent, parentSuspense
1469
1478
  // now check if we have encountered any async deps
1470
1479
  if (suspense.deps > 0) {
1471
1480
  // has async
1481
+ // invoke @fallback event
1482
+ triggerEvent(vnode, 'onPending');
1483
+ triggerEvent(vnode, 'onFallback');
1472
1484
  // mount the fallback tree
1473
1485
  patch(null, vnode.ssFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
1474
1486
  isSVG, slotScopeIds);
@@ -1556,10 +1568,7 @@ function patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotSc
1556
1568
  else {
1557
1569
  // root node toggled
1558
1570
  // invoke @pending event
1559
- const onPending = n2.props && n2.props.onPending;
1560
- if (shared.isFunction(onPending)) {
1561
- onPending();
1562
- }
1571
+ triggerEvent(n2, 'onPending');
1563
1572
  // mount pending branch in off-dom container
1564
1573
  suspense.pendingBranch = newBranch;
1565
1574
  suspense.pendingId++;
@@ -1672,10 +1681,7 @@ function createSuspenseBoundary(vnode, parent, parentComponent, container, hidde
1672
1681
  }
1673
1682
  suspense.effects = [];
1674
1683
  // invoke @resolve event
1675
- const onResolve = vnode.props && vnode.props.onResolve;
1676
- if (shared.isFunction(onResolve)) {
1677
- onResolve();
1678
- }
1684
+ triggerEvent(vnode, 'onResolve');
1679
1685
  },
1680
1686
  fallback(fallbackVNode) {
1681
1687
  if (!suspense.pendingBranch) {
@@ -1683,10 +1689,7 @@ function createSuspenseBoundary(vnode, parent, parentComponent, container, hidde
1683
1689
  }
1684
1690
  const { vnode, activeBranch, parentComponent, container, isSVG } = suspense;
1685
1691
  // invoke @fallback event
1686
- const onFallback = vnode.props && vnode.props.onFallback;
1687
- if (shared.isFunction(onFallback)) {
1688
- onFallback();
1689
- }
1692
+ triggerEvent(vnode, 'onFallback');
1690
1693
  const anchor = next(activeBranch);
1691
1694
  const mountFallback = () => {
1692
1695
  if (!suspense.isInFallback) {
@@ -1701,11 +1704,11 @@ function createSuspenseBoundary(vnode, parent, parentComponent, container, hidde
1701
1704
  if (delayEnter) {
1702
1705
  activeBranch.transition.afterLeave = mountFallback;
1703
1706
  }
1707
+ suspense.isInFallback = true;
1704
1708
  // unmount current active branch
1705
1709
  unmount(activeBranch, parentComponent, null, // no suspense so unmount hooks fire now
1706
1710
  true // shouldRemove
1707
1711
  );
1708
- suspense.isInFallback = true;
1709
1712
  if (!delayEnter) {
1710
1713
  mountFallback();
1711
1714
  }
@@ -1900,7 +1903,7 @@ function inject(key, defaultValue, treatDefaultAsFactory = false) {
1900
1903
  }
1901
1904
  else if (arguments.length > 1) {
1902
1905
  return treatDefaultAsFactory && shared.isFunction(defaultValue)
1903
- ? defaultValue()
1906
+ ? defaultValue.call(instance.proxy)
1904
1907
  : defaultValue;
1905
1908
  }
1906
1909
  else {
@@ -2133,9 +2136,11 @@ function createPathGetter(ctx, path) {
2133
2136
  };
2134
2137
  }
2135
2138
  function traverse(value, seen = new Set()) {
2136
- if (!shared.isObject(value) ||
2137
- seen.has(value) ||
2138
- value["__v_skip" /* SKIP */]) {
2139
+ if (!shared.isObject(value) || value["__v_skip" /* SKIP */]) {
2140
+ return value;
2141
+ }
2142
+ seen = seen || new Set();
2143
+ if (seen.has(value)) {
2139
2144
  return value;
2140
2145
  }
2141
2146
  seen.add(value);
@@ -3133,13 +3138,16 @@ function applyOptions(instance) {
3133
3138
  registerLifecycleHook(onServerPrefetch, serverPrefetch);
3134
3139
  if (shared.isArray(expose)) {
3135
3140
  if (expose.length) {
3136
- const exposed = instance.exposed || (instance.exposed = reactivity.proxyRefs({}));
3141
+ const exposed = instance.exposed || (instance.exposed = {});
3137
3142
  expose.forEach(key => {
3138
- exposed[key] = reactivity.toRef(publicThis, key);
3143
+ Object.defineProperty(exposed, key, {
3144
+ get: () => publicThis[key],
3145
+ set: val => (publicThis[key] = val)
3146
+ });
3139
3147
  });
3140
3148
  }
3141
3149
  else if (!instance.exposed) {
3142
- instance.exposed = shared.EMPTY_OBJ;
3150
+ instance.exposed = {};
3143
3151
  }
3144
3152
  }
3145
3153
  // options that are handled when creating the instance but also need to be
@@ -3276,25 +3284,23 @@ const internalOptionMergeStrats = {
3276
3284
  methods: mergeObjectOptions,
3277
3285
  computed: mergeObjectOptions,
3278
3286
  // lifecycle
3279
- beforeCreate: mergeHook,
3280
- created: mergeHook,
3281
- beforeMount: mergeHook,
3282
- mounted: mergeHook,
3283
- beforeUpdate: mergeHook,
3284
- updated: mergeHook,
3285
- beforeDestroy: mergeHook,
3286
- destroyed: mergeHook,
3287
- activated: mergeHook,
3288
- deactivated: mergeHook,
3289
- errorCaptured: mergeHook,
3290
- serverPrefetch: mergeHook,
3287
+ beforeCreate: mergeAsArray,
3288
+ created: mergeAsArray,
3289
+ beforeMount: mergeAsArray,
3290
+ mounted: mergeAsArray,
3291
+ beforeUpdate: mergeAsArray,
3292
+ updated: mergeAsArray,
3293
+ beforeDestroy: mergeAsArray,
3294
+ destroyed: mergeAsArray,
3295
+ activated: mergeAsArray,
3296
+ deactivated: mergeAsArray,
3297
+ errorCaptured: mergeAsArray,
3298
+ serverPrefetch: mergeAsArray,
3291
3299
  // assets
3292
3300
  components: mergeObjectOptions,
3293
3301
  directives: mergeObjectOptions,
3294
- // watch has special merge behavior in v2, but isn't actually needed in v3.
3295
- // since we are only exposing these for compat and nobody should be relying
3296
- // on the watch-specific behavior, just expose the object merge strat.
3297
- watch: mergeObjectOptions,
3302
+ // watch
3303
+ watch: mergeWatchOptions,
3298
3304
  // provide / inject
3299
3305
  provide: mergeDataFn,
3300
3306
  inject: mergeInject
@@ -3323,11 +3329,22 @@ function normalizeInject(raw) {
3323
3329
  }
3324
3330
  return raw;
3325
3331
  }
3326
- function mergeHook(to, from) {
3332
+ function mergeAsArray(to, from) {
3327
3333
  return to ? [...new Set([].concat(to, from))] : from;
3328
3334
  }
3329
3335
  function mergeObjectOptions(to, from) {
3330
3336
  return to ? shared.extend(shared.extend(Object.create(null), to), from) : from;
3337
+ }
3338
+ function mergeWatchOptions(to, from) {
3339
+ if (!to)
3340
+ return from;
3341
+ if (!from)
3342
+ return to;
3343
+ const merged = shared.extend(Object.create(null), to);
3344
+ for (const key in from) {
3345
+ merged[key] = mergeAsArray(to[key], from[key]);
3346
+ }
3347
+ return merged;
3331
3348
  }
3332
3349
 
3333
3350
  function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison
@@ -3912,6 +3929,9 @@ function withDirectives(vnode, directives) {
3912
3929
  updated: dir
3913
3930
  };
3914
3931
  }
3932
+ if (dir.deep) {
3933
+ traverse(value);
3934
+ }
3915
3935
  bindings.push({
3916
3936
  dir,
3917
3937
  instance,
@@ -3984,6 +4004,7 @@ function createAppAPI(render, hydrate) {
3984
4004
  _props: rootProps,
3985
4005
  _container: null,
3986
4006
  _context: context,
4007
+ _instance: null,
3987
4008
  version,
3988
4009
  get config() {
3989
4010
  return context.config;
@@ -4071,6 +4092,7 @@ function createAppAPI(render, hydrate) {
4071
4092
  app._container = rootContainer;
4072
4093
  rootContainer.__vue_app__ = app;
4073
4094
  {
4095
+ app._instance = vnode.component;
4074
4096
  devtoolsInitApp(app, version);
4075
4097
  }
4076
4098
  return vnode.component.proxy;
@@ -4086,6 +4108,7 @@ function createAppAPI(render, hydrate) {
4086
4108
  if (isMounted) {
4087
4109
  render(null, app._container);
4088
4110
  {
4111
+ app._instance = null;
4089
4112
  devtoolsUnmountApp(app);
4090
4113
  }
4091
4114
  delete app._container.__vue_app__;
@@ -4122,8 +4145,9 @@ function createHydrationFunctions(rendererInternals) {
4122
4145
  const hydrate = (vnode, container) => {
4123
4146
  if (!container.hasChildNodes()) {
4124
4147
  warn(`Attempting to hydrate existing markup but container is empty. ` +
4125
- `Performing full mount instead.`);
4148
+ `Performing full mount instead.`);
4126
4149
  patch(null, vnode, container);
4150
+ flushPostFlushCbs();
4127
4151
  return;
4128
4152
  }
4129
4153
  hasMismatch = false;
@@ -4260,19 +4284,24 @@ function createHydrationFunctions(rendererInternals) {
4260
4284
  };
4261
4285
  const hydrateElement = (el, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
4262
4286
  optimized = optimized || !!vnode.dynamicChildren;
4263
- const { props, patchFlag, shapeFlag, dirs } = vnode;
4287
+ const { type, props, patchFlag, shapeFlag, dirs } = vnode;
4288
+ // #4006 for form elements with non-string v-model value bindings
4289
+ // e.g. <option :value="obj">, <input type="checkbox" :true-value="1">
4290
+ const forcePatchValue = (type === 'input' && dirs) || type === 'option';
4264
4291
  // skip props & children if this is hoisted static nodes
4265
- if (patchFlag !== -1 /* HOISTED */) {
4292
+ if (forcePatchValue || patchFlag !== -1 /* HOISTED */) {
4266
4293
  if (dirs) {
4267
4294
  invokeDirectiveHook(vnode, null, parentComponent, 'created');
4268
4295
  }
4269
4296
  // props
4270
4297
  if (props) {
4271
- if (!optimized ||
4298
+ if (forcePatchValue ||
4299
+ !optimized ||
4272
4300
  (patchFlag & 16 /* FULL_PROPS */ ||
4273
4301
  patchFlag & 32 /* HYDRATE_EVENTS */)) {
4274
4302
  for (const key in props) {
4275
- if (!shared.isReservedProp(key) && shared.isOn(key)) {
4303
+ if ((forcePatchValue && key.endsWith('value')) ||
4304
+ (shared.isOn(key) && !shared.isReservedProp(key))) {
4276
4305
  patchProp(el, key, null, props[key]);
4277
4306
  }
4278
4307
  }
@@ -4486,7 +4515,7 @@ const setRef = (rawRef, oldRawRef, parentSuspense, vnode, isUnmount = false) =>
4486
4515
  return;
4487
4516
  }
4488
4517
  const refValue = vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */
4489
- ? vnode.component.exposed || vnode.component.proxy
4518
+ ? getExposeProxy(vnode.component) || vnode.component.proxy
4490
4519
  : vnode.el;
4491
4520
  const value = isUnmount ? null : refValue;
4492
4521
  const { i: owner, r: ref } = rawRef;
@@ -4583,7 +4612,7 @@ function baseCreateRenderer(options, createHydrationFns) {
4583
4612
  const { insert: hostInsert, remove: hostRemove, patchProp: hostPatchProp, forcePatchProp: hostForcePatchProp, createElement: hostCreateElement, createText: hostCreateText, createComment: hostCreateComment, setText: hostSetText, setElementText: hostSetElementText, parentNode: hostParentNode, nextSibling: hostNextSibling, setScopeId: hostSetScopeId = shared.NOOP, cloneNode: hostCloneNode, insertStaticContent: hostInsertStaticContent } = options;
4584
4613
  // Note: functions inside this closure should use `const xxx = () => {}`
4585
4614
  // style in order to prevent being inlined by minifiers.
4586
- const patch = (n1, n2, container, anchor = null, parentComponent = null, parentSuspense = null, isSVG = false, slotScopeIds = null, optimized = false) => {
4615
+ const patch = (n1, n2, container, anchor = null, parentComponent = null, parentSuspense = null, isSVG = false, slotScopeIds = null, optimized = isHmrUpdating ? false : !!n2.dynamicChildren) => {
4587
4616
  // patching & not same type, unmount old tree
4588
4617
  if (n1 && !isSameVNodeType(n1, n2)) {
4589
4618
  anchor = getNextHostNode(n1);
@@ -4713,7 +4742,7 @@ function baseCreateRenderer(options, createHydrationFns) {
4713
4742
  hostSetElementText(el, vnode.children);
4714
4743
  }
4715
4744
  else if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
4716
- mountChildren(vnode.children, el, null, parentComponent, parentSuspense, isSVG && type !== 'foreignObject', slotScopeIds, optimized || !!vnode.dynamicChildren);
4745
+ mountChildren(vnode.children, el, null, parentComponent, parentSuspense, isSVG && type !== 'foreignObject', slotScopeIds, optimized);
4717
4746
  }
4718
4747
  if (dirs) {
4719
4748
  invokeDirectiveHook(vnode, null, parentComponent, 'created');
@@ -6288,7 +6317,6 @@ function _createVNode(type, props = null, children = null, patchFlag = 0, dynami
6288
6317
  anchor: null,
6289
6318
  target: null,
6290
6319
  targetAnchor: null,
6291
- staticCount: 0,
6292
6320
  shapeFlag,
6293
6321
  patchFlag,
6294
6322
  dynamicProps,
@@ -6665,7 +6693,7 @@ const getPublicInstance = (i) => {
6665
6693
  if (!i)
6666
6694
  return null;
6667
6695
  if (isStatefulComponent(i))
6668
- return i.exposed ? i.exposed : i.proxy;
6696
+ return getExposeProxy(i) || i.proxy;
6669
6697
  return getPublicInstance(i.parent);
6670
6698
  };
6671
6699
  const publicPropertiesMap = shared.extend(Object.create(null), {
@@ -6687,14 +6715,19 @@ const publicPropertiesMap = shared.extend(Object.create(null), {
6687
6715
  const PublicInstanceProxyHandlers = {
6688
6716
  get({ _: instance }, key) {
6689
6717
  const { ctx, setupState, data, props, accessCache, type, appContext } = instance;
6690
- // let @vue/reactivity know it should never observe Vue public instances.
6691
- if (key === "__v_skip" /* SKIP */) {
6692
- return true;
6693
- }
6694
6718
  // for internal formatters to know that this is a Vue instance
6695
6719
  if (key === '__isVue') {
6696
6720
  return true;
6697
6721
  }
6722
+ // prioritize <script setup> bindings during dev.
6723
+ // this allows even properties that start with _ or $ to be used - so that
6724
+ // it aligns with the production behavior where the render fn is inlined and
6725
+ // indeed has access to all declared variables.
6726
+ if (setupState !== shared.EMPTY_OBJ &&
6727
+ setupState.__isScriptSetup &&
6728
+ shared.hasOwn(setupState, key)) {
6729
+ return setupState[key];
6730
+ }
6698
6731
  // data / props / ctx
6699
6732
  // This getter gets called for every property access on the render context
6700
6733
  // during render and is a major hotspot. The most expensive part of this
@@ -6894,7 +6927,7 @@ function exposePropsOnRenderContext(instance) {
6894
6927
  function exposeSetupStateOnRenderContext(instance) {
6895
6928
  const { ctx, setupState } = instance;
6896
6929
  Object.keys(reactivity.toRaw(setupState)).forEach(key => {
6897
- if (key[0] === '$' || key[0] === '_') {
6930
+ if (!setupState.__isScriptSetup && (key[0] === '$' || key[0] === '_')) {
6898
6931
  warn(`setup() return property ${JSON.stringify(key)} should not start with "$" or "_" ` +
6899
6932
  `which are reserved prefixes for Vue internals.`);
6900
6933
  return;
@@ -6927,6 +6960,7 @@ function createComponentInstance(vnode, parent, suspense) {
6927
6960
  render: null,
6928
6961
  proxy: null,
6929
6962
  exposed: null,
6963
+ exposeProxy: null,
6930
6964
  withProxy: null,
6931
6965
  effects: null,
6932
6966
  provides: parent ? parent.provides : Object.create(appContext.provides),
@@ -7042,7 +7076,7 @@ function setupStatefulComponent(instance, isSSR) {
7042
7076
  instance.accessCache = Object.create(null);
7043
7077
  // 1. create public instance / render proxy
7044
7078
  // also mark it raw so it's never observed
7045
- instance.proxy = new Proxy(instance.ctx, PublicInstanceProxyHandlers);
7079
+ instance.proxy = reactivity.markRaw(new Proxy(instance.ctx, PublicInstanceProxyHandlers));
7046
7080
  {
7047
7081
  exposePropsOnRenderContext(instance);
7048
7082
  }
@@ -7057,6 +7091,10 @@ function setupStatefulComponent(instance, isSSR) {
7057
7091
  reactivity.resetTracking();
7058
7092
  currentInstance = null;
7059
7093
  if (shared.isPromise(setupResult)) {
7094
+ const unsetInstance = () => {
7095
+ currentInstance = null;
7096
+ };
7097
+ setupResult.then(unsetInstance, unsetInstance);
7060
7098
  if (isSSR) {
7061
7099
  // return the promise so server-renderer can wait on it
7062
7100
  return setupResult
@@ -7186,11 +7224,9 @@ function finishComponentSetup(instance, isSSR, skipOptions) {
7186
7224
  }
7187
7225
  }
7188
7226
  }
7189
- const attrHandlers = {
7227
+ const attrDevProxyHandlers = {
7190
7228
  get: (target, key) => {
7191
- {
7192
- markAttrsAccessed();
7193
- }
7229
+ markAttrsAccessed();
7194
7230
  return target[key];
7195
7231
  },
7196
7232
  set: () => {
@@ -7207,14 +7243,15 @@ function createSetupContext(instance) {
7207
7243
  if (instance.exposed) {
7208
7244
  warn(`expose() should be called only once per setup().`);
7209
7245
  }
7210
- instance.exposed = reactivity.proxyRefs(exposed);
7246
+ instance.exposed = exposed || {};
7211
7247
  };
7212
7248
  {
7249
+ let attrs;
7213
7250
  // We use getters in dev in case libs like test-utils overwrite instance
7214
7251
  // properties (overwrites should not be done in prod)
7215
7252
  return Object.freeze({
7216
7253
  get attrs() {
7217
- return new Proxy(instance.attrs, attrHandlers);
7254
+ return (attrs || (attrs = new Proxy(instance.attrs, attrDevProxyHandlers)));
7218
7255
  },
7219
7256
  get slots() {
7220
7257
  return reactivity.shallowReadonly(instance.slots);
@@ -7226,6 +7263,21 @@ function createSetupContext(instance) {
7226
7263
  });
7227
7264
  }
7228
7265
  }
7266
+ function getExposeProxy(instance) {
7267
+ if (instance.exposed) {
7268
+ return (instance.exposeProxy ||
7269
+ (instance.exposeProxy = new Proxy(reactivity.proxyRefs(reactivity.markRaw(instance.exposed)), {
7270
+ get(target, key) {
7271
+ if (key in target) {
7272
+ return target[key];
7273
+ }
7274
+ else if (key in publicPropertiesMap) {
7275
+ return publicPropertiesMap[key](instance);
7276
+ }
7277
+ }
7278
+ })));
7279
+ }
7280
+ }
7229
7281
  // record effects created during a component's setup() so that they can be
7230
7282
  // stopped when the component unmounts
7231
7283
  function recordInstanceBoundEffect(effect, instance = currentInstance) {
@@ -7274,30 +7326,152 @@ function computed(getterOrOptions) {
7274
7326
  return c;
7275
7327
  }
7276
7328
 
7329
+ Object.freeze({})
7330
+ ;
7331
+ Object.freeze([]) ;
7332
+ const isFunction = (val) => typeof val === 'function';
7333
+ const isObject = (val) => val !== null && typeof val === 'object';
7334
+ const isPromise = (val) => {
7335
+ return isObject(val) && isFunction(val.then) && isFunction(val.catch);
7336
+ };
7337
+
7338
+ // dev only
7339
+ const warnRuntimeUsage = (method) => warn(`${method}() is a compiler-hint helper that is only usable inside ` +
7340
+ `<script setup> of a single file component. Its arguments should be ` +
7341
+ `compiled away and passing it at runtime has no effect.`);
7277
7342
  // implementation
7278
7343
  function defineProps() {
7279
7344
  {
7280
- warn(`defineProps() is a compiler-hint helper that is only usable inside ` +
7281
- `<script setup> of a single file component. Its arguments should be ` +
7282
- `compiled away and passing it at runtime has no effect.`);
7345
+ warnRuntimeUsage(`defineProps`);
7283
7346
  }
7284
7347
  return null;
7285
7348
  }
7286
7349
  // implementation
7287
- function defineEmit() {
7350
+ function defineEmits() {
7288
7351
  {
7289
- warn(`defineEmit() is a compiler-hint helper that is only usable inside ` +
7290
- `<script setup> of a single file component. Its arguments should be ` +
7291
- `compiled away and passing it at runtime has no effect.`);
7352
+ warnRuntimeUsage(`defineEmits`);
7292
7353
  }
7293
7354
  return null;
7294
7355
  }
7356
+ /**
7357
+ * @deprecated use `defineEmits` instead.
7358
+ */
7359
+ const defineEmit = defineEmits;
7360
+ /**
7361
+ * Vue `<script setup>` compiler macro for declaring a component's exposed
7362
+ * instance properties when it is accessed by a parent component via template
7363
+ * refs.
7364
+ *
7365
+ * `<script setup>` components are closed by default - i.e. varaibles inside
7366
+ * the `<script setup>` scope is not exposed to parent unless explicitly exposed
7367
+ * via `defineExpose`.
7368
+ *
7369
+ * This is only usable inside `<script setup>`, is compiled away in the
7370
+ * output and should **not** be actually called at runtime.
7371
+ */
7372
+ function defineExpose(exposed) {
7373
+ {
7374
+ warnRuntimeUsage(`defineExpose`);
7375
+ }
7376
+ }
7377
+ /**
7378
+ * Vue `<script setup>` compiler macro for providing props default values when
7379
+ * using type-based `defineProps` decalration.
7380
+ *
7381
+ * Example usage:
7382
+ * ```ts
7383
+ * withDefaults(defineProps<{
7384
+ * size?: number
7385
+ * labels?: string[]
7386
+ * }>(), {
7387
+ * size: 3,
7388
+ * labels: () => ['default label']
7389
+ * })
7390
+ * ```
7391
+ *
7392
+ * This is only usable inside `<script setup>`, is compiled away in the output
7393
+ * and should **not** be actually called at runtime.
7394
+ */
7395
+ function withDefaults(props, defaults) {
7396
+ {
7397
+ warnRuntimeUsage(`withDefaults`);
7398
+ }
7399
+ return null;
7400
+ }
7401
+ /**
7402
+ * @deprecated use `useSlots` and `useAttrs` instead.
7403
+ */
7295
7404
  function useContext() {
7405
+ {
7406
+ warn(`\`useContext()\` has been deprecated and will be removed in the ` +
7407
+ `next minor release. Use \`useSlots()\` and \`useAttrs()\` instead.`);
7408
+ }
7409
+ return getContext();
7410
+ }
7411
+ function useSlots() {
7412
+ return getContext().slots;
7413
+ }
7414
+ function useAttrs() {
7415
+ return getContext().attrs;
7416
+ }
7417
+ function getContext() {
7296
7418
  const i = getCurrentInstance();
7297
7419
  if (!i) {
7298
7420
  warn(`useContext() called without active instance.`);
7299
7421
  }
7300
7422
  return i.setupContext || (i.setupContext = createSetupContext(i));
7423
+ }
7424
+ /**
7425
+ * Runtime helper for merging default declarations. Imported by compiled code
7426
+ * only.
7427
+ * @internal
7428
+ */
7429
+ function mergeDefaults(
7430
+ // the base props is compiler-generated and guaranteed to be in this shape.
7431
+ props, defaults) {
7432
+ for (const key in defaults) {
7433
+ const val = props[key];
7434
+ if (val) {
7435
+ val.default = defaults[key];
7436
+ }
7437
+ else if (val === null) {
7438
+ props[key] = { default: defaults[key] };
7439
+ }
7440
+ else {
7441
+ warn(`props default key "${key}" has no corresponding declaration.`);
7442
+ }
7443
+ }
7444
+ return props;
7445
+ }
7446
+ /**
7447
+ * `<script setup>` helper for persisting the current instance context over
7448
+ * async/await flows.
7449
+ *
7450
+ * `@vue/compiler-sfc` converts the following:
7451
+ *
7452
+ * ```ts
7453
+ * const x = await foo()
7454
+ * ```
7455
+ *
7456
+ * into:
7457
+ *
7458
+ * ```ts
7459
+ * let __temp, __restore
7460
+ * const x = (([__temp, __restore] = withAsyncContext(() => foo())),__temp=await __temp,__restore(),__temp)
7461
+ * ```
7462
+ * @internal
7463
+ */
7464
+ function withAsyncContext(getAwaitable) {
7465
+ const ctx = getCurrentInstance();
7466
+ let awaitable = getAwaitable();
7467
+ setCurrentInstance(null);
7468
+ if (isPromise(awaitable)) {
7469
+ awaitable = awaitable.catch(e => {
7470
+ setCurrentInstance(ctx);
7471
+ throw e;
7472
+ });
7473
+ }
7474
+ return [awaitable, () => setCurrentInstance(ctx)];
7301
7475
  }
7302
7476
 
7303
7477
  // Actual implementation
@@ -7530,7 +7704,7 @@ function initCustomFormatter() {
7530
7704
  }
7531
7705
 
7532
7706
  // Core API ------------------------------------------------------------------
7533
- const version = "3.1.1";
7707
+ const version = "3.1.5";
7534
7708
  const _ssrUtils = {
7535
7709
  createComponentInstance,
7536
7710
  setupComponent,
@@ -7599,6 +7773,8 @@ exports.createVNode = createVNode;
7599
7773
  exports.defineAsyncComponent = defineAsyncComponent;
7600
7774
  exports.defineComponent = defineComponent;
7601
7775
  exports.defineEmit = defineEmit;
7776
+ exports.defineEmits = defineEmits;
7777
+ exports.defineExpose = defineExpose;
7602
7778
  exports.defineProps = defineProps;
7603
7779
  exports.getCurrentInstance = getCurrentInstance;
7604
7780
  exports.getTransitionRawChildren = getTransitionRawChildren;
@@ -7608,6 +7784,7 @@ exports.initCustomFormatter = initCustomFormatter;
7608
7784
  exports.inject = inject;
7609
7785
  exports.isRuntimeOnly = isRuntimeOnly;
7610
7786
  exports.isVNode = isVNode;
7787
+ exports.mergeDefaults = mergeDefaults;
7611
7788
  exports.mergeProps = mergeProps;
7612
7789
  exports.nextTick = nextTick;
7613
7790
  exports.onActivated = onActivated;
@@ -7642,13 +7819,17 @@ exports.ssrContextKey = ssrContextKey;
7642
7819
  exports.ssrUtils = ssrUtils;
7643
7820
  exports.toHandlers = toHandlers;
7644
7821
  exports.transformVNodeArgs = transformVNodeArgs;
7822
+ exports.useAttrs = useAttrs;
7645
7823
  exports.useContext = useContext;
7646
7824
  exports.useSSRContext = useSSRContext;
7825
+ exports.useSlots = useSlots;
7647
7826
  exports.useTransitionState = useTransitionState;
7648
7827
  exports.version = version;
7649
7828
  exports.warn = warn;
7650
7829
  exports.watch = watch;
7651
7830
  exports.watchEffect = watchEffect;
7831
+ exports.withAsyncContext = withAsyncContext;
7652
7832
  exports.withCtx = withCtx;
7833
+ exports.withDefaults = withDefaults;
7653
7834
  exports.withDirectives = withDirectives;
7654
7835
  exports.withScopeId = withScopeId;