All files / src/custom-element/helpers getCustomElementMetadata.ts

84.62% Statements 11/13
66.67% Branches 4/6
50% Functions 1/2
84.62% Lines 11/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55    3x   9x                   9x   9x           43x   43x     43x                 43x           43x         43x         9x    
import { CustomElementMetadata } from "../interfaces";
 
export default function getCustomElementMetadata(ctor: any) {
 
    const metadata : CustomElementMetadata = {
        //component: {},
        properties: {},
        state: {}
    };
 
    // Set the shadow property
    //metadata.component.shadow = (ctor.component || {}).shadow === undefined ? true : ctor.component.shadow;
 
    // Merge the URL styles
    const set = new Set<string>(); // To avoid URL duplicates
 
    while (ctor !== HTMLElement) {
 
        const {
            component,
            properties,
            state
        } = ctor;
 
        const urls = (component || {}).styleUrls || [];
 
        // Merge the style urls
        urls.forEach(url => {
 
            if (!set.has(url)) {
 
                set.add(url);
            }
        });
 
        // Merge the property descriptors
        metadata.properties = {
            ...metadata.properties,
            ...properties
        };
 
        // Merge the state descriptor
        metadata.state = {
            ...metadata.state,
            ...state
        };
 
        ctor = Object.getPrototypeOf(ctor.prototype).constructor;
    }
 
    //metadata.component.styleUrls = Array.from(set);
 
    return metadata;
 
}