Skip to content

Commit e5919d4

Browse files
authored
fix(compile-sfc): analyze v-bind shorthand usage in template (#10518)
close #10515
1 parent 6b4b8ec commit e5919d4

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

Diff for: packages/compiler-sfc/__tests__/compileScript/__snapshots__/importUsageCheck.spec.ts.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ return { get vMyDir() { return vMyDir } }
6666

6767
exports[`dynamic arguments 1`] = `
6868
"import { defineComponent as _defineComponent } from 'vue'
69-
import { FooBar, foo, bar, unused, baz } from './x'
69+
import { FooBar, foo, bar, unused, baz, msg } from './x'
7070
7171
export default /*#__PURE__*/_defineComponent({
7272
setup(__props, { expose: __expose }) {
7373
__expose();
7474
7575
76-
return { get FooBar() { return FooBar }, get foo() { return foo }, get bar() { return bar }, get baz() { return baz } }
76+
return { get FooBar() { return FooBar }, get foo() { return foo }, get bar() { return bar }, get baz() { return baz }, get msg() { return msg } }
7777
}
7878
7979
})"

Diff for: packages/compiler-sfc/__tests__/compileScript/importUsageCheck.spec.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,20 @@ test('directive', () => {
4545
test('dynamic arguments', () => {
4646
const { content } = compile(`
4747
<script setup lang="ts">
48-
import { FooBar, foo, bar, unused, baz } from './x'
48+
import { FooBar, foo, bar, unused, baz, msg } from './x'
4949
</script>
5050
<template>
5151
<FooBar #[foo.slotName] />
5252
<FooBar #unused />
5353
<div :[bar.attrName]="15"></div>
5454
<div unused="unused"></div>
5555
<div #[\`item:\${baz.key}\`]="{ value }"></div>
56+
<FooBar :msg />
5657
</template>
5758
`)
5859
expect(content).toMatch(
5960
`return { get FooBar() { return FooBar }, get foo() { return foo }, ` +
60-
`get bar() { return bar }, get baz() { return baz } }`,
61+
`get bar() { return bar }, get baz() { return baz }, get msg() { return msg } }`,
6162
)
6263
assertCode(content)
6364
})

Diff for: packages/compiler-sfc/src/script/importUsageCheck.ts

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ function resolveTemplateUsedIdentifiers(sfc: SFCDescriptor): Set<string> {
6060
extractIdentifiers(ids, prop.forParseResult!.source)
6161
} else if (prop.exp) {
6262
extractIdentifiers(ids, prop.exp)
63+
} else if (prop.name === 'bind' && !prop.exp) {
64+
// v-bind shorthand name as identifier
65+
ids.add((prop.arg as SimpleExpressionNode).content)
6366
}
6467
}
6568
if (

0 commit comments

Comments
 (0)