Skip to content

Commit

Permalink
fix(compiler-sfc): fix dynamic directive arguments usage check for sl…
Browse files Browse the repository at this point in the history
…ots (#9495)

close #9493
  • Loading branch information
edison1105 committed Nov 6, 2023
1 parent 462aeb3 commit b39fa1f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -696,14 +696,14 @@ return { get vMyDir() { return vMyDir } }
exports[`SFC compile <script setup> > dev mode import usage check > dynamic arguments 1`] = `
"import { defineComponent as _defineComponent } from 'vue'
import { FooBar, foo, bar, unused } from './x'
import { FooBar, foo, bar, unused, baz } from './x'
export default /*#__PURE__*/_defineComponent({
setup(__props, { expose: __expose }) {
__expose();
return { get FooBar() { return FooBar }, get foo() { return foo }, get bar() { return bar } }
return { get FooBar() { return FooBar }, get foo() { return foo }, get bar() { return bar }, get baz() { return baz } }
}
})"
Expand Down
5 changes: 3 additions & 2 deletions packages/compiler-sfc/__tests__/compileScript.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,18 +376,19 @@ describe('SFC compile <script setup>', () => {
test('dynamic arguments', () => {
const { content } = compile(`
<script setup lang="ts">
import { FooBar, foo, bar, unused } from './x'
import { FooBar, foo, bar, unused, baz } from './x'
</script>
<template>
<FooBar #[foo.slotName] />
<FooBar #unused />
<div :[bar.attrName]="15"></div>
<div unused="unused"></div>
<div #[\`item:\${baz.key}\`]="{ value }"></div>
</template>
`)
expect(content).toMatch(
`return { get FooBar() { return FooBar }, get foo() { return foo }, ` +
`get bar() { return bar } }`
`get bar() { return bar }, get baz() { return baz } }`
)
assertCode(content)
})
Expand Down
8 changes: 5 additions & 3 deletions packages/compiler-sfc/src/script/importUsageCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ function resolveTemplateUsageCheckString(sfc: SFCDescriptor) {
if (!isBuiltInDirective(prop.name)) {
code += `,v${capitalize(camelize(prop.name))}`
}

// process dynamic directive arguments
if (prop.arg && !(prop.arg as SimpleExpressionNode).isStatic) {
code += `,${processExp(
(prop.arg as SimpleExpressionNode).content,
prop.name
code += `,${stripStrings(
(prop.arg as SimpleExpressionNode).content
)}`
}

if (prop.exp) {
code += `,${processExp(
(prop.exp as SimpleExpressionNode).content,
Expand Down

0 comments on commit b39fa1f

Please sign in to comment.