diff --git a/internal/bundler_tests/bundler_default_test.go b/internal/bundler_tests/bundler_default_test.go index d272cf5eb38..2eb614a7a19 100644 --- a/internal/bundler_tests/bundler_default_test.go +++ b/internal/bundler_tests/bundler_default_test.go @@ -7493,8 +7493,8 @@ func TestManglePropsKeyCommentMinify(t *testing.T) { x[/* @__KEY__ */ '_mangleThisToo'] = 2 x['_doNotMangleThis'] = 3 x([ - ` + "`" + `foo.${/* @__KEY__ */ '_mangleThis'} = bar.${/* @__KEY__ */ '_mangleThisToo'}` + "`" + `, - ` + "`" + `foo.${/* @__KEY__ */ 'notMangled'} = bar.${/* @__KEY__ */ 'notMangledEither'}` + "`" + `, + ` + "`" + `${foo}.${/* @__KEY__ */ '_mangleThis'} = bar.${/* @__KEY__ */ '_mangleThisToo'}` + "`" + `, + ` + "`" + `${foo}.${/* @__KEY__ */ 'notMangled'} = bar.${/* @__KEY__ */ 'notMangledEither'}` + "`" + `, ]) `, }, diff --git a/internal/bundler_tests/snapshots/snapshots_default.txt b/internal/bundler_tests/snapshots/snapshots_default.txt index 265928bf67d..be5ce957ea6 100644 --- a/internal/bundler_tests/snapshots/snapshots_default.txt +++ b/internal/bundler_tests/snapshots/snapshots_default.txt @@ -3253,8 +3253,8 @@ x = class { b: 2, _doNotMangleThis: 3 }, x.a = 1, x.b = 2, x._doNotMangleThis = 3, x([ - "foo.a = bar.b", - "foo.notMangled = bar.notMangledEither" + `${foo}.a = bar.b`, + `${foo}.notMangled = bar.notMangledEither` ]); ================================================================================ diff --git a/internal/js_printer/js_printer.go b/internal/js_printer/js_printer.go index e069ffc7eb1..470f9993dd1 100644 --- a/internal/js_printer/js_printer.go +++ b/internal/js_printer/js_printer.go @@ -2868,12 +2868,13 @@ func (p *printer) printExpr(expr js_ast.Expr, level js_ast.L, flags printExprFla for i, part := range e.Parts { if mangled, ok := part.Value.Data.(*js_ast.ENameOfSymbol); ok { if replaced == nil { - replaced = make([]js_ast.TemplatePart, len(e.Parts)) + replaced = make([]js_ast.TemplatePart, 0, len(e.Parts)) + replaced = append(replaced, e.Parts[:i]...) } part.Value.Data = &js_ast.EString{Value: helpers.StringToUTF16(p.mangledPropName(mangled.Ref))} - replaced[i] = part + replaced = append(replaced, part) } else if replaced != nil { - replaced[i] = part + replaced = append(replaced, part) } } if replaced != nil {