Skip to content

Commit 364e5b9

Browse files
committed
internal: remove the separate DotDefine struct
1 parent cbed653 commit 364e5b9

File tree

5 files changed

+123
-97
lines changed

5 files changed

+123
-97
lines changed

internal/bundler_tests/bundler_dce_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,9 +1272,9 @@ func TestTreeShakingReactElements(t *testing.T) {
12721272
}
12731273

12741274
func TestDisableTreeShaking(t *testing.T) {
1275-
defines := config.ProcessDefines(map[string]config.DefineData{
1276-
"pure": {Flags: config.CallCanBeUnwrappedIfUnused},
1277-
"some.fn": {Flags: config.CallCanBeUnwrappedIfUnused},
1275+
defines := config.ProcessDefines([]config.DefineData{
1276+
{KeyParts: []string{"pure"}, Flags: config.CallCanBeUnwrappedIfUnused},
1277+
{KeyParts: []string{"some", "fn"}, Flags: config.CallCanBeUnwrappedIfUnused},
12781278
})
12791279
dce_suite.expectBundled(t, bundled{
12801280
files: map[string]string{

internal/bundler_tests/bundler_default_test.go

Lines changed: 84 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4618,23 +4618,27 @@ func TestInjectDuplicate(t *testing.T) {
46184618
}
46194619

46204620
func TestInject(t *testing.T) {
4621-
defines := config.ProcessDefines(map[string]config.DefineData{
4622-
"chain.prop": {
4621+
defines := config.ProcessDefines([]config.DefineData{
4622+
{
4623+
KeyParts: []string{"chain", "prop"},
46234624
DefineExpr: &config.DefineExpr{
46244625
Parts: []string{"replace"},
46254626
},
46264627
},
4627-
"obj.defined": {
4628+
{
4629+
KeyParts: []string{"obj", "defined"},
46284630
DefineExpr: &config.DefineExpr{
46294631
Constant: &js_ast.EString{Value: helpers.StringToUTF16("defined")},
46304632
},
46314633
},
4632-
"injectedAndDefined": {
4634+
{
4635+
KeyParts: []string{"injectedAndDefined"},
46334636
DefineExpr: &config.DefineExpr{
46344637
Constant: &js_ast.EString{Value: helpers.StringToUTF16("should be used")},
46354638
},
46364639
},
4637-
"injected.and.defined": {
4640+
{
4641+
KeyParts: []string{"injected", "and", "defined"},
46384642
DefineExpr: &config.DefineExpr{
46394643
Constant: &js_ast.EString{Value: helpers.StringToUTF16("should be used")},
46404644
},
@@ -4714,23 +4718,27 @@ func TestInject(t *testing.T) {
47144718
}
47154719

47164720
func TestInjectNoBundle(t *testing.T) {
4717-
defines := config.ProcessDefines(map[string]config.DefineData{
4718-
"chain.prop": {
4721+
defines := config.ProcessDefines([]config.DefineData{
4722+
{
4723+
KeyParts: []string{"chain", "prop"},
47194724
DefineExpr: &config.DefineExpr{
47204725
Parts: []string{"replace"},
47214726
},
47224727
},
4723-
"obj.defined": {
4728+
{
4729+
KeyParts: []string{"obj", "defined"},
47244730
DefineExpr: &config.DefineExpr{
47254731
Constant: &js_ast.EString{Value: helpers.StringToUTF16("defined")},
47264732
},
47274733
},
4728-
"injectedAndDefined": {
4734+
{
4735+
KeyParts: []string{"injectedAndDefined"},
47294736
DefineExpr: &config.DefineExpr{
47304737
Constant: &js_ast.EString{Value: helpers.StringToUTF16("should be used")},
47314738
},
47324739
},
4733-
"injected.and.defined": {
4740+
{
4741+
KeyParts: []string{"injected", "and", "defined"},
47344742
DefineExpr: &config.DefineExpr{
47354743
Constant: &js_ast.EString{Value: helpers.StringToUTF16("should be used")},
47364744
},
@@ -4804,13 +4812,15 @@ func TestInjectNoBundle(t *testing.T) {
48044812
}
48054813

48064814
func TestInjectJSX(t *testing.T) {
4807-
defines := config.ProcessDefines(map[string]config.DefineData{
4808-
"React.createElement": {
4815+
defines := config.ProcessDefines([]config.DefineData{
4816+
{
4817+
KeyParts: []string{"React", "createElement"},
48094818
DefineExpr: &config.DefineExpr{
48104819
Parts: []string{"el"},
48114820
},
48124821
},
4813-
"React.Fragment": {
4822+
{
4823+
KeyParts: []string{"React", "Fragment"},
48144824
DefineExpr: &config.DefineExpr{
48154825
Parts: []string{"frag"},
48164826
},
@@ -4927,9 +4937,10 @@ func TestInjectImportOrder(t *testing.T) {
49274937
}
49284938

49294939
func TestInjectAssign(t *testing.T) {
4930-
defines := config.ProcessDefines(map[string]config.DefineData{
4931-
"defined": {DefineExpr: &config.DefineExpr{Parts: []string{"some", "define"}}},
4932-
})
4940+
defines := config.ProcessDefines([]config.DefineData{{
4941+
KeyParts: []string{"defined"},
4942+
DefineExpr: &config.DefineExpr{Parts: []string{"some", "define"}},
4943+
}})
49334944
default_suite.expectBundled(t, bundled{
49344945
files: map[string]string{
49354946
"/entry.js": `
@@ -5004,9 +5015,9 @@ func TestInjectWithDefine(t *testing.T) {
50045015
"both": {DefineExpr: &config.DefineExpr{Constant: &js_ast.EString{Value: helpers.StringToUTF16("define")}}},
50055016
"first": {DefineExpr: &config.DefineExpr{Parts: []string{"second"}}},
50065017
},
5007-
DotDefines: map[string][]config.DotDefine{
5008-
"th": {{Parts: []string{"bo", "th"}, Data: config.DefineData{DefineExpr: &config.DefineExpr{Constant: &js_ast.EString{Value: helpers.StringToUTF16("defi.ne")}}}}},
5009-
"st": {{Parts: []string{"fir", "st"}, Data: config.DefineData{DefineExpr: &config.DefineExpr{Parts: []string{"seco", "nd"}}}}},
5018+
DotDefines: map[string][]config.DefineData{
5019+
"th": {{KeyParts: []string{"bo", "th"}, DefineExpr: &config.DefineExpr{Constant: &js_ast.EString{Value: helpers.StringToUTF16("defi.ne")}}}},
5020+
"st": {{KeyParts: []string{"fir", "st"}, DefineExpr: &config.DefineExpr{Parts: []string{"seco", "nd"}}}},
50105021
},
50115022
},
50125023
},
@@ -5075,18 +5086,21 @@ func TestAvoidTDZNoBundle(t *testing.T) {
50755086
}
50765087

50775088
func TestDefineImportMeta(t *testing.T) {
5078-
defines := config.ProcessDefines(map[string]config.DefineData{
5079-
"import.meta": {
5089+
defines := config.ProcessDefines([]config.DefineData{
5090+
{
5091+
KeyParts: []string{"import", "meta"},
50805092
DefineExpr: &config.DefineExpr{
50815093
Constant: &js_ast.ENumber{Value: 1},
50825094
},
50835095
},
5084-
"import.meta.foo": {
5096+
{
5097+
KeyParts: []string{"import", "meta", "foo"},
50855098
DefineExpr: &config.DefineExpr{
50865099
Constant: &js_ast.ENumber{Value: 2},
50875100
},
50885101
},
5089-
"import.meta.foo.bar": {
5102+
{
5103+
KeyParts: []string{"import", "meta", "foo", "bar"},
50905104
DefineExpr: &config.DefineExpr{
50915105
Constant: &js_ast.ENumber{Value: 3},
50925106
},
@@ -5119,8 +5133,9 @@ func TestDefineImportMeta(t *testing.T) {
51195133
}
51205134

51215135
func TestDefineImportMetaES5(t *testing.T) {
5122-
defines := config.ProcessDefines(map[string]config.DefineData{
5123-
"import.meta.x": {
5136+
defines := config.ProcessDefines([]config.DefineData{
5137+
{
5138+
KeyParts: []string{"import", "meta", "x"},
51245139
DefineExpr: &config.DefineExpr{
51255140
Constant: &js_ast.ENumber{Value: 1},
51265141
},
@@ -5193,18 +5208,21 @@ func TestInjectImportMeta(t *testing.T) {
51935208
}
51945209

51955210
func TestDefineThis(t *testing.T) {
5196-
defines := config.ProcessDefines(map[string]config.DefineData{
5197-
"this": {
5211+
defines := config.ProcessDefines([]config.DefineData{
5212+
{
5213+
KeyParts: []string{"this"},
51985214
DefineExpr: &config.DefineExpr{
51995215
Constant: &js_ast.ENumber{Value: 1},
52005216
},
52015217
},
5202-
"this.foo": {
5218+
{
5219+
KeyParts: []string{"this", "foo"},
52035220
DefineExpr: &config.DefineExpr{
52045221
Constant: &js_ast.ENumber{Value: 2},
52055222
},
52065223
},
5207-
"this.foo.bar": {
5224+
{
5225+
KeyParts: []string{"this", "foo", "bar"},
52085226
DefineExpr: &config.DefineExpr{
52095227
Constant: &js_ast.ENumber{Value: 3},
52105228
},
@@ -5259,13 +5277,12 @@ func TestDefineThis(t *testing.T) {
52595277
}
52605278

52615279
func TestDefineOptionalChain(t *testing.T) {
5262-
defines := config.ProcessDefines(map[string]config.DefineData{
5263-
"a.b.c": {
5264-
DefineExpr: &config.DefineExpr{
5265-
Constant: &js_ast.ENumber{Value: 1},
5266-
},
5280+
defines := config.ProcessDefines([]config.DefineData{{
5281+
KeyParts: []string{"a", "b", "c"},
5282+
DefineExpr: &config.DefineExpr{
5283+
Constant: &js_ast.ENumber{Value: 1},
52675284
},
5268-
})
5285+
}})
52695286
default_suite.expectBundled(t, bundled{
52705287
files: map[string]string{
52715288
"/entry.js": `
@@ -5294,13 +5311,12 @@ func TestDefineOptionalChain(t *testing.T) {
52945311
}
52955312

52965313
func TestDefineOptionalChainLowered(t *testing.T) {
5297-
defines := config.ProcessDefines(map[string]config.DefineData{
5298-
"a.b.c": {
5299-
DefineExpr: &config.DefineExpr{
5300-
Constant: &js_ast.ENumber{Value: 1},
5301-
},
5314+
defines := config.ProcessDefines([]config.DefineData{{
5315+
KeyParts: []string{"a", "b", "c"},
5316+
DefineExpr: &config.DefineExpr{
5317+
Constant: &js_ast.ENumber{Value: 1},
53025318
},
5303-
})
5319+
}})
53045320
default_suite.expectBundled(t, bundled{
53055321
files: map[string]string{
53065322
"/entry.js": `
@@ -5331,13 +5347,15 @@ func TestDefineOptionalChainLowered(t *testing.T) {
53315347

53325348
// See: https://github.com/evanw/esbuild/issues/3551
53335349
func TestDefineOptionalChainPanicIssue3551(t *testing.T) {
5334-
defines := config.ProcessDefines(map[string]config.DefineData{
5335-
"x": {
5350+
defines := config.ProcessDefines([]config.DefineData{
5351+
{
5352+
KeyParts: []string{"x"},
53365353
DefineExpr: &config.DefineExpr{
53375354
Constant: &js_ast.ENumber{Value: 1},
53385355
},
53395356
},
5340-
"a.b": {
5357+
{
5358+
KeyParts: []string{"a", "b"},
53415359
DefineExpr: &config.DefineExpr{
53425360
Constant: &js_ast.ENumber{Value: 1},
53435361
},
@@ -5389,23 +5407,27 @@ func TestDefineOptionalChainPanicIssue3551(t *testing.T) {
53895407

53905408
// See: https://github.com/evanw/esbuild/issues/2407
53915409
func TestDefineInfiniteLoopIssue2407(t *testing.T) {
5392-
defines := config.ProcessDefines(map[string]config.DefineData{
5393-
"a.b": {
5410+
defines := config.ProcessDefines([]config.DefineData{
5411+
{
5412+
KeyParts: []string{"a", "b"},
53945413
DefineExpr: &config.DefineExpr{
53955414
Parts: []string{"b", "c"},
53965415
},
53975416
},
5398-
"b.c": {
5417+
{
5418+
KeyParts: []string{"b", "c"},
53995419
DefineExpr: &config.DefineExpr{
54005420
Parts: []string{"c", "a"},
54015421
},
54025422
},
5403-
"c.a": {
5423+
{
5424+
KeyParts: []string{"c", "a"},
54045425
DefineExpr: &config.DefineExpr{
54055426
Parts: []string{"a", "b"},
54065427
},
54075428
},
5408-
"x.y": {
5429+
{
5430+
KeyParts: []string{"x", "y"},
54095431
DefineExpr: &config.DefineExpr{
54105432
Parts: []string{"y"},
54115433
},
@@ -5428,33 +5450,39 @@ func TestDefineInfiniteLoopIssue2407(t *testing.T) {
54285450
}
54295451

54305452
func TestDefineAssignWarning(t *testing.T) {
5431-
defines := config.ProcessDefines(map[string]config.DefineData{
5432-
"a": {
5453+
defines := config.ProcessDefines([]config.DefineData{
5454+
{
5455+
KeyParts: []string{"a"},
54335456
DefineExpr: &config.DefineExpr{
54345457
Constant: js_ast.ENullShared,
54355458
},
54365459
},
5437-
"b.c": {
5460+
{
5461+
KeyParts: []string{"b", "c"},
54385462
DefineExpr: &config.DefineExpr{
54395463
Constant: js_ast.ENullShared,
54405464
},
54415465
},
5442-
"d": {
5466+
{
5467+
KeyParts: []string{"d"},
54435468
DefineExpr: &config.DefineExpr{
54445469
Parts: []string{"ident"},
54455470
},
54465471
},
5447-
"e.f": {
5472+
{
5473+
KeyParts: []string{"e", "f"},
54485474
DefineExpr: &config.DefineExpr{
54495475
Parts: []string{"ident"},
54505476
},
54515477
},
5452-
"g": {
5478+
{
5479+
KeyParts: []string{"g"},
54535480
DefineExpr: &config.DefineExpr{
54545481
Parts: []string{"dot", "chain"},
54555482
},
54565483
},
5457-
"h.i": {
5484+
{
5485+
KeyParts: []string{"h", "i"},
54585486
DefineExpr: &config.DefineExpr{
54595487
Parts: []string{"dot", "chain"},
54605488
},

0 commit comments

Comments
 (0)