@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.
- package/dist/availability.d.ts +3 -1
- package/dist/availability.js +173 -151
- package/dist/availability.js.map +1 -1
- package/dist/cli/cli.js +52 -66
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/command.d.ts +9 -0
- package/dist/cli/command.js.map +1 -1
- package/dist/cli/commands/data/clear.js +2 -2
- package/dist/cli/commands/data/clear.js.map +1 -1
- package/dist/cli/commands/data/data.js +2 -2
- package/dist/cli/commands/data/data.js.map +1 -1
- package/dist/cli/commands/data/list.js +3 -3
- package/dist/cli/commands/data/list.js.map +1 -1
- package/dist/cli/commands/data/operand.js.map +1 -1
- package/dist/cli/commands/data/read.js +4 -7
- package/dist/cli/commands/data/read.js.map +1 -1
- package/dist/cli/commands/data/remove.js +3 -3
- package/dist/cli/commands/data/remove.js.map +1 -1
- package/dist/cli/commands/data/write.js +2 -2
- package/dist/cli/commands/data/write.js.map +1 -1
- package/dist/cli/commands/device/add.js +2 -2
- package/dist/cli/commands/device/add.js.map +1 -1
- package/dist/cli/commands/device/device.js +2 -2
- package/dist/cli/commands/device/device.js.map +1 -1
- package/dist/cli/commands/device/list.js +2 -2
- package/dist/cli/commands/device/list.js.map +1 -1
- package/dist/cli/commands/device/logs.js +44 -46
- package/dist/cli/commands/device/logs.js.map +1 -1
- package/dist/cli/commands/device/remove.js +2 -2
- package/dist/cli/commands/device/remove.js.map +1 -1
- package/dist/cli/commands/device/stop.js +3 -3
- package/dist/cli/commands/device/stop.js.map +1 -1
- package/dist/cli/commands/driver/driver.js +6 -6
- package/dist/cli/commands/driver/driver.js.map +1 -1
- package/dist/cli/commands/flags.js +9 -9
- package/dist/cli/commands/flags.js.map +1 -1
- package/dist/cli/commands/index.js +2 -2
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/commands/project/build.js +2 -2
- package/dist/cli/commands/project/build.js.map +1 -1
- package/dist/cli/commands/project/create.js +3 -3
- package/dist/cli/commands/project/create.js.map +1 -1
- package/dist/cli/commands/project/deploy.js +2 -2
- package/dist/cli/commands/project/deploy.js.map +1 -1
- package/dist/cli/commands/project/develop.js +19 -19
- package/dist/cli/commands/project/develop.js.map +1 -1
- package/dist/cli/commands/project/project.js +2 -2
- package/dist/cli/commands/project/project.js.map +1 -1
- package/dist/cli/commands/project/source.js +62 -37
- package/dist/cli/commands/project/source.js.map +1 -1
- package/dist/cli/commands/repl/api.js +2 -2
- package/dist/cli/commands/repl/api.js.map +1 -1
- package/dist/cli/commands/repl/repl.js +4 -4
- package/dist/cli/commands/repl/repl.js.map +1 -1
- package/dist/cli/commands/repl/reset.js +2 -2
- package/dist/cli/commands/repl/reset.js.map +1 -1
- package/dist/cli/commands/repl/run.js +5 -5
- package/dist/cli/commands/repl/run.js.map +1 -1
- package/dist/cli/commands/sideload/install.js +4 -4
- package/dist/cli/commands/sideload/install.js.map +1 -1
- package/dist/cli/commands/sideload/setup.js +3 -3
- package/dist/cli/commands/sideload/setup.js.map +1 -1
- package/dist/cli/commands/sideload/sideload.js +2 -2
- package/dist/cli/commands/sideload/sideload.js.map +1 -1
- package/dist/cli/commands/sideload/uninstall.js +2 -2
- package/dist/cli/commands/sideload/uninstall.js.map +1 -1
- package/dist/cli/commands/sideload/update.js +3 -3
- package/dist/cli/commands/sideload/update.js.map +1 -1
- package/dist/cli/commands/swiplet/call.js +6 -6
- package/dist/cli/commands/swiplet/call.js.map +1 -1
- package/dist/cli/commands/swiplet/install.js +3 -3
- package/dist/cli/commands/swiplet/install.js.map +1 -1
- package/dist/cli/commands/swiplet/list.js +8 -8
- package/dist/cli/commands/swiplet/list.js.map +1 -1
- package/dist/cli/commands/swiplet/remove.js +3 -3
- package/dist/cli/commands/swiplet/remove.js.map +1 -1
- package/dist/cli/commands/swiplet/service/disable.js +3 -3
- package/dist/cli/commands/swiplet/service/disable.js.map +1 -1
- package/dist/cli/commands/swiplet/service/enable.js +3 -3
- package/dist/cli/commands/swiplet/service/enable.js.map +1 -1
- package/dist/cli/commands/swiplet/service/service.js +2 -2
- package/dist/cli/commands/swiplet/service/service.js.map +1 -1
- package/dist/cli/commands/swiplet/service/services.js +2 -2
- package/dist/cli/commands/swiplet/service/services.js.map +1 -1
- package/dist/cli/commands/swiplet/service/watch.js +2 -2
- package/dist/cli/commands/swiplet/service/watch.js.map +1 -1
- package/dist/cli/commands/swiplet/show.js +6 -6
- package/dist/cli/commands/swiplet/show.js.map +1 -1
- package/dist/cli/commands/swiplet/swiplet.js +4 -4
- package/dist/cli/commands/swiplet/swiplet.js.map +1 -1
- package/dist/cli/commands/version/version.js +2 -2
- package/dist/cli/commands/version/version.js.map +1 -1
- package/dist/cli/deploy.js +9 -7
- package/dist/cli/deploy.js.map +1 -1
- package/dist/cli/session.js.map +1 -1
- package/dist/client.d.ts +145 -7
- package/dist/client.js +20 -22
- package/dist/client.js.map +1 -1
- package/dist/connection.d.ts +292 -25
- package/dist/connection.js +36 -35
- package/dist/connection.js.map +1 -1
- package/dist/driver.d.ts +62 -23
- package/dist/driver.js +29 -33
- package/dist/driver.js.map +1 -1
- package/dist/i18n.d.ts +2 -5
- package/dist/i18n.js +15 -13
- package/dist/i18n.js.map +1 -1
- package/dist/i18next.d.ts +7 -0
- package/dist/ignore.d.ts +14 -7
- package/dist/ignore.js +13 -14
- package/dist/ignore.js.map +1 -1
- package/dist/mdns.d.ts +2 -2
- package/dist/mdns.js +1 -1
- package/dist/mdns.js.map +1 -1
- package/dist/metro.d.ts +19 -5
- package/dist/metro.js +61 -63
- package/dist/metro.js.map +1 -1
- package/dist/output.d.ts +29 -14
- package/dist/output.js +17 -15
- package/dist/output.js.map +1 -1
- package/dist/passcode.d.ts +12 -8
- package/dist/passcode.js +18 -18
- package/dist/passcode.js.map +1 -1
- package/dist/project.d.ts +20 -10
- package/dist/project.js +72 -49
- package/dist/project.js.map +1 -1
- package/dist/proto/common_pb.d.ts +240 -0
- package/dist/proto/common_pb.js +7 -2
- package/dist/proto/common_pb.js.map +1 -1
- package/dist/proto/logs_pb.d.ts +38 -0
- package/dist/proto/repl_pb.d.ts +96 -0
- package/dist/proto/swiplets_pb.d.ts +361 -0
- package/dist/proto/swiplets_pb.js +7 -2
- package/dist/proto/swiplets_pb.js.map +1 -1
- package/dist/proto/system_pb.d.ts +33 -0
- package/dist/resources.d.ts +400 -0
- package/dist/serve.d.ts +9 -1
- package/dist/serve.js +17 -16
- package/dist/serve.js.map +1 -1
- package/dist/sideload.d.ts +27 -14
- package/dist/sideload.js +102 -89
- package/dist/sideload.js.map +1 -1
- package/dist/swipt-app.d.ts +19 -9
- package/dist/swipt-app.js +1 -1
- package/dist/swipt-app.js.map +1 -1
- package/locales/ar/translation.json +413 -0
- package/locales/bg/translation.json +397 -0
- package/locales/bn/translation.json +397 -0
- package/locales/ca/translation.json +401 -0
- package/locales/cs/translation.json +405 -0
- package/locales/da/translation.json +397 -0
- package/locales/de/translation.json +397 -0
- package/locales/el/translation.json +397 -0
- package/locales/en/translation.json +397 -0
- package/locales/es/translation.json +401 -0
- package/locales/es-419/translation.json +401 -0
- package/locales/fi/translation.json +397 -0
- package/locales/fr/translation.json +401 -0
- package/locales/fr-CA/translation.json +401 -0
- package/locales/gu/translation.json +397 -0
- package/locales/he/translation.json +401 -0
- package/locales/hi/translation.json +397 -0
- package/locales/hr/translation.json +401 -0
- package/locales/hu/translation.json +397 -0
- package/locales/id/translation.json +393 -0
- package/locales/it/translation.json +401 -0
- package/locales/ja/translation.json +393 -0
- package/locales/kk/translation.json +397 -0
- package/locales/kn/translation.json +397 -0
- package/locales/ko/translation.json +393 -0
- package/locales/lt/translation.json +405 -0
- package/locales/ml/translation.json +397 -0
- package/locales/mr/translation.json +397 -0
- package/locales/ms/translation.json +393 -0
- package/locales/nb/translation.json +397 -0
- package/locales/nl/translation.json +397 -0
- package/locales/or/translation.json +397 -0
- package/locales/pa/translation.json +397 -0
- package/locales/pl/translation.json +405 -0
- package/locales/pt-BR/translation.json +401 -0
- package/locales/pt-PT/translation.json +401 -0
- package/locales/ro/translation.json +401 -0
- package/locales/ru/translation.json +405 -0
- package/locales/sk/translation.json +405 -0
- package/locales/sl/translation.json +405 -0
- package/locales/sv/translation.json +397 -0
- package/locales/ta/translation.json +397 -0
- package/locales/te/translation.json +397 -0
- package/locales/th/translation.json +393 -0
- package/locales/tr/translation.json +397 -0
- package/locales/uk/translation.json +405 -0
- package/locales/ur/translation.json +397 -0
- package/locales/vi/translation.json +397 -0
- package/locales/zh-HK/translation.json +393 -0
- package/locales/zh-Hans/translation.json +393 -0
- package/locales/zh-Hant/translation.json +393 -0
- package/package.json +14 -9
- package/locales/ar.json +0 -311
- package/locales/bg.json +0 -295
- package/locales/bn.json +0 -295
- package/locales/ca.json +0 -299
- package/locales/cs.json +0 -303
- package/locales/da.json +0 -295
- package/locales/de.json +0 -295
- package/locales/el.json +0 -295
- package/locales/es-419.json +0 -299
- package/locales/es.json +0 -299
- package/locales/fi.json +0 -295
- package/locales/fr-CA.json +0 -299
- package/locales/fr.json +0 -299
- package/locales/gu.json +0 -295
- package/locales/he.json +0 -299
- package/locales/hi.json +0 -295
- package/locales/hr.json +0 -299
- package/locales/hu.json +0 -295
- package/locales/id.json +0 -283
- package/locales/it.json +0 -299
- package/locales/ja.json +0 -283
- package/locales/kk.json +0 -295
- package/locales/kn.json +0 -295
- package/locales/ko.json +0 -283
- package/locales/lt.json +0 -303
- package/locales/ml.json +0 -295
- package/locales/mr.json +0 -295
- package/locales/ms.json +0 -283
- package/locales/nb.json +0 -295
- package/locales/nl.json +0 -295
- package/locales/or.json +0 -295
- package/locales/pa.json +0 -295
- package/locales/pl.json +0 -303
- package/locales/pt-BR.json +0 -299
- package/locales/pt-PT.json +0 -299
- package/locales/ro.json +0 -299
- package/locales/ru.json +0 -303
- package/locales/sk.json +0 -303
- package/locales/sl.json +0 -303
- package/locales/sv.json +0 -295
- package/locales/ta.json +0 -295
- package/locales/te.json +0 -295
- package/locales/th.json +0 -283
- package/locales/tr.json +0 -295
- package/locales/uk.json +0 -303
- package/locales/ur.json +0 -295
- package/locales/vi.json +0 -295
- package/locales/zh-HK.json +0 -283
- package/locales/zh-Hans.json +0 -283
- package/locales/zh-Hant.json +0 -283
package/dist/availability.d.ts
CHANGED
package/dist/availability.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { language,
|
|
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) =>
|
|
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
|
|
37
|
+
for (const kind of kindsOf(from)) mergeKind(into, from, kind);
|
|
24
38
|
return into;
|
|
25
39
|
};
|
|
26
|
-
const
|
|
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 &&
|
|
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
|
-
|
|
56
|
+
const repeated = kindsOf(parsed).find((name) => requirement[name] !== void 0);
|
|
57
|
+
if (repeated !== void 0) return {
|
|
37
58
|
requirement,
|
|
38
|
-
repeated
|
|
59
|
+
repeated
|
|
39
60
|
};
|
|
40
|
-
requirement
|
|
61
|
+
Object.assign(requirement, parsed);
|
|
41
62
|
}
|
|
42
63
|
return { requirement };
|
|
43
64
|
}
|
|
44
|
-
const tagText = (tag) =>
|
|
45
|
-
const annotationTags = (node) => (node.jsDoc ?? []).flatMap((comment) => (comment.tags ?? []).filter((tag) => tag.tagName.text === "available"));
|
|
46
|
-
const exits = (statement) =>
|
|
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
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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) =>
|
|
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 ? [
|
|
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(
|
|
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
|
|
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
|
|
165
|
-
const
|
|
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 ||
|
|
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
|
|
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
|
|
187
|
-
else if (node
|
|
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
|
|
210
|
+
if (checked && isIdentifier(node)) {
|
|
190
211
|
const { parent } = node;
|
|
191
|
-
const property = parent
|
|
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
|
|
214
|
+
if (isShorthandPropertyAssignment(parent) || !property && !isPropertyNameOf(node) && (!isNameOf(node) || isPropertyAccessExpression(parent))) identifiers.push(node);
|
|
194
215
|
}
|
|
195
|
-
if (checked && (node
|
|
216
|
+
if (checked && isStringLiteralLikeNode(node)) {
|
|
196
217
|
const { parent } = node;
|
|
197
|
-
const member = parent
|
|
198
|
-
if (
|
|
199
|
-
else if (parent
|
|
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
|
|
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
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
this.#
|
|
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
|
|
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
|
|
247
|
+
#use(node, symbol, name) {
|
|
226
248
|
if (symbol === void 0) return;
|
|
227
249
|
this.#useImport(symbol);
|
|
228
|
-
const
|
|
229
|
-
|
|
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(
|
|
253
|
+
this.#problems.lines.add(t("availability.needs", {
|
|
233
254
|
location: this.#location(node),
|
|
234
255
|
name,
|
|
235
|
-
requirement
|
|
256
|
+
requirement
|
|
236
257
|
}));
|
|
237
258
|
}
|
|
238
259
|
}
|
|
239
260
|
#useImport(symbol) {
|
|
240
|
-
let declaration = symbol.flags & SymbolFlags.Alias ? symbol.declarations
|
|
241
|
-
while (declaration !== void 0 && declaration
|
|
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
|
-
|
|
249
|
-
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
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
|
|
275
|
+
requirement
|
|
256
276
|
}));
|
|
257
277
|
}
|
|
258
278
|
#moduleRequirement(source) {
|
|
259
279
|
const requirement = {};
|
|
260
|
-
const
|
|
261
|
-
if (first
|
|
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
|
|
267
|
-
|
|
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
|
|
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(
|
|
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(
|
|
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
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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
|
|
331
|
+
return requirement;
|
|
312
332
|
}
|
|
313
333
|
#annotationOf(node) {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
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
|
|
343
|
+
return requirement;
|
|
322
344
|
}
|
|
323
345
|
#propertySymbol(name) {
|
|
324
|
-
const
|
|
325
|
-
|
|
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
|
|
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
|
-
#
|
|
335
|
-
const
|
|
336
|
-
|
|
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
|
|
339
|
-
const
|
|
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 ||=
|
|
367
|
+
crossed ||= isFunctionLikeDeclaration(parent);
|
|
342
368
|
}
|
|
343
369
|
return false;
|
|
344
370
|
}
|
|
345
371
|
#provenBy(parent, child, crossed) {
|
|
346
372
|
const proven = {};
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
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
|
|
384
|
+
for (const statement of statementsOf(parent)) {
|
|
363
385
|
if (statement === child) break;
|
|
364
|
-
if (statement
|
|
386
|
+
if (isIfStatement(statement) && statement.elseStatement === void 0 && exits(statement.thenStatement)) merge(proven, this.#factsOf(statement.expression, false));
|
|
365
387
|
}
|
|
366
|
-
if (
|
|
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
|
-
|
|
393
|
+
let facts = cache.get(node);
|
|
394
|
+
if (facts === void 0) {
|
|
372
395
|
cache.set(node, {});
|
|
373
|
-
|
|
396
|
+
facts = this.#computeFacts(node, outcome);
|
|
397
|
+
cache.set(node, facts);
|
|
374
398
|
}
|
|
375
|
-
return
|
|
399
|
+
return facts;
|
|
376
400
|
}
|
|
377
401
|
#computeFacts(node, outcome) {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
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
|
|
417
|
+
for (const seen = /* @__PURE__ */ new Set(); isIdentifier(node);) {
|
|
397
418
|
const declaration = this.#symbolOf(node)?.valueDeclaration?.resolve(this.#project);
|
|
398
|
-
if (declaration
|
|
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
|
|
406
|
-
return this.#available !== void 0 && name
|
|
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
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
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
|
|
421
|
-
return
|
|
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
|
|
447
|
+
while (!isSourceFile(node)) node = node.parent;
|
|
426
448
|
return node;
|
|
427
449
|
}
|
|
428
450
|
export { AvailabilityChecker };
|