File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed
packages/core/schematics/migrations/signal-queries-migration Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -150,8 +150,17 @@ export function computeReplacementsToMigrateQuery(
150150 resolvedReadType === null && type !== undefined ? [ type ] : undefined ,
151151 args ,
152152 ) ;
153+
154+ const accessibilityModifier = getAccessibilityModifier ( node ) ;
155+ let modifiers : ( ts . ModifierLike | ts . ModifierToken < ts . SyntaxKind . ReadonlyKeyword > ) [ ] = [
156+ ts . factory . createModifier ( ts . SyntaxKind . ReadonlyKeyword ) ,
157+ ] ;
158+ if ( accessibilityModifier ) {
159+ modifiers = [ accessibilityModifier , ...modifiers ] ;
160+ }
161+
153162 const updated = ts . factory . createPropertyDeclaration (
154- [ ts . factory . createModifier ( ts . SyntaxKind . ReadonlyKeyword ) ] ,
163+ modifiers ,
155164 node . name ,
156165 undefined ,
157166 undefined ,
@@ -169,3 +178,12 @@ export function computeReplacementsToMigrateQuery(
169178 ) ,
170179 ] ;
171180}
181+
182+ function getAccessibilityModifier ( node : ts . PropertyDeclaration ) : ts . ModifierLike | undefined {
183+ return node . modifiers ?. find (
184+ ( mod ) =>
185+ mod . kind === ts . SyntaxKind . PublicKeyword ||
186+ mod . kind === ts . SyntaxKind . PrivateKeyword ||
187+ mod . kind === ts . SyntaxKind . ProtectedKeyword ,
188+ ) ;
189+ }
Original file line number Diff line number Diff line change @@ -55,6 +55,11 @@ const declarationTestCases: TestCase[] = [
5555 before : `@ViewChild('myBtn', {read: ElementRef}) buttonEl!: ElementRef;` ,
5656 after : `readonly buttonEl = viewChild.required('myBtn', { read: ElementRef });` ,
5757 } ,
58+ {
59+ id : 'viewChild retain accessibility modifier' ,
60+ before : `@ViewChild('sidenav') public sidenav: HTMLElement;` ,
61+ after : `public readonly sidenav = viewChild<HTMLElement>('sidenav');` ,
62+ } ,
5863 // Content Child
5964 {
6065 id : 'contentChild with string locator and nullable' ,
@@ -137,6 +142,11 @@ const declarationTestCases: TestCase[] = [
137142 before : `@ViewChildren('myBtn', {descendants: true}) buttonEl = new QueryList<ElementRef>()` ,
138143 after : `readonly buttonEl = viewChildren<ElementRef>('myBtn');` ,
139144 } ,
145+ {
146+ id : 'viewChildren retain accessibility modifier' ,
147+ before : `@ViewChildren('sidenav') public sidenav: HTMLElement;` ,
148+ after : `public readonly sidenav = viewChildren('sidenav');` ,
149+ } ,
140150 // ContentChildren
141151 {
142152 id : 'contentChildren with string locator and nullable' ,
You can’t perform that action at this time.
0 commit comments