Skip to content

Drop compiled-artifact functions from the functions metric - #30

Merged
NullVoxPopuli merged 1 commit into
NullVoxPopuli:mainfrom
NullVoxPopuli-ai-agent:fix-compiled-artifact-functions
Aug 7, 2026
Merged

NullVoxPopuli merged 1 commit into
NullVoxPopuli:mainfrom
NullVoxPopuli-ai-agent:fix-compiled-artifact-functions

Conversation

@NullVoxPopuli-ai-agent

Copy link
Copy Markdown
Contributor

Fixes #29

Root cause

Your source-mapping hunch was right. Reproduced in the scenario apps by dumping the istanbul fnMap: the compiled class output contains functions that don't exist in the original source — decorator <static_initializer> blocks, <instance_members_initializer>, implicit constructors, and gjs template scope thunks. Their source-mapped declaration positions land on class headers and field lines. That's why a fully-covered class reports 4/6 functions with the uncovered range painted on extends Component, and why router.js in the scenario apps reported 0% functions — its only "function" was an <instance_members_initializer> with count 0, when the source contains no functions at all.

=== app/components/counter.gjs (before)
  fn[0] "<static_initializer>"           decl L12 count=1   ← not in source
  fn[1] "<instance_members_initializer>" decl L13 count=2   ← not in source
  fn[2] "get label"                      decl L17 count=4
  ...

Fix

The original-source pass added for tree-shake detection (#27) now also prunes the functions map: a function entry whose declaration is not inside any real function span of the original source — function/arrow/method, a user-written static {} block, or a <template> tag — is a compiled artifact and is removed. The functions metric then counts only functions the user wrote. Statement, branch, and line data are untouched, and real uncovered functions (never-called methods, tree-shaken functions) still report as uncovered.

Results in the scenario: router.js and app.js go from 0%/50% to 100% functions; tracked-box.js (new fixture, the issue #29 shape: fully-exercised class with a decorated field and one getter) reports exactly 1/1 functions and 100% everywhere — previously it reported 3 functions with phantom entries.

All 24 tests across the three scenarios pass, lint clean. (One local run flaked with a 10s browser timeout in the v2-addon scenario under 3-parallel-Chrome load — unrelated to this change; the coverage pipeline succeeded even in that run.)

🤖 Generated with Claude Code

The build output contains functions that do not exist in the original
source: decorator static blocks, <instance_members_initializer>,
implicit constructors, and template scope thunks. Their source-mapped
positions land on class headers or field lines, so a fully-covered
class reported e.g. "4/6 functions" with an uncovered range highlighted
on `extends` (issue NullVoxPopuli#29), and a file whose only "function" was such an
artifact reported 0% functions (router.js).

The original-source pass introduced for tree-shake detection now also
prunes the functions map: every function entry whose declaration is not
inside a real function span of the original source — function / arrow /
method / user-written static block / <template> tag — is removed, so
the functions metric counts only functions the user actually wrote.
Statement, branch, and line data are untouched.

Adds app/utils/tracked-box.js to the vite-app-using-v2-addon-js
scenario as the issue NullVoxPopuli#29 shape: a fully-exercised class with a
decorated field and one getter, asserted to report exactly 1/1
functions and 100% everywhere.

Fixes NullVoxPopuli#29

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@NullVoxPopuli NullVoxPopuli added the bug Something isn't working label Aug 7, 2026
@NullVoxPopuli
NullVoxPopuli merged commit a276583 into NullVoxPopuli:main Aug 7, 2026
5 checks passed
@github-actions github-actions Bot mentioned this pull request Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Odd coverage data

2 participants