I have something like `const val FOOBAR: String = ...
# javascript
f
I have something like
const val FOOBAR: String = "xxx/xxx"
and in various parts of the codebase:
someVar = js("require('$FOOBAR/foo/bar.html')") // for processing by webpack-html-loader
after upgrading from Kotlin 1.7 to 1.8.0 and enabling the new IR backend, the JS output would sometime become:
<GENERATED>.someVar = require('xxx/xxx/foo/bar.html') // OK, this is the expected output
but sometimes* it generates the following wrong output
<GENERATED>.someVar = require('/foo/bar.html') // WRONG! seems like the compiler does see the value of $FOOBAR
I have been trying to produce a short self-contained correct example (it's part of a bigger private project), but so far no luck in reproducing the issue is there a way for me to debug the compiler to see what happens? _sometimes*_: the affected Kotlin statements are consistent between compilations, but not all statements having that shape are affected
also, that issue appeared after I added missing "external" keywords required by the IR backend strangely, without the missing external definitions, the generated .js is OK and the generated strings are complete (but fails at runtime because it uses generated symbol names)
t
Looks like you don’t need
js
call at all. 😞 You can write custom external
require
to avoid such problems
f
I need the Kotlin compiler to output string literals, in order for them to be processed by webpack (i. e. before runtime) If I put a regular function call, I would have to inline the FOOBAR constant everywhere