@@ -2,6 +2,8 @@ package ts2kt.kotlin.ast
2
2
3
3
import ts2kt.DYNAMIC
4
4
import ts2kt.NATIVE_ANNOTATION
5
+ import ts2kt.NATIVE_INVOKE_ANNOTATION
6
+ import ts2kt.UNIT
5
7
import ts2kt.escapeIfNeed
6
8
import ts2kt.sanitize
7
9
@@ -11,6 +13,7 @@ private val EQ_NO_IMPL = " = $NO_IMPL"
11
13
private val NO_IMPL_PROPERTY_GETTER = " get()" + EQ_NO_IMPL
12
14
private val NO_IMPL_PROPERTY_SETTER = " set(value)" + EQ_NO_IMPL
13
15
private val EXTERNAL = " external"
16
+ private val INLINE = " inline"
14
17
private val OPEN = " open"
15
18
private val OVERRIDE = " override"
16
19
private val OPERATOR = " operator"
@@ -130,12 +133,14 @@ class Stringify(
130
133
131
134
override fun visitFunction (function : KtFunction ) {
132
135
with (function) {
133
- annotations.acceptForEach(this @Stringify)
136
+ annotations.filter { function.extendsType == null || it != NATIVE_INVOKE_ANNOTATION }. acceptForEach(this @Stringify)
134
137
135
138
out .printIndent()
136
139
137
- // TODO remove hack
138
- printExternalIfNeed()
140
+ if (function.extendsType == null ) {
141
+ // TODO remove hack
142
+ printExternalIfNeed()
143
+ }
139
144
140
145
if (isOverride) {
141
146
out .print (OVERRIDE + " " )
@@ -144,6 +149,10 @@ class Stringify(
144
149
out .print (OPEN + " " )
145
150
}
146
151
152
+ if (function.extendsType != null ) {
153
+ out .print (INLINE + " " )
154
+ }
155
+
147
156
if (isOperator) {
148
157
out .print (OPERATOR + " " )
149
158
}
@@ -159,9 +168,19 @@ class Stringify(
159
168
160
169
out .print (name.asString())
161
170
162
- callSignature.printToOut(withTypeParams = false , printUnitReturnType = needsNoImpl, printDefaultValues = ! isOverride)
171
+ callSignature.printToOut(withTypeParams = false , printUnitReturnType = needsNoImpl, printDefaultValues = ! isOverride, noImpl = extendsType == null )
163
172
164
- if (needsNoImpl) {
173
+ if (function.extendsType != null ) {
174
+ out .print (" { " )
175
+ if (function.callSignature.returnType.type.qualifiedName != UNIT ) {
176
+ out .print (" return " )
177
+ }
178
+ out .print (" this.asDynamic()." )
179
+ out .print (name.asString())
180
+ out .print (" (" )
181
+ out .print (callSignature.params.map { it.name.asString() }.joinToString(" , " ))
182
+ out .print (" ) }" )
183
+ } else if (needsNoImpl) {
165
184
out .print (EQ_NO_IMPL )
166
185
}
167
186
}
@@ -174,8 +193,10 @@ class Stringify(
174
193
175
194
out .printIndent()
176
195
177
- // TODO remove hack
178
- printExternalIfNeed()
196
+ if (variable.extendsType == null ) {
197
+ // TODO remove hack
198
+ printExternalIfNeed()
199
+ }
179
200
180
201
// TODO extract common logic between Variable and Function
181
202
if (isOverride) {
@@ -184,6 +205,10 @@ class Stringify(
184
205
out .print (OPEN + " " )
185
206
}
186
207
208
+ if (variable.extendsType != null ) {
209
+ out .print (INLINE + " " )
210
+ }
211
+
187
212
out .print ((if (isVar) VAR else VAL ) + " " )
188
213
189
214
typeParams?.acceptForEach(this @Stringify, " , " , startWithIfNotEmpty = " <" , endWithIfNotEmpty = " > " )
@@ -197,7 +222,15 @@ class Stringify(
197
222
198
223
type.printToOut(printUnitType = ! needsNoImpl)
199
224
200
- if (needsNoImpl) {
225
+ if (variable.extendsType != null ) {
226
+ out .print (" get() = this.asDynamic()." )
227
+ out .print (name.asString())
228
+ if (isVar) {
229
+ out .print (" ; set(value) { this.asDynamic()." )
230
+ out .print (name.asString())
231
+ out .print (" = value }" )
232
+ }
233
+ } else if (needsNoImpl) {
201
234
if (isInInterface) {
202
235
out .print (NO_IMPL_PROPERTY_GETTER )
203
236
if (isVar) {
@@ -256,7 +289,7 @@ class Stringify(
256
289
packagePart.members.filter(isNotAnnotatedAsFake).acceptForEach(this )
257
290
}
258
291
259
- fun KtFunParam.printToOut (printDefaultValue : Boolean ) {
292
+ fun KtFunParam.printToOut (printDefaultValue : Boolean , noImpl : Boolean = true ) {
260
293
if (isVar) {
261
294
out .print (" $OPEN $VAR " )
262
295
}
@@ -269,7 +302,11 @@ class Stringify(
269
302
type.printToOut(printUnitType = true )
270
303
271
304
if (defaultValue != null && printDefaultValue) {
272
- out .print (" = $NO_IMPL /* $defaultValue */" )
305
+ if (noImpl) {
306
+ out .print (" = $NO_IMPL /* $defaultValue */" )
307
+ } else {
308
+ out .print (" = $defaultValue " )
309
+ }
273
310
}
274
311
}
275
312
@@ -278,7 +315,7 @@ class Stringify(
278
315
}
279
316
280
317
override fun visitCallSignature (signature : KtCallSignature ) {
281
- signature.printToOut(withTypeParams = true , printUnitReturnType = true , printDefaultValues = true )
318
+ signature.printToOut(withTypeParams = true , printUnitReturnType = true , printDefaultValues = true , noImpl = true )
282
319
}
283
320
284
321
fun KtCallSignature.printTypeParams (withSpaceAfter : Boolean ) {
@@ -289,15 +326,15 @@ class Stringify(
289
326
endWithIfNotEmpty = " >" + if (withSpaceAfter) " " else " " )
290
327
}
291
328
292
- fun KtCallSignature.printToOut (withTypeParams : Boolean , printUnitReturnType : Boolean , printDefaultValues : Boolean ) {
329
+ fun KtCallSignature.printToOut (withTypeParams : Boolean , printUnitReturnType : Boolean , printDefaultValues : Boolean , noImpl : Boolean ) {
293
330
if (withTypeParams) {
294
331
printTypeParams(withSpaceAfter = false )
295
332
}
296
333
297
334
out .print (" (" )
298
335
params.forEachIndexed { index, funParam ->
299
336
if (index > 0 ) out .print (" , " )
300
- funParam.printToOut(printDefaultValues)
337
+ funParam.printToOut(printDefaultValues, noImpl )
301
338
}
302
339
out .print (" )" )
303
340
0 commit comments