Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/compiler-sfc/src/compileScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1815,6 +1815,8 @@ function resolveTemplateUsageCheckString(sfc: SFCDescriptor, isTS: boolean) {
if (value) {
code += `,${processExp(value, isTS, baseName)}`
}
} else if (name === 'ref') {
code += `,${value}`
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,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'
Expand Down
13 changes: 13 additions & 0 deletions packages/compiler-sfc/test/compileScript.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,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">
Expand Down
Loading