Edoardo Luppi
12/28/2020, 2:34 PMimport
or require
(inside a function) a JSON file. How does this translate to KotlinJS?turansky
12/28/2020, 2:38 PMEdoardo Luppi
12/28/2020, 2:42 PMinterface
in TSturansky
12/28/2020, 2:47 PMrequire
@JsName("require")
external fun requireJson(path: String): String
@JsName("require")
external fun requireCss(path: String): Array<dynamic>
Edoardo Luppi
12/28/2020, 2:48 PMunsafeCast
option to convert the file content to a typed structure.turansky
12/28/2020, 2:50 PMexternal fun <T:Any> require(path: String): T
turansky
12/28/2020, 2:53 PMEdoardo Luppi
12/28/2020, 3:04 PMinterface Dictionary {
val words: Array<String>
}
require<Dictionary>("./dictionary.json")
the generated JS code is
var dictionary = require('./dictionary.json');
var tmp0_forEach_0 = dictionary._get_words___error();
Can't understand why honestlyturansky
12/28/2020, 3:05 PMturansky
12/28/2020, 3:06 PMrequire
return String
for json by defaultEdoardo Luppi
12/28/2020, 3:08 PMdictionary.words
While here a strange function call is generated insteadEdoardo Luppi
12/28/2020, 3:10 PMvar tmp0_forEach_0 = dictionary.words__error;
Almost...Edoardo Luppi
12/28/2020, 3:16 PMvar dictionary = require('./dictionary.json');
var $receiver = dictionary.words;
turansky
12/28/2020, 3:18 PMAtomicfu
doc
2. Report require
error in IR
🙂Edoardo Luppi
12/28/2020, 3:21 PMturansky
12/28/2020, 3:22 PM1.4.30-M1
?Edoardo Luppi
12/28/2020, 3:22 PMturansky
12/28/2020, 3:22 PMEdoardo Luppi
12/28/2020, 3:26 PMEdoardo Luppi
12/28/2020, 3:28 PMturansky
12/28/2020, 4:47 PMEdoardo Luppi
12/28/2020, 4:47 PMturansky
12/28/2020, 4:49 PMturansky
12/28/2020, 4:51 PMturansky
12/28/2020, 4:52 PMEdoardo Luppi
12/28/2020, 4:54 PMEdoardo Luppi
12/28/2020, 5:04 PMturansky
12/28/2020, 5:16 PMEdoardo Luppi
12/28/2020, 5:20 PMturansky
12/28/2020, 5:23 PMEdoardo Luppi
12/28/2020, 5:24 PMturansky
12/28/2020, 5:24 PMEdoardo Luppi
12/28/2020, 6:48 PMturansky
12/29/2020, 1:20 PMEdoardo Luppi
12/29/2020, 5:54 PMEdoardo Luppi
12/29/2020, 5:55 PMturansky
12/29/2020, 5:56 PMEdoardo Luppi
12/29/2020, 5:59 PMturansky
12/29/2020, 9:32 PMturansky
12/29/2020, 9:34 PMturansky
12/29/2020, 9:37 PM