knip 5.9.0 → 5.9.2
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 -6
- package/dist/ConfigurationChief.js +10 -8
- package/dist/ConsoleStreamer.js +1 -1
- package/dist/DependencyDeputy.d.ts +1 -1
- package/dist/DependencyDeputy.js +22 -18
- package/dist/IssueCollector.js +10 -9
- package/dist/IssueFixer.js +9 -7
- package/dist/PrincipalFactory.d.ts +2 -2
- package/dist/PrincipalFactory.js +3 -5
- package/dist/ProjectPrincipal.d.ts +6 -6
- package/dist/ProjectPrincipal.js +12 -10
- package/dist/WorkspaceWorker.d.ts +2 -2
- package/dist/WorkspaceWorker.js +13 -9
- package/dist/binaries/index.js +1 -1
- package/dist/binaries/resolvers/bun.js +1 -1
- package/dist/binaries/resolvers/index.d.ts +12 -12
- package/dist/binaries/util.js +1 -1
- package/dist/cli.js +10 -9
- package/dist/compilers/index.d.ts +1 -1
- package/dist/index.js +65 -57
- package/dist/issues/initializers.d.ts +1 -1
- package/dist/manifest/helpers.js +1 -1
- package/dist/manifest/index.d.ts +1 -1
- package/dist/manifest/index.js +4 -4
- package/dist/plugins/ava/index.js +8 -8
- package/dist/plugins/babel/index.js +2 -2
- package/dist/plugins/babel/types.d.ts +1 -1
- package/dist/plugins/babel/types.js +1 -1
- package/dist/plugins/commitlint/index.d.ts +1 -1
- package/dist/plugins/cspell/index.d.ts +1 -1
- package/dist/plugins/drizzle/index.d.ts +1 -1
- package/dist/plugins/eleventy/helpers.d.ts +0 -1
- package/dist/plugins/eleventy/helpers.js +1 -2
- package/dist/plugins/eleventy/index.d.ts +1 -1
- package/dist/plugins/eslint/helpers.d.ts +1 -1
- package/dist/plugins/eslint/helpers.js +5 -2
- package/dist/plugins/eslint/index.d.ts +0 -1
- package/dist/plugins/eslint/index.js +1 -1
- package/dist/plugins/github-actions/index.js +1 -1
- package/dist/plugins/graphql-codegen/index.d.ts +1 -1
- package/dist/plugins/jest/index.js +5 -4
- package/dist/plugins/lint-staged/index.d.ts +1 -1
- package/dist/plugins/lint-staged/index.js +2 -1
- package/dist/plugins/linthtml/index.d.ts +1 -1
- package/dist/plugins/markdownlint/index.d.ts +1 -1
- package/dist/plugins/npm-package-json-lint/index.d.ts +1 -1
- package/dist/plugins/nyc/index.d.ts +1 -1
- package/dist/plugins/playwright/index.d.ts +1 -1
- package/dist/plugins/playwright-ct/index.js +1 -1
- package/dist/plugins/postcss/index.d.ts +1 -1
- package/dist/plugins/prettier/index.d.ts +1 -1
- package/dist/plugins/release-it/index.d.ts +1 -1
- package/dist/plugins/remark/index.d.ts +1 -1
- package/dist/plugins/semantic-release/index.d.ts +1 -1
- package/dist/plugins/stryker/index.d.ts +1 -1
- package/dist/plugins/stylelint/index.d.ts +1 -1
- package/dist/plugins/tsup/index.d.ts +1 -1
- package/dist/plugins/typescript/index.d.ts +0 -1
- package/dist/plugins/typescript/index.js +4 -3
- package/dist/plugins/unbuild/index.d.ts +1 -1
- package/dist/plugins/vite/index.d.ts +2 -2
- package/dist/plugins/vite/index.js +1 -1
- package/dist/plugins/vitest/index.d.ts +1 -1
- package/dist/plugins/vitest/index.js +8 -4
- package/dist/plugins/vue/index.d.ts +1 -1
- package/dist/plugins/vue/index.js +2 -1
- package/dist/plugins/vue/types.d.ts +1 -1
- package/dist/plugins/webpack/index.js +4 -4
- package/dist/plugins/wireit/index.d.ts +1 -1
- package/dist/plugins/yorkie/index.d.ts +1 -1
- package/dist/plugins/yorkie/index.js +2 -1
- package/dist/plugins.d.ts +1 -1
- package/dist/plugins.js +6 -3
- package/dist/reporters/codeowners.js +9 -7
- package/dist/reporters/compact.js +1 -1
- package/dist/reporters/index.d.ts +5 -5
- package/dist/reporters/json.js +3 -3
- package/dist/reporters/markdown.js +7 -7
- package/dist/reporters/symbols.js +8 -8
- package/dist/reporters/util.js +3 -2
- package/dist/types/config.d.ts +5 -5
- package/dist/types/config.js +1 -3
- package/dist/types/exports.d.ts +1 -1
- package/dist/types/exports.js +1 -1
- package/dist/types/imports.d.ts +1 -1
- package/dist/types/imports.js +1 -1
- package/dist/typescript/SourceFile.d.ts +1 -1
- package/dist/typescript/SourceFile.js +1 -1
- package/dist/typescript/SourceFileManager.d.ts +1 -1
- package/dist/typescript/ast-helpers.js +2 -2
- package/dist/typescript/createHosts.d.ts +1 -1
- package/dist/typescript/createHosts.js +1 -1
- package/dist/typescript/getImportsAndExports.d.ts +1 -1
- package/dist/typescript/getImportsAndExports.js +15 -12
- package/dist/typescript/resolveModuleNames.js +2 -2
- package/dist/typescript/visitors/dynamic-imports/importCall.d.ts +1 -1
- package/dist/typescript/visitors/dynamic-imports/importCall.js +24 -30
- package/dist/typescript/visitors/dynamic-imports/importType.d.ts +1 -1
- package/dist/typescript/visitors/dynamic-imports/index.d.ts +2 -2
- package/dist/typescript/visitors/dynamic-imports/index.js +0 -1
- package/dist/typescript/visitors/dynamic-imports/jsDocType.d.ts +1 -1
- package/dist/typescript/visitors/dynamic-imports/propertyAccessCall.d.ts +1 -1
- package/dist/typescript/visitors/dynamic-imports/requireCall.d.ts +1 -1
- package/dist/typescript/visitors/dynamic-imports/requireCall.js +14 -22
- package/dist/typescript/visitors/exports/exportAssignment.d.ts +1 -1
- package/dist/typescript/visitors/exports/exportDeclaration.d.ts +1 -1
- package/dist/typescript/visitors/exports/exportKeyword.d.ts +1 -1
- package/dist/typescript/visitors/exports/exportKeyword.js +10 -12
- package/dist/typescript/visitors/exports/exportsAccessExpression.d.ts +1 -1
- package/dist/typescript/visitors/exports/index.d.ts +2 -2
- package/dist/typescript/visitors/exports/index.js +0 -1
- package/dist/typescript/visitors/exports/moduleExportsAccessExpression.d.ts +1 -1
- package/dist/typescript/visitors/exports/moduleExportsAccessExpression.js +2 -4
- package/dist/typescript/visitors/imports/importDeclaration.d.ts +1 -1
- package/dist/typescript/visitors/imports/importDeclaration.js +18 -20
- package/dist/typescript/visitors/imports/importEqualsDeclaration.d.ts +1 -1
- package/dist/typescript/visitors/imports/index.d.ts +2 -2
- package/dist/typescript/visitors/imports/index.js +0 -1
- package/dist/typescript/visitors/imports/reExportDeclaration.d.ts +1 -1
- package/dist/typescript/visitors/imports/reExportDeclaration.js +14 -16
- package/dist/typescript/visitors/index.d.ts +1 -1
- package/dist/typescript/visitors/index.js +0 -1
- package/dist/typescript/visitors/scripts/bun.d.ts +1 -1
- package/dist/typescript/visitors/scripts/execa.d.ts +1 -1
- package/dist/typescript/visitors/scripts/index.d.ts +2 -2
- package/dist/typescript/visitors/scripts/index.js +0 -1
- package/dist/typescript/visitors/scripts/zx.d.ts +1 -1
- package/dist/util/Performance.d.ts +1 -1
- package/dist/util/Performance.js +5 -5
- package/dist/util/cli-arguments.js +1 -1
- package/dist/util/debug.js +1 -1
- package/dist/util/fs.d.ts +2 -2
- package/dist/util/fs.js +3 -3
- package/dist/util/get-included-issue-types.js +8 -5
- package/dist/util/get-reexporting-entry-file.js +12 -16
- package/dist/util/git.js +5 -5
- package/dist/util/glob.js +2 -2
- package/dist/util/globby.d.ts +1 -1
- package/dist/util/globby.js +11 -12
- package/dist/util/handle-dependency.d.ts +1 -1
- package/dist/util/handle-dependency.js +1 -2
- package/dist/util/is-identifier-referenced.js +4 -4
- package/dist/util/loader.js +3 -5
- package/dist/util/modules.js +7 -5
- package/dist/util/object.js +1 -1
- package/dist/util/plugin.d.ts +1 -1
- package/dist/util/plugin.js +12 -14
- package/dist/util/regex.js +1 -1
- package/dist/util/require.js +2 -2
- package/dist/util/tag.js +4 -2
- package/dist/util/type.js +2 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +15 -23
|
@@ -3,8 +3,8 @@ import path from 'node:path';
|
|
|
3
3
|
import ts from 'typescript';
|
|
4
4
|
import { getCompilerExtensions } from '../compilers/index.js';
|
|
5
5
|
import { FOREIGN_FILE_EXTENSIONS } from '../constants.js';
|
|
6
|
-
import { createCustomModuleResolver } from './resolveModuleNames.js';
|
|
7
6
|
import { SourceFileManager } from './SourceFileManager.js';
|
|
7
|
+
import { createCustomModuleResolver } from './resolveModuleNames.js';
|
|
8
8
|
import { createCustomSys } from './sys.js';
|
|
9
9
|
const libLocation = path.dirname(ts.getDefaultLibFilePath({}));
|
|
10
10
|
export const createHosts = ({ cwd, compilerOptions, entryPaths, compilers, isSkipLibs }) => {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
import type { BoundSourceFile, GetResolvedModule } from './SourceFile.js';
|
|
3
2
|
import type { Tags } from '../types/cli.js';
|
|
4
3
|
import type { SerializableExports } from '../types/exports.js';
|
|
5
4
|
import type { SerializableImportMap, UnresolvedImport } from '../types/imports.js';
|
|
6
5
|
import type { IssueSymbol } from '../types/issues.js';
|
|
6
|
+
import type { BoundSourceFile, GetResolvedModule } from './SourceFile.js';
|
|
7
7
|
export type GetImportsAndExportsOptions = {
|
|
8
8
|
skipTypeOnly: boolean;
|
|
9
9
|
skipExports: boolean;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { isBuiltin } from 'node:module';
|
|
2
2
|
import ts from 'typescript';
|
|
3
|
+
import { timerify } from '../util/Performance.js';
|
|
3
4
|
import { isStartsLikePackageName, sanitizeSpecifier } from '../util/modules.js';
|
|
4
5
|
import { isInNodeModules } from '../util/path.js';
|
|
5
|
-
import { timerify } from '../util/Performance.js';
|
|
6
6
|
import { shouldIgnore } from '../util/tag.js';
|
|
7
|
-
import {
|
|
7
|
+
import { getJSDocTags, getLineAndCharacterOfPosition, getMemberStringLiterals, isAccessExpression, } from './ast-helpers.js';
|
|
8
8
|
import getDynamicImportVisitors from './visitors/dynamic-imports/index.js';
|
|
9
9
|
import getExportVisitors from './visitors/exports/index.js';
|
|
10
10
|
import { getImportsFromPragmas } from './visitors/helpers.js';
|
|
@@ -121,7 +121,8 @@ const getImportsAndExports = (sourceFile, getResolvedModule, typeChecker, option
|
|
|
121
121
|
if (typeof member === 'string')
|
|
122
122
|
internalImport.identifiers.add(`${namespace}.${member}`);
|
|
123
123
|
else
|
|
124
|
-
|
|
124
|
+
for (const m of member)
|
|
125
|
+
internalImport.identifiers.add(`${namespace}.${m}`);
|
|
125
126
|
}
|
|
126
127
|
}
|
|
127
128
|
};
|
|
@@ -192,7 +193,7 @@ const getImportsAndExports = (sourceFile, getResolvedModule, typeChecker, option
|
|
|
192
193
|
const identifier = node?.getText();
|
|
193
194
|
if (node && identifier) {
|
|
194
195
|
const symbol = sourceFile.symbol?.exports?.get(identifier);
|
|
195
|
-
if (symbol
|
|
196
|
+
if (symbol?.valueDeclaration) {
|
|
196
197
|
if (!aliasedExports.has(identifier)) {
|
|
197
198
|
const pos = getLineAndCharacterOfPosition(symbol.valueDeclaration, symbol.valueDeclaration.pos);
|
|
198
199
|
aliasedExports.set(identifier, [{ symbol: identifier, ...pos }]);
|
|
@@ -206,15 +207,16 @@ const getImportsAndExports = (sourceFile, getResolvedModule, typeChecker, option
|
|
|
206
207
|
}
|
|
207
208
|
};
|
|
208
209
|
const visit = (node) => {
|
|
210
|
+
const addImportWithNode = (result) => addImport(result, node);
|
|
209
211
|
for (const visitor of visitors.dynamicImport) {
|
|
210
212
|
const result = visitor(node, options);
|
|
211
|
-
result && (Array.isArray(result) ? result.forEach(
|
|
213
|
+
result && (Array.isArray(result) ? result.forEach(addImportWithNode) : addImportWithNode(result));
|
|
212
214
|
}
|
|
213
215
|
const isTopLevel = node.parent === sourceFile || node.parent?.parent === sourceFile;
|
|
214
216
|
if (isTopLevel) {
|
|
215
217
|
for (const visitor of visitors.import) {
|
|
216
218
|
const result = visitor(node, options);
|
|
217
|
-
result && (Array.isArray(result) ? result.forEach(
|
|
219
|
+
result && (Array.isArray(result) ? result.forEach(addImportWithNode) : addImportWithNode(result));
|
|
218
220
|
}
|
|
219
221
|
for (const visitor of visitors.export) {
|
|
220
222
|
const result = visitor(node, options);
|
|
@@ -287,7 +289,8 @@ const getImportsAndExports = (sourceFile, getResolvedModule, typeChecker, option
|
|
|
287
289
|
visit(sourceFile);
|
|
288
290
|
const pragmaImports = getImportsFromPragmas(sourceFile);
|
|
289
291
|
if (pragmaImports)
|
|
290
|
-
|
|
292
|
+
for (const node of pragmaImports)
|
|
293
|
+
addImport(node, sourceFile);
|
|
291
294
|
const setRefs = (item) => {
|
|
292
295
|
if (!item.symbol)
|
|
293
296
|
return;
|
|
@@ -302,15 +305,15 @@ const getImportsAndExports = (sourceFile, getResolvedModule, typeChecker, option
|
|
|
302
305
|
}
|
|
303
306
|
}
|
|
304
307
|
};
|
|
305
|
-
for (
|
|
308
|
+
for (const key in exports) {
|
|
306
309
|
const item = exports[key];
|
|
307
310
|
if (options.ignoreExportsUsedInFile)
|
|
308
311
|
setRefs(item);
|
|
309
|
-
item.members
|
|
312
|
+
for (const member of item.members) {
|
|
310
313
|
setRefs(member);
|
|
311
|
-
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
+
member.symbol = undefined;
|
|
315
|
+
}
|
|
316
|
+
item.symbol = undefined;
|
|
314
317
|
}
|
|
315
318
|
return {
|
|
316
319
|
imports: {
|
|
@@ -63,7 +63,7 @@ export function createCustomModuleResolver(customSys, compilerOptions, virtualFi
|
|
|
63
63
|
const resolvedFileName = tsResolvedModule.resolvedFileName.replace(/\.d\.mts$/, '.mjs');
|
|
64
64
|
return { resolvedFileName, extension: '.mjs', isExternalLibraryImport: false, resolvedUsingTsExtension: false };
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
if (tsResolvedModule.extension === '.d.cts') {
|
|
67
67
|
const resolvedFileName = tsResolvedModule.resolvedFileName.replace(/\.d\.cts$/, '.cjs');
|
|
68
68
|
return { resolvedFileName, extension: '.cjs', isExternalLibraryImport: false, resolvedUsingTsExtension: false };
|
|
69
69
|
}
|
|
@@ -89,7 +89,7 @@ export function createCustomModuleResolver(customSys, compilerOptions, virtualFi
|
|
|
89
89
|
return tsResolvedModule;
|
|
90
90
|
}
|
|
91
91
|
const customResolvedModule = ts.resolveModuleName(sanitizedSpecifier, containingFile, compilerOptions, customSys).resolvedModule;
|
|
92
|
-
if (!customResolvedModule
|
|
92
|
+
if (!(customResolvedModule && isVirtualFilePath(customResolvedModule.resolvedFileName, virtualFileExtensions))) {
|
|
93
93
|
const module = fileExists(sanitizedSpecifier, containingFile);
|
|
94
94
|
if (module)
|
|
95
95
|
return module;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("
|
|
2
|
+
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../getImportsAndExports.js").GetImportsAndExportsOptions) => import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[] | undefined;
|
|
3
3
|
export default _default;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
import {
|
|
2
|
+
import { findAncestor, findDescendants, isAccessExpression, isImportCall, stripQuotes } from '../../ast-helpers.js';
|
|
3
3
|
import { importVisitor as visit } from '../index.js';
|
|
4
4
|
export default visit(() => true, node => {
|
|
5
5
|
if (isImportCall(node)) {
|
|
@@ -49,39 +49,33 @@ export default visit(() => true, node => {
|
|
|
49
49
|
if (ts.isIdentifier(variableDeclaration.name)) {
|
|
50
50
|
return { identifier: 'default', specifier, pos: node.arguments[0].pos };
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
return { identifier: 'default', specifier, pos: node.arguments[0].pos };
|
|
62
|
-
}
|
|
52
|
+
const bindings = findDescendants(variableDeclaration, ts.isBindingElement);
|
|
53
|
+
if (bindings.length > 0) {
|
|
54
|
+
return bindings.map(element => {
|
|
55
|
+
const identifier = (element.propertyName ?? element.name).getText();
|
|
56
|
+
return { identifier, specifier, pos: element.pos };
|
|
57
|
+
});
|
|
63
58
|
}
|
|
59
|
+
return { identifier: 'default', specifier, pos: node.arguments[0].pos };
|
|
64
60
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
return { identifier: 'default', specifier, pos: element.pos };
|
|
61
|
+
const arrayLiteralExpression = node.parent;
|
|
62
|
+
const variableDeclarationParent = node.parent.parent?.parent?.parent;
|
|
63
|
+
if (ts.isArrayLiteralExpression(arrayLiteralExpression) &&
|
|
64
|
+
variableDeclarationParent &&
|
|
65
|
+
ts.isVariableDeclarationList(variableDeclarationParent.parent) &&
|
|
66
|
+
ts.isVariableDeclaration(variableDeclarationParent) &&
|
|
67
|
+
ts.isArrayBindingPattern(variableDeclarationParent.name)) {
|
|
68
|
+
const index = arrayLiteralExpression.elements.indexOf(node);
|
|
69
|
+
const element = variableDeclarationParent.name.elements[index];
|
|
70
|
+
if (ts.isBindingElement(element) && ts.isObjectBindingPattern(element.name) && element.name.elements) {
|
|
71
|
+
return element.name.elements.map(element => {
|
|
72
|
+
const identifier = (element.propertyName ?? element.name).getText();
|
|
73
|
+
return { identifier, specifier, pos: element.pos };
|
|
74
|
+
});
|
|
82
75
|
}
|
|
83
|
-
return { identifier: 'default', specifier, pos:
|
|
76
|
+
return { identifier: 'default', specifier, pos: element.pos };
|
|
84
77
|
}
|
|
78
|
+
return { identifier: 'default', specifier, pos: node.arguments[0].pos };
|
|
85
79
|
}
|
|
86
80
|
}
|
|
87
81
|
return { specifier, identifier: 'default', pos: node.arguments[0].pos };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("
|
|
2
|
+
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../getImportsAndExports.js").GetImportsAndExportsOptions) => import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[] | undefined;
|
|
3
3
|
export default _default;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import ts from 'typescript';
|
|
2
|
-
declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("
|
|
1
|
+
import type ts from 'typescript';
|
|
2
|
+
declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("../../getImportsAndExports.js").GetImportsAndExportsOptions) => import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[] | undefined)[];
|
|
3
3
|
export default _default;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
import type { ImportNode } from '../../../types/imports.js';
|
|
3
|
-
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("
|
|
3
|
+
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../getImportsAndExports.js").GetImportsAndExportsOptions) => ImportNode | ImportNode[] | undefined;
|
|
4
4
|
export default _default;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("
|
|
2
|
+
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../getImportsAndExports.js").GetImportsAndExportsOptions) => import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[] | undefined;
|
|
3
3
|
export default _default;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("
|
|
2
|
+
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../getImportsAndExports.js").GetImportsAndExportsOptions) => import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[] | undefined;
|
|
3
3
|
export default _default;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
import {
|
|
2
|
+
import { findAncestor, findDescendants, isRequireCall } from '../../ast-helpers.js';
|
|
3
3
|
import { importVisitor as visit } from '../index.js';
|
|
4
4
|
export default visit(() => true, node => {
|
|
5
5
|
if (isRequireCall(node)) {
|
|
@@ -15,30 +15,22 @@ export default visit(() => true, node => {
|
|
|
15
15
|
const identifier = String(propertyAccessExpression.name.escapedText);
|
|
16
16
|
return { identifier, specifier, pos: propertyAccessExpression.name.pos };
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (ts.isIdentifier(variableDeclaration.name)) {
|
|
23
|
-
return { identifier: 'default', specifier, pos: node.arguments[0].pos };
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
const bindings = findDescendants(variableDeclaration, ts.isBindingElement);
|
|
27
|
-
if (bindings.length > 0) {
|
|
28
|
-
return bindings.map(element => {
|
|
29
|
-
const identifier = (element.propertyName ?? element.name).getText();
|
|
30
|
-
return { identifier, specifier, pos: element.pos };
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
return { identifier: 'default', specifier, pos: node.arguments[0].pos };
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
18
|
+
const variableDeclaration = node.parent;
|
|
19
|
+
if (ts.isVariableDeclaration(variableDeclaration) &&
|
|
20
|
+
ts.isVariableDeclarationList(variableDeclaration.parent)) {
|
|
21
|
+
if (ts.isIdentifier(variableDeclaration.name)) {
|
|
39
22
|
return { identifier: 'default', specifier, pos: node.arguments[0].pos };
|
|
40
23
|
}
|
|
24
|
+
const bindings = findDescendants(variableDeclaration, ts.isBindingElement);
|
|
25
|
+
if (bindings.length > 0) {
|
|
26
|
+
return bindings.map(element => {
|
|
27
|
+
const identifier = (element.propertyName ?? element.name).getText();
|
|
28
|
+
return { identifier, specifier, pos: element.pos };
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return { identifier: 'default', specifier, pos: node.arguments[0].pos };
|
|
41
32
|
}
|
|
33
|
+
return { identifier: 'default', specifier, pos: node.arguments[0].pos };
|
|
42
34
|
}
|
|
43
35
|
}
|
|
44
36
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("
|
|
2
|
+
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../getImportsAndExports.js").GetImportsAndExportsOptions) => import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[] | undefined;
|
|
3
3
|
export default _default;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("
|
|
2
|
+
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../getImportsAndExports.js").GetImportsAndExportsOptions) => import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[] | undefined;
|
|
3
3
|
export default _default;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("
|
|
2
|
+
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../getImportsAndExports.js").GetImportsAndExportsOptions) => import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[] | undefined;
|
|
3
3
|
export default _default;
|
|
@@ -22,7 +22,7 @@ export default visit(() => true, (node, { isFixExports, isFixTypes, isReportClas
|
|
|
22
22
|
}
|
|
23
23
|
}));
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
if (ts.isArrayBindingPattern(declaration.name)) {
|
|
26
26
|
return compact(declaration.name.elements.map(element => {
|
|
27
27
|
if (ts.isBindingElement(element)) {
|
|
28
28
|
const fix = isFixExports ? [element.getStart(), element.getEnd()] : undefined;
|
|
@@ -36,17 +36,15 @@ export default visit(() => true, (node, { isFixExports, isFixTypes, isReportClas
|
|
|
36
36
|
}
|
|
37
37
|
}));
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
};
|
|
49
|
-
}
|
|
39
|
+
const identifier = declaration.name.getText();
|
|
40
|
+
const fix = isFixExports ? [exportKeyword.getStart(), exportKeyword.getEnd() + 1] : undefined;
|
|
41
|
+
return {
|
|
42
|
+
node: declaration,
|
|
43
|
+
identifier,
|
|
44
|
+
type: SymbolType.UNKNOWN,
|
|
45
|
+
pos: declaration.name.getStart(),
|
|
46
|
+
fix,
|
|
47
|
+
};
|
|
50
48
|
});
|
|
51
49
|
}
|
|
52
50
|
const defaultKeyword = node.modifiers?.find(mod => mod.kind === ts.SyntaxKind.DefaultKeyword);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("
|
|
2
|
+
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../getImportsAndExports.js").GetImportsAndExportsOptions) => import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[] | undefined;
|
|
3
3
|
export default _default;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import ts from 'typescript';
|
|
2
|
-
declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("
|
|
1
|
+
import type ts from 'typescript';
|
|
2
|
+
declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("../../getImportsAndExports.js").GetImportsAndExportsOptions) => import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[] | undefined)[];
|
|
3
3
|
export default _default;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("
|
|
2
|
+
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../getImportsAndExports.js").GetImportsAndExportsOptions) => import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[] | undefined;
|
|
3
3
|
export default _default;
|
|
@@ -21,7 +21,7 @@ export default visit(isJS, (node, { isFixExports }) => {
|
|
|
21
21
|
fix,
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
if (isModuleExportsAccess(node.expression.left)) {
|
|
25
25
|
const expr = node.expression.right;
|
|
26
26
|
if (ts.isObjectLiteralExpression(expr) && expr.properties.every(ts.isShorthandPropertyAssignment)) {
|
|
27
27
|
return expr.properties.map(node => {
|
|
@@ -29,9 +29,7 @@ export default visit(isJS, (node, { isFixExports }) => {
|
|
|
29
29
|
return { node, identifier: node.getText(), type: SymbolType.UNKNOWN, pos: node.getStart(), fix };
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
return { node, identifier: 'default', type: SymbolType.UNKNOWN, pos: expr.pos + 1, fix: undefined };
|
|
34
|
-
}
|
|
32
|
+
return { node, identifier: 'default', type: SymbolType.UNKNOWN, pos: expr.pos + 1, fix: undefined };
|
|
35
33
|
}
|
|
36
34
|
}
|
|
37
35
|
else if (ts.isElementAccessExpression(node.expression.left) &&
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("
|
|
2
|
+
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../getImportsAndExports.js").GetImportsAndExportsOptions) => import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[] | undefined;
|
|
3
3
|
export default _default;
|
|
@@ -7,30 +7,28 @@ export default visit(() => true, node => {
|
|
|
7
7
|
if (!node.importClause) {
|
|
8
8
|
return { specifier, identifier: undefined, pos: node.pos };
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const imports = [];
|
|
11
|
+
if (isDefaultImport(node)) {
|
|
12
|
+
imports.push({ specifier, identifier: 'default', pos: node.moduleSpecifier.pos });
|
|
13
|
+
}
|
|
14
|
+
if (node.importClause?.namedBindings) {
|
|
15
|
+
if (ts.isNamespaceImport(node.importClause.namedBindings)) {
|
|
16
|
+
const symbol = node.importClause.namedBindings.symbol;
|
|
17
|
+
imports.push({ symbol, specifier, identifier: '*', pos: symbol?.declarations[0]?.pos ?? node.pos });
|
|
14
18
|
}
|
|
15
|
-
if (node.importClause
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
imports.push({
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
symbol: element.symbol,
|
|
25
|
-
isTypeOnly: node.importClause?.isTypeOnly,
|
|
26
|
-
specifier,
|
|
27
|
-
identifier,
|
|
28
|
-
pos: element.pos,
|
|
29
|
-
});
|
|
19
|
+
if (ts.isNamedImports(node.importClause.namedBindings)) {
|
|
20
|
+
for (const element of node.importClause.namedBindings.elements) {
|
|
21
|
+
const identifier = (element.propertyName ?? element.name).getText();
|
|
22
|
+
imports.push({
|
|
23
|
+
symbol: element.symbol,
|
|
24
|
+
isTypeOnly: node.importClause?.isTypeOnly,
|
|
25
|
+
specifier,
|
|
26
|
+
identifier,
|
|
27
|
+
pos: element.pos,
|
|
30
28
|
});
|
|
31
29
|
}
|
|
32
30
|
}
|
|
33
|
-
return imports;
|
|
34
31
|
}
|
|
32
|
+
return imports;
|
|
35
33
|
}
|
|
36
34
|
});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("
|
|
2
|
+
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../getImportsAndExports.js").GetImportsAndExportsOptions) => import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[] | undefined;
|
|
3
3
|
export default _default;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import ts from 'typescript';
|
|
2
|
-
declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("
|
|
1
|
+
import type ts from 'typescript';
|
|
2
|
+
declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("../../getImportsAndExports.js").GetImportsAndExportsOptions) => import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[] | undefined)[];
|
|
3
3
|
export default _default;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("
|
|
2
|
+
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../getImportsAndExports.js").GetImportsAndExportsOptions) => import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[] | undefined;
|
|
3
3
|
export default _default;
|
|
@@ -6,7 +6,7 @@ export default visit(() => true, node => {
|
|
|
6
6
|
if (!node.exportClause) {
|
|
7
7
|
return { identifier: '*', specifier: node.moduleSpecifier.text, isReExport: true, pos: node.pos };
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
if (node.exportClause.kind === ts.SyntaxKind.NamespaceExport) {
|
|
10
10
|
return {
|
|
11
11
|
identifier: '*',
|
|
12
12
|
namespace: node.exportClause.name.escapedText,
|
|
@@ -15,26 +15,24 @@ export default visit(() => true, node => {
|
|
|
15
15
|
pos: node.exportClause.name.pos,
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (element.propertyName && element.name) {
|
|
22
|
-
return {
|
|
23
|
-
identifier: String(element.name.escapedText),
|
|
24
|
-
namespace: element.propertyName.escapedText,
|
|
25
|
-
specifier: specifier.text,
|
|
26
|
-
isReExport: true,
|
|
27
|
-
pos: element.pos,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
18
|
+
const specifier = node.moduleSpecifier;
|
|
19
|
+
return node.exportClause.elements.map(element => {
|
|
20
|
+
if (element.propertyName && element.name) {
|
|
30
21
|
return {
|
|
31
|
-
identifier: (element.
|
|
22
|
+
identifier: String(element.name.escapedText),
|
|
23
|
+
namespace: element.propertyName.escapedText,
|
|
32
24
|
specifier: specifier.text,
|
|
33
25
|
isReExport: true,
|
|
34
26
|
pos: element.pos,
|
|
35
27
|
};
|
|
36
|
-
}
|
|
37
|
-
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
identifier: (element.propertyName ?? element.name).getText(),
|
|
31
|
+
specifier: specifier.text,
|
|
32
|
+
isReExport: true,
|
|
33
|
+
pos: element.pos,
|
|
34
|
+
};
|
|
35
|
+
});
|
|
38
36
|
}
|
|
39
37
|
}
|
|
40
38
|
});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("
|
|
2
|
+
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../getImportsAndExports.js").GetImportsAndExportsOptions) => string | string[] | undefined;
|
|
3
3
|
export default _default;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("
|
|
2
|
+
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../getImportsAndExports.js").GetImportsAndExportsOptions) => string | string[] | undefined;
|
|
3
3
|
export default _default;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import ts from 'typescript';
|
|
2
|
-
declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("
|
|
1
|
+
import type ts from 'typescript';
|
|
2
|
+
declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("../../getImportsAndExports.js").GetImportsAndExportsOptions) => string | string[] | undefined)[];
|
|
3
3
|
export default _default;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("
|
|
2
|
+
declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../getImportsAndExports.js").GetImportsAndExportsOptions) => string | string[] | undefined;
|
|
3
3
|
export default _default;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
-
import {
|
|
3
|
+
import { type PerformanceEntry, PerformanceObserver } from 'node:perf_hooks';
|
|
4
4
|
import { memoryUsage } from 'node:process';
|
|
5
5
|
export declare const timerify: <T extends (...params: any[]) => any>(fn: T, name?: string) => T;
|
|
6
6
|
export declare class Performance {
|