@@ -23,6 +23,7 @@ use crate::ast::Span;
23
23
use crate :: ast:: TagName ;
24
24
use crate :: ast:: TagNode ;
25
25
use crate :: db:: Db as TemplateDb ;
26
+ use crate :: templatetags:: ArgSpec ;
26
27
use crate :: templatetags:: TagType ;
27
28
use crate :: Ast ;
28
29
@@ -52,25 +53,34 @@ impl<'db> TagValidator<'db> {
52
53
if let Some ( Node :: Tag { name, bits, span } ) = self . current_node ( ) {
53
54
let name_str = name. text ( self . db ) ;
54
55
55
- match TagType :: for_name ( & name_str, & self . db . tag_specs ( ) ) {
56
+ let tag_specs = self . db . tag_specs ( ) ;
57
+ let tag_type = TagType :: for_name ( & name_str, & tag_specs) ;
58
+
59
+ let arg_spec = match tag_type {
60
+ TagType :: Closer => tag_specs
61
+ . get_end_spec_for_closer ( & name_str)
62
+ . and_then ( |s| s. args . as_ref ( ) ) ,
63
+ _ => tag_specs. get ( & name_str) . and_then ( |s| s. args . as_ref ( ) ) ,
64
+ } ;
65
+
66
+ self . check_arguments ( & name_str, & bits, span, arg_spec) ;
67
+
68
+ match tag_type {
56
69
TagType :: Opener => {
57
- self . check_arguments ( & name_str, & bits, span) ;
58
70
self . stack . push ( TagNode {
59
71
name,
60
72
bits : bits. clone ( ) ,
61
73
span,
62
74
} ) ;
63
75
}
64
76
TagType :: Intermediate => {
65
- self . check_arguments ( & name_str, & bits, span) ;
66
77
self . handle_intermediate ( & name_str, span) ;
67
78
}
68
79
TagType :: Closer => {
69
- self . check_closer_arguments ( & name_str, & bits, span) ;
70
80
self . handle_closer ( name, & bits, span) ;
71
81
}
72
82
TagType :: Standalone => {
73
- self . check_arguments ( & name_str , & bits , span ) ;
83
+ // No additional action needed for standalone tags
74
84
}
75
85
}
76
86
}
@@ -89,46 +99,14 @@ impl<'db> TagValidator<'db> {
89
99
self . errors
90
100
}
91
101
92
- fn check_arguments ( & mut self , name : & str , bits : & [ String ] , span : Span < ' db > ) {
93
- let tag_specs = self . db . tag_specs ( ) ;
94
- let Some ( spec) = tag_specs. get ( name) else {
95
- return ;
96
- } ;
97
-
98
- let Some ( arg_spec) = & spec. args else {
99
- return ;
100
- } ;
101
-
102
- if let Some ( min) = arg_spec. min {
103
- if bits. len ( ) < min {
104
- self . errors . push ( AstError :: MissingRequiredArguments {
105
- tag : name. to_string ( ) ,
106
- min,
107
- span_start : span. start ( self . db ) ,
108
- span_length : span. length ( self . db ) ,
109
- } ) ;
110
- }
111
- }
112
-
113
- if let Some ( max) = arg_spec. max {
114
- if bits. len ( ) > max {
115
- self . errors . push ( AstError :: TooManyArguments {
116
- tag : name. to_string ( ) ,
117
- max,
118
- span_start : span. start ( self . db ) ,
119
- span_length : span. length ( self . db ) ,
120
- } ) ;
121
- }
122
- }
123
- }
124
-
125
- fn check_closer_arguments ( & mut self , name : & str , bits : & [ String ] , span : Span < ' db > ) {
126
- let tag_specs = self . db . tag_specs ( ) ;
127
- let Some ( end_spec) = tag_specs. get_end_spec_for_closer ( name) else {
128
- return ;
129
- } ;
130
-
131
- let Some ( arg_spec) = & end_spec. args else {
102
+ fn check_arguments (
103
+ & mut self ,
104
+ name : & str ,
105
+ bits : & [ String ] ,
106
+ span : Span < ' db > ,
107
+ arg_spec : Option < & ArgSpec > ,
108
+ ) {
109
+ let Some ( arg_spec) = arg_spec else {
132
110
return ;
133
111
} ;
134
112
0 commit comments