Skip to content

Commit

Permalink
Merge branch 'main' into fix/#3716
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 authored Apr 29, 2024
2 parents 3974b5d + 2d56816 commit 32215c5
Show file tree
Hide file tree
Showing 11 changed files with 471 additions and 283 deletions.
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"version": "3.4.25",
"packageManager": "[email protected].5",
"packageManager": "[email protected].6",
"type": "module",
"scripts": {
"dev": "node scripts/dev.js",
Expand Down Expand Up @@ -72,15 +72,15 @@
"@types/minimist": "^1.2.5",
"@types/node": "^20.12.7",
"@types/semver": "^7.5.8",
"@vitest/coverage-istanbul": "^1.5.0",
"@vitest/coverage-istanbul": "^1.5.2",
"@vue/consolidate": "1.0.0",
"conventional-changelog-cli": "^4.1.0",
"enquirer": "^2.4.1",
"esbuild": "^0.20.2",
"esbuild-plugin-polyfill-node": "^0.3.0",
"eslint": "^9.0.0",
"eslint": "^9.1.1",
"eslint-plugin-import-x": "^0.5.0",
"eslint-plugin-vitest": "^0.5.3",
"eslint-plugin-vitest": "^0.5.4",
"estree-walker": "^2.0.2",
"execa": "^8.0.1",
"jsdom": "^24.0.0",
Expand All @@ -95,23 +95,23 @@
"prettier": "^3.2.5",
"pretty-bytes": "^6.1.1",
"pug": "^3.0.2",
"puppeteer": "~22.6.5",
"puppeteer": "~22.7.1",
"rimraf": "^5.0.5",
"rollup": "^4.16.1",
"rollup": "^4.17.1",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-esbuild": "^6.1.1",
"rollup-plugin-polyfill-node": "^0.13.0",
"semver": "^7.6.0",
"serve": "^14.2.1",
"serve": "^14.2.3",
"simple-git-hooks": "^2.11.1",
"terser": "^5.30.3",
"terser": "^5.30.4",
"todomvc-app-css": "^2.4.3",
"tslib": "^2.6.2",
"tsx": "^4.7.2",
"tsx": "^4.7.3",
"typescript": "~5.4.5",
"typescript-eslint": "^7.6.0",
"typescript-eslint": "^7.7.1",
"vite": "^5.2.10",
"vitest": "^1.5.0"
"vitest": "^1.5.2"
},
"pnpm": {
"peerDependencyRules": {
Expand Down
15 changes: 8 additions & 7 deletions packages/compiler-core/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ const tokenizer = new Tokenizer(stack, {
const name = currentOpenTag!.tag
currentOpenTag!.isSelfClosing = true
endOpenTag(end)
if (stack[0]?.tag === name) {
if (stack[0] && stack[0].tag === name) {
onCloseTag(stack.shift()!, end)
}
},
Expand Down Expand Up @@ -587,14 +587,14 @@ function endOpenTag(end: number) {

function onText(content: string, start: number, end: number) {
if (__BROWSER__) {
const tag = stack[0]?.tag
const tag = stack[0] && stack[0].tag
if (tag !== 'script' && tag !== 'style' && content.includes('&')) {
content = currentOptions.decodeEntities!(content, false)
}
}
const parent = stack[0] || currentRoot
const lastNode = parent.children[parent.children.length - 1]
if (lastNode?.type === NodeTypes.TEXT) {
if (lastNode && lastNode.type === NodeTypes.TEXT) {
// merge
lastNode.content += content
setLocEnd(lastNode.loc, end)
Expand Down Expand Up @@ -771,7 +771,8 @@ function isComponent({ tag, props }: ElementNode): boolean {
tag === 'component' ||
isUpperCase(tag.charCodeAt(0)) ||
isCoreComponent(tag) ||
currentOptions.isBuiltInComponent?.(tag) ||
(currentOptions.isBuiltInComponent &&
currentOptions.isBuiltInComponent(tag)) ||
(currentOptions.isNativeTag && !currentOptions.isNativeTag(tag))
) {
return true
Expand Down Expand Up @@ -828,8 +829,8 @@ function condenseWhitespace(
if (node.type === NodeTypes.TEXT) {
if (!inPre) {
if (isAllWhitespace(node.content)) {
const prev = nodes[i - 1]?.type
const next = nodes[i + 1]?.type
const prev = nodes[i - 1] && nodes[i - 1].type
const next = nodes[i + 1] && nodes[i + 1].type
// Remove if:
// - the whitespace is the first or last node, or:
// - (condense mode) the whitespace is between two comments, or:
Expand Down Expand Up @@ -1063,7 +1064,7 @@ export function baseParse(input: string, options?: ParserOptions): RootNode {
currentOptions.ns === Namespaces.SVG ||
currentOptions.ns === Namespaces.MATH_ML

const delimiters = options?.delimiters
const delimiters = options && options.delimiters
if (delimiters) {
tokenizer.delimiterOpen = toCharCodes(delimiters[0])
tokenizer.delimiterClose = toCharCodes(delimiters[1])
Expand Down
2 changes: 1 addition & 1 deletion packages/reactivity/src/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class ReactiveEffect<T = any> {
if (this.active) {
preCleanupEffect(this)
postCleanupEffect(this)
this.onStop?.()
this.onStop && this.onStop()
this.active = false
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/reactivity/src/reactiveEffect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,6 @@ export function trigger(
}

export function getDepFromReactive(object: any, key: string | number | symbol) {
return targetMap.get(object)?.get(key)
const depsMap = targetMap.get(object)
return depsMap && depsMap.get(key)
}
37 changes: 0 additions & 37 deletions packages/runtime-core/__tests__/components/BaseTransition.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
h,
nextTick,
nodeOps,
onUnmounted,
ref,
render,
serialize,
Expand Down Expand Up @@ -769,42 +768,6 @@ describe('BaseTransition', () => {
test('w/ KeepAlive', async () => {
await runTestWithKeepAlive(testOutIn)
})

test('w/ KeepAlive + unmount innerChild', async () => {
const unmountSpy = vi.fn()
const includeRef = ref(['TrueBranch'])
const trueComp = {
name: 'TrueBranch',
setup() {
onUnmounted(unmountSpy)
const count = ref(0)
return () => h('div', count.value)
},
}

const toggle = ref(true)
const { props } = mockProps({ mode: 'out-in' }, true /*withKeepAlive*/)
const root = nodeOps.createElement('div')
const App = {
render() {
return h(BaseTransition, props, () => {
return h(
KeepAlive,
{ include: includeRef.value },
toggle.value ? h(trueComp) : h('div'),
)
})
},
}
render(h(App), root)

// trigger toggle
toggle.value = false
includeRef.value = []

await nextTick()
expect(unmountSpy).toHaveBeenCalledTimes(1)
})
})

// #6835
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/__tests__/hmr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ describe('hot module replacement', () => {
triggerEvent(root.children[1] as TestElement, 'click')
await nextTick()
await new Promise(r => setTimeout(r, 0))
expect(serializeInner(root)).toBe(`<button></button><!---->`)
expect(serializeInner(root)).toBe(`<button></button><!--v-if-->`)
expect(unmountSpy).toHaveBeenCalledTimes(1)
expect(mountSpy).toHaveBeenCalledTimes(1)
expect(activeSpy).toHaveBeenCalledTimes(1)
Expand Down
21 changes: 7 additions & 14 deletions packages/runtime-core/src/apiWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,39 +466,32 @@ export function createPathGetter(ctx: any, path: string) {

export function traverse(
value: unknown,
depth?: number,
currentDepth = 0,
depth = Infinity,
seen?: Set<unknown>,
) {
if (!isObject(value) || (value as any)[ReactiveFlags.SKIP]) {
if (depth <= 0 || !isObject(value) || (value as any)[ReactiveFlags.SKIP]) {
return value
}

if (depth && depth > 0) {
if (currentDepth >= depth) {
return value
}
currentDepth++
}

seen = seen || new Set()
if (seen.has(value)) {
return value
}
seen.add(value)
depth--
if (isRef(value)) {
traverse(value.value, depth, currentDepth, seen)
traverse(value.value, depth, seen)
} else if (isArray(value)) {
for (let i = 0; i < value.length; i++) {
traverse(value[i], depth, currentDepth, seen)
traverse(value[i], depth, seen)
}
} else if (isSet(value) || isMap(value)) {
value.forEach((v: any) => {
traverse(v, depth, currentDepth, seen)
traverse(v, depth, seen)
})
} else if (isPlainObject(value)) {
for (const key in value) {
traverse(value[key], depth, currentDepth, seen)
traverse(value[key], depth, seen)
}
}
return value
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/components/BaseTransition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ const BaseTransitionImpl: ComponentOptions = {
// update old tree's hooks in case of dynamic transition
setTransitionHooks(oldInnerChild, leavingHooks)
// switching between different views
if (mode === 'out-in') {
if (mode === 'out-in' && innerChild.type !== Comment) {
state.isLeaving = true
// return placeholder node and queue update when leave finishes
leavingHooks.afterLeave = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/components/KeepAlive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ const KeepAliveImpl: ComponentOptions = {
pendingCacheKey = null

if (!slots.default) {
return (current = null)
return null
}

const children = slots.default()
Expand Down
5 changes: 3 additions & 2 deletions packages/runtime-core/src/components/Suspense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ function createSuspenseBoundary(
let parentSuspenseId: number | undefined
const isSuspensible = isVNodeSuspensible(vnode)
if (isSuspensible) {
if (parentSuspense?.pendingBranch) {
if (parentSuspense && parentSuspense.pendingBranch) {
parentSuspenseId = parentSuspense.pendingId
parentSuspense.deps++
}
Expand Down Expand Up @@ -898,5 +898,6 @@ function setActiveBranch(suspense: SuspenseBoundary, branch: VNode) {
}

function isVNodeSuspensible(vnode: VNode) {
return vnode.props?.suspensible != null && vnode.props.suspensible !== false
const suspensible = vnode.props && vnode.props.suspensible
return suspensible != null && suspensible !== false
}
Loading

0 comments on commit 32215c5

Please sign in to comment.