Assemblyscript: Custom transformers

Created on 30 Jan 2018  路  7Comments  路  Source: AssemblyScript/assemblyscript

Is AssemblyScript planning to support TypeScript-like custom transformers?

question

Most helpful comment

Regarding the commit above, there is now a way to provide transforms with the --transform option to asc. This basically loads a node module that then exports hooks the compiler will call on specific occasions. The only hook for now is afterParse which calls the transform with the parser instance that contains the parsed sources, prior to initializing the program from it. It's relatively easy to add more hooks, of course, but I didn't want to go overboard with that so let me know if there's something specific you'd need.

All 7 comments

If I understand this correctly, custom transformers do not look AOT-compatible. More like something that requires the language to be highly dynamic.

On a second thought, something similar might be possible if there was an API to plug in custom built-ins that have full access to the compiler's type information and transform such code at compile time.

Custom transformer is a function plugged into the compilation process. It takes the AST of the program and returns a new (or the same) AST. It has nothing to do with anything dynamic; other statically typed languages have this sort of plugin functionality as well.

I see, thanks. AssemblyScript has an AST representation as well, so transforming it prior to the final compilation step shouldn't be a big deal. There is also the Program that wraps the higher level IR created from the AST. That's where built-in functionality is combined with the processed source information, which is the last step before compilation is finally performed.

Not directly "planning", though, because there's still so much to do, but not impossible either.

Regarding the commit above, there is now a way to provide transforms with the --transform option to asc. This basically loads a node module that then exports hooks the compiler will call on specific occasions. The only hook for now is afterParse which calls the transform with the parser instance that contains the parsed sources, prior to initializing the program from it. It's relatively easy to add more hooks, of course, but I didn't want to go overboard with that so let me know if there's something specific you'd need.

Closing this for now as the infrastructure is in place. Just let me know if more hooks are necessary :)

Was this page helpful?
0 / 5 - 0 ratings