Skip to content

Commit

Permalink
fix(es): Fix various bugs. (#1664)
Browse files Browse the repository at this point in the history
swc_ecma_codegen:
 - Emit comments of `BytePos(0)`. (#1657)

swc_ecma_transforms_compat:
 - `classes`: Optimize class expresssions. (#1660)
  • Loading branch information
kdy1 authored May 9, 2021
1 parent 4d013d9 commit b0b0709
Show file tree
Hide file tree
Showing 22 changed files with 251 additions and 155 deletions.
2 changes: 1 addition & 1 deletion ecmascript/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs"]
license = "Apache-2.0/MIT"
name = "swc_ecma_codegen"
repository = "https://github.com/swc-project/swc.git"
version = "0.52.4"
version = "0.52.5"

[dependencies]
bitflags = "1"
Expand Down
15 changes: 10 additions & 5 deletions ecmascript/codegen/src/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ impl<'a> Emitter<'a> {
write_comments!(self, prefix_space, &cmts)
}

pub(super) fn emit_leading_comments_of_pos(&mut self, mut pos: BytePos, is_hi: bool) -> Result {
if pos == BytePos(0) {
return Ok(());
}

pub(super) fn emit_leading_comments(&mut self, mut pos: BytePos, is_hi: bool) -> Result {
if is_hi {
pos = pos - BytePos(1)
}
Expand All @@ -71,4 +67,13 @@ impl<'a> Emitter<'a> {

write_comments!(self, false, comments.take_leading(pos))
}

pub(super) fn emit_leading_comments_of_span(&mut self, span: Span, is_hi: bool) -> Result {
if span.is_dummy() {
return Ok(());
}

let pos = if is_hi { span.hi } else { span.lo };
self.emit_leading_comments(pos, is_hi)
}
}
8 changes: 4 additions & 4 deletions ecmascript/codegen/src/decl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl<'a> Emitter<'a> {

#[emitter]
fn emit_class_decl(&mut self, node: &ClassDecl) -> Result {
self.emit_leading_comments_of_pos(node.span().lo(), false)?;
self.emit_leading_comments_of_span(node.span(), false)?;

if node.declare {
keyword!("declare");
Expand All @@ -44,7 +44,7 @@ impl<'a> Emitter<'a> {

#[emitter]
fn emit_fn_decl(&mut self, node: &FnDecl) -> Result {
self.emit_leading_comments_of_pos(node.span().lo(), false)?;
self.emit_leading_comments_of_span(node.span(), false)?;

if node.declare {
keyword!("declare");
Expand All @@ -71,7 +71,7 @@ impl<'a> Emitter<'a> {

#[emitter]
fn emit_var_decl(&mut self, node: &VarDecl) -> Result {
self.emit_leading_comments_of_pos(node.span.lo(), false)?;
self.emit_leading_comments_of_span(node.span, false)?;

if node.declare {
keyword!("declare");
Expand All @@ -90,7 +90,7 @@ impl<'a> Emitter<'a> {

#[emitter]
fn emit_var_declarator(&mut self, node: &VarDeclarator) -> Result {
self.emit_leading_comments_of_pos(node.span().lo(), false)?;
self.emit_leading_comments_of_span(node.span(), false)?;

emit!(node.name);

Expand Down
Loading

0 comments on commit b0b0709

Please sign in to comment.