Skip to content

Commit 7189409

Browse files
authored
Merge pull request #236 from jesusgn90/patch-1
Support pure functional components
2 parents 20b3b5e + 651bd31 commit 7189409

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<script>
2+
export default {
3+
name: 'FunctionalSFCRender',
4+
functional: true,
5+
render(createElement, { $style }) {
6+
return createElement('div', {
7+
class: [$style.ModuleClass]
8+
})
9+
}
10+
}
11+
</script>
12+
13+
<style lang="scss" module>
14+
.ModuleClass {
15+
width: auto;
16+
}
17+
</style>

e2e/__projects__/basic/test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import jestVue from 'vue-jest'
66
import RenderFunction from './components/RenderFunction.vue'
77
import Jade from './components/Jade.vue'
88
import FunctionalSFC from './components/FunctionalSFC.vue'
9+
import FunctionalSFCRender from './components/FunctionalSFCRender.vue'
910
import Basic from './components/Basic.vue'
1011
import BasicSrc from './components/BasicSrc.vue'
1112
import { randomExport } from './components/NamedExport.vue'
@@ -92,6 +93,12 @@ test('processes functional components', () => {
9293
expect(clickSpy).toHaveBeenCalledWith(1)
9394
})
9495

96+
test('processes functional components using render function', () => {
97+
const wrapper = mount(FunctionalSFCRender)
98+
const CSS_CLASSES = ['ModuleClass']
99+
expect(wrapper.classes().toString()).toBe(CSS_CLASSES.toString())
100+
})
101+
95102
test('processes SFC with functional template from parent', () => {
96103
const wrapper = mount(FunctionalSFCParent)
97104
expect(wrapper.text().trim()).toBe('foo')

lib/process.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,12 @@ module.exports = function(src, filename, config) {
107107
)
108108

109109
const isFunctional =
110-
descriptor.template &&
111-
descriptor.template.attrs &&
112-
descriptor.template.attrs.functional
110+
(descriptor.template &&
111+
descriptor.template.attrs &&
112+
descriptor.template.attrs.functional) ||
113+
(descriptor.script &&
114+
descriptor.script.content &&
115+
/functional:\s*true/.test(descriptor.script.content))
113116

114117
const templateStart = descriptor.template && descriptor.template.start
115118
const templateLine = src.slice(0, templateStart).split(splitRE).length

0 commit comments

Comments
 (0)