https://kotlinlang.org logo
#javascript
Title
# javascript
e

Edoardo Luppi

09/26/2023, 10:29 AM
My outputted JS files are full of comments like:
Copy code
protoOf(BufferInputStream).readBytes = function (byteCount) {
  require_0(this, byteCount);
  // Inline function 'my.package.ext.toPlatformArray' call
  // Inline function 'my.package.ext.toUint8Array' call
  // Inline function 'my.package.ext.asInt8Array' call
  // Inline function 'kotlin.js.unsafeCast' call
  // Inline function 'kotlin.js.asDynamic' call
  var i8a = readByteArray(this.ft_1, byteCount);
  return new Uint8Array(i8a.buffer, i8a.byteOffset, i8a.length);
};
Can I get rid of them when targeting Node? Maybe without fiddling with Webpack
a

Artem Kobzar

09/28/2023, 10:30 AM
We can make the option, but in this case, the source map will work badly with the inline functions, and the debugging experience will be also not so good as well.
e

Edoardo Luppi

09/28/2023, 10:36 AM
@Artem Kobzar currently I'm building in two ways: production and development. In development build I let Kotlin create source maps and all of the other nice stuff for debugging, but in production builds I turn everything off. An option like that is something I'd use in the prod builds only. But it's up to you, if you think it makes sense. My only gripe is that I use inline functions A LOT
Those comments also come from kotlin-wrappers, which uses inline a lot too
a

Artem Kobzar

09/28/2023, 1:12 PM
I think I could add the logic, in case of the source-maps flag is turned off to not add such comments. Does it work for you?
e

Edoardo Luppi

09/28/2023, 1:15 PM
Basically no configuration will be required, correct? I'm not sure if there are people using those comments in strange ways, maybe worth adding a setting to maintain the old behavior. This is what I do now btw. Note the
isRelease
Copy code
// See <https://youtrack.jetbrains.com/issue/KT-61318>
binaries.withType<JsIrBinary>().configureEach {
  linkTask.configure {
    kotlinOptions {
      if (isRelease) {
        sourceMap = false
      } else {
        sourceMap = true
        sourceMapEmbedSources = "always"
      }
    }
  }
}
a

Ayfri

09/29/2023, 10:07 PM
How can you determine the
isRelease
value ?
e

Edoardo Luppi

09/30/2023, 11:18 AM
@Ayfri ah it's just a Gradle property I pass in at build time. Not something that Kotlin provides.
👍 1
2 Views