chore: run updated prettier
This commit is contained in:
parent
69344ff1ae
commit
47f488350c
@ -61,11 +61,7 @@ describe('compiler: codegen', () => {
|
||||
})
|
||||
const { code } = generate(root, { mode: 'module' })
|
||||
expect(code).toMatch(
|
||||
`import { ${helperNameMap[CREATE_VNODE]} as _${
|
||||
helperNameMap[CREATE_VNODE]
|
||||
}, ${helperNameMap[RESOLVE_DIRECTIVE]} as _${
|
||||
helperNameMap[RESOLVE_DIRECTIVE]
|
||||
} } from "vue"`
|
||||
`import { ${helperNameMap[CREATE_VNODE]} as _${helperNameMap[CREATE_VNODE]}, ${helperNameMap[RESOLVE_DIRECTIVE]} as _${helperNameMap[RESOLVE_DIRECTIVE]} } from "vue"`
|
||||
)
|
||||
expect(code).toMatchSnapshot()
|
||||
})
|
||||
@ -76,16 +72,10 @@ describe('compiler: codegen', () => {
|
||||
})
|
||||
const { code } = generate(root, { mode: 'module', optimizeImports: true })
|
||||
expect(code).toMatch(
|
||||
`import { ${helperNameMap[CREATE_VNODE]}, ${
|
||||
helperNameMap[RESOLVE_DIRECTIVE]
|
||||
} } from "vue"`
|
||||
`import { ${helperNameMap[CREATE_VNODE]}, ${helperNameMap[RESOLVE_DIRECTIVE]} } from "vue"`
|
||||
)
|
||||
expect(code).toMatch(
|
||||
`const _${helperNameMap[CREATE_VNODE]} = ${
|
||||
helperNameMap[CREATE_VNODE]
|
||||
}, _${helperNameMap[RESOLVE_DIRECTIVE]} = ${
|
||||
helperNameMap[RESOLVE_DIRECTIVE]
|
||||
}`
|
||||
`const _${helperNameMap[CREATE_VNODE]} = ${helperNameMap[CREATE_VNODE]}, _${helperNameMap[RESOLVE_DIRECTIVE]} = ${helperNameMap[RESOLVE_DIRECTIVE]}`
|
||||
)
|
||||
expect(code).toMatchSnapshot()
|
||||
})
|
||||
@ -97,11 +87,7 @@ describe('compiler: codegen', () => {
|
||||
const { code } = generate(root, { mode: 'function' })
|
||||
expect(code).toMatch(`const _Vue = Vue`)
|
||||
expect(code).toMatch(
|
||||
`const { ${helperNameMap[CREATE_VNODE]}: _${
|
||||
helperNameMap[CREATE_VNODE]
|
||||
}, ${helperNameMap[RESOLVE_DIRECTIVE]}: _${
|
||||
helperNameMap[RESOLVE_DIRECTIVE]
|
||||
} } = _Vue`
|
||||
`const { ${helperNameMap[CREATE_VNODE]}: _${helperNameMap[CREATE_VNODE]}, ${helperNameMap[RESOLVE_DIRECTIVE]}: _${helperNameMap[RESOLVE_DIRECTIVE]} } = _Vue`
|
||||
)
|
||||
expect(code).toMatchSnapshot()
|
||||
})
|
||||
@ -116,11 +102,7 @@ describe('compiler: codegen', () => {
|
||||
})
|
||||
expect(code).not.toMatch(`const _Vue = Vue`)
|
||||
expect(code).toMatch(
|
||||
`const { ${helperNameMap[CREATE_VNODE]}: _${
|
||||
helperNameMap[CREATE_VNODE]
|
||||
}, ${helperNameMap[RESOLVE_DIRECTIVE]}: _${
|
||||
helperNameMap[RESOLVE_DIRECTIVE]
|
||||
} } = Vue`
|
||||
`const { ${helperNameMap[CREATE_VNODE]}: _${helperNameMap[CREATE_VNODE]}, ${helperNameMap[RESOLVE_DIRECTIVE]}: _${helperNameMap[RESOLVE_DIRECTIVE]} } = Vue`
|
||||
)
|
||||
expect(code).toMatchSnapshot()
|
||||
})
|
||||
@ -136,30 +118,20 @@ describe('compiler: codegen', () => {
|
||||
`const _component_Foo = _${helperNameMap[RESOLVE_COMPONENT]}("Foo")\n`
|
||||
)
|
||||
expect(code).toMatch(
|
||||
`const _component_bar_baz = _${
|
||||
helperNameMap[RESOLVE_COMPONENT]
|
||||
}("bar-baz")\n`
|
||||
`const _component_bar_baz = _${helperNameMap[RESOLVE_COMPONENT]}("bar-baz")\n`
|
||||
)
|
||||
expect(code).toMatch(
|
||||
`const _component_barbaz = _${
|
||||
helperNameMap[RESOLVE_COMPONENT]
|
||||
}("barbaz")\n`
|
||||
`const _component_barbaz = _${helperNameMap[RESOLVE_COMPONENT]}("barbaz")\n`
|
||||
)
|
||||
// implicit self reference from SFC filename
|
||||
expect(code).toMatch(
|
||||
`const _component_Qux = _${
|
||||
helperNameMap[RESOLVE_COMPONENT]
|
||||
}("Qux", true)\n`
|
||||
`const _component_Qux = _${helperNameMap[RESOLVE_COMPONENT]}("Qux", true)\n`
|
||||
)
|
||||
expect(code).toMatch(
|
||||
`const _directive_my_dir_0 = _${
|
||||
helperNameMap[RESOLVE_DIRECTIVE]
|
||||
}("my_dir_0")\n`
|
||||
`const _directive_my_dir_0 = _${helperNameMap[RESOLVE_DIRECTIVE]}("my_dir_0")\n`
|
||||
)
|
||||
expect(code).toMatch(
|
||||
`const _directive_my_dir_1 = _${
|
||||
helperNameMap[RESOLVE_DIRECTIVE]
|
||||
}("my_dir_1")\n`
|
||||
`const _directive_my_dir_1 = _${helperNameMap[RESOLVE_DIRECTIVE]}("my_dir_1")\n`
|
||||
)
|
||||
expect(code).toMatch(`let _temp0, _temp1, _temp2`)
|
||||
expect(code).toMatchSnapshot()
|
||||
|
@ -2871,7 +2871,7 @@ foo
|
||||
]
|
||||
}
|
||||
|
||||
for (const key of Object.keys(patterns) as (keyof (typeof patterns))[]) {
|
||||
for (const key of Object.keys(patterns) as (keyof typeof patterns)[]) {
|
||||
describe(key, () => {
|
||||
for (const { code, errors, options } of patterns[key]) {
|
||||
test(
|
||||
|
@ -355,8 +355,9 @@ describe('compiler: hoistStatic transform', () => {
|
||||
},
|
||||
hoistedChildrenArrayMatcher(2)
|
||||
])
|
||||
const forBlockCodegen = ((root.children[0] as ElementNode)
|
||||
.children[0] as ForNode).codegenNode
|
||||
const forBlockCodegen = (
|
||||
(root.children[0] as ElementNode).children[0] as ForNode
|
||||
).codegenNode
|
||||
expect(forBlockCodegen).toMatchObject({
|
||||
type: NodeTypes.VNODE_CALL,
|
||||
tag: FRAGMENT,
|
||||
|
@ -654,8 +654,8 @@ describe('compiler: v-for', () => {
|
||||
patchFlag: !disableTracking
|
||||
? genFlagText(PatchFlags.STABLE_FRAGMENT)
|
||||
: keyed
|
||||
? genFlagText(PatchFlags.KEYED_FRAGMENT)
|
||||
: genFlagText(PatchFlags.UNKEYED_FRAGMENT),
|
||||
? genFlagText(PatchFlags.KEYED_FRAGMENT)
|
||||
: genFlagText(PatchFlags.UNKEYED_FRAGMENT),
|
||||
children: {
|
||||
type: NodeTypes.JS_CALL_EXPRESSION,
|
||||
callee: RENDER_LIST,
|
||||
|
@ -290,8 +290,8 @@ describe('compiler: transform v-model', () => {
|
||||
test('with dynamic argument', () => {
|
||||
const root = parseWithVModel('<input v-model:[value]="model" />')
|
||||
const node = root.children[0] as ElementNode
|
||||
const props = ((node.codegenNode as VNodeCall)
|
||||
.props as unknown) as CallExpression
|
||||
const props = (node.codegenNode as VNodeCall)
|
||||
.props as unknown as CallExpression
|
||||
|
||||
expect(props).toMatchObject({
|
||||
type: NodeTypes.JS_CALL_EXPRESSION,
|
||||
@ -344,8 +344,8 @@ describe('compiler: transform v-model', () => {
|
||||
prefixIdentifiers: true
|
||||
})
|
||||
const node = root.children[0] as ElementNode
|
||||
const props = ((node.codegenNode as VNodeCall)
|
||||
.props as unknown) as CallExpression
|
||||
const props = (node.codegenNode as VNodeCall)
|
||||
.props as unknown as CallExpression
|
||||
|
||||
expect(props).toMatchObject({
|
||||
type: NodeTypes.JS_CALL_EXPRESSION,
|
||||
@ -417,8 +417,9 @@ describe('compiler: transform v-model', () => {
|
||||
}
|
||||
)
|
||||
expect(root.cached).toBe(0)
|
||||
const codegen = ((root.children[0] as ForNode)
|
||||
.children[0] as PlainElementNode).codegenNode as VNodeCall
|
||||
const codegen = (
|
||||
(root.children[0] as ForNode).children[0] as PlainElementNode
|
||||
).codegenNode as VNodeCall
|
||||
expect(codegen.dynamicProps).toBe(`["modelValue", "onUpdate:modelValue"]`)
|
||||
expect(
|
||||
(codegen.props as ObjectExpression).properties[1].value.type
|
||||
@ -426,13 +427,10 @@ describe('compiler: transform v-model', () => {
|
||||
})
|
||||
|
||||
test('should not cache update handler if it inside v-once', () => {
|
||||
const root = parseWithVModel(
|
||||
'<div v-once><input v-model="foo" /></div>',
|
||||
{
|
||||
prefixIdentifiers: true,
|
||||
cacheHandlers: true
|
||||
}
|
||||
)
|
||||
const root = parseWithVModel('<div v-once><input v-model="foo" /></div>', {
|
||||
prefixIdentifiers: true,
|
||||
cacheHandlers: true
|
||||
})
|
||||
expect(root.cached).not.toBe(2)
|
||||
expect(root.cached).toBe(1)
|
||||
})
|
||||
@ -444,8 +442,9 @@ describe('compiler: transform v-model', () => {
|
||||
prefixIdentifiers: true
|
||||
}
|
||||
)
|
||||
const codegen = ((root.children[0] as ComponentNode)
|
||||
.children[0] as PlainElementNode).codegenNode as VNodeCall
|
||||
const codegen = (
|
||||
(root.children[0] as ComponentNode).children[0] as PlainElementNode
|
||||
).codegenNode as VNodeCall
|
||||
expect(codegen.dynamicProps).toBe(`["modelValue", "onUpdate:modelValue"]`)
|
||||
})
|
||||
|
||||
|
@ -531,10 +531,13 @@ describe('compiler: transform v-on', () => {
|
||||
})
|
||||
|
||||
test('should not be cached inside v-once', () => {
|
||||
const { root } = parseWithVOn(`<div v-once><div v-on:click="foo"/></div>`, {
|
||||
prefixIdentifiers: true,
|
||||
cacheHandlers: true
|
||||
})
|
||||
const { root } = parseWithVOn(
|
||||
`<div v-once><div v-on:click="foo"/></div>`,
|
||||
{
|
||||
prefixIdentifiers: true,
|
||||
cacheHandlers: true
|
||||
}
|
||||
)
|
||||
expect(root.cached).not.toBe(2)
|
||||
expect(root.cached).toBe(1)
|
||||
})
|
||||
|
@ -237,7 +237,8 @@ export interface CompoundExpressionNode extends Node {
|
||||
| InterpolationNode
|
||||
| TextNode
|
||||
| string
|
||||
| symbol)[]
|
||||
| symbol
|
||||
)[]
|
||||
|
||||
/**
|
||||
* an expression parsed as the params of a function will track
|
||||
@ -328,7 +329,8 @@ export interface CallExpression extends Node {
|
||||
| JSChildNode
|
||||
| SSRCodegenNode
|
||||
| TemplateChildNode
|
||||
| TemplateChildNode[])[]
|
||||
| TemplateChildNode[]
|
||||
)[]
|
||||
}
|
||||
|
||||
export interface ObjectExpression extends Node {
|
||||
@ -439,8 +441,8 @@ export interface DirectiveArguments extends ArrayExpression {
|
||||
}
|
||||
|
||||
export interface DirectiveArgumentNode extends ArrayExpression {
|
||||
elements: // dir, exp, arg, modifiers
|
||||
| [string]
|
||||
elements: // dir, exp, arg, modifiers
|
||||
| [string]
|
||||
| [string, ExpressionNode]
|
||||
| [string, ExpressionNode, ExpressionNode]
|
||||
| [string, ExpressionNode, ExpressionNode, ObjectExpression]
|
||||
@ -449,8 +451,8 @@ export interface DirectiveArgumentNode extends ArrayExpression {
|
||||
// renderSlot(...)
|
||||
export interface RenderSlotCall extends CallExpression {
|
||||
callee: typeof RENDER_SLOT
|
||||
arguments: // $slots, name, props, fallback
|
||||
| [string, string | ExpressionNode]
|
||||
arguments: // $slots, name, props, fallback
|
||||
| [string, string | ExpressionNode]
|
||||
| [string, string | ExpressionNode, PropsExpression]
|
||||
| [
|
||||
string,
|
||||
|
@ -444,8 +444,8 @@ function genAssets(
|
||||
__COMPAT__ && type === 'filter'
|
||||
? RESOLVE_FILTER
|
||||
: type === 'component'
|
||||
? RESOLVE_COMPONENT
|
||||
: RESOLVE_DIRECTIVE
|
||||
? RESOLVE_COMPONENT
|
||||
: RESOLVE_DIRECTIVE
|
||||
)
|
||||
for (let i = 0; i < assets.length; i++) {
|
||||
let id = assets[i]
|
||||
|
@ -41,8 +41,8 @@ export function getBaseTransformPreset(
|
||||
transformExpression
|
||||
]
|
||||
: __BROWSER__ && __DEV__
|
||||
? [transformExpression]
|
||||
: []),
|
||||
? [transformExpression]
|
||||
: []),
|
||||
transformSlotOutlet,
|
||||
transformElement,
|
||||
trackSlotScopes,
|
||||
@ -83,9 +83,8 @@ export function baseCompile(
|
||||
}
|
||||
|
||||
const ast = isString(template) ? baseParse(template, options) : template
|
||||
const [nodeTransforms, directiveTransforms] = getBaseTransformPreset(
|
||||
prefixIdentifiers
|
||||
)
|
||||
const [nodeTransforms, directiveTransforms] =
|
||||
getBaseTransformPreset(prefixIdentifiers)
|
||||
transform(
|
||||
ast,
|
||||
extend({}, options, {
|
||||
|
@ -774,9 +774,10 @@ function parseAttribute(
|
||||
const loc = getSelection(context, start)
|
||||
|
||||
if (!context.inVPre && /^(v-|:|\.|@|#)/.test(name)) {
|
||||
const match = /(?:^v-([a-z0-9-]+))?(?:(?::|^\.|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec(
|
||||
name
|
||||
)!
|
||||
const match =
|
||||
/(?:^v-([a-z0-9-]+))?(?:(?::|^\.|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec(
|
||||
name
|
||||
)!
|
||||
|
||||
let isPropShorthand = startsWith(name, '.')
|
||||
let dirName =
|
||||
@ -784,8 +785,8 @@ function parseAttribute(
|
||||
(isPropShorthand || startsWith(name, ':')
|
||||
? 'bind'
|
||||
: startsWith(name, '@')
|
||||
? 'on'
|
||||
: 'slot')
|
||||
? 'on'
|
||||
: 'slot')
|
||||
let arg: ExpressionNode | undefined
|
||||
|
||||
if (match[2]) {
|
||||
|
@ -235,8 +235,8 @@ export function createTransformContext(
|
||||
const removalIndex = node
|
||||
? list.indexOf(node)
|
||||
: context.currentNode
|
||||
? context.childIndex
|
||||
: -1
|
||||
? context.childIndex
|
||||
: -1
|
||||
/* istanbul ignore if */
|
||||
if (__DEV__ && removalIndex < 0) {
|
||||
throw new Error(`node being removed is not a child of current parent`)
|
||||
|
@ -86,8 +86,8 @@ export const transformFor = createStructuralDirectiveTransform(
|
||||
const fragmentFlag = isStableFragment
|
||||
? PatchFlags.STABLE_FRAGMENT
|
||||
: keyProp
|
||||
? PatchFlags.KEYED_FRAGMENT
|
||||
: PatchFlags.UNKEYED_FRAGMENT
|
||||
? PatchFlags.KEYED_FRAGMENT
|
||||
: PatchFlags.UNKEYED_FRAGMENT
|
||||
|
||||
forNode.codegenNode = createVNodeCall(
|
||||
context,
|
||||
@ -135,8 +135,8 @@ export const transformFor = createStructuralDirectiveTransform(
|
||||
: isTemplate &&
|
||||
node.children.length === 1 &&
|
||||
isSlotOutlet(node.children[0])
|
||||
? (node.children[0] as SlotOutletNode) // api-extractor somehow fails to infer this
|
||||
: null
|
||||
? (node.children[0] as SlotOutletNode) // api-extractor somehow fails to infer this
|
||||
: null
|
||||
|
||||
if (slotOutlet) {
|
||||
// <slot v-for="..."> or <template v-for="..."><slot/></template>
|
||||
@ -221,11 +221,13 @@ export const transformFor = createStructuralDirectiveTransform(
|
||||
createSimpleExpression(String(context.cached++))
|
||||
)
|
||||
} else {
|
||||
renderExp.arguments.push(createFunctionExpression(
|
||||
createForLoopParams(forNode.parseResult),
|
||||
childBlock,
|
||||
true /* force newline */
|
||||
) as ForIteratorExpression)
|
||||
renderExp.arguments.push(
|
||||
createFunctionExpression(
|
||||
createForLoopParams(forNode.parseResult),
|
||||
childBlock,
|
||||
true /* force newline */
|
||||
) as ForIteratorExpression
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -343,9 +345,7 @@ export function parseForExpression(
|
||||
validateBrowserExpression(result.source as SimpleExpressionNode, context)
|
||||
}
|
||||
|
||||
let valueContent = LHS.trim()
|
||||
.replace(stripParensRE, '')
|
||||
.trim()
|
||||
let valueContent = LHS.trim().replace(stripParensRE, '').trim()
|
||||
const trimmedOffset = LHS.indexOf(valueContent)
|
||||
|
||||
const iteratorMatch = valueContent.match(forIteratorRE)
|
||||
|
@ -319,8 +319,8 @@ function isSameKey(
|
||||
}
|
||||
if (
|
||||
exp.type !== NodeTypes.SIMPLE_EXPRESSION ||
|
||||
(exp.isStatic !== (branchExp as SimpleExpressionNode).isStatic ||
|
||||
exp.content !== (branchExp as SimpleExpressionNode).content)
|
||||
exp.isStatic !== (branchExp as SimpleExpressionNode).isStatic ||
|
||||
exp.content !== (branchExp as SimpleExpressionNode).content
|
||||
) {
|
||||
return false
|
||||
}
|
||||
|
@ -337,8 +337,8 @@ export function buildSlots(
|
||||
const slotFlag = hasDynamicSlots
|
||||
? SlotFlags.DYNAMIC
|
||||
: hasForwardedSlots(node.children)
|
||||
? SlotFlags.FORWARDED
|
||||
: SlotFlags.STABLE
|
||||
? SlotFlags.FORWARDED
|
||||
: SlotFlags.STABLE
|
||||
|
||||
let slots = createObjectExpression(
|
||||
slotsProperties.concat(
|
||||
|
@ -273,7 +273,7 @@ export function hasDynamicKeyVBind(node: ElementNode): boolean {
|
||||
p.type === NodeTypes.DIRECTIVE &&
|
||||
p.name === 'bind' &&
|
||||
(!p.arg || // v-bind="obj"
|
||||
p.arg.type !== NodeTypes.SIMPLE_EXPRESSION || // v-bind:[_ctx.foo]
|
||||
p.arg.type !== NodeTypes.SIMPLE_EXPRESSION || // v-bind:[_ctx.foo]
|
||||
!p.arg.isStatic) // v-bind:[foo]
|
||||
)
|
||||
}
|
||||
|
@ -18,7 +18,8 @@ const prohibitedKeywordRE = new RegExp(
|
||||
)
|
||||
|
||||
// strip strings in expressions
|
||||
const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g
|
||||
const stripStringRE =
|
||||
/'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g
|
||||
|
||||
/**
|
||||
* Validate a non-prefixed expression.
|
||||
@ -51,9 +52,7 @@ export function validateBrowserExpression(
|
||||
.replace(stripStringRE, '')
|
||||
.match(prohibitedKeywordRE)
|
||||
if (keywordMatch) {
|
||||
message = `avoid using JavaScript keyword as property name: "${
|
||||
keywordMatch[0]
|
||||
}"`
|
||||
message = `avoid using JavaScript keyword as property name: "${keywordMatch[0]}"`
|
||||
}
|
||||
context.onError(
|
||||
createCompilerError(
|
||||
|
@ -27,8 +27,10 @@ function parseWithVOn(template: string, options: CompilerOptions = {}) {
|
||||
})
|
||||
return {
|
||||
root: ast,
|
||||
props: (((ast.children[0] as ElementNode).codegenNode as VNodeCall)
|
||||
.props as ObjectExpression).properties
|
||||
props: (
|
||||
((ast.children[0] as ElementNode).codegenNode as VNodeCall)
|
||||
.props as ObjectExpression
|
||||
).properties
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,14 +96,14 @@ const transformClick = (key: ExpressionNode, event: string) => {
|
||||
return isStaticClick
|
||||
? createSimpleExpression(event, true)
|
||||
: key.type !== NodeTypes.SIMPLE_EXPRESSION
|
||||
? createCompoundExpression([
|
||||
`(`,
|
||||
key,
|
||||
`) === "onClick" ? "${event}" : (`,
|
||||
key,
|
||||
`)`
|
||||
])
|
||||
: key
|
||||
? createCompoundExpression([
|
||||
`(`,
|
||||
key,
|
||||
`) === "onClick" ? "${event}" : (`,
|
||||
key,
|
||||
`)`
|
||||
])
|
||||
: key
|
||||
}
|
||||
|
||||
export const transformOn: DirectiveTransform = (dir, node, context) => {
|
||||
@ -112,11 +112,8 @@ export const transformOn: DirectiveTransform = (dir, node, context) => {
|
||||
if (!modifiers.length) return baseResult
|
||||
|
||||
let { key, value: handlerExp } = baseResult.props[0]
|
||||
const {
|
||||
keyModifiers,
|
||||
nonKeyModifiers,
|
||||
eventOptionModifiers
|
||||
} = resolveModifiers(key, modifiers, context, dir.loc)
|
||||
const { keyModifiers, nonKeyModifiers, eventOptionModifiers } =
|
||||
resolveModifiers(key, modifiers, context, dir.loc)
|
||||
|
||||
// normalize click.right and click.middle since they don't actually fire
|
||||
if (nonKeyModifiers.includes('right')) {
|
||||
|
@ -59,8 +59,8 @@ describe('compiler sfc: transform asset url', () => {
|
||||
test('with explicit base', () => {
|
||||
const { code } = compileWithAssetUrls(
|
||||
`<img src="./bar.png"></img>` + // -> /foo/bar.png
|
||||
`<img src="bar.png"></img>` + // -> bar.png (untouched)
|
||||
`<img src="~bar.png"></img>` + // -> still converts to import
|
||||
`<img src="bar.png"></img>` + // -> bar.png (untouched)
|
||||
`<img src="~bar.png"></img>` + // -> still converts to import
|
||||
`<img src="@theme/bar.png"></img>`, // -> still converts to import
|
||||
{
|
||||
base: '/foo'
|
||||
|
@ -678,7 +678,9 @@ export function compileScript(
|
||||
.map(key => {
|
||||
let defaultString: string | undefined
|
||||
if (hasStaticDefaults) {
|
||||
const prop = (propsRuntimeDefaults as ObjectExpression).properties.find(
|
||||
const prop = (
|
||||
propsRuntimeDefaults as ObjectExpression
|
||||
).properties.find(
|
||||
(node: any) => node.key.name === key
|
||||
) as ObjectProperty
|
||||
if (prop) {
|
||||
@ -776,9 +778,7 @@ export function compileScript(
|
||||
// rewrite to `import { x as __default__ } from './x'` and
|
||||
// add to top
|
||||
s.prepend(
|
||||
`import { ${
|
||||
defaultSpecifier.local.name
|
||||
} as ${defaultTempVar} } from '${node.source.value}'\n`
|
||||
`import { ${defaultSpecifier.local.name} as ${defaultTempVar} } from '${node.source.value}'\n`
|
||||
)
|
||||
} else {
|
||||
// export { x as default }
|
||||
@ -1376,11 +1376,11 @@ export function compileScript(
|
||||
...scriptSetup,
|
||||
bindings: bindingMetadata,
|
||||
content: s.toString(),
|
||||
map: (s.generateMap({
|
||||
map: s.generateMap({
|
||||
source: filename,
|
||||
hires: true,
|
||||
includeContent: true
|
||||
}) as unknown) as RawSourceMap,
|
||||
}) as unknown as RawSourceMap,
|
||||
scriptAst,
|
||||
scriptSetupAst
|
||||
}
|
||||
@ -1470,8 +1470,8 @@ function walkObjectPattern(
|
||||
const type = isDefineCall
|
||||
? BindingTypes.SETUP_CONST
|
||||
: isConst
|
||||
? BindingTypes.SETUP_MAYBE_REF
|
||||
: BindingTypes.SETUP_LET
|
||||
? BindingTypes.SETUP_MAYBE_REF
|
||||
: BindingTypes.SETUP_LET
|
||||
registerBinding(bindings, p.key, type)
|
||||
} else {
|
||||
walkPattern(p.value, bindings, isConst, isDefineCall)
|
||||
@ -1507,8 +1507,8 @@ function walkPattern(
|
||||
const type = isDefineCall
|
||||
? BindingTypes.SETUP_CONST
|
||||
: isConst
|
||||
? BindingTypes.SETUP_MAYBE_REF
|
||||
: BindingTypes.SETUP_LET
|
||||
? BindingTypes.SETUP_MAYBE_REF
|
||||
: BindingTypes.SETUP_LET
|
||||
registerBinding(bindings, node, type)
|
||||
} else if (node.type === 'RestElement') {
|
||||
// argument can only be identifer when destructuring
|
||||
@ -1523,8 +1523,8 @@ function walkPattern(
|
||||
const type = isDefineCall
|
||||
? BindingTypes.SETUP_CONST
|
||||
: isConst
|
||||
? BindingTypes.SETUP_MAYBE_REF
|
||||
: BindingTypes.SETUP_LET
|
||||
? BindingTypes.SETUP_MAYBE_REF
|
||||
: BindingTypes.SETUP_LET
|
||||
registerBinding(bindings, node.left, type)
|
||||
} else {
|
||||
walkPattern(node.left, bindings, isConst)
|
||||
@ -1651,9 +1651,9 @@ function inferRuntimeType(
|
||||
case 'TSUnionType':
|
||||
return [
|
||||
...new Set(
|
||||
[].concat(node.types.map(t =>
|
||||
inferRuntimeType(t, declaredTypes)
|
||||
) as any)
|
||||
[].concat(
|
||||
node.types.map(t => inferRuntimeType(t, declaredTypes)) as any
|
||||
)
|
||||
)
|
||||
]
|
||||
case 'TSIntersectionType':
|
||||
@ -1668,8 +1668,8 @@ function toRuntimeTypeString(types: string[]) {
|
||||
return types.some(t => t === 'null')
|
||||
? `null`
|
||||
: types.length > 1
|
||||
? `[${types.join(', ')}]`
|
||||
: types[0]
|
||||
? `[${types.join(', ')}]`
|
||||
: types[0]
|
||||
}
|
||||
|
||||
function extractRuntimeEmits(
|
||||
|
@ -79,9 +79,10 @@ export function compileStyle(
|
||||
export function compileStyleAsync(
|
||||
options: SFCAsyncStyleCompileOptions
|
||||
): Promise<SFCStyleCompileResults> {
|
||||
return doCompileStyle({ ...options, isAsync: true }) as Promise<
|
||||
SFCStyleCompileResults
|
||||
>
|
||||
return doCompileStyle({
|
||||
...options,
|
||||
isAsync: true
|
||||
}) as Promise<SFCStyleCompileResults>
|
||||
}
|
||||
|
||||
export function doCompileStyle(
|
||||
|
@ -140,14 +140,10 @@ export function compileTemplate(
|
||||
code: `export default function render() {}`,
|
||||
source: options.source,
|
||||
tips: [
|
||||
`Component ${
|
||||
options.filename
|
||||
} uses lang ${preprocessLang} for template. Please install the language preprocessor.`
|
||||
`Component ${options.filename} uses lang ${preprocessLang} for template. Please install the language preprocessor.`
|
||||
],
|
||||
errors: [
|
||||
`Component ${
|
||||
options.filename
|
||||
} uses lang ${preprocessLang} for template, however it is not installed.`
|
||||
`Component ${options.filename} uses lang ${preprocessLang} for template, however it is not installed.`
|
||||
]
|
||||
}
|
||||
} else {
|
||||
|
@ -12,7 +12,8 @@ import { PluginCreator } from 'postcss'
|
||||
import hash from 'hash-sum'
|
||||
|
||||
export const CSS_VARS_HELPER = `useCssVars`
|
||||
export const cssVarRE = /\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([^'"][^)]*))\s*\)/g
|
||||
export const cssVarRE =
|
||||
/\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([^'"][^)]*))\s*\)/g
|
||||
|
||||
export function genCssVarsFromList(
|
||||
vars: string[],
|
||||
|
@ -3,7 +3,8 @@ import MagicString from 'magic-string'
|
||||
|
||||
const defaultExportRE = /((?:^|\n|;)\s*)export(\s*)default/
|
||||
const namedDefaultExportRE = /((?:^|\n|;)\s*)export(.+)as(\s*)default/s
|
||||
const exportDefaultClassRE = /((?:^|\n|;)\s*)export\s+default\s+class\s+([\w$]+)/
|
||||
const exportDefaultClassRE =
|
||||
/((?:^|\n|;)\s*)export\s+default\s+class\s+([\w$]+)/
|
||||
|
||||
/**
|
||||
* Utility for rewriting `export default` in a script block into a variable
|
||||
|
@ -71,9 +71,10 @@ describe('ssr: element', () => {
|
||||
`)
|
||||
})
|
||||
|
||||
test("multiple _ssrInterpolate at parent and child import dependency once", () => {
|
||||
expect( compile(`<div>{{ hello }}<textarea v-bind="a"></textarea></div>`).code)
|
||||
.toMatchInlineSnapshot(`
|
||||
test('multiple _ssrInterpolate at parent and child import dependency once', () => {
|
||||
expect(
|
||||
compile(`<div>{{ hello }}<textarea v-bind="a"></textarea></div>`).code
|
||||
).toMatchInlineSnapshot(`
|
||||
"const { ssrRenderAttrs: _ssrRenderAttrs, ssrInterpolate: _ssrInterpolate } = require(\\"@vue/server-renderer\\")
|
||||
|
||||
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
||||
@ -89,8 +90,8 @@ describe('ssr: element', () => {
|
||||
_ssrInterpolate((\\"value\\" in _temp0) ? _temp0.value : \\"\\")
|
||||
}</textarea></div>\`)
|
||||
}"
|
||||
`);
|
||||
});
|
||||
`)
|
||||
})
|
||||
|
||||
test('should pass tag to custom elements w/ dynamic v-bind', () => {
|
||||
expect(
|
||||
|
@ -56,11 +56,10 @@ export function ssrCodegenTransform(ast: RootNode, options: CompilerOptions) {
|
||||
|
||||
// Finalize helpers.
|
||||
// We need to separate helpers imported from 'vue' vs. '@vue/server-renderer'
|
||||
ast.ssrHelpers = Array.from(new Set([
|
||||
...ast.helpers.filter(h => h in ssrHelpers),
|
||||
...context.helpers
|
||||
]))
|
||||
|
||||
ast.ssrHelpers = Array.from(
|
||||
new Set([...ast.helpers.filter(h => h in ssrHelpers), ...context.helpers])
|
||||
)
|
||||
|
||||
ast.helpers = ast.helpers.filter(h => !(h in ssrHelpers))
|
||||
}
|
||||
|
||||
|
@ -225,9 +225,8 @@ export function ssrProcessComponent(
|
||||
|
||||
export const rawOptionsMap = new WeakMap<RootNode, CompilerOptions>()
|
||||
|
||||
const [baseNodeTransforms, baseDirectiveTransforms] = getBaseTransformPreset(
|
||||
true
|
||||
)
|
||||
const [baseNodeTransforms, baseDirectiveTransforms] =
|
||||
getBaseTransformPreset(true)
|
||||
const vnodeNodeTransforms = [...baseNodeTransforms, ...DOMNodeTransforms]
|
||||
const vnodeDirectiveTransforms = {
|
||||
...baseDirectiveTransforms,
|
||||
|
4
packages/global.d.ts
vendored
4
packages/global.d.ts
vendored
@ -24,9 +24,7 @@ declare namespace jest {
|
||||
}
|
||||
}
|
||||
|
||||
declare module '*.vue' {
|
||||
|
||||
}
|
||||
declare module '*.vue' {}
|
||||
declare module '*?raw' {
|
||||
const content: string
|
||||
export default content
|
||||
|
@ -422,7 +422,7 @@ describe('reactivity/collections', () => {
|
||||
const proxy = reactive(raw)
|
||||
const thisArg = {}
|
||||
let count = 0
|
||||
proxy.forEach(function(this: {}, value, _, set) {
|
||||
proxy.forEach(function (this: {}, value, _, set) {
|
||||
++count
|
||||
expect(this).toBe(thisArg)
|
||||
expect(value).toBe('value')
|
||||
|
@ -178,7 +178,10 @@ describe('reactivity/readonly', () => {
|
||||
test('should make nested values readonly', () => {
|
||||
const key1 = {}
|
||||
const key2 = {}
|
||||
const original = new Collection([[key1, {}], [key2, {}]])
|
||||
const original = new Collection([
|
||||
[key1, {}],
|
||||
[key2, {}]
|
||||
])
|
||||
const wrapped = readonly(original)
|
||||
expect(wrapped).not.toBe(original)
|
||||
expect(isProxy(wrapped)).toBe(true)
|
||||
@ -228,7 +231,10 @@ describe('reactivity/readonly', () => {
|
||||
test('should retrieve readonly values on iteration', () => {
|
||||
const key1 = {}
|
||||
const key2 = {}
|
||||
const original = new Map([[key1, {}], [key2, {}]])
|
||||
const original = new Map([
|
||||
[key1, {}],
|
||||
[key2, {}]
|
||||
])
|
||||
const wrapped: any = readonly(original)
|
||||
expect(wrapped.size).toBe(2)
|
||||
for (const [key, value] of wrapped) {
|
||||
@ -246,7 +252,12 @@ describe('reactivity/readonly', () => {
|
||||
test('should retrieve reactive + readonly values on iteration', () => {
|
||||
const key1 = {}
|
||||
const key2 = {}
|
||||
const original = reactive(new Map([[key1, {}], [key2, {}]]))
|
||||
const original = reactive(
|
||||
new Map([
|
||||
[key1, {}],
|
||||
[key2, {}]
|
||||
])
|
||||
)
|
||||
const wrapped: any = readonly(original)
|
||||
expect(wrapped.size).toBe(2)
|
||||
for (const [key, value] of wrapped) {
|
||||
|
@ -49,7 +49,7 @@ function createArrayInstrumentations() {
|
||||
// instrument identity-sensitive Array methods to account for possible reactive
|
||||
// values
|
||||
;(['includes', 'indexOf', 'lastIndexOf'] as const).forEach(key => {
|
||||
instrumentations[key] = function(this: unknown[], ...args: unknown[]) {
|
||||
instrumentations[key] = function (this: unknown[], ...args: unknown[]) {
|
||||
const arr = toRaw(this) as any
|
||||
for (let i = 0, l = this.length; i < l; i++) {
|
||||
track(arr, TrackOpTypes.GET, i + '')
|
||||
@ -67,7 +67,7 @@ function createArrayInstrumentations() {
|
||||
// instrument length-altering mutation methods to avoid length being tracked
|
||||
// which leads to infinite loops in some cases (#2137)
|
||||
;(['push', 'pop', 'shift', 'unshift', 'splice'] as const).forEach(key => {
|
||||
instrumentations[key] = function(this: unknown[], ...args: unknown[]) {
|
||||
instrumentations[key] = function (this: unknown[], ...args: unknown[]) {
|
||||
pauseTracking()
|
||||
const res = (toRaw(this) as any)[key].apply(this, args)
|
||||
resetTracking()
|
||||
@ -91,8 +91,8 @@ function createGetter(isReadonly = false, shallow = false) {
|
||||
? shallowReadonlyMap
|
||||
: readonlyMap
|
||||
: shallow
|
||||
? shallowReactiveMap
|
||||
: reactiveMap
|
||||
? shallowReactiveMap
|
||||
: reactiveMap
|
||||
).get(target)
|
||||
) {
|
||||
return target
|
||||
|
@ -184,7 +184,7 @@ function createIterableMethod(
|
||||
isReadonly: boolean,
|
||||
isShallow: boolean
|
||||
) {
|
||||
return function(
|
||||
return function (
|
||||
this: IterableCollections,
|
||||
...args: unknown[]
|
||||
): Iterable & Iterator {
|
||||
@ -224,7 +224,7 @@ function createIterableMethod(
|
||||
}
|
||||
|
||||
function createReadonlyMethod(type: TriggerOpTypes): Function {
|
||||
return function(this: CollectionTypes, ...args: unknown[]) {
|
||||
return function (this: CollectionTypes, ...args: unknown[]) {
|
||||
if (__DEV__) {
|
||||
const key = args[0] ? `on key "${args[0]}" ` : ``
|
||||
console.warn(
|
||||
@ -242,7 +242,7 @@ function createInstrumentations() {
|
||||
return get(this, key)
|
||||
},
|
||||
get size() {
|
||||
return size((this as unknown) as IterableCollections)
|
||||
return size(this as unknown as IterableCollections)
|
||||
},
|
||||
has,
|
||||
add,
|
||||
@ -257,7 +257,7 @@ function createInstrumentations() {
|
||||
return get(this, key, false, true)
|
||||
},
|
||||
get size() {
|
||||
return size((this as unknown) as IterableCollections)
|
||||
return size(this as unknown as IterableCollections)
|
||||
},
|
||||
has,
|
||||
add,
|
||||
@ -272,7 +272,7 @@ function createInstrumentations() {
|
||||
return get(this, key, true)
|
||||
},
|
||||
get size() {
|
||||
return size((this as unknown) as IterableCollections, true)
|
||||
return size(this as unknown as IterableCollections, true)
|
||||
},
|
||||
has(this: MapTypes, key: unknown) {
|
||||
return has.call(this, key, true)
|
||||
@ -289,7 +289,7 @@ function createInstrumentations() {
|
||||
return get(this, key, true, true)
|
||||
},
|
||||
get size() {
|
||||
return size((this as unknown) as IterableCollections, true)
|
||||
return size(this as unknown as IterableCollections, true)
|
||||
},
|
||||
has(this: MapTypes, key: unknown) {
|
||||
return has.call(this, key, true)
|
||||
@ -346,8 +346,8 @@ function createInstrumentationGetter(isReadonly: boolean, shallow: boolean) {
|
||||
? shallowReadonlyInstrumentations
|
||||
: shallowInstrumentations
|
||||
: isReadonly
|
||||
? readonlyInstrumentations
|
||||
: mutableInstrumentations
|
||||
? readonlyInstrumentations
|
||||
: mutableInstrumentations
|
||||
|
||||
return (
|
||||
target: CollectionTypes,
|
||||
@ -384,11 +384,10 @@ export const readonlyCollectionHandlers: ProxyHandler<CollectionTypes> = {
|
||||
get: /*#__PURE__*/ createInstrumentationGetter(true, false)
|
||||
}
|
||||
|
||||
export const shallowReadonlyCollectionHandlers: ProxyHandler<
|
||||
CollectionTypes
|
||||
> = {
|
||||
get: /*#__PURE__*/ createInstrumentationGetter(true, true)
|
||||
}
|
||||
export const shallowReadonlyCollectionHandlers: ProxyHandler<CollectionTypes> =
|
||||
{
|
||||
get: /*#__PURE__*/ createInstrumentationGetter(true, true)
|
||||
}
|
||||
|
||||
function checkIdentityKeys(
|
||||
target: CollectionTypes,
|
||||
|
@ -37,7 +37,7 @@ class ComputedRefImpl<T> {
|
||||
private _dirty = true
|
||||
public readonly effect: ReactiveEffect<T>
|
||||
|
||||
public readonly __v_isRef = true;
|
||||
public readonly __v_isRef = true
|
||||
public readonly [ReactiveFlags.IS_READONLY]: boolean
|
||||
|
||||
constructor(
|
||||
|
@ -119,22 +119,22 @@ type Builtin = Primitive | Function | Date | Error | RegExp
|
||||
export type DeepReadonly<T> = T extends Builtin
|
||||
? T
|
||||
: T extends Map<infer K, infer V>
|
||||
? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>>
|
||||
: T extends ReadonlyMap<infer K, infer V>
|
||||
? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>>
|
||||
: T extends WeakMap<infer K, infer V>
|
||||
? WeakMap<DeepReadonly<K>, DeepReadonly<V>>
|
||||
: T extends Set<infer U>
|
||||
? ReadonlySet<DeepReadonly<U>>
|
||||
: T extends ReadonlySet<infer U>
|
||||
? ReadonlySet<DeepReadonly<U>>
|
||||
: T extends WeakSet<infer U>
|
||||
? WeakSet<DeepReadonly<U>>
|
||||
: T extends Promise<infer U>
|
||||
? Promise<DeepReadonly<U>>
|
||||
: T extends {}
|
||||
? { readonly [K in keyof T]: DeepReadonly<T[K]> }
|
||||
: Readonly<T>
|
||||
? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>>
|
||||
: T extends ReadonlyMap<infer K, infer V>
|
||||
? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>>
|
||||
: T extends WeakMap<infer K, infer V>
|
||||
? WeakMap<DeepReadonly<K>, DeepReadonly<V>>
|
||||
: T extends Set<infer U>
|
||||
? ReadonlySet<DeepReadonly<U>>
|
||||
: T extends ReadonlySet<infer U>
|
||||
? ReadonlySet<DeepReadonly<U>>
|
||||
: T extends WeakSet<infer U>
|
||||
? WeakSet<DeepReadonly<U>>
|
||||
: T extends Promise<infer U>
|
||||
? Promise<DeepReadonly<U>>
|
||||
: T extends {}
|
||||
? { readonly [K in keyof T]: DeepReadonly<T[K]> }
|
||||
: Readonly<T>
|
||||
|
||||
/**
|
||||
* Creates a readonly copy of the original object. Note the returned copy is not
|
||||
|
@ -259,8 +259,10 @@ export type ShallowUnwrapRef<T> = {
|
||||
[K in keyof T]: T[K] extends Ref<infer V>
|
||||
? V
|
||||
: T[K] extends Ref<infer V> | undefined // if `V` is `unknown` that means it does not extend `Ref` and is undefined
|
||||
? unknown extends V ? undefined : V | undefined
|
||||
: T[K]
|
||||
? unknown extends V
|
||||
? undefined
|
||||
: V | undefined
|
||||
: T[K]
|
||||
}
|
||||
|
||||
export type UnwrapRef<T> = T extends Ref<infer V>
|
||||
@ -275,8 +277,10 @@ type UnwrapRefSimple<T> = T extends
|
||||
| RefUnwrapBailTypes[keyof RefUnwrapBailTypes]
|
||||
? T
|
||||
: T extends Array<any>
|
||||
? { [K in keyof T]: UnwrapRefSimple<T[K]> }
|
||||
: T extends object ? UnwrappedObject<T> : T
|
||||
? { [K in keyof T]: UnwrapRefSimple<T[K]> }
|
||||
: T extends object
|
||||
? UnwrappedObject<T>
|
||||
: T
|
||||
|
||||
// Extract all known symbols from an object
|
||||
// when unwrapping Object the symbols are not `in keyof`, this should cover all the
|
||||
|
@ -123,15 +123,16 @@ describe('SFC <script setup> helpers', () => {
|
||||
|
||||
beforeInstance = getCurrentInstance()
|
||||
|
||||
const msg = (([__temp, __restore] = withAsyncContext(
|
||||
() =>
|
||||
new Promise(r => {
|
||||
resolve = r
|
||||
})
|
||||
)),
|
||||
(__temp = await __temp),
|
||||
__restore(),
|
||||
__temp)
|
||||
const msg =
|
||||
(([__temp, __restore] = withAsyncContext(
|
||||
() =>
|
||||
new Promise(r => {
|
||||
resolve = r
|
||||
})
|
||||
)),
|
||||
(__temp = await __temp),
|
||||
__restore(),
|
||||
__temp)
|
||||
|
||||
// register the lifecycle after an await statement
|
||||
onMounted(spy)
|
||||
@ -141,7 +142,10 @@ describe('SFC <script setup> helpers', () => {
|
||||
})
|
||||
|
||||
const root = nodeOps.createElement('div')
|
||||
render(h(() => h(Suspense, () => h(Comp))), root)
|
||||
render(
|
||||
h(() => h(Suspense, () => h(Comp))),
|
||||
root
|
||||
)
|
||||
|
||||
expect(spy).not.toHaveBeenCalled()
|
||||
resolve!('hello')
|
||||
@ -186,7 +190,10 @@ describe('SFC <script setup> helpers', () => {
|
||||
})
|
||||
|
||||
const root = nodeOps.createElement('div')
|
||||
render(h(() => h(Suspense, () => h(Comp))), root)
|
||||
render(
|
||||
h(() => h(Suspense, () => h(Comp))),
|
||||
root
|
||||
)
|
||||
|
||||
expect(spy).not.toHaveBeenCalled()
|
||||
reject!()
|
||||
@ -242,7 +249,10 @@ describe('SFC <script setup> helpers', () => {
|
||||
})
|
||||
|
||||
const root = nodeOps.createElement('div')
|
||||
render(h(() => h(Suspense, () => h(Comp))), root)
|
||||
render(
|
||||
h(() => h(Suspense, () => h(Comp))),
|
||||
root
|
||||
)
|
||||
|
||||
await ready
|
||||
expect(inBandInstance).toBe(beforeInstance)
|
||||
|
@ -115,8 +115,8 @@ describe('api: template refs', () => {
|
||||
const fn = jest.fn()
|
||||
const toggle = ref(true)
|
||||
|
||||
const Comp = defineComponent(() => () =>
|
||||
toggle.value ? h('div', { ref: fn }) : null
|
||||
const Comp = defineComponent(
|
||||
() => () => toggle.value ? h('div', { ref: fn }) : null
|
||||
)
|
||||
render(h(Comp), root)
|
||||
expect(fn.mock.calls[0][0]).toBe(root.children[0])
|
||||
|
@ -168,7 +168,10 @@ describe('api: watch', () => {
|
||||
state.count++
|
||||
count.value++
|
||||
await nextTick()
|
||||
expect(dummy).toMatchObject([[2, 2, 3], [1, 1, 2]])
|
||||
expect(dummy).toMatchObject([
|
||||
[2, 2, 3],
|
||||
[1, 1, 2]
|
||||
])
|
||||
})
|
||||
|
||||
it('watching multiple sources: readonly array', async () => {
|
||||
@ -188,7 +191,10 @@ describe('api: watch', () => {
|
||||
state.count++
|
||||
status.value = true
|
||||
await nextTick()
|
||||
expect(dummy).toMatchObject([[2, true], [1, false]])
|
||||
expect(dummy).toMatchObject([
|
||||
[2, true],
|
||||
[1, false]
|
||||
])
|
||||
})
|
||||
|
||||
it('watching multiple sources: reactive object (with automatic deep: true)', async () => {
|
||||
@ -568,7 +574,10 @@ describe('api: watch', () => {
|
||||
count: ref(0)
|
||||
},
|
||||
array: [1, 2, 3],
|
||||
map: new Map([['a', 1], ['b', 2]]),
|
||||
map: new Map([
|
||||
['a', 1],
|
||||
['b', 2]
|
||||
]),
|
||||
set: new Set([1, 2, 3])
|
||||
})
|
||||
|
||||
@ -868,7 +877,10 @@ describe('api: watch', () => {
|
||||
mounted() {
|
||||
// this call runs while Comp is currentInstance, but
|
||||
// the effect for this `$watch` should nontheless be registered with Child
|
||||
this.comp!.$watch(() => this.show, () => void 0)
|
||||
this.comp!.$watch(
|
||||
() => this.show,
|
||||
() => void 0
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
@ -895,7 +907,7 @@ describe('api: watch', () => {
|
||||
render() {},
|
||||
created(this: any) {
|
||||
instance = this
|
||||
this.$watch(source, function() {})
|
||||
this.$watch(source, function () {})
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -97,7 +97,7 @@ describe('component: proxy', () => {
|
||||
expect(() => (instanceProxy.$data = {})).toThrow(TypeError)
|
||||
expect(`Attempting to mutate public property "$data"`).toHaveBeenWarned()
|
||||
|
||||
const nextTickThis = await instanceProxy.$nextTick(function(this: any) {
|
||||
const nextTickThis = await instanceProxy.$nextTick(function (this: any) {
|
||||
return this
|
||||
})
|
||||
expect(nextTickThis).toBe(instanceProxy)
|
||||
|
@ -258,9 +258,8 @@ describe('BaseTransition', () => {
|
||||
) {
|
||||
const toggle = ref(true)
|
||||
const { props, cbs } = mockProps({ mode })
|
||||
const root = mount(
|
||||
props,
|
||||
() => (toggle.value ? trueBranch() : falseBranch())
|
||||
const root = mount(props, () =>
|
||||
toggle.value ? trueBranch() : falseBranch()
|
||||
)
|
||||
|
||||
// without appear: true, enter hooks should not be called on mount
|
||||
@ -348,9 +347,8 @@ describe('BaseTransition', () => {
|
||||
}: ToggleOptions) {
|
||||
const toggle = ref(false)
|
||||
const { props, cbs } = mockProps()
|
||||
const root = mount(
|
||||
props,
|
||||
() => (toggle.value ? trueBranch() : falseBranch())
|
||||
const root = mount(props, () =>
|
||||
toggle.value ? trueBranch() : falseBranch()
|
||||
)
|
||||
|
||||
// start enter
|
||||
|
@ -841,10 +841,8 @@ describe('KeepAlive', () => {
|
||||
const instanceRef = ref<any>(null)
|
||||
const App = {
|
||||
render: () => {
|
||||
return h(
|
||||
KeepAlive,
|
||||
{ include: 'Foo' },
|
||||
() => (toggle.value ? h(AsyncComp, { ref: instanceRef }) : null)
|
||||
return h(KeepAlive, { include: 'Foo' }, () =>
|
||||
toggle.value ? h(AsyncComp, { ref: instanceRef }) : null
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +106,10 @@ describe('renderer: teleport', () => {
|
||||
const root = nodeOps.createElement('div')
|
||||
const children = ref([h('div', 'teleported')])
|
||||
|
||||
render(h(() => h(Teleport, { to: target }, children.value)), root)
|
||||
render(
|
||||
h(() => h(Teleport, { to: target }, children.value)),
|
||||
root
|
||||
)
|
||||
expect(serializeInner(target)).toMatchInlineSnapshot(
|
||||
`"<div>teleported</div>"`
|
||||
)
|
||||
|
@ -42,7 +42,10 @@ describe('createSlot', () => {
|
||||
it('should add each slot to the record when given slot is an array', () => {
|
||||
const dynamicSlot = [
|
||||
{ name: 'descriptor', fn: slot },
|
||||
[{ name: 'descriptor2', fn: slot }, { name: 'descriptor3', fn: slot }]
|
||||
[
|
||||
{ name: 'descriptor2', fn: slot },
|
||||
{ name: 'descriptor3', fn: slot }
|
||||
]
|
||||
]
|
||||
|
||||
const actual = createSlots(record, dynamicSlot)
|
||||
|
@ -38,7 +38,7 @@ describe('renderList', () => {
|
||||
})
|
||||
|
||||
it('should render an item for entry in an iterable', () => {
|
||||
const iterable = function*() {
|
||||
const iterable = function* () {
|
||||
yield 1
|
||||
yield 2
|
||||
yield 3
|
||||
|
@ -759,9 +759,11 @@ describe('SSR hydration', () => {
|
||||
})
|
||||
|
||||
expect(
|
||||
(app.mount(svgContainer).$.subTree as VNode<Node, Element> & {
|
||||
el: Element
|
||||
}).el instanceof SVGElement
|
||||
(
|
||||
app.mount(svgContainer).$.subTree as VNode<Node, Element> & {
|
||||
el: Element
|
||||
}
|
||||
).el instanceof SVGElement
|
||||
)
|
||||
})
|
||||
|
||||
|
@ -321,21 +321,28 @@ describe('renderer: keyed children', () => {
|
||||
}
|
||||
|
||||
for (let n = 0; n < samples; ++n) {
|
||||
render(h('span', arr.map(n => spanNumWithOpacity(n, '1'))), root)
|
||||
render(
|
||||
h(
|
||||
'span',
|
||||
arr.map(n => spanNumWithOpacity(n, '1'))
|
||||
),
|
||||
root
|
||||
)
|
||||
elm = root.children[0] as TestElement
|
||||
|
||||
for (let i = 0; i < elms; ++i) {
|
||||
expect(serializeInner(elm.children[i] as TestElement)).toBe(
|
||||
i.toString()
|
||||
)
|
||||
opacities[i] = Math.random()
|
||||
.toFixed(5)
|
||||
.toString()
|
||||
opacities[i] = Math.random().toFixed(5).toString()
|
||||
}
|
||||
|
||||
const shufArr = shuffle(arr.slice(0))
|
||||
render(
|
||||
h('span', arr.map(n => spanNumWithOpacity(shufArr[n], opacities[n]))),
|
||||
h(
|
||||
'span',
|
||||
arr.map(n => spanNumWithOpacity(shufArr[n], opacities[n]))
|
||||
),
|
||||
root
|
||||
)
|
||||
elm = root.children[0] as TestElement
|
||||
|
@ -217,7 +217,10 @@ describe('renderer: component', () => {
|
||||
const Child = {
|
||||
props: ['value'],
|
||||
setup(props: any, { emit }: SetupContext) {
|
||||
watch(() => props.value, (val: number) => emit('update', val))
|
||||
watch(
|
||||
() => props.value,
|
||||
(val: number) => emit('update', val)
|
||||
)
|
||||
|
||||
return () => {
|
||||
return h('div', props.value)
|
||||
|
@ -417,11 +417,12 @@ describe('renderer: optimized mode', () => {
|
||||
const Comp = defineComponent({
|
||||
setup(_props, { slots }) {
|
||||
return () => {
|
||||
const vnode = (openBlock(),
|
||||
(block = createBlock('div', null, {
|
||||
default: withCtx(() => [renderSlot(slots, 'default')]),
|
||||
_: SlotFlags.FORWARDED
|
||||
})))
|
||||
const vnode =
|
||||
(openBlock(),
|
||||
(block = createBlock('div', null, {
|
||||
default: withCtx(() => [renderSlot(slots, 'default')]),
|
||||
_: SlotFlags.FORWARDED
|
||||
})))
|
||||
|
||||
return vnode
|
||||
}
|
||||
@ -449,8 +450,9 @@ describe('renderer: optimized mode', () => {
|
||||
expect(block!.dynamicChildren![0].type).toBe(Fragment)
|
||||
expect(block!.dynamicChildren![0].dynamicChildren!.length).toBe(1)
|
||||
expect(
|
||||
serialize(block!.dynamicChildren![0].dynamicChildren![0]
|
||||
.el as TestElement)
|
||||
serialize(
|
||||
block!.dynamicChildren![0].dynamicChildren![0].el as TestElement
|
||||
)
|
||||
).toBe('<p>0</p>')
|
||||
|
||||
foo.value++
|
||||
|
@ -226,7 +226,7 @@ describe('backwards compat with <=3.0.7', () => {
|
||||
test('should work on slots', () => {
|
||||
const Child = {
|
||||
__scopeId: 'child',
|
||||
render: withChildId(function(this: any) {
|
||||
render: withChildId(function (this: any) {
|
||||
return h('div', renderSlot(this.$slots, 'default'))
|
||||
})
|
||||
}
|
||||
|
@ -411,9 +411,9 @@ describe('vnode', () => {
|
||||
})
|
||||
|
||||
test('handlers', () => {
|
||||
let clickHandler1 = function() {}
|
||||
let clickHandler2 = function() {}
|
||||
let focusHandler2 = function() {}
|
||||
let clickHandler1 = function () {}
|
||||
let clickHandler2 = function () {}
|
||||
let focusHandler2 = function () {}
|
||||
|
||||
let props1: Data = { onClick: clickHandler1 }
|
||||
let props2: Data = { onClick: clickHandler2, onFocus: focusHandler2 }
|
||||
@ -439,37 +439,41 @@ describe('vnode', () => {
|
||||
test('with patchFlags', () => {
|
||||
const hoist = createVNode('div')
|
||||
let vnode1
|
||||
const vnode = (openBlock(),
|
||||
createBlock('div', null, [
|
||||
hoist,
|
||||
(vnode1 = createVNode('div', null, 'text', PatchFlags.TEXT))
|
||||
]))
|
||||
const vnode =
|
||||
(openBlock(),
|
||||
createBlock('div', null, [
|
||||
hoist,
|
||||
(vnode1 = createVNode('div', null, 'text', PatchFlags.TEXT))
|
||||
]))
|
||||
expect(vnode.dynamicChildren).toStrictEqual([vnode1])
|
||||
})
|
||||
|
||||
test('should not track vnodes with only HYDRATE_EVENTS flag', () => {
|
||||
const hoist = createVNode('div')
|
||||
const vnode = (openBlock(),
|
||||
createBlock('div', null, [
|
||||
hoist,
|
||||
createVNode('div', null, 'text', PatchFlags.HYDRATE_EVENTS)
|
||||
]))
|
||||
const vnode =
|
||||
(openBlock(),
|
||||
createBlock('div', null, [
|
||||
hoist,
|
||||
createVNode('div', null, 'text', PatchFlags.HYDRATE_EVENTS)
|
||||
]))
|
||||
expect(vnode.dynamicChildren).toStrictEqual([])
|
||||
})
|
||||
|
||||
test('many times call openBlock', () => {
|
||||
const hoist = createVNode('div')
|
||||
let vnode1, vnode2, vnode3
|
||||
const vnode = (openBlock(),
|
||||
createBlock('div', null, [
|
||||
hoist,
|
||||
(vnode1 = createVNode('div', null, 'text', PatchFlags.TEXT)),
|
||||
(vnode2 = (openBlock(),
|
||||
const vnode =
|
||||
(openBlock(),
|
||||
createBlock('div', null, [
|
||||
hoist,
|
||||
(vnode3 = createVNode('div', null, 'text', PatchFlags.TEXT))
|
||||
])))
|
||||
]))
|
||||
(vnode1 = createVNode('div', null, 'text', PatchFlags.TEXT)),
|
||||
(vnode2 =
|
||||
(openBlock(),
|
||||
createBlock('div', null, [
|
||||
hoist,
|
||||
(vnode3 = createVNode('div', null, 'text', PatchFlags.TEXT))
|
||||
])))
|
||||
]))
|
||||
expect(vnode.dynamicChildren).toStrictEqual([vnode1, vnode2])
|
||||
expect(vnode2.dynamicChildren).toStrictEqual([vnode3])
|
||||
})
|
||||
@ -477,33 +481,36 @@ describe('vnode', () => {
|
||||
test('with stateful component', () => {
|
||||
const hoist = createVNode('div')
|
||||
let vnode1
|
||||
const vnode = (openBlock(),
|
||||
createBlock('div', null, [
|
||||
hoist,
|
||||
(vnode1 = createVNode({}, null, 'text'))
|
||||
]))
|
||||
const vnode =
|
||||
(openBlock(),
|
||||
createBlock('div', null, [
|
||||
hoist,
|
||||
(vnode1 = createVNode({}, null, 'text'))
|
||||
]))
|
||||
expect(vnode.dynamicChildren).toStrictEqual([vnode1])
|
||||
})
|
||||
|
||||
test('with functional component', () => {
|
||||
const hoist = createVNode('div')
|
||||
let vnode1
|
||||
const vnode = (openBlock(),
|
||||
createBlock('div', null, [
|
||||
hoist,
|
||||
(vnode1 = createVNode(() => {}, null, 'text'))
|
||||
]))
|
||||
const vnode =
|
||||
(openBlock(),
|
||||
createBlock('div', null, [
|
||||
hoist,
|
||||
(vnode1 = createVNode(() => {}, null, 'text'))
|
||||
]))
|
||||
expect(vnode.dynamicChildren).toStrictEqual([vnode1])
|
||||
})
|
||||
|
||||
test('with suspense', () => {
|
||||
const hoist = createVNode('div')
|
||||
let vnode1
|
||||
const vnode = (openBlock(),
|
||||
createBlock('div', null, [
|
||||
hoist,
|
||||
(vnode1 = createVNode(() => {}, null, 'text'))
|
||||
]))
|
||||
const vnode =
|
||||
(openBlock(),
|
||||
createBlock('div', null, [
|
||||
hoist,
|
||||
(vnode1 = createVNode(() => {}, null, 'text'))
|
||||
]))
|
||||
expect(vnode.dynamicChildren).toStrictEqual([vnode1])
|
||||
})
|
||||
|
||||
@ -516,32 +523,35 @@ describe('vnode', () => {
|
||||
test('element block should track normalized slot children', () => {
|
||||
const hoist = createVNode('div')
|
||||
let vnode1: any
|
||||
const vnode = (openBlock(),
|
||||
createBlock('div', null, {
|
||||
default: () => {
|
||||
return [
|
||||
hoist,
|
||||
(vnode1 = createVNode('div', null, 'text', PatchFlags.TEXT))
|
||||
]
|
||||
}
|
||||
}))
|
||||
const vnode =
|
||||
(openBlock(),
|
||||
createBlock('div', null, {
|
||||
default: () => {
|
||||
return [
|
||||
hoist,
|
||||
(vnode1 = createVNode('div', null, 'text', PatchFlags.TEXT))
|
||||
]
|
||||
}
|
||||
}))
|
||||
expect(vnode.dynamicChildren).toStrictEqual([vnode1])
|
||||
})
|
||||
|
||||
test('openBlock w/ disableTracking: true', () => {
|
||||
const hoist = createVNode('div')
|
||||
let vnode1
|
||||
const vnode = (openBlock(),
|
||||
createBlock('div', null, [
|
||||
// a v-for fragment block generated by the compiler
|
||||
// disables tracking because it always diffs its
|
||||
// children.
|
||||
(vnode1 = (openBlock(true),
|
||||
createBlock(Fragment, null, [
|
||||
hoist,
|
||||
/*vnode2*/ createVNode(() => {}, null, 'text')
|
||||
])))
|
||||
]))
|
||||
const vnode =
|
||||
(openBlock(),
|
||||
createBlock('div', null, [
|
||||
// a v-for fragment block generated by the compiler
|
||||
// disables tracking because it always diffs its
|
||||
// children.
|
||||
(vnode1 =
|
||||
(openBlock(true),
|
||||
createBlock(Fragment, null, [
|
||||
hoist,
|
||||
/*vnode2*/ createVNode(() => {}, null, 'text')
|
||||
])))
|
||||
]))
|
||||
expect(vnode.dynamicChildren).toStrictEqual([vnode1])
|
||||
expect(vnode1.dynamicChildren).toStrictEqual([])
|
||||
})
|
||||
@ -549,27 +559,30 @@ describe('vnode', () => {
|
||||
test('openBlock without disableTracking: true', () => {
|
||||
const hoist = createVNode('div')
|
||||
let vnode1, vnode2
|
||||
const vnode = (openBlock(),
|
||||
createBlock('div', null, [
|
||||
(vnode1 = (openBlock(),
|
||||
createBlock(Fragment, null, [
|
||||
hoist,
|
||||
(vnode2 = createVNode(() => {}, null, 'text'))
|
||||
])))
|
||||
]))
|
||||
const vnode =
|
||||
(openBlock(),
|
||||
createBlock('div', null, [
|
||||
(vnode1 =
|
||||
(openBlock(),
|
||||
createBlock(Fragment, null, [
|
||||
hoist,
|
||||
(vnode2 = createVNode(() => {}, null, 'text'))
|
||||
])))
|
||||
]))
|
||||
expect(vnode.dynamicChildren).toStrictEqual([vnode1])
|
||||
expect(vnode1.dynamicChildren).toStrictEqual([vnode2])
|
||||
})
|
||||
|
||||
test('should not track openBlock() when tracking is disabled', () => {
|
||||
let vnode1
|
||||
const vnode = (openBlock(),
|
||||
createBlock('div', null, [
|
||||
setBlockTracking(-1),
|
||||
(vnode1 = (openBlock(), createBlock('div'))),
|
||||
setBlockTracking(1),
|
||||
vnode1
|
||||
]))
|
||||
const vnode =
|
||||
(openBlock(),
|
||||
createBlock('div', null, [
|
||||
setBlockTracking(-1),
|
||||
(vnode1 = (openBlock(), createBlock('div'))),
|
||||
setBlockTracking(1),
|
||||
vnode1
|
||||
]))
|
||||
expect(vnode.dynamicChildren).toStrictEqual([])
|
||||
})
|
||||
})
|
||||
|
@ -71,42 +71,43 @@ export function defineAsyncComponent<
|
||||
let thisRequest: Promise<ConcreteComponent>
|
||||
return (
|
||||
pendingRequest ||
|
||||
(thisRequest = pendingRequest = loader()
|
||||
.catch(err => {
|
||||
err = err instanceof Error ? err : new Error(String(err))
|
||||
if (userOnError) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const userRetry = () => resolve(retry())
|
||||
const userFail = () => reject(err)
|
||||
userOnError(err, userRetry, userFail, retries + 1)
|
||||
})
|
||||
} else {
|
||||
throw err
|
||||
}
|
||||
})
|
||||
.then((comp: any) => {
|
||||
if (thisRequest !== pendingRequest && pendingRequest) {
|
||||
return pendingRequest
|
||||
}
|
||||
if (__DEV__ && !comp) {
|
||||
warn(
|
||||
`Async component loader resolved to undefined. ` +
|
||||
`If you are using retry(), make sure to return its return value.`
|
||||
)
|
||||
}
|
||||
// interop module default
|
||||
if (
|
||||
comp &&
|
||||
(comp.__esModule || comp[Symbol.toStringTag] === 'Module')
|
||||
) {
|
||||
comp = comp.default
|
||||
}
|
||||
if (__DEV__ && comp && !isObject(comp) && !isFunction(comp)) {
|
||||
throw new Error(`Invalid async component load result: ${comp}`)
|
||||
}
|
||||
resolvedComp = comp
|
||||
return comp
|
||||
}))
|
||||
(thisRequest = pendingRequest =
|
||||
loader()
|
||||
.catch(err => {
|
||||
err = err instanceof Error ? err : new Error(String(err))
|
||||
if (userOnError) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const userRetry = () => resolve(retry())
|
||||
const userFail = () => reject(err)
|
||||
userOnError(err, userRetry, userFail, retries + 1)
|
||||
})
|
||||
} else {
|
||||
throw err
|
||||
}
|
||||
})
|
||||
.then((comp: any) => {
|
||||
if (thisRequest !== pendingRequest && pendingRequest) {
|
||||
return pendingRequest
|
||||
}
|
||||
if (__DEV__ && !comp) {
|
||||
warn(
|
||||
`Async component loader resolved to undefined. ` +
|
||||
`If you are using retry(), make sure to return its return value.`
|
||||
)
|
||||
}
|
||||
// interop module default
|
||||
if (
|
||||
comp &&
|
||||
(comp.__esModule || comp[Symbol.toStringTag] === 'Module')
|
||||
) {
|
||||
comp = comp.default
|
||||
}
|
||||
if (__DEV__ && comp && !isObject(comp) && !isFunction(comp)) {
|
||||
throw new Error(`Invalid async component load result: ${comp}`)
|
||||
}
|
||||
resolvedComp = comp
|
||||
return comp
|
||||
}))
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ export interface AppContext {
|
||||
type PluginInstallFunction = (app: App, ...options: any[]) => any
|
||||
|
||||
export type Plugin =
|
||||
| PluginInstallFunction & { install?: PluginInstallFunction }
|
||||
| (PluginInstallFunction & { install?: PluginInstallFunction })
|
||||
| {
|
||||
install: PluginInstallFunction
|
||||
}
|
||||
|
@ -63,12 +63,12 @@ export function injectHook(
|
||||
}
|
||||
}
|
||||
|
||||
export const createHook = <T extends Function = () => any>(
|
||||
lifecycle: LifecycleHooks
|
||||
) => (hook: T, target: ComponentInternalInstance | null = currentInstance) =>
|
||||
// post-create lifecycle registrations are noops during SSR (except for serverPrefetch)
|
||||
(!isInSSRComponentSetup || lifecycle === LifecycleHooks.SERVER_PREFETCH) &&
|
||||
injectHook(lifecycle, hook, target)
|
||||
export const createHook =
|
||||
<T extends Function = () => any>(lifecycle: LifecycleHooks) =>
|
||||
(hook: T, target: ComponentInternalInstance | null = currentInstance) =>
|
||||
// post-create lifecycle registrations are noops during SSR (except for serverPrefetch)
|
||||
(!isInSSRComponentSetup || lifecycle === LifecycleHooks.SERVER_PREFETCH) &&
|
||||
injectHook(lifecycle, hook, target)
|
||||
|
||||
export const onBeforeMount = createHook(LifecycleHooks.BEFORE_MOUNT)
|
||||
export const onMounted = createHook(LifecycleHooks.MOUNTED)
|
||||
|
@ -130,12 +130,12 @@ export function defineExpose(exposed?: Record<string, any>) {
|
||||
type NotUndefined<T> = T extends undefined ? never : T
|
||||
|
||||
type InferDefaults<T> = {
|
||||
[K in keyof T]?: NotUndefined<T[K]> extends (
|
||||
[K in keyof T]?: NotUndefined<T[K]> extends
|
||||
| number
|
||||
| string
|
||||
| boolean
|
||||
| symbol
|
||||
| Function)
|
||||
| Function
|
||||
? NotUndefined<T[K]>
|
||||
: (props: T) => NotUndefined<T[K]>
|
||||
}
|
||||
|
@ -50,10 +50,14 @@ export type WatchCallback<V = any, OV = any> = (
|
||||
|
||||
type MapSources<T, Immediate> = {
|
||||
[K in keyof T]: T[K] extends WatchSource<infer V>
|
||||
? Immediate extends true ? (V | undefined) : V
|
||||
? Immediate extends true
|
||||
? V | undefined
|
||||
: V
|
||||
: T[K] extends object
|
||||
? Immediate extends true ? (T[K] | undefined) : T[K]
|
||||
: never
|
||||
? Immediate extends true
|
||||
? T[K] | undefined
|
||||
: T[K]
|
||||
: never
|
||||
}
|
||||
|
||||
type InvalidateCbRegistrator = (cb: () => void) => void
|
||||
@ -81,9 +85,13 @@ export function watchPostEffect(
|
||||
effect: WatchEffect,
|
||||
options?: DebuggerOptions
|
||||
) {
|
||||
return doWatch(effect, null, (__DEV__
|
||||
? Object.assign(options || {}, { flush: 'post' })
|
||||
: { flush: 'post' }) as WatchOptionsBase)
|
||||
return doWatch(
|
||||
effect,
|
||||
null,
|
||||
(__DEV__
|
||||
? Object.assign(options || {}, { flush: 'post' })
|
||||
: { flush: 'post' }) as WatchOptionsBase
|
||||
)
|
||||
}
|
||||
|
||||
// initial value for watchers to trigger on undefined initial values
|
||||
@ -116,7 +124,7 @@ export function watch<
|
||||
// overload: single source + cb
|
||||
export function watch<T, Immediate extends Readonly<boolean> = false>(
|
||||
source: WatchSource<T>,
|
||||
cb: WatchCallback<T, Immediate extends true ? (T | undefined) : T>,
|
||||
cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
|
||||
options?: WatchOptions<Immediate>
|
||||
): WatchStopHandle
|
||||
|
||||
@ -126,7 +134,7 @@ export function watch<
|
||||
Immediate extends Readonly<boolean> = false
|
||||
>(
|
||||
source: T,
|
||||
cb: WatchCallback<T, Immediate extends true ? (T | undefined) : T>,
|
||||
cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
|
||||
options?: WatchOptions<Immediate>
|
||||
): WatchStopHandle
|
||||
|
||||
|
@ -238,8 +238,9 @@ export const deprecationData: Record<DeprecationTypes, DeprecationData> = {
|
||||
|
||||
[DeprecationTypes.INSTANCE_ATTRS_CLASS_STYLE]: {
|
||||
message: componentName =>
|
||||
`Component <${componentName ||
|
||||
'Anonymous'}> has \`inheritAttrs: false\` but is ` +
|
||||
`Component <${
|
||||
componentName || 'Anonymous'
|
||||
}> has \`inheritAttrs: false\` but is ` +
|
||||
`relying on class/style fallthrough from parent. In Vue 3, class/style ` +
|
||||
`are now included in $attrs and will no longer fallthrough when ` +
|
||||
`inheritAttrs is false. If you are already using v-bind="$attrs" on ` +
|
||||
@ -317,9 +318,7 @@ export const deprecationData: Record<DeprecationTypes, DeprecationData> = {
|
||||
`${name}="false" instead of removing it in Vue 3. To remove the attribute, ` +
|
||||
`use \`null\` or \`undefined\` instead. If the usage is intended, ` +
|
||||
`you can disable the compat behavior and suppress this warning with:` +
|
||||
`\n\n configureCompat({ ${
|
||||
DeprecationTypes.ATTR_FALSE_VALUE
|
||||
}: false })\n`,
|
||||
`\n\n configureCompat({ ${DeprecationTypes.ATTR_FALSE_VALUE}: false })\n`,
|
||||
link: `https://v3.vuejs.org/guide/migration/attribute-coercion.html`
|
||||
},
|
||||
|
||||
@ -332,9 +331,7 @@ export const deprecationData: Record<DeprecationTypes, DeprecationData> = {
|
||||
`Always use explicit "true" or "false" values for enumerated attributes. ` +
|
||||
`If the usage is intended, ` +
|
||||
`you can disable the compat behavior and suppress this warning with:` +
|
||||
`\n\n configureCompat({ ${
|
||||
DeprecationTypes.ATTR_ENUMERATED_COERCION
|
||||
}: false })\n`,
|
||||
`\n\n configureCompat({ ${DeprecationTypes.ATTR_ENUMERATED_COERCION}: false })\n`,
|
||||
link: `https://v3.vuejs.org/guide/migration/attribute-coercion.html`
|
||||
},
|
||||
|
||||
@ -348,9 +345,7 @@ export const deprecationData: Record<DeprecationTypes, DeprecationData> = {
|
||||
`default if no "tag" prop is specified. If you do not rely on the span ` +
|
||||
`for styling, you can disable the compat behavior and suppress this ` +
|
||||
`warning with:` +
|
||||
`\n\n configureCompat({ ${
|
||||
DeprecationTypes.TRANSITION_GROUP_ROOT
|
||||
}: false })\n`,
|
||||
`\n\n configureCompat({ ${DeprecationTypes.TRANSITION_GROUP_ROOT}: false })\n`,
|
||||
link: `https://v3.vuejs.org/guide/migration/transition-group.html`
|
||||
},
|
||||
|
||||
@ -366,9 +361,7 @@ export const deprecationData: Record<DeprecationTypes, DeprecationData> = {
|
||||
`usage and intend to use plain functions for functional components, ` +
|
||||
`you can disable the compat behavior and suppress this ` +
|
||||
`warning with:` +
|
||||
`\n\n configureCompat({ ${
|
||||
DeprecationTypes.COMPONENT_ASYNC
|
||||
}: false })\n`
|
||||
`\n\n configureCompat({ ${DeprecationTypes.COMPONENT_ASYNC}: false })\n`
|
||||
)
|
||||
},
|
||||
link: `https://v3.vuejs.org/guide/migration/async-components.html`
|
||||
@ -394,9 +387,7 @@ export const deprecationData: Record<DeprecationTypes, DeprecationData> = {
|
||||
message: (comp: ComponentOptions) => {
|
||||
const configMsg =
|
||||
`opt-in to ` +
|
||||
`Vue 3 behavior on a per-component basis with \`compatConfig: { ${
|
||||
DeprecationTypes.COMPONENT_V_MODEL
|
||||
}: false }\`.`
|
||||
`Vue 3 behavior on a per-component basis with \`compatConfig: { ${DeprecationTypes.COMPONENT_V_MODEL}: false }\`.`
|
||||
if (
|
||||
comp.props &&
|
||||
(isArray(comp.props)
|
||||
@ -421,9 +412,7 @@ export const deprecationData: Record<DeprecationTypes, DeprecationData> = {
|
||||
message:
|
||||
`Vue 3's render function API has changed. ` +
|
||||
`You can opt-in to the new API with:` +
|
||||
`\n\n configureCompat({ ${
|
||||
DeprecationTypes.RENDER_FUNCTION
|
||||
}: false })\n` +
|
||||
`\n\n configureCompat({ ${DeprecationTypes.RENDER_FUNCTION}: false })\n` +
|
||||
`\n (This can also be done per-component via the "compatConfig" option.)`,
|
||||
link: `https://v3.vuejs.org/guide/migration/render-function-api.html`
|
||||
},
|
||||
@ -565,9 +554,7 @@ export function validateCompatConfig(
|
||||
|
||||
if (instance && config[DeprecationTypes.OPTIONS_DATA_MERGE] != null) {
|
||||
warn(
|
||||
`Deprecation config "${
|
||||
DeprecationTypes.OPTIONS_DATA_MERGE
|
||||
}" can only be configured globally.`
|
||||
`Deprecation config "${DeprecationTypes.OPTIONS_DATA_MERGE}" can only be configured globally.`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -251,8 +251,8 @@ export function createCompatVue(
|
||||
mergeBase[key] = isArray(superValue)
|
||||
? superValue.slice()
|
||||
: isObject(superValue)
|
||||
? extend(Object.create(null), superValue)
|
||||
: superValue
|
||||
? extend(Object.create(null), superValue)
|
||||
: superValue
|
||||
}
|
||||
|
||||
SubVue.options = mergeOptions(
|
||||
|
@ -177,7 +177,7 @@ const skipLegacyRootLevelProps = /*#__PURE__*/ makeMap(
|
||||
function convertLegacyProps(
|
||||
legacyProps: LegacyVNodeProps | undefined,
|
||||
type: any
|
||||
): Data & VNodeProps | null {
|
||||
): (Data & VNodeProps) | null {
|
||||
if (!legacyProps) {
|
||||
return null
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ export function legacyBindObjectProps(
|
||||
|
||||
if (isSync) {
|
||||
const on = data.on || (data.on = {})
|
||||
on[`update:${key}`] = function($event: any) {
|
||||
on[`update:${key}`] = function ($event: any) {
|
||||
value[key] = $event
|
||||
}
|
||||
}
|
||||
|
@ -761,10 +761,8 @@ export function finishComponentSetup(
|
||||
startMeasure(instance, `compile`)
|
||||
}
|
||||
const { isCustomElement, compilerOptions } = instance.appContext.config
|
||||
const {
|
||||
delimiters,
|
||||
compilerOptions: componentCompilerOptions
|
||||
} = Component
|
||||
const { delimiters, compilerOptions: componentCompilerOptions } =
|
||||
Component
|
||||
const finalCompilerOptions: CompilerOptions = extend(
|
||||
extend(
|
||||
{
|
||||
@ -822,10 +820,10 @@ export function finishComponentSetup(
|
||||
(__ESM_BUNDLER__
|
||||
? ` Configure your bundler to alias "vue" to "vue/dist/vue.esm-bundler.js".`
|
||||
: __ESM_BROWSER__
|
||||
? ` Use "vue.esm-browser.js" instead.`
|
||||
: __GLOBAL__
|
||||
? ` Use "vue.global.js" instead.`
|
||||
: ``) /* should not happen */
|
||||
? ` Use "vue.esm-browser.js" instead.`
|
||||
: __GLOBAL__
|
||||
? ` Use "vue.global.js" instead.`
|
||||
: ``) /* should not happen */
|
||||
)
|
||||
} else {
|
||||
warn(`Component is missing template or render function.`)
|
||||
|
@ -77,7 +77,9 @@ type RequiredKeys<T> = {
|
||||
// don't mark Boolean props as undefined
|
||||
| BooleanConstructor
|
||||
| { type: BooleanConstructor }
|
||||
? T[K] extends { default: undefined | (() => undefined) } ? never : K
|
||||
? T[K] extends { default: undefined | (() => undefined) }
|
||||
? never
|
||||
: K
|
||||
: never
|
||||
}[keyof T]
|
||||
|
||||
@ -98,16 +100,18 @@ type DefaultKeys<T> = {
|
||||
type InferPropType<T> = [T] extends [null]
|
||||
? any // null & true would fail to infer
|
||||
: [T] extends [{ type: null | true }]
|
||||
? any // As TS issue https://github.com/Microsoft/TypeScript/issues/14829 // somehow `ObjectConstructor` when inferred from { (): T } becomes `any` // `BooleanConstructor` when inferred from PropConstructor(with PropMethod) becomes `Boolean`
|
||||
: [T] extends [ObjectConstructor | { type: ObjectConstructor }]
|
||||
? Record<string, any>
|
||||
: [T] extends [BooleanConstructor | { type: BooleanConstructor }]
|
||||
? boolean
|
||||
: [T] extends [DateConstructor | { type: DateConstructor }]
|
||||
? Date
|
||||
: [T] extends [Prop<infer V, infer D>]
|
||||
? (unknown extends V ? D : V)
|
||||
: T
|
||||
? any // As TS issue https://github.com/Microsoft/TypeScript/issues/14829 // somehow `ObjectConstructor` when inferred from { (): T } becomes `any` // `BooleanConstructor` when inferred from PropConstructor(with PropMethod) becomes `Boolean`
|
||||
: [T] extends [ObjectConstructor | { type: ObjectConstructor }]
|
||||
? Record<string, any>
|
||||
: [T] extends [BooleanConstructor | { type: BooleanConstructor }]
|
||||
? boolean
|
||||
: [T] extends [DateConstructor | { type: DateConstructor }]
|
||||
? Date
|
||||
: [T] extends [Prop<infer V, infer D>]
|
||||
? unknown extends V
|
||||
? D
|
||||
: V
|
||||
: T
|
||||
|
||||
export type ExtractPropTypes<O> = O extends object
|
||||
? { [K in keyof O]?: unknown } & // This is needed to keep the relation between the option prop and the props, allowing to use ctrl+click to navigate to the prop options. see: #3656
|
||||
@ -407,7 +411,7 @@ function resolvePropValue(
|
||||
setCurrentInstance(instance)
|
||||
value = propsDefaults[key] = defaultValue.call(
|
||||
__COMPAT__ &&
|
||||
isCompatEnabled(DeprecationTypes.PROPS_DEFAULT_THIS, instance)
|
||||
isCompatEnabled(DeprecationTypes.PROPS_DEFAULT_THIS, instance)
|
||||
? createPropsDefaultThis(instance, props, key)
|
||||
: null,
|
||||
props
|
||||
|
@ -72,7 +72,9 @@ import { installCompatInstanceProperties } from './compat/instance'
|
||||
export interface ComponentCustomProperties {}
|
||||
|
||||
type IsDefaultMixinComponent<T> = T extends ComponentOptionsMixin
|
||||
? ComponentOptionsMixin extends T ? true : false
|
||||
? ComponentOptionsMixin extends T
|
||||
? true
|
||||
: false
|
||||
: false
|
||||
|
||||
type MixinToOptionTypes<T> = T extends ComponentOptionsBase<
|
||||
@ -261,15 +263,8 @@ export interface ComponentRenderContext {
|
||||
|
||||
export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
|
||||
get({ _: instance }: ComponentRenderContext, key: string) {
|
||||
const {
|
||||
ctx,
|
||||
setupState,
|
||||
data,
|
||||
props,
|
||||
accessCache,
|
||||
type,
|
||||
appContext
|
||||
} = instance
|
||||
const { ctx, setupState, data, props, accessCache, type, appContext } =
|
||||
instance
|
||||
|
||||
// for internal formatters to know that this is a Vue instance
|
||||
if (__DEV__ && key === '__isVue') {
|
||||
|
@ -257,7 +257,7 @@ if (__COMPAT__) {
|
||||
|
||||
// export the public type for h/tsx inference
|
||||
// also to avoid inline import() in generated d.ts files
|
||||
export const BaseTransition = (BaseTransitionImpl as any) as {
|
||||
export const BaseTransition = BaseTransitionImpl as any as {
|
||||
new (): {
|
||||
$props: BaseTransitionProps<any>
|
||||
}
|
||||
|
@ -329,7 +329,7 @@ if (__COMPAT__) {
|
||||
|
||||
// export the public type for h/tsx inference
|
||||
// also to avoid inline import() in generated d.ts files
|
||||
export const KeepAlive = (KeepAliveImpl as any) as {
|
||||
export const KeepAlive = KeepAliveImpl as any as {
|
||||
__isKeepAlive: true
|
||||
new (): {
|
||||
$props: VNodeProps & KeepAliveProps
|
||||
|
@ -87,9 +87,7 @@ export const SuspenseImpl = {
|
||||
}
|
||||
|
||||
// Force-casted public typing for h and TSX props inference
|
||||
export const Suspense = ((__FEATURE_SUSPENSE__
|
||||
? SuspenseImpl
|
||||
: null) as any) as {
|
||||
export const Suspense = (__FEATURE_SUSPENSE__ ? SuspenseImpl : null) as any as {
|
||||
__isSuspense: true
|
||||
new (): { $props: VNodeProps & SuspenseProps }
|
||||
}
|
||||
@ -520,13 +518,8 @@ function createSuspenseBoundary(
|
||||
return
|
||||
}
|
||||
|
||||
const {
|
||||
vnode,
|
||||
activeBranch,
|
||||
parentComponent,
|
||||
container,
|
||||
isSVG
|
||||
} = suspense
|
||||
const { vnode, activeBranch, parentComponent, container, isSVG } =
|
||||
suspense
|
||||
|
||||
// invoke @fallback event
|
||||
triggerEvent(vnode, 'onFallback')
|
||||
|
@ -371,7 +371,7 @@ function hydrateTeleport(
|
||||
}
|
||||
|
||||
// Force-casted public typing for h and TSX props inference
|
||||
export const Teleport = (TeleportImpl as any) as {
|
||||
export const Teleport = TeleportImpl as any as {
|
||||
__isTeleport: true
|
||||
new (): { $props: VNodeProps & TeleportProps }
|
||||
}
|
||||
|
@ -54,13 +54,11 @@ export const devtoolsComponentAdded = /*#__PURE__*/ createDevtoolsComponentHook(
|
||||
DevtoolsHooks.COMPONENT_ADDED
|
||||
)
|
||||
|
||||
export const devtoolsComponentUpdated = /*#__PURE__*/ createDevtoolsComponentHook(
|
||||
DevtoolsHooks.COMPONENT_UPDATED
|
||||
)
|
||||
export const devtoolsComponentUpdated =
|
||||
/*#__PURE__*/ createDevtoolsComponentHook(DevtoolsHooks.COMPONENT_UPDATED)
|
||||
|
||||
export const devtoolsComponentRemoved = /*#__PURE__*/ createDevtoolsComponentHook(
|
||||
DevtoolsHooks.COMPONENT_REMOVED
|
||||
)
|
||||
export const devtoolsComponentRemoved =
|
||||
/*#__PURE__*/ createDevtoolsComponentHook(DevtoolsHooks.COMPONENT_REMOVED)
|
||||
|
||||
function createDevtoolsComponentHook(hook: DevtoolsHooks) {
|
||||
return (component: ComponentInternalInstance) => {
|
||||
|
@ -15,7 +15,8 @@ export function createSlots(
|
||||
dynamicSlots: (
|
||||
| CompiledSlotDescriptor
|
||||
| CompiledSlotDescriptor[]
|
||||
| undefined)[]
|
||||
| undefined
|
||||
)[]
|
||||
): Record<string, Slot> {
|
||||
for (let i = 0; i < dynamicSlots.length; i++) {
|
||||
const slot = dynamicSlots[i]
|
||||
|
@ -1,6 +1,6 @@
|
||||
export type UnionToIntersection<U> = (U extends any
|
||||
? (k: U) => void
|
||||
: never) extends ((k: infer I) => void)
|
||||
export type UnionToIntersection<U> = (
|
||||
U extends any ? (k: U) => void : never
|
||||
) extends (k: infer I) => void
|
||||
? I
|
||||
: never
|
||||
|
||||
|
@ -31,10 +31,10 @@ if (__DEV__) {
|
||||
typeof global !== 'undefined'
|
||||
? global
|
||||
: typeof self !== 'undefined'
|
||||
? self
|
||||
: typeof window !== 'undefined'
|
||||
? window
|
||||
: {}
|
||||
? self
|
||||
: typeof window !== 'undefined'
|
||||
? window
|
||||
: {}
|
||||
|
||||
globalObject.__VUE_HMR_RUNTIME__ = {
|
||||
createRecord: tryWrap(createRecord),
|
||||
|
@ -280,8 +280,8 @@ export function createHydrationFunctions(
|
||||
if (
|
||||
forcePatchValue ||
|
||||
!optimized ||
|
||||
(patchFlag & PatchFlags.FULL_PROPS ||
|
||||
patchFlag & PatchFlags.HYDRATE_EVENTS)
|
||||
patchFlag & PatchFlags.FULL_PROPS ||
|
||||
patchFlag & PatchFlags.HYDRATE_EVENTS
|
||||
) {
|
||||
for (const key in props) {
|
||||
if (
|
||||
@ -346,7 +346,9 @@ export function createHydrationFunctions(
|
||||
hasMismatch = true
|
||||
__DEV__ &&
|
||||
warn(
|
||||
`Hydration text content mismatch in <${vnode.type as string}>:\n` +
|
||||
`Hydration text content mismatch in <${
|
||||
vnode.type as string
|
||||
}>:\n` +
|
||||
`- Client: ${el.textContent}\n` +
|
||||
`- Server: ${vnode.children as string}`
|
||||
)
|
||||
@ -465,8 +467,8 @@ export function createHydrationFunctions(
|
||||
node.nodeType === DOMNodeTypes.TEXT
|
||||
? `(text)`
|
||||
: isComment(node) && node.data === '['
|
||||
? `(start of fragment)`
|
||||
: ``
|
||||
? `(start of fragment)`
|
||||
: ``
|
||||
)
|
||||
vnode.el = null
|
||||
|
||||
|
@ -341,9 +341,9 @@ const _compatUtils = {
|
||||
/**
|
||||
* @internal only exposed in compat builds.
|
||||
*/
|
||||
export const compatUtils = (__COMPAT__
|
||||
? _compatUtils
|
||||
: null) as typeof _compatUtils
|
||||
export const compatUtils = (
|
||||
__COMPAT__ ? _compatUtils : null
|
||||
) as typeof _compatUtils
|
||||
|
||||
// Ref macros ------------------------------------------------------------------
|
||||
// for dts generation only
|
||||
|
@ -1444,7 +1444,7 @@ function baseCreateRenderer(
|
||||
}
|
||||
|
||||
if (isAsyncWrapper(initialVNode)) {
|
||||
(initialVNode.type as ComponentOptions).__asyncLoader!().then(
|
||||
;(initialVNode.type as ComponentOptions).__asyncLoader!().then(
|
||||
// note: we are moving the render call into an async callback,
|
||||
// which means it won't track dependencies - but it's ok because
|
||||
// a server-rendered async wrapper is already in resolved state
|
||||
@ -2406,10 +2406,9 @@ function baseCreateRenderer(
|
||||
let hydrate: ReturnType<typeof createHydrationFunctions>[0] | undefined
|
||||
let hydrateNode: ReturnType<typeof createHydrationFunctions>[1] | undefined
|
||||
if (createHydrationFns) {
|
||||
;[hydrate, hydrateNode] = createHydrationFns(internals as RendererInternals<
|
||||
Node,
|
||||
Element
|
||||
>)
|
||||
;[hydrate, hydrateNode] = createHydrationFns(
|
||||
internals as RendererInternals<Node, Element>
|
||||
)
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -44,7 +44,7 @@ import { convertLegacyVModelProps } from './compat/componentVModel'
|
||||
import { defineLegacyVNodeProperties } from './compat/renderFn'
|
||||
import { convertLegacyRefInFor } from './compat/ref'
|
||||
|
||||
export const Fragment = (Symbol(__DEV__ ? 'Fragment' : undefined) as any) as {
|
||||
export const Fragment = Symbol(__DEV__ ? 'Fragment' : undefined) as any as {
|
||||
__isFragment: true
|
||||
new (): {
|
||||
$props: VNodeProps
|
||||
@ -78,7 +78,7 @@ export type VNodeNormalizedRefAtom = {
|
||||
|
||||
export type VNodeNormalizedRef =
|
||||
| VNodeNormalizedRefAtom
|
||||
| (VNodeNormalizedRefAtom)[]
|
||||
| VNodeNormalizedRefAtom[]
|
||||
|
||||
type VNodeMountHook = (vnode: VNode) => void
|
||||
type VNodeUpdateHook = (vnode: VNode, oldVNode: VNode) => void
|
||||
@ -381,11 +381,13 @@ const normalizeKey = ({ key }: VNodeProps): VNode['key'] =>
|
||||
key != null ? key : null
|
||||
|
||||
const normalizeRef = ({ ref }: VNodeProps): VNodeNormalizedRefAtom | null => {
|
||||
return (ref != null
|
||||
? isString(ref) || isRef(ref) || isFunction(ref)
|
||||
? { i: currentRenderingInstance, r: ref }
|
||||
: ref
|
||||
: null) as any
|
||||
return (
|
||||
ref != null
|
||||
? isString(ref) || isRef(ref) || isFunction(ref)
|
||||
? { i: currentRenderingInstance, r: ref }
|
||||
: ref
|
||||
: null
|
||||
) as any
|
||||
}
|
||||
|
||||
function createBaseVNode(
|
||||
@ -475,9 +477,9 @@ function createBaseVNode(
|
||||
|
||||
export { createBaseVNode as createElementVNode }
|
||||
|
||||
export const createVNode = (__DEV__
|
||||
? createVNodeWithArgsTransform
|
||||
: _createVNode) as typeof _createVNode
|
||||
export const createVNode = (
|
||||
__DEV__ ? createVNodeWithArgsTransform : _createVNode
|
||||
) as typeof _createVNode
|
||||
|
||||
function _createVNode(
|
||||
type: VNodeTypes | ClassComponent | typeof NULL_DYNAMIC_COMPONENT,
|
||||
@ -537,14 +539,14 @@ function _createVNode(
|
||||
const shapeFlag = isString(type)
|
||||
? ShapeFlags.ELEMENT
|
||||
: __FEATURE_SUSPENSE__ && isSuspense(type)
|
||||
? ShapeFlags.SUSPENSE
|
||||
: isTeleport(type)
|
||||
? ShapeFlags.TELEPORT
|
||||
: isObject(type)
|
||||
? ShapeFlags.STATEFUL_COMPONENT
|
||||
: isFunction(type)
|
||||
? ShapeFlags.FUNCTIONAL_COMPONENT
|
||||
: 0
|
||||
? ShapeFlags.SUSPENSE
|
||||
: isTeleport(type)
|
||||
? ShapeFlags.TELEPORT
|
||||
: isObject(type)
|
||||
? ShapeFlags.STATEFUL_COMPONENT
|
||||
: isFunction(type)
|
||||
? ShapeFlags.FUNCTIONAL_COMPONENT
|
||||
: 0
|
||||
|
||||
if (__DEV__ && shapeFlag & ShapeFlags.STATEFUL_COMPONENT && isProxy(type)) {
|
||||
type = toRaw(type)
|
||||
@ -579,7 +581,7 @@ export function guardReactiveProps(props: (Data & VNodeProps) | null) {
|
||||
|
||||
export function cloneVNode<T, U>(
|
||||
vnode: VNode<T, U>,
|
||||
extraProps?: Data & VNodeProps | null,
|
||||
extraProps?: (Data & VNodeProps) | null,
|
||||
mergeRef = false
|
||||
): VNode<T, U> {
|
||||
// This is intentionally NOT using spread or extend to avoid the runtime
|
||||
|
@ -17,7 +17,7 @@ const triggerEvent = (type: string, el: Element) => {
|
||||
const withVModel = (node: VNode, arg: any, mods?: any) =>
|
||||
withDirectives(node, [[vModelDynamic, arg, '', mods]])
|
||||
|
||||
const setValue = function(this: any, value: any) {
|
||||
const setValue = function (this: any, value: any) {
|
||||
this.value = value
|
||||
}
|
||||
|
||||
|
@ -41,9 +41,9 @@ describe('runtime-dom: v-on directive', () => {
|
||||
})
|
||||
|
||||
test('it should support key modifiers and system modifiers', () => {
|
||||
const keyNames = ["ctrl","shift","meta","alt"]
|
||||
const keyNames = ['ctrl', 'shift', 'meta', 'alt']
|
||||
|
||||
keyNames.forEach(keyName=>{
|
||||
keyNames.forEach(keyName => {
|
||||
const el = document.createElement('div')
|
||||
const fn = jest.fn()
|
||||
// <div @keyup[keyName].esc="test"/>
|
||||
@ -52,28 +52,28 @@ describe('runtime-dom: v-on directive', () => {
|
||||
'arrow-left'
|
||||
])
|
||||
patchEvent(el, 'onKeyup', null, nextValue, null)
|
||||
|
||||
|
||||
triggerEvent(el, 'keyup', e => (e.key = 'a'))
|
||||
expect(fn).not.toBeCalled()
|
||||
|
||||
|
||||
triggerEvent(el, 'keyup', e => {
|
||||
e[`${keyName}Key`] = false
|
||||
e.key = 'esc'
|
||||
})
|
||||
expect(fn).not.toBeCalled()
|
||||
|
||||
|
||||
triggerEvent(el, 'keyup', e => {
|
||||
e[`${keyName}Key`] = true
|
||||
e.key = 'Escape'
|
||||
})
|
||||
expect(fn).toBeCalledTimes(1)
|
||||
|
||||
|
||||
triggerEvent(el, 'keyup', e => {
|
||||
e[`${keyName}Key`] = true
|
||||
e.key = 'ArrowLeft'
|
||||
})
|
||||
expect(fn).toBeCalledTimes(2)
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
test('it should support "exact" modifier', () => {
|
||||
@ -114,9 +114,11 @@ describe('runtime-dom: v-on directive', () => {
|
||||
const fn = jest.fn()
|
||||
const handler = withModifiers(fn, [button])
|
||||
patchEvent(el, 'onMousedown', null, handler, null)
|
||||
buttons.filter(b => b !== button).forEach(button => {
|
||||
triggerEvent(el, 'mousedown', e => (e.button = buttonCodes[button]))
|
||||
})
|
||||
buttons
|
||||
.filter(b => b !== button)
|
||||
.forEach(button => {
|
||||
triggerEvent(el, 'mousedown', e => (e.button = buttonCodes[button]))
|
||||
})
|
||||
expect(fn).not.toBeCalled()
|
||||
triggerEvent(el, 'mousedown', e => (e.button = buttonCodes[button]))
|
||||
expect(fn).toBeCalled()
|
||||
|
@ -155,10 +155,8 @@ describe('useCssVars', () => {
|
||||
setup() {
|
||||
useCssVars(() => state)
|
||||
return () =>
|
||||
h(
|
||||
Child,
|
||||
null,
|
||||
() => (value.value ? [h('div')] : [h('div'), h('div')])
|
||||
h(Child, null, () =>
|
||||
value.value ? [h('div')] : [h('div'), h('div')]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -157,9 +157,9 @@ export const defineSSRCustomElement = ((options: any) => {
|
||||
return defineCustomElement(options, hydrate)
|
||||
}) as typeof defineCustomElement
|
||||
|
||||
const BaseClass = (typeof HTMLElement !== 'undefined'
|
||||
? HTMLElement
|
||||
: class {}) as typeof HTMLElement
|
||||
const BaseClass = (
|
||||
typeof HTMLElement !== 'undefined' ? HTMLElement : class {}
|
||||
) as typeof HTMLElement
|
||||
|
||||
export class VueElement extends BaseClass {
|
||||
/**
|
||||
|
@ -69,11 +69,12 @@ const DOMTransitionPropsValidators = {
|
||||
leaveToClass: String
|
||||
}
|
||||
|
||||
export const TransitionPropsValidators = (Transition.props = /*#__PURE__*/ extend(
|
||||
{},
|
||||
(BaseTransition as any).props,
|
||||
DOMTransitionPropsValidators
|
||||
))
|
||||
export const TransitionPropsValidators = (Transition.props =
|
||||
/*#__PURE__*/ extend(
|
||||
{},
|
||||
(BaseTransition as any).props,
|
||||
DOMTransitionPropsValidators
|
||||
))
|
||||
|
||||
/**
|
||||
* #3227 Incoming hooks may be merged into arrays when wrapping Transition
|
||||
|
@ -159,7 +159,7 @@ if (__COMPAT__) {
|
||||
const removeMode = (props: any) => delete props.mode
|
||||
/*#__PURE__*/ removeMode(TransitionGroupImpl.props)
|
||||
|
||||
export const TransitionGroup = (TransitionGroupImpl as unknown) as {
|
||||
export const TransitionGroup = TransitionGroupImpl as unknown as {
|
||||
new (): {
|
||||
$props: TransitionGroupProps
|
||||
}
|
||||
@ -210,9 +210,9 @@ function hasCSSTransform(
|
||||
}
|
||||
moveClass.split(/\s+/).forEach(c => c && clone.classList.add(c))
|
||||
clone.style.display = 'none'
|
||||
const container = (root.nodeType === 1
|
||||
? root
|
||||
: root.parentNode) as HTMLElement
|
||||
const container = (
|
||||
root.nodeType === 1 ? root : root.parentNode
|
||||
) as HTMLElement
|
||||
container.appendChild(clone)
|
||||
const { hasTransform } = getTransitionInfo(clone)
|
||||
container.removeChild(clone)
|
||||
|
@ -181,9 +181,8 @@ export const vModelSelect: ModelDirective<HTMLSelectElement> = {
|
||||
addEventListener(el, 'change', () => {
|
||||
const selectedVal = Array.prototype.filter
|
||||
.call(el.options, (o: HTMLOptionElement) => o.selected)
|
||||
.map(
|
||||
(o: HTMLOptionElement) =>
|
||||
number ? toNumber(getValue(o)) : getValue(o)
|
||||
.map((o: HTMLOptionElement) =>
|
||||
number ? toNumber(getValue(o)) : getValue(o)
|
||||
)
|
||||
el._assign(
|
||||
el.multiple
|
||||
|
@ -66,7 +66,7 @@ export const withKeys = (fn: Function, modifiers: string[]) => {
|
||||
compatUtils.isCompatEnabled(DeprecationTypes.CONFIG_KEY_CODES, instance)
|
||||
) {
|
||||
if (instance) {
|
||||
globalKeyCodes = ((instance.appContext.config as any) as LegacyConfig)
|
||||
globalKeyCodes = (instance.appContext.config as any as LegacyConfig)
|
||||
.keyCodes
|
||||
}
|
||||
}
|
||||
|
@ -52,8 +52,8 @@ export function compatCoerceAttr(
|
||||
value === null
|
||||
? 'false'
|
||||
: typeof value !== 'boolean' && value !== undefined
|
||||
? 'true'
|
||||
: null
|
||||
? 'true'
|
||||
: null
|
||||
if (
|
||||
v2CocercedValue &&
|
||||
compatUtils.softAssertCompatEnabled(
|
||||
|
@ -8,9 +8,8 @@ export function patchClass(el: Element, value: string | null, isSVG: boolean) {
|
||||
// classes into account.
|
||||
const transitionClasses = (el as ElementWithTransition)._vtc
|
||||
if (transitionClasses) {
|
||||
value = (value
|
||||
? [value, ...transitionClasses]
|
||||
: [...transitionClasses]
|
||||
value = (
|
||||
value ? [value, ...transitionClasses] : [...transitionClasses]
|
||||
).join(' ')
|
||||
}
|
||||
if (value == null) {
|
||||
|
@ -37,8 +37,8 @@ export const patchProp: DOMRendererOptions['patchProp'] = (
|
||||
key[0] === '.'
|
||||
? ((key = key.slice(1)), true)
|
||||
: key[0] === '^'
|
||||
? ((key = key.slice(1)), false)
|
||||
: shouldSetAsProp(el, key, nextValue, isSVG)
|
||||
? ((key = key.slice(1)), false)
|
||||
: shouldSetAsProp(el, key, nextValue, isSVG)
|
||||
) {
|
||||
patchDOMProp(
|
||||
el,
|
||||
|
@ -43,8 +43,8 @@ function serializeElement(
|
||||
return isOn(key) || value == null
|
||||
? ``
|
||||
: value === ``
|
||||
? key
|
||||
: `${key}=${JSON.stringify(value)}`
|
||||
? key
|
||||
: `${key}=${JSON.stringify(value)}`
|
||||
})
|
||||
.filter(Boolean)
|
||||
.join(' ')
|
||||
|
@ -721,7 +721,7 @@ function testRender(type: string, render: typeof renderToString) {
|
||||
test('with client-compiled vnode slots', async () => {
|
||||
const Child = {
|
||||
__scopeId: 'data-v-child',
|
||||
render: function(this: any) {
|
||||
render: function (this: any) {
|
||||
return h('div', null, [renderSlot(this.$slots, 'default')])
|
||||
}
|
||||
}
|
||||
@ -1069,7 +1069,7 @@ function testRender(type: string, render: typeof renderToString) {
|
||||
renderError = e
|
||||
}
|
||||
expect(renderError).toBe(null)
|
||||
expect(((capturedError as unknown) as Error).message).toBe('An error')
|
||||
expect((capturedError as unknown as Error).message).toBe('An error')
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ describe('ssr: renderList', () => {
|
||||
})
|
||||
|
||||
it('should render an item for entry in an iterable', () => {
|
||||
const iterable = function*() {
|
||||
const iterable = function* () {
|
||||
yield 1
|
||||
yield 2
|
||||
yield 3
|
||||
|
@ -26,9 +26,7 @@ export function ssrCompile(
|
||||
isNativeTag: instance.appContext.config.isNativeTag || NO,
|
||||
onError(err: CompilerError) {
|
||||
if (__DEV__) {
|
||||
const message = `[@vue/server-renderer] Template compilation error: ${
|
||||
err.message
|
||||
}`
|
||||
const message = `[@vue/server-renderer] Template compilation error: ${err.message}`
|
||||
const codeFrame =
|
||||
err.loc &&
|
||||
generateCodeFrame(
|
||||
|
@ -17,9 +17,7 @@ export function ssrRenderDynamicModel(
|
||||
case 'radio':
|
||||
return looseEqual(model, value) ? ' checked' : ''
|
||||
case 'checkbox':
|
||||
return (isArray(model)
|
||||
? ssrLooseContain(model, value)
|
||||
: model)
|
||||
return (isArray(model) ? ssrLooseContain(model, value) : model)
|
||||
? ' checked'
|
||||
: ''
|
||||
default:
|
||||
@ -38,9 +36,7 @@ export function ssrGetDynamicModelProps(
|
||||
case 'radio':
|
||||
return looseEqual(model, value) ? { checked: true } : null
|
||||
case 'checkbox':
|
||||
return (isArray(model)
|
||||
? ssrLooseContain(model, value)
|
||||
: model)
|
||||
return (isArray(model) ? ssrLooseContain(model, value) : model)
|
||||
? { checked: true }
|
||||
: null
|
||||
default:
|
||||
|
@ -74,9 +74,9 @@ async function resolveTeleports(context: SSRContext) {
|
||||
for (const key in context.__teleportBuffers) {
|
||||
// note: it's OK to await sequentially here because the Promises were
|
||||
// created eagerly in parallel.
|
||||
context.teleports[key] = await unrollBuffer((await Promise.all(
|
||||
context.__teleportBuffers[key]
|
||||
)) as SSRBuffer)
|
||||
context.teleports[key] = await unrollBuffer(
|
||||
(await Promise.all(context.__teleportBuffers[key])) as SSRBuffer
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -217,12 +217,7 @@ async function doCompileScript(
|
||||
|
||||
return [code, compiledScript.bindings]
|
||||
} catch (e) {
|
||||
store.errors = [
|
||||
e.stack
|
||||
.split('\n')
|
||||
.slice(0, 12)
|
||||
.join('\n')
|
||||
]
|
||||
store.errors = [e.stack.split('\n').slice(0, 12).join('\n')]
|
||||
return
|
||||
}
|
||||
} else {
|
||||
|
@ -54,27 +54,27 @@ describe('utils/looseEqual', () => {
|
||||
const date2 = new Date(2019, 1, 2, 3, 4, 5, 7)
|
||||
const file1 = new File([''], 'filename.txt', {
|
||||
type: 'text/plain',
|
||||
lastModified: date1.getTime(),
|
||||
lastModified: date1.getTime()
|
||||
})
|
||||
const file2 = new File([''], 'filename.txt', {
|
||||
type: 'text/plain',
|
||||
lastModified: date1.getTime(),
|
||||
lastModified: date1.getTime()
|
||||
})
|
||||
const file3 = new File([''], 'filename.txt', {
|
||||
type: 'text/plain',
|
||||
lastModified: date2.getTime(),
|
||||
lastModified: date2.getTime()
|
||||
})
|
||||
const file4 = new File([''], 'filename.csv', {
|
||||
type: 'text/csv',
|
||||
lastModified: date1.getTime(),
|
||||
lastModified: date1.getTime()
|
||||
})
|
||||
const file5 = new File(['abcdef'], 'filename.txt', {
|
||||
type: 'text/plain',
|
||||
lastModified: date1.getTime(),
|
||||
lastModified: date1.getTime()
|
||||
})
|
||||
const file6 = new File(['12345'], 'filename.txt', {
|
||||
type: 'text/plain',
|
||||
lastModified: date1.getTime(),
|
||||
lastModified: date1.getTime()
|
||||
})
|
||||
|
||||
// Identical file object references
|
||||
@ -163,7 +163,7 @@ describe('utils/looseEqual', () => {
|
||||
const date1 = new Date(2019, 1, 2, 3, 4, 5, 6)
|
||||
const file1 = new File([''], 'filename.txt', {
|
||||
type: 'text/plain',
|
||||
lastModified: date1.getTime(),
|
||||
lastModified: date1.getTime()
|
||||
})
|
||||
|
||||
expect(looseEqual(123, '123')).toBe(true)
|
||||
|
@ -6,7 +6,9 @@ describe('normalizeClass', () => {
|
||||
})
|
||||
|
||||
test('handles array correctly', () => {
|
||||
expect(normalizeClass(['foo', undefined, true, false, 'bar'])).toEqual('foo bar')
|
||||
expect(normalizeClass(['foo', undefined, true, false, 'bar'])).toEqual(
|
||||
'foo bar'
|
||||
)
|
||||
})
|
||||
|
||||
test('handles object correctly', () => {
|
||||
|
@ -113,11 +113,9 @@ const camelizeRE = /-(\w)/g
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
export const camelize = cacheStringFunction(
|
||||
(str: string): string => {
|
||||
return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''))
|
||||
}
|
||||
)
|
||||
export const camelize = cacheStringFunction((str: string): string => {
|
||||
return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''))
|
||||
})
|
||||
|
||||
const hyphenateRE = /\B([A-Z])/g
|
||||
/**
|
||||
@ -137,8 +135,8 @@ export const capitalize = cacheStringFunction(
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
export const toHandlerKey = cacheStringFunction(
|
||||
(str: string) => (str ? `on${capitalize(str)}` : ``)
|
||||
export const toHandlerKey = cacheStringFunction((str: string) =>
|
||||
str ? `on${capitalize(str)}` : ``
|
||||
)
|
||||
|
||||
// compare whether a value has changed, accounting for NaN.
|
||||
@ -172,11 +170,11 @@ export const getGlobalThis = (): any => {
|
||||
typeof globalThis !== 'undefined'
|
||||
? globalThis
|
||||
: typeof self !== 'undefined'
|
||||
? self
|
||||
: typeof window !== 'undefined'
|
||||
? window
|
||||
: typeof global !== 'undefined'
|
||||
? global
|
||||
: {})
|
||||
? self
|
||||
: typeof window !== 'undefined'
|
||||
? window
|
||||
: typeof global !== 'undefined'
|
||||
? global
|
||||
: {})
|
||||
)
|
||||
}
|
||||
|
@ -8,8 +8,8 @@ export const toDisplayString = (val: unknown): string => {
|
||||
return val == null
|
||||
? ''
|
||||
: isObject(val)
|
||||
? JSON.stringify(val, replacer, 2)
|
||||
: String(val)
|
||||
? JSON.stringify(val, replacer, 2)
|
||||
: String(val)
|
||||
}
|
||||
|
||||
const replacer = (_key: string, val: any) => {
|
||||
|
@ -72,9 +72,7 @@ window.init = () => {
|
||||
lastSuccessfulMap = new SourceMapConsumer(map!)
|
||||
lastSuccessfulMap!.computeColumnSpans()
|
||||
} catch (e) {
|
||||
lastSuccessfulCode = `/* ERROR: ${
|
||||
e.message
|
||||
} (see console for more info) */`
|
||||
lastSuccessfulCode = `/* ERROR: ${e.message} (see console for more info) */`
|
||||
console.error(e)
|
||||
}
|
||||
return lastSuccessfulCode
|
||||
@ -195,8 +193,10 @@ window.init = () => {
|
||||
if (
|
||||
pos.line != null &&
|
||||
pos.column != null &&
|
||||
!// ignore mock location
|
||||
(pos.line === 1 && pos.column === 0)
|
||||
!(
|
||||
// ignore mock location
|
||||
(pos.line === 1 && pos.column === 0)
|
||||
)
|
||||
) {
|
||||
const translatedPos = {
|
||||
column: pos.column + 1,
|
||||
|
@ -48,8 +48,7 @@ const App = {
|
||||
h(
|
||||
'a',
|
||||
{
|
||||
href:
|
||||
'https://app.netlify.com/sites/vue-next-template-explorer/deploys',
|
||||
href: 'https://app.netlify.com/sites/vue-next-template-explorer/deploys',
|
||||
target: `_blank`
|
||||
},
|
||||
'History'
|
||||
@ -147,7 +146,9 @@ const App = {
|
||||
checked: compilerOptions.hoistStatic && !isSSR,
|
||||
disabled: isSSR,
|
||||
onChange(e: Event) {
|
||||
compilerOptions.hoistStatic = (e.target as HTMLInputElement).checked
|
||||
compilerOptions.hoistStatic = (
|
||||
e.target as HTMLInputElement
|
||||
).checked
|
||||
}
|
||||
}),
|
||||
h('label', { for: 'hoist' }, 'hoistStatic')
|
||||
@ -161,7 +162,9 @@ const App = {
|
||||
checked: usePrefix && compilerOptions.cacheHandlers && !isSSR,
|
||||
disabled: !usePrefix || isSSR,
|
||||
onChange(e: Event) {
|
||||
compilerOptions.cacheHandlers = (e.target as HTMLInputElement).checked
|
||||
compilerOptions.cacheHandlers = (
|
||||
e.target as HTMLInputElement
|
||||
).checked
|
||||
}
|
||||
}),
|
||||
h('label', { for: 'cache' }, 'cacheHandlers')
|
||||
@ -191,7 +194,9 @@ const App = {
|
||||
id: 'inline',
|
||||
checked: compilerOptions.inline,
|
||||
onChange(e: Event) {
|
||||
compilerOptions.inline = (e.target as HTMLInputElement).checked
|
||||
compilerOptions.inline = (
|
||||
e.target as HTMLInputElement
|
||||
).checked
|
||||
}
|
||||
}),
|
||||
h('label', { for: 'inline' }, 'inline')
|
||||
@ -204,8 +209,9 @@ const App = {
|
||||
id: 'compat',
|
||||
checked: compilerOptions.compatConfig!.MODE === 2,
|
||||
onChange(e: Event) {
|
||||
compilerOptions.compatConfig!.MODE = (e.target as HTMLInputElement)
|
||||
.checked
|
||||
compilerOptions.compatConfig!.MODE = (
|
||||
e.target as HTMLInputElement
|
||||
).checked
|
||||
? 2
|
||||
: 3
|
||||
}
|
||||
|
@ -55,7 +55,8 @@ test('COMPONENT_FUNCTIONAL', async () => {
|
||||
)
|
||||
|
||||
expect(
|
||||
(deprecationData[DeprecationTypes.COMPONENT_FUNCTIONAL]
|
||||
.message as Function)(func)
|
||||
(
|
||||
deprecationData[DeprecationTypes.COMPONENT_FUNCTIONAL].message as Function
|
||||
)(func)
|
||||
).toHaveBeenWarned()
|
||||
})
|
||||
|
@ -26,10 +26,7 @@ describe('FILTERS', () => {
|
||||
}
|
||||
|
||||
function reverse(v: string) {
|
||||
return v
|
||||
.split('')
|
||||
.reverse()
|
||||
.join('')
|
||||
return v.split('').reverse().join('')
|
||||
}
|
||||
|
||||
function double(v: number) {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user