emit comments inside @if rule

This commit is contained in:
Connor Skees 2021-07-14 21:19:18 -04:00
parent 1a660c7aa8
commit 839f101829
2 changed files with 30 additions and 2 deletions

View File

@ -29,11 +29,10 @@ impl<'a> Parser<'a> {
return Err(("expected \"}\".", self.span_before).into());
}
self.whitespace_or_comment();
if init_cond.is_true() {
self.scopes.enter_new_scope();
found_true = true;
body = Parser {
toks: self.toks,
map: self.map,
@ -53,6 +52,7 @@ impl<'a> Parser<'a> {
module_config: self.module_config,
}
.parse_stmt()?;
self.scopes.exit_scope();
} else {
self.throw_away_until_closing_curly_brace()?;
@ -108,6 +108,7 @@ impl<'a> Parser<'a> {
module_config: self.module_config,
}
.parse_stmt()?;
self.scopes.exit_scope();
} else {
self.throw_away_until_closing_curly_brace()?;

View File

@ -184,6 +184,33 @@ test!(
}",
""
);
test!(
comment_inside_if_body,
"@if true {
/* a */
}",
"/* a */\n"
);
test!(
comment_inside_if_else_body,
"@if false {
/* a */
} @else if true {
/* b */
}",
"/* b */\n"
);
test!(
comment_inside_else_body,
"@if false {
/* a */
} @else if false {
/* b */
} @else {
/* c */
}",
"/* c */\n"
);
error!(
nothing_after_escape,
"@if \\", "Error: Expected expression."