storybook 10.1.0-alpha.9 → 10.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/dist/_browser-chunks/Color-FTG7SQDA.js +1097 -0
  2. package/dist/_browser-chunks/WithTooltip-LMROHDUP.js +1651 -0
  3. package/dist/_browser-chunks/chunk-2FRVAXCZ.js +7 -0
  4. package/dist/_browser-chunks/{chunk-FDWKXLBI.js → chunk-2XZMBGTA.js} +44 -109
  5. package/dist/_browser-chunks/chunk-3IAH5M2U.js +171 -0
  6. package/dist/_browser-chunks/chunk-3OXGAGBE.js +779 -0
  7. package/dist/_browser-chunks/{chunk-TMDZCWME.js → chunk-3PJE6VLG.js} +1 -3
  8. package/dist/_browser-chunks/{chunk-VAMFPZY3.js → chunk-45UGUKRX.js} +2 -7
  9. package/dist/_browser-chunks/chunk-6XWLIJQL.js +11 -0
  10. package/dist/_browser-chunks/{chunk-MM7DTO55.js → chunk-A242L54C.js} +10 -16
  11. package/dist/_browser-chunks/chunk-AIOS4NGK.js +252 -0
  12. package/dist/_browser-chunks/chunk-AS2HQEYC.js +14 -0
  13. package/dist/_browser-chunks/chunk-AXG2BOBL.js +836 -0
  14. package/dist/_browser-chunks/{chunk-MH6AXFXB.js → chunk-CHUV5WSW.js} +0 -5
  15. package/dist/_browser-chunks/chunk-EUVGDK4H.js +93 -0
  16. package/dist/_browser-chunks/chunk-EZSQOHRI.js +18 -0
  17. package/dist/_browser-chunks/{chunk-CADGRH3P.js → chunk-FNXWN6IK.js} +3 -8
  18. package/dist/_browser-chunks/chunk-FQ7SLVLR.js +66 -0
  19. package/dist/_browser-chunks/chunk-GFLS4VP3.js +64 -0
  20. package/dist/_browser-chunks/chunk-GFY5R5EY.js +47 -0
  21. package/dist/_browser-chunks/{chunk-L2D73C6Z.js → chunk-H6XK3RSC.js} +13 -21
  22. package/dist/_browser-chunks/chunk-IPA5A322.js +71 -0
  23. package/dist/_browser-chunks/chunk-JP7NCOJX.js +37 -0
  24. package/dist/_browser-chunks/chunk-KJHJLCBK.js +11 -0
  25. package/dist/_browser-chunks/{chunk-OWPZQM2D.js → chunk-L4RMQ7D7.js} +60 -110
  26. package/dist/_browser-chunks/chunk-P4F4UVXX.js +951 -0
  27. package/dist/_browser-chunks/{chunk-AB7OOPUX.js → chunk-QKODTO7K.js} +0 -5
  28. package/dist/_browser-chunks/chunk-RP5RXKFU.js +2491 -0
  29. package/dist/_browser-chunks/chunk-SL75JR6Y.js +9 -0
  30. package/dist/_browser-chunks/chunk-SS2NHR7W.js +2969 -0
  31. package/dist/_browser-chunks/chunk-UD6FQLAF.js +1481 -0
  32. package/dist/_browser-chunks/chunk-VYJQ7RU5.js +2853 -0
  33. package/dist/_browser-chunks/chunk-WJYERY3R.js +136 -0
  34. package/dist/_browser-chunks/chunk-XJNX76GA.js +85 -0
  35. package/dist/_browser-chunks/{chunk-F4Q6SGTB.js → chunk-YKE5S47A.js} +177 -399
  36. package/dist/_browser-chunks/{chunk-SN4J4IQ3.js → chunk-ZUWEVLDX.js} +1 -7
  37. package/dist/_browser-chunks/{formatter-OMEEQ6HG.js → formatter-QJ4M4OGQ.js} +4 -9
  38. package/dist/_browser-chunks/{syntaxhighlighter-CAVLW7PM.js → syntaxhighlighter-IQDEPFLK.js} +704 -1848
  39. package/dist/_node-chunks/{builder-manager-SM3UWERX.js → builder-manager-FTVC2JL7.js} +510 -1019
  40. package/dist/_node-chunks/camelcase-3SMT5WKC.js +37 -0
  41. package/dist/_node-chunks/chunk-2OVULPK3.js +54 -0
  42. package/dist/_node-chunks/chunk-3JJPSDXI.js +3043 -0
  43. package/dist/_node-chunks/chunk-54NMJ4II.js +1564 -0
  44. package/dist/_node-chunks/chunk-5V4A6MSI.js +943 -0
  45. package/dist/_node-chunks/chunk-6DEMT5VX.js +299 -0
  46. package/dist/_node-chunks/{chunk-HHSTA6QS.js → chunk-6L7FFBOW.js} +8 -10
  47. package/dist/_node-chunks/chunk-6ULDIDXV.js +46662 -0
  48. package/dist/_node-chunks/chunk-AREL5IXS.js +603 -0
  49. package/dist/_node-chunks/chunk-DWA53E73.js +23 -0
  50. package/dist/_node-chunks/chunk-FNYKBULZ.js +765 -0
  51. package/dist/_node-chunks/chunk-IUYZQKSX.js +70 -0
  52. package/dist/_node-chunks/{chunk-F6EFOEC7.js → chunk-K673CX4Q.js} +469 -983
  53. package/dist/_node-chunks/chunk-KJAFCNZ3.js +61 -0
  54. package/dist/_node-chunks/chunk-N3BJOOY5.js +78 -0
  55. package/dist/_node-chunks/{chunk-EBUEXRH5.js → chunk-O5FMCQHP.js} +116 -276
  56. package/dist/_node-chunks/chunk-RIKQZHV3.js +29 -0
  57. package/dist/_node-chunks/chunk-RURZIE3W.js +3780 -0
  58. package/dist/_node-chunks/chunk-RVII4SK6.js +919 -0
  59. package/dist/_node-chunks/chunk-S3PBHOVC.js +6024 -0
  60. package/dist/_node-chunks/chunk-SQSFX47N.js +61 -0
  61. package/dist/_node-chunks/{chunk-SGM3ZCCT.js → chunk-TURUTKVH.js} +292 -688
  62. package/dist/_node-chunks/chunk-VRICJPXY.js +72 -0
  63. package/dist/_node-chunks/chunk-WIWWMCEU.js +119 -0
  64. package/dist/_node-chunks/{chunk-ATDHMMIZ.js → chunk-XGNRK7QB.js} +15 -24
  65. package/dist/_node-chunks/chunk-Y2FOTPAE.js +4523 -0
  66. package/dist/_node-chunks/{chunk-GHIBZRKD.js → chunk-Y4UYN72K.js} +8133 -8887
  67. package/dist/_node-chunks/chunk-Z4BMBA5L.js +18 -0
  68. package/dist/_node-chunks/chunk-ZMCJS2GU.js +20 -0
  69. package/dist/_node-chunks/dist-TZLZ3T6L.js +121 -0
  70. package/dist/_node-chunks/globby-22GFCZQD.js +3452 -0
  71. package/dist/_node-chunks/lib-37NQ4ZIJ.js +366 -0
  72. package/dist/_node-chunks/mdx-N42X6CFJ-2TRB7OEH.js +14329 -0
  73. package/dist/_node-chunks/p-limit-UD7TYFDW.js +116 -0
  74. package/dist/actions/decorator.js +21 -42
  75. package/dist/actions/index.js +3 -3
  76. package/dist/babel/index.d.ts +671 -335
  77. package/dist/babel/index.js +10 -11
  78. package/dist/bin/core.js +602 -1549
  79. package/dist/bin/dispatcher.js +36 -36
  80. package/dist/bin/loader.js +24 -38
  81. package/dist/channels/index.js +98 -234
  82. package/dist/cli/index.d.ts +1479 -133
  83. package/dist/cli/index.js +30 -8540
  84. package/dist/client-logger/index.js +31 -61
  85. package/dist/common/index.d.ts +139 -62
  86. package/dist/common/index.js +66 -51
  87. package/dist/components/index.d.ts +575 -273
  88. package/dist/components/index.js +14863 -4313
  89. package/dist/core-events/index.js +2 -66
  90. package/dist/core-server/index.d.ts +3 -2
  91. package/dist/core-server/index.js +2911 -8519
  92. package/dist/core-server/presets/common-manager.css +2 -2
  93. package/dist/core-server/presets/common-manager.js +2521 -5233
  94. package/dist/core-server/presets/common-override-preset.js +31 -60
  95. package/dist/core-server/presets/common-preset.js +663 -962
  96. package/dist/csf/index.js +534 -1179
  97. package/dist/csf-tools/index.js +9 -9
  98. package/dist/docs-tools/index.js +6 -6
  99. package/dist/highlight/index.js +2 -2
  100. package/dist/instrumenter/index.js +199 -415
  101. package/dist/manager/globals-runtime.js +59044 -67141
  102. package/dist/manager/globals.js +2 -3
  103. package/dist/manager/manager-stores.d.ts +1 -0
  104. package/dist/manager/manager-stores.js +23 -0
  105. package/dist/manager/runtime.js +11569 -10953
  106. package/dist/manager-api/index.d.ts +1813 -2
  107. package/dist/manager-api/index.js +1348 -2401
  108. package/dist/manager-errors.d.ts +9 -0
  109. package/dist/manager-errors.js +3 -3
  110. package/dist/mocking-utils/index.d.ts +1126 -0
  111. package/dist/mocking-utils/index.js +1181 -0
  112. package/dist/node-logger/index.d.ts +192 -24
  113. package/dist/node-logger/index.js +23 -4471
  114. package/dist/preview/globals.js +2 -3
  115. package/dist/preview/runtime.js +10799 -22393
  116. package/dist/preview-api/index.d.ts +1 -1
  117. package/dist/preview-api/index.js +13 -13
  118. package/dist/preview-errors.d.ts +9 -0
  119. package/dist/preview-errors.js +4 -4
  120. package/dist/router/index.js +347 -899
  121. package/dist/server-errors.d.ts +34 -1
  122. package/dist/server-errors.js +17 -10
  123. package/dist/telemetry/index.d.ts +24 -3
  124. package/dist/telemetry/index.js +25 -24
  125. package/dist/test/index.js +6131 -11916
  126. package/dist/theming/create.d.ts +1 -0
  127. package/dist/theming/create.js +4 -4
  128. package/dist/theming/index.d.ts +3366 -2599
  129. package/dist/theming/index.js +501 -1091
  130. package/dist/types/index.d.ts +72 -8
  131. package/dist/types/index.js +27 -12
  132. package/dist/viewport/index.js +3 -3
  133. package/package.json +26 -17
  134. package/dist/_browser-chunks/Color-7ZNS6F6B.js +0 -1676
  135. package/dist/_browser-chunks/WithTooltip-SK46ZJ2J.js +0 -13
  136. package/dist/_browser-chunks/chunk-6A7OIVEL.js +0 -66
  137. package/dist/_browser-chunks/chunk-B4A3ADP3.js +0 -3816
  138. package/dist/_browser-chunks/chunk-BOOOPFZF.js +0 -2335
  139. package/dist/_browser-chunks/chunk-FSBVR7H5.js +0 -106
  140. package/dist/_browser-chunks/chunk-FUOHXXZT.js +0 -23
  141. package/dist/_browser-chunks/chunk-GTKOCWCT.js +0 -17
  142. package/dist/_browser-chunks/chunk-HHW4FUMO.js +0 -12
  143. package/dist/_browser-chunks/chunk-JVSKG4YS.js +0 -4052
  144. package/dist/_browser-chunks/chunk-LASUB7TL.js +0 -76
  145. package/dist/_browser-chunks/chunk-LYCSRYYR.js +0 -101
  146. package/dist/_browser-chunks/chunk-NVV6MIOE.js +0 -243
  147. package/dist/_browser-chunks/chunk-OBXWFEPB.js +0 -852
  148. package/dist/_browser-chunks/chunk-OPCDBBL3.js +0 -48
  149. package/dist/_browser-chunks/chunk-PB6FZ3WE.js +0 -130
  150. package/dist/_browser-chunks/chunk-RNE2IUTB.js +0 -1300
  151. package/dist/_browser-chunks/chunk-RW5PKMWM.js +0 -4182
  152. package/dist/_browser-chunks/chunk-SYS437NN.js +0 -122
  153. package/dist/_browser-chunks/chunk-U46RQHA4.js +0 -12
  154. package/dist/_browser-chunks/chunk-UTNZYD2N.js +0 -311
  155. package/dist/_browser-chunks/chunk-VUAFL5XK.js +0 -20
  156. package/dist/_browser-chunks/chunk-XDGMHOV7.js +0 -2197
  157. package/dist/_browser-chunks/chunk-XW6KSYKF.js +0 -16
  158. package/dist/_browser-chunks/chunk-Y3M7TW6K.js +0 -1041
  159. package/dist/_browser-chunks/chunk-ZNRFDIVA.js +0 -233
  160. package/dist/_node-chunks/camelcase-H5QSGQLK.js +0 -18
  161. package/dist/_node-chunks/chunk-3THWHQOC.js +0 -61
  162. package/dist/_node-chunks/chunk-45YUOLTU.js +0 -69
  163. package/dist/_node-chunks/chunk-4QSNCPAU.js +0 -64656
  164. package/dist/_node-chunks/chunk-744PQSOU.js +0 -79
  165. package/dist/_node-chunks/chunk-74Z2U7QG.js +0 -1544
  166. package/dist/_node-chunks/chunk-7MB7TFPO.js +0 -1198
  167. package/dist/_node-chunks/chunk-A7GS4RFT.js +0 -697
  168. package/dist/_node-chunks/chunk-BIA3A5UM.js +0 -61
  169. package/dist/_node-chunks/chunk-C5G7CLWX.js +0 -1657
  170. package/dist/_node-chunks/chunk-DLFUKMYJ.js +0 -1531
  171. package/dist/_node-chunks/chunk-EMRGRXKT.js +0 -111
  172. package/dist/_node-chunks/chunk-EX46EHHY.js +0 -420
  173. package/dist/_node-chunks/chunk-F76QKNOJ.js +0 -304
  174. package/dist/_node-chunks/chunk-HDCRUTEF.js +0 -220
  175. package/dist/_node-chunks/chunk-HUYAOIPH.js +0 -90
  176. package/dist/_node-chunks/chunk-IBJZQZJC.js +0 -101
  177. package/dist/_node-chunks/chunk-KZN2RDDT.js +0 -6712
  178. package/dist/_node-chunks/chunk-LYUNFU3F.js +0 -4741
  179. package/dist/_node-chunks/chunk-N44SIS6K.js +0 -28
  180. package/dist/_node-chunks/chunk-NILZM6KR.js +0 -18
  181. package/dist/_node-chunks/chunk-PC4ZRP6W.js +0 -34
  182. package/dist/_node-chunks/chunk-TJNGOQUH.js +0 -4272
  183. package/dist/_node-chunks/chunk-UBSYLHIL.js +0 -1250
  184. package/dist/_node-chunks/chunk-UTCLXPOC.js +0 -1518
  185. package/dist/_node-chunks/chunk-WOXXODXP.js +0 -5029
  186. package/dist/_node-chunks/chunk-XC4MEUA6.js +0 -1586
  187. package/dist/_node-chunks/chunk-YRXXMKRR.js +0 -2256
  188. package/dist/_node-chunks/dist-SL73W244.js +0 -175
  189. package/dist/_node-chunks/globby-ZSHAUQZ5.js +0 -5222
  190. package/dist/_node-chunks/lib-U2VIPUTI.js +0 -518
  191. package/dist/_node-chunks/mdx-N42X6CFJ-ZLHD33JK.js +0 -22017
  192. package/dist/_node-chunks/p-limit-K5BS5MSV.js +0 -168
  193. package/dist/_node-chunks/plugin-5PD4YIUH.js +0 -129
  194. package/dist/_node-chunks/plugin-MONDT2WL.js +0 -159
  195. package/dist/_node-chunks/webpack-inject-mocker-runtime-plugin-EUZJRG3W.js +0 -69102
  196. package/dist/_node-chunks/webpack-mock-plugin-T4LDXEHE.js +0 -124
  197. package/dist/core-server/presets/webpack/loaders/storybook-mock-transform-loader.js +0 -36
  198. package/dist/core-server/presets/webpack/loaders/webpack-automock-loader.js +0 -33
@@ -1,3816 +0,0 @@
1
- import {
2
- mapValues
3
- } from "./chunk-UTNZYD2N.js";
4
- import {
5
- isPlainObject
6
- } from "./chunk-FSBVR7H5.js";
7
- import {
8
- __commonJS,
9
- __name,
10
- __toESM
11
- } from "./chunk-MM7DTO55.js";
12
-
13
- // ../node_modules/jsdoc-type-pratt-parser/dist/index.js
14
- var require_dist = __commonJS({
15
- "../node_modules/jsdoc-type-pratt-parser/dist/index.js"(exports, module) {
16
- (function(global, factory) {
17
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.jtpp = {}));
18
- })(exports, function(exports2) {
19
- "use strict";
20
- function tokenToString(token) {
21
- if (token.text !== void 0 && token.text !== "") {
22
- return `'${token.type}' with value '${token.text}'`;
23
- } else {
24
- return `'${token.type}'`;
25
- }
26
- }
27
- __name(tokenToString, "tokenToString");
28
- const _NoParsletFoundError = class _NoParsletFoundError extends Error {
29
- constructor(token) {
30
- super(`No parslet found for token: ${tokenToString(token)}`);
31
- this.token = token;
32
- Object.setPrototypeOf(this, _NoParsletFoundError.prototype);
33
- }
34
- getToken() {
35
- return this.token;
36
- }
37
- };
38
- __name(_NoParsletFoundError, "NoParsletFoundError");
39
- let NoParsletFoundError = _NoParsletFoundError;
40
- const _EarlyEndOfParseError = class _EarlyEndOfParseError extends Error {
41
- constructor(token) {
42
- super(`The parsing ended early. The next token was: ${tokenToString(token)}`);
43
- this.token = token;
44
- Object.setPrototypeOf(this, _EarlyEndOfParseError.prototype);
45
- }
46
- getToken() {
47
- return this.token;
48
- }
49
- };
50
- __name(_EarlyEndOfParseError, "EarlyEndOfParseError");
51
- let EarlyEndOfParseError = _EarlyEndOfParseError;
52
- const _UnexpectedTypeError = class _UnexpectedTypeError extends Error {
53
- constructor(result, message) {
54
- let error = `Unexpected type: '${result.type}'.`;
55
- if (message !== void 0) {
56
- error += ` Message: ${message}`;
57
- }
58
- super(error);
59
- Object.setPrototypeOf(this, _UnexpectedTypeError.prototype);
60
- }
61
- };
62
- __name(_UnexpectedTypeError, "UnexpectedTypeError");
63
- let UnexpectedTypeError = _UnexpectedTypeError;
64
- function makePunctuationRule(type) {
65
- return (text) => {
66
- if (text.startsWith(type)) {
67
- return { type, text: type };
68
- } else {
69
- return null;
70
- }
71
- };
72
- }
73
- __name(makePunctuationRule, "makePunctuationRule");
74
- function getQuoted(text) {
75
- let position = 0;
76
- let char;
77
- const mark = text[0];
78
- let escaped = false;
79
- if (mark !== "'" && mark !== '"') {
80
- return null;
81
- }
82
- while (position < text.length) {
83
- position++;
84
- char = text[position];
85
- if (!escaped && char === mark) {
86
- position++;
87
- break;
88
- }
89
- escaped = !escaped && char === "\\";
90
- }
91
- if (char !== mark) {
92
- throw new Error("Unterminated String");
93
- }
94
- return text.slice(0, position);
95
- }
96
- __name(getQuoted, "getQuoted");
97
- const identifierStartRegex = new RegExp("[$_\\p{ID_Start}]|\\\\u\\p{Hex_Digit}{4}|\\\\u\\{0*(?:\\p{Hex_Digit}{1,5}|10\\p{Hex_Digit}{4})\\}", "u");
98
- const identifierContinueRegex = 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");
99
- function getIdentifier(text) {
100
- let char = text[0];
101
- if (!identifierStartRegex.test(char)) {
102
- return null;
103
- }
104
- let position = 1;
105
- do {
106
- char = text[position];
107
- if (!identifierContinueRegex.test(char)) {
108
- break;
109
- }
110
- position++;
111
- } while (position < text.length);
112
- return text.slice(0, position);
113
- }
114
- __name(getIdentifier, "getIdentifier");
115
- const numberRegex = /^(NaN|-?((\d*\.\d+|\d+)([Ee][+-]?\d+)?|Infinity))/;
116
- function getNumber(text) {
117
- var _a, _b;
118
- return (_b = (_a = numberRegex.exec(text)) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : null;
119
- }
120
- __name(getNumber, "getNumber");
121
- const identifierRule = /* @__PURE__ */ __name((text) => {
122
- const value = getIdentifier(text);
123
- if (value == null) {
124
- return null;
125
- }
126
- return {
127
- type: "Identifier",
128
- text: value
129
- };
130
- }, "identifierRule");
131
- function makeKeyWordRule(type) {
132
- return (text) => {
133
- if (!text.startsWith(type)) {
134
- return null;
135
- }
136
- const prepends = text[type.length];
137
- if (prepends !== void 0 && identifierContinueRegex.test(prepends)) {
138
- return null;
139
- }
140
- return {
141
- type,
142
- text: type
143
- };
144
- };
145
- }
146
- __name(makeKeyWordRule, "makeKeyWordRule");
147
- const stringValueRule = /* @__PURE__ */ __name((text) => {
148
- const value = getQuoted(text);
149
- if (value == null) {
150
- return null;
151
- }
152
- return {
153
- type: "StringValue",
154
- text: value
155
- };
156
- }, "stringValueRule");
157
- const eofRule = /* @__PURE__ */ __name((text) => {
158
- if (text.length > 0) {
159
- return null;
160
- }
161
- return {
162
- type: "EOF",
163
- text: ""
164
- };
165
- }, "eofRule");
166
- const numberRule = /* @__PURE__ */ __name((text) => {
167
- const value = getNumber(text);
168
- if (value === null) {
169
- return null;
170
- }
171
- return {
172
- type: "Number",
173
- text: value
174
- };
175
- }, "numberRule");
176
- const rules = [
177
- eofRule,
178
- makePunctuationRule("=>"),
179
- makePunctuationRule("("),
180
- makePunctuationRule(")"),
181
- makePunctuationRule("{"),
182
- makePunctuationRule("}"),
183
- makePunctuationRule("["),
184
- makePunctuationRule("]"),
185
- makePunctuationRule("|"),
186
- makePunctuationRule("&"),
187
- makePunctuationRule("<"),
188
- makePunctuationRule(">"),
189
- makePunctuationRule(","),
190
- makePunctuationRule(";"),
191
- makePunctuationRule("*"),
192
- makePunctuationRule("?"),
193
- makePunctuationRule("!"),
194
- makePunctuationRule("="),
195
- makePunctuationRule(":"),
196
- makePunctuationRule("..."),
197
- makePunctuationRule("."),
198
- makePunctuationRule("#"),
199
- makePunctuationRule("~"),
200
- makePunctuationRule("/"),
201
- makePunctuationRule("@"),
202
- makeKeyWordRule("undefined"),
203
- makeKeyWordRule("null"),
204
- makeKeyWordRule("function"),
205
- makeKeyWordRule("this"),
206
- makeKeyWordRule("new"),
207
- makeKeyWordRule("module"),
208
- makeKeyWordRule("event"),
209
- makeKeyWordRule("extends"),
210
- makeKeyWordRule("external"),
211
- makeKeyWordRule("infer"),
212
- makeKeyWordRule("typeof"),
213
- makeKeyWordRule("keyof"),
214
- makeKeyWordRule("readonly"),
215
- makeKeyWordRule("import"),
216
- makeKeyWordRule("is"),
217
- makeKeyWordRule("in"),
218
- makeKeyWordRule("asserts"),
219
- numberRule,
220
- identifierRule,
221
- stringValueRule
222
- ];
223
- const breakingWhitespaceRegex = /^\s*\n\s*/;
224
- const _Lexer = class _Lexer {
225
- static create(text) {
226
- const current = this.read(text);
227
- text = current.text;
228
- const next = this.read(text);
229
- text = next.text;
230
- return new _Lexer(text, void 0, current.token, next.token);
231
- }
232
- constructor(text, previous, current, next) {
233
- this.text = "";
234
- this.text = text;
235
- this.previous = previous;
236
- this.current = current;
237
- this.next = next;
238
- }
239
- static read(text, startOfLine = false) {
240
- startOfLine = startOfLine || breakingWhitespaceRegex.test(text);
241
- text = text.trim();
242
- for (const rule of rules) {
243
- const partial = rule(text);
244
- if (partial !== null) {
245
- const token = Object.assign(Object.assign({}, partial), { startOfLine });
246
- text = text.slice(token.text.length);
247
- return { text, token };
248
- }
249
- }
250
- throw new Error("Unexpected Token " + text);
251
- }
252
- advance() {
253
- const next = _Lexer.read(this.text);
254
- return new _Lexer(next.text, this.current, this.next, next.token);
255
- }
256
- };
257
- __name(_Lexer, "Lexer");
258
- let Lexer = _Lexer;
259
- function assertRootResult(result) {
260
- if (result === void 0) {
261
- throw new Error("Unexpected undefined");
262
- }
263
- if (result.type === "JsdocTypeKeyValue" || result.type === "JsdocTypeParameterList" || result.type === "JsdocTypeProperty" || result.type === "JsdocTypeReadonlyProperty" || result.type === "JsdocTypeObjectField" || result.type === "JsdocTypeJsdocObjectField" || result.type === "JsdocTypeIndexSignature" || result.type === "JsdocTypeMappedType" || result.type === "JsdocTypeTypeParameter") {
264
- throw new UnexpectedTypeError(result);
265
- }
266
- return result;
267
- }
268
- __name(assertRootResult, "assertRootResult");
269
- function assertPlainKeyValueOrRootResult(result) {
270
- if (result.type === "JsdocTypeKeyValue") {
271
- return assertPlainKeyValueResult(result);
272
- }
273
- return assertRootResult(result);
274
- }
275
- __name(assertPlainKeyValueOrRootResult, "assertPlainKeyValueOrRootResult");
276
- function assertPlainKeyValueOrNameResult(result) {
277
- if (result.type === "JsdocTypeName") {
278
- return result;
279
- }
280
- return assertPlainKeyValueResult(result);
281
- }
282
- __name(assertPlainKeyValueOrNameResult, "assertPlainKeyValueOrNameResult");
283
- function assertPlainKeyValueResult(result) {
284
- if (result.type !== "JsdocTypeKeyValue") {
285
- throw new UnexpectedTypeError(result);
286
- }
287
- return result;
288
- }
289
- __name(assertPlainKeyValueResult, "assertPlainKeyValueResult");
290
- function assertNumberOrVariadicNameResult(result) {
291
- var _a;
292
- if (result.type === "JsdocTypeVariadic") {
293
- if (((_a = result.element) === null || _a === void 0 ? void 0 : _a.type) === "JsdocTypeName") {
294
- return result;
295
- }
296
- throw new UnexpectedTypeError(result);
297
- }
298
- if (result.type !== "JsdocTypeNumber" && result.type !== "JsdocTypeName") {
299
- throw new UnexpectedTypeError(result);
300
- }
301
- return result;
302
- }
303
- __name(assertNumberOrVariadicNameResult, "assertNumberOrVariadicNameResult");
304
- function assertArrayOrTupleResult(result) {
305
- if (result.type === "JsdocTypeTuple") {
306
- return result;
307
- }
308
- if (result.type === "JsdocTypeGeneric" && result.meta.brackets === "square") {
309
- return result;
310
- }
311
- throw new UnexpectedTypeError(result);
312
- }
313
- __name(assertArrayOrTupleResult, "assertArrayOrTupleResult");
314
- function isSquaredProperty(result) {
315
- return result.type === "JsdocTypeIndexSignature" || result.type === "JsdocTypeMappedType";
316
- }
317
- __name(isSquaredProperty, "isSquaredProperty");
318
- var Precedence;
319
- (function(Precedence2) {
320
- Precedence2[Precedence2["ALL"] = 0] = "ALL";
321
- Precedence2[Precedence2["PARAMETER_LIST"] = 1] = "PARAMETER_LIST";
322
- Precedence2[Precedence2["OBJECT"] = 2] = "OBJECT";
323
- Precedence2[Precedence2["KEY_VALUE"] = 3] = "KEY_VALUE";
324
- Precedence2[Precedence2["INDEX_BRACKETS"] = 4] = "INDEX_BRACKETS";
325
- Precedence2[Precedence2["UNION"] = 5] = "UNION";
326
- Precedence2[Precedence2["INTERSECTION"] = 6] = "INTERSECTION";
327
- Precedence2[Precedence2["PREFIX"] = 7] = "PREFIX";
328
- Precedence2[Precedence2["INFIX"] = 8] = "INFIX";
329
- Precedence2[Precedence2["TUPLE"] = 9] = "TUPLE";
330
- Precedence2[Precedence2["SYMBOL"] = 10] = "SYMBOL";
331
- Precedence2[Precedence2["OPTIONAL"] = 11] = "OPTIONAL";
332
- Precedence2[Precedence2["NULLABLE"] = 12] = "NULLABLE";
333
- Precedence2[Precedence2["KEY_OF_TYPE_OF"] = 13] = "KEY_OF_TYPE_OF";
334
- Precedence2[Precedence2["FUNCTION"] = 14] = "FUNCTION";
335
- Precedence2[Precedence2["ARROW"] = 15] = "ARROW";
336
- Precedence2[Precedence2["ARRAY_BRACKETS"] = 16] = "ARRAY_BRACKETS";
337
- Precedence2[Precedence2["GENERIC"] = 17] = "GENERIC";
338
- Precedence2[Precedence2["NAME_PATH"] = 18] = "NAME_PATH";
339
- Precedence2[Precedence2["PARENTHESIS"] = 19] = "PARENTHESIS";
340
- Precedence2[Precedence2["SPECIAL_TYPES"] = 20] = "SPECIAL_TYPES";
341
- })(Precedence || (Precedence = {}));
342
- const _Parser = class _Parser {
343
- constructor(grammar, textOrLexer, baseParser) {
344
- this.grammar = grammar;
345
- if (typeof textOrLexer === "string") {
346
- this._lexer = Lexer.create(textOrLexer);
347
- } else {
348
- this._lexer = textOrLexer;
349
- }
350
- this.baseParser = baseParser;
351
- }
352
- get lexer() {
353
- return this._lexer;
354
- }
355
- /**
356
- * Parses a given string and throws an error if the parse ended before the end of the string.
357
- */
358
- parse() {
359
- const result = this.parseType(Precedence.ALL);
360
- if (this.lexer.current.type !== "EOF") {
361
- throw new EarlyEndOfParseError(this.lexer.current);
362
- }
363
- return result;
364
- }
365
- /**
366
- * Parses with the current lexer and asserts that the result is a {@link RootResult}.
367
- */
368
- parseType(precedence) {
369
- return assertRootResult(this.parseIntermediateType(precedence));
370
- }
371
- /**
372
- * The main parsing function. First it tries to parse the current state in the prefix step, and then it continues
373
- * to parse the state in the infix step.
374
- */
375
- parseIntermediateType(precedence) {
376
- const result = this.tryParslets(null, precedence);
377
- if (result === null) {
378
- throw new NoParsletFoundError(this.lexer.current);
379
- }
380
- return this.parseInfixIntermediateType(result, precedence);
381
- }
382
- /**
383
- * In the infix parsing step the parser continues to parse the current state with all parslets until none returns
384
- * a result.
385
- */
386
- parseInfixIntermediateType(left, precedence) {
387
- let result = this.tryParslets(left, precedence);
388
- while (result !== null) {
389
- left = result;
390
- result = this.tryParslets(left, precedence);
391
- }
392
- return left;
393
- }
394
- /**
395
- * Tries to parse the current state with all parslets in the grammar and returns the first non null result.
396
- */
397
- tryParslets(left, precedence) {
398
- for (const parslet of this.grammar) {
399
- const result = parslet(this, precedence, left);
400
- if (result !== null) {
401
- return result;
402
- }
403
- }
404
- return null;
405
- }
406
- /**
407
- * If the given type equals the current type of the {@link Lexer} advance the lexer. Return true if the lexer was
408
- * advanced.
409
- */
410
- consume(types) {
411
- if (!Array.isArray(types)) {
412
- types = [types];
413
- }
414
- if (types.includes(this.lexer.current.type)) {
415
- this._lexer = this.lexer.advance();
416
- return true;
417
- } else {
418
- return false;
419
- }
420
- }
421
- acceptLexerState(parser) {
422
- this._lexer = parser.lexer;
423
- }
424
- };
425
- __name(_Parser, "Parser");
426
- let Parser = _Parser;
427
- function isQuestionMarkUnknownType(next) {
428
- return next === "}" || next === "EOF" || next === "|" || next === "," || next === ")" || next === ">";
429
- }
430
- __name(isQuestionMarkUnknownType, "isQuestionMarkUnknownType");
431
- const nullableParslet = /* @__PURE__ */ __name((parser, precedence, left) => {
432
- const type = parser.lexer.current.type;
433
- const next = parser.lexer.next.type;
434
- const accept = left == null && type === "?" && !isQuestionMarkUnknownType(next) || left != null && type === "?";
435
- if (!accept) {
436
- return null;
437
- }
438
- parser.consume("?");
439
- if (left == null) {
440
- return {
441
- type: "JsdocTypeNullable",
442
- element: parser.parseType(Precedence.NULLABLE),
443
- meta: {
444
- position: "prefix"
445
- }
446
- };
447
- } else {
448
- return {
449
- type: "JsdocTypeNullable",
450
- element: assertRootResult(left),
451
- meta: {
452
- position: "suffix"
453
- }
454
- };
455
- }
456
- }, "nullableParslet");
457
- function composeParslet(options) {
458
- const parslet = /* @__PURE__ */ __name((parser, curPrecedence, left) => {
459
- const type = parser.lexer.current.type;
460
- const next = parser.lexer.next.type;
461
- if (left === null) {
462
- if ("parsePrefix" in options) {
463
- if (options.accept(type, next)) {
464
- return options.parsePrefix(parser);
465
- }
466
- }
467
- } else {
468
- if ("parseInfix" in options) {
469
- if (options.precedence > curPrecedence && options.accept(type, next)) {
470
- return options.parseInfix(parser, left);
471
- }
472
- }
473
- }
474
- return null;
475
- }, "parslet");
476
- Object.defineProperty(parslet, "name", {
477
- value: options.name
478
- });
479
- return parslet;
480
- }
481
- __name(composeParslet, "composeParslet");
482
- const optionalParslet = composeParslet({
483
- name: "optionalParslet",
484
- accept: /* @__PURE__ */ __name((type) => type === "=", "accept"),
485
- precedence: Precedence.OPTIONAL,
486
- parsePrefix: /* @__PURE__ */ __name((parser) => {
487
- parser.consume("=");
488
- return {
489
- type: "JsdocTypeOptional",
490
- element: parser.parseType(Precedence.OPTIONAL),
491
- meta: {
492
- position: "prefix"
493
- }
494
- };
495
- }, "parsePrefix"),
496
- parseInfix: /* @__PURE__ */ __name((parser, left) => {
497
- parser.consume("=");
498
- return {
499
- type: "JsdocTypeOptional",
500
- element: assertRootResult(left),
501
- meta: {
502
- position: "suffix"
503
- }
504
- };
505
- }, "parseInfix")
506
- });
507
- const numberParslet = composeParslet({
508
- name: "numberParslet",
509
- accept: /* @__PURE__ */ __name((type) => type === "Number", "accept"),
510
- parsePrefix: /* @__PURE__ */ __name((parser) => {
511
- const value = parseFloat(parser.lexer.current.text);
512
- parser.consume("Number");
513
- return {
514
- type: "JsdocTypeNumber",
515
- value
516
- };
517
- }, "parsePrefix")
518
- });
519
- const parenthesisParslet = composeParslet({
520
- name: "parenthesisParslet",
521
- accept: /* @__PURE__ */ __name((type) => type === "(", "accept"),
522
- parsePrefix: /* @__PURE__ */ __name((parser) => {
523
- parser.consume("(");
524
- if (parser.consume(")")) {
525
- return {
526
- type: "JsdocTypeParameterList",
527
- elements: []
528
- };
529
- }
530
- const result = parser.parseIntermediateType(Precedence.ALL);
531
- if (!parser.consume(")")) {
532
- throw new Error("Unterminated parenthesis");
533
- }
534
- if (result.type === "JsdocTypeParameterList") {
535
- return result;
536
- } else if (result.type === "JsdocTypeKeyValue") {
537
- return {
538
- type: "JsdocTypeParameterList",
539
- elements: [result]
540
- };
541
- }
542
- return {
543
- type: "JsdocTypeParenthesis",
544
- element: assertRootResult(result)
545
- };
546
- }, "parsePrefix")
547
- });
548
- const specialTypesParslet = composeParslet({
549
- name: "specialTypesParslet",
550
- accept: /* @__PURE__ */ __name((type, next) => type === "?" && isQuestionMarkUnknownType(next) || type === "null" || type === "undefined" || type === "*", "accept"),
551
- parsePrefix: /* @__PURE__ */ __name((parser) => {
552
- if (parser.consume("null")) {
553
- return {
554
- type: "JsdocTypeNull"
555
- };
556
- }
557
- if (parser.consume("undefined")) {
558
- return {
559
- type: "JsdocTypeUndefined"
560
- };
561
- }
562
- if (parser.consume("*")) {
563
- return {
564
- type: "JsdocTypeAny"
565
- };
566
- }
567
- if (parser.consume("?")) {
568
- return {
569
- type: "JsdocTypeUnknown"
570
- };
571
- }
572
- throw new Error("Unacceptable token: " + parser.lexer.current.text);
573
- }, "parsePrefix")
574
- });
575
- const notNullableParslet = composeParslet({
576
- name: "notNullableParslet",
577
- accept: /* @__PURE__ */ __name((type) => type === "!", "accept"),
578
- precedence: Precedence.NULLABLE,
579
- parsePrefix: /* @__PURE__ */ __name((parser) => {
580
- parser.consume("!");
581
- return {
582
- type: "JsdocTypeNotNullable",
583
- element: parser.parseType(Precedence.NULLABLE),
584
- meta: {
585
- position: "prefix"
586
- }
587
- };
588
- }, "parsePrefix"),
589
- parseInfix: /* @__PURE__ */ __name((parser, left) => {
590
- parser.consume("!");
591
- return {
592
- type: "JsdocTypeNotNullable",
593
- element: assertRootResult(left),
594
- meta: {
595
- position: "suffix"
596
- }
597
- };
598
- }, "parseInfix")
599
- });
600
- function createParameterListParslet({ allowTrailingComma }) {
601
- return composeParslet({
602
- name: "parameterListParslet",
603
- accept: /* @__PURE__ */ __name((type) => type === ",", "accept"),
604
- precedence: Precedence.PARAMETER_LIST,
605
- parseInfix: /* @__PURE__ */ __name((parser, left) => {
606
- const elements = [
607
- assertPlainKeyValueOrRootResult(left)
608
- ];
609
- parser.consume(",");
610
- do {
611
- try {
612
- const next = parser.parseIntermediateType(Precedence.PARAMETER_LIST);
613
- elements.push(assertPlainKeyValueOrRootResult(next));
614
- } catch (e) {
615
- if (e instanceof NoParsletFoundError) {
616
- break;
617
- } else {
618
- throw e;
619
- }
620
- }
621
- } while (parser.consume(","));
622
- if (elements.length > 0 && elements.slice(0, -1).some((e) => e.type === "JsdocTypeVariadic")) {
623
- throw new Error("Only the last parameter may be a rest parameter");
624
- }
625
- return {
626
- type: "JsdocTypeParameterList",
627
- elements
628
- };
629
- }, "parseInfix")
630
- });
631
- }
632
- __name(createParameterListParslet, "createParameterListParslet");
633
- const genericParslet = composeParslet({
634
- name: "genericParslet",
635
- accept: /* @__PURE__ */ __name((type, next) => type === "<" || type === "." && next === "<", "accept"),
636
- precedence: Precedence.GENERIC,
637
- parseInfix: /* @__PURE__ */ __name((parser, left) => {
638
- const dot = parser.consume(".");
639
- parser.consume("<");
640
- const objects = [];
641
- let infer = false;
642
- if (parser.consume("infer")) {
643
- infer = true;
644
- const left2 = parser.parseIntermediateType(Precedence.SYMBOL);
645
- if (left2.type !== "JsdocTypeName") {
646
- throw new UnexpectedTypeError(left2, "A typescript asserts always has to have a name on the left side.");
647
- }
648
- objects.push(left2);
649
- } else {
650
- do {
651
- objects.push(parser.parseType(Precedence.PARAMETER_LIST));
652
- } while (parser.consume(","));
653
- }
654
- if (!parser.consume(">")) {
655
- throw new Error("Unterminated generic parameter list");
656
- }
657
- return Object.assign(Object.assign({ type: "JsdocTypeGeneric", left: assertRootResult(left), elements: objects }, infer ? { infer: true } : {}), { meta: {
658
- brackets: "angle",
659
- dot
660
- } });
661
- }, "parseInfix")
662
- });
663
- const unionParslet = composeParslet({
664
- name: "unionParslet",
665
- accept: /* @__PURE__ */ __name((type) => type === "|", "accept"),
666
- precedence: Precedence.UNION,
667
- parseInfix: /* @__PURE__ */ __name((parser, left) => {
668
- parser.consume("|");
669
- const elements = [];
670
- do {
671
- elements.push(parser.parseType(Precedence.UNION));
672
- } while (parser.consume("|"));
673
- return {
674
- type: "JsdocTypeUnion",
675
- elements: [assertRootResult(left), ...elements]
676
- };
677
- }, "parseInfix")
678
- });
679
- const baseGrammar = [
680
- nullableParslet,
681
- optionalParslet,
682
- numberParslet,
683
- parenthesisParslet,
684
- specialTypesParslet,
685
- notNullableParslet,
686
- createParameterListParslet({
687
- allowTrailingComma: true
688
- }),
689
- genericParslet,
690
- unionParslet,
691
- optionalParslet
692
- ];
693
- function createNamePathParslet({ allowSquareBracketsOnAnyType, allowJsdocNamePaths, pathGrammar: pathGrammar2 }) {
694
- return /* @__PURE__ */ __name(function namePathParslet(parser, precedence, left) {
695
- if (left == null || precedence >= Precedence.NAME_PATH) {
696
- return null;
697
- }
698
- const type = parser.lexer.current.type;
699
- const next = parser.lexer.next.type;
700
- const accept = type === "." && next !== "<" || type === "[" && (allowSquareBracketsOnAnyType || left.type === "JsdocTypeName") || allowJsdocNamePaths && (type === "~" || type === "#");
701
- if (!accept) {
702
- return null;
703
- }
704
- let pathType;
705
- let brackets = false;
706
- if (parser.consume(".")) {
707
- pathType = "property";
708
- } else if (parser.consume("[")) {
709
- pathType = "property-brackets";
710
- brackets = true;
711
- } else if (parser.consume("~")) {
712
- pathType = "inner";
713
- } else {
714
- parser.consume("#");
715
- pathType = "instance";
716
- }
717
- const pathParser = pathGrammar2 !== null ? new Parser(pathGrammar2, parser.lexer, parser) : parser;
718
- const parsed = pathParser.parseIntermediateType(Precedence.NAME_PATH);
719
- parser.acceptLexerState(pathParser);
720
- let right;
721
- switch (parsed.type) {
722
- case "JsdocTypeName":
723
- right = {
724
- type: "JsdocTypeProperty",
725
- value: parsed.value,
726
- meta: {
727
- quote: void 0
728
- }
729
- };
730
- break;
731
- case "JsdocTypeNumber":
732
- right = {
733
- type: "JsdocTypeProperty",
734
- value: parsed.value.toString(10),
735
- meta: {
736
- quote: void 0
737
- }
738
- };
739
- break;
740
- case "JsdocTypeStringValue":
741
- right = {
742
- type: "JsdocTypeProperty",
743
- value: parsed.value,
744
- meta: {
745
- quote: parsed.meta.quote
746
- }
747
- };
748
- break;
749
- case "JsdocTypeSpecialNamePath":
750
- if (parsed.specialType === "event") {
751
- right = parsed;
752
- } else {
753
- throw new UnexpectedTypeError(parsed, "Type 'JsdocTypeSpecialNamePath' is only allowed with specialType 'event'");
754
- }
755
- break;
756
- default:
757
- throw new UnexpectedTypeError(parsed, "Expecting 'JsdocTypeName', 'JsdocTypeNumber', 'JsdocStringValue' or 'JsdocTypeSpecialNamePath'");
758
- }
759
- if (brackets && !parser.consume("]")) {
760
- const token = parser.lexer.current;
761
- throw new Error(`Unterminated square brackets. Next token is '${token.type}' with text '${token.text}'`);
762
- }
763
- return {
764
- type: "JsdocTypeNamePath",
765
- left: assertRootResult(left),
766
- right,
767
- pathType
768
- };
769
- }, "namePathParslet");
770
- }
771
- __name(createNamePathParslet, "createNamePathParslet");
772
- function createNameParslet({ allowedAdditionalTokens }) {
773
- return composeParslet({
774
- name: "nameParslet",
775
- accept: /* @__PURE__ */ __name((type) => type === "Identifier" || type === "this" || type === "new" || allowedAdditionalTokens.includes(type), "accept"),
776
- parsePrefix: /* @__PURE__ */ __name((parser) => {
777
- const { type, text } = parser.lexer.current;
778
- parser.consume(type);
779
- return {
780
- type: "JsdocTypeName",
781
- value: text
782
- };
783
- }, "parsePrefix")
784
- });
785
- }
786
- __name(createNameParslet, "createNameParslet");
787
- const stringValueParslet = composeParslet({
788
- name: "stringValueParslet",
789
- accept: /* @__PURE__ */ __name((type) => type === "StringValue", "accept"),
790
- parsePrefix: /* @__PURE__ */ __name((parser) => {
791
- const text = parser.lexer.current.text;
792
- parser.consume("StringValue");
793
- return {
794
- type: "JsdocTypeStringValue",
795
- value: text.slice(1, -1),
796
- meta: {
797
- quote: text[0] === "'" ? "single" : "double"
798
- }
799
- };
800
- }, "parsePrefix")
801
- });
802
- function createSpecialNamePathParslet({ pathGrammar: pathGrammar2, allowedTypes }) {
803
- return composeParslet({
804
- name: "specialNamePathParslet",
805
- accept: /* @__PURE__ */ __name((type) => allowedTypes.includes(type), "accept"),
806
- parsePrefix: /* @__PURE__ */ __name((parser) => {
807
- const type = parser.lexer.current.type;
808
- parser.consume(type);
809
- if (!parser.consume(":")) {
810
- return {
811
- type: "JsdocTypeName",
812
- value: type
813
- };
814
- }
815
- let result;
816
- let token = parser.lexer.current;
817
- if (parser.consume("StringValue")) {
818
- result = {
819
- type: "JsdocTypeSpecialNamePath",
820
- value: token.text.slice(1, -1),
821
- specialType: type,
822
- meta: {
823
- quote: token.text[0] === "'" ? "single" : "double"
824
- }
825
- };
826
- } else {
827
- let value = "";
828
- const allowed = ["Identifier", "@", "/"];
829
- while (allowed.some((type2) => parser.consume(type2))) {
830
- value += token.text;
831
- token = parser.lexer.current;
832
- }
833
- result = {
834
- type: "JsdocTypeSpecialNamePath",
835
- value,
836
- specialType: type,
837
- meta: {
838
- quote: void 0
839
- }
840
- };
841
- }
842
- const moduleParser = new Parser(pathGrammar2, parser.lexer, parser);
843
- const moduleResult = moduleParser.parseInfixIntermediateType(result, Precedence.ALL);
844
- parser.acceptLexerState(moduleParser);
845
- return assertRootResult(moduleResult);
846
- }, "parsePrefix")
847
- });
848
- }
849
- __name(createSpecialNamePathParslet, "createSpecialNamePathParslet");
850
- const basePathGrammar = [
851
- createNameParslet({
852
- allowedAdditionalTokens: ["external", "module"]
853
- }),
854
- stringValueParslet,
855
- numberParslet,
856
- createNamePathParslet({
857
- allowSquareBracketsOnAnyType: false,
858
- allowJsdocNamePaths: true,
859
- pathGrammar: null
860
- })
861
- ];
862
- const pathGrammar = [
863
- ...basePathGrammar,
864
- createSpecialNamePathParslet({
865
- allowedTypes: ["event"],
866
- pathGrammar: basePathGrammar
867
- })
868
- ];
869
- function getParameters(value) {
870
- let parameters;
871
- if (value.type === "JsdocTypeParameterList") {
872
- parameters = value.elements;
873
- } else if (value.type === "JsdocTypeParenthesis") {
874
- parameters = [value.element];
875
- } else {
876
- throw new UnexpectedTypeError(value);
877
- }
878
- return parameters.map((p) => assertPlainKeyValueOrRootResult(p));
879
- }
880
- __name(getParameters, "getParameters");
881
- function getUnnamedParameters(value) {
882
- const parameters = getParameters(value);
883
- if (parameters.some((p) => p.type === "JsdocTypeKeyValue")) {
884
- throw new Error("No parameter should be named");
885
- }
886
- return parameters;
887
- }
888
- __name(getUnnamedParameters, "getUnnamedParameters");
889
- function createFunctionParslet({ allowNamedParameters, allowNoReturnType, allowWithoutParenthesis, allowNewAsFunctionKeyword }) {
890
- return composeParslet({
891
- name: "functionParslet",
892
- accept: /* @__PURE__ */ __name((type, next) => type === "function" || allowNewAsFunctionKeyword && type === "new" && next === "(", "accept"),
893
- parsePrefix: /* @__PURE__ */ __name((parser) => {
894
- const newKeyword = parser.consume("new");
895
- parser.consume("function");
896
- const hasParenthesis = parser.lexer.current.type === "(";
897
- if (!hasParenthesis) {
898
- if (!allowWithoutParenthesis) {
899
- throw new Error("function is missing parameter list");
900
- }
901
- return {
902
- type: "JsdocTypeName",
903
- value: "function"
904
- };
905
- }
906
- let result = {
907
- type: "JsdocTypeFunction",
908
- parameters: [],
909
- arrow: false,
910
- constructor: newKeyword,
911
- parenthesis: hasParenthesis
912
- };
913
- const value = parser.parseIntermediateType(Precedence.FUNCTION);
914
- if (allowNamedParameters === void 0) {
915
- result.parameters = getUnnamedParameters(value);
916
- } else if (newKeyword && value.type === "JsdocTypeFunction" && value.arrow) {
917
- result = value;
918
- result.constructor = true;
919
- return result;
920
- } else {
921
- result.parameters = getParameters(value);
922
- for (const p of result.parameters) {
923
- if (p.type === "JsdocTypeKeyValue" && !allowNamedParameters.includes(p.key)) {
924
- throw new Error(`only allowed named parameters are ${allowNamedParameters.join(", ")} but got ${p.type}`);
925
- }
926
- }
927
- }
928
- if (parser.consume(":")) {
929
- result.returnType = parser.parseType(Precedence.PREFIX);
930
- } else {
931
- if (!allowNoReturnType) {
932
- throw new Error("function is missing return type");
933
- }
934
- }
935
- return result;
936
- }, "parsePrefix")
937
- });
938
- }
939
- __name(createFunctionParslet, "createFunctionParslet");
940
- function createVariadicParslet({ allowPostfix, allowEnclosingBrackets }) {
941
- return composeParslet({
942
- name: "variadicParslet",
943
- accept: /* @__PURE__ */ __name((type) => type === "...", "accept"),
944
- precedence: Precedence.PREFIX,
945
- parsePrefix: /* @__PURE__ */ __name((parser) => {
946
- parser.consume("...");
947
- const brackets = allowEnclosingBrackets && parser.consume("[");
948
- try {
949
- const element = parser.parseType(Precedence.PREFIX);
950
- if (brackets && !parser.consume("]")) {
951
- throw new Error("Unterminated variadic type. Missing ']'");
952
- }
953
- return {
954
- type: "JsdocTypeVariadic",
955
- element: assertRootResult(element),
956
- meta: {
957
- position: "prefix",
958
- squareBrackets: brackets
959
- }
960
- };
961
- } catch (e) {
962
- if (e instanceof NoParsletFoundError) {
963
- if (brackets) {
964
- throw new Error("Empty square brackets for variadic are not allowed.");
965
- }
966
- return {
967
- type: "JsdocTypeVariadic",
968
- meta: {
969
- position: void 0,
970
- squareBrackets: false
971
- }
972
- };
973
- } else {
974
- throw e;
975
- }
976
- }
977
- }, "parsePrefix"),
978
- parseInfix: allowPostfix ? (parser, left) => {
979
- parser.consume("...");
980
- return {
981
- type: "JsdocTypeVariadic",
982
- element: assertRootResult(left),
983
- meta: {
984
- position: "suffix",
985
- squareBrackets: false
986
- }
987
- };
988
- } : void 0
989
- });
990
- }
991
- __name(createVariadicParslet, "createVariadicParslet");
992
- const symbolParslet = composeParslet({
993
- name: "symbolParslet",
994
- accept: /* @__PURE__ */ __name((type) => type === "(", "accept"),
995
- precedence: Precedence.SYMBOL,
996
- parseInfix: /* @__PURE__ */ __name((parser, left) => {
997
- if (left.type !== "JsdocTypeName") {
998
- throw new Error("Symbol expects a name on the left side. (Reacting on '(')");
999
- }
1000
- parser.consume("(");
1001
- const result = {
1002
- type: "JsdocTypeSymbol",
1003
- value: left.value
1004
- };
1005
- if (!parser.consume(")")) {
1006
- const next = parser.parseIntermediateType(Precedence.SYMBOL);
1007
- result.element = assertNumberOrVariadicNameResult(next);
1008
- if (!parser.consume(")")) {
1009
- throw new Error("Symbol does not end after value");
1010
- }
1011
- }
1012
- return result;
1013
- }, "parseInfix")
1014
- });
1015
- const arrayBracketsParslet = composeParslet({
1016
- name: "arrayBracketsParslet",
1017
- precedence: Precedence.ARRAY_BRACKETS,
1018
- accept: /* @__PURE__ */ __name((type, next) => type === "[" && next === "]", "accept"),
1019
- parseInfix: /* @__PURE__ */ __name((parser, left) => {
1020
- parser.consume("[");
1021
- parser.consume("]");
1022
- return {
1023
- type: "JsdocTypeGeneric",
1024
- left: {
1025
- type: "JsdocTypeName",
1026
- value: "Array"
1027
- },
1028
- elements: [
1029
- assertRootResult(left)
1030
- ],
1031
- meta: {
1032
- brackets: "square",
1033
- dot: false
1034
- }
1035
- };
1036
- }, "parseInfix")
1037
- });
1038
- function createObjectParslet({ objectFieldGrammar: objectFieldGrammar2, allowKeyTypes }) {
1039
- return composeParslet({
1040
- name: "objectParslet",
1041
- accept: /* @__PURE__ */ __name((type) => type === "{", "accept"),
1042
- parsePrefix: /* @__PURE__ */ __name((parser) => {
1043
- parser.consume("{");
1044
- const result = {
1045
- type: "JsdocTypeObject",
1046
- meta: {
1047
- separator: "comma"
1048
- },
1049
- elements: []
1050
- };
1051
- if (!parser.consume("}")) {
1052
- let separator;
1053
- const fieldParser = new Parser(objectFieldGrammar2, parser.lexer, parser);
1054
- while (true) {
1055
- fieldParser.acceptLexerState(parser);
1056
- let field = fieldParser.parseIntermediateType(Precedence.OBJECT);
1057
- parser.acceptLexerState(fieldParser);
1058
- if (field === void 0 && allowKeyTypes) {
1059
- field = parser.parseIntermediateType(Precedence.OBJECT);
1060
- }
1061
- let optional = false;
1062
- if (field.type === "JsdocTypeNullable") {
1063
- optional = true;
1064
- field = field.element;
1065
- }
1066
- if (field.type === "JsdocTypeNumber" || field.type === "JsdocTypeName" || field.type === "JsdocTypeStringValue") {
1067
- let quote2;
1068
- if (field.type === "JsdocTypeStringValue") {
1069
- quote2 = field.meta.quote;
1070
- }
1071
- result.elements.push({
1072
- type: "JsdocTypeObjectField",
1073
- key: field.value.toString(),
1074
- right: void 0,
1075
- optional,
1076
- readonly: false,
1077
- meta: {
1078
- quote: quote2
1079
- }
1080
- });
1081
- } else if (field.type === "JsdocTypeObjectField" || field.type === "JsdocTypeJsdocObjectField") {
1082
- result.elements.push(field);
1083
- } else {
1084
- throw new UnexpectedTypeError(field);
1085
- }
1086
- if (parser.lexer.current.startOfLine) {
1087
- separator = "linebreak";
1088
- parser.consume(",") || parser.consume(";");
1089
- } else if (parser.consume(",")) {
1090
- separator = "comma";
1091
- } else if (parser.consume(";")) {
1092
- separator = "semicolon";
1093
- } else {
1094
- break;
1095
- }
1096
- const type = parser.lexer.current.type;
1097
- if (type === "}") {
1098
- break;
1099
- }
1100
- }
1101
- result.meta.separator = separator !== null && separator !== void 0 ? separator : "comma";
1102
- if (separator === "linebreak") {
1103
- result.meta.propertyIndent = " ";
1104
- }
1105
- if (!parser.consume("}")) {
1106
- throw new Error("Unterminated record type. Missing '}'");
1107
- }
1108
- }
1109
- return result;
1110
- }, "parsePrefix")
1111
- });
1112
- }
1113
- __name(createObjectParslet, "createObjectParslet");
1114
- function createObjectFieldParslet({ allowSquaredProperties, allowKeyTypes, allowReadonly, allowOptional }) {
1115
- return composeParslet({
1116
- name: "objectFieldParslet",
1117
- precedence: Precedence.KEY_VALUE,
1118
- accept: /* @__PURE__ */ __name((type) => type === ":", "accept"),
1119
- parseInfix: /* @__PURE__ */ __name((parser, left) => {
1120
- var _a;
1121
- let optional = false;
1122
- let readonlyProperty = false;
1123
- if (allowOptional && left.type === "JsdocTypeNullable") {
1124
- optional = true;
1125
- left = left.element;
1126
- }
1127
- if (allowReadonly && left.type === "JsdocTypeReadonlyProperty") {
1128
- readonlyProperty = true;
1129
- left = left.element;
1130
- }
1131
- const parentParser = (_a = parser.baseParser) !== null && _a !== void 0 ? _a : parser;
1132
- parentParser.acceptLexerState(parser);
1133
- if (left.type === "JsdocTypeNumber" || left.type === "JsdocTypeName" || left.type === "JsdocTypeStringValue" || isSquaredProperty(left)) {
1134
- if (isSquaredProperty(left) && !allowSquaredProperties) {
1135
- throw new UnexpectedTypeError(left);
1136
- }
1137
- parentParser.consume(":");
1138
- let quote2;
1139
- if (left.type === "JsdocTypeStringValue") {
1140
- quote2 = left.meta.quote;
1141
- }
1142
- const right = parentParser.parseType(Precedence.KEY_VALUE);
1143
- parser.acceptLexerState(parentParser);
1144
- return {
1145
- type: "JsdocTypeObjectField",
1146
- key: isSquaredProperty(left) ? left : left.value.toString(),
1147
- right,
1148
- optional,
1149
- readonly: readonlyProperty,
1150
- meta: {
1151
- quote: quote2
1152
- }
1153
- };
1154
- } else {
1155
- if (!allowKeyTypes) {
1156
- throw new UnexpectedTypeError(left);
1157
- }
1158
- parentParser.consume(":");
1159
- const right = parentParser.parseType(Precedence.KEY_VALUE);
1160
- parser.acceptLexerState(parentParser);
1161
- return {
1162
- type: "JsdocTypeJsdocObjectField",
1163
- left: assertRootResult(left),
1164
- right
1165
- };
1166
- }
1167
- }, "parseInfix")
1168
- });
1169
- }
1170
- __name(createObjectFieldParslet, "createObjectFieldParslet");
1171
- function createKeyValueParslet({ allowOptional, allowVariadic }) {
1172
- return composeParslet({
1173
- name: "keyValueParslet",
1174
- precedence: Precedence.KEY_VALUE,
1175
- accept: /* @__PURE__ */ __name((type) => type === ":", "accept"),
1176
- parseInfix: /* @__PURE__ */ __name((parser, left) => {
1177
- let optional = false;
1178
- let variadic = false;
1179
- if (allowOptional && left.type === "JsdocTypeNullable") {
1180
- optional = true;
1181
- left = left.element;
1182
- }
1183
- if (allowVariadic && left.type === "JsdocTypeVariadic" && left.element !== void 0) {
1184
- variadic = true;
1185
- left = left.element;
1186
- }
1187
- if (left.type !== "JsdocTypeName") {
1188
- throw new UnexpectedTypeError(left);
1189
- }
1190
- parser.consume(":");
1191
- const right = parser.parseType(Precedence.KEY_VALUE);
1192
- return {
1193
- type: "JsdocTypeKeyValue",
1194
- key: left.value,
1195
- right,
1196
- optional,
1197
- variadic
1198
- };
1199
- }, "parseInfix")
1200
- });
1201
- }
1202
- __name(createKeyValueParslet, "createKeyValueParslet");
1203
- const jsdocBaseGrammar = [
1204
- ...baseGrammar,
1205
- createFunctionParslet({
1206
- allowWithoutParenthesis: true,
1207
- allowNamedParameters: ["this", "new"],
1208
- allowNoReturnType: true,
1209
- allowNewAsFunctionKeyword: false
1210
- }),
1211
- stringValueParslet,
1212
- createSpecialNamePathParslet({
1213
- allowedTypes: ["module", "external", "event"],
1214
- pathGrammar
1215
- }),
1216
- createVariadicParslet({
1217
- allowEnclosingBrackets: true,
1218
- allowPostfix: true
1219
- }),
1220
- createNameParslet({
1221
- allowedAdditionalTokens: ["keyof"]
1222
- }),
1223
- symbolParslet,
1224
- arrayBracketsParslet,
1225
- createNamePathParslet({
1226
- allowSquareBracketsOnAnyType: false,
1227
- allowJsdocNamePaths: true,
1228
- pathGrammar
1229
- })
1230
- ];
1231
- const jsdocGrammar = [
1232
- ...jsdocBaseGrammar,
1233
- createObjectParslet({
1234
- // jsdoc syntax allows full types as keys, so we need to pull in the full grammar here
1235
- // we leave out the object type deliberately
1236
- objectFieldGrammar: [
1237
- createNameParslet({
1238
- allowedAdditionalTokens: ["typeof", "module", "in"]
1239
- }),
1240
- createObjectFieldParslet({
1241
- allowSquaredProperties: false,
1242
- allowKeyTypes: true,
1243
- allowOptional: false,
1244
- allowReadonly: false
1245
- }),
1246
- ...jsdocBaseGrammar
1247
- ],
1248
- allowKeyTypes: true
1249
- }),
1250
- createKeyValueParslet({
1251
- allowOptional: true,
1252
- allowVariadic: true
1253
- })
1254
- ];
1255
- const typeOfParslet = composeParslet({
1256
- name: "typeOfParslet",
1257
- accept: /* @__PURE__ */ __name((type) => type === "typeof", "accept"),
1258
- parsePrefix: /* @__PURE__ */ __name((parser) => {
1259
- parser.consume("typeof");
1260
- return {
1261
- type: "JsdocTypeTypeof",
1262
- element: parser.parseType(Precedence.KEY_OF_TYPE_OF)
1263
- };
1264
- }, "parsePrefix")
1265
- });
1266
- const objectFieldGrammar$1 = [
1267
- createNameParslet({
1268
- allowedAdditionalTokens: ["typeof", "module", "keyof", "event", "external", "in"]
1269
- }),
1270
- nullableParslet,
1271
- optionalParslet,
1272
- stringValueParslet,
1273
- numberParslet,
1274
- createObjectFieldParslet({
1275
- allowSquaredProperties: false,
1276
- allowKeyTypes: false,
1277
- allowOptional: false,
1278
- allowReadonly: false
1279
- })
1280
- ];
1281
- const closureGrammar = [
1282
- ...baseGrammar,
1283
- createObjectParslet({
1284
- allowKeyTypes: false,
1285
- objectFieldGrammar: objectFieldGrammar$1
1286
- }),
1287
- createNameParslet({
1288
- allowedAdditionalTokens: ["event", "external", "in"]
1289
- }),
1290
- typeOfParslet,
1291
- createFunctionParslet({
1292
- allowWithoutParenthesis: false,
1293
- allowNamedParameters: ["this", "new"],
1294
- allowNoReturnType: true,
1295
- allowNewAsFunctionKeyword: false
1296
- }),
1297
- createVariadicParslet({
1298
- allowEnclosingBrackets: false,
1299
- allowPostfix: false
1300
- }),
1301
- // additional name parslet is needed for some special cases
1302
- createNameParslet({
1303
- allowedAdditionalTokens: ["keyof"]
1304
- }),
1305
- createSpecialNamePathParslet({
1306
- allowedTypes: ["module"],
1307
- pathGrammar
1308
- }),
1309
- createNamePathParslet({
1310
- allowSquareBracketsOnAnyType: false,
1311
- allowJsdocNamePaths: true,
1312
- pathGrammar
1313
- }),
1314
- createKeyValueParslet({
1315
- allowOptional: false,
1316
- allowVariadic: false
1317
- }),
1318
- symbolParslet
1319
- ];
1320
- const assertsParslet = composeParslet({
1321
- name: "assertsParslet",
1322
- accept: /* @__PURE__ */ __name((type) => type === "asserts", "accept"),
1323
- parsePrefix: /* @__PURE__ */ __name((parser) => {
1324
- parser.consume("asserts");
1325
- const left = parser.parseIntermediateType(Precedence.SYMBOL);
1326
- if (left.type !== "JsdocTypeName") {
1327
- throw new UnexpectedTypeError(left, "A typescript asserts always has to have a name on the left side.");
1328
- }
1329
- if (!parser.consume("is")) {
1330
- return {
1331
- type: "JsdocTypeAssertsPlain",
1332
- element: left
1333
- };
1334
- }
1335
- return {
1336
- type: "JsdocTypeAsserts",
1337
- left,
1338
- right: assertRootResult(parser.parseIntermediateType(Precedence.INFIX))
1339
- };
1340
- }, "parsePrefix")
1341
- });
1342
- function createTupleParslet({ allowQuestionMark }) {
1343
- return composeParslet({
1344
- name: "tupleParslet",
1345
- accept: /* @__PURE__ */ __name((type) => type === "[", "accept"),
1346
- parsePrefix: /* @__PURE__ */ __name((parser) => {
1347
- parser.consume("[");
1348
- const result = {
1349
- type: "JsdocTypeTuple",
1350
- elements: []
1351
- };
1352
- if (parser.consume("]")) {
1353
- return result;
1354
- }
1355
- const typeList = parser.parseIntermediateType(Precedence.ALL);
1356
- if (typeList.type === "JsdocTypeParameterList") {
1357
- if (typeList.elements[0].type === "JsdocTypeKeyValue") {
1358
- result.elements = typeList.elements.map(assertPlainKeyValueResult);
1359
- } else {
1360
- result.elements = typeList.elements.map(assertRootResult);
1361
- }
1362
- } else {
1363
- if (typeList.type === "JsdocTypeKeyValue") {
1364
- result.elements = [assertPlainKeyValueResult(typeList)];
1365
- } else {
1366
- result.elements = [assertRootResult(typeList)];
1367
- }
1368
- }
1369
- if (!parser.consume("]")) {
1370
- throw new Error("Unterminated '['");
1371
- }
1372
- if (result.elements.some((e) => e.type === "JsdocTypeUnknown")) {
1373
- throw new Error("Question mark in tuple not allowed");
1374
- }
1375
- return result;
1376
- }, "parsePrefix")
1377
- });
1378
- }
1379
- __name(createTupleParslet, "createTupleParslet");
1380
- const keyOfParslet = composeParslet({
1381
- name: "keyOfParslet",
1382
- accept: /* @__PURE__ */ __name((type) => type === "keyof", "accept"),
1383
- parsePrefix: /* @__PURE__ */ __name((parser) => {
1384
- parser.consume("keyof");
1385
- return {
1386
- type: "JsdocTypeKeyof",
1387
- element: assertRootResult(parser.parseType(Precedence.KEY_OF_TYPE_OF))
1388
- };
1389
- }, "parsePrefix")
1390
- });
1391
- const importParslet = composeParslet({
1392
- name: "importParslet",
1393
- accept: /* @__PURE__ */ __name((type) => type === "import", "accept"),
1394
- parsePrefix: /* @__PURE__ */ __name((parser) => {
1395
- parser.consume("import");
1396
- if (!parser.consume("(")) {
1397
- throw new Error("Missing parenthesis after import keyword");
1398
- }
1399
- const path = parser.parseType(Precedence.PREFIX);
1400
- if (path.type !== "JsdocTypeStringValue") {
1401
- throw new Error("Only string values are allowed as paths for imports");
1402
- }
1403
- if (!parser.consume(")")) {
1404
- throw new Error("Missing closing parenthesis after import keyword");
1405
- }
1406
- return {
1407
- type: "JsdocTypeImport",
1408
- element: path
1409
- };
1410
- }, "parsePrefix")
1411
- });
1412
- const readonlyPropertyParslet = composeParslet({
1413
- name: "readonlyPropertyParslet",
1414
- accept: /* @__PURE__ */ __name((type) => type === "readonly", "accept"),
1415
- parsePrefix: /* @__PURE__ */ __name((parser) => {
1416
- parser.consume("readonly");
1417
- return {
1418
- type: "JsdocTypeReadonlyProperty",
1419
- element: parser.parseIntermediateType(Precedence.KEY_VALUE)
1420
- };
1421
- }, "parsePrefix")
1422
- });
1423
- const arrowFunctionParslet = composeParslet({
1424
- name: "arrowFunctionParslet",
1425
- precedence: Precedence.ARROW,
1426
- accept: /* @__PURE__ */ __name((type) => type === "=>", "accept"),
1427
- parseInfix: /* @__PURE__ */ __name((parser, left) => {
1428
- parser.consume("=>");
1429
- return {
1430
- type: "JsdocTypeFunction",
1431
- parameters: getParameters(left).map(assertPlainKeyValueOrNameResult),
1432
- arrow: true,
1433
- constructor: false,
1434
- parenthesis: true,
1435
- returnType: parser.parseType(Precedence.OBJECT)
1436
- };
1437
- }, "parseInfix")
1438
- });
1439
- const genericArrowFunctionParslet = composeParslet({
1440
- name: "genericArrowFunctionParslet",
1441
- accept: /* @__PURE__ */ __name((type) => type === "<", "accept"),
1442
- parsePrefix: /* @__PURE__ */ __name((parser) => {
1443
- const typeParameters = [];
1444
- parser.consume("<");
1445
- do {
1446
- let defaultValue;
1447
- let name = parser.parseIntermediateType(Precedence.SYMBOL);
1448
- if (name.type === "JsdocTypeOptional") {
1449
- name = name.element;
1450
- defaultValue = parser.parseType(Precedence.SYMBOL);
1451
- }
1452
- if (name.type !== "JsdocTypeName") {
1453
- throw new UnexpectedTypeError(name);
1454
- }
1455
- let constraint;
1456
- if (parser.consume("extends")) {
1457
- constraint = parser.parseType(Precedence.SYMBOL);
1458
- if (constraint.type === "JsdocTypeOptional") {
1459
- constraint = constraint.element;
1460
- defaultValue = parser.parseType(Precedence.SYMBOL);
1461
- }
1462
- }
1463
- const typeParameter = {
1464
- type: "JsdocTypeTypeParameter",
1465
- name
1466
- };
1467
- if (constraint !== void 0) {
1468
- typeParameter.constraint = constraint;
1469
- }
1470
- if (defaultValue !== void 0) {
1471
- typeParameter.defaultValue = defaultValue;
1472
- }
1473
- typeParameters.push(typeParameter);
1474
- if (parser.consume(">")) {
1475
- break;
1476
- }
1477
- } while (parser.consume(","));
1478
- const functionBase = parser.parseIntermediateType(Precedence.SYMBOL);
1479
- functionBase.typeParameters = typeParameters;
1480
- return functionBase;
1481
- }, "parsePrefix")
1482
- });
1483
- const intersectionParslet = composeParslet({
1484
- name: "intersectionParslet",
1485
- accept: /* @__PURE__ */ __name((type) => type === "&", "accept"),
1486
- precedence: Precedence.INTERSECTION,
1487
- parseInfix: /* @__PURE__ */ __name((parser, left) => {
1488
- parser.consume("&");
1489
- const elements = [];
1490
- do {
1491
- elements.push(parser.parseType(Precedence.INTERSECTION));
1492
- } while (parser.consume("&"));
1493
- return {
1494
- type: "JsdocTypeIntersection",
1495
- elements: [assertRootResult(left), ...elements]
1496
- };
1497
- }, "parseInfix")
1498
- });
1499
- const predicateParslet = composeParslet({
1500
- name: "predicateParslet",
1501
- precedence: Precedence.INFIX,
1502
- accept: /* @__PURE__ */ __name((type) => type === "is", "accept"),
1503
- parseInfix: /* @__PURE__ */ __name((parser, left) => {
1504
- if (left.type !== "JsdocTypeName") {
1505
- throw new UnexpectedTypeError(left, "A typescript predicate always has to have a name on the left side.");
1506
- }
1507
- parser.consume("is");
1508
- return {
1509
- type: "JsdocTypePredicate",
1510
- left,
1511
- right: assertRootResult(parser.parseIntermediateType(Precedence.INFIX))
1512
- };
1513
- }, "parseInfix")
1514
- });
1515
- const objectSquaredPropertyParslet = composeParslet({
1516
- name: "objectSquareBracketPropertyParslet",
1517
- accept: /* @__PURE__ */ __name((type) => type === "[", "accept"),
1518
- parsePrefix: /* @__PURE__ */ __name((parser) => {
1519
- if (parser.baseParser === void 0) {
1520
- throw new Error("Only allowed inside object grammar");
1521
- }
1522
- parser.consume("[");
1523
- const key = parser.lexer.current.text;
1524
- parser.consume("Identifier");
1525
- let result;
1526
- if (parser.consume(":")) {
1527
- const parentParser = parser.baseParser;
1528
- parentParser.acceptLexerState(parser);
1529
- result = {
1530
- type: "JsdocTypeIndexSignature",
1531
- key,
1532
- right: parentParser.parseType(Precedence.INDEX_BRACKETS)
1533
- };
1534
- parser.acceptLexerState(parentParser);
1535
- } else if (parser.consume("in")) {
1536
- const parentParser = parser.baseParser;
1537
- parentParser.acceptLexerState(parser);
1538
- result = {
1539
- type: "JsdocTypeMappedType",
1540
- key,
1541
- right: parentParser.parseType(Precedence.ARRAY_BRACKETS)
1542
- };
1543
- parser.acceptLexerState(parentParser);
1544
- } else {
1545
- throw new Error("Missing ':' or 'in' inside square bracketed property.");
1546
- }
1547
- if (!parser.consume("]")) {
1548
- throw new Error("Unterminated square brackets");
1549
- }
1550
- return result;
1551
- }, "parsePrefix")
1552
- });
1553
- const readonlyArrayParslet = composeParslet({
1554
- name: "readonlyArrayParslet",
1555
- accept: /* @__PURE__ */ __name((type) => type === "readonly", "accept"),
1556
- parsePrefix: /* @__PURE__ */ __name((parser) => {
1557
- parser.consume("readonly");
1558
- return {
1559
- type: "JsdocTypeReadonlyArray",
1560
- element: assertArrayOrTupleResult(parser.parseIntermediateType(Precedence.ALL))
1561
- };
1562
- }, "parsePrefix")
1563
- });
1564
- const conditionalParslet = composeParslet({
1565
- name: "conditionalParslet",
1566
- precedence: Precedence.INFIX,
1567
- accept: /* @__PURE__ */ __name((type) => type === "extends", "accept"),
1568
- parseInfix: /* @__PURE__ */ __name((parser, left) => {
1569
- parser.consume("extends");
1570
- const extendsType = parser.parseType(Precedence.KEY_OF_TYPE_OF).element;
1571
- const trueType = parser.parseType(Precedence.INFIX);
1572
- parser.consume(":");
1573
- return {
1574
- type: "JsdocTypeConditional",
1575
- checksType: assertRootResult(left),
1576
- extendsType,
1577
- trueType,
1578
- falseType: parser.parseType(Precedence.INFIX)
1579
- };
1580
- }, "parseInfix")
1581
- });
1582
- const objectFieldGrammar = [
1583
- readonlyPropertyParslet,
1584
- createNameParslet({
1585
- allowedAdditionalTokens: ["typeof", "module", "keyof", "event", "external", "in"]
1586
- }),
1587
- nullableParslet,
1588
- optionalParslet,
1589
- stringValueParslet,
1590
- numberParslet,
1591
- createObjectFieldParslet({
1592
- allowSquaredProperties: true,
1593
- allowKeyTypes: false,
1594
- allowOptional: true,
1595
- allowReadonly: true
1596
- }),
1597
- objectSquaredPropertyParslet
1598
- ];
1599
- const typescriptGrammar = [
1600
- ...baseGrammar,
1601
- createObjectParslet({
1602
- allowKeyTypes: false,
1603
- objectFieldGrammar
1604
- }),
1605
- readonlyArrayParslet,
1606
- typeOfParslet,
1607
- keyOfParslet,
1608
- importParslet,
1609
- stringValueParslet,
1610
- createFunctionParslet({
1611
- allowWithoutParenthesis: true,
1612
- allowNoReturnType: false,
1613
- allowNamedParameters: ["this", "new", "args"],
1614
- allowNewAsFunctionKeyword: true
1615
- }),
1616
- createTupleParslet({
1617
- allowQuestionMark: false
1618
- }),
1619
- createVariadicParslet({
1620
- allowEnclosingBrackets: false,
1621
- allowPostfix: false
1622
- }),
1623
- assertsParslet,
1624
- conditionalParslet,
1625
- createNameParslet({
1626
- allowedAdditionalTokens: ["event", "external", "in"]
1627
- }),
1628
- createSpecialNamePathParslet({
1629
- allowedTypes: ["module"],
1630
- pathGrammar
1631
- }),
1632
- arrayBracketsParslet,
1633
- arrowFunctionParslet,
1634
- genericArrowFunctionParslet,
1635
- createNamePathParslet({
1636
- allowSquareBracketsOnAnyType: true,
1637
- allowJsdocNamePaths: false,
1638
- pathGrammar
1639
- }),
1640
- intersectionParslet,
1641
- predicateParslet,
1642
- createKeyValueParslet({
1643
- allowVariadic: true,
1644
- allowOptional: true
1645
- })
1646
- ];
1647
- function parse3(expression, mode) {
1648
- switch (mode) {
1649
- case "closure":
1650
- return new Parser(closureGrammar, expression).parse();
1651
- case "jsdoc":
1652
- return new Parser(jsdocGrammar, expression).parse();
1653
- case "typescript":
1654
- return new Parser(typescriptGrammar, expression).parse();
1655
- }
1656
- }
1657
- __name(parse3, "parse");
1658
- function tryParse(expression, modes = ["typescript", "closure", "jsdoc"]) {
1659
- let error;
1660
- for (const mode of modes) {
1661
- try {
1662
- return parse3(expression, mode);
1663
- } catch (e) {
1664
- error = e;
1665
- }
1666
- }
1667
- throw error;
1668
- }
1669
- __name(tryParse, "tryParse");
1670
- function transform(rules2, parseResult) {
1671
- const rule = rules2[parseResult.type];
1672
- if (rule === void 0) {
1673
- throw new Error(`In this set of transform rules exists no rule for type ${parseResult.type}.`);
1674
- }
1675
- return rule(parseResult, (aParseResult) => transform(rules2, aParseResult));
1676
- }
1677
- __name(transform, "transform");
1678
- function notAvailableTransform(parseResult) {
1679
- throw new Error("This transform is not available. Are you trying the correct parsing mode?");
1680
- }
1681
- __name(notAvailableTransform, "notAvailableTransform");
1682
- function extractSpecialParams(source) {
1683
- const result = {
1684
- params: []
1685
- };
1686
- for (const param of source.parameters) {
1687
- if (param.type === "JsdocTypeKeyValue") {
1688
- if (param.key === "this") {
1689
- result.this = param.right;
1690
- } else if (param.key === "new") {
1691
- result.new = param.right;
1692
- } else {
1693
- result.params.push(param);
1694
- }
1695
- } else {
1696
- result.params.push(param);
1697
- }
1698
- }
1699
- return result;
1700
- }
1701
- __name(extractSpecialParams, "extractSpecialParams");
1702
- function applyPosition(position, target, value) {
1703
- return position === "prefix" ? value + target : target + value;
1704
- }
1705
- __name(applyPosition, "applyPosition");
1706
- function quote(value, quote2) {
1707
- switch (quote2) {
1708
- case "double":
1709
- return `"${value}"`;
1710
- case "single":
1711
- return `'${value}'`;
1712
- case void 0:
1713
- return value;
1714
- }
1715
- }
1716
- __name(quote, "quote");
1717
- function stringifyRules2() {
1718
- return {
1719
- JsdocTypeParenthesis: /* @__PURE__ */ __name((result, transform2) => `(${result.element !== void 0 ? transform2(result.element) : ""})`, "JsdocTypeParenthesis"),
1720
- JsdocTypeKeyof: /* @__PURE__ */ __name((result, transform2) => `keyof ${transform2(result.element)}`, "JsdocTypeKeyof"),
1721
- JsdocTypeFunction: /* @__PURE__ */ __name((result, transform2) => {
1722
- var _a;
1723
- if (!result.arrow) {
1724
- let stringified = result.constructor ? "new" : "function";
1725
- if (!result.parenthesis) {
1726
- return stringified;
1727
- }
1728
- stringified += `(${result.parameters.map(transform2).join(", ")})`;
1729
- if (result.returnType !== void 0) {
1730
- stringified += `: ${transform2(result.returnType)}`;
1731
- }
1732
- return stringified;
1733
- } else {
1734
- if (result.returnType === void 0) {
1735
- throw new Error("Arrow function needs a return type.");
1736
- }
1737
- let stringified = `${result.typeParameters !== void 0 ? `<${(_a = result.typeParameters.map(transform2).join(", ")) !== null && _a !== void 0 ? _a : ""}>` : ""}(${result.parameters.map(transform2).join(", ")}) => ${transform2(result.returnType)}`;
1738
- if (result.constructor) {
1739
- stringified = "new " + stringified;
1740
- }
1741
- return stringified;
1742
- }
1743
- }, "JsdocTypeFunction"),
1744
- JsdocTypeName: /* @__PURE__ */ __name((result) => result.value, "JsdocTypeName"),
1745
- JsdocTypeTuple: /* @__PURE__ */ __name((result, transform2) => `[${result.elements.map(transform2).join(", ")}]`, "JsdocTypeTuple"),
1746
- JsdocTypeVariadic: /* @__PURE__ */ __name((result, transform2) => result.meta.position === void 0 ? "..." : applyPosition(result.meta.position, transform2(result.element), "..."), "JsdocTypeVariadic"),
1747
- JsdocTypeNamePath: /* @__PURE__ */ __name((result, transform2) => {
1748
- const left = transform2(result.left);
1749
- const right = transform2(result.right);
1750
- switch (result.pathType) {
1751
- case "inner":
1752
- return `${left}~${right}`;
1753
- case "instance":
1754
- return `${left}#${right}`;
1755
- case "property":
1756
- return `${left}.${right}`;
1757
- case "property-brackets":
1758
- return `${left}[${right}]`;
1759
- }
1760
- }, "JsdocTypeNamePath"),
1761
- JsdocTypeStringValue: /* @__PURE__ */ __name((result) => quote(result.value, result.meta.quote), "JsdocTypeStringValue"),
1762
- JsdocTypeAny: /* @__PURE__ */ __name(() => "*", "JsdocTypeAny"),
1763
- JsdocTypeGeneric: /* @__PURE__ */ __name((result, transform2) => {
1764
- if (result.meta.brackets === "square") {
1765
- const element = result.elements[0];
1766
- const transformed = transform2(element);
1767
- if (element.type === "JsdocTypeUnion" || element.type === "JsdocTypeIntersection") {
1768
- return `(${transformed})[]`;
1769
- } else {
1770
- return `${transformed}[]`;
1771
- }
1772
- } else {
1773
- return `${transform2(result.left)}${result.meta.dot ? "." : ""}<${result.infer === true ? "infer " : ""}${result.elements.map(transform2).join(", ")}>`;
1774
- }
1775
- }, "JsdocTypeGeneric"),
1776
- JsdocTypeImport: /* @__PURE__ */ __name((result, transform2) => `import(${transform2(result.element)})`, "JsdocTypeImport"),
1777
- JsdocTypeObjectField: /* @__PURE__ */ __name((result, transform2) => {
1778
- let text = "";
1779
- if (result.readonly) {
1780
- text += "readonly ";
1781
- }
1782
- if (typeof result.key === "string") {
1783
- text += quote(result.key, result.meta.quote);
1784
- } else {
1785
- text += transform2(result.key);
1786
- }
1787
- if (result.optional) {
1788
- text += "?";
1789
- }
1790
- if (result.right === void 0) {
1791
- return text;
1792
- } else {
1793
- return text + `: ${transform2(result.right)}`;
1794
- }
1795
- }, "JsdocTypeObjectField"),
1796
- JsdocTypeJsdocObjectField: /* @__PURE__ */ __name((result, transform2) => {
1797
- return `${transform2(result.left)}: ${transform2(result.right)}`;
1798
- }, "JsdocTypeJsdocObjectField"),
1799
- JsdocTypeKeyValue: /* @__PURE__ */ __name((result, transform2) => {
1800
- let text = result.key;
1801
- if (result.optional) {
1802
- text += "?";
1803
- }
1804
- if (result.variadic) {
1805
- text = "..." + text;
1806
- }
1807
- if (result.right === void 0) {
1808
- return text;
1809
- } else {
1810
- return text + `: ${transform2(result.right)}`;
1811
- }
1812
- }, "JsdocTypeKeyValue"),
1813
- JsdocTypeSpecialNamePath: /* @__PURE__ */ __name((result) => `${result.specialType}:${quote(result.value, result.meta.quote)}`, "JsdocTypeSpecialNamePath"),
1814
- JsdocTypeNotNullable: /* @__PURE__ */ __name((result, transform2) => applyPosition(result.meta.position, transform2(result.element), "!"), "JsdocTypeNotNullable"),
1815
- JsdocTypeNull: /* @__PURE__ */ __name(() => "null", "JsdocTypeNull"),
1816
- JsdocTypeNullable: /* @__PURE__ */ __name((result, transform2) => applyPosition(result.meta.position, transform2(result.element), "?"), "JsdocTypeNullable"),
1817
- JsdocTypeNumber: /* @__PURE__ */ __name((result) => result.value.toString(), "JsdocTypeNumber"),
1818
- JsdocTypeObject: /* @__PURE__ */ __name((result, transform2) => {
1819
- var _a, _b;
1820
- return `{${(result.meta.separator === "linebreak" && result.elements.length > 1 ? "\n" + ((_a = result.meta.propertyIndent) !== null && _a !== void 0 ? _a : "") : "") + result.elements.map(transform2).join(result.meta.separator === "comma" ? ", " : result.meta.separator === "linebreak" ? "\n" + ((_b = result.meta.propertyIndent) !== null && _b !== void 0 ? _b : "") : "; ") + (result.meta.separator === "linebreak" && result.elements.length > 1 ? "\n" : "")}}`;
1821
- }, "JsdocTypeObject"),
1822
- JsdocTypeOptional: /* @__PURE__ */ __name((result, transform2) => applyPosition(result.meta.position, transform2(result.element), "="), "JsdocTypeOptional"),
1823
- JsdocTypeSymbol: /* @__PURE__ */ __name((result, transform2) => `${result.value}(${result.element !== void 0 ? transform2(result.element) : ""})`, "JsdocTypeSymbol"),
1824
- JsdocTypeTypeof: /* @__PURE__ */ __name((result, transform2) => `typeof ${transform2(result.element)}`, "JsdocTypeTypeof"),
1825
- JsdocTypeUndefined: /* @__PURE__ */ __name(() => "undefined", "JsdocTypeUndefined"),
1826
- JsdocTypeUnion: /* @__PURE__ */ __name((result, transform2) => result.elements.map(transform2).join(" | "), "JsdocTypeUnion"),
1827
- JsdocTypeUnknown: /* @__PURE__ */ __name(() => "?", "JsdocTypeUnknown"),
1828
- JsdocTypeIntersection: /* @__PURE__ */ __name((result, transform2) => result.elements.map(transform2).join(" & "), "JsdocTypeIntersection"),
1829
- JsdocTypeProperty: /* @__PURE__ */ __name((result) => quote(result.value, result.meta.quote), "JsdocTypeProperty"),
1830
- JsdocTypePredicate: /* @__PURE__ */ __name((result, transform2) => `${transform2(result.left)} is ${transform2(result.right)}`, "JsdocTypePredicate"),
1831
- JsdocTypeIndexSignature: /* @__PURE__ */ __name((result, transform2) => `[${result.key}: ${transform2(result.right)}]`, "JsdocTypeIndexSignature"),
1832
- JsdocTypeMappedType: /* @__PURE__ */ __name((result, transform2) => `[${result.key} in ${transform2(result.right)}]`, "JsdocTypeMappedType"),
1833
- JsdocTypeAsserts: /* @__PURE__ */ __name((result, transform2) => `asserts ${transform2(result.left)} is ${transform2(result.right)}`, "JsdocTypeAsserts"),
1834
- JsdocTypeReadonlyArray: /* @__PURE__ */ __name((result, transform2) => `readonly ${transform2(result.element)}`, "JsdocTypeReadonlyArray"),
1835
- JsdocTypeAssertsPlain: /* @__PURE__ */ __name((result, transform2) => `asserts ${transform2(result.element)}`, "JsdocTypeAssertsPlain"),
1836
- JsdocTypeConditional: /* @__PURE__ */ __name((result, transform2) => `${transform2(result.checksType)} extends ${transform2(result.extendsType)} ? ${transform2(result.trueType)} : ${transform2(result.falseType)}`, "JsdocTypeConditional"),
1837
- JsdocTypeTypeParameter: /* @__PURE__ */ __name((result, transform2) => `${transform2(result.name)}${result.constraint !== void 0 ? ` extends ${transform2(result.constraint)}` : ""}${result.defaultValue !== void 0 ? ` = ${transform2(result.defaultValue)}` : ""}`, "JsdocTypeTypeParameter")
1838
- };
1839
- }
1840
- __name(stringifyRules2, "stringifyRules");
1841
- const storedStringifyRules = stringifyRules2();
1842
- function stringify2(result) {
1843
- return transform(storedStringifyRules, result);
1844
- }
1845
- __name(stringify2, "stringify");
1846
- const reservedWords = [
1847
- "null",
1848
- "true",
1849
- "false",
1850
- "break",
1851
- "case",
1852
- "catch",
1853
- "class",
1854
- "const",
1855
- "continue",
1856
- "debugger",
1857
- "default",
1858
- "delete",
1859
- "do",
1860
- "else",
1861
- "export",
1862
- "extends",
1863
- "finally",
1864
- "for",
1865
- "function",
1866
- "if",
1867
- "import",
1868
- "in",
1869
- "instanceof",
1870
- "new",
1871
- "return",
1872
- "super",
1873
- "switch",
1874
- "this",
1875
- "throw",
1876
- "try",
1877
- "typeof",
1878
- "var",
1879
- "void",
1880
- "while",
1881
- "with",
1882
- "yield"
1883
- ];
1884
- function makeName(value) {
1885
- const result = {
1886
- type: "NameExpression",
1887
- name: value
1888
- };
1889
- if (reservedWords.includes(value)) {
1890
- result.reservedWord = true;
1891
- }
1892
- return result;
1893
- }
1894
- __name(makeName, "makeName");
1895
- const catharsisTransformRules = {
1896
- JsdocTypeOptional: /* @__PURE__ */ __name((result, transform2) => {
1897
- const transformed = transform2(result.element);
1898
- transformed.optional = true;
1899
- return transformed;
1900
- }, "JsdocTypeOptional"),
1901
- JsdocTypeNullable: /* @__PURE__ */ __name((result, transform2) => {
1902
- const transformed = transform2(result.element);
1903
- transformed.nullable = true;
1904
- return transformed;
1905
- }, "JsdocTypeNullable"),
1906
- JsdocTypeNotNullable: /* @__PURE__ */ __name((result, transform2) => {
1907
- const transformed = transform2(result.element);
1908
- transformed.nullable = false;
1909
- return transformed;
1910
- }, "JsdocTypeNotNullable"),
1911
- JsdocTypeVariadic: /* @__PURE__ */ __name((result, transform2) => {
1912
- if (result.element === void 0) {
1913
- throw new Error("dots without value are not allowed in catharsis mode");
1914
- }
1915
- const transformed = transform2(result.element);
1916
- transformed.repeatable = true;
1917
- return transformed;
1918
- }, "JsdocTypeVariadic"),
1919
- JsdocTypeAny: /* @__PURE__ */ __name(() => ({
1920
- type: "AllLiteral"
1921
- }), "JsdocTypeAny"),
1922
- JsdocTypeNull: /* @__PURE__ */ __name(() => ({
1923
- type: "NullLiteral"
1924
- }), "JsdocTypeNull"),
1925
- JsdocTypeStringValue: /* @__PURE__ */ __name((result) => makeName(quote(result.value, result.meta.quote)), "JsdocTypeStringValue"),
1926
- JsdocTypeUndefined: /* @__PURE__ */ __name(() => ({
1927
- type: "UndefinedLiteral"
1928
- }), "JsdocTypeUndefined"),
1929
- JsdocTypeUnknown: /* @__PURE__ */ __name(() => ({
1930
- type: "UnknownLiteral"
1931
- }), "JsdocTypeUnknown"),
1932
- JsdocTypeFunction: /* @__PURE__ */ __name((result, transform2) => {
1933
- const params = extractSpecialParams(result);
1934
- const transformed = {
1935
- type: "FunctionType",
1936
- params: params.params.map(transform2)
1937
- };
1938
- if (params.this !== void 0) {
1939
- transformed.this = transform2(params.this);
1940
- }
1941
- if (params.new !== void 0) {
1942
- transformed.new = transform2(params.new);
1943
- }
1944
- if (result.returnType !== void 0) {
1945
- transformed.result = transform2(result.returnType);
1946
- }
1947
- return transformed;
1948
- }, "JsdocTypeFunction"),
1949
- JsdocTypeGeneric: /* @__PURE__ */ __name((result, transform2) => ({
1950
- type: "TypeApplication",
1951
- applications: result.elements.map((o) => transform2(o)),
1952
- expression: transform2(result.left)
1953
- }), "JsdocTypeGeneric"),
1954
- JsdocTypeSpecialNamePath: /* @__PURE__ */ __name((result) => makeName(result.specialType + ":" + quote(result.value, result.meta.quote)), "JsdocTypeSpecialNamePath"),
1955
- JsdocTypeName: /* @__PURE__ */ __name((result) => {
1956
- if (result.value !== "function") {
1957
- return makeName(result.value);
1958
- } else {
1959
- return {
1960
- type: "FunctionType",
1961
- params: []
1962
- };
1963
- }
1964
- }, "JsdocTypeName"),
1965
- JsdocTypeNumber: /* @__PURE__ */ __name((result) => makeName(result.value.toString()), "JsdocTypeNumber"),
1966
- JsdocTypeObject: /* @__PURE__ */ __name((result, transform2) => {
1967
- const transformed = {
1968
- type: "RecordType",
1969
- fields: []
1970
- };
1971
- for (const field of result.elements) {
1972
- if (field.type !== "JsdocTypeObjectField" && field.type !== "JsdocTypeJsdocObjectField") {
1973
- transformed.fields.push({
1974
- type: "FieldType",
1975
- key: transform2(field),
1976
- value: void 0
1977
- });
1978
- } else {
1979
- transformed.fields.push(transform2(field));
1980
- }
1981
- }
1982
- return transformed;
1983
- }, "JsdocTypeObject"),
1984
- JsdocTypeObjectField: /* @__PURE__ */ __name((result, transform2) => {
1985
- if (typeof result.key !== "string") {
1986
- throw new Error("Index signatures and mapped types are not supported");
1987
- }
1988
- return {
1989
- type: "FieldType",
1990
- key: makeName(quote(result.key, result.meta.quote)),
1991
- value: result.right === void 0 ? void 0 : transform2(result.right)
1992
- };
1993
- }, "JsdocTypeObjectField"),
1994
- JsdocTypeJsdocObjectField: /* @__PURE__ */ __name((result, transform2) => ({
1995
- type: "FieldType",
1996
- key: transform2(result.left),
1997
- value: transform2(result.right)
1998
- }), "JsdocTypeJsdocObjectField"),
1999
- JsdocTypeUnion: /* @__PURE__ */ __name((result, transform2) => ({
2000
- type: "TypeUnion",
2001
- elements: result.elements.map((e) => transform2(e))
2002
- }), "JsdocTypeUnion"),
2003
- JsdocTypeKeyValue: /* @__PURE__ */ __name((result, transform2) => {
2004
- return {
2005
- type: "FieldType",
2006
- key: makeName(result.key),
2007
- value: result.right === void 0 ? void 0 : transform2(result.right)
2008
- };
2009
- }, "JsdocTypeKeyValue"),
2010
- JsdocTypeNamePath: /* @__PURE__ */ __name((result, transform2) => {
2011
- const leftResult = transform2(result.left);
2012
- let rightValue;
2013
- if (result.right.type === "JsdocTypeSpecialNamePath") {
2014
- rightValue = transform2(result.right).name;
2015
- } else {
2016
- rightValue = quote(result.right.value, result.right.meta.quote);
2017
- }
2018
- const joiner = result.pathType === "inner" ? "~" : result.pathType === "instance" ? "#" : ".";
2019
- return makeName(`${leftResult.name}${joiner}${rightValue}`);
2020
- }, "JsdocTypeNamePath"),
2021
- JsdocTypeSymbol: /* @__PURE__ */ __name((result) => {
2022
- let value = "";
2023
- let element = result.element;
2024
- let trailingDots = false;
2025
- if ((element === null || element === void 0 ? void 0 : element.type) === "JsdocTypeVariadic") {
2026
- if (element.meta.position === "prefix") {
2027
- value = "...";
2028
- } else {
2029
- trailingDots = true;
2030
- }
2031
- element = element.element;
2032
- }
2033
- if ((element === null || element === void 0 ? void 0 : element.type) === "JsdocTypeName") {
2034
- value += element.value;
2035
- } else if ((element === null || element === void 0 ? void 0 : element.type) === "JsdocTypeNumber") {
2036
- value += element.value.toString();
2037
- }
2038
- if (trailingDots) {
2039
- value += "...";
2040
- }
2041
- return makeName(`${result.value}(${value})`);
2042
- }, "JsdocTypeSymbol"),
2043
- JsdocTypeParenthesis: /* @__PURE__ */ __name((result, transform2) => transform2(assertRootResult(result.element)), "JsdocTypeParenthesis"),
2044
- JsdocTypeMappedType: notAvailableTransform,
2045
- JsdocTypeIndexSignature: notAvailableTransform,
2046
- JsdocTypeImport: notAvailableTransform,
2047
- JsdocTypeKeyof: notAvailableTransform,
2048
- JsdocTypeTuple: notAvailableTransform,
2049
- JsdocTypeTypeof: notAvailableTransform,
2050
- JsdocTypeIntersection: notAvailableTransform,
2051
- JsdocTypeProperty: notAvailableTransform,
2052
- JsdocTypePredicate: notAvailableTransform,
2053
- JsdocTypeAsserts: notAvailableTransform,
2054
- JsdocTypeReadonlyArray: notAvailableTransform,
2055
- JsdocTypeAssertsPlain: notAvailableTransform,
2056
- JsdocTypeConditional: notAvailableTransform,
2057
- JsdocTypeTypeParameter: notAvailableTransform
2058
- };
2059
- function catharsisTransform(result) {
2060
- return transform(catharsisTransformRules, result);
2061
- }
2062
- __name(catharsisTransform, "catharsisTransform");
2063
- function getQuoteStyle(quote2) {
2064
- switch (quote2) {
2065
- case void 0:
2066
- return "none";
2067
- case "single":
2068
- return "single";
2069
- case "double":
2070
- return "double";
2071
- }
2072
- }
2073
- __name(getQuoteStyle, "getQuoteStyle");
2074
- function getMemberType(type) {
2075
- switch (type) {
2076
- case "inner":
2077
- return "INNER_MEMBER";
2078
- case "instance":
2079
- return "INSTANCE_MEMBER";
2080
- case "property":
2081
- return "MEMBER";
2082
- case "property-brackets":
2083
- return "MEMBER";
2084
- }
2085
- }
2086
- __name(getMemberType, "getMemberType");
2087
- function nestResults(type, results) {
2088
- if (results.length === 2) {
2089
- return {
2090
- type,
2091
- left: results[0],
2092
- right: results[1]
2093
- };
2094
- } else {
2095
- return {
2096
- type,
2097
- left: results[0],
2098
- right: nestResults(type, results.slice(1))
2099
- };
2100
- }
2101
- }
2102
- __name(nestResults, "nestResults");
2103
- const jtpRules = {
2104
- JsdocTypeOptional: /* @__PURE__ */ __name((result, transform2) => ({
2105
- type: "OPTIONAL",
2106
- value: transform2(result.element),
2107
- meta: {
2108
- syntax: result.meta.position === "prefix" ? "PREFIX_EQUAL_SIGN" : "SUFFIX_EQUALS_SIGN"
2109
- }
2110
- }), "JsdocTypeOptional"),
2111
- JsdocTypeNullable: /* @__PURE__ */ __name((result, transform2) => ({
2112
- type: "NULLABLE",
2113
- value: transform2(result.element),
2114
- meta: {
2115
- syntax: result.meta.position === "prefix" ? "PREFIX_QUESTION_MARK" : "SUFFIX_QUESTION_MARK"
2116
- }
2117
- }), "JsdocTypeNullable"),
2118
- JsdocTypeNotNullable: /* @__PURE__ */ __name((result, transform2) => ({
2119
- type: "NOT_NULLABLE",
2120
- value: transform2(result.element),
2121
- meta: {
2122
- syntax: result.meta.position === "prefix" ? "PREFIX_BANG" : "SUFFIX_BANG"
2123
- }
2124
- }), "JsdocTypeNotNullable"),
2125
- JsdocTypeVariadic: /* @__PURE__ */ __name((result, transform2) => {
2126
- const transformed = {
2127
- type: "VARIADIC",
2128
- meta: {
2129
- syntax: result.meta.position === "prefix" ? "PREFIX_DOTS" : result.meta.position === "suffix" ? "SUFFIX_DOTS" : "ONLY_DOTS"
2130
- }
2131
- };
2132
- if (result.element !== void 0) {
2133
- transformed.value = transform2(result.element);
2134
- }
2135
- return transformed;
2136
- }, "JsdocTypeVariadic"),
2137
- JsdocTypeName: /* @__PURE__ */ __name((result) => ({
2138
- type: "NAME",
2139
- name: result.value
2140
- }), "JsdocTypeName"),
2141
- JsdocTypeTypeof: /* @__PURE__ */ __name((result, transform2) => ({
2142
- type: "TYPE_QUERY",
2143
- name: transform2(result.element)
2144
- }), "JsdocTypeTypeof"),
2145
- JsdocTypeTuple: /* @__PURE__ */ __name((result, transform2) => ({
2146
- type: "TUPLE",
2147
- entries: result.elements.map(transform2)
2148
- }), "JsdocTypeTuple"),
2149
- JsdocTypeKeyof: /* @__PURE__ */ __name((result, transform2) => ({
2150
- type: "KEY_QUERY",
2151
- value: transform2(result.element)
2152
- }), "JsdocTypeKeyof"),
2153
- JsdocTypeImport: /* @__PURE__ */ __name((result) => ({
2154
- type: "IMPORT",
2155
- path: {
2156
- type: "STRING_VALUE",
2157
- quoteStyle: getQuoteStyle(result.element.meta.quote),
2158
- string: result.element.value
2159
- }
2160
- }), "JsdocTypeImport"),
2161
- JsdocTypeUndefined: /* @__PURE__ */ __name(() => ({
2162
- type: "NAME",
2163
- name: "undefined"
2164
- }), "JsdocTypeUndefined"),
2165
- JsdocTypeAny: /* @__PURE__ */ __name(() => ({
2166
- type: "ANY"
2167
- }), "JsdocTypeAny"),
2168
- JsdocTypeFunction: /* @__PURE__ */ __name((result, transform2) => {
2169
- const specialParams = extractSpecialParams(result);
2170
- const transformed = {
2171
- type: result.arrow ? "ARROW" : "FUNCTION",
2172
- params: specialParams.params.map((param) => {
2173
- if (param.type === "JsdocTypeKeyValue") {
2174
- if (param.right === void 0) {
2175
- throw new Error("Function parameter without ':' is not expected to be 'KEY_VALUE'");
2176
- }
2177
- return {
2178
- type: "NAMED_PARAMETER",
2179
- name: param.key,
2180
- typeName: transform2(param.right)
2181
- };
2182
- } else {
2183
- return transform2(param);
2184
- }
2185
- }),
2186
- new: null,
2187
- returns: null
2188
- };
2189
- if (specialParams.this !== void 0) {
2190
- transformed.this = transform2(specialParams.this);
2191
- } else if (!result.arrow) {
2192
- transformed.this = null;
2193
- }
2194
- if (specialParams.new !== void 0) {
2195
- transformed.new = transform2(specialParams.new);
2196
- }
2197
- if (result.returnType !== void 0) {
2198
- transformed.returns = transform2(result.returnType);
2199
- }
2200
- return transformed;
2201
- }, "JsdocTypeFunction"),
2202
- JsdocTypeGeneric: /* @__PURE__ */ __name((result, transform2) => {
2203
- const transformed = {
2204
- type: "GENERIC",
2205
- subject: transform2(result.left),
2206
- objects: result.elements.map(transform2),
2207
- meta: {
2208
- syntax: result.meta.brackets === "square" ? "SQUARE_BRACKET" : result.meta.dot ? "ANGLE_BRACKET_WITH_DOT" : "ANGLE_BRACKET"
2209
- }
2210
- };
2211
- if (result.meta.brackets === "square" && result.elements[0].type === "JsdocTypeFunction" && !result.elements[0].parenthesis) {
2212
- transformed.objects[0] = {
2213
- type: "NAME",
2214
- name: "function"
2215
- };
2216
- }
2217
- return transformed;
2218
- }, "JsdocTypeGeneric"),
2219
- JsdocTypeObjectField: /* @__PURE__ */ __name((result, transform2) => {
2220
- if (typeof result.key !== "string") {
2221
- throw new Error("Index signatures and mapped types are not supported");
2222
- }
2223
- if (result.right === void 0) {
2224
- return {
2225
- type: "RECORD_ENTRY",
2226
- key: result.key,
2227
- quoteStyle: getQuoteStyle(result.meta.quote),
2228
- value: null,
2229
- readonly: false
2230
- };
2231
- }
2232
- let right = transform2(result.right);
2233
- if (result.optional) {
2234
- right = {
2235
- type: "OPTIONAL",
2236
- value: right,
2237
- meta: {
2238
- syntax: "SUFFIX_KEY_QUESTION_MARK"
2239
- }
2240
- };
2241
- }
2242
- return {
2243
- type: "RECORD_ENTRY",
2244
- key: result.key.toString(),
2245
- quoteStyle: getQuoteStyle(result.meta.quote),
2246
- value: right,
2247
- readonly: false
2248
- };
2249
- }, "JsdocTypeObjectField"),
2250
- JsdocTypeJsdocObjectField: /* @__PURE__ */ __name(() => {
2251
- throw new Error("Keys may not be typed in jsdoctypeparser.");
2252
- }, "JsdocTypeJsdocObjectField"),
2253
- JsdocTypeKeyValue: /* @__PURE__ */ __name((result, transform2) => {
2254
- if (result.right === void 0) {
2255
- return {
2256
- type: "RECORD_ENTRY",
2257
- key: result.key,
2258
- quoteStyle: "none",
2259
- value: null,
2260
- readonly: false
2261
- };
2262
- }
2263
- let right = transform2(result.right);
2264
- if (result.optional) {
2265
- right = {
2266
- type: "OPTIONAL",
2267
- value: right,
2268
- meta: {
2269
- syntax: "SUFFIX_KEY_QUESTION_MARK"
2270
- }
2271
- };
2272
- }
2273
- return {
2274
- type: "RECORD_ENTRY",
2275
- key: result.key,
2276
- quoteStyle: "none",
2277
- value: right,
2278
- readonly: false
2279
- };
2280
- }, "JsdocTypeKeyValue"),
2281
- JsdocTypeObject: /* @__PURE__ */ __name((result, transform2) => {
2282
- const entries = [];
2283
- for (const field of result.elements) {
2284
- if (field.type === "JsdocTypeObjectField" || field.type === "JsdocTypeJsdocObjectField") {
2285
- entries.push(transform2(field));
2286
- }
2287
- }
2288
- return {
2289
- type: "RECORD",
2290
- entries
2291
- };
2292
- }, "JsdocTypeObject"),
2293
- JsdocTypeSpecialNamePath: /* @__PURE__ */ __name((result) => {
2294
- if (result.specialType !== "module") {
2295
- throw new Error(`jsdoctypeparser does not support type ${result.specialType} at this point.`);
2296
- }
2297
- return {
2298
- type: "MODULE",
2299
- value: {
2300
- type: "FILE_PATH",
2301
- quoteStyle: getQuoteStyle(result.meta.quote),
2302
- path: result.value
2303
- }
2304
- };
2305
- }, "JsdocTypeSpecialNamePath"),
2306
- JsdocTypeNamePath: /* @__PURE__ */ __name((result, transform2) => {
2307
- let hasEventPrefix = false;
2308
- let name;
2309
- let quoteStyle;
2310
- if (result.right.type === "JsdocTypeSpecialNamePath" && result.right.specialType === "event") {
2311
- hasEventPrefix = true;
2312
- name = result.right.value;
2313
- quoteStyle = getQuoteStyle(result.right.meta.quote);
2314
- } else {
2315
- name = result.right.value;
2316
- quoteStyle = getQuoteStyle(result.right.meta.quote);
2317
- }
2318
- const transformed = {
2319
- type: getMemberType(result.pathType),
2320
- owner: transform2(result.left),
2321
- name,
2322
- quoteStyle,
2323
- hasEventPrefix
2324
- };
2325
- if (transformed.owner.type === "MODULE") {
2326
- const tModule = transformed.owner;
2327
- transformed.owner = transformed.owner.value;
2328
- tModule.value = transformed;
2329
- return tModule;
2330
- } else {
2331
- return transformed;
2332
- }
2333
- }, "JsdocTypeNamePath"),
2334
- JsdocTypeUnion: /* @__PURE__ */ __name((result, transform2) => nestResults("UNION", result.elements.map(transform2)), "JsdocTypeUnion"),
2335
- JsdocTypeParenthesis: /* @__PURE__ */ __name((result, transform2) => ({
2336
- type: "PARENTHESIS",
2337
- value: transform2(assertRootResult(result.element))
2338
- }), "JsdocTypeParenthesis"),
2339
- JsdocTypeNull: /* @__PURE__ */ __name(() => ({
2340
- type: "NAME",
2341
- name: "null"
2342
- }), "JsdocTypeNull"),
2343
- JsdocTypeUnknown: /* @__PURE__ */ __name(() => ({
2344
- type: "UNKNOWN"
2345
- }), "JsdocTypeUnknown"),
2346
- JsdocTypeStringValue: /* @__PURE__ */ __name((result) => ({
2347
- type: "STRING_VALUE",
2348
- quoteStyle: getQuoteStyle(result.meta.quote),
2349
- string: result.value
2350
- }), "JsdocTypeStringValue"),
2351
- JsdocTypeIntersection: /* @__PURE__ */ __name((result, transform2) => nestResults("INTERSECTION", result.elements.map(transform2)), "JsdocTypeIntersection"),
2352
- JsdocTypeNumber: /* @__PURE__ */ __name((result) => ({
2353
- type: "NUMBER_VALUE",
2354
- number: result.value.toString()
2355
- }), "JsdocTypeNumber"),
2356
- JsdocTypeSymbol: notAvailableTransform,
2357
- JsdocTypeProperty: notAvailableTransform,
2358
- JsdocTypePredicate: notAvailableTransform,
2359
- JsdocTypeMappedType: notAvailableTransform,
2360
- JsdocTypeIndexSignature: notAvailableTransform,
2361
- JsdocTypeAsserts: notAvailableTransform,
2362
- JsdocTypeReadonlyArray: notAvailableTransform,
2363
- JsdocTypeAssertsPlain: notAvailableTransform,
2364
- JsdocTypeConditional: notAvailableTransform,
2365
- JsdocTypeTypeParameter: notAvailableTransform
2366
- };
2367
- function jtpTransform(result) {
2368
- return transform(jtpRules, result);
2369
- }
2370
- __name(jtpTransform, "jtpTransform");
2371
- function identityTransformRules() {
2372
- return {
2373
- JsdocTypeIntersection: /* @__PURE__ */ __name((result, transform2) => ({
2374
- type: "JsdocTypeIntersection",
2375
- elements: result.elements.map(transform2)
2376
- }), "JsdocTypeIntersection"),
2377
- JsdocTypeGeneric: /* @__PURE__ */ __name((result, transform2) => ({
2378
- type: "JsdocTypeGeneric",
2379
- left: transform2(result.left),
2380
- elements: result.elements.map(transform2),
2381
- meta: {
2382
- dot: result.meta.dot,
2383
- brackets: result.meta.brackets
2384
- }
2385
- }), "JsdocTypeGeneric"),
2386
- JsdocTypeNullable: /* @__PURE__ */ __name((result) => result, "JsdocTypeNullable"),
2387
- JsdocTypeUnion: /* @__PURE__ */ __name((result, transform2) => ({
2388
- type: "JsdocTypeUnion",
2389
- elements: result.elements.map(transform2)
2390
- }), "JsdocTypeUnion"),
2391
- JsdocTypeUnknown: /* @__PURE__ */ __name((result) => result, "JsdocTypeUnknown"),
2392
- JsdocTypeUndefined: /* @__PURE__ */ __name((result) => result, "JsdocTypeUndefined"),
2393
- JsdocTypeTypeof: /* @__PURE__ */ __name((result, transform2) => ({
2394
- type: "JsdocTypeTypeof",
2395
- element: transform2(result.element)
2396
- }), "JsdocTypeTypeof"),
2397
- JsdocTypeSymbol: /* @__PURE__ */ __name((result, transform2) => {
2398
- const transformed = {
2399
- type: "JsdocTypeSymbol",
2400
- value: result.value
2401
- };
2402
- if (result.element !== void 0) {
2403
- transformed.element = transform2(result.element);
2404
- }
2405
- return transformed;
2406
- }, "JsdocTypeSymbol"),
2407
- JsdocTypeOptional: /* @__PURE__ */ __name((result, transform2) => ({
2408
- type: "JsdocTypeOptional",
2409
- element: transform2(result.element),
2410
- meta: {
2411
- position: result.meta.position
2412
- }
2413
- }), "JsdocTypeOptional"),
2414
- JsdocTypeObject: /* @__PURE__ */ __name((result, transform2) => ({
2415
- type: "JsdocTypeObject",
2416
- meta: {
2417
- separator: "comma"
2418
- },
2419
- elements: result.elements.map(transform2)
2420
- }), "JsdocTypeObject"),
2421
- JsdocTypeNumber: /* @__PURE__ */ __name((result) => result, "JsdocTypeNumber"),
2422
- JsdocTypeNull: /* @__PURE__ */ __name((result) => result, "JsdocTypeNull"),
2423
- JsdocTypeNotNullable: /* @__PURE__ */ __name((result, transform2) => ({
2424
- type: "JsdocTypeNotNullable",
2425
- element: transform2(result.element),
2426
- meta: {
2427
- position: result.meta.position
2428
- }
2429
- }), "JsdocTypeNotNullable"),
2430
- JsdocTypeSpecialNamePath: /* @__PURE__ */ __name((result) => result, "JsdocTypeSpecialNamePath"),
2431
- JsdocTypeObjectField: /* @__PURE__ */ __name((result, transform2) => ({
2432
- type: "JsdocTypeObjectField",
2433
- key: result.key,
2434
- right: result.right === void 0 ? void 0 : transform2(result.right),
2435
- optional: result.optional,
2436
- readonly: result.readonly,
2437
- meta: result.meta
2438
- }), "JsdocTypeObjectField"),
2439
- JsdocTypeJsdocObjectField: /* @__PURE__ */ __name((result, transform2) => ({
2440
- type: "JsdocTypeJsdocObjectField",
2441
- left: transform2(result.left),
2442
- right: transform2(result.right)
2443
- }), "JsdocTypeJsdocObjectField"),
2444
- JsdocTypeKeyValue: /* @__PURE__ */ __name((result, transform2) => {
2445
- return {
2446
- type: "JsdocTypeKeyValue",
2447
- key: result.key,
2448
- right: result.right === void 0 ? void 0 : transform2(result.right),
2449
- optional: result.optional,
2450
- variadic: result.variadic
2451
- };
2452
- }, "JsdocTypeKeyValue"),
2453
- JsdocTypeImport: /* @__PURE__ */ __name((result, transform2) => ({
2454
- type: "JsdocTypeImport",
2455
- element: transform2(result.element)
2456
- }), "JsdocTypeImport"),
2457
- JsdocTypeAny: /* @__PURE__ */ __name((result) => result, "JsdocTypeAny"),
2458
- JsdocTypeStringValue: /* @__PURE__ */ __name((result) => result, "JsdocTypeStringValue"),
2459
- JsdocTypeNamePath: /* @__PURE__ */ __name((result) => result, "JsdocTypeNamePath"),
2460
- JsdocTypeVariadic: /* @__PURE__ */ __name((result, transform2) => {
2461
- const transformed = {
2462
- type: "JsdocTypeVariadic",
2463
- meta: {
2464
- position: result.meta.position,
2465
- squareBrackets: result.meta.squareBrackets
2466
- }
2467
- };
2468
- if (result.element !== void 0) {
2469
- transformed.element = transform2(result.element);
2470
- }
2471
- return transformed;
2472
- }, "JsdocTypeVariadic"),
2473
- JsdocTypeTuple: /* @__PURE__ */ __name((result, transform2) => ({
2474
- type: "JsdocTypeTuple",
2475
- elements: result.elements.map(transform2)
2476
- }), "JsdocTypeTuple"),
2477
- JsdocTypeName: /* @__PURE__ */ __name((result) => result, "JsdocTypeName"),
2478
- JsdocTypeFunction: /* @__PURE__ */ __name((result, transform2) => {
2479
- const transformed = {
2480
- type: "JsdocTypeFunction",
2481
- arrow: result.arrow,
2482
- parameters: result.parameters.map(transform2),
2483
- constructor: result.constructor,
2484
- parenthesis: result.parenthesis
2485
- };
2486
- if (result.returnType !== void 0) {
2487
- transformed.returnType = transform2(result.returnType);
2488
- }
2489
- return transformed;
2490
- }, "JsdocTypeFunction"),
2491
- JsdocTypeKeyof: /* @__PURE__ */ __name((result, transform2) => ({
2492
- type: "JsdocTypeKeyof",
2493
- element: transform2(result.element)
2494
- }), "JsdocTypeKeyof"),
2495
- JsdocTypeParenthesis: /* @__PURE__ */ __name((result, transform2) => ({
2496
- type: "JsdocTypeParenthesis",
2497
- element: transform2(result.element)
2498
- }), "JsdocTypeParenthesis"),
2499
- JsdocTypeProperty: /* @__PURE__ */ __name((result) => result, "JsdocTypeProperty"),
2500
- JsdocTypePredicate: /* @__PURE__ */ __name((result, transform2) => ({
2501
- type: "JsdocTypePredicate",
2502
- left: transform2(result.left),
2503
- right: transform2(result.right)
2504
- }), "JsdocTypePredicate"),
2505
- JsdocTypeIndexSignature: /* @__PURE__ */ __name((result, transform2) => ({
2506
- type: "JsdocTypeIndexSignature",
2507
- key: result.key,
2508
- right: transform2(result.right)
2509
- }), "JsdocTypeIndexSignature"),
2510
- JsdocTypeMappedType: /* @__PURE__ */ __name((result, transform2) => ({
2511
- type: "JsdocTypeMappedType",
2512
- key: result.key,
2513
- right: transform2(result.right)
2514
- }), "JsdocTypeMappedType"),
2515
- JsdocTypeAsserts: /* @__PURE__ */ __name((result, transform2) => ({
2516
- type: "JsdocTypeAsserts",
2517
- left: transform2(result.left),
2518
- right: transform2(result.right)
2519
- }), "JsdocTypeAsserts"),
2520
- JsdocTypeReadonlyArray: /* @__PURE__ */ __name((result, transform2) => ({
2521
- type: "JsdocTypeReadonlyArray",
2522
- element: transform2(result.element)
2523
- }), "JsdocTypeReadonlyArray"),
2524
- JsdocTypeAssertsPlain: /* @__PURE__ */ __name((result, transform2) => ({
2525
- type: "JsdocTypeAssertsPlain",
2526
- element: transform2(result.element)
2527
- }), "JsdocTypeAssertsPlain"),
2528
- JsdocTypeConditional: /* @__PURE__ */ __name((result, transform2) => ({
2529
- type: "JsdocTypeConditional",
2530
- checksType: transform2(result.checksType),
2531
- extendsType: transform2(result.extendsType),
2532
- trueType: transform2(result.trueType),
2533
- falseType: transform2(result.falseType)
2534
- }), "JsdocTypeConditional"),
2535
- JsdocTypeTypeParameter: /* @__PURE__ */ __name((result, transform2) => ({
2536
- type: "JsdocTypeTypeParameter",
2537
- name: transform2(result.name),
2538
- constraint: result.constraint !== void 0 ? transform2(result.constraint) : void 0,
2539
- defaultValue: result.defaultValue !== void 0 ? transform2(result.defaultValue) : void 0
2540
- }), "JsdocTypeTypeParameter")
2541
- };
2542
- }
2543
- __name(identityTransformRules, "identityTransformRules");
2544
- const visitorKeys = {
2545
- JsdocTypeAny: [],
2546
- JsdocTypeFunction: ["parameters", "returnType"],
2547
- JsdocTypeGeneric: ["left", "elements"],
2548
- JsdocTypeImport: [],
2549
- JsdocTypeIndexSignature: ["right"],
2550
- JsdocTypeIntersection: ["elements"],
2551
- JsdocTypeKeyof: ["element"],
2552
- JsdocTypeKeyValue: ["right"],
2553
- JsdocTypeMappedType: ["right"],
2554
- JsdocTypeName: [],
2555
- JsdocTypeNamePath: ["left", "right"],
2556
- JsdocTypeNotNullable: ["element"],
2557
- JsdocTypeNull: [],
2558
- JsdocTypeNullable: ["element"],
2559
- JsdocTypeNumber: [],
2560
- JsdocTypeObject: ["elements"],
2561
- JsdocTypeObjectField: ["right"],
2562
- JsdocTypeJsdocObjectField: ["left", "right"],
2563
- JsdocTypeOptional: ["element"],
2564
- JsdocTypeParenthesis: ["element"],
2565
- JsdocTypeSpecialNamePath: [],
2566
- JsdocTypeStringValue: [],
2567
- JsdocTypeSymbol: ["element"],
2568
- JsdocTypeTuple: ["elements"],
2569
- JsdocTypeTypeof: ["element"],
2570
- JsdocTypeUndefined: [],
2571
- JsdocTypeUnion: ["elements"],
2572
- JsdocTypeUnknown: [],
2573
- JsdocTypeVariadic: ["element"],
2574
- JsdocTypeProperty: [],
2575
- JsdocTypePredicate: ["left", "right"],
2576
- JsdocTypeAsserts: ["left", "right"],
2577
- JsdocTypeReadonlyArray: ["element"],
2578
- JsdocTypeAssertsPlain: ["element"],
2579
- JsdocTypeConditional: ["checksType", "extendsType", "trueType", "falseType"],
2580
- JsdocTypeTypeParameter: ["name", "constraint", "defaultValue"]
2581
- };
2582
- function _traverse(node, parentNode, property, onEnter, onLeave) {
2583
- onEnter === null || onEnter === void 0 ? void 0 : onEnter(node, parentNode, property);
2584
- const keysToVisit = visitorKeys[node.type];
2585
- for (const key of keysToVisit) {
2586
- const value = node[key];
2587
- if (value !== void 0) {
2588
- if (Array.isArray(value)) {
2589
- for (const element of value) {
2590
- _traverse(element, node, key, onEnter, onLeave);
2591
- }
2592
- } else {
2593
- _traverse(value, node, key, onEnter, onLeave);
2594
- }
2595
- }
2596
- }
2597
- onLeave === null || onLeave === void 0 ? void 0 : onLeave(node, parentNode, property);
2598
- }
2599
- __name(_traverse, "_traverse");
2600
- function traverse(node, onEnter, onLeave) {
2601
- _traverse(node, void 0, void 0, onEnter, onLeave);
2602
- }
2603
- __name(traverse, "traverse");
2604
- exports2.catharsisTransform = catharsisTransform;
2605
- exports2.identityTransformRules = identityTransformRules;
2606
- exports2.jtpTransform = jtpTransform;
2607
- exports2.parse = parse3;
2608
- exports2.stringify = stringify2;
2609
- exports2.stringifyRules = stringifyRules2;
2610
- exports2.transform = transform;
2611
- exports2.traverse = traverse;
2612
- exports2.tryParse = tryParse;
2613
- exports2.visitorKeys = visitorKeys;
2614
- });
2615
- }
2616
- });
2617
-
2618
- // src/docs-tools/argTypes/convert/flow/convert.ts
2619
- import { UnknownArgTypesError } from "storybook/internal/preview-errors";
2620
- var isLiteral = /* @__PURE__ */ __name((type) => type.name === "literal", "isLiteral");
2621
- var toEnumOption = /* @__PURE__ */ __name((element) => element.value.replace(/['|"]/g, ""), "toEnumOption");
2622
- var convertSig = /* @__PURE__ */ __name((type) => {
2623
- switch (type.type) {
2624
- case "function":
2625
- return { name: "function" };
2626
- case "object":
2627
- const values = {};
2628
- type.signature.properties.forEach((prop) => {
2629
- values[prop.key] = convert(prop.value);
2630
- });
2631
- return {
2632
- name: "object",
2633
- value: values
2634
- };
2635
- default:
2636
- throw new UnknownArgTypesError({ type, language: "Flow" });
2637
- }
2638
- }, "convertSig");
2639
- var convert = /* @__PURE__ */ __name((type) => {
2640
- const { name, raw } = type;
2641
- const base = {};
2642
- if (typeof raw !== "undefined") {
2643
- base.raw = raw;
2644
- }
2645
- switch (type.name) {
2646
- case "literal":
2647
- return { ...base, name: "other", value: type.value };
2648
- case "string":
2649
- case "number":
2650
- case "symbol":
2651
- case "boolean": {
2652
- return { ...base, name };
2653
- }
2654
- case "Array": {
2655
- return { ...base, name: "array", value: type.elements.map(convert) };
2656
- }
2657
- case "signature":
2658
- return { ...base, ...convertSig(type) };
2659
- case "union":
2660
- if (type.elements?.every(isLiteral)) {
2661
- return { ...base, name: "enum", value: type.elements?.map(toEnumOption) };
2662
- }
2663
- return { ...base, name, value: type.elements?.map(convert) };
2664
- case "intersection":
2665
- return { ...base, name, value: type.elements?.map(convert) };
2666
- default:
2667
- return { ...base, name: "other", value: name };
2668
- }
2669
- }, "convert");
2670
-
2671
- // src/docs-tools/argTypes/convert/utils.ts
2672
- var QUOTE_REGEX = /^['"]|['"]$/g;
2673
- var trimQuotes = /* @__PURE__ */ __name((str2) => str2.replace(QUOTE_REGEX, ""), "trimQuotes");
2674
- var includesQuotes = /* @__PURE__ */ __name((str2) => QUOTE_REGEX.test(str2), "includesQuotes");
2675
- var parseLiteral = /* @__PURE__ */ __name((str2) => {
2676
- const trimmedValue = trimQuotes(str2);
2677
- return includesQuotes(str2) || Number.isNaN(Number(trimmedValue)) ? trimmedValue : Number(trimmedValue);
2678
- }, "parseLiteral");
2679
-
2680
- // src/docs-tools/argTypes/convert/proptypes/convert.ts
2681
- var SIGNATURE_REGEXP = /^\(.*\) => /;
2682
- var convert2 = /* @__PURE__ */ __name((type) => {
2683
- const { name, raw, computed, value } = type;
2684
- const base = {};
2685
- if (typeof raw !== "undefined") {
2686
- base.raw = raw;
2687
- }
2688
- switch (name) {
2689
- case "enum": {
2690
- const values2 = computed ? value : value.map((v) => parseLiteral(v.value));
2691
- return { ...base, name, value: values2 };
2692
- }
2693
- case "string":
2694
- case "number":
2695
- case "symbol":
2696
- return { ...base, name };
2697
- case "func":
2698
- return { ...base, name: "function" };
2699
- case "bool":
2700
- case "boolean":
2701
- return { ...base, name: "boolean" };
2702
- case "arrayOf":
2703
- case "array":
2704
- return { ...base, name: "array", value: value && convert2(value) };
2705
- case "object":
2706
- return { ...base, name };
2707
- case "objectOf":
2708
- return { ...base, name, value: convert2(value) };
2709
- case "shape":
2710
- case "exact":
2711
- const values = mapValues(value, (field) => convert2(field));
2712
- return { ...base, name: "object", value: values };
2713
- case "union":
2714
- return { ...base, name: "union", value: value.map((v) => convert2(v)) };
2715
- case "instanceOf":
2716
- case "element":
2717
- case "elementType":
2718
- default: {
2719
- if (name?.indexOf("|") > 0) {
2720
- try {
2721
- const literalValues = name.split("|").map((v) => JSON.parse(v));
2722
- return { ...base, name: "enum", value: literalValues };
2723
- } catch (err) {
2724
- }
2725
- }
2726
- const otherVal = value ? `${name}(${value})` : name;
2727
- const otherName = SIGNATURE_REGEXP.test(name) ? "function" : "other";
2728
- return { ...base, name: otherName, value: otherVal };
2729
- }
2730
- }
2731
- }, "convert");
2732
-
2733
- // src/docs-tools/argTypes/convert/typescript/convert.ts
2734
- import { UnknownArgTypesError as UnknownArgTypesError2 } from "storybook/internal/preview-errors";
2735
- var convertSig2 = /* @__PURE__ */ __name((type) => {
2736
- switch (type.type) {
2737
- case "function":
2738
- return { name: "function" };
2739
- case "object":
2740
- const values = {};
2741
- type.signature.properties.forEach((prop) => {
2742
- values[prop.key] = convert3(prop.value);
2743
- });
2744
- return {
2745
- name: "object",
2746
- value: values
2747
- };
2748
- default:
2749
- throw new UnknownArgTypesError2({ type, language: "Typescript" });
2750
- }
2751
- }, "convertSig");
2752
- var convert3 = /* @__PURE__ */ __name((type) => {
2753
- const { name, raw } = type;
2754
- const base = {};
2755
- if (typeof raw !== "undefined") {
2756
- base.raw = raw;
2757
- }
2758
- switch (type.name) {
2759
- case "string":
2760
- case "number":
2761
- case "symbol":
2762
- case "boolean": {
2763
- return { ...base, name };
2764
- }
2765
- case "Array": {
2766
- return { ...base, name: "array", value: type.elements.map(convert3) };
2767
- }
2768
- case "signature":
2769
- return { ...base, ...convertSig2(type) };
2770
- case "union":
2771
- let result;
2772
- if (type.elements?.every((element) => element.name === "literal")) {
2773
- result = {
2774
- ...base,
2775
- name: "enum",
2776
- // @ts-expect-error fix types
2777
- value: type.elements?.map((v) => parseLiteral(v.value))
2778
- };
2779
- } else {
2780
- result = { ...base, name, value: type.elements?.map(convert3) };
2781
- }
2782
- return result;
2783
- case "intersection":
2784
- return { ...base, name, value: type.elements?.map(convert3) };
2785
- default:
2786
- return { ...base, name: "other", value: name };
2787
- }
2788
- }, "convert");
2789
-
2790
- // src/docs-tools/argTypes/convert/index.ts
2791
- var convert4 = /* @__PURE__ */ __name((docgenInfo) => {
2792
- const { type, tsType, flowType } = docgenInfo;
2793
- try {
2794
- if (type != null) {
2795
- return convert2(type);
2796
- }
2797
- if (tsType != null) {
2798
- return convert3(tsType);
2799
- }
2800
- if (flowType != null) {
2801
- return convert(flowType);
2802
- }
2803
- } catch (err) {
2804
- console.error(err);
2805
- }
2806
- return null;
2807
- }, "convert");
2808
-
2809
- // src/docs-tools/argTypes/docgen/types.ts
2810
- var TypeSystem = /* @__PURE__ */ ((TypeSystem2) => {
2811
- TypeSystem2["JAVASCRIPT"] = "JavaScript";
2812
- TypeSystem2["FLOW"] = "Flow";
2813
- TypeSystem2["TYPESCRIPT"] = "TypeScript";
2814
- TypeSystem2["UNKNOWN"] = "Unknown";
2815
- return TypeSystem2;
2816
- })(TypeSystem || {});
2817
-
2818
- // src/docs-tools/argTypes/docgen/utils/defaultValue.ts
2819
- var BLACKLIST = ["null", "undefined"];
2820
- function isDefaultValueBlacklisted(value) {
2821
- return BLACKLIST.some((x) => x === value);
2822
- }
2823
- __name(isDefaultValueBlacklisted, "isDefaultValueBlacklisted");
2824
-
2825
- // src/docs-tools/argTypes/docgen/utils/string.ts
2826
- var str = /* @__PURE__ */ __name((obj) => {
2827
- if (!obj) {
2828
- return "";
2829
- }
2830
- if (typeof obj === "string") {
2831
- return obj;
2832
- }
2833
- throw new Error(`Description: expected string, got: ${JSON.stringify(obj)}`);
2834
- }, "str");
2835
-
2836
- // src/docs-tools/argTypes/docgen/utils/docgenInfo.ts
2837
- function hasDocgen(component) {
2838
- return !!component.__docgenInfo;
2839
- }
2840
- __name(hasDocgen, "hasDocgen");
2841
- function isValidDocgenSection(docgenSection) {
2842
- return docgenSection != null && Object.keys(docgenSection).length > 0;
2843
- }
2844
- __name(isValidDocgenSection, "isValidDocgenSection");
2845
- function getDocgenSection(component, section) {
2846
- return hasDocgen(component) ? component.__docgenInfo[section] : null;
2847
- }
2848
- __name(getDocgenSection, "getDocgenSection");
2849
- function getDocgenDescription(component) {
2850
- return hasDocgen(component) ? str(component.__docgenInfo.description) : "";
2851
- }
2852
- __name(getDocgenDescription, "getDocgenDescription");
2853
-
2854
- // ../node_modules/comment-parser/es6/primitives.js
2855
- var Markers;
2856
- (function(Markers2) {
2857
- Markers2["start"] = "/**";
2858
- Markers2["nostart"] = "/***";
2859
- Markers2["delim"] = "*";
2860
- Markers2["end"] = "*/";
2861
- })(Markers = Markers || (Markers = {}));
2862
-
2863
- // ../node_modules/comment-parser/es6/util.js
2864
- function isSpace(source) {
2865
- return /^\s+$/.test(source);
2866
- }
2867
- __name(isSpace, "isSpace");
2868
- function splitCR(source) {
2869
- const matches = source.match(/\r+$/);
2870
- return matches == null ? ["", source] : [source.slice(-matches[0].length), source.slice(0, -matches[0].length)];
2871
- }
2872
- __name(splitCR, "splitCR");
2873
- function splitSpace(source) {
2874
- const matches = source.match(/^\s+/);
2875
- return matches == null ? ["", source] : [source.slice(0, matches[0].length), source.slice(matches[0].length)];
2876
- }
2877
- __name(splitSpace, "splitSpace");
2878
- function splitLines(source) {
2879
- return source.split(/\n/);
2880
- }
2881
- __name(splitLines, "splitLines");
2882
- function seedSpec(spec = {}) {
2883
- return Object.assign({ tag: "", name: "", type: "", optional: false, description: "", problems: [], source: [] }, spec);
2884
- }
2885
- __name(seedSpec, "seedSpec");
2886
- function seedTokens(tokens = {}) {
2887
- return Object.assign({ start: "", delimiter: "", postDelimiter: "", tag: "", postTag: "", name: "", postName: "", type: "", postType: "", description: "", end: "", lineEnd: "" }, tokens);
2888
- }
2889
- __name(seedTokens, "seedTokens");
2890
-
2891
- // ../node_modules/comment-parser/es6/parser/block-parser.js
2892
- var reTag = /^@\S+/;
2893
- function getParser({ fence = "```" } = {}) {
2894
- const fencer = getFencer(fence);
2895
- const toggleFence = /* @__PURE__ */ __name((source, isFenced) => fencer(source) ? !isFenced : isFenced, "toggleFence");
2896
- return /* @__PURE__ */ __name(function parseBlock(source) {
2897
- const sections = [[]];
2898
- let isFenced = false;
2899
- for (const line of source) {
2900
- if (reTag.test(line.tokens.description) && !isFenced) {
2901
- sections.push([line]);
2902
- } else {
2903
- sections[sections.length - 1].push(line);
2904
- }
2905
- isFenced = toggleFence(line.tokens.description, isFenced);
2906
- }
2907
- return sections;
2908
- }, "parseBlock");
2909
- }
2910
- __name(getParser, "getParser");
2911
- function getFencer(fence) {
2912
- if (typeof fence === "string")
2913
- return (source) => source.split(fence).length % 2 === 0;
2914
- return fence;
2915
- }
2916
- __name(getFencer, "getFencer");
2917
-
2918
- // ../node_modules/comment-parser/es6/parser/source-parser.js
2919
- function getParser2({ startLine = 0, markers = Markers } = {}) {
2920
- let block = null;
2921
- let num = startLine;
2922
- return /* @__PURE__ */ __name(function parseSource(source) {
2923
- let rest = source;
2924
- const tokens = seedTokens();
2925
- [tokens.lineEnd, rest] = splitCR(rest);
2926
- [tokens.start, rest] = splitSpace(rest);
2927
- if (block === null && rest.startsWith(markers.start) && !rest.startsWith(markers.nostart)) {
2928
- block = [];
2929
- tokens.delimiter = rest.slice(0, markers.start.length);
2930
- rest = rest.slice(markers.start.length);
2931
- [tokens.postDelimiter, rest] = splitSpace(rest);
2932
- }
2933
- if (block === null) {
2934
- num++;
2935
- return null;
2936
- }
2937
- const isClosed = rest.trimRight().endsWith(markers.end);
2938
- if (tokens.delimiter === "" && rest.startsWith(markers.delim) && !rest.startsWith(markers.end)) {
2939
- tokens.delimiter = markers.delim;
2940
- rest = rest.slice(markers.delim.length);
2941
- [tokens.postDelimiter, rest] = splitSpace(rest);
2942
- }
2943
- if (isClosed) {
2944
- const trimmed = rest.trimRight();
2945
- tokens.end = rest.slice(trimmed.length - markers.end.length);
2946
- rest = trimmed.slice(0, -markers.end.length);
2947
- }
2948
- tokens.description = rest;
2949
- block.push({ number: num, source, tokens });
2950
- num++;
2951
- if (isClosed) {
2952
- const result = block.slice();
2953
- block = null;
2954
- return result;
2955
- }
2956
- return null;
2957
- }, "parseSource");
2958
- }
2959
- __name(getParser2, "getParser");
2960
-
2961
- // ../node_modules/comment-parser/es6/parser/spec-parser.js
2962
- function getParser3({ tokenizers }) {
2963
- return /* @__PURE__ */ __name(function parseSpec(source) {
2964
- var _a;
2965
- let spec = seedSpec({ source });
2966
- for (const tokenize of tokenizers) {
2967
- spec = tokenize(spec);
2968
- if ((_a = spec.problems[spec.problems.length - 1]) === null || _a === void 0 ? void 0 : _a.critical)
2969
- break;
2970
- }
2971
- return spec;
2972
- }, "parseSpec");
2973
- }
2974
- __name(getParser3, "getParser");
2975
-
2976
- // ../node_modules/comment-parser/es6/parser/tokenizers/tag.js
2977
- function tagTokenizer() {
2978
- return (spec) => {
2979
- const { tokens } = spec.source[0];
2980
- const match = tokens.description.match(/\s*(@(\S+))(\s*)/);
2981
- if (match === null) {
2982
- spec.problems.push({
2983
- code: "spec:tag:prefix",
2984
- message: 'tag should start with "@" symbol',
2985
- line: spec.source[0].number,
2986
- critical: true
2987
- });
2988
- return spec;
2989
- }
2990
- tokens.tag = match[1];
2991
- tokens.postTag = match[3];
2992
- tokens.description = tokens.description.slice(match[0].length);
2993
- spec.tag = match[2];
2994
- return spec;
2995
- };
2996
- }
2997
- __name(tagTokenizer, "tagTokenizer");
2998
-
2999
- // ../node_modules/comment-parser/es6/parser/tokenizers/type.js
3000
- function typeTokenizer(spacing = "compact") {
3001
- const join2 = getJoiner(spacing);
3002
- return (spec) => {
3003
- let curlies = 0;
3004
- let lines = [];
3005
- for (const [i, { tokens }] of spec.source.entries()) {
3006
- let type = "";
3007
- if (i === 0 && tokens.description[0] !== "{")
3008
- return spec;
3009
- for (const ch of tokens.description) {
3010
- if (ch === "{")
3011
- curlies++;
3012
- if (ch === "}")
3013
- curlies--;
3014
- type += ch;
3015
- if (curlies === 0)
3016
- break;
3017
- }
3018
- lines.push([tokens, type]);
3019
- if (curlies === 0)
3020
- break;
3021
- }
3022
- if (curlies !== 0) {
3023
- spec.problems.push({
3024
- code: "spec:type:unpaired-curlies",
3025
- message: "unpaired curlies",
3026
- line: spec.source[0].number,
3027
- critical: true
3028
- });
3029
- return spec;
3030
- }
3031
- const parts = [];
3032
- const offset = lines[0][0].postDelimiter.length;
3033
- for (const [i, [tokens, type]] of lines.entries()) {
3034
- tokens.type = type;
3035
- if (i > 0) {
3036
- tokens.type = tokens.postDelimiter.slice(offset) + type;
3037
- tokens.postDelimiter = tokens.postDelimiter.slice(0, offset);
3038
- }
3039
- [tokens.postType, tokens.description] = splitSpace(tokens.description.slice(type.length));
3040
- parts.push(tokens.type);
3041
- }
3042
- parts[0] = parts[0].slice(1);
3043
- parts[parts.length - 1] = parts[parts.length - 1].slice(0, -1);
3044
- spec.type = join2(parts);
3045
- return spec;
3046
- };
3047
- }
3048
- __name(typeTokenizer, "typeTokenizer");
3049
- var trim = /* @__PURE__ */ __name((x) => x.trim(), "trim");
3050
- function getJoiner(spacing) {
3051
- if (spacing === "compact")
3052
- return (t) => t.map(trim).join("");
3053
- else if (spacing === "preserve")
3054
- return (t) => t.join("\n");
3055
- else
3056
- return spacing;
3057
- }
3058
- __name(getJoiner, "getJoiner");
3059
-
3060
- // ../node_modules/comment-parser/es6/parser/tokenizers/name.js
3061
- var isQuoted = /* @__PURE__ */ __name((s) => s && s.startsWith('"') && s.endsWith('"'), "isQuoted");
3062
- function nameTokenizer() {
3063
- const typeEnd = /* @__PURE__ */ __name((num, { tokens }, i) => tokens.type === "" ? num : i, "typeEnd");
3064
- return (spec) => {
3065
- const { tokens } = spec.source[spec.source.reduce(typeEnd, 0)];
3066
- const source = tokens.description.trimLeft();
3067
- const quotedGroups = source.split('"');
3068
- if (quotedGroups.length > 1 && quotedGroups[0] === "" && quotedGroups.length % 2 === 1) {
3069
- spec.name = quotedGroups[1];
3070
- tokens.name = `"${quotedGroups[1]}"`;
3071
- [tokens.postName, tokens.description] = splitSpace(source.slice(tokens.name.length));
3072
- return spec;
3073
- }
3074
- let brackets = 0;
3075
- let name = "";
3076
- let optional = false;
3077
- let defaultValue;
3078
- for (const ch of source) {
3079
- if (brackets === 0 && isSpace(ch))
3080
- break;
3081
- if (ch === "[")
3082
- brackets++;
3083
- if (ch === "]")
3084
- brackets--;
3085
- name += ch;
3086
- }
3087
- if (brackets !== 0) {
3088
- spec.problems.push({
3089
- code: "spec:name:unpaired-brackets",
3090
- message: "unpaired brackets",
3091
- line: spec.source[0].number,
3092
- critical: true
3093
- });
3094
- return spec;
3095
- }
3096
- const nameToken = name;
3097
- if (name[0] === "[" && name[name.length - 1] === "]") {
3098
- optional = true;
3099
- name = name.slice(1, -1);
3100
- const parts = name.split("=");
3101
- name = parts[0].trim();
3102
- if (parts[1] !== void 0)
3103
- defaultValue = parts.slice(1).join("=").trim();
3104
- if (name === "") {
3105
- spec.problems.push({
3106
- code: "spec:name:empty-name",
3107
- message: "empty name",
3108
- line: spec.source[0].number,
3109
- critical: true
3110
- });
3111
- return spec;
3112
- }
3113
- if (defaultValue === "") {
3114
- spec.problems.push({
3115
- code: "spec:name:empty-default",
3116
- message: "empty default value",
3117
- line: spec.source[0].number,
3118
- critical: true
3119
- });
3120
- return spec;
3121
- }
3122
- if (!isQuoted(defaultValue) && /=(?!>)/.test(defaultValue)) {
3123
- spec.problems.push({
3124
- code: "spec:name:invalid-default",
3125
- message: "invalid default value syntax",
3126
- line: spec.source[0].number,
3127
- critical: true
3128
- });
3129
- return spec;
3130
- }
3131
- }
3132
- spec.optional = optional;
3133
- spec.name = name;
3134
- tokens.name = nameToken;
3135
- if (defaultValue !== void 0)
3136
- spec.default = defaultValue;
3137
- [tokens.postName, tokens.description] = splitSpace(source.slice(tokens.name.length));
3138
- return spec;
3139
- };
3140
- }
3141
- __name(nameTokenizer, "nameTokenizer");
3142
-
3143
- // ../node_modules/comment-parser/es6/parser/tokenizers/description.js
3144
- function descriptionTokenizer(spacing = "compact", markers = Markers) {
3145
- const join2 = getJoiner2(spacing);
3146
- return (spec) => {
3147
- spec.description = join2(spec.source, markers);
3148
- return spec;
3149
- };
3150
- }
3151
- __name(descriptionTokenizer, "descriptionTokenizer");
3152
- function getJoiner2(spacing) {
3153
- if (spacing === "compact")
3154
- return compactJoiner;
3155
- if (spacing === "preserve")
3156
- return preserveJoiner;
3157
- return spacing;
3158
- }
3159
- __name(getJoiner2, "getJoiner");
3160
- function compactJoiner(lines, markers = Markers) {
3161
- return lines.map(({ tokens: { description } }) => description.trim()).filter((description) => description !== "").join(" ");
3162
- }
3163
- __name(compactJoiner, "compactJoiner");
3164
- var lineNo = /* @__PURE__ */ __name((num, { tokens }, i) => tokens.type === "" ? num : i, "lineNo");
3165
- var getDescription = /* @__PURE__ */ __name(({ tokens }) => (tokens.delimiter === "" ? tokens.start : tokens.postDelimiter.slice(1)) + tokens.description, "getDescription");
3166
- function preserveJoiner(lines, markers = Markers) {
3167
- if (lines.length === 0)
3168
- return "";
3169
- if (lines[0].tokens.description === "" && lines[0].tokens.delimiter === markers.start)
3170
- lines = lines.slice(1);
3171
- const lastLine = lines[lines.length - 1];
3172
- if (lastLine !== void 0 && lastLine.tokens.description === "" && lastLine.tokens.end.endsWith(markers.end))
3173
- lines = lines.slice(0, -1);
3174
- lines = lines.slice(lines.reduce(lineNo, 0));
3175
- return lines.map(getDescription).join("\n");
3176
- }
3177
- __name(preserveJoiner, "preserveJoiner");
3178
-
3179
- // ../node_modules/comment-parser/es6/parser/index.js
3180
- function getParser4({ startLine = 0, fence = "```", spacing = "compact", markers = Markers, tokenizers = [
3181
- tagTokenizer(),
3182
- typeTokenizer(spacing),
3183
- nameTokenizer(),
3184
- descriptionTokenizer(spacing)
3185
- ] } = {}) {
3186
- if (startLine < 0 || startLine % 1 > 0)
3187
- throw new Error("Invalid startLine");
3188
- const parseSource = getParser2({ startLine, markers });
3189
- const parseBlock = getParser({ fence });
3190
- const parseSpec = getParser3({ tokenizers });
3191
- const joinDescription = getJoiner2(spacing);
3192
- return function(source) {
3193
- const blocks = [];
3194
- for (const line of splitLines(source)) {
3195
- const lines = parseSource(line);
3196
- if (lines === null)
3197
- continue;
3198
- const sections = parseBlock(lines);
3199
- const specs = sections.slice(1).map(parseSpec);
3200
- blocks.push({
3201
- description: joinDescription(sections[0], markers),
3202
- tags: specs,
3203
- source: lines,
3204
- problems: specs.reduce((acc, spec) => acc.concat(spec.problems), [])
3205
- });
3206
- }
3207
- return blocks;
3208
- };
3209
- }
3210
- __name(getParser4, "getParser");
3211
-
3212
- // ../node_modules/comment-parser/es6/stringifier/index.js
3213
- function join(tokens) {
3214
- return tokens.start + tokens.delimiter + tokens.postDelimiter + tokens.tag + tokens.postTag + tokens.type + tokens.postType + tokens.name + tokens.postName + tokens.description + tokens.end + tokens.lineEnd;
3215
- }
3216
- __name(join, "join");
3217
- function getStringifier() {
3218
- return (block) => block.source.map(({ tokens }) => join(tokens)).join("\n");
3219
- }
3220
- __name(getStringifier, "getStringifier");
3221
-
3222
- // ../node_modules/comment-parser/es6/stringifier/inspect.js
3223
- var zeroWidth = {
3224
- line: 0,
3225
- start: 0,
3226
- delimiter: 0,
3227
- postDelimiter: 0,
3228
- tag: 0,
3229
- postTag: 0,
3230
- name: 0,
3231
- postName: 0,
3232
- type: 0,
3233
- postType: 0,
3234
- description: 0,
3235
- end: 0,
3236
- lineEnd: 0
3237
- };
3238
- var fields = Object.keys(zeroWidth);
3239
-
3240
- // ../node_modules/comment-parser/es6/index.js
3241
- function parse(source, options = {}) {
3242
- return getParser4(options)(source);
3243
- }
3244
- __name(parse, "parse");
3245
- var stringify = getStringifier();
3246
-
3247
- // src/docs-tools/argTypes/jsdocParser.ts
3248
- var import_jsdoc_type_pratt_parser = __toESM(require_dist(), 1);
3249
- function containsJsDoc(value) {
3250
- return value != null && value.includes("@");
3251
- }
3252
- __name(containsJsDoc, "containsJsDoc");
3253
- function parse2(content) {
3254
- const contentString = content ?? "";
3255
- const mappedLines = contentString.split("\n").map((line) => ` * ${line}`).join("\n");
3256
- const normalisedContent = "/**\n" + mappedLines + "\n*/";
3257
- const ast = parse(normalisedContent, {
3258
- spacing: "preserve"
3259
- });
3260
- if (!ast || ast.length === 0) {
3261
- throw new Error("Cannot parse JSDoc tags.");
3262
- }
3263
- return ast[0];
3264
- }
3265
- __name(parse2, "parse");
3266
- var DEFAULT_OPTIONS = {
3267
- tags: ["param", "arg", "argument", "returns", "ignore", "deprecated"]
3268
- };
3269
- var parseJsDoc = /* @__PURE__ */ __name((value, options = DEFAULT_OPTIONS) => {
3270
- if (!containsJsDoc(value)) {
3271
- return {
3272
- includesJsDoc: false,
3273
- ignore: false
3274
- };
3275
- }
3276
- const jsDocAst = parse2(value);
3277
- const extractedTags = extractJsDocTags(jsDocAst, options.tags);
3278
- if (extractedTags.ignore) {
3279
- return {
3280
- includesJsDoc: true,
3281
- ignore: true
3282
- };
3283
- }
3284
- return {
3285
- includesJsDoc: true,
3286
- ignore: false,
3287
- // Always use the parsed description to ensure JSDoc is removed from the description.
3288
- description: jsDocAst.description.trim(),
3289
- extractedTags
3290
- };
3291
- }, "parseJsDoc");
3292
- function extractJsDocTags(ast, tags) {
3293
- const extractedTags = {
3294
- params: null,
3295
- deprecated: null,
3296
- returns: null,
3297
- ignore: false
3298
- };
3299
- for (const tagSpec of ast.tags) {
3300
- if (tags !== void 0 && !tags.includes(tagSpec.tag)) {
3301
- continue;
3302
- }
3303
- if (tagSpec.tag === "ignore") {
3304
- extractedTags.ignore = true;
3305
- break;
3306
- } else {
3307
- switch (tagSpec.tag) {
3308
- // arg & argument are aliases for param.
3309
- case "param":
3310
- case "arg":
3311
- case "argument": {
3312
- const paramTag = extractParam(tagSpec);
3313
- if (paramTag != null) {
3314
- if (extractedTags.params == null) {
3315
- extractedTags.params = [];
3316
- }
3317
- extractedTags.params.push(paramTag);
3318
- }
3319
- break;
3320
- }
3321
- case "deprecated": {
3322
- const deprecatedTag = extractDeprecated(tagSpec);
3323
- if (deprecatedTag != null) {
3324
- extractedTags.deprecated = deprecatedTag;
3325
- }
3326
- break;
3327
- }
3328
- case "returns": {
3329
- const returnsTag = extractReturns(tagSpec);
3330
- if (returnsTag != null) {
3331
- extractedTags.returns = returnsTag;
3332
- }
3333
- break;
3334
- }
3335
- default:
3336
- break;
3337
- }
3338
- }
3339
- }
3340
- return extractedTags;
3341
- }
3342
- __name(extractJsDocTags, "extractJsDocTags");
3343
- function normaliseParamName(name) {
3344
- return name.replace(/[\.-]$/, "");
3345
- }
3346
- __name(normaliseParamName, "normaliseParamName");
3347
- function extractParam(tag) {
3348
- if (!tag.name || tag.name === "-") {
3349
- return null;
3350
- }
3351
- const type = extractType(tag.type);
3352
- return {
3353
- name: tag.name,
3354
- type,
3355
- description: normaliseDescription(tag.description),
3356
- getPrettyName: /* @__PURE__ */ __name(() => {
3357
- return normaliseParamName(tag.name);
3358
- }, "getPrettyName"),
3359
- getTypeName: /* @__PURE__ */ __name(() => {
3360
- return type ? extractTypeName(type) : null;
3361
- }, "getTypeName")
3362
- };
3363
- }
3364
- __name(extractParam, "extractParam");
3365
- function extractDeprecated(tag) {
3366
- if (tag.name) {
3367
- return joinNameAndDescription(tag.name, tag.description);
3368
- }
3369
- return null;
3370
- }
3371
- __name(extractDeprecated, "extractDeprecated");
3372
- function joinNameAndDescription(name, desc) {
3373
- const joined = name === "" ? desc : `${name} ${desc}`;
3374
- return normaliseDescription(joined);
3375
- }
3376
- __name(joinNameAndDescription, "joinNameAndDescription");
3377
- function normaliseDescription(text) {
3378
- const normalised = text.replace(/^- /g, "").trim();
3379
- return normalised === "" ? null : normalised;
3380
- }
3381
- __name(normaliseDescription, "normaliseDescription");
3382
- function extractReturns(tag) {
3383
- const type = extractType(tag.type);
3384
- if (type) {
3385
- return {
3386
- type,
3387
- description: joinNameAndDescription(tag.name, tag.description),
3388
- getTypeName: /* @__PURE__ */ __name(() => {
3389
- return extractTypeName(type);
3390
- }, "getTypeName")
3391
- };
3392
- }
3393
- return null;
3394
- }
3395
- __name(extractReturns, "extractReturns");
3396
- var jsdocStringifyRules = (0, import_jsdoc_type_pratt_parser.stringifyRules)();
3397
- var originalJsdocStringifyObject = jsdocStringifyRules.JsdocTypeObject;
3398
- jsdocStringifyRules.JsdocTypeAny = () => "any";
3399
- jsdocStringifyRules.JsdocTypeObject = (result, transform) => `(${originalJsdocStringifyObject(result, transform)})`;
3400
- jsdocStringifyRules.JsdocTypeOptional = (result, transform) => transform(result.element);
3401
- jsdocStringifyRules.JsdocTypeNullable = (result, transform) => transform(result.element);
3402
- jsdocStringifyRules.JsdocTypeNotNullable = (result, transform) => transform(result.element);
3403
- jsdocStringifyRules.JsdocTypeUnion = (result, transform) => result.elements.map(transform).join("|");
3404
- function extractType(typeString) {
3405
- try {
3406
- return (0, import_jsdoc_type_pratt_parser.parse)(typeString, "typescript");
3407
- } catch (_err) {
3408
- return null;
3409
- }
3410
- }
3411
- __name(extractType, "extractType");
3412
- function extractTypeName(type) {
3413
- return (0, import_jsdoc_type_pratt_parser.transform)(jsdocStringifyRules, type);
3414
- }
3415
- __name(extractTypeName, "extractTypeName");
3416
-
3417
- // src/docs-tools/argTypes/utils.ts
3418
- var MAX_TYPE_SUMMARY_LENGTH = 90;
3419
- var MAX_DEFAULT_VALUE_SUMMARY_LENGTH = 50;
3420
- function isTooLongForTypeSummary(value) {
3421
- return value.length > MAX_TYPE_SUMMARY_LENGTH;
3422
- }
3423
- __name(isTooLongForTypeSummary, "isTooLongForTypeSummary");
3424
- function isTooLongForDefaultValueSummary(value) {
3425
- return value.length > MAX_DEFAULT_VALUE_SUMMARY_LENGTH;
3426
- }
3427
- __name(isTooLongForDefaultValueSummary, "isTooLongForDefaultValueSummary");
3428
- function createSummaryValue(summary, detail) {
3429
- if (summary === detail) {
3430
- return { summary };
3431
- }
3432
- return { summary, detail };
3433
- }
3434
- __name(createSummaryValue, "createSummaryValue");
3435
- var normalizeNewlines = /* @__PURE__ */ __name((string) => string.replace(/\\r\\n/g, "\\n"), "normalizeNewlines");
3436
-
3437
- // src/docs-tools/argTypes/docgen/flow/createDefaultValue.ts
3438
- function createDefaultValue(defaultValue, type) {
3439
- if (defaultValue != null) {
3440
- const { value } = defaultValue;
3441
- if (!isDefaultValueBlacklisted(value)) {
3442
- return !isTooLongForDefaultValueSummary(value) ? createSummaryValue(value) : createSummaryValue(type?.name, value);
3443
- }
3444
- }
3445
- return null;
3446
- }
3447
- __name(createDefaultValue, "createDefaultValue");
3448
-
3449
- // src/docs-tools/argTypes/docgen/flow/createType.ts
3450
- function generateUnionElement({ name, value, elements, raw }) {
3451
- if (value != null) {
3452
- return value;
3453
- }
3454
- if (elements != null) {
3455
- return elements.map(generateUnionElement).join(" | ");
3456
- }
3457
- if (raw != null) {
3458
- return raw;
3459
- }
3460
- return name;
3461
- }
3462
- __name(generateUnionElement, "generateUnionElement");
3463
- function generateUnion({ name, raw, elements }) {
3464
- if (elements != null) {
3465
- return createSummaryValue(elements.map(generateUnionElement).join(" | "));
3466
- }
3467
- if (raw != null) {
3468
- return createSummaryValue(raw.replace(/^\|\s*/, ""));
3469
- }
3470
- return createSummaryValue(name);
3471
- }
3472
- __name(generateUnion, "generateUnion");
3473
- function generateFuncSignature({ type, raw }) {
3474
- if (raw != null) {
3475
- return createSummaryValue(raw);
3476
- }
3477
- return createSummaryValue(type);
3478
- }
3479
- __name(generateFuncSignature, "generateFuncSignature");
3480
- function generateObjectSignature({ type, raw }) {
3481
- if (raw != null) {
3482
- return !isTooLongForTypeSummary(raw) ? createSummaryValue(raw) : createSummaryValue(type, raw);
3483
- }
3484
- return createSummaryValue(type);
3485
- }
3486
- __name(generateObjectSignature, "generateObjectSignature");
3487
- function generateSignature(flowType) {
3488
- const { type } = flowType;
3489
- return type === "object" ? generateObjectSignature(flowType) : generateFuncSignature(flowType);
3490
- }
3491
- __name(generateSignature, "generateSignature");
3492
- function generateDefault({ name, raw }) {
3493
- if (raw != null) {
3494
- return !isTooLongForTypeSummary(raw) ? createSummaryValue(raw) : createSummaryValue(name, raw);
3495
- }
3496
- return createSummaryValue(name);
3497
- }
3498
- __name(generateDefault, "generateDefault");
3499
- function createType(type) {
3500
- if (type == null) {
3501
- return null;
3502
- }
3503
- switch (type.name) {
3504
- case "union" /* UNION */:
3505
- return generateUnion(type);
3506
- case "signature" /* SIGNATURE */:
3507
- return generateSignature(type);
3508
- default:
3509
- return generateDefault(type);
3510
- }
3511
- }
3512
- __name(createType, "createType");
3513
-
3514
- // src/docs-tools/argTypes/docgen/flow/createPropDef.ts
3515
- var createFlowPropDef = /* @__PURE__ */ __name((propName, docgenInfo) => {
3516
- const { flowType, description, required, defaultValue } = docgenInfo;
3517
- return {
3518
- name: propName,
3519
- type: createType(flowType),
3520
- required,
3521
- description,
3522
- defaultValue: createDefaultValue(defaultValue ?? null, flowType ?? null)
3523
- };
3524
- }, "createFlowPropDef");
3525
-
3526
- // src/docs-tools/argTypes/docgen/typeScript/createDefaultValue.ts
3527
- function createDefaultValue2({ defaultValue }) {
3528
- if (defaultValue != null) {
3529
- const { value } = defaultValue;
3530
- if (!isDefaultValueBlacklisted(value)) {
3531
- return createSummaryValue(value);
3532
- }
3533
- }
3534
- return null;
3535
- }
3536
- __name(createDefaultValue2, "createDefaultValue");
3537
-
3538
- // src/docs-tools/argTypes/docgen/typeScript/createType.ts
3539
- function createType2({ tsType, required }) {
3540
- if (tsType == null) {
3541
- return null;
3542
- }
3543
- let typeName = tsType.name;
3544
- if (!required) {
3545
- typeName = typeName.replace(" | undefined", "");
3546
- }
3547
- return createSummaryValue(
3548
- ["Array", "Record", "signature"].includes(tsType.name) ? tsType.raw : typeName
3549
- );
3550
- }
3551
- __name(createType2, "createType");
3552
-
3553
- // src/docs-tools/argTypes/docgen/typeScript/createPropDef.ts
3554
- var createTsPropDef = /* @__PURE__ */ __name((propName, docgenInfo) => {
3555
- const { description, required } = docgenInfo;
3556
- return {
3557
- name: propName,
3558
- type: createType2(docgenInfo),
3559
- required,
3560
- description,
3561
- defaultValue: createDefaultValue2(docgenInfo)
3562
- };
3563
- }, "createTsPropDef");
3564
-
3565
- // src/docs-tools/argTypes/docgen/createPropDef.ts
3566
- function createType3(type) {
3567
- return type != null ? createSummaryValue(type.name) : null;
3568
- }
3569
- __name(createType3, "createType");
3570
- function isReactDocgenTypescript(defaultValue) {
3571
- const { computed, func } = defaultValue;
3572
- return typeof computed === "undefined" && typeof func === "undefined";
3573
- }
3574
- __name(isReactDocgenTypescript, "isReactDocgenTypescript");
3575
- function isStringValued(type) {
3576
- if (!type) {
3577
- return false;
3578
- }
3579
- if (type.name === "string") {
3580
- return true;
3581
- }
3582
- if (type.name === "enum") {
3583
- return Array.isArray(type.value) && type.value.every(
3584
- ({ value: tv }) => typeof tv === "string" && tv[0] === '"' && tv[tv.length - 1] === '"'
3585
- );
3586
- }
3587
- return false;
3588
- }
3589
- __name(isStringValued, "isStringValued");
3590
- function createDefaultValue3(defaultValue, type) {
3591
- if (defaultValue != null) {
3592
- const { value } = defaultValue;
3593
- if (!isDefaultValueBlacklisted(value)) {
3594
- if (isReactDocgenTypescript(defaultValue) && isStringValued(type)) {
3595
- return createSummaryValue(JSON.stringify(value));
3596
- }
3597
- return createSummaryValue(value);
3598
- }
3599
- }
3600
- return null;
3601
- }
3602
- __name(createDefaultValue3, "createDefaultValue");
3603
- function createBasicPropDef(name, type, docgenInfo) {
3604
- const { description, required, defaultValue } = docgenInfo;
3605
- return {
3606
- name,
3607
- type: createType3(type),
3608
- required,
3609
- description,
3610
- defaultValue: createDefaultValue3(defaultValue, type)
3611
- };
3612
- }
3613
- __name(createBasicPropDef, "createBasicPropDef");
3614
- function applyJsDocResult(propDef, jsDocParsingResult) {
3615
- if (jsDocParsingResult?.includesJsDoc) {
3616
- const { description, extractedTags } = jsDocParsingResult;
3617
- if (description != null) {
3618
- propDef.description = jsDocParsingResult.description;
3619
- }
3620
- const value = {
3621
- ...extractedTags,
3622
- params: extractedTags?.params?.map(
3623
- (x) => ({
3624
- name: x.getPrettyName(),
3625
- description: x.description
3626
- })
3627
- )
3628
- };
3629
- if (Object.values(value).filter(Boolean).length > 0) {
3630
- propDef.jsDocTags = value;
3631
- }
3632
- }
3633
- return propDef;
3634
- }
3635
- __name(applyJsDocResult, "applyJsDocResult");
3636
- var javaScriptFactory = /* @__PURE__ */ __name((propName, docgenInfo, jsDocParsingResult) => {
3637
- const propDef = createBasicPropDef(propName, docgenInfo.type, docgenInfo);
3638
- propDef.sbType = convert4(docgenInfo);
3639
- return applyJsDocResult(propDef, jsDocParsingResult);
3640
- }, "javaScriptFactory");
3641
- var tsFactory = /* @__PURE__ */ __name((propName, docgenInfo, jsDocParsingResult) => {
3642
- const propDef = createTsPropDef(propName, docgenInfo);
3643
- propDef.sbType = convert4(docgenInfo);
3644
- return applyJsDocResult(propDef, jsDocParsingResult);
3645
- }, "tsFactory");
3646
- var flowFactory = /* @__PURE__ */ __name((propName, docgenInfo, jsDocParsingResult) => {
3647
- const propDef = createFlowPropDef(propName, docgenInfo);
3648
- propDef.sbType = convert4(docgenInfo);
3649
- return applyJsDocResult(propDef, jsDocParsingResult);
3650
- }, "flowFactory");
3651
- var unknownFactory = /* @__PURE__ */ __name((propName, docgenInfo, jsDocParsingResult) => {
3652
- const propDef = createBasicPropDef(propName, { name: "unknown" }, docgenInfo);
3653
- return applyJsDocResult(propDef, jsDocParsingResult);
3654
- }, "unknownFactory");
3655
- var getPropDefFactory = /* @__PURE__ */ __name((typeSystem) => {
3656
- switch (typeSystem) {
3657
- case "JavaScript" /* JAVASCRIPT */:
3658
- return javaScriptFactory;
3659
- case "TypeScript" /* TYPESCRIPT */:
3660
- return tsFactory;
3661
- case "Flow" /* FLOW */:
3662
- return flowFactory;
3663
- default:
3664
- return unknownFactory;
3665
- }
3666
- }, "getPropDefFactory");
3667
-
3668
- // src/docs-tools/argTypes/docgen/extractDocgenProps.ts
3669
- var getTypeSystem = /* @__PURE__ */ __name((docgenInfo) => {
3670
- if (docgenInfo.type != null) {
3671
- return "JavaScript" /* JAVASCRIPT */;
3672
- }
3673
- if (docgenInfo.flowType != null) {
3674
- return "Flow" /* FLOW */;
3675
- }
3676
- if (docgenInfo.tsType != null) {
3677
- return "TypeScript" /* TYPESCRIPT */;
3678
- }
3679
- return "Unknown" /* UNKNOWN */;
3680
- }, "getTypeSystem");
3681
- var extractComponentSectionArray = /* @__PURE__ */ __name((docgenSection) => {
3682
- const typeSystem = getTypeSystem(docgenSection[0]);
3683
- const createPropDef = getPropDefFactory(typeSystem);
3684
- return docgenSection.map((item) => {
3685
- let sanitizedItem = item;
3686
- if (item.type?.elements) {
3687
- sanitizedItem = {
3688
- ...item,
3689
- type: {
3690
- ...item.type,
3691
- value: item.type.elements
3692
- }
3693
- };
3694
- }
3695
- return extractProp(sanitizedItem.name, sanitizedItem, typeSystem, createPropDef);
3696
- });
3697
- }, "extractComponentSectionArray");
3698
- var extractComponentSectionObject = /* @__PURE__ */ __name((docgenSection) => {
3699
- const docgenPropsKeys = Object.keys(docgenSection);
3700
- const typeSystem = getTypeSystem(docgenSection[docgenPropsKeys[0]]);
3701
- const createPropDef = getPropDefFactory(typeSystem);
3702
- return docgenPropsKeys.map((propName) => {
3703
- const docgenInfo = docgenSection[propName];
3704
- return docgenInfo != null ? extractProp(propName, docgenInfo, typeSystem, createPropDef) : null;
3705
- }).filter(Boolean);
3706
- }, "extractComponentSectionObject");
3707
- var extractComponentProps = /* @__PURE__ */ __name((component, section) => {
3708
- const docgenSection = getDocgenSection(component, section);
3709
- if (!isValidDocgenSection(docgenSection)) {
3710
- return [];
3711
- }
3712
- return Array.isArray(docgenSection) ? extractComponentSectionArray(docgenSection) : extractComponentSectionObject(docgenSection);
3713
- }, "extractComponentProps");
3714
- function extractProp(propName, docgenInfo, typeSystem, createPropDef) {
3715
- const jsDocParsingResult = parseJsDoc(docgenInfo.description);
3716
- const isIgnored = jsDocParsingResult.includesJsDoc && jsDocParsingResult.ignore;
3717
- if (!isIgnored) {
3718
- const propDef = createPropDef(propName, docgenInfo, jsDocParsingResult);
3719
- return {
3720
- propDef,
3721
- jsDocTags: jsDocParsingResult.extractedTags,
3722
- docgenInfo,
3723
- typeSystem
3724
- };
3725
- }
3726
- return null;
3727
- }
3728
- __name(extractProp, "extractProp");
3729
- function extractComponentDescription(component) {
3730
- return component != null ? getDocgenDescription(component) : "";
3731
- }
3732
- __name(extractComponentDescription, "extractComponentDescription");
3733
-
3734
- // src/preview-api/modules/store/parameters.ts
3735
- var combineParameters = /* @__PURE__ */ __name((...parameterSets) => {
3736
- const mergeKeys = {};
3737
- const definedParametersSets = parameterSets.filter(Boolean);
3738
- const combined = definedParametersSets.reduce((acc, parameters) => {
3739
- Object.entries(parameters).forEach(([key, value]) => {
3740
- const existing = acc[key];
3741
- if (Array.isArray(value) || typeof existing === "undefined") {
3742
- acc[key] = value;
3743
- } else if (isPlainObject(value) && isPlainObject(existing)) {
3744
- mergeKeys[key] = true;
3745
- } else if (typeof value !== "undefined") {
3746
- acc[key] = value;
3747
- }
3748
- });
3749
- return acc;
3750
- }, {});
3751
- Object.keys(mergeKeys).forEach((key) => {
3752
- const mergeValues = definedParametersSets.filter(Boolean).map((p) => p[key]).filter((value) => typeof value !== "undefined");
3753
- if (mergeValues.every((value) => isPlainObject(value))) {
3754
- combined[key] = combineParameters(...mergeValues);
3755
- } else {
3756
- combined[key] = mergeValues[mergeValues.length - 1];
3757
- }
3758
- });
3759
- return combined;
3760
- }, "combineParameters");
3761
-
3762
- // src/docs-tools/argTypes/enhanceArgTypes.ts
3763
- var enhanceArgTypes = /* @__PURE__ */ __name((context) => {
3764
- const {
3765
- component,
3766
- argTypes: userArgTypes,
3767
- parameters: { docs = {} }
3768
- } = context;
3769
- const { extractArgTypes } = docs;
3770
- if (!extractArgTypes || !component) {
3771
- return userArgTypes;
3772
- }
3773
- const extractedArgTypes = extractArgTypes(component);
3774
- return extractedArgTypes ? combineParameters(extractedArgTypes, userArgTypes) : userArgTypes;
3775
- }, "enhanceArgTypes");
3776
-
3777
- // src/docs-tools/shared.ts
3778
- var ADDON_ID = "storybook/docs";
3779
- var PANEL_ID = `${ADDON_ID}/panel`;
3780
- var PARAM_KEY = `docs`;
3781
- var SNIPPET_RENDERED = `${ADDON_ID}/snippet-rendered`;
3782
- var SourceType = /* @__PURE__ */ ((SourceType2) => {
3783
- SourceType2["AUTO"] = "auto";
3784
- SourceType2["CODE"] = "code";
3785
- SourceType2["DYNAMIC"] = "dynamic";
3786
- return SourceType2;
3787
- })(SourceType || {});
3788
-
3789
- export {
3790
- combineParameters,
3791
- convert4 as convert,
3792
- TypeSystem,
3793
- isDefaultValueBlacklisted,
3794
- str,
3795
- hasDocgen,
3796
- isValidDocgenSection,
3797
- getDocgenSection,
3798
- getDocgenDescription,
3799
- parseJsDoc,
3800
- MAX_TYPE_SUMMARY_LENGTH,
3801
- MAX_DEFAULT_VALUE_SUMMARY_LENGTH,
3802
- isTooLongForTypeSummary,
3803
- isTooLongForDefaultValueSummary,
3804
- createSummaryValue,
3805
- normalizeNewlines,
3806
- extractComponentSectionArray,
3807
- extractComponentSectionObject,
3808
- extractComponentProps,
3809
- extractComponentDescription,
3810
- enhanceArgTypes,
3811
- ADDON_ID,
3812
- PANEL_ID,
3813
- PARAM_KEY,
3814
- SNIPPET_RENDERED,
3815
- SourceType
3816
- };