I have:
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 readFileCalled and override readFile method to update this variable
var 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 readFile is called on afterParse
-
Run npm run test:transformer
Expected result: readFileCalled is true
Actual result: readFileCalled is false
AssemblyScript version
v0.28.17
I have:
I have a sample code fix on
readFilein 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
super.readFile(filename, baseDir) can fail or be skipped.
Expected behavior
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 variableAssert
readFileis called onafterParseRun
npm run test:transformerExpected result:
readFileCalledis trueActual result:
readFileCalledis falseAssemblyScript version
v0.28.17