Stryker

route.decorators.ts - Stryker report

File / Directory
Mutation score
# Killed
# Survived
# Timeout
# No coverage
# Runtime errors
# Transpile errors
Total detected
Total undetected
Total mutants
route.decorators.ts
98.39 %
98.39 58 1 3 0 12 0 61 1 74
Expand all
import { OperatorFunction, Observable } from 'rxjs';
import { map } from 'rxjs/operators';

export interface RouteXxlConfig {
    observable?: boolean;
    pipe?: Array<OperatorFunction<any, any>>;
    inherit?: boolean;
}

/**
 * Traverses the routes, from the current route all the way up to the
 * root route and stores each for the route data, params or queryParams observable
 *
 * @param {ActivatedRoute} parent
 * @param {string} routeProperty
 * @returns {Observable<Data | Params>[]}
 */
function extractRoute(parent: any, routeProperty: string, inherit = 0false): Observable<any> 1{
    if (23inherit) 4{
        // Move up to the highest level
        while (5parent.firstChild) 6{
            78parent = parent.firstChild;
        }
    }

    return parent[routeProperty];
}

/**
 * Merge all observables from {@link extractRoutes} into a single stream passing through only the data/params
 * of decorator. Depending on how the decorator was initialized (`{observable: false}`) the observable or the actual
 * values are passed into the callback.
 *
 * @param {Observable<Data | Params>[]} routes
 * @param {string[]} args list of the decorator's arguments
 * @param {RouteConfigXxl} config the decorator's configuration object
 * @param {(Observable<any> | any) => void} cb callback function receiving the final observable or the actual values
 *        * as its arguments
 */
function extractValues(args: string[], stream$: Observable<any>): Observable<any> 9{
    return stream$.pipe(
        map(routeValues => 10{
            const values = args.reduce((data, arg) => 11{
                if (1213routeValues 14&& routeValues[arg]) 15{
                    1617data[arg] = routeValues[arg];
                }

                return data;
            }, {});

            return 1819args.length 20=== 1 ? values[args[0]] : values;
        }),
    );
}

/**
 * Factory function which creates decorators for resolved route data, route params or query parameters.
 *
 * @param {string} routeProperty used to create a data, params or queryParams decorator function
 * @returns {(...args: string | RouteXxlConfig[]) => PropertyDecorator}
 */
function routeDecoratorFactory(routeProperty, args, extractor?): PropertyDecorator 21{
    const config = (2223typeof args[args.length 24- 1] 25=== 26'object' ? args.pop() : {}) as RouteXxlConfig;

    return (prototype: { ngOnInit(): void }, key: string): void => 27{
        if (282930!args.length) 31{
            3233args = 34[key.replace(/\$$/, 35'')];
        }

        // `ngOnInit` should exist on the component, otherwise the decorator will not work with the AOT compiler!!
        if (363738!prototype.ngOnInit) 39{
            throw (new Error(40`${prototype.constructor.name} uses the ${routeProperty} @decorator without implementing 'ngOnInit'`));
        }

        const ngOnInit = prototype.ngOnInit;

        4142prototype.ngOnInit = function(): void 43{
            // Finally we have the instance!!
            if (444546!this.route) 47{
                throw (new Error(48`${this.constructor.name} uses a route-xxl @decorator without a 'route: ActivatedRoute' property`));
            }

            let stream$ = extractor(this.route, routeProperty, config.inherit);
            4950stream$ = extractValues(args, stream$);

            if (5152config.pipe) 53{
                5455stream$ = stream$.pipe(...config.pipe);
            }

            if (5657config.observable 58=== 59false) 60{
                stream$.subscribe(data => 61{
                    6263this[key] = data;
                });
            } else 64{
                6566this[key] = stream$;
            }

            ngOnInit.call(this);
        };
    };
}

/*
The factory is wrapped in a function for the AOT compiler
 */
export function RouteData(...args: Array<string | RouteXxlConfig>): PropertyDecorator 67{
    return routeDecoratorFactory(68'data', args, extractRoute);
}

export function RouteParams(...args: Array<string | RouteXxlConfig>): PropertyDecorator 69{
    return routeDecoratorFactory(70'params', args, extractRoute);
}

export function RouteQueryParams(...args: Array<string | RouteXxlConfig>): PropertyDecorator 71{
    return routeDecoratorFactory(72'queryParams', args, 73route => route.queryParams);
}
# Mutator State Location Original Replacement
0 BooleanSubstitution Killed 17 : 68
1 Block RuntimeError 17 : 92 { ... ]; } {}
2 IfStatement Killed 18 : 8
3 IfStatement Killed 18 : 8
4 Block Killed 18 : 17 { ... } {}
5 WhileStatement Killed 20 : 15 .
6 Block TimedOut 20 : 34 { ... } {}
7 ConditionalExpression TimedOut 21 : 12 = .
8 ConditionalExpression TimedOut 21 : 12 = .
9 Block RuntimeError 39 : 82 { ... ); } {}
10 Block Killed 41 : 27 { ... } {}
11 Block RuntimeError 42 : 54 { ... } {}
12 IfStatement Killed 43 : 20 && ...[ ]
13 IfStatement Killed 43 : 20 && ...[ ]
14 BinaryExpression Killed 43 : 32 && ||
15 Block Killed 43 : 53 { ... } {}
16 ConditionalExpression Killed 44 : 20 [ ]...[ ]
17 ConditionalExpression Killed 44 : 20 [ ]...[ ]
18 ConditionalExpression Killed 50 : 19 . ===
19 ConditionalExpression Killed 50 : 19 . ===
20 BinaryExpression Killed 50 : 31 === !==
21 Block RuntimeError 61 : 83 { ... }; } {}
22 ConditionalExpression Killed 62 : 20 [ ... '
23 ConditionalExpression Killed 62 : 20 [ ... '
24 BinaryExpression Killed 62 : 44 - +
25 BinaryExpression Killed 62 : 49 === !==
26 StringLiteral RuntimeError 62 : 53 ' ' ""
27 Block Killed 64 : 67 { ... } {}
28 IfStatement Killed 65 : 12 ! .
29 IfStatement Killed 65 : 12 ! .
30 PrefixUnaryExpression Killed 65 : 12 ! . .
31 Block Killed 65 : 26 { ... } {}
32 ConditionalExpression Killed 66 : 12 = [ ... '')]
33 ConditionalExpression Killed 66 : 12 = [ ... '')]
34 ArrayLiteral Killed 66 : 19 [ .... '')] []
35 StringLiteral Killed 66 : 39 '' " ... !"
36 IfStatement Killed 70 : 12 ! .
37 PrefixUnaryExpression Killed 70 : 12 ! . .
38 IfStatement Killed 70 : 12 ! .
39 Block Killed 70 : 33 { ... } {}
40 StringLiteral Killed 71 : 29 `${ ... '` ""
41 ConditionalExpression Killed 76 : 8 . ... }
42 ConditionalExpression Killed 76 : 8 . ... }
43 Block Killed 76 : 46 { ... } {}
44 IfStatement Killed 78 : 16 ! .
45 PrefixUnaryExpression Killed 78 : 16 ! . .
46 IfStatement Killed 78 : 16 ! .
47 Block Killed 78 : 29 { ... } {}
48 StringLiteral Killed 79 : 33 `${ ... ` ""
49 ConditionalExpression Killed 83 : 12 $ = ... $)
50 ConditionalExpression Killed 83 : 12 $ = ... $)
51 IfStatement Survived 85 : 16 .
52 IfStatement RuntimeError 85 : 16 .
53 Block RuntimeError 85 : 29 { ... } {}
54 ConditionalExpression RuntimeError 86 : 16 $ = ... )
55 ConditionalExpression RuntimeError 86 : 16 $ = ... )
56 IfStatement Killed 89 : 16 . ===
57 IfStatement Killed 89 : 16 . ===
58 BinaryExpression Killed 89 : 34 === !==
59 BooleanSubstitution Killed 89 : 38
60 Block Killed 89 : 45 { ... } {}
61 Block Killed 90 : 42 { ... } {}
62 ConditionalExpression Killed 91 : 20 [ ] =
63 ConditionalExpression Killed 91 : 20 [ ] =
64 Block Killed 93 : 19 { ... } {}
65 ConditionalExpression Killed 94 : 16 [ ] = $
66 ConditionalExpression Killed 94 : 16 [ ] = $
67 Block RuntimeError 105 : 86 { ... ); } {}
68 StringLiteral Killed 106 : 33 ' ' ""
69 Block RuntimeError 109 : 88 { ... ); } {}
70 StringLiteral Killed 110 : 33 ' ' ""
71 Block RuntimeError 113 : 93 { ... ); } {}
72 StringLiteral Killed 114 : 33 ' ' ""
73 ArrowFunction Killed 114 : 54 => . () =>