Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
"firebase-tools": "^9.2.1",
"fs-extra": "^9.0.1",
"glob": "^7.2.0",
"glob-latest": "npm:glob@^11.0.1",
"highlight.js": "^10.7.0",
"husky": "^9.0.1",
"inquirer": "^8.2.0",
Expand Down
56 changes: 56 additions & 0 deletions scripts/count_any_keywords.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {readFileSync} from 'fs';
import * as ts from 'typescript';
import {Glob} from 'glob-latest';

function countAnyKeywords(fileName: string): number {
const sourceFile = ts.createSourceFile(
fileName,
readFileSync(fileName).toString(),
ts.ScriptTarget.ES2022,
);

return countAnyKeywordsInNode(sourceFile);
}

function countAnyKeywordsInNode(node: ts.Node): number {
if (node.kind === ts.SyntaxKind.AnyKeyword) {
return 1;
}

let total = 0;
ts.forEachChild(node, child => void (total += countAnyKeywordsInNode(child)));

return total;
}

function printMap(map: ReadonlyMap<unknown, unknown>) {
for (const [k, v] of map.entries()) {
console.log(`${k}: ${v}`);
}
}

async function main() {
const tsFilesGlob = new Glob('src/**/*.ts', {});
const filesMap = new Map<string, number>();

for await (const path of tsFilesGlob) {
const count = countAnyKeywords(path);
if (count > 0) {
filesMap.set(path, count);
}
}

const total = Array.from(filesMap.values()).reduce((a, b) => a + b);
const specCount = Array.from(filesMap.entries())
.filter(([path]) => path.includes('spec.ts'))
.reduce((sum, [, count]) => sum + count, 0);

printMap(filesMap);

console.log('\n');
console.log('total:', total);
console.log('spec', specCount);
console.log('non-spec:', total - specCount);
}

main();
8 changes: 4 additions & 4 deletions src/google-maps/map-event-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ type MapEventManagerTarget =
| {
addListener: (
name: string,
callback: (...args: any[]) => void,
callback: (...args: unknown[]) => void,
) => google.maps.MapsEventListener | undefined;
}
| undefined;

/** Manages event on a Google Maps object, ensuring that events are added only when necessary. */
export class MapEventManager {
/** Pending listeners that were added before the target was set. */
private _pending: {observable: Observable<any>; observer: Subscriber<any>}[] = [];
private _pending: {observable: Observable<unknown>; observer: Subscriber<unknown>}[] = [];
private _listeners: google.maps.MapsEventListener[] = [];
private _targetStream = new BehaviorSubject<MapEventManagerTarget>(undefined);

Expand All @@ -48,8 +48,8 @@ export class MapEventManager {
return undefined;
}

const listener = target.addListener(name, (event: T) => {
this._ngZone.run(() => observer.next(event));
const listener = target.addListener(name, (event: unknown) => {
this._ngZone.run(() => observer.next(event as T));
});

// If there's an error when initializing the Maps API (e.g. a wrong API key), it will
Expand Down
8 changes: 4 additions & 4 deletions src/material-date-fns-adapter/adapter/date-fns-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class DateFnsAdapter extends DateAdapter<Date, Locale> {
return new Date();
}

parse(value: any, parseFormat: string | string[]): Date | null {
parse(value: unknown, parseFormat: string | string[]): Date | null {
if (typeof value == 'string' && value.length > 0) {
const iso8601Date = parseISO(value);

Expand Down Expand Up @@ -222,7 +222,7 @@ export class DateFnsAdapter extends DateAdapter<Date, Locale> {
* (https://www.ietf.org/rfc/rfc3339.txt) into valid Dates and empty string into null. Returns an
* invalid date for all other values.
*/
override deserialize(value: any): Date | null {
override deserialize(value: unknown): Date | null {
if (typeof value === 'string') {
if (!value) {
return null;
Expand All @@ -235,7 +235,7 @@ export class DateFnsAdapter extends DateAdapter<Date, Locale> {
return super.deserialize(value);
}

isDateInstance(obj: any): boolean {
isDateInstance(obj: unknown): obj is Date {
return isDate(obj);
}

Expand Down Expand Up @@ -277,7 +277,7 @@ export class DateFnsAdapter extends DateAdapter<Date, Locale> {
return getSeconds(date);
}

override parseTime(value: any, parseFormat: string | string[]): Date | null {
override parseTime(value: unknown, parseFormat: string | string[]): Date | null {
return this.parse(value, parseFormat);
}

Expand Down
82 changes: 41 additions & 41 deletions src/material-experimental/column-resize/column-resize.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ class ElementDataSource extends DataSource<PeriodicElement> {
}

// There's 1px of variance between different browsers in terms of positioning.
const approximateMatcher = {
const approximateMatcher: jasmine.CustomMatcherFactories = {
isApproximately: () => ({
compare: (actual: number, expected: number) => {
const result = {
Expand All @@ -348,6 +348,14 @@ const approximateMatcher = {
}),
};

interface NumberMatchers extends jasmine.Matchers<number> {
isApproximately(expected: number): void;
not: NumberMatchers;
}
declare global {
function expect(actual: number): NumberMatchers;
}

const testCases = [
[MatColumnResizeModule, MatResizeTest, 'opt-in table-based mat-table'],
[MatColumnResizeModule, MatResizeOnPushTest, 'inside OnPush component'],
Expand Down Expand Up @@ -409,12 +417,8 @@ describe('Material Popover Edit', () => {
component.getOverlayThumbElement(2).classList.contains('mat-column-resize-overlay-thumb'),
).toBe(true);

(expect(component.getOverlayThumbElement(0).offsetHeight) as any).isApproximately(
headerRowHeight,
);
(expect(component.getOverlayThumbElement(2).offsetHeight) as any).isApproximately(
headerRowHeight,
);
expect(component.getOverlayThumbElement(0).offsetHeight).isApproximately(headerRowHeight);
expect(component.getOverlayThumbElement(2).offsetHeight).isApproximately(headerRowHeight);

component.beginColumnResizeWithMouse(0);

Expand All @@ -425,15 +429,11 @@ describe('Material Popover Edit', () => {
component.getOverlayThumbElement(2).classList.contains('mat-column-resize-overlay-thumb'),
).toBe(true);

(expect(component.getOverlayThumbElement(0).offsetHeight) as any).isApproximately(
tableHeight,
);
(expect(component.getOverlayThumbTopElement(0).offsetHeight) as any).isApproximately(
headerRowHeight,
);
(expect(component.getOverlayThumbElement(2).offsetHeight) as any).isApproximately(
expect(component.getOverlayThumbElement(0).offsetHeight).isApproximately(tableHeight);
expect(component.getOverlayThumbTopElement(0).offsetHeight).isApproximately(
headerRowHeight,
);
expect(component.getOverlayThumbElement(2).offsetHeight).isApproximately(headerRowHeight);

component.completeResizeWithMouseInProgress(0);
component.endHoverState();
Expand Down Expand Up @@ -462,31 +462,31 @@ describe('Material Popover Edit', () => {
let columnPositionDelta = component.getColumnOriginPosition(1) - initialColumnPosition;
// let nextColumnPositionDelta =
// component.getColumnOriginPosition(2) - initialNextColumnPosition;
(expect(thumbPositionDelta) as any).isApproximately(columnPositionDelta);
expect(thumbPositionDelta).isApproximately(columnPositionDelta);
// TODO: This was commented out after switching from the legacy table to the current
// MDC-based table. This failed by being inaccurate by several pixels.
// (expect(nextColumnPositionDelta) as any).isApproximately(columnPositionDelta);
// expect(nextColumnPositionDelta).isApproximately(columnPositionDelta);

// TODO: This was commented out after switching from the legacy table to the current
// MDC-based table. This failed by being inaccurate by several pixels.
// (expect(component.getTableWidth()) as any).isApproximately(initialTableWidth + 5);
(expect(component.getColumnWidth(1)) as any).isApproximately(initialColumnWidth + 5);
// expect(component.getTableWidth()).isApproximately(initialTableWidth + 5);
expect(component.getColumnWidth(1)).isApproximately(initialColumnWidth + 5);

component.updateResizeWithMouseInProgress(1);
fixture.detectChanges();
flush();

thumbPositionDelta = component.getOverlayThumbPosition(1) - initialThumbPosition;
columnPositionDelta = component.getColumnOriginPosition(1) - initialColumnPosition;
(expect(thumbPositionDelta) as any).isApproximately(columnPositionDelta);
expect(thumbPositionDelta).isApproximately(columnPositionDelta);

(expect(component.getTableWidth()) as any).isApproximately(initialTableWidth + 1);
(expect(component.getColumnWidth(1)) as any).isApproximately(initialColumnWidth + 1);
expect(component.getTableWidth()).isApproximately(initialTableWidth + 1);
expect(component.getColumnWidth(1)).isApproximately(initialColumnWidth + 1);

component.completeResizeWithMouseInProgress(1);
flush();

(expect(component.getColumnWidth(1)) as any).isApproximately(initialColumnWidth + 1);
expect(component.getColumnWidth(1)).isApproximately(initialColumnWidth + 1);

component.endHoverState();
fixture.detectChanges();
Expand All @@ -508,23 +508,23 @@ describe('Material Popover Edit', () => {
flush();

let thumbPositionDelta = component.getOverlayThumbPosition(1) - initialThumbPosition;
(expect(thumbPositionDelta) as any).isApproximately(5);
(expect(component.getColumnWidth(1)) as any).toBe(initialColumnWidth);
expect(thumbPositionDelta).isApproximately(5);
expect(component.getColumnWidth(1)).toBe(initialColumnWidth);

component.updateResizeWithMouseInProgress(1);
fixture.detectChanges();
flush();

thumbPositionDelta = component.getOverlayThumbPosition(1) - initialThumbPosition;

(expect(component.getTableWidth()) as any).toBe(initialTableWidth);
(expect(component.getColumnWidth(1)) as any).toBe(initialColumnWidth);
expect(component.getTableWidth()).toBe(initialTableWidth);
expect(component.getColumnWidth(1)).toBe(initialColumnWidth);

component.completeResizeWithMouseInProgress(1);
flush();

(expect(component.getTableWidth()) as any).isApproximately(initialTableWidth + 1);
(expect(component.getColumnWidth(1)) as any).isApproximately(initialColumnWidth + 1);
expect(component.getTableWidth()).isApproximately(initialTableWidth + 1);
expect(component.getColumnWidth(1)).isApproximately(initialColumnWidth + 1);

component.endHoverState();
fixture.detectChanges();
Expand Down Expand Up @@ -562,18 +562,18 @@ describe('Material Popover Edit', () => {

let thumbPositionDelta = component.getOverlayThumbPosition(1) - initialThumbPosition;
let columnPositionDelta = component.getColumnOriginPosition(1) - initialColumnPosition;
(expect(thumbPositionDelta) as any).isApproximately(columnPositionDelta);
expect(thumbPositionDelta).isApproximately(columnPositionDelta);

(expect(component.getColumnWidth(1)) as any).isApproximately(initialColumnWidth + 5);
expect(component.getColumnWidth(1)).isApproximately(initialColumnWidth + 5);
// TODO: This was commented out after switching from the legacy table to the current
// MDC-based table. This failed by being inaccurate by several pixels.
// (expect(component.getTableWidth()) as any).isApproximately(initialTableWidth + 5);
// expect(component.getTableWidth()).isApproximately(initialTableWidth + 5);

dispatchKeyboardEvent(document, 'keyup', ESCAPE);
flush();

(expect(component.getColumnWidth(1)) as any).isApproximately(initialColumnWidth);
(expect(component.getTableWidth()) as any).isApproximately(initialTableWidth);
expect(component.getColumnWidth(1)).isApproximately(initialColumnWidth);
expect(component.getTableWidth()).isApproximately(initialTableWidth);

component.endHoverState();
fixture.detectChanges();
Expand All @@ -582,7 +582,7 @@ describe('Material Popover Edit', () => {
it('notifies subscribers of a completed resize via ColumnResizeNotifier', fakeAsync(() => {
const initialColumnWidth = component.getColumnWidth(1);

let resize: ColumnSize | null = null;
let resize: ColumnSize | null = null as ColumnSize | null;
component.columnResize.columnResizeNotifier.resizeCompleted.subscribe(size => {
resize = size;
});
Expand All @@ -596,7 +596,7 @@ describe('Material Popover Edit', () => {
fixture.detectChanges();
flush();

expect(resize).toEqual({columnId: 'name', size: initialColumnWidth + 5} as any);
expect(resize).toEqual({columnId: 'name', size: initialColumnWidth + 5});

component.endHoverState();
fixture.detectChanges();
Expand Down Expand Up @@ -626,12 +626,12 @@ describe('Material Popover Edit', () => {

it('performs a column resize triggered via ColumnResizeNotifier', fakeAsync(() => {
// Pre-verify that we are not updating the size to the initial size.
(expect(component.getColumnWidth(1)) as any).not.isApproximately(173);
expect(component.getColumnWidth(1)).not.isApproximately(173);

component.columnResize.columnResizeNotifier.resize('name', 173);
flush();

(expect(component.getColumnWidth(1)) as any).isApproximately(173);
expect(component.getColumnWidth(1)).isApproximately(173);
}));
});
}
Expand Down Expand Up @@ -660,13 +660,13 @@ describe('Material Popover Edit', () => {
}));

it('applies the persisted size', fakeAsync(() => {
(expect(component.getColumnWidth(1)).not as any).isApproximately(300);
expect(component.getColumnWidth(1)).not.isApproximately(300);

columnSizeStore.emitSize('theTable', 'name', 300);

flush();

(expect(component.getColumnWidth(1)) as any).isApproximately(300);
expect(component.getColumnWidth(1)).isApproximately(300);
}));

it('persists the user-triggered size update', fakeAsync(() => {
Expand All @@ -689,7 +689,7 @@ describe('Material Popover Edit', () => {
const {tableId, columnId, sizePx} = columnSizeStore.setSizeCalls[0];
expect(tableId).toBe('theTable');
expect(columnId).toBe('name');
(expect(sizePx) as any).isApproximately(initialColumnWidth + 5);
expect(sizePx).isApproximately(initialColumnWidth + 5);
}));

it('persists the user-triggered size update (live updates off)', fakeAsync(() => {
Expand All @@ -714,7 +714,7 @@ describe('Material Popover Edit', () => {
const {tableId, columnId, sizePx} = columnSizeStore.setSizeCalls[0];
expect(tableId).toBe('theTable');
expect(columnId).toBe('name');
(expect(sizePx) as any).isApproximately(initialColumnWidth + 5);
expect(sizePx).isApproximately(initialColumnWidth + 5);
}));
});
});
Expand Down
8 changes: 4 additions & 4 deletions src/material-luxon-adapter/adapter/luxon-date-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class LuxonDateAdapter extends DateAdapter<LuxonDateTime> {
return this._useUTC ? LuxonDateTime.utc(options) : LuxonDateTime.local(options);
}

parse(value: any, parseFormat: string | string[]): LuxonDateTime | null {
parse(value: unknown, parseFormat: string | string[]): LuxonDateTime | null {
const options: LuxonDateTimeOptions = this._getOptions();

if (typeof value == 'string' && value.length > 0) {
Expand Down Expand Up @@ -241,7 +241,7 @@ export class LuxonDateAdapter extends DateAdapter<LuxonDateTime> {
* (https://www.ietf.org/rfc/rfc3339.txt) and valid Date objects into valid DateTime and empty
* string into null. Returns an invalid date for all other values.
*/
override deserialize(value: any): LuxonDateTime | null {
override deserialize(value: unknown): LuxonDateTime | null {
const options = this._getOptions();
let date: LuxonDateTime | undefined;
if (value instanceof Date) {
Expand All @@ -259,7 +259,7 @@ export class LuxonDateAdapter extends DateAdapter<LuxonDateTime> {
return super.deserialize(value);
}

isDateInstance(obj: any): boolean {
isDateInstance(obj: unknown): obj is LuxonDateTime {
return obj instanceof LuxonDateTime;
}

Expand Down Expand Up @@ -311,7 +311,7 @@ export class LuxonDateAdapter extends DateAdapter<LuxonDateTime> {
return date.second;
}

override parseTime(value: any, parseFormat: string | string[]): LuxonDateTime | null {
override parseTime(value: unknown, parseFormat: string | string[]): LuxonDateTime | null {
const result = this.parse(value, parseFormat);

if ((!result || !this.isValid(result)) && typeof value === 'string') {
Expand Down
Loading
Loading