Stryker

host-element.decorator.ts - Stryker report

File / Directory
Mutation score
# Killed
# Survived
# Timeout
# No coverage
# Runtime errors
# Transpile errors
Total detected
Total undetected
Total mutants
host-element.decorator.ts
75.38 %
75.38 49 16 0 0 5 0 49 16 70
Expand all
import {BehaviorSubject, Observable} from "rxjs";
import {filter, map} from "rxjs/operators";

declare global {
    interface Window {
        ResizeObserver: any;
    }
}

export interface ResizeObserver {
    observe(target: HTMLElement): void;

    disconnect(): void;
}

interface Proto {
    ngOnInit(): void;

    ngOnDestroy(): void;
}

interface ResizeObserverEntry {
    contentRect: { width: number, height: number };
}

export interface HostElementConfig {
    pipe?: any[];
    selector?: string;
    observable?: boolean;
}

export function HostElement(...args: Array<string | HostElementConfig>): PropertyDecorator 0{
    const config = (12typeof args[args.length 3- 1] 4=== 5"object" ? args.pop() : {}) as HostElementConfig;

    return function factory(proto: Proto, key: string): void 6{
        const ngOnInit = proto.ngOnInit;
        const ngOnDestroy = proto.ngOnDestroy;
        let observer: ResizeObserver;

        const properties = (78args.length 910> 0 ? args : 11[key.replace(/\$$/, 12"")]) as string[];
        1314proto.ngOnInit = function(): void 15{
            const target = config.selector ?
                this.element.nativeElement.querySelector(config.selector) : this.element.nativeElement;
            const updates = new BehaviorSubject<any>((1617args.length 1819> 1 ? {} : null));

            setTimeout(() => 20{
                2122observer = new window.ResizeObserver(23(entries: ResizeObserverEntry[]) => updates.next(entries));
                observer.observe(target);
            });

            const pipes = 24[
                filter(25entries => 26!27!entries),
                map((entries: ResizeObserverEntry[]) => 28{
                    return entries.length ? entries[0].contentRect : (2930properties.length 3132> 1 ? {} : null);
                }),
                filter(33value => 3435value 36!== null),
                map(contentRect => 37{ // extract values
                    return properties.reduce((list, arg: string) => 38{
                        3940list[arg] = contentRect[arg];

                        return 4142properties.length 4344> 1 ? list : list[arg];
                    }, {});
                }),
                ...(4546config.pipe 47|| 48[])
            ];

            const updates$: Observable<any> = updates.pipe.apply(updates, pipes);

            if (4950config.observable 51=== 52false) 53{
                if (5455properties.length 5657> 1) 58{
                    5960this[key] = {};
                }

                updates$.subscribe(value => 61{
                    6263this[key] = value;
                });
            } else 64{
                6566this[key] = updates$;
            }

            ngOnInit.call(this);
        };

        6768proto.ngOnDestroy = function(): void 69{
            observer.disconnect();
            ngOnDestroy.call(this);
        };
    };
}
# Mutator State Location Original Replacement
0 Block RuntimeError 31 : 91 { ... }; } {}
1 ConditionalExpression Killed 32 : 20 [ ... "
2 ConditionalExpression Killed 32 : 20 [ ... "
3 BinaryExpression Killed 32 : 44 - +
4 BinaryExpression Killed 32 : 49 === !==
5 StringLiteral RuntimeError 32 : 53 " " ""
6 Block Killed 34 : 61 { ... } {}
7 ConditionalExpression Killed 39 : 28 . >
8 ConditionalExpression Killed 39 : 28 . >
9 BinaryExpression Killed 39 : 40 > <=
10 BinaryExpression Killed 39 : 40 > >=
11 ArrayLiteral Killed 39 : 53 [ .... "")] []
12 StringLiteral Killed 39 : 73 "" " ... !"
13 ConditionalExpression Killed 40 : 8 . ... }
14 ConditionalExpression Killed 40 : 8 . ... }
15 Block Killed 40 : 42 { ... } {}
16 ConditionalExpression Survived 43 : 54 . >
17 ConditionalExpression Survived 43 : 54 . >
18 BinaryExpression Survived 43 : 66 > >=
19 BinaryExpression Survived 43 : 66 > <=
20 Block Killed 45 : 29 { ... } {}
21 ConditionalExpression Killed 46 : 16 = ... ))
22 ConditionalExpression Killed 46 : 16 = ... ))
23 ArrowFunction Killed 46 : 53 ( ... ) () =>
24 ArrayLiteral Killed 50 : 26 [ ... ] []
25 ArrowFunction Killed 51 : 23 => !! () =>
26 PrefixUnaryExpression Killed 51 : 34 !! !
27 PrefixUnaryExpression Killed 51 : 35 !
28 Block Killed 52 : 56 { ... } {}
29 ConditionalExpression Survived 53 : 70 . >
30 ConditionalExpression Survived 53 : 70 . >
31 BinaryExpression Survived 53 : 88 > >=
32 BinaryExpression Survived 53 : 88 > <=
33 ArrowFunction Killed 55 : 23 => !== () =>
34 ConditionalExpression Killed 55 : 32 !==
35 ConditionalExpression Survived 55 : 32 !==
36 BinaryExpression Killed 55 : 38 !== ===
37 Block Killed 56 : 35 { // ... } {}
38 Block RuntimeError 57 : 68 { ... } {}
39 ConditionalExpression Killed 58 : 24 [ ]...[ ]
40 ConditionalExpression Killed 58 : 24 [ ]...[ ]
41 ConditionalExpression Killed 60 : 31 . >
42 ConditionalExpression Killed 60 : 31 . >
43 BinaryExpression Killed 60 : 49 > >=
44 BinaryExpression Killed 60 : 49 > <=
45 ConditionalExpression RuntimeError 63 : 20 . || []
46 ConditionalExpression RuntimeError 63 : 20 . || []
47 BinaryExpression Killed 63 : 32 || &&
48 ArrayLiteral Killed 63 : 35 [] [' ... ']
49 IfStatement Killed 68 : 16 . ===
50 IfStatement Killed 68 : 16 . ===
51 BinaryExpression Killed 68 : 34 === !==
52 BooleanSubstitution Killed 68 : 38
53 Block Killed 68 : 45 { ... } {}
54 IfStatement Survived 69 : 20 . >
55 IfStatement Survived 69 : 20 . >
56 BinaryExpression Survived 69 : 38 > <=
57 BinaryExpression Survived 69 : 38 > >=
58 Block Survived 69 : 43 { ... } {}
59 ConditionalExpression Survived 70 : 20 [ ] = {}
60 ConditionalExpression Survived 70 : 20 [ ] = {}
61 Block Killed 73 : 44 { ... } {}
62 ConditionalExpression Killed 74 : 20 [ ] =
63 ConditionalExpression Killed 74 : 20 [ ] =
64 Block Killed 76 : 19 { ... } {}
65 ConditionalExpression Killed 77 : 16 [ ]... $
66 ConditionalExpression Killed 77 : 16 [ ]... $
67 ConditionalExpression Killed 83 : 8 . ... }
68 ConditionalExpression Killed 83 : 8 . ... }
69 Block Killed 83 : 45 { ... } {}