@shivaedev/quality 0.69.3 → 0.69.5
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/CHANGELOG.md +19 -0
- package/README.md +6 -6
- package/dist/adapters/biome/pluginContract.d.ts +3 -0
- package/dist/adapters/biome/pluginContract.d.ts.map +1 -0
- package/dist/adapters/biome/pluginContract.js +35 -0
- package/dist/adapters/biome/pluginContract.js.map +1 -0
- package/dist/adapters/biome/toolContractDefaults.d.ts +18 -0
- package/dist/adapters/biome/toolContractDefaults.d.ts.map +1 -0
- package/dist/adapters/biome/toolContractDefaults.js +28 -0
- package/dist/adapters/biome/toolContractDefaults.js.map +1 -0
- package/dist/adapters/buildEntryPaths.d.ts +2 -1
- package/dist/adapters/buildEntryPaths.d.ts.map +1 -1
- package/dist/adapters/buildEntryPaths.js +6 -3
- package/dist/adapters/buildEntryPaths.js.map +1 -1
- package/dist/adapters/buildEntryValue.d.ts +2 -1
- package/dist/adapters/buildEntryValue.d.ts.map +1 -1
- package/dist/adapters/buildEntryValue.js +11 -5
- package/dist/adapters/buildEntryValue.js.map +1 -1
- package/dist/adapters/buildHelper.d.ts +7 -0
- package/dist/adapters/buildHelper.d.ts.map +1 -0
- package/dist/adapters/buildHelper.js +55 -0
- package/dist/adapters/buildHelper.js.map +1 -0
- package/dist/adapters/bundlerEntries.d.ts +2 -1
- package/dist/adapters/bundlerEntries.d.ts.map +1 -1
- package/dist/adapters/bundlerEntries.js +27 -13
- package/dist/adapters/bundlerEntries.js.map +1 -1
- package/dist/adapters/bundlerSources.d.ts +5 -0
- package/dist/adapters/bundlerSources.d.ts.map +1 -0
- package/dist/adapters/bundlerSources.js +55 -0
- package/dist/adapters/bundlerSources.js.map +1 -0
- package/dist/adapters/composedContext.d.ts +1 -1
- package/dist/adapters/composedContext.d.ts.map +1 -1
- package/dist/adapters/composedContext.js +37 -16
- package/dist/adapters/composedContext.js.map +1 -1
- package/dist/adapters/foreignResources.d.ts.map +1 -1
- package/dist/adapters/foreignResources.js +6 -0
- package/dist/adapters/foreignResources.js.map +1 -1
- package/dist/adapters/imports/resolve.d.ts.map +1 -1
- package/dist/adapters/imports/resolve.js +14 -1
- package/dist/adapters/imports/resolve.js.map +1 -1
- package/dist/adapters/knip/configuration.d.ts.map +1 -1
- package/dist/adapters/knip/configuration.js +3 -1
- package/dist/adapters/knip/configuration.js.map +1 -1
- package/dist/adapters/knip/entryPointFindings.js +1 -1
- package/dist/adapters/knip/entryPointFindings.js.map +1 -1
- package/dist/adapters/moduleResolver.d.ts +3 -0
- package/dist/adapters/moduleResolver.d.ts.map +1 -0
- package/dist/adapters/moduleResolver.js +22 -0
- package/dist/adapters/moduleResolver.js.map +1 -0
- package/dist/adapters/reachableBuildEntries.d.ts.map +1 -1
- package/dist/adapters/reachableBuildEntries.js +5 -4
- package/dist/adapters/reachableBuildEntries.js.map +1 -1
- package/dist/adapters/reactComponent.d.ts +4 -0
- package/dist/adapters/reactComponent.d.ts.map +1 -0
- package/dist/adapters/reactComponent.js +61 -0
- package/dist/adapters/reactComponent.js.map +1 -0
- package/dist/adapters/serviceStateProblems.d.ts.map +1 -1
- package/dist/adapters/serviceStateProblems.js +2 -1
- package/dist/adapters/serviceStateProblems.js.map +1 -1
- package/dist/adapters/vitestContractPaths.d.ts +2 -0
- package/dist/adapters/vitestContractPaths.d.ts.map +1 -0
- package/dist/adapters/vitestContractPaths.js +24 -0
- package/dist/adapters/vitestContractPaths.js.map +1 -0
- package/dist/biome/recognizeDiagnostics.d.ts +1 -1
- package/dist/biome/recognizeDiagnostics.d.ts.map +1 -1
- package/dist/biome/recognizeDiagnostics.js +19 -5
- package/dist/biome/recognizeDiagnostics.js.map +1 -1
- package/dist/biome/report.d.ts.map +1 -1
- package/dist/biome/report.js +2 -1
- package/dist/biome/report.js.map +1 -1
- package/dist/imports/extract.d.ts.map +1 -1
- package/dist/imports/extract.js +3 -15
- package/dist/imports/extract.js.map +1 -1
- package/dist/naming/developmentCode.d.ts +4 -0
- package/dist/naming/developmentCode.d.ts.map +1 -0
- package/dist/naming/developmentCode.js +16 -0
- package/dist/naming/developmentCode.js.map +1 -0
- package/dist/naming/testCode.d.ts.map +1 -1
- package/dist/naming/testCode.js +3 -1
- package/dist/naming/testCode.js.map +1 -1
- package/dist/rules/effect/serviceFindings.d.ts.map +1 -1
- package/dist/rules/effect/serviceFindings.js +4 -0
- package/dist/rules/effect/serviceFindings.js.map +1 -1
- package/dist/rules/effect/serviceParameters.js +1 -1
- package/dist/rules/effect/serviceParameters.js.map +1 -1
- package/dist/rules/effect/serviceTypes.d.ts.map +1 -1
- package/dist/rules/effect/serviceTypes.js +1 -0
- package/dist/rules/effect/serviceTypes.js.map +1 -1
- package/dist/rules/imports/manifest.d.ts.map +1 -1
- package/dist/rules/imports/manifest.js +6 -1
- package/dist/rules/imports/manifest.js.map +1 -1
- package/dist/rules/imports/noTestCode.d.ts.map +1 -1
- package/dist/rules/imports/noTestCode.js +4 -2
- package/dist/rules/imports/noTestCode.js.map +1 -1
- package/package.json +10 -10
- package/src/adapters/biome/pluginContract.ts +42 -0
- package/src/adapters/biome/toolContractDefaults.ts +31 -0
- package/src/adapters/buildEntryPaths.ts +13 -4
- package/src/adapters/buildEntryValue.ts +13 -5
- package/src/adapters/buildHelper.ts +61 -0
- package/src/adapters/bundlerEntries.ts +38 -14
- package/src/adapters/bundlerSources.ts +60 -0
- package/src/adapters/composedContext.ts +42 -18
- package/src/adapters/foreignResources.ts +6 -0
- package/src/adapters/imports/resolve.ts +13 -0
- package/src/adapters/knip/configuration.ts +3 -1
- package/src/adapters/knip/entryPointFindings.ts +1 -1
- package/src/adapters/moduleResolver.ts +23 -0
- package/src/adapters/reachableBuildEntries.ts +5 -4
- package/src/adapters/reactComponent.ts +72 -0
- package/src/adapters/serviceStateProblems.ts +2 -1
- package/src/adapters/vitestContractPaths.ts +25 -0
- package/src/biome/recognizeDiagnostics.ts +26 -5
- package/src/biome/report.ts +2 -1
- package/src/imports/extract.ts +3 -17
- package/src/naming/developmentCode.ts +21 -0
- package/src/naming/testCode.ts +3 -1
- package/src/rules/effect/serviceFindings.ts +4 -0
- package/src/rules/effect/serviceParameters.ts +1 -1
- package/src/rules/effect/serviceTypes.ts +1 -0
- package/src/rules/imports/manifest.ts +6 -1
- package/src/rules/imports/noTestCode.ts +5 -2
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import type { Syntax } from "#biome/syntax.ts";
|
|
3
|
+
|
|
4
|
+
function pluginType(node: ts.TypeNode | undefined, { checker }: Syntax): boolean {
|
|
5
|
+
if (node === undefined || !ts.isTypeReferenceNode(node)) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
return (checker.getSymbolAtLocation(node.typeName)?.declarations ?? []).some((declaration) => {
|
|
9
|
+
if (!(ts.isImportSpecifier(declaration) && /^(?:[A-Z]\w*)?Plugin$/u.test((declaration.propertyName ?? declaration.name).text))) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
const module = declaration.parent.parent.parent.moduleSpecifier;
|
|
13
|
+
return ts.isStringLiteral(module) && !/^[.#/]/u.test(module.text);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function pluginContract({ source, checker }: Syntax): boolean {
|
|
18
|
+
if (!/(?:^|\/)adapters\//u.test(source.fileName)) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
const syntax = { checker, source };
|
|
22
|
+
function contract(node: ts.Expression): boolean {
|
|
23
|
+
if (ts.isSatisfiesExpression(node) || ts.isAsExpression(node)) {
|
|
24
|
+
return pluginType(node.type, syntax);
|
|
25
|
+
}
|
|
26
|
+
if (ts.isParenthesizedExpression(node)) {
|
|
27
|
+
return contract(node.expression);
|
|
28
|
+
}
|
|
29
|
+
return (
|
|
30
|
+
ts.isIdentifier(node)
|
|
31
|
+
&& (checker.getSymbolAtLocation(node)?.declarations ?? []).some(
|
|
32
|
+
(declaration) =>
|
|
33
|
+
ts.isVariableDeclaration(declaration)
|
|
34
|
+
&& (pluginType(declaration.type, syntax)
|
|
35
|
+
|| (declaration.initializer !== undefined
|
|
36
|
+
&& ts.isSatisfiesExpression(declaration.initializer)
|
|
37
|
+
&& pluginType(declaration.initializer.type, syntax))),
|
|
38
|
+
)
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
return source.statements.some((statement) => ts.isExportAssignment(statement) && !statement.isExportEquals && contract(statement.expression));
|
|
42
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { readPackageManifest } from "#adapters/manifestInventory.ts";
|
|
4
|
+
import { manifestReader } from "#adapters/manifestReader.ts";
|
|
5
|
+
import { vitestContractPaths } from "#adapters/vitestContractPaths.ts";
|
|
6
|
+
import type { Diagnostic } from "#biome/report.ts";
|
|
7
|
+
|
|
8
|
+
export const toolContractDefaults = Effect.fn("Biome.toolContractDefaults")(function* (root: string, diagnostics: readonly Diagnostic[]) {
|
|
9
|
+
const directories = new Set<string>();
|
|
10
|
+
for (const diagnostic of diagnostics) {
|
|
11
|
+
if (diagnostic.category !== "lint/style/noDefaultExport" || diagnostic.location.path === undefined) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
let directory = dirname(relative(root, resolve(root, diagnostic.location.path)));
|
|
15
|
+
while (!directories.has(directory)) {
|
|
16
|
+
directories.add(directory);
|
|
17
|
+
if (directory === ".") {
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
directory = dirname(directory);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const readText = yield* manifestReader(root);
|
|
24
|
+
const contracts = yield* Effect.forEach([...directories], (directory) =>
|
|
25
|
+
Effect.promise(async () => {
|
|
26
|
+
const manifest = await readPackageManifest(readText, join(directory, "package.json"));
|
|
27
|
+
return vitestContractPaths(directory, manifest?.scripts ?? {}).map((path) => resolve(root, path));
|
|
28
|
+
}),
|
|
29
|
+
);
|
|
30
|
+
return new Set(contracts.flat());
|
|
31
|
+
}, Effect.scoped);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { posix } from "node:path";
|
|
2
2
|
import ts from "typescript";
|
|
3
|
-
import { buildEntryValue, buildOption } from "./buildEntryValue.ts";
|
|
3
|
+
import { type BuildBindings, buildEntryValue, buildOption } from "./buildEntryValue.ts";
|
|
4
4
|
import { importedCall } from "./importedCall.ts";
|
|
5
5
|
|
|
6
6
|
function pathFromCall(node: ts.CallExpression, cwd: string, paths: (expression: ts.Expression) => readonly string[]): readonly string[] {
|
|
@@ -30,18 +30,27 @@ function valuesOf(node: ts.Expression): readonly ts.Expression[] {
|
|
|
30
30
|
return input === undefined ? node.properties.flatMap((property) => (ts.isPropertyAssignment(property) ? [property.initializer] : [])) : [input];
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
export function buildEntryPaths(
|
|
34
|
-
|
|
33
|
+
export function buildEntryPaths(
|
|
34
|
+
expression: ts.Expression,
|
|
35
|
+
cwd: string,
|
|
36
|
+
file: string,
|
|
37
|
+
active: ReadonlySet<ts.Node> = new Set(),
|
|
38
|
+
bindings: BuildBindings = new Map(),
|
|
39
|
+
): readonly string[] {
|
|
40
|
+
const node = buildEntryValue(expression, new Set(), bindings);
|
|
35
41
|
if (active.has(node)) {
|
|
36
42
|
return [];
|
|
37
43
|
}
|
|
38
44
|
const visited = new Set([...active, node]);
|
|
39
45
|
function paths(value: ts.Expression) {
|
|
40
|
-
return buildEntryPaths(value, cwd, file, visited);
|
|
46
|
+
return buildEntryPaths(value, cwd, file, visited, bindings);
|
|
41
47
|
}
|
|
42
48
|
if (ts.isStringLiteralLike(node)) {
|
|
43
49
|
return [node.text];
|
|
44
50
|
}
|
|
51
|
+
if (ts.isSpreadElement(node)) {
|
|
52
|
+
return paths(node.expression);
|
|
53
|
+
}
|
|
45
54
|
if (
|
|
46
55
|
(ts.isIdentifier(node) && node.text === "__dirname")
|
|
47
56
|
|| (ts.isPropertyAccessExpression(node) && node.expression.kind === ts.SyntaxKind.MetaProperty && node.name.text === "dirname")
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
|
|
3
|
+
export type BuildBindings = ReadonlyMap<ts.ParameterDeclaration, ts.Expression>;
|
|
4
|
+
|
|
3
5
|
function declaredValue(statements: readonly ts.Statement[], name: string): ts.Expression | undefined {
|
|
4
6
|
for (const statement of statements) {
|
|
5
7
|
if (!(ts.isVariableStatement(statement) && statement.declarationList.flags & ts.NodeFlags.Const)) {
|
|
@@ -13,9 +15,15 @@ function declaredValue(statements: readonly ts.Statement[], name: string): ts.Ex
|
|
|
13
15
|
return undefined;
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
function initializer(node: ts.Identifier): ts.Expression | undefined {
|
|
18
|
+
function initializer(node: ts.Identifier, bindings: BuildBindings): ts.Expression | undefined {
|
|
17
19
|
let scope: ts.Node | undefined = node.parent;
|
|
18
20
|
while (scope !== undefined) {
|
|
21
|
+
if (ts.isFunctionLike(scope)) {
|
|
22
|
+
const parameter = scope.parameters.find((entry) => ts.isIdentifier(entry.name) && entry.name.text === node.text);
|
|
23
|
+
if (parameter !== undefined) {
|
|
24
|
+
return bindings.get(parameter);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
19
27
|
const value = ts.isSourceFile(scope) || ts.isBlock(scope) ? declaredValue(scope.statements, node.text) : undefined;
|
|
20
28
|
if (value !== undefined) {
|
|
21
29
|
return value;
|
|
@@ -25,17 +33,17 @@ function initializer(node: ts.Identifier): ts.Expression | undefined {
|
|
|
25
33
|
return undefined;
|
|
26
34
|
}
|
|
27
35
|
|
|
28
|
-
export function buildEntryValue(node: ts.Expression, active: ReadonlySet<ts.Node> = new Set()): ts.Expression {
|
|
36
|
+
export function buildEntryValue(node: ts.Expression, active: ReadonlySet<ts.Node> = new Set(), bindings: BuildBindings = new Map()): ts.Expression {
|
|
29
37
|
if (active.has(node)) {
|
|
30
38
|
return node;
|
|
31
39
|
}
|
|
32
40
|
const visited = new Set([...active, node]);
|
|
33
41
|
if (ts.isIdentifier(node)) {
|
|
34
|
-
const value = initializer(node);
|
|
35
|
-
return value === undefined ? node : buildEntryValue(value, visited);
|
|
42
|
+
const value = initializer(node, bindings);
|
|
43
|
+
return value === undefined ? node : buildEntryValue(value, visited, bindings);
|
|
36
44
|
}
|
|
37
45
|
return ts.isAsExpression(node) || ts.isSatisfiesExpression(node) || ts.isParenthesizedExpression(node)
|
|
38
|
-
? buildEntryValue(node.expression, visited)
|
|
46
|
+
? buildEntryValue(node.expression, visited, bindings)
|
|
39
47
|
: node;
|
|
40
48
|
}
|
|
41
49
|
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { posix } from "node:path";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { type BuildBindings, buildEntryValue } from "./buildEntryValue.ts";
|
|
4
|
+
import { importedCall } from "./importedCall.ts";
|
|
5
|
+
|
|
6
|
+
type Helper = ts.FunctionDeclaration | ts.FunctionExpression | ts.ArrowFunction;
|
|
7
|
+
|
|
8
|
+
export function buildArguments(helper: Helper, call: ts.CallExpression, bindings: BuildBindings): BuildBindings {
|
|
9
|
+
const arguments_ = new Map(bindings);
|
|
10
|
+
for (const [index, parameter] of helper.parameters.entries()) {
|
|
11
|
+
const value = call.arguments[index] ?? parameter.initializer;
|
|
12
|
+
if (value !== undefined) {
|
|
13
|
+
arguments_.set(parameter, buildEntryValue(value, new Set(), bindings));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return arguments_;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function declared(scope: ts.SourceFile | ts.Block, name: string): Helper | undefined {
|
|
20
|
+
for (const statement of scope.statements) {
|
|
21
|
+
if (ts.isFunctionDeclaration(statement) && statement.name?.text === name) {
|
|
22
|
+
return statement;
|
|
23
|
+
}
|
|
24
|
+
if (ts.isVariableStatement(statement)) {
|
|
25
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
26
|
+
const value = declaration.initializer;
|
|
27
|
+
if (
|
|
28
|
+
ts.isIdentifier(declaration.name)
|
|
29
|
+
&& declaration.name.text === name
|
|
30
|
+
&& value !== undefined
|
|
31
|
+
&& (ts.isArrowFunction(value) || ts.isFunctionExpression(value))
|
|
32
|
+
) {
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function buildHelper(call: ts.CallExpression, sources: ReadonlyMap<string, ts.SourceFile>, bindings: BuildBindings): Helper | undefined {
|
|
42
|
+
const expression = buildEntryValue(call.expression, new Set(), bindings);
|
|
43
|
+
if (ts.isArrowFunction(expression) || ts.isFunctionExpression(expression)) {
|
|
44
|
+
return expression;
|
|
45
|
+
}
|
|
46
|
+
if (ts.isIdentifier(expression)) {
|
|
47
|
+
for (let scope: ts.Node | undefined = call.parent; scope !== undefined; scope = scope.parent) {
|
|
48
|
+
const helper = ts.isSourceFile(scope) || ts.isBlock(scope) ? declared(scope, expression.text) : undefined;
|
|
49
|
+
if (helper !== undefined) {
|
|
50
|
+
return helper;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const imported = importedCall(call);
|
|
55
|
+
if (imported === undefined || !imported.module.startsWith(".")) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
const path = posix.join(posix.dirname(call.getSourceFile().fileName), imported.module);
|
|
59
|
+
const source = sources.get(path);
|
|
60
|
+
return source === undefined ? undefined : declared(source, imported.name);
|
|
61
|
+
}
|
|
@@ -3,11 +3,18 @@ import ts from "typescript";
|
|
|
3
3
|
import type { SourceFile } from "#rule.ts";
|
|
4
4
|
import { parse } from "#rules/parse.ts";
|
|
5
5
|
import { buildEntryPaths } from "./buildEntryPaths.ts";
|
|
6
|
-
import { buildEntryValue, buildOption } from "./buildEntryValue.ts";
|
|
6
|
+
import { type BuildBindings, buildEntryValue, buildOption } from "./buildEntryValue.ts";
|
|
7
|
+
import { buildArguments, buildHelper } from "./buildHelper.ts";
|
|
7
8
|
import { importedCall } from "./importedCall.ts";
|
|
8
9
|
|
|
9
10
|
const ESBUILD = new Set(["build", "buildSync", "context"]);
|
|
10
11
|
|
|
12
|
+
function callbackBody(node: ts.Node): ts.ConciseBody | undefined {
|
|
13
|
+
return (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) && ts.isCallExpression(node.parent) && node.parent.arguments.includes(node)
|
|
14
|
+
? node.body
|
|
15
|
+
: undefined;
|
|
16
|
+
}
|
|
17
|
+
|
|
11
18
|
function entryOption(call: ts.CallExpression): string | undefined {
|
|
12
19
|
const expression = call.expression;
|
|
13
20
|
if (ts.isPropertyAccessExpression(expression) && expression.expression.getText() === "Bun" && expression.name.text === "build") {
|
|
@@ -17,37 +24,54 @@ function entryOption(call: ts.CallExpression): string | undefined {
|
|
|
17
24
|
return imported?.module === "esbuild" && ESBUILD.has(imported.name) ? "entryPoints" : undefined;
|
|
18
25
|
}
|
|
19
26
|
|
|
20
|
-
function entriesOf(call: ts.CallExpression, file: string, cwd: string): readonly string[] {
|
|
27
|
+
function entriesOf(call: ts.CallExpression, file: string, cwd: string, bindings: BuildBindings): readonly string[] {
|
|
21
28
|
const option = entryOption(call);
|
|
22
29
|
const [argument] = call.arguments;
|
|
23
|
-
const options = argument === undefined ? undefined : buildEntryValue(argument);
|
|
30
|
+
const options = argument === undefined ? undefined : buildEntryValue(argument, new Set(), bindings);
|
|
24
31
|
if (option === undefined || options === undefined || !ts.isObjectLiteralExpression(options)) {
|
|
25
32
|
return [];
|
|
26
33
|
}
|
|
27
34
|
const directory = buildOption(options, "absWorkingDir");
|
|
28
|
-
const working = directory === undefined ? cwd : buildEntryPaths(directory, cwd, file)[0];
|
|
35
|
+
const working = directory === undefined ? cwd : buildEntryPaths(directory, cwd, file, new Set(), bindings)[0];
|
|
29
36
|
if (working === undefined) {
|
|
30
37
|
return [];
|
|
31
38
|
}
|
|
32
39
|
const entries = buildOption(options, option);
|
|
33
|
-
return entries === undefined ? [] : buildEntryPaths(entries, cwd, file).map((path) => posix.resolve(cwd, working, path));
|
|
40
|
+
return entries === undefined ? [] : buildEntryPaths(entries, cwd, file, new Set(), bindings).map((path) => posix.resolve(cwd, working, path));
|
|
34
41
|
}
|
|
35
42
|
|
|
36
|
-
export function bundlerEntries(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
export function bundlerEntries(
|
|
44
|
+
file: SourceFile,
|
|
45
|
+
root: string,
|
|
46
|
+
directory: string,
|
|
47
|
+
sources: ReadonlyMap<string, ts.SourceFile> = new Map(),
|
|
48
|
+
): readonly string[] {
|
|
49
|
+
const source = sources.get(file.path) ?? parse(file);
|
|
41
50
|
if (source === undefined) {
|
|
42
51
|
return [];
|
|
43
52
|
}
|
|
44
53
|
const entries: string[] = [];
|
|
45
|
-
function visit(node: ts.Node): void {
|
|
54
|
+
function visit(node: ts.Node, bindings: BuildBindings, active: ReadonlySet<ts.Node>): void {
|
|
55
|
+
if (ts.isFunctionLike(node)) {
|
|
56
|
+
const body = callbackBody(node);
|
|
57
|
+
if (body !== undefined) {
|
|
58
|
+
visit(body, bindings, active);
|
|
59
|
+
}
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
46
62
|
if (ts.isCallExpression(node)) {
|
|
47
|
-
entries.push(
|
|
63
|
+
entries.push(
|
|
64
|
+
...entriesOf(node, posix.join(root, node.getSourceFile().fileName), posix.join(root, directory), bindings).map((path) =>
|
|
65
|
+
posix.relative(root, path),
|
|
66
|
+
),
|
|
67
|
+
);
|
|
68
|
+
const helper = buildHelper(node, sources, bindings);
|
|
69
|
+
if (helper?.body !== undefined && !active.has(helper)) {
|
|
70
|
+
visit(helper.body, buildArguments(helper, node, bindings), new Set([...active, helper]));
|
|
71
|
+
}
|
|
48
72
|
}
|
|
49
|
-
ts.forEachChild(node, visit);
|
|
73
|
+
ts.forEachChild(node, (child) => visit(child, bindings, active));
|
|
50
74
|
}
|
|
51
|
-
visit(source);
|
|
75
|
+
visit(source, new Map(), new Set());
|
|
52
76
|
return entries;
|
|
53
77
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import type { ImportGraph } from "#imports/graph.ts";
|
|
3
|
+
import type { SourceFile } from "#rule.ts";
|
|
4
|
+
import { parse } from "#rules/parse.ts";
|
|
5
|
+
|
|
6
|
+
function usesBundler(source: ts.SourceFile): boolean {
|
|
7
|
+
function visit(node: ts.Node): boolean {
|
|
8
|
+
if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier) && node.moduleSpecifier.text === "esbuild") {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "Bun" && node.name.text === "build") {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
return ts.forEachChild(node, visit) ?? false;
|
|
15
|
+
}
|
|
16
|
+
return visit(source);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function directSources(files: readonly SourceFile[]): Map<string, ts.SourceFile> {
|
|
20
|
+
const sources = new Map<string, ts.SourceFile>();
|
|
21
|
+
for (const file of files) {
|
|
22
|
+
if (!(file.text.includes("esbuild") || file.text.includes("Bun"))) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
const source = parse(file);
|
|
26
|
+
if (source !== undefined && usesBundler(source)) {
|
|
27
|
+
sources.set(file.path, source);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return sources;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function importedBy(graph: ImportGraph): ReadonlyMap<string, readonly string[]> {
|
|
34
|
+
const importers = new Map<string, string[]>();
|
|
35
|
+
for (const edge of graph.edges) {
|
|
36
|
+
if (!edge.type && edge.to.kind === "file") {
|
|
37
|
+
importers.set(edge.to.path, [...(importers.get(edge.to.path) ?? []), edge.from]);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return importers;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function bundlerSources(files: readonly SourceFile[], graph: ImportGraph): ReadonlyMap<string, ts.SourceFile> {
|
|
44
|
+
const filesByPath = new Map(files.map((file) => [file.path, file]));
|
|
45
|
+
const sources = directSources(files);
|
|
46
|
+
const importers = importedBy(graph);
|
|
47
|
+
const pending = [...sources.keys()];
|
|
48
|
+
while (pending.length > 0) {
|
|
49
|
+
const path = pending.pop();
|
|
50
|
+
for (const importer of importers.get(path ?? "") ?? []) {
|
|
51
|
+
const file = filesByPath.get(importer);
|
|
52
|
+
const source = sources.has(importer) || file === undefined ? undefined : parse(file);
|
|
53
|
+
if (source !== undefined) {
|
|
54
|
+
sources.set(importer, source);
|
|
55
|
+
pending.push(importer);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return sources;
|
|
60
|
+
}
|
|
@@ -2,6 +2,26 @@ import ts from "typescript";
|
|
|
2
2
|
import { effectApi, resolvedValue } from "#adapters/serviceModelSyntax.ts";
|
|
3
3
|
import { boundaryReference } from "#rules/effect/boundaryReference.ts";
|
|
4
4
|
|
|
5
|
+
const COMPOSERS = new Set(["effect.Context.merge", "effect/Context.merge", "effect.Scope.provide", "effect/Scope.provide"]);
|
|
6
|
+
|
|
7
|
+
function compositionInputs(checker: ts.TypeChecker, call: ts.CallExpression): readonly ts.Expression[] | undefined {
|
|
8
|
+
if (COMPOSERS.has(boundaryReference(checker, call.expression) ?? "")) {
|
|
9
|
+
return call.arguments;
|
|
10
|
+
}
|
|
11
|
+
if (ts.isCallExpression(call.expression) && COMPOSERS.has(boundaryReference(checker, call.expression.expression) ?? "")) {
|
|
12
|
+
return [...call.expression.arguments, ...call.arguments];
|
|
13
|
+
}
|
|
14
|
+
if (ts.isPropertyAccessExpression(call.expression) && call.expression.name.text === "pipe") {
|
|
15
|
+
const composers = call.arguments.filter(
|
|
16
|
+
(argument) => ts.isCallExpression(argument) && COMPOSERS.has(boundaryReference(checker, argument.expression) ?? ""),
|
|
17
|
+
);
|
|
18
|
+
if (composers.length > 0) {
|
|
19
|
+
return [call.expression.expression, ...composers.flatMap((composer) => (ts.isCallExpression(composer) ? [...composer.arguments] : []))];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
5
25
|
function closedEffect(checker: ts.TypeChecker, node: ts.Node): boolean {
|
|
6
26
|
const brand = checker.getTypeAtLocation(node).getProperty("~effect/Effect");
|
|
7
27
|
const requirement = brand === undefined ? undefined : checker.getTypeOfSymbol(brand).getProperty("_R");
|
|
@@ -17,24 +37,7 @@ function layerProvision(checker: ts.TypeChecker, node: ts.Node): boolean {
|
|
|
17
37
|
);
|
|
18
38
|
}
|
|
19
39
|
|
|
20
|
-
|
|
21
|
-
const value = resolvedValue(checker, environment);
|
|
22
|
-
if (!(ts.isYieldExpression(value) && value.expression !== undefined && ts.isCallExpression(value.expression))) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
const acquisition = value.expression;
|
|
26
|
-
const reference = boundaryReference(checker, acquisition.expression);
|
|
27
|
-
if (
|
|
28
|
-
reference === "effect.Layer.build"
|
|
29
|
-
|| reference === "effect/Layer.build"
|
|
30
|
-
|| reference === "effect.Layer.buildWithScope"
|
|
31
|
-
|| reference === "effect/Layer.buildWithScope"
|
|
32
|
-
) {
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
35
|
-
if (!effectApi(checker, acquisition.expression, "context")) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
40
|
+
function fullyProvided(checker: ts.TypeChecker, value: ts.Node): boolean {
|
|
38
41
|
let provided = false;
|
|
39
42
|
for (let ancestor: ts.Node | undefined = value.parent; ancestor !== undefined; ancestor = ancestor.parent) {
|
|
40
43
|
if (ts.isCallExpression(ancestor)) {
|
|
@@ -46,3 +49,24 @@ export function composedContext(checker: ts.TypeChecker, environment: ts.Express
|
|
|
46
49
|
}
|
|
47
50
|
return false;
|
|
48
51
|
}
|
|
52
|
+
|
|
53
|
+
export function composedContext(checker: ts.TypeChecker, environment: ts.Expression, seen = new Set<ts.Node>()): boolean {
|
|
54
|
+
const value = resolvedValue(checker, environment);
|
|
55
|
+
if (seen.has(value)) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
seen.add(value);
|
|
59
|
+
const acquisition = ts.isYieldExpression(value) ? value.expression : value;
|
|
60
|
+
if (acquisition === undefined || !ts.isCallExpression(acquisition)) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
const reference = boundaryReference(checker, acquisition.expression);
|
|
64
|
+
const inputs = compositionInputs(checker, acquisition);
|
|
65
|
+
if (inputs !== undefined) {
|
|
66
|
+
return inputs.some((argument) => composedContext(checker, argument, seen));
|
|
67
|
+
}
|
|
68
|
+
if (["effect.Layer.build", "effect/Layer.build", "effect.Layer.buildWithScope", "effect/Layer.buildWithScope"].includes(reference ?? "")) {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
return effectApi(checker, acquisition.expression, "context") && fullyProvided(checker, value);
|
|
72
|
+
}
|
|
@@ -33,6 +33,12 @@ function acquisition(checker: ts.TypeChecker, node: ts.CallExpression | ts.NewEx
|
|
|
33
33
|
if (signature?.declaration !== undefined && foreign(signature.declaration)) {
|
|
34
34
|
return true;
|
|
35
35
|
}
|
|
36
|
+
if (ts.isCallExpression(node)) {
|
|
37
|
+
const factory = resolvedValue(checker, node.expression);
|
|
38
|
+
if (ts.isFunctionLike(factory) && constructed(checker, factory, seen)) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
36
42
|
if (!(ts.isCallExpression(node) && ["promise", "tryPromise", "sync", "acquireRelease"].some((name) => effectApi(checker, node.expression, name)))) {
|
|
37
43
|
return false;
|
|
38
44
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { realpathSync } from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
2
3
|
import { dirname, join, relative } from "node:path";
|
|
3
4
|
import ts from "typescript";
|
|
4
5
|
import type { Ambient } from "#imports/ambient.ts";
|
|
@@ -47,6 +48,17 @@ function fitting(resolved: string, type: boolean): string | undefined {
|
|
|
47
48
|
return type || !isDeclarationFile(resolved) ? resolved : undefined;
|
|
48
49
|
}
|
|
49
50
|
|
|
51
|
+
function nativeResolution(request: ImportRequest, from: string): string | undefined {
|
|
52
|
+
if (request.kind !== "resolve") {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
return createRequire(from).resolve(request.specifier.replace(QUERY, ""));
|
|
57
|
+
} catch {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
50
62
|
function located(request: ImportRequest, from: string, project: Project): string | undefined {
|
|
51
63
|
const specifier = request.specifier.replace(QUERY, "");
|
|
52
64
|
if (request.kind === "type-reference") {
|
|
@@ -60,6 +72,7 @@ function located(request: ImportRequest, from: string, project: Project): string
|
|
|
60
72
|
ts.resolveModuleName(specifier, from, project.options, ts.sys, project.cache, undefined, request.mode).resolvedModule?.resolvedFileName
|
|
61
73
|
?? ts.resolveModuleName(specifier, from, project.typesOptions, assetHost, project.typesCache, undefined, request.mode).resolvedModule
|
|
62
74
|
?.resolvedFileName
|
|
75
|
+
?? nativeResolution(request, from)
|
|
63
76
|
);
|
|
64
77
|
}
|
|
65
78
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { posix } from "node:path";
|
|
2
|
+
import { isToolConfig } from "#adapters/isToolConfig.ts";
|
|
2
3
|
import { readPackageManifest } from "#adapters/manifestInventory.ts";
|
|
3
4
|
import { scriptPaths } from "#adapters/scriptPaths.ts";
|
|
4
5
|
import { exportedModule, exportTargets } from "#imports/packageExports.ts";
|
|
@@ -47,6 +48,7 @@ export async function knipConfiguration(inputs: RuleInputs, toolOwned: readonly
|
|
|
47
48
|
(path) => bins.includes(path) || bins.includes(path.replace(/^src\//u, "dist/").replace(/\.(?<mode>[cm]?)tsx?$/u, ".$<mode>js")),
|
|
48
49
|
);
|
|
49
50
|
const publicFiles = sources.filter((path) => exportedModule(manifest.exports, path));
|
|
51
|
+
const configs = sources.filter(isToolConfig);
|
|
50
52
|
// Migration runners load these files from their directory, so no import reaches them.
|
|
51
53
|
const migrations = sources.filter((path) => /(?:^|\/)server\/migrations\//u.test(path));
|
|
52
54
|
const ui = toolOwned.filter((file) => (packageOf(packages, file)?.directory ?? ".") === directory).map((file) => posix.relative(directory, file));
|
|
@@ -56,7 +58,7 @@ export async function knipConfiguration(inputs: RuleInputs, toolOwned: readonly
|
|
|
56
58
|
return [
|
|
57
59
|
directory,
|
|
58
60
|
{
|
|
59
|
-
entry: [...ENTRIES, ...publicFiles, ...migrations, ...bins, ...binaries, ...scriptEntries, ...bundled, ...ui, ...styles],
|
|
61
|
+
entry: [...ENTRIES, ...publicFiles, ...configs, ...migrations, ...bins, ...binaries, ...scriptEntries, ...bundled, ...ui, ...styles],
|
|
60
62
|
paths: importPaths(manifest.imports ?? {}),
|
|
61
63
|
project: [...sources, ...ui, ...styles],
|
|
62
64
|
vitest: { config: ["vitest*.config.{ts,mts,cts,js,mjs,cjs}", "vitest.{workspace,projects}.{ts,mts,cts,js,mjs,cjs,json}"] },
|
|
@@ -71,7 +71,7 @@ export const entryPointFindings = Effect.fn("Knip.entryPointFindings")(function*
|
|
|
71
71
|
const consumer = owner(edge.from);
|
|
72
72
|
const supplied = provider(policies.get(consumer) ?? [], target, development(consumer, edge.from), true);
|
|
73
73
|
return consumer === directory
|
|
74
|
-
? supplied?.name === name
|
|
74
|
+
? (edge.kind === "resolve" && target === name) || supplied?.name === name
|
|
75
75
|
: supplied !== undefined && workspace.get(supplied.name) === directory && target === name;
|
|
76
76
|
});
|
|
77
77
|
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { importedCall } from "./importedCall.ts";
|
|
3
|
+
|
|
4
|
+
function isImportMeta(node: ts.Expression): boolean {
|
|
5
|
+
return ts.isMetaProperty(node) && node.keywordToken === ts.SyntaxKind.ImportKeyword && node.name.text === "meta";
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function moduleResolver(call: ts.CallExpression): "meta" | "require" | undefined {
|
|
9
|
+
const callee = call.expression;
|
|
10
|
+
if (!ts.isPropertyAccessExpression(callee) || callee.name.text !== "resolve") {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
if (ts.isIdentifier(callee.expression) && callee.expression.text === "require") {
|
|
14
|
+
return "require";
|
|
15
|
+
}
|
|
16
|
+
if (ts.isCallExpression(callee.expression)) {
|
|
17
|
+
const factory = importedCall(callee.expression);
|
|
18
|
+
if (factory?.name === "createRequire" && /^(?:node:)?module$/u.test(factory.module)) {
|
|
19
|
+
return "require";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return isImportMeta(callee.expression) ? "meta" : undefined;
|
|
23
|
+
}
|
|
@@ -2,6 +2,7 @@ import type { ImportGraph } from "#imports/graph.ts";
|
|
|
2
2
|
import type { PackageLayout } from "#naming/packageLayout.ts";
|
|
3
3
|
import type { RuleInputs } from "#rule.ts";
|
|
4
4
|
import { bundlerEntries } from "./bundlerEntries.ts";
|
|
5
|
+
import { bundlerSources } from "./bundlerSources.ts";
|
|
5
6
|
import { spawnedEntries } from "./spawnedEntries.ts";
|
|
6
7
|
|
|
7
8
|
function scriptsByPackage(layout: PackageLayout): ReadonlyMap<string, readonly string[]> {
|
|
@@ -41,6 +42,7 @@ function importsOf(graph: ImportGraph): ReadonlyMap<string, readonly string[]> {
|
|
|
41
42
|
export function reachableBuildEntries(inputs: RuleInputs, graph: ImportGraph, layout: PackageLayout): ReadonlySet<string> {
|
|
42
43
|
const imports = importsOf(graph);
|
|
43
44
|
const sources = new Map(inputs.sources.map((source) => [source.path, source]));
|
|
45
|
+
const syntax = bundlerSources(inputs.sources, graph);
|
|
44
46
|
const entries = new Set<string>();
|
|
45
47
|
for (const [directory, scripts] of scriptsByPackage(layout)) {
|
|
46
48
|
for (const path of reachable(scripts, imports)) {
|
|
@@ -48,10 +50,9 @@ export function reachableBuildEntries(inputs: RuleInputs, graph: ImportGraph, la
|
|
|
48
50
|
if (source === undefined) {
|
|
49
51
|
continue;
|
|
50
52
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
53
|
+
const bundled = syntax.has(path) ? bundlerEntries(source, inputs.root, directory, syntax) : [];
|
|
54
|
+
for (const entry of [...bundled, ...spawnedEntries(source, inputs.root, directory)].filter((target) => sources.has(target))) {
|
|
55
|
+
entries.add(entry);
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { browserLibraryType } from "#adapters/browserLibraryType.ts";
|
|
3
|
+
|
|
4
|
+
function reactResult(type: ts.Type): boolean {
|
|
5
|
+
const named = [type.getSymbol(), type.aliasSymbol].some(
|
|
6
|
+
(symbol) =>
|
|
7
|
+
["ReactNode", "ReactElement", "Element", "ReactPortal"].includes(symbol?.name ?? "")
|
|
8
|
+
&& (symbol?.declarations ?? []).some((declaration) =>
|
|
9
|
+
/\/node_modules\/(?:@types\/)?react\//u.test(declaration.getSourceFile().fileName.replaceAll("\\", "/")),
|
|
10
|
+
),
|
|
11
|
+
);
|
|
12
|
+
if (named || !type.isUnion()) {
|
|
13
|
+
return named;
|
|
14
|
+
}
|
|
15
|
+
const elements = type.types.filter(
|
|
16
|
+
(part) =>
|
|
17
|
+
!(part.flags & (ts.TypeFlags.Null | ts.TypeFlags.Undefined | ts.TypeFlags.StringLike | ts.TypeFlags.NumberLike | ts.TypeFlags.BooleanLike)),
|
|
18
|
+
);
|
|
19
|
+
return elements.length > 0 && elements.every(reactResult);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function reactComponent(checker: ts.TypeChecker, node: ts.Node): boolean {
|
|
23
|
+
if (!(ts.isFunctionDeclaration(node) || ts.isArrowFunction(node) || ts.isFunctionExpression(node)) || node.parameters.length !== 1) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
const declaration = ts.isVariableDeclaration(node.parent) ? node.parent : node;
|
|
27
|
+
const name = declaration.name;
|
|
28
|
+
const statement = ts.isVariableDeclaration(declaration) ? declaration.parent.parent : declaration;
|
|
29
|
+
if (name === undefined || !ts.isIdentifier(name) || !/^[A-Z]/u.test(name.text) || !ts.isSourceFile(statement.parent)) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
const signature = checker.getSignatureFromDeclaration(node);
|
|
33
|
+
return signature !== undefined && reactResult(signature.getReturnType());
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function propSignature(signature: ts.Signature): readonly ts.ParameterDeclaration[] {
|
|
37
|
+
const declaration = signature.declaration;
|
|
38
|
+
return declaration !== undefined
|
|
39
|
+
&& (ts.isFunctionTypeNode(declaration) || ts.isMethodSignature(declaration) || ts.isCallSignatureDeclaration(declaration))
|
|
40
|
+
? declaration.parameters
|
|
41
|
+
: [];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function reactPropParameters(checker: ts.TypeChecker, sources: readonly ts.SourceFile[]): ReadonlySet<ts.ParameterDeclaration> {
|
|
45
|
+
const parameters = new Set<ts.ParameterDeclaration>();
|
|
46
|
+
const seen = new Set<ts.Type>();
|
|
47
|
+
function props(type: ts.Type): void {
|
|
48
|
+
if (seen.has(type) || browserLibraryType(type)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
seen.add(type);
|
|
52
|
+
for (const signature of type.getCallSignatures()) {
|
|
53
|
+
for (const parameter of propSignature(signature)) {
|
|
54
|
+
parameters.add(parameter);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (type.isUnionOrIntersection()) {
|
|
58
|
+
type.types.forEach(props);
|
|
59
|
+
}
|
|
60
|
+
for (const property of type.getProperties()) {
|
|
61
|
+
props(checker.getTypeOfSymbol(property));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function visit(node: ts.Node): void {
|
|
65
|
+
if (reactComponent(checker, node) && ts.isFunctionLike(node) && node.parameters[0] !== undefined) {
|
|
66
|
+
props(checker.getTypeAtLocation(node.parameters[0]));
|
|
67
|
+
}
|
|
68
|
+
ts.forEachChild(node, visit);
|
|
69
|
+
}
|
|
70
|
+
sources.forEach(visit);
|
|
71
|
+
return parameters;
|
|
72
|
+
}
|