Repository navigation
fix(parser): resolve grammar wasm when dependencies are hoisted (npm / npx) - #165
Closed
Johnson1662 wants to merge 2 commits into
Closed
Johnson1662 wants to merge 2 commits into
Johnson1662 wants to merge 2 commits into
Conversation
tree-sitter-wasms was resolved through a hard-coded path relative to this package (`node_modules/tree-sitter-wasms/out/*.wasm`), which only exists with pnpm-style nested installs. Under npm and npx the dependency is hoisted next to the package, so every language failed with ENOENT and silently fell back to the regex parser: [WARN] Tree-sitter init failed for javascript, falling back to regex parser: ENOENT ... eff-u-code/node_modules/tree-sitter-wasms/out/tree-sitter-javascript.wasm The regex parser loses nesting, so a function nested inside another scope had its end pinned to the end of that scope. In one repository a 20-line function was reported as 250 lines with complexity 40, and the overall score moved 83.9 -> 92.0 once real ASTs were used. Resolve through the module resolver first and keep the nested path as a fallback for pnpm.
Johnson1662
added a commit
to Johnson1662/dsh-inbox
that referenced
this pull request
Nov 15, 2026
根因不是它的函数边界算法,而是 wasm 路径写死成包内 node_modules(pnpm 布局); npm/npx 会提升依赖,所有语法解析 ENOENT,静默退化成正则,嵌套函数把外层代码吞进自己长度。 - 上游修复已提 PR:Done-0/fuck-u-code#165 - npm run rot 暂指向自己的 fork 分支 - AGENTS/CONTRIBUTING 换成准确描述,并给出判断依据(-v 看有没有 falling back 警告) - 同一仓库分数:正则 83.9 → 真 AST 92.0
The silent fallback hid a broken wasm path for months: every score looked plausible while the parser could not see scopes at all. Track the languages that fell back and print a one-line summary at the end of a run, plus an actionable warning at the point of failure.
Author
|
Closing this — the project has had no commits since 2026-09-07, so I've been carrying both fixes in a fork instead (Johnson1662/fuck-u-code, tag v2.2.2-fork.1): the wasm resolution fix in this PR, plus a follow-up so a grammar that fails to load no longer degrades to the regex parser silently. If development picks up again, both commits apply cleanly — feel free to reopen or cherry-pick. Thanks for the tool; it found real problems in my code once the parser was actually loading. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
resolveWasmPath()hard-codes<pkg>/node_modules/tree-sitter-wasms/out/*.wasm. That layout only exists with pnpm-style nested installs. Under npm and npx the dependency is hoisted next to the package, so every grammar failed to load and the tool silently fell back to the regex parser:This is what
npx eff-u-code/ a global npm install hits — i.e. most users.Why it matters
The regex fallback loses scope structure, so a function nested inside another function gets its end pinned to the end of the enclosing scope. Everything after it is attributed to it. On one 403-line file:
record()readLines()Overall score for that repository: 83.9 → 92.0 once real ASTs were used, and most of the top-10 'worst' list disappeared.
Fix
Ask the module resolver first, keep the nested path as a fallback for pnpm:
Verification
npm run buildcleannpm test: 205 passed (14 files)npm run lintandnpm run format:checkclean[WARN] ... falling back to regex parser, and the nested function above now reports 20 linesOptional follow-up
If the wasm still cannot be loaded, the regex fallback is silent apart from a
[WARN]. Failing loudly (or surfacing it in the report) would have made this bug obvious sooner — happy to do that in a separate PR if you want it.