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) {
2121 return compileBabel ( scriptPart . content )
2222}
2323
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+
2439module . exports = function ( src , path ) {
2540 var parts = vueCompiler . parseComponent ( src , { pad : true } )
2641
42+ changePartsIfFunctional ( parts )
43+
2744 const result = processScript ( parts . script )
2845 const script = result . code
2946 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