index.js 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205
  1. var __accessCheck = (obj, member, msg) => {
  2. if (!member.has(obj))
  3. throw TypeError("Cannot " + msg);
  4. };
  5. var __privateGet = (obj, member, getter) => {
  6. __accessCheck(obj, member, "read from private field");
  7. return getter ? getter.call(obj) : member.get(obj);
  8. };
  9. var __privateAdd = (obj, member, value) => {
  10. if (member.has(obj))
  11. throw TypeError("Cannot add the same private member more than once");
  12. member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
  13. };
  14. var __privateSet = (obj, member, value, setter) => {
  15. __accessCheck(obj, member, "write to private field");
  16. setter ? setter.call(obj, value) : member.set(obj, value);
  17. return value;
  18. };
  19. var __privateMethod = (obj, member, method) => {
  20. __accessCheck(obj, member, "access private method");
  21. return method;
  22. };
  23. // src/comments.ts
  24. import ts2 from "typescript";
  25. // src/tokens.ts
  26. import ts from "typescript";
  27. function forEachToken(node, callback, sourceFile = node.getSourceFile()) {
  28. const queue = [];
  29. while (true) {
  30. if (ts.isTokenKind(node.kind)) {
  31. callback(node);
  32. } else if (
  33. // eslint-disable-next-line deprecation/deprecation -- need for support of TS < 4.7
  34. node.kind !== ts.SyntaxKind.JSDocComment
  35. ) {
  36. const children = node.getChildren(sourceFile);
  37. if (children.length === 1) {
  38. node = children[0];
  39. continue;
  40. }
  41. for (let i = children.length - 1; i >= 0; --i) {
  42. queue.push(children[i]);
  43. }
  44. }
  45. if (queue.length === 0) {
  46. break;
  47. }
  48. node = queue.pop();
  49. }
  50. }
  51. // src/comments.ts
  52. function canHaveTrailingTrivia(token) {
  53. switch (token.kind) {
  54. case ts2.SyntaxKind.CloseBraceToken:
  55. return token.parent.kind !== ts2.SyntaxKind.JsxExpression || !isJsxElementOrFragment(token.parent.parent);
  56. case ts2.SyntaxKind.GreaterThanToken:
  57. switch (token.parent.kind) {
  58. case ts2.SyntaxKind.JsxOpeningElement:
  59. return token.end !== token.parent.end;
  60. case ts2.SyntaxKind.JsxOpeningFragment:
  61. return false;
  62. case ts2.SyntaxKind.JsxSelfClosingElement:
  63. return token.end !== token.parent.end || // if end is not equal, this is part of the type arguments list
  64. !isJsxElementOrFragment(token.parent.parent);
  65. case ts2.SyntaxKind.JsxClosingElement:
  66. case ts2.SyntaxKind.JsxClosingFragment:
  67. return !isJsxElementOrFragment(token.parent.parent.parent);
  68. }
  69. }
  70. return true;
  71. }
  72. function isJsxElementOrFragment(node) {
  73. return node.kind === ts2.SyntaxKind.JsxElement || node.kind === ts2.SyntaxKind.JsxFragment;
  74. }
  75. function forEachComment(node, callback, sourceFile = node.getSourceFile()) {
  76. const fullText = sourceFile.text;
  77. const notJsx = sourceFile.languageVariant !== ts2.LanguageVariant.JSX;
  78. return forEachToken(
  79. node,
  80. (token) => {
  81. if (token.pos === token.end) {
  82. return;
  83. }
  84. if (token.kind !== ts2.SyntaxKind.JsxText) {
  85. ts2.forEachLeadingCommentRange(
  86. fullText,
  87. // skip shebang at position 0
  88. token.pos === 0 ? (ts2.getShebang(fullText) ?? "").length : token.pos,
  89. commentCallback
  90. );
  91. }
  92. if (notJsx || canHaveTrailingTrivia(token)) {
  93. return ts2.forEachTrailingCommentRange(
  94. fullText,
  95. token.end,
  96. commentCallback
  97. );
  98. }
  99. },
  100. sourceFile
  101. );
  102. function commentCallback(pos, end, kind) {
  103. callback(fullText, { end, kind, pos });
  104. }
  105. }
  106. // src/compilerOptions.ts
  107. import ts3 from "typescript";
  108. function isCompilerOptionEnabled(options, option) {
  109. switch (option) {
  110. case "stripInternal":
  111. case "declarationMap":
  112. case "emitDeclarationOnly":
  113. return options[option] === true && isCompilerOptionEnabled(options, "declaration");
  114. case "declaration":
  115. return options.declaration || isCompilerOptionEnabled(options, "composite");
  116. case "incremental":
  117. return options.incremental === void 0 ? isCompilerOptionEnabled(options, "composite") : options.incremental;
  118. case "skipDefaultLibCheck":
  119. return options.skipDefaultLibCheck || isCompilerOptionEnabled(options, "skipLibCheck");
  120. case "suppressImplicitAnyIndexErrors":
  121. return options.suppressImplicitAnyIndexErrors === true && isCompilerOptionEnabled(options, "noImplicitAny");
  122. case "allowSyntheticDefaultImports":
  123. return options.allowSyntheticDefaultImports !== void 0 ? options.allowSyntheticDefaultImports : isCompilerOptionEnabled(options, "esModuleInterop") || options.module === ts3.ModuleKind.System;
  124. case "noUncheckedIndexedAccess":
  125. return options.noUncheckedIndexedAccess === true && isCompilerOptionEnabled(options, "strictNullChecks");
  126. case "allowJs":
  127. return options.allowJs === void 0 ? isCompilerOptionEnabled(options, "checkJs") : options.allowJs;
  128. case "noImplicitAny":
  129. case "noImplicitThis":
  130. case "strictNullChecks":
  131. case "strictFunctionTypes":
  132. case "strictPropertyInitialization":
  133. case "alwaysStrict":
  134. case "strictBindCallApply":
  135. return isStrictCompilerOptionEnabled(
  136. options,
  137. option
  138. );
  139. }
  140. return options[option] === true;
  141. }
  142. function isStrictCompilerOptionEnabled(options, option) {
  143. return (options.strict ? options[option] !== false : options[option] === true) && (option !== "strictPropertyInitialization" || isStrictCompilerOptionEnabled(options, "strictNullChecks"));
  144. }
  145. // src/flags.ts
  146. import ts4 from "typescript";
  147. function isFlagSet(allFlags, flag) {
  148. return (allFlags & flag) !== 0;
  149. }
  150. function isFlagSetOnObject(obj, flag) {
  151. return isFlagSet(obj.flags, flag);
  152. }
  153. function isModifierFlagSet(node, flag) {
  154. return isFlagSet(ts4.getCombinedModifierFlags(node), flag);
  155. }
  156. var isNodeFlagSet = isFlagSetOnObject;
  157. function isObjectFlagSet(objectType, flag) {
  158. return isFlagSet(objectType.objectFlags, flag);
  159. }
  160. var isSymbolFlagSet = isFlagSetOnObject;
  161. var isTypeFlagSet = isFlagSetOnObject;
  162. // src/modifiers.ts
  163. function includesModifier(modifiers, ...kinds) {
  164. if (modifiers === void 0) {
  165. return false;
  166. }
  167. for (const modifier of modifiers) {
  168. if (kinds.includes(modifier.kind)) {
  169. return true;
  170. }
  171. }
  172. return false;
  173. }
  174. // src/nodes/typeGuards/compound.ts
  175. import ts8 from "typescript";
  176. // src/nodes/typeGuards/single.ts
  177. import ts5 from "typescript";
  178. function isAbstractKeyword(node) {
  179. return node.kind === ts5.SyntaxKind.AbstractKeyword;
  180. }
  181. function isAccessorKeyword(node) {
  182. return node.kind === ts5.SyntaxKind.AccessorKeyword;
  183. }
  184. function isAnyKeyword(node) {
  185. return node.kind === ts5.SyntaxKind.AnyKeyword;
  186. }
  187. function isAssertKeyword(node) {
  188. return node.kind === ts5.SyntaxKind.AssertKeyword;
  189. }
  190. function isAssertsKeyword(node) {
  191. return node.kind === ts5.SyntaxKind.AssertsKeyword;
  192. }
  193. function isAsyncKeyword(node) {
  194. return node.kind === ts5.SyntaxKind.AsyncKeyword;
  195. }
  196. function isAwaitKeyword(node) {
  197. return node.kind === ts5.SyntaxKind.AwaitKeyword;
  198. }
  199. function isBigIntKeyword(node) {
  200. return node.kind === ts5.SyntaxKind.BigIntKeyword;
  201. }
  202. function isBooleanKeyword(node) {
  203. return node.kind === ts5.SyntaxKind.BooleanKeyword;
  204. }
  205. function isColonToken(node) {
  206. return node.kind === ts5.SyntaxKind.ColonToken;
  207. }
  208. function isConstKeyword(node) {
  209. return node.kind === ts5.SyntaxKind.ConstKeyword;
  210. }
  211. function isDeclareKeyword(node) {
  212. return node.kind === ts5.SyntaxKind.DeclareKeyword;
  213. }
  214. function isDefaultKeyword(node) {
  215. return node.kind === ts5.SyntaxKind.DefaultKeyword;
  216. }
  217. function isDotToken(node) {
  218. return node.kind === ts5.SyntaxKind.DotToken;
  219. }
  220. function isEndOfFileToken(node) {
  221. return node.kind === ts5.SyntaxKind.EndOfFileToken;
  222. }
  223. function isEqualsGreaterThanToken(node) {
  224. return node.kind === ts5.SyntaxKind.EqualsGreaterThanToken;
  225. }
  226. function isEqualsToken(node) {
  227. return node.kind === ts5.SyntaxKind.EqualsToken;
  228. }
  229. function isExclamationToken(node) {
  230. return node.kind === ts5.SyntaxKind.ExclamationToken;
  231. }
  232. function isExportKeyword(node) {
  233. return node.kind === ts5.SyntaxKind.ExportKeyword;
  234. }
  235. function isFalseKeyword(node) {
  236. return node.kind === ts5.SyntaxKind.FalseKeyword;
  237. }
  238. function isFalseLiteral(node) {
  239. return node.kind === ts5.SyntaxKind.FalseKeyword;
  240. }
  241. function isImportExpression(node) {
  242. return node.kind === ts5.SyntaxKind.ImportKeyword;
  243. }
  244. function isImportKeyword(node) {
  245. return node.kind === ts5.SyntaxKind.ImportKeyword;
  246. }
  247. function isInKeyword(node) {
  248. return node.kind === ts5.SyntaxKind.InKeyword;
  249. }
  250. function isInputFiles(node) {
  251. return node.kind === ts5.SyntaxKind.InputFiles;
  252. }
  253. function isJSDocText(node) {
  254. return node.kind === ts5.SyntaxKind.JSDocText;
  255. }
  256. function isJsonMinusNumericLiteral(node) {
  257. return node.kind === ts5.SyntaxKind.PrefixUnaryExpression;
  258. }
  259. function isNeverKeyword(node) {
  260. return node.kind === ts5.SyntaxKind.NeverKeyword;
  261. }
  262. function isNullKeyword(node) {
  263. return node.kind === ts5.SyntaxKind.NullKeyword;
  264. }
  265. function isNullLiteral(node) {
  266. return node.kind === ts5.SyntaxKind.NullKeyword;
  267. }
  268. function isNumberKeyword(node) {
  269. return node.kind === ts5.SyntaxKind.NumberKeyword;
  270. }
  271. function isObjectKeyword(node) {
  272. return node.kind === ts5.SyntaxKind.ObjectKeyword;
  273. }
  274. function isOutKeyword(node) {
  275. return node.kind === ts5.SyntaxKind.OutKeyword;
  276. }
  277. function isOverrideKeyword(node) {
  278. return node.kind === ts5.SyntaxKind.OverrideKeyword;
  279. }
  280. function isPrivateKeyword(node) {
  281. return node.kind === ts5.SyntaxKind.PrivateKeyword;
  282. }
  283. function isProtectedKeyword(node) {
  284. return node.kind === ts5.SyntaxKind.ProtectedKeyword;
  285. }
  286. function isPublicKeyword(node) {
  287. return node.kind === ts5.SyntaxKind.PublicKeyword;
  288. }
  289. function isQuestionDotToken(node) {
  290. return node.kind === ts5.SyntaxKind.QuestionDotToken;
  291. }
  292. function isQuestionToken(node) {
  293. return node.kind === ts5.SyntaxKind.QuestionToken;
  294. }
  295. function isReadonlyKeyword(node) {
  296. return node.kind === ts5.SyntaxKind.ReadonlyKeyword;
  297. }
  298. function isStaticKeyword(node) {
  299. return node.kind === ts5.SyntaxKind.StaticKeyword;
  300. }
  301. function isStringKeyword(node) {
  302. return node.kind === ts5.SyntaxKind.StringKeyword;
  303. }
  304. function isSuperExpression(node) {
  305. return node.kind === ts5.SyntaxKind.SuperKeyword;
  306. }
  307. function isSuperKeyword(node) {
  308. return node.kind === ts5.SyntaxKind.SuperKeyword;
  309. }
  310. function isSymbolKeyword(node) {
  311. return node.kind === ts5.SyntaxKind.SymbolKeyword;
  312. }
  313. function isSyntaxList(node) {
  314. return node.kind === ts5.SyntaxKind.SyntaxList;
  315. }
  316. function isThisExpression(node) {
  317. return node.kind === ts5.SyntaxKind.ThisKeyword;
  318. }
  319. function isThisKeyword(node) {
  320. return node.kind === ts5.SyntaxKind.ThisKeyword;
  321. }
  322. function isTrueKeyword(node) {
  323. return node.kind === ts5.SyntaxKind.TrueKeyword;
  324. }
  325. function isTrueLiteral(node) {
  326. return node.kind === ts5.SyntaxKind.TrueKeyword;
  327. }
  328. function isUndefinedKeyword(node) {
  329. return node.kind === ts5.SyntaxKind.UndefinedKeyword;
  330. }
  331. function isUnknownKeyword(node) {
  332. return node.kind === ts5.SyntaxKind.UnknownKeyword;
  333. }
  334. function isUnparsedPrologue(node) {
  335. return node.kind === ts5.SyntaxKind.UnparsedPrologue;
  336. }
  337. function isUnparsedSyntheticReference(node) {
  338. return node.kind === ts5.SyntaxKind.UnparsedSyntheticReference;
  339. }
  340. function isVoidKeyword(node) {
  341. return node.kind === ts5.SyntaxKind.VoidKeyword;
  342. }
  343. // src/nodes/typeGuards/union.ts
  344. import ts7 from "typescript";
  345. // src/utils.ts
  346. import ts6 from "typescript";
  347. var [tsMajor, tsMinor] = ts6.versionMajorMinor.split(".").map((raw) => Number.parseInt(raw, 10));
  348. function isTsVersionAtLeast(major, minor = 0) {
  349. return tsMajor > major || tsMajor === major && tsMinor >= minor;
  350. }
  351. // src/nodes/typeGuards/union.ts
  352. function isAccessExpression(node) {
  353. return ts7.isPropertyAccessExpression(node) || ts7.isElementAccessExpression(node);
  354. }
  355. function isAccessibilityModifier(node) {
  356. return isPublicKeyword(node) || isPrivateKeyword(node) || isProtectedKeyword(node);
  357. }
  358. function isAccessorDeclaration(node) {
  359. return ts7.isGetAccessorDeclaration(node) || ts7.isSetAccessorDeclaration(node);
  360. }
  361. function isArrayBindingElement(node) {
  362. return ts7.isBindingElement(node) || ts7.isOmittedExpression(node);
  363. }
  364. function isArrayBindingOrAssignmentPattern(node) {
  365. return ts7.isArrayBindingPattern(node) || ts7.isArrayLiteralExpression(node);
  366. }
  367. function isAssignmentPattern(node) {
  368. return ts7.isObjectLiteralExpression(node) || ts7.isArrayLiteralExpression(node);
  369. }
  370. function isBindingOrAssignmentElementRestIndicator(node) {
  371. if (ts7.isSpreadElement(node) || ts7.isSpreadAssignment(node)) {
  372. return true;
  373. }
  374. if (isTsVersionAtLeast(4, 4)) {
  375. return ts7.isDotDotDotToken(node);
  376. }
  377. return false;
  378. }
  379. function isBindingOrAssignmentElementTarget(node) {
  380. return isBindingOrAssignmentPattern(node) || ts7.isIdentifier(node) || ts7.isPropertyAccessExpression(node) || ts7.isElementAccessExpression(node) || ts7.isOmittedExpression(node);
  381. }
  382. function isBindingOrAssignmentPattern(node) {
  383. return isObjectBindingOrAssignmentPattern(node) || isArrayBindingOrAssignmentPattern(node);
  384. }
  385. function isBindingPattern(node) {
  386. return ts7.isObjectBindingPattern(node) || ts7.isArrayBindingPattern(node);
  387. }
  388. function isBlockLike(node) {
  389. return ts7.isSourceFile(node) || ts7.isBlock(node) || ts7.isModuleBlock(node) || ts7.isCaseOrDefaultClause(node);
  390. }
  391. function isBooleanLiteral(node) {
  392. return isTrueLiteral(node) || isFalseLiteral(node);
  393. }
  394. function isClassLikeDeclaration(node) {
  395. return ts7.isClassDeclaration(node) || ts7.isClassExpression(node);
  396. }
  397. function isClassMemberModifier(node) {
  398. return isAccessibilityModifier(node) || isReadonlyKeyword(node) || isStaticKeyword(node) || isAccessorKeyword(node);
  399. }
  400. function isDeclarationName(node) {
  401. return ts7.isIdentifier(node) || ts7.isPrivateIdentifier(node) || ts7.isStringLiteralLike(node) || ts7.isNumericLiteral(node) || ts7.isComputedPropertyName(node) || ts7.isElementAccessExpression(node) || isBindingPattern(node) || isEntityNameExpression(node);
  402. }
  403. function isDeclarationWithTypeParameterChildren(node) {
  404. return isSignatureDeclaration(node) || // eslint-disable-next-line deprecation/deprecation -- Keep compatibility with ts <5
  405. isClassLikeDeclaration(node) || ts7.isInterfaceDeclaration(node) || ts7.isTypeAliasDeclaration(node) || ts7.isJSDocTemplateTag(node);
  406. }
  407. function isDeclarationWithTypeParameters(node) {
  408. return isDeclarationWithTypeParameterChildren(node) || ts7.isJSDocTypedefTag(node) || ts7.isJSDocCallbackTag(node) || ts7.isJSDocSignature(node);
  409. }
  410. function isDestructuringPattern(node) {
  411. return isBindingPattern(node) || ts7.isObjectLiteralExpression(node) || ts7.isArrayLiteralExpression(node);
  412. }
  413. function isEntityNameExpression(node) {
  414. return ts7.isIdentifier(node) || isPropertyAccessEntityNameExpression(node);
  415. }
  416. function isEntityNameOrEntityNameExpression(node) {
  417. return ts7.isEntityName(node) || isEntityNameExpression(node);
  418. }
  419. function isForInOrOfStatement(node) {
  420. return ts7.isForInStatement(node) || ts7.isForOfStatement(node);
  421. }
  422. function isFunctionLikeDeclaration(node) {
  423. return ts7.isFunctionDeclaration(node) || ts7.isMethodDeclaration(node) || ts7.isGetAccessorDeclaration(node) || ts7.isSetAccessorDeclaration(node) || ts7.isConstructorDeclaration(node) || ts7.isFunctionExpression(node) || ts7.isArrowFunction(node);
  424. }
  425. function hasDecorators(node) {
  426. return ts7.isParameter(node) || ts7.isPropertyDeclaration(node) || ts7.isMethodDeclaration(node) || ts7.isGetAccessorDeclaration(node) || ts7.isSetAccessorDeclaration(node) || ts7.isClassExpression(node) || ts7.isClassDeclaration(node);
  427. }
  428. function hasExpressionInitializer(node) {
  429. return ts7.isVariableDeclaration(node) || ts7.isParameter(node) || ts7.isBindingElement(node) || ts7.isPropertyDeclaration(node) || ts7.isPropertyAssignment(node) || ts7.isEnumMember(node);
  430. }
  431. function hasInitializer(node) {
  432. return hasExpressionInitializer(node) || ts7.isForStatement(node) || ts7.isForInStatement(node) || ts7.isForOfStatement(node) || ts7.isJsxAttribute(node);
  433. }
  434. function hasJSDoc(node) {
  435. if (
  436. // eslint-disable-next-line deprecation/deprecation -- Keep compatibility with ts <5
  437. isAccessorDeclaration(node) || ts7.isArrowFunction(node) || ts7.isBlock(node) || ts7.isBreakStatement(node) || ts7.isCallSignatureDeclaration(node) || ts7.isCaseClause(node) || // eslint-disable-next-line deprecation/deprecation -- Keep compatibility with ts <5
  438. isClassLikeDeclaration(node) || ts7.isConstructorDeclaration(node) || ts7.isConstructorTypeNode(node) || ts7.isConstructSignatureDeclaration(node) || ts7.isContinueStatement(node) || ts7.isDebuggerStatement(node) || ts7.isDoStatement(node) || ts7.isEmptyStatement(node) || isEndOfFileToken(node) || ts7.isEnumDeclaration(node) || ts7.isEnumMember(node) || ts7.isExportAssignment(node) || ts7.isExportDeclaration(node) || ts7.isExportSpecifier(node) || ts7.isExpressionStatement(node) || ts7.isForInStatement(node) || ts7.isForOfStatement(node) || ts7.isForStatement(node) || ts7.isFunctionDeclaration(node) || ts7.isFunctionExpression(node) || ts7.isFunctionTypeNode(node) || ts7.isIfStatement(node) || ts7.isImportDeclaration(node) || ts7.isImportEqualsDeclaration(node) || ts7.isIndexSignatureDeclaration(node) || ts7.isInterfaceDeclaration(node) || ts7.isJSDocFunctionType(node) || ts7.isLabeledStatement(node) || ts7.isMethodDeclaration(node) || ts7.isMethodSignature(node) || ts7.isModuleDeclaration(node) || ts7.isNamedTupleMember(node) || ts7.isNamespaceExportDeclaration(node) || ts7.isParameter(node) || ts7.isParenthesizedExpression(node) || ts7.isPropertyAssignment(node) || ts7.isPropertyDeclaration(node) || ts7.isPropertySignature(node) || ts7.isReturnStatement(node) || ts7.isShorthandPropertyAssignment(node) || ts7.isSpreadAssignment(node) || ts7.isSwitchStatement(node) || ts7.isThrowStatement(node) || ts7.isTryStatement(node) || ts7.isTypeAliasDeclaration(node) || ts7.isVariableDeclaration(node) || ts7.isVariableStatement(node) || ts7.isWhileStatement(node) || ts7.isWithStatement(node)
  439. ) {
  440. return true;
  441. }
  442. if (isTsVersionAtLeast(4, 4) && ts7.isClassStaticBlockDeclaration(node)) {
  443. return true;
  444. }
  445. if (isTsVersionAtLeast(5, 0) && (ts7.isBinaryExpression(node) || ts7.isElementAccessExpression(node) || ts7.isIdentifier(node) || ts7.isJSDocSignature(node) || ts7.isObjectLiteralExpression(node) || ts7.isPropertyAccessExpression(node) || ts7.isTypeParameterDeclaration(node))) {
  446. return true;
  447. }
  448. return false;
  449. }
  450. function hasModifiers(node) {
  451. return ts7.isTypeParameterDeclaration(node) || ts7.isParameter(node) || ts7.isConstructorTypeNode(node) || ts7.isPropertySignature(node) || ts7.isPropertyDeclaration(node) || ts7.isMethodSignature(node) || ts7.isMethodDeclaration(node) || ts7.isConstructorDeclaration(node) || ts7.isGetAccessorDeclaration(node) || ts7.isSetAccessorDeclaration(node) || ts7.isIndexSignatureDeclaration(node) || ts7.isFunctionExpression(node) || ts7.isArrowFunction(node) || ts7.isClassExpression(node) || ts7.isVariableStatement(node) || ts7.isFunctionDeclaration(node) || ts7.isClassDeclaration(node) || ts7.isInterfaceDeclaration(node) || ts7.isTypeAliasDeclaration(node) || ts7.isEnumDeclaration(node) || ts7.isModuleDeclaration(node) || ts7.isImportEqualsDeclaration(node) || ts7.isImportDeclaration(node) || ts7.isExportAssignment(node) || ts7.isExportDeclaration(node);
  452. }
  453. function hasType(node) {
  454. return isSignatureDeclaration(node) || ts7.isVariableDeclaration(node) || ts7.isParameter(node) || ts7.isPropertySignature(node) || ts7.isPropertyDeclaration(node) || ts7.isTypePredicateNode(node) || ts7.isParenthesizedTypeNode(node) || ts7.isTypeOperatorNode(node) || ts7.isMappedTypeNode(node) || ts7.isAssertionExpression(node) || ts7.isTypeAliasDeclaration(node) || ts7.isJSDocTypeExpression(node) || ts7.isJSDocNonNullableType(node) || ts7.isJSDocNullableType(node) || ts7.isJSDocOptionalType(node) || ts7.isJSDocVariadicType(node);
  455. }
  456. function hasTypeArguments(node) {
  457. return ts7.isCallExpression(node) || ts7.isNewExpression(node) || ts7.isTaggedTemplateExpression(node) || ts7.isJsxOpeningElement(node) || ts7.isJsxSelfClosingElement(node);
  458. }
  459. function isJSDocComment(node) {
  460. if (isJSDocText(node)) {
  461. return true;
  462. }
  463. if (isTsVersionAtLeast(4, 4)) {
  464. return ts7.isJSDocLink(node) || ts7.isJSDocLinkCode(node) || ts7.isJSDocLinkPlain(node);
  465. }
  466. return false;
  467. }
  468. function isJSDocNamespaceBody(node) {
  469. return ts7.isIdentifier(node) || isJSDocNamespaceDeclaration(node);
  470. }
  471. function isJSDocTypeReferencingNode(node) {
  472. return ts7.isJSDocVariadicType(node) || ts7.isJSDocOptionalType(node) || ts7.isJSDocNullableType(node) || ts7.isJSDocNonNullableType(node);
  473. }
  474. function isJsonObjectExpression(node) {
  475. return ts7.isObjectLiteralExpression(node) || ts7.isArrayLiteralExpression(node) || isJsonMinusNumericLiteral(node) || ts7.isNumericLiteral(node) || ts7.isStringLiteral(node) || isBooleanLiteral(node) || isNullLiteral(node);
  476. }
  477. function isJsxAttributeLike(node) {
  478. return ts7.isJsxAttribute(node) || ts7.isJsxSpreadAttribute(node);
  479. }
  480. function isJsxAttributeValue(node) {
  481. return ts7.isStringLiteral(node) || ts7.isJsxExpression(node) || ts7.isJsxElement(node) || ts7.isJsxSelfClosingElement(node) || ts7.isJsxFragment(node);
  482. }
  483. function isJsxChild(node) {
  484. return ts7.isJsxText(node) || ts7.isJsxExpression(node) || ts7.isJsxElement(node) || ts7.isJsxSelfClosingElement(node) || ts7.isJsxFragment(node);
  485. }
  486. function isJsxTagNameExpression(node) {
  487. return ts7.isIdentifier(node) || isThisExpression(node) || isJsxTagNamePropertyAccess(node);
  488. }
  489. function isLiteralToken(node) {
  490. return ts7.isNumericLiteral(node) || ts7.isBigIntLiteral(node) || ts7.isStringLiteral(node) || ts7.isJsxText(node) || ts7.isRegularExpressionLiteral(node) || ts7.isNoSubstitutionTemplateLiteral(node);
  491. }
  492. function isModuleBody(node) {
  493. return isNamespaceBody(node) || isJSDocNamespaceBody(node);
  494. }
  495. function isModuleName(node) {
  496. return ts7.isIdentifier(node) || ts7.isStringLiteral(node);
  497. }
  498. function isModuleReference(node) {
  499. return ts7.isEntityName(node) || ts7.isExternalModuleReference(node);
  500. }
  501. function isNamedImportBindings(node) {
  502. return ts7.isNamespaceImport(node) || ts7.isNamedImports(node);
  503. }
  504. function isNamedImportsOrExports(node) {
  505. return ts7.isNamedImports(node) || ts7.isNamedExports(node);
  506. }
  507. function isNamespaceBody(node) {
  508. return ts7.isModuleBlock(node) || isNamespaceDeclaration(node);
  509. }
  510. function isObjectBindingOrAssignmentElement(node) {
  511. return ts7.isBindingElement(node) || ts7.isPropertyAssignment(node) || ts7.isShorthandPropertyAssignment(node) || ts7.isSpreadAssignment(node);
  512. }
  513. function isObjectBindingOrAssignmentPattern(node) {
  514. return ts7.isObjectBindingPattern(node) || ts7.isObjectLiteralExpression(node);
  515. }
  516. function isObjectTypeDeclaration(node) {
  517. return (
  518. // eslint-disable-next-line deprecation/deprecation -- Keep compatibility with ts <5
  519. isClassLikeDeclaration(node) || ts7.isInterfaceDeclaration(node) || ts7.isTypeLiteralNode(node)
  520. );
  521. }
  522. function isParameterPropertyModifier(node) {
  523. return isAccessibilityModifier(node) || isReadonlyKeyword(node);
  524. }
  525. function isPropertyNameLiteral(node) {
  526. return ts7.isIdentifier(node) || ts7.isStringLiteralLike(node) || ts7.isNumericLiteral(node);
  527. }
  528. function isPseudoLiteralToken(node) {
  529. return ts7.isTemplateHead(node) || ts7.isTemplateMiddle(node) || ts7.isTemplateTail(node);
  530. }
  531. function isSignatureDeclaration(node) {
  532. return ts7.isCallSignatureDeclaration(node) || ts7.isConstructSignatureDeclaration(node) || ts7.isMethodSignature(node) || ts7.isIndexSignatureDeclaration(node) || ts7.isFunctionTypeNode(node) || ts7.isConstructorTypeNode(node) || ts7.isJSDocFunctionType(node) || ts7.isFunctionDeclaration(node) || ts7.isMethodDeclaration(node) || ts7.isConstructorDeclaration(node) || // eslint-disable-next-line deprecation/deprecation -- Keep compatibility with ts <5
  533. isAccessorDeclaration(node) || ts7.isFunctionExpression(node) || ts7.isArrowFunction(node);
  534. }
  535. function isSuperProperty(node) {
  536. return isSuperPropertyAccessExpression(node) || isSuperElementAccessExpression(node);
  537. }
  538. function isTypeOnlyCompatibleAliasDeclaration(node) {
  539. if (ts7.isImportClause(node) || ts7.isImportEqualsDeclaration(node) || ts7.isNamespaceImport(node) || ts7.isImportOrExportSpecifier(node)) {
  540. return true;
  541. }
  542. if (isTsVersionAtLeast(5, 0) && (ts7.isExportDeclaration(node) || ts7.isNamespaceExport(node))) {
  543. return true;
  544. }
  545. return false;
  546. }
  547. function isTypeReferenceType(node) {
  548. return ts7.isTypeReferenceNode(node) || ts7.isExpressionWithTypeArguments(node);
  549. }
  550. function isUnionOrIntersectionTypeNode(node) {
  551. return ts7.isUnionTypeNode(node) || ts7.isIntersectionTypeNode(node);
  552. }
  553. function isUnparsedSourceText(node) {
  554. return ts7.isUnparsedPrepend(node) || ts7.isUnparsedTextLike(node);
  555. }
  556. function isVariableLikeDeclaration(node) {
  557. return ts7.isVariableDeclaration(node) || ts7.isParameter(node) || ts7.isBindingElement(node) || ts7.isPropertyDeclaration(node) || ts7.isPropertyAssignment(node) || ts7.isPropertySignature(node) || ts7.isJsxAttribute(node) || ts7.isShorthandPropertyAssignment(node) || ts7.isEnumMember(node) || ts7.isJSDocPropertyTag(node) || ts7.isJSDocParameterTag(node);
  558. }
  559. // src/nodes/typeGuards/compound.ts
  560. function isConstAssertionExpression(node) {
  561. return ts8.isTypeReferenceNode(node.type) && ts8.isIdentifier(node.type.typeName) && node.type.typeName.escapedText === "const";
  562. }
  563. function isIterationStatement(node) {
  564. switch (node.kind) {
  565. case ts8.SyntaxKind.DoStatement:
  566. case ts8.SyntaxKind.ForInStatement:
  567. case ts8.SyntaxKind.ForOfStatement:
  568. case ts8.SyntaxKind.ForStatement:
  569. case ts8.SyntaxKind.WhileStatement:
  570. return true;
  571. default:
  572. return false;
  573. }
  574. }
  575. function isJSDocNamespaceDeclaration(node) {
  576. return ts8.isModuleDeclaration(node) && ts8.isIdentifier(node.name) && (node.body === void 0 || isJSDocNamespaceBody(node.body));
  577. }
  578. function isJsxTagNamePropertyAccess(node) {
  579. return ts8.isPropertyAccessExpression(node) && // eslint-disable-next-line deprecation/deprecation -- Keep compatibility with ts < 5
  580. isJsxTagNameExpression(node.expression);
  581. }
  582. function isNamedDeclarationWithName(node) {
  583. return "name" in node && node.name !== void 0 && node.name !== null && isDeclarationName(node.name);
  584. }
  585. function isNamespaceDeclaration(node) {
  586. return ts8.isModuleDeclaration(node) && ts8.isIdentifier(node.name) && node.body !== void 0 && isNamespaceBody(node.body);
  587. }
  588. function isNumericOrStringLikeLiteral(node) {
  589. switch (node.kind) {
  590. case ts8.SyntaxKind.StringLiteral:
  591. case ts8.SyntaxKind.NumericLiteral:
  592. case ts8.SyntaxKind.NoSubstitutionTemplateLiteral:
  593. return true;
  594. default:
  595. return false;
  596. }
  597. }
  598. function isPropertyAccessEntityNameExpression(node) {
  599. return ts8.isPropertyAccessExpression(node) && ts8.isIdentifier(node.name) && isEntityNameExpression(node.expression);
  600. }
  601. function isSuperElementAccessExpression(node) {
  602. return ts8.isElementAccessExpression(node) && isSuperExpression(node.expression);
  603. }
  604. function isSuperPropertyAccessExpression(node) {
  605. return ts8.isPropertyAccessExpression(node) && isSuperExpression(node.expression);
  606. }
  607. // src/scopes.ts
  608. import ts9 from "typescript";
  609. function isFunctionScopeBoundary(node) {
  610. switch (node.kind) {
  611. case ts9.SyntaxKind.FunctionExpression:
  612. case ts9.SyntaxKind.ArrowFunction:
  613. case ts9.SyntaxKind.Constructor:
  614. case ts9.SyntaxKind.ModuleDeclaration:
  615. case ts9.SyntaxKind.ClassDeclaration:
  616. case ts9.SyntaxKind.ClassExpression:
  617. case ts9.SyntaxKind.EnumDeclaration:
  618. case ts9.SyntaxKind.MethodDeclaration:
  619. case ts9.SyntaxKind.FunctionDeclaration:
  620. case ts9.SyntaxKind.GetAccessor:
  621. case ts9.SyntaxKind.SetAccessor:
  622. case ts9.SyntaxKind.MethodSignature:
  623. case ts9.SyntaxKind.CallSignature:
  624. case ts9.SyntaxKind.ConstructSignature:
  625. case ts9.SyntaxKind.ConstructorType:
  626. case ts9.SyntaxKind.FunctionType:
  627. return true;
  628. case ts9.SyntaxKind.SourceFile:
  629. return ts9.isExternalModule(node);
  630. default:
  631. return false;
  632. }
  633. }
  634. // src/syntax.ts
  635. import ts10 from "typescript";
  636. function isAssignmentKind(kind) {
  637. return kind >= ts10.SyntaxKind.FirstAssignment && kind <= ts10.SyntaxKind.LastAssignment;
  638. }
  639. function isNumericPropertyName(name) {
  640. return String(+name) === name;
  641. }
  642. function charSize(ch) {
  643. return ch >= 65536 ? 2 : 1;
  644. }
  645. function isValidPropertyAccess(text, languageVersion = ts10.ScriptTarget.Latest) {
  646. if (text.length === 0) {
  647. return false;
  648. }
  649. let ch = text.codePointAt(0);
  650. if (!ts10.isIdentifierStart(ch, languageVersion)) {
  651. return false;
  652. }
  653. for (let i = charSize(ch); i < text.length; i += charSize(ch)) {
  654. ch = text.codePointAt(i);
  655. if (!ts10.isIdentifierPart(ch, languageVersion)) {
  656. return false;
  657. }
  658. }
  659. return true;
  660. }
  661. // src/types/getters.ts
  662. import ts15 from "typescript";
  663. // src/types/typeGuards/intrinsic.ts
  664. import ts11 from "typescript";
  665. function isIntrinsicAnyType(type) {
  666. return isTypeFlagSet(type, ts11.TypeFlags.Any);
  667. }
  668. function isIntrinsicBooleanType(type) {
  669. return isTypeFlagSet(type, ts11.TypeFlags.Boolean);
  670. }
  671. function isIntrinsicBigIntType(type) {
  672. return isTypeFlagSet(type, ts11.TypeFlags.BigInt);
  673. }
  674. function isIntrinsicErrorType(type) {
  675. return isIntrinsicType(type) && type.intrinsicName === "error";
  676. }
  677. function isIntrinsicESSymbolType(type) {
  678. return isTypeFlagSet(type, ts11.TypeFlags.ESSymbol);
  679. }
  680. var IntrinsicTypeFlags = ts11.TypeFlags.Intrinsic ?? ts11.TypeFlags.Any | ts11.TypeFlags.Unknown | ts11.TypeFlags.String | ts11.TypeFlags.Number | ts11.TypeFlags.BigInt | ts11.TypeFlags.Boolean | ts11.TypeFlags.BooleanLiteral | ts11.TypeFlags.ESSymbol | ts11.TypeFlags.Void | ts11.TypeFlags.Undefined | ts11.TypeFlags.Null | ts11.TypeFlags.Never | ts11.TypeFlags.NonPrimitive;
  681. function isIntrinsicType(type) {
  682. return isTypeFlagSet(type, IntrinsicTypeFlags);
  683. }
  684. function isIntrinsicNeverType(type) {
  685. return isTypeFlagSet(type, ts11.TypeFlags.Never);
  686. }
  687. function isIntrinsicNonPrimitiveType(type) {
  688. return isTypeFlagSet(type, ts11.TypeFlags.NonPrimitive);
  689. }
  690. function isIntrinsicNullType(type) {
  691. return isTypeFlagSet(type, ts11.TypeFlags.Null);
  692. }
  693. function isIntrinsicNumberType(type) {
  694. return isTypeFlagSet(type, ts11.TypeFlags.Number);
  695. }
  696. function isIntrinsicStringType(type) {
  697. return isTypeFlagSet(type, ts11.TypeFlags.String);
  698. }
  699. function isIntrinsicUndefinedType(type) {
  700. return isTypeFlagSet(type, ts11.TypeFlags.Undefined);
  701. }
  702. function isIntrinsicUnknownType(type) {
  703. return isTypeFlagSet(type, ts11.TypeFlags.Unknown);
  704. }
  705. function isIntrinsicVoidType(type) {
  706. return isTypeFlagSet(type, ts11.TypeFlags.Void);
  707. }
  708. // src/types/typeGuards/objects.ts
  709. import ts13 from "typescript";
  710. // src/types/typeGuards/single.ts
  711. import ts12 from "typescript";
  712. function isConditionalType(type) {
  713. return isTypeFlagSet(type, ts12.TypeFlags.Conditional);
  714. }
  715. function isEnumType(type) {
  716. return isTypeFlagSet(type, ts12.TypeFlags.Enum);
  717. }
  718. function isFreshableType(type) {
  719. return isTypeFlagSet(type, ts12.TypeFlags.Freshable);
  720. }
  721. function isIndexType(type) {
  722. return isTypeFlagSet(type, ts12.TypeFlags.Index);
  723. }
  724. function isIndexedAccessType(type) {
  725. return isTypeFlagSet(type, ts12.TypeFlags.IndexedAccess);
  726. }
  727. function isInstantiableType(type) {
  728. return isTypeFlagSet(type, ts12.TypeFlags.Instantiable);
  729. }
  730. function isIntersectionType(type) {
  731. return isTypeFlagSet(type, ts12.TypeFlags.Intersection);
  732. }
  733. function isObjectType(type) {
  734. return isTypeFlagSet(type, ts12.TypeFlags.Object);
  735. }
  736. function isStringMappingType(type) {
  737. return isTypeFlagSet(type, ts12.TypeFlags.StringMapping);
  738. }
  739. function isSubstitutionType(type) {
  740. return isTypeFlagSet(type, ts12.TypeFlags.Substitution);
  741. }
  742. function isTypeParameter(type) {
  743. return isTypeFlagSet(type, ts12.TypeFlags.TypeParameter);
  744. }
  745. function isTypeVariable(type) {
  746. return isTypeFlagSet(type, ts12.TypeFlags.TypeVariable);
  747. }
  748. function isUnionType(type) {
  749. return isTypeFlagSet(type, ts12.TypeFlags.Union);
  750. }
  751. function isUnionOrIntersectionType(type) {
  752. return isTypeFlagSet(type, ts12.TypeFlags.UnionOrIntersection);
  753. }
  754. function isUniqueESSymbolType(type) {
  755. return isTypeFlagSet(type, ts12.TypeFlags.UniqueESSymbol);
  756. }
  757. // src/types/typeGuards/objects.ts
  758. function isEvolvingArrayType(type) {
  759. return isObjectType(type) && isObjectFlagSet(type, ts13.ObjectFlags.EvolvingArray);
  760. }
  761. function isTupleType(type) {
  762. return isObjectType(type) && isObjectFlagSet(type, ts13.ObjectFlags.Tuple);
  763. }
  764. function isTypeReference(type) {
  765. return isObjectType(type) && isObjectFlagSet(type, ts13.ObjectFlags.Reference);
  766. }
  767. // src/types/typeGuards/compound.ts
  768. function isFreshableIntrinsicType(type) {
  769. return isIntrinsicType(type) && isFreshableType(type);
  770. }
  771. function isTupleTypeReference(type) {
  772. return isTypeReference(type) && isTupleType(type.target);
  773. }
  774. // src/types/typeGuards/literal.ts
  775. import ts14 from "typescript";
  776. function isBooleanLiteralType(type) {
  777. return isTypeFlagSet(type, ts14.TypeFlags.BooleanLiteral);
  778. }
  779. function isBigIntLiteralType(type) {
  780. return isTypeFlagSet(type, ts14.TypeFlags.BigIntLiteral);
  781. }
  782. function isFalseLiteralType(type) {
  783. return isBooleanLiteralType(type) && type.intrinsicName === "false";
  784. }
  785. function isLiteralType(type) {
  786. return isTypeFlagSet(type, ts14.TypeFlags.Literal);
  787. }
  788. function isNumberLiteralType(type) {
  789. return isTypeFlagSet(type, ts14.TypeFlags.NumberLiteral);
  790. }
  791. function isStringLiteralType(type) {
  792. return isTypeFlagSet(type, ts14.TypeFlags.StringLiteral);
  793. }
  794. function isTemplateLiteralType(type) {
  795. return isTypeFlagSet(type, ts14.TypeFlags.TemplateLiteral);
  796. }
  797. function isTrueLiteralType(type) {
  798. return isBooleanLiteralType(type) && type.intrinsicName === "true";
  799. }
  800. function isUnknownLiteralType(type) {
  801. return isTypeFlagSet(type, ts14.TypeFlags.Literal);
  802. }
  803. // src/types/getters.ts
  804. function getCallSignaturesOfType(type) {
  805. if (isUnionType(type)) {
  806. const signatures = [];
  807. for (const subType of type.types) {
  808. signatures.push(...getCallSignaturesOfType(subType));
  809. }
  810. return signatures;
  811. }
  812. if (isIntersectionType(type)) {
  813. let signatures;
  814. for (const subType of type.types) {
  815. const sig = getCallSignaturesOfType(subType);
  816. if (sig.length !== 0) {
  817. if (signatures !== void 0) {
  818. return [];
  819. }
  820. signatures = sig;
  821. }
  822. }
  823. return signatures === void 0 ? [] : signatures;
  824. }
  825. return type.getCallSignatures();
  826. }
  827. function getPropertyOfType(type, name) {
  828. if (!name.startsWith("__")) {
  829. return type.getProperty(name);
  830. }
  831. return type.getProperties().find((s) => s.escapedName === name);
  832. }
  833. function getWellKnownSymbolPropertyOfType(type, wellKnownSymbolName, typeChecker) {
  834. const prefix = "__@" + wellKnownSymbolName;
  835. for (const prop of type.getProperties()) {
  836. if (!prop.name.startsWith(prefix)) {
  837. continue;
  838. }
  839. const declaration = prop.valueDeclaration ?? prop.getDeclarations()[0];
  840. if (!isNamedDeclarationWithName(declaration) || declaration.name === void 0 || !ts15.isComputedPropertyName(declaration.name)) {
  841. continue;
  842. }
  843. const globalSymbol = typeChecker.getApparentType(
  844. typeChecker.getTypeAtLocation(declaration.name.expression)
  845. ).symbol;
  846. if (prop.escapedName === getPropertyNameOfWellKnownSymbol(
  847. typeChecker,
  848. globalSymbol,
  849. wellKnownSymbolName
  850. )) {
  851. return prop;
  852. }
  853. }
  854. return void 0;
  855. }
  856. function getPropertyNameOfWellKnownSymbol(typeChecker, symbolConstructor, symbolName) {
  857. const knownSymbol = symbolConstructor && typeChecker.getTypeOfSymbolAtLocation(
  858. symbolConstructor,
  859. // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
  860. symbolConstructor.valueDeclaration
  861. ).getProperty(symbolName);
  862. const knownSymbolType = knownSymbol && typeChecker.getTypeOfSymbolAtLocation(
  863. knownSymbol,
  864. // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
  865. knownSymbol.valueDeclaration
  866. );
  867. if (knownSymbolType && isUniqueESSymbolType(knownSymbolType)) {
  868. return knownSymbolType.escapedName;
  869. }
  870. return "__@" + symbolName;
  871. }
  872. // src/types/utilities.ts
  873. import ts17 from "typescript";
  874. // src/nodes/utilities.ts
  875. import ts16 from "typescript";
  876. function isBindableObjectDefinePropertyCall(node) {
  877. return node.arguments.length === 3 && isEntityNameExpression(node.arguments[0]) && isNumericOrStringLikeLiteral(node.arguments[1]) && ts16.isPropertyAccessExpression(node.expression) && node.expression.name.escapedText === "defineProperty" && ts16.isIdentifier(node.expression.expression) && node.expression.expression.escapedText === "Object";
  878. }
  879. function isInConstContext(node) {
  880. let current = node;
  881. while (true) {
  882. const parent = current.parent;
  883. outer:
  884. switch (parent.kind) {
  885. case ts16.SyntaxKind.TypeAssertionExpression:
  886. case ts16.SyntaxKind.AsExpression:
  887. return isConstAssertionExpression(parent);
  888. case ts16.SyntaxKind.PrefixUnaryExpression:
  889. if (current.kind !== ts16.SyntaxKind.NumericLiteral) {
  890. return false;
  891. }
  892. switch (parent.operator) {
  893. case ts16.SyntaxKind.PlusToken:
  894. case ts16.SyntaxKind.MinusToken:
  895. current = parent;
  896. break outer;
  897. default:
  898. return false;
  899. }
  900. case ts16.SyntaxKind.PropertyAssignment:
  901. if (parent.initializer !== current) {
  902. return false;
  903. }
  904. current = parent.parent;
  905. break;
  906. case ts16.SyntaxKind.ShorthandPropertyAssignment:
  907. current = parent.parent;
  908. break;
  909. case ts16.SyntaxKind.ParenthesizedExpression:
  910. case ts16.SyntaxKind.ArrayLiteralExpression:
  911. case ts16.SyntaxKind.ObjectLiteralExpression:
  912. case ts16.SyntaxKind.TemplateExpression:
  913. current = parent;
  914. break;
  915. default:
  916. return false;
  917. }
  918. }
  919. }
  920. // src/types/utilities.ts
  921. function isFalsyType(type) {
  922. if (isTypeFlagSet(
  923. type,
  924. ts17.TypeFlags.Undefined | ts17.TypeFlags.Null | ts17.TypeFlags.Void
  925. )) {
  926. return true;
  927. }
  928. if (type.isLiteral()) {
  929. return !type.value;
  930. }
  931. return isFalseLiteralType(type);
  932. }
  933. function intersectionTypeParts(type) {
  934. return isIntersectionType(type) ? type.types : [type];
  935. }
  936. function typeParts(type) {
  937. return isIntersectionType(type) || isUnionType(type) ? type.types : [type];
  938. }
  939. function isReadonlyPropertyIntersection(type, name, typeChecker) {
  940. const typeParts2 = isIntersectionType(type) ? type.types : [type];
  941. return typeParts2.some((subType) => {
  942. const prop = getPropertyOfType(subType, name);
  943. if (prop === void 0) {
  944. return false;
  945. }
  946. if (prop.flags & ts17.SymbolFlags.Transient) {
  947. if (/^(?:[1-9]\d*|0)$/.test(name) && isTupleTypeReference(subType)) {
  948. return subType.target.readonly;
  949. }
  950. switch (isReadonlyPropertyFromMappedType(subType, name, typeChecker)) {
  951. case true:
  952. return true;
  953. case false:
  954. return false;
  955. default:
  956. }
  957. }
  958. return !!// members of namespace import
  959. (isSymbolFlagSet(prop, ts17.SymbolFlags.ValueModule) || // we unwrapped every mapped type, now we can check the actual declarations
  960. symbolHasReadonlyDeclaration(prop, typeChecker));
  961. });
  962. }
  963. function isReadonlyPropertyFromMappedType(type, name, typeChecker) {
  964. if (!isObjectType(type) || !isObjectFlagSet(type, ts17.ObjectFlags.Mapped)) {
  965. return;
  966. }
  967. const declaration = type.symbol.declarations[0];
  968. if (declaration.readonlyToken !== void 0 && !/^__@[^@]+$/.test(name)) {
  969. return declaration.readonlyToken.kind !== ts17.SyntaxKind.MinusToken;
  970. }
  971. const { modifiersType } = type;
  972. return modifiersType && isPropertyReadonlyInType(modifiersType, name, typeChecker);
  973. }
  974. function isCallback(typeChecker, param, node) {
  975. let type = typeChecker.getApparentType(
  976. typeChecker.getTypeOfSymbolAtLocation(param, node)
  977. );
  978. if (param.valueDeclaration.dotDotDotToken) {
  979. type = type.getNumberIndexType();
  980. if (type === void 0) {
  981. return false;
  982. }
  983. }
  984. for (const subType of unionTypeParts(type)) {
  985. if (subType.getCallSignatures().length !== 0) {
  986. return true;
  987. }
  988. }
  989. return false;
  990. }
  991. function isPropertyReadonlyInType(type, name, typeChecker) {
  992. let seenProperty = false;
  993. let seenReadonlySignature = false;
  994. for (const subType of unionTypeParts(type)) {
  995. if (getPropertyOfType(subType, name) === void 0) {
  996. const index = (isNumericPropertyName(name) ? typeChecker.getIndexInfoOfType(subType, ts17.IndexKind.Number) : void 0) ?? typeChecker.getIndexInfoOfType(subType, ts17.IndexKind.String);
  997. if (index?.isReadonly) {
  998. if (seenProperty) {
  999. return true;
  1000. }
  1001. seenReadonlySignature = true;
  1002. }
  1003. } else if (seenReadonlySignature || isReadonlyPropertyIntersection(subType, name, typeChecker)) {
  1004. return true;
  1005. } else {
  1006. seenProperty = true;
  1007. }
  1008. }
  1009. return false;
  1010. }
  1011. function isReadonlyAssignmentDeclaration(node, typeChecker) {
  1012. if (!isBindableObjectDefinePropertyCall(node)) {
  1013. return false;
  1014. }
  1015. const descriptorType = typeChecker.getTypeAtLocation(node.arguments[2]);
  1016. if (descriptorType.getProperty("value") === void 0) {
  1017. return descriptorType.getProperty("set") === void 0;
  1018. }
  1019. const writableProp = descriptorType.getProperty("writable");
  1020. if (writableProp === void 0) {
  1021. return false;
  1022. }
  1023. const writableType = writableProp.valueDeclaration !== void 0 && ts17.isPropertyAssignment(writableProp.valueDeclaration) ? typeChecker.getTypeAtLocation(writableProp.valueDeclaration.initializer) : typeChecker.getTypeOfSymbolAtLocation(writableProp, node.arguments[2]);
  1024. return isFalseLiteralType(writableType);
  1025. }
  1026. function isThenableType(typeChecker, node, type = typeChecker.getTypeAtLocation(node)) {
  1027. for (const typePart of unionTypeParts(typeChecker.getApparentType(type))) {
  1028. const then = typePart.getProperty("then");
  1029. if (then === void 0) {
  1030. continue;
  1031. }
  1032. const thenType = typeChecker.getTypeOfSymbolAtLocation(then, node);
  1033. for (const subTypePart of unionTypeParts(thenType)) {
  1034. for (const signature of subTypePart.getCallSignatures()) {
  1035. if (signature.parameters.length !== 0 && isCallback(typeChecker, signature.parameters[0], node)) {
  1036. return true;
  1037. }
  1038. }
  1039. }
  1040. }
  1041. return false;
  1042. }
  1043. function symbolHasReadonlyDeclaration(symbol, typeChecker) {
  1044. return !!((symbol.flags & ts17.SymbolFlags.Accessor) === ts17.SymbolFlags.GetAccessor || symbol.declarations?.some(
  1045. (node) => isModifierFlagSet(node, ts17.ModifierFlags.Readonly) || ts17.isVariableDeclaration(node) && isNodeFlagSet(node.parent, ts17.NodeFlags.Const) || ts17.isCallExpression(node) && isReadonlyAssignmentDeclaration(node, typeChecker) || ts17.isEnumMember(node) || (ts17.isPropertyAssignment(node) || ts17.isShorthandPropertyAssignment(node)) && isInConstContext(node.parent)
  1046. ));
  1047. }
  1048. function unionTypeParts(type) {
  1049. return isUnionType(type) ? type.types : [type];
  1050. }
  1051. // src/usage/UsageWalker.ts
  1052. import ts23 from "typescript";
  1053. // src/usage/Scope.ts
  1054. import ts18 from "typescript";
  1055. function isBlockScopeBoundary(node) {
  1056. switch (node.kind) {
  1057. case ts18.SyntaxKind.Block: {
  1058. const parent = node.parent;
  1059. return parent.kind !== ts18.SyntaxKind.CatchClause && // blocks inside SourceFile are block scope boundaries
  1060. (parent.kind === ts18.SyntaxKind.SourceFile || // blocks that are direct children of a function scope boundary are no scope boundary
  1061. // for example the FunctionBlock is part of the function scope of the containing function
  1062. !isFunctionScopeBoundary(parent)) ? 2 /* Block */ : 0 /* None */;
  1063. }
  1064. case ts18.SyntaxKind.ForStatement:
  1065. case ts18.SyntaxKind.ForInStatement:
  1066. case ts18.SyntaxKind.ForOfStatement:
  1067. case ts18.SyntaxKind.CaseBlock:
  1068. case ts18.SyntaxKind.CatchClause:
  1069. case ts18.SyntaxKind.WithStatement:
  1070. return 2 /* Block */;
  1071. default:
  1072. return 0 /* None */;
  1073. }
  1074. }
  1075. // src/usage/declarations.ts
  1076. import ts20 from "typescript";
  1077. // src/usage/utils.ts
  1078. import ts19 from "typescript";
  1079. function identifierToKeywordKind(node) {
  1080. return "identifierToKeywordKind" in ts19 ? ts19.identifierToKeywordKind(node) : (
  1081. // eslint-disable-next-line deprecation/deprecation
  1082. node.originalKeywordKind
  1083. );
  1084. }
  1085. function canHaveDecorators(node) {
  1086. return "canHaveDecorators" in ts19 ? ts19.canHaveDecorators(node) : "decorators" in node;
  1087. }
  1088. function getDecorators(node) {
  1089. return "getDecorators" in ts19 ? ts19.getDecorators(node) : node.decorators;
  1090. }
  1091. // src/usage/declarations.ts
  1092. var DeclarationDomain = /* @__PURE__ */ ((DeclarationDomain2) => {
  1093. DeclarationDomain2[DeclarationDomain2["Import"] = 8] = "Import";
  1094. DeclarationDomain2[DeclarationDomain2["Namespace"] = 1] = "Namespace";
  1095. DeclarationDomain2[DeclarationDomain2["Type"] = 2] = "Type";
  1096. DeclarationDomain2[DeclarationDomain2["Value"] = 4] = "Value";
  1097. DeclarationDomain2[DeclarationDomain2["Any"] = 7] = "Any";
  1098. return DeclarationDomain2;
  1099. })(DeclarationDomain || {});
  1100. function getDeclarationDomain(node) {
  1101. switch (node.parent.kind) {
  1102. case ts20.SyntaxKind.TypeParameter:
  1103. case ts20.SyntaxKind.InterfaceDeclaration:
  1104. case ts20.SyntaxKind.TypeAliasDeclaration:
  1105. return 2 /* Type */;
  1106. case ts20.SyntaxKind.ClassDeclaration:
  1107. case ts20.SyntaxKind.ClassExpression:
  1108. return 2 /* Type */ | 4 /* Value */;
  1109. case ts20.SyntaxKind.EnumDeclaration:
  1110. return 7 /* Any */;
  1111. case ts20.SyntaxKind.NamespaceImport:
  1112. case ts20.SyntaxKind.ImportClause:
  1113. return 7 /* Any */ | 8 /* Import */;
  1114. case ts20.SyntaxKind.ImportEqualsDeclaration:
  1115. case ts20.SyntaxKind.ImportSpecifier:
  1116. return node.parent.name === node ? 7 /* Any */ | 8 /* Import */ : void 0;
  1117. case ts20.SyntaxKind.ModuleDeclaration:
  1118. return 1 /* Namespace */;
  1119. case ts20.SyntaxKind.Parameter:
  1120. if (node.parent.parent.kind === ts20.SyntaxKind.IndexSignature || identifierToKeywordKind(node) === ts20.SyntaxKind.ThisKeyword) {
  1121. return;
  1122. }
  1123. case ts20.SyntaxKind.BindingElement:
  1124. case ts20.SyntaxKind.VariableDeclaration:
  1125. return node.parent.name === node ? 4 /* Value */ : void 0;
  1126. case ts20.SyntaxKind.FunctionDeclaration:
  1127. case ts20.SyntaxKind.FunctionExpression:
  1128. return 4 /* Value */;
  1129. }
  1130. }
  1131. // src/usage/getPropertyName.ts
  1132. import ts21 from "typescript";
  1133. function unwrapParentheses(node) {
  1134. while (node.kind === ts21.SyntaxKind.ParenthesizedExpression) {
  1135. node = node.expression;
  1136. }
  1137. return node;
  1138. }
  1139. function getPropertyName(propertyName) {
  1140. if (propertyName.kind === ts21.SyntaxKind.ComputedPropertyName) {
  1141. const expression = unwrapParentheses(propertyName.expression);
  1142. if (ts21.isPrefixUnaryExpression(expression)) {
  1143. let negate = false;
  1144. switch (expression.operator) {
  1145. case ts21.SyntaxKind.MinusToken:
  1146. negate = true;
  1147. case ts21.SyntaxKind.PlusToken:
  1148. return ts21.isNumericLiteral(expression.operand) ? `${negate ? "-" : ""}${expression.operand.text}` : ts21.isBigIntLiteral(expression.operand) ? `${negate ? "-" : ""}${expression.operand.text.slice(0, -1)}` : void 0;
  1149. default:
  1150. return;
  1151. }
  1152. }
  1153. if (ts21.isBigIntLiteral(expression)) {
  1154. return expression.text.slice(0, -1);
  1155. }
  1156. if (isNumericOrStringLikeLiteral(expression)) {
  1157. return expression.text;
  1158. }
  1159. return;
  1160. }
  1161. return propertyName.kind === ts21.SyntaxKind.PrivateIdentifier ? void 0 : propertyName.text;
  1162. }
  1163. // src/usage/getUsageDomain.ts
  1164. import ts22 from "typescript";
  1165. var UsageDomain = /* @__PURE__ */ ((UsageDomain2) => {
  1166. UsageDomain2[UsageDomain2["Namespace"] = 1] = "Namespace";
  1167. UsageDomain2[UsageDomain2["Type"] = 2] = "Type";
  1168. UsageDomain2[UsageDomain2["TypeQuery"] = 8] = "TypeQuery";
  1169. UsageDomain2[UsageDomain2["Value"] = 4] = "Value";
  1170. UsageDomain2[UsageDomain2["ValueOrNamespace"] = 5] = "ValueOrNamespace";
  1171. UsageDomain2[UsageDomain2["Any"] = 7] = "Any";
  1172. return UsageDomain2;
  1173. })(UsageDomain || {});
  1174. function getUsageDomain(node) {
  1175. const parent = node.parent;
  1176. switch (parent.kind) {
  1177. case ts22.SyntaxKind.TypeReference:
  1178. return identifierToKeywordKind(node) !== ts22.SyntaxKind.ConstKeyword ? 2 /* Type */ : void 0;
  1179. case ts22.SyntaxKind.ExpressionWithTypeArguments:
  1180. return parent.parent.token === ts22.SyntaxKind.ImplementsKeyword || parent.parent.parent.kind === ts22.SyntaxKind.InterfaceDeclaration ? 2 /* Type */ : 4 /* Value */;
  1181. case ts22.SyntaxKind.TypeQuery:
  1182. return 5 /* ValueOrNamespace */ | 8 /* TypeQuery */;
  1183. case ts22.SyntaxKind.QualifiedName:
  1184. if (parent.left === node) {
  1185. if (getEntityNameParent(parent).kind === ts22.SyntaxKind.TypeQuery) {
  1186. return 1 /* Namespace */ | 8 /* TypeQuery */;
  1187. }
  1188. return 1 /* Namespace */;
  1189. }
  1190. break;
  1191. case ts22.SyntaxKind.ExportSpecifier:
  1192. if (parent.propertyName === void 0 || parent.propertyName === node) {
  1193. return 7 /* Any */;
  1194. }
  1195. break;
  1196. case ts22.SyntaxKind.ExportAssignment:
  1197. return 7 /* Any */;
  1198. case ts22.SyntaxKind.BindingElement:
  1199. if (parent.initializer === node) {
  1200. return 5 /* ValueOrNamespace */;
  1201. }
  1202. break;
  1203. case ts22.SyntaxKind.Parameter:
  1204. case ts22.SyntaxKind.EnumMember:
  1205. case ts22.SyntaxKind.PropertyDeclaration:
  1206. case ts22.SyntaxKind.VariableDeclaration:
  1207. case ts22.SyntaxKind.PropertyAssignment:
  1208. case ts22.SyntaxKind.PropertyAccessExpression:
  1209. case ts22.SyntaxKind.ImportEqualsDeclaration:
  1210. if (parent.name !== node) {
  1211. return 5 /* ValueOrNamespace */;
  1212. }
  1213. break;
  1214. case ts22.SyntaxKind.JsxAttribute:
  1215. case ts22.SyntaxKind.FunctionDeclaration:
  1216. case ts22.SyntaxKind.FunctionExpression:
  1217. case ts22.SyntaxKind.NamespaceImport:
  1218. case ts22.SyntaxKind.ClassDeclaration:
  1219. case ts22.SyntaxKind.ClassExpression:
  1220. case ts22.SyntaxKind.ModuleDeclaration:
  1221. case ts22.SyntaxKind.MethodDeclaration:
  1222. case ts22.SyntaxKind.EnumDeclaration:
  1223. case ts22.SyntaxKind.GetAccessor:
  1224. case ts22.SyntaxKind.SetAccessor:
  1225. case ts22.SyntaxKind.LabeledStatement:
  1226. case ts22.SyntaxKind.BreakStatement:
  1227. case ts22.SyntaxKind.ContinueStatement:
  1228. case ts22.SyntaxKind.ImportClause:
  1229. case ts22.SyntaxKind.ImportSpecifier:
  1230. case ts22.SyntaxKind.TypePredicate:
  1231. case ts22.SyntaxKind.MethodSignature:
  1232. case ts22.SyntaxKind.PropertySignature:
  1233. case ts22.SyntaxKind.NamespaceExportDeclaration:
  1234. case ts22.SyntaxKind.NamespaceExport:
  1235. case ts22.SyntaxKind.InterfaceDeclaration:
  1236. case ts22.SyntaxKind.TypeAliasDeclaration:
  1237. case ts22.SyntaxKind.TypeParameter:
  1238. case ts22.SyntaxKind.NamedTupleMember:
  1239. break;
  1240. default:
  1241. return 5 /* ValueOrNamespace */;
  1242. }
  1243. }
  1244. function getEntityNameParent(name) {
  1245. let parent = name.parent;
  1246. while (parent.kind === ts22.SyntaxKind.QualifiedName) {
  1247. parent = parent.parent;
  1248. }
  1249. return parent;
  1250. }
  1251. // src/usage/scopes.ts
  1252. var _enumScopes;
  1253. var AbstractScope = class {
  1254. constructor(global) {
  1255. this.global = global;
  1256. __privateAdd(this, _enumScopes, void 0);
  1257. this.namespaceScopes = void 0;
  1258. this.uses = [];
  1259. this.variables = /* @__PURE__ */ new Map();
  1260. }
  1261. addUse(use) {
  1262. this.uses.push(use);
  1263. }
  1264. // eslint-disable-next-line @typescript-eslint/no-empty-function
  1265. addUseToParent(_use) {
  1266. }
  1267. addVariable(identifier, name, selector, exported, domain) {
  1268. const variables = this.getDestinationScope(selector).getVariables();
  1269. const declaration = {
  1270. declaration: name,
  1271. domain,
  1272. exported
  1273. };
  1274. const variable = variables.get(identifier);
  1275. if (variable === void 0) {
  1276. variables.set(identifier, {
  1277. declarations: [declaration],
  1278. domain,
  1279. uses: []
  1280. });
  1281. } else {
  1282. variable.domain |= domain;
  1283. variable.declarations.push(declaration);
  1284. }
  1285. }
  1286. applyUse(use, variables = this.variables) {
  1287. const variable = variables.get(use.location.text);
  1288. if (variable === void 0 || (variable.domain & use.domain) === 0) {
  1289. return false;
  1290. }
  1291. variable.uses.push(use);
  1292. return true;
  1293. }
  1294. applyUses() {
  1295. for (const use of this.uses) {
  1296. if (!this.applyUse(use)) {
  1297. this.addUseToParent(use);
  1298. }
  1299. }
  1300. this.uses = [];
  1301. }
  1302. createOrReuseEnumScope(name, _exported) {
  1303. let scope;
  1304. if (__privateGet(this, _enumScopes) === void 0) {
  1305. __privateSet(this, _enumScopes, /* @__PURE__ */ new Map());
  1306. } else {
  1307. scope = __privateGet(this, _enumScopes).get(name);
  1308. }
  1309. if (scope === void 0) {
  1310. scope = new EnumScope(this);
  1311. __privateGet(this, _enumScopes).set(name, scope);
  1312. }
  1313. return scope;
  1314. }
  1315. // only relevant for the root scope
  1316. createOrReuseNamespaceScope(name, _exported, ambient, hasExportStatement) {
  1317. let scope;
  1318. if (this.namespaceScopes === void 0) {
  1319. this.namespaceScopes = /* @__PURE__ */ new Map();
  1320. } else {
  1321. scope = this.namespaceScopes.get(name);
  1322. }
  1323. if (scope === void 0) {
  1324. scope = new NamespaceScope(ambient, hasExportStatement, this);
  1325. this.namespaceScopes.set(name, scope);
  1326. } else {
  1327. scope.refresh(ambient, hasExportStatement);
  1328. }
  1329. return scope;
  1330. }
  1331. end(cb) {
  1332. if (this.namespaceScopes !== void 0) {
  1333. this.namespaceScopes.forEach((value) => value.finish(cb));
  1334. }
  1335. this.namespaceScopes = __privateSet(this, _enumScopes, void 0);
  1336. this.applyUses();
  1337. this.variables.forEach((variable) => {
  1338. for (const declaration of variable.declarations) {
  1339. const result = {
  1340. declarations: [],
  1341. domain: declaration.domain,
  1342. exported: declaration.exported,
  1343. inGlobalScope: this.global,
  1344. uses: []
  1345. };
  1346. for (const other of variable.declarations) {
  1347. if (other.domain & declaration.domain) {
  1348. result.declarations.push(other.declaration);
  1349. }
  1350. }
  1351. for (const use of variable.uses) {
  1352. if (use.domain & declaration.domain) {
  1353. result.uses.push(use);
  1354. }
  1355. }
  1356. cb(result, declaration.declaration, this);
  1357. }
  1358. });
  1359. }
  1360. getFunctionScope() {
  1361. return this;
  1362. }
  1363. getVariables() {
  1364. return this.variables;
  1365. }
  1366. // eslint-disable-next-line @typescript-eslint/no-empty-function
  1367. markExported(_name2) {
  1368. }
  1369. };
  1370. _enumScopes = new WeakMap();
  1371. var NonRootScope = class extends AbstractScope {
  1372. constructor(parent, boundary) {
  1373. super(false);
  1374. this.parent = parent;
  1375. this.boundary = boundary;
  1376. }
  1377. addUseToParent(use) {
  1378. return this.parent.addUse(use, this);
  1379. }
  1380. getDestinationScope(selector) {
  1381. return this.boundary & selector ? this : this.parent.getDestinationScope(selector);
  1382. }
  1383. };
  1384. var EnumScope = class extends NonRootScope {
  1385. constructor(parent) {
  1386. super(parent, 1 /* Function */);
  1387. }
  1388. end() {
  1389. this.applyUses();
  1390. }
  1391. };
  1392. var _exportAll, _exports, _innerScope;
  1393. var RootScope = class extends AbstractScope {
  1394. constructor(exportAll, global) {
  1395. super(global);
  1396. __privateAdd(this, _exportAll, void 0);
  1397. __privateAdd(this, _exports, void 0);
  1398. __privateAdd(this, _innerScope, new NonRootScope(this, 1 /* Function */));
  1399. __privateSet(this, _exportAll, exportAll);
  1400. }
  1401. addUse(use, origin) {
  1402. if (origin === __privateGet(this, _innerScope)) {
  1403. return super.addUse(use);
  1404. }
  1405. return __privateGet(this, _innerScope).addUse(use);
  1406. }
  1407. addVariable(identifier, name, selector, exported, domain) {
  1408. if (domain & 8 /* Import */) {
  1409. return super.addVariable(identifier, name, selector, exported, domain);
  1410. }
  1411. return __privateGet(this, _innerScope).addVariable(
  1412. identifier,
  1413. name,
  1414. selector,
  1415. exported,
  1416. domain
  1417. );
  1418. }
  1419. end(cb) {
  1420. __privateGet(this, _innerScope).end((value, key) => {
  1421. value.exported ||= __privateGet(this, _exportAll) || __privateGet(this, _exports) !== void 0 && __privateGet(this, _exports).includes(key.text);
  1422. value.inGlobalScope = this.global;
  1423. return cb(value, key, this);
  1424. });
  1425. return super.end((value, key, scope) => {
  1426. value.exported ||= scope === this && __privateGet(this, _exports) !== void 0 && __privateGet(this, _exports).includes(key.text);
  1427. return cb(value, key, scope);
  1428. });
  1429. }
  1430. getDestinationScope() {
  1431. return this;
  1432. }
  1433. markExported(id) {
  1434. if (__privateGet(this, _exports) === void 0) {
  1435. __privateSet(this, _exports, [id.text]);
  1436. } else {
  1437. __privateGet(this, _exports).push(id.text);
  1438. }
  1439. }
  1440. };
  1441. _exportAll = new WeakMap();
  1442. _exports = new WeakMap();
  1443. _innerScope = new WeakMap();
  1444. var _ambient, _exports2, _hasExport, _innerScope2;
  1445. var NamespaceScope = class extends NonRootScope {
  1446. constructor(ambient, hasExport, parent) {
  1447. super(parent, 1 /* Function */);
  1448. __privateAdd(this, _ambient, void 0);
  1449. __privateAdd(this, _exports2, void 0);
  1450. __privateAdd(this, _hasExport, void 0);
  1451. __privateAdd(this, _innerScope2, new NonRootScope(this, 1 /* Function */));
  1452. __privateSet(this, _ambient, ambient);
  1453. __privateSet(this, _hasExport, hasExport);
  1454. }
  1455. addUse(use, source) {
  1456. if (source !== __privateGet(this, _innerScope2)) {
  1457. return __privateGet(this, _innerScope2).addUse(use);
  1458. }
  1459. this.uses.push(use);
  1460. }
  1461. createOrReuseEnumScope(name, exported) {
  1462. if (!exported && (!__privateGet(this, _ambient) || __privateGet(this, _hasExport))) {
  1463. return __privateGet(this, _innerScope2).createOrReuseEnumScope(name, exported);
  1464. }
  1465. return super.createOrReuseEnumScope(name, exported);
  1466. }
  1467. createOrReuseNamespaceScope(name, exported, ambient, hasExportStatement) {
  1468. if (!exported && (!__privateGet(this, _ambient) || __privateGet(this, _hasExport))) {
  1469. return __privateGet(this, _innerScope2).createOrReuseNamespaceScope(
  1470. name,
  1471. exported,
  1472. ambient || __privateGet(this, _ambient),
  1473. hasExportStatement
  1474. );
  1475. }
  1476. return super.createOrReuseNamespaceScope(
  1477. name,
  1478. exported,
  1479. ambient || __privateGet(this, _ambient),
  1480. hasExportStatement
  1481. );
  1482. }
  1483. end(cb) {
  1484. __privateGet(this, _innerScope2).end((variable, key, scope) => {
  1485. if (scope !== __privateGet(this, _innerScope2) || !variable.exported && (!__privateGet(this, _ambient) || __privateGet(this, _exports2) !== void 0 && !__privateGet(this, _exports2).has(key.text))) {
  1486. return cb(variable, key, scope);
  1487. }
  1488. const namespaceVar = this.variables.get(key.text);
  1489. if (namespaceVar === void 0) {
  1490. this.variables.set(key.text, {
  1491. declarations: variable.declarations.map(mapDeclaration),
  1492. domain: variable.domain,
  1493. uses: [...variable.uses]
  1494. });
  1495. } else {
  1496. outer:
  1497. for (const declaration of variable.declarations) {
  1498. for (const existing of namespaceVar.declarations) {
  1499. if (existing.declaration === declaration) {
  1500. continue outer;
  1501. }
  1502. namespaceVar.declarations.push(mapDeclaration(declaration));
  1503. }
  1504. }
  1505. namespaceVar.domain |= variable.domain;
  1506. for (const use of variable.uses) {
  1507. if (namespaceVar.uses.includes(use)) {
  1508. continue;
  1509. }
  1510. namespaceVar.uses.push(use);
  1511. }
  1512. }
  1513. });
  1514. this.applyUses();
  1515. __privateSet(this, _innerScope2, new NonRootScope(this, 1 /* Function */));
  1516. }
  1517. finish(cb) {
  1518. return super.end(cb);
  1519. }
  1520. getDestinationScope() {
  1521. return __privateGet(this, _innerScope2);
  1522. }
  1523. markExported(name) {
  1524. if (__privateGet(this, _exports2) === void 0) {
  1525. __privateSet(this, _exports2, /* @__PURE__ */ new Set());
  1526. }
  1527. __privateGet(this, _exports2).add(name.text);
  1528. }
  1529. refresh(ambient, hasExport) {
  1530. __privateSet(this, _ambient, ambient);
  1531. __privateSet(this, _hasExport, hasExport);
  1532. }
  1533. };
  1534. _ambient = new WeakMap();
  1535. _exports2 = new WeakMap();
  1536. _hasExport = new WeakMap();
  1537. _innerScope2 = new WeakMap();
  1538. function mapDeclaration(declaration) {
  1539. return {
  1540. declaration,
  1541. domain: getDeclarationDomain(declaration),
  1542. exported: true
  1543. };
  1544. }
  1545. var FunctionScope = class extends NonRootScope {
  1546. constructor(parent) {
  1547. super(parent, 1 /* Function */);
  1548. }
  1549. beginBody() {
  1550. this.applyUses();
  1551. }
  1552. };
  1553. var _domain, _name;
  1554. var AbstractNamedExpressionScope = class extends NonRootScope {
  1555. constructor(name, domain, parent) {
  1556. super(parent, 1 /* Function */);
  1557. __privateAdd(this, _domain, void 0);
  1558. __privateAdd(this, _name, void 0);
  1559. __privateSet(this, _name, name);
  1560. __privateSet(this, _domain, domain);
  1561. }
  1562. addUse(use, source) {
  1563. if (source !== this.innerScope) {
  1564. return this.innerScope.addUse(use);
  1565. }
  1566. if (use.domain & __privateGet(this, _domain) && use.location.text === __privateGet(this, _name).text) {
  1567. this.uses.push(use);
  1568. } else {
  1569. return this.parent.addUse(use, this);
  1570. }
  1571. }
  1572. end(cb) {
  1573. this.innerScope.end(cb);
  1574. return cb(
  1575. {
  1576. declarations: [__privateGet(this, _name)],
  1577. domain: __privateGet(this, _domain),
  1578. exported: false,
  1579. inGlobalScope: false,
  1580. uses: this.uses
  1581. },
  1582. __privateGet(this, _name),
  1583. this
  1584. );
  1585. }
  1586. getDestinationScope() {
  1587. return this.innerScope;
  1588. }
  1589. getFunctionScope() {
  1590. return this.innerScope;
  1591. }
  1592. };
  1593. _domain = new WeakMap();
  1594. _name = new WeakMap();
  1595. var FunctionExpressionScope = class extends AbstractNamedExpressionScope {
  1596. constructor(name, parent) {
  1597. super(name, 4 /* Value */, parent);
  1598. this.innerScope = new FunctionScope(this);
  1599. }
  1600. beginBody() {
  1601. return this.innerScope.beginBody();
  1602. }
  1603. };
  1604. var _functionScope;
  1605. var BlockScope = class extends NonRootScope {
  1606. constructor(functionScope, parent) {
  1607. super(parent, 2 /* Block */);
  1608. __privateAdd(this, _functionScope, void 0);
  1609. __privateSet(this, _functionScope, functionScope);
  1610. }
  1611. getFunctionScope() {
  1612. return __privateGet(this, _functionScope);
  1613. }
  1614. };
  1615. _functionScope = new WeakMap();
  1616. var ClassExpressionScope = class extends AbstractNamedExpressionScope {
  1617. constructor(name, parent) {
  1618. super(name, 4 /* Value */ | 2 /* Type */, parent);
  1619. this.innerScope = new NonRootScope(this, 1 /* Function */);
  1620. }
  1621. };
  1622. var _state;
  1623. var ConditionalTypeScope = class extends NonRootScope {
  1624. constructor(parent) {
  1625. super(parent, 8 /* ConditionalType */);
  1626. __privateAdd(this, _state, 0 /* Initial */);
  1627. }
  1628. addUse(use) {
  1629. if (__privateGet(this, _state) === 2 /* TrueType */) {
  1630. return void this.uses.push(use);
  1631. }
  1632. return this.parent.addUse(use, this);
  1633. }
  1634. updateState(newState) {
  1635. __privateSet(this, _state, newState);
  1636. }
  1637. };
  1638. _state = new WeakMap();
  1639. // src/usage/UsageWalker.ts
  1640. var _result, _scope, _handleBindingName, handleBindingName_fn, _handleConditionalType, handleConditionalType_fn, _handleDeclaration, handleDeclaration_fn, _handleFunctionLikeDeclaration, handleFunctionLikeDeclaration_fn, _handleModule, handleModule_fn, _handleVariableDeclaration, handleVariableDeclaration_fn;
  1641. var UsageWalker = class {
  1642. constructor() {
  1643. __privateAdd(this, _handleBindingName);
  1644. __privateAdd(this, _handleConditionalType);
  1645. __privateAdd(this, _handleDeclaration);
  1646. __privateAdd(this, _handleFunctionLikeDeclaration);
  1647. __privateAdd(this, _handleModule);
  1648. __privateAdd(this, _handleVariableDeclaration);
  1649. __privateAdd(this, _result, /* @__PURE__ */ new Map());
  1650. __privateAdd(this, _scope, void 0);
  1651. }
  1652. getUsage(sourceFile) {
  1653. const variableCallback = (variable, key) => {
  1654. __privateGet(this, _result).set(key, variable);
  1655. };
  1656. const isModule = ts23.isExternalModule(sourceFile);
  1657. __privateSet(this, _scope, new RootScope(
  1658. sourceFile.isDeclarationFile && isModule && !containsExportStatement(sourceFile),
  1659. !isModule
  1660. ));
  1661. const cb = (node) => {
  1662. if (isBlockScopeBoundary(node)) {
  1663. return continueWithScope(
  1664. node,
  1665. new BlockScope(__privateGet(this, _scope).getFunctionScope(), __privateGet(this, _scope)),
  1666. handleBlockScope
  1667. );
  1668. }
  1669. switch (node.kind) {
  1670. case ts23.SyntaxKind.ClassExpression:
  1671. return continueWithScope(
  1672. node,
  1673. node.name !== void 0 ? new ClassExpressionScope(
  1674. node.name,
  1675. __privateGet(this, _scope)
  1676. ) : new NonRootScope(__privateGet(this, _scope), 1 /* Function */)
  1677. );
  1678. case ts23.SyntaxKind.ClassDeclaration:
  1679. __privateMethod(this, _handleDeclaration, handleDeclaration_fn).call(this, node, true, 4 /* Value */ | 2 /* Type */);
  1680. return continueWithScope(
  1681. node,
  1682. new NonRootScope(__privateGet(this, _scope), 1 /* Function */)
  1683. );
  1684. case ts23.SyntaxKind.InterfaceDeclaration:
  1685. case ts23.SyntaxKind.TypeAliasDeclaration:
  1686. __privateMethod(this, _handleDeclaration, handleDeclaration_fn).call(this, node, true, 2 /* Type */);
  1687. return continueWithScope(
  1688. node,
  1689. new NonRootScope(__privateGet(this, _scope), 4 /* Type */)
  1690. );
  1691. case ts23.SyntaxKind.EnumDeclaration:
  1692. __privateMethod(this, _handleDeclaration, handleDeclaration_fn).call(this, node, true, 7 /* Any */);
  1693. return continueWithScope(
  1694. node,
  1695. __privateGet(this, _scope).createOrReuseEnumScope(
  1696. node.name.text,
  1697. includesModifier(
  1698. node.modifiers,
  1699. ts23.SyntaxKind.ExportKeyword
  1700. )
  1701. )
  1702. );
  1703. case ts23.SyntaxKind.ModuleDeclaration:
  1704. return __privateMethod(this, _handleModule, handleModule_fn).call(this, node, continueWithScope);
  1705. case ts23.SyntaxKind.MappedType:
  1706. return continueWithScope(
  1707. node,
  1708. new NonRootScope(__privateGet(this, _scope), 4 /* Type */)
  1709. );
  1710. case ts23.SyntaxKind.FunctionExpression:
  1711. case ts23.SyntaxKind.ArrowFunction:
  1712. case ts23.SyntaxKind.Constructor:
  1713. case ts23.SyntaxKind.MethodDeclaration:
  1714. case ts23.SyntaxKind.FunctionDeclaration:
  1715. case ts23.SyntaxKind.GetAccessor:
  1716. case ts23.SyntaxKind.SetAccessor:
  1717. case ts23.SyntaxKind.MethodSignature:
  1718. case ts23.SyntaxKind.CallSignature:
  1719. case ts23.SyntaxKind.ConstructSignature:
  1720. case ts23.SyntaxKind.ConstructorType:
  1721. case ts23.SyntaxKind.FunctionType:
  1722. return __privateMethod(this, _handleFunctionLikeDeclaration, handleFunctionLikeDeclaration_fn).call(this, node, cb, variableCallback);
  1723. case ts23.SyntaxKind.ConditionalType:
  1724. return __privateMethod(this, _handleConditionalType, handleConditionalType_fn).call(this, node, cb, variableCallback);
  1725. case ts23.SyntaxKind.VariableDeclarationList:
  1726. __privateMethod(this, _handleVariableDeclaration, handleVariableDeclaration_fn).call(this, node);
  1727. break;
  1728. case ts23.SyntaxKind.Parameter:
  1729. if (node.parent.kind !== ts23.SyntaxKind.IndexSignature && (node.name.kind !== ts23.SyntaxKind.Identifier || identifierToKeywordKind(
  1730. node.name
  1731. ) !== ts23.SyntaxKind.ThisKeyword)) {
  1732. __privateMethod(this, _handleBindingName, handleBindingName_fn).call(this, node.name, false, false);
  1733. }
  1734. break;
  1735. case ts23.SyntaxKind.EnumMember:
  1736. __privateGet(this, _scope).addVariable(
  1737. getPropertyName(node.name),
  1738. node.name,
  1739. 1 /* Function */,
  1740. true,
  1741. 4 /* Value */
  1742. );
  1743. break;
  1744. case ts23.SyntaxKind.ImportClause:
  1745. case ts23.SyntaxKind.ImportSpecifier:
  1746. case ts23.SyntaxKind.NamespaceImport:
  1747. case ts23.SyntaxKind.ImportEqualsDeclaration:
  1748. __privateMethod(this, _handleDeclaration, handleDeclaration_fn).call(this, node, false, 7 /* Any */ | 8 /* Import */);
  1749. break;
  1750. case ts23.SyntaxKind.TypeParameter:
  1751. __privateGet(this, _scope).addVariable(
  1752. node.name.text,
  1753. node.name,
  1754. node.parent.kind === ts23.SyntaxKind.InferType ? 8 /* InferType */ : 7 /* Type */,
  1755. false,
  1756. 2 /* Type */
  1757. );
  1758. break;
  1759. case ts23.SyntaxKind.ExportSpecifier:
  1760. if (node.propertyName !== void 0) {
  1761. return __privateGet(this, _scope).markExported(
  1762. node.propertyName,
  1763. node.name
  1764. );
  1765. }
  1766. return __privateGet(this, _scope).markExported(node.name);
  1767. case ts23.SyntaxKind.ExportAssignment:
  1768. if (node.expression.kind === ts23.SyntaxKind.Identifier) {
  1769. return __privateGet(this, _scope).markExported(
  1770. node.expression
  1771. );
  1772. }
  1773. break;
  1774. case ts23.SyntaxKind.Identifier: {
  1775. const domain = getUsageDomain(node);
  1776. if (domain !== void 0) {
  1777. __privateGet(this, _scope).addUse({ domain, location: node });
  1778. }
  1779. return;
  1780. }
  1781. }
  1782. return ts23.forEachChild(node, cb);
  1783. };
  1784. const continueWithScope = (node, scope, next = forEachChild) => {
  1785. const savedScope = __privateGet(this, _scope);
  1786. __privateSet(this, _scope, scope);
  1787. next(node);
  1788. __privateGet(this, _scope).end(variableCallback);
  1789. __privateSet(this, _scope, savedScope);
  1790. };
  1791. const handleBlockScope = (node) => {
  1792. if (node.kind === ts23.SyntaxKind.CatchClause && node.variableDeclaration !== void 0) {
  1793. __privateMethod(this, _handleBindingName, handleBindingName_fn).call(this, node.variableDeclaration.name, true, false);
  1794. }
  1795. return ts23.forEachChild(node, cb);
  1796. };
  1797. ts23.forEachChild(sourceFile, cb);
  1798. __privateGet(this, _scope).end(variableCallback);
  1799. return __privateGet(this, _result);
  1800. function forEachChild(node) {
  1801. return ts23.forEachChild(node, cb);
  1802. }
  1803. }
  1804. };
  1805. _result = new WeakMap();
  1806. _scope = new WeakMap();
  1807. _handleBindingName = new WeakSet();
  1808. handleBindingName_fn = function(name, blockScoped, exported) {
  1809. if (name.kind === ts23.SyntaxKind.Identifier) {
  1810. return __privateGet(this, _scope).addVariable(
  1811. name.text,
  1812. name,
  1813. blockScoped ? 3 /* Block */ : 1 /* Function */,
  1814. exported,
  1815. 4 /* Value */
  1816. );
  1817. }
  1818. forEachDestructuringIdentifier(name, (declaration) => {
  1819. __privateGet(this, _scope).addVariable(
  1820. declaration.name.text,
  1821. declaration.name,
  1822. blockScoped ? 3 /* Block */ : 1 /* Function */,
  1823. exported,
  1824. 4 /* Value */
  1825. );
  1826. });
  1827. };
  1828. _handleConditionalType = new WeakSet();
  1829. handleConditionalType_fn = function(node, cb, varCb) {
  1830. const savedScope = __privateGet(this, _scope);
  1831. const scope = __privateSet(this, _scope, new ConditionalTypeScope(savedScope));
  1832. cb(node.checkType);
  1833. scope.updateState(1 /* Extends */);
  1834. cb(node.extendsType);
  1835. scope.updateState(2 /* TrueType */);
  1836. cb(node.trueType);
  1837. scope.updateState(3 /* FalseType */);
  1838. cb(node.falseType);
  1839. scope.end(varCb);
  1840. __privateSet(this, _scope, savedScope);
  1841. };
  1842. _handleDeclaration = new WeakSet();
  1843. handleDeclaration_fn = function(node, blockScoped, domain) {
  1844. if (node.name !== void 0) {
  1845. __privateGet(this, _scope).addVariable(
  1846. node.name.text,
  1847. node.name,
  1848. blockScoped ? 3 /* Block */ : 1 /* Function */,
  1849. includesModifier(
  1850. node.modifiers,
  1851. ts23.SyntaxKind.ExportKeyword
  1852. ),
  1853. domain
  1854. );
  1855. }
  1856. };
  1857. _handleFunctionLikeDeclaration = new WeakSet();
  1858. handleFunctionLikeDeclaration_fn = function(node, cb, varCb) {
  1859. if (canHaveDecorators(node)) {
  1860. getDecorators(node)?.forEach(cb);
  1861. }
  1862. const savedScope = __privateGet(this, _scope);
  1863. if (node.kind === ts23.SyntaxKind.FunctionDeclaration) {
  1864. __privateMethod(this, _handleDeclaration, handleDeclaration_fn).call(this, node, false, 4 /* Value */);
  1865. }
  1866. const scope = __privateSet(this, _scope, node.kind === ts23.SyntaxKind.FunctionExpression && node.name !== void 0 ? new FunctionExpressionScope(node.name, savedScope) : new FunctionScope(savedScope));
  1867. if (node.name !== void 0) {
  1868. cb(node.name);
  1869. }
  1870. if (node.typeParameters !== void 0) {
  1871. node.typeParameters.forEach(cb);
  1872. }
  1873. node.parameters.forEach(cb);
  1874. if (node.type !== void 0) {
  1875. cb(node.type);
  1876. }
  1877. if (node.body !== void 0) {
  1878. scope.beginBody();
  1879. cb(node.body);
  1880. }
  1881. scope.end(varCb);
  1882. __privateSet(this, _scope, savedScope);
  1883. };
  1884. _handleModule = new WeakSet();
  1885. handleModule_fn = function(node, next) {
  1886. if (node.flags & ts23.NodeFlags.GlobalAugmentation) {
  1887. return next(
  1888. node,
  1889. __privateGet(this, _scope).createOrReuseNamespaceScope("-global", false, true, false)
  1890. );
  1891. }
  1892. if (node.name.kind === ts23.SyntaxKind.Identifier) {
  1893. const exported = isNamespaceExported(node);
  1894. __privateGet(this, _scope).addVariable(
  1895. node.name.text,
  1896. node.name,
  1897. 1 /* Function */,
  1898. exported,
  1899. 1 /* Namespace */ | 4 /* Value */
  1900. );
  1901. const ambient = includesModifier(
  1902. node.modifiers,
  1903. ts23.SyntaxKind.DeclareKeyword
  1904. );
  1905. return next(
  1906. node,
  1907. __privateGet(this, _scope).createOrReuseNamespaceScope(
  1908. node.name.text,
  1909. exported,
  1910. ambient,
  1911. ambient && namespaceHasExportStatement(node)
  1912. )
  1913. );
  1914. }
  1915. return next(
  1916. node,
  1917. __privateGet(this, _scope).createOrReuseNamespaceScope(
  1918. `"${node.name.text}"`,
  1919. false,
  1920. true,
  1921. namespaceHasExportStatement(node)
  1922. )
  1923. );
  1924. };
  1925. _handleVariableDeclaration = new WeakSet();
  1926. handleVariableDeclaration_fn = function(declarationList) {
  1927. const blockScoped = isBlockScopedVariableDeclarationList(declarationList);
  1928. const exported = declarationList.parent.kind === ts23.SyntaxKind.VariableStatement && includesModifier(
  1929. declarationList.parent.modifiers,
  1930. ts23.SyntaxKind.ExportKeyword
  1931. );
  1932. for (const declaration of declarationList.declarations) {
  1933. __privateMethod(this, _handleBindingName, handleBindingName_fn).call(this, declaration.name, blockScoped, exported);
  1934. }
  1935. };
  1936. function isNamespaceExported(node) {
  1937. return node.parent.kind === ts23.SyntaxKind.ModuleDeclaration || includesModifier(node.modifiers, ts23.SyntaxKind.ExportKeyword);
  1938. }
  1939. function namespaceHasExportStatement(ns) {
  1940. if (ns.body === void 0 || ns.body.kind !== ts23.SyntaxKind.ModuleBlock) {
  1941. return false;
  1942. }
  1943. return containsExportStatement(ns.body);
  1944. }
  1945. function containsExportStatement(block) {
  1946. for (const statement of block.statements) {
  1947. if (statement.kind === ts23.SyntaxKind.ExportDeclaration || statement.kind === ts23.SyntaxKind.ExportAssignment) {
  1948. return true;
  1949. }
  1950. }
  1951. return false;
  1952. }
  1953. function isBlockScopedVariableDeclarationList(declarationList) {
  1954. return (declarationList.flags & ts23.NodeFlags.BlockScoped) !== 0;
  1955. }
  1956. function forEachDestructuringIdentifier(pattern, fn) {
  1957. for (const element of pattern.elements) {
  1958. if (element.kind !== ts23.SyntaxKind.BindingElement) {
  1959. continue;
  1960. }
  1961. let result;
  1962. if (element.name.kind === ts23.SyntaxKind.Identifier) {
  1963. result = fn(element);
  1964. } else {
  1965. result = forEachDestructuringIdentifier(element.name, fn);
  1966. }
  1967. if (result) {
  1968. return result;
  1969. }
  1970. }
  1971. }
  1972. // src/usage/collectVariableUsage.ts
  1973. function collectVariableUsage(sourceFile) {
  1974. return new UsageWalker().getUsage(sourceFile);
  1975. }
  1976. export {
  1977. DeclarationDomain,
  1978. UsageDomain,
  1979. collectVariableUsage,
  1980. forEachComment,
  1981. forEachToken,
  1982. getCallSignaturesOfType,
  1983. getPropertyOfType,
  1984. getWellKnownSymbolPropertyOfType,
  1985. hasDecorators,
  1986. hasExpressionInitializer,
  1987. hasInitializer,
  1988. hasJSDoc,
  1989. hasModifiers,
  1990. hasType,
  1991. hasTypeArguments,
  1992. includesModifier,
  1993. intersectionTypeParts,
  1994. isAbstractKeyword,
  1995. isAccessExpression,
  1996. isAccessibilityModifier,
  1997. isAccessorDeclaration,
  1998. isAccessorKeyword,
  1999. isAnyKeyword,
  2000. isArrayBindingElement,
  2001. isArrayBindingOrAssignmentPattern,
  2002. isAssertKeyword,
  2003. isAssertsKeyword,
  2004. isAssignmentKind,
  2005. isAssignmentPattern,
  2006. isAsyncKeyword,
  2007. isAwaitKeyword,
  2008. isBigIntKeyword,
  2009. isBigIntLiteralType,
  2010. isBindingOrAssignmentElementRestIndicator,
  2011. isBindingOrAssignmentElementTarget,
  2012. isBindingOrAssignmentPattern,
  2013. isBindingPattern,
  2014. isBlockLike,
  2015. isBooleanKeyword,
  2016. isBooleanLiteral,
  2017. isBooleanLiteralType,
  2018. isClassLikeDeclaration,
  2019. isClassMemberModifier,
  2020. isColonToken,
  2021. isCompilerOptionEnabled,
  2022. isConditionalType,
  2023. isConstAssertionExpression,
  2024. isConstKeyword,
  2025. isDeclarationName,
  2026. isDeclarationWithTypeParameterChildren,
  2027. isDeclarationWithTypeParameters,
  2028. isDeclareKeyword,
  2029. isDefaultKeyword,
  2030. isDestructuringPattern,
  2031. isDotToken,
  2032. isEndOfFileToken,
  2033. isEntityNameExpression,
  2034. isEntityNameOrEntityNameExpression,
  2035. isEnumType,
  2036. isEqualsGreaterThanToken,
  2037. isEqualsToken,
  2038. isEvolvingArrayType,
  2039. isExclamationToken,
  2040. isExportKeyword,
  2041. isFalseKeyword,
  2042. isFalseLiteral,
  2043. isFalseLiteralType,
  2044. isFalsyType,
  2045. isForInOrOfStatement,
  2046. isFreshableIntrinsicType,
  2047. isFreshableType,
  2048. isFunctionLikeDeclaration,
  2049. isFunctionScopeBoundary,
  2050. isImportExpression,
  2051. isImportKeyword,
  2052. isInKeyword,
  2053. isIndexType,
  2054. isIndexedAccessType,
  2055. isInputFiles,
  2056. isInstantiableType,
  2057. isIntersectionType,
  2058. isIntrinsicAnyType,
  2059. isIntrinsicBigIntType,
  2060. isIntrinsicBooleanType,
  2061. isIntrinsicESSymbolType,
  2062. isIntrinsicErrorType,
  2063. isIntrinsicNeverType,
  2064. isIntrinsicNonPrimitiveType,
  2065. isIntrinsicNullType,
  2066. isIntrinsicNumberType,
  2067. isIntrinsicStringType,
  2068. isIntrinsicType,
  2069. isIntrinsicUndefinedType,
  2070. isIntrinsicUnknownType,
  2071. isIntrinsicVoidType,
  2072. isIterationStatement,
  2073. isJSDocComment,
  2074. isJSDocNamespaceBody,
  2075. isJSDocNamespaceDeclaration,
  2076. isJSDocText,
  2077. isJSDocTypeReferencingNode,
  2078. isJsonMinusNumericLiteral,
  2079. isJsonObjectExpression,
  2080. isJsxAttributeLike,
  2081. isJsxAttributeValue,
  2082. isJsxChild,
  2083. isJsxTagNameExpression,
  2084. isJsxTagNamePropertyAccess,
  2085. isLiteralToken,
  2086. isLiteralType,
  2087. isModifierFlagSet,
  2088. isModuleBody,
  2089. isModuleName,
  2090. isModuleReference,
  2091. isNamedDeclarationWithName,
  2092. isNamedImportBindings,
  2093. isNamedImportsOrExports,
  2094. isNamespaceBody,
  2095. isNamespaceDeclaration,
  2096. isNeverKeyword,
  2097. isNodeFlagSet,
  2098. isNullKeyword,
  2099. isNullLiteral,
  2100. isNumberKeyword,
  2101. isNumberLiteralType,
  2102. isNumericOrStringLikeLiteral,
  2103. isNumericPropertyName,
  2104. isObjectBindingOrAssignmentElement,
  2105. isObjectBindingOrAssignmentPattern,
  2106. isObjectFlagSet,
  2107. isObjectKeyword,
  2108. isObjectType,
  2109. isObjectTypeDeclaration,
  2110. isOutKeyword,
  2111. isOverrideKeyword,
  2112. isParameterPropertyModifier,
  2113. isPrivateKeyword,
  2114. isPropertyAccessEntityNameExpression,
  2115. isPropertyNameLiteral,
  2116. isPropertyReadonlyInType,
  2117. isProtectedKeyword,
  2118. isPseudoLiteralToken,
  2119. isPublicKeyword,
  2120. isQuestionDotToken,
  2121. isQuestionToken,
  2122. isReadonlyKeyword,
  2123. isSignatureDeclaration,
  2124. isStaticKeyword,
  2125. isStrictCompilerOptionEnabled,
  2126. isStringKeyword,
  2127. isStringLiteralType,
  2128. isStringMappingType,
  2129. isSubstitutionType,
  2130. isSuperElementAccessExpression,
  2131. isSuperExpression,
  2132. isSuperKeyword,
  2133. isSuperProperty,
  2134. isSuperPropertyAccessExpression,
  2135. isSymbolFlagSet,
  2136. isSymbolKeyword,
  2137. isSyntaxList,
  2138. isTemplateLiteralType,
  2139. isThenableType,
  2140. isThisExpression,
  2141. isThisKeyword,
  2142. isTrueKeyword,
  2143. isTrueLiteral,
  2144. isTrueLiteralType,
  2145. isTupleType,
  2146. isTupleTypeReference,
  2147. isTypeFlagSet,
  2148. isTypeOnlyCompatibleAliasDeclaration,
  2149. isTypeParameter,
  2150. isTypeReference,
  2151. isTypeReferenceType,
  2152. isTypeVariable,
  2153. isUndefinedKeyword,
  2154. isUnionOrIntersectionType,
  2155. isUnionOrIntersectionTypeNode,
  2156. isUnionType,
  2157. isUniqueESSymbolType,
  2158. isUnknownKeyword,
  2159. isUnknownLiteralType,
  2160. isUnparsedPrologue,
  2161. isUnparsedSourceText,
  2162. isUnparsedSyntheticReference,
  2163. isValidPropertyAccess,
  2164. isVariableLikeDeclaration,
  2165. isVoidKeyword,
  2166. symbolHasReadonlyDeclaration,
  2167. typeParts,
  2168. unionTypeParts
  2169. };
  2170. //# sourceMappingURL=index.js.map