forked from Zaid-Ajaj/Feliz
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feliz v1.17 with new [Hook] attribute
- Loading branch information
Showing
19 changed files
with
128 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
namespace Feliz | ||
|
||
open Fable | ||
open Fable.AST | ||
|
||
/// <summary>Applies to custom defined React hooks to ensure the generated code starts with "use" in order for fast-refresh to pick it up</summary> | ||
type HookAttribute() = | ||
inherit MemberDeclarationPluginAttribute() | ||
override _.FableMinimumVersion = "3.0" | ||
|
||
/// <summary>Transforms call-site into createElement calls</summary> | ||
override _.TransformCall(compiler, memb, expr) = | ||
let membArgs = memb.CurriedParameterGroups |> List.concat | ||
match expr with | ||
| Fable.Call(callee, info, typeInfo, range) -> | ||
let callee = | ||
match callee with | ||
| Fable.Expr.IdentExpr ident -> | ||
// capitalize same-file references | ||
Fable.Expr.IdentExpr { ident with Name = "use" + ident.Name } | ||
| Fable.Expr.Import(importInfo, fableType, sourceLocation) -> | ||
// capitalize component imports from different modules/files | ||
let selector = "use" + importInfo.Selector | ||
let modifiedImportInfo = { importInfo with Selector = selector } | ||
Fable.Expr.Import(modifiedImportInfo, fableType, sourceLocation) | ||
| _ -> | ||
callee | ||
|
||
Fable.Call(callee, info, typeInfo, range) | ||
|
||
| _ -> | ||
expr | ||
|
||
override this.Transform(compiler, decl) = | ||
if decl.Info.IsValue || decl.Info.IsGetter || decl.Info.IsSetter then | ||
// Invalid attribute usage | ||
let errorMessage = sprintf "Expecting a function declation for %s when using [<Hook>]" decl.Name | ||
compiler.LogWarning(errorMessage, ?range=decl.Body.Range) | ||
decl | ||
else | ||
{ decl with Name = "use" + decl.Name } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.