knip 0.0.0-angular.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/README.md +907 -0
- package/dist/ConfigurationChief.d.ts +53 -0
- package/dist/ConfigurationChief.js +297 -0
- package/dist/ConfigurationValidator.d.ts +2325 -0
- package/dist/ConfigurationValidator.js +119 -0
- package/dist/ConsoleStreamer.d.ts +12 -0
- package/dist/ConsoleStreamer.js +34 -0
- package/dist/DependencyDeputy.d.ts +64 -0
- package/dist/DependencyDeputy.js +254 -0
- package/dist/IssueCollector.d.ts +27 -0
- package/dist/IssueCollector.js +52 -0
- package/dist/PrincipalFactory.d.ts +25 -0
- package/dist/PrincipalFactory.js +56 -0
- package/dist/ProjectPrincipal.d.ts +64 -0
- package/dist/ProjectPrincipal.js +197 -0
- package/dist/WorkspaceWorker.d.ts +56 -0
- package/dist/WorkspaceWorker.js +244 -0
- package/dist/binaries/bash-parser.d.ts +6 -0
- package/dist/binaries/bash-parser.js +58 -0
- package/dist/binaries/index.d.ts +2 -0
- package/dist/binaries/index.js +18 -0
- package/dist/binaries/resolvers/c8.d.ts +2 -0
- package/dist/binaries/resolvers/c8.js +10 -0
- package/dist/binaries/resolvers/dotenv.d.ts +2 -0
- package/dist/binaries/resolvers/dotenv.js +6 -0
- package/dist/binaries/resolvers/fallback.d.ts +2 -0
- package/dist/binaries/resolvers/fallback.js +22 -0
- package/dist/binaries/resolvers/index.d.ts +8 -0
- package/dist/binaries/resolvers/index.js +8 -0
- package/dist/binaries/resolvers/node.d.ts +2 -0
- package/dist/binaries/resolvers/node.js +10 -0
- package/dist/binaries/resolvers/nodemon.d.ts +2 -0
- package/dist/binaries/resolvers/nodemon.js +15 -0
- package/dist/binaries/resolvers/npx.d.ts +2 -0
- package/dist/binaries/resolvers/npx.js +20 -0
- package/dist/binaries/resolvers/pnpm.d.ts +2 -0
- package/dist/binaries/resolvers/pnpm.js +63 -0
- package/dist/binaries/resolvers/rollup.d.ts +2 -0
- package/dist/binaries/resolvers/rollup.js +11 -0
- package/dist/binaries/resolvers/yarn.d.ts +2 -0
- package/dist/binaries/resolvers/yarn.js +48 -0
- package/dist/binaries/types.d.ts +15 -0
- package/dist/binaries/types.js +1 -0
- package/dist/binaries/util.d.ts +8 -0
- package/dist/binaries/util.js +33 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +72 -0
- package/dist/constants.d.ts +12 -0
- package/dist/constants.js +90 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +334 -0
- package/dist/issues/initializers.d.ts +4 -0
- package/dist/issues/initializers.js +11 -0
- package/dist/manifest/helpers.d.ts +7 -0
- package/dist/manifest/helpers.js +16 -0
- package/dist/manifest/index.d.ts +16 -0
- package/dist/manifest/index.js +56 -0
- package/dist/plugins/_template/index.d.ts +9 -0
- package/dist/plugins/_template/index.js +14 -0
- package/dist/plugins/_template/types.d.ts +3 -0
- package/dist/plugins/_template/types.js +1 -0
- package/dist/plugins/angular/index.d.ts +6 -0
- package/dist/plugins/angular/index.js +36 -0
- package/dist/plugins/angular/types.d.ts +745 -0
- package/dist/plugins/angular/types.js +1 -0
- package/dist/plugins/ava/index.d.ts +7 -0
- package/dist/plugins/ava/index.js +20 -0
- package/dist/plugins/ava/types.d.ts +4 -0
- package/dist/plugins/ava/types.js +1 -0
- package/dist/plugins/babel/helpers.d.ts +15 -0
- package/dist/plugins/babel/helpers.js +34 -0
- package/dist/plugins/babel/index.d.ts +8 -0
- package/dist/plugins/babel/index.js +30 -0
- package/dist/plugins/babel/types.d.ts +9 -0
- package/dist/plugins/babel/types.js +1 -0
- package/dist/plugins/capacitor/index.d.ts +6 -0
- package/dist/plugins/capacitor/index.js +11 -0
- package/dist/plugins/capacitor/types.d.ts +3 -0
- package/dist/plugins/capacitor/types.js +1 -0
- package/dist/plugins/changesets/index.d.ts +6 -0
- package/dist/plugins/changesets/index.js +15 -0
- package/dist/plugins/commitizen/index.d.ts +6 -0
- package/dist/plugins/commitizen/index.js +14 -0
- package/dist/plugins/commitizen/types.d.ts +3 -0
- package/dist/plugins/commitizen/types.js +1 -0
- package/dist/plugins/commitlint/index.d.ts +6 -0
- package/dist/plugins/commitlint/index.js +18 -0
- package/dist/plugins/cspell/index.d.ts +6 -0
- package/dist/plugins/cspell/index.js +17 -0
- package/dist/plugins/cspell/types.d.ts +3 -0
- package/dist/plugins/cspell/types.js +1 -0
- package/dist/plugins/cypress/index.d.ts +5 -0
- package/dist/plugins/cypress/index.js +10 -0
- package/dist/plugins/eslint/fallback.d.ts +1 -0
- package/dist/plugins/eslint/fallback.js +13 -0
- package/dist/plugins/eslint/helpers.d.ts +14 -0
- package/dist/plugins/eslint/helpers.js +83 -0
- package/dist/plugins/eslint/index.d.ts +7 -0
- package/dist/plugins/eslint/index.js +15 -0
- package/dist/plugins/eslint/types.d.ts +27 -0
- package/dist/plugins/eslint/types.js +1 -0
- package/dist/plugins/gatsby/index.d.ts +7 -0
- package/dist/plugins/gatsby/index.js +30 -0
- package/dist/plugins/gatsby/types.d.ts +15 -0
- package/dist/plugins/gatsby/types.js +1 -0
- package/dist/plugins/github-actions/index.d.ts +6 -0
- package/dist/plugins/github-actions/index.js +21 -0
- package/dist/plugins/husky/index.d.ts +6 -0
- package/dist/plugins/husky/index.js +19 -0
- package/dist/plugins/index.d.ts +41 -0
- package/dist/plugins/index.js +41 -0
- package/dist/plugins/jest/index.d.ts +7 -0
- package/dist/plugins/jest/index.js +68 -0
- package/dist/plugins/lefthook/index.d.ts +6 -0
- package/dist/plugins/lefthook/index.js +28 -0
- package/dist/plugins/lint-staged/index.d.ts +6 -0
- package/dist/plugins/lint-staged/index.js +32 -0
- package/dist/plugins/lint-staged/types.d.ts +5 -0
- package/dist/plugins/lint-staged/types.js +1 -0
- package/dist/plugins/markdownlint/helpers.d.ts +1 -0
- package/dist/plugins/markdownlint/helpers.js +6 -0
- package/dist/plugins/markdownlint/index.d.ts +6 -0
- package/dist/plugins/markdownlint/index.js +19 -0
- package/dist/plugins/markdownlint/types.d.ts +3 -0
- package/dist/plugins/markdownlint/types.js +1 -0
- package/dist/plugins/mocha/index.d.ts +6 -0
- package/dist/plugins/mocha/index.js +15 -0
- package/dist/plugins/next/index.d.ts +6 -0
- package/dist/plugins/next/index.js +11 -0
- package/dist/plugins/npm-package-json-lint/index.d.ts +6 -0
- package/dist/plugins/npm-package-json-lint/index.js +13 -0
- package/dist/plugins/npm-package-json-lint/types.d.ts +3 -0
- package/dist/plugins/npm-package-json-lint/types.js +1 -0
- package/dist/plugins/nx/index.d.ts +6 -0
- package/dist/plugins/nx/index.js +24 -0
- package/dist/plugins/nx/types.d.ts +11 -0
- package/dist/plugins/nx/types.js +1 -0
- package/dist/plugins/nyc/index.d.ts +6 -0
- package/dist/plugins/nyc/index.js +11 -0
- package/dist/plugins/playwright/index.d.ts +5 -0
- package/dist/plugins/playwright/index.js +5 -0
- package/dist/plugins/postcss/index.d.ts +6 -0
- package/dist/plugins/postcss/index.js +23 -0
- package/dist/plugins/postcss/types.d.ts +3 -0
- package/dist/plugins/postcss/types.js +1 -0
- package/dist/plugins/prettier/index.d.ts +6 -0
- package/dist/plugins/prettier/index.js +20 -0
- package/dist/plugins/release-it/index.d.ts +6 -0
- package/dist/plugins/release-it/index.js +30 -0
- package/dist/plugins/release-it/types.d.ts +10 -0
- package/dist/plugins/release-it/types.js +1 -0
- package/dist/plugins/remark/index.d.ts +6 -0
- package/dist/plugins/remark/index.js +18 -0
- package/dist/plugins/remix/index.d.ts +6 -0
- package/dist/plugins/remix/index.js +11 -0
- package/dist/plugins/rollup/index.d.ts +5 -0
- package/dist/plugins/rollup/index.js +5 -0
- package/dist/plugins/semantic-release/index.d.ts +6 -0
- package/dist/plugins/semantic-release/index.js +17 -0
- package/dist/plugins/semantic-release/types.d.ts +3 -0
- package/dist/plugins/semantic-release/types.js +1 -0
- package/dist/plugins/sentry/index.d.ts +5 -0
- package/dist/plugins/sentry/index.js +5 -0
- package/dist/plugins/storybook/index.d.ts +8 -0
- package/dist/plugins/storybook/index.js +19 -0
- package/dist/plugins/storybook/types.d.ts +11 -0
- package/dist/plugins/storybook/types.js +1 -0
- package/dist/plugins/stryker/index.d.ts +6 -0
- package/dist/plugins/stryker/index.js +17 -0
- package/dist/plugins/stryker/types.d.ts +5 -0
- package/dist/plugins/stryker/types.js +1 -0
- package/dist/plugins/stylelint/index.d.ts +6 -0
- package/dist/plugins/stylelint/index.js +22 -0
- package/dist/plugins/stylelint/types.d.ts +4 -0
- package/dist/plugins/stylelint/types.js +1 -0
- package/dist/plugins/svelte/index.d.ts +7 -0
- package/dist/plugins/svelte/index.js +9 -0
- package/dist/plugins/tailwind/index.d.ts +5 -0
- package/dist/plugins/tailwind/index.js +5 -0
- package/dist/plugins/typedoc/index.d.ts +6 -0
- package/dist/plugins/typedoc/index.js +22 -0
- package/dist/plugins/typedoc/types.d.ts +3 -0
- package/dist/plugins/typedoc/types.js +1 -0
- package/dist/plugins/typescript/index.d.ts +7 -0
- package/dist/plugins/typescript/index.js +42 -0
- package/dist/plugins/vite/index.d.ts +6 -0
- package/dist/plugins/vite/index.js +12 -0
- package/dist/plugins/vite/types.d.ts +4 -0
- package/dist/plugins/vite/types.js +1 -0
- package/dist/plugins/vitest/helpers.d.ts +6 -0
- package/dist/plugins/vitest/helpers.js +22 -0
- package/dist/plugins/vitest/index.d.ts +9 -0
- package/dist/plugins/vitest/index.js +25 -0
- package/dist/plugins/vitest/types.d.ts +11 -0
- package/dist/plugins/vitest/types.js +1 -0
- package/dist/plugins/webpack/index.d.ts +6 -0
- package/dist/plugins/webpack/index.js +82 -0
- package/dist/plugins/webpack/types.d.ts +10 -0
- package/dist/plugins/webpack/types.js +1 -0
- package/dist/reporters/codeowners.d.ts +3 -0
- package/dist/reporters/codeowners.js +62 -0
- package/dist/reporters/compact.d.ts +3 -0
- package/dist/reporters/compact.js +36 -0
- package/dist/reporters/index.d.ts +7 -0
- package/dist/reporters/index.js +10 -0
- package/dist/reporters/json.d.ts +3 -0
- package/dist/reporters/json.js +67 -0
- package/dist/reporters/symbols.d.ts +3 -0
- package/dist/reporters/symbols.js +54 -0
- package/dist/reporters/util.d.ts +15 -0
- package/dist/reporters/util.js +17 -0
- package/dist/types/cli.d.ts +10 -0
- package/dist/types/cli.js +1 -0
- package/dist/types/compilers.d.ts +6 -0
- package/dist/types/compilers.js +1 -0
- package/dist/types/config.d.ts +39 -0
- package/dist/types/config.js +3 -0
- package/dist/types/exports.d.ts +20 -0
- package/dist/types/exports.js +1 -0
- package/dist/types/imports.d.ts +13 -0
- package/dist/types/imports.js +1 -0
- package/dist/types/issues.d.ts +62 -0
- package/dist/types/issues.js +10 -0
- package/dist/types/plugins.d.ts +19 -0
- package/dist/types/plugins.js +1 -0
- package/dist/types/workspace.d.ts +17 -0
- package/dist/types/workspace.js +1 -0
- package/dist/typescript/SourceFile.d.ts +18 -0
- package/dist/typescript/SourceFile.js +1 -0
- package/dist/typescript/SourceFileManager.d.ts +13 -0
- package/dist/typescript/SourceFileManager.js +57 -0
- package/dist/typescript/ast-helpers.d.ts +27 -0
- package/dist/typescript/ast-helpers.js +101 -0
- package/dist/typescript/createHosts.d.ts +15 -0
- package/dist/typescript/createHosts.js +39 -0
- package/dist/typescript/getImportsAndExports.d.ts +29 -0
- package/dist/typescript/getImportsAndExports.js +159 -0
- package/dist/typescript/resolveModuleNames.d.ts +2 -0
- package/dist/typescript/resolveModuleNames.js +27 -0
- package/dist/typescript/sys.d.ts +35 -0
- package/dist/typescript/sys.js +16 -0
- package/dist/typescript/utils.d.ts +2 -0
- package/dist/typescript/utils.js +9 -0
- package/dist/typescript/visitors/exports/exportAssignment.d.ts +3 -0
- package/dist/typescript/visitors/exports/exportAssignment.js +9 -0
- package/dist/typescript/visitors/exports/exportDeclaration.d.ts +3 -0
- package/dist/typescript/visitors/exports/exportDeclaration.js +13 -0
- package/dist/typescript/visitors/exports/exportKeyword.d.ts +3 -0
- package/dist/typescript/visitors/exports/exportKeyword.js +77 -0
- package/dist/typescript/visitors/exports/index.d.ts +3 -0
- package/dist/typescript/visitors/exports/index.js +7 -0
- package/dist/typescript/visitors/exports/moduleExportsAccessExpression.d.ts +3 -0
- package/dist/typescript/visitors/exports/moduleExportsAccessExpression.js +31 -0
- package/dist/typescript/visitors/helpers.d.ts +4 -0
- package/dist/typescript/visitors/helpers.js +10 -0
- package/dist/typescript/visitors/imports/importCall.d.ts +3 -0
- package/dist/typescript/visitors/imports/importCall.js +11 -0
- package/dist/typescript/visitors/imports/importDeclaration.d.ts +3 -0
- package/dist/typescript/visitors/imports/importDeclaration.js +32 -0
- package/dist/typescript/visitors/imports/importEqualsDeclaration.d.ts +3 -0
- package/dist/typescript/visitors/imports/importEqualsDeclaration.js +11 -0
- package/dist/typescript/visitors/imports/index.d.ts +3 -0
- package/dist/typescript/visitors/imports/index.js +18 -0
- package/dist/typescript/visitors/imports/jsDocType.d.ts +3 -0
- package/dist/typescript/visitors/imports/jsDocType.js +11 -0
- package/dist/typescript/visitors/imports/reExportDeclaration.d.ts +3 -0
- package/dist/typescript/visitors/imports/reExportDeclaration.js +21 -0
- package/dist/typescript/visitors/imports/requireCall.d.ts +3 -0
- package/dist/typescript/visitors/imports/requireCall.js +45 -0
- package/dist/typescript/visitors/imports/requireResolveCall.d.ts +3 -0
- package/dist/typescript/visitors/imports/requireResolveCall.js +12 -0
- package/dist/typescript/visitors/index.d.ts +10 -0
- package/dist/typescript/visitors/index.js +16 -0
- package/dist/typescript/visitors/scripts/execa.d.ts +3 -0
- package/dist/typescript/visitors/scripts/execa.js +18 -0
- package/dist/typescript/visitors/scripts/index.d.ts +3 -0
- package/dist/typescript/visitors/scripts/index.js +5 -0
- package/dist/typescript/visitors/scripts/zx.d.ts +3 -0
- package/dist/typescript/visitors/scripts/zx.js +8 -0
- package/dist/util/Performance.d.ts +23 -0
- package/dist/util/Performance.js +80 -0
- package/dist/util/array.d.ts +2 -0
- package/dist/util/array.js +2 -0
- package/dist/util/cli-arguments.d.ts +28 -0
- package/dist/util/cli-arguments.js +83 -0
- package/dist/util/compilers.d.ts +426 -0
- package/dist/util/compilers.js +20 -0
- package/dist/util/debug.d.ts +3 -0
- package/dist/util/debug.js +34 -0
- package/dist/util/errors.d.ts +12 -0
- package/dist/util/errors.js +14 -0
- package/dist/util/fs.d.ts +7 -0
- package/dist/util/fs.js +42 -0
- package/dist/util/get-included-issue-types.d.ts +16 -0
- package/dist/util/get-included-issue-types.js +37 -0
- package/dist/util/git.d.ts +1 -0
- package/dist/util/git.js +20 -0
- package/dist/util/glob.d.ts +19 -0
- package/dist/util/glob.js +59 -0
- package/dist/util/loader.d.ts +1 -0
- package/dist/util/loader.js +31 -0
- package/dist/util/map.d.ts +1 -0
- package/dist/util/map.js +6 -0
- package/dist/util/modules.d.ts +8 -0
- package/dist/util/modules.js +52 -0
- package/dist/util/object.d.ts +3 -0
- package/dist/util/object.js +37 -0
- package/dist/util/path.d.ts +11 -0
- package/dist/util/path.js +13 -0
- package/dist/util/plugin.d.ts +3 -0
- package/dist/util/plugin.js +14 -0
- package/dist/util/register.d.ts +1 -0
- package/dist/util/register.js +14 -0
- package/dist/util/reporter.d.ts +3 -0
- package/dist/util/reporter.js +16 -0
- package/dist/util/require.d.ts +5 -0
- package/dist/util/require.js +34 -0
- package/dist/util/tsconfig-loader.d.ts +2 -0
- package/dist/util/tsconfig-loader.js +11 -0
- package/dist/util/workspace.d.ts +1 -0
- package/dist/util/workspace.js +11 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +1 -0
- package/license +12 -0
- package/package.json +150 -0
- package/schema.json +403 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
export function isValidImportTypeNode(node) {
|
|
3
|
+
return ts.isImportTypeNode(node);
|
|
4
|
+
}
|
|
5
|
+
export function isPrivateMember(node) {
|
|
6
|
+
return node.modifiers?.some(modifier => modifier.kind === ts.SyntaxKind.PrivateKeyword) ?? false;
|
|
7
|
+
}
|
|
8
|
+
export function isDefaultImport(node) {
|
|
9
|
+
return node.kind === ts.SyntaxKind.ImportDeclaration && !!node.importClause && !!node.importClause.name;
|
|
10
|
+
}
|
|
11
|
+
export function isAccessExpression(node) {
|
|
12
|
+
return ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node);
|
|
13
|
+
}
|
|
14
|
+
export function isImportCall(node) {
|
|
15
|
+
return (node.kind === ts.SyntaxKind.CallExpression &&
|
|
16
|
+
node.expression.kind === ts.SyntaxKind.ImportKeyword);
|
|
17
|
+
}
|
|
18
|
+
export function isRequireCall(callExpression) {
|
|
19
|
+
if (callExpression.kind !== ts.SyntaxKind.CallExpression) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
const { expression, arguments: args } = callExpression;
|
|
23
|
+
if (expression.kind !== ts.SyntaxKind.Identifier || expression.escapedText !== 'require') {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return args.length === 1;
|
|
27
|
+
}
|
|
28
|
+
export function isRequireResolveCall(node) {
|
|
29
|
+
return (ts.isCallExpression(node) &&
|
|
30
|
+
ts.isPropertyAccessExpression(node.expression) &&
|
|
31
|
+
node.expression.getText() === 'require.resolve');
|
|
32
|
+
}
|
|
33
|
+
export function getAccessExpressionName(node) {
|
|
34
|
+
return 'argumentExpression' in node ? stripQuotes(node.argumentExpression.getText()) : node.name.getText();
|
|
35
|
+
}
|
|
36
|
+
export function isModuleExportsAccessExpression(node) {
|
|
37
|
+
return ((ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) &&
|
|
38
|
+
ts.isIdentifier(node.expression) &&
|
|
39
|
+
node.expression.escapedText === 'module' &&
|
|
40
|
+
getAccessExpressionName(node) === 'exports');
|
|
41
|
+
}
|
|
42
|
+
export function stripQuotes(name) {
|
|
43
|
+
const length = name.length;
|
|
44
|
+
if (length >= 2 && name.charCodeAt(0) === name.charCodeAt(length - 1) && isQuoteOrBacktick(name.charCodeAt(0))) {
|
|
45
|
+
return name.substring(1, length - 1);
|
|
46
|
+
}
|
|
47
|
+
return name;
|
|
48
|
+
}
|
|
49
|
+
var CharacterCodes;
|
|
50
|
+
(function (CharacterCodes) {
|
|
51
|
+
CharacterCodes[CharacterCodes["backtick"] = 96] = "backtick";
|
|
52
|
+
CharacterCodes[CharacterCodes["doubleQuote"] = 34] = "doubleQuote";
|
|
53
|
+
CharacterCodes[CharacterCodes["singleQuote"] = 39] = "singleQuote";
|
|
54
|
+
})(CharacterCodes || (CharacterCodes = {}));
|
|
55
|
+
function isQuoteOrBacktick(charCode) {
|
|
56
|
+
return (charCode === CharacterCodes.singleQuote ||
|
|
57
|
+
charCode === CharacterCodes.doubleQuote ||
|
|
58
|
+
charCode === CharacterCodes.backtick);
|
|
59
|
+
}
|
|
60
|
+
export function findAncestor(node, callback) {
|
|
61
|
+
node = node?.parent;
|
|
62
|
+
while (node) {
|
|
63
|
+
const result = callback(node);
|
|
64
|
+
if (result === 'STOP') {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
else if (result) {
|
|
68
|
+
return node;
|
|
69
|
+
}
|
|
70
|
+
node = node.parent;
|
|
71
|
+
}
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
export function findDescendants(node, callback) {
|
|
75
|
+
const results = [];
|
|
76
|
+
if (!node)
|
|
77
|
+
return results;
|
|
78
|
+
function visit(node) {
|
|
79
|
+
const result = callback(node);
|
|
80
|
+
if (result === 'STOP') {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
else if (result) {
|
|
84
|
+
results.push(node);
|
|
85
|
+
}
|
|
86
|
+
ts.forEachChild(node, visit);
|
|
87
|
+
}
|
|
88
|
+
visit(node);
|
|
89
|
+
return results;
|
|
90
|
+
}
|
|
91
|
+
export const isDeclarationFileExtension = (extension) => extension === '.d.ts' || extension === '.d.mts' || extension === '.d.cts';
|
|
92
|
+
export const isInModuleBlock = (node) => {
|
|
93
|
+
node = node?.parent;
|
|
94
|
+
while (node) {
|
|
95
|
+
if (ts.isModuleBlock(node))
|
|
96
|
+
return true;
|
|
97
|
+
node = node.parent;
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
};
|
|
101
|
+
export const getJSDocTags = (node) => ts.getJSDocTags(node).map(node => node.getText().match(/@\S+/)[0]);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { SourceFileManager } from './SourceFileManager.js';
|
|
3
|
+
import type { SyncCompilers, AsyncCompilers } from '../types/compilers.js';
|
|
4
|
+
type CreateHostsOptions = {
|
|
5
|
+
cwd: string;
|
|
6
|
+
compilerOptions: ts.CompilerOptions;
|
|
7
|
+
entryPaths: Set<string>;
|
|
8
|
+
compilers: [SyncCompilers, AsyncCompilers];
|
|
9
|
+
};
|
|
10
|
+
export declare const createHosts: ({ cwd, compilerOptions, entryPaths, compilers }: CreateHostsOptions) => {
|
|
11
|
+
fileManager: SourceFileManager;
|
|
12
|
+
languageServiceHost: ts.LanguageServiceHost;
|
|
13
|
+
compilerHost: ts.CompilerHost;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { EOL } from 'node:os';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import ts from 'typescript';
|
|
4
|
+
import { createCustomModuleResolver } from './resolveModuleNames.js';
|
|
5
|
+
import { SourceFileManager } from './SourceFileManager.js';
|
|
6
|
+
import { createCustomSys } from './sys.js';
|
|
7
|
+
const libLocation = path.dirname(ts.getDefaultLibFilePath({}));
|
|
8
|
+
const fileManager = new SourceFileManager();
|
|
9
|
+
export const createHosts = ({ cwd, compilerOptions, entryPaths, compilers }) => {
|
|
10
|
+
fileManager.installCompilers(compilers);
|
|
11
|
+
const virtualFileExtensions = [...compilers[0].keys(), ...compilers[1].keys()];
|
|
12
|
+
const sys = createCustomSys(cwd, virtualFileExtensions);
|
|
13
|
+
const resolveModuleNames = createCustomModuleResolver(sys, compilerOptions, virtualFileExtensions);
|
|
14
|
+
const languageServiceHost = {
|
|
15
|
+
getCompilationSettings: () => compilerOptions,
|
|
16
|
+
getScriptFileNames: () => Array.from(entryPaths),
|
|
17
|
+
getScriptVersion: () => '0',
|
|
18
|
+
getScriptSnapshot: (fileName) => fileManager.getSnapshot(fileName),
|
|
19
|
+
getCurrentDirectory: sys.getCurrentDirectory,
|
|
20
|
+
getDefaultLibFileName: ts.getDefaultLibFilePath,
|
|
21
|
+
readFile: sys.readFile,
|
|
22
|
+
fileExists: sys.fileExists,
|
|
23
|
+
resolveModuleNames,
|
|
24
|
+
};
|
|
25
|
+
const compilerHost = {
|
|
26
|
+
writeFile: () => undefined,
|
|
27
|
+
getDefaultLibLocation: () => libLocation,
|
|
28
|
+
getDefaultLibFileName: languageServiceHost.getDefaultLibFileName,
|
|
29
|
+
getSourceFile: (fileName) => fileManager.getSourceFile(fileName),
|
|
30
|
+
getCurrentDirectory: languageServiceHost.getCurrentDirectory,
|
|
31
|
+
getCanonicalFileName: (fileName) => fileName,
|
|
32
|
+
useCaseSensitiveFileNames: () => true,
|
|
33
|
+
getNewLine: () => EOL,
|
|
34
|
+
readFile: languageServiceHost.readFile,
|
|
35
|
+
fileExists: languageServiceHost.fileExists,
|
|
36
|
+
resolveModuleNames: languageServiceHost.resolveModuleNames,
|
|
37
|
+
};
|
|
38
|
+
return { fileManager, languageServiceHost, compilerHost };
|
|
39
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import type { BoundSourceFile } from './SourceFile.js';
|
|
3
|
+
import type { ExportItems as Exports, ExportItem } from '../types/exports.js';
|
|
4
|
+
import type { Imports } from '../types/imports.js';
|
|
5
|
+
export type GetImportsAndExportsOptions = {
|
|
6
|
+
skipTypeOnly: boolean;
|
|
7
|
+
skipExports: boolean;
|
|
8
|
+
};
|
|
9
|
+
export type AddImportOptions = {
|
|
10
|
+
specifier: string;
|
|
11
|
+
symbol?: ts.Symbol;
|
|
12
|
+
identifier?: string;
|
|
13
|
+
isReExport?: boolean;
|
|
14
|
+
};
|
|
15
|
+
export type AddExportOptions = ExportItem & {
|
|
16
|
+
identifier: string;
|
|
17
|
+
};
|
|
18
|
+
export declare const getImportsAndExports: (sourceFile: BoundSourceFile, options: GetImportsAndExportsOptions) => {
|
|
19
|
+
imports: {
|
|
20
|
+
internal: Imports;
|
|
21
|
+
external: Set<string>;
|
|
22
|
+
unresolved: Set<string>;
|
|
23
|
+
};
|
|
24
|
+
exports: {
|
|
25
|
+
exported: Exports;
|
|
26
|
+
duplicate: string[][];
|
|
27
|
+
};
|
|
28
|
+
scripts: Set<string>;
|
|
29
|
+
};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { isBuiltin } from 'node:module';
|
|
2
|
+
import ts from 'typescript';
|
|
3
|
+
import { getOrSet } from '../util/map.js';
|
|
4
|
+
import { isMaybePackageName } from '../util/modules.js';
|
|
5
|
+
import { isInNodeModules } from '../util/path.js';
|
|
6
|
+
import { isDeclarationFileExtension, isAccessExpression, getAccessExpressionName, getJSDocTags, } from './ast-helpers.js';
|
|
7
|
+
import getExportVisitors from './visitors/exports/index.js';
|
|
8
|
+
import { getJSXImplicitImportBase } from './visitors/helpers.js';
|
|
9
|
+
import getImportVisitors from './visitors/imports/index.js';
|
|
10
|
+
import getScriptVisitors from './visitors/scripts/index.js';
|
|
11
|
+
const getVisitors = (sourceFile) => ({
|
|
12
|
+
export: getExportVisitors(sourceFile),
|
|
13
|
+
import: getImportVisitors(sourceFile),
|
|
14
|
+
script: getScriptVisitors(sourceFile),
|
|
15
|
+
});
|
|
16
|
+
export const getImportsAndExports = (sourceFile, options) => {
|
|
17
|
+
const internalImports = new Map();
|
|
18
|
+
const externalImports = new Set();
|
|
19
|
+
const unresolvedImports = new Set();
|
|
20
|
+
const exports = new Map();
|
|
21
|
+
const aliasedExports = {};
|
|
22
|
+
const scripts = new Set();
|
|
23
|
+
const importedInternalSymbols = new Map();
|
|
24
|
+
const jsxImport = getJSXImplicitImportBase(sourceFile);
|
|
25
|
+
if (jsxImport)
|
|
26
|
+
externalImports.add(jsxImport);
|
|
27
|
+
const visitors = getVisitors(sourceFile);
|
|
28
|
+
const addInternalImport = (options) => {
|
|
29
|
+
const { identifier, specifier, symbol, filePath, isReExport } = options;
|
|
30
|
+
const isStar = identifier === '*';
|
|
31
|
+
const internalImport = getOrSet(internalImports, filePath, {
|
|
32
|
+
specifier,
|
|
33
|
+
isStar,
|
|
34
|
+
isReExport,
|
|
35
|
+
isReExportedBy: new Set(),
|
|
36
|
+
symbols: new Set(),
|
|
37
|
+
});
|
|
38
|
+
if (isReExport) {
|
|
39
|
+
internalImport.isReExport = isReExport;
|
|
40
|
+
internalImport.isReExportedBy.add(sourceFile.fileName);
|
|
41
|
+
}
|
|
42
|
+
if (isStar)
|
|
43
|
+
internalImport.isStar = isStar;
|
|
44
|
+
if (!isStar)
|
|
45
|
+
internalImport.symbols.add(identifier);
|
|
46
|
+
if (isStar && symbol)
|
|
47
|
+
importedInternalSymbols.set(symbol, filePath);
|
|
48
|
+
};
|
|
49
|
+
const addImport = (options) => {
|
|
50
|
+
const { specifier, symbol, identifier = '__anonymous', isReExport = false } = options;
|
|
51
|
+
if (isBuiltin(specifier))
|
|
52
|
+
return;
|
|
53
|
+
const module = sourceFile.resolvedModules?.get(specifier, undefined);
|
|
54
|
+
if (module?.resolvedModule) {
|
|
55
|
+
const filePath = module.resolvedModule.resolvedFileName;
|
|
56
|
+
if (filePath) {
|
|
57
|
+
if (module.resolvedModule.isExternalLibraryImport) {
|
|
58
|
+
if (!isInNodeModules(filePath)) {
|
|
59
|
+
addInternalImport({ identifier, specifier, symbol, filePath, isReExport });
|
|
60
|
+
}
|
|
61
|
+
if (!isMaybePackageName(specifier))
|
|
62
|
+
return;
|
|
63
|
+
if (isDeclarationFileExtension(module.resolvedModule.extension)) {
|
|
64
|
+
externalImports.add(specifier);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
externalImports.add(module.resolvedModule.packageId?.name ?? specifier);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
addInternalImport({ identifier, specifier, symbol, filePath, isReExport });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
unresolvedImports.add(specifier);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const maybeAddNamespaceAccessAsImport = ({ namespace, member }) => {
|
|
80
|
+
const symbol = sourceFile.locals?.get(namespace);
|
|
81
|
+
if (symbol) {
|
|
82
|
+
const importedSymbolFilePath = importedInternalSymbols.get(symbol);
|
|
83
|
+
if (importedSymbolFilePath) {
|
|
84
|
+
const internalImport = internalImports.get(importedSymbolFilePath);
|
|
85
|
+
internalImport?.symbols.add(member);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const addExport = ({ node, identifier, type, pos, members = [] }) => {
|
|
90
|
+
if (options.skipExports)
|
|
91
|
+
return;
|
|
92
|
+
const jsDocTags = getJSDocTags(node);
|
|
93
|
+
if (exports.has(identifier)) {
|
|
94
|
+
const item = exports.get(identifier);
|
|
95
|
+
const crew = [...item.members, ...members];
|
|
96
|
+
const tags = [...item.jsDocTags, ...jsDocTags];
|
|
97
|
+
exports.set(identifier, { ...item, node, type, pos, members: crew, jsDocTags: tags });
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
exports.set(identifier, { node, type, pos, members, jsDocTags });
|
|
101
|
+
}
|
|
102
|
+
if (!jsDocTags.includes('@alias')) {
|
|
103
|
+
if (ts.isExportAssignment(node))
|
|
104
|
+
maybeAddAliasedExport(node.expression, 'default');
|
|
105
|
+
if (ts.isVariableDeclaration(node))
|
|
106
|
+
maybeAddAliasedExport(node.initializer, identifier);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const maybeAddAliasedExport = (node, alias) => {
|
|
110
|
+
const identifier = node?.getText();
|
|
111
|
+
if (identifier && sourceFile.symbol?.exports?.has(identifier)) {
|
|
112
|
+
aliasedExports[identifier] = aliasedExports[identifier] ?? [identifier];
|
|
113
|
+
aliasedExports[identifier].push(alias);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const visit = (node) => {
|
|
117
|
+
for (const visitor of visitors.import) {
|
|
118
|
+
if (visitor) {
|
|
119
|
+
const results = visitor(node, options);
|
|
120
|
+
if (results)
|
|
121
|
+
[results].flat().forEach(addImport);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
for (const visitor of visitors.export) {
|
|
125
|
+
if (visitor) {
|
|
126
|
+
const results = visitor(node, options);
|
|
127
|
+
if (results)
|
|
128
|
+
[results].flat().forEach(addExport);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
for (const visitor of visitors.script) {
|
|
132
|
+
if (visitor) {
|
|
133
|
+
const results = visitor(node, options);
|
|
134
|
+
if (results)
|
|
135
|
+
[results].flat().forEach(script => scripts.add(script));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (isAccessExpression(node)) {
|
|
139
|
+
maybeAddNamespaceAccessAsImport({
|
|
140
|
+
namespace: node.expression.getText(),
|
|
141
|
+
member: getAccessExpressionName(node),
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
ts.forEachChild(node, visit);
|
|
145
|
+
};
|
|
146
|
+
visit(sourceFile);
|
|
147
|
+
return {
|
|
148
|
+
imports: {
|
|
149
|
+
internal: internalImports,
|
|
150
|
+
external: externalImports,
|
|
151
|
+
unresolved: unresolvedImports,
|
|
152
|
+
},
|
|
153
|
+
exports: {
|
|
154
|
+
exported: exports,
|
|
155
|
+
duplicate: Object.values(aliasedExports),
|
|
156
|
+
},
|
|
157
|
+
scripts,
|
|
158
|
+
};
|
|
159
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { ensureRealFilePath, isVirtualFilePath } from './utils.js';
|
|
3
|
+
export function createCustomModuleResolver(customSys, compilerOptions, virtualFileExtensions) {
|
|
4
|
+
function resolveModuleNames(moduleNames, containingFile) {
|
|
5
|
+
return moduleNames.map(moduleName => resolveModuleName(moduleName, containingFile));
|
|
6
|
+
}
|
|
7
|
+
function resolveModuleName(name, containingFile) {
|
|
8
|
+
const tsResolvedModule = ts.resolveModuleName(name, containingFile, compilerOptions, ts.sys).resolvedModule;
|
|
9
|
+
if (virtualFileExtensions.length === 0)
|
|
10
|
+
return tsResolvedModule;
|
|
11
|
+
if (tsResolvedModule && !isVirtualFilePath(tsResolvedModule.resolvedFileName, virtualFileExtensions)) {
|
|
12
|
+
return tsResolvedModule;
|
|
13
|
+
}
|
|
14
|
+
const customResolvedModule = ts.resolveModuleName(name, containingFile, compilerOptions, customSys).resolvedModule;
|
|
15
|
+
if (!customResolvedModule || !isVirtualFilePath(customResolvedModule.resolvedFileName, virtualFileExtensions)) {
|
|
16
|
+
return customResolvedModule;
|
|
17
|
+
}
|
|
18
|
+
const resolvedFileName = ensureRealFilePath(customResolvedModule.resolvedFileName, virtualFileExtensions);
|
|
19
|
+
const resolvedModule = {
|
|
20
|
+
extension: ts.Extension.Js,
|
|
21
|
+
resolvedFileName,
|
|
22
|
+
isExternalLibraryImport: customResolvedModule.isExternalLibraryImport,
|
|
23
|
+
};
|
|
24
|
+
return resolvedModule;
|
|
25
|
+
}
|
|
26
|
+
return resolveModuleNames;
|
|
27
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
export declare function createCustomSys(cwd: string, virtualFileExtensions: string[]): {
|
|
3
|
+
getCurrentDirectory: () => string;
|
|
4
|
+
args: string[];
|
|
5
|
+
newLine: string;
|
|
6
|
+
useCaseSensitiveFileNames: boolean;
|
|
7
|
+
write(s: string): void;
|
|
8
|
+
writeOutputIsTTY?(): boolean;
|
|
9
|
+
getWidthOfTerminal?(): number;
|
|
10
|
+
readFile(path: string, encoding?: string | undefined): string | undefined;
|
|
11
|
+
getFileSize?(path: string): number;
|
|
12
|
+
writeFile(path: string, data: string, writeByteOrderMark?: boolean | undefined): void;
|
|
13
|
+
watchFile?(path: string, callback: ts.FileWatcherCallback, pollingInterval?: number | undefined, options?: ts.WatchOptions | undefined): ts.FileWatcher;
|
|
14
|
+
watchDirectory?(path: string, callback: ts.DirectoryWatcherCallback, recursive?: boolean | undefined, options?: ts.WatchOptions | undefined): ts.FileWatcher;
|
|
15
|
+
resolvePath(path: string): string;
|
|
16
|
+
fileExists(path: string): boolean;
|
|
17
|
+
directoryExists(path: string): boolean;
|
|
18
|
+
createDirectory(path: string): void;
|
|
19
|
+
getExecutingFilePath(): string;
|
|
20
|
+
getDirectories(path: string): string[];
|
|
21
|
+
readDirectory(path: string, extensions?: readonly string[] | undefined, exclude?: readonly string[] | undefined, include?: readonly string[] | undefined, depth?: number | undefined): string[];
|
|
22
|
+
getModifiedTime?(path: string): Date | undefined;
|
|
23
|
+
setModifiedTime?(path: string, time: Date): void;
|
|
24
|
+
deleteFile?(path: string): void;
|
|
25
|
+
createHash?(data: string): string;
|
|
26
|
+
createSHA256Hash?(data: string): string;
|
|
27
|
+
getMemoryUsage?(): number;
|
|
28
|
+
exit(exitCode?: number | undefined): void;
|
|
29
|
+
realpath?(path: string): string;
|
|
30
|
+
setTimeout?(callback: (...args: any[]) => void, ms: number, ...args: any[]): any;
|
|
31
|
+
clearTimeout?(timeoutId: any): void;
|
|
32
|
+
clearScreen?(): void;
|
|
33
|
+
base64decode?(input: string): string;
|
|
34
|
+
base64encode?(input: string): string;
|
|
35
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { ensureRealFilePath } from './utils.js';
|
|
3
|
+
export function createCustomSys(cwd, virtualFileExtensions) {
|
|
4
|
+
const sys = {
|
|
5
|
+
...ts.sys,
|
|
6
|
+
getCurrentDirectory: () => cwd,
|
|
7
|
+
};
|
|
8
|
+
if (virtualFileExtensions.length === 0)
|
|
9
|
+
return sys;
|
|
10
|
+
return {
|
|
11
|
+
...sys,
|
|
12
|
+
fileExists(path) {
|
|
13
|
+
return ts.sys.fileExists(ensureRealFilePath(path, virtualFileExtensions));
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
function toRealFilePath(filePath) {
|
|
2
|
+
return filePath.slice(0, -'.ts'.length);
|
|
3
|
+
}
|
|
4
|
+
export function isVirtualFilePath(filePath, extensions) {
|
|
5
|
+
return extensions.some(extension => filePath.endsWith(`${extension}.ts`));
|
|
6
|
+
}
|
|
7
|
+
export function ensureRealFilePath(filePath, extensions) {
|
|
8
|
+
return isVirtualFilePath(filePath, extensions) ? toRealFilePath(filePath) : filePath;
|
|
9
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("../../getImportsAndExports.js").GetImportsAndExportsOptions) => import("../../getImportsAndExports.js").AddExportOptions | import("../../getImportsAndExports.js").AddExportOptions[] | undefined) | undefined;
|
|
3
|
+
export default _default;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { SymbolType } from '../../../types/issues.js';
|
|
3
|
+
import { exportVisitor as visit } from '../index.js';
|
|
4
|
+
export default visit(() => true, node => {
|
|
5
|
+
if (ts.isExportAssignment(node)) {
|
|
6
|
+
const pos = node.getChildAt(1).getStart();
|
|
7
|
+
return { node, identifier: 'default', type: SymbolType.UNKNOWN, pos };
|
|
8
|
+
}
|
|
9
|
+
});
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("../../getImportsAndExports.js").GetImportsAndExportsOptions) => import("../../getImportsAndExports.js").AddExportOptions | import("../../getImportsAndExports.js").AddExportOptions[] | undefined) | undefined;
|
|
3
|
+
export default _default;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { SymbolType } from '../../../types/issues.js';
|
|
3
|
+
import { exportVisitor as visit } from '../index.js';
|
|
4
|
+
export default visit(() => true, node => {
|
|
5
|
+
if (ts.isExportDeclaration(node)) {
|
|
6
|
+
if (node.exportClause && ts.isNamedExports(node.exportClause)) {
|
|
7
|
+
const type = node.isTypeOnly ? SymbolType.TYPE : SymbolType.UNKNOWN;
|
|
8
|
+
return node.exportClause.elements.map(element => {
|
|
9
|
+
return { node: element, identifier: element.name.getText(), type, pos: element.name.pos };
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
});
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("../../getImportsAndExports.js").GetImportsAndExportsOptions) => import("../../getImportsAndExports.js").AddExportOptions | import("../../getImportsAndExports.js").AddExportOptions[] | undefined) | undefined;
|
|
3
|
+
export default _default;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { SymbolType } from '../../../types/issues.js';
|
|
3
|
+
import { compact } from '../../../util/array.js';
|
|
4
|
+
import { isPrivateMember, stripQuotes } from '../../ast-helpers.js';
|
|
5
|
+
import { exportVisitor as visit } from '../index.js';
|
|
6
|
+
export default visit(() => true, node => {
|
|
7
|
+
const modifierKinds = node.modifiers?.map(modifier => modifier.kind) ?? [];
|
|
8
|
+
if (modifierKinds.includes(ts.SyntaxKind.ExportKeyword)) {
|
|
9
|
+
if (ts.isVariableStatement(node)) {
|
|
10
|
+
return node.declarationList.declarations.flatMap(declaration => {
|
|
11
|
+
if (ts.isObjectBindingPattern(declaration.name)) {
|
|
12
|
+
return compact(declaration.name.elements.map(element => {
|
|
13
|
+
if (ts.isIdentifier(element.name)) {
|
|
14
|
+
return {
|
|
15
|
+
node: element,
|
|
16
|
+
identifier: element.name.escapedText.toString(),
|
|
17
|
+
type: SymbolType.UNKNOWN,
|
|
18
|
+
pos: element.name.getStart(),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
else if (ts.isArrayBindingPattern(declaration.name)) {
|
|
24
|
+
return compact(declaration.name.elements.map(element => {
|
|
25
|
+
if (ts.isBindingElement(element)) {
|
|
26
|
+
return {
|
|
27
|
+
node: element,
|
|
28
|
+
identifier: element.getText(),
|
|
29
|
+
type: SymbolType.UNKNOWN,
|
|
30
|
+
pos: element.getStart(),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
const identifier = declaration.name.getText();
|
|
37
|
+
return { node: declaration, identifier, type: SymbolType.UNKNOWN, pos: declaration.name.getStart() };
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (ts.isFunctionDeclaration(node) && node.name) {
|
|
42
|
+
const identifier = modifierKinds.includes(ts.SyntaxKind.DefaultKeyword) ? 'default' : node.name.getText();
|
|
43
|
+
const pos = (node.name ?? node.body ?? node).getStart();
|
|
44
|
+
return { node, identifier, pos, type: SymbolType.FUNCTION };
|
|
45
|
+
}
|
|
46
|
+
if (ts.isClassDeclaration(node) && node.name) {
|
|
47
|
+
const identifier = modifierKinds.includes(ts.SyntaxKind.DefaultKeyword) ? 'default' : node.name.getText();
|
|
48
|
+
const pos = (node.name ?? node).getStart();
|
|
49
|
+
const members = node.members
|
|
50
|
+
.filter((member) => (ts.isPropertyDeclaration(member) || ts.isMethodDeclaration(member)) && !isPrivateMember(member))
|
|
51
|
+
.map(member => ({
|
|
52
|
+
node: member,
|
|
53
|
+
identifier: member.name.getText(),
|
|
54
|
+
pos: member.name.getStart(),
|
|
55
|
+
type: SymbolType.MEMBER,
|
|
56
|
+
}));
|
|
57
|
+
return { node, identifier, type: SymbolType.CLASS, pos, members };
|
|
58
|
+
}
|
|
59
|
+
if (ts.isTypeAliasDeclaration(node)) {
|
|
60
|
+
return { node, identifier: node.name.getText(), type: SymbolType.TYPE, pos: node.name.getStart() };
|
|
61
|
+
}
|
|
62
|
+
if (ts.isInterfaceDeclaration(node)) {
|
|
63
|
+
return { node, identifier: node.name.getText(), type: SymbolType.INTERFACE, pos: node.name.getStart() };
|
|
64
|
+
}
|
|
65
|
+
if (ts.isEnumDeclaration(node)) {
|
|
66
|
+
const identifier = modifierKinds.includes(ts.SyntaxKind.DefaultKeyword) ? 'default' : node.name.getText();
|
|
67
|
+
const pos = node.name.getStart();
|
|
68
|
+
const members = node.members.map(member => ({
|
|
69
|
+
node: member,
|
|
70
|
+
identifier: stripQuotes(member.name.getText()),
|
|
71
|
+
pos: member.name.getStart(),
|
|
72
|
+
type: SymbolType.MEMBER,
|
|
73
|
+
}));
|
|
74
|
+
return { node, identifier, type: SymbolType.ENUM, pos, members };
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
});
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
declare const _default: (sourceFile: ts.SourceFile) => (((node: ts.Node, options: import("../../getImportsAndExports.js").GetImportsAndExportsOptions) => import("../../getImportsAndExports.js").AddExportOptions | import("../../getImportsAndExports.js").AddExportOptions[] | undefined) | undefined)[];
|
|
3
|
+
export default _default;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import exportAssignment from './exportAssignment.js';
|
|
3
|
+
import exportDeclaration from './exportDeclaration.js';
|
|
4
|
+
import exportKeyword from './exportKeyword.js';
|
|
5
|
+
import moduleExportsAccessExpression from './moduleExportsAccessExpression.js';
|
|
6
|
+
const visitors = [exportAssignment, exportDeclaration, exportKeyword, moduleExportsAccessExpression];
|
|
7
|
+
export default (sourceFile) => visitors.map(v => v(sourceFile));
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("../../getImportsAndExports.js").GetImportsAndExportsOptions) => import("../../getImportsAndExports.js").AddExportOptions | import("../../getImportsAndExports.js").AddExportOptions[] | undefined) | undefined;
|
|
3
|
+
export default _default;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { SymbolType } from '../../../types/issues.js';
|
|
3
|
+
import { isModuleExportsAccessExpression, stripQuotes } from '../../ast-helpers.js';
|
|
4
|
+
import { isJS } from '../helpers.js';
|
|
5
|
+
import { exportVisitor as visit } from '../index.js';
|
|
6
|
+
export default visit(isJS, node => {
|
|
7
|
+
if (isModuleExportsAccessExpression(node)) {
|
|
8
|
+
const parent = node.parent;
|
|
9
|
+
if (ts.isPropertyAccessExpression(parent)) {
|
|
10
|
+
const identifier = parent.name.getText();
|
|
11
|
+
const pos = parent.name.getStart();
|
|
12
|
+
return { node, identifier, type: SymbolType.UNKNOWN, pos };
|
|
13
|
+
}
|
|
14
|
+
else if (ts.isElementAccessExpression(parent)) {
|
|
15
|
+
const identifier = stripQuotes(parent.argumentExpression.getText());
|
|
16
|
+
const pos = parent.argumentExpression.getStart();
|
|
17
|
+
return { node, identifier, type: SymbolType.UNKNOWN, pos };
|
|
18
|
+
}
|
|
19
|
+
else if (ts.isBinaryExpression(parent)) {
|
|
20
|
+
const expr = parent.right;
|
|
21
|
+
if (ts.isObjectLiteralExpression(expr) && expr.properties.every(ts.isShorthandPropertyAssignment)) {
|
|
22
|
+
return expr.properties.map(node => {
|
|
23
|
+
return { node, identifier: node.getText(), type: SymbolType.UNKNOWN, pos: node.pos };
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return { node, identifier: 'default', type: SymbolType.UNKNOWN, pos: node.getStart() };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { BoundSourceFile } from '../SourceFile.js';
|
|
2
|
+
export declare const isNotJS: (sourceFile: BoundSourceFile) => boolean;
|
|
3
|
+
export declare const isJS: (sourceFile: BoundSourceFile) => boolean;
|
|
4
|
+
export declare function getJSXImplicitImportBase(sourceFile: BoundSourceFile): string | undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
export const isNotJS = (sourceFile) => sourceFile.scriptKind !== ts.ScriptKind.JS && sourceFile.scriptKind !== ts.ScriptKind.JSX;
|
|
3
|
+
export const isJS = (sourceFile) => sourceFile.scriptKind === ts.ScriptKind.JS || sourceFile.scriptKind === ts.ScriptKind.JSX;
|
|
4
|
+
export function getJSXImplicitImportBase(sourceFile) {
|
|
5
|
+
const jsxImportSourcePragmas = sourceFile.pragmas?.get('jsximportsource');
|
|
6
|
+
const jsxImportSourcePragma = Array.isArray(jsxImportSourcePragmas)
|
|
7
|
+
? jsxImportSourcePragmas[jsxImportSourcePragmas.length - 1]
|
|
8
|
+
: jsxImportSourcePragmas;
|
|
9
|
+
return jsxImportSourcePragma?.arguments.factory;
|
|
10
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("../../getImportsAndExports.js").GetImportsAndExportsOptions) => import("../../getImportsAndExports.js").AddImportOptions | import("../../getImportsAndExports.js").AddImportOptions[] | undefined) | undefined;
|
|
3
|
+
export default _default;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { isImportCall } from '../../ast-helpers.js';
|
|
3
|
+
import { importVisitor as visit } from '../index.js';
|
|
4
|
+
export default visit(() => true, node => {
|
|
5
|
+
if (isImportCall(node)) {
|
|
6
|
+
if (node.arguments[0] && ts.isStringLiteralLike(node.arguments[0])) {
|
|
7
|
+
const specifier = node.arguments[0].text;
|
|
8
|
+
return { specifier, identifier: 'default' };
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
});
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("../../getImportsAndExports.js").GetImportsAndExportsOptions) => import("../../getImportsAndExports.js").AddImportOptions | import("../../getImportsAndExports.js").AddImportOptions[] | undefined) | undefined;
|
|
3
|
+
export default _default;
|