Skip to content

fix: convert JS template expressions to glob wildcards in pattern mat…#3

Merged
runkids merged 1 commit into
runkids:mainfrom
hiro05097952:fix/resolve-path
Jun 10, 2026
Merged

fix: convert JS template expressions to glob wildcards in pattern mat…#3
runkids merged 1 commit into
runkids:mainfrom
hiro05097952:fix/resolve-path

Conversation

@hiro05097952

Copy link
Copy Markdown
Contributor

Summary

  • resolvePattern preserved ${...} template literal syntax verbatim, but Go's path.Match doesn't recognize JS template expressions — causing dynamic references like new URL(`./images/${code}.webp`, import.meta.url) to never match sibling assets
  • Added templateExprRe to replace ${...} with * glob wildcards before matching, so ./images/${code}.webp becomes ./images/*.webp
  • Added test covering template literal pattern resolution with multiple assets

Problem

Files referenced via JS template literals were incorrectly reported as unused:

function getIcon(name: string) {
  return new URL(`./icons/${name}.webp`, import.meta.url).href
}

Extract() correctly identified this as a pattern kind, but resolvePattern() passed ${category} through to globMatchRepoPath(), where path.Match("${category}.webp", "apple.webp") returned false.

Test plan

  • go test ./internal/references/ -run TestBuildMapResolvesTemplateLiteralPattern -v — PASS
  • go test ./internal/references/ -v — all existing tests still pass

…ching

`resolvePattern` preserved `${...}` template syntax verbatim, but Go's
`path.Match` doesn't recognize it — so `new URL(`./images/${code}.webp`)`
never matched sibling assets like `blockchain.webp`. Replace `${...}` with
`*` before glob matching.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for resolving template literal patterns (e.g., ${code}) in asset references by replacing them with a wildcard * before resolving aliases. A new regular expression templateExprRe is added to match these expressions, and a corresponding unit test is introduced to verify the resolution of template literal patterns. There are no review comments, and I have no additional feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@runkids runkids merged commit caf6c98 into runkids:main Jun 10, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants