fcis 0.1.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/.plans/001-fcis-analyzer.md +832 -0
- package/.plans/002-fcis-analyzer-improvements.md +205 -0
- package/README.md +272 -0
- package/TECHNICAL.md +386 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +1836 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +709 -0
- package/dist/index.js +1845 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -0
- package/pnpm-workspace.yaml +0 -0
- package/src/analyzer.ts +266 -0
- package/src/classification/classifier.ts +156 -0
- package/src/classification/derive-status.ts +171 -0
- package/src/classification/quality-scorer.ts +481 -0
- package/src/cli.ts +286 -0
- package/src/detection/detect-markers.ts +480 -0
- package/src/detection/markers.ts +332 -0
- package/src/extraction/extract-functions.ts +570 -0
- package/src/extraction/extractor.ts +188 -0
- package/src/index.ts +111 -0
- package/src/reporting/report-console.ts +416 -0
- package/src/reporting/report-json.ts +232 -0
- package/src/scoring/scorer.ts +504 -0
- package/src/types.ts +248 -0
- package/tests/classifier.test.ts +480 -0
- package/tests/derive-status.test.ts +464 -0
- package/tests/detect-markers.test.ts +639 -0
- package/tests/extractor.test.ts +155 -0
- package/tests/integration.test.ts +706 -0
- package/tests/quality-scorer.test.ts +650 -0
- package/tests/scorer.test.ts +768 -0
- package/tsconfig.json +34 -0
- package/tsup.config.ts +17 -0
- package/vendor/ts-morph/.editorconfig +10 -0
- package/vendor/ts-morph/.gitattributes +11 -0
- package/vendor/ts-morph/.github/CODE_OF_CONDUCT.md +77 -0
- package/vendor/ts-morph/.github/ISSUE_TEMPLATE/bug_report.md +29 -0
- package/vendor/ts-morph/.github/ISSUE_TEMPLATE/custom.md +4 -0
- package/vendor/ts-morph/.github/ISSUE_TEMPLATE/feature_request.md +18 -0
- package/vendor/ts-morph/.github/workflows/ci.yml +50 -0
- package/vendor/ts-morph/.github/workflows/publish.yml +53 -0
- package/vendor/ts-morph/.vscode/settings.json +10 -0
- package/vendor/ts-morph/CONTRIBUTING.md +23 -0
- package/vendor/ts-morph/DEVELOPMENT.md +32 -0
- package/vendor/ts-morph/LICENSE +21 -0
- package/vendor/ts-morph/deno.json +8 -0
- package/vendor/ts-morph/deno.lock +1233 -0
- package/vendor/ts-morph/docs/CNAME +1 -0
- package/vendor/ts-morph/docs/Gemfile +2 -0
- package/vendor/ts-morph/docs/_config.yml +5 -0
- package/vendor/ts-morph/docs/_layouts/default.html +159 -0
- package/vendor/ts-morph/docs/_script-templates/main.ts +116 -0
- package/vendor/ts-morph/docs/assets/css/style.scss +212 -0
- package/vendor/ts-morph/docs/details/ambient.md +38 -0
- package/vendor/ts-morph/docs/details/async.md +31 -0
- package/vendor/ts-morph/docs/details/classes.md +314 -0
- package/vendor/ts-morph/docs/details/comment-ranges.md +7 -0
- package/vendor/ts-morph/docs/details/comments.md +122 -0
- package/vendor/ts-morph/docs/details/decorators.md +119 -0
- package/vendor/ts-morph/docs/details/documentation.md +73 -0
- package/vendor/ts-morph/docs/details/enums.md +117 -0
- package/vendor/ts-morph/docs/details/exports.md +308 -0
- package/vendor/ts-morph/docs/details/expressions.md +46 -0
- package/vendor/ts-morph/docs/details/functions.md +150 -0
- package/vendor/ts-morph/docs/details/generators.md +27 -0
- package/vendor/ts-morph/docs/details/identifiers.md +79 -0
- package/vendor/ts-morph/docs/details/imports.md +191 -0
- package/vendor/ts-morph/docs/details/index.md +52 -0
- package/vendor/ts-morph/docs/details/initializers.md +40 -0
- package/vendor/ts-morph/docs/details/interfaces.md +218 -0
- package/vendor/ts-morph/docs/details/literals.md +20 -0
- package/vendor/ts-morph/docs/details/modifiers.md +38 -0
- package/vendor/ts-morph/docs/details/modules.md +113 -0
- package/vendor/ts-morph/docs/details/namespaces.md +7 -0
- package/vendor/ts-morph/docs/details/object-literal-expressions.md +106 -0
- package/vendor/ts-morph/docs/details/parameters.md +64 -0
- package/vendor/ts-morph/docs/details/signatures.md +41 -0
- package/vendor/ts-morph/docs/details/source-files.md +292 -0
- package/vendor/ts-morph/docs/details/type-aliases.md +34 -0
- package/vendor/ts-morph/docs/details/type-parameters.md +72 -0
- package/vendor/ts-morph/docs/details/types.md +254 -0
- package/vendor/ts-morph/docs/details/variables.md +110 -0
- package/vendor/ts-morph/docs/emitting.md +151 -0
- package/vendor/ts-morph/docs/index.md +25 -0
- package/vendor/ts-morph/docs/manipulation/code-writer.md +20 -0
- package/vendor/ts-morph/docs/manipulation/formatting.md +76 -0
- package/vendor/ts-morph/docs/manipulation/index.md +136 -0
- package/vendor/ts-morph/docs/manipulation/order.md +14 -0
- package/vendor/ts-morph/docs/manipulation/performance.md +222 -0
- package/vendor/ts-morph/docs/manipulation/removing.md +31 -0
- package/vendor/ts-morph/docs/manipulation/renaming.md +106 -0
- package/vendor/ts-morph/docs/manipulation/settings.md +76 -0
- package/vendor/ts-morph/docs/manipulation/structures.md +117 -0
- package/vendor/ts-morph/docs/manipulation/transforms.md +84 -0
- package/vendor/ts-morph/docs/metrics/performance.json +4 -0
- package/vendor/ts-morph/docs/navigation/ambient-modules.md +22 -0
- package/vendor/ts-morph/docs/navigation/compiler-nodes.md +82 -0
- package/vendor/ts-morph/docs/navigation/directories.md +287 -0
- package/vendor/ts-morph/docs/navigation/example.md +50 -0
- package/vendor/ts-morph/docs/navigation/finding-references.md +53 -0
- package/vendor/ts-morph/docs/navigation/getting-source-files.md +59 -0
- package/vendor/ts-morph/docs/navigation/images/getChildrenVsForEachChild.gif +0 -0
- package/vendor/ts-morph/docs/navigation/index.md +94 -0
- package/vendor/ts-morph/docs/navigation/language-service.md +23 -0
- package/vendor/ts-morph/docs/navigation/program.md +25 -0
- package/vendor/ts-morph/docs/navigation/type-checker.md +33 -0
- package/vendor/ts-morph/docs/setup/adding-source-files.md +145 -0
- package/vendor/ts-morph/docs/setup/ast-viewers.md +46 -0
- package/vendor/ts-morph/docs/setup/diagnostics.md +109 -0
- package/vendor/ts-morph/docs/setup/file-system.md +106 -0
- package/vendor/ts-morph/docs/setup/images/atom-ast.png +0 -0
- package/vendor/ts-morph/docs/setup/images/atom-ast_small.png +0 -0
- package/vendor/ts-morph/docs/setup/images/atom-command-palette.png +0 -0
- package/vendor/ts-morph/docs/setup/images/atom-file.png +0 -0
- package/vendor/ts-morph/docs/setup/images/ts-ast-viewer.png +0 -0
- package/vendor/ts-morph/docs/setup/index.md +94 -0
- package/vendor/ts-morph/docs/utilities.md +55 -0
- package/vendor/ts-morph/dprint.json +23 -0
- package/vendor/ts-morph/package.json +30 -0
- package/vendor/ts-morph/packages/bootstrap/LICENSE +21 -0
- package/vendor/ts-morph/packages/bootstrap/lib/ts-morph-bootstrap.d.ts +397 -0
- package/vendor/ts-morph/packages/bootstrap/package.json +46 -0
- package/vendor/ts-morph/packages/bootstrap/readme.md +200 -0
- package/vendor/ts-morph/packages/common/LICENSE +21 -0
- package/vendor/ts-morph/packages/common/lib/ts-morph-common.d.ts +1082 -0
- package/vendor/ts-morph/packages/common/lib/typescript.d.ts +11439 -0
- package/vendor/ts-morph/packages/common/package.json +65 -0
- package/vendor/ts-morph/packages/common/readme.md +5 -0
- package/vendor/ts-morph/packages/scripts/changeTypeScriptVersion.ts +28 -0
- package/vendor/ts-morph/packages/scripts/createDeclarationProject.ts +47 -0
- package/vendor/ts-morph/packages/scripts/deps.ts +2 -0
- package/vendor/ts-morph/packages/scripts/execScript.ts +31 -0
- package/vendor/ts-morph/packages/scripts/folders.ts +11 -0
- package/vendor/ts-morph/packages/scripts/getDevCompilerVersions.ts +19 -0
- package/vendor/ts-morph/packages/scripts/mod.ts +7 -0
- package/vendor/ts-morph/packages/scripts/utils/Memoize.ts +36 -0
- package/vendor/ts-morph/packages/scripts/utils/forEachTypeText.ts +23 -0
- package/vendor/ts-morph/packages/scripts/utils/makeConstructorsPrivate.ts +26 -0
- package/vendor/ts-morph/packages/scripts/utils/mod.ts +4 -0
- package/vendor/ts-morph/packages/scripts/utils/printDiagnostics.ts +10 -0
- package/vendor/ts-morph/packages/ts-morph/LICENSE +21 -0
- package/vendor/ts-morph/packages/ts-morph/lib/ts-morph.d.ts +11198 -0
- package/vendor/ts-morph/packages/ts-morph/package.json +78 -0
- package/vendor/ts-morph/packages/ts-morph/readme.md +111 -0
- package/vendor/ts-morph/readme.md +14 -0
- package/vendor/ts-morph/rfcs/README.md +13 -0
- package/vendor/ts-morph/rfcs/RFC-0001 - Inserting Into Statements Handling Comments.md +181 -0
- package/vendor/ts-morph/tsconfig.common.json +17 -0
- package/vitest.config.ts +16 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ts-morph/common",
|
|
3
|
+
"version": "0.28.1",
|
|
4
|
+
"description": "Common functionality for ts-morph packages.",
|
|
5
|
+
"main": "dist/ts-morph-common.js",
|
|
6
|
+
"author": "David Sherret",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": "git+https://github.com/dsherret/ts-morph.git",
|
|
9
|
+
"types": "lib/ts-morph-common.d.ts",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "deno task build:declarations && deno task build:node",
|
|
12
|
+
"build:node": "rimraf dist && deno task createLibFile && deno task rollup && deno run -A scripts/bundleLocalTs.ts",
|
|
13
|
+
"build:deno": "rimraf ../../deno/common && rimraf dist-deno && deno task rollup --environment BUILD:deno && deno task build:declarations && deno run -A scripts/buildDeno.ts",
|
|
14
|
+
"build:declarations": "deno run -A scripts/buildDeclarations.ts",
|
|
15
|
+
"createLibFile": "deno run -A scripts/createLibFile.ts",
|
|
16
|
+
"test": "deno run -A npm:mocha",
|
|
17
|
+
"test:ci": "deno task test",
|
|
18
|
+
"test:debug": "deno task test --inspect-brk",
|
|
19
|
+
"rollup": "rollup --config"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"minimatch": "^10.0.1",
|
|
23
|
+
"path-browserify": "^1.0.1",
|
|
24
|
+
"tinyglobby": "^0.2.14"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
28
|
+
"@types/chai": "^5.2.1",
|
|
29
|
+
"@types/mocha": "^10.0.10",
|
|
30
|
+
"@types/node": "^22.14.1",
|
|
31
|
+
"chai": "^5.2.0",
|
|
32
|
+
"cross-env": "^7.0.3",
|
|
33
|
+
"mocha": "^11.1.0",
|
|
34
|
+
"rimraf": "^6.0.1",
|
|
35
|
+
"rollup": "=4.40.0",
|
|
36
|
+
"ts-node": "^10.9.2",
|
|
37
|
+
"tslib": "^2.8.1",
|
|
38
|
+
"typescript": "5.9.2"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"browser": {
|
|
44
|
+
"fs": false,
|
|
45
|
+
"node:fs": false,
|
|
46
|
+
"fs/promises": false,
|
|
47
|
+
"node:fs/promises": false,
|
|
48
|
+
"os": false,
|
|
49
|
+
"node:os": false,
|
|
50
|
+
"fs.realpath": false,
|
|
51
|
+
"mkdirp": false,
|
|
52
|
+
"dir-glob": false,
|
|
53
|
+
"graceful-fs": false,
|
|
54
|
+
"tinyglobby": false,
|
|
55
|
+
"source-map-support": false,
|
|
56
|
+
"glob-parent": false,
|
|
57
|
+
"glob": false,
|
|
58
|
+
"path": false,
|
|
59
|
+
"node:path": false,
|
|
60
|
+
"crypto": false,
|
|
61
|
+
"buffer": false,
|
|
62
|
+
"@microsoft/typescript-etw": false,
|
|
63
|
+
"inspector": false
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { path, tsMorph } from "./deps.ts";
|
|
2
|
+
import { folders } from "./folders.ts";
|
|
3
|
+
const { Project, SyntaxKind } = tsMorph;
|
|
4
|
+
|
|
5
|
+
export function changeTypeScriptVersion(version: string) {
|
|
6
|
+
setModuleSpecifierValue(`typescript-${version}`);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function resetTypeScriptVersion() {
|
|
10
|
+
setModuleSpecifierValue("typescript");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function setModuleSpecifierValue(value: string) {
|
|
14
|
+
const project = new Project();
|
|
15
|
+
const declarationFile = project.addSourceFileAtPath(path.join(folders.common, "lib/ts-morph-common.d.ts"));
|
|
16
|
+
const jsFile = project.addSourceFileAtPath(path.join(folders.common, "dist/ts-morph-common.js"));
|
|
17
|
+
|
|
18
|
+
for (const importDec of declarationFile.getImportDeclarations()) {
|
|
19
|
+
const moduleSpecifierValue = importDec.getModuleSpecifierValue();
|
|
20
|
+
if (moduleSpecifierValue.startsWith("typescript"))
|
|
21
|
+
importDec.setModuleSpecifier(value);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const callExpr = jsFile.getVariableDeclarationOrThrow("ts").getInitializerIfKindOrThrow(SyntaxKind.CallExpression);
|
|
25
|
+
callExpr.getArguments()[0].asKindOrThrow(SyntaxKind.StringLiteral).setLiteralValue(value);
|
|
26
|
+
|
|
27
|
+
[declarationFile, jsFile].forEach(s => s.saveSync());
|
|
28
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { tsMorph } from "./deps.ts";
|
|
2
|
+
import { printDiagnostics } from "./utils/mod.ts";
|
|
3
|
+
const { IndentationText, NewLineKind, Project } = tsMorph;
|
|
4
|
+
|
|
5
|
+
export interface CreateDeclarationProjectOptions {
|
|
6
|
+
tsConfigFilePath: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function createDeclarationProject(opts: CreateDeclarationProjectOptions) {
|
|
10
|
+
const project = new Project({
|
|
11
|
+
tsConfigFilePath: opts.tsConfigFilePath,
|
|
12
|
+
manipulationSettings: {
|
|
13
|
+
indentationText: IndentationText.TwoSpaces,
|
|
14
|
+
newLineKind: NewLineKind.LineFeed,
|
|
15
|
+
},
|
|
16
|
+
compilerOptions: {
|
|
17
|
+
declaration: true,
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const emitResult = project.emitToMemory({ emitOnlyDtsFiles: true });
|
|
22
|
+
|
|
23
|
+
if (emitResult.getDiagnostics().length > 0) {
|
|
24
|
+
printDiagnostics(emitResult.getDiagnostics());
|
|
25
|
+
Deno.exit(1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const declarationProject = new Project({
|
|
29
|
+
tsConfigFilePath: opts.tsConfigFilePath,
|
|
30
|
+
manipulationSettings: {
|
|
31
|
+
indentationText: IndentationText.TwoSpaces,
|
|
32
|
+
newLineKind: NewLineKind.LineFeed,
|
|
33
|
+
},
|
|
34
|
+
skipAddingFilesFromTsConfig: true,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
for (const file of emitResult.getFiles())
|
|
38
|
+
declarationProject.createSourceFile(file.filePath, file.text, { overwrite: true });
|
|
39
|
+
|
|
40
|
+
const declDiagnostics = declarationProject.getPreEmitDiagnostics();
|
|
41
|
+
if (declDiagnostics.length > 0) {
|
|
42
|
+
console.log(declarationProject.formatDiagnosticsWithColorAndContext(declDiagnostics));
|
|
43
|
+
Deno.exit(1);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return declarationProject;
|
|
47
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
async function execScript(command: string, args: string[], cwd: string) {
|
|
2
|
+
const p = Deno.run({
|
|
3
|
+
cwd,
|
|
4
|
+
cmd: [command, ...args],
|
|
5
|
+
stderr: "piped",
|
|
6
|
+
stdout: "piped",
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const [status, stdout, stderr] = await Promise.all([
|
|
10
|
+
p.status(),
|
|
11
|
+
p.output(),
|
|
12
|
+
p.stderrOutput(),
|
|
13
|
+
]);
|
|
14
|
+
p.close();
|
|
15
|
+
|
|
16
|
+
if (!status.success) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
`Error executing ${command} ${args.join(" ")}: ${new TextDecoder().decode(stderr)}`,
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return new TextDecoder().decode(stdout);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function execNpmScript(scriptName: string, cwd: string) {
|
|
26
|
+
return execScript(
|
|
27
|
+
"npm",
|
|
28
|
+
["run", scriptName, "--no-update-notifier", "--scripts-prepend-node-path"],
|
|
29
|
+
cwd,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { path } from "./deps.ts";
|
|
2
|
+
|
|
3
|
+
const dirname = path.dirname(path.fromFileUrl(import.meta.url));
|
|
4
|
+
const root = path.join(dirname, "../../");
|
|
5
|
+
export const folders = {
|
|
6
|
+
scripts: path.join(root, "./packages/scripts"),
|
|
7
|
+
common: path.join(root, "./packages/common"),
|
|
8
|
+
bootstrap: path.join(root, "./packages/bootstrap"),
|
|
9
|
+
tsMorph: path.join(root, "./packages/ts-morph"),
|
|
10
|
+
root,
|
|
11
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { path } from "./deps.ts";
|
|
2
|
+
import { folders } from "./folders.ts";
|
|
3
|
+
|
|
4
|
+
export function getDevCompilerVersions() {
|
|
5
|
+
const fileData = JSON.parse(Deno.readTextFileSync(path.join(folders.common, "package.json")));
|
|
6
|
+
const dependencies = fileData["devDependencies"];
|
|
7
|
+
const keyRegEx = /^typescript(-[0-9]+\.[0-9]+\.[0-9]+)$/;
|
|
8
|
+
const versionRegEx = /[0-9]+\.[0-9]+\.[0-9]+/;
|
|
9
|
+
const versions: { version: string; name: string }[] = [];
|
|
10
|
+
|
|
11
|
+
for (const key of Object.keys(dependencies)) {
|
|
12
|
+
if (!keyRegEx.test(key))
|
|
13
|
+
continue;
|
|
14
|
+
const matches = versionRegEx.exec(dependencies[key]);
|
|
15
|
+
versions.push({ version: matches![0], name: key });
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return versions.sort((a, b) => a.version > b.version ? -1 : 1);
|
|
19
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./changeTypeScriptVersion.ts";
|
|
2
|
+
export * from "./createDeclarationProject.ts";
|
|
3
|
+
export { path, tsMorph } from "./deps.ts";
|
|
4
|
+
export * from "./execScript.ts";
|
|
5
|
+
export * from "./folders.ts";
|
|
6
|
+
export * from "./getDevCompilerVersions.ts";
|
|
7
|
+
export * from "./utils/mod.ts";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Decorator for memoizing the result of a method. */
|
|
2
|
+
export function Memoize(target: any, context: DecoratorContext) {
|
|
3
|
+
if (context.kind === "method" || context.kind === "getter")
|
|
4
|
+
return getNewFunction(target);
|
|
5
|
+
else
|
|
6
|
+
throw new Error("Not implemented.");
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const weakMap = new WeakMap<object, Map<string, unknown>>();
|
|
10
|
+
|
|
11
|
+
let counter = 0;
|
|
12
|
+
function getNewFunction(originalFunction: Function) {
|
|
13
|
+
const identifier = counter++;
|
|
14
|
+
function decorator(this: any, ...args: any[]) {
|
|
15
|
+
let propertyValues = weakMap.get(this);
|
|
16
|
+
if (propertyValues == null) {
|
|
17
|
+
propertyValues = new Map<string, unknown>();
|
|
18
|
+
weakMap.set(this, propertyValues);
|
|
19
|
+
}
|
|
20
|
+
let propName = `__memoized_value_${identifier}`;
|
|
21
|
+
if (arguments.length > 0)
|
|
22
|
+
propName += "_" + JSON.stringify(args);
|
|
23
|
+
let returnedValue: any;
|
|
24
|
+
|
|
25
|
+
if (propertyValues.has(propName))
|
|
26
|
+
returnedValue = propertyValues.get(propName);
|
|
27
|
+
else {
|
|
28
|
+
returnedValue = originalFunction.apply(this, args);
|
|
29
|
+
propertyValues.set(propName, returnedValue);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return returnedValue;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return decorator;
|
|
36
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { tsMorph } from "../deps.ts";
|
|
2
|
+
|
|
3
|
+
export function forEachTypeText(structure: tsMorph.Structures, func: (typeText: string) => string) {
|
|
4
|
+
forEachChild(structure);
|
|
5
|
+
|
|
6
|
+
function forEachChild(child: tsMorph.Structures) {
|
|
7
|
+
if (tsMorph.Structure.isTyped(child) && child.type != null)
|
|
8
|
+
child.type = withType(child.type);
|
|
9
|
+
if (tsMorph.Structure.isReturnTyped(child) && child.returnType != null)
|
|
10
|
+
child.returnType = withType(child.returnType);
|
|
11
|
+
if (tsMorph.Structure.isTypeParameter(child) && child.constraint != null)
|
|
12
|
+
child.constraint = withType(child.constraint);
|
|
13
|
+
|
|
14
|
+
tsMorph.forEachStructureChild(child, forEachChild);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function withType(text: string | tsMorph.WriterFunction) {
|
|
18
|
+
if (typeof text !== "string")
|
|
19
|
+
throw new Error("Unhandled scenario where the type text was not a string.");
|
|
20
|
+
|
|
21
|
+
return func(text);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { tsMorph } from "../deps.ts";
|
|
2
|
+
|
|
3
|
+
export function makeConstructorsPrivate(mainFile: tsMorph.SourceFile) {
|
|
4
|
+
forEachDescendant(mainFile);
|
|
5
|
+
|
|
6
|
+
function forEachDescendant(node: tsMorph.Node) {
|
|
7
|
+
node.forEachChild(forEachDescendant);
|
|
8
|
+
|
|
9
|
+
if (tsMorph.Node.isClassDeclaration(node))
|
|
10
|
+
withClass(node);
|
|
11
|
+
|
|
12
|
+
if (!tsMorph.Node.isSourceFile(node))
|
|
13
|
+
node.forget();
|
|
14
|
+
|
|
15
|
+
function withClass(classDec: tsMorph.ClassDeclaration) {
|
|
16
|
+
for (const ctor of classDec.getConstructors()) {
|
|
17
|
+
const hasPrivateTag = ctor.getJsDocs().some(doc => doc.getTags().some(tag => tag.getTagName() === "private"));
|
|
18
|
+
if (hasPrivateTag) {
|
|
19
|
+
ctor.getParameters().forEach(p => p.remove());
|
|
20
|
+
ctor.getJsDocs().forEach(d => d.remove());
|
|
21
|
+
ctor.setScope(classDec.getDerivedClasses().length > 0 ? tsMorph.Scope.Protected : tsMorph.Scope.Private);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { tsMorph } from "../deps.ts";
|
|
2
|
+
|
|
3
|
+
/** Prints the provided diagnostics with colour and context. */
|
|
4
|
+
export function printDiagnostics(diagnostics: tsMorph.Diagnostic[]) {
|
|
5
|
+
console.log(tsMorph.ts.formatDiagnosticsWithColorAndContext(diagnostics.map(d => d.compilerObject), {
|
|
6
|
+
getCurrentDirectory: () => Deno.cwd(),
|
|
7
|
+
getCanonicalFileName: fileName => fileName,
|
|
8
|
+
getNewLine: () => "\n",
|
|
9
|
+
}));
|
|
10
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 David Sherret
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|