Skip to content

Commit 04a82dc

Browse files
committed
fix: support resolving name when deconstructing a parameter
[converter][web] Fix #116 === changelog === ```ts export interface LogOptions { prefix: string; } export interface Context { indentationLevel: number; } declare class Signature { toText({ indentationLevel }: Context, data : string, {prefix }?: LogOptions): string; } ``` ```fs [<AllowNullLiteral>] [<Interface>] type LogOptions = abstract member prefix: string with get, set [<AllowNullLiteral>] [<Interface>] type Context = abstract member indentationLevel: float with get, set [<AllowNullLiteral>] [<Interface>] type Signature = abstract member toText: arg0: Context * data: string * ?arg2: LogOptions -> string ``` === changelog ===
1 parent 0657ea3 commit 04a82dc

File tree

5 files changed

+93
-3
lines changed

5 files changed

+93
-3
lines changed

src/Glutinum.Converter/Reader/Parameters.fs

+18-3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,26 @@ let readParameters
1111
=
1212
parameters
1313
|> Seq.toList
14-
|> List.map (fun parameter ->
15-
let name = unbox<Ts.Identifier> parameter.name
14+
|> List.mapi (fun index parameter ->
15+
let nameNode = unbox<Ts.Node> parameter.name
16+
17+
let name =
18+
match nameNode.kind with
19+
| Ts.SyntaxKind.Identifier ->
20+
let name = nameNode :?> Ts.Identifier
21+
name.getText ()
22+
| Ts.SyntaxKind.ObjectBindingPattern -> $"arg%i{index}"
23+
| _ ->
24+
Utils.generateReaderError
25+
"name"
26+
$"Unsupported kind %A{nameNode.kind}"
27+
nameNode
28+
|> reader.Warnings.Add
29+
30+
$"arg%i{index}"
1631

1732
{
18-
Name = name.getText ()
33+
Name = name
1934
IsOptional = parameter.questionToken.IsSome
2035
IsSpread = parameter.dotDotDotToken.IsSome
2136
Type = reader.ReadTypeNode parameter.``type``
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export interface LogOptions {
2+
prefix: string;
3+
}
4+
5+
export interface Context {
6+
indentationLevel: number;
7+
}
8+
9+
declare class Signature {
10+
toText({ indentationLevel }: Context, data : string, {prefix }?: LogOptions): string;
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module rec Glutinum
2+
3+
open Fable.Core
4+
open Fable.Core.JsInterop
5+
open System
6+
7+
[<AbstractClass>]
8+
[<Erase>]
9+
type Exports =
10+
[<Import("Signature", "REPLACE_ME_WITH_MODULE_NAME"); EmitConstructor>]
11+
static member Signature () : Signature = nativeOnly
12+
13+
[<AllowNullLiteral>]
14+
[<Interface>]
15+
type LogOptions =
16+
abstract member prefix: string with get, set
17+
18+
[<AllowNullLiteral>]
19+
[<Interface>]
20+
type Context =
21+
abstract member indentationLevel: float with get, set
22+
23+
[<AllowNullLiteral>]
24+
[<Interface>]
25+
type Signature =
26+
abstract member toText: arg0: Context * data: string * ?arg2: LogOptions -> string
27+
28+
(***)
29+
#r "nuget: Fable.Core"
30+
(***)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export interface LogOptions {
2+
prefix: string;
3+
}
4+
5+
export interface Context {
6+
indentationLevel: number;
7+
}
8+
9+
declare function toText({ indentationLevel }: Context, data : string, {prefix }?: LogOptions): string;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module rec Glutinum
2+
3+
open Fable.Core
4+
open Fable.Core.JsInterop
5+
open System
6+
7+
[<AbstractClass>]
8+
[<Erase>]
9+
type Exports =
10+
[<Import("toText", "REPLACE_ME_WITH_MODULE_NAME")>]
11+
static member toText (arg0: Context, data: string, ?arg2: LogOptions) : string = nativeOnly
12+
13+
[<AllowNullLiteral>]
14+
[<Interface>]
15+
type LogOptions =
16+
abstract member prefix: string with get, set
17+
18+
[<AllowNullLiteral>]
19+
[<Interface>]
20+
type Context =
21+
abstract member indentationLevel: float with get, set
22+
23+
(***)
24+
#r "nuget: Fable.Core"
25+
(***)

0 commit comments

Comments
 (0)