feat(sfc): support $shallowRef ref sugar

This commit is contained in:
Evan You
2021-08-11 10:19:58 -04:00
parent e42d7794cb
commit 00b76d3dc1
7 changed files with 46 additions and 20 deletions

View File

@@ -33,8 +33,8 @@ return { a, b, c }
}"
`;
exports[`<script setup> ref sugar $ref declarations 1`] = `
"import { ref as _ref } from 'vue'
exports[`<script setup> ref sugar $ref & $shallowRef declarations 1`] = `
"import { ref as _ref, shallowRef as _shallowRef } from 'vue'
export default {
setup(__props, { expose }) {
@@ -42,7 +42,7 @@ export default {
let foo = _ref()
let a = _ref(1)
let b = _ref({
let b = _shallowRef({
count: 0
})
let c = () => {}

View File

@@ -6,24 +6,26 @@ describe('<script setup> ref sugar', () => {
return compile(src, { refSugar: true })
}
test('$ref declarations', () => {
test('$ref & $shallowRef declarations', () => {
const { content, bindings } = compileWithRefSugar(`<script setup>
let foo = $ref()
let a = $ref(1)
let b = $ref({
let b = $shallowRef({
count: 0
})
let c = () => {}
let d
</script>`)
expect(content).toMatch(`import { ref as _ref } from 'vue'`)
expect(content).toMatch(
`import { ref as _ref, shallowRef as _shallowRef } from 'vue'`
)
expect(content).not.toMatch(`$ref()`)
expect(content).not.toMatch(`$ref(1)`)
expect(content).not.toMatch(`$ref({`)
expect(content).not.toMatch(`$shallowRef({`)
expect(content).toMatch(`let foo = _ref()`)
expect(content).toMatch(`let a = _ref(1)`)
expect(content).toMatch(`
let b = _ref({
let b = _shallowRef({
count: 0
})
`)