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.41 %
75.41 46 15 0 0 8 0 46 15 69
Expand all
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { Observable } from 'rxjs/Observable';
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 Array<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 updates$: Observable<any> = updates.pipe(
                filter(24entries => 25!26!entries),
                map((entries: ResizeObserverEntry[]) => 27{
                    return entries.length ? entries[0].contentRect : (2829properties.length 3031> 1 ? {} : null);
                }),
                filter(32value => 3334value 35!== null),
                map(contentRect => 36{ // extract values
                    return properties.reduce((list, arg: string) => 37{
                        3839list[arg] = contentRect[arg];

                        return 4041properties.length 4243> 1 ? list : list[arg];
                    }, {});
                }),
                ...(4445config.pipe 46|| 47[]),
            );

            if (4849config.observable 50=== 51false) 52{
                if (5354properties.length 5556> 1) 57{
                    5859this[key] = {};
                }

                updates$.subscribe(value => 60{
                    6162this[key] = value;
                });
            } else 63{
                6465this[key] = updates$;
            }

            ngOnInit.call(this);
        };

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