@nexus-ioc/language-service 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/LICENSE +21 -0
- package/README.md +134 -0
- package/dist/actions/get-completion-info.actions.d.ts +3 -0
- package/dist/actions/get-completion-info.actions.js +57 -0
- package/dist/actions/get-completion-info.actions.js.map +1 -0
- package/dist/actions/get-semantic-diagnostics.actions.d.ts +3 -0
- package/dist/actions/get-semantic-diagnostics.actions.js +153 -0
- package/dist/actions/get-semantic-diagnostics.actions.js.map +1 -0
- package/dist/helpers/check-types.helper.d.ts +3 -0
- package/dist/helpers/check-types.helper.js +30 -0
- package/dist/helpers/check-types.helper.js.map +1 -0
- package/dist/helpers/compare-string-types.helper.d.ts +4 -0
- package/dist/helpers/compare-string-types.helper.js +16 -0
- package/dist/helpers/compare-string-types.helper.js.map +1 -0
- package/dist/helpers/find-node-at-position.helper.d.ts +2 -0
- package/dist/helpers/find-node-at-position.helper.js +16 -0
- package/dist/helpers/find-node-at-position.helper.js.map +1 -0
- package/dist/helpers/find-type-references.helper.d.ts +8 -0
- package/dist/helpers/find-type-references.helper.js +51 -0
- package/dist/helpers/find-type-references.helper.js.map +1 -0
- package/dist/helpers/get-type-of-node.helper.d.ts +2 -0
- package/dist/helpers/get-type-of-node.helper.js +14 -0
- package/dist/helpers/get-type-of-node.helper.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +62 -0
- package/dist/index.js.map +1 -0
- package/dist/language-service/ns-language-service.d.ts +19 -0
- package/dist/language-service/ns-language-service.js +33 -0
- package/dist/language-service/ns-language-service.js.map +1 -0
- package/dist/language-service/parse-config-service.d.ts +22 -0
- package/dist/language-service/parse-config-service.js +61 -0
- package/dist/language-service/parse-config-service.js.map +1 -0
- package/dist/language-service/types.d.ts +88 -0
- package/dist/language-service/types.js +3 -0
- package/dist/language-service/types.js.map +1 -0
- package/dist/logger.d.ts +8 -0
- package/dist/logger.js +19 -0
- package/dist/logger.js.map +1 -0
- package/dist/parsers/inject.parser.d.ts +16 -0
- package/dist/parsers/inject.parser.js +44 -0
- package/dist/parsers/inject.parser.js.map +1 -0
- package/dist/parsers/injectable.parser.d.ts +5 -0
- package/dist/parsers/injectable.parser.js +13 -0
- package/dist/parsers/injectable.parser.js.map +1 -0
- package/dist/parsers/ns-module.parser.d.ts +45 -0
- package/dist/parsers/ns-module.parser.js +237 -0
- package/dist/parsers/ns-module.parser.js.map +1 -0
- package/dist/parsers/ns-modules.parser.d.ts +7 -0
- package/dist/parsers/ns-modules.parser.js +35 -0
- package/dist/parsers/ns-modules.parser.js.map +1 -0
- package/package.json +59 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type ts from "typescript/lib/tsserverlibrary";
|
|
2
|
+
import type { Logger } from "../logger";
|
|
3
|
+
import type { CompilerOptions } from "./types";
|
|
4
|
+
export type PluginConfig = {
|
|
5
|
+
debug?: boolean;
|
|
6
|
+
logPath?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare class NsLanguageService {
|
|
9
|
+
private readonly project;
|
|
10
|
+
private readonly host;
|
|
11
|
+
private readonly _tsLS;
|
|
12
|
+
private readonly config;
|
|
13
|
+
private readonly _logger;
|
|
14
|
+
private options;
|
|
15
|
+
constructor(project: ts.server.Project, host: ts.server.ServerHost, _tsLS: ts.LanguageService, config: PluginConfig, _logger: Logger);
|
|
16
|
+
get logger(): Logger;
|
|
17
|
+
get tsLS(): ts.LanguageService;
|
|
18
|
+
getConfigOptions(): CompilerOptions;
|
|
19
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NsLanguageService = void 0;
|
|
4
|
+
function parseNsCompilerOptions(config) {
|
|
5
|
+
return {
|
|
6
|
+
debug: false,
|
|
7
|
+
logPath: "./nexus-ioc-plugin.log",
|
|
8
|
+
...config,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
class NsLanguageService {
|
|
12
|
+
constructor(project, host, _tsLS, config, _logger) {
|
|
13
|
+
this.project = project;
|
|
14
|
+
this.host = host;
|
|
15
|
+
this._tsLS = _tsLS;
|
|
16
|
+
this.config = config;
|
|
17
|
+
this._logger = _logger;
|
|
18
|
+
this.options = parseNsCompilerOptions(config);
|
|
19
|
+
const projectName = project.getProjectName();
|
|
20
|
+
_logger.log(`Nexus-IoC compiler options for ${projectName}: ${JSON.stringify(this.options)}`);
|
|
21
|
+
}
|
|
22
|
+
get logger() {
|
|
23
|
+
return this._logger;
|
|
24
|
+
}
|
|
25
|
+
get tsLS() {
|
|
26
|
+
return this._tsLS;
|
|
27
|
+
}
|
|
28
|
+
getConfigOptions() {
|
|
29
|
+
return this.options;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.NsLanguageService = NsLanguageService;
|
|
33
|
+
//# sourceMappingURL=ns-language-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ns-language-service.js","sourceRoot":"","sources":["../../src/language-service/ns-language-service.ts"],"names":[],"mappings":";;;AAIA,SAAS,sBAAsB,CAAC,MAAoB;IACnD,OAAO;QACN,KAAK,EAAE,KAAK;QACZ,OAAO,EAAE,wBAAwB;QACjC,GAAG,MAAM;KACT,CAAC;AACH,CAAC;AAOD,MAAa,iBAAiB;IAG7B,YACkB,OAA0B,EAC1B,IAA0B,EAC1B,KAAyB,EACzB,MAAoB,EACpB,OAAe;QAJf,YAAO,GAAP,OAAO,CAAmB;QAC1B,SAAI,GAAJ,IAAI,CAAsB;QAC1B,UAAK,GAAL,KAAK,CAAoB;QACzB,WAAM,GAAN,MAAM,CAAc;QACpB,YAAO,GAAP,OAAO,CAAQ;QAEhC,IAAI,CAAC,OAAO,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAAC;QAC9C,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;QAE7C,OAAO,CAAC,GAAG,CACV,kCAAkC,WAAW,KAAK,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAChF,CAAC;IACH,CAAC;IAED,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAED,IAAI,IAAI;QACP,OAAO,IAAI,CAAC,KAAK,CAAC;IACnB,CAAC;IAEM,gBAAgB;QACtB,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;CACD;AA7BD,8CA6BC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type ts from "typescript";
|
|
2
|
+
import type { AbsoluteFsPath, ConfigurationHost, FileStats, PathSegment, PathString } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Used to read configuration files.
|
|
5
|
+
*
|
|
6
|
+
* A language service parse configuration host is independent of the adapter
|
|
7
|
+
* because signatures of calls like `FileSystem#readFile` are a bit stricter
|
|
8
|
+
* than those on the adapter.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ParseConfigHost implements ConfigurationHost {
|
|
11
|
+
private readonly serverHost;
|
|
12
|
+
constructor(serverHost: ts.server.ServerHost);
|
|
13
|
+
exists(path: AbsoluteFsPath): boolean;
|
|
14
|
+
readFile(path: AbsoluteFsPath): string;
|
|
15
|
+
lstat(path: AbsoluteFsPath): FileStats;
|
|
16
|
+
readdir(path: AbsoluteFsPath): PathSegment[];
|
|
17
|
+
pwd(): AbsoluteFsPath;
|
|
18
|
+
extname(path: AbsoluteFsPath | PathSegment): string;
|
|
19
|
+
resolve(...paths: string[]): AbsoluteFsPath;
|
|
20
|
+
dirname<T extends PathString>(file: T): T;
|
|
21
|
+
join<T extends PathString>(basePath: T, ...paths: string[]): T;
|
|
22
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParseConfigHost = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const p = tslib_1.__importStar(require("node:path"));
|
|
6
|
+
/**
|
|
7
|
+
* Used to read configuration files.
|
|
8
|
+
*
|
|
9
|
+
* A language service parse configuration host is independent of the adapter
|
|
10
|
+
* because signatures of calls like `FileSystem#readFile` are a bit stricter
|
|
11
|
+
* than those on the adapter.
|
|
12
|
+
*/
|
|
13
|
+
class ParseConfigHost {
|
|
14
|
+
constructor(serverHost) {
|
|
15
|
+
this.serverHost = serverHost;
|
|
16
|
+
}
|
|
17
|
+
exists(path) {
|
|
18
|
+
return (this.serverHost.fileExists(path) || this.serverHost.directoryExists(path));
|
|
19
|
+
}
|
|
20
|
+
readFile(path) {
|
|
21
|
+
const content = this.serverHost.readFile(path);
|
|
22
|
+
if (content === undefined) {
|
|
23
|
+
throw new Error(`LanguageServiceFS#readFile called on unavailable file ${path}`);
|
|
24
|
+
}
|
|
25
|
+
return content;
|
|
26
|
+
}
|
|
27
|
+
lstat(path) {
|
|
28
|
+
return {
|
|
29
|
+
isFile: () => {
|
|
30
|
+
return this.serverHost.fileExists(path);
|
|
31
|
+
},
|
|
32
|
+
isDirectory: () => {
|
|
33
|
+
return this.serverHost.directoryExists(path);
|
|
34
|
+
},
|
|
35
|
+
isSymbolicLink: () => {
|
|
36
|
+
throw new Error("LanguageServiceFS#lstat#isSymbolicLink not implemented");
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
readdir(path) {
|
|
41
|
+
return this.serverHost.readDirectory(path, undefined, undefined, undefined,
|
|
42
|
+
/* depth */ 1);
|
|
43
|
+
}
|
|
44
|
+
pwd() {
|
|
45
|
+
return this.serverHost.getCurrentDirectory();
|
|
46
|
+
}
|
|
47
|
+
extname(path) {
|
|
48
|
+
return p.extname(path);
|
|
49
|
+
}
|
|
50
|
+
resolve(...paths) {
|
|
51
|
+
return p.resolve(...paths);
|
|
52
|
+
}
|
|
53
|
+
dirname(file) {
|
|
54
|
+
return p.dirname(file);
|
|
55
|
+
}
|
|
56
|
+
join(basePath, ...paths) {
|
|
57
|
+
return p.join(basePath, ...paths);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.ParseConfigHost = ParseConfigHost;
|
|
61
|
+
//# sourceMappingURL=parse-config-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-config-service.js","sourceRoot":"","sources":["../../src/language-service/parse-config-service.ts"],"names":[],"mappings":";;;;AAAA,qDAA+B;AAU/B;;;;;;GAMG;AACH,MAAa,eAAe;IAC3B,YAA6B,UAAgC;QAAhC,eAAU,GAAV,UAAU,CAAsB;IAAG,CAAC;IAEjE,MAAM,CAAC,IAAoB;QAC1B,OAAO,CACN,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,IAAI,CAAC,CACzE,CAAC;IACH,CAAC;IACD,QAAQ,CAAC,IAAoB;QAC5B,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC/C,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CACd,yDAAyD,IAAI,EAAE,CAC/D,CAAC;QACH,CAAC;QACD,OAAO,OAAO,CAAC;IAChB,CAAC;IACD,KAAK,CAAC,IAAoB;QACzB,OAAO;YACN,MAAM,EAAE,GAAG,EAAE;gBACZ,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;YACzC,CAAC;YACD,WAAW,EAAE,GAAG,EAAE;gBACjB,OAAO,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;YAC9C,CAAC;YACD,cAAc,EAAE,GAAG,EAAE;gBACpB,MAAM,IAAI,KAAK,CACd,wDAAwD,CACxD,CAAC;YACH,CAAC;SACD,CAAC;IACH,CAAC;IAED,OAAO,CAAC,IAAoB;QAC3B,OAAO,IAAI,CAAC,UAAU,CAAC,aAAa,CACnC,IAAI,EACJ,SAAS,EACT,SAAS,EACT,SAAS;QACT,WAAW,CAAC,CAAC,CACI,CAAC;IACpB,CAAC;IAED,GAAG;QACF,OAAO,IAAI,CAAC,UAAU,CAAC,mBAAmB,EAAoB,CAAC;IAChE,CAAC;IAED,OAAO,CAAC,IAAkC;QACzC,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAED,OAAO,CAAC,GAAG,KAAe;QACzB,OAAO,CAAC,CAAC,OAAO,CAAC,GAAG,KAAK,CAAmB,CAAC;IAC9C,CAAC;IAED,OAAO,CAAuB,IAAO;QACpC,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,CAAM,CAAC;IAC7B,CAAC;IAED,IAAI,CAAuB,QAAW,EAAE,GAAG,KAAe;QACzD,OAAO,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,KAAK,CAAM,CAAC;IACxC,CAAC;CACD;AA9DD,0CA8DC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
export type PathString = string | AbsoluteFsPath | PathSegment;
|
|
2
|
+
/**
|
|
3
|
+
* A `string` representing a specific type of path, with a particular brand `B`.
|
|
4
|
+
*
|
|
5
|
+
* A `string` is not assignable to a `BrandedPath`, but a `BrandedPath` is assignable to a `string`.
|
|
6
|
+
* Two `BrandedPath`s with different brands are not mutually assignable.
|
|
7
|
+
*/
|
|
8
|
+
export type BrandedPath<B extends string> = string & {
|
|
9
|
+
_brand: B;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* A fully qualified path in the file system, in POSIX form.
|
|
13
|
+
*/
|
|
14
|
+
export type AbsoluteFsPath = BrandedPath<"AbsoluteFsPath">;
|
|
15
|
+
/**
|
|
16
|
+
* A path that's relative to another (unspecified) root.
|
|
17
|
+
*
|
|
18
|
+
* This does not necessarily have to refer to a physical file.
|
|
19
|
+
*/
|
|
20
|
+
export type PathSegment = BrandedPath<"PathSegment">;
|
|
21
|
+
/**
|
|
22
|
+
* An abstraction over the path manipulation aspects of a file-system.
|
|
23
|
+
*/
|
|
24
|
+
export interface PathManipulation {
|
|
25
|
+
extname(path: AbsoluteFsPath | PathSegment): string;
|
|
26
|
+
isRoot(path: AbsoluteFsPath): boolean;
|
|
27
|
+
isRooted(path: string): boolean;
|
|
28
|
+
dirname<T extends PathString>(file: T): T;
|
|
29
|
+
extname(path: AbsoluteFsPath | PathSegment): string;
|
|
30
|
+
join<T extends PathString>(basePath: T, ...paths: string[]): T;
|
|
31
|
+
/**
|
|
32
|
+
* Compute the relative path between `from` and `to`.
|
|
33
|
+
*
|
|
34
|
+
* In file-systems that can have multiple file trees the returned path may not actually be
|
|
35
|
+
* "relative" (i.e. `PathSegment`). For example, Windows can have multiple drives :
|
|
36
|
+
* `relative('c:/a/b', 'd:/a/c')` would be `d:/a/c'.
|
|
37
|
+
*/
|
|
38
|
+
relative<T extends PathString>(from: T, to: T): PathSegment | AbsoluteFsPath;
|
|
39
|
+
basename(filePath: string, extension?: string): PathSegment;
|
|
40
|
+
normalize<T extends PathString>(path: T): T;
|
|
41
|
+
resolve(...paths: string[]): AbsoluteFsPath;
|
|
42
|
+
pwd(): AbsoluteFsPath;
|
|
43
|
+
chdir(path: AbsoluteFsPath): void;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* An abstraction over the read-only aspects of a file-system.
|
|
47
|
+
*/
|
|
48
|
+
export interface ReadonlyFileSystem extends PathManipulation {
|
|
49
|
+
isCaseSensitive(): boolean;
|
|
50
|
+
exists(path: AbsoluteFsPath): boolean;
|
|
51
|
+
readFile(path: AbsoluteFsPath): string;
|
|
52
|
+
readFileBuffer(path: AbsoluteFsPath): Uint8Array;
|
|
53
|
+
readdir(path: AbsoluteFsPath): PathSegment[];
|
|
54
|
+
lstat(path: AbsoluteFsPath): FileStats;
|
|
55
|
+
stat(path: AbsoluteFsPath): FileStats;
|
|
56
|
+
realpath(filePath: AbsoluteFsPath): AbsoluteFsPath;
|
|
57
|
+
getDefaultLibLocation(): AbsoluteFsPath;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A basic interface to abstract the underlying file-system.
|
|
61
|
+
*
|
|
62
|
+
* This makes it easier to provide mock file-systems in unit tests,
|
|
63
|
+
* but also to create clever file-systems that have features such as caching.
|
|
64
|
+
*/
|
|
65
|
+
export interface FileSystem extends ReadonlyFileSystem {
|
|
66
|
+
writeFile(path: AbsoluteFsPath, data: string | Uint8Array, exclusive?: boolean): void;
|
|
67
|
+
removeFile(path: AbsoluteFsPath): void;
|
|
68
|
+
symlink(target: AbsoluteFsPath, path: AbsoluteFsPath): void;
|
|
69
|
+
copyFile(from: AbsoluteFsPath, to: AbsoluteFsPath): void;
|
|
70
|
+
moveFile(from: AbsoluteFsPath, to: AbsoluteFsPath): void;
|
|
71
|
+
ensureDir(path: AbsoluteFsPath): void;
|
|
72
|
+
removeDeep(path: AbsoluteFsPath): void;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Information about an object in the FileSystem.
|
|
76
|
+
* This is analogous to the `fs.Stats` class in Node.js.
|
|
77
|
+
*/
|
|
78
|
+
export interface FileStats {
|
|
79
|
+
isFile(): boolean;
|
|
80
|
+
isDirectory(): boolean;
|
|
81
|
+
isSymbolicLink(): boolean;
|
|
82
|
+
}
|
|
83
|
+
/** Used to read configuration files. */
|
|
84
|
+
export type ConfigurationHost = Pick<ReadonlyFileSystem, "readFile" | "exists" | "lstat" | "resolve" | "join" | "dirname" | "extname" | "pwd" | "readdir">;
|
|
85
|
+
export type CompilerOptions = {
|
|
86
|
+
debug: boolean;
|
|
87
|
+
logPath: string;
|
|
88
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/language-service/types.ts"],"names":[],"mappings":""}
|
package/dist/logger.d.ts
ADDED
package/dist/logger.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Logger = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs = tslib_1.__importStar(require("node:fs"));
|
|
6
|
+
class Logger {
|
|
7
|
+
constructor(options) {
|
|
8
|
+
this.options = options;
|
|
9
|
+
}
|
|
10
|
+
log(message) {
|
|
11
|
+
if (!this.options.debug) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const logMessage = `${message}\n`;
|
|
15
|
+
fs.appendFileSync(this.options.logPath, logMessage, { encoding: "utf8" });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.Logger = Logger;
|
|
19
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;;;AAAA,oDAA8B;AAE9B,MAAa,MAAM;IAClB,YAA6B,OAA4C;QAA5C,YAAO,GAAP,OAAO,CAAqC;IAAG,CAAC;IAE7E,GAAG,CAAC,OAAe;QAClB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YACzB,OAAO;QACR,CAAC;QAED,MAAM,UAAU,GAAG,GAAG,OAAO,IAAI,CAAC;QAClC,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;IAC3E,CAAC;CACD;AAXD,wBAWC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type * as ts from "typescript/lib/tsserverlibrary";
|
|
2
|
+
import type { Logger } from "../logger";
|
|
3
|
+
export type InjectParameterDeclaration = {
|
|
4
|
+
name: ts.Identifier | ts.StringLiteral;
|
|
5
|
+
location: "constructor" | "property";
|
|
6
|
+
declaration: ts.ParameterDeclaration;
|
|
7
|
+
start: number;
|
|
8
|
+
end: number;
|
|
9
|
+
length: number;
|
|
10
|
+
parameterName: string;
|
|
11
|
+
parameterType?: ts.TypeReferenceType | ts.Node;
|
|
12
|
+
};
|
|
13
|
+
export declare class InjectParser {
|
|
14
|
+
static execute(classDeclaration: ts.ClassDeclaration, logger: Logger): InjectParameterDeclaration[];
|
|
15
|
+
private static getParameterTypeNode;
|
|
16
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InjectParser = void 0;
|
|
4
|
+
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
5
|
+
// biome-ignore lint/complexity/noStaticOnlyClass: <explanation>
|
|
6
|
+
class InjectParser {
|
|
7
|
+
static execute(classDeclaration, logger) {
|
|
8
|
+
const params = [];
|
|
9
|
+
logger.log(`[InjectParser][execute] ${classDeclaration.getText()}`);
|
|
10
|
+
const injectConstructorParams = tsquery_1.tsquery.query(classDeclaration, `Constructor > Parameter:has(Decorator > CallExpression > Identifier[name="Inject"])`);
|
|
11
|
+
for (const injectConstructorParam of injectConstructorParams) {
|
|
12
|
+
const [dependencyStringName] = tsquery_1.tsquery.query(injectConstructorParam, "Decorator > CallExpression StringLiteral") || [];
|
|
13
|
+
const [dependencyLink] = tsquery_1.tsquery.query(injectConstructorParam, "Decorator > CallExpression Identifier:not([name='Inject'])") || [];
|
|
14
|
+
const dependencyName = dependencyStringName || dependencyLink;
|
|
15
|
+
if (!dependencyName) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
const start = injectConstructorParam.getStart();
|
|
19
|
+
const end = injectConstructorParam.getEnd();
|
|
20
|
+
const parameterName = injectConstructorParam.name.getText();
|
|
21
|
+
const parameterType = InjectParser.getParameterTypeNode(injectConstructorParam);
|
|
22
|
+
params.push({
|
|
23
|
+
name: dependencyName,
|
|
24
|
+
location: "constructor",
|
|
25
|
+
declaration: injectConstructorParam,
|
|
26
|
+
start,
|
|
27
|
+
end,
|
|
28
|
+
length: end - start,
|
|
29
|
+
parameterName,
|
|
30
|
+
parameterType,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
// const injectPropertyParams = tsquery.query<ts.PropertyDeclaration>(
|
|
34
|
+
// classDeclaration,
|
|
35
|
+
// selectorInjectProperty,
|
|
36
|
+
// );
|
|
37
|
+
return params;
|
|
38
|
+
}
|
|
39
|
+
static getParameterTypeNode(param) {
|
|
40
|
+
return param.type;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.InjectParser = InjectParser;
|
|
44
|
+
//# sourceMappingURL=inject.parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject.parser.js","sourceRoot":"","sources":["../../src/parsers/inject.parser.ts"],"names":[],"mappings":";;;AAAA,uDAAoD;AAepD,gEAAgE;AAChE,MAAa,YAAY;IACjB,MAAM,CAAC,OAAO,CAAC,gBAAqC,EAAE,MAAc;QAC1E,MAAM,MAAM,GAAiC,EAAE,CAAC;QAChD,MAAM,CAAC,GAAG,CAAC,2BAA2B,gBAAgB,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACpE,MAAM,uBAAuB,GAAG,iBAAO,CAAC,KAAK,CAC5C,gBAAgB,EAChB,qFAAqF,CACrF,CAAC;QAEF,KAAK,MAAM,sBAAsB,IAAI,uBAAuB,EAAE,CAAC;YAC9D,MAAM,CAAC,oBAAoB,CAAC,GAC3B,iBAAO,CAAC,KAAK,CACZ,sBAAsB,EACtB,0CAA0C,CAC1C,IAAI,EAAE,CAAC;YACT,MAAM,CAAC,cAAc,CAAC,GACrB,iBAAO,CAAC,KAAK,CACZ,sBAAsB,EACtB,4DAA4D,CAC5D,IAAI,EAAE,CAAC;YAET,MAAM,cAAc,GAAG,oBAAoB,IAAI,cAAc,CAAC;YAE9D,IAAI,CAAC,cAAc,EAAE,CAAC;gBACrB,SAAS;YACV,CAAC;YAED,MAAM,KAAK,GAAG,sBAAsB,CAAC,QAAQ,EAAE,CAAC;YAChD,MAAM,GAAG,GAAG,sBAAsB,CAAC,MAAM,EAAE,CAAC;YAC5C,MAAM,aAAa,GAAG,sBAAsB,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAC5D,MAAM,aAAa,GAAG,YAAY,CAAC,oBAAoB,CACtD,sBAAsB,CACtB,CAAC;YAEF,MAAM,CAAC,IAAI,CAAC;gBACX,IAAI,EAAE,cAAc;gBACpB,QAAQ,EAAE,aAAa;gBACvB,WAAW,EAAE,sBAAsB;gBACnC,KAAK;gBACL,GAAG;gBACH,MAAM,EAAE,GAAG,GAAG,KAAK;gBACnB,aAAa;gBACb,aAAa;aACb,CAAC,CAAC;QACJ,CAAC;QAED,sEAAsE;QACtE,qBAAqB;QACrB,2BAA2B;QAC3B,KAAK;QAEL,OAAO,MAAM,CAAC;IACf,CAAC;IAEO,MAAM,CAAC,oBAAoB,CAAC,KAA8B;QACjE,OAAO,KAAK,CAAC,IAAI,CAAC;IACnB,CAAC;CACD;AAzDD,oCAyDC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InjectableParser = void 0;
|
|
4
|
+
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
5
|
+
const selector = `ClassDeclaration:has(Decorator > CallExpression > Identifier[name="Injectable"])`;
|
|
6
|
+
// biome-ignore lint/complexity/noStaticOnlyClass: <explanation>
|
|
7
|
+
class InjectableParser {
|
|
8
|
+
static execute(sourceFile) {
|
|
9
|
+
return tsquery_1.tsquery.query(sourceFile, selector);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.InjectableParser = InjectableParser;
|
|
13
|
+
//# sourceMappingURL=injectable.parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injectable.parser.js","sourceRoot":"","sources":["../../src/parsers/injectable.parser.ts"],"names":[],"mappings":";;;AAAA,uDAAqE;AAGrE,MAAM,QAAQ,GAAG,kFAAkF,CAAC;AAEpG,gEAAgE;AAChE,MAAa,gBAAgB;IACrB,MAAM,CAAC,OAAO,CAAC,UAAsB;QAC3C,OAAO,iBAAO,CAAC,KAAK,CAAsB,UAAU,EAAE,QAAQ,CAAC,CAAC;IACjE,CAAC;CACD;AAJD,4CAIC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as ts from "typescript/lib/tsserverlibrary";
|
|
2
|
+
import type { Logger } from "../logger";
|
|
3
|
+
export type ProviderType = {
|
|
4
|
+
provide: ts.Expression | ts.StringLiteral;
|
|
5
|
+
provideType: "class" | "useClass" | "useValue" | "useFactory";
|
|
6
|
+
declaration: ts.Expression | ts.Identifier;
|
|
7
|
+
start: number;
|
|
8
|
+
end: number;
|
|
9
|
+
length: number;
|
|
10
|
+
};
|
|
11
|
+
export type ImportType = {
|
|
12
|
+
importType: "local" | "feature" | "global";
|
|
13
|
+
declaration: ts.Expression;
|
|
14
|
+
start: number;
|
|
15
|
+
end: number;
|
|
16
|
+
length: number;
|
|
17
|
+
};
|
|
18
|
+
export type ExportType = {
|
|
19
|
+
name?: string;
|
|
20
|
+
scope: "internal" | "external";
|
|
21
|
+
declaration: ts.Identifier | ts.StringLiteral;
|
|
22
|
+
start: number;
|
|
23
|
+
end: number;
|
|
24
|
+
length: number;
|
|
25
|
+
illegal: boolean;
|
|
26
|
+
};
|
|
27
|
+
export type NsModuleDeclaration = {
|
|
28
|
+
moduleName: string;
|
|
29
|
+
providers: ProviderType[];
|
|
30
|
+
imports: ImportType[];
|
|
31
|
+
exports: ExportType[];
|
|
32
|
+
start: number;
|
|
33
|
+
end: number;
|
|
34
|
+
length: number;
|
|
35
|
+
sourceFile: ts.SourceFile;
|
|
36
|
+
};
|
|
37
|
+
export declare class NsModuleParser {
|
|
38
|
+
static execute(modules: ts.ClassDeclaration[], typeChecker: ts.TypeChecker, logger: Logger): NsModuleDeclaration[];
|
|
39
|
+
private static getNsModuleName;
|
|
40
|
+
private static getNsModuleDecoratorValue;
|
|
41
|
+
private static parseImports;
|
|
42
|
+
private static parseExports;
|
|
43
|
+
private static parseProviders;
|
|
44
|
+
private static parseUseProvider;
|
|
45
|
+
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NsModuleParser = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
6
|
+
const ts = tslib_1.__importStar(require("typescript/lib/tsserverlibrary"));
|
|
7
|
+
const findPropertyInObject = (obj, key) => obj.properties.find((property) => {
|
|
8
|
+
return obj.properties.find((property) => {
|
|
9
|
+
if (ts.isPropertyAssignment(property) && ts.isIdentifier(property.name)) {
|
|
10
|
+
return property.name.text === key;
|
|
11
|
+
}
|
|
12
|
+
if (ts.isMethodDeclaration(property) && ts.isIdentifier(property.name)) {
|
|
13
|
+
return property.name.text === key;
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
// biome-ignore lint/complexity/noStaticOnlyClass: <explanation>
|
|
19
|
+
class NsModuleParser {
|
|
20
|
+
static execute(modules, typeChecker, logger) {
|
|
21
|
+
const result = [];
|
|
22
|
+
for (const module of modules) {
|
|
23
|
+
const moduleName = NsModuleParser.getNsModuleName(module);
|
|
24
|
+
if (!NsModuleParser) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const start = module.getStart();
|
|
28
|
+
const end = module.getEnd();
|
|
29
|
+
const length = end - start;
|
|
30
|
+
const { providers, imports, exports } = NsModuleParser.getNsModuleDecoratorValue(module, typeChecker, logger);
|
|
31
|
+
const sourceFile = module.getSourceFile();
|
|
32
|
+
result.push({
|
|
33
|
+
moduleName,
|
|
34
|
+
providers,
|
|
35
|
+
imports,
|
|
36
|
+
exports,
|
|
37
|
+
start,
|
|
38
|
+
end,
|
|
39
|
+
length,
|
|
40
|
+
sourceFile,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
static getNsModuleName(classDeclaration) {
|
|
46
|
+
return classDeclaration.name?.getText();
|
|
47
|
+
}
|
|
48
|
+
static getNsModuleDecoratorValue(classDeclaration, typeChecker, logger) {
|
|
49
|
+
const [decoratorValue] = tsquery_1.tsquery.query(classDeclaration, `CallExpression:has(Identifier[name="NsModule"]) > ObjectLiteralExpression`) || [];
|
|
50
|
+
const providersRaw = decoratorValue.properties.find((item) => item.name?.getText() === "providers");
|
|
51
|
+
const importsRaw = decoratorValue.properties.find((item) => item.name?.getText() === "imports");
|
|
52
|
+
const exportsRaw = decoratorValue.properties.find((item) => item.name?.getText() === "exports");
|
|
53
|
+
const providers = providersRaw?.initializer
|
|
54
|
+
? NsModuleParser.parseProviders(providersRaw.initializer, logger)
|
|
55
|
+
: [];
|
|
56
|
+
const imports = importsRaw?.initializer
|
|
57
|
+
? NsModuleParser.parseImports(importsRaw.initializer, logger)
|
|
58
|
+
: [];
|
|
59
|
+
const exports = exportsRaw?.initializer
|
|
60
|
+
? NsModuleParser.parseExports(exportsRaw.initializer, providers, typeChecker, logger)
|
|
61
|
+
: [];
|
|
62
|
+
return {
|
|
63
|
+
imports,
|
|
64
|
+
exports,
|
|
65
|
+
providers,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
static parseImports(imports, logger) {
|
|
69
|
+
const result = [];
|
|
70
|
+
imports.forEachChild((child) => {
|
|
71
|
+
if (ts.isIdentifier(child) || ts.isCallExpression(child)) {
|
|
72
|
+
const start = child.getStart();
|
|
73
|
+
const end = child.getEnd();
|
|
74
|
+
const length = end - start;
|
|
75
|
+
let importType = null;
|
|
76
|
+
let type = ts.isIdentifier(child) ? child : null;
|
|
77
|
+
if (ts.isIdentifier(child)) {
|
|
78
|
+
importType = "local";
|
|
79
|
+
}
|
|
80
|
+
else if (ts.isCallExpression(child)) {
|
|
81
|
+
const [typeNode] = (0, tsquery_1.tsquery)(child, "PropertyAccessExpression Identifier");
|
|
82
|
+
type = typeNode;
|
|
83
|
+
const isFeature = Boolean((0, tsquery_1.tsquery)(child, `PropertyAccessExpression Identifier[name="forFeature"]`)?.length);
|
|
84
|
+
const isRoot = Boolean((0, tsquery_1.tsquery)(child, `PropertyAccessExpression Identifier[name="forRoot"]`)?.length);
|
|
85
|
+
if (isFeature) {
|
|
86
|
+
importType = "feature";
|
|
87
|
+
}
|
|
88
|
+
else if (isRoot) {
|
|
89
|
+
importType = "global";
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (!importType || !type) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
result.push({
|
|
96
|
+
importType,
|
|
97
|
+
start,
|
|
98
|
+
end,
|
|
99
|
+
length,
|
|
100
|
+
declaration: type,
|
|
101
|
+
});
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
static parseExports(exports, providers, typeChecker, logger) {
|
|
108
|
+
const result = [];
|
|
109
|
+
exports.forEachChild((child) => {
|
|
110
|
+
if (ts.isIdentifier(child)) {
|
|
111
|
+
const type = child;
|
|
112
|
+
const start = child.getStart();
|
|
113
|
+
const end = child.getEnd();
|
|
114
|
+
const length = end - start;
|
|
115
|
+
let importType = "external";
|
|
116
|
+
for (const provider of providers) {
|
|
117
|
+
const type1 = typeChecker.getTypeAtLocation(provider.declaration);
|
|
118
|
+
const type2 = typeChecker.getTypeAtLocation(type);
|
|
119
|
+
if (typeChecker.isTypeAssignableTo(type1, type2) &&
|
|
120
|
+
typeChecker.isTypeAssignableTo(type2, type1)) {
|
|
121
|
+
importType = "internal";
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
result.push({
|
|
125
|
+
scope: importType,
|
|
126
|
+
declaration: type,
|
|
127
|
+
start,
|
|
128
|
+
end,
|
|
129
|
+
length,
|
|
130
|
+
illegal: false,
|
|
131
|
+
});
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (ts.isStringLiteral(child)) {
|
|
135
|
+
const type = child;
|
|
136
|
+
const start = child.getStart();
|
|
137
|
+
const end = child.getEnd();
|
|
138
|
+
const length = end - start;
|
|
139
|
+
let depType = "external";
|
|
140
|
+
for (const provider of providers) {
|
|
141
|
+
if (provider.provide?.getText() === type.text) {
|
|
142
|
+
depType = "internal";
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
result.push({
|
|
146
|
+
name: type.getText(),
|
|
147
|
+
scope: depType,
|
|
148
|
+
start,
|
|
149
|
+
end,
|
|
150
|
+
length,
|
|
151
|
+
declaration: type,
|
|
152
|
+
illegal: depType === "external",
|
|
153
|
+
});
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
static parseProviders(providers, logger) {
|
|
160
|
+
const result = [];
|
|
161
|
+
providers.forEachChild((child) => {
|
|
162
|
+
if (ts.isIdentifier(child)) {
|
|
163
|
+
const start = child.getStart();
|
|
164
|
+
const end = child.getEnd();
|
|
165
|
+
const length = end - start;
|
|
166
|
+
result.push({
|
|
167
|
+
provide: child,
|
|
168
|
+
provideType: "class",
|
|
169
|
+
start,
|
|
170
|
+
end,
|
|
171
|
+
length,
|
|
172
|
+
declaration: child,
|
|
173
|
+
});
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
if (ts.isObjectLiteralExpression(child)) {
|
|
177
|
+
const provider = NsModuleParser.parseUseProvider(child, logger);
|
|
178
|
+
if (provider) {
|
|
179
|
+
result.push(provider);
|
|
180
|
+
}
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
static parseUseProvider(provider, logger) {
|
|
187
|
+
const provideNameNode = findPropertyInObject(provider, "provide");
|
|
188
|
+
const provideUseClassNode = findPropertyInObject(provider, "useClass");
|
|
189
|
+
const provideUseValueNode = findPropertyInObject(provider, "useValue");
|
|
190
|
+
const provideUseFactoryNode = findPropertyInObject(provider, "useFactory");
|
|
191
|
+
const providerNode = provideUseClassNode || provideUseValueNode || provideUseFactoryNode;
|
|
192
|
+
if (!provideNameNode || !providerNode) {
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
let provide = null;
|
|
196
|
+
if (ts.isPropertyAssignment(provideNameNode) &&
|
|
197
|
+
ts.isStringLiteral(provideNameNode.initializer)) {
|
|
198
|
+
provide = provideNameNode.initializer;
|
|
199
|
+
}
|
|
200
|
+
else if (ts.isPropertyAssignment(provideNameNode) &&
|
|
201
|
+
ts.isExpression(provideNameNode.initializer)) {
|
|
202
|
+
provide = provideNameNode.initializer;
|
|
203
|
+
}
|
|
204
|
+
const providerTypeLink = ts.isPropertyAssignment(providerNode)
|
|
205
|
+
? providerNode.initializer
|
|
206
|
+
: null;
|
|
207
|
+
if (!provide || !providerTypeLink) {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
const start = provideNameNode.getStart();
|
|
211
|
+
const end = provideNameNode.getEnd();
|
|
212
|
+
const length = end - start;
|
|
213
|
+
let provideType = null;
|
|
214
|
+
if (provideUseClassNode) {
|
|
215
|
+
provideType = "useClass";
|
|
216
|
+
}
|
|
217
|
+
else if (provideUseValueNode) {
|
|
218
|
+
provideType = "useValue";
|
|
219
|
+
}
|
|
220
|
+
else if (provideUseFactoryNode) {
|
|
221
|
+
provideType = "useFactory";
|
|
222
|
+
}
|
|
223
|
+
if (!provideType) {
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
return {
|
|
227
|
+
provide,
|
|
228
|
+
provideType,
|
|
229
|
+
declaration: providerTypeLink,
|
|
230
|
+
start,
|
|
231
|
+
end,
|
|
232
|
+
length,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
exports.NsModuleParser = NsModuleParser;
|
|
237
|
+
//# sourceMappingURL=ns-module.parser.js.map
|