text stringlengths 14 100k | source stringclasses 1
value | repo stringclasses 810
values | language stringclasses 13
values |
|---|---|---|---|
<|fim_prefix|>import { getCompiledString } from './utils'
import { compile } from '../src'
describe('ssr: element', () => {
test('basic elements', () => {
expect(getCompiledString(`<div></div>`)).toMatchInlineSnapshot(
`"\`<div></div>\`"`,
)
expect(getCompiledString(`<div/>`)).toMatchInlineSnapshot... | fim | vuejs/core | typescript |
<|fim_prefix|>import { compile } from '../src'
describe('ssr: attrs fallthrough', () => {
test('basic', () => {
expect(compile(`<div/>`).code).toMatchInlineSnapshot(`
"const { ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-renderer")
return function ssrRender(_ctx, _push, _parent, _attrs) {... | fim | vuejs/core | typescript |
<|fim_suffix|> </template>
</Suspense>`,
{
ssrCssVars: `{ color }`,
},
).code,
).toMatchInlineSnapshot(`
"const { withCtx: _withCtx } = require("vue")
const { ssrRenderAttrs: _ssrRenderAttrs, ssrRenderSuspense: _ssrRenderSuspense } = require("vue/server-renderer... | fim | vuejs/core | typescript |
<|fim_prefix|>import { compile } from '../src'
describe('ssr compile: teleport', () =<|fim_suffix|>)
}"
`)
})
})
<|fim_middle|>> {
test('should work', () => {
expect(compile(`<teleport :to="target"><div/></teleport>`).code)
.toMatchInlineSnapshot(`
"const { ssrRenderTeleport: _ssrRender... | fim | vuejs/core | typescript |
import { compile } from '../src'
const scopeId = 'data-v-xxxxxxx'
describe('ssr: scopeId', () => {
test('basic', () => {
expect(
compile(`<div><span>hello</span></div>`, {
scopeId,
mode: 'module',
}).code,
).toMatchInlineSnapshot(`
"import { ssrRenderAttrs as _ssrRenderAttr... | fim | vuejs/core | typescript |
<|fim_prefix|>import { compile } from '../src'
import { SSR_RENDER_SLOT_INNER, ssrHelpers } from '../src/runtimeHelpers'
describe('ssr: <slot>', () => {
test('basic', () => {
expect(compile(`<slot/>`).code).toMatchInlineSnapshot(`
"const { ssrRenderSlot: _ssrRenderSlot } = require("vue/server-renderer")
... | fim | vuejs/core | typescript |
<|fim_suffix|> loading...
</template>
</suspense>`).code,
).toMatchInlineSnapshot(`
"const { resolveComponent: _resolveComponent, withCtx: _withCtx } = require("vue")
const { ssrRenderComponent: _ssrRenderComponent, ssrRenderSuspense: _ssrRenderSuspense } = require("vue/server-renderer")
... | fim | vuejs/core | typescript |
<|fim_suffix|>>`)
.code,
).toMatchInlineSnapshot(`
"const { ssrRenderAttrs: _ssrRenderAttrs, ssrInterpolate: _ssrInterpolate } = require("vue/server-renderer")
return function ssrRender(_ctx, _push, _parent, _attrs) {
_push(\`<div\${
_ssrRenderAttrs(_attrs)
}><span>\${... | fim | vuejs/core | typescript |
<|fim_suffix|>`)
}"
`)
})
})
<|fim_prefix|>import { compile } from '../src'
describe('transition', () => {
test('basic', () => {
expect(compile(`<transition><div>foo</div></transition>`).code)
.toMatchInlineSnapshot(`
"const { ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-... | fim | vuejs/core | typescript |
import { compile } from '../src'
// transition-group should flatten and concat its children fragments into
// a single one
describe('transition-group', () => {
test('basic', () => {
expect(
compile(`<transition-group><div v-for="i in list"/></transition-group>`)
.code,
).toMatchInlineSnapshot(`... | fim | vuejs/core | typescript |
<|fim_prefix|>import { compile } from '../src'
describe('ssr: v-for', () => {
test('basic', () => {
expect(compile(`<div v-for="i in list" />`).code).toMatchInlineSnapshot(`
"const { ssrRenderList: _ssrRenderList } = require("vue/server-renderer")
return function ssrRender(_ctx, _push, _parent, _att... | fim | vuejs/core | typescript |
<|fim_prefix|>import { compile } from '../src'
describe('ssr: v-if', () => {
test('basic', () => {
expect(compile(`<div v-if="foo"></div>`).code).toMatchInlineSnapshot(`
"const { ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-renderer")
return function ssrRender(_ctx, _push, _parent, _attrs... | fim | vuejs/core | typescript |
<|fim_prefix|>import { compile } from '../src'
function compileWithWrapper(src: string) {
return compile(`<div>${src}</div>`)
}
describe('ssr: v-model', () => {
test('<input> (text types)', () => {
expect(compileWithWrapper(`<input v-model="bar">`).code)
.toMatchInlineSnapshot(`
"const { ssrRend... | fim | vuejs/core | typescript |
import { compile } from '../src'
function compileWithWrapper(src: string) {
return compile(`<div>${src}</div>`)
}
describe('ssr: v-show', () => {
test('basic as root', () => {
expect(compile(`<div v-show="foo"/>`).code).toMatchInlineSnapshot(`
"const { mergeProps: _mergeProps } = require("vue")
co... | fim | vuejs/core | typescript |
<|fim_suffix|>llthrough attr. This results in less noise in generated snapshots
// but also means this util can only be used for non-root cases.
const { code } = compile(`<div>${src}</div>`)
const match = code.match(
/_push\(\`<div\${\s*_ssrRenderAttrs\(_attrs\)\s*}>([^]*)<\/div>\`\)/,
)
if (!match) {
... | fim | vuejs/core | typescript |
<|fim_suffix|>ND_POINT__
} to match extension point from core DOMErrorCodes.`,
)
}
}
export const SSRErrorMessages: { [code: number]: string } = {
[SSRErrorCodes.X_SSR_UNSAFE_ATTR_NAME]: `Unsafe attribute name for SSR.`,
[SSRErrorCodes.X_SSR_NO_TELEPORT_TARGET]: `Missing the 'to' prop on teleport eleme... | fim | vuejs/core | typescript |
import {
type CodegenResult,
type CompilerOptions,
type RootNode,
baseParse,
generate,
noopDirectiveTransform,
parserOptions,
trackSlotScopes,
trackVForSlotScopes,
transform,
transformBind,
transformExpression,
transformOn,
transformStyle,
transformVBindShorthand,
} from '@vue/compiler-dom... | fim | vuejs/core | typescript |
<|fim_prefix|>import { registerRuntimeHelpers } from '@vue/compile<|fim_suffix|>t const SSR_RENDER_SLOT_INNER: unique symbol = Symbol(`ssrRenderSlotInner`)
export const SSR_RENDER_CLASS: unique symbol = Symbol(`ssrRenderClass`)
export const SSR_RENDER_STYLE: unique symbol = Symbol(`ssrRenderStyle`)
export const SSR_REN... | fim | vuejs/core | typescript |
<|fim_prefix|>import {
type BlockStatement,
type CallExpression,
type CompilerError,
type CompilerOptions,
ElementTypes,
type IfStatement,
type JSChildNode,
NodeTypes,
type RootNode,
type TemplateChildNode,
type TemplateLiteral,
createBlockStatement,
createCallExpression,
createCompoundExpre... | fim | vuejs/core | typescript |
<|fim_prefix|>import {
ElementTypes,
type NodeTransform,
NodeTypes,
type RootNode,
type TemplateChildNode,
createSimpleExpression,
findDir,
locStub,
} from '@vue/compiler-dom'
export const ssrInjectCssVars: NodeTransform = (node, context) => {
if (!context.ssrCssVars) {
return
}
// _cssVars ... | fim | vuejs/core | typescript |
<|fim_prefix|>import {
ElementTypes,
type NodeTransform,
NodeTypes,
type ParentNode,
type RootNode,
type TemplateChildNode,
createSimpleExpression,
findDir,
isCommentOrWhitespace,
locStub,
} from '@vue/compiler-dom'
const filterChild = (node: ParentNode) =>
node.children.filter(n => !isCommentOrW... | fim | vuejs/core | typescript |
import {
CREATE_VNODE,
type CallExpression,
type CompilerOptions,
type ComponentNode,
DOMDirectiveTransforms,
DOMNodeTransforms,
type DirectiveNode,
ElementTypes,
type ExpressionNode,
type FunctionExpression,
type JSChildNode,
Namespaces,
type NodeTransform,
NodeTypes,
RESOLVE_DYNAMIC_COMP... | fim | vuejs/core | typescript |
<|fim_suffix|>.type === NodeTypes.DIRECTIVE) {
return (
prop.name === 'bind' &&
prop.arg &&
isStaticExp(prop.arg) &&
(prop.arg.content === 'true-value' || prop.arg.content === 'false-value')
)
} else {
return prop.name === 'true-value' || prop.name === 'false-value'
}
}
function... | fim | vuejs/core | typescript |
<|fim_prefix|>import {
ElementTypes,
type NodeTransform,
NodeTypes,
type SlotOutletNode,
TRANSITION,
TRANSITION_GROUP,
createCallExpression,
createFunctionExpression,
isSlotOutlet,
processSlotOutlet,
resolveComponentType,
} from '@vue/compiler-dom'
import { SSR_RENDER_SLOT, SSR_RENDER_SLOT_INNER }... | fim | vuejs/core | typescript |
<|fim_suffix|>= 0; i < wipSlots.length; i++) {
const slot = wipSlots[i]
slot.fn.body = processChildrenAsStatement(slot, context)
}
// _push(ssrRenderSuspense(slots))
context.pushStatement(
createCallExpression(context.helper(SSR_RENDER_SUSPENSE), [
`_push`,
slotsExp,
]),
)
}
<|fim_pr... | fim | vuejs/core | typescript |
import {
type ComponentNode,
type ExpressionNode,
NodeTypes,
createCallExpression,
createFunctionExpression,
createSimpleExpression,
findProp,
} from '@vue/compiler-dom'
import {
type SSRTransformContext,
processChildrenAsStatement,
} from '../ssrCodegenTransform'
import { SSRErrorCodes, createSSRComp... | fim | vuejs/core | typescript |
<|fim_prefix|>import {
type ComponentNode,
NodeTypes,
type TransformContext,
findProp,
} from '@vue/compiler-dom'
import {
type SSRTransformContext,
processChildren,
} from '../ssrCodegenTransform'
const wipMap = new WeakMap<ComponentNode, Boolean>()
export function ssrTransformTransition(
node: Compone... | fim | vuejs/core | typescript |
<|fim_prefix|>import {
type AttributeNode,
type ComponentNode,
type DirectiveNode,
type JSChildNode,
NodeTypes,
type TransformContext,
buildProps,
createCallExpression,
findProp,
} from '@vue/compiler-dom'
import { SSR_RENDER_ATTRS } from '../runtimeHelpers'
import {
type SSRTransformContext,
proc... | fim | vuejs/core | typescript |
<|fim_prefix|>import {
type ForNode,
type NodeTransform,
NodeTypes,
createCallExpression,
createForLoopParams,
createFunctionExpression,
createStructuralDirectiveTransform,
processFor,
} from '@vue/compiler-dom'
import {
type SSRTransformContext,
processChildrenAsSt<|fim_suffix|>For)
// This is cal... | fim | vuejs/core | typescript |
<|fim_prefix|>import {
type BlockStatement,
type IfBranchNode,
type IfNode,
type NodeTransform,
NodeTypes,
createBlockStatement,
createCallExpression,
createIfStatement,
createStructuralDirectiveTransform,
processIf,
} from '@vue/compiler-dom'
import {
type SSRTransfor<|fim_suffix|>FOR)
return p... | fim | vuejs/core | typescript |
<|fim_suffix|>pe
res.ssrTagParts = [
createCallExpression(context.helper(SSR_RENDER_DYNAMIC_MODEL), [
type.exp!,
model,
value,
]),
]
} else if (type.value) {
// static type
switch (type.value.content) {
... | fim | vuejs/core | typescript |
<|fim_suffix|>ession(`none`, true),
),
]),
false /* no newline */,
),
),
],
}
}
<|fim_prefix|>import {
DOMErrorCodes,
type DirectiveTransform,
createConditionalExpression,
createDOMCompilerError,
createObjectExpression,
createObjectProperty,
createSimple... | fim | vuejs/core | typescript |
<|fim_prefix|>// Global compile-time constants
declare var __DEV__: boolean
declare var __TEST__: boolean
declare var __BROWSER__: boolean
declare var __GLOBAL__: boolean
declare var __ESM_BUNDLER__: boolean
declare var __ESM_BROWSER__: boolean
declare var __CJS__: boolean
declare var __SSR__: boolean
declare var __VER... | fim | vuejs/core | typescript |
<|fim_prefix|>import { bench, describe } from 'vitest'
import type { ComputedRef, Ref } from '../src'
import { computed, effect, ref } from '../dist/reactivity.esm-browser.prod'
declare module '../dist/reactivity.esm-browser.prod' {
function computed(...args: any[]): any
}
describe('computed', () => {
bench('crea... | fim | vuejs/core | typescript |
<|fim_prefix|>import { bench, describe } from 'vitest'
import type { Ref } from '../src'
import { effect, ref } from '../dist/reactivity.esm-browser.prod'
describe('effect', (<|fim_suffix|>]
for (let i = 0; i < size; i++) {
refs.push(ref(i))
}
effect(() => {
for (let i = 0; i < size; ... | fim | vuejs/core | typescript |
<|fim_suffix|>nts`, () => {
let sum = 0
effect(() => {
for (let x of arr) {
sum += x
}
})
})
}
{
const rawArray: number[] = []
for (let i = 0, n = amount; i < n; i++) {
rawArray.push(i)
}
const arr = reactive(rawArray)
bench(`track forEach,... | fim | vuejs/core | typescript |
<|fim_suffix|>Ref<number>[] = []
for (let i = 0, n = 1000; i < n; i++) {
const c = computed(() => {
return r.get('a') * 2
})
computeds.push(c)
}
let i = 0
bench('write reactive map, read 1000 computeds', () => {
r.set('a', i++)
computeds.forEach(c => c.value)
})
}
{
const reactive... | fim | vuejs/core | typescript |
<|fim_prefix|>import { bench } from 'vitest'
import { reactive } from '../dist/reactivity.esm-browser.prod'
bench('create reactive obj', () => {
reactive({ a: 1 })
})
{
const raw = { a: 1 }
reactive(raw)
bench('return cached reactive obj', () => {
reactive(raw)
})
}
{
const r = rea<|fim_suffix|>read ... | fim | vuejs/core | typescript |
<|fim_suffix|> const v = ref(100)
bench('write/read ref', () => {
v.value = i++
v.value
})
}
})
<|fim_prefix|>import { bench, describe } from 'vitest'
import { ref } from '../dist/reactivity.esm-browser.prod'
describe('ref', () => {
bench<|fim_middle|>('create ref', () => {
ref(100)
})
... | fim | vuejs/core | typescript |
<|fim_suffix|>nst key = reactive(rawKey)
raw.set(rawKey, 1)
raw.set(key, 1)
const map = reactive(raw)
map.set(key, 2)
expect(
`Reactive Map contains both the raw and reactive`,
).toHaveBeenWarned()
})
// #877
it('should not trigger key iteration when setting exis... | fim | vuejs/core | typescript |
<|fim_prefix|>import {
effect,
isReactive,
reactive,
readonly,
shallowReactive,
toRaw,
} from '../../src'
describe('reactivity/collections', () => {
function coverCollectionFn(collection: Set<any>, fnName: string) {
const spy = vi.fn()
let proxy = reactive(collection)
;(collection as any)[fnN... | fim | vuejs/core | typescript |
<|fim_prefix|>import { effect, isReactive, reactive, toRaw } from '../../src'
describe('reactivity/collections', () => {
describe('WeakMap', () => {
test('instanceof', () => {
const original = new WeakMap()
const observed = reactive(original)
expect(isReactive(observed)).toBe(true)
expect... | fim | vuejs/core | typescript |
<|fim_prefix|>import { effect, isReactive, reactive, toRaw } from '../../src'
describe('reactivity/collections', () => {
describe('WeakSet', () => {
it('instanceof', () => {
const original = new WeakSet()
const observed = reactive(original)
expect(isReactive(observed)).toBe(true)
expect(o... | fim | vuejs/core | typescript |
<|fim_suffix|>ct(
`Set operation on key "foo" failed: target is readonly.`,
).not.toHaveBeenWarned()
})
})
})
})
<|fim_prefix|>import { isReactive, isReadonly, shallowReadonly } from '../../src'
describe('reactivity/collections', () => {
describe('shallowReadonly/Map', () => {
;[Map... | fim | vuejs/core | typescript |
<|fim_suffix|>)
test('should not trigger if value did not change', () => {
const src = ref(0)
const c = computed(() => src.value % 2)
const spy = vi.fn()
effect(() => {
spy(c.value)
})
expect(spy).toHaveBeenCalledTimes(1)
src.value = 2
// should not trigger
expect(spy).toHa... | fim | vuejs/core | typescript |
<|fim_prefix|>import {
type DebuggerEvent,
type ReactiveEffectRunner,
TrackOpTypes,
TriggerOpTypes,
effect,
markRaw,
reactive,
readonly,
shallowReactive,
stop,
toRaw,
} from '../src/index'
import { type Dep, ITERATE_KEY, getDepFromReactive } from '../src/dep'
import {
computed,
h,
nextTick,
... | fim | vuejs/core | typescript |
<|fim_prefix|>import { nextTick, watch, watchEffect } from '@vue/runtime-core'
import {
type ComputedRef,
EffectScope,
computed,
effect,
effectScope,
getCurrentScope,
onScopeDispose,
reactive,
ref,
} from '../src'
describe('reactivity/effect/scope', () => {
it('should run', () => {
const fnSpy ... | fim | vuejs/core | typescript |
<|fim_suffix|>lue)
c.value // cache src value
src.value = undefined // release value
c = undefined // release computed
await gc()
expect(srcRef.deref()).toBeUndefined()
})
it('should release reactive property dep', async () => {
const src = reactive({ foo: 1 })
let c: ComputedRef | u... | fim | vuejs/core | typescript |
<|fim_suffix|>},
bar: markRaw({ b: 2 }),
})
expect(isReactive(obj.foo)).toBe(true)
expect(isReactive(obj.bar)).toBe(false)
})
test('markRaw should skip non-extensible objects', () => {
const obj = Object.seal({ foo: 1 })
expect(() => markRaw(obj)).not.toThrowError()
})
test('markRaw ... | fim | vuejs/core | typescript |
<|fim_prefix|>import { type ComputedRef, computed } from '../src/computed'
import { isReactive, reactive, shallowReactive, toRaw } from '../src/reactive'
import { isRef, ref } from '../src/ref'
import { effect } from '../src/effect'
describe('reactivity/reactive/Array', () => {
test('should make Array reactive', () ... | fim | vuejs/core | typescript |
<|fim_suffix|> roItem = roMap.get(key)
expect(isReactive(roItem)).toBe(true)
expect(isReadonly(roItem)).toBe(true)
})
if (Collection === Map) {
test('should retrieve readonly values on iteration', () => {
const key1 = {}
const key2 = {}
const original =... | fim | vuejs/core | typescript |
import {
type Ref,
effect,
isReactive,
isRef,
reactive,
ref,
toRef,
toRefs,
toValue,
} from '../src/index'
import { computed } from '@vue/runtime-dom'
import { customRef, shallowRef, triggerRef, unref } from '../src/ref'
import {
isReadonly,
isShallow,
readonly,
shallowReactive,
shallowReado... | fim | vuejs/core | typescript |
import {
isReactive,
isShallow,
reactive,
shallowReactive,
shallowReadonly,
} from '../src/reactive'
import { effect } from '../src/effect'
import { type Ref, isRef, ref } from '../src/ref'
describe('shallowReactive', () => {
test('should not make non-reactive properties reactive', () => {
const props... | fim | vuejs/core | typescript |
<|fim_suffix|>enWarned()
})
})
test('should not make nested values readonly', () => {
const obj = { foo: 1 }
const original = new Set([obj])
const sroSet = shallowReadonly(original)
const values = [...sroSet.values()]
expect(values[0]).toBe(obj)
expect(isReadonly(val... | fim | vuejs/core | typescript |
<|fim_suffix|>n with error handling', () => {
const onError = vi.fn()
const call: WatchOptions['call'] = function call(fn, type, args) {
if (Array.isArray(fn)) {
fn.forEach(f => call(f, type, args))
return
}
try {
fn.apply(null, args)
} catch (e) {
onError... | fim | vuejs/core | typescript |
<|fim_suffix|>od.js')
} else {
module.exports = require('./dist/reactivity.cjs.js')
}
<|fim_prefix|>'us<|fim_middle|>e strict'
if (process.env.NODE_ENV === 'production') {
module.exports = require('./dist/reactivity.cjs.pr<|endoftext|> | fim | vuejs/core | javascript |
<|fim_suffix|>},
shift() {
return noTracking(this, 'shift')
},
// slice could use ARRAY_ITERATE but also seems to beg for range tracking
some(
fn: (item: unknown, index: number, array: unknown[]) => unknown,
thisArg?: unknown,
) {
return apply(this, 'some', fn, thisArg, undefined, arguments... | fim | vuejs/core | typescript |
<|fim_suffix|>l
if (target === toRaw(receiver)) {
if (!hadKey) {
trigger(target, TriggerOpTypes.ADD, key, value)
} else if (hasChanged(value, oldValue)) {
trigger(target, TriggerOpTypes.SET, key, value, oldValue)
}
}
return result
}
deleteProperty(
target: Record<s... | fim | vuejs/core | typescript |
import {
type Target,
isReadonly,
isShallow,
toRaw,
toReactive,
toReadonly,
} from './reactive'
import { ITERATE_KEY, MAP_KEY_ITERATE_KEY, track, trigger } from './dep'
import { ReactiveFlags, TrackOpTypes, TriggerOpTypes } from './constants'
import {
capitalize,
extend,
hasChanged,
hasOwn,
isMap,... | fim | vuejs/core | typescript |
<|fim_suffix|>ned value from the getter. It can also take an object with get and set
* functions to create a writable ref object.
*
* @example
* ```js
* // Creating a readonly computed ref:
* const count = ref(1)
* const plusOne = computed(() => count.value + 1)
*
* console.log(plusOne.value) // 2
* plusOne.v... | fim | vuejs/core | typescript |
<|fim_prefix|>// using literal strings instead of numbers so that it's easier to inspect
// debugger events
export enum TrackOpTypes {
GET = 'get',
HAS = 'has',
ITERATE = 'iterate',
}
export enum TriggerOpTypes {
SET = 'set',
ADD = 'add',
DELETE = 'delete',
CLEAR = 'clear',
}
export enum R<|fim_suffix|... | fim | vuejs/core | typescript |
<|fim_prefix|>import { extend, isArray, isIntegerKey, isMap, isSymbol } from '@vue/shared'
import type { ComputedRefImpl } from './computed'
import { type TrackOpTypes, TriggerOpTypes } from './constants'
import {
type DebuggerEventExtraInfo,
EffectFlags,
type Subscriber,
activeSub,
endBatch,
shouldTrack,
... | fim | vuejs/core | typescript |
<|fim_prefix|>import { extend, hasChanged } from '@vue/shared'
import type { ComputedRefImpl } from './computed'
import type { TrackOpTypes, TriggerOpTypes } from './constants'
import { type Link, globalVersion } from './dep'
import { activeEffectScope } from './effectScope'
import { warn } from './warning'
export typ... | fim | vuejs/core | typescript |
<|fim_prefix|>import type { ReactiveEffect } from './effect'
import { warn } from './warning'
export let activeEffectScope: EffectScope | undefined
export class EffectScope {
/**
* @internal
*/
private _active = true
/**
* @internal track `on` calls, allow `on` call multiple times
*/
private _on =... | fim | vuejs/core | typescript |
<|fim_prefix|>export {
ref,
shallowRef,
isRef,
toRef,
toValue,
toRefs,
unref,
proxyRefs,
customRef,
triggerRef,
type Ref,
type MaybeRef,
type MaybeRefOrGetter,
type ToRef,
type ToRefs,
type UnwrapRef,
type ShallowRef,
type ShallowUnwrapRef,
type RefUnwrapBailTypes,
type CustomRef... | fim | vuejs/core | typescript |
<|fim_suffix|>proxy is deep: any nested property accessed will be readonly as
* well. It also has the same ref-unwrapping behavior as {@link reactive},
* except the unwrapped values will also be made readonly.
*
* @example
* ```js
* const original = reactive({ count: 0 })
*
* const copy = readonly(original)
*
... | fim | vuejs/core | typescript |
<|fim_suffix|>ect[this._key] = newVal
}
get dep(): Dep | undefined {
return getDepFromReactive(this._raw, this._key)
}
}
class GetterRefImpl<T> {
public readonly [ReactiveFlags.IS_REF] = true
public readonly [ReactiveFlags.IS_READONLY] = true
public _value: T = undefined!
constructor(private readon... | fim | vuejs/core | typescript |
<|fim_prefix|>export function warn(msg: string, ...args: any[]): void<|fim_suffix|>rn(`[Vue warn] ${msg}`, ...args)
}
<|fim_middle|> {
console.wa<|endoftext|> | fim | vuejs/core | typescript |
<|fim_suffix|>rgs = [
newValue,
// pass undefined as the old value when it's changed for the first time
oldValue === INITIAL_WATCHER_VALUE
? undefined
: isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE
? []
: oldValue,... | fim | vuejs/core | typescript |
<|fim_prefix|>import {
type Component,
KeepAlive,
Suspense,
defineAsyncComponent,
h,
nextTick,
ref,
} from '../src'
import { createApp, nodeOps, serializeInner } from '@vue/runtime-test'
import { onActivated } from '../src/components/KeepAlive'
const timeout = (n: number = 0) => new Promise(r => setTimeo... | fim | vuejs/core | typescript |
import {
type Plugin,
createApp,
defineComponent,
getCurrentInstance,
h,
inject,
nextTick,
nodeOps,
onMounted,
provide,
ref,
resolveComponent,
resolveDirective,
serializeInner,
watch,
withDirectives,
} from '@vue/runtime-test'
describe('api: createApp', () => {
test('mount', () => {
... | fim | vuejs/core | typescript |
<|fim_suffix|>defineComponent({
setup(_, { expose }) {
expose(['focus'])
return () => null
},
})
render(h(Comp), nodeOps.createElement('div'))
expect(
'expose() should be passed a plain object, received array',
).toHaveBeenWarned()
})
test('warning for function', (... | fim | vuejs/core | typescript |
<|fim_prefix|>import {
type InjectionKey,
type Ref,
defineComponent,
h,
hasInjectionContext,
inject,
nextTick,
onMounted,
provide,
reactive,
readonly,
ref,
} from '../src/index'
import { createApp, nodeOps, render, serialize } from '@vue/runtime-test'
describe('api: provide/inject', () => {
i... | fim | vuejs/core | typescript |
<|fim_suffix|>(2)
toggle.value = false
await nextTick()
expect(fn).toHaveBeenCalledTimes(4)
})
it('immediately trigger unmount during rendering', async () => {
const fn = vi.fn()
const toggle = ref(false)
const Child = {
setup() {
onMounted(fn)
// trigger unmount imme... | fim | vuejs/core | typescript |
<|fim_suffix|>unction as watch handler', () => {
const Comp = {
watch: {
foo: 'notExistingMethod',
foo2: {
handler: 'notExistingMethod2',
},
},
render() {},
}
const root = nodeOps.createElement('div')
render(h(Comp), root)
... | fim | vuejs/core | typescript |
<|fim_prefix|>import { reactive, ref } from '@vue/reactivity'
import {
type TestElement,
defineComponent,
h,
nextTick,
nodeOps,
render,
renderToString,
serializeInner,
triggerEvent,
watchEffect,
} from '@vue/runtime-test'
describe('api: setup context', () => {
it('should expose return values to t... | fim | vuejs/core | typescript |
import {
type ComponentInternalInstance,
type SetupContext,
Suspense,
computed,
createApp,
defineComponent,
getCurrentInstance,
h,
nodeOps,
onMounted,
render,
serializeInner,
shallowReactive,
} from '@vue/runtime-test'
import {
createPropsRestProxy,
defineEmits,
defineExpose,
definePro... | fim | vuejs/core | typescript |
<|fim_suffix|>',
() => {
v.value = i++
},
)
}
{
const v = ref(100)
watchEffect(() => {
v.value
})
let i = 0
bench('update ref to trigger watchEffect (executed)', async () => {
v.value = i++
await nextTick()
})
}
<|fim_prefix|>import { nextTi<|fim_middle|>ck, ref, watch, watchEff... | fim | vuejs/core | typescript |
<|fim_suffix|>(Function))
pause()
count.value++
await nextTick()
expect(cb).toHaveBeenCalledTimes(3)
expect(cb).toHaveBeenLastCalledWith(4, 3, expect.any(Function))
resume()
await nextTick()
expect(cb).toHaveBeenCalledTimes(4)
expect(cb).toHaveBeenLastCalledWith(5, 4, expect.any(Fu... | fim | vuejs/core | typescript |
<|fim_prefix|>import {
type ComponentInternalInstance,
getCurrentInstance,
h,
nodeOps,
render,
} from '@vue/runtime-test'
import { formatComponentName } from '../src/component'
describe('formatComponentName', () => {
test('default name', () => {
let instance: ComponentInternalInstance | null = null
... | fim | vuejs/core | typescript |
<|fim_suffix|>eOps.createElement('div')
expect(renderFn).toHaveBeenCalledTimes(0)
render(h(ComponentC), el)
expect(renderFn).toHaveBeenCalledTimes(1)
})
test('merge object emits', async () => {
const twoFn = vi.fn((v: unknown) => !v)
const ComponentA = defineComponent({
emits: {
o... | fim | vuejs/core | typescript |
<|fim_suffix|>g props when casting`, async () => {
const Parent = {
setup(props: any, { slots }: SetupContext) {
const childProps = ref()
const registerChildProps = (props: any) => {
childProps.value = props
}
provide('register', registerChildProps)
return ()... | fim | vuejs/core | typescript |
<|fim_suffix|> expect(getCalledTimes).toEqual(1)
// expect toggle getter not to be cached. it can't be
instanceProxy.toggle()
expect(getCalledTimes).toEqual(2)
// attaching spy, triggers the getter once, and override the property.
// also uses Object.defineProperty
const spy = vi.spyOn(insta... | fim | vuejs/core | typescript |
<|fim_prefix|>import {
createApp,
getCurrentInstance,
h,
nextTick,
nodeOps,
ref,
render,
serializeInner,
useSlots,
} from '@vue/runtime-test'
import { createBlock, normalizeVNode } from '../src/vnode'
import { createSlots } from '../src/helpers/createSlots'
describe('component: slots', () => {
func... | fim | vuejs/core | typescript |
<|fim_suffix|>lseSerialized]()
expect(props.onAfterEnter).toHaveBeenCalledTimes(1)
assertCalledWithEl(props.onAfterEnter, falseSerialized)
assertCalls(props, {
onBeforeEnter: 1,
onEnter: 1,
onAfterEnter: 1,
onEnterCancelled: 0,
onBeforeLeave: 1,
onLeave... | fim | vuejs/core | typescript |
<|fim_suffix|>nextTick()
expect(serializeInner(root)).toBe(`1`)
})
})
it('should call correct vnode hooks', async () => {
const Foo = markRaw({
name: 'Foo',
render() {
return h('Foo')
},
})
const Bar = markRaw({
name: 'Bar',
render() {
return h('B... | fim | vuejs/core | typescript |
<|fim_suffix|>eateElement('div')
render(h(Comp), root)
expect(serializeInner(root)).toBe(`<div>fallback outer</div>`)
// mount outer component
await Promise.all(deps)
await nextTick()
expect(serializeInner(root)).toBe(`<div>outerA</div><!---->`)
expect(calls).toEqual([`outerA created`, `ou... | fim | vuejs/core | typescript |
<|fim_suffix|> )
})
// #3497
test(`the dir hooks of the Teleport's children should be called correctly`, async () => {
const target = nodeOps.createElement('div')
const root = nodeOps.createElement('div')
const toggle = ref(true)
const dir = {
mounted: vi.fn(),
u... | fim | vuejs/core | typescript |
<|fim_suffix|>const App = {
name: 'App',
render() {
// simulates the code generated on an unknown directive
return withDirectives(h('div'), [[undefined], [d1]])
},
}
const root = nodeOps.createElement('div')
render(h(App), root)
expect(d1.mounted).toHaveBeenCalled()
... | fim | vuejs/core | typescript |
<|fim_prefix|>import {
type VNode,
computed,
createApp,
defineComponent,
h,
nextTick,
nodeOps,
onErrorCaptured,
onMounted,
ref,
render,
watch,
watchEffect,
} from '@vue/runtime-test'
import { ErrorCodes, ErrorTypeStrings } from '../src/errorHandling'
describe('error handling', () => {
test(... | fim | vuejs/core | typescript |
<|fim_suffix|>t Component = { template: '<br />' }
expect(h(Component, {}, slots)).toMatchObject(
createVNode(Component, {}, slots),
)
// default slot
const slot = () => {}
expect(h(Component, {}, slot)).toMatchObject(
createVNode(Component, {}, slot),
)
// single vnode
const... | fim | vuejs/core | typescript |
<|fim_prefix|>import type { Slot } from '../../src/componentSlots'
import { createSlots } from '../../src/helpers/createSlots'
describe('createSlot', () => {
const slot = () => []
let record: Record<string, Slot>
<|fim_suffix|>) as Slot
const dynamicSlot = [{ name: 'descriptor', fn: slot, key: '1' }]
cons... | fim | vuejs/core | typescript |
<|fim_suffix|>teger value but got -1.`,
).toHaveBeenWarned()
})
it('should not warn when given 0', () => {
renderList(0, () => {})
expect(
`The v-for range expects a positive integer value but got 0.`,
).not.toHaveBeenWarned()
})
it('should render properties in an object', () => {
ex... | fim | vuejs/core | typescript |
<|fim_suffix|>key).toBe('_default')
})
it('should render slot fallback', () => {
const vnode = renderSlot({}, 'default', { key: 'foo' }, () => ['fallback'])
expect(vnode.children).toEqual(['fallback'])
// should attach fallback key postfix
expect(vnode.key).toBe('foo_fb')
})
it('should warn re... | fim | vuejs/core | typescript |
<|fim_suffix|>p.mount(root)
expect(foo).toBe(dynamicComponents.foo)
expect(bar).toBe(dynamicComponents.bar)
expect(baz).toBe(dynamicComponents.baz)
// should allow explicit falsy type to remove the component
expect(dynamicVNode!.type).toBe(Comment)
})
test('resolve dynamic compone... | fim | vuejs/core | typescript |
<|fim_suffix|>
expect(toHandlers({ input, change })).toStrictEqual({
onInput: input,
onChange: change,
})
})
})
<|fim_prefix|>import { toHandlers } from '../../src/helpers/toHandlers'
describe('toHandlers', () => {
it('should not acc<|fim_middle|>ept non-objects', () => {
toHandlers(null as... | fim | vuejs/core | typescript |
<|fim_prefix|>/**
* @vitest-environment jsdom
*/
import {
type App,
Suspense,
createApp,
defineAsyncComponent,
defineComponent,
h,
onServerPrefetch,
useId,
} from 'vue'
import { renderToString } from '@vue/server-renderer'
type FactoryRes = [App, Promise<an<|fim_suffix|> return {}
},
... | fim | vuejs/core | typescript |
<|fim_suffix|>pdate:msg'],
setup(props) {
const childMsg = useModel(props, 'msg', {
set: value => {
if (value === msg.value) {
return null
} else {
return value
}
},
})
changeChildMsg = (val: boolean) => (c... | fim | vuejs/core | typescript |
<|fim_suffix|>teRef('foo')
return () => h('div', { ref: foo })
},
}
const root = nodeOps.createElement('div')
render(h(Comp), root)
expect('target is readonly').not.toHaveBeenWarned()
expect(foo!.value).toBe(root.children[0])
} finally {
__DEV__ = true
}
... | fim | vuejs/core | typescript |
<|fim_suffix|>k()
expect(el.innerHTML).toBe(`<div>1 0</div>`)
vm.x++
// should update
await nextTick()
expect(el.innerHTML).toBe(`<div>2 1</div>`)
vm.ok = false
await nextTick()
expect(el.innerHTML).toBe(`<div>1 2</div>`)
vm.y++
// should update
await nextTick()
expect... | fim | vuejs/core | typescript |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.