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(
150
150
resolvedReadType === null && type !== undefined ? [ type ] : undefined ,
151
151
args ,
152
152
) ;
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
+
153
162
const updated = ts . factory . createPropertyDeclaration (
154
- [ ts . factory . createModifier ( ts . SyntaxKind . ReadonlyKeyword ) ] ,
163
+ modifiers ,
155
164
node . name ,
156
165
undefined ,
157
166
undefined ,
@@ -169,3 +178,12 @@ export function computeReplacementsToMigrateQuery(
169
178
) ,
170
179
] ;
171
180
}
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[] = [
55
55
before : `@ViewChild('myBtn', {read: ElementRef}) buttonEl!: ElementRef;` ,
56
56
after : `readonly buttonEl = viewChild.required('myBtn', { read: ElementRef });` ,
57
57
} ,
58
+ {
59
+ id : 'viewChild retain accessibility modifier' ,
60
+ before : `@ViewChild('sidenav') public sidenav: HTMLElement;` ,
61
+ after : `public readonly sidenav = viewChild<HTMLElement>('sidenav');` ,
62
+ } ,
58
63
// Content Child
59
64
{
60
65
id : 'contentChild with string locator and nullable' ,
@@ -137,6 +142,11 @@ const declarationTestCases: TestCase[] = [
137
142
before : `@ViewChildren('myBtn', {descendants: true}) buttonEl = new QueryList<ElementRef>()` ,
138
143
after : `readonly buttonEl = viewChildren<ElementRef>('myBtn');` ,
139
144
} ,
145
+ {
146
+ id : 'viewChildren retain accessibility modifier' ,
147
+ before : `@ViewChildren('sidenav') public sidenav: HTMLElement;` ,
148
+ after : `public readonly sidenav = viewChildren('sidenav');` ,
149
+ } ,
140
150
// ContentChildren
141
151
{
142
152
id : 'contentChildren with string locator and nullable' ,
You can’t perform that action at this time.
0 commit comments