@swipt/cli 0.1.0-nightly.98 → 0.1.0-nightly.99

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. package/dist/availability.d.ts +3 -1
  2. package/dist/availability.js +173 -151
  3. package/dist/availability.js.map +1 -1
  4. package/dist/cli/cli.js +52 -66
  5. package/dist/cli/cli.js.map +1 -1
  6. package/dist/cli/command.d.ts +9 -0
  7. package/dist/cli/command.js.map +1 -1
  8. package/dist/cli/commands/data/clear.js +2 -2
  9. package/dist/cli/commands/data/clear.js.map +1 -1
  10. package/dist/cli/commands/data/data.js +2 -2
  11. package/dist/cli/commands/data/data.js.map +1 -1
  12. package/dist/cli/commands/data/list.js +3 -3
  13. package/dist/cli/commands/data/list.js.map +1 -1
  14. package/dist/cli/commands/data/operand.js.map +1 -1
  15. package/dist/cli/commands/data/read.js +4 -7
  16. package/dist/cli/commands/data/read.js.map +1 -1
  17. package/dist/cli/commands/data/remove.js +3 -3
  18. package/dist/cli/commands/data/remove.js.map +1 -1
  19. package/dist/cli/commands/data/write.js +2 -2
  20. package/dist/cli/commands/data/write.js.map +1 -1
  21. package/dist/cli/commands/device/add.js +2 -2
  22. package/dist/cli/commands/device/add.js.map +1 -1
  23. package/dist/cli/commands/device/device.js +2 -2
  24. package/dist/cli/commands/device/device.js.map +1 -1
  25. package/dist/cli/commands/device/list.js +2 -2
  26. package/dist/cli/commands/device/list.js.map +1 -1
  27. package/dist/cli/commands/device/logs.js +44 -46
  28. package/dist/cli/commands/device/logs.js.map +1 -1
  29. package/dist/cli/commands/device/remove.js +2 -2
  30. package/dist/cli/commands/device/remove.js.map +1 -1
  31. package/dist/cli/commands/device/stop.js +3 -3
  32. package/dist/cli/commands/device/stop.js.map +1 -1
  33. package/dist/cli/commands/driver/driver.js +6 -6
  34. package/dist/cli/commands/driver/driver.js.map +1 -1
  35. package/dist/cli/commands/flags.js +9 -9
  36. package/dist/cli/commands/flags.js.map +1 -1
  37. package/dist/cli/commands/index.js +2 -2
  38. package/dist/cli/commands/index.js.map +1 -1
  39. package/dist/cli/commands/project/build.js +2 -2
  40. package/dist/cli/commands/project/build.js.map +1 -1
  41. package/dist/cli/commands/project/create.js +3 -3
  42. package/dist/cli/commands/project/create.js.map +1 -1
  43. package/dist/cli/commands/project/deploy.js +2 -2
  44. package/dist/cli/commands/project/deploy.js.map +1 -1
  45. package/dist/cli/commands/project/develop.js +19 -19
  46. package/dist/cli/commands/project/develop.js.map +1 -1
  47. package/dist/cli/commands/project/project.js +2 -2
  48. package/dist/cli/commands/project/project.js.map +1 -1
  49. package/dist/cli/commands/project/source.js +62 -37
  50. package/dist/cli/commands/project/source.js.map +1 -1
  51. package/dist/cli/commands/repl/api.js +2 -2
  52. package/dist/cli/commands/repl/api.js.map +1 -1
  53. package/dist/cli/commands/repl/repl.js +4 -4
  54. package/dist/cli/commands/repl/repl.js.map +1 -1
  55. package/dist/cli/commands/repl/reset.js +2 -2
  56. package/dist/cli/commands/repl/reset.js.map +1 -1
  57. package/dist/cli/commands/repl/run.js +5 -5
  58. package/dist/cli/commands/repl/run.js.map +1 -1
  59. package/dist/cli/commands/sideload/install.js +4 -4
  60. package/dist/cli/commands/sideload/install.js.map +1 -1
  61. package/dist/cli/commands/sideload/setup.js +3 -3
  62. package/dist/cli/commands/sideload/setup.js.map +1 -1
  63. package/dist/cli/commands/sideload/sideload.js +2 -2
  64. package/dist/cli/commands/sideload/sideload.js.map +1 -1
  65. package/dist/cli/commands/sideload/uninstall.js +2 -2
  66. package/dist/cli/commands/sideload/uninstall.js.map +1 -1
  67. package/dist/cli/commands/sideload/update.js +3 -3
  68. package/dist/cli/commands/sideload/update.js.map +1 -1
  69. package/dist/cli/commands/swiplet/call.js +6 -6
  70. package/dist/cli/commands/swiplet/call.js.map +1 -1
  71. package/dist/cli/commands/swiplet/install.js +3 -3
  72. package/dist/cli/commands/swiplet/install.js.map +1 -1
  73. package/dist/cli/commands/swiplet/list.js +8 -8
  74. package/dist/cli/commands/swiplet/list.js.map +1 -1
  75. package/dist/cli/commands/swiplet/remove.js +3 -3
  76. package/dist/cli/commands/swiplet/remove.js.map +1 -1
  77. package/dist/cli/commands/swiplet/service/disable.js +3 -3
  78. package/dist/cli/commands/swiplet/service/disable.js.map +1 -1
  79. package/dist/cli/commands/swiplet/service/enable.js +3 -3
  80. package/dist/cli/commands/swiplet/service/enable.js.map +1 -1
  81. package/dist/cli/commands/swiplet/service/service.js +2 -2
  82. package/dist/cli/commands/swiplet/service/service.js.map +1 -1
  83. package/dist/cli/commands/swiplet/service/services.js +2 -2
  84. package/dist/cli/commands/swiplet/service/services.js.map +1 -1
  85. package/dist/cli/commands/swiplet/service/watch.js +2 -2
  86. package/dist/cli/commands/swiplet/service/watch.js.map +1 -1
  87. package/dist/cli/commands/swiplet/show.js +6 -6
  88. package/dist/cli/commands/swiplet/show.js.map +1 -1
  89. package/dist/cli/commands/swiplet/swiplet.js +4 -4
  90. package/dist/cli/commands/swiplet/swiplet.js.map +1 -1
  91. package/dist/cli/commands/version/version.js +2 -2
  92. package/dist/cli/commands/version/version.js.map +1 -1
  93. package/dist/cli/deploy.js +9 -7
  94. package/dist/cli/deploy.js.map +1 -1
  95. package/dist/cli/session.js.map +1 -1
  96. package/dist/client.d.ts +145 -7
  97. package/dist/client.js +20 -22
  98. package/dist/client.js.map +1 -1
  99. package/dist/connection.d.ts +292 -25
  100. package/dist/connection.js +36 -35
  101. package/dist/connection.js.map +1 -1
  102. package/dist/driver.d.ts +62 -23
  103. package/dist/driver.js +29 -33
  104. package/dist/driver.js.map +1 -1
  105. package/dist/i18n.d.ts +2 -5
  106. package/dist/i18n.js +15 -13
  107. package/dist/i18n.js.map +1 -1
  108. package/dist/i18next.d.ts +7 -0
  109. package/dist/ignore.d.ts +14 -7
  110. package/dist/ignore.js +13 -14
  111. package/dist/ignore.js.map +1 -1
  112. package/dist/mdns.d.ts +2 -2
  113. package/dist/mdns.js +1 -1
  114. package/dist/mdns.js.map +1 -1
  115. package/dist/metro.d.ts +19 -5
  116. package/dist/metro.js +61 -63
  117. package/dist/metro.js.map +1 -1
  118. package/dist/output.d.ts +29 -14
  119. package/dist/output.js +17 -15
  120. package/dist/output.js.map +1 -1
  121. package/dist/passcode.d.ts +12 -8
  122. package/dist/passcode.js +18 -18
  123. package/dist/passcode.js.map +1 -1
  124. package/dist/project.d.ts +20 -10
  125. package/dist/project.js +72 -49
  126. package/dist/project.js.map +1 -1
  127. package/dist/proto/common_pb.d.ts +240 -0
  128. package/dist/proto/common_pb.js +7 -2
  129. package/dist/proto/common_pb.js.map +1 -1
  130. package/dist/proto/logs_pb.d.ts +38 -0
  131. package/dist/proto/repl_pb.d.ts +96 -0
  132. package/dist/proto/swiplets_pb.d.ts +361 -0
  133. package/dist/proto/swiplets_pb.js +7 -2
  134. package/dist/proto/swiplets_pb.js.map +1 -1
  135. package/dist/proto/system_pb.d.ts +33 -0
  136. package/dist/resources.d.ts +400 -0
  137. package/dist/serve.d.ts +9 -1
  138. package/dist/serve.js +17 -16
  139. package/dist/serve.js.map +1 -1
  140. package/dist/sideload.d.ts +27 -14
  141. package/dist/sideload.js +102 -89
  142. package/dist/sideload.js.map +1 -1
  143. package/dist/swipt-app.d.ts +19 -9
  144. package/dist/swipt-app.js +1 -1
  145. package/dist/swipt-app.js.map +1 -1
  146. package/locales/ar/translation.json +413 -0
  147. package/locales/bg/translation.json +397 -0
  148. package/locales/bn/translation.json +397 -0
  149. package/locales/ca/translation.json +401 -0
  150. package/locales/cs/translation.json +405 -0
  151. package/locales/da/translation.json +397 -0
  152. package/locales/de/translation.json +397 -0
  153. package/locales/el/translation.json +397 -0
  154. package/locales/en/translation.json +397 -0
  155. package/locales/es/translation.json +401 -0
  156. package/locales/es-419/translation.json +401 -0
  157. package/locales/fi/translation.json +397 -0
  158. package/locales/fr/translation.json +401 -0
  159. package/locales/fr-CA/translation.json +401 -0
  160. package/locales/gu/translation.json +397 -0
  161. package/locales/he/translation.json +401 -0
  162. package/locales/hi/translation.json +397 -0
  163. package/locales/hr/translation.json +401 -0
  164. package/locales/hu/translation.json +397 -0
  165. package/locales/id/translation.json +393 -0
  166. package/locales/it/translation.json +401 -0
  167. package/locales/ja/translation.json +393 -0
  168. package/locales/kk/translation.json +397 -0
  169. package/locales/kn/translation.json +397 -0
  170. package/locales/ko/translation.json +393 -0
  171. package/locales/lt/translation.json +405 -0
  172. package/locales/ml/translation.json +397 -0
  173. package/locales/mr/translation.json +397 -0
  174. package/locales/ms/translation.json +393 -0
  175. package/locales/nb/translation.json +397 -0
  176. package/locales/nl/translation.json +397 -0
  177. package/locales/or/translation.json +397 -0
  178. package/locales/pa/translation.json +397 -0
  179. package/locales/pl/translation.json +405 -0
  180. package/locales/pt-BR/translation.json +401 -0
  181. package/locales/pt-PT/translation.json +401 -0
  182. package/locales/ro/translation.json +401 -0
  183. package/locales/ru/translation.json +405 -0
  184. package/locales/sk/translation.json +405 -0
  185. package/locales/sl/translation.json +405 -0
  186. package/locales/sv/translation.json +397 -0
  187. package/locales/ta/translation.json +397 -0
  188. package/locales/te/translation.json +397 -0
  189. package/locales/th/translation.json +393 -0
  190. package/locales/tr/translation.json +397 -0
  191. package/locales/uk/translation.json +405 -0
  192. package/locales/ur/translation.json +397 -0
  193. package/locales/vi/translation.json +397 -0
  194. package/locales/zh-HK/translation.json +393 -0
  195. package/locales/zh-Hans/translation.json +393 -0
  196. package/locales/zh-Hant/translation.json +393 -0
  197. package/package.json +14 -9
  198. package/locales/ar.json +0 -311
  199. package/locales/bg.json +0 -295
  200. package/locales/bn.json +0 -295
  201. package/locales/ca.json +0 -299
  202. package/locales/cs.json +0 -303
  203. package/locales/da.json +0 -295
  204. package/locales/de.json +0 -295
  205. package/locales/el.json +0 -295
  206. package/locales/es-419.json +0 -299
  207. package/locales/es.json +0 -299
  208. package/locales/fi.json +0 -295
  209. package/locales/fr-CA.json +0 -299
  210. package/locales/fr.json +0 -299
  211. package/locales/gu.json +0 -295
  212. package/locales/he.json +0 -299
  213. package/locales/hi.json +0 -295
  214. package/locales/hr.json +0 -299
  215. package/locales/hu.json +0 -295
  216. package/locales/id.json +0 -283
  217. package/locales/it.json +0 -299
  218. package/locales/ja.json +0 -283
  219. package/locales/kk.json +0 -295
  220. package/locales/kn.json +0 -295
  221. package/locales/ko.json +0 -283
  222. package/locales/lt.json +0 -303
  223. package/locales/ml.json +0 -295
  224. package/locales/mr.json +0 -295
  225. package/locales/ms.json +0 -283
  226. package/locales/nb.json +0 -295
  227. package/locales/nl.json +0 -295
  228. package/locales/or.json +0 -295
  229. package/locales/pa.json +0 -295
  230. package/locales/pl.json +0 -303
  231. package/locales/pt-BR.json +0 -299
  232. package/locales/pt-PT.json +0 -299
  233. package/locales/ro.json +0 -299
  234. package/locales/ru.json +0 -303
  235. package/locales/sk.json +0 -303
  236. package/locales/sl.json +0 -303
  237. package/locales/sv.json +0 -295
  238. package/locales/ta.json +0 -295
  239. package/locales/te.json +0 -295
  240. package/locales/th.json +0 -283
  241. package/locales/tr.json +0 -295
  242. package/locales/uk.json +0 -303
  243. package/locales/ur.json +0 -295
  244. package/locales/vi.json +0 -295
  245. package/locales/zh-HK.json +0 -283
  246. package/locales/zh-Hans.json +0 -283
  247. package/locales/zh-Hant.json +0 -283
@@ -1,5 +1,7 @@
1
+ import { Project } from "./project.js";
2
+ import { Metafile } from "esbuild";
1
3
  export declare class AvailabilityChecker {
2
4
  #private;
3
- check(project: any, metafiles: any): void;
5
+ check(project: Project, metafiles: readonly Metafile[]): void;
4
6
  close(): void;
5
7
  }
@@ -1,16 +1,16 @@
1
- import { language, tr } from "./i18n.js";
1
+ import { language, t } from "./i18n.js";
2
2
  import { parseVersion, versionAtLeast } from "./version.js";
3
3
  import fs from "node:fs";
4
4
  import path from "node:path";
5
5
  import { NodeFlags, SyntaxKind } from "typescript/unstable/ast";
6
- import { isTypeNode } from "typescript/unstable/ast/is";
6
+ import { isAccessorDeclaration, isArrowFunction, isBinaryExpression, isBindingElement, isBlock, isBreakOrContinueStatement, isCallExpression, isCallOrNewExpression, isCaseClause, isClassDeclaration, isClassLikeDeclaration, isComputedPropertyName, isConditionalExpression, isConstructorDeclaration, isDefaultClause, isElementAccessExpression, isExportDeclaration, isExpressionWithTypeArguments, isFunctionDeclaration, isFunctionLikeDeclaration, isHeritageClause, isIdentifier, isIfStatement, isImportDeclaration, isInterfaceDeclaration, isJSDoc, isJsxAttribute, isJsxAttributes, isJsxSpreadAttribute, isMethodDeclaration, isModuleBlock, isNamedExports, isNumericLiteral, isNumericOrStringLikeLiteral, isObjectBindingPattern, isObjectLiteralExpression, isParenthesizedExpression, isPrefixUnaryExpression, isPropertyAccessExpression, isPropertyAssignment, isPropertyDeclaration, isReturnStatement, isShorthandPropertyAssignment, isSourceFile, isSpreadAssignment, isStringLiteralLikeNode, isThrowStatement, isTypeNode, isVariableDeclaration } from "typescript/unstable/ast/is";
7
7
  import { API, SymbolFlags } from "typescript/unstable/sync";
8
8
  // src/availability.ts
9
9
  const requirements = {
10
10
  apiLevel: {
11
11
  parse: (text) => /^[1-9]\d*$/.test(text) ? Number(text) : void 0,
12
12
  covers: (level, needed) => level >= needed,
13
- describe: (level) => tr("API level {level}", { level })
13
+ describe: (level) => t("availability.apiLevel", { level })
14
14
  },
15
15
  iOS: {
16
16
  parse: parseVersion,
@@ -18,55 +18,70 @@ const requirements = {
18
18
  describe: (version) => `iOS ${version.join(".")}`
19
19
  }
20
20
  };
21
+ const isKind = (name) => Object.hasOwn(requirements, name);
22
+ const kindsOf = (requirement) => Object.keys(requirement).filter(isKind);
23
+ const parseKind = (kind, text) => {
24
+ const value = requirements[kind].parse(text);
25
+ if (value === void 0) return;
26
+ const requirement = {};
27
+ requirement[kind] = value;
28
+ return requirement;
29
+ };
21
30
  const lists = new Intl.ListFormat(language, { type: "conjunction" });
31
+ const mergeKind = (into, from, kind) => {
32
+ const needed = from[kind];
33
+ const current = into[kind];
34
+ if (needed !== void 0 && (current === void 0 || !requirements[kind].covers(current, needed))) into[kind] = needed;
35
+ };
22
36
  const merge = (into, from) => {
23
- for (const [name, needed] of Object.entries(from)) if (into[name] === void 0 || !requirements[name].covers(into[name], needed)) into[name] = needed;
37
+ for (const kind of kindsOf(from)) mergeKind(into, from, kind);
24
38
  return into;
25
39
  };
26
- const describe = (needed, missing) => lists.format(missing.map((name) => requirements[name].describe(needed[name])));
40
+ const unmet = (needed, covered) => {
41
+ const missing = kindsOf(needed).flatMap((kind) => {
42
+ const value = needed[kind];
43
+ return value === void 0 || covered(kind, value) ? [] : [requirements[kind].describe(value)];
44
+ });
45
+ return missing.length > 0 ? lists.format(missing) : void 0;
46
+ };
27
47
  function parseAnnotation(text) {
28
48
  const requirement = {};
29
49
  for (const entry of text.split(",").map((part) => part.trim())) {
30
- const [kind, value, ...rest] = entry.split(/\s+/);
31
- const parsed = rest.length === 0 && Object.hasOwn(requirements, kind) ? requirements[kind].parse(value ?? "") : void 0;
50
+ const [kind = "", value = "", ...rest] = entry.split(/\s+/);
51
+ const parsed = rest.length === 0 && isKind(kind) ? parseKind(kind, value) : void 0;
32
52
  if (parsed === void 0) return {
33
53
  requirement,
34
54
  invalid: entry
35
55
  };
36
- if (requirement[kind] !== void 0) return {
56
+ const repeated = kindsOf(parsed).find((name) => requirement[name] !== void 0);
57
+ if (repeated !== void 0) return {
37
58
  requirement,
38
- repeated: kind
59
+ repeated
39
60
  };
40
- requirement[kind] = parsed;
61
+ Object.assign(requirement, parsed);
41
62
  }
42
63
  return { requirement };
43
64
  }
44
- const tagText = (tag) => typeof tag.comment === "string" ? tag.comment : (tag.comment ?? []).map((part) => part.text).join("");
45
- const annotationTags = (node) => (node.jsDoc ?? []).flatMap((comment) => (comment.tags ?? []).filter((tag) => tag.tagName.text === "available"));
46
- const exits = (statement) => statement.kind === SyntaxKind.ReturnStatement || statement.kind === SyntaxKind.ThrowStatement || statement.kind === SyntaxKind.BreakStatement || statement.kind === SyntaxKind.ContinueStatement || statement.kind === SyntaxKind.Block && statement.statements.length > 0 && exits(statement.statements.at(-1));
65
+ const tagText = (tag) => (tag.comment ?? []).map((part) => part.text).join("");
66
+ const annotationTags = (node) => (node.jsDoc ?? []).filter(isJSDoc).flatMap((comment) => (comment.tags ?? []).filter((tag) => tag.tagName.text === "available"));
67
+ const exits = (statement) => {
68
+ if (isReturnStatement(statement) || isThrowStatement(statement) || isBreakOrContinueStatement(statement)) return true;
69
+ const last = isBlock(statement) ? statement.statements.at(-1) : void 0;
70
+ return last !== void 0 && exits(last);
71
+ };
47
72
  const hasModifier = (node, kind) => node.modifiers?.some((modifier) => modifier.kind === kind) ?? false;
48
- const functions = /* @__PURE__ */ new Set([
49
- SyntaxKind.FunctionDeclaration,
50
- SyntaxKind.FunctionExpression,
51
- SyntaxKind.ArrowFunction,
52
- SyntaxKind.MethodDeclaration,
53
- SyntaxKind.GetAccessor,
54
- SyntaxKind.SetAccessor,
55
- SyntaxKind.Constructor
56
- ]);
57
- const classes = /* @__PURE__ */ new Set([SyntaxKind.ClassDeclaration, SyntaxKind.ClassExpression]);
58
- const valueHolders = /* @__PURE__ */ new Set([
59
- SyntaxKind.VariableDeclaration,
60
- SyntaxKind.PropertyDeclaration,
61
- SyntaxKind.PropertyAssignment
62
- ]);
63
- const objectMembers = /* @__PURE__ */ new Set([
64
- SyntaxKind.PropertyAssignment,
65
- SyntaxKind.ShorthandPropertyAssignment,
66
- SyntaxKind.MethodDeclaration,
67
- SyntaxKind.GetAccessor,
68
- SyntaxKind.SetAccessor
69
- ]);
73
+ const statementsOf = (node) => isBlock(node) || isSourceFile(node) || isModuleBlock(node) || isCaseClause(node) || isDefaultClause(node) ? node.statements : [];
74
+ const isNameOf = (node) => "name" in node.parent && node.parent.name === node;
75
+ const isPropertyNameOf = (node) => "propertyName" in node.parent && node.parent.propertyName === node;
76
+ const isObjectMember = (node) => isPropertyAssignment(node) || isShorthandPropertyAssignment(node) || isMethodDeclaration(node) || isAccessorDeclaration(node);
77
+ const isValueHolder = (node) => isVariableDeclaration(node) || isPropertyDeclaration(node) || isPropertyAssignment(node);
78
+ const writtenName = (member) => {
79
+ if (isSpreadAssignment(member)) return;
80
+ const { name } = member;
81
+ if (isComputedPropertyName(name)) return isNumericOrStringLikeLiteral(name.expression) ? name.expression.text : void 0;
82
+ return name.text;
83
+ };
84
+ const constituentsOf = (type) => type.isUnionType() || type.isIntersectionType() || type.isTemplateLiteralType() ? type.getTypes() : [];
70
85
  const literals = /* @__PURE__ */ new Set([
71
86
  SyntaxKind.ObjectLiteralExpression,
72
87
  SyntaxKind.ArrayLiteralExpression,
@@ -81,7 +96,6 @@ const literals = /* @__PURE__ */ new Set([
81
96
  SyntaxKind.NullKeyword,
82
97
  SyntaxKind.SpreadElement
83
98
  ]);
84
- const names = /* @__PURE__ */ new Set([SyntaxKind.StringLiteral, SyntaxKind.NoSubstitutionTemplateLiteral]);
85
99
  const inert = /* @__PURE__ */ new Set([
86
100
  SyntaxKind.ImportDeclaration,
87
101
  SyntaxKind.ExportDeclaration,
@@ -115,9 +129,13 @@ var AvailabilityChecker = class {
115
129
  lines: /* @__PURE__ */ new Set(),
116
130
  guarding: false
117
131
  };
118
- const groups = Map.groupBy(files, (file) => snapshot.getDefaultProjectForFile(file));
132
+ const groups = Map.groupBy(files, (file) => {
133
+ const typescript = snapshot.getDefaultProjectForFile(file);
134
+ if (typescript === void 0) throw new Error(`no TypeScript project contains ${file}`);
135
+ return typescript;
136
+ });
119
137
  for (const [typescript, owned] of groups) new Checker(typescript, project, files, problems).check(owned);
120
- if (problems.lines.size > 0) throw new Error([...problems.lines, ...problems.guarding ? [tr("Check these with available(), mark the code that uses them with @available, or raise \"swiplet.minimumAPILevel\" or \"swiplet.minimumIOSVersion\" in package.json.")] : []].join("\n"));
138
+ if (problems.lines.size > 0) throw new Error([...problems.lines, ...problems.guarding ? [t("availability.advice")] : []].join("\n"));
121
139
  }
122
140
  close() {
123
141
  this.#api?.close();
@@ -149,28 +167,31 @@ var Checker = class {
149
167
  apiLevel: project.config.minimumAPILevel ?? project.apiLevel,
150
168
  iOS: parseVersion(project.config.minimumIOSVersion ?? project.minimumIOSVersion)
151
169
  };
152
- this.#entries = new Set([project.app, project.extension].filter(Boolean).map((entry) => fs.realpathSync(entry)));
170
+ this.#entries = new Set([project.app, project.extension].filter((entry) => entry !== void 0).map((entry) => fs.realpathSync(entry)));
153
171
  this.#available = this.#availableSymbol(project.apiDirectory);
154
172
  }
155
173
  check(files) {
156
174
  for (const file of files) {
157
175
  const source = this.#project.program.getSourceFile(file);
176
+ if (source === void 0) throw new Error(`the TypeScript program has no ${file}`);
158
177
  const { identifiers, properties, values } = this.#collect(source);
159
178
  const symbols = this.#checker.getSymbolAtLocation(identifiers);
160
- for (const [index, node] of identifiers.entries()) this.#use(node, node.parent.kind === SyntaxKind.ShorthandPropertyAssignment ? this.#checker.getShorthandAssignmentValueSymbol(node.parent) : symbols[index]);
161
- for (const node of properties) this.#use(node, this.#propertySymbol(node));
179
+ for (const [index, node] of identifiers.entries()) this.#use(node, isShorthandPropertyAssignment(node.parent) ? this.#checker.getShorthandAssignmentValueSymbol(node.parent) : symbols[index], node.text);
180
+ for (const node of properties) this.#use(node, this.#propertySymbol(node), node.text);
162
181
  for (const node of values) this.#useValue(node);
163
182
  for (const statement of source.statements) {
164
- if (statement.kind !== SyntaxKind.ExportDeclaration || statement.isTypeOnly) continue;
165
- const exported = (statement.exportClause?.elements ?? []).filter((specifier) => !specifier.isTypeOnly);
183
+ if (!isExportDeclaration(statement) || statement.isTypeOnly) continue;
184
+ const { exportClause } = statement;
185
+ const elements = exportClause !== void 0 && isNamedExports(exportClause) ? exportClause.elements : void 0;
186
+ const exported = (elements ?? []).filter((specifier) => !specifier.isTypeOnly);
166
187
  if (statement.moduleSpecifier === void 0) for (const specifier of exported) {
167
188
  const local = this.#checker.getExportSpecifierLocalTargetSymbol(specifier);
168
189
  if (local !== void 0) this.#useImport(local);
169
190
  }
170
- else if (exported.length > 0 || statement.exportClause?.elements === void 0) this.#importModule(statement);
191
+ else if (exported.length > 0 || elements === void 0) this.#importModule(statement);
171
192
  }
172
193
  if (this.#entries.has(file)) {
173
- for (const statement of source.statements) if (statement.name !== void 0 && hasModifier(statement, SyntaxKind.DefaultKeyword)) this.#useEntry(statement.name);
194
+ for (const statement of source.statements) if ((isFunctionDeclaration(statement) || isClassDeclaration(statement) || isInterfaceDeclaration(statement)) && statement.name !== void 0 && hasModifier(statement, SyntaxKind.DefaultKeyword)) this.#useEntry(statement.name);
174
195
  }
175
196
  }
176
197
  }
@@ -180,25 +201,25 @@ var Checker = class {
180
201
  const values = [];
181
202
  const visit = (node, checked) => {
182
203
  for (const tag of annotationTags(node)) this.#parse(tagText(tag), tag);
183
- const extended = node.kind === SyntaxKind.ExpressionWithTypeArguments && node.parent.token === SyntaxKind.ExtendsKeyword && classes.has(node.parent.parent.kind);
204
+ const extended = isExpressionWithTypeArguments(node) && isHeritageClause(node.parent) && node.parent.token === SyntaxKind.ExtendsKeyword && isClassLikeDeclaration(node.parent.parent);
184
205
  if (inert.has(node.kind) || isTypeNode(node) && !extended) checked = false;
185
206
  if (checked) {
186
- if (node.kind === SyntaxKind.CallExpression || node.kind === SyntaxKind.NewExpression) values.push(...(node.arguments ?? []).filter((argument) => !literals.has(argument.kind)));
187
- else if (node.kind === SyntaxKind.SpreadAssignment || node.kind === SyntaxKind.JsxSpreadAttribute) values.push(node.expression);
207
+ if (isCallOrNewExpression(node)) values.push(...(node.arguments ?? []).filter((argument) => !literals.has(argument.kind)));
208
+ else if (isSpreadAssignment(node) || isJsxSpreadAttribute(node)) values.push(node.expression);
188
209
  }
189
- if (checked && node.kind === SyntaxKind.Identifier) {
210
+ if (checked && isIdentifier(node)) {
190
211
  const { parent } = node;
191
- const property = parent.kind === SyntaxKind.JsxAttribute || objectMembers.has(parent.kind) && parent.parent.kind === SyntaxKind.ObjectLiteralExpression && parent.name === node || parent.kind === SyntaxKind.BindingElement && parent.parent.kind === SyntaxKind.ObjectBindingPattern && (parent.propertyName ?? parent.name) === node;
212
+ const property = isJsxAttribute(parent) || isObjectMember(parent) && isObjectLiteralExpression(parent.parent) && parent.name === node || isBindingElement(parent) && isObjectBindingPattern(parent.parent) && (parent.propertyName ?? parent.name) === node;
192
213
  if (property) properties.push(node);
193
- if (parent.kind === SyntaxKind.ShorthandPropertyAssignment || !property && parent.propertyName !== node && (parent.name !== node || parent.kind === SyntaxKind.PropertyAccessExpression)) identifiers.push(node);
214
+ if (isShorthandPropertyAssignment(parent) || !property && !isPropertyNameOf(node) && (!isNameOf(node) || isPropertyAccessExpression(parent))) identifiers.push(node);
194
215
  }
195
- if (checked && (node.kind === SyntaxKind.StringLiteral || node.kind === SyntaxKind.NoSubstitutionTemplateLiteral)) {
216
+ if (checked && isStringLiteralLikeNode(node)) {
196
217
  const { parent } = node;
197
- const member = parent.kind === SyntaxKind.ComputedPropertyName ? parent.parent : parent;
198
- if (objectMembers.has(member.kind) && member.parent.kind === SyntaxKind.ObjectLiteralExpression && (member.name === node || member.name === parent) || member.kind === SyntaxKind.BindingElement && member.parent.kind === SyntaxKind.ObjectBindingPattern && (member.propertyName === node || member.propertyName === parent)) properties.push(node);
199
- else if (parent.kind === SyntaxKind.ElementAccessExpression && parent.argumentExpression === node) identifiers.push(node);
218
+ const member = isComputedPropertyName(parent) ? parent.parent : parent;
219
+ if (isObjectMember(member) && isObjectLiteralExpression(member.parent) && (member.name === node || member.name === parent) || isBindingElement(member) && isObjectBindingPattern(member.parent) && (member.propertyName === node || member.propertyName === parent)) properties.push(node);
220
+ else if (isElementAccessExpression(parent) && parent.argumentExpression === node) identifiers.push(node);
200
221
  }
201
- if (checked && node.kind === SyntaxKind.ObjectLiteralExpression && node.properties.some((member) => member.name?.kind === SyntaxKind.ComputedPropertyName && !names.has(member.name.expression.kind))) values.push(node);
222
+ if (checked && isObjectLiteralExpression(node) && node.properties.some((member) => !isSpreadAssignment(member) && isComputedPropertyName(member.name) && !isStringLiteralLikeNode(member.name.expression))) values.push(node);
202
223
  node.forEachChild((child) => visit(child, checked));
203
224
  };
204
225
  source.forEachChild((child) => visit(child, true));
@@ -211,64 +232,62 @@ var Checker = class {
211
232
  #useValue(node) {
212
233
  const expected = this.#checker.getContextualType(node);
213
234
  if (expected === void 0) return;
214
- if (!this.#annotated.has(expected.id)) {
215
- const annotated = /* @__PURE__ */ new Map();
216
- for (const candidate of [expected, ...expected.getTypes?.() ?? []]) for (const property of this.#checker.getPropertiesOfType(candidate)) if (Object.keys(this.#requirementOf(property)).length > 0) annotated.set(property.name, property);
217
- this.#annotated.set(expected.id, [...annotated.values()]);
235
+ let annotated = this.#annotated.get(expected.id);
236
+ if (annotated === void 0) {
237
+ const found = /* @__PURE__ */ new Map();
238
+ for (const candidate of [expected, ...constituentsOf(expected)]) for (const property of this.#checker.getPropertiesOfType(candidate)) if (Object.keys(this.#requirementOf(property)).length > 0) found.set(property.name, property);
239
+ annotated = [...found.values()];
240
+ this.#annotated.set(expected.id, annotated);
218
241
  }
219
- const annotated = this.#annotated.get(expected.id);
220
242
  const type = annotated.length > 0 ? this.#checker.getTypeAtLocation(node) : void 0;
221
243
  if (type === void 0) return;
222
- const named = new Set((node.kind === SyntaxKind.ObjectLiteralExpression ? node.properties : []).map((member) => member.name?.kind === SyntaxKind.ComputedPropertyName ? member.name.expression.text : member.name?.text));
244
+ const named = new Set((isObjectLiteralExpression(node) ? node.properties : []).map(writtenName));
223
245
  for (const property of annotated) if (!named.has(property.name) && this.#checker.getPropertyOfType(type, property.name) !== void 0) this.#use(node, property, property.name);
224
246
  }
225
- #use(node, symbol, name = node.text) {
247
+ #use(node, symbol, name) {
226
248
  if (symbol === void 0) return;
227
249
  this.#useImport(symbol);
228
- const needed = this.#requirementOf(symbol);
229
- const missing = Object.keys(needed).filter((name) => !this.#covered(name, needed[name], node));
230
- if (missing.length > 0) {
250
+ const requirement = unmet(this.#requirementOf(symbol), (kind, needed) => this.#covered(kind, needed, node));
251
+ if (requirement !== void 0) {
231
252
  this.#problems.guarding = true;
232
- this.#problems.lines.add(tr("{location}: {name} needs {requirement}.", {
253
+ this.#problems.lines.add(t("availability.needs", {
233
254
  location: this.#location(node),
234
255
  name,
235
- requirement: describe(needed, missing)
256
+ requirement
236
257
  }));
237
258
  }
238
259
  }
239
260
  #useImport(symbol) {
240
- let declaration = symbol.flags & SymbolFlags.Alias ? symbol.declarations?.[0]?.resolve(this.#project) : void 0;
241
- while (declaration !== void 0 && declaration.kind !== SyntaxKind.ImportDeclaration) declaration = declaration.parent;
261
+ let declaration = symbol.flags & SymbolFlags.Alias ? symbol.declarations.at(0)?.resolve(this.#project) : void 0;
262
+ while (declaration !== void 0 && !isImportDeclaration(declaration)) declaration = isSourceFile(declaration) ? void 0 : declaration.parent;
242
263
  if (declaration !== void 0) this.#importModule(declaration);
243
264
  }
244
265
  #importModule(declaration) {
245
- if (this.#imports.has(declaration)) return;
246
- this.#imports.add(declaration);
247
266
  const name = declaration.moduleSpecifier;
248
- const module = this.#checker.getSymbolAtLocation(name)?.declarations?.[0]?.resolve(this.#project);
249
- if (module?.kind !== SyntaxKind.SourceFile || this.#files.has(module.fileName)) return;
250
- const needed = this.#moduleRequirement(module);
251
- const missing = Object.keys(needed).filter((kind) => !requirements[kind].covers(this.#minimum[kind], needed[kind]));
252
- if (missing.length > 0) this.#problems.lines.add(tr("{location}: importing {name} needs {requirement}; raise \"swiplet.minimumAPILevel\" or \"swiplet.minimumIOSVersion\" in package.json.", {
267
+ if (this.#imports.has(declaration) || name === void 0 || !isStringLiteralLikeNode(name)) return;
268
+ this.#imports.add(declaration);
269
+ const module = this.#checker.getSymbolAtLocation(name)?.declarations.at(0)?.resolve(this.#project);
270
+ if (module === void 0 || !isSourceFile(module) || this.#files.has(module.fileName)) return;
271
+ const requirement = unmet(this.#moduleRequirement(module), (kind, needed) => this.#meetsMinimum(kind, needed));
272
+ if (requirement !== void 0) this.#problems.lines.add(t("availability.importNeeds", {
253
273
  location: this.#location(name),
254
274
  name: name.text,
255
- requirement: describe(needed, missing)
275
+ requirement
256
276
  }));
257
277
  }
258
278
  #moduleRequirement(source) {
259
279
  const requirement = {};
260
- const [first] = source.statements;
261
- if (first?.kind === SyntaxKind.ImportDeclaration) for (const tag of annotationTags(first)) merge(requirement, this.#parse(tagText(tag), tag));
280
+ const first = source.statements.at(0);
281
+ if (first !== void 0 && isImportDeclaration(first)) for (const tag of annotationTags(first)) merge(requirement, this.#parse(tagText(tag), tag));
262
282
  return requirement;
263
283
  }
264
284
  #useEntry(name) {
265
285
  const symbol = this.#checker.getSymbolAtLocation(name);
266
- const needed = symbol === void 0 ? {} : this.#requirementOf(symbol);
267
- const missing = Object.keys(needed).filter((kind) => !requirements[kind].covers(this.#minimum[kind], needed[kind]));
268
- if (missing.length > 0) this.#problems.lines.add(tr("{location}: {name} is an entry of the swiplet and needs {requirement}; raise \"swiplet.minimumAPILevel\" or \"swiplet.minimumIOSVersion\" in package.json.", {
286
+ const requirement = unmet(symbol === void 0 ? {} : this.#requirementOf(symbol), (kind, needed) => this.#meetsMinimum(kind, needed));
287
+ if (requirement !== void 0) this.#problems.lines.add(t("availability.entryNeeds", {
269
288
  location: this.#location(name),
270
289
  name: name.text,
271
- requirement: describe(needed, missing)
290
+ requirement
272
291
  }));
273
292
  }
274
293
  #location(node) {
@@ -278,11 +297,11 @@ var Checker = class {
278
297
  }
279
298
  #parse(text, node) {
280
299
  const { requirement, invalid, repeated } = parseAnnotation(text);
281
- if (invalid !== void 0) this.#problems.lines.add(tr("{location}: @available has \"{entry}\"; it takes \"apiLevel <level>\" and \"iOS <version>\", separated by commas.", {
300
+ if (invalid !== void 0) this.#problems.lines.add(t("availability.invalidEntry", {
282
301
  location: this.#location(node),
283
302
  entry: invalid
284
303
  }));
285
- else if (repeated !== void 0) this.#problems.lines.add(tr("{location}: @available names {kind} twice.", {
304
+ else if (repeated !== void 0) this.#problems.lines.add(t("availability.repeatedEntry", {
286
305
  location: this.#location(node),
287
306
  kind: repeated
288
307
  }));
@@ -300,129 +319,132 @@ var Checker = class {
300
319
  }
301
320
  #requirementOf(symbol) {
302
321
  const target = this.#target(symbol);
303
- if (!this.#requirements.has(target.id)) {
304
- const requirement = {};
305
- const declaration = (target.valueDeclaration ?? target.declarations[0])?.resolve(this.#project);
322
+ let requirement = this.#requirements.get(target.id);
323
+ if (requirement === void 0) {
324
+ requirement = {};
325
+ const declaration = (target.valueDeclaration ?? target.declarations.at(0))?.resolve(this.#project);
306
326
  const external = declaration !== void 0 && !this.#files.has(sourceFileOf(declaration).fileName);
307
327
  for (const tag of this.#checker.getJsDocTagsOfSymbol(target)) if (tag.name === "available") merge(requirement, external ? this.#parse(tag.text ?? "", declaration) : parseAnnotation(tag.text ?? "").requirement);
308
328
  if (external) merge(requirement, this.#moduleRequirement(sourceFileOf(declaration)));
309
329
  this.#requirements.set(target.id, requirement);
310
330
  }
311
- return this.#requirements.get(target.id);
331
+ return requirement;
312
332
  }
313
333
  #annotationOf(node) {
314
- if (!this.#annotations.has(node)) {
315
- const requirement = {};
316
- const symbol = node.name?.kind === SyntaxKind.Identifier ? this.#checker.getSymbolAtLocation(node.name) : void 0;
334
+ let requirement = this.#annotations.get(node);
335
+ if (requirement === void 0) {
336
+ requirement = {};
337
+ const name = isArrowFunction(node) || isConstructorDeclaration(node) ? void 0 : node.name;
338
+ const symbol = name !== void 0 && isIdentifier(name) ? this.#checker.getSymbolAtLocation(name) : void 0;
317
339
  if (symbol !== void 0) merge(requirement, this.#requirementOf(symbol));
318
340
  for (const tag of annotationTags(node)) merge(requirement, parseAnnotation(tagText(tag)).requirement);
319
341
  this.#annotations.set(node, requirement);
320
342
  }
321
- return this.#annotations.get(node);
343
+ return requirement;
322
344
  }
323
345
  #propertySymbol(name) {
324
- const member = name.parent.kind === SyntaxKind.ComputedPropertyName ? name.parent.parent : name.parent;
325
- const container = member.parent;
326
- if (!this.#types.has(container)) this.#types.set(container, member.kind === SyntaxKind.BindingElement ? this.#checker.getTypeAtLocation(container) : this.#checker.getContextualType(container));
346
+ const container = (isComputedPropertyName(name.parent) ? name.parent.parent : name.parent).parent;
347
+ if (!this.#types.has(container)) this.#types.set(container, isObjectBindingPattern(container) ? this.#checker.getTypeAtLocation(container) : isObjectLiteralExpression(container) || isJsxAttributes(container) ? this.#checker.getContextualType(container) : void 0);
327
348
  const type = this.#types.get(container);
328
349
  if (type === void 0) return;
329
- for (const candidate of [type, ...type.getTypes?.() ?? []]) {
350
+ for (const candidate of [type, ...constituentsOf(type)]) {
330
351
  const property = this.#checker.getPropertyOfType(candidate, name.text);
331
352
  if (property !== void 0) return property;
332
353
  }
333
354
  }
334
- #covered(name, needed, reference) {
335
- const { covers } = requirements[name];
336
- if (covers(this.#minimum[name], needed)) return true;
355
+ #meetsMinimum(kind, needed) {
356
+ const minimum = this.#minimum[kind];
357
+ return minimum !== void 0 && requirements[kind].covers(minimum, needed);
358
+ }
359
+ #covered(kind, needed, reference) {
360
+ if (this.#meetsMinimum(kind, needed)) return true;
361
+ const { covers } = requirements[kind];
337
362
  let crossed = false;
338
- for (let child = reference, parent = reference.parent; parent; child = parent, parent = parent.parent) {
339
- const proven = this.#provenBy(parent, child, crossed)[name];
363
+ for (let child = reference; !isSourceFile(child); child = child.parent) {
364
+ const { parent } = child;
365
+ const proven = this.#provenBy(parent, child, crossed)[kind];
340
366
  if (proven !== void 0 && covers(proven, needed)) return true;
341
- crossed ||= functions.has(parent.kind);
367
+ crossed ||= isFunctionLikeDeclaration(parent);
342
368
  }
343
369
  return false;
344
370
  }
345
371
  #provenBy(parent, child, crossed) {
346
372
  const proven = {};
347
- switch (parent.kind) {
348
- case SyntaxKind.IfStatement:
349
- if (child === parent.thenStatement) merge(proven, this.#factsOf(parent.expression, true));
350
- else if (child === parent.elseStatement) merge(proven, this.#factsOf(parent.expression, false));
351
- break;
352
- case SyntaxKind.ConditionalExpression:
353
- if (child === parent.whenTrue) merge(proven, this.#factsOf(parent.condition, true));
354
- else if (child === parent.whenFalse) merge(proven, this.#factsOf(parent.condition, false));
355
- break;
356
- case SyntaxKind.BinaryExpression: if (child === parent.right) {
357
- const operator = parent.operatorToken.kind;
358
- if (operator === SyntaxKind.AmpersandAmpersandToken) merge(proven, this.#factsOf(parent.left, true));
359
- else if (operator === SyntaxKind.BarBarToken) merge(proven, this.#factsOf(parent.left, false));
360
- }
373
+ if (isIfStatement(parent)) {
374
+ if (child === parent.thenStatement) merge(proven, this.#factsOf(parent.expression, true));
375
+ else if (child === parent.elseStatement) merge(proven, this.#factsOf(parent.expression, false));
376
+ } else if (isConditionalExpression(parent)) {
377
+ if (child === parent.whenTrue) merge(proven, this.#factsOf(parent.condition, true));
378
+ else if (child === parent.whenFalse) merge(proven, this.#factsOf(parent.condition, false));
379
+ } else if (isBinaryExpression(parent) && child === parent.right) {
380
+ const operator = parent.operatorToken.kind;
381
+ if (operator === SyntaxKind.AmpersandAmpersandToken) merge(proven, this.#factsOf(parent.left, true));
382
+ else if (operator === SyntaxKind.BarBarToken) merge(proven, this.#factsOf(parent.left, false));
361
383
  }
362
- for (const statement of parent.statements ?? []) {
384
+ for (const statement of statementsOf(parent)) {
363
385
  if (statement === child) break;
364
- if (statement.kind === SyntaxKind.IfStatement && statement.elseStatement === void 0 && exits(statement.thenStatement)) merge(proven, this.#factsOf(statement.expression, false));
386
+ if (isIfStatement(statement) && statement.elseStatement === void 0 && exits(statement.thenStatement)) merge(proven, this.#factsOf(statement.expression, false));
365
387
  }
366
- if (functions.has(parent.kind) || classes.has(parent.kind) && (crossed || child.kind === SyntaxKind.PropertyDeclaration && !hasModifier(child, SyntaxKind.StaticKeyword)) || valueHolders.has(parent.kind) && crossed && child === parent.initializer) merge(proven, this.#annotationOf(parent));
388
+ if (isFunctionLikeDeclaration(parent) || isClassLikeDeclaration(parent) && (crossed || isPropertyDeclaration(child) && !hasModifier(child, SyntaxKind.StaticKeyword)) || isValueHolder(parent) && crossed && child === parent.initializer) merge(proven, this.#annotationOf(parent));
367
389
  return proven;
368
390
  }
369
391
  #factsOf(node, outcome) {
370
392
  const cache = this.#facts[Number(outcome)];
371
- if (!cache.has(node)) {
393
+ let facts = cache.get(node);
394
+ if (facts === void 0) {
372
395
  cache.set(node, {});
373
- cache.set(node, this.#computeFacts(node, outcome));
396
+ facts = this.#computeFacts(node, outcome);
397
+ cache.set(node, facts);
374
398
  }
375
- return cache.get(node);
399
+ return facts;
376
400
  }
377
401
  #computeFacts(node, outcome) {
378
- switch (node.kind) {
379
- case SyntaxKind.Identifier: {
380
- const value = this.#constant(node);
381
- return value === node ? {} : this.#factsOf(value, outcome);
382
- }
383
- case SyntaxKind.ParenthesizedExpression: return this.#factsOf(node.expression, outcome);
384
- case SyntaxKind.PrefixUnaryExpression: return node.operator === SyntaxKind.ExclamationToken ? this.#factsOf(node.operand, !outcome) : {};
385
- case SyntaxKind.CallExpression: return outcome && this.#isAvailable(node.expression) ? this.#requirementsOf(node.arguments[0]) : {};
386
- case SyntaxKind.BinaryExpression: {
387
- const operator = node.operatorToken.kind;
388
- if (operator === SyntaxKind.AmpersandAmpersandToken) return outcome ? merge(merge({}, this.#factsOf(node.left, true)), this.#factsOf(node.right, true)) : {};
389
- if (operator === SyntaxKind.BarBarToken) return outcome ? {} : merge(merge({}, this.#factsOf(node.left, false)), this.#factsOf(node.right, false));
390
- return {};
391
- }
402
+ if (isIdentifier(node)) {
403
+ const value = this.#constant(node);
404
+ return value === node ? {} : this.#factsOf(value, outcome);
405
+ }
406
+ if (isParenthesizedExpression(node)) return this.#factsOf(node.expression, outcome);
407
+ if (isPrefixUnaryExpression(node)) return node.operator === SyntaxKind.ExclamationToken ? this.#factsOf(node.operand, !outcome) : {};
408
+ if (isCallExpression(node)) return outcome && this.#isAvailable(node.expression) ? this.#requirementsOf(node.arguments.at(0)) : {};
409
+ if (isBinaryExpression(node)) {
410
+ const operator = node.operatorToken.kind;
411
+ if (operator === SyntaxKind.AmpersandAmpersandToken) return outcome ? merge(merge({}, this.#factsOf(node.left, true)), this.#factsOf(node.right, true)) : {};
412
+ if (operator === SyntaxKind.BarBarToken) return outcome ? {} : merge(merge({}, this.#factsOf(node.left, false)), this.#factsOf(node.right, false));
392
413
  }
393
414
  return {};
394
415
  }
395
416
  #constant(node) {
396
- for (const seen = /* @__PURE__ */ new Set(); node.kind === SyntaxKind.Identifier;) {
417
+ for (const seen = /* @__PURE__ */ new Set(); isIdentifier(node);) {
397
418
  const declaration = this.#symbolOf(node)?.valueDeclaration?.resolve(this.#project);
398
- if (declaration?.kind !== SyntaxKind.VariableDeclaration || declaration.initializer === void 0 || !(declaration.parent.flags & NodeFlags.Const) || seen.has(declaration)) break;
419
+ if (declaration === void 0 || !isVariableDeclaration(declaration) || declaration.initializer === void 0 || !(declaration.parent.flags & NodeFlags.Const) || seen.has(declaration)) break;
399
420
  seen.add(declaration);
400
421
  node = declaration.initializer;
401
422
  }
402
423
  return node;
403
424
  }
404
425
  #isAvailable(node) {
405
- const name = node.kind === SyntaxKind.PropertyAccessExpression ? node.name : node;
406
- return this.#available !== void 0 && name.kind === SyntaxKind.Identifier && this.#symbolOf(name)?.id === this.#available;
426
+ const name = isPropertyAccessExpression(node) ? node.name : node;
427
+ return this.#available !== void 0 && isIdentifier(name) && this.#symbolOf(name)?.id === this.#available;
407
428
  }
408
429
  #requirementsOf(argument) {
409
430
  const proven = {};
410
- for (const property of argument?.kind === SyntaxKind.ObjectLiteralExpression ? argument.properties : []) {
411
- const value = property.kind === SyntaxKind.PropertyAssignment && Object.hasOwn(requirements, property.name.text) ? this.#constant(property.initializer) : void 0;
412
- if (value?.kind === SyntaxKind.NumericLiteral) {
413
- const parsed = requirements[property.name.text].parse(String(Number(value.text)));
414
- if (parsed !== void 0) proven[property.name.text] = parsed;
415
- }
431
+ for (const property of argument !== void 0 && isObjectLiteralExpression(argument) ? argument.properties : []) {
432
+ if (!isPropertyAssignment(property) || isComputedPropertyName(property.name)) continue;
433
+ const kind = property.name.text;
434
+ if (!isKind(kind)) continue;
435
+ const value = this.#constant(property.initializer);
436
+ const parsed = isNumericLiteral(value) ? parseKind(kind, String(Number(value.text))) : void 0;
437
+ if (parsed !== void 0) Object.assign(proven, parsed);
416
438
  }
417
439
  return proven;
418
440
  }
419
441
  #availableSymbol(apiDirectory) {
420
- const declaration = this.#project.program.getSourceFile(fs.realpathSync(path.join(apiDirectory, "index.d.ts")))?.statements.find((statement) => statement.kind === SyntaxKind.FunctionDeclaration && statement.name?.text === "available");
421
- return declaration === void 0 ? void 0 : this.#checker.getSymbolAtLocation(declaration.name)?.id;
442
+ const name = this.#project.program.getSourceFile(fs.realpathSync(path.join(apiDirectory, "index.d.ts")))?.statements.filter(isFunctionDeclaration).map((statement) => statement.name).find((name) => name?.text === "available");
443
+ return name === void 0 ? void 0 : this.#checker.getSymbolAtLocation(name)?.id;
422
444
  }
423
445
  };
424
446
  function sourceFileOf(node) {
425
- while (node.kind !== SyntaxKind.SourceFile) node = node.parent;
447
+ while (!isSourceFile(node)) node = node.parent;
426
448
  return node;
427
449
  }
428
450
  export { AvailabilityChecker };