From aa67d7ddcf9a0a3c8f9885d00368b58d274cda0f Mon Sep 17 00:00:00 2001 From: PJ Date: Mon, 13 Jul 2026 07:02:56 +0530 Subject: [PATCH] feat(bundler): map generator export to globalThis.generator --- internal/bundler/bundler.go | 1 + internal/bundler/bundler_test.go | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/bundler/bundler.go b/internal/bundler/bundler.go index 043c125..6b05a03 100644 --- a/internal/bundler/bundler.go +++ b/internal/bundler/bundler.go @@ -110,6 +110,7 @@ func Bundle(options Options) (Result, error) { func registrationEntry(specAbs string) string { return fmt.Sprintf(`import * as __spec from %q; if (__spec.actionsRoot !== undefined) globalThis.actions = __spec.actionsRoot; +if (__spec.generator !== undefined) globalThis.generator = __spec.generator; if (__spec.properties !== undefined) globalThis.properties = __spec.properties; if (__spec.setup !== undefined) globalThis.setup = __spec.setup; `, specAbs) diff --git a/internal/bundler/bundler_test.go b/internal/bundler/bundler_test.go index 56221f9..07b69e4 100644 --- a/internal/bundler/bundler_test.go +++ b/internal/bundler/bundler_test.go @@ -156,6 +156,7 @@ func TestBundle_RegistersNamedExportsOnGlobalThis(t *testing.T) { spec := ` export const properties = "PROPS_MARKER"; export const actionsRoot = "ACTIONS_MARKER"; + export const generator = "GENERATOR_MARKER"; export const setup = "SETUP_MARKER"; ` if err := os.WriteFile(specPath, []byte(spec), 0o600); err != nil { @@ -166,7 +167,7 @@ func TestBundle_RegistersNamedExportsOnGlobalThis(t *testing.T) { t.Fatal(err) } body := string(result.JavaScript) - for _, marker := range []string{"PROPS_MARKER", "ACTIONS_MARKER", "SETUP_MARKER"} { + for _, marker := range []string{"PROPS_MARKER", "ACTIONS_MARKER", "GENERATOR_MARKER", "SETUP_MARKER"} { if !strings.Contains(body, marker) { t.Errorf("named export %q not registered in bundle:\n%s", marker, body) } @@ -174,6 +175,9 @@ func TestBundle_RegistersNamedExportsOnGlobalThis(t *testing.T) { if !strings.Contains(body, "globalThis.actions") { t.Errorf("trailer should assign globalThis.actions:\n%s", body) } + if !strings.Contains(body, "globalThis.generator") { + t.Errorf("trailer should assign globalThis.generator:\n%s", body) + } } func TestBundle_RegistersWithoutSetupExport(t *testing.T) {