Skip to content
Merged
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
12 changes: 6 additions & 6 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ let package = Package(
)
],
dependencies: [
.package(url: "https://github.com/omochi/SwiftTypeReader", from: "2.7.0"),
.package(url: "https://github.com/omochi/SwiftTypeReader", from: "2.10.0"),
// .package(path: "../SwiftTypeReader"),
.package(url: "https://github.com/omochi/TypeScriptAST", from: "1.8.6"),
],
targets: [
Expand Down
14 changes: 7 additions & 7 deletions Sources/CodableToTypeScript/TypeConverter/StructConverter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public struct StructConverter: TypeConverter {
var fields: [TSObjectType.Field] = []

try withErrorCollector { collect in
for property in decl.storedProperties {
for property in decl.storedProperties.instances {
collect(at: "\(property.name)") {
let (type, isOptional) = try generator.converter(for: property.interfaceType)
.fieldType(for: target)
Expand Down Expand Up @@ -66,7 +66,7 @@ public struct StructConverter: TypeConverter {

var result: [CodecPresence] = [.identity]
try withErrorCollector { collect in
for p in decl.storedProperties {
for p in decl.storedProperties.instances {
collect(at: "\(p.name)") {
let converter = try generator.converter(for: p.interfaceType.subst(map: map))
result.append(try converter.decodePresence())
Expand All @@ -82,7 +82,7 @@ public struct StructConverter: TypeConverter {
var fields: [TSObjectExpr.Field] = []

try withErrorCollector { collect in
for field in decl.storedProperties {
for field in decl.storedProperties.instances {
var expr: any TSExpr = TSMemberExpr(
base: TSIdentExpr.json,
name: field.name
Expand All @@ -101,7 +101,7 @@ public struct StructConverter: TypeConverter {
}
}

for field in decl.storedProperties {
for field in decl.storedProperties.instances {
let expr = TSIdentExpr(TSKeyword.escaped(field.name))

fields.append(
Expand All @@ -124,7 +124,7 @@ public struct StructConverter: TypeConverter {

var result: [CodecPresence] = [.identity]
try withErrorCollector { collect in
for p in decl.storedProperties {
for p in decl.storedProperties.instances {
collect(at: "\(p.name)") {
let converter = try generator.converter(for: p.interfaceType.subst(map: map))
result.append(try converter.encodePresence())
Expand All @@ -139,7 +139,7 @@ public struct StructConverter: TypeConverter {

var fields: [TSObjectExpr.Field] = []

for field in decl.storedProperties {
for field in decl.storedProperties.instances {
var expr: any TSExpr = TSMemberExpr(
base: TSIdentExpr.entity,
name: field.name
Expand All @@ -156,7 +156,7 @@ public struct StructConverter: TypeConverter {
function.body.elements.append(def)
}

for field in decl.storedProperties {
for field in decl.storedProperties.instances {
let expr = TSIdentExpr(TSKeyword.escaped(field.name))

fields.append(
Expand Down
36 changes: 36 additions & 0 deletions Tests/CodableToTypeScriptTests/Generate/GenerateStructTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -371,4 +371,40 @@ struct S {
""")
)
}

func testStaticProperty() throws {
try assertGenerate(
source: """
struct S {
static var k: Int = 0

var a: Int
}
""",
expecteds: ["""
export type S = {
a: number;
} & TagRecord<"S">;
"""
]
)
}

func testUnknownStaticProperty() throws {
try assertGenerate(
source: """
struct S {
static var k: Unknown = 0

var a: Int
}
""",
expecteds: ["""
export type S = {
a: number;
} & TagRecord<"S">;
"""
]
)
}
}