fix(codegen): disambiguate tool names that sanitize to a JS/TS reserved word#137
Merged
Conversation
…ed word resolve_typescript_names now checks a sanitized tool name against the set of JS/TS reserved words (including eval/arguments, which strict mode forbids as a function-declaration BindingIdentifier) and disambiguates matches with the same numeric-suffix strategy already used for name collisions. Previously a tool named delete or typeof produced export async function delete(...), a hard syntax error that also broke the generated index.ts re-export. Closes #133
bug-ops
enabled auto-merge (squash)
July 9, 2026 15:46
bug-ops
force-pushed
the
133-reserved-keyword-tool-name
branch
from
July 9, 2026 15:46
140fb9e to
7716c22
Compare
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.
Summary
resolve_typescript_namesnow seeds the shared disambiguationusedset with the JS/TS reserved word list before resolving each tool's identifier, so a tool nameddelete,typeof,eval,arguments, etc. gets the same numeric-suffix disambiguation as a genuine name collision instead of being emitted verbatim as an invalid function identifier.sanitize_ts_identifieritself is left untouched, since it is also used to sanitize object property keys, where reserved words are syntactically legal.eval/arguments, which are not formally reserved words but are forbidden as a strict-modeBindingIdentifier(a function declaration's name); generated code is always an ES module, hence always strict mode.Test plan
test_resolve_typescript_names_disambiguates_reserved_words— unit coverage for delete, typeof, class, new, import, export, in, instanceof, void, enum, eval, argumentstest_resolve_typescript_names_reserved_word_avoids_existing_collision— reserved-word fallback doesn't collide with an unrelated tool that already claims the fallback identifiertest_generate_sanitizes_reserved_word_tool_name— generator-level regression test asserting the emitted.tsfile never containsexport async function delete(and does contain the disambiguated formcargo +nightly fmt --checkcargo +stable clippy --all-targets --all-features --workspace -- -D warningscargo nextest run --all-features --workspace --no-fail-fastcargo test --doc --all-features --workspaceCloses #133