From 295162276825b6e17cd8caac5d3f7ba8bc151ff8 Mon Sep 17 00:00:00 2001 From: Zaid Ajaj Date: Mon, 9 May 2022 15:22:09 -0700 Subject: [PATCH] Feliz v1.64 ensure [] only apply use prefix when necessary (fixes #479) --- .vscode/settings.json | 3 ++- .../Feliz.CompilerPlugins.fsproj | 4 ++-- Feliz.CompilerPlugins/Hook.fs | 21 ++++++++++++++----- Feliz/Feliz.fsproj | 4 ++-- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index a0970c74..647b57cc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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 } \ No newline at end of file diff --git a/Feliz.CompilerPlugins/Feliz.CompilerPlugins.fsproj b/Feliz.CompilerPlugins/Feliz.CompilerPlugins.fsproj index 9a082b83..64a64c74 100644 --- a/Feliz.CompilerPlugins/Feliz.CompilerPlugins.fsproj +++ b/Feliz.CompilerPlugins/Feliz.CompilerPlugins.fsproj @@ -3,9 +3,9 @@ Provides compile-time transformation for React components fsharp;fable;react;html Zaid Ajaj - 1.8.0 + 1.9.0 netstandard2.0 - Added ReactMemoComponent attribute + Make the Hook attribute check if and apply the "use" prefix only if necessary diff --git a/Feliz.CompilerPlugins/Hook.fs b/Feliz.CompilerPlugins/Hook.fs index 1f918c70..d19489bc 100644 --- a/Feliz.CompilerPlugins/Hook.fs +++ b/Feliz.CompilerPlugins/Hook.fs @@ -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) | _ -> @@ -38,4 +44,9 @@ type HookAttribute() = compiler.LogWarning(errorMessage, ?range=decl.Body.Range) decl else - { decl with Name = "use" + decl.Name } \ No newline at end of file + 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 \ No newline at end of file diff --git a/Feliz/Feliz.fsproj b/Feliz/Feliz.fsproj index 8ee4d375..e713ad2f 100644 --- a/Feliz/Feliz.fsproj +++ b/Feliz/Feliz.fsproj @@ -4,9 +4,9 @@ A fresh retake of the React API in Fable, optimized for happiness fsharp;fable;react;html Zaid Ajaj - 1.63.0 + 1.64.0 netstandard2.0 - object-fit CSS property and source link support + Make the Hook attribute check if and apply the "use" prefix only if necessary