diff --git a/unsupported/juno/src/gen_js.rs b/unsupported/juno/src/gen_js.rs index 4afac2a97f3..373e624817b 100644 --- a/unsupported/juno/src/gen_js.rs +++ b/unsupported/juno/src/gen_js.rs @@ -881,23 +881,33 @@ impl GenJS { } TemplateLiteral { - quasis: _, - expressions: _, + quasis, + expressions, } => { - unimplemented!("TemplateLiteral"); - // out!(self, "`"); - // let mut it_expr = expressions.iter(); - // for quasi in quasis { - // if let TemplateElement { raw, .. } = &quasi.kind { - // out!(self, "{}", raw.str); - // if let Some(expr) = it_expr.next() { - // out!(self, "${{"); - // expr.visit(self, Some(node)); - // out!(self, "}}"); - // } - // } - // } - // out!(self, "`"); + out!(self, "`"); + let mut it_expr = expressions.iter(); + for quasi in quasis { + if let TemplateElement { + raw, + tail: _, + cooked: _, + } = &quasi.kind + { + out!( + self, + "{}", + char::decode_utf16(raw.str.iter().cloned()) + .map(|r| r.expect("Template element raw must be valid UTF-16")) + .collect::() + ); + if let Some(expr) = it_expr.next() { + out!(self, "${{"); + expr.visit(self, Some(node)); + out!(self, "}}"); + } + } + } + out!(self, "`"); } TaggedTemplateExpression { tag, quasi } => { self.print_child(Some(tag), node, ChildPos::Left); diff --git a/unsupported/juno/tests/gen_js.rs b/unsupported/juno/tests/gen_js.rs index 10e18daf0d2..888938239aa 100644 --- a/unsupported/juno/tests/gen_js.rs +++ b/unsupported/juno/tests/gen_js.rs @@ -87,6 +87,18 @@ fn test_literals() { test_roundtrip("/abc/"); test_roundtrip("/abc/gi"); test_roundtrip("/abc/gi"); + + test_roundtrip(r#" `abc` "#); + test_roundtrip(r#" `abc\ndef` "#); + test_roundtrip( + r#" `abc + def` "#, + ); + test_roundtrip(r#" `abc \ud800 def` "#); + test_roundtrip(r#" `abc \ud800 def` "#); + test_roundtrip(r#" `\ud83d\udcd5` "#); + test_roundtrip(r#" `escape backtick: \` should work` "#); + test_roundtrip(r#" `😹` "#); } #[test]