UNPKG

storybook

Version:

Storybook: Develop, document, and test UI components in isolation

1,489 lines (1,488 loc) • 95 kB
var dr = Object.create; var Ie = Object.defineProperty; var Tr = Object.getOwnPropertyDescriptor; var gr = Object.getOwnPropertyNames; var xr = Object.getPrototypeOf, hr = Object.prototype.hasOwnProperty; var r = (n, s) => Ie(n, "name", { value: s, configurable: !0 }); var Jr = (n, s) => () => (s || n((s = { exports: {} }).exports, s), s.exports); var wr = (n, s, a, p) => { if (s && typeof s == "object" || typeof s == "function") for (let c of gr(s)) !hr.call(n, c) && c !== a && Ie(n, c, { get: () => s[c], enumerable: !(p = Tr(s, c)) || p.enumerable }); return n; }; var Pr = (n, s, a) => (a = n != null ? dr(xr(n)) : {}, wr( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. s || !n || !n.__esModule ? Ie(a, "default", { value: n, enumerable: !0 }) : a, n )); // ../node_modules/jsdoc-type-pratt-parser/dist/index.js var dt = Jr((fe, yt) => { (function(n, s) { typeof fe == "object" && typeof yt < "u" ? s(fe) : typeof define == "function" && define.amd ? define(["exports"], s) : (n = typeof globalThis < "u" ? globalThis : n || self, s(n.jtpp = {})); })(fe, function(n) { "use strict"; function s(e) { return e.text !== void 0 && e.text !== "" ? `'${e.type}' with value '${e.text}'` : `'${e.type}'`; } r(s, "tokenToString"); let ne = class ne extends Error { constructor(t) { super(`No parslet found for token: ${s(t)}`), this.token = t, Object.setPrototypeOf(this, ne.prototype); } getToken() { return this.token; } }; r(ne, "NoParsletFoundError"); let a = ne, oe = class oe extends Error { constructor(t) { super(`The parsing ended early. The next token was: ${s(t)}`), this.token = t, Object.setPrototypeOf(this, oe.prototype); } getToken() { return this.token; } }; r(oe, "EarlyEndOfParseError"); let p = oe, se = class se extends Error { constructor(t, o) { let i = `Unexpected type: '${t.type}'.`; o !== void 0 && (i += ` Message: ${o}`), super(i), Object.setPrototypeOf(this, se.prototype); } }; r(se, "UnexpectedTypeError"); let c = se; function u(e) { return (t) => t.startsWith(e) ? { type: e, text: e } : null; } r(u, "makePunctuationRule"); function m(e) { let t = 0, o, i = e[0], l = !1; if (i !== "'" && i !== '"') return null; for (; t < e.length; ) { if (t++, o = e[t], !l && o === i) { t++; break; } l = !l && o === "\\"; } if (o !== i) throw new Error("Unterminated String"); return e.slice(0, t); } r(m, "getQuoted"); let T = new RegExp("[$_\\p{ID_Start}]|\\\\u\\p{Hex_Digit}{4}|\\\\u\\{0*(?:\\p{Hex_Digit}{1,5}|10\\p{Hex_Digit}{4})\\}", "u"), g = new RegExp( "[$\\-\\p{ID_Continue}\\u200C\\u200D]|\\\\u\\p{Hex_Digit}{4}|\\\\u\\{0*(?:\\p{Hex_Digit}{1,5}|10\\p{Hex_Digit}{4})\\}", "u"); function P(e) { let t = e[0]; if (!T.test(t)) return null; let o = 1; do { if (t = e[o], !g.test(t)) break; o++; } while (o < e.length); return e.slice(0, o); } r(P, "getIdentifier"); let b = /^(NaN|-?((\d*\.\d+|\d+)([Ee][+-]?\d+)?|Infinity))/; function de(e) { var t, o; return (o = (t = b.exec(e)) === null || t === void 0 ? void 0 : t[0]) !== null && o !== void 0 ? o : null; } r(de, "getNumber"); let q = /* @__PURE__ */ r((e) => { let t = P(e); return t == null ? null : { type: "Identifier", text: t }; }, "identifierRule"); function S(e) { return (t) => { if (!t.startsWith(e)) return null; let o = t[e.length]; return o !== void 0 && g.test(o) ? null : { type: e, text: e }; }; } r(S, "makeKeyWordRule"); let z = /* @__PURE__ */ r((e) => { let t = m(e); return t == null ? null : { type: "StringValue", text: t }; }, "stringValueRule"), Te = /* @__PURE__ */ r((e) => e.length > 0 ? null : { type: "EOF", text: "" }, "eofRule"), ge = /* @__PURE__ */ r((e) => { let t = de(e); return t === null ? null : { type: "Number", text: t }; }, "numberRule"), Rt = [ Te, u("=>"), u("("), u(")"), u("{"), u("}"), u("["), u("]"), u("|"), u("&"), u("<"), u(">"), u(","), u(";"), u("*"), u("?"), u("!"), u("="), u(":"), u("..."), u("."), u("#"), u("~"), u("/"), u("@"), S("undefined"), S("null"), S("function"), S("this"), S("new"), S("module"), S("event"), S("external"), S("typeof"), S("keyof"), S("readonly"), S("import"), S("is"), S("in"), S("asserts"), ge, q, z ], jt = /^\s*\n\s*/, U = class U { static create(t) { let o = this.read(t); t = o.text; let i = this.read(t); return t = i.text, new U(t, void 0, o.token, i.token); } constructor(t, o, i, l) { this.text = "", this.text = t, this.previous = o, this.current = i, this.next = l; } static read(t, o = !1) { o = o || jt.test(t), t = t.trim(); for (let i of Rt) { let l = i(t); if (l !== null) { let f = Object.assign(Object.assign({}, l), { startOfLine: o }); return t = t.slice(f.text.length), { text: t, token: f }; } } throw new Error("Unexpected Token " + t); } advance() { let t = U.read(this.text); return new U(t.text, this.current, this.next, t.token); } }; r(U, "Lexer"); let xe = U; function J(e) { if (e === void 0) throw new Error("Unexpected undefined"); if (e.type === "JsdocTypeKeyValue" || e.type === "JsdocTypeParameterList" || e.type === "JsdocTypeProperty" || e.type === "JsdocTypeRe\ adonlyProperty" || e.type === "JsdocTypeObjectField" || e.type === "JsdocTypeJsdocObjectField" || e.type === "JsdocTypeIndexSignature" || e. type === "JsdocTypeMappedType") throw new c(e); return e; } r(J, "assertRootResult"); function he(e) { return e.type === "JsdocTypeKeyValue" ? H(e) : J(e); } r(he, "assertPlainKeyValueOrRootResult"); function Ft(e) { return e.type === "JsdocTypeName" ? e : H(e); } r(Ft, "assertPlainKeyValueOrNameResult"); function H(e) { if (e.type !== "JsdocTypeKeyValue") throw new c(e); return e; } r(H, "assertPlainKeyValueResult"); function _t(e) { var t; if (e.type === "JsdocTypeVariadic") { if (((t = e.element) === null || t === void 0 ? void 0 : t.type) === "JsdocTypeName") return e; throw new c(e); } if (e.type !== "JsdocTypeNumber" && e.type !== "JsdocTypeName") throw new c(e); return e; } r(_t, "assertNumberOrVariadicNameResult"); function Je(e) { return e.type === "JsdocTypeIndexSignature" || e.type === "JsdocTypeMappedType"; } r(Je, "isSquaredProperty"); var y; (function(e) { e[e.ALL = 0] = "ALL", e[e.PARAMETER_LIST = 1] = "PARAMETER_LIST", e[e.OBJECT = 2] = "OBJECT", e[e.KEY_VALUE = 3] = "KEY_VALUE", e[e.INDEX_BRACKETS = 4] = "INDEX_BRACKETS", e[e.UNION = 5] = "UNION", e[e.INTERSECTION = 6] = "INTERSECTION", e[e.PREFIX = 7] = "PREFIX", e[e.INFIX = 8] = "\ INFIX", e[e.TUPLE = 9] = "TUPLE", e[e.SYMBOL = 10] = "SYMBOL", e[e.OPTIONAL = 11] = "OPTIONAL", e[e.NULLABLE = 12] = "NULLABLE", e[e.KEY_OF_TYPE_OF = 13] = "KEY_OF_TYPE_OF", e[e.FUNCTION = 14] = "FUNCTION", e[e.ARROW = 15] = "ARROW", e[e.ARRAY_BRACKETS = 16] = "ARRAY_BRACKETS", e[e.GENERIC = 17] = "GENERIC", e[e.NAME_PATH = 18] = "NAME_PATH", e[e.PARENTHESIS = 19] = "PARENTHESIS", e[e.SPECIAL_TYPES = 20] = "SPECIAL_TYPES"; })(y || (y = {})); let Ae = class Ae { constructor(t, o, i) { this.grammar = t, typeof o == "string" ? this._lexer = xe.create(o) : this._lexer = o, this.baseParser = i; } get lexer() { return this._lexer; } /** * Parses a given string and throws an error if the parse ended before the end of the string. */ parse() { let t = this.parseType(y.ALL); if (this.lexer.current.type !== "EOF") throw new p(this.lexer.current); return t; } /** * Parses with the current lexer and asserts that the result is a {@link RootResult}. */ parseType(t) { return J(this.parseIntermediateType(t)); } /** * The main parsing function. First it tries to parse the current state in the prefix step, and then it continues * to parse the state in the infix step. */ parseIntermediateType(t) { let o = this.tryParslets(null, t); if (o === null) throw new a(this.lexer.current); return this.parseInfixIntermediateType(o, t); } /** * In the infix parsing step the parser continues to parse the current state with all parslets until none returns * a result. */ parseInfixIntermediateType(t, o) { let i = this.tryParslets(t, o); for (; i !== null; ) t = i, i = this.tryParslets(t, o); return t; } /** * Tries to parse the current state with all parslets in the grammar and returns the first non null result. */ tryParslets(t, o) { for (let i of this.grammar) { let l = i(this, o, t); if (l !== null) return l; } return null; } /** * If the given type equals the current type of the {@link Lexer} advance the lexer. Return true if the lexer was * advanced. */ consume(t) { return Array.isArray(t) || (t = [t]), t.includes(this.lexer.current.type) ? (this._lexer = this.lexer.advance(), !0) : !1; } acceptLexerState(t) { this._lexer = t.lexer; } }; r(Ae, "Parser"); let I = Ae; function Ye(e) { return e === "EOF" || e === "|" || e === "," || e === ")" || e === ">"; } r(Ye, "isQuestionMarkUnknownType"); let we = /* @__PURE__ */ r((e, t, o) => { let i = e.lexer.current.type, l = e.lexer.next.type; return o == null && i === "?" && !Ye(l) || o != null && i === "?" ? (e.consume("?"), o == null ? { type: "JsdocTypeNullable", element: e.parseType(y.NULLABLE), meta: { position: "prefix" } } : { type: "JsdocTypeNullable", element: J(o), meta: { position: "suffix" } }) : null; }, "nullableParslet"); function x(e) { let t = /* @__PURE__ */ r((o, i, l) => { let f = o.lexer.current.type, d = o.lexer.next.type; if (l === null) { if ("parsePrefix" in e && e.accept(f, d)) return e.parsePrefix(o); } else if ("parseInfix" in e && e.precedence > i && e.accept(f, d)) return e.parseInfix(o, l); return null; }, "parslet"); return Object.defineProperty(t, "name", { value: e.name }), t; } r(x, "composeParslet"); let Q = x({ name: "optionalParslet", accept: /* @__PURE__ */ r((e) => e === "=", "accept"), precedence: y.OPTIONAL, parsePrefix: /* @__PURE__ */ r((e) => (e.consume("="), { type: "JsdocTypeOptional", element: e.parseType(y.OPTIONAL), meta: { position: "prefix" } }), "parsePrefix"), parseInfix: /* @__PURE__ */ r((e, t) => (e.consume("="), { type: "JsdocTypeOptional", element: J(t), meta: { position: "suffix" } }), "parseInfix") }), Z = x({ name: "numberParslet", accept: /* @__PURE__ */ r((e) => e === "Number", "accept"), parsePrefix: /* @__PURE__ */ r((e) => { let t = parseFloat(e.lexer.current.text); return e.consume("Number"), { type: "JsdocTypeNumber", value: t }; }, "parsePrefix") }), Vt = x({ name: "parenthesisParslet", accept: /* @__PURE__ */ r((e) => e === "(", "accept"), parsePrefix: /* @__PURE__ */ r((e) => { if (e.consume("("), e.consume(")")) return { type: "JsdocTypeParameterList", elements: [] }; let t = e.parseIntermediateType(y.ALL); if (!e.consume(")")) throw new Error("Unterminated parenthesis"); return t.type === "JsdocTypeParameterList" ? t : t.type === "JsdocTypeKeyValue" ? { type: "JsdocTypeParameterList", elements: [t] } : { type: "JsdocTypeParenthesis", element: J(t) }; }, "parsePrefix") }), Lt = x({ name: "specialTypesParslet", accept: /* @__PURE__ */ r((e, t) => e === "?" && Ye(t) || e === "null" || e === "undefined" || e === "*", "accept"), parsePrefix: /* @__PURE__ */ r((e) => { if (e.consume("null")) return { type: "JsdocTypeNull" }; if (e.consume("undefined")) return { type: "JsdocTypeUndefined" }; if (e.consume("*")) return { type: "JsdocTypeAny" }; if (e.consume("?")) return { type: "JsdocTypeUnknown" }; throw new Error("Unacceptable token: " + e.lexer.current.text); }, "parsePrefix") }), Ut = x({ name: "notNullableParslet", accept: /* @__PURE__ */ r((e) => e === "!", "accept"), precedence: y.NULLABLE, parsePrefix: /* @__PURE__ */ r((e) => (e.consume("!"), { type: "JsdocTypeNotNullable", element: e.parseType(y.NULLABLE), meta: { position: "prefix" } }), "parsePrefix"), parseInfix: /* @__PURE__ */ r((e, t) => (e.consume("!"), { type: "JsdocTypeNotNullable", element: J(t), meta: { position: "suffix" } }), "parseInfix") }); function Bt({ allowTrailingComma: e }) { return x({ name: "parameterListParslet", accept: /* @__PURE__ */ r((t) => t === ",", "accept"), precedence: y.PARAMETER_LIST, parseInfix: /* @__PURE__ */ r((t, o) => { let i = [ he(o) ]; t.consume(","); do try { let l = t.parseIntermediateType(y.PARAMETER_LIST); i.push(he(l)); } catch (l) { if (e && l instanceof a) break; throw l; } while (t.consume(",")); if (i.length > 0 && i.slice(0, -1).some((l) => l.type === "JsdocTypeVariadic")) throw new Error("Only the last parameter may be a rest parameter"); return { type: "JsdocTypeParameterList", elements: i }; }, "parseInfix") }); } r(Bt, "createParameterListParslet"); let Ct = x({ name: "genericParslet", accept: /* @__PURE__ */ r((e, t) => e === "<" || e === "." && t === "<", "accept"), precedence: y.GENERIC, parseInfix: /* @__PURE__ */ r((e, t) => { let o = e.consume("."); e.consume("<"); let i = []; do i.push(e.parseType(y.PARAMETER_LIST)); while (e.consume(",")); if (!e.consume(">")) throw new Error("Unterminated generic parameter list"); return { type: "JsdocTypeGeneric", left: J(t), elements: i, meta: { brackets: "angle", dot: o } }; }, "parseInfix") }), Mt = x({ name: "unionParslet", accept: /* @__PURE__ */ r((e) => e === "|", "accept"), precedence: y.UNION, parseInfix: /* @__PURE__ */ r((e, t) => { e.consume("|"); let o = []; do o.push(e.parseType(y.UNION)); while (e.consume("|")); return { type: "JsdocTypeUnion", elements: [J(t), ...o] }; }, "parseInfix") }), Pe = [ we, Q, Z, Vt, Lt, Ut, Bt({ allowTrailingComma: !0 }), Ct, Mt, Q ]; function ee({ allowSquareBracketsOnAnyType: e, allowJsdocNamePaths: t, pathGrammar: o }) { return /* @__PURE__ */ r(function(l, f, d) { if (d == null || f >= y.NAME_PATH) return null; let h = l.lexer.current.type, D = l.lexer.next.type; if (!(h === "." && D !== "<" || h === "[" && (e || d.type === "JsdocTypeName") || t && (h === "~" || h === "#"))) return null; let O, ae = !1; l.consume(".") ? O = "property" : l.consume("[") ? (O = "property-brackets", ae = !0) : l.consume("~") ? O = "inner" : (l.consume("#"), O = "instance"); let rt = o !== null ? new I(o, l.lexer, l) : l, k = rt.parseIntermediateType(y.NAME_PATH); l.acceptLexerState(rt); let G; switch (k.type) { case "JsdocTypeName": G = { type: "JsdocTypeProperty", value: k.value, meta: { quote: void 0 } }; break; case "JsdocTypeNumber": G = { type: "JsdocTypeProperty", value: k.value.toString(10), meta: { quote: void 0 } }; break; case "JsdocTypeStringValue": G = { type: "JsdocTypeProperty", value: k.value, meta: { quote: k.meta.quote } }; break; case "JsdocTypeSpecialNamePath": if (k.specialType === "event") G = k; else throw new c(k, "Type 'JsdocTypeSpecialNamePath' is only allowed with specialType 'event'"); break; default: throw new c(k, "Expecting 'JsdocTypeName', 'JsdocTypeNumber', 'JsdocStringValue' or 'JsdocTypeSpecialNamePath'"); } if (ae && !l.consume("]")) { let nt = l.lexer.current; throw new Error(`Unterminated square brackets. Next token is '${nt.type}' with text '${nt.text}'`); } return { type: "JsdocTypeNamePath", left: J(d), right: G, pathType: O }; }, "namePathParslet"); } r(ee, "createNamePathParslet"); function R({ allowedAdditionalTokens: e }) { return x({ name: "nameParslet", accept: /* @__PURE__ */ r((t) => t === "Identifier" || t === "this" || t === "new" || e.includes(t), "accept"), parsePrefix: /* @__PURE__ */ r((t) => { let { type: o, text: i } = t.lexer.current; return t.consume(o), { type: "JsdocTypeName", value: i }; }, "parsePrefix") }); } r(R, "createNameParslet"); let Y = x({ name: "stringValueParslet", accept: /* @__PURE__ */ r((e) => e === "StringValue", "accept"), parsePrefix: /* @__PURE__ */ r((e) => { let t = e.lexer.current.text; return e.consume("StringValue"), { type: "JsdocTypeStringValue", value: t.slice(1, -1), meta: { quote: t[0] === "'" ? "single" : "double" } }; }, "parsePrefix") }); function te({ pathGrammar: e, allowedTypes: t }) { return x({ name: "specialNamePathParslet", accept: /* @__PURE__ */ r((o) => t.includes(o), "accept"), parsePrefix: /* @__PURE__ */ r((o) => { let i = o.lexer.current.type; if (o.consume(i), !o.consume(":")) return { type: "JsdocTypeName", value: i }; let l, f = o.lexer.current; if (o.consume("StringValue")) l = { type: "JsdocTypeSpecialNamePath", value: f.text.slice(1, -1), specialType: i, meta: { quote: f.text[0] === "'" ? "single" : "double" } }; else { let D = "", E = ["Identifier", "@", "/"]; for (; E.some((O) => o.consume(O)); ) D += f.text, f = o.lexer.current; l = { type: "JsdocTypeSpecialNamePath", value: D, specialType: i, meta: { quote: void 0 } }; } let d = new I(e, o.lexer, o), h = d.parseInfixIntermediateType(l, y.ALL); return o.acceptLexerState(d), J(h); }, "parsePrefix") }); } r(te, "createSpecialNamePathParslet"); let We = [ R({ allowedAdditionalTokens: ["external", "module"] }), Y, Z, ee({ allowSquareBracketsOnAnyType: !1, allowJsdocNamePaths: !0, pathGrammar: null }) ], L = [ ...We, te({ allowedTypes: ["event"], pathGrammar: We }) ]; function be(e) { let t; if (e.type === "JsdocTypeParameterList") t = e.elements; else if (e.type === "JsdocTypeParenthesis") t = [e.element]; else throw new c(e); return t.map((o) => he(o)); } r(be, "getParameters"); function Kt(e) { let t = be(e); if (t.some((o) => o.type === "JsdocTypeKeyValue")) throw new Error("No parameter should be named"); return t; } r(Kt, "getUnnamedParameters"); function Se({ allowNamedParameters: e, allowNoReturnType: t, allowWithoutParenthesis: o, allowNewAsFunctionKeyword: i }) { return x({ name: "functionParslet", accept: /* @__PURE__ */ r((l, f) => l === "function" || i && l === "new" && f === "(", "accept"), parsePrefix: /* @__PURE__ */ r((l) => { let f = l.consume("new"); l.consume("function"); let d = l.lexer.current.type === "("; if (!d) { if (!o) throw new Error("function is missing parameter list"); return { type: "JsdocTypeName", value: "function" }; } let h = { type: "JsdocTypeFunction", parameters: [], arrow: !1, constructor: f, parenthesis: d }, D = l.parseIntermediateType(y.FUNCTION); if (e === void 0) h.parameters = Kt(D); else { if (f && D.type === "JsdocTypeFunction" && D.arrow) return h = D, h.constructor = !0, h; h.parameters = be(D); for (let E of h.parameters) if (E.type === "JsdocTypeKeyValue" && !e.includes(E.key)) throw new Error(`only allowed named parameters are ${e.join(", ")} but got ${E.type}`); } if (l.consume(":")) h.returnType = l.parseType(y.PREFIX); else if (!t) throw new Error("function is missing return type"); return h; }, "parsePrefix") }); } r(Se, "createFunctionParslet"); function Ee({ allowPostfix: e, allowEnclosingBrackets: t }) { return x({ name: "variadicParslet", accept: /* @__PURE__ */ r((o) => o === "...", "accept"), precedence: y.PREFIX, parsePrefix: /* @__PURE__ */ r((o) => { o.consume("..."); let i = t && o.consume("["); try { let l = o.parseType(y.PREFIX); if (i && !o.consume("]")) throw new Error("Unterminated variadic type. Missing ']'"); return { type: "JsdocTypeVariadic", element: J(l), meta: { position: "prefix", squareBrackets: i } }; } catch (l) { if (l instanceof a) { if (i) throw new Error("Empty square brackets for variadic are not allowed."); return { type: "JsdocTypeVariadic", meta: { position: void 0, squareBrackets: !1 } }; } else throw l; } }, "parsePrefix"), parseInfix: e ? (o, i) => (o.consume("..."), { type: "JsdocTypeVariadic", element: J(i), meta: { position: "suffix", squareBrackets: !1 } }) : void 0 }); } r(Ee, "createVariadicParslet"); let Ge = x({ name: "symbolParslet", accept: /* @__PURE__ */ r((e) => e === "(", "accept"), precedence: y.SYMBOL, parseInfix: /* @__PURE__ */ r((e, t) => { if (t.type !== "JsdocTypeName") throw new Error("Symbol expects a name on the left side. (Reacting on '(')"); e.consume("("); let o = { type: "JsdocTypeSymbol", value: t.value }; if (!e.consume(")")) { let i = e.parseIntermediateType(y.SYMBOL); if (o.element = _t(i), !e.consume(")")) throw new Error("Symbol does not end after value"); } return o; }, "parseInfix") }), Xe = x({ name: "arrayBracketsParslet", precedence: y.ARRAY_BRACKETS, accept: /* @__PURE__ */ r((e, t) => e === "[" && t === "]", "accept"), parseInfix: /* @__PURE__ */ r((e, t) => (e.consume("["), e.consume("]"), { type: "JsdocTypeGeneric", left: { type: "JsdocTypeName", value: "Array" }, elements: [ J(t) ], meta: { brackets: "square", dot: !1 } }), "parseInfix") }); function Ne({ objectFieldGrammar: e, allowKeyTypes: t }) { return x({ name: "objectParslet", accept: /* @__PURE__ */ r((o) => o === "{", "accept"), parsePrefix: /* @__PURE__ */ r((o) => { o.consume("{"); let i = { type: "JsdocTypeObject", meta: { separator: "comma" }, elements: [] }; if (!o.consume("}")) { let l, f = new I(e, o.lexer, o); for (; ; ) { f.acceptLexerState(o); let d = f.parseIntermediateType(y.OBJECT); o.acceptLexerState(f), d === void 0 && t && (d = o.parseIntermediateType(y.OBJECT)); let h = !1; if (d.type === "JsdocTypeNullable" && (h = !0, d = d.element), d.type === "JsdocTypeNumber" || d.type === "JsdocTypeName" || d. type === "JsdocTypeStringValue") { let E; d.type === "JsdocTypeStringValue" && (E = d.meta.quote), i.elements.push({ type: "JsdocTypeObjectField", key: d.value.toString(), right: void 0, optional: h, readonly: !1, meta: { quote: E } }); } else if (d.type === "JsdocTypeObjectField" || d.type === "JsdocTypeJsdocObjectField") i.elements.push(d); else throw new c(d); if (o.lexer.current.startOfLine) l = "linebreak"; else if (o.consume(",")) l = "comma"; else if (o.consume(";")) l = "semicolon"; else break; if (o.lexer.current.type === "}") break; } if (i.meta.separator = l ?? "comma", !o.consume("}")) throw new Error("Unterminated record type. Missing '}'"); } return i; }, "parsePrefix") }); } r(Ne, "createObjectParslet"); function De({ allowSquaredProperties: e, allowKeyTypes: t, allowReadonly: o, allowOptional: i }) { return x({ name: "objectFieldParslet", precedence: y.KEY_VALUE, accept: /* @__PURE__ */ r((l) => l === ":", "accept"), parseInfix: /* @__PURE__ */ r((l, f) => { var d; let h = !1, D = !1; i && f.type === "JsdocTypeNullable" && (h = !0, f = f.element), o && f.type === "JsdocTypeReadonlyProperty" && (D = !0, f = f.element); let E = (d = l.baseParser) !== null && d !== void 0 ? d : l; if (E.acceptLexerState(l), f.type === "JsdocTypeNumber" || f.type === "JsdocTypeName" || f.type === "JsdocTypeStringValue" || Je(f)) { if (Je(f) && !e) throw new c(f); E.consume(":"); let O; f.type === "JsdocTypeStringValue" && (O = f.meta.quote); let ae = E.parseType(y.KEY_VALUE); return l.acceptLexerState(E), { type: "JsdocTypeObjectField", key: Je(f) ? f : f.value.toString(), right: ae, optional: h, readonly: D, meta: { quote: O } }; } else { if (!t) throw new c(f); E.consume(":"); let O = E.parseType(y.KEY_VALUE); return l.acceptLexerState(E), { type: "JsdocTypeJsdocObjectField", left: J(f), right: O }; } }, "parseInfix") }); } r(De, "createObjectFieldParslet"); function Oe({ allowOptional: e, allowVariadic: t }) { return x({ name: "keyValueParslet", precedence: y.KEY_VALUE, accept: /* @__PURE__ */ r((o) => o === ":", "accept"), parseInfix: /* @__PURE__ */ r((o, i) => { let l = !1, f = !1; if (e && i.type === "JsdocTypeNullable" && (l = !0, i = i.element), t && i.type === "JsdocTypeVariadic" && i.element !== void 0 && (f = !0, i = i.element), i.type !== "JsdocTypeName") throw new c(i); o.consume(":"); let d = o.parseType(y.KEY_VALUE); return { type: "JsdocTypeKeyValue", key: i.value, right: d, optional: l, variadic: f }; }, "parseInfix") }); } r(Oe, "createKeyValueParslet"); let ze = [ ...Pe, Se({ allowWithoutParenthesis: !0, allowNamedParameters: ["this", "new"], allowNoReturnType: !0, allowNewAsFunctionKeyword: !1 }), Y, te({ allowedTypes: ["module", "external", "event"], pathGrammar: L }), Ee({ allowEnclosingBrackets: !0, allowPostfix: !0 }), R({ allowedAdditionalTokens: ["keyof"] }), Ge, Xe, ee({ allowSquareBracketsOnAnyType: !1, allowJsdocNamePaths: !0, pathGrammar: L }) ], $t = [ ...ze, Ne({ // jsdoc syntax allows full types as keys, so we need to pull in the full grammar here // we leave out the object type deliberately objectFieldGrammar: [ R({ allowedAdditionalTokens: ["module", "in"] }), De({ allowSquaredProperties: !1, allowKeyTypes: !0, allowOptional: !1, allowReadonly: !1 }), ...ze ], allowKeyTypes: !0 }), Oe({ allowOptional: !0, allowVariadic: !0 }) ], He = x({ name: "typeOfParslet", accept: /* @__PURE__ */ r((e) => e === "typeof", "accept"), parsePrefix: /* @__PURE__ */ r((e) => (e.consume("typeof"), { type: "JsdocTypeTypeof", element: J(e.parseType(y.KEY_OF_TYPE_OF)) }), "parsePrefix") }), qt = [ R({ allowedAdditionalTokens: ["module", "keyof", "event", "external", "in"] }), we, Q, Y, Z, De({ allowSquaredProperties: !1, allowKeyTypes: !1, allowOptional: !1, allowReadonly: !1 }) ], Yt = [ ...Pe, Ne({ allowKeyTypes: !1, objectFieldGrammar: qt }), R({ allowedAdditionalTokens: ["event", "external", "in"] }), He, Se({ allowWithoutParenthesis: !1, allowNamedParameters: ["this", "new"], allowNoReturnType: !0, allowNewAsFunctionKeyword: !1 }), Ee({ allowEnclosingBrackets: !1, allowPostfix: !1 }), // additional name parslet is needed for some special cases R({ allowedAdditionalTokens: ["keyof"] }), te({ allowedTypes: ["module"], pathGrammar: L }), ee({ allowSquareBracketsOnAnyType: !1, allowJsdocNamePaths: !0, pathGrammar: L }), Oe({ allowOptional: !1, allowVariadic: !1 }), Ge ], Wt = x({ name: "assertsParslet", accept: /* @__PURE__ */ r((e) => e === "asserts", "accept"), parsePrefix: /* @__PURE__ */ r((e) => { e.consume("asserts"); let t = e.parseIntermediateType(y.SYMBOL); if (t.type !== "JsdocTypeName") throw new c(t, "A typescript asserts always has to have a name on the left side."); return e.consume("is"), { type: "JsdocTypeAsserts", left: t, right: J(e.parseIntermediateType(y.INFIX)) }; }, "parsePrefix") }); function Gt({ allowQuestionMark: e }) { return x({ name: "tupleParslet", accept: /* @__PURE__ */ r((t) => t === "[", "accept"), parsePrefix: /* @__PURE__ */ r((t) => { t.consume("["); let o = { type: "JsdocTypeTuple", elements: [] }; if (t.consume("]")) return o; let i = t.parseIntermediateType(y.ALL); if (i.type === "JsdocTypeParameterList" ? i.elements[0].type === "JsdocTypeKeyValue" ? o.elements = i.elements.map(H) : o.elements = i.elements.map(J) : i.type === "JsdocTypeKeyValue" ? o.elements = [H(i)] : o.elements = [J(i)], !t.consume("]")) throw new Error("Unterminated '['"); if (!e && o.elements.some((l) => l.type === "JsdocTypeUnknown")) throw new Error("Question mark in tuple not allowed"); return o; }, "parsePrefix") }); } r(Gt, "createTupleParslet"); let Xt = x({ name: "keyOfParslet", accept: /* @__PURE__ */ r((e) => e === "keyof", "accept"), parsePrefix: /* @__PURE__ */ r((e) => (e.consume("keyof"), { type: "JsdocTypeKeyof", element: J(e.parseType(y.KEY_OF_TYPE_OF)) }), "parsePrefix") }), zt = x({ name: "importParslet", accept: /* @__PURE__ */ r((e) => e === "import", "accept"), parsePrefix: /* @__PURE__ */ r((e) => { if (e.consume("import"), !e.consume("(")) throw new Error("Missing parenthesis after import keyword"); let t = e.parseType(y.PREFIX); if (t.type !== "JsdocTypeStringValue") throw new Error("Only string values are allowed as paths for imports"); if (!e.consume(")")) throw new Error("Missing closing parenthesis after import keyword"); return { type: "JsdocTypeImport", element: t }; }, "parsePrefix") }), Ht = x({ name: "readonlyPropertyParslet", accept: /* @__PURE__ */ r((e) => e === "readonly", "accept"), parsePrefix: /* @__PURE__ */ r((e) => (e.consume("readonly"), { type: "JsdocTypeReadonlyProperty", element: e.parseType(y.KEY_VALUE) }), "parsePrefix") }), Qt = x({ name: "arrowFunctionParslet", precedence: y.ARROW, accept: /* @__PURE__ */ r((e) => e === "=>", "accept"), parseInfix: /* @__PURE__ */ r((e, t) => (e.consume("=>"), { type: "JsdocTypeFunction", parameters: be(t).map(Ft), arrow: !0, constructor: !1, parenthesis: !0, returnType: e.parseType(y.OBJECT) }), "parseInfix") }), Zt = x({ name: "intersectionParslet", accept: /* @__PURE__ */ r((e) => e === "&", "accept"), precedence: y.INTERSECTION, parseInfix: /* @__PURE__ */ r((e, t) => { e.consume("&"); let o = []; do o.push(e.parseType(y.INTERSECTION)); while (e.consume("&")); return { type: "JsdocTypeIntersection", elements: [J(t), ...o] }; }, "parseInfix") }), er = x({ name: "predicateParslet", precedence: y.INFIX, accept: /* @__PURE__ */ r((e) => e === "is", "accept"), parseInfix: /* @__PURE__ */ r((e, t) => { if (t.type !== "JsdocTypeName") throw new c(t, "A typescript predicate always has to have a name on the left side."); return e.consume("is"), { type: "JsdocTypePredicate", left: t, right: J(e.parseIntermediateType(y.INFIX)) }; }, "parseInfix") }), tr = x({ name: "objectSquareBracketPropertyParslet", accept: /* @__PURE__ */ r((e) => e === "[", "accept"), parsePrefix: /* @__PURE__ */ r((e) => { if (e.baseParser === void 0) throw new Error("Only allowed inside object grammar"); e.consume("["); let t = e.lexer.current.text; e.consume("Identifier"); let o; if (e.consume(":")) { let i = e.baseParser; i.acceptLexerState(e), o = { type: "JsdocTypeIndexSignature", key: t, right: i.parseType(y.INDEX_BRACKETS) }, e.acceptLexerState(i); } else if (e.consume("in")) { let i = e.baseParser; i.acceptLexerState(e), o = { type: "JsdocTypeMappedType", key: t, right: i.parseType(y.ARRAY_BRACKETS) }, e.acceptLexerState(i); } else throw new Error("Missing ':' or 'in' inside square bracketed property."); if (!e.consume("]")) throw new Error("Unterminated square brackets"); return o; }, "parsePrefix") }), rr = [ Ht, R({ allowedAdditionalTokens: ["module", "event", "keyof", "event", "external", "in"] }), we, Q, Y, Z, De({ allowSquaredProperties: !0, allowKeyTypes: !1, allowOptional: !0, allowReadonly: !0 }), tr ], nr = [ ...Pe, Ne({ allowKeyTypes: !1, objectFieldGrammar: rr }), He, Xt, zt, Y, Se({ allowWithoutParenthesis: !0, allowNoReturnType: !1, allowNamedParameters: ["this", "new", "args"], allowNewAsFunctionKeyword: !0 }), Gt({ allowQuestionMark: !1 }), Ee({ allowEnclosingBrackets: !1, allowPostfix: !1 }), Wt, R({ allowedAdditionalTokens: ["event", "external", "in"] }), te({ allowedTypes: ["module"], pathGrammar: L }), Xe, Qt, ee({ allowSquareBracketsOnAnyType: !0, allowJsdocNamePaths: !1, pathGrammar: L }), Zt, er, Oe({ allowVariadic: !0, allowOptional: !0 }) ]; function Qe(e, t) { switch (t) { case "closure": return new I(Yt, e).parse(); case "jsdoc": return new I($t, e).parse(); case "typescript": return new I(nr, e).parse(); } } r(Qe, "parse"); function or(e, t = ["typescript", "closure", "jsdoc"]) { let o; for (let i of t) try { return Qe(e, i); } catch (l) { o = l; } throw o; } r(or, "tryParse"); function W(e, t) { let o = e[t.type]; if (o === void 0) throw new Error(`In this set of transform rules exists no rule for type ${t.type}.`); return o(t, (i) => W(e, i)); } r(W, "transform"); function N(e) { throw new Error("This transform is not available. Are you trying the correct parsing mode?"); } r(N, "notAvailableTransform"); function Ze(e) { let t = { params: [] }; for (let o of e.parameters) o.type === "JsdocTypeKeyValue" ? o.key === "this" ? t.this = o.right : o.key === "new" ? t.new = o.right : t.params.push(o) : t.params. push(o); return t; } r(Ze, "extractSpecialParams"); function re(e, t, o) { return e === "prefix" ? o + t : t + o; } r(re, "applyPosition"); function j(e, t) { switch (t) { case "double": return `"${e}"`; case "single": return `'${e}'`; case void 0: return e; } } r(j, "quote"); function et() { return { JsdocTypeParenthesis: /* @__PURE__ */ r((e, t) => `(${e.element !== void 0 ? t(e.element) : ""})`, "JsdocTypeParenthesis"), JsdocTypeKeyof: /* @__PURE__ */ r((e, t) => `keyof ${t(e.element)}`, "JsdocTypeKeyof"), JsdocTypeFunction: /* @__PURE__ */ r((e, t) => { if (e.arrow) { if (e.returnType === void 0) throw new Error("Arrow function needs a return type."); let o = `(${e.parameters.map(t).join(", ")}) => ${t(e.returnType)}`; return e.constructor && (o = "new " + o), o; } else { let o = e.constructor ? "new" : "function"; return e.parenthesis && (o += `(${e.parameters.map(t).join(", ")})`, e.returnType !== void 0 && (o += `: ${t(e.returnType)}`)), o; } }, "JsdocTypeFunction"), JsdocTypeName: /* @__PURE__ */ r((e) => e.value, "JsdocTypeName"), JsdocTypeTuple: /* @__PURE__ */ r((e, t) => `[${e.elements.map(t).join(", ")}]`, "JsdocTypeTuple"), JsdocTypeVariadic: /* @__PURE__ */ r((e, t) => e.meta.position === void 0 ? "..." : re(e.meta.position, t(e.element), "..."), "Jsdoc\ TypeVariadic"), JsdocTypeNamePath: /* @__PURE__ */ r((e, t) => { let o = t(e.left), i = t(e.right); switch (e.pathType) { case "inner": return `${o}~${i}`; case "instance": return `${o}#${i}`; case "property": return `${o}.${i}`; case "property-brackets": return `${o}[${i}]`; } }, "JsdocTypeNamePath"), JsdocTypeStringValue: /* @__PURE__ */ r((e) => j(e.value, e.meta.quote), "JsdocTypeStringValue"), JsdocTypeAny: /* @__PURE__ */ r(() => "*", "JsdocTypeAny"), JsdocTypeGeneric: /* @__PURE__ */ r((e, t) => { if (e.meta.brackets === "square") { let o = e.elements[0], i = t(o); return o.type === "JsdocTypeUnion" || o.type === "JsdocTypeIntersection" ? `(${i})[]` : `${i}[]`; } else return `${t(e.left)}${e.meta.dot ? "." : ""}<${e.elements.map(t).join(", ")}>`; }, "JsdocTypeGeneric"), JsdocTypeImport: /* @__PURE__ */ r((e, t) => `import(${t(e.element)})`, "JsdocTypeImport"), JsdocTypeObjectField: /* @__PURE__ */ r((e, t) => { let o = ""; return e.readonly && (o += "readonly "), typeof e.key == "string" ? o += j(e.key, e.meta.quote) : o += t(e.key), e.optional && (o += "?"), e.right === void 0 ? o : o + `: ${t(e.right)}`; }, "JsdocTypeObjectField"), JsdocTypeJsdocObjectField: /* @__PURE__ */ r((e, t) => `${t(e.left)}: ${t(e.right)}`, "JsdocTypeJsdocObjectField"), JsdocTypeKeyValue: /* @__PURE__ */ r((e, t) => { let o = e.key; return e.optional && (o += "?"), e.variadic && (o = "..." + o), e.right === void 0 ? o : o + `: ${t(e.right)}`; }, "JsdocTypeKeyValue"), JsdocTypeSpecialNamePath: /* @__PURE__ */ r((e) => `${e.specialType}:${j(e.value, e.meta.quote)}`, "JsdocTypeSpecialNamePath"), JsdocTypeNotNullable: /* @__PURE__ */ r((e, t) => re(e.meta.position, t(e.element), "!"), "JsdocTypeNotNullable"), JsdocTypeNull: /* @__PURE__ */ r(() => "null", "JsdocTypeNull"), JsdocTypeNullable: /* @__PURE__ */ r((e, t) => re(e.meta.position, t(e.element), "?"), "JsdocTypeNullable"), JsdocTypeNumber: /* @__PURE__ */ r((e) => e.value.toString(), "JsdocTypeNumber"), JsdocTypeObject: /* @__PURE__ */ r((e, t) => `{${e.elements.map(t).join((e.meta.separator === "comma" ? "," : ";") + " ")}}`, "Jsdoc\ TypeObject"), JsdocTypeOptional: /* @__PURE__ */ r((e, t) => re(e.meta.position, t(e.element), "="), "JsdocTypeOptional"), JsdocTypeSymbol: /* @__PURE__ */ r((e, t) => `${e.value}(${e.element !== void 0 ? t(e.element) : ""})`, "JsdocTypeSymbol"), JsdocTypeTypeof: /* @__PURE__ */ r((e, t) => `typeof ${t(e.element)}`, "JsdocTypeTypeof"), JsdocTypeUndefined: /* @__PURE__ */ r(() => "undefined", "JsdocTypeUndefined"), JsdocTypeUnion: /* @__PURE__ */ r((e, t) => e.elements.map(t).join(" | "), "JsdocTypeUnion"), JsdocTypeUnknown: /* @__PURE__ */ r(() => "?", "JsdocTypeUnknown"), JsdocTypeIntersection: /* @__PURE__ */ r((e, t) => e.elements.map(t).join(" & "), "JsdocTypeIntersection"), JsdocTypeProperty: /* @__PURE__ */ r((e) => j(e.value, e.meta.quote), "JsdocTypeProperty"), JsdocTypePredicate: /* @__PURE__ */ r((e, t) => `${t(e.left)} is ${t(e.right)}`, "JsdocTypePredicate"), JsdocTypeIndexSignature: /* @__PURE__ */ r((e, t) => `[${e.key}: ${t(e.right)}]`, "JsdocTypeIndexSignature"), JsdocTypeMappedType: /* @__PURE__ */ r((e, t) => `[${e.key} in ${t(e.right)}]`, "JsdocTypeMappedType"), JsdocTypeAsserts: /* @__PURE__ */ r((e, t) => `asserts ${t(e.left)} is ${t(e.right)}`, "JsdocTypeAsserts") }; } r(et, "stringifyRules"); let sr = et(); function ar(e) { return W(sr, e); } r(ar, "stringify"); let ir = [ "null", "true", "false", "break", "case", "catch", "class", "const", "continue", "debugger", "default", "delete", "do", "else", "export", "extends", "finally", "for", "function", "if", "import", "in", "instanceof", "new", "return", "super", "switch", "this", "throw", "try", "typeof", "var", "void", "while", "with", "yield" ]; function F(e) { let t = { type: "NameExpression", name: e }; return ir.includes(e) && (t.reservedWord = !0), t; } r(F, "makeName"); let pr = { JsdocTypeOptional: /* @__PURE__ */ r((e, t) => { let o = t(e.element); return o.optional = !0, o; }, "JsdocTypeOptional"), JsdocTypeNullable: /* @__PURE__ */ r((e, t) => { let o = t(e.element); return o.nullable = !0, o; }, "JsdocTypeNullable"), JsdocTypeNotNullable: /* @__PURE__ */ r((e, t) => { let o = t(e.element); return o.nullable = !1, o; }, "JsdocTypeNotNullable"), JsdocTypeVariadic: /* @__PURE__ */ r((e, t) => { if (e.element === void 0) throw new Error("dots without value are not allowed in catharsis mode"); let o = t(e.element); return o.repeatable = !0, o; }, "JsdocTypeVariadic"), JsdocTypeAny: /* @__PURE__ */ r(() => ({ type: "AllLiteral" }), "JsdocTypeAny"), JsdocTypeNull: /* @__PURE__ */ r(() => ({ type: "NullLiteral" }), "JsdocTypeNull"), JsdocTypeStringValue: /* @__PURE__ */ r((e) => F(j(e.value, e.meta.quote)), "JsdocTypeStringValue"), JsdocTypeUndefined: /* @__PURE__ */ r(() => ({ type: "UndefinedLiteral" }), "JsdocTypeUndefined"), JsdocTypeUnknown: /* @__PURE__ */ r(() => ({ type: "UnknownLiteral" }), "JsdocTypeUnknown"), JsdocTypeFunction: /* @__PURE__ */ r((e, t) => { let o = Ze(e), i = { type: "FunctionType", params: o.params.map(t) }; return o.this !== void 0 && (i.this = t(o.this)), o.new !== void 0 && (i.new = t(o.new)), e.returnType !== void 0 && (i.result = t(e. returnType)), i; }, "JsdocTypeFunction"), JsdocTypeGeneric: /* @__PURE__ */ r((e, t) => ({ type: "TypeApplication", applications: e.elements.map((o) => t(o)), expression: t(e.left) }), "JsdocTypeGeneric"), JsdocTypeSpecialNamePath: /* @__PURE__ */ r((e) => F(e.specialType + ":" + j(e.value, e.meta.quote)), "JsdocTypeSpecialNamePath"), JsdocTypeName: /* @__PURE__ */ r((e) => e.value !== "function" ? F(e.value) : { type: "FunctionType", params: [] }, "JsdocTypeName"), JsdocTypeNumber: /* @__PURE__ */ r((e) => F(e.value.toString()), "JsdocTypeNumber"), JsdocTypeObject: /* @__PURE__ */ r((e, t) => { let o = { type: "RecordType", fields: [] }; for (let i of e.elements) i.type !== "JsdocTypeObjectField" && i.type !== "JsdocTypeJsdocObjectField" ? o.fields.pu