assemblyscript icon indicating copy to clipboard operation
assemblyscript copied to clipboard

Support more options for providing Transforms to compiler frontend API

Open A-Babin opened this issue 4 years ago • 2 comments

Hi there!

This PR adds support for providing custom Transforms directly to the compiler frontend. A new optional parameter is added to compileString and a new prop is added to APIOptions, accepting an array of Transform constructors or instances. To keep it simple, the implementation avoids affecting any existing arg/option parsing.

Configuration can be passed to the Transform, which can't be done trivially with dynamically imported modules.

class MyTransform extends Transform {
// ...
}

const output = compileString(source, opts, [MyTransform, new MyTransform()]);

// or

main(argv, {
  //...
  transforms: [MyTransform, new MyTransfrom()]
});
  • [x] I've read the contributing guidelines

A-Babin avatar Dec 11 '20 04:12 A-Babin

Makes me wonder whether we may just accept an instantiated Transform as a --transform argument, which the API can handle while irrelevant for the CLI, avoiding appending somewhat special arguments. For instance, the next similar feature would append an argument again and so on, which is probably good to avoid.

dcodeIO avatar Dec 11 '20 16:12 dcodeIO

I wanted to do that in the first place, but carving out special cases in the options parsing code, which assumes primitives that are then cast to strings, feels to me like more trouble than it's worth for only one option. Considering --transform is the only option dynamically importing modules, I'd argue a new parameter is substantiated.

To compromise, how about taking all Transforms via CompilerOptions of compileString, but then passing the instances and constructors to main via the APIOptions object, as I do now? No new function argument and optionUtils.parse stays as it is.

A-Babin avatar Dec 11 '20 17:12 A-Babin

This PR has been automatically marked as stale because it has not had recent activity. It will be closed in one week if no further activity occurs. Thank you for your contributions!

github-actions[bot] avatar Dec 06 '23 23:12 github-actions[bot]