Skip to content

Commit 216759b

Browse files
crisbetojelbourn
authored andcommitted
refactor: expand private getter restrictions to underscored members (#20083)
We have a lint rule that doesn't allow private getters, because they increase the generated ES5 code without much benefit for a private API. These changes expand the restrictions to any public members that are prefixed with an underscore since we don't consider them part of the public API surface. (cherry picked from commit 3dce841)
1 parent 5b63309 commit 216759b

29 files changed

+159
-157
lines changed

src/cdk-experimental/dialog/dialog-container.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class CdkDialogContainer extends BasePortalOutlet implements OnDestroy {
8787
// @HostBinding is used in the class as it is expected to be extended. Since @Component decorator
8888
// metadata is not inherited by child classes, instead the host binding data is defined in a way
8989
// that can be inherited.
90-
// tslint:disable:no-host-decorator-in-concrete
90+
// tslint:disable:no-host-decorator-in-concrete no-private-getters
9191
@HostBinding('attr.aria-label') get _ariaLabel() { return this._config.ariaLabel || null; }
9292

9393
@HostBinding('attr.aria-describedby')
@@ -98,7 +98,7 @@ export class CdkDialogContainer extends BasePortalOutlet implements OnDestroy {
9898
@HostBinding('attr.aria-modal') _ariaModal: boolean = true;
9999

100100
@HostBinding('attr.tabindex') get _tabindex() { return -1; }
101-
// tslint:disable:no-host-decorator-in-concrete
101+
// tslint:disable:no-host-decorator-in-concrete no-private-getters
102102

103103
/** The portal host inside of this container into which the dialog content will be loaded. */
104104
@ViewChild(CdkPortalOutlet, {static: true}) _portalHost: CdkPortalOutlet;

src/cdk-experimental/dialog/dialog.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ export class Dialog implements OnDestroy {
5050
private _scrollStrategy: () => ScrollStrategy;
5151

5252
/** Stream that emits when all dialogs are closed. */
53-
get _afterAllClosed(): Observable<void> {
53+
_getAfterAllClosed(): Observable<void> {
5454
return this._parentDialog ? this._parentDialog.afterAllClosed : this._afterAllClosedBase;
5555
}
5656
_afterAllClosedBase = new Subject<void>();
5757

5858
// TODO(jelbourn): tighten the type on the right-hand side of this expression.
5959
afterAllClosed: Observable<void> = defer(() => this.openDialogs.length ?
60-
this._afterAllClosed : this._afterAllClosed.pipe(startWith(undefined)));
60+
this._getAfterAllClosed() : this._getAfterAllClosed().pipe(startWith(undefined)));
6161

6262
/** Stream that emits when a dialog is opened. */
6363
get afterOpened(): Subject<DialogRef<any>> {

src/cdk/overlay/position/connected-position-strategy.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ export class ConnectedPositionStrategy implements PositionStrategy {
4545

4646
private _direction: Direction | null;
4747

48-
/** Whether the we're dealing with an RTL context */
49-
get _isRtl() {
50-
return this._overlayRef.getDirection() === 'rtl';
51-
}
52-
5348
/** Ordered list of preferred positions, from most to least desirable. */
5449
_preferredPositions: ConnectionPositionPair[] = [];
5550

src/material-experimental/mdc-chips/chip-grid.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,12 +533,12 @@ describe('MDC-based MatChipGrid', () => {
533533
secondChip.focus();
534534
fixture.detectChanges();
535535

536-
expect(chipGridInstance._chips.toArray().findIndex(chip => chip._hasFocus)).toBe(1);
536+
expect(chipGridInstance._chips.toArray().findIndex(chip => chip._hasFocus())).toBe(1);
537537

538538
dispatchKeyboardEvent(secondChip, 'keydown', DELETE);
539539
fixture.detectChanges();
540540

541-
expect(chipGridInstance._chips.toArray().findIndex(chip => chip._hasFocus)).toBe(1);
541+
expect(chipGridInstance._chips.toArray().findIndex(chip => chip._hasFocus())).toBe(1);
542542
});
543543

544544
describe('when the input has focus', () => {

src/material-experimental/mdc-chips/chip-option.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export class MatChipOption extends MatChip implements AfterContentInit {
183183
return;
184184
}
185185

186-
if (!this._hasFocus) {
186+
if (!this._hasFocus()) {
187187
this._elementRef.nativeElement.focus();
188188
this._onFocus.next({chip: this});
189189
}

src/material-experimental/mdc-chips/chip-row.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export class MatChipRow extends MatChip implements AfterContentInit, AfterViewIn
150150
this._hasFocusInternal = false;
151151
// Wait to see if focus moves to the other gridcell
152152
setTimeout(() => {
153-
if (this._hasFocus) {
153+
if (this._hasFocus()) {
154154
return;
155155
}
156156
this._onBlur.next({chip: this});

src/material-experimental/mdc-chips/chip-set.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ export class MatChipSet extends _MatChipSetMixinBase implements AfterContentInit
193193

194194
/** Checks whether any of the chips is focused. */
195195
protected _hasFocusedChip() {
196-
return this._chips && this._chips.some(chip => chip._hasFocus);
196+
return this._chips && this._chips.some(chip => chip._hasFocus());
197197
}
198198

199199
/** Syncs the chip-set's state with the individual chips. */
@@ -251,7 +251,7 @@ export class MatChipSet extends _MatChipSetMixinBase implements AfterContentInit
251251
// In case the chip that will be removed is currently focused, we temporarily store
252252
// the index in order to be able to determine an appropriate sibling chip that will
253253
// receive focus.
254-
if (this._isValidIndex(chipIndex) && chip._hasFocus) {
254+
if (this._isValidIndex(chipIndex) && chip._hasFocus()) {
255255
this._lastDestroyedChipIndex = chipIndex;
256256
}
257257
});

src/material-experimental/mdc-chips/chip.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
158158
this._chipFoundation.handleTransitionEnd(event);
159159
}
160160

161-
get _hasFocus() {
161+
_hasFocus() {
162162
return this._hasFocusInternal;
163163
}
164164

src/material/datepicker/datepicker-base.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,16 +341,16 @@ export abstract class MatDatepickerBase<C extends MatDatepickerControl<D>, S,
341341
id: string = `mat-datepicker-${datepickerUid++}`;
342342

343343
/** The minimum selectable date. */
344-
get _minDate(): D | null {
344+
_getMinDate(): D | null {
345345
return this._datepickerInput && this._datepickerInput.min;
346346
}
347347

348348
/** The maximum selectable date. */
349-
get _maxDate(): D | null {
349+
_getMaxDate(): D | null {
350350
return this._datepickerInput && this._datepickerInput.max;
351351
}
352352

353-
get _dateFilter(): DateFilterFn<D> {
353+
_getDateFilter(): DateFilterFn<D> {
354354
return this._datepickerInput && this._datepickerInput.dateFilter;
355355
}
356356

src/material/datepicker/datepicker-content.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
[ngClass]="datepicker.panelClass"
44
[startAt]="datepicker.startAt"
55
[startView]="datepicker.startView"
6-
[minDate]="datepicker._minDate"
7-
[maxDate]="datepicker._maxDate"
8-
[dateFilter]="datepicker._dateFilter"
6+
[minDate]="datepicker._getMinDate()"
7+
[maxDate]="datepicker._getMaxDate()"
8+
[dateFilter]="datepicker._getDateFilter()"
99
[headerComponent]="datepicker.calendarHeaderComponent"
1010
[selected]="_getSelected()"
1111
[dateClass]="datepicker.dateClass"

src/material/datepicker/datepicker.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,8 +1262,8 @@ describe('MatDatepicker', () => {
12621262
}));
12631263

12641264
it('should use min and max dates specified by the input', () => {
1265-
expect(testComponent.datepicker._minDate).toEqual(new Date(2010, JAN, 1));
1266-
expect(testComponent.datepicker._maxDate).toEqual(new Date(2020, JAN, 1));
1265+
expect(testComponent.datepicker._getMinDate()).toEqual(new Date(2010, JAN, 1));
1266+
expect(testComponent.datepicker._getMaxDate()).toEqual(new Date(2020, JAN, 1));
12671267
});
12681268

12691269
it('should mark invalid when value is before min', fakeAsync(() => {
@@ -1283,15 +1283,15 @@ describe('MatDatepicker', () => {
12831283
}));
12841284

12851285
it('should not mark invalid when value equals min', fakeAsync(() => {
1286-
testComponent.date = testComponent.datepicker._minDate;
1286+
testComponent.date = testComponent.datepicker._getMinDate();
12871287
revalidate();
12881288

12891289
expect(fixture.debugElement.query(By.css('input'))!.nativeElement.classList)
12901290
.not.toContain('ng-invalid');
12911291
}));
12921292

12931293
it('should not mark invalid when value equals max', fakeAsync(() => {
1294-
testComponent.date = testComponent.datepicker._maxDate;
1294+
testComponent.date = testComponent.datepicker._getMaxDate();
12951295
revalidate();
12961296

12971297
expect(fixture.debugElement.query(By.css('input'))!.nativeElement.classList)

src/material/dialog/dialog.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ export class MatDialog implements OnDestroy {
8585
return this._parentDialog ? this._parentDialog.afterOpened : this._afterOpenedAtThisLevel;
8686
}
8787

88-
get _afterAllClosed(): Subject<void> {
88+
_getAfterAllClosed(): Subject<void> {
8989
const parent = this._parentDialog;
90-
return parent ? parent._afterAllClosed : this._afterAllClosedAtThisLevel;
90+
return parent ? parent._getAfterAllClosed() : this._afterAllClosedAtThisLevel;
9191
}
9292

9393
// TODO (jelbourn): tighten the typing right-hand side of this expression.
@@ -96,8 +96,8 @@ export class MatDialog implements OnDestroy {
9696
* Will emit on subscribe if there are no open dialogs to begin with.
9797
*/
9898
readonly afterAllClosed: Observable<void> = defer(() => this.openDialogs.length ?
99-
this._afterAllClosed :
100-
this._afterAllClosed.pipe(startWith(undefined))) as Observable<any>;
99+
this._getAfterAllClosed() :
100+
this._getAfterAllClosed().pipe(startWith(undefined))) as Observable<any>;
101101

102102
constructor(
103103
private _overlay: Overlay,
@@ -324,7 +324,7 @@ export class MatDialog implements OnDestroy {
324324
});
325325

326326
this._ariaHiddenElements.clear();
327-
this._afterAllClosed.next();
327+
this._getAfterAllClosed().next();
328328
}
329329
}
330330
}

src/material/form-field/form-field.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
[id]="_labelId"
3333
[attr.for]="_control.id"
3434
[attr.aria-owns]="_control.id"
35-
[class.mat-empty]="_control.empty && !_shouldAlwaysFloat"
36-
[class.mat-form-field-empty]="_control.empty && !_shouldAlwaysFloat"
35+
[class.mat-empty]="_control.empty && !_shouldAlwaysFloat()"
36+
[class.mat-form-field-empty]="_control.empty && !_shouldAlwaysFloat()"
3737
[class.mat-accent]="color == 'accent'"
3838
[class.mat-warn]="color == 'warn'"
3939
#label

src/material/form-field/form-field.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export const MAT_FORM_FIELD = new InjectionToken<MatFormField>('MatFormField');
132132
'[class.mat-form-field-appearance-outline]': 'appearance == "outline"',
133133
'[class.mat-form-field-appearance-legacy]': 'appearance == "legacy"',
134134
'[class.mat-form-field-invalid]': '_control.errorState',
135-
'[class.mat-form-field-can-float]': '_canLabelFloat',
135+
'[class.mat-form-field-can-float]': '_canLabelFloat()',
136136
'[class.mat-form-field-should-float]': '_shouldLabelFloat()',
137137
'[class.mat-form-field-has-label]': '_hasFloatingLabel()',
138138
'[class.mat-form-field-hide-placeholder]': '_hideControlPlaceholder()',
@@ -199,12 +199,12 @@ export class MatFormField extends _MatFormFieldMixinBase
199199
private _showAlwaysAnimate = false;
200200

201201
/** Whether the floating label should always float or not. */
202-
get _shouldAlwaysFloat(): boolean {
202+
_shouldAlwaysFloat(): boolean {
203203
return this.floatLabel === 'always' && !this._showAlwaysAnimate;
204204
}
205205

206206
/** Whether the label can float or not. */
207-
get _canLabelFloat(): boolean { return this.floatLabel !== 'never'; }
207+
_canLabelFloat(): boolean { return this.floatLabel !== 'never'; }
208208

209209
/** State of the mat-hint and mat-error animations. */
210210
_subscriptAnimationState: string = '';
@@ -271,10 +271,6 @@ export class MatFormField extends _MatFormFieldMixinBase
271271

272272
@ContentChild(MatLabel) _labelChildNonStatic: MatLabel;
273273
@ContentChild(MatLabel, {static: true}) _labelChildStatic: MatLabel;
274-
get _labelChild() {
275-
return this._labelChildNonStatic || this._labelChildStatic;
276-
}
277-
278274
@ContentChild(MatPlaceholder) _placeholderChild: MatPlaceholder;
279275

280276
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
@@ -407,12 +403,12 @@ export class MatFormField extends _MatFormFieldMixinBase
407403
}
408404

409405
_hasLabel() {
410-
return !!this._labelChild;
406+
return !!(this._labelChildNonStatic || this._labelChildStatic);
411407
}
412408

413409
_shouldLabelFloat() {
414-
return this._canLabelFloat &&
415-
((this._control && this._control.shouldLabelFloat) || this._shouldAlwaysFloat);
410+
return this._canLabelFloat() &&
411+
((this._control && this._control.shouldLabelFloat) || this._shouldAlwaysFloat());
416412
}
417413

418414
_hideControlPlaceholder() {
@@ -434,7 +430,7 @@ export class MatFormField extends _MatFormFieldMixinBase
434430

435431
/** Animates the placeholder up and locks it in position. */
436432
_animateAndLockLabel(): void {
437-
if (this._hasFloatingLabel() && this._canLabelFloat) {
433+
if (this._hasFloatingLabel() && this._canLabelFloat()) {
438434
// If animations are disabled, we shouldn't go in here,
439435
// because the `transitionend` will never fire.
440436
if (this._animationsEnabled && this._label) {

src/material/input/input.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,15 +845,15 @@ describe('MatInput without forms', () => {
845845
inputContainer._animateAndLockLabel();
846846
fixture.detectChanges();
847847

848-
expect(inputContainer._shouldAlwaysFloat).toBe(false);
848+
expect(inputContainer._shouldAlwaysFloat()).toBe(false);
849849
expect(inputContainer.floatLabel).toBe('always');
850850

851851
const fakeEvent = createFakeEvent('transitionend');
852852
(fakeEvent as any).propertyName = 'transform';
853853
label.dispatchEvent(fakeEvent);
854854
fixture.detectChanges();
855855

856-
expect(inputContainer._shouldAlwaysFloat).toBe(true);
856+
expect(inputContainer._shouldAlwaysFloat()).toBe(true);
857857
expect(inputContainer.floatLabel).toBe('always');
858858
}));
859859

src/material/progress-spinner/progress-spinner.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<svg
99
[style.width.px]="diameter"
1010
[style.height.px]="diameter"
11-
[attr.viewBox]="_viewBox"
11+
[attr.viewBox]="_getViewBox()"
1212
preserveAspectRatio="xMidYMid meet"
1313
focusable="false"
1414
[ngSwitch]="mode === 'indeterminate'">
@@ -24,18 +24,18 @@
2424
*ngSwitchCase="true"
2525
cx="50%"
2626
cy="50%"
27-
[attr.r]="_circleRadius"
27+
[attr.r]="_getCircleRadius()"
2828
[style.animation-name]="'mat-progress-spinner-stroke-rotate-' + diameter"
29-
[style.stroke-dashoffset.px]="_strokeDashOffset"
30-
[style.stroke-dasharray.px]="_strokeCircumference"
31-
[style.stroke-width.%]="_circleStrokeWidth"></circle>
29+
[style.stroke-dashoffset.px]="_getStrokeDashOffset()"
30+
[style.stroke-dasharray.px]="_getStrokeCircumference()"
31+
[style.stroke-width.%]="_getCircleStrokeWidth()"></circle>
3232

3333
<circle
3434
*ngSwitchCase="false"
3535
cx="50%"
3636
cy="50%"
37-
[attr.r]="_circleRadius"
38-
[style.stroke-dashoffset.px]="_strokeDashOffset"
39-
[style.stroke-dasharray.px]="_strokeCircumference"
40-
[style.stroke-width.%]="_circleStrokeWidth"></circle>
37+
[attr.r]="_getCircleRadius()"
38+
[style.stroke-dashoffset.px]="_getStrokeDashOffset()"
39+
[style.stroke-dasharray.px]="_getStrokeCircumference()"
40+
[style.stroke-width.%]="_getCircleStrokeWidth()"></circle>
4141
</svg>

src/material/progress-spinner/progress-spinner.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -230,37 +230,37 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
230230
}
231231

232232
/** The radius of the spinner, adjusted for stroke width. */
233-
get _circleRadius() {
233+
_getCircleRadius() {
234234
return (this.diameter - BASE_STROKE_WIDTH) / 2;
235235
}
236236

237237
/** The view box of the spinner's svg element. */
238-
get _viewBox() {
239-
const viewBox = this._circleRadius * 2 + this.strokeWidth;
238+
_getViewBox() {
239+
const viewBox = this._getCircleRadius() * 2 + this.strokeWidth;
240240
return `0 0 ${viewBox} ${viewBox}`;
241241
}
242242

243243
/** The stroke circumference of the svg circle. */
244-
get _strokeCircumference(): number {
245-
return 2 * Math.PI * this._circleRadius;
244+
_getStrokeCircumference(): number {
245+
return 2 * Math.PI * this._getCircleRadius();
246246
}
247247

248248
/** The dash offset of the svg circle. */
249-
get _strokeDashOffset() {
249+
_getStrokeDashOffset() {
250250
if (this.mode === 'determinate') {
251-
return this._strokeCircumference * (100 - this._value) / 100;
251+
return this._getStrokeCircumference() * (100 - this._value) / 100;
252252
}
253253

254254
// In fallback mode set the circle to 80% and rotate it with CSS.
255255
if (this._fallbackAnimation && this.mode === 'indeterminate') {
256-
return this._strokeCircumference * 0.2;
256+
return this._getStrokeCircumference() * 0.2;
257257
}
258258

259259
return null;
260260
}
261261

262262
/** Stroke width of the circle in percent. */
263-
get _circleStrokeWidth() {
263+
_getCircleStrokeWidth() {
264264
return this.strokeWidth / this.diameter * 100;
265265
}
266266

@@ -288,10 +288,11 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
288288

289289
/** Generates animation styles adjusted for the spinner's diameter. */
290290
private _getAnimationText(): string {
291+
const strokeCircumference = this._getStrokeCircumference();
291292
return INDETERMINATE_ANIMATION_TEMPLATE
292293
// Animation should begin at 5% and end at 80%
293-
.replace(/START_VALUE/g, `${0.95 * this._strokeCircumference}`)
294-
.replace(/END_VALUE/g, `${0.2 * this._strokeCircumference}`)
294+
.replace(/START_VALUE/g, `${0.95 * strokeCircumference}`)
295+
.replace(/END_VALUE/g, `${0.2 * strokeCircumference}`)
295296
.replace(/DIAMETER/g, `${this.diameter}`);
296297
}
297298

0 commit comments

Comments
 (0)