Skip to content

Commit

Permalink
Prevent useNavigator being compiled as tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Lanayx committed Jan 3, 2025
1 parent aff174f commit dcf7e9f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Oxpecker.Solid.FablePlugin/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ module internal rec AST =

let (|LibraryTagImport|_|) (expr: Expr) =
match expr with
| Call(Import({ Kind = UserImport false }, Any, _) as imp, _, DeclaredType(typ, []), range) when
| Call(Import({ Kind = UserImport false }, Any, _) as imp, { Tags = [ "new" ] }, DeclaredType(typ, []), range) when
typ.FullName.StartsWith("Oxpecker.Solid")
->
Some(imp, range)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
<Authors>Vladimir Shchur and contributors</Authors>
<Copyright>Copyright (c) Vladimir Shchur 2024</Copyright>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Version>0.4.1</Version>
<PackageVersion>0.4.1</PackageVersion>
<PackageReleaseNotes>More graceful fallback on compilation error</PackageReleaseNotes>
<Version>0.4.2</Version>
<PackageVersion>0.4.2</PackageVersion>
<PackageReleaseNotes>Prevent useNavigator being compiled as tag</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/Oxpecker.Solid/Oxpecker.Solid.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
<Authors>Vladimir Shchur and contributors</Authors>
<Copyright>Copyright (c) Vladimir Shchur 2024</Copyright>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Version>0.4.1</Version>
<PackageVersion>0.4.1</PackageVersion>
<PackageReleaseNotes>More graceful fallback on compilation error</PackageReleaseNotes>
<Version>0.4.2</Version>
<PackageVersion>0.4.2</PackageVersion>
<PackageReleaseNotes>Prevent useNavigator being compiled as tag</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions tests/Oxpecker.Solid.Tests/Common.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ let private runCase folderName caseName =
cli {
Shell CMD
WorkingDirectory dir
Command "dotnet fable --noCache --exclude Oxpecker.Solid.FablePlugin"
Command "dotnet fable --noCache --exclude Oxpecker.Solid.FablePlugin --extension .jsx"
}
|> Command.execute
|> Output.toExitCode
|> shouldEqual 0

let result = File.ReadAllText($"{dir}/{caseName}.fs.js")
let result = File.ReadAllText($"{dir}/{caseName}.jsx")
let expected = File.ReadAllText($"{dir}/{caseName}.expected")
result |> shouldEqual expected

Expand Down
18 changes: 14 additions & 4 deletions tests/Oxpecker.Solid.Tests/SolidCases/Router/Router.expected
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Route, Router, A } from "@solidjs/router";
import { App1 } from "./App1.fs.js";
import { App2 } from "./App2.fs.js";
import { lazy } from "solid-js";
import { Route, Router, useNavigate, A } from "@solidjs/router";
import { lazy, createEffect } from "solid-js";
import { App1 } from "./App1.jsx";
import { App2 } from "./App2.jsx";

export function Root(props) {
return <>
Expand All @@ -15,6 +15,16 @@ export function Root(props) {
</>;
}

export function App3() {
const navigator = useNavigate();
createEffect(() => {
navigator("/def/inner");
});
return <h1>
Hello world 3
</h1>;
}

export function Test1() {
return <Router root={Root}>
<Route></Route>
Expand Down
7 changes: 7 additions & 0 deletions tests/Oxpecker.Solid.Tests/SolidCases/Router/Router.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ let Root (props: RootProps) : HtmlElement =
A(href="/about") { "About" }
}

[<SolidComponent>]
let App3 () : HtmlElement =
let navigator = useNavigate()
createEffect(fun _ -> navigator.Invoke("/def/inner"))

h1() { "Hello world 3" }

[<SolidComponent>]
let Test1 () =
Router(root=Root) {
Expand Down

0 comments on commit dcf7e9f

Please sign in to comment.