knip 5.73.3 → 5.74.0
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/ProjectPrincipal.d.ts +0 -1
- package/dist/ProjectPrincipal.js +18 -13
- package/dist/binaries/package-manager/bun.js +10 -0
- package/dist/compilers/index.d.ts +10 -0
- package/dist/compilers/scss.js +1 -1
- package/dist/constants.d.ts +6 -1
- package/dist/constants.js +6 -1
- package/dist/graph/build.js +18 -9
- package/dist/graph-explorer/visitors.js +3 -3
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.js +2 -0
- package/dist/plugins/swc/index.d.ts +3 -0
- package/dist/plugins/swc/index.js +18 -0
- package/dist/plugins/swc/types.d.ts +7 -0
- package/dist/plugins/swc/types.js +1 -0
- 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/exports.d.ts +14 -13
- package/dist/types/imports.d.ts +7 -7
- package/dist/types/module-graph.d.ts +27 -26
- package/dist/typescript/ast-helpers.d.ts +5 -3
- package/dist/typescript/ast-helpers.js +5 -2
- package/dist/typescript/create-hosts.d.ts +1 -2
- package/dist/typescript/create-hosts.js +2 -2
- package/dist/typescript/get-imports-and-exports.js +18 -15
- package/dist/typescript/pragmas/custom.js +11 -3
- package/dist/typescript/pragmas/typescript.js +20 -4
- package/dist/typescript/resolve-module-names.d.ts +1 -1
- package/dist/typescript/resolve-module-names.js +5 -9
- package/dist/typescript/visitors/dynamic-imports/importCall.js +100 -14
- package/dist/typescript/visitors/dynamic-imports/importType.js +5 -2
- package/dist/typescript/visitors/dynamic-imports/jsDocType.js +13 -4
- package/dist/typescript/visitors/dynamic-imports/requireCall.js +52 -8
- package/dist/typescript/visitors/dynamic-imports/resolveCall.js +5 -2
- package/dist/typescript/visitors/dynamic-imports/urlConstructor.js +5 -2
- package/dist/typescript/visitors/exports/exportAssignment.js +7 -9
- package/dist/typescript/visitors/exports/exportDeclaration.js +2 -2
- package/dist/typescript/visitors/exports/exportKeyword.js +49 -10
- package/dist/typescript/visitors/exports/exportsAccessExpression.js +4 -1
- package/dist/typescript/visitors/exports/moduleExportsAccessExpression.js +27 -3
- package/dist/typescript/visitors/imports/importDeclaration.js +19 -3
- package/dist/typescript/visitors/imports/importEqualsDeclaration.js +3 -2
- package/dist/typescript/visitors/imports/reExportDeclaration.js +15 -5
- package/dist/util/create-options.d.ts +10 -0
- package/dist/util/errors.js +2 -0
- package/dist/util/get-referenced-inputs.js +3 -3
- package/dist/util/module-graph.d.ts +0 -1
- package/dist/util/module-graph.js +3 -2
- package/dist/util/modules.js +7 -1
- package/dist/util/resolve.js +3 -3
- package/dist/util/to-source-path.d.ts +2 -2
- package/dist/util/to-source-path.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
- package/schema.json +4 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
import { FIX_FLAGS, SYMBOL_TYPE } from '../constants.js';
|
|
2
|
+
import { FIX_FLAGS, MEMBER_FLAGS, SYMBOL_TYPE } from '../constants.js';
|
|
3
3
|
function isGetOrSetAccessorDeclaration(node) {
|
|
4
4
|
return node.kind === ts.SyntaxKind.SetAccessor || node.kind === ts.SyntaxKind.GetAccessor;
|
|
5
5
|
}
|
|
@@ -48,7 +48,7 @@ export const getNodeType = (node) => {
|
|
|
48
48
|
return SYMBOL_TYPE.VARIABLE;
|
|
49
49
|
return SYMBOL_TYPE.UNKNOWN;
|
|
50
50
|
};
|
|
51
|
-
export const
|
|
51
|
+
export const isNonPrivateDeclaration = (member) => (ts.isPropertyDeclaration(member) || ts.isMethodDeclaration(member) || isGetOrSetAccessorDeclaration(member)) &&
|
|
52
52
|
!isPrivateMember(member);
|
|
53
53
|
export const getClassMember = (member, isFixTypes) => ({
|
|
54
54
|
node: member,
|
|
@@ -56,6 +56,7 @@ export const getClassMember = (member, isFixTypes) => ({
|
|
|
56
56
|
pos: member.name.getStart() + (ts.isComputedPropertyName(member.name) ? 1 : 0),
|
|
57
57
|
type: SYMBOL_TYPE.MEMBER,
|
|
58
58
|
fix: isFixTypes ? [member.getStart(), member.getEnd(), FIX_FLAGS.NONE] : undefined,
|
|
59
|
+
flags: member.kind === ts.SyntaxKind.SetAccessor ? MEMBER_FLAGS.SETTER : MEMBER_FLAGS.NONE,
|
|
59
60
|
});
|
|
60
61
|
export const getEnumMember = (member, isFixTypes) => ({
|
|
61
62
|
node: member,
|
|
@@ -65,6 +66,7 @@ export const getEnumMember = (member, isFixTypes) => ({
|
|
|
65
66
|
fix: isFixTypes
|
|
66
67
|
? [member.getStart(), member.getEnd(), FIX_FLAGS.OBJECT_BINDING | FIX_FLAGS.WITH_NEWLINE]
|
|
67
68
|
: undefined,
|
|
69
|
+
flags: MEMBER_FLAGS.NONE,
|
|
68
70
|
});
|
|
69
71
|
export function stripQuotes(name) {
|
|
70
72
|
const length = name.length;
|
|
@@ -202,6 +204,7 @@ export const isConsiderReferencedNS = (node) => ts.isPropertyAssignment(node.par
|
|
|
202
204
|
ts.isSpreadAssignment(node.parent) ||
|
|
203
205
|
ts.isArrayLiteralExpression(node.parent) ||
|
|
204
206
|
ts.isExportAssignment(node.parent) ||
|
|
207
|
+
(ts.isBindingElement(node.parent) && node.parent.initializer === node) ||
|
|
205
208
|
ts.isTypeQueryNode(node.parent.parent);
|
|
206
209
|
export const isInOpaqueExpression = (node) => ts.isAwaitExpression(node.parent)
|
|
207
210
|
? isInOpaqueExpression(node.parent)
|
|
@@ -7,12 +7,11 @@ type CreateHostsOptions = {
|
|
|
7
7
|
compilerOptions: ts.CompilerOptions;
|
|
8
8
|
entryPaths: Set<string>;
|
|
9
9
|
compilers: [SyncCompilers, AsyncCompilers];
|
|
10
|
-
isSkipLibs: boolean;
|
|
11
10
|
toSourceFilePath: ToSourceFilePath;
|
|
12
11
|
useResolverCache: boolean;
|
|
13
12
|
fileManager: SourceFileManager;
|
|
14
13
|
};
|
|
15
|
-
export declare const createHosts: ({ cwd, compilerOptions, fileManager, entryPaths, compilers,
|
|
14
|
+
export declare const createHosts: ({ cwd, compilerOptions, fileManager, entryPaths, compilers, toSourceFilePath, useResolverCache, }: CreateHostsOptions) => {
|
|
16
15
|
fileManager: SourceFileManager;
|
|
17
16
|
compilerHost: ts.CompilerHost;
|
|
18
17
|
resolveModuleNames: (moduleNames: string[], containingFile: string) => Array<ts.ResolvedModuleFull | undefined>;
|
|
@@ -4,9 +4,9 @@ import ts from 'typescript';
|
|
|
4
4
|
import { getCompilerExtensions } from '../compilers/index.js';
|
|
5
5
|
import { createCustomModuleResolver } from './resolve-module-names.js';
|
|
6
6
|
const libLocation = path.dirname(ts.getDefaultLibFilePath({}));
|
|
7
|
-
export const createHosts = ({ cwd, compilerOptions, fileManager, entryPaths, compilers,
|
|
7
|
+
export const createHosts = ({ cwd, compilerOptions, fileManager, entryPaths, compilers, toSourceFilePath, useResolverCache, }) => {
|
|
8
8
|
const compilerExtensions = getCompilerExtensions(compilers);
|
|
9
|
-
const resolveModuleNames = createCustomModuleResolver(compilerOptions, compilerExtensions, toSourceFilePath, useResolverCache
|
|
9
|
+
const resolveModuleNames = createCustomModuleResolver(compilerOptions, compilerExtensions, toSourceFilePath, useResolverCache);
|
|
10
10
|
const languageServiceHost = {
|
|
11
11
|
getCompilationSettings: () => compilerOptions,
|
|
12
12
|
getScriptFileNames: () => Array.from(entryPaths),
|
|
@@ -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_FLAGS, 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';
|
|
@@ -31,6 +31,7 @@ const createMember = (node, member, pos) => {
|
|
|
31
31
|
fix: member.fix,
|
|
32
32
|
self: [0, false],
|
|
33
33
|
jsDocTags: getJSDocTags(member.node),
|
|
34
|
+
flags: member.flags,
|
|
34
35
|
};
|
|
35
36
|
};
|
|
36
37
|
const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, ignoreExportsUsedInFile, skipExports) => {
|
|
@@ -83,7 +84,7 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
|
|
|
83
84
|
};
|
|
84
85
|
const addInternalImport = (options) => {
|
|
85
86
|
const { symbol, filePath, namespace, specifier, modifiers } = options;
|
|
86
|
-
const identifier = options.identifier ?? (modifiers &
|
|
87
|
+
const identifier = options.identifier ?? (modifiers & IMPORT_FLAGS.OPAQUE ? OPAQUE : SIDE_EFFECTS);
|
|
87
88
|
const isStar = identifier === IMPORT_STAR;
|
|
88
89
|
imports.add({
|
|
89
90
|
filePath,
|
|
@@ -92,14 +93,14 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
|
|
|
92
93
|
pos: options.pos,
|
|
93
94
|
line: options.line,
|
|
94
95
|
col: options.col,
|
|
95
|
-
isTypeOnly: !!(modifiers &
|
|
96
|
+
isTypeOnly: !!(modifiers & IMPORT_FLAGS.TYPE_ONLY),
|
|
96
97
|
});
|
|
97
98
|
const file = internal.get(filePath);
|
|
98
99
|
const importMaps = file ?? createImports();
|
|
99
100
|
if (!file)
|
|
100
101
|
internal.set(filePath, importMaps);
|
|
101
102
|
const nsOrAlias = symbol ? String(symbol.escapedName) : options.alias;
|
|
102
|
-
if (modifiers &
|
|
103
|
+
if (modifiers & IMPORT_FLAGS.RE_EXPORT) {
|
|
103
104
|
if (isStar && namespace) {
|
|
104
105
|
addValue(importMaps.reExportedNs, namespace, sourceFile.fileName);
|
|
105
106
|
}
|
|
@@ -134,9 +135,9 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
|
|
|
134
135
|
const filePath = module.resolvedFileName;
|
|
135
136
|
if (filePath) {
|
|
136
137
|
if (!isInNodeModules(filePath)) {
|
|
137
|
-
if (opts.modifiers &
|
|
138
|
+
if (opts.modifiers & IMPORT_FLAGS.ENTRY)
|
|
138
139
|
entryFiles.add(filePath);
|
|
139
|
-
if (opts.modifiers &
|
|
140
|
+
if (opts.modifiers & IMPORT_FLAGS.BRIDGE)
|
|
140
141
|
programFiles.add(filePath);
|
|
141
142
|
}
|
|
142
143
|
if (!module.isExternalLibraryImport || !isInNodeModules(filePath)) {
|
|
@@ -149,7 +150,7 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
|
|
|
149
150
|
});
|
|
150
151
|
}
|
|
151
152
|
if (module.isExternalLibraryImport) {
|
|
152
|
-
if (options.skipTypeOnly && opts.modifiers &
|
|
153
|
+
if (options.skipTypeOnly && opts.modifiers & IMPORT_FLAGS.TYPE_ONLY)
|
|
153
154
|
return;
|
|
154
155
|
const sanitizedSpecifier = sanitizeSpecifier(isInNodeModules(filePath) || isInNodeModules(opts.specifier)
|
|
155
156
|
? getPackageNameFromFilePath(opts.specifier)
|
|
@@ -166,19 +167,19 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
|
|
|
166
167
|
pos: opts.pos,
|
|
167
168
|
line: line + 1,
|
|
168
169
|
col: character + 2,
|
|
169
|
-
isTypeOnly: !!(opts.modifiers &
|
|
170
|
+
isTypeOnly: !!(opts.modifiers & IMPORT_FLAGS.TYPE_ONLY),
|
|
170
171
|
});
|
|
171
172
|
}
|
|
172
173
|
}
|
|
173
174
|
}
|
|
174
175
|
else {
|
|
175
|
-
if (options.skipTypeOnly && opts.modifiers &
|
|
176
|
+
if (options.skipTypeOnly && opts.modifiers & IMPORT_FLAGS.TYPE_ONLY)
|
|
176
177
|
return;
|
|
177
178
|
if (shouldIgnore(getJSDocTags(node), options.tags))
|
|
178
179
|
return;
|
|
179
180
|
if (opts.specifier.startsWith(PROTOCOL_VIRTUAL))
|
|
180
181
|
return;
|
|
181
|
-
if (opts.modifiers && opts.modifiers &
|
|
182
|
+
if (opts.modifiers && opts.modifiers & IMPORT_FLAGS.OPTIONAL) {
|
|
182
183
|
programFiles.add(resolve(dirname(sourceFile.fileName), opts.specifier));
|
|
183
184
|
return;
|
|
184
185
|
}
|
|
@@ -191,11 +192,11 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
|
|
|
191
192
|
pos,
|
|
192
193
|
line: line + 1,
|
|
193
194
|
col: character + 2,
|
|
194
|
-
isTypeOnly: !!(opts.modifiers &
|
|
195
|
+
isTypeOnly: !!(opts.modifiers & IMPORT_FLAGS.TYPE_ONLY),
|
|
195
196
|
});
|
|
196
197
|
}
|
|
197
198
|
};
|
|
198
|
-
const addExport = ({ node, symbol, identifier, type, pos, members
|
|
199
|
+
const addExport = ({ node, symbol, identifier, type, pos, members, fix }) => {
|
|
199
200
|
if (skipExports)
|
|
200
201
|
return;
|
|
201
202
|
let isReExport = Boolean(node.parent?.parent && ts.isExportDeclaration(node.parent.parent) && node.parent.parent.moduleSpecifier);
|
|
@@ -222,9 +223,9 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
|
|
|
222
223
|
const exportMembers = members.map(member => createMember(node, member, member.pos));
|
|
223
224
|
const item = exports.get(identifier);
|
|
224
225
|
if (item) {
|
|
225
|
-
const members = [...
|
|
226
|
-
const tags = new Set([...
|
|
227
|
-
const fixes = fix ? [...
|
|
226
|
+
const members = [...item.members, ...exportMembers];
|
|
227
|
+
const tags = new Set([...item.jsDocTags, ...jsDocTags]);
|
|
228
|
+
const fixes = fix ? [...item.fixes, fix] : item.fixes;
|
|
228
229
|
exports.set(identifier, { ...item, members, jsDocTags: tags, fixes, isReExport });
|
|
229
230
|
}
|
|
230
231
|
else {
|
|
@@ -448,6 +449,8 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
|
|
|
448
449
|
exports,
|
|
449
450
|
duplicates: [...aliasedExports.values()],
|
|
450
451
|
scripts,
|
|
452
|
+
imported: undefined,
|
|
453
|
+
internalImportCache: undefined,
|
|
451
454
|
};
|
|
452
455
|
};
|
|
453
456
|
export const _getImportsAndExports = timerify(getImportsAndExports);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IMPORT_FLAGS } from '../../constants.js';
|
|
2
2
|
import { getEnvSpecifier } from '../../plugins/vitest/helpers.js';
|
|
3
3
|
import { isAbsolute, isInternal } from '../../util/path.js';
|
|
4
4
|
import { getLeadingComments, stripQuotes } from '../ast-helpers.js';
|
|
@@ -15,10 +15,18 @@ export const collectCustomImports = (sourceFile) => {
|
|
|
15
15
|
if (!id)
|
|
16
16
|
continue;
|
|
17
17
|
const isLocal = isInternal(id) || isAbsolute(id);
|
|
18
|
-
const modifiers = isLocal ?
|
|
18
|
+
const modifiers = isLocal ? IMPORT_FLAGS.ENTRY : IMPORT_FLAGS.NONE;
|
|
19
19
|
const offset = match[0].length - match[2].length;
|
|
20
20
|
const specifier = isLocal || id === 'node' ? id : getEnvSpecifier(id);
|
|
21
|
-
importNodes.push({
|
|
21
|
+
importNodes.push({
|
|
22
|
+
specifier,
|
|
23
|
+
identifier: undefined,
|
|
24
|
+
pos: comment.pos + match.index + offset,
|
|
25
|
+
modifiers,
|
|
26
|
+
alias: undefined,
|
|
27
|
+
namespace: undefined,
|
|
28
|
+
symbol: undefined,
|
|
29
|
+
});
|
|
22
30
|
}
|
|
23
31
|
}
|
|
24
32
|
return importNodes;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IMPORT_FLAGS } from '../../constants.js';
|
|
2
2
|
export const collectTypeScriptPragmaImports = (sourceFile) => {
|
|
3
3
|
if (!sourceFile.pragmas || sourceFile.pragmas.size === 0)
|
|
4
4
|
return [];
|
|
5
5
|
const importNodes = [];
|
|
6
|
-
const modifiers =
|
|
6
|
+
const modifiers = IMPORT_FLAGS.TYPE_ONLY;
|
|
7
7
|
const jsxImportSourcePragmas = sourceFile.pragmas.get('jsximportsource');
|
|
8
8
|
if (jsxImportSourcePragmas) {
|
|
9
9
|
const jsxImportSourcePragma = Array.isArray(jsxImportSourcePragmas)
|
|
@@ -12,7 +12,15 @@ export const collectTypeScriptPragmaImports = (sourceFile) => {
|
|
|
12
12
|
const { factory: specifier } = jsxImportSourcePragma?.arguments ?? {};
|
|
13
13
|
const pos = jsxImportSourcePragma.range?.pos ?? 0;
|
|
14
14
|
if (specifier)
|
|
15
|
-
importNodes.push({
|
|
15
|
+
importNodes.push({
|
|
16
|
+
specifier,
|
|
17
|
+
identifier: undefined,
|
|
18
|
+
pos,
|
|
19
|
+
modifiers,
|
|
20
|
+
alias: undefined,
|
|
21
|
+
namespace: undefined,
|
|
22
|
+
symbol: undefined,
|
|
23
|
+
});
|
|
16
24
|
}
|
|
17
25
|
const referencePragma = sourceFile.pragmas.get('reference');
|
|
18
26
|
if (referencePragma) {
|
|
@@ -21,7 +29,15 @@ export const collectTypeScriptPragmaImports = (sourceFile) => {
|
|
|
21
29
|
if (ref.arguments?.types) {
|
|
22
30
|
const { value: specifier, pos } = ref.arguments.types;
|
|
23
31
|
if (specifier)
|
|
24
|
-
importNodes.push({
|
|
32
|
+
importNodes.push({
|
|
33
|
+
specifier,
|
|
34
|
+
identifier: undefined,
|
|
35
|
+
pos,
|
|
36
|
+
modifiers,
|
|
37
|
+
alias: undefined,
|
|
38
|
+
namespace: undefined,
|
|
39
|
+
symbol: undefined,
|
|
40
|
+
});
|
|
25
41
|
}
|
|
26
42
|
}
|
|
27
43
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
import type { ToSourceFilePath } from '../util/to-source-path.js';
|
|
3
3
|
export type ResolveModuleNames = ReturnType<typeof createCustomModuleResolver>;
|
|
4
|
-
export declare function createCustomModuleResolver(compilerOptions: ts.CompilerOptions, customCompilerExtensions: string[], toSourceFilePath: ToSourceFilePath, useCache?: boolean
|
|
4
|
+
export declare function createCustomModuleResolver(compilerOptions: ts.CompilerOptions, customCompilerExtensions: string[], toSourceFilePath: ToSourceFilePath, useCache?: boolean): (moduleNames: string[], containingFile: string) => Array<ts.ResolvedModuleFull | undefined>;
|
|
@@ -8,7 +8,7 @@ import { dirname, extname, isAbsolute, isInNodeModules, join } from '../util/pat
|
|
|
8
8
|
import { _createSyncModuleResolver, _resolveModuleSync } from '../util/resolve.js';
|
|
9
9
|
import { isDeclarationFileExtension } from './ast-helpers.js';
|
|
10
10
|
const resolutionCache = new Map();
|
|
11
|
-
const
|
|
11
|
+
const moduleIfFileExists = (name, containingFile) => {
|
|
12
12
|
const resolvedFileName = isAbsolute(name) ? name : join(dirname(containingFile), name);
|
|
13
13
|
if (existsSync(resolvedFileName)) {
|
|
14
14
|
return {
|
|
@@ -20,7 +20,7 @@ const fileExists = (name, containingFile) => {
|
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
22
|
const tsResolveModuleName = timerify(ts.resolveModuleName);
|
|
23
|
-
export function createCustomModuleResolver(compilerOptions, customCompilerExtensions, toSourceFilePath, useCache = true
|
|
23
|
+
export function createCustomModuleResolver(compilerOptions, customCompilerExtensions, toSourceFilePath, useCache = true) {
|
|
24
24
|
const customCompilerExtensionsSet = new Set(customCompilerExtensions);
|
|
25
25
|
const extensions = [...DEFAULT_EXTENSIONS, ...customCompilerExtensions];
|
|
26
26
|
const resolveSync = customCompilerExtensionsSet.size === 0 ? _resolveModuleSync : _createSyncModuleResolver(extensions);
|
|
@@ -28,9 +28,8 @@ export function createCustomModuleResolver(compilerOptions, customCompilerExtens
|
|
|
28
28
|
const tsSys = {
|
|
29
29
|
...ts.sys,
|
|
30
30
|
fileExists(path) {
|
|
31
|
-
if (ts.sys.fileExists(path))
|
|
31
|
+
if (ts.sys.fileExists(path))
|
|
32
32
|
return true;
|
|
33
|
-
}
|
|
34
33
|
const original = originalFromDeclarationPath(path);
|
|
35
34
|
if (original && ts.sys.fileExists(original.path)) {
|
|
36
35
|
virtualDeclarationFiles.set(path, original);
|
|
@@ -58,7 +57,7 @@ export function createCustomModuleResolver(compilerOptions, customCompilerExtens
|
|
|
58
57
|
const sanitizedSpecifier = sanitizeSpecifier(name);
|
|
59
58
|
if (isBuiltin(sanitizedSpecifier))
|
|
60
59
|
return undefined;
|
|
61
|
-
const resolvedFileName =
|
|
60
|
+
const resolvedFileName = resolveSync(sanitizedSpecifier, containingFile);
|
|
62
61
|
if (resolvedFileName) {
|
|
63
62
|
const ext = extname(resolvedFileName);
|
|
64
63
|
if (!customCompilerExtensionsSet.has(ext)) {
|
|
@@ -102,10 +101,7 @@ export function createCustomModuleResolver(compilerOptions, customCompilerExtens
|
|
|
102
101
|
}
|
|
103
102
|
return tsResolvedModule;
|
|
104
103
|
}
|
|
105
|
-
|
|
106
|
-
if (module)
|
|
107
|
-
return module;
|
|
108
|
-
return undefined;
|
|
104
|
+
return moduleIfFileExists(sanitizedSpecifier, containingFile);
|
|
109
105
|
}
|
|
110
106
|
return timerify(resolveModuleNames);
|
|
111
107
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
import {
|
|
2
|
+
import { IMPORT_FLAGS } from '../../../constants.js';
|
|
3
3
|
import { findAncestor, findDescendants, getAccessedIdentifiers, getThenBindings, 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);
|
|
@@ -7,7 +7,7 @@ export default visit(() => true, node => {
|
|
|
7
7
|
if (isImportCall(node)) {
|
|
8
8
|
if (node.arguments[0] && ts.isStringLiteralLike(node.arguments[0])) {
|
|
9
9
|
const specifier = node.arguments[0].text;
|
|
10
|
-
const modifiers =
|
|
10
|
+
const modifiers = IMPORT_FLAGS.NONE;
|
|
11
11
|
if (specifier) {
|
|
12
12
|
const accessExpression = findAncestor(node, _node => {
|
|
13
13
|
if (ts.isExpressionStatement(_node) || ts.isCallExpression(_node))
|
|
@@ -23,20 +23,51 @@ export default visit(() => true, node => {
|
|
|
23
23
|
if (ts.isCallExpression(callExpression)) {
|
|
24
24
|
const accessed = getThenBindings(callExpression);
|
|
25
25
|
if (accessed && accessed.length > 0) {
|
|
26
|
-
return accessed.map(acc => ({
|
|
26
|
+
return accessed.map(acc => ({
|
|
27
|
+
...acc,
|
|
28
|
+
specifier,
|
|
29
|
+
modifiers,
|
|
30
|
+
alias: undefined,
|
|
31
|
+
namespace: undefined,
|
|
32
|
+
symbol: undefined,
|
|
33
|
+
}));
|
|
27
34
|
}
|
|
28
35
|
}
|
|
29
|
-
return {
|
|
36
|
+
return {
|
|
37
|
+
identifier: 'default',
|
|
38
|
+
specifier,
|
|
39
|
+
pos,
|
|
40
|
+
modifiers,
|
|
41
|
+
alias: undefined,
|
|
42
|
+
namespace: undefined,
|
|
43
|
+
symbol: undefined,
|
|
44
|
+
};
|
|
30
45
|
}
|
|
31
46
|
if (identifier !== 'catch')
|
|
32
|
-
return {
|
|
47
|
+
return {
|
|
48
|
+
identifier,
|
|
49
|
+
specifier,
|
|
50
|
+
pos,
|
|
51
|
+
modifiers,
|
|
52
|
+
alias: undefined,
|
|
53
|
+
namespace: undefined,
|
|
54
|
+
symbol: undefined,
|
|
55
|
+
};
|
|
33
56
|
}
|
|
34
57
|
if (ts.isElementAccessExpression(accessExpression) &&
|
|
35
58
|
ts.isStringLiteral(accessExpression.argumentExpression)) {
|
|
36
59
|
const name = stripQuotes(accessExpression.argumentExpression.text);
|
|
37
60
|
const pos = accessExpression.argumentExpression.pos;
|
|
38
61
|
const identifier = name;
|
|
39
|
-
return {
|
|
62
|
+
return {
|
|
63
|
+
identifier,
|
|
64
|
+
specifier,
|
|
65
|
+
pos,
|
|
66
|
+
modifiers,
|
|
67
|
+
alias: undefined,
|
|
68
|
+
namespace: undefined,
|
|
69
|
+
symbol: undefined,
|
|
70
|
+
};
|
|
40
71
|
}
|
|
41
72
|
}
|
|
42
73
|
const variableDeclaration = accessExpression &&
|
|
@@ -63,9 +94,18 @@ export default visit(() => true, node => {
|
|
|
63
94
|
specifier,
|
|
64
95
|
pos: acc.pos,
|
|
65
96
|
modifiers,
|
|
97
|
+
namespace: undefined,
|
|
66
98
|
}));
|
|
67
99
|
}
|
|
68
|
-
return {
|
|
100
|
+
return {
|
|
101
|
+
identifier: 'default',
|
|
102
|
+
alias,
|
|
103
|
+
symbol,
|
|
104
|
+
specifier,
|
|
105
|
+
pos: node.arguments[0].pos,
|
|
106
|
+
modifiers,
|
|
107
|
+
namespace: undefined,
|
|
108
|
+
};
|
|
69
109
|
}
|
|
70
110
|
const bindings = findDescendants(variableDeclaration, ts.isBindingElement);
|
|
71
111
|
if (bindings.length > 0) {
|
|
@@ -73,14 +113,25 @@ export default visit(() => true, node => {
|
|
|
73
113
|
const identifier = (element.propertyName ?? element.name).getText();
|
|
74
114
|
const alias = element.propertyName ? element.name.getText() : undefined;
|
|
75
115
|
const symbol = getSymbol(element, isTLA);
|
|
76
|
-
return {
|
|
116
|
+
return {
|
|
117
|
+
identifier,
|
|
118
|
+
alias,
|
|
119
|
+
symbol,
|
|
120
|
+
specifier,
|
|
121
|
+
pos: element.name.getStart(),
|
|
122
|
+
modifiers,
|
|
123
|
+
namespace: undefined,
|
|
124
|
+
};
|
|
77
125
|
});
|
|
78
126
|
}
|
|
79
127
|
return {
|
|
80
128
|
identifier: undefined,
|
|
81
129
|
specifier,
|
|
82
130
|
pos: node.arguments[0].pos,
|
|
83
|
-
modifiers:
|
|
131
|
+
modifiers: IMPORT_FLAGS.SIDE_EFFECTS,
|
|
132
|
+
alias: undefined,
|
|
133
|
+
namespace: undefined,
|
|
134
|
+
symbol: undefined,
|
|
84
135
|
};
|
|
85
136
|
}
|
|
86
137
|
const arrayLiteralExpression = node.parent;
|
|
@@ -99,25 +150,60 @@ export default visit(() => true, node => {
|
|
|
99
150
|
const identifier = (element.propertyName ?? element.name).getText();
|
|
100
151
|
const alias = element.propertyName ? element.name.getText() : undefined;
|
|
101
152
|
const symbol = getSymbol(element, isTL);
|
|
102
|
-
return {
|
|
153
|
+
return {
|
|
154
|
+
identifier,
|
|
155
|
+
alias,
|
|
156
|
+
symbol,
|
|
157
|
+
specifier,
|
|
158
|
+
pos: element.getStart(),
|
|
159
|
+
modifiers,
|
|
160
|
+
namespace: undefined,
|
|
161
|
+
};
|
|
103
162
|
});
|
|
104
163
|
}
|
|
105
164
|
if (!ts.isOmittedExpression(element) && ts.isIdentifier(element.name)) {
|
|
106
165
|
const alias = String(element.name.escapedText);
|
|
107
166
|
const symbol = getSymbol(element, isTL);
|
|
108
|
-
return {
|
|
167
|
+
return {
|
|
168
|
+
identifier: 'default',
|
|
169
|
+
symbol,
|
|
170
|
+
alias,
|
|
171
|
+
specifier,
|
|
172
|
+
pos: element.getStart(),
|
|
173
|
+
modifiers,
|
|
174
|
+
namespace: undefined,
|
|
175
|
+
};
|
|
109
176
|
}
|
|
110
|
-
return {
|
|
177
|
+
return {
|
|
178
|
+
identifier: 'default',
|
|
179
|
+
specifier,
|
|
180
|
+
pos: element.getStart(),
|
|
181
|
+
modifiers,
|
|
182
|
+
alias: undefined,
|
|
183
|
+
namespace: undefined,
|
|
184
|
+
symbol: undefined,
|
|
185
|
+
};
|
|
111
186
|
}
|
|
112
187
|
}
|
|
113
188
|
return {
|
|
114
189
|
identifier: undefined,
|
|
115
190
|
specifier,
|
|
116
191
|
pos: node.arguments[0].pos,
|
|
117
|
-
modifiers: isInOpaqueExpression(node) ?
|
|
192
|
+
modifiers: isInOpaqueExpression(node) ? IMPORT_FLAGS.OPAQUE : IMPORT_FLAGS.SIDE_EFFECTS,
|
|
193
|
+
alias: undefined,
|
|
194
|
+
namespace: undefined,
|
|
195
|
+
symbol: undefined,
|
|
118
196
|
};
|
|
119
197
|
}
|
|
120
|
-
return {
|
|
198
|
+
return {
|
|
199
|
+
specifier,
|
|
200
|
+
identifier: 'default',
|
|
201
|
+
pos: node.arguments[0].pos,
|
|
202
|
+
modifiers,
|
|
203
|
+
alias: undefined,
|
|
204
|
+
namespace: undefined,
|
|
205
|
+
symbol: undefined,
|
|
206
|
+
};
|
|
121
207
|
}
|
|
122
208
|
}
|
|
123
209
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
import {
|
|
2
|
+
import { IMPORT_FLAGS } from '../../../constants.js';
|
|
3
3
|
import { importVisitor as visit } from '../index.js';
|
|
4
4
|
export default visit(() => true, node => {
|
|
5
5
|
if (ts.isImportTypeNode(node)) {
|
|
@@ -8,7 +8,10 @@ export default visit(() => true, node => {
|
|
|
8
8
|
specifier: node.argument.literal.text,
|
|
9
9
|
identifier: undefined,
|
|
10
10
|
pos: node.argument.literal.getStart(),
|
|
11
|
-
modifiers:
|
|
11
|
+
modifiers: IMPORT_FLAGS.TYPE_ONLY,
|
|
12
|
+
alias: undefined,
|
|
13
|
+
namespace: undefined,
|
|
14
|
+
symbol: undefined,
|
|
12
15
|
};
|
|
13
16
|
}
|
|
14
17
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
import {
|
|
2
|
+
import { IMPORT_FLAGS, 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) => {
|
|
@@ -13,7 +13,10 @@ const getImportSpecifiers = (node) => {
|
|
|
13
13
|
specifier: importClause.literal.text,
|
|
14
14
|
identifier,
|
|
15
15
|
pos: node.qualifier?.getStart() ?? importClause.literal.pos,
|
|
16
|
-
modifiers:
|
|
16
|
+
modifiers: IMPORT_FLAGS.TYPE_ONLY,
|
|
17
|
+
alias: undefined,
|
|
18
|
+
namespace: undefined,
|
|
19
|
+
symbol: undefined,
|
|
17
20
|
});
|
|
18
21
|
}
|
|
19
22
|
}
|
|
@@ -27,7 +30,10 @@ const getImportSpecifiers = (node) => {
|
|
|
27
30
|
specifier: moduleSpecifier.text,
|
|
28
31
|
identifier: IMPORT_STAR,
|
|
29
32
|
pos: bindings.name.getStart(),
|
|
30
|
-
modifiers:
|
|
33
|
+
modifiers: IMPORT_FLAGS.TYPE_ONLY,
|
|
34
|
+
alias: undefined,
|
|
35
|
+
namespace: undefined,
|
|
36
|
+
symbol: undefined,
|
|
31
37
|
});
|
|
32
38
|
}
|
|
33
39
|
else {
|
|
@@ -36,7 +42,10 @@ const getImportSpecifiers = (node) => {
|
|
|
36
42
|
specifier: moduleSpecifier.text,
|
|
37
43
|
identifier: String((element.propertyName ?? element.name).escapedText),
|
|
38
44
|
pos: element.name.getStart(),
|
|
39
|
-
modifiers:
|
|
45
|
+
modifiers: IMPORT_FLAGS.TYPE_ONLY,
|
|
46
|
+
alias: undefined,
|
|
47
|
+
namespace: undefined,
|
|
48
|
+
symbol: undefined,
|
|
40
49
|
});
|
|
41
50
|
}
|
|
42
51
|
}
|