@@ -4618,23 +4618,27 @@ func TestInjectDuplicate(t *testing.T) {
4618
4618
}
4619
4619
4620
4620
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" },
4623
4624
DefineExpr : & config.DefineExpr {
4624
4625
Parts : []string {"replace" },
4625
4626
},
4626
4627
},
4627
- "obj.defined" : {
4628
+ {
4629
+ KeyParts : []string {"obj" , "defined" },
4628
4630
DefineExpr : & config.DefineExpr {
4629
4631
Constant : & js_ast.EString {Value : helpers .StringToUTF16 ("defined" )},
4630
4632
},
4631
4633
},
4632
- "injectedAndDefined" : {
4634
+ {
4635
+ KeyParts : []string {"injectedAndDefined" },
4633
4636
DefineExpr : & config.DefineExpr {
4634
4637
Constant : & js_ast.EString {Value : helpers .StringToUTF16 ("should be used" )},
4635
4638
},
4636
4639
},
4637
- "injected.and.defined" : {
4640
+ {
4641
+ KeyParts : []string {"injected" , "and" , "defined" },
4638
4642
DefineExpr : & config.DefineExpr {
4639
4643
Constant : & js_ast.EString {Value : helpers .StringToUTF16 ("should be used" )},
4640
4644
},
@@ -4714,23 +4718,27 @@ func TestInject(t *testing.T) {
4714
4718
}
4715
4719
4716
4720
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" },
4719
4724
DefineExpr : & config.DefineExpr {
4720
4725
Parts : []string {"replace" },
4721
4726
},
4722
4727
},
4723
- "obj.defined" : {
4728
+ {
4729
+ KeyParts : []string {"obj" , "defined" },
4724
4730
DefineExpr : & config.DefineExpr {
4725
4731
Constant : & js_ast.EString {Value : helpers .StringToUTF16 ("defined" )},
4726
4732
},
4727
4733
},
4728
- "injectedAndDefined" : {
4734
+ {
4735
+ KeyParts : []string {"injectedAndDefined" },
4729
4736
DefineExpr : & config.DefineExpr {
4730
4737
Constant : & js_ast.EString {Value : helpers .StringToUTF16 ("should be used" )},
4731
4738
},
4732
4739
},
4733
- "injected.and.defined" : {
4740
+ {
4741
+ KeyParts : []string {"injected" , "and" , "defined" },
4734
4742
DefineExpr : & config.DefineExpr {
4735
4743
Constant : & js_ast.EString {Value : helpers .StringToUTF16 ("should be used" )},
4736
4744
},
@@ -4804,13 +4812,15 @@ func TestInjectNoBundle(t *testing.T) {
4804
4812
}
4805
4813
4806
4814
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" },
4809
4818
DefineExpr : & config.DefineExpr {
4810
4819
Parts : []string {"el" },
4811
4820
},
4812
4821
},
4813
- "React.Fragment" : {
4822
+ {
4823
+ KeyParts : []string {"React" , "Fragment" },
4814
4824
DefineExpr : & config.DefineExpr {
4815
4825
Parts : []string {"frag" },
4816
4826
},
@@ -4927,9 +4937,10 @@ func TestInjectImportOrder(t *testing.T) {
4927
4937
}
4928
4938
4929
4939
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
+ }})
4933
4944
default_suite .expectBundled (t , bundled {
4934
4945
files : map [string ]string {
4935
4946
"/entry.js" : `
@@ -5004,9 +5015,9 @@ func TestInjectWithDefine(t *testing.T) {
5004
5015
"both" : {DefineExpr : & config.DefineExpr {Constant : & js_ast.EString {Value : helpers .StringToUTF16 ("define" )}}},
5005
5016
"first" : {DefineExpr : & config.DefineExpr {Parts : []string {"second" }}},
5006
5017
},
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" }}}},
5010
5021
},
5011
5022
},
5012
5023
},
@@ -5075,18 +5086,21 @@ func TestAvoidTDZNoBundle(t *testing.T) {
5075
5086
}
5076
5087
5077
5088
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" },
5080
5092
DefineExpr : & config.DefineExpr {
5081
5093
Constant : & js_ast.ENumber {Value : 1 },
5082
5094
},
5083
5095
},
5084
- "import.meta.foo" : {
5096
+ {
5097
+ KeyParts : []string {"import" , "meta" , "foo" },
5085
5098
DefineExpr : & config.DefineExpr {
5086
5099
Constant : & js_ast.ENumber {Value : 2 },
5087
5100
},
5088
5101
},
5089
- "import.meta.foo.bar" : {
5102
+ {
5103
+ KeyParts : []string {"import" , "meta" , "foo" , "bar" },
5090
5104
DefineExpr : & config.DefineExpr {
5091
5105
Constant : & js_ast.ENumber {Value : 3 },
5092
5106
},
@@ -5119,8 +5133,9 @@ func TestDefineImportMeta(t *testing.T) {
5119
5133
}
5120
5134
5121
5135
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" },
5124
5139
DefineExpr : & config.DefineExpr {
5125
5140
Constant : & js_ast.ENumber {Value : 1 },
5126
5141
},
@@ -5193,18 +5208,21 @@ func TestInjectImportMeta(t *testing.T) {
5193
5208
}
5194
5209
5195
5210
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" },
5198
5214
DefineExpr : & config.DefineExpr {
5199
5215
Constant : & js_ast.ENumber {Value : 1 },
5200
5216
},
5201
5217
},
5202
- "this.foo" : {
5218
+ {
5219
+ KeyParts : []string {"this" , "foo" },
5203
5220
DefineExpr : & config.DefineExpr {
5204
5221
Constant : & js_ast.ENumber {Value : 2 },
5205
5222
},
5206
5223
},
5207
- "this.foo.bar" : {
5224
+ {
5225
+ KeyParts : []string {"this" , "foo" , "bar" },
5208
5226
DefineExpr : & config.DefineExpr {
5209
5227
Constant : & js_ast.ENumber {Value : 3 },
5210
5228
},
@@ -5259,13 +5277,12 @@ func TestDefineThis(t *testing.T) {
5259
5277
}
5260
5278
5261
5279
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 },
5267
5284
},
5268
- })
5285
+ }} )
5269
5286
default_suite .expectBundled (t , bundled {
5270
5287
files : map [string ]string {
5271
5288
"/entry.js" : `
@@ -5294,13 +5311,12 @@ func TestDefineOptionalChain(t *testing.T) {
5294
5311
}
5295
5312
5296
5313
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 },
5302
5318
},
5303
- })
5319
+ }} )
5304
5320
default_suite .expectBundled (t , bundled {
5305
5321
files : map [string ]string {
5306
5322
"/entry.js" : `
@@ -5331,13 +5347,15 @@ func TestDefineOptionalChainLowered(t *testing.T) {
5331
5347
5332
5348
// See: https://github.com/evanw/esbuild/issues/3551
5333
5349
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" },
5336
5353
DefineExpr : & config.DefineExpr {
5337
5354
Constant : & js_ast.ENumber {Value : 1 },
5338
5355
},
5339
5356
},
5340
- "a.b" : {
5357
+ {
5358
+ KeyParts : []string {"a" , "b" },
5341
5359
DefineExpr : & config.DefineExpr {
5342
5360
Constant : & js_ast.ENumber {Value : 1 },
5343
5361
},
@@ -5389,23 +5407,27 @@ func TestDefineOptionalChainPanicIssue3551(t *testing.T) {
5389
5407
5390
5408
// See: https://github.com/evanw/esbuild/issues/2407
5391
5409
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" },
5394
5413
DefineExpr : & config.DefineExpr {
5395
5414
Parts : []string {"b" , "c" },
5396
5415
},
5397
5416
},
5398
- "b.c" : {
5417
+ {
5418
+ KeyParts : []string {"b" , "c" },
5399
5419
DefineExpr : & config.DefineExpr {
5400
5420
Parts : []string {"c" , "a" },
5401
5421
},
5402
5422
},
5403
- "c.a" : {
5423
+ {
5424
+ KeyParts : []string {"c" , "a" },
5404
5425
DefineExpr : & config.DefineExpr {
5405
5426
Parts : []string {"a" , "b" },
5406
5427
},
5407
5428
},
5408
- "x.y" : {
5429
+ {
5430
+ KeyParts : []string {"x" , "y" },
5409
5431
DefineExpr : & config.DefineExpr {
5410
5432
Parts : []string {"y" },
5411
5433
},
@@ -5428,33 +5450,39 @@ func TestDefineInfiniteLoopIssue2407(t *testing.T) {
5428
5450
}
5429
5451
5430
5452
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" },
5433
5456
DefineExpr : & config.DefineExpr {
5434
5457
Constant : js_ast .ENullShared ,
5435
5458
},
5436
5459
},
5437
- "b.c" : {
5460
+ {
5461
+ KeyParts : []string {"b" , "c" },
5438
5462
DefineExpr : & config.DefineExpr {
5439
5463
Constant : js_ast .ENullShared ,
5440
5464
},
5441
5465
},
5442
- "d" : {
5466
+ {
5467
+ KeyParts : []string {"d" },
5443
5468
DefineExpr : & config.DefineExpr {
5444
5469
Parts : []string {"ident" },
5445
5470
},
5446
5471
},
5447
- "e.f" : {
5472
+ {
5473
+ KeyParts : []string {"e" , "f" },
5448
5474
DefineExpr : & config.DefineExpr {
5449
5475
Parts : []string {"ident" },
5450
5476
},
5451
5477
},
5452
- "g" : {
5478
+ {
5479
+ KeyParts : []string {"g" },
5453
5480
DefineExpr : & config.DefineExpr {
5454
5481
Parts : []string {"dot" , "chain" },
5455
5482
},
5456
5483
},
5457
- "h.i" : {
5484
+ {
5485
+ KeyParts : []string {"h" , "i" },
5458
5486
DefineExpr : & config.DefineExpr {
5459
5487
Parts : []string {"dot" , "chain" },
5460
5488
},
0 commit comments