Repository navigation
fix: report nested JavaScript function declarations once - #196
DaisukeYoda merged 2 commits into
Conversation
Nested function declarations were either dropped or emitted twice as name_<line>, which skewed complexity totals. Fixes ludo-technologies#135
DaisukeYoda
left a comment
There was a problem hiding this comment.
Thanks for picking up #135. markFunctionLocations fixes the duplicate on its own, but returning false from the BuildAll walk causes a regression.
Callbacks inside function bodies are dropped
The walk no longer enters function bodies, so function expressions inside them are never found:
function top(items) {
return items.map((x) => { if (x) { return 1; } return 0; });
}main reports anonymous_2, but this branch does not. Returning true in both places fixes it. With that change, #135 stays fixed and go test ./internal/js/... passes. Please also add a callback case to the new test.
Minor (optional)
When two functions each contain a nested function h(), absorbNestedFunctionCFGs drops the second h. This is not a regression, so a follow-up PR is fine.
Returning false from the BuildAll walk skipped callbacks and other function expressions nested inside already-discovered functions. Always return true so the walk continues (markFunctionLocations still prevents duplicates) and add a callback case to the nested-declaration test. Fixes the regression noted in the review of ludo-technologies#196.
|
Thanks for the review @DaisukeYoda. Addressed the regression: the Also added the callback case from your example to Verified with The optional |
Summary
name_<line>.Motivation
Fixes #135. Complexity analysis dropped
inNamed-style declarations and duplicatedinArrow/inMethod/inExported, which also inflatedsummary.total_functions.Implementation
processStatementnow keeps CFGs built for declarations inside the function it just analyzed. Those nodes are already on the child CFG, soBuildAllwill not rebuild them.BuildAllsees a function span it already recorded, it stops the walk instead of descending. The AST walk visits the same statement from bothChildrenandBody, and the previousreturn truewalked into the body and minted thename_<line>duplicate.Testing
cd polyscan && go test ./internal/js/analyzer/ -count=1— passcd polyscan && go vet ./internal/js/analyzer/— passTestCFGBuilder_BuildAll_NestedFunctionDeclarationsfor the arrow, method, function-declaration, and exported-function cases from [BUG][auto] js/js-nested-function-declaration-dropped-or-duplicated: nested function declarations are reported twice (name, name_<line>) or not at all #135.The ASCII-only name suffix path is unchanged for genuinely distinct functions that share a name.