fix(compiler-sfc): check template ref usage, (#12985)

close #12984
This commit is contained in:
lsdsjy 2023-12-07 14:14:27 +08:00 committed by GitHub
parent 24fcf69624
commit 83d95351a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 0 deletions

View File

@ -1818,6 +1818,8 @@ function resolveTemplateUsageCheckString(sfc: SFCDescriptor, isTS: boolean) {
if (value) {
code += `,${processExp(value, isTS, baseName)}`
}
} else if (name === 'ref') {
code += `,${value}`
}
}
},

View File

@ -364,6 +364,20 @@ return { vMyDir }
})"
`;
exports[`SFC compile <script setup> > dev mode import usage check > imported ref as template ref 1`] = `
"import { defineComponent as _defineComponent } from 'vue'
import { aref } from './x'
export default /*#__PURE__*/_defineComponent({
setup(__props) {
return { aref }
}
})"
`;
exports[`SFC compile <script setup> > dev mode import usage check > js template string interpolations 1`] = `
"import { defineComponent as _defineComponent } from 'vue'
import { VAR, VAR2, VAR3 } from './x'

View File

@ -398,6 +398,19 @@ defineExpose({ foo: 123 })
assertCode(content)
})
test('imported ref as template ref', () => {
const { content } = compile(`
<script setup lang="ts">
import { aref } from './x'
</script>
<template>
<div ref="aref"></div>
</template>
`)
expect(content).toMatch(`return { aref }`)
assertCode(content)
})
test('vue interpolations', () => {
const { content } = compile(`
<script setup lang="ts">