Skip to content

Commit 52ce64a

Browse files
marcosmouraeddyerburgh
authored andcommitted
fix: make tests work with pure render functions
* fix: make tests work with pure render functions * fix: rename component
1 parent d9bc9e4 commit 52ce64a

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

lib/process.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ function processScript (scriptPart) {
2323

2424
module.exports = function (src, path) {
2525
var parts = vueCompiler.parseComponent(src, { pad: true })
26-
const renderFunctions = compileTemplate(parts.template)
2726

2827
const result = processScript(parts.script)
29-
3028
const script = result.code
3129
const inputMap = result.sourceMap
3230

@@ -37,12 +35,16 @@ module.exports = function (src, path) {
3735
'? module.exports.options' +
3836
': module.exports)\n'
3937

40-
output += '__vue__options__.render = ' + renderFunctions.render + '\n' +
41-
'__vue__options__.staticRenderFns = ' + renderFunctions.staticRenderFns + '\n'
38+
if (parts.template) {
39+
const renderFunctions = compileTemplate(parts.template)
4240

43-
if (map) {
44-
const beforeLines = output.split(splitRE).length
45-
addTemplateMapping(script, parts, output, map, beforeLines)
41+
output += '__vue__options__.render = ' + renderFunctions.render + '\n' +
42+
'__vue__options__.staticRenderFns = ' + renderFunctions.staticRenderFns + '\n'
43+
44+
if (map) {
45+
const beforeLines = output.split(splitRE).length
46+
addTemplateMapping(script, parts, output, map, beforeLines)
47+
}
4648
}
4749

4850
if (map) {

lib/template-compiler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function getTemplateContent (templatePart) {
1515
return templatePart.content
1616
}
1717

18-
module.exports = function compileTemplate (templatePart, compiler) {
18+
module.exports = function compileTemplate (templatePart) {
1919
var templateContent = getTemplateContent(templatePart)
2020

2121
var compiled = vueCompiler.compile(templateContent)

test/RenderFunction.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { shallow } from 'vue-test-utils'
2+
import RenderFunction from './resources/RenderFunction.vue'
3+
4+
test('processes .vue file with no template', () => {
5+
const wrapper = shallow(RenderFunction)
6+
7+
expect(wrapper.is('section')).toBe(true)
8+
})

test/resources/RenderFunction.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script>
2+
export default {
3+
name: 'RenderFunction',
4+
render (createElement) {
5+
return createElement('section', [this.$slots.default])
6+
}
7+
}
8+
</script>

0 commit comments

Comments
 (0)