Skip to content

Commit

Permalink
Transform TypeScriptReader from an object expression to an interfac…
Browse files Browse the repository at this point in the history
…e `ITypeScriptReader` to work around a bug in Fable

See fable-compiler/Fable#3779
  • Loading branch information
MangelMaxime committed Mar 9, 2024
1 parent 85fd7a7 commit 523d567
Show file tree
Hide file tree
Showing 20 changed files with 36 additions and 26 deletions.
1 change: 1 addition & 0 deletions src/Glutinum.Build/Web.fs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ let handle (args: string list) =
|> CmdLine.appendRaw "fable"
|> CmdLine.appendRaw "--noCache"
|> CmdLine.appendRaw "--verbose"
|> CmdLine.appendPrefix "--define" "DEBUG"
|> CmdLine.toString,
workingDirectory = "src/Glutinum.Web"
)
Expand Down
6 changes: 3 additions & 3 deletions src/Glutinum.Converter.CLI/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
".NETStandard,Version=v2.0": {
"Fable.Core": {
"type": "Direct",
"requested": "[4.2.0, )",
"resolved": "4.2.0",
"contentHash": "ikacgHRLZpNVS33oBzl4uDHXZJDH660SaNPYCDGvFb7Hhm4WCXq0qTik8bpPJAhCnLDVrXLCAIoGKsKQ5pfx2A=="
"requested": "[4.3.0, )",
"resolved": "4.3.0",
"contentHash": "sbK+hYs7H7I3b3sbgttI4GlvQfNPcIqSz1qPSagF3QbVA46KJ/pWSXC/Dwv0s9M6AeRGmoqcIeD7GUaLn41zkA=="
},
"FSharp.Core": {
"type": "Direct",
Expand Down
4 changes: 3 additions & 1 deletion src/Glutinum.Converter/Read.fs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
module rec Glutinum.Converter.Read

open TypeScript
open Glutinum.Converter.Reader.Types
open Glutinum.Converter.Reader.TypeScriptReader

let readSourceFile
(checker: Ts.TypeChecker)
(sourceFile: option<Ts.SourceFile>)
=
let reader = Reader.TypeScriptReader.typeScriptReader checker
let reader: ITypeScriptReader = TypeScriptReader(checker)

{|
GlueAST =
Expand Down
2 changes: 1 addition & 1 deletion src/Glutinum.Converter/Reader/ClassDeclaration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ open Glutinum.Converter.Reader.Types
open TypeScript

let readClassDeclaration
(reader: TypeScriptReader)
(reader: ITypeScriptReader)
(classDeclaration: Ts.ClassDeclaration)
: GlueClassDeclaration
=
Expand Down
2 changes: 1 addition & 1 deletion src/Glutinum.Converter/Reader/EnumDeclaration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ let private readEnumMembers
|}

let readEnumDeclaration
(reader: TypeScriptReader)
(reader: ITypeScriptReader)
(enumDeclaration: Ts.EnumDeclaration)
: GlueEnum
=
Expand Down
2 changes: 1 addition & 1 deletion src/Glutinum.Converter/Reader/FunctionDeclaration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ open TypeScript
open Fable.Core.JsInterop

let readFunctionDeclaration
(reader: TypeScriptReader)
(reader: ITypeScriptReader)
(declaration: Ts.FunctionDeclaration)
: GlueFunctionDeclaration
=
Expand Down
2 changes: 1 addition & 1 deletion src/Glutinum.Converter/Reader/IndexedAccessType.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ open Glutinum.Converter.Reader.Types
open TypeScript

let readIndexedAccessType
(reader: TypeScriptReader)
(reader: ITypeScriptReader)
(declaration: Ts.IndexedAccessType)
: GlueType
=
Expand Down
2 changes: 1 addition & 1 deletion src/Glutinum.Converter/Reader/InterfaceDeclaration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ open Glutinum.Converter.GlueAST
open Glutinum.Converter.Reader.Types

let readInterfaceDeclaration
(reader: TypeScriptReader)
(reader: ITypeScriptReader)
(declaration: Ts.InterfaceDeclaration)
: GlueInterface
=
Expand Down
2 changes: 1 addition & 1 deletion src/Glutinum.Converter/Reader/ModuleDeclaration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ open Glutinum.Converter.Reader.Types
open TypeScript

let readModuleDeclaration
(reader: TypeScriptReader)
(reader: ITypeScriptReader)
(declaration: Ts.ModuleDeclaration)
: GlueModuleDeclaration
=
Expand Down
2 changes: 1 addition & 1 deletion src/Glutinum.Converter/Reader/NamedDeclaration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ open TypeScript
open Fable.Core.JsInterop

let readNamedDeclaration
(reader: TypeScriptReader)
(reader: ITypeScriptReader)
(declaration: Ts.NamedDeclaration)
: GlueMember
=
Expand Down
4 changes: 3 additions & 1 deletion src/Glutinum.Converter/Reader/Node.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ open Glutinum.Converter.GlueAST
open Glutinum.Converter.Reader.Types
open TypeScript

let readNode (reader: TypeScriptReader) (node: Ts.Node) : GlueType =
let readNode (reader: ITypeScriptReader) (node: Ts.Node) : GlueType =
match node.kind with
| Ts.SyntaxKind.EnumDeclaration ->
reader.ReadEnumDeclaration(node :?> Ts.EnumDeclaration)
Expand Down Expand Up @@ -39,6 +39,8 @@ let readNode (reader: TypeScriptReader) (node: Ts.Node) : GlueType =
$"Unsupported node kind %A{unsupported}"
node

printfn "Warning: %s" warning

reader.Warnings.Add warning

GlueType.Discard
2 changes: 1 addition & 1 deletion src/Glutinum.Converter/Reader/Parameters.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ open Glutinum.Converter.Reader.Types
open TypeScript

let readParameters
(reader: TypeScriptReader)
(reader: ITypeScriptReader)
(parameters: ResizeArray<Ts.ParameterDeclaration>)
=
parameters
Expand Down
2 changes: 1 addition & 1 deletion src/Glutinum.Converter/Reader/TypeAliasDeclaration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ open Glutinum.Converter.Reader.Types
open TypeScript

let readTypeAliasDeclaration
(reader: TypeScriptReader)
(reader: ITypeScriptReader)
(declaration: Ts.TypeAliasDeclaration)
: GlueType
=
Expand Down
6 changes: 5 additions & 1 deletion src/Glutinum.Converter/Reader/TypeNode.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ open Fable.Core.JsInterop
open Fable.Core.JS
open Glutinum.Converter.Reader.Utils

let readTypeNode (reader: TypeScriptReader) (typeNode: Ts.TypeNode) : GlueType =
let readTypeNode
(reader: ITypeScriptReader)
(typeNode: Ts.TypeNode)
: GlueType
=
let checker = reader.checker

match typeNode.kind with
Expand Down
2 changes: 1 addition & 1 deletion src/Glutinum.Converter/Reader/TypeOperatorNode.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ open TypeScript
open Fable.Core.JsInterop

let readTypeOperatorNode
(reader: TypeScriptReader)
(reader: ITypeScriptReader)
(node: Ts.TypeOperatorNode)
=

Expand Down
2 changes: 1 addition & 1 deletion src/Glutinum.Converter/Reader/TypeParameters.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ open TypeScript
open Fable.Core.JsInterop

let readTypeParameters
(reader: TypeScriptReader)
(reader: ITypeScriptReader)
(typeParameters: ResizeArray<Ts.TypeParameterDeclaration> option)
: GlueTypeParameter list
=
Expand Down
8 changes: 4 additions & 4 deletions src/Glutinum.Converter/Reader/TypeScriptReader.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ open Glutinum.Converter.Reader.TypeParameters
open Glutinum.Converter.Reader.UnionTypeNode
open Glutinum.Converter.Reader.VariableStatement

let typeScriptReader checker =
type TypeScriptReader(checker: Ts.TypeChecker) =
let warnings = ResizeArray<string>()

{ new TypeScriptReader(checker) with
interface ITypeScriptReader with

override _.checker: Ts.TypeChecker = checker

member _.Warnings = warnings
Expand Down Expand Up @@ -70,7 +71,7 @@ let typeScriptReader checker =
readTypeAliasDeclaration this typeAliasDeclaration

member this.ReadTypeNode(typNode: Ts.TypeNode) : GlueType =
this.ReadTypeNode(Some typNode)
(this :> ITypeScriptReader).ReadTypeNode(Some typNode)

member this.ReadTypeNode(typNode: Ts.TypeNode option) : GlueType =
match typNode with
Expand Down Expand Up @@ -112,4 +113,3 @@ let typeScriptReader checker =
: GlueTypeParameter list
=
readTypeParameters this typeParametersOpt
}
5 changes: 3 additions & 2 deletions src/Glutinum.Converter/Reader/Types.fs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
module Glutinum.Converter.Reader.Types

open Fable.Core
open TypeScript
open Glutinum.Converter.GlueAST

exception TypeScriptReaderException of message: string

[<AbstractClass>]
type TypeScriptReader(checker: Ts.TypeChecker) =
[<Mangle>]
type ITypeScriptReader =
abstract checker: Ts.TypeChecker with get
abstract Warnings: ResizeArray<string> with get

Expand Down
4 changes: 2 additions & 2 deletions src/Glutinum.Converter/Reader/UnionTypeNode.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ open TypeScript
open Fable.Core.JsInterop

let rec private readUnionTypeCases
(reader: TypeScriptReader)
(reader: ITypeScriptReader)
(unionTypeNode: Ts.UnionTypeNode)
: GlueTypeUnion
=
Expand Down Expand Up @@ -143,7 +143,7 @@ let rec private readUnionTypeCases
|> GlueTypeUnion

let readUnionTypeNode
(reader: TypeScriptReader)
(reader: ITypeScriptReader)
(unionTypeNode: Ts.UnionTypeNode)
: GlueType
=
Expand Down
2 changes: 1 addition & 1 deletion src/Glutinum.Converter/Reader/VariableStatement.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ open TypeScript
open Fable.Core.JsInterop

let readVariableStatement
(reader: TypeScriptReader)
(reader: ITypeScriptReader)
(statement: Ts.VariableStatement)
: GlueType
=
Expand Down

0 comments on commit 523d567

Please sign in to comment.