File tree Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -21,9 +21,26 @@ function processScript (scriptPart) {
21
21
return compileBabel ( scriptPart . content )
22
22
}
23
23
24
+ function isFunctionalTemplate ( parts ) {
25
+ try {
26
+ if ( parts . template . attrs . functional === true ) return true
27
+ } catch ( error ) {
28
+ return false
29
+ }
30
+ }
31
+
32
+ function changePartsIfFunctional ( parts ) {
33
+ if ( isFunctionalTemplate ( parts ) ) {
34
+ parts . lang = 'javascript'
35
+ parts . script = { type : 'script' , content : 'export default { props: { props: Object } }' }
36
+ }
37
+ }
38
+
24
39
module . exports = function ( src , path ) {
25
40
var parts = vueCompiler . parseComponent ( src , { pad : true } )
26
41
42
+ changePartsIfFunctional ( parts )
43
+
27
44
const result = processScript ( parts . script )
28
45
const script = result . code
29
46
const inputMap = result . sourceMap
Original file line number Diff line number Diff line change
1
+ import { shallow } from 'vue-test-utils'
2
+ import FunctionalSFC from './resources/FunctionalSFC.vue'
3
+
4
+ test ( 'processes .vue file with functional template' , ( ) => {
5
+ const wrapper = shallow ( FunctionalSFC , {
6
+ propsData : { props : { msg : 'Hello' } }
7
+ } )
8
+ expect ( wrapper . is ( 'div' ) ) . toBe ( true )
9
+ expect ( wrapper . text ( ) . trim ( ) ) . toBe ( 'Hello' )
10
+ } )
Original file line number Diff line number Diff line change
1
+ <template functional>
2
+ <div class =" hello" >
3
+ {{ props.msg }}
4
+ </div >
5
+ </template >
You can’t perform that action at this time.
0 commit comments