File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -881,23 +881,33 @@ impl<W: Write> GenJS<W> {
881881 }
882882
883883 TemplateLiteral {
884- quasis : _ ,
885- expressions : _ ,
884+ quasis,
885+ expressions,
886886 } => {
887- unimplemented ! ( "TemplateLiteral" ) ;
888- // out!(self, "`");
889- // let mut it_expr = expressions.iter();
890- // for quasi in quasis {
891- // if let TemplateElement { raw, .. } = &quasi.kind {
892- // out!(self, "{}", raw.str);
893- // if let Some(expr) = it_expr.next() {
894- // out!(self, "${{");
895- // expr.visit(self, Some(node));
896- // out!(self, "}}");
897- // }
898- // }
899- // }
900- // out!(self, "`");
887+ out ! ( self , "`" ) ;
888+ let mut it_expr = expressions. iter ( ) ;
889+ for quasi in quasis {
890+ if let TemplateElement {
891+ raw,
892+ tail : _,
893+ cooked : _,
894+ } = & quasi. kind
895+ {
896+ out ! (
897+ self ,
898+ "{}" ,
899+ char :: decode_utf16( raw. str . iter( ) . cloned( ) )
900+ . map( |r| r. expect( "Template element raw must be valid UTF-16" ) )
901+ . collect:: <String >( )
902+ ) ;
903+ if let Some ( expr) = it_expr. next ( ) {
904+ out ! ( self , "${{" ) ;
905+ expr. visit ( self , Some ( node) ) ;
906+ out ! ( self , "}}" ) ;
907+ }
908+ }
909+ }
910+ out ! ( self , "`" ) ;
901911 }
902912 TaggedTemplateExpression { tag, quasi } => {
903913 self . print_child ( Some ( tag) , node, ChildPos :: Left ) ;
Original file line number Diff line number Diff line change @@ -87,6 +87,18 @@ fn test_literals() {
8787 test_roundtrip ( "/abc/" ) ;
8888 test_roundtrip ( "/abc/gi" ) ;
8989 test_roundtrip ( "/abc/gi" ) ;
90+
91+ test_roundtrip ( r#" `abc` "# ) ;
92+ test_roundtrip ( r#" `abc\ndef` "# ) ;
93+ test_roundtrip (
94+ r#" `abc
95+ def` "# ,
96+ ) ;
97+ test_roundtrip ( r#" `abc \ud800 def` "# ) ;
98+ test_roundtrip ( r#" `abc \ud800 def` "# ) ;
99+ test_roundtrip ( r#" `\ud83d\udcd5` "# ) ;
100+ test_roundtrip ( r#" `escape backtick: \` should work` "# ) ;
101+ test_roundtrip ( r#" `😹` "# ) ;
90102}
91103
92104#[ test]
You can’t perform that action at this time.
0 commit comments