File tree 2 files changed +24
-10
lines changed
test/unit/modules/compiler
2 files changed +24
-10
lines changed Original file line number Diff line number Diff line change @@ -377,16 +377,20 @@ export function parse (
377
377
}
378
378
} ,
379
379
comment ( text : string , start , end ) {
380
- const child : ASTText = {
381
- type : 3 ,
382
- text,
383
- isComment : true
384
- }
385
- if ( process . env . NODE_ENV !== 'production' && options . outputSourceRange ) {
386
- child . start = start
387
- child . end = end
380
+ // adding anyting as a sibling to the root node is forbidden
381
+ // comments should still be allowed, but ignored
382
+ if ( currentParent ) {
383
+ const child : ASTText = {
384
+ type : 3 ,
385
+ text,
386
+ isComment : true
387
+ }
388
+ if ( process . env . NODE_ENV !== 'production' && options . outputSourceRange ) {
389
+ child . start = start
390
+ child . end = end
391
+ }
392
+ currentParent . children . push ( child )
388
393
}
389
- currentParent . children . push ( child )
390
394
}
391
395
} )
392
396
return root
Original file line number Diff line number Diff line change @@ -786,6 +786,16 @@ describe('parser', () => {
786
786
expect ( ast . children [ 1 ] . text ) . toBe ( 'comment here' )
787
787
} )
788
788
789
+ // #9407
790
+ it ( 'should parse templates with comments anywhere' , ( ) => {
791
+ const options = extend ( {
792
+ comments : true
793
+ } , baseOptions )
794
+ const ast = parse ( `<!--comment here--><div>123</div>` , options )
795
+ expect ( ast . tag ) . toBe ( 'div' )
796
+ expect ( ast . children . length ) . toBe ( 1 )
797
+ } )
798
+
789
799
// #8103
790
800
it ( 'should allow CRLFs in string interpolations' , ( ) => {
791
801
const ast = parse ( `<p>{{\r\nmsg\r\n}}</p>` , baseOptions )
@@ -797,7 +807,7 @@ describe('parser', () => {
797
807
preserveWhitespace : false
798
808
} , baseOptions )
799
809
800
- const ast = parse ( '<p>\n Welcome to <b>Vue.js</b> <i>world</i> \n <span>.\n Have fun!\n</span></p>' , options )
810
+ const ast = parse ( '<p>\n Welcome to <b>Vue.js</b> <i>world</i> \n <span>.\n Have fun!\n</span></p>' , options )
801
811
expect ( ast . tag ) . toBe ( 'p' )
802
812
expect ( ast . children . length ) . toBe ( 4 )
803
813
expect ( ast . children [ 0 ] . type ) . toBe ( 3 )
You can’t perform that action at this time.
0 commit comments