Skip to content

feat(javascript): inventory Expo Router require.context route keys - #10624

Merged
N0zoM1z0 merged 5 commits into
morluto:mainfrom
Davmunrey:claude/expo-router-routes
Nov 22, 2026
Merged

N0zoM1z0 merged 5 commits into
morluto:mainfrom
Davmunrey:claude/expo-router-routes

Conversation

@Davmunrey

Copy link
Copy Markdown
Contributor

Summary

Refs #7510. This covers only the separate route gap, not the timeout. Expo Router (Metro) web exports register file routes in a bundled require.context map, Object.defineProperties({}, {"./(app)/[id]/edit.tsx": …}). The route scan ignored that map, so javascript-routes came back empty.

Change and scope

  • JavaScriptRouteScan recognises Metro's context template.
  • classifyExpoRouterContextKey applies Expo Router conventions:
    • (group) segments are dropped;
    • [id] becomes :id;
    • [...rest] becomes :rest+;
    • index, platform extensions and +api follow Expo's rules;
    • _layout and other + files produce no route.
  • A map is read only if all its keys are ./*.[jt]sx? and it has a _layout or + file. Otherwise it records a single unknown.
  • Candidates are low/inferred and their classification is unknown. The mechanism enum gains one value, expo-router-context-key, which is an additive output change.

Evidence and regression coverage

  • Scan and inventory tests: 3 failed on the base, 354 passed after the change. The CLI acceptance case passed 13.
  • Four non-route defineProperties controls stay negative.
  • Gaps: there is no real expo export run. The conventions were checked against the metro 0.88.0 and expo-router 58.0.31 sources.

Reviewer notes

  • The Object.defineProperties branch returns early even for maps it does not accept.

Validation performed

  • npm run test:local on the route test files: 378 passed.
  • npm run test:focused -- tests/acceptance/javascriptRoutesCli.test.ts: 13 passed.
  • npm run docs:check and npm run check:fast passed.

Author readiness

Human owner: @Davmunrey

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

Problem: Expo Router (Metro) web exports register file routes through a
bundled require.context map whose keys are literal route filenames such as
"./(app)/<section>/[id]/edit.tsx", "./_layout.tsx" and "./+not-found.tsx".
The route scan did not recognise that map, so the javascript-routes view of
analyze_javascript_application returned an empty inventory for these apps.

Fix: the route scan owner recognises Metro's context template,
Object.defineProperties({}, {"./file.tsx": getter, ...}). When every key is a
./-relative .js/.jsx/.ts/.tsx file and the map holds at least one _layout or
"+" file, each other key becomes a candidate with the new
expo-router-context-key mechanism, located at the key literal, with low
confidence and inferred derivation. The route-path owner converts keys with
Expo Router file conventions: groups (including group arrays) contribute no
segment, [id] -> :id, [...rest] -> :rest+, a trailing index names its
directory, platform extensions select the same route, and +api files keep
their API path. Layouts and other "+" files are not URL patterns.
Classification stays unknown; a bundled key does not establish platform,
navigator, server or reachability. A file map without a layout or "+" file
retains an interpretation unknown instead of becoming routes. Other
defineProperties calls are not read. The route inventory guide documents this.

Validation: new scan, inventory and CLI acceptance cases with a synthetic
Metro-style module. On the base, the scan and inventory cases failed with
empty candidates and routes; they pass now. Ran test:local for the route
scan, inventory, view, delivery-contract, result-budget and advertised
schema tests (378 passed), test:focused for
tests/acceptance/javascriptRoutesCli.test.ts (13 passed), docs:check and
check:fast. The conventions were checked against the published metro 0.88.0
context template and expo-router 58.0.31 matchers, not a real Expo export.

Refs morluto#7510
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-14T19:15:43.517100Z
We couldn’t complete this review. Comment @codex review to try again.
3204bfd PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · No blocking failure was found; two narrow cases can add false route candidates.RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] No blocking failure was found; two narrow cases can add false route candidates.

Findings

  1. P2 Data files become routes ▶
  2. P2 Local helpers become Expo contexts ▶
Fix with agent prompt
### Issue 1
src/domain/javascript/javascriptRouteScan.ts:908-915
`#expoRouterContextSteps` checks filenames but never checks their property descriptors. `Object.defineProperties({}, {'./_layout.tsx': {value: 0}, './ordinary.tsx': {value: 1}})` therefore adds `/ordinary` as an Expo route, even though it contains no Metro getters. These false candidates can also admit unrelated path constants with the same root.

Require getter descriptors before accepting the map, and add an ordinary data-property map as a negative control.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

### Issue 2
src/domain/javascript/javascriptRouteScan.ts:661-668
The new branch identifies `Object.defineProperties` by spelling alone. A function parameter, import, or local variable named `Object` passes the same check. Its file-shaped arguments then become Expo routes even when that helper returns no such files, adding false routes to the inventory.

Use the existing `globalReferenceNamespace` check with `this.index.bindings` before queuing the map, and add a shadowed-`Object` control.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Adds Expo Router filename candidates from Metro-style require.context maps.

  • Expo Router file keys in Metro bundles become route candidates.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["Object.defineProperties call"] --> B{"Empty target and literal map?"}
  B -- No --> X["Skip Expo detector"]
  B -- Yes --> C{"Every key is a route-shaped filename?"}
  C -- No --> X
  C -- Yes --> D{"Layout or special file present?"}
  D -- No --> U["Record interpretation unknown"]
  D -- Yes --> E["Convert and admit one route key at a time"]
  E --> F["Shared inventory retains source and key location"]
  F --> G["CLI and MCP route views"]
Loading

Reviews (6) · Last reviewed commit: "Merge origin/main into claude/expo-route..." · Reviewed by Greptile

Comment thread docs/javascript-route-inventory.md Resolved
Review follow-up for Expo Router route keys.

The context-map reader converted every key and kept each derived path
in a local array before emission. Only a location per property was
charged, so a map with many long filenames retained route text beyond
the fact budget, including text later discarded at capacity. The reader
now establishes applicability in a first pass without keeping derived
paths. A second pass converts and admits one key at a time through the
budgeted fact owner. Emitted facts and their order are unchanged.

The route inventory guide said Expo keys stay classified unknown, but
the existing path-name heuristic still applies: ./login.tsx becomes
/login, classified system by path-name-heuristic. The guide now says a
bundled key adds no classification of its own.

Tests: a budgeted case with 80 long keys admits a key-ordered prefix and
stays within the limit. The route scan and inventory tests (355) and the
routes CLI acceptance tests (13) pass. check:fast and docs:check pass.

@Davmunrey Davmunrey left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Status since opening:

  • Greptile findings fixed in 2930bb8:
    • route keys are admitted one at a time through the fact budget;
    • the guide now says the path-name heuristic still classifies Expo keys (./login.tsx becomes /login, system).
  • Validation: route scan and inventory tests (355), routes CLI acceptance (13), check:fast and docs:check.
  • architecture-guards, format:check and check:ci:fast also pass with the branch merged into current main.

@Davmunrey

Copy link
Copy Markdown
Contributor Author

Ready to merge: full CI is green on this head, Greptile's latest review is 5/5 with no open threads, and it merges into main 42cab26 without conflicts.

main consolidated the JavaScript route tests: the getter cases in the
scanner tests became one test, and the Next filename delimiter cases in
the inventory tests became two. Take those consolidated tests and keep
the Expo Router tests this branch adds after them.
The documentation guide asks each feature for a spec.md, plan.md and
tasks.md under docs/specs/. Add the record for reading Expo Router
require.context keys in the JavaScript route inventory, and index it.
@Davmunrey

Copy link
Copy Markdown
Contributor Author

Added in 3ae22e0: docs/specs/javascript/expo-router-context-routes/ with spec.md, plan.md and tasks.md, indexed in docs/specs/README.md. The record was written after the implementation, so it describes what this PR does and does not reconstruct an earlier plan. docs:check passes.

Main removed the tracked planning records under docs/specs (morluto#12856), so
this branch's Expo Router plan, spec and task files are dropped with it.

Co-Authored-By: gensokyo-dev <[email protected]>
@N0zoM1z0

Copy link
Copy Markdown
Collaborator

I merged current main into this branch (3ae22e074). Main removed the tracked planning records under docs/specs in #12856, so this PR's docs/specs/javascript/expo-router-context-routes/{plan,spec,tasks}.md and README entry are dropped. Per AGENTS.md, specs and plans live in issues or PR descriptions. On the merged result, 228 route-scan, inventory and CLI acceptance tests pass, and lint, typecheck and docs checks are clean.

@gensokyo-dev gensokyo-dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Verified on current main after merging it in: 228 route-scan, inventory and CLI acceptance tests pass, with lint, typecheck and docs checks clean. Classification follows Expo Router's matchers (groups, [id], [...rest], index, platform variants, +api; _layout and other + files produce no route), and a map counts as Expo routes only when every key is a route file and a convention file is present. The planning files under docs/specs were dropped, since main removed that directory. Fresh CI is green. Thanks.

@N0zoM1z0
N0zoM1z0 merged commit 7b6e816 into morluto:main Nov 22, 2026
39 checks passed
@morluto morluto added the enhancement New feature or request label Nov 22, 2026
@morluto morluto added the area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior label Nov 26, 2026
Comment on lines +908 to +915
if (
!this.#queue(property) ||
!t.isObjectProperty(property) ||
property.computed ||
!t.isStringLiteral(property.key)
)
return;
const file = classifyExpoRouterContextKey(property.key.value);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Data files become routes

#expoRouterContextSteps checks filenames but never checks their property descriptors. Object.defineProperties({}, {'./_layout.tsx': {value: 0}, './ordinary.tsx': {value: 1}}) therefore adds /ordinary as an Expo route, even though it contains no Metro getters. These false candidates can also admit unrelated path constants with the same root.

Require getter descriptors before accepting the map, and add an ordinary data-property map as a negative control.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/javascriptRouteScan.ts
Line: 908-915

Comment:
**Data files become routes**

`#expoRouterContextSteps` checks filenames but never checks their property descriptors. `Object.defineProperties({}, {'./_layout.tsx': {value: 0}, './ordinary.tsx': {value: 1}})` therefore adds `/ordinary` as an Expo route, even though it contains no Metro getters. These false candidates can also admit unrelated path constants with the same root.

Require getter descriptors before accepting the map, and add an ordinary data-property map as a negative control.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +661 to +668
if (fullName === "Object.defineProperties") {
// Metro compiles each `require.context` into getters on a fresh object.
const [target, map] = node.arguments;
if (
node.arguments.length === 2 &&
t.isObjectExpression(target) &&
target.properties.length === 0 &&
t.isObjectExpression(map) &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Local helpers become Expo contexts

The new branch identifies Object.defineProperties by spelling alone. A function parameter, import, or local variable named Object passes the same check. Its file-shaped arguments then become Expo routes even when that helper returns no such files, adding false routes to the inventory.

Use the existing globalReferenceNamespace check with this.index.bindings before queuing the map, and add a shadowed-Object control.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/javascriptRouteScan.ts
Line: 661-668

Comment:
**Local helpers become Expo contexts**

The new branch identifies `Object.defineProperties` by spelling alone. A function parameter, import, or local variable named `Object` passes the same check. Its file-shaped arguments then become Expo routes even when that helper returns no such files, adding false routes to the inventory.

Use the existing `globalReferenceNamespace` check with `this.index.bindings` before queuing the map, and add a shadowed-`Object` control.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants