Skip to content

Commit 8c08980

Browse files
authored
Merge pull request #783 from wfltaylor/js-merge-structs
BridgeJS: Fix issues exporting nested types
2 parents 2290507 + 79a58f2 commit 8c08980

77 files changed

Lines changed: 2777 additions & 488 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,15 +560,15 @@ public class ExportSwift {
560560
func callName(for property: ExportedProperty) -> String {
561561
switch self {
562562
case .enumStatic(let enumDef):
563-
return property.callName(prefix: enumDef.swiftCallName)
563+
return "\(enumDef.swiftCallName).\(property.name)"
564564
case .classStatic(let klass):
565565
// property.callName() would use staticContext (the ABI name) as prefix;
566566
// use swiftCallName directly so the emitted expression is valid Swift.
567567
return "\(klass.swiftCallName).\(property.name)"
568568
case .classInstance:
569569
return property.callName()
570570
case .structStatic(let structDef):
571-
return property.callName(prefix: structDef.swiftCallName)
571+
return "\(structDef.swiftCallName).\(property.name)"
572572
}
573573
}
574574
}

Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift

Lines changed: 303 additions & 262 deletions
Large diffs are not rendered by default.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
@JS class Account {
2+
@JS enum Role: String {
3+
case admin
4+
case guest
5+
}
6+
7+
@JS struct Credentials {
8+
var token: String
9+
10+
@JS init(token: String) {
11+
self.token = token
12+
}
13+
14+
@JS static var maxLength: Int { 64 }
15+
16+
@JS static func empty() -> Credentials {
17+
Credentials(token: "")
18+
}
19+
}
20+
21+
@JS var name: String
22+
23+
@JS var role: Role { .admin }
24+
25+
@JS static var defaultRole: Role { .guest }
26+
27+
@JS init(name: String) {
28+
self.name = name
29+
}
30+
31+
@JS func describe() -> String {
32+
name
33+
}
34+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
@JS struct Shape {
2+
@JS enum Kind: String {
3+
case circle
4+
case square
5+
}
6+
7+
var label: String
8+
9+
@JS init(label: String) {
10+
self.label = label
11+
}
12+
}
13+
14+
@JS struct Widget {
15+
@JS enum Variant: String {
16+
case button
17+
case slider
18+
}
19+
20+
@JS struct Layout {
21+
@JS enum Alignment: String {
22+
case leading
23+
case trailing
24+
}
25+
26+
var padding: Int
27+
}
28+
29+
@JS struct Bounds {
30+
var width: Int
31+
var height: Int
32+
33+
@JS init(width: Int, height: Int) {
34+
self.width = width
35+
self.height = height
36+
}
37+
38+
@JS static var dimensions: Int {
39+
2
40+
}
41+
42+
@JS static func zero() -> Bounds {
43+
Bounds(width: 0, height: 0)
44+
}
45+
}
46+
47+
var name: String
48+
49+
@JS init(name: String) {
50+
self.name = name
51+
}
52+
}
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
{
2+
"exported" : {
3+
"aliases" : [
4+
5+
],
6+
"classes" : [
7+
{
8+
"constructor" : {
9+
"abiName" : "bjs_Account_init",
10+
"effects" : {
11+
"isAsync" : false,
12+
"isStatic" : false,
13+
"isThrows" : false
14+
},
15+
"parameters" : [
16+
{
17+
"label" : "name",
18+
"name" : "name",
19+
"type" : {
20+
"string" : {
21+
22+
}
23+
}
24+
}
25+
]
26+
},
27+
"methods" : [
28+
{
29+
"abiName" : "bjs_Account_describe",
30+
"effects" : {
31+
"isAsync" : false,
32+
"isStatic" : false,
33+
"isThrows" : false
34+
},
35+
"name" : "describe",
36+
"parameters" : [
37+
38+
],
39+
"returnType" : {
40+
"string" : {
41+
42+
}
43+
}
44+
}
45+
],
46+
"name" : "Account",
47+
"properties" : [
48+
{
49+
"isReadonly" : false,
50+
"isStatic" : false,
51+
"name" : "name",
52+
"type" : {
53+
"string" : {
54+
55+
}
56+
}
57+
},
58+
{
59+
"isReadonly" : true,
60+
"isStatic" : false,
61+
"name" : "role",
62+
"type" : {
63+
"rawValueEnum" : {
64+
"_0" : "Account.Role",
65+
"_1" : "String"
66+
}
67+
}
68+
},
69+
{
70+
"isReadonly" : true,
71+
"isStatic" : true,
72+
"name" : "defaultRole",
73+
"staticContext" : {
74+
"className" : {
75+
"_0" : "Account"
76+
}
77+
},
78+
"type" : {
79+
"rawValueEnum" : {
80+
"_0" : "Account.Role",
81+
"_1" : "String"
82+
}
83+
}
84+
}
85+
],
86+
"swiftCallName" : "Account"
87+
}
88+
],
89+
"enums" : [
90+
{
91+
"cases" : [
92+
{
93+
"associatedValues" : [
94+
95+
],
96+
"name" : "admin"
97+
},
98+
{
99+
"associatedValues" : [
100+
101+
],
102+
"name" : "guest"
103+
}
104+
],
105+
"emitStyle" : "const",
106+
"name" : "Role",
107+
"namespace" : [
108+
"Account"
109+
],
110+
"rawType" : "String",
111+
"staticMethods" : [
112+
113+
],
114+
"staticProperties" : [
115+
116+
],
117+
"swiftCallName" : "Account.Role",
118+
"tsFullPath" : "Account.Role"
119+
}
120+
],
121+
"exposeToGlobal" : false,
122+
"functions" : [
123+
124+
],
125+
"protocols" : [
126+
127+
],
128+
"structs" : [
129+
{
130+
"constructor" : {
131+
"abiName" : "bjs_Account_Credentials_init",
132+
"effects" : {
133+
"isAsync" : false,
134+
"isStatic" : false,
135+
"isThrows" : false
136+
},
137+
"parameters" : [
138+
{
139+
"label" : "token",
140+
"name" : "token",
141+
"type" : {
142+
"string" : {
143+
144+
}
145+
}
146+
}
147+
]
148+
},
149+
"methods" : [
150+
{
151+
"abiName" : "bjs_Account_Credentials_static_empty",
152+
"effects" : {
153+
"isAsync" : false,
154+
"isStatic" : true,
155+
"isThrows" : false
156+
},
157+
"name" : "empty",
158+
"parameters" : [
159+
160+
],
161+
"returnType" : {
162+
"swiftStruct" : {
163+
"_0" : "Account.Credentials"
164+
}
165+
},
166+
"staticContext" : {
167+
"structName" : {
168+
"_0" : "Account_Credentials"
169+
}
170+
}
171+
}
172+
],
173+
"name" : "Credentials",
174+
"namespace" : [
175+
"Account"
176+
],
177+
"properties" : [
178+
{
179+
"isReadonly" : true,
180+
"isStatic" : false,
181+
"name" : "token",
182+
"namespace" : [
183+
"Account"
184+
],
185+
"type" : {
186+
"string" : {
187+
188+
}
189+
}
190+
},
191+
{
192+
"isReadonly" : true,
193+
"isStatic" : true,
194+
"name" : "maxLength",
195+
"staticContext" : {
196+
"structName" : {
197+
"_0" : "Account_Credentials"
198+
}
199+
},
200+
"type" : {
201+
"integer" : {
202+
"_0" : {
203+
"isSigned" : true,
204+
"width" : "word"
205+
}
206+
}
207+
}
208+
}
209+
],
210+
"swiftCallName" : "Account.Credentials"
211+
}
212+
]
213+
},
214+
"moduleName" : "TestModule",
215+
"usedExternalModules" : [
216+
217+
]
218+
}

0 commit comments

Comments
 (0)