Bindings & TypeScript Transformers #27
-
Hi everyone! First of all I would like to thank @nonara for having this discussion panel and for immediately answering my question at #25 (comment). This discussion should be a follow up for the mentioned topic as I unfortunately need some more clarifications. 1) Transformer Output with target CommonJsLet's assume having the following source file: source.ts
Let's assume the following transformation using the following setup: tsconfig.json (Partial)
transformer.ts (Partial)
Running the transformation results in: Result
The result is as expected. Although with a modified source the result is not as I would expect it to be. source.ts
Result
Now the added import is not in the expected CommonJs style. Does anybody know why this is the case? It seems as there is no import statement in the original source something goes wrong... 2) How to use the after transformer by exampleExample
source.ts
transformer (Partial)
Running the transformer in before mode results in:
In the result we see the expected CommonJs binding problem. Using the transformer in after mode results in:
Now the import and usage of the decorator do not apply the CommonJs style. How to write the provided transformer correctly using the configuration 3) Program TransformerHow would the provided example in 2) look like with a program transformer (https://www.npmjs.com/package/ts-patch#transforming-program)? The shown example (https://www.npmjs.com/package/ts-patch#example-program-transformer) does not work for me.
Furthermore Lastly I do not understand how I would run a transformation with this approach. Therefore, as I said, I would really appreciate a code snippet showing how to solve the example described in 2). If someone has the time to help me with this I would really really appreciate it, as I am currently a little bit stuck with this. Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Config should be Also, ensure your |
Beta Was this translation helpful? Give feedback.
Config should be
transformProgram: true
.Also, ensure your
transformer.ts
code exports a default function (see docs for example entry point), which returns aProgram
instance