@starci/eslint-canon-be 3.11.10 → 3.11.14
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 +18 -0
- package/dist/builders.js +30 -2
- package/dist/lib/builder-provenance.d.ts +3 -0
- package/dist/lib/builder-provenance.js +45 -0
- package/dist/lib/subject-values.js +7 -7
- package/package.json +1 -1
- package/runtime/knowledge/hfs/canon-pins.yaml +6 -6
- package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +47 -3
- package/runtime/scripts/hfs/architecture/contracts.mjs +3 -0
- package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +19 -5
- package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 3.11.14 - 2026-11-02
|
|
4
|
+
|
|
5
|
+
- Fixed: canonical test builders accept repeated override literals by proving the actual kit factory through imports and immutable value aliases. Repeated raw entity rows, arbitrary partial-row callbacks and callable type annotations remain checked.
|
|
6
|
+
|
|
7
|
+
## 3.11.13
|
|
8
|
+
|
|
9
|
+
- Changed: Align bundled canon pins and exact sibling requirements with Grammar and its lint families at 0.21.6. Runtime behavior and rule severity are unchanged.
|
|
10
|
+
|
|
3
11
|
## Unreleased
|
|
4
12
|
|
|
13
|
+
## 3.11.12 - 2026-11-02
|
|
14
|
+
|
|
15
|
+
- Fixed: unit-spec subject discovery resolves callable re-exports through the canonical HFS provenance owner, including namespace and renamed exports, without relaxing real subject invocation requirements.
|
|
16
|
+
- Changed: bundled pins follow HFS 5.0.1 and the coherent canon cohort.
|
|
17
|
+
|
|
18
|
+
## 3.11.11 - 2026-11-02
|
|
19
|
+
|
|
20
|
+
- Changed: refreshed bundled canonical pins for the HFS 5.0.0 CLI selector cohort; the Grammar component runtime stays at 0.21.3.
|
|
21
|
+
- Fixed: TypeORM read-query selectors retain their query shape instead of being treated as entity row fixtures; actual entity and partial row literals remain checked.
|
|
22
|
+
|
|
5
23
|
## 3.11.10 - 2026-11-02
|
|
6
24
|
|
|
7
25
|
- Changed: bundled canonical pins follow the consolidated Grammar 0.21.3 preservation API cohort; runtime rules are unchanged.
|
package/dist/builders.js
CHANGED
|
@@ -20,6 +20,7 @@ import ts from "typescript";
|
|
|
20
20
|
import { INSERTING_SQL, isDatabaseReceiver, methodOf, queryText, WRITING_SQL } from "./lib/db-writes.js";
|
|
21
21
|
import { hfsOf } from "./lib/hfs.js";
|
|
22
22
|
import { moduleOf, resolvedSymbol, typed } from "./lib/types.js";
|
|
23
|
+
import { isKitBuilderOverride } from "./lib/builder-provenance.js";
|
|
23
24
|
/** The file name of a linted path, in forward-slash form. */
|
|
24
25
|
const baseOf = (filename) => basename(String(filename || "").replace(/\\/g, "/"));
|
|
25
26
|
// -- spec-no-raw-insert ----------------------------------------------------------------------------
|
|
@@ -76,12 +77,37 @@ const isEntityClass = (checker, declaration) => {
|
|
|
76
77
|
return (target?.getDeclarations?.() ?? []).some((found) => moduleOf(found, String(found.getSourceFile().fileName).replace(/\\/g, "/")) === "typeorm");
|
|
77
78
|
});
|
|
78
79
|
};
|
|
79
|
-
/**
|
|
80
|
+
/** A TypeORM FindOptions contract selects rows; its entity argument does not turn the selector into a row. */
|
|
81
|
+
const isFindOptionsDeclaration = (checker, declaration, seen) => {
|
|
82
|
+
if (seen.has(declaration))
|
|
83
|
+
return false;
|
|
84
|
+
seen.add(declaration);
|
|
85
|
+
const file = String(declaration.getSourceFile().fileName).replace(/\\/g, "/");
|
|
86
|
+
if ((ts.isTypeAliasDeclaration(declaration) || ts.isInterfaceDeclaration(declaration)) && declaration.name.text.startsWith("FindOptions") && moduleOf(declaration, file) === "typeorm")
|
|
87
|
+
return true;
|
|
88
|
+
if (!ts.isTypeAliasDeclaration(declaration))
|
|
89
|
+
return false;
|
|
90
|
+
const selectorReference = (node) => {
|
|
91
|
+
if (ts.isParenthesizedTypeNode(node))
|
|
92
|
+
return selectorReference(node.type);
|
|
93
|
+
if (ts.isUnionTypeNode(node) || ts.isIntersectionTypeNode(node))
|
|
94
|
+
return node.types.some(selectorReference);
|
|
95
|
+
if (!ts.isTypeReferenceNode(node))
|
|
96
|
+
return false;
|
|
97
|
+
const symbol = checker.getSymbolAtLocation(node.typeName);
|
|
98
|
+
if (!symbol)
|
|
99
|
+
return false;
|
|
100
|
+
return (resolvedSymbol(checker, symbol)?.getDeclarations() ?? []).some(found => isFindOptionsDeclaration(checker, found, seen));
|
|
101
|
+
};
|
|
102
|
+
return selectorReference(declaration.type);
|
|
103
|
+
};
|
|
104
|
+
const isFindOptionsType = (checker, type) => [type.aliasSymbol, type.getSymbol()].some(symbol => (symbol?.getDeclarations() ?? []).some(declaration => isFindOptionsDeclaration(checker, declaration, new Set())));
|
|
105
|
+
/** Entity rows, including partial row aliases; read selectors retain their distinct TypeORM contract through local aliases. */
|
|
80
106
|
const entityClassesOf = (checker, type) => {
|
|
81
107
|
if (!type)
|
|
82
108
|
return [];
|
|
83
109
|
const parts = type.isUnion?.() ? type.types : [type];
|
|
84
|
-
const candidates = parts.flatMap((part) => [part, ...(part.aliasTypeArguments ?? [])]);
|
|
110
|
+
const candidates = parts.filter(part => !isFindOptionsType(checker, part)).flatMap((part) => [part, ...(part.aliasTypeArguments ?? [])]);
|
|
85
111
|
return candidates.flatMap((candidate) => (candidate.getSymbol?.()?.getDeclarations?.() ?? []).filter((declaration) => isEntityClass(checker, declaration)));
|
|
86
112
|
};
|
|
87
113
|
/** A spec builds each persistence entity as an object literal at most once; further rows come from a builder. */
|
|
@@ -104,6 +130,8 @@ export const specNoRepeatedRowLiteral = {
|
|
|
104
130
|
if (node.properties.length === 0 || node.properties.some((property) => property.type === "SpreadElement"))
|
|
105
131
|
return;
|
|
106
132
|
const tsNode = toTs(node);
|
|
133
|
+
if (tsNode && isKitBuilderOverride(checker, tsNode))
|
|
134
|
+
return;
|
|
107
135
|
const [entity] = entityClassesOf(checker, tsNode && checker.getContextualType(tsNode));
|
|
108
136
|
if (!entity)
|
|
109
137
|
return;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { moduleOf, resolvedSymbol } from "./types.js";
|
|
3
|
+
const unwrapped = (input) => {
|
|
4
|
+
let node = input;
|
|
5
|
+
while (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isTypeAssertionExpression(node)
|
|
6
|
+
|| ts.isNonNullExpression(node) || ts.isSatisfiesExpression(node))
|
|
7
|
+
node = node.expression;
|
|
8
|
+
return node;
|
|
9
|
+
};
|
|
10
|
+
/** Follows actual constant values; a matching callable annotation never supplies value provenance. */
|
|
11
|
+
const valueOrigins = (checker, input, seen) => {
|
|
12
|
+
const node = unwrapped(input);
|
|
13
|
+
if (ts.isCallExpression(node))
|
|
14
|
+
return [node];
|
|
15
|
+
const symbol = resolvedSymbol(checker, checker.getSymbolAtLocation(node));
|
|
16
|
+
if (!symbol || seen.has(symbol))
|
|
17
|
+
return [];
|
|
18
|
+
seen.add(symbol);
|
|
19
|
+
return (symbol.getDeclarations() ?? []).flatMap((declaration) => {
|
|
20
|
+
if (!ts.isVariableDeclaration(declaration))
|
|
21
|
+
return [declaration];
|
|
22
|
+
if (!ts.isVariableDeclarationList(declaration.parent) || !(declaration.parent.flags & ts.NodeFlags.Const)
|
|
23
|
+
|| !ts.isIdentifier(declaration.name) || !declaration.initializer)
|
|
24
|
+
return [];
|
|
25
|
+
return valueOrigins(checker, declaration.initializer, seen);
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
const isKitFactory = (checker, expression) => valueOrigins(checker, expression, new Set()).some((declaration) => {
|
|
29
|
+
if (!ts.isFunctionDeclaration(declaration) || declaration.name?.text !== "builder")
|
|
30
|
+
return false;
|
|
31
|
+
const owner = moduleOf(declaration, declaration.getSourceFile().fileName.replaceAll("\\", "/"));
|
|
32
|
+
return owner === "@starci/jest-preset" || owner === "@starci/jest-preset/builders";
|
|
33
|
+
});
|
|
34
|
+
/** A direct override reaches a value actually produced by the canonical builder factory, including immutable aliases. */
|
|
35
|
+
export const isKitBuilderOverride = (checker, literal) => {
|
|
36
|
+
let argument = literal;
|
|
37
|
+
while (ts.isParenthesizedExpression(argument.parent) || ts.isAsExpression(argument.parent)
|
|
38
|
+
|| ts.isTypeAssertionExpression(argument.parent) || ts.isSatisfiesExpression(argument.parent)
|
|
39
|
+
|| ts.isNonNullExpression(argument.parent))
|
|
40
|
+
argument = argument.parent;
|
|
41
|
+
const call = argument.parent;
|
|
42
|
+
if (!ts.isCallExpression(call) || call.arguments[0] !== argument)
|
|
43
|
+
return false;
|
|
44
|
+
return valueOrigins(checker, call.expression, new Set()).some(origin => ts.isCallExpression(origin) && isKitFactory(checker, origin.expression));
|
|
45
|
+
};
|
|
@@ -15,16 +15,16 @@ const realSubjectFunction = (context, value) => {
|
|
|
15
15
|
const tsNode = toTs(value);
|
|
16
16
|
const symbol = ts.isShorthandPropertyAssignment(tsNode.parent)
|
|
17
17
|
? checker.getShorthandAssignmentValueSymbol(tsNode.parent) : checker.getSymbolAtLocation(tsNode);
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
const declaration = target?.valueDeclaration;
|
|
21
|
-
if (!declaration)
|
|
18
|
+
const declaration = symbol?.declarations?.find(ts.isImportSpecifier);
|
|
19
|
+
if (!declaration || declaration.isTypeOnly || declaration.parent.parent.isTypeOnly)
|
|
22
20
|
return null;
|
|
23
|
-
const
|
|
21
|
+
const importedModule = checker.getSymbolAtLocation(declaration.parent.parent.parent.moduleSpecifier);
|
|
24
22
|
const sibling = (context.filename || context.getFilename()).replace(/\.spec\.ts$/u, ".ts");
|
|
25
|
-
|
|
23
|
+
const sourceFile = importedModule?.declarations?.find((candidate) => ts.isSourceFile(candidate)
|
|
24
|
+
&& path.resolve(candidate.fileName) === path.resolve(sibling));
|
|
25
|
+
if (!sourceFile)
|
|
26
26
|
return null;
|
|
27
|
-
const names = functionSubjectExports(ts, sourceFile);
|
|
27
|
+
const names = functionSubjectExports(ts, sourceFile, checker);
|
|
28
28
|
return imported.imported !== null && names?.includes(imported.imported) ? imported.imported : null;
|
|
29
29
|
};
|
|
30
30
|
const VALUE_OBJECTS = new Map();
|
package/package.json
CHANGED
|
@@ -31,35 +31,35 @@ pins:
|
|
|
31
31
|
source: packages/event-stream/package.json
|
|
32
32
|
why: 'the one server-sent-events client of every front end (fe-stack event-stream, owner:event-stream-package): the transport client layer (modules/api/sse/clients) creates one instance for the app with the bearer token source and the stream operations follow on it; it carries Last-Event-ID resume, the capped doubling backoff, the heartbeat timeout, the single 401 renewal and the useSWRSubscription adapter, so no app keeps a hand-written reader.'
|
|
33
33
|
'@starci/grammar':
|
|
34
|
-
version: 0.21.
|
|
34
|
+
version: 0.21.7
|
|
35
35
|
group: starci
|
|
36
36
|
install: registry
|
|
37
37
|
side: fe
|
|
38
38
|
source: packages/grammar/package.json
|
|
39
39
|
why: 'the grammar front ends read: the brand layer sets `--font-sans` and `--font-mono` and the grammar reads them; it carries the Input tel kind, the copyable and read-only Input, the IconButton disclosure props and count badge, ChatBubble, FillViewport, Textarea mentions and Enter-to-send, the leading PrimaryRailLayout rail, the plate-less Image, ListRow, the soft Alert, Progress steps, the floating primary IconButton, FlowGraph, the STATE-8 loading views and the bordered selectable TagGroup chips. The runtime source version wins for a @starci package.'
|
|
40
40
|
'@starci/eslint-canon-be':
|
|
41
|
-
version: 3.11.
|
|
41
|
+
version: 3.11.14
|
|
42
42
|
group: starci
|
|
43
43
|
install: registry
|
|
44
44
|
side: be
|
|
45
45
|
source: packages/eslint-canon-be/package.json
|
|
46
46
|
why: 'the back-end ESLint canon: `loadHfs(import.meta.url)` of be/eslint.config.mjs finds the app-root hfs.json (kind app) and gives every linted file the view of the be side, and the project graph is built per side; its bundled runtime copies (slots, canon-pins, failure codes, the architecture machine) put .starcistacks and .sops.yaml at the app root; `starciBeConfig({ hfs: loadHfs(import.meta.url) })` is the typed factory and the BE-CONVENTION laws are its rules.'
|
|
47
47
|
'@starci/eslint-canon-fe':
|
|
48
|
-
version: 9.9.
|
|
48
|
+
version: 9.9.7
|
|
49
49
|
group: starci
|
|
50
50
|
install: registry
|
|
51
51
|
side: fe
|
|
52
52
|
source: packages/eslint-canon-fe/package.json
|
|
53
53
|
why: 'the front-end ESLint canon: `loadHfs(import.meta.url)` of fe/eslint.config.mjs finds the app-root hfs.json (kind app) and gives every linted file the view of the fe side, and the project graph is built per side; its bundled runtime copies (slots, canon-pins, failure codes, the architecture machine) put .starcistacks and .sops.yaml at the app root; the front end has no tests (FE_NO_TESTS R97 in hfs) and no-vietnamese-in-source (R91) applies.'
|
|
54
54
|
'@starci/eslint-grammar-core':
|
|
55
|
-
version: 0.21.
|
|
55
|
+
version: 0.21.7
|
|
56
56
|
group: starci
|
|
57
57
|
install: registry
|
|
58
58
|
side: fe
|
|
59
59
|
source: packages/eslint-grammar-core/package.json
|
|
60
60
|
why: 'the StarCi Grammar component API lint, versioned with @starci/grammar; front ends compose this family package with the universal FE canon.'
|
|
61
61
|
'@starci/eslint-grammar-offset-pop':
|
|
62
|
-
version: 0.21.
|
|
62
|
+
version: 0.21.7
|
|
63
63
|
group: starci
|
|
64
64
|
install: registry
|
|
65
65
|
side: fe
|
|
@@ -106,7 +106,7 @@ pins:
|
|
|
106
106
|
source: packages/ai-router/package.json
|
|
107
107
|
why: 'the AI pool router of a back end: a NestJS module that routes OpenAI-compatible chat, stream and embeddings calls across keys, models and providers, with @starci/ai-router/testing for its specs; @starci/jest-preset compiles it as an ESM-only dependency.'
|
|
108
108
|
'@starci/hfs':
|
|
109
|
-
version:
|
|
109
|
+
version: 5.0.3
|
|
110
110
|
group: starci
|
|
111
111
|
install: registry
|
|
112
112
|
side: both
|
|
@@ -17,7 +17,7 @@ function importBindings(ts, scope, statement) {
|
|
|
17
17
|
return;
|
|
18
18
|
const module = statement.moduleSpecifier.text;
|
|
19
19
|
if (clause.name)
|
|
20
|
-
scope.bindings.set(clause.name.text, { kind: 'component' });
|
|
20
|
+
scope.bindings.set(clause.name.text, { kind: 'component', module, name: 'default' });
|
|
21
21
|
const named = clause.namedBindings;
|
|
22
22
|
if (!named)
|
|
23
23
|
return;
|
|
@@ -28,8 +28,9 @@ function importBindings(ts, scope, statement) {
|
|
|
28
28
|
if (element.isTypeOnly)
|
|
29
29
|
continue;
|
|
30
30
|
const imported = element.propertyName?.text ?? element.name.text;
|
|
31
|
-
const
|
|
32
|
-
|
|
31
|
+
const binding = TRANSLATION_MODULES.has(module) && TRANSLATION_FACTORIES.has(imported)
|
|
32
|
+
? { kind: 'translation-factory' } : { kind: 'component', module, name: imported };
|
|
33
|
+
scope.bindings.set(element.name.text, binding);
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
function lexicalBindings(ts, sourceFile) {
|
|
@@ -151,12 +152,55 @@ function nestedDataObjects(ts, expression, bindingOf, excluded) {
|
|
|
151
152
|
nestedDataObjects(ts, element, bindingOf, excluded);
|
|
152
153
|
}
|
|
153
154
|
}
|
|
155
|
+
/** Resolve the canonical status owner through its import binding, including aliases and namespaces. */
|
|
156
|
+
function statusOwner(ts, tag, bindingOf) {
|
|
157
|
+
const binding = ts.isIdentifier(tag) ? bindingOf(tag) : ts.isPropertyAccessExpression(tag) && ts.isIdentifier(tag.expression) ? bindingOf(tag.expression) : null;
|
|
158
|
+
const module = binding?.kind === 'component' || binding?.kind === 'namespace' ? binding.module : null;
|
|
159
|
+
const name = binding?.kind === 'component' ? binding.name : ts.isPropertyAccessExpression(tag) ? tag.name.text : null;
|
|
160
|
+
return name === 'SlotView' && module !== null && /(?:^|\/)components\/composites\/SlotView(?:\/index)?(?:\.[cm]?tsx?)?$/.test(module);
|
|
161
|
+
}
|
|
162
|
+
/** The mandated status wiring breaks clone windows; its render body remains ordinary compared code. */
|
|
163
|
+
function statusRecipe(ts, opening, bindingOf, excluded) {
|
|
164
|
+
if (!statusOwner(ts, opening.tagName, bindingOf))
|
|
165
|
+
return;
|
|
166
|
+
const attributes = opening.attributes.properties;
|
|
167
|
+
const render = attributes.find(attribute => ts.isJsxAttribute(attribute) && ts.isIdentifier(attribute.name) && attribute.name.text === 'render');
|
|
168
|
+
const value = render && ts.isJsxAttribute(render) && render.initializer && ts.isJsxExpression(render.initializer) ? unwrap(ts, render.initializer.expression) : undefined;
|
|
169
|
+
if (!value || !ts.isArrowFunction(value) || value.parameters.length !== 2 || ts.isBlock(value.body))
|
|
170
|
+
return;
|
|
171
|
+
const waiting = value.parameters[1];
|
|
172
|
+
if (!waiting || !ts.isIdentifier(waiting.name) || waiting.initializer || waiting.dotDotDotToken)
|
|
173
|
+
return;
|
|
174
|
+
const waitingBinding = bindingOf(waiting.name);
|
|
175
|
+
let forwardsLoading = false;
|
|
176
|
+
const visit = (node) => {
|
|
177
|
+
if (ts.isJsxAttribute(node) && ts.isIdentifier(node.name) && node.name.text === 'isLoading'
|
|
178
|
+
&& node.initializer && ts.isJsxExpression(node.initializer)) {
|
|
179
|
+
const flag = unwrap(ts, node.initializer.expression);
|
|
180
|
+
if (flag && ts.isIdentifier(flag) && waitingBinding && bindingOf(flag) === waitingBinding)
|
|
181
|
+
forwardsLoading = true;
|
|
182
|
+
}
|
|
183
|
+
ts.forEachChild(node, visit);
|
|
184
|
+
};
|
|
185
|
+
visit(value.body);
|
|
186
|
+
if (!forwardsLoading)
|
|
187
|
+
return;
|
|
188
|
+
const wiring = attributes.filter(attribute => ts.isJsxSpreadAttribute(attribute) ? dataMapping(ts, attribute.expression, bindingOf)
|
|
189
|
+
: ts.isIdentifier(attribute.name) && ['slot', 'placeholder', 'labels', 'onRetry'].includes(attribute.name.text)
|
|
190
|
+
&& !!attribute.initializer && ts.isJsxExpression(attribute.initializer) && dataMapping(ts, attribute.initializer.expression, bindingOf));
|
|
191
|
+
const hasSlot = wiring.some(attribute => ts.isJsxSpreadAttribute(attribute) || ts.isJsxAttribute(attribute) && ts.isIdentifier(attribute.name) && attribute.name.text === 'slot');
|
|
192
|
+
if (!hasSlot)
|
|
193
|
+
return;
|
|
194
|
+
for (const attribute of wiring)
|
|
195
|
+
excluded.add(attribute);
|
|
196
|
+
}
|
|
154
197
|
/** Canon data prop objects qualify through an imported component binding, never its chosen name or file path. */
|
|
155
198
|
export function canonJsxCloneNodes(ts, sourceFile) {
|
|
156
199
|
const bindingOf = lexicalBindings(ts, sourceFile);
|
|
157
200
|
const excluded = new Set();
|
|
158
201
|
const visit = (node) => {
|
|
159
202
|
if ((ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) && importedComponent(ts, node.tagName, bindingOf)) {
|
|
203
|
+
statusRecipe(ts, node, bindingOf, excluded);
|
|
160
204
|
for (const attribute of node.attributes.properties) {
|
|
161
205
|
if (!ts.isJsxAttribute(attribute) || !attribute.initializer || !ts.isJsxExpression(attribute.initializer))
|
|
162
206
|
continue;
|
|
@@ -203,6 +203,9 @@ function signatureParameterStatus(ts, checker, signature, location, parameter, s
|
|
|
203
203
|
const actual = parameterSymbol ? checker.getTypeOfSymbolAtLocation(parameterSymbol, location) : null;
|
|
204
204
|
if (actual && parameter.questionToken && !ts.isUnionTypeNode(parameter.type) && hasAnyFlag(actual.flags, ts.TypeFlags.Union)) {
|
|
205
205
|
const selected = actual.types.filter((type) => !hasAnyFlag(type.flags, ts.TypeFlags.Undefined));
|
|
206
|
+
// An optional boolean is represented as true | false | undefined, not one Boolean member.
|
|
207
|
+
if (selected.length > 0 && selected.every((type) => hasAnyFlag(type.flags, ts.TypeFlags.BooleanLike)))
|
|
208
|
+
return 'scalar';
|
|
206
209
|
return selected.length === 1 ? contractTypeStatusFromType(ts, checker, selected[0]) : 'inline';
|
|
207
210
|
}
|
|
208
211
|
return actual ? contractTypeStatusFromType(ts, checker, actual) : contractTypeStatus(ts, checker, parameter.type);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
import { normalizedSymbol } from './ast-walks.mjs';
|
|
2
3
|
export const keyOf = (ts, property) => (ts.isPropertyAssignment(property) || ts.isShorthandPropertyAssignment(property)) && (ts.isIdentifier(property.name) || ts.isStringLiteralLike(property.name)) ? property.name.text : null;
|
|
3
4
|
const exported = (ts, statement) => statement.modifiers?.some(modifier => modifier.kind === ts.SyntaxKind.ExportKeyword) ?? false;
|
|
4
5
|
/** The directly defined functions among the declarations of an exported variable statement; other values are not callable. */
|
|
@@ -19,17 +20,30 @@ function callableExports(ts, statement) {
|
|
|
19
20
|
return statement.name && statement.body ? [statement.name.text] : [];
|
|
20
21
|
return ts.isVariableStatement(statement) ? callableVariables(ts, statement) : [];
|
|
21
22
|
}
|
|
23
|
+
/** Named value re-exports count only when the checker resolves an actual function implementation. */
|
|
24
|
+
function callableReexports(ts, checker, statement) {
|
|
25
|
+
if (!ts.isExportDeclaration(statement) || statement.isTypeOnly || !statement.exportClause || !ts.isNamedExports(statement.exportClause))
|
|
26
|
+
return [];
|
|
27
|
+
return statement.exportClause.elements.filter(element => !element.isTypeOnly && (normalizedSymbol(ts, checker, element.name)?.declarations ?? []).some(declaration => {
|
|
28
|
+
if (declaration.getSourceFile().isDeclarationFile)
|
|
29
|
+
return false;
|
|
30
|
+
if (ts.isFunctionDeclaration(declaration))
|
|
31
|
+
return Boolean(declaration.body);
|
|
32
|
+
return ts.isVariableDeclaration(declaration) && Boolean(declaration.initializer
|
|
33
|
+
&& (ts.isArrowFunction(declaration.initializer) || ts.isFunctionExpression(declaration.initializer)));
|
|
34
|
+
})).map(element => element.name.text);
|
|
35
|
+
}
|
|
22
36
|
/**
|
|
23
|
-
* The callable subset of a function subject's exports
|
|
24
|
-
*
|
|
25
|
-
* check (null), as does a module with no callable export.
|
|
37
|
+
* The callable subset of a function subject's exports, including named re-exports resolved to real implementations. Constants,
|
|
38
|
+
* enums, objects, type-only exports and bodyless declarations do not count; a class or a default-export assignment keeps the
|
|
39
|
+
* class-provider check (null), as does a module with no callable export.
|
|
26
40
|
*/
|
|
27
|
-
export function functionSubjectExports(ts, sourceFile) {
|
|
41
|
+
export function functionSubjectExports(ts, sourceFile, checker) {
|
|
28
42
|
const names = [];
|
|
29
43
|
for (const statement of sourceFile.statements) {
|
|
30
44
|
if (ts.isClassDeclaration(statement) || ts.isExportAssignment(statement))
|
|
31
45
|
return null;
|
|
32
|
-
for (const name of callableExports(ts, statement))
|
|
46
|
+
for (const name of [...callableExports(ts, statement), ...callableReexports(ts, checker, statement)])
|
|
33
47
|
if (!names.includes(name))
|
|
34
48
|
names.push(name);
|
|
35
49
|
}
|
|
@@ -18,7 +18,7 @@ import { checkFunctionSubject, functionSubjectExports, keyOf as literalKey, valu
|
|
|
18
18
|
* constructor-deps.mjs). Providers are matched by the exported name of the imported binding (`import { CACHE as C }` is
|
|
19
19
|
* CACHE), never by text. A provider is a class, or `{ provide: TOKEN, useValue: double }` and nothing else. A sibling
|
|
20
20
|
* containing only exported functions instead provides its complete real function object and exercises it through module.get;
|
|
21
|
-
*
|
|
21
|
+
* callable named re-exports count, while constants, enums, type-only exports and overload signatures do not. A value-object subject (an
|
|
22
22
|
* undecorated class whose constructor parameters carry no injection token) is built with `new`, Nest never constructs it.
|
|
23
23
|
*
|
|
24
24
|
* Findings: an extra provider, a missing provider, a service that is not the first provider, a dependency whose token cannot
|
|
@@ -111,7 +111,7 @@ function checkTestingModule({ ts, kit, rel, serviceRel, serviceFile, imports, ca
|
|
|
111
111
|
const list = providerList(ts, call, rel, report);
|
|
112
112
|
if (!list)
|
|
113
113
|
return;
|
|
114
|
-
const names = functionSubjectExports(ts, serviceFile.sourceFile);
|
|
114
|
+
const names = functionSubjectExports(ts, serviceFile.sourceFile, kit.checkerOf(serviceFile.sourceFile));
|
|
115
115
|
if (names) {
|
|
116
116
|
checkFunctionSubject({ ts, rel, serviceRel, imports, call, list, names, report });
|
|
117
117
|
return;
|