Skip to content

Commit 8155733

Browse files
serpentbladeclaude
andcommitted
fix(codemirror): apply the engine-helper :any type-aids to angular
The codegen annotates langExt/themeExt/phExt and buildMarkers returns `: any` to satisfy strict tsc on the type-checked leaves (TS2742 not-nameable, TS2345 unknown-not-Extension, TS2322 RangeSet widening). The guards excluded angular — correct when it shipped source-only, stale under the dist+source standard where ng-packagr runs real ngc/tsc. Angular emits the same `name = () =>` / `const buildMarkers = (mView: any) =>` token forms as Lit/the bundled leaves, so it joins those two guards. Unblocks the codemirror angular leaf. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KcWqckxMNtbU5LGEAvYXEk
1 parent 857c0d3 commit 8155733

2 files changed

Lines changed: 18 additions & 12 deletions

File tree

packages/ui/codemirror/packages/angular/src/CodeMirror.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ export class CodeMirror {
582582
// Recompute the marker RangeSet from `gutterLines` against the live doc —
583583
// one marker at the START of each in-range line. RangeSet.of REQUIRES the
584584
// ranges sorted by `from`, so sort the resolved positions.
585-
const buildMarkers = (mView: any) => {
585+
const buildMarkers = (mView: any): any => {
586586
const doc = mView.state.doc;
587587
const ranges = [];
588588
for (const n of this.gutterLines() as any) {
@@ -734,8 +734,8 @@ export class CodeMirror {
734734
decorationCompartment = new Compartment();
735735
rebuildGutterExt: any = null;
736736
rebuildDecorationExt: any = null;
737-
langExt = () => this.language() === 'javascript' ? javascript() : [];
738-
themeExt = () => {
737+
langExt = (): any => this.language() === 'javascript' ? javascript() : [];
738+
themeExt = (): any => {
739739
const t = this.theme();
740740
if (t === 'dark') return oneDark;
741741
if (t === 'light' || t === '' || t == null) return [];
@@ -745,7 +745,7 @@ export class CodeMirror {
745745
// accept it; the type-neutral targets strip types entirely.
746746
return t;
747747
};
748-
phExt = () => this.placeholder() ? placeholderExt(this.placeholder()) : [];
748+
phExt = (): any => this.placeholder() ? placeholderExt(this.placeholder()) : [];
749749
baselineExt = () => this.basicSetup() ? [basicSetupBundle] : [lineNumbers(), history(), keymap.of([...defaultKeymap, ...historyKeymap])];
750750
writeDoc = (v: any) => {
751751
if (!this.view) return;

packages/ui/codemirror/scripts/codegen.mjs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,15 @@ function main() {
359359
// SCOPE (SCOPE FENCE). As the sanctioned in-scope per-leaf type aid (the CM
360360
// analog of FullCalendar's `const opts` widening), annotate the three helper
361361
// arrows with an explicit `: any` return here in codegen GLUE — durable
362-
// across regeneration, a pure type annotation (zero runtime change), and
363-
// scoped to the Lit leaf (react/solid emit these helpers in a form that does
364-
// not trip TS2742; vue/svelte/angular are type-neutral and never see it).
362+
// across regeneration, a pure type annotation (zero runtime change). Applies
363+
// to Lit AND Angular: both emit these helpers as `name = () =>` class fields
364+
// (react/solid use a different form that doesn't trip TS2742, and have their
365+
// own themeExt aid below). Angular's leaf now compiles via ng-packagr (real
366+
// ngc/tsc) under the dist+source standard, so it sees these the same way Lit
367+
// does — TS2742 on langExt (not nameable without @codemirror/language) and
368+
// TS2345 on themeExt's `unknown` return. svelte stays type-neutral at build.
365369
// Tracked as an emitter follow-up (annotate hoisted engine-typed helpers).
366-
if (cfg.dir === 'lit') {
370+
if (cfg.dir === 'lit' || cfg.dir === 'angular') {
367371
let aided = 0;
368372
for (const name of ['langExt', 'themeExt', 'phExt']) {
369373
const token = `${name} = () =>`;
@@ -422,10 +426,12 @@ function main() {
422426
// (OUT OF SCOPE — SCOPE FENCE); as the sanctioned in-scope per-leaf aid (the
423427
// analog of the `themeExt`/`*Ext` annotations above), annotate `buildMarkers`'s
424428
// return `: any` here — a pure type annotation, zero runtime change. The emit
425-
// shape is identical across the three bundled leaves; vue/svelte/angular are
426-
// type-neutral and never see it. Only present when the `gutter` slot wires the
427-
// marker builder, so this aid is gated on the token's presence.
428-
if (cfg.dir === 'react' || cfg.dir === 'solid' || cfg.dir === 'lit') {
429+
// shape (`const buildMarkers = (mView: any) =>`) is identical across the three
430+
// bundled leaves AND the Angular leaf (now ngc/tsc-compiled under the
431+
// dist+source standard, so it trips the same TS2322); vue/svelte stay
432+
// type-neutral at build. Only present when the `gutter` slot wires the marker
433+
// builder, so this aid is gated on the token's presence.
434+
if (cfg.dir === 'react' || cfg.dir === 'solid' || cfg.dir === 'lit' || cfg.dir === 'angular') {
429435
const markersToken = 'const buildMarkers = (mView: any) =>';
430436
const markersAnnotated = 'const buildMarkers = (mView: any): any =>';
431437
if (!code.includes(markersToken)) {

0 commit comments

Comments
 (0)