UNPKG

buildtypedefs

Version:

This is a utility that transforms code documented with getdocs-style doc comments into TypeScript definition files

77 lines 3.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const function_1 = require("./function"); const type_1 = require("./type"); const object_1 = require("./object"); const import_1 = require("./import"); function default_1(sb, item, skipOptional, skipColon, isParam, items, imports, additionalTypes, useDummyName = true) { switch (item.type) { case "Function": function_1.default(sb, item, items, imports, isParam, additionalTypes, useDummyName); break; case "Array": if (!skipOptional && item.optional) sb.append("?"); if (item.typeParams[0].type == "Function") { sb.append(": ("); function_1.default(sb, item.typeParams[0], items, imports, true, additionalTypes, false); sb.append(")"); } else { type_1.default(sb, item.typeParams[0], false, skipColon, false, items, imports, additionalTypes); } sb.append("[]"); break; case "union": if (!skipOptional && item.optional) sb.append("?"); if (isParam || /\^returns$/.test(item.id) || !skipColon) { sb.append(": "); } for (let i in item.typeParams) { if (i != "0") sb.append(" | "); if (item.typeParams[i].type == "Function") { sb.append("("); type_1.default(sb, item.typeParams[i], false, true, true, items, imports, additionalTypes, false); sb.append(")"); } else { type_1.default(sb, item.typeParams[i], false, true, true, items, imports, additionalTypes); } } break; case "Object": object_1.default(sb, item, skipColon, items, imports, additionalTypes); break; default: import_1.default(item.type, items, imports, additionalTypes); if (!skipOptional && item.optional) sb.append("?"); if (!skipColon) sb.append(": "); switch (item.type) { case "bool": sb.append("boolean"); break; default: if (additionalTypes[item.type]) sb.append(additionalTypes[item.type].replacement); else sb.append(item.type); break; } if (item.typeParams) { sb.append("<"); for (let i in item.typeParams) { if (i != "0") sb.append(", "); type_1.default(sb, item.typeParams[i], false, true, true, items, imports, additionalTypes); } sb.append(">"); } break; } } exports.default = default_1; //# sourceMappingURL=type.js.map