fix(compiler-sfc): add test for #5808

This commit is contained in:
liulinboyi
2022-04-27 09:33:21 +08:00
committed by Evan You
parent 6c3b681d23
commit a0290fe781
2 changed files with 220 additions and 0 deletions

View File

@@ -1195,6 +1195,59 @@ const emit = defineEmits(['a', 'b'])
assertAwaitDetection(`if (ok) { await foo } else { await bar }`)
})
test('multiple `if` nested statements', () => {
assertAwaitDetection(`if (ok) {
let a = 'foo'
await 0 + await 1
await 2
} else if (a) {
await 10
if (b) {
await 0 + await 1
} else {
let a = 'foo'
await 2
}
if (b) {
await 3
await 4
}
} else {
await 5
}`)
})
test('multiple `if while` nested statements', () => {
assertAwaitDetection(`if (ok) {
while (d) {
await 5
}
while (d) {
await 5
await 6
if (c) {
let f = 10
10 + await 7
} else {
await 8
await 9
}
}
}`)
})
test('multiple `if for` nested statements', () => {
assertAwaitDetection(`if (ok) {
for (let a of [1,2,3]) {
await a
}
for (let a of [1,2,3]) {
await a
await a
}
}`)
})
test('should ignore await inside functions', () => {
// function declaration
assertAwaitDetection(`async function foo() { await bar }`, false)