Skip to content

Commit

Permalink
fix a crash with --mangle-props= + --minify
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Jul 27, 2023
1 parent be33c09 commit d7838ab
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions internal/bundler_tests/bundler_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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'}` + "`" + `,
])
`,
},
Expand Down
4 changes: 2 additions & 2 deletions internal/bundler_tests/snapshots/snapshots_default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`
]);

================================================================================
Expand Down
7 changes: 4 additions & 3 deletions internal/js_printer/js_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d7838ab

Please sign in to comment.