From a862c5e817ce369c4c4c37afa1f7691d6b48b68f Mon Sep 17 00:00:00 2001 From: UMASHIBA Date: Tue, 16 Nov 2021 18:07:32 +0900 Subject: [PATCH 1/9] chore add println for debug --- crates/swc/src/lib.rs | 12 ++++++++++++ crates/swc_ecma_codegen/src/comments.rs | 6 ++++++ crates/swc_ecma_codegen/src/decl.rs | 3 +++ crates/swc_ecma_codegen/src/lib.rs | 18 +++++++++++++++++- .../src/es2017/async_to_generator.rs | 9 ++++++++- 5 files changed, 46 insertions(+), 2 deletions(-) diff --git a/crates/swc/src/lib.rs b/crates/swc/src/lib.rs index 3f474aab71f4..27dc4731f47b 100644 --- a/crates/swc/src/lib.rs +++ b/crates/swc/src/lib.rs @@ -484,6 +484,10 @@ impl Compiler { }); let span = node.span(); + println!("span: {:?}", span); + + println!("leading: {:?}", self.comments.leading); + println!("trailing: {:?}", self.comments.trailing); match preserve_comments { BoolOrObject::Bool(true) @@ -519,6 +523,7 @@ impl Compiler { self.comments.trailing.retain(remove_all_in_range); } } + println!("leading after: {:?}", self.comments.leading); let mut src_map_buf = vec![]; @@ -548,12 +553,17 @@ impl Compiler { wr, }; + println!("emitter comment: {:?}", self.comments.leading); + node.emit_with(&mut emitter) .context("failed to emit module")?; } // Invalid utf8 is valid in javascript world. String::from_utf8(buf).expect("invalid utf8 character detected") }; + + println!("src: {}", src); + let (code, map) = match source_map { SourceMapsConfig::Bool(v) => { if v { @@ -1076,6 +1086,8 @@ impl Compiler { }) }); + println!("before self.print program: {:?}", program); + self.print( &program, config.source_file_name.as_deref(), diff --git a/crates/swc_ecma_codegen/src/comments.rs b/crates/swc_ecma_codegen/src/comments.rs index 2388cbb68438..3e030e090203 100644 --- a/crates/swc_ecma_codegen/src/comments.rs +++ b/crates/swc_ecma_codegen/src/comments.rs @@ -64,6 +64,12 @@ where None => return Ok(()), }; + println!( + "run emit_leading_comments: pos: {:?}, comment.leading: {:?}", + pos, + comments.get_leading(pos) + ); + if is_hi { pos = pos - BytePos(1) } diff --git a/crates/swc_ecma_codegen/src/decl.rs b/crates/swc_ecma_codegen/src/decl.rs index 6895f90fd459..03fcd41af5d2 100644 --- a/crates/swc_ecma_codegen/src/decl.rs +++ b/crates/swc_ecma_codegen/src/decl.rs @@ -54,7 +54,10 @@ where space!(); } + println!("run emit_fn_decl"); + if node.function.is_async { + println!("run async emit_fn_decl"); keyword!("async"); space!(); } diff --git a/crates/swc_ecma_codegen/src/lib.rs b/crates/swc_ecma_codegen/src/lib.rs index ca2077f5ac5d..f2710663b85d 100644 --- a/crates/swc_ecma_codegen/src/lib.rs +++ b/crates/swc_ecma_codegen/src/lib.rs @@ -1315,6 +1315,8 @@ where fn emit_fn_expr(&mut self, n: &FnExpr) -> Result { self.emit_leading_comments_of_span(n.span(), false)?; + println!("run emit_fn_expr: {:?}, {:?}", n.function.span.lo, n.span()); + if n.function.is_async { keyword!("async"); space!(); @@ -1600,6 +1602,7 @@ where #[emitter] fn emit_prop(&mut self, node: &Prop) -> Result { + println!("run emit_prop{:?}", node); match *node { Prop::Shorthand(ref n) => emit!(n), Prop::KeyValue(ref n) => emit!(n), @@ -1613,7 +1616,11 @@ where #[emitter] fn emit_kv_prop(&mut self, node: &KeyValueProp) -> Result { self.emit_leading_comments_of_span(node.span(), false)?; - + println!( + "run kv_prop, node.span: {:?}, key: {:?}", + node.span(), + node.key + ); emit!(node.key); punct!(":"); formatting_space!(); @@ -1682,6 +1689,7 @@ where #[emitter] fn emit_method_prop(&mut self, node: &MethodProp) -> Result { self.emit_leading_comments_of_span(node.span(), false)?; + println!("run emit_method_prop"); if node.function.is_async { keyword!("async"); @@ -1742,6 +1750,7 @@ where fn emit_ident(&mut self, ident: &Ident) -> Result { // TODO: Use write_symbol when ident is a symbol. self.emit_leading_comments_of_span(ident.span, false)?; + println!("run emit_ident: {:?}", ident.span); // TODO: span self.wr @@ -1895,8 +1904,12 @@ where } } + println!("before run child.emit_with"); + child.emit_with(self)?; + println!("after run child.emit_with"); + // Emit this child. if should_emit_intervening_comments { if self.comments.is_some() { @@ -2356,6 +2369,8 @@ where fn emit_return_stmt(&mut self, n: &ReturnStmt) -> Result { self.emit_leading_comments_of_span(n.span, false)?; + println!("run emit_return: {:?}", n.span()); + { let span = if n.span.is_dummy() { DUMMY_SP @@ -2371,6 +2386,7 @@ where .as_deref() .map(|expr| self.has_leading_comment(expr)) .unwrap_or(false); + println!("run need_paren in emit_return"); if need_paren { punct!("("); } else { diff --git a/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs b/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs index 6d544a7c7955..bf13f86dd393 100644 --- a/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs +++ b/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs @@ -32,6 +32,7 @@ use swc_ecma_visit::{ /// }); /// ``` pub fn async_to_generator() -> impl Fold + VisitMut { + println!("run async_to_generator"); as_folder(AsyncToGenerator) } @@ -63,6 +64,7 @@ impl AsyncToGenerator { T: StmtLike + VisitMutWith, Vec: VisitMutWith, { + println!("run visit_mut_stmt_like"); stmts.visit_mut_children_with(self); let mut stmts_updated = Vec::with_capacity(stmts.len()); @@ -73,8 +75,9 @@ impl AsyncToGenerator { in_prototype_assignment: false, extra_stmts: vec![], }; - + println!("before visit_mut_with: {:?}", stmt.as_stmt()); stmt.visit_mut_with(&mut actual); + println!("after visit_mut_with: {:?}", stmt.as_stmt()); stmts_updated.push(stmt); stmts_updated.extend(actual.extra_stmts.into_iter().map(T::from_stmt)); } @@ -385,7 +388,9 @@ impl VisitMut for Actual { } fn visit_mut_method_prop(&mut self, prop: &mut MethodProp) { + println!("visit_mut_method_prop before: {:?}", &prop); prop.visit_mut_children_with(self); + println!("visit_mut_method_prop after: {:?}", &prop); if !prop.function.is_async { return; @@ -421,6 +426,8 @@ impl VisitMut for Actual { }) }; + println!("\nprop span: {:?}\n", prop); + prop.function = Function { params: original_fn_params, span: DUMMY_SP, From df5fe73fe0168e9a242a7356e56953f236ec219f Mon Sep 17 00:00:00 2001 From: UMASHIBA Date: Tue, 16 Nov 2021 18:16:36 +0900 Subject: [PATCH 2/9] test: add test --- .../tests/fixture/issue-2701/1/input/.swcrc | 13 +++++++ .../tests/fixture/issue-2701/1/input/index.js | 6 +++ .../fixture/issue-2701/1/output/index.js | 37 +++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 crates/swc/tests/fixture/issue-2701/1/input/.swcrc create mode 100644 crates/swc/tests/fixture/issue-2701/1/input/index.js create mode 100644 crates/swc/tests/fixture/issue-2701/1/output/index.js diff --git a/crates/swc/tests/fixture/issue-2701/1/input/.swcrc b/crates/swc/tests/fixture/issue-2701/1/input/.swcrc new file mode 100644 index 000000000000..d7328379af1c --- /dev/null +++ b/crates/swc/tests/fixture/issue-2701/1/input/.swcrc @@ -0,0 +1,13 @@ +{ + "jsc": { + "externalHelpers": false, + "parser": { + "syntax": "ecmascript", + "jsx": false + }, + "target": "es2016" + }, + "module": { + "type": "es6" + } + } \ No newline at end of file diff --git a/crates/swc/tests/fixture/issue-2701/1/input/index.js b/crates/swc/tests/fixture/issue-2701/1/input/index.js new file mode 100644 index 000000000000..131224fb87c8 --- /dev/null +++ b/crates/swc/tests/fixture/issue-2701/1/input/index.js @@ -0,0 +1,6 @@ +const x = { + // i am some comment + async hello() { + console.log("Hello"); + }, +}; diff --git a/crates/swc/tests/fixture/issue-2701/1/output/index.js b/crates/swc/tests/fixture/issue-2701/1/output/index.js new file mode 100644 index 000000000000..b848da6a4caf --- /dev/null +++ b/crates/swc/tests/fixture/issue-2701/1/output/index.js @@ -0,0 +1,37 @@ +function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { + try { + var info = gen[key](arg); + var value = info.value; + } catch (error) { + reject(error); + return; + } + if (info.done) { + resolve(value); + } else { + Promise.resolve(value).then(_next, _throw); + } +} +function _asyncToGenerator(fn) { + return function() { + var self = this, args = arguments; + return new Promise(function(resolve, reject) { + var gen = fn.apply(self, args); + function _next(value) { + asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); + } + function _throw(err) { + asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); + } + _next(undefined); + }); + }; +} +const x = { + // i am some comment + hello () { + return _asyncToGenerator(function*() { + console.log("Hello"); + })(); + } +}; From 92fd35161557f385c614b268b4815b05f7479606 Mon Sep 17 00:00:00 2001 From: UMASHIBA Date: Tue, 16 Nov 2021 22:44:38 +0900 Subject: [PATCH 3/9] fix: fix early return caused by comment in object async method --- .../src/es2017/async_to_generator.rs | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs b/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs index bf13f86dd393..8eec8844d73b 100644 --- a/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs +++ b/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs @@ -1,5 +1,5 @@ use std::{iter, mem::replace}; -use swc_common::{util::take::Take, Mark, Span, Spanned, DUMMY_SP}; +use swc_common::{util::take::Take, BytePos, Mark, Span, Spanned, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::{helper, perf::Check}; use swc_ecma_transforms_macros::fast_path; @@ -428,9 +428,28 @@ impl VisitMut for Actual { println!("\nprop span: {:?}\n", prop); + let func_span_lo = { + let key_span_lo = match &prop.key { + PropName::Ident(ident) => ident.span().lo(), + PropName::Str(str) => str.span().lo(), + PropName::Num(num) => num.span().lo(), + PropName::Computed(computed) => computed.span().lo(), + PropName::BigInt(bigint) => bigint.span().lo(), + }; + + // sub length of "async " from prop's key span + key_span_lo - BytePos(6) + }; + + let func_span = Span::new( + func_span_lo, + func_span_lo + BytePos(1), // dummy pos + SyntaxContext::empty(), + ); + prop.function = Function { params: original_fn_params, - span: DUMMY_SP, + span: func_span, is_async: false, is_generator: false, body: Some(BlockStmt { From 00fc110d524da0f95a7ceff33af9e4834132d65b Mon Sep 17 00:00:00 2001 From: UMASHIBA Date: Tue, 16 Nov 2021 22:45:57 +0900 Subject: [PATCH 4/9] test: fix issue-2701 test --- crates/swc/tests/fixture/issue-2701/1/output/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc/tests/fixture/issue-2701/1/output/index.js b/crates/swc/tests/fixture/issue-2701/1/output/index.js index b848da6a4caf..a96d2d9879e9 100644 --- a/crates/swc/tests/fixture/issue-2701/1/output/index.js +++ b/crates/swc/tests/fixture/issue-2701/1/output/index.js @@ -28,7 +28,7 @@ function _asyncToGenerator(fn) { }; } const x = { - // i am some comment + // i am some comment hello () { return _asyncToGenerator(function*() { console.log("Hello"); From b4a5926cec66e89446fb194264ec26d811e12b1c Mon Sep 17 00:00:00 2001 From: UMASHIBA Date: Tue, 16 Nov 2021 23:49:19 +0900 Subject: [PATCH 5/9] chore: remove println for debug --- crates/swc/src/lib.rs | 10 ---------- crates/swc_ecma_codegen/src/comments.rs | 6 ------ crates/swc_ecma_codegen/src/decl.rs | 3 --- crates/swc_ecma_codegen/src/lib.rs | 17 ----------------- .../src/es2017/async_to_generator.rs | 8 -------- 5 files changed, 44 deletions(-) diff --git a/crates/swc/src/lib.rs b/crates/swc/src/lib.rs index 27dc4731f47b..39ef608eb1df 100644 --- a/crates/swc/src/lib.rs +++ b/crates/swc/src/lib.rs @@ -484,10 +484,6 @@ impl Compiler { }); let span = node.span(); - println!("span: {:?}", span); - - println!("leading: {:?}", self.comments.leading); - println!("trailing: {:?}", self.comments.trailing); match preserve_comments { BoolOrObject::Bool(true) @@ -523,7 +519,6 @@ impl Compiler { self.comments.trailing.retain(remove_all_in_range); } } - println!("leading after: {:?}", self.comments.leading); let mut src_map_buf = vec![]; @@ -553,7 +548,6 @@ impl Compiler { wr, }; - println!("emitter comment: {:?}", self.comments.leading); node.emit_with(&mut emitter) .context("failed to emit module")?; @@ -562,8 +556,6 @@ impl Compiler { String::from_utf8(buf).expect("invalid utf8 character detected") }; - println!("src: {}", src); - let (code, map) = match source_map { SourceMapsConfig::Bool(v) => { if v { @@ -1086,8 +1078,6 @@ impl Compiler { }) }); - println!("before self.print program: {:?}", program); - self.print( &program, config.source_file_name.as_deref(), diff --git a/crates/swc_ecma_codegen/src/comments.rs b/crates/swc_ecma_codegen/src/comments.rs index 3e030e090203..2388cbb68438 100644 --- a/crates/swc_ecma_codegen/src/comments.rs +++ b/crates/swc_ecma_codegen/src/comments.rs @@ -64,12 +64,6 @@ where None => return Ok(()), }; - println!( - "run emit_leading_comments: pos: {:?}, comment.leading: {:?}", - pos, - comments.get_leading(pos) - ); - if is_hi { pos = pos - BytePos(1) } diff --git a/crates/swc_ecma_codegen/src/decl.rs b/crates/swc_ecma_codegen/src/decl.rs index 03fcd41af5d2..6895f90fd459 100644 --- a/crates/swc_ecma_codegen/src/decl.rs +++ b/crates/swc_ecma_codegen/src/decl.rs @@ -54,10 +54,7 @@ where space!(); } - println!("run emit_fn_decl"); - if node.function.is_async { - println!("run async emit_fn_decl"); keyword!("async"); space!(); } diff --git a/crates/swc_ecma_codegen/src/lib.rs b/crates/swc_ecma_codegen/src/lib.rs index f2710663b85d..ed820fbe91c8 100644 --- a/crates/swc_ecma_codegen/src/lib.rs +++ b/crates/swc_ecma_codegen/src/lib.rs @@ -1315,8 +1315,6 @@ where fn emit_fn_expr(&mut self, n: &FnExpr) -> Result { self.emit_leading_comments_of_span(n.span(), false)?; - println!("run emit_fn_expr: {:?}, {:?}", n.function.span.lo, n.span()); - if n.function.is_async { keyword!("async"); space!(); @@ -1602,7 +1600,6 @@ where #[emitter] fn emit_prop(&mut self, node: &Prop) -> Result { - println!("run emit_prop{:?}", node); match *node { Prop::Shorthand(ref n) => emit!(n), Prop::KeyValue(ref n) => emit!(n), @@ -1616,11 +1613,6 @@ where #[emitter] fn emit_kv_prop(&mut self, node: &KeyValueProp) -> Result { self.emit_leading_comments_of_span(node.span(), false)?; - println!( - "run kv_prop, node.span: {:?}, key: {:?}", - node.span(), - node.key - ); emit!(node.key); punct!(":"); formatting_space!(); @@ -1689,7 +1681,6 @@ where #[emitter] fn emit_method_prop(&mut self, node: &MethodProp) -> Result { self.emit_leading_comments_of_span(node.span(), false)?; - println!("run emit_method_prop"); if node.function.is_async { keyword!("async"); @@ -1750,7 +1741,6 @@ where fn emit_ident(&mut self, ident: &Ident) -> Result { // TODO: Use write_symbol when ident is a symbol. self.emit_leading_comments_of_span(ident.span, false)?; - println!("run emit_ident: {:?}", ident.span); // TODO: span self.wr @@ -1904,12 +1894,8 @@ where } } - println!("before run child.emit_with"); - child.emit_with(self)?; - println!("after run child.emit_with"); - // Emit this child. if should_emit_intervening_comments { if self.comments.is_some() { @@ -2369,8 +2355,6 @@ where fn emit_return_stmt(&mut self, n: &ReturnStmt) -> Result { self.emit_leading_comments_of_span(n.span, false)?; - println!("run emit_return: {:?}", n.span()); - { let span = if n.span.is_dummy() { DUMMY_SP @@ -2386,7 +2370,6 @@ where .as_deref() .map(|expr| self.has_leading_comment(expr)) .unwrap_or(false); - println!("run need_paren in emit_return"); if need_paren { punct!("("); } else { diff --git a/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs b/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs index 8eec8844d73b..eae331501104 100644 --- a/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs +++ b/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs @@ -32,7 +32,6 @@ use swc_ecma_visit::{ /// }); /// ``` pub fn async_to_generator() -> impl Fold + VisitMut { - println!("run async_to_generator"); as_folder(AsyncToGenerator) } @@ -64,7 +63,6 @@ impl AsyncToGenerator { T: StmtLike + VisitMutWith, Vec: VisitMutWith, { - println!("run visit_mut_stmt_like"); stmts.visit_mut_children_with(self); let mut stmts_updated = Vec::with_capacity(stmts.len()); @@ -75,9 +73,7 @@ impl AsyncToGenerator { in_prototype_assignment: false, extra_stmts: vec![], }; - println!("before visit_mut_with: {:?}", stmt.as_stmt()); stmt.visit_mut_with(&mut actual); - println!("after visit_mut_with: {:?}", stmt.as_stmt()); stmts_updated.push(stmt); stmts_updated.extend(actual.extra_stmts.into_iter().map(T::from_stmt)); } @@ -388,9 +384,7 @@ impl VisitMut for Actual { } fn visit_mut_method_prop(&mut self, prop: &mut MethodProp) { - println!("visit_mut_method_prop before: {:?}", &prop); prop.visit_mut_children_with(self); - println!("visit_mut_method_prop after: {:?}", &prop); if !prop.function.is_async { return; @@ -426,8 +420,6 @@ impl VisitMut for Actual { }) }; - println!("\nprop span: {:?}\n", prop); - let func_span_lo = { let key_span_lo = match &prop.key { PropName::Ident(ident) => ident.span().lo(), From 88f383ca3e01d9f9e466f000c97cca4baddd99fa Mon Sep 17 00:00:00 2001 From: UMASHIBA Date: Tue, 16 Nov 2021 23:52:06 +0900 Subject: [PATCH 6/9] chore: fmt --- crates/swc/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/swc/src/lib.rs b/crates/swc/src/lib.rs index 39ef608eb1df..52d6c797daf3 100644 --- a/crates/swc/src/lib.rs +++ b/crates/swc/src/lib.rs @@ -548,7 +548,6 @@ impl Compiler { wr, }; - node.emit_with(&mut emitter) .context("failed to emit module")?; } From 59757e2b283af1a1d3db7073f6eb4d9ea6cd657c Mon Sep 17 00:00:00 2001 From: UMASHIBA Date: Wed, 17 Nov 2021 00:50:44 +0900 Subject: [PATCH 7/9] test: change issue-2701 test --- .../tests/fixture/issue-2701/1/input/index.js | 22 +++++++++++++--- .../fixture/issue-2701/1/output/index.js | 26 ++++++++++++++++++- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/crates/swc/tests/fixture/issue-2701/1/input/index.js b/crates/swc/tests/fixture/issue-2701/1/input/index.js index 131224fb87c8..aed69abe2031 100644 --- a/crates/swc/tests/fixture/issue-2701/1/input/index.js +++ b/crates/swc/tests/fixture/issue-2701/1/input/index.js @@ -1,6 +1,22 @@ const x = { - // i am some comment + // i am some comment1 async hello() { - console.log("Hello"); + console.log("Hello") }, -}; + // i am some comment2 + async "hello"(){ + console.log("Hello") + }, + // i am some comment3 + async 1(){ + console.log("Hello") + }, + // i am some comment4 + async [Date.now()](){ + console.log("Hello") + }, + // i am some comment5 + async 1n() { + console.log("Hello") + } +}; \ No newline at end of file diff --git a/crates/swc/tests/fixture/issue-2701/1/output/index.js b/crates/swc/tests/fixture/issue-2701/1/output/index.js index a96d2d9879e9..8c467ba26270 100644 --- a/crates/swc/tests/fixture/issue-2701/1/output/index.js +++ b/crates/swc/tests/fixture/issue-2701/1/output/index.js @@ -28,10 +28,34 @@ function _asyncToGenerator(fn) { }; } const x = { - // i am some comment + // i am some comment1 hello () { return _asyncToGenerator(function*() { console.log("Hello"); })(); + }, + // i am some comment2 + "hello" () { + return _asyncToGenerator(function*() { + console.log("Hello"); + })(); + }, + // i am some comment3 + 1 () { + return _asyncToGenerator(function*() { + console.log("Hello"); + })(); + }, + // i am some comment4 + [Date.now()] () { + return _asyncToGenerator(function*() { + console.log("Hello"); + })(); + }, + // i am some comment5 + 1n () { + return _asyncToGenerator(function*() { + console.log("Hello"); + })(); } }; From a09dbb84288916f823e98350bfcba0d80ee606f2 Mon Sep 17 00:00:00 2001 From: UMASHIBA Date: Wed, 17 Nov 2021 00:55:43 +0900 Subject: [PATCH 8/9] chore: fmt --- crates/swc/src/lib.rs | 1 - crates/swc_ecma_codegen/src/lib.rs | 1 + .../swc_ecma_transforms_compat/src/es2017/async_to_generator.rs | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/swc/src/lib.rs b/crates/swc/src/lib.rs index 52d6c797daf3..3f474aab71f4 100644 --- a/crates/swc/src/lib.rs +++ b/crates/swc/src/lib.rs @@ -554,7 +554,6 @@ impl Compiler { // Invalid utf8 is valid in javascript world. String::from_utf8(buf).expect("invalid utf8 character detected") }; - let (code, map) = match source_map { SourceMapsConfig::Bool(v) => { if v { diff --git a/crates/swc_ecma_codegen/src/lib.rs b/crates/swc_ecma_codegen/src/lib.rs index ed820fbe91c8..ca2077f5ac5d 100644 --- a/crates/swc_ecma_codegen/src/lib.rs +++ b/crates/swc_ecma_codegen/src/lib.rs @@ -1613,6 +1613,7 @@ where #[emitter] fn emit_kv_prop(&mut self, node: &KeyValueProp) -> Result { self.emit_leading_comments_of_span(node.span(), false)?; + emit!(node.key); punct!(":"); formatting_space!(); diff --git a/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs b/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs index eae331501104..d91d6ed0d5f0 100644 --- a/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs +++ b/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs @@ -73,6 +73,7 @@ impl AsyncToGenerator { in_prototype_assignment: false, extra_stmts: vec![], }; + stmt.visit_mut_with(&mut actual); stmts_updated.push(stmt); stmts_updated.extend(actual.extra_stmts.into_iter().map(T::from_stmt)); From 948ed5635b2eada2ad1aa257d1aacc02ceb65dd1 Mon Sep 17 00:00:00 2001 From: UMASHIBA Date: Wed, 17 Nov 2021 03:16:05 +0900 Subject: [PATCH 9/9] chore: fix duplicate prop --- .../swc_ecma_transforms_compat/src/es2017/async_to_generator.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs b/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs index bb2192ab5736..0b6b8e28fad5 100644 --- a/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs +++ b/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs @@ -451,7 +451,6 @@ impl VisitMut for Actual { prop.function = Function { params: original_fn_params, span: func_span, - span: prop_method_span, is_async: false, is_generator: false, body: Some(BlockStmt {