Skip to content

refactor(language-core): unwrap setup bindings by value - #6184

Merged
johnsoncodehk merged 48 commits into
masterfrom
refactor/unwrap-binding-access
Aug 26, 2026
Merged

johnsoncodehk merged 48 commits into
masterfrom
refactor/unwrap-binding-access

Conversation

@johnsoncodehk

@johnsoncodehk johnsoncodehk commented Aug 25, 2026 •

Copy link
Copy Markdown
Member

Problem

For every <script setup> top-level binding read in the template, codegen appends .value and relies on an asserts function (__VLS_withDotValue) to make the synthetic .value a no-op for non-ref bindings. But TypeScript's assertion signatures do not apply to function / class / enum declarations, so:

<script setup lang="ts">
function foo() {}
</script>

<template>{{ foo() }}</template>

generates foo.value() and reports TS2339: 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:

  • Narrowed at least once (v-if / v-else-if conditions, && / || / ?? guards, type guards, write targets, type queries, …) → foo.value at every access. A single top-level __VLS_withDotValue assertion guarantees the binding has a value property, so the synthetic .value is type-safe at every site, and TypeScript's control-flow narrowing simply transfers onto the foo.value chain.
  • Otherwise → __VLS_unwrap(foo, {} as Ref) at every access — a value-returning helper, so it works where assertion signatures cannot (function declarations, call results, new operands, …).
function __VLS_withDotValue<T, Ref>(t: T, ref: Ref): asserts t is [T] extends [Ref] ? T
	: NonNullable<T> & Ref & { value: T extends Ref & { value: infer V } ? V : T };
function __VLS_unwrap<T, Ref>(t: T, ref: Ref): T extends Ref & { value: infer V } ? V
	: T;

The assertion is global and idempotent, so once a binding needs .value anywhere, 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

  • A wholly-ref type stays as-is; anything else is intersected with Ref and { value: ... }, whose value unwraps ref members per union member.
  • The Ref conjunct 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.
  • The first check uses the tuple form [T] extends [Ref]: a bare T extends Ref is distributive, and TS2677 requires every branch of an assertion signature to stay assignable to T — distributing the intersection would collapse nullish union members into never.
  • NonNullable<T> strips nullish members before intersecting (undefined & Ref would be never). Side effect: in a ref-or-nullish union (e.g. inject<Ref<T>>), the ref's own value absorbs the nullish member, so reads stay T instead of T | undefined.
  • The Ref type arrives as a phantom argument ({} as import('vue').Ref<unknown>): the helper lives in a global .d.ts that cannot import the component library.
  • Not Vue core's unref / toValue: unref's parameter type rejects native-{ value } objects and mixed ref unions (TS2345), and toValue invokes 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-if at 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-for aliases, 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 .value form.

Assertions and closures

Assertion narrowing flows into closures only for const locals — not for imports or let / var (plain-TypeScript semantics, verified against the compiler). Generated event-handler closures therefore re-assert those bindings at their top:

<script setup lang="ts">
import { maybeFn } from './somewhere';
</script>

<template>
	<div v-if="maybeFn" @click="() => maybeFn()"></div>
</template>
if (maybeFn.value) { ... }
__VLS_on('click', () => {
	__VLS_withDotValue(maybeFn, {} as Ref); // re-asserted: import assertion does not flow in
	maybeFn.value();
});

const bindings 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-for alias), the replay is skipped — the name inside refers to the local, not the setup binding.

Native-value objects

The { value: T } wrap restores exactly the one appended level, which is what makes the user's own .value on a native-value object resolve correctly — every virtual access shifts one level, and the wrap shifts the type one level back:

<script setup lang="ts">
const box = { value: 42 };
</script>

<template>
	{{ box.value }} <!-- virtual: box.value.value → number -->
	<div v-if="box.value">{{ box.value }}</div> <!-- virtual: if (box.value.value), body same -->
</template>

Behavior changes

  • TS2454 now surfaces for never-assigned let bindings 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 is undefined at runtime while the declared type claims otherwise. The Dynamic argument type incorrect? #2514 fixture now initializes eventName to null, matching the issue's intent.

Known limitations

  • A const whose initializer pins it to null / 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 reports TS18048 / TS18047 on the synthetic .value. This only affects always-nullish conditions — dead code in practice — and read positions are unaffected (__VLS_unwrap is transparent for them).
  • A native-value object 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.
  • Closures re-assert imports / let / var only at the top of codegen-created closures (event handlers). A closure the user writes inside an inline handler loses the assertion for those bindings.
  • Rename at the immediate left boundary of an __VLS_unwrap(...) read additionally hits the helper's declaration in template-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

  • Removed the isCall analysis (inCallPosition / accessVariableAsCall / callAccessedBindings): call callees now go through __VLS_unwrap, which matches Vue's template auto-unwrap more closely.
  • Identifier skip classification is now computed at yield time. The logical/ternary branches buffer their left/condition sub-traversal; doing so used to close nested arrow-function scopes before the skip check ran, so ((x) => x)(value) && other rewrote the arrow parameter x as a setup binding.
  • v-for destructuring 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 inline v-for sources #6067.
  • Rename on shorthand prop keys under new was restored: the old baseline emitted new 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; the renaming.spec.ts snapshot changed for that reason.
  • The scoped-class references registry is reset at the start of each codegen pass; it accumulates as a module-level side effect, and the discarded collection pass would otherwise duplicate document links.

Motivation

This is a prerequisite for #6179 (eliminate unmapped codegen diagnostics): it removes the TS2339 ".value on 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 into v-else, control-flow statements in event handlers, destructuring assignment targets, for...of loop 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-for destructuring defaults, and native-value object member access both outside and inside narrowed scopes (exactType(box2.value) → number).

johnsoncodehk and others added 5 commits August 25, 2026 06:49
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.

Copilot AI 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.

Pull request overview

Refactors template code generation to unwrap setup bindings by value while preserving references for narrowing and writes.

Changes:

  • Adds __VLS_unwrap and narrowing-scope tracking.
  • Updates interpolation, props, events, and v-if access 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)())`.

Copilot AI 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.

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 inNarrowing to every call argument reintroduces the function-declaration failure. In v-if="predicate(handler)", handler is a value read but is generated as handler.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 buffered x reaches shouldIdentifierSkipped, 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 new from raw preceding text fails when valid comments intervene. new /* comment */ Foo() does not match this regex, so it emits the unparenthesized new /* 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

Copilot AI 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.

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 new detection fails when legal comments appear between the keyword and operand, for example new /* factory */ Foo(). That case emits new __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

Copilot AI 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.

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 for incrementor 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_unwrap and loses that narrowing (for example for (; 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 case expression 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.

Copilot AI 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.

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 = replacement or handler++ 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 as typeof count instead of applying the type-query .value access, producing the wrong generated type. Traverse node.typeParameters before 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 }, count remains the Ref type instead of the template-facing value type, while method return/parameter types are handled correctly above. Visit member.type before 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)
@johnsoncodehk
johnsoncodehk requested a balanced review from Copilot August 25, 2026 14:28
- `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

Copilot AI 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.

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> {}, remains typeof count (the Ref) instead of typeof 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-if conditions were generated, but generateConditionGuards() copies those conditions into this closure. For <div v-if="importedMaybe" @click="localAction()">, the guard contains importedMaybe.value while the handler access slice contains only localAction, 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

  • inTypeQuery always forces the .value form, 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 becomes typeof 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.)
@johnsoncodehk
johnsoncodehk requested a balanced review from Copilot August 26, 2026 15:21
@johnsoncodehk
johnsoncodehk merged commit 0658218 into master Aug 26, 2026
@johnsoncodehk
johnsoncodehk deleted the refactor/unwrap-binding-access branch August 26, 2026 15:44
@johnsoncodehk
johnsoncodehk removed the request for review from Copilot August 26, 2026 16:30
johnsoncodehk added a commit that referenced this pull request Aug 27, 2026
The master merge brought #6184 (unwrap setup bindings by value), #6181
(calling template bindings without .value), #6179 (unmapped diagnostics),
and the withDotValue/unwrapBindingAccess fixtures, all of which change the
generated virtual code and the diagnostics the corpus reports.
sircharlo added a commit to sircharlo/meeting-media-manager that referenced this pull request Oct 7, 2026
…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]>
sircharlo added a commit to sircharlo/meeting-media-manager that referenced this pull request Oct 7, 2026
* 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]>
johnsoncodehk added a commit that referenced this pull request Dec 1, 2026
…emplate reads unwrapped (#6402)

The check asked the type of the identifier, which is the `Ref` of the binding since template reads of setup bindings are generated as `__VLS_unwrap(x)` or `x.value` (#6184). It now asks the type of that read.

Fixes #6272
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