@eventra_dev/eventra-cli 0.1.5 → 0.1.6
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.
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.resolveExportedSymbol = resolveExportedSymbol;
|
|
7
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
8
|
+
function resolveExportedSymbol(symbol, checker, visited = new Set()) {
|
|
9
|
+
if (visited.has(symbol))
|
|
10
|
+
return null;
|
|
11
|
+
visited.add(symbol);
|
|
12
|
+
if (symbol.flags & typescript_1.default.SymbolFlags.Alias) {
|
|
13
|
+
const aliased = checker.getAliasedSymbol(symbol);
|
|
14
|
+
return resolveExportedSymbol(aliased, checker, visited);
|
|
15
|
+
}
|
|
16
|
+
if (symbol.getDeclarations()?.length) {
|
|
17
|
+
return symbol;
|
|
18
|
+
}
|
|
19
|
+
const declarations = symbol.getDeclarations() ?? [];
|
|
20
|
+
for (const decl of declarations) {
|
|
21
|
+
const source = decl.getSourceFile();
|
|
22
|
+
const moduleSymbol = checker.getSymbolAtLocation(source);
|
|
23
|
+
if (!moduleSymbol)
|
|
24
|
+
continue;
|
|
25
|
+
const exports = checker.getExportsOfModule(moduleSymbol);
|
|
26
|
+
for (const exp of exports) {
|
|
27
|
+
const resolved = resolveExportedSymbol(exp, checker, visited);
|
|
28
|
+
if (resolved?.getDeclarations()?.length) {
|
|
29
|
+
return resolved;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return symbol;
|
|
34
|
+
}
|
|
@@ -43,7 +43,9 @@ class TSService {
|
|
|
43
43
|
}
|
|
44
44
|
this.compilerOptions = compilerOptions;
|
|
45
45
|
const host = {
|
|
46
|
-
getScriptFileNames: () =>
|
|
46
|
+
getScriptFileNames: () => {
|
|
47
|
+
return [...new Set(this.fileNames)].sort((a, b) => a.localeCompare(b));
|
|
48
|
+
},
|
|
47
49
|
getScriptVersion: (file) => this.files.get(file)?.version.toString() ?? "0",
|
|
48
50
|
getScriptSnapshot: (file) => {
|
|
49
51
|
const f = this.files.get(file);
|
package/dist/engine/resolver.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.resolveNodeValue = resolveNodeValue;
|
|
7
7
|
const typescript_1 = __importDefault(require("typescript"));
|
|
8
|
+
const exportResolver_1 = require("./exportResolver");
|
|
8
9
|
function resolveNodeValue(node, checker, paramMap, seen = new Set()) {
|
|
9
10
|
if (seen.has(node))
|
|
10
11
|
return null;
|
|
@@ -36,6 +37,7 @@ function resolveNodeValue(node, checker, paramMap, seen = new Set()) {
|
|
|
36
37
|
let symbol = checker.getSymbolAtLocation(node);
|
|
37
38
|
if (!symbol)
|
|
38
39
|
return null;
|
|
40
|
+
symbol = (0, exportResolver_1.resolveExportedSymbol)(symbol, checker) ?? symbol;
|
|
39
41
|
if (symbol.flags & typescript_1.default.SymbolFlags.Alias) {
|
|
40
42
|
symbol = checker.getAliasedSymbol(symbol);
|
|
41
43
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export function resolveExportedSymbol(
|
|
4
|
+
symbol: ts.Symbol,
|
|
5
|
+
checker: ts.TypeChecker,
|
|
6
|
+
visited = new Set<ts.Symbol>()
|
|
7
|
+
): ts.Symbol | null {
|
|
8
|
+
|
|
9
|
+
if (visited.has(symbol)) return null;
|
|
10
|
+
visited.add(symbol);
|
|
11
|
+
if (symbol.flags & ts.SymbolFlags.Alias) {
|
|
12
|
+
const aliased = checker.getAliasedSymbol(symbol);
|
|
13
|
+
return resolveExportedSymbol(aliased, checker, visited);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (symbol.getDeclarations()?.length) {
|
|
17
|
+
return symbol;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const declarations = symbol.getDeclarations() ?? [];
|
|
21
|
+
|
|
22
|
+
for (const decl of declarations) {
|
|
23
|
+
const source = decl.getSourceFile();
|
|
24
|
+
const moduleSymbol = checker.getSymbolAtLocation(source);
|
|
25
|
+
|
|
26
|
+
if (!moduleSymbol) continue;
|
|
27
|
+
|
|
28
|
+
const exports = checker.getExportsOfModule(moduleSymbol);
|
|
29
|
+
|
|
30
|
+
for (const exp of exports) {
|
|
31
|
+
const resolved = resolveExportedSymbol(exp, checker, visited);
|
|
32
|
+
if (resolved?.getDeclarations()?.length) {
|
|
33
|
+
return resolved;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return symbol;
|
|
39
|
+
}
|
|
@@ -52,7 +52,11 @@ export class TSService {
|
|
|
52
52
|
this.compilerOptions = compilerOptions;
|
|
53
53
|
|
|
54
54
|
const host: ts.LanguageServiceHost = {
|
|
55
|
-
getScriptFileNames: () =>
|
|
55
|
+
getScriptFileNames: () => {
|
|
56
|
+
return [...new Set(this.fileNames)].sort((a, b) =>
|
|
57
|
+
a.localeCompare(b)
|
|
58
|
+
);
|
|
59
|
+
},
|
|
56
60
|
|
|
57
61
|
getScriptVersion: (file) =>
|
|
58
62
|
this.files.get(file)?.version.toString() ?? "0",
|
package/src/engine/resolver.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
|
+
import {resolveExportedSymbol} from "./exportResolver";
|
|
2
3
|
|
|
3
4
|
export type ResolveResult = {
|
|
4
5
|
values: string[];
|
|
@@ -53,6 +54,8 @@ export function resolveNodeValue(
|
|
|
53
54
|
let symbol = checker.getSymbolAtLocation(node);
|
|
54
55
|
if (!symbol) return null;
|
|
55
56
|
|
|
57
|
+
symbol = resolveExportedSymbol(symbol, checker) ?? symbol;
|
|
58
|
+
|
|
56
59
|
if (symbol.flags & ts.SymbolFlags.Alias) {
|
|
57
60
|
symbol = checker.getAliasedSymbol(symbol);
|
|
58
61
|
}
|