@@ -11870,6 +11870,49 @@ func (p *parser) mangleTemplate(loc logger.Loc, e *js_ast.ETemplate) js_ast.Expr
11870
11870
return js_ast.Expr{Loc: loc, Data: e}
11871
11871
}
11872
11872
11873
+ func (p *parser) mangleObjectSpread(properties []js_ast.Property) []js_ast.Property {
11874
+ var result []js_ast.Property
11875
+ for _, property := range properties {
11876
+ if property.Kind == js_ast.PropertySpread {
11877
+ switch v := property.ValueOrNil.Data.(type) {
11878
+ case *js_ast.EBoolean, *js_ast.ENull, *js_ast.EUndefined, *js_ast.ENumber,
11879
+ *js_ast.EBigInt, *js_ast.ERegExp, *js_ast.EFunction, *js_ast.EArrow:
11880
+ // This value is ignored because it doesn't have any of its own properties
11881
+ continue
11882
+
11883
+ case *js_ast.EObject:
11884
+ for i, p := range v.Properties {
11885
+ // Getters are evaluated at iteration time. The property
11886
+ // descriptor is not inlined into the caller. Since we are not
11887
+ // evaluating code at compile time, just bail if we hit one
11888
+ // and preserve the spread with the remaining properties.
11889
+ if p.Kind == js_ast.PropertyGet || p.Kind == js_ast.PropertySet {
11890
+ v.Properties = v.Properties[i:]
11891
+ result = append(result, property)
11892
+ break
11893
+ }
11894
+
11895
+ // Also bail if we hit a verbatim "__proto__" key. This will
11896
+ // actually set the prototype of the object being spread so
11897
+ // inlining it is not correct.
11898
+ if p.Kind == js_ast.PropertyNormal && !p.Flags.Has(js_ast.PropertyIsComputed) && !p.Flags.Has(js_ast.PropertyIsMethod) {
11899
+ if str, ok := p.Key.Data.(*js_ast.EString); ok && helpers.UTF16EqualsString(str.Value, "__proto__") {
11900
+ v.Properties = v.Properties[i:]
11901
+ result = append(result, property)
11902
+ break
11903
+ }
11904
+ }
11905
+
11906
+ result = append(result, p)
11907
+ }
11908
+ continue
11909
+ }
11910
+ }
11911
+ result = append(result, property)
11912
+ }
11913
+ return result
11914
+ }
11915
+
11873
11916
func containsClosingScriptTag(text string) bool {
11874
11917
for {
11875
11918
i := strings.Index(text, "</")
@@ -12256,8 +12299,11 @@ func (p *parser) visitExprInOut(expr js_ast.Expr, in exprIn) (js_ast.Expr, exprO
12256
12299
}
12257
12300
12258
12301
// Visit properties
12302
+ hasSpread := false
12259
12303
for i, property := range e.Properties {
12260
- if property.Kind != js_ast.PropertySpread {
12304
+ if property.Kind == js_ast.PropertySpread {
12305
+ hasSpread = true
12306
+ } else {
12261
12307
if mangled, ok := property.Key.Data.(*js_ast.EMangledProp); ok {
12262
12308
mangled.Ref = p.symbolForMangledProp(p.loadNameFromRef(mangled.Ref))
12263
12309
} else {
@@ -12273,6 +12319,11 @@ func (p *parser) visitExprInOut(expr js_ast.Expr, in exprIn) (js_ast.Expr, exprO
12273
12319
e.Properties[i] = property
12274
12320
}
12275
12321
12322
+ // "{a, ...{b, c}, d}" => "{a, b, c, d}"
12323
+ if p.options.minifySyntax && hasSpread {
12324
+ e.Properties = p.mangleObjectSpread(e.Properties)
12325
+ }
12326
+
12276
12327
// Visit children
12277
12328
if len(e.Children) > 0 {
12278
12329
for i, child := range e.Children {
@@ -13802,46 +13853,7 @@ func (p *parser) visitExprInOut(expr js_ast.Expr, in exprIn) (js_ast.Expr, exprO
13802
13853
if in.assignTarget == js_ast.AssignTargetNone {
13803
13854
// "{a, ...{b, c}, d}" => "{a, b, c, d}"
13804
13855
if p.options.minifySyntax && hasSpread {
13805
- var properties []js_ast.Property
13806
- for _, property := range e.Properties {
13807
- if property.Kind == js_ast.PropertySpread {
13808
- switch v := property.ValueOrNil.Data.(type) {
13809
- case *js_ast.EBoolean, *js_ast.ENull, *js_ast.EUndefined, *js_ast.ENumber,
13810
- *js_ast.EBigInt, *js_ast.ERegExp, *js_ast.EFunction, *js_ast.EArrow:
13811
- // This value is ignored because it doesn't have any of its own properties
13812
- continue
13813
-
13814
- case *js_ast.EObject:
13815
- for i, p := range v.Properties {
13816
- // Getters are evaluated at iteration time. The property
13817
- // descriptor is not inlined into the caller. Since we are not
13818
- // evaluating code at compile time, just bail if we hit one
13819
- // and preserve the spread with the remaining properties.
13820
- if p.Kind == js_ast.PropertyGet || p.Kind == js_ast.PropertySet {
13821
- v.Properties = v.Properties[i:]
13822
- properties = append(properties, property)
13823
- break
13824
- }
13825
-
13826
- // Also bail if we hit a verbatim "__proto__" key. This will
13827
- // actually set the prototype of the object being spread so
13828
- // inlining it is not correct.
13829
- if p.Kind == js_ast.PropertyNormal && !p.Flags.Has(js_ast.PropertyIsComputed) && !p.Flags.Has(js_ast.PropertyIsMethod) {
13830
- if str, ok := p.Key.Data.(*js_ast.EString); ok && helpers.UTF16EqualsString(str.Value, "__proto__") {
13831
- v.Properties = v.Properties[i:]
13832
- properties = append(properties, property)
13833
- break
13834
- }
13835
- }
13836
-
13837
- properties = append(properties, p)
13838
- }
13839
- continue
13840
- }
13841
- }
13842
- properties = append(properties, property)
13843
- }
13844
- e.Properties = properties
13856
+ e.Properties = p.mangleObjectSpread(e.Properties)
13845
13857
}
13846
13858
13847
13859
// Object expressions represent both object literals and binding patterns.
0 commit comments