Skip to content

Commit

Permalink
Feliz v1.64 ensure [<Hook>] only apply use prefix when necessary (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaid-Ajaj committed May 9, 2022
1 parent 73b90f8 commit 2951622
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"FSharp.showExplorerOnStartup": false,
"FSharp.simplifyNameAnalyzer": false,
"FSharp.linter": false,
"FSharp.lineLens.enabled": "never"
"FSharp.lineLens.enabled": "never",
"FSharp.inlayHints.typeAnnotations": false
}
4 changes: 2 additions & 2 deletions Feliz.CompilerPlugins/Feliz.CompilerPlugins.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<Description>Provides compile-time transformation for React components</Description>
<PackageTags>fsharp;fable;react;html</PackageTags>
<Authors>Zaid Ajaj</Authors>
<Version>1.8.0</Version>
<Version>1.9.0</Version>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageReleaseNotes>Added ReactMemoComponent attribute</PackageReleaseNotes>
<PackageReleaseNotes>Make the Hook attribute check if and apply the "use" prefix only if necessary</PackageReleaseNotes>
</PropertyGroup>
<ItemGroup>
<Compile Include="AstUtils.fs" />
Expand Down
21 changes: 16 additions & 5 deletions Feliz.CompilerPlugins/Hook.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ type HookAttribute() =
let callee =
match callee with
| Fable.Expr.IdentExpr ident ->
// capitalize same-file references
Fable.Expr.IdentExpr { ident with Name = "use" + ident.Name }
if not (ident.Name.StartsWith "use") then
Fable.Expr.IdentExpr { ident with Name = "use" + ident.Name }
else
callee
| Fable.Expr.Import(importInfo, fableType, sourceLocation) ->
// capitalize component imports from different modules/files
let selector = "use" + importInfo.Selector
// apply prefix "use" from hook imports from different modules/files
let selector =
if not (importInfo.Selector.StartsWith "use") then
"use" + importInfo.Selector
else
importInfo.Selector
let modifiedImportInfo = { importInfo with Selector = selector }
Fable.Expr.Import(modifiedImportInfo, fableType, sourceLocation)
| _ ->
Expand All @@ -38,4 +44,9 @@ type HookAttribute() =
compiler.LogWarning(errorMessage, ?range=decl.Body.Range)
decl
else
{ decl with Name = "use" + decl.Name }
if not (decl.Name.StartsWith "use") then
// only apply "use" prefix if the declaration doesn't already have it
{ decl with Name = "use" + decl.Name }
else
// hook function already start with "use", keep it as-is
decl
4 changes: 2 additions & 2 deletions Feliz/Feliz.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<Description>A fresh retake of the React API in Fable, optimized for happiness</Description>
<PackageTags>fsharp;fable;react;html</PackageTags>
<Authors>Zaid Ajaj</Authors>
<Version>1.63.0</Version>
<Version>1.64.0</Version>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageReleaseNotes>object-fit CSS property and source link support</PackageReleaseNotes>
<PackageReleaseNotes>Make the Hook attribute check if and apply the "use" prefix only if necessary</PackageReleaseNotes>
</PropertyGroup>
<PropertyGroup>
<NpmDependencies>
Expand Down

0 comments on commit 2951622

Please sign in to comment.