Files (1063)
docs/proposals/vue-recovery-resolve-imported-composables.md
GitHubProposal: Resolver-back imported composable ASTs (retire the last hand-rolled shadow stack)
Status: DEFERRED — not started. Independent of the Phase 4 AST-IR proposal
(vue-recovery-ast-ir.md); no ordering constraint either
way. This closes the one remaining gap in the resolver-backed Vue recovery
redesign (issue #196): identifier matching is SyntaxContext-gated everywhere
except on imported composable module sources.
Problem
After Phases 0–3 / 2a / 2b, every recovery collector keys on (name, ctxt) and
the hand-rolled ScopeStack is gone — except the collectors that run on
imported composable sources. composable_ref_props_from_source
(crates/core/src/vue_recovery/imports.rs) parses imported module text with
parse_module and does not run SWC's resolver() (neither the direct parse
nor the unpack_bundle fallback path). Those ASTs therefore carry empty
SyntaxContexts.
Consequences:
StrongValueMemberCollectorkeeps its own hand-rolled shadow stack (shadowed: Vec<HashSet<Atom>>) — the last hand-rolled scope tracking in recovery — andRefLocalCollector/collect_object_pat_ref_bindings/collect_pat_ref_bindingsmatch by name.- Latent correctness gap: on empty-context ASTs, identity is name + a coarse
shadow stack rather than resolver's precise per-scope contexts. The stack
handles the common cases, but it is weaker than the
(name, ctxt)identity used on the (resolver-processed) local composable and render paths.
Proposed change
- Run
resolver()on imported composable ASTs at parse time incomposable_ref_props_from_source— both the directparse_moduleand theunpack_bundlemodule path — inside aGLOBALS.set, mirroring the recovery entry points invue_recovery.rs. Real per-scope contexts; behavior-preserving for the existing name-based analyses that also run on this AST. - Convert
StrongValueMemberCollectorto(name, ctxt): dropshadowed+is_shadowed/enter_shadowed/exit_shadowed+ thevisit_block_stmt/visit_function/visit_arrow_exprscope overrides;value_member_objectreturns(Atom, SyntaxContext); collect(base.sym, base.ctxt)unconditionally — shadowing falls out of context identity, exactly like the render-side member collectors converted in Phase 2a. - Thread
(name, ctxt)through the consumers:function_strong_value_member_bindingsreturn type,RefLocalCollector.strong_value_member_refs, thevisit_var_declaratormatch (binding.id.sym,binding.id.ctxt), andcollect_object_pat_ref_bindings/collect_pat_ref_bindings. - Remove the now-dead helpers:
block_shadowed_bindings,collect_decl_bound_atoms,pat_bound_atoms,collect_pat_bound_atoms.
Prior attempt (reverted — read before retrying)
Steps 2–4 were prototyped in the Phase 2b session without step 1 and reverted.
Without resolver() on the imported AST, (name, ctxt) degenerates to
name-matching (every ident has the empty context), so a
subscribe((itemList) => { itemList.value.push(...) }) callback param was
conflated with a top-level itemList, wrongly classifying it as a ref. This is
caught by the regression test
preserves_imported_composable_shadowed_callback_value_members
(vue_recovery/tests.rs). The collector conversion (steps 2–4) is correct once
step 1 lands; reconstruct that diff from git history if useful. Do step 1
first.
Size / risk
Small–medium, self-contained. The collector conversion is mechanical (mirrors
Phase 2a). The resolver-wrapping is a few lines but touches the shared imported
composable parse path: every imported-composable analysis
(composable_ref_props_from_module, local_injected_composable_ref_props,
ref-returning-function detection, …) runs on that AST. They match by name, so
adding contexts should be behavior-preserving — the full core suite (many
composable-ref tests) is the guard.
ROI / when to do it
Low priority. It retires the last hand-rolled shadow tracking and makes imported
composable analysis ctxt-safe (a latent correctness improvement), but it is
cleanup on an experimental feature and the shadow stack works today. Worth doing
if a shadow bug surfaces in imported composable ref detection, or as part of a
"fully ctxt-safe recovery" / promote---vue-sfc-out-of-experimental push.
References
- Binding-identity pattern:
crates/core/src/rules/rename_utils.rs(BindingRenamer) and the Phase 2a render-side member collectors incrates/core/src/vue_recovery/context.rs. - The separate, unrelated cleanup: Phase 4 — vue-recovery-ast-ir.md.
- Redesign history: issue #196 and the
#196commit history (git log --grep '#196').