Skip to content

Commit

Permalink
Merge pull request #239 from nksaraf/fix-nest-fn
Browse files Browse the repository at this point in the history
fix: nested fns in plugin directives, fix solidjs/solid-start#1360 #238,
  • Loading branch information
nksaraf committed Mar 5, 2024
2 parents 102c7ba + e78cdce commit 0e39b30
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/three-tables-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vinxi/plugin-directives": patch
---

fix: nested fns in plugin directives, fix solidjs/solid-start#1360 #238,
4 changes: 4 additions & 0 deletions packages/vinxi-directives/fixtures/example-5.shim.snapshot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createReference } from "~/runtime";

export const x = () => y(createReference($$function0, "test", "$$function0"));
export function $$function0() {}
5 changes: 5 additions & 0 deletions packages/vinxi-directives/fixtures/example-5.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const x = () =>
y(() => {
"use runtime";
console.log("hello");
});
7 changes: 7 additions & 0 deletions packages/vinxi-directives/fixtures/example-5.wrap.snapshot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createReference } from "~/runtime";

export const x = () => y(createReference($$function0, "test", "$$function0"));

export function $$function0() {
console.log("hello");
}
4 changes: 2 additions & 2 deletions packages/vinxi-directives/plugins/shim-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export function shimExportsPlugin({
onModuleFound?.(id);
this.traverse(path);
}
return false;
return this.traverse(path);
},
visitFunctionExpression(path) {
const name = path.node.id?.name.toString();
Expand Down Expand Up @@ -300,7 +300,7 @@ export function shimExportsPlugin({
onModuleFound?.(id);
this.traverse(path);
}
return false;
return this.traverse(path);
},
});

Expand Down
4 changes: 2 additions & 2 deletions packages/vinxi-directives/plugins/wrap-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export function wrapExportsPlugin({
onModuleFound?.(id);
this.traverse(path);
}
return false;
return this.traverse(path);
},
visitFunctionExpression(path) {
const name = path.node.id?.name.toString();
Expand All @@ -255,7 +255,7 @@ export function wrapExportsPlugin({
);
this.traverse(path);
}
return false;
return this.traverse(path);
},
});

Expand Down
4 changes: 3 additions & 1 deletion packages/vinxi-directives/transform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async function transformSSR(

let result = await instance.transform(code, args.id, args.options);
const data = js(result);
expect(onModuleFound.mock.calls.length).toBeGreaterThan(0);
// expect(onModuleFound.mock.calls.length).toBeGreaterThan(0);
return data;
}
async function transformClient(
Expand Down Expand Up @@ -112,3 +112,5 @@ runTest(
(code) => transformSSR(code, shimExportsPlugin),
"shim",
);
runTest("example-5", (code) => transformSSR(code, shimExportsPlugin), "shim");
runTest("example-5", (code) => transformSSR(code, wrapExportsPlugin), "wrap");

0 comments on commit 0e39b30

Please sign in to comment.