Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JS/TS/Python] Fix #4041: Replace idents with unit type #4044

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/Fable.Transforms/Fable2Babel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2827,13 +2827,17 @@ module Util =

| _ -> transformDecisionTreeWithExtraSwitch com ctx returnStrategy targets treeExpr

let transformIdent (com: IBabelCompiler) ctx id =
let e = identAsExpr id
let transformIdent (com: IBabelCompiler) ctx (id: Fable.Ident) =
match id.Type with
// Remove unit idents, because the declaration may have been erased #4041
| Fable.Unit -> undefined id.Range None
| _ ->
let e = identAsExpr id

if com.IsTypeScript && ctx.ForcedIdents.Contains id.Name then
Expression.unaryExpression (UnaryNot, e, isSuffix = true)
else
e
if com.IsTypeScript && ctx.ForcedIdents.Contains id.Name then
Expression.unaryExpression (UnaryNot, e, isSuffix = true)
else
e

let rec transformAsExpr (com: IBabelCompiler) ctx (expr: Fable.Expr) : Expression =
match expr with
Expand Down
10 changes: 8 additions & 2 deletions src/Fable.Transforms/Python/Fable2Python.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2950,6 +2950,12 @@ module Util =
let name = Expression.name name
Expression.call name, [ func ]

let transformIdent (com: IPythonCompiler) ctx (id: Fable.Ident) =
match id.Type with
// Remove unit idents, because the declaration may have been erased #4041
| Fable.Unit -> undefined id.Range
| _ -> identAsExpr com ctx id

let rec transformAsExpr (com: IPythonCompiler) ctx (expr: Fable.Expr) : Expression * Statement list =
// printfn "transformAsExpr: %A" expr
match expr with
Expand All @@ -2959,7 +2965,7 @@ module Util =

| Fable.Value(kind, r) -> transformValue com ctx r kind

| Fable.IdentExpr id -> identAsExpr com ctx id, []
| Fable.IdentExpr id -> transformIdent com ctx id, []

| Fable.Import({
Selector = selector
Expand Down Expand Up @@ -3154,7 +3160,7 @@ module Util =

stmts @ (expr |> resolveExpr ctx kind.Type returnStrategy)

| Fable.IdentExpr id -> identAsExpr com ctx id |> resolveExpr ctx id.Type returnStrategy
| Fable.IdentExpr id -> transformIdent com ctx id |> resolveExpr ctx id.Type returnStrategy

| Fable.Import({
Selector = selector
Expand Down
Loading