diff --git a/internal/bundler_tests/bundler_default_test.go b/internal/bundler_tests/bundler_default_test.go index fb691400141..5baeb8b631f 100644 --- a/internal/bundler_tests/bundler_default_test.go +++ b/internal/bundler_tests/bundler_default_test.go @@ -4841,6 +4841,40 @@ inject.js: NOTE: The symbol "test" was exported from "inject.js" here: }) } +func TestInjectWithDefine(t *testing.T) { + default_suite.expectBundled(t, bundled{ + files: map[string]string{ + "/entry.js": ` + console.log( + // define wins over inject + both === 'define', + // define forwards to inject + first === 'second', + ) + `, + "/inject.js": ` + export let both = 'inject' + export let first = 'TEST FAILED!' + export let second = 'second' + `, + }, + entryPaths: []string{"/entry.js"}, + options: config.Options{ + Mode: config.ModeBundle, + AbsOutputFile: "/out.js", + InjectPaths: []string{ + "/inject.js", + }, + Defines: &config.ProcessedDefines{ + IdentifierDefines: map[string]config.DefineData{ + "both": {DefineExpr: &config.DefineExpr{Constant: &js_ast.EString{Value: helpers.StringToUTF16("define")}}}, + "first": {DefineExpr: &config.DefineExpr{Parts: []string{"second"}}}, + }, + }, + }, + }) +} + func TestOutbase(t *testing.T) { default_suite.expectBundled(t, bundled{ files: map[string]string{ diff --git a/internal/bundler_tests/snapshots/snapshots_default.txt b/internal/bundler_tests/snapshots/snapshots_default.txt index 8412070cfa9..8d6f5536874 100644 --- a/internal/bundler_tests/snapshots/snapshots_default.txt +++ b/internal/bundler_tests/snapshots/snapshots_default.txt @@ -1995,6 +1995,20 @@ console.log(replace.test); console.log(collide); console.log(re_export); +================================================================================ +TestInjectWithDefine +---------- /out.js ---------- +// inject.js +var second = "second"; + +// entry.js +console.log( + // define wins over inject + true, + // define forwards to inject + second === "second" +); + ================================================================================ TestJSXAutomaticImportsCommonJS ---------- /out.js ----------