This commit is contained in:
강동윤 2019-09-20 23:07:24 +09:00
parent 4f8220329f
commit c20176820e
3 changed files with 23 additions and 2 deletions

View File

@ -1636,8 +1636,22 @@ impl<'a> Emitter<'a> {
keyword!("return"); keyword!("return");
if let Some(ref arg) = node.arg { if let Some(ref arg) = node.arg {
let need_paren = if let Some(cmt) = self.comments {
!self.pos_of_leading_comments.contains(&arg.span().lo()) && {
// see #415
cmt.leading_comments(arg.span().lo()).is_some()
}
} else {
false
};
if need_paren {
punct!("(");
}
space!(); space!();
emit!(arg) emit!(arg);
if need_paren {
punct!(")");
}
} }
semi!(); semi!();
} }

View File

@ -246,6 +246,13 @@ impl State {
.unwrap_or(false) .unwrap_or(false)
} }
pub fn last_was_return(&self) -> bool {
match self.token_type {
Some(TokenType::Keyword(Keyword::Return)) => true,
_ => false,
}
}
pub fn last_was_tpl_element(&self) -> bool { pub fn last_was_tpl_element(&self) -> bool {
match self.token_type { match self.token_type {
Some(TokenType::Template) => true, Some(TokenType::Template) => true,

View File

@ -205,7 +205,7 @@ impl<'a, I: Input> Lexer<'a, I> {
false false
}; };
let is_for_next = self.state.had_line_break; let is_for_next = self.state.had_line_break || self.state.last_was_return();
while let Some(c) = self.cur() { while let Some(c) = self.cur() {
if was_star && c == '/' { if was_star && c == '/' {