typescript-transformer-handbook icon indicating copy to clipboard operation
typescript-transformer-handbook copied to clipboard

General question with focus on bindings

Open LukasMachetanz opened this issue 3 years ago • 2 comments

Hey!

I have a really general question which I need to ask providing an example.

Let's assume we add some kind of function with the typescript transformer. - function whatever() {} And then I would like to use this function somewhere else, like whatever().

Should this work or would I have to consider something regarding bindings?

E.g. what's the point of adding import statements if the stuff imported can't be used. Or am I missing something here?

Thanks in advance.

LukasMachetanz avatar Jan 22 '21 21:01 LukasMachetanz

heya

i've had use cases where i import functions and then use those functions after the transformation, so imagine importing extra functions that consumers don't actually use - the transformer just utilizes them so they're used in the final transformed code

honestly it works ok but there are a bunch of edge cases where this doesn't work well in TS transformers. with Babel they work as expected.

if you're compiling down to commonjs your bindings will be renamed but your callsites where you use the function wont be, so be careful for that. you'll need to do the renaming manually.

when targetting esmodules it should just work because no renaming is done.

itsdouges avatar Jan 24 '21 01:01 itsdouges

Thanks for the answer. I explained my problem(s) a little bit more detailed here: https://github.com/nonara/ts-patch/discussions/27#discussion-2019093. It also includes a practical example I would like to solve. If you could help me to succeed I would really really appreciate it. Currently I am a little bit stuck how to proceed.

LukasMachetanz avatar Jan 25 '21 15:01 LukasMachetanz