@@ -33,6 +33,20 @@ describe('compiler:sfc', () => {
33
33
expect ( mapping . originalLine - mapping . generatedLine ) . toBe ( padding )
34
34
} )
35
35
} )
36
+
37
+ test ( 'custom block' , ( ) => {
38
+ const padding = Math . round ( Math . random ( ) * 10 )
39
+ const custom = parse (
40
+ `${ '\n' . repeat ( padding ) } <i18n>\n{\n "greeting": "hello"\n}\n</i18n>\n`
41
+ ) . descriptor . customBlocks [ 0 ]
42
+
43
+ expect ( custom ! . map ) . not . toBeUndefined ( )
44
+
45
+ const consumer = new SourceMapConsumer ( custom ! . map ! )
46
+ consumer . eachMapping ( mapping => {
47
+ expect ( mapping . originalLine - mapping . generatedLine ) . toBe ( padding )
48
+ } )
49
+ } )
36
50
} )
37
51
38
52
test ( 'pad content' , ( ) => {
@@ -45,11 +59,16 @@ export default {}
45
59
</script>
46
60
<style>
47
61
h1 { color: red }
48
- </style>`
62
+ </style>
63
+ <i18n>
64
+ { "greeting": "hello" }
65
+ </i18n>
66
+ `
49
67
const padFalse = parse ( content . trim ( ) , { pad : false } ) . descriptor
50
68
expect ( padFalse . template ! . content ) . toBe ( '\n<div></div>\n' )
51
69
expect ( padFalse . script ! . content ) . toBe ( '\nexport default {}\n' )
52
70
expect ( padFalse . styles [ 0 ] . content ) . toBe ( '\nh1 { color: red }\n' )
71
+ expect ( padFalse . customBlocks [ 0 ] . content ) . toBe ( '\n{ "greeting": "hello" }\n' )
53
72
54
73
const padTrue = parse ( content . trim ( ) , { pad : true } ) . descriptor
55
74
expect ( padTrue . script ! . content ) . toBe (
@@ -58,6 +77,9 @@ h1 { color: red }
58
77
expect ( padTrue . styles [ 0 ] . content ) . toBe (
59
78
Array ( 6 + 1 ) . join ( '\n' ) + '\nh1 { color: red }\n'
60
79
)
80
+ expect ( padTrue . customBlocks [ 0 ] . content ) . toBe (
81
+ Array ( 9 + 1 ) . join ( '\n' ) + '\n{ "greeting": "hello" }\n'
82
+ )
61
83
62
84
const padLine = parse ( content . trim ( ) , { pad : 'line' } ) . descriptor
63
85
expect ( padLine . script ! . content ) . toBe (
@@ -66,6 +88,9 @@ h1 { color: red }
66
88
expect ( padLine . styles [ 0 ] . content ) . toBe (
67
89
Array ( 6 + 1 ) . join ( '\n' ) + '\nh1 { color: red }\n'
68
90
)
91
+ expect ( padLine . customBlocks [ 0 ] . content ) . toBe (
92
+ Array ( 9 + 1 ) . join ( '\n' ) + '\n{ "greeting": "hello" }\n'
93
+ )
69
94
70
95
const padSpace = parse ( content . trim ( ) , { pad : 'space' } ) . descriptor
71
96
expect ( padSpace . script ! . content ) . toBe (
@@ -78,6 +103,12 @@ h1 { color: red }
78
103
' '
79
104
) + '\nh1 { color: red }\n'
80
105
)
106
+ expect ( padSpace . customBlocks [ 0 ] . content ) . toBe (
107
+ `<template>\n<div></div>\n</template>\n<script>\nexport default {}\n</script>\n<style>\nh1 { color: red }\n</style>\n<i18n>` . replace (
108
+ / ./ g,
109
+ ' '
110
+ ) + '\n{ "greeting": "hello" }\n'
111
+ )
81
112
} )
82
113
83
114
test ( 'should ignore nodes with no content' , ( ) => {
0 commit comments