• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

satisfactory-dev / ajv-utilities / 26333519053

23 May 2026 01:06PM UTC coverage: 99.237% (+0.05%) from 99.186%
26333519053

push

github

SignpostMarv
updating readme

609 of 626 branches covered (97.28%)

Branch coverage included in aggregate %.

5372 of 5401 relevant lines covered (99.46%)

16572.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.86
/src/TypeScriptify/modifiers/HoistDeclarationAsUndefined.ts
1
import type {
1✔
2
        FunctionDeclaration,
1✔
3
        Identifier,
1✔
4
        NodeArray,
1✔
5
        VariableDeclaration,
1✔
6
        VariableDeclarationList,
1✔
7
        VariableStatement,
1✔
8
} from 'typescript';
1✔
9

1✔
10
import {
1✔
11
        ConditionalModification,
1✔
12
} from '../abstracts.ts';
1✔
13

1✔
14
import type {
1✔
15
        ts,
1✔
16
} from '../../TypeScriptify.ts';
1✔
17

1✔
18
type Candidate = (
1✔
19
        & VariableStatement
1✔
20
        & {
1✔
21
                declarationList: (
1✔
22
                        & VariableDeclarationList
1✔
23
                        & {
1✔
24
                                declarations: (
1✔
25
                                        & NodeArray<VariableDeclaration>
1✔
26
                                        & {
1✔
27
                                                length: 1,
1✔
28
                                                0: (
1✔
29
                                                        & VariableDeclaration
1✔
30
                                                        & {
1✔
31
                                                                name: (
1✔
32
                                                                        & Identifier
1✔
33
                                                                        & {
1✔
34
                                                                                text: `props${number}`,
1✔
35
                                                                        }
1✔
36
                                                                ),
1✔
37
                                                                initializer: Exclude<
1✔
38
                                                                        VariableDeclaration['initializer'],
1✔
39
                                                                        undefined
1✔
40
                                                                >,
1✔
41
                                                        }
1✔
42
                                                ),
1✔
43
                                        }
1✔
44
                                ),
1✔
45
                        }
1✔
46
                ),
1✔
47
        }
1✔
48
);
1✔
49

1✔
50
type HoistingToHereCandidate = (
1✔
51
        & FunctionDeclaration
1✔
52
        & {
1✔
53
                name: (
1✔
54
                        & Identifier
1✔
55
                        & {
1✔
56
                                text: `validate${number}`,
1✔
57
                        }
1✔
58
                ),
1✔
59
                body: Exclude<FunctionDeclaration['body'], undefined>,
1✔
60
        }
1✔
61
);
1✔
62

1✔
63
export type hoist_candidates = {
1✔
64
        [key: string]: Set<string>,
1✔
65
};
1✔
66

1✔
67
export class FindHoistCandidate extends ConditionalModification<
1✔
68
        Candidate
1✔
69
> {
1✔
70
        constructor(
1✔
71
                {
26✔
72
                        factory,
26✔
73
                        isFunctionDeclaration,
26✔
74
                        isIdentifier,
26✔
75
                        isVariableDeclaration,
26✔
76
                        isVariableStatement,
26✔
77
                        SyntaxKind,
26✔
78
                }: ts,
26✔
79
                hoist_candidates: hoist_candidates,
26✔
80
        ) {
26✔
81
                super(
26✔
82
                        (maybe): maybe is Candidate => {
26✔
83
                                if (
238,764✔
84
                                        !(
238,764✔
85
                                                isVariableStatement(maybe)
238,764✔
86
                                                && 1 === maybe.declarationList.declarations.length
238,764✔
87
                                                && isVariableDeclaration(
238,764✔
88
                                                        maybe.declarationList.declarations[0],
4,887✔
89
                                                )
4,887✔
90
                                                && isIdentifier(
238,764✔
91
                                                        maybe.declarationList.declarations[0].name,
4,887✔
92
                                                )
4,887✔
93
                                                && /^props\d+$/.test(
238,764✔
94
                                                        maybe.declarationList.declarations[
4,887✔
95
                                                                0
4,887✔
96
                                                        ].name.text,
4,887✔
97
                                                )
4,887✔
98
                                        )
238,764✔
99
                                ) {
238,764✔
100
                                        return false;
238,754✔
101
                                }
238,754✔
102

10✔
103
                                const variable_name = maybe.declarationList.declarations[
10✔
104
                                        0
10✔
105
                                ].name.getText();
10✔
106

10✔
107
                                let checking = maybe.parent;
10✔
108

10✔
109
                                while (checking) {
238,764✔
110
                                        if (
130✔
111
                                                isFunctionDeclaration(checking)
130✔
112
                                                && !!checking.name
130✔
113
                                                && isIdentifier(checking.name)
130✔
114
                                                && this.validate_function_name.test(
130✔
115
                                                        checking.name.getText(),
10✔
116
                                                )
10✔
117
                                        ) {
130✔
118
                                                const name = checking.name.getText();
10✔
119

10✔
120
                                                if (!(name in hoist_candidates)) {
10✔
121
                                                        hoist_candidates[name] = new Set([variable_name]);
6✔
122
                                                } else {
10✔
123
                                                        hoist_candidates[name].add(variable_name);
4✔
124
                                                }
4✔
125

10✔
126
                                                return true;
10✔
127
                                        }
10✔
128

120✔
129
                                        checking = checking.parent;
120✔
130
                                }
120!
131

×
132
                                return false;
×
133
                        },
26✔
134
                        (node) => {
26✔
135
                                const variable_name = node.declarationList.declarations[
10✔
136
                                        0
10✔
137
                                ].name.getText();
10✔
138

10✔
139
                                return factory.createExpressionStatement(
10✔
140
                                        factory.createBinaryExpression(
10✔
141
                                                factory.createIdentifier(variable_name),
10✔
142
                                                factory.createToken(SyntaxKind.EqualsToken),
10✔
143
                                                node.declarationList.declarations[0].initializer,
10✔
144
                                        ),
10✔
145
                                );
10✔
146
                        },
26✔
147
                );
26✔
148
        }
26✔
149
}
1✔
150

1✔
151
export class HoistDeclarationsHere extends ConditionalModification<
1✔
152
        HoistingToHereCandidate
1✔
153
> {
1✔
154
        #createHoistedType(
1✔
155
                {
10✔
156
                        factory,
10✔
157
                        SyntaxKind,
10✔
158
                }: ts,
10✔
159
        ) {
10✔
160
                return factory.createParenthesizedType(factory.createUnionTypeNode([
10✔
161
                        factory.createLiteralTypeNode(factory.createTrue()),
10✔
162
                        factory.createTypeLiteralNode([
10✔
163
                                factory.createIndexSignature(
10✔
164
                                        undefined,
10✔
165
                                        [
10✔
166
                                                factory.createParameterDeclaration(
10✔
167
                                                        undefined,
10✔
168
                                                        undefined,
10✔
169
                                                        'key',
10✔
170
                                                        undefined,
10✔
171
                                                        factory.createKeywordTypeNode(
10✔
172
                                                                SyntaxKind.StringKeyword,
10✔
173
                                                        ),
10✔
174
                                                ),
10✔
175
                                        ],
10✔
176
                                        factory.createLiteralTypeNode(
10✔
177
                                                factory.createTrue(),
10✔
178
                                        ),
10✔
179
                                ),
10✔
180
                        ]),
10✔
181
                        factory.createKeywordTypeNode(SyntaxKind.UndefinedKeyword),
10✔
182
                ]));
10✔
183
        }
10✔
184

1✔
185
        constructor(
1✔
186
                ts: ts,
26✔
187
                hoist_candidates: Readonly<hoist_candidates>,
26✔
188
        ) {
26✔
189
                const {
26✔
190
                        factory,
26✔
191
                        isFunctionDeclaration,
26✔
192
                        isIdentifier,
26✔
193
                        NodeFlags,
26✔
194
                } = ts;
26✔
195

26✔
196
                super(
26✔
197
                        (maybe): maybe is HoistingToHereCandidate => (
26✔
198
                                isFunctionDeclaration(maybe)
239,126✔
199
                                && !!maybe.name
239,126✔
200
                                && isIdentifier(maybe.name)
239,126✔
201
                                && maybe.name.text in hoist_candidates
239,126✔
202
                                && undefined !== maybe.body
239,126✔
203
                        ),
26✔
204
                        (node) => factory.updateFunctionDeclaration(
26✔
205
                                node,
6✔
206
                                node.modifiers,
6✔
207
                                node.asteriskToken,
6✔
208
                                node.name,
6✔
209
                                node.typeParameters,
6✔
210
                                node.parameters,
6✔
211
                                node.type,
6✔
212
                                factory.updateBlock(
6✔
213
                                        node.body,
6✔
214
                                        [
6✔
215
                                                factory.createVariableStatement(
6✔
216
                                                        undefined,
6✔
217
                                                        factory.createVariableDeclarationList(
6✔
218
                                                                [...hoist_candidates[node.name.getText()]]
6✔
219
                                                                        .map((
6✔
220
                                                                                variable_name,
10✔
221
                                                                        ) => factory.createVariableDeclaration(
10✔
222
                                                                                variable_name,
10✔
223
                                                                                undefined,
10✔
224
                                                                                this.#createHoistedType(ts),
10✔
225
                                                                                factory.createIdentifier('undefined'),
10✔
226
                                                                        )),
6✔
227
                                                                NodeFlags.Let,
6✔
228
                                                        ),
6✔
229
                                                ),
6✔
230
                                                ...node.body.statements,
6✔
231
                                        ],
6✔
232
                                ),
6✔
233
                        ),
26✔
234
                );
26✔
235
        }
26✔
236
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc