Adjust output js


(Remco Huijser) #1

I want to change to make some small changes to the JS file outputted by the compilation process. What is the best way of doing this?

What I tried so far is overwriting the JS generator, but this seems like too much effort for what I want to achieve. The other approach that worked quite well is to open the output js file after it has been generated, make the changes and save it again. This does feel like dirty and involves IO operations. I was wondering whether there is a better approach…

As always thanks a lot for the input!

(Andy Li) #2

It all depends on what changes you wanna make. So what do you want to change?

(Remco Huijser) #3

That is a very valid question, sorry for using such a short problem description.

There are two cases I want to deal with:

  1. We obfuscate our code by adding @:native values to classes and functions. This means that fields and properties get renamed. In our templating system we sometimes need to use reflection (reference a field with a string). I was experimenting with the following: instead of using the field name “FieldName” directly I wrap this in a function like GetFieldName(Something). This gets compiled to GetFieldName(x) because of obfuscation. I can then search this with a regex and replace it with “x”.

  2. It is a bit much to explain (sorry) but we generate some code after typing has been done, because we need the rich information provided by the typed AST. This code is then inserted at the right location in the output js file. So again a simple search replace here.

Thanks for your attention so far!