Fix so that only comments doesn't format to empty
This commit is contained in:
@ -60,11 +60,8 @@ pub fn parse_tokens(mut tokens: TokenStream) -> ParseResult {
|
|||||||
return Node::<Program>::default().into();
|
return Node::<Program>::default().into();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check all the tokens are whitespace or comments.
|
// Check all the tokens are whitespace.
|
||||||
if tokens
|
if tokens.iter().all(|t| t.token_type.is_whitespace()) {
|
||||||
.iter()
|
|
||||||
.all(|t| t.token_type.is_whitespace() || t.token_type.is_comment())
|
|
||||||
{
|
|
||||||
return Node::<Program>::default().into();
|
return Node::<Program>::default().into();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2039,6 +2039,15 @@ thing = 'foo'
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_recast_only_line_comments() {
|
||||||
|
let code = r#"// comment at start
|
||||||
|
"#;
|
||||||
|
let program = crate::parsing::top_level_parse(code).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(program.recast(&Default::default(), 0), code);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_recast_comment_at_start() {
|
fn test_recast_comment_at_start() {
|
||||||
let test_program = r#"
|
let test_program = r#"
|
||||||
|
Reference in New Issue
Block a user