Repository navigation
refactor(language-core): unwrap setup bindings by value - #6184
Conversation
Covers the read/narrowing/write split for the upcoming __VLS_unwrap refactor: function bindings in read position must not get .value, while ref bindings keep .value for v-if / ternary narrowing and v-model write.
Replace the assertion-based `.value` access with a value-returning __VLS_unwrap helper for read and call positions, so function bindings no longer get an invalid `.value` (TS2339). Narrowing/write positions (v-if, v-model write, ternary condition, property-access object, type guards like typeof/instanceof/in/equality) keep `.value`, now asserted by a simplified __VLS_withDotValue. This also drops the isCall analysis (call callee now goes through __VLS_unwrap, which is closer to Vue's template auto-unwrap) and the ref-of-function callable branch of withDotValue.
The __VLS_unwrap refactor lost narrowing when a ref read follows a narrowing position (v-if body, ternary branch, &&/||/??, type guard), because __VLS_unwrap is a function call that flow-narrowing can't cross. Track which bindings are narrowed in a nested scope in the codegen context: narrowing positions mark their bindings, the scope is entered/left around v-if bodies and ternary/logical right sides, and setup bindings access with .value while narrowed (reference) or __VLS_unwrap otherwise. Also carry the v-if condition bindings forward into v-else/v-else-if as negated narrowing, and narrow the && right operand (but not ||/?? right). A non-ref nullish union still can't keep .value (TS collapses undefined), so that stays a known limitation.
…lable
Use `NonNullable<T> extends Ref ? T : NonNullable<T> & { value: T }` so that
non-ref nullish unions (e.g. `(() => void) | undefined`) keep their nullish
branch instead of collapsing to `never` in the distributive `T extends Ref`
conditional.
There was a problem hiding this comment.
Pull request overview
Refactors template code generation to unwrap setup bindings by value while preserving references for narrowing and writes.
Changes:
- Adds
__VLS_unwrapand narrowing-scope tracking. - Updates interpolation, props, events, and
v-ifaccess generation. - Adds setup-binding unwrapping and narrowing tests.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
packages/language-core/types/template-helpers.d.ts |
Defines unwrap and assertion helpers. |
packages/language-core/lib/codegen/names.ts |
Registers the unwrap helper name. |
packages/language-core/lib/codegen/template/context.ts |
Tracks narrowed setup bindings. |
packages/language-core/lib/codegen/template/interpolation.ts |
Selects unwrap versus reference access. |
packages/language-core/lib/codegen/template/vIf.ts |
Propagates branch narrowing. |
packages/language-core/lib/codegen/template/elementProps.ts |
Unwraps shorthand prop bindings. |
packages/language-core/lib/codegen/template/elementEvents.ts |
Updates event and model generation. |
test-workspace/tsc/unwrapBindingAccess/main.vue |
Exercises reads, writes, and narrowing. |
test-workspace/tsc/unwrapBindingAccess/tsconfig.json |
Configures the new fixture. |
test-workspace/tsc/tsconfig.json |
Registers the fixture. |
Suppressed comments (1)
packages/language-core/lib/codegen/template/interpolation.ts:314
- Increment and decrement are writes, but this marks only
!as a reference position and the generic postfix path also treats its operand as a read. Thus handlers such as@click="count++"generate__VLS_unwrap(count)++, which is not an assignable target. Classify both prefix and postfix++/--operands as reference/write positions.
node.operator === ts.SyntaxKind.ExclamationToken,
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…p bindings Address three review findings on the unwrap-by-value access strategy: - Treat prefix/postfix ++/-- operands as reference positions so `@click="count++"` emits `count.value++` instead of `__VLS_unwrap(count)++` (which is not an assignable target). - Keep shorthand prop bindings narrowed under `v-if` by emitting `.value` when the binding is already narrowed, instead of always `__VLS_unwrap`. - Scope `forceDotValue` to the expression's top level (initial `inNarrowing`) instead of forcing `.value` on every identifier, so call callees like `v-if="handler()"` stay value reads (`__VLS_unwrap(handler)()`).
…perands - Rename generateInterpolation's `forceDotValue` to `inNarrowing` to match the value it forwards to forEachDeclarations. - Make forEachDeclarations' fallback conservative (false) and explicitly forward `inNarrowing` through the transparent SourceFile/ExpressionStatement wrappers instead of the broad else branch. - Treat the NewExpression constructor as a value read (false), mirroring the CallExpression callee, so `new Foo()` no longer emits `Foo.value`. - Parenthesize the `__VLS_unwrap` of a `new` operand so `new Foo()` parses as `new (__VLS_unwrap(Foo))()` rather than `new (__VLS_unwrap(Foo)())`.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 10 changed files in this pull request and generated 4 comments.
Suppressed comments (3)
packages/language-core/lib/codegen/template/interpolation.ts:255
- Propagating
inNarrowingto every call argument reintroduces the function-declaration failure. Inv-if="predicate(handler)",handleris a value read but is generated ashandler.value, which reports TS2339 because the assertion cannot narrow function declarations. Call arguments should remain value reads unless a specific guard form requires a stable reference.
yield* forEachDeclarations(ts, arg, ast, ctx, scope, inNarrowing);
packages/language-core/lib/codegen/template/interpolation.ts:313
- Buffering the conditional's identifier traversal has the same lexical-scope loss as the logical-expression path. For
((x) => x)(value) ? yes : no, the arrow scope is popped before the bufferedxreachesshouldIdentifierSkipped, causing a local parameter to be rewritten as an external binding. Scope/skip metadata must be captured before materialization.
else if (ts.isConditionalExpression(node)) {
const condition = [...forEachDeclarations(ts, node.condition, ast, ctx, scope, true)];
packages/language-core/lib/codegen/template/interpolation.ts:113
- Detecting
newfrom raw preceding text fails when valid comments intervene.new /* comment */ Foo()does not match this regex, so it emits the unparenthesizednew /* comment */ __VLS_unwrap(Foo)()form that this code is explicitly avoiding. Determine the constructor-operand relationship from the TypeScript AST rather than adjacent text.
const isNewOperand = /\bnew\s*$/.test(code.slice(prevEnd, offset));
… new
The unwrap refactor emits `new (__VLS_unwrap(Comp))(...)` instead of the
invalid `new Comp.value(...)`, which restores the props type context on the
object literal. The shorthand key `{ fooBar }` is now correctly recognized
as a reference to the props property `fooBar`, so rename returns it as the
key side (`suffixText: ": fooBar"`).
…template expressions
- never emit `.value` for function/class/enum declarations: assertion
signatures cannot narrow them, so narrowing positions now use
`__VLS_unwrap` via a new `setupNonNarrowableBindings` option
- compute identifier skip flags at yield time so buffered traversal of
logical / conditional branches no longer reads stale scope state
- classify destructuring assignment targets (`({ x } = source)`,
`[x] = source`) as writes
- classify for-of / for-in loop targets: declared names become scoped
locals, bare identifiers are writes
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 14 out of 15 changed files in this pull request and generated 2 comments.
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
packages/language-core/lib/codegen/template/interpolation.ts:114
- The textual
newdetection fails when legal comments appear between the keyword and operand, for examplenew /* factory */ Foo(). That case emitsnew __VLS_unwrap(Foo)(), which has the precedence problem described above and targets the unwrap call rather than the constructor. Determine this relationship from the AST, or make the detection skip JavaScript comments as well as whitespace.
const isNewOperand = /\bnew\s*$/.test(code.slice(prevEnd, offset));
…nd control-flow statements - traverse the right operand of `||` / `??` (not just `&&`) as a reference position so TS control-flow narrowing carries into v-else / subsequent branches - add narrowing-aware traversal for if / while / do / for / switch statements in inline handlers, so condition narrowing reaches the guarded bodies instead of degrading to independent `__VLS_unwrap` calls
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 14 out of 15 changed files in this pull request and generated 2 comments.
Suppressed comments (2)
packages/language-core/lib/codegen/template/interpolation.ts:490
- The
forincrementor runs only after the loop condition has succeeded, so TypeScript narrows condition bindings there just as it does in the body. Emitting the incrementor before entering the narrowed scope makes reads use__VLS_unwrapand loses that narrowing (for examplefor (; maybe; use(maybe))). Enter the narrowed scope before traversing both the incrementor and body.
if (node.incrementor) {
yield* forEachDeclarations(ts, node.incrementor, ast, ctx, scope, false);
packages/language-core/lib/codegen/template/interpolation.ts:511
- This traverses every
caseexpression before any clause statements, which is not source order. With multiple cases, identifier offsets move backward when the first clause body is finally yielded, and interpolation reconstruction produces malformed generated code. Traverse each case expression followed by that clause's statements, while keeping switch-local declarations in a dedicated lexical scope.
for (const clause of node.caseBlock.clauses) {
if (ts.isCaseClause(clause)) {
yield* forEachDeclarations(ts, clause.expression, ast, ctx, scope, false);
}
}
… in do/switch - seed the branch narrowed scope with all collected condition names before generating the condition, so names in nested RHS positions (e.g. `v-if="a && b"`) stay narrowed for branch children; the now-redundant `markNarrowed` parameter is removed - split do-while out of the while branch: its body precedes the condition in source, so emit it first and leave the first execution unnarrowed - interleave switch case expressions and clause statements in source order instead of yielding all case expressions first
…sions - type queries keep reference semantics: `typeof count` on a setup binding emits `typeof count.value` again (a `__VLS_unwrap` call is not valid in type position); non-narrowable declarations stay bare - function declarations and class declarations/expressions: declare their names, scope their params, walk heritage clauses, computed member names, property initializers, and static blocks instead of rewriting member/param identifiers as setup bindings - labels of labeled statements and break/continue, and meta properties (`new.target`, `import.meta`), are never rewritten - interface / type alias / enum / namespace declarations in handler bodies no longer corrupt the declaration names - catch clause variables are scoped to the catch block
In `v-for="x in x"` the source expression is evaluated in the outer scope, but the generated loop head sits inside the loop bindings' lexical scope, so a bare `x` resolved to the loop variable itself (TDZ). When a loop binding shares its name with a setup binding referenced by the source, hoist the source into a `const __VLS_N = (…)` alias emitted before the loop and reference the alias in the head. Also pin the shadowing behavior with fixture cases: loop variable, key/index aliases, and destructured patterns shadowing same-named setup bindings, including inside a narrowed v-if branch.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 16 changed files in this pull request and generated 3 comments.
Suppressed comments (3)
packages/language-core/lib/codegen/template/interpolation.ts:120
- Non-narrowable declarations are routed into this value-read branch even for assignment targets. An inline handler such as
handler = replacementorhandler++therefore becomes__VLS_unwrap(handler) = .../__VLS_unwrap(handler)++, and a call expression is not a valid left-hand side. Writes to function/class declaration bindings need to emit the bare binding (or otherwise use a distinct write classification) instead of the unwrap call.
else {
packages/language-core/lib/codegen/template/interpolation.ts:741
- The custom class traversal never visits class type parameters. A handler such as
class C<T = typeof count> {}therefore leaves the setup ref astypeof countinstead of applying the type-query.valueaccess, producing the wrong generated type. Traversenode.typeParametersbefore the heritage clauses.
for (const clause of node.heritageClauses ?? []) {
packages/language-core/lib/codegen/template/interpolation.ts:779
- Property type annotations are skipped by this class traversal. For
class C { field: typeof count },countremains the Ref type instead of the template-facing value type, while method return/parameter types are handled correctly above. Visitmember.typebefore the initializer.
else if (ts.isPropertyDeclaration(member)) {
if (member.initializer) {
yield* forEachDeclarations(ts, member.initializer, ast, ctx, scope, false);
}
}
…der traversals by source - replace the source-text regex that detected `new` operands with an `isNewOperand` flag carried by the AST traversal, so comments between `new` and the binding no longer break parenthesization - yield identifiers in source order in function and binding traversals: type parameters before parameters, binding patterns before their type annotations - traverse explicit call/new type arguments so `typeof` queries inside `f<typeof x>(...)` are rewritten - v-for: hoist the source expression into an outer-scope alias whenever a loop binding shadows a setup binding, instead of detecting the collision with a regex (which missed `$` and non-ASCII identifiers)
- `delete` operands are write-shaped targets: `delete foo` on a setup binding now emits `delete foo.value` instead of deleting an unwrap call result (TS2703, previously dropped silently) - computed property names in type literals traverse their expression and force the entity-name `.value` form (TS1170 forbids call expressions) - class property type annotations are traversed, so `typeof foo` in a field type sees the unwrapped type - function declarations are predeclared per statement-list scope, so hoisted references no longer resolve to setup/context bindings
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 20 out of 21 changed files in this pull request and generated no new comments.
Suppressed comments (3)
Previously missed (2) — in code that hasn't changed since the last review.
packages/language-core/lib/codegen/template/interpolation.ts:776
- Class type parameters are never traversed here, although function type parameters are handled above. Consequently a setup binding in a class constraint/default, such as
class C<T extends typeof count> {}, remainstypeof count(the Ref) instead oftypeof count.value(the template-unwrapped value), producing incorrect constraints. Traverse the class type parameters before the heritage clauses.
for (const clause of node.heritageClauses ?? []) {
packages/language-core/lib/codegen/template/elementEvents.ts:178
- The reassert scan starts after the enclosing
v-ifconditions were generated, butgenerateConditionGuards()copies those conditions into this closure. For<div v-if="importedMaybe" @click="localAction()">, the guard containsimportedMaybe.valuewhile the handler access slice contains onlylocalAction, so no closure-local assertion is emitted; TypeScript does not carry the top-level assertion for the import into this closure. Include non-flowing dot-value bindings referenced by active condition guards in the reassert set.
yield `(...[$event]) => {${newLine}`;
yield* generateReasserts(options, ctx, accessMark);
yield* ctx.generateConditionGuards();
packages/language-core/lib/codegen/template/interpolation.ts:108
inTypeQueryalways forces the.valueform, including for local function/class/enum declarations. Those are legitimate type-query operands (for example,type F = typeof handler), but the assertion cannot narrow declaration symbols—the limitation this PR is addressing—so the generated query becomestypeof handler.value, reports an unmapped TS2339, and loses the callable type. Type queries need a declaration-safe direct or type-level unwrap path rather than relying on the assertion.
ctx.accessVariable(block.name, name, start + offset, inTypeQuery || isNarrowing);
if (inTypeQuery || dotValueBindings.has(name)) {
- interpolation: drop array buffer in forEachNarrowedBy, collapse assignment / for-of-initializer branches onto forEachDeclarationsInAssignmentTarget - vFor: always hoist source into an alias const wrapped in __VLS_tryAsConstant, merging the dual paths; tryAsConstant keeps inline literal sources from widening (#6067) - rename template option nonFlowingBindings to reassertBindings and simplify generateReasserts / getDotValueBindings accordingly - restore inline _getStartEnd pushes in parsers/utils
- traverse class declaration/expression type parameters so typeof queries in constraints resolve unwrapped binding types - record bindings accessed by each v-if/v-else-if condition and re-assert them inside inline-handler closures that replay the condition guards
- skip re-asserting a binding whose name is covered by an active template scope (slot prop, v-for binding); the name there refers to the shadowing local, and asserting it narrowed the local's type - skip replaying a condition guard when every accessed name is shadowed in the current scope chain - brand the __VLS_withDotValue result with a unique symbol so a re-assert on a binding whose narrowing already flowed into the closure (never-assigned `let`) is a no-op instead of wrapping the intersection twice; tuple-wrapped check avoids distributing over union members - declare inline for-of/for-in loop bindings only after the source is traversed, matching the runtime scoping rule of `for (const x of x)` - pin rename behavior for setup bindings in interpolation, v-for source, inline handler write targets, and v-bind shorthand
- `__VLS_withDotValue`: the ref branch now requires the whole type to be
a ref (`[T] extends [Ref]`), so `Ref<T> | null | undefined` unions
(e.g. `inject<Ref<T>>`) fall through to the intersection branch
instead of keeping the nullish member and erroring on the appended
`.value` (TS18047/48); the intersection's `value` type now unwraps
ref members per union member. A distributive variant was rejected:
it violates TS2677 (predicate no longer assignable to the parameter),
which makes the checker fall back to intersection narrowing with
chaotic results.
- interpolation: the right operand of `&&`/`||`/`??` inherits the
outer narrowing flag instead of forcing it, so `{{ flag && box }}`
no longer mis-marks a plain object binding as dotValue (which
corrupted its own `.value`).
- script codegen: rename `withDotValueBindings` to `dotValueBindings`
to match the template/style option name (same set, single source).
- fixture: pin inject-style unions and the logical-right-operand case;
drop the obsolete `shadowed` assignment (brand idempotency made it
meaningless).
The wrapped type is ref-shaped anyway, so intersect with the
caller-supplied `Ref` type directly: the conjunct satisfies the first
branch on re-assertion, which makes the dedicated
`__VLS_dotValueBrand` unique symbol unnecessary. (The global helper
file cannot `import('vue')` — vue is not resolvable from
packages/language-core — which is why the Ref type must come in
through the type parameter.)
…nd switch-hoisting cases
…ist preview URLs vue-tsc 3.3.12 (Dependabot PR #9464) fails type checking on two templates: - DialogDisplayPopup: the Cancel button assigned `showCustomBackgroundPicker = false`, but that is a getter-only computed (TS2540). language-core 3.3.12 now emits `.value` for template write targets (vuejs/language-tools#6184), so it finally catches this. The write was always a no-op at runtime, and so was BaseDialog's v-model write on Esc / backdrop click, which meant the picker could only be closed with Cancel or by picking an image. Give the computed a setter that clears the import state when set to false, and use it from Cancel. - DialogJwPlaylist: `<q-img :src="'file://' + path">` trips a 3.3.12 codegen regression (vuejs/language-tools#6240, fix pending in #6241): any `//` inside a component prop value breaks the generated code, so every v-for variable after it becomes "Cannot find name". Building the URL with the existing pathToFileURL helper avoids the `//` literal and also fixes previews for playlists whose filename contains a `#` (it ends up in the extraction folder name and was parsed as a URL fragment). Adds a regression test for each and changelog entries. Co-Authored-By: Claude Opus 5.5 <[email protected]>
* chore(deps-dev): bump vue-tsc from 3.3.11 to 3.3.12 Bumps [vue-tsc](https://github.com/vuejs/language-tools/tree/HEAD/packages/tsc) from 3.3.11 to 3.3.12. - [Release notes](https://github.com/vuejs/language-tools/releases) - [Changelog](https://github.com/vuejs/language-tools/blob/master/CHANGELOG.md) - [Commits](https://github.com/vuejs/language-tools/commits/v3.3.12/packages/tsc) --- updated-dependencies: - dependency-name: vue-tsc dependency-version: 3.3.12 dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * fix(dialogs): make custom background picker closable and encode playlist preview URLs vue-tsc 3.3.12 (Dependabot PR #9464) fails type checking on two templates: - DialogDisplayPopup: the Cancel button assigned `showCustomBackgroundPicker = false`, but that is a getter-only computed (TS2540). language-core 3.3.12 now emits `.value` for template write targets (vuejs/language-tools#6184), so it finally catches this. The write was always a no-op at runtime, and so was BaseDialog's v-model write on Esc / backdrop click, which meant the picker could only be closed with Cancel or by picking an image. Give the computed a setter that clears the import state when set to false, and use it from Cancel. - DialogJwPlaylist: `<q-img :src="'file://' + path">` trips a 3.3.12 codegen regression (vuejs/language-tools#6240, fix pending in #6241): any `//` inside a component prop value breaks the generated code, so every v-for variable after it becomes "Cannot find name". Building the URL with the existing pathToFileURL helper avoids the `//` literal and also fixes previews for playlists whose filename contains a `#` (it ends up in the extraction folder name and was parsed as a URL fragment). Adds a regression test for each and changelog entries. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Olivier Savignac <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Problem
For every
<script setup>top-level binding read in the template, codegen appends.valueand relies on anassertsfunction (__VLS_withDotValue) to make the synthetic.valuea no-op for non-ref bindings. But TypeScript's assertion signatures do not apply to function / class / enum declarations, so:generates
foo.value()and reportsTS2339: Property 'value' does not exist on type '() => void'.Solution: one access form per binding
Each
<script setup>binding gets exactly one access form in the template, decided by how it is consumed — never by how it was declared, so local and imported bindings behave identically:&&/||/??guards, type guards, write targets, type queries, …) →foo.valueat every access. A single top-level__VLS_withDotValueassertion guarantees the binding has avalueproperty, so the synthetic.valueis type-safe at every site, and TypeScript's control-flow narrowing simply transfers onto thefoo.valuechain.__VLS_unwrap(foo, {} as Ref)at every access — a value-returning helper, so it works where assertion signatures cannot (function declarations, call results,newoperands, …).The assertion is global and idempotent, so once a binding needs
.valueanywhere, per-position mixing buys nothing — every site shares the one form. That also keeps each source identifier mapped to a single generated shape.How the assertion is shaped
Refand{ value: ... }, whosevalueunwraps ref members per union member.Refconjunct doubles as the idempotency marker: an already-wrapped binding satisfies the first branch, so re-asserting it (closures re-assert imports /let/var— see below) is a no-op.[T] extends [Ref]: a bareT extends Refis distributive, and TS2677 requires every branch of an assertion signature to stay assignable toT— distributing the intersection would collapse nullish union members intonever.NonNullable<T>strips nullish members before intersecting (undefined & Refwould benever). Side effect: in a ref-or-nullish union (e.g.inject<Ref<T>>), the ref's ownvalueabsorbs the nullish member, so reads stayTinstead ofT | undefined.Reftype arrives as a phantom argument ({} as import('vue').Ref<unknown>): the helper lives in a global.d.tsthat cannot import the component library.unref/toValue:unref's parameter type rejects native-{ value }objects and mixed ref unions (TS2345), andtoValueinvokes getters — neither matches template auto-unwrap semantics.Two-pass codegen
Whether a binding is narrowed is not knowable until the whole template has been traversed — a
v-ifat the bottom decides the access form of a read at the top. Codegen therefore runs twice per template/style block: the first pass runs with an empty dot-value set and only records bindings seen in narrowing positions; the second pass emits the final code from the finalized set. The collection pass's output is discarded, and the expression AST parse is cached, so the extra pass is bounded.Consumption analysis
Narrowing positions are detected by a pure TypeScript AST walk — no type analysis, which is unavailable at codegen time. The walker mirrors JavaScript semantics: conditions of
if/ ternary /while/do-while/for/switch, the left operands of&&/||/??, assignment and destructuring targets,typeof/instanceof/in/ equality guards, type queries, and write-shaped positions (++,delete). It also tracks scopes —v-foraliases, slot props, named class/function expressions, hoisted function declarations (including inside switch case blocks) — so a shadowed name is never mistaken for the setup binding. Entity-name positions (computed names in class properties and type literals, TS1170) cannot hold a call, so they always keep the.valueform.Assertions and closures
Assertion narrowing flows into closures only for
constlocals — not for imports orlet/var(plain-TypeScript semantics, verified against the compiler). Generated event-handler closures therefore re-assert those bindings at their top:constbindings are never re-asserted: a second assertion would double-wrap the type and break the exact-type pin. When every name a condition guard accesses is shadowed by an active template scope (slot prop,v-foralias), the replay is skipped — the name inside refers to the local, not the setup binding.Native-
valueobjectsThe
{ value: T }wrap restores exactly the one appended level, which is what makes the user's own.valueon a native-valueobject resolve correctly — every virtual access shifts one level, and the wrap shifts the type one level back:Behavior changes
letbindings read in the template. Such reads were previously masked — on master by__VLS_ctx.*property access, and earlier in this branch by the assertion call doubling as a CFA assignment. The diagnostic is genuine: the value isundefinedat runtime while the declared type claims otherwise. The Dynamic argument type incorrect? #2514 fixture now initializeseventNametonull, matching the issue's intent.Known limitations
constwhose initializer pins it tonull/undefined(e.g.const x = undefined) has its flow type pinned to that unit type, which the assertion cannot flip, so a condition on it reportsTS18048/TS18047on the synthetic.value. This only affects always-nullish conditions — dead code in practice — and read positions are unaffected (__VLS_unwrapis transparent for them).valueobject that is both narrowed somewhere and bare-read elsewhere: the bare read sees the wrapped intersection type. No diagnostics are produced; hover and exact-identity precision degrade. Pathological enough to accept.let/varonly at the top of codegen-created closures (event handlers). A closure the user writes inside an inline handler loses the assertion for those bindings.__VLS_unwrap(...)read additionally hits the helper's declaration intemplate-helpers.d.ts: mappings are closed intervals, so the source offset is claimed by both the preceding chunk's end and the binding's start, and with the injected prefix in between they resolve to two disjoint generated positions. This double-claim exists on master too (e.g. the__VLS_ctx.*path), where it is invisible because the extra position is virtual-unmapped and its edits are silently dropped. The fix belongs at the mapping / position-translation layer — tracked in Rename at a shared source boundary executes at two generated positions when unmapped text is injected between chunks #6186.Also
isCallanalysis (inCallPosition/accessVariableAsCall/callAccessedBindings): call callees now go through__VLS_unwrap, which matches Vue's template auto-unwrap more closely.((x) => x)(value) && otherrewrote the arrow parameterxas a setup binding.v-fordestructuring defaults (v-for="{ val = fallback } in objs") are parsed from the binding AST and routed through interpolation, so ref bindings referenced by defaults unwrap correctly. The inline-literal source pins (v-for="n in [1, 2, 3]"→1 | 2 | 3) are kept as-is: preserving literals there is the deliberate behavior from feat(language-core): preserve literal types for inlinev-forsources #6067.newwas restored: the old baseline emittednew Comp.value(...)(a TS error that broke the object literal's props constraint), so the shorthand key was not recognized as a props reference. With the constructor unwrapped it works; therenaming.spec.tssnapshot changed for that reason.Motivation
This is a prerequisite for #6179 (eliminate unmapped codegen diagnostics): it removes the
TS2339".valueon function" noise at the source, instead of suppressing it downstream.Test
test-workspace/tsc/unwrapBindingAccess/covers: function and class declaration reads, ref read/narrowing/write, the four type-guard forms,&&/||/??narrowing intov-else, control-flow statements in event handlers, destructuring assignment targets,for...ofloop targets (bare and declared), arrow-IIFE scope preservation in logical conditions, non-ref nullish narrowing (local and imported), comma-operand narrowing, early-exit fall-through narrowing, computed property names, hoisted function declarations (including inside switch clauses), named function/class expression scoping,v-fordestructuring defaults, and native-valueobject member access both outside and inside narrowed scopes (exactType(box2.value)→number).