fix logic for adding or not a newline after a missed span

This commit is contained in:
Stéphane Campinas 2018-11-09 20:50:07 +01:00
parent 4e2f741917
commit d121d7205f
No known key found for this signature in database
GPG key ID: 6D5620D908210133
3 changed files with 46 additions and 9 deletions

View file

@ -259,15 +259,16 @@ impl<'a> FmtVisitor<'a> {
status.last_wspace = None;
status.line_start = offset + subslice.len();
if let Some('/') = subslice.chars().nth(1) {
// Only add a newline if the last line is a line comment
if !subslice.trim_end().ends_with("*/") {
self.push_str("\n");
}
} else if status.line_start <= snippet.len() {
// For other comments add a newline if there isn't one at the end already
// Add a newline:
// - if there isn't one already
// - otherwise, only if the last line is a line comment
if status.line_start <= snippet.len() {
match snippet[status.line_start..].chars().next() {
Some('\n') | Some('\r') => (),
Some('\n') | Some('\r') => {
if !subslice.trim_end().ends_with("*/") {
self.push_str("\n");
}
}
_ => self.push_str("\n"),
}
}

View file

@ -236,7 +236,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
}
}
let unindent_comment = (self.is_if_else_block && !b.stmts.is_empty()) && {
let unindent_comment = self.is_if_else_block && !b.stmts.is_empty() && {
let end_pos = source!(self, b.span).hi() - brace_compensation - remove_len;
let snippet = self.snippet(mk_sp(self.last_pos, end_pos));
snippet.contains("//") || snippet.contains("/*")

View file

@ -0,0 +1,36 @@
pub fn get_array_index_from_id(_cx: *mut JSContext, id: HandleId) -> Option<u32> {
let raw_id = id.into();
unsafe {
if RUST_JSID_IS_INT(raw_id) {
return Some(RUST_JSID_TO_INT(raw_id) as u32);
}
None
}
// if id is length atom, -1, otherwise
/*return if JSID_IS_ATOM(id) {
let atom = JSID_TO_ATOM(id);
//let s = *GetAtomChars(id);
if s > 'a' && s < 'z' {
return -1;
}
let i = 0;
let str = AtomToLinearString(JSID_TO_ATOM(id));
return if StringIsArray(str, &mut i) != 0 { i } else { -1 }
} else {
IdToInt32(cx, id);
}*/
}
impl Foo {
fn bar() -> usize {
42
/* a block comment */
}
fn baz() -> usize {
42
// this is a line
/* a block comment */
}
}