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
Commit a027214
Browse filesBrowse the repository at this point in the historyBrowse files
Traverse subnode arrays as a copy and assign the result back, like php-parser
The native NodeTraverser wrote replacement nodes straight into the
property's table (shared with its own guard reference, never separated),
and assigned the property only when splices were recorded. A visitor
holding the parent's array saw it change mid-traversal, and a visitor
reassigning the property kept its array where php-parser overwrites it
with the traversal result. It also separated every subnode array up
front, so each empty list - the shared [] - became a fresh heap table
retained in cached ASTs (25 KB over NodeScopeResolver.php's AST).
traverseArray() now holds its own reference to the array it iterates,
writes replacements by key into a copy made on the first write, and
returns the resulting array (the input's table when nothing changed);
traverseNode() assigns it to the property through the engine write path
unless the property already holds exactly that table.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Fdg8n3eEi4ZoXa4dA2k4A
public ?\PhpParser\Node\Stmt\Function_$function = null;
256
+
257
+
/** @var list<string> */
258
+
publicarray$log = [];
259
+
260
+
publicmixed$held = null;
261
+
262
+
publicfunction__construct(private$onEcho)
263
+
{
264
+
}
265
+
266
+
publicfunctionenterNode(\PhpParser\Node$node)
267
+
{
268
+
if ($nodeinstanceof \PhpParser\Node\Stmt\Function_) {
269
+
$this->function = $node;
270
+
$this->held = $node->stmts;
271
+
returnnull;
272
+
}
273
+
if ($nodeinstanceof \PhpParser\Node\Stmt\Echo_) {
274
+
return ($this->onEcho)($this, $node);
275
+
}
276
+
returnnull;
277
+
}
278
+
279
+
};
280
+
$ntCompare('replacements in a subnode array a visitor holds', staticfunction (string$side, string$traverserClass) use ($smokeParser, $ntMarks, $ntReplacingVisitor): array {
281
+
$visitor = $ntReplacingVisitor(staticfunction ($visitor, $node) use ($ntMarks) {
$ntCompare('a visitor reassigning the subnode array next to a replacement', staticfunction (string$side, string$traverserClass) use ($smokeParser, $ntMarks, $ntReplacingVisitor): array {
0 commit comments