test: improve test case for 865b84bf

This commit is contained in:
Evan You 2021-08-06 13:01:39 -04:00
parent fdc9a4d301
commit 1994f1200d
3 changed files with 26 additions and 10 deletions

View File

@ -99,11 +99,18 @@ export default _defineComponent({
setup(__props, { expose }) {
expose()
let n = _ref<number | undefined>()
console.log(n.value!)
console.log(n.value as number)
let a = _ref(1)
console.log(a.value!)
console.log(a.value! + 1)
console.log(a.value as number)
console.log((a.value as number) + 1)
console.log(<number>a.value)
console.log(<number>a.value + 1)
console.log(a.value! + (a.value as number))
console.log(a.value! + <number>a.value)
console.log((a.value as number) + <number>a.value)
return { n }
return { a }
}
})"

View File

@ -286,17 +286,25 @@ describe('<script setup> ref sugar', () => {
const { content } = compile(
`
<script setup lang="ts">
let n = $ref<number | undefined>()
console.log(n!)
console.log(n as number)
let a = $ref(1)
console.log(a!)
console.log(a! + 1)
console.log(a as number)
console.log((a as number) + 1)
console.log(<number>a)
console.log(<number>a + 1)
console.log(a! + (a as number))
console.log(a! + <number>a)
console.log((a as number) + <number>a)
</script>`,
{
refSugar: true
}
)
assertCode(content)
expect(content).toMatch('console.log(n.value!)')
expect(content).toMatch('console.log(n.value as number)')
expect(content).toMatch('console.log(a.value!)')
expect(content).toMatch('console.log(a.value as number)')
expect(content).toMatch('console.log(<number>a.value)')
})
describe('errors', () => {

View File

@ -1785,7 +1785,8 @@ export function walkIdentifiers(
parent &&
parent.type.startsWith('TS') &&
parent.type !== 'TSAsExpression' &&
parent.type !== 'TSNonNullExpression'
parent.type !== 'TSNonNullExpression' &&
parent.type !== 'TSTypeAssertion'
) {
return this.skip()
}