HaxeFoundation / HaxeFoundation/haxe

`Context.registerModuleDependency`/`getBuildFields` behavior change

Open
#12,846 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

```haxe
import sys.io.File;
import haxe.macro.Context;
import haxe.macro.Expr;

class Macro {
macro static public function build(): Array {
final fields = Context.getBuildFields();
if (fields.length > 0) return fields;
trace("invalidate", fields.map(struct -> struct.name));

final resPath = "./files.txt";
final content = File.getContent(resPath);
final lines = content.split("\n");
Context.registerModuleDependency(Context.getLocalModule(), resPath);
for (name in lines) {
if (name.length == 0) continue;
fields.push({
name: name,
access: [APublic, AStatic],
kind: FVar(macro :Int),
pos: Context.currentPos()
});
}
return fields;
}
}
```

In vscode, after i change `files.txt` on latest stable release, `invalidate` triggers once after i focus on `Main` file where i use generated Module with this build macro.
On development, `invalidate` triggers on every `Main` save/focus now, because `getBuildFields` stops returning already builded fields after prev build.

Project: [regdep.zip](https://github.com/user-attachments/files/26112007/regdep.zip)

And let me know if my macro is bad and i should use `@:persistent` there for simple file cache or something else.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.