You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ts.transform output may have inconsistent node.parent pointers, observed around usingTransformer #1685
While working on a regression test for usingTransformer (PR #1613), I noticed a broader/related situation around TypeScript AST node.parent pointer consistency after ts.transform.
In short: when building a tree via ts.forEachChild(...), some nodes appear as children of a parent in the transformed tree, but their .parent pointers can still reference a different node instance (or be missing), making .parent chains unreliable for whole-tree invariants.
This issue is not about runtime Lua output; it’s about the shape/invariants of the transformed TS AST and what invariants TSTL expects/relies on.
Repro (copy/paste test)
This is an exact test which can place into test/unit/using.spec.ts. It:
Creates a virtual program.
Runs the usingTransformer pre-transformer.
Assigns numeric IDs to nodes using ts.forEachChild (structural edges).
Records each node’s .parent:
outside:<Kind> means node.parent is set but is not present in the visited node set (likely a different object instance than the structural parent).
- means node.parent is missing.
Prints the full subtree starting at the function body block, plus a “parent mismatch” section asserting structural edge consistency (child.parent === parent), but only within the function-body block subtree.
Many nodes inside the function-body block subtree have missing or outside parents (- / outside:*), and the mismatch report shows structural edges not matching .parent pointers.
Is it expected (given TypeScript transformer behavior) that ts.transform(...) output may have .parent pointers that:
are missing (-), or
point to nodes not reachable from the returned root via ts.forEachChild (our outside:*)?
What invariants does TSTL want to maintain?
Only for synthetic nodes introduced by TSTL transformers (e.g. usingTransformer), or
For larger subtrees / whole-file AST?
If .parent is not intended to be reliable post-transform, would it be helpful to document that in contribution/testing guidance (to avoid writing brittle tests that assume whole-tree .parent consistency)?
changed the title [-]ts.transform output may have inconsistent node.parent pointers (structure vs parent chain), observed around usingTransformer[/-][+]ts.transform output may have inconsistent node.parent pointers, observed around usingTransformer[/+]on Feb 27, 2026
Activity
[-]ts.transform output may have inconsistent node.parent pointers (structure vs parent chain), observed around usingTransformer[/-][+]ts.transform output may have inconsistent node.parent pointers, observed around usingTransformer[/+]test: assert usingTransformer AST parent consistency (TypeScriptToLua…