mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-04 12:07:09 +00:00
feat(bundler): map generator export to globalThis.generator
This commit is contained in:
1 parent
c38c21dea1
commit
aa67d7ddcf
2 files changed
+6
-1
No files matched your search
@@ -110,6 +110,7 @@ func Bundle(options Options) (Result, error) {
|
|||||||
func registrationEntry(specAbs string) string {
|
func registrationEntry(specAbs string) string {
|
||||||
return fmt.Sprintf(`import * as __spec from %q;
|
return fmt.Sprintf(`import * as __spec from %q;
|
||||||
if (__spec.actionsRoot !== undefined) globalThis.actions = __spec.actionsRoot;
|
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.properties !== undefined) globalThis.properties = __spec.properties;
|
||||||
if (__spec.setup !== undefined) globalThis.setup = __spec.setup;
|
if (__spec.setup !== undefined) globalThis.setup = __spec.setup;
|
||||||
`, specAbs)
|
`, specAbs)
|
||||||
|
|||||||
@@ -156,6 +156,7 @@ func TestBundle_RegistersNamedExportsOnGlobalThis(t *testing.T) {
|
|||||||
spec := `
|
spec := `
|
||||||
export const properties = "PROPS_MARKER";
|
export const properties = "PROPS_MARKER";
|
||||||
export const actionsRoot = "ACTIONS_MARKER";
|
export const actionsRoot = "ACTIONS_MARKER";
|
||||||
|
export const generator = "GENERATOR_MARKER";
|
||||||
export const setup = "SETUP_MARKER";
|
export const setup = "SETUP_MARKER";
|
||||||
`
|
`
|
||||||
if err := os.WriteFile(specPath, []byte(spec), 0o600); err != nil {
|
if err := os.WriteFile(specPath, []byte(spec), 0o600); err != nil {
|
||||||
@@ -166,7 +167,7 @@ func TestBundle_RegistersNamedExportsOnGlobalThis(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
body := string(result.JavaScript)
|
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) {
|
if !strings.Contains(body, marker) {
|
||||||
t.Errorf("named export %q not registered in bundle:\n%s", marker, body)
|
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") {
|
if !strings.Contains(body, "globalThis.actions") {
|
||||||
t.Errorf("trailer should assign globalThis.actions:\n%s", body)
|
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) {
|
func TestBundle_RegistersWithoutSetupExport(t *testing.T) {
|
||||||
|
|||||||
Reference in new issue
Block a user