knip 5.69.1 → 5.70.1
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/ConfigurationChief.d.ts +6 -0
- package/dist/binaries/package-manager/yarn.js +1 -0
- package/dist/binaries/plugins.js +4 -4
- package/dist/compilers/index.d.ts +10 -0
- package/dist/compilers/index.js +2 -0
- package/dist/compilers/prisma.d.ts +6 -0
- package/dist/compilers/prisma.js +13 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +4 -0
- package/dist/graph/build.js +3 -3
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.js +2 -0
- package/dist/plugins/prisma/index.js +27 -5
- package/dist/plugins/prisma/types.d.ts +1 -0
- package/dist/plugins/taskfile/index.d.ts +3 -0
- package/dist/plugins/taskfile/index.js +111 -0
- package/dist/plugins/taskfile/types.d.ts +25 -0
- package/dist/plugins/taskfile/types.js +1 -0
- package/dist/plugins/vitest/helpers.d.ts +1 -1
- package/dist/plugins/vitest/helpers.js +1 -1
- package/dist/plugins/vitest/index.js +11 -4
- package/dist/reporters/util/configuration-hints.js +1 -1
- package/dist/schema/configuration.d.ts +10 -0
- package/dist/schema/plugins.d.ts +5 -0
- package/dist/schema/plugins.js +1 -0
- package/dist/types/PluginNames.d.ts +2 -2
- package/dist/types/PluginNames.js +1 -0
- package/dist/types/args.d.ts +4 -1
- package/dist/types/module-graph.d.ts +6 -6
- package/dist/typescript/ast-helpers.d.ts +9 -0
- package/dist/typescript/ast-helpers.js +33 -4
- package/dist/typescript/get-imports-and-exports.js +46 -38
- package/dist/typescript/pragmas/custom.d.ts +3 -0
- package/dist/typescript/pragmas/custom.js +25 -0
- package/dist/typescript/pragmas/index.d.ts +3 -0
- package/dist/typescript/pragmas/index.js +3 -0
- package/dist/typescript/pragmas/typescript.d.ts +3 -0
- package/dist/typescript/pragmas/typescript.js +29 -0
- package/dist/typescript/visitors/dynamic-imports/importCall.js +21 -9
- package/dist/typescript/visitors/dynamic-imports/jsDocType.js +23 -9
- package/dist/typescript/visitors/dynamic-imports/requireCall.js +7 -4
- package/dist/typescript/visitors/helpers.d.ts +0 -2
- package/dist/typescript/visitors/helpers.js +0 -38
- package/dist/typescript/visitors/imports/importDeclaration.js +1 -1
- package/dist/typescript/visitors/imports/reExportDeclaration.js +4 -4
- package/dist/util/create-options.d.ts +10 -0
- package/dist/util/has-strictly-ns-references.d.ts +3 -3
- package/dist/util/is-identifier-referenced.js +10 -10
- package/dist/util/module-graph.d.ts +2 -2
- package/dist/util/module-graph.js +22 -22
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +5 -5
- package/schema.json +4 -0
|
@@ -115,6 +115,23 @@ export function findDescendants(node, callback) {
|
|
|
115
115
|
visit(node);
|
|
116
116
|
return results;
|
|
117
117
|
}
|
|
118
|
+
export const getLeadingComments = (sourceFile) => {
|
|
119
|
+
const text = sourceFile.text;
|
|
120
|
+
if (!text)
|
|
121
|
+
return [];
|
|
122
|
+
const firstStatement = sourceFile.statements[0];
|
|
123
|
+
const limit = firstStatement ? firstStatement.getStart() : text.length;
|
|
124
|
+
const ranges = ts.getLeadingCommentRanges(text, 0);
|
|
125
|
+
if (!ranges?.length)
|
|
126
|
+
return [];
|
|
127
|
+
const comments = [];
|
|
128
|
+
for (const range of ranges) {
|
|
129
|
+
if (range.end > limit)
|
|
130
|
+
break;
|
|
131
|
+
comments.push({ ...range, text: text.slice(range.pos, range.end) });
|
|
132
|
+
}
|
|
133
|
+
return comments;
|
|
134
|
+
};
|
|
118
135
|
export const isDeclarationFileExtension = (extension) => extension === '.d.ts' || extension === '.d.mts' || extension === '.d.cts';
|
|
119
136
|
export const getJSDocTags = (node) => {
|
|
120
137
|
const tags = new Set();
|
|
@@ -188,6 +205,13 @@ export const isConsiderReferencedNS = (node) => ts.isPropertyAssignment(node.par
|
|
|
188
205
|
ts.isExportAssignment(node.parent) ||
|
|
189
206
|
(ts.isVariableDeclaration(node.parent) && node.parent.initializer === node) ||
|
|
190
207
|
ts.isTypeQueryNode(node.parent.parent);
|
|
208
|
+
export const isInOpaqueExpression = (node) => ts.isAwaitExpression(node.parent)
|
|
209
|
+
? isInOpaqueExpression(node.parent)
|
|
210
|
+
: ts.isCallExpression(node.parent) ||
|
|
211
|
+
ts.isReturnStatement(node.parent) ||
|
|
212
|
+
ts.isArrowFunction(node.parent) ||
|
|
213
|
+
ts.isPropertyAssignment(node.parent) ||
|
|
214
|
+
ts.isSpreadAssignment(node.parent.parent);
|
|
191
215
|
const objectEnumerationMethods = new Set(['keys', 'entries', 'values', 'getOwnPropertyNames']);
|
|
192
216
|
export const isObjectEnumerationCallExpressionArgument = (node) => ts.isCallExpression(node.parent) &&
|
|
193
217
|
node.parent.arguments.includes(node) &&
|
|
@@ -275,14 +299,19 @@ export const getPropertyValues = (node, propertyName) => {
|
|
|
275
299
|
}
|
|
276
300
|
return values;
|
|
277
301
|
};
|
|
302
|
+
const isMatchAlias = (expression, identifier) => {
|
|
303
|
+
while (expression && ts.isAwaitExpression(expression))
|
|
304
|
+
expression = expression.expression;
|
|
305
|
+
return expression && ts.isIdentifier(expression) && expression.escapedText === identifier;
|
|
306
|
+
};
|
|
278
307
|
export const getAccessedIdentifiers = (identifier, scope) => {
|
|
279
308
|
const identifiers = [];
|
|
280
309
|
function visit(node) {
|
|
281
|
-
if (ts.isPropertyAccessExpression(node) && node.expression
|
|
310
|
+
if (ts.isPropertyAccessExpression(node) && isMatchAlias(node.expression, identifier)) {
|
|
282
311
|
identifiers.push({ identifier: String(node.name.escapedText), pos: node.name.pos });
|
|
283
312
|
}
|
|
284
313
|
else if (ts.isElementAccessExpression(node) &&
|
|
285
|
-
node.expression
|
|
314
|
+
isMatchAlias(node.expression, identifier) &&
|
|
286
315
|
ts.isStringLiteral(node.argumentExpression)) {
|
|
287
316
|
identifiers.push({
|
|
288
317
|
identifier: stripQuotes(node.argumentExpression.text),
|
|
@@ -290,12 +319,12 @@ export const getAccessedIdentifiers = (identifier, scope) => {
|
|
|
290
319
|
});
|
|
291
320
|
}
|
|
292
321
|
else if (ts.isVariableDeclaration(node) &&
|
|
293
|
-
node.initializer
|
|
322
|
+
isMatchAlias(node.initializer, identifier) &&
|
|
294
323
|
ts.isObjectBindingPattern(node.name)) {
|
|
295
324
|
for (const element of node.name.elements) {
|
|
296
325
|
if (ts.isBindingElement(element)) {
|
|
297
326
|
const identifier = (element.propertyName ?? element.name).getText();
|
|
298
|
-
identifiers.push({ identifier, pos: element.
|
|
327
|
+
identifiers.push({ identifier, pos: element.getStart() });
|
|
299
328
|
}
|
|
300
329
|
}
|
|
301
330
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isBuiltin } from 'node:module';
|
|
2
2
|
import ts from 'typescript';
|
|
3
|
-
import { ALIAS_TAG,
|
|
3
|
+
import { ALIAS_TAG, IMPORT_MODIFIERS, IMPORT_STAR, OPAQUE, PROTOCOL_VIRTUAL, SIDE_EFFECTS } from '../constants.js';
|
|
4
4
|
import { addNsValue, addValue, createImports } from '../util/module-graph.js';
|
|
5
5
|
import { getPackageNameFromFilePath, isStartsLikePackageName, sanitizeSpecifier } from '../util/modules.js';
|
|
6
6
|
import { timerify } from '../util/Performance.js';
|
|
@@ -8,9 +8,9 @@ import { dirname, isInNodeModules, resolve } from '../util/path.js';
|
|
|
8
8
|
import { shouldIgnore } from '../util/tag.js';
|
|
9
9
|
import { getAccessMembers, getDestructuredNames, getJSDocTags, getLineAndCharacterOfPosition, getTypeRef, isAccessExpression, isConsiderReferencedNS, isDestructuring, isImportSpecifier, isInForIteration, isObjectEnumerationCallExpressionArgument, isReferencedInExport, } from './ast-helpers.js';
|
|
10
10
|
import { findInternalReferences, isType } from './find-internal-references.js';
|
|
11
|
+
import { getImportsFromPragmas } from './pragmas/index.js';
|
|
11
12
|
import getDynamicImportVisitors from './visitors/dynamic-imports/index.js';
|
|
12
13
|
import getExportVisitors from './visitors/exports/index.js';
|
|
13
|
-
import { getImportsFromPragmas } from './visitors/helpers.js';
|
|
14
14
|
import getImportVisitors from './visitors/imports/index.js';
|
|
15
15
|
import getScriptVisitors from './visitors/scripts/index.js';
|
|
16
16
|
const getVisitors = (sourceFile) => ({
|
|
@@ -38,7 +38,7 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
|
|
|
38
38
|
const external = new Set();
|
|
39
39
|
const unresolved = new Set();
|
|
40
40
|
const resolved = new Set();
|
|
41
|
-
const
|
|
41
|
+
const imports = new Set();
|
|
42
42
|
const exports = new Map();
|
|
43
43
|
const aliasedExports = new Map();
|
|
44
44
|
const scripts = new Set();
|
|
@@ -76,36 +76,37 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
|
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
78
|
const addInternalImport = (options) => {
|
|
79
|
-
const {
|
|
79
|
+
const { symbol, filePath, namespace, specifier, modifiers } = options;
|
|
80
|
+
const identifier = options.identifier ?? (modifiers & IMPORT_MODIFIERS.OPAQUE ? OPAQUE : SIDE_EFFECTS);
|
|
80
81
|
const isStar = identifier === IMPORT_STAR;
|
|
81
|
-
|
|
82
|
+
imports.add([{ specifier, identifier, pos: options.pos, line: options.line, col: options.col }, filePath]);
|
|
82
83
|
const file = internal.get(filePath);
|
|
83
|
-
const
|
|
84
|
+
const importMaps = file ?? createImports();
|
|
84
85
|
if (!file)
|
|
85
|
-
internal.set(filePath,
|
|
86
|
-
const nsOrAlias = symbol ? String(symbol.escapedName) : alias;
|
|
87
|
-
if (
|
|
86
|
+
internal.set(filePath, importMaps);
|
|
87
|
+
const nsOrAlias = symbol ? String(symbol.escapedName) : options.alias;
|
|
88
|
+
if (modifiers & IMPORT_MODIFIERS.RE_EXPORT) {
|
|
88
89
|
if (isStar && namespace) {
|
|
89
|
-
addValue(
|
|
90
|
+
addValue(importMaps.reExportedNs, namespace, sourceFile.fileName);
|
|
90
91
|
}
|
|
91
92
|
else if (nsOrAlias) {
|
|
92
|
-
addNsValue(
|
|
93
|
+
addNsValue(importMaps.reExportedAs, identifier, nsOrAlias, sourceFile.fileName);
|
|
93
94
|
}
|
|
94
95
|
else {
|
|
95
|
-
addValue(
|
|
96
|
+
addValue(importMaps.reExported, identifier, sourceFile.fileName);
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
else {
|
|
99
100
|
if (nsOrAlias && nsOrAlias !== identifier) {
|
|
100
101
|
if (isStar) {
|
|
101
|
-
addValue(
|
|
102
|
+
addValue(importMaps.importedNs, nsOrAlias, sourceFile.fileName);
|
|
102
103
|
}
|
|
103
104
|
else {
|
|
104
|
-
addNsValue(
|
|
105
|
+
addNsValue(importMaps.importedAs, identifier, nsOrAlias, sourceFile.fileName);
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
|
-
else if (identifier !==
|
|
108
|
-
addValue(
|
|
108
|
+
else if (identifier !== SIDE_EFFECTS && identifier !== IMPORT_STAR) {
|
|
109
|
+
addValue(importMaps.imported, identifier, sourceFile.fileName);
|
|
109
110
|
}
|
|
110
111
|
if (symbol)
|
|
111
112
|
importedInternalSymbols.set(symbol, filePath);
|
|
@@ -126,7 +127,6 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
|
|
|
126
127
|
const { line, character } = node.getSourceFile().getLineAndCharacterOfPosition(opts.pos);
|
|
127
128
|
addInternalImport({
|
|
128
129
|
...opts,
|
|
129
|
-
identifier: opts.identifier ?? ANONYMOUS,
|
|
130
130
|
filePath,
|
|
131
131
|
line: line + 1,
|
|
132
132
|
col: character + 1,
|
|
@@ -143,7 +143,13 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
|
|
|
143
143
|
}
|
|
144
144
|
const pos = node.moduleSpecifier?.getStart() ?? opts.pos;
|
|
145
145
|
const { line, character } = sourceFile.getLineAndCharacterOfPosition(pos);
|
|
146
|
-
external.add({
|
|
146
|
+
external.add({
|
|
147
|
+
specifier: sanitizedSpecifier,
|
|
148
|
+
identifier: opts.identifier ?? SIDE_EFFECTS,
|
|
149
|
+
pos: opts.pos,
|
|
150
|
+
line: line + 1,
|
|
151
|
+
col: character + 2,
|
|
152
|
+
});
|
|
147
153
|
}
|
|
148
154
|
}
|
|
149
155
|
}
|
|
@@ -154,14 +160,19 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
|
|
|
154
160
|
return;
|
|
155
161
|
if (opts.specifier.startsWith(PROTOCOL_VIRTUAL))
|
|
156
162
|
return;
|
|
157
|
-
const r = resolve(dirname(sourceFile.fileName), opts.specifier);
|
|
158
163
|
if (opts.modifiers && opts.modifiers & IMPORT_MODIFIERS.OPTIONAL) {
|
|
159
|
-
resolved.add(
|
|
164
|
+
resolved.add(resolve(dirname(sourceFile.fileName), opts.specifier));
|
|
160
165
|
return;
|
|
161
166
|
}
|
|
162
167
|
const pos = 'moduleSpecifier' in node ? node.moduleSpecifier.pos : node.pos;
|
|
163
168
|
const { line, character } = sourceFile.getLineAndCharacterOfPosition(pos);
|
|
164
|
-
unresolved.add({
|
|
169
|
+
unresolved.add({
|
|
170
|
+
specifier: opts.specifier,
|
|
171
|
+
identifier: opts.identifier ?? SIDE_EFFECTS,
|
|
172
|
+
pos,
|
|
173
|
+
line: line + 1,
|
|
174
|
+
col: character + 2,
|
|
175
|
+
});
|
|
165
176
|
}
|
|
166
177
|
};
|
|
167
178
|
const addExport = ({ node, symbol, identifier, type, pos, members = [], fix }) => {
|
|
@@ -187,13 +198,12 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
|
|
|
187
198
|
}
|
|
188
199
|
const jsDocTags = getJSDocTags(node);
|
|
189
200
|
const exportMembers = members.map(member => createMember(node, member, member.pos));
|
|
190
|
-
const isReExport = Boolean(node.parent?.parent && ts.isExportDeclaration(node.parent.parent) && node.parent.parent.moduleSpecifier);
|
|
191
201
|
const item = exports.get(identifier);
|
|
192
202
|
if (item) {
|
|
193
203
|
const members = [...(item.members ?? []), ...exportMembers];
|
|
194
204
|
const tags = new Set([...(item.jsDocTags ?? []), ...jsDocTags]);
|
|
195
205
|
const fixes = fix ? [...(item.fixes ?? []), fix] : item.fixes;
|
|
196
|
-
exports.set(identifier, { ...item, members, jsDocTags: tags, fixes
|
|
206
|
+
exports.set(identifier, { ...item, members, jsDocTags: tags, fixes });
|
|
197
207
|
}
|
|
198
208
|
else {
|
|
199
209
|
const { line, character } = node.getSourceFile().getLineAndCharacterOfPosition(pos);
|
|
@@ -208,7 +218,6 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
|
|
|
208
218
|
col: character + 1,
|
|
209
219
|
fixes: fix ? [fix] : [],
|
|
210
220
|
refs: [0, false],
|
|
211
|
-
isReExport,
|
|
212
221
|
});
|
|
213
222
|
}
|
|
214
223
|
if (!jsDocTags.has(ALIAS_TAG)) {
|
|
@@ -237,6 +246,18 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
|
|
|
237
246
|
const result = visitor(node, options);
|
|
238
247
|
result && (Array.isArray(result) ? result.forEach(addExport) : addExport(result));
|
|
239
248
|
}
|
|
249
|
+
if (ts.isImportEqualsDeclaration(node) &&
|
|
250
|
+
ts.isQualifiedName(node.moduleReference) &&
|
|
251
|
+
ts.isIdentifier(node.moduleReference.left)) {
|
|
252
|
+
const { left, right } = node.moduleReference;
|
|
253
|
+
const namespace = left.text;
|
|
254
|
+
const { filePath } = getImport(namespace, node);
|
|
255
|
+
if (filePath) {
|
|
256
|
+
const internalImport = internal.get(filePath);
|
|
257
|
+
if (internalImport)
|
|
258
|
+
addNsMemberRefs(internalImport, namespace, right.text);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
240
261
|
}
|
|
241
262
|
for (const visitor of visitors.dynamicImport) {
|
|
242
263
|
const result = visitor(node, options);
|
|
@@ -313,19 +334,6 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
|
|
|
313
334
|
}
|
|
314
335
|
}
|
|
315
336
|
}
|
|
316
|
-
if (isTopLevel &&
|
|
317
|
-
ts.isImportEqualsDeclaration(node) &&
|
|
318
|
-
ts.isQualifiedName(node.moduleReference) &&
|
|
319
|
-
ts.isIdentifier(node.moduleReference.left)) {
|
|
320
|
-
const { left, right } = node.moduleReference;
|
|
321
|
-
const namespace = left.text;
|
|
322
|
-
const { filePath } = getImport(namespace, node);
|
|
323
|
-
if (filePath) {
|
|
324
|
-
const internalImport = internal.get(filePath);
|
|
325
|
-
if (internalImport)
|
|
326
|
-
addNsMemberRefs(internalImport, namespace, right.text);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
337
|
ts.forEachChild(node, visit);
|
|
330
338
|
};
|
|
331
339
|
visit(sourceFile);
|
|
@@ -354,7 +362,7 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
|
|
|
354
362
|
item.symbol = undefined;
|
|
355
363
|
}
|
|
356
364
|
return {
|
|
357
|
-
imports: { internal, external, resolved,
|
|
365
|
+
imports: { internal, external, resolved, imports, unresolved },
|
|
358
366
|
exports,
|
|
359
367
|
duplicates: [...aliasedExports.values()],
|
|
360
368
|
scripts,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { IMPORT_MODIFIERS } from '../../constants.js';
|
|
2
|
+
import { getEnvSpecifier } from '../../plugins/vitest/helpers.js';
|
|
3
|
+
import { isAbsolute, isInternal } from '../../util/path.js';
|
|
4
|
+
import { getLeadingComments, stripQuotes } from '../ast-helpers.js';
|
|
5
|
+
const VITEST_ENV = /@(vitest|jest)-environment\s+(\S+)/g;
|
|
6
|
+
export const collectCustomImports = (sourceFile) => {
|
|
7
|
+
const comments = getLeadingComments(sourceFile);
|
|
8
|
+
if (!comments.length)
|
|
9
|
+
return [];
|
|
10
|
+
const importNodes = [];
|
|
11
|
+
for (const comment of comments) {
|
|
12
|
+
let match;
|
|
13
|
+
while ((match = VITEST_ENV.exec(comment.text)) !== null) {
|
|
14
|
+
const id = stripQuotes(match[2].trim());
|
|
15
|
+
if (!id)
|
|
16
|
+
continue;
|
|
17
|
+
const isLocal = isInternal(id) || isAbsolute(id);
|
|
18
|
+
const modifiers = isLocal ? IMPORT_MODIFIERS.ENTRY : IMPORT_MODIFIERS.NONE;
|
|
19
|
+
const offset = match[0].length - match[2].length;
|
|
20
|
+
const specifier = isLocal || id === 'node' ? id : getEnvSpecifier(id);
|
|
21
|
+
importNodes.push({ specifier, identifier: undefined, pos: comment.pos + match.index + offset, modifiers });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return importNodes;
|
|
25
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { IMPORT_MODIFIERS } from '../../constants.js';
|
|
2
|
+
export const collectTypeScriptPragmaImports = (sourceFile) => {
|
|
3
|
+
if (!sourceFile.pragmas || sourceFile.pragmas.size === 0)
|
|
4
|
+
return [];
|
|
5
|
+
const importNodes = [];
|
|
6
|
+
const modifiers = IMPORT_MODIFIERS.TYPE_ONLY;
|
|
7
|
+
const jsxImportSourcePragmas = sourceFile.pragmas.get('jsximportsource');
|
|
8
|
+
if (jsxImportSourcePragmas) {
|
|
9
|
+
const jsxImportSourcePragma = Array.isArray(jsxImportSourcePragmas)
|
|
10
|
+
? jsxImportSourcePragmas[jsxImportSourcePragmas.length - 1]
|
|
11
|
+
: jsxImportSourcePragmas;
|
|
12
|
+
const { factory: specifier } = jsxImportSourcePragma?.arguments ?? {};
|
|
13
|
+
const pos = jsxImportSourcePragma.range?.pos ?? 0;
|
|
14
|
+
if (specifier)
|
|
15
|
+
importNodes.push({ specifier, identifier: undefined, pos, modifiers });
|
|
16
|
+
}
|
|
17
|
+
const referencePragma = sourceFile.pragmas.get('reference');
|
|
18
|
+
if (referencePragma) {
|
|
19
|
+
const refs = [referencePragma].flat();
|
|
20
|
+
for (const ref of refs) {
|
|
21
|
+
if (ref.arguments?.types) {
|
|
22
|
+
const { value: specifier, pos } = ref.arguments.types;
|
|
23
|
+
if (specifier)
|
|
24
|
+
importNodes.push({ specifier, identifier: undefined, pos, modifiers });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return importNodes;
|
|
29
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
import {
|
|
3
|
-
import { findAncestor, findDescendants, getAccessedIdentifiers, isAccessExpression, isImportCall, isTopLevel, stripQuotes, } from '../../ast-helpers.js';
|
|
2
|
+
import { IMPORT_MODIFIERS } from '../../../constants.js';
|
|
3
|
+
import { findAncestor, findDescendants, getAccessedIdentifiers, isAccessExpression, isImportCall, isInOpaqueExpression, isTopLevel, stripQuotes, } from '../../ast-helpers.js';
|
|
4
4
|
import { importVisitor as visit } from '../index.js';
|
|
5
5
|
const getSymbol = (node, isTopLevel) => (isTopLevel ? node.symbol : undefined);
|
|
6
6
|
export default visit(() => true, node => {
|
|
@@ -58,7 +58,9 @@ export default visit(() => true, node => {
|
|
|
58
58
|
accessExpression.name &&
|
|
59
59
|
accessExpression.name.escapedText === 'catch'
|
|
60
60
|
? node.parent.parent.parent.parent
|
|
61
|
-
: node.parent
|
|
61
|
+
: ts.isVariableDeclaration(node.parent)
|
|
62
|
+
? node.parent
|
|
63
|
+
: node.parent.parent;
|
|
62
64
|
if (ts.isVariableDeclaration(variableDeclaration) &&
|
|
63
65
|
ts.isVariableDeclarationList(variableDeclaration.parent)) {
|
|
64
66
|
const isTLA = isTopLevel(variableDeclaration.parent);
|
|
@@ -85,10 +87,15 @@ export default visit(() => true, node => {
|
|
|
85
87
|
const identifier = (element.propertyName ?? element.name).getText();
|
|
86
88
|
const alias = element.propertyName ? element.name.getText() : undefined;
|
|
87
89
|
const symbol = getSymbol(element, isTLA);
|
|
88
|
-
return { identifier, alias, symbol, specifier, pos: element.
|
|
90
|
+
return { identifier, alias, symbol, specifier, pos: element.name.getStart(), modifiers };
|
|
89
91
|
});
|
|
90
92
|
}
|
|
91
|
-
return {
|
|
93
|
+
return {
|
|
94
|
+
identifier: undefined,
|
|
95
|
+
specifier,
|
|
96
|
+
pos: node.arguments[0].pos,
|
|
97
|
+
modifiers: IMPORT_MODIFIERS.SIDE_EFFECTS,
|
|
98
|
+
};
|
|
92
99
|
}
|
|
93
100
|
const arrayLiteralExpression = node.parent;
|
|
94
101
|
const variableDeclarationParent = node.parent.parent?.parent?.parent;
|
|
@@ -106,18 +113,23 @@ export default visit(() => true, node => {
|
|
|
106
113
|
const identifier = (element.propertyName ?? element.name).getText();
|
|
107
114
|
const alias = element.propertyName ? element.name.getText() : undefined;
|
|
108
115
|
const symbol = getSymbol(element, isTL);
|
|
109
|
-
return { identifier, alias, symbol, specifier, pos: element.
|
|
116
|
+
return { identifier, alias, symbol, specifier, pos: element.getStart(), modifiers };
|
|
110
117
|
});
|
|
111
118
|
}
|
|
112
119
|
if (!ts.isOmittedExpression(element) && ts.isIdentifier(element.name)) {
|
|
113
120
|
const alias = String(element.name.escapedText);
|
|
114
121
|
const symbol = getSymbol(element, isTL);
|
|
115
|
-
return { identifier: 'default', symbol, alias, specifier, pos: element.
|
|
122
|
+
return { identifier: 'default', symbol, alias, specifier, pos: element.getStart(), modifiers };
|
|
116
123
|
}
|
|
117
|
-
return { identifier: 'default', specifier, pos: element.
|
|
124
|
+
return { identifier: 'default', specifier, pos: element.getStart(), modifiers };
|
|
118
125
|
}
|
|
119
126
|
}
|
|
120
|
-
return {
|
|
127
|
+
return {
|
|
128
|
+
identifier: undefined,
|
|
129
|
+
specifier,
|
|
130
|
+
pos: node.arguments[0].pos,
|
|
131
|
+
modifiers: isInOpaqueExpression(node) ? IMPORT_MODIFIERS.OPAQUE : IMPORT_MODIFIERS.SIDE_EFFECTS,
|
|
132
|
+
};
|
|
121
133
|
}
|
|
122
134
|
return { specifier, identifier: 'default', pos: node.arguments[0].pos, modifiers };
|
|
123
135
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
import { IMPORT_MODIFIERS } from '../../../constants.js';
|
|
2
|
+
import { IMPORT_MODIFIERS, IMPORT_STAR } from '../../../constants.js';
|
|
3
3
|
import { importVisitor as visit } from '../index.js';
|
|
4
4
|
const supportsJSDocImportTag = 'isJSDocImportTag' in ts;
|
|
5
5
|
const getImportSpecifiers = (node) => {
|
|
@@ -12,19 +12,33 @@ const getImportSpecifiers = (node) => {
|
|
|
12
12
|
imports.push({
|
|
13
13
|
specifier: importClause.literal.text,
|
|
14
14
|
identifier,
|
|
15
|
-
pos: importClause.literal.pos,
|
|
15
|
+
pos: node.qualifier?.getStart() ?? importClause.literal.pos,
|
|
16
16
|
modifiers: IMPORT_MODIFIERS.NONE,
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
if (supportsJSDocImportTag && ts.isJSDocImportTag(node) && ts.isStringLiteralLike(node.moduleSpecifier)) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
if (node.importClause?.namedBindings && ts.isNamedImportBindings(node.importClause.namedBindings)) {
|
|
22
|
+
const bindings = node.importClause.namedBindings;
|
|
23
|
+
if (ts.isNamespaceImport(bindings)) {
|
|
24
|
+
imports.push({
|
|
25
|
+
specifier: node.moduleSpecifier.text,
|
|
26
|
+
identifier: IMPORT_STAR,
|
|
27
|
+
pos: bindings.name.getStart(),
|
|
28
|
+
modifiers: IMPORT_MODIFIERS.TYPE_ONLY,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
for (const element of bindings.elements) {
|
|
33
|
+
imports.push({
|
|
34
|
+
specifier: node.moduleSpecifier.text,
|
|
35
|
+
identifier: String((element.propertyName ?? element.name).escapedText),
|
|
36
|
+
pos: element.name.getStart(),
|
|
37
|
+
modifiers: IMPORT_MODIFIERS.TYPE_ONLY,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
28
42
|
}
|
|
29
43
|
ts.forEachChild(node, visit);
|
|
30
44
|
}
|
|
@@ -15,7 +15,7 @@ export default visit(() => true, node => {
|
|
|
15
15
|
});
|
|
16
16
|
if (propertyAccessExpression) {
|
|
17
17
|
const identifier = String(propertyAccessExpression.name.escapedText);
|
|
18
|
-
return { identifier, specifier, pos: propertyAccessExpression.name.
|
|
18
|
+
return { identifier, specifier, pos: propertyAccessExpression.name.getStart(), modifiers };
|
|
19
19
|
}
|
|
20
20
|
const variableDeclaration = node.parent;
|
|
21
21
|
if (ts.isVariableDeclaration(variableDeclaration) &&
|
|
@@ -28,7 +28,7 @@ export default visit(() => true, node => {
|
|
|
28
28
|
alias,
|
|
29
29
|
symbol: isTLA ? variableDeclaration.symbol : undefined,
|
|
30
30
|
specifier,
|
|
31
|
-
pos:
|
|
31
|
+
pos: variableDeclaration.name.getStart(),
|
|
32
32
|
modifiers,
|
|
33
33
|
};
|
|
34
34
|
}
|
|
@@ -38,7 +38,7 @@ export default visit(() => true, node => {
|
|
|
38
38
|
const identifier = (element.propertyName ?? element.name).getText();
|
|
39
39
|
const alias = element.propertyName ? element.name.getText() : undefined;
|
|
40
40
|
const symbol = isTLA ? element.symbol : undefined;
|
|
41
|
-
return { identifier, specifier, alias, symbol, pos: element.
|
|
41
|
+
return { identifier, specifier, alias, symbol, pos: element.name.getStart(), modifiers };
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
return { identifier: 'default', specifier, pos: node.arguments[0].pos, modifiers };
|
|
@@ -53,7 +53,10 @@ export default visit(() => true, node => {
|
|
|
53
53
|
modifiers: IMPORT_MODIFIERS.RE_EXPORT,
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
|
-
|
|
56
|
+
if (ts.isCallExpression(node.parent)) {
|
|
57
|
+
return { identifier: 'default', specifier, pos: node.getEnd(), modifiers };
|
|
58
|
+
}
|
|
59
|
+
return { identifier: 'default', specifier, pos: node.getStart(), modifiers };
|
|
57
60
|
}
|
|
58
61
|
}
|
|
59
62
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
import type { ImportNode } from '../../types/imports.js';
|
|
3
2
|
import type { BoundSourceFile } from '../SourceFile.js';
|
|
4
3
|
export declare const isNotJS: (sourceFile: BoundSourceFile) => boolean;
|
|
5
4
|
export declare const isJS: (sourceFile: BoundSourceFile) => boolean;
|
|
6
5
|
export declare const isModule: (sourceFile: BoundSourceFile) => boolean;
|
|
7
|
-
export declare function getImportsFromPragmas(sourceFile: BoundSourceFile): ImportNode[];
|
|
8
6
|
export declare function hasImportSpecifier(node: ts.Statement, name: string, id?: string): boolean;
|
|
@@ -1,45 +1,7 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
import { IMPORT_MODIFIERS } from '../../constants.js';
|
|
3
2
|
export const isNotJS = (sourceFile) => !isJS(sourceFile);
|
|
4
3
|
export const isJS = (sourceFile) => sourceFile.scriptKind === ts.ScriptKind.JS || sourceFile.scriptKind === ts.ScriptKind.JSX;
|
|
5
4
|
export const isModule = (sourceFile) => ts.isExternalModule(sourceFile);
|
|
6
|
-
export function getImportsFromPragmas(sourceFile) {
|
|
7
|
-
const importNodes = [];
|
|
8
|
-
if (sourceFile.pragmas) {
|
|
9
|
-
const jsxImportSourcePragmas = sourceFile.pragmas.get('jsximportsource');
|
|
10
|
-
if (jsxImportSourcePragmas) {
|
|
11
|
-
const jsxImportSourcePragma = Array.isArray(jsxImportSourcePragmas)
|
|
12
|
-
? jsxImportSourcePragmas[jsxImportSourcePragmas.length - 1]
|
|
13
|
-
: jsxImportSourcePragmas;
|
|
14
|
-
const { factory: specifier } = jsxImportSourcePragma?.arguments ?? {};
|
|
15
|
-
const pos = jsxImportSourcePragma.range?.pos ?? 0;
|
|
16
|
-
if (specifier)
|
|
17
|
-
importNodes.push({
|
|
18
|
-
specifier,
|
|
19
|
-
identifier: '__jsx',
|
|
20
|
-
pos,
|
|
21
|
-
modifiers: IMPORT_MODIFIERS.TYPE_ONLY,
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
const referencePragma = sourceFile.pragmas.get('reference');
|
|
25
|
-
if (referencePragma) {
|
|
26
|
-
const refs = [referencePragma].flat();
|
|
27
|
-
for (const ref of refs) {
|
|
28
|
-
if (ref.arguments?.types) {
|
|
29
|
-
const { value: specifier, pos } = ref.arguments.types;
|
|
30
|
-
if (specifier)
|
|
31
|
-
importNodes.push({
|
|
32
|
-
specifier,
|
|
33
|
-
identifier: undefined,
|
|
34
|
-
pos,
|
|
35
|
-
modifiers: IMPORT_MODIFIERS.TYPE_ONLY,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return importNodes;
|
|
42
|
-
}
|
|
43
5
|
export function hasImportSpecifier(node, name, id) {
|
|
44
6
|
return (ts.isImportDeclaration(node) &&
|
|
45
7
|
ts.isStringLiteral(node.moduleSpecifier) &&
|
|
@@ -6,7 +6,7 @@ export default visit(() => true, node => {
|
|
|
6
6
|
if (ts.isImportDeclaration(node) && ts.isStringLiteralLike(node.moduleSpecifier)) {
|
|
7
7
|
const specifier = node.moduleSpecifier.text;
|
|
8
8
|
if (!node.importClause) {
|
|
9
|
-
return { specifier, identifier: undefined, pos: node.pos, modifiers: IMPORT_MODIFIERS.
|
|
9
|
+
return { specifier, identifier: undefined, pos: node.pos, modifiers: IMPORT_MODIFIERS.SIDE_EFFECTS };
|
|
10
10
|
}
|
|
11
11
|
const imports = [];
|
|
12
12
|
if (isDefaultImport(node)) {
|
|
@@ -8,7 +8,7 @@ export default visit(() => true, node => {
|
|
|
8
8
|
return {
|
|
9
9
|
identifier: IMPORT_STAR,
|
|
10
10
|
specifier: node.moduleSpecifier.text,
|
|
11
|
-
pos: node.
|
|
11
|
+
pos: node.moduleSpecifier.getStart() - 7,
|
|
12
12
|
modifiers: IMPORT_MODIFIERS.RE_EXPORT,
|
|
13
13
|
};
|
|
14
14
|
}
|
|
@@ -17,7 +17,7 @@ export default visit(() => true, node => {
|
|
|
17
17
|
identifier: IMPORT_STAR,
|
|
18
18
|
namespace: String(node.exportClause.name.text),
|
|
19
19
|
specifier: node.moduleSpecifier.text,
|
|
20
|
-
pos: node.exportClause.name.
|
|
20
|
+
pos: node.exportClause.name.getStart(),
|
|
21
21
|
modifiers: IMPORT_MODIFIERS.RE_EXPORT,
|
|
22
22
|
};
|
|
23
23
|
}
|
|
@@ -28,14 +28,14 @@ export default visit(() => true, node => {
|
|
|
28
28
|
identifier: String(element.propertyName.text),
|
|
29
29
|
alias: String(element.name.text),
|
|
30
30
|
specifier: specifier.text,
|
|
31
|
-
pos: element.
|
|
31
|
+
pos: element.propertyName.getStart(),
|
|
32
32
|
modifiers: IMPORT_MODIFIERS.RE_EXPORT,
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
return {
|
|
36
36
|
identifier: (element.propertyName ?? element.name).getText(),
|
|
37
37
|
specifier: specifier.text,
|
|
38
|
-
pos: element.
|
|
38
|
+
pos: element.name.getStart(),
|
|
39
39
|
modifiers: IMPORT_MODIFIERS.RE_EXPORT,
|
|
40
40
|
};
|
|
41
41
|
});
|
|
@@ -526,6 +526,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
|
|
|
526
526
|
entry?: string | string[] | undefined;
|
|
527
527
|
project?: string | string[] | undefined;
|
|
528
528
|
} | undefined;
|
|
529
|
+
taskfile?: string | boolean | string[] | {
|
|
530
|
+
config?: string | string[] | undefined;
|
|
531
|
+
entry?: string | string[] | undefined;
|
|
532
|
+
project?: string | string[] | undefined;
|
|
533
|
+
} | undefined;
|
|
529
534
|
travis?: string | boolean | string[] | {
|
|
530
535
|
config?: string | string[] | undefined;
|
|
531
536
|
entry?: string | string[] | undefined;
|
|
@@ -1117,6 +1122,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
|
|
|
1117
1122
|
entry?: string | string[] | undefined;
|
|
1118
1123
|
project?: string | string[] | undefined;
|
|
1119
1124
|
} | undefined;
|
|
1125
|
+
taskfile?: string | boolean | string[] | {
|
|
1126
|
+
config?: string | string[] | undefined;
|
|
1127
|
+
entry?: string | string[] | undefined;
|
|
1128
|
+
project?: string | string[] | undefined;
|
|
1129
|
+
} | undefined;
|
|
1120
1130
|
travis?: string | boolean | string[] | {
|
|
1121
1131
|
config?: string | string[] | undefined;
|
|
1122
1132
|
entry?: string | string[] | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const hasStrictlyEnumReferences: (importsForExport:
|
|
3
|
-
export declare const hasStrictlyNsReferences: (graph: ModuleGraph, importsForExport:
|
|
1
|
+
import type { ImportMaps, ModuleGraph } from '../types/module-graph.js';
|
|
2
|
+
export declare const hasStrictlyEnumReferences: (importsForExport: ImportMaps | undefined, id: string) => boolean;
|
|
3
|
+
export declare const hasStrictlyNsReferences: (graph: ModuleGraph, importsForExport: ImportMaps | undefined, id: string) => [boolean, string?];
|
|
4
4
|
export declare const getType: (hasOnlyNsReference: boolean, isType: boolean) => "exports" | "nsExports" | "types" | "nsTypes";
|