wip: support resolving directives from setup scope variables by naming convention

v-my-dir can be resovled from setup scope variable named "vMyDir".
This commit is contained in:
Evan You
2020-11-23 16:32:24 -05:00
parent 2f32e4a077
commit ae2caad740
4 changed files with 121 additions and 35 deletions

View File

@@ -177,6 +177,32 @@ return (_ctx, _cache) => {
}"
`;
exports[`SFC compile <script setup> inlineTemplate mode referencing scope components and directives 1`] = `
"import { unref as _unref, createVNode as _createVNode, withDirectives as _withDirectives, Fragment as _Fragment, openBlock as _openBlock, createBlock as _createBlock } from \\"vue\\"
import ChildComp from './Child.vue'
import SomeOtherComp from './Other.vue'
import vMyDir from './my-dir'
export default {
expose: [],
setup(__props) {
return (_ctx, _cache) => {
return (_openBlock(), _createBlock(_Fragment, null, [
_withDirectives(_createVNode(\\"div\\", null, null, 512 /* NEED_PATCH */), [
[_unref(vMyDir)]
]),
_createVNode(ChildComp),
_createVNode(SomeOtherComp)
], 64 /* STABLE_FRAGMENT */))
}
}
}"
`;
exports[`SFC compile <script setup> inlineTemplate mode should work 1`] = `
"import { toDisplayString as _toDisplayString, createVNode as _createVNode, Fragment as _Fragment, openBlock as _openBlock, createBlock as _createBlock } from \\"vue\\"

View File

@@ -147,6 +147,29 @@ const bar = 1
assertCode(content)
})
test('referencing scope components and directives', () => {
const { content } = compile(
`
<script setup>
import ChildComp from './Child.vue'
import SomeOtherComp from './Other.vue'
import vMyDir from './my-dir'
</script>
<template>
<div v-my-dir></div>
<ChildComp/>
<some-other-comp/>
</template>
`,
{ inlineTemplate: true }
)
expect(content).toMatch('[_unref(vMyDir)]')
expect(content).toMatch('_createVNode(ChildComp)')
// kebab-case component support
expect(content).toMatch('_createVNode(SomeOtherComp)')
assertCode(content)
})
test('avoid unref() when necessary', () => {
// function, const, component import
const { content } = compile(