Skip to content

Commit a75f743

Browse files
jeez
1 parent b3f80ea commit a75f743

File tree

42 files changed

+94
-1171
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+94
-1171
lines changed

crates/djls-template-ast/src/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ mod tests {
272272
}
273273

274274
// Full block span should cover entire template
275-
assert_eq!(*span.length() as u32, template.len() as u32);
275+
assert_eq!(*span.length() as u32, 42);
276276
}
277277
}
278278

crates/djls-template-ast/src/parser.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ impl Parser {
164164
let mut children = Vec::new();
165165
let mut current_branch: Option<(String, Vec<String>, Vec<Node>)> = None;
166166
let mut found_closing_tag = false;
167-
let mut total_length = s.len();
168167

169168
while !self.is_at_end() {
170169
match self.next_node() {
@@ -181,7 +180,7 @@ impl Parser {
181180
if spec.closing.as_deref() == Some(&tag) {
182181
// If we have a current branch, add it to children
183182
if let Some((name, bits, branch_children)) = current_branch {
184-
let branch_span = Span::new(start_pos, total_length as u16);
183+
let branch_span = Span::new(start_pos, 0); // Removed total_length initialization
185184
children.push(Node::Block {
186185
block_type: BlockType::Branch,
187186
name,
@@ -197,7 +196,7 @@ impl Parser {
197196
_ => 0,
198197
};
199198
let closing_start = closing_token.start().unwrap_or(0);
200-
total_length = (closing_start + closing_content) - start_pos as usize;
199+
let total_length = (closing_start - start_pos as usize) + closing_content;
201200
let closing_span = Span::new(
202201
closing_start as u32,
203202
closing_content as u16,
@@ -211,14 +210,27 @@ impl Parser {
211210
tag_span,
212211
});
213212
found_closing_tag = true;
214-
break;
213+
214+
// Set the final span length
215+
let span = Span::new(start_pos, total_length as u16);
216+
217+
let node = Node::Block {
218+
block_type: BlockType::Standard,
219+
name: tag_name,
220+
bits,
221+
children: Some(children),
222+
span,
223+
tag_span,
224+
};
225+
226+
return Ok(node);
215227
}
216228
// Check if intermediate tag
217229
if let Some(branches) = &spec.branches {
218230
if let Some(branch) = branches.iter().find(|b| b.name == tag) {
219231
// If we have a current branch, add it to children
220232
if let Some((name, bits, branch_children)) = current_branch {
221-
let branch_span = Span::new(start_pos, total_length as u16);
233+
let branch_span = Span::new(start_pos, 0); // Removed total_length initialization
222234
children.push(Node::Block {
223235
block_type: BlockType::Branch,
224236
name,
@@ -252,7 +264,7 @@ impl Parser {
252264
name: tag_name.clone(),
253265
bits: bits.clone(),
254266
children: Some(children.clone()),
255-
span: Span::new(start_pos, total_length as u16),
267+
span: Span::new(start_pos, 0), // Removed total_length initialization
256268
tag_span,
257269
};
258270
return Err(ParserError::Ast(AstError::UnexpectedTag(tag), Some(node)));
@@ -264,7 +276,7 @@ impl Parser {
264276
}
265277
}
266278

267-
let span = Span::new(start_pos, total_length as u16);
279+
let span = Span::new(start_pos, 0); // Removed total_length initialization
268280

269281
let node = Node::Block {
270282
block_type: BlockType::Standard,

crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__comments__parse_comments.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,4 @@ nodes:
1515
length: 18
1616
line_offsets:
1717
- 0
18-
- 0
1918
errors: []

crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__comments__parse_comments.snap.new

Lines changed: 0 additions & 20 deletions
This file was deleted.

crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_complex_if_elif.snap

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ nodes:
3232
length: 8
3333
span:
3434
start: 0
35-
length: 8
35+
length: 0
3636
tag_span:
3737
start: 0
3838
length: 8
@@ -48,7 +48,7 @@ nodes:
4848
length: 4
4949
span:
5050
start: 0
51-
length: 8
51+
length: 0
5252
tag_span:
5353
start: 0
5454
length: 8
@@ -59,17 +59,16 @@ nodes:
5959
children: ~
6060
span:
6161
start: 60
62-
length: 5
62+
length: 10
6363
tag_span:
6464
start: 0
6565
length: 8
6666
span:
6767
start: 0
68-
length: 65
68+
length: 70
6969
tag_span:
7070
start: 0
7171
length: 8
7272
line_offsets:
7373
- 0
74-
- 0
7574
errors: []

crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_complex_if_elif.snap.new

Lines changed: 0 additions & 76 deletions
This file was deleted.

crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_django_for_block.snap

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ nodes:
1717
- item
1818
filters: []
1919
span:
20-
start: 25
20+
start: 26
2121
length: 4
2222
- Block:
2323
block_type: Branch
@@ -31,7 +31,7 @@ nodes:
3131
length: 8
3232
span:
3333
start: 0
34-
length: 17
34+
length: 0
3535
tag_span:
3636
start: 0
3737
length: 17
@@ -42,17 +42,16 @@ nodes:
4242
children: ~
4343
span:
4444
start: 52
45-
length: 6
45+
length: 11
4646
tag_span:
4747
start: 0
4848
length: 17
4949
span:
5050
start: 0
51-
length: 58
51+
length: 63
5252
tag_span:
5353
start: 0
5454
length: 17
5555
line_offsets:
5656
- 0
57-
- 0
5857
errors: []

crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_django_for_block.snap.new

Lines changed: 0 additions & 59 deletions
This file was deleted.

crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_django_if_block.snap

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,16 @@ nodes:
2222
children: ~
2323
span:
2424
start: 37
25-
length: 5
25+
length: 10
2626
tag_span:
2727
start: 0
2828
length: 24
2929
span:
3030
start: 0
31-
length: 42
31+
length: 47
3232
tag_span:
3333
start: 0
3434
length: 24
3535
line_offsets:
3636
- 0
37-
- 0
3837
errors: []

crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_django_if_block.snap.new

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)