@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 varnames = imports.get(pkg);
32
- if (!varnames) {
33
- varnames = new Set();
34
- for (let info of all(file, pkg)) {
35
- for (let [, varname] of info.specifiers) {
36
- varnames.add(varname);
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, varnames);
40
+ imports.set(pkg, names);
40
41
  }
41
- if (ts.isIdentifier(node) && varnames.has(node.text) && (!symbolName || node.text === symbolName)) {
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 (symbol.flags & ts.SymbolFlags.Alias) {
52
- symbol = checker.getAliasedSymbol(symbol);
53
- }
54
- if (symbolName && symbol.name !== symbolName) {
55
- return ts.isIdentifier(node) && varnames.has(node.text);
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 ts.isIdentifier(node) && varnames.has(node.text);
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}/plugin-vite`,
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
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "type": "module",
39
39
  "types": "build/index.d.ts",
40
- "version": "0.27.1",
40
+ "version": "0.27.3",
41
41
  "scripts": {
42
42
  "build": "tsc && tsc-alias",
43
43
  "-": "-"
@@ -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 varnames = imports.get(pkg);
66
+ let names = imports.get(pkg);
67
67
 
68
- if (!varnames) {
69
- varnames = new Set();
68
+ if (!names) {
69
+ names = new Set();
70
70
 
71
- for (let info of all(file, pkg)) {
72
- for (let [, varname] of info.specifiers) {
73
- varnames.add(varname);
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, varnames);
79
+ imports.set(pkg, names);
78
80
  }
79
81
 
80
- // Fast path: identifier matches known import and expected name
81
- if (ts.isIdentifier(node) && varnames.has(node.text) && (!symbolName || node.text === symbolName)) {
82
- return true;
82
+ // If no imports from this package, definitely not from it
83
+ if (names.size === 0) {
84
+ return false;
83
85
  }
84
86
 
85
- let symbol = checker.getSymbolAtLocation(node);
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
- if (!symbol) {
88
- // Fallback: aliased import - check if local name is in imports
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
- return false;
94
- }
97
+ // Try to verify via checker that this identifier refers to the import
98
+ let symbol = checker.getSymbolAtLocation(node);
95
99
 
96
- // Follow aliases to original symbol (handles re-exports and aliased imports)
97
- if (symbol.flags & ts.SymbolFlags.Alias) {
98
- symbol = checker.getAliasedSymbol(symbol);
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
- // Check symbol name if specified
102
- if (symbolName && symbol.name !== symbolName) {
103
- return ts.isIdentifier(node) && varnames.has(node.text);
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
- let declarations = symbol.getDeclarations();
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
- if (!declarations || declarations.length === 0) {
109
- return ts.isIdentifier(node) && varnames.has(node.text);
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
- // Check if any declaration is from the expected package
113
- for (let i = 0, n = declarations.length; i < n; i++) {
114
- if (declarations[i].getSourceFile().fileName.includes(pkg)) {
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 ts.isIdentifier(node) && varnames.has(node.text);
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}/plugin-vite`,
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;