@@ -820,12 +820,14 @@ describe('parser', () => {
820
820
expect ( ast . children [ 3 ] . children [ 0 ] . text ) . toBe ( '.\n Have fun!\n' )
821
821
} )
822
822
823
+ const condenseOptions = extend ( {
824
+ whitespace : 'condense' ,
825
+ // should be ignored when whitespace is specified
826
+ preserveWhitespace : false
827
+ } , baseOptions )
828
+
823
829
it ( `whitespace: 'condense'` , ( ) => {
824
- const options = extend ( {
825
- whitespace : 'condense' ,
826
- // should be ignored when whitespace is specified
827
- preserveWhitespace : false
828
- } , baseOptions )
830
+ const options = extend ( { } , condenseOptions )
829
831
const ast = parse ( '<p>\n Welcome to <b>Vue.js</b> <i>world</i> \n <span>.\n Have fun!\n</span></p>' , options )
830
832
expect ( ast . tag ) . toBe ( 'p' )
831
833
expect ( ast . children . length ) . toBe ( 5 )
@@ -842,4 +844,41 @@ describe('parser', () => {
842
844
expect ( ast . children [ 4 ] . tag ) . toBe ( 'span' )
843
845
expect ( ast . children [ 4 ] . children [ 0 ] . text ) . toBe ( '. Have fun! ' )
844
846
} )
847
+
848
+ it ( `preserve whitespace in <pre> tag with whitespace: 'condense'` , function ( ) {
849
+ const options = extend ( { } , condenseOptions )
850
+ const ast = parse ( '<pre><code> \n<span>hi</span>\n </code><span> </span></pre>' , options )
851
+ const code = ast . children [ 0 ]
852
+ expect ( code . children [ 0 ] . type ) . toBe ( 3 )
853
+ expect ( code . children [ 0 ] . text ) . toBe ( ' \n' )
854
+ expect ( code . children [ 2 ] . type ) . toBe ( 3 )
855
+ expect ( code . children [ 2 ] . text ) . toBe ( '\n ' )
856
+
857
+ const span = ast . children [ 1 ]
858
+ expect ( span . children [ 0 ] . type ) . toBe ( 3 )
859
+ expect ( span . children [ 0 ] . text ) . toBe ( ' ' )
860
+ } )
861
+
862
+ it ( `ignore the first newline in <pre> tag with whitespace: 'condense'` , function ( ) {
863
+ const options = extend ( { } , condenseOptions )
864
+ const ast = parse ( '<div><pre>\nabc</pre>\ndef<pre>\n\nabc</pre></div>' , options )
865
+ const pre = ast . children [ 0 ]
866
+ expect ( pre . children [ 0 ] . type ) . toBe ( 3 )
867
+ expect ( pre . children [ 0 ] . text ) . toBe ( 'abc' )
868
+ const text = ast . children [ 1 ]
869
+ expect ( text . type ) . toBe ( 3 )
870
+ expect ( text . text ) . toBe ( ' def' )
871
+ const pre2 = ast . children [ 2 ]
872
+ expect ( pre2 . children [ 0 ] . type ) . toBe ( 3 )
873
+ expect ( pre2 . children [ 0 ] . text ) . toBe ( '\nabc' )
874
+ } )
875
+
876
+ it ( `keep first newline after unary tag in <pre> with whitespace: 'condense'` , ( ) => {
877
+ const options = extend ( { } , condenseOptions )
878
+ const ast = parse ( '<pre>abc<input>\ndef</pre>' , options )
879
+ expect ( ast . children [ 1 ] . type ) . toBe ( 1 )
880
+ expect ( ast . children [ 1 ] . tag ) . toBe ( 'input' )
881
+ expect ( ast . children [ 2 ] . type ) . toBe ( 3 )
882
+ expect ( ast . children [ 2 ] . text ) . toBe ( '\ndef' )
883
+ } )
845
884
} )
0 commit comments