當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript webidl2.parse函數代碼示例

本文整理匯總了TypeScript中webidl2.parse函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript parse函數的具體用法?TypeScript parse怎麽用?TypeScript parse使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了parse函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: convert

export function convert(text: string, commentMap: Record<string, string>) {
    const rootTypes = webidl2.parse(text);
    const partialInterfaces: Browser.Interface[] = [];
    const partialMixins: Browser.Interface[] = [];
    const partialDictionaries: Browser.Dictionary[] = [];
    const includes: webidl2.IncludesType[] = [];
    const browser = getEmptyWebIDL();
    for (const rootType of rootTypes) {
        if (rootType.type === "interface") {
            const converted = convertInterface(rootType, commentMap);
            if (rootType.partial) {
                partialInterfaces.push(converted);
            }
            else {
                browser.interfaces!.interface[rootType.name] = converted;
            }
        }
        else if (rootType.type === "interface mixin") {
            const converted = convertInterfaceMixin(rootType, commentMap);
            if (rootType.partial) {
                partialMixins.push(converted);
            }
            else {
                browser["mixins"]!.mixin[rootType.name] = converted;
            }
        }
        else if (rootType.type === "callback interface") {
            browser["callback-interfaces"]!.interface[rootType.name] = convertInterface(rootType, commentMap);
        }
        else if (rootType.type === "callback") {
            browser["callback-functions"]!["callback-function"][rootType.name]
                = convertCallbackFunctions(rootType);
            addComments(browser["callback-functions"]!["callback-function"][rootType.name], commentMap, rootType.name);
        }
        else if (rootType.type === "dictionary") {
            const converted = convertDictionary(rootType, commentMap);
            if (rootType.partial) {
                partialDictionaries.push(converted);
            }
            else {
                browser.dictionaries!.dictionary[rootType.name] = converted;
            }
        }
        else if (rootType.type === "enum") {
            browser.enums!.enum[rootType.name] = convertEnum(rootType);
        }
        else if (rootType.type === "typedef") {
            browser.typedefs!.typedef.push(convertTypedef(rootType));
        }
        else if (rootType.type === "includes") {
            includes.push(rootType);
        }
    }
    return { browser, partialInterfaces, partialMixins, partialDictionaries, includes };
}
開發者ID:YuichiNukiyama,項目名稱:TSJS-lib-generator,代碼行數:55,代碼來源:widlprocess.ts

示例2: switch

import * as webidl2 from "webidl2";

const parsed = webidl2.parse("");

for (const rootType of parsed) {
    if (rootType.type !== "implements" && rootType.type !== "includes") {
        console.log(rootType.name);
    }
    switch (rootType.type) {
        case "interface":
            console.log(rootType.inheritance);
            logMembers(rootType.members);
            console.log(rootType.partial);
            break;
        case "interface mixin":
            logMembers(rootType.members);
            console.log(rootType.partial);
            break;
        case "namespace":
            console.log(rootType.partial);
            logNamespaceMembers(rootType.members);
            break;
        case "callback interface":
            logMembers(rootType.members);
            console.log(rootType.partial);
            break;
        case "callback":
            logArguments(rootType.arguments);
            break;
        case "dictionary":
            console.log(rootType.inheritance);
開發者ID:Dru89,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:webidl2-tests.ts

示例3: exportIDLSnippets

function exportIDLSnippets(idlTexts: string[], origin: FetchResult) {
    const snippets: IDLSnippetContent[] = [];

    for (const item of idlTexts) {
        try {
            const snippet = createIDLSnippetContentContainer();
            const parsed = WebIDL2.parse(item);
            const implementsMap = new Map<string, Element[]>();

            for (const rootItem of parsed) {
                /*
                implements: if the IDL snippet has target interface or partial interface, then insert <implements> into it
                if not, create a new partial interface that contains <implements>
                */
                if (rootItem.type === "implements") {
                    const implementEl = document.createElement("implements");
                    implementEl.textContent = rootItem.implements;
                    if (!implementsMap.has(rootItem.target)) {
                        implementsMap.set(rootItem.target, [implementEl]);
                    }
                    else {
                        implementsMap.get(rootItem.target).push(implementEl);
                    }
                }
                else {
                    insert(rootItem, snippet);
                }
            }

            for (const entry of implementsMap.entries()) {
                let interfaceEl = snippet.interfaces.filter(item => item.getAttribute("name") === entry[0])[0];
                if (!interfaceEl) {
                    interfaceEl = document.createElement("interface");
                    interfaceEl.setAttribute("name", entry[0]);
                    // temp: absence of 'extends' causes incorrect interface declaration on TSJS-lib-generator
                    interfaceEl.setAttribute("extends", "Object");
                    interfaceEl.setAttribute("no-interface-object", "1");
                    interfaceEl.setAttribute("sn:partial", "1");
                    snippet.interfaces.push(interfaceEl);
                }

                for (const implementsEl of entry[1]) {
                    interfaceEl.appendChild(implementsEl);
                }
            }

            snippets.push(snippet);
        }
        catch (err) {
            if (isWebIDLParseError(err)) {
                console.warn(`A syntax error has found in a WebIDL code line ${err.line} from ${origin.description.url}:\n${err.message}\n${err.input}\n`);
            }
            else {
                err.message = `An error occured while converting WebIDL from ${origin.description.url}: ${err.message}`;
                throw err;
            }
        }
    }

    return snippets;
}
開發者ID:SaschaNaz,項目名稱:webxml,代碼行數:61,代碼來源:webxml.ts


注:本文中的webidl2.parse函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。