当前位置: 首页>>代码示例>>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;未经允许,请勿转载。