Repository navigation
Transform readFile/writeFile methods are not called #3022
Description
I have:
- Searched in the repository for existing result
- Developed a POC to fix this issue at ye-yu/assemblyscript@23cdb69
I have a sample code fix on readFile in my fork that I would like to contribute to this repository as a fix to this issue. I would like to obtain suggestions and discussions on how to fix this issue before submitting a PR.
Bug description
Custom compiler transformers extending Transform do not reliably receive readFile / writeFile calls during compilation. This prevents transformer implementations from intercepting file I/O and breaks transform-based file resolution.
Actual behavior
- Transform.prototype.readFile / writeFile are not properly wired for derived transformer classes.
super.readFile(filename, baseDir) can fail or be skipped. - When multiple transformers are configured, the first transformer that returns a result should short-circuit, but current handling does not consistently enforce that.
Expected behavior
- A transformer subclass should be able to override readFile and writeFile and have those methods called during compilation.
- Calling super.readFile(...) inside an override should delegate to the next transform or the default loader.
If multiple transformers are configured, the first non-null result should be used and remaining transformers should not override it.
My use case: another source to source on top of AS transpiler
I would like to develop a feature that will transform unsupported syntaxes to an intermediary source to work around some limitation. I'd figure that a transformer that was promised to me in this documentation Compiler - Transforms - readFile would work. However, it did not return the expected result :(
Steps to reproduce
-
In tests/transform/index.js, add a tracking variable
readFileCalledand overridereadFilemethod to update this variablevar constructorCalled = false; var afterParseCalled = false; var afterInitializeCalled = false; var afterCompileCalled = false; + var readFileCalled = false; console.log("Transform loaded"); export default class MyTransform extends Transform { // ... readFile(filename, baseDir) { + readFileCalled = true; return super.readFile(filename, baseDir); } // ...
-
Assert
readFileis called onafterParse -
Run
npm run test:transformer
Expected result: readFileCalled is true
Actual result: readFileCalled is false
AssemblyScript version
v0.28.17
Activity
ye-yu commentedon Apr 29, 2026
Case study from https://github.com/JairusSW/try-as
My use case to transpile generator function does not work as the parser will throw error before I could manipulate the source.