mirror of
https://github.com/swc-project/swc.git
synced 2024-11-23 17:54:15 +03:00
Fix #415
This commit is contained in:
parent
4f8220329f
commit
c20176820e
@ -1636,8 +1636,22 @@ impl<'a> Emitter<'a> {
|
||||
|
||||
keyword!("return");
|
||||
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!();
|
||||
emit!(arg)
|
||||
emit!(arg);
|
||||
if need_paren {
|
||||
punct!(")");
|
||||
}
|
||||
}
|
||||
semi!();
|
||||
}
|
||||
|
@ -246,6 +246,13 @@ impl State {
|
||||
.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 {
|
||||
match self.token_type {
|
||||
Some(TokenType::Template) => true,
|
||||
|
@ -205,7 +205,7 @@ impl<'a, I: Input> Lexer<'a, I> {
|
||||
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() {
|
||||
if was_star && c == '/' {
|
||||
|
Loading…
Reference in New Issue
Block a user