@esportsplus/typescript 0.27.1 → 0.27.3
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.
|
@@ -28,41 +28,50 @@ const includes = (checker, node, pkg, symbolName) => {
|
|
|
28
28
|
imports = new Map();
|
|
29
29
|
cache.set(file, imports);
|
|
30
30
|
}
|
|
31
|
-
let
|
|
32
|
-
if (!
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
let names = imports.get(pkg);
|
|
32
|
+
if (!names) {
|
|
33
|
+
names = new Set();
|
|
34
|
+
let packages = all(file, pkg);
|
|
35
|
+
for (let i = 0, n = packages.length; i < n; i++) {
|
|
36
|
+
for (let [, localName] of packages[i].specifiers) {
|
|
37
|
+
names.add(localName);
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
|
-
imports.set(pkg,
|
|
40
|
+
imports.set(pkg, names);
|
|
40
41
|
}
|
|
41
|
-
if (
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
let symbol = checker.getSymbolAtLocation(node);
|
|
45
|
-
if (!symbol) {
|
|
46
|
-
if (ts.isIdentifier(node) && varnames.has(node.text)) {
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
42
|
+
if (names.size === 0) {
|
|
49
43
|
return false;
|
|
50
44
|
}
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
let declarations = symbol.getDeclarations();
|
|
58
|
-
if (!declarations || declarations.length === 0) {
|
|
59
|
-
return ts.isIdentifier(node) && varnames.has(node.text);
|
|
60
|
-
}
|
|
61
|
-
for (let i = 0, n = declarations.length; i < n; i++) {
|
|
62
|
-
if (declarations[i].getSourceFile().fileName.includes(pkg)) {
|
|
63
|
-
return true;
|
|
45
|
+
if (ts.isIdentifier(node)) {
|
|
46
|
+
if (!names.has(node.text)) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
if (symbolName && node.text !== symbolName) {
|
|
50
|
+
return false;
|
|
64
51
|
}
|
|
52
|
+
let symbol = checker.getSymbolAtLocation(node);
|
|
53
|
+
if (symbol) {
|
|
54
|
+
let declarations = symbol.getDeclarations();
|
|
55
|
+
if (declarations && declarations.length > 0) {
|
|
56
|
+
for (let i = 0, n = declarations.length; i < n; i++) {
|
|
57
|
+
let decl = declarations[i];
|
|
58
|
+
if (ts.isImportSpecifier(decl)) {
|
|
59
|
+
let importDecl = decl.parent?.parent?.parent;
|
|
60
|
+
if (importDecl && ts.isImportDeclaration(importDecl) && ts.isStringLiteral(importDecl.moduleSpecifier)) {
|
|
61
|
+
if (importDecl.moduleSpecifier.text === pkg) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (decl.getSourceFile().fileName.includes(pkg)) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
65
74
|
}
|
|
66
|
-
return
|
|
75
|
+
return false;
|
|
67
76
|
};
|
|
68
77
|
export default { all, includes };
|
|
@@ -10,7 +10,7 @@ export default ({ name, onWatchChange, plugins }) => {
|
|
|
10
10
|
root ??= config.root;
|
|
11
11
|
},
|
|
12
12
|
enforce: 'pre',
|
|
13
|
-
name: `${name}/
|
|
13
|
+
name: `${name}/compiler/vite`,
|
|
14
14
|
transform(code, id) {
|
|
15
15
|
if (!FILE_REGEX.test(id) || id.includes('node_modules')) {
|
|
16
16
|
return null;
|
package/package.json
CHANGED
package/src/compiler/imports.ts
CHANGED
|
@@ -63,60 +63,75 @@ const includes = (checker: ts.TypeChecker, node: ts.Node, pkg: string, symbolNam
|
|
|
63
63
|
cache.set(file, imports);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
let
|
|
66
|
+
let names = imports.get(pkg);
|
|
67
67
|
|
|
68
|
-
if (!
|
|
69
|
-
|
|
68
|
+
if (!names) {
|
|
69
|
+
names = new Set();
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
let packages = all(file, pkg);
|
|
72
|
+
|
|
73
|
+
for (let i = 0, n = packages.length; i < n; i++) {
|
|
74
|
+
for (let [, localName] of packages[i].specifiers) {
|
|
75
|
+
names.add(localName);
|
|
74
76
|
}
|
|
75
77
|
}
|
|
76
78
|
|
|
77
|
-
imports.set(pkg,
|
|
79
|
+
imports.set(pkg, names);
|
|
78
80
|
}
|
|
79
81
|
|
|
80
|
-
//
|
|
81
|
-
if (
|
|
82
|
-
return
|
|
82
|
+
// If no imports from this package, definitely not from it
|
|
83
|
+
if (names.size === 0) {
|
|
84
|
+
return false;
|
|
83
85
|
}
|
|
84
86
|
|
|
85
|
-
|
|
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
|
+
}
|
|
86
92
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (ts.isIdentifier(node) && varnames.has(node.text)) {
|
|
90
|
-
return true;
|
|
93
|
+
if (symbolName && node.text !== symbolName) {
|
|
94
|
+
return false;
|
|
91
95
|
}
|
|
92
96
|
|
|
93
|
-
|
|
94
|
-
|
|
97
|
+
// Try to verify via checker that this identifier refers to the import
|
|
98
|
+
let symbol = checker.getSymbolAtLocation(node);
|
|
95
99
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
+
if (symbol) {
|
|
101
|
+
// Check if the symbol's declaration is an import specifier from this package
|
|
102
|
+
let declarations = symbol.getDeclarations();
|
|
100
103
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
104
|
+
if (declarations && declarations.length > 0) {
|
|
105
|
+
for (let i = 0, n = declarations.length; i < n; i++) {
|
|
106
|
+
let decl = declarations[i];
|
|
105
107
|
|
|
106
|
-
|
|
108
|
+
// If declaration is an ImportSpecifier, check the import's module
|
|
109
|
+
if (ts.isImportSpecifier(decl)) {
|
|
110
|
+
let importDecl = decl.parent?.parent?.parent;
|
|
107
111
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
112
|
+
if (importDecl && ts.isImportDeclaration(importDecl) && ts.isStringLiteral(importDecl.moduleSpecifier)) {
|
|
113
|
+
if (importDecl.moduleSpecifier.text === pkg) {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Also check if declaration is from a file in the package
|
|
120
|
+
if (decl.getSourceFile().fileName.includes(pkg)) {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
111
124
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return true;
|
|
125
|
+
// Symbol resolved but doesn't match package - it's shadowed
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
116
128
|
}
|
|
129
|
+
|
|
130
|
+
// Checker couldn't resolve - trust the name match if it's in import list
|
|
131
|
+
return true;
|
|
117
132
|
}
|
|
118
133
|
|
|
119
|
-
return
|
|
134
|
+
return false;
|
|
120
135
|
};
|
|
121
136
|
|
|
122
137
|
|
|
@@ -33,7 +33,7 @@ export default ({ name, onWatchChange, plugins }: VitePluginOptions) => {
|
|
|
33
33
|
root ??= (config as ResolvedConfig).root;
|
|
34
34
|
},
|
|
35
35
|
enforce: 'pre',
|
|
36
|
-
name: `${name}/
|
|
36
|
+
name: `${name}/compiler/vite`,
|
|
37
37
|
transform(code: string, id: string) {
|
|
38
38
|
if (!FILE_REGEX.test(id) || id.includes('node_modules')) {
|
|
39
39
|
return null;
|