Skip to content

Commit

Permalink
feat: directive resolution for <script setup>
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jun 15, 2022
1 parent 4b19339 commit aa2b1f4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/core/vdom/modules/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ function normalizeDirectives(
dir.modifiers = emptyModifiers
}
res[getRawDirName(dir)] = dir
dir.def = resolveAsset(vm.$options, 'directives', dir.name, true)
if (vm._setupState && vm._setupState.__sfc) {
dir.def = resolveAsset(vm, '_setupState', 'v-' + dir.name)
}
dir.def = dir.def || resolveAsset(vm.$options, 'directives', dir.name, true)
}
// $flow-disable-line
return res
Expand Down
14 changes: 14 additions & 0 deletions test/unit/features/v3/apiSetup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,18 @@ describe('api: setup context', () => {
await nextTick()
expect(vm.$el.outerHTML).toMatch(`<div>1</div>`)
})

it('directive resolution', () => {
const spy = vi.fn()
new Vue({
setup: () => ({
__sfc: true,
vDir: {
inserted: spy
}
}),
template: `<div v-dir />`
}).$mount()
expect(spy).toHaveBeenCalled()
})
})

0 comments on commit aa2b1f4

Please sign in to comment.