Skip to content

Commit 83d9535

Browse files
authored
fix(compiler-sfc): check template ref usage, (vuejs#12985)
close vuejs#12984
1 parent 24fcf69 commit 83d9535

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

packages/compiler-sfc/src/compileScript.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,6 +1818,8 @@ function resolveTemplateUsageCheckString(sfc: SFCDescriptor, isTS: boolean) {
18181818
if (value) {
18191819
code += `,${processExp(value, isTS, baseName)}`
18201820
}
1821+
} else if (name === 'ref') {
1822+
code += `,${value}`
18211823
}
18221824
}
18231825
},

packages/compiler-sfc/test/__snapshots__/compileScript.spec.ts.snap

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,20 @@ return { vMyDir }
364364
})"
365365
`;
366366
367+
exports[`SFC compile <script setup> > dev mode import usage check > imported ref as template ref 1`] = `
368+
"import { defineComponent as _defineComponent } from 'vue'
369+
import { aref } from './x'
370+
371+
export default /*#__PURE__*/_defineComponent({
372+
setup(__props) {
373+
374+
375+
return { aref }
376+
}
377+
378+
})"
379+
`;
380+
367381
exports[`SFC compile <script setup> > dev mode import usage check > js template string interpolations 1`] = `
368382
"import { defineComponent as _defineComponent } from 'vue'
369383
import { VAR, VAR2, VAR3 } from './x'

packages/compiler-sfc/test/compileScript.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,19 @@ defineExpose({ foo: 123 })
398398
assertCode(content)
399399
})
400400

401+
test('imported ref as template ref', () => {
402+
const { content } = compile(`
403+
<script setup lang="ts">
404+
import { aref } from './x'
405+
</script>
406+
<template>
407+
<div ref="aref"></div>
408+
</template>
409+
`)
410+
expect(content).toMatch(`return { aref }`)
411+
assertCode(content)
412+
})
413+
401414
test('vue interpolations', () => {
402415
const { content } = compile(`
403416
<script setup lang="ts">

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy