import { isPromise } from '../../shared/src' ; import { getCurrentInstance , setCurrentInstance , SetupContext , createSetupContext , unsetCurrentInstance } from './component' ; import { EmitFn , EmitsOptions } from './componentEmits' ; import { ComponentObjectPropsOptions , PropOptions , ExtractPropTypes } from './componentProps' ; import { warn } from './warning' ; const warnRuntimeUsage = ( method ) => warn ( `${ method }() is a compiler-hint helper that is only usable inside ` + `<script setup> of a single file component. Its arguments should be ` + `compiled away and passing it at runtime has no effect.` ) ; /**
 * Vue `<script setup>` compiler macro for declaring component props. The
 * expected argument is the same as the component `props` option.
 *
 * Example runtime declaration:
 * ```js
 * // using Array syntax
 * const props = defineProps(['foo', 'bar'])
 * // using Object syntax
 * const props = defineProps({
 *   foo: String,
 *   bar: {
 *     type: Number,
 *     required: true
 *   }
 * })
 * ```
 *
 * Equivalent type-based decalration:
 * ```ts
 * // will be compiled into equivalent runtime declarations
 * const props = defineProps<{
 *   foo?: string
 *   bar: number
 * }>()
 * ```
 *
 * This is only usable inside `<script setup>`, is compiled away in the
 * output and should **not** be actually called at runtime.
 */ export function defineProps < PropNames extends string = string > ( props ) ; export function defineProps < PP extends ComponentObjectPropsOptions = ComponentObjectPropsOptions > ( props ) ; export function defineProps < TypeProps > ( ) ; export function defineProps ( ) { if ( __DEV__ ) { warnRuntimeUsage ( `defineProps` ) ; } return null as any ; } /**
 * Vue `<script setup>` compiler macro for declaring a component's emitted
 * events. The expected argument is the same as the component `emits` option.
 *
 * Example runtime declaration:
 * ```js
 * const emit = defineEmits(['change', 'update'])
 * ```
 *
 * Example type-based decalration:
 * ```ts
 * const emit = defineEmits<{
 *   (event: 'change'): void
 *   (event: 'update', id: number): void
 * }>()
 *
 * emit('change')
 * emit('update', 1)
 * ```
 *
 * This is only usable inside `<script setup>`, is compiled away in the
 * output and should **not** be actually called at runtime.
 */ export function defineEmits < EE extends string = string > ( emitOptions ) ; export function defineEmits < E extends EmitsOptions = EmitsOptions > ( emitOptions ) ; export function defineEmits < TypeEmit > ( ) ; export function defineEmits ( ) { if ( __DEV__ ) { warnRuntimeUsage ( `defineEmits` ) ; } return null as any ; } /**
 * Vue `<script setup>` compiler macro for declaring a component's exposed
 * instance properties when it is accessed by a parent component via template
 * refs.
 *
 * `<script setup>` components are closed by default - i.e. varaibles inside
 * the `<script setup>` scope is not exposed to parent unless explicitly exposed
 * via `defineExpose`.
 *
 * This is only usable inside `<script setup>`, is compiled away in the
 * output and should **not** be actually called at runtime.
 */ export function defineExpose ( exposed ? ) { if ( __DEV__ ) { warnRuntimeUsage ( `defineExpose` ) ; } } type NotUndefined < T > = T extends undefined ? never : T ; type InferDefaults < T > = { [ K in keyof T ] ? : NotUndefined < T [ K ] > extends number | string | boolean | symbol | Function ? NotUndefined < T [ K ] > : ( props : T ) => NotUndefined < T [ K ] > ; } ; type PropsWithDefaults < Base , Defaults > = Base & { [ K in keyof Defaults ] : K extends keyof Base ? NotUndefined < Base [ K ] > : never ; } ; /**
 * Vue `<script setup>` compiler macro for providing props default values when
 * using type-based `defineProps` decalration.
 *
 * Example usage:
 * ```ts
 * withDefaults(defineProps<{
 *   size?: number
 *   labels?: string[]
 * }>(), {
 *   size: 3,
 *   labels: () => ['default label']
 * })
 * ```
 *
 * This is only usable inside `<script setup>`, is compiled away in the output
 * and should **not** be actually called at runtime.
 */ export function withDefaults < Props , Defaults extends InferDefaults < Props > > ( props , defaults ) { if ( __DEV__ ) { warnRuntimeUsage ( `withDefaults` ) ; } return null as any ; } export function useSlots ( ) { return getContext ( ) . slots ; } export function useAttrs ( ) { return getContext ( ) . attrs ; } function getContext ( ) { const i = getCurrentInstance ( ) ! ; if ( __DEV__ && ! i ) { warn ( `useContext() called without active instance.` ) ; } return i . setupContext || ( i . setupContext = createSetupContext ( i ) ) ; } internal export function mergeDefaults ( props , defaults ) { for ( const key in defaults ) { const val = props [ key ] ; if ( val ) { val . default = defaults [ key ] ; } else if ( val === null ) { props [ key ] = { default : defaults [ key ] } ; } else if ( __DEV__ ) { warn ( `props default key "${ key }" has no corresponding declaration.` ) ; } } return props ; } internal export function withAsyncContext ( getAwaitable ) { const ctx = getCurrentInstance ( ) ! ; if ( __DEV__ && ! ctx ) { warn ( `withAsyncContext called without active current instance. ` + `This is likely a bug.` ) ; } let awaitable = getAwaitable ( ) ; unsetCurrentInstance ( ) ; if ( isPromise ( awaitable ) ) { awaitable = awaitable . catch ( e => { setCurrentInstance ( ctx ) ; throw e ; } ) ; } return [ awaitable , ( ) => setCurrentInstance ( ctx ) ] ; }