Skip to content

Commit

Permalink
fix(swc): Fix bugs (#1529)
Browse files Browse the repository at this point in the history
swc_ecma_parser:
 - Fix comment positions. (#1530)

swc_ecam_transforms_compat:
 - Handle default in destructuring binding patterns. (#1477, #1449)
 - `async_to_generator`: Handle `this` correctly for async function in key-value properties. (#1455)

swc_ecam_transforms_typescript:
 - Handle import defaults. (#1448)
  • Loading branch information
kdy1 authored Apr 2, 2021
1 parent b9f5a50 commit 252804d
Show file tree
Hide file tree
Showing 44 changed files with 1,014 additions and 209 deletions.
4 changes: 2 additions & 2 deletions ecmascript/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"
license = "Apache-2.0/MIT"
name = "swc_ecmascript"
repository = "https://github.com/swc-project/swc.git"
version = "0.29.0"
version = "0.29.1"

[package.metadata.docs.rs]
all-features = true
Expand All @@ -30,7 +30,7 @@ typescript = ["swc_ecma_transforms/typescript"]
swc_ecma_ast = {version = "0.42.0", path = "./ast"}
swc_ecma_codegen = {version = "0.50.0", path = "./codegen", optional = true}
swc_ecma_dep_graph = {version = "0.20.0", path = "./dep-graph", optional = true}
swc_ecma_parser = {version = "0.52.0", path = "./parser", optional = true}
swc_ecma_parser = {version = "0.52.1", path = "./parser", optional = true}
swc_ecma_transforms = {version = "0.43.0", path = "./transforms", optional = true}
swc_ecma_utils = {version = "0.33.0", path = "./utils", optional = true}
swc_ecma_visit = {version = "0.28.0", path = "./visit", optional = true}
Expand Down
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.50.2"
version = "0.50.3"

[dependencies]
bitflags = "1"
Expand Down
7 changes: 6 additions & 1 deletion ecmascript/codegen/src/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ impl<'a> Emitter<'a> {
&mut self,
pos: BytePos,
prefix_space: bool,
_is_hi: bool,
) -> Result {
if pos == BytePos(0) {
return Ok(());
Expand All @@ -54,11 +55,15 @@ impl<'a> Emitter<'a> {
write_comments!(self, prefix_space, &cmts)
}

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

if is_hi {
pos = pos - BytePos(1)
}

let comments = match self.comments {
Some(ref comments) => comments,
None => return Ok(()),
Expand Down
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())?;
self.emit_leading_comments_of_pos(node.span().lo(), 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())?;
self.emit_leading_comments_of_pos(node.span().lo(), 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())?;
self.emit_leading_comments_of_pos(node.span.lo(), 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())?;
self.emit_leading_comments_of_pos(node.span().lo(), false)?;

emit!(node.name);

Expand Down
Loading

0 comments on commit 252804d

Please sign in to comment.