@@ -7,7 +7,7 @@ use super::{
77} ;
88use vize_carton:: Bump ;
99use vize_relief:: {
10- ElementType , ExpressionNode , Namespace , PropNode , TemplateChildNode ,
10+ CommentKind , ElementType , ExpressionNode , Namespace , PropNode , TemplateChildNode ,
1111 errors:: { CompilerError , ErrorCode } ,
1212 options:: { ParserOptions , TemplateSyntaxMode } ,
1313} ;
@@ -626,6 +626,93 @@ fn test_parse_whitespace_condense_skips_comment_gaps_when_comments_disabled() {
626626 }
627627}
628628
629+ #[ test]
630+ fn test_parse_experimental_in_tag_comments ( ) {
631+ let allocator = Bump :: new ( ) ;
632+ let ( root, errors) = parse_with_options (
633+ & allocator,
634+ "<LegacySelect\n :options=\" options\" \n // @vue-expect-error legacy API\n :selected-id=\" selectedId\" \n />" ,
635+ ParserOptions {
636+ experimental_in_tag_comments : true ,
637+ ..ParserOptions :: default ( )
638+ } ,
639+ ) ;
640+
641+ assert ! ( errors. is_empty( ) ) ;
642+ assert_eq ! ( root. comments. len( ) , 1 ) ;
643+ assert_eq ! ( root. comments[ 0 ] . kind, CommentKind :: InTag ) ;
644+ assert_eq ! (
645+ root. comments[ 0 ] . content. as_str( ) ,
646+ " @vue-expect-error legacy API"
647+ ) ;
648+
649+ let TemplateChildNode :: Element ( el) = & root. children [ 0 ] else {
650+ panic ! ( "Expected element" ) ;
651+ } ;
652+ assert_eq ! ( el. props. len( ) , 2 ) ;
653+ assert ! (
654+ root. children
655+ . iter( )
656+ . all( |child| !matches!( child, TemplateChildNode :: Comment ( _) ) )
657+ ) ;
658+ }
659+
660+ #[ test]
661+ fn test_parse_in_tag_comments_are_opt_in ( ) {
662+ let allocator = Bump :: new ( ) ;
663+ let ( _root, errors) = parse ( & allocator, "<LegacySelect\n // note\n />" ) ;
664+
665+ assert ! (
666+ errors
667+ . iter( )
668+ . any( |error| error. code == ErrorCode :: UnexpectedSolidusInTag )
669+ ) ;
670+ }
671+
672+ #[ test]
673+ fn test_parse_in_tag_comments_preserve_when_comments_disabled ( ) {
674+ let allocator = Bump :: new ( ) ;
675+ let ( root, errors) = parse_with_options (
676+ & allocator,
677+ "<LegacySelect\n // note\n />" ,
678+ ParserOptions {
679+ comments : false ,
680+ experimental_in_tag_comments : true ,
681+ ..ParserOptions :: default ( )
682+ } ,
683+ ) ;
684+
685+ assert ! ( errors. is_empty( ) ) ;
686+ assert_eq ! ( root. comments. len( ) , 1 ) ;
687+ assert_eq ! ( root. children. len( ) , 1 ) ;
688+ }
689+
690+ #[ test]
691+ fn test_parse_slash_slash_inside_attribute_value_is_not_in_tag_comment ( ) {
692+ let allocator = Bump :: new ( ) ;
693+ let ( root, errors) = parse_with_options (
694+ & allocator,
695+ r#"<div title="not // a comment"></div>"# ,
696+ ParserOptions {
697+ experimental_in_tag_comments : true ,
698+ ..ParserOptions :: default ( )
699+ } ,
700+ ) ;
701+
702+ assert ! ( errors. is_empty( ) ) ;
703+ assert ! ( root. comments. is_empty( ) ) ;
704+ let TemplateChildNode :: Element ( el) = & root. children [ 0 ] else {
705+ panic ! ( "Expected element" ) ;
706+ } ;
707+ let PropNode :: Attribute ( attr) = & el. props [ 0 ] else {
708+ panic ! ( "Expected attribute" ) ;
709+ } ;
710+ assert_eq ! (
711+ attr. value. as_ref( ) . map( |value| value. content. as_str( ) ) ,
712+ Some ( "not // a comment" )
713+ ) ;
714+ }
715+
629716#[ test]
630717fn test_parse_whitespace_condense_preserves_pre_children ( ) {
631718 let allocator = Bump :: new ( ) ;
0 commit comments