# Name mangling for Kotlin/JS

**URL:** <https://discuss.kotlinlang.org/t/name-mangling-for-kotlin-js/13412>\
**Category:** JavaScript\
**Created:** [July 8, 2019, 11:22am UTC](https://discuss.kotlinlang.org/t/name-mangling-for-kotlin-js/13412 "2019-07-08T11:22:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TorRanfelt](https://avatars.discourse-cdn.com/v4/letter/t/3bc359/32.png) [@TorRanfelt](https://discuss.kotlinlang.org/u/TorRanfelt)\
**Post date:** [July 8, 2019, 11:22am UTC](https://discuss.kotlinlang.org/t/name-mangling-for-kotlin-js/13412/1 "2019-07-08T11:22:56Z")

</div>

Is there a plugin or something else that makes it possible to mangle names of functions, classes and properties?

Webpack can do this with plugins like terser-webpack-plugin, but due to the dynamic nature of JavaScript, where every property can be referenced by a string, it doesn’t work for properties without some serious hoop jumping.

However, Kotlin is static so maybe there is a tool in the Kotlin ecosystem?

The reason I ask in the JavaScript section is that this question doesn’t really make sense in JVM land.

---

<div class="post-metadata">

**Author:** ![darksnake](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/darksnake/32/2479_2.png) [@darksnake](https://discuss.kotlinlang.org/u/darksnake)\
**Post date:** [July 9, 2019, 6:13am UTC](https://discuss.kotlinlang.org/t/name-mangling-for-kotlin-js/13412/2 "2019-07-09T06:13:25Z")

</div>

It depends on what do you mean by mangling. There are `@JVMName` and `@JSName` annotations which allow to change platform names. Also JS plugin automatically mangles some names. If you need some kind of obfuscation, the simplest thing to do is to run webpack obfuscation on bundle.

---

<div class="post-metadata">

**Author:** ![TorRanfelt](https://avatars.discourse-cdn.com/v4/letter/t/3bc359/32.png) [@TorRanfelt](https://discuss.kotlinlang.org/u/TorRanfelt)\
**Post date:** [July 9, 2019, 12:47pm UTC](https://discuss.kotlinlang.org/t/name-mangling-for-kotlin-js/13412/3 "2019-07-09T12:47:04Z")

</div>

The problem is that name mangling doesn’t work for names in “top level”/“global scope” due to the dynamic nature of Java Script. Surprisingly even when I have split my code apart from libraries.  
Hence I hoped Kotlin might have something.
