@esportsplus/typescript 0.27.3 → 0.27.4
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/build/compiler/imports.js +36 -12
- package/package.json +1 -1
- package/src/compiler/imports.ts +52 -24
|
@@ -23,6 +23,12 @@ const all = (file, pkg) => {
|
|
|
23
23
|
return imports;
|
|
24
24
|
};
|
|
25
25
|
const includes = (checker, node, pkg, symbolName) => {
|
|
26
|
+
if (!ts.isIdentifier(node)) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
if (symbolName && node.text !== symbolName) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
26
32
|
let file = node.getSourceFile(), imports = cache.get(file);
|
|
27
33
|
if (!imports) {
|
|
28
34
|
imports = new Map();
|
|
@@ -39,17 +45,8 @@ const includes = (checker, node, pkg, symbolName) => {
|
|
|
39
45
|
}
|
|
40
46
|
imports.set(pkg, names);
|
|
41
47
|
}
|
|
42
|
-
if (names.
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
if (ts.isIdentifier(node)) {
|
|
46
|
-
if (!names.has(node.text)) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
if (symbolName && node.text !== symbolName) {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
let symbol = checker.getSymbolAtLocation(node);
|
|
48
|
+
if (names.has(node.text)) {
|
|
49
|
+
let symbol = checker?.getSymbolAtLocation(node);
|
|
53
50
|
if (symbol) {
|
|
54
51
|
let declarations = symbol.getDeclarations();
|
|
55
52
|
if (declarations && declarations.length > 0) {
|
|
@@ -67,11 +64,38 @@ const includes = (checker, node, pkg, symbolName) => {
|
|
|
67
64
|
return true;
|
|
68
65
|
}
|
|
69
66
|
}
|
|
70
|
-
return false;
|
|
71
67
|
}
|
|
72
68
|
}
|
|
73
69
|
return true;
|
|
74
70
|
}
|
|
71
|
+
let symbol = checker?.getSymbolAtLocation(node);
|
|
72
|
+
if (!symbol) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
let declarations = symbol.getDeclarations();
|
|
76
|
+
if (declarations && declarations.length > 0) {
|
|
77
|
+
for (let i = 0, n = declarations.length; i < n; i++) {
|
|
78
|
+
let decl = declarations[i];
|
|
79
|
+
if (decl.getSourceFile().fileName.includes(pkg)) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
let aliased = checker.getAliasedSymbol(symbol);
|
|
86
|
+
if (aliased && aliased !== symbol) {
|
|
87
|
+
let aliasedDecls = aliased.getDeclarations();
|
|
88
|
+
if (aliasedDecls) {
|
|
89
|
+
for (let i = 0, n = aliasedDecls.length; i < n; i++) {
|
|
90
|
+
if (aliasedDecls[i].getSourceFile().fileName.includes(pkg)) {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
}
|
|
75
99
|
return false;
|
|
76
100
|
};
|
|
77
101
|
export default { all, includes };
|
package/package.json
CHANGED
package/src/compiler/imports.ts
CHANGED
|
@@ -55,6 +55,14 @@ const all = (file: ts.SourceFile, pkg: string): ImportInfo[] => {
|
|
|
55
55
|
|
|
56
56
|
// Check if node's symbol originates from a specific package (with optional symbol name validation)
|
|
57
57
|
const includes = (checker: ts.TypeChecker, node: ts.Node, pkg: string, symbolName?: string): boolean => {
|
|
58
|
+
if (!ts.isIdentifier(node)) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (symbolName && node.text !== symbolName) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
58
66
|
let file = node.getSourceFile(),
|
|
59
67
|
imports = cache.get(file);
|
|
60
68
|
|
|
@@ -79,33 +87,17 @@ const includes = (checker: ts.TypeChecker, node: ts.Node, pkg: string, symbolNam
|
|
|
79
87
|
imports.set(pkg, names);
|
|
80
88
|
}
|
|
81
89
|
|
|
82
|
-
//
|
|
83
|
-
if (names.
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// For identifiers, check if name matches an import AND verify via symbol
|
|
88
|
-
if (ts.isIdentifier(node)) {
|
|
89
|
-
if (!names.has(node.text)) {
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (symbolName && node.text !== symbolName) {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Try to verify via checker that this identifier refers to the import
|
|
98
|
-
let symbol = checker.getSymbolAtLocation(node);
|
|
90
|
+
// Fast path: direct import from package
|
|
91
|
+
if (names.has(node.text)) {
|
|
92
|
+
let symbol = checker?.getSymbolAtLocation(node);
|
|
99
93
|
|
|
100
94
|
if (symbol) {
|
|
101
|
-
// Check if the symbol's declaration is an import specifier from this package
|
|
102
95
|
let declarations = symbol.getDeclarations();
|
|
103
96
|
|
|
104
97
|
if (declarations && declarations.length > 0) {
|
|
105
98
|
for (let i = 0, n = declarations.length; i < n; i++) {
|
|
106
99
|
let decl = declarations[i];
|
|
107
100
|
|
|
108
|
-
// If declaration is an ImportSpecifier, check the import's module
|
|
109
101
|
if (ts.isImportSpecifier(decl)) {
|
|
110
102
|
let importDecl = decl.parent?.parent?.parent;
|
|
111
103
|
|
|
@@ -116,21 +108,57 @@ const includes = (checker: ts.TypeChecker, node: ts.Node, pkg: string, symbolNam
|
|
|
116
108
|
}
|
|
117
109
|
}
|
|
118
110
|
|
|
119
|
-
// Also check if declaration is from a file in the package
|
|
120
111
|
if (decl.getSourceFile().fileName.includes(pkg)) {
|
|
121
112
|
return true;
|
|
122
113
|
}
|
|
123
114
|
}
|
|
124
|
-
|
|
125
|
-
// Symbol resolved but doesn't match package - it's shadowed
|
|
126
|
-
return false;
|
|
127
115
|
}
|
|
128
116
|
}
|
|
129
117
|
|
|
130
|
-
//
|
|
118
|
+
// If checker failed but name matches direct import, trust it
|
|
131
119
|
return true;
|
|
132
120
|
}
|
|
133
121
|
|
|
122
|
+
// Slow path: check for re-exports via aliased symbol
|
|
123
|
+
let symbol = checker?.getSymbolAtLocation(node);
|
|
124
|
+
|
|
125
|
+
if (!symbol) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Check declarations
|
|
130
|
+
let declarations = symbol.getDeclarations();
|
|
131
|
+
|
|
132
|
+
if (declarations && declarations.length > 0) {
|
|
133
|
+
for (let i = 0, n = declarations.length; i < n; i++) {
|
|
134
|
+
let decl = declarations[i];
|
|
135
|
+
|
|
136
|
+
if (decl.getSourceFile().fileName.includes(pkg)) {
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Check aliased symbol for re-exports
|
|
143
|
+
try {
|
|
144
|
+
let aliased = checker.getAliasedSymbol(symbol);
|
|
145
|
+
|
|
146
|
+
if (aliased && aliased !== symbol) {
|
|
147
|
+
let aliasedDecls = aliased.getDeclarations();
|
|
148
|
+
|
|
149
|
+
if (aliasedDecls) {
|
|
150
|
+
for (let i = 0, n = aliasedDecls.length; i < n; i++) {
|
|
151
|
+
if (aliasedDecls[i].getSourceFile().fileName.includes(pkg)) {
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
// getAliasedSymbol can throw for non-alias symbols
|
|
160
|
+
}
|
|
161
|
+
|
|
134
162
|
return false;
|
|
135
163
|
};
|
|
136
164
|
|