@typescript-eslint/type-utils 8.71.1-alpha.1 → 8.71.1-alpha.10

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.
@@ -159,7 +159,7 @@ function typeMatchesSpecifier(type, specifier, program) {
159
159
  case 'lib':
160
160
  return (0, typeDeclaredInLib_1.typeDeclaredInLib)(declarationFiles, program);
161
161
  case 'package':
162
- return (0, typeDeclaredInPackageDeclarationFile_1.typeDeclaredInPackageDeclarationFile)(specifier.package, declarations, declarationFiles, program);
162
+ return (0, typeDeclaredInPackageDeclarationFile_1.typeDeclaredInPackageDeclarationFile)(specifier.package, symbol, declarations, declarationFiles, program);
163
163
  }
164
164
  })();
165
165
  if (wholeTypeMatches) {
@@ -204,7 +204,7 @@ function valueMatchesSpecifier(node, specifier, program, type) {
204
204
  const symbol = type.getSymbol() ?? type.aliasSymbol;
205
205
  const declarations = symbol?.getDeclarations() ?? [];
206
206
  const declarationFiles = declarations.map(declaration => declaration.getSourceFile());
207
- return (0, typeDeclaredInPackageDeclarationFile_1.typeDeclaredInPackageDeclarationFile)(specifier.package, declarations, declarationFiles, program);
207
+ return (0, typeDeclaredInPackageDeclarationFile_1.typeDeclaredInPackageDeclarationFile)(specifier.package, symbol, declarations, declarationFiles, program);
208
208
  }
209
209
  return true;
210
210
  }
@@ -1,2 +1,2 @@
1
1
  import * as ts from 'typescript';
2
- export declare function typeDeclaredInPackageDeclarationFile(packageName: string, declarations: ts.Node[], declarationFiles: ts.SourceFile[], program: ts.Program): boolean;
2
+ export declare function typeDeclaredInPackageDeclarationFile(packageName: string, symbol: ts.Symbol | undefined, declarations: ts.Node[], declarationFiles: ts.SourceFile[], program: ts.Program): boolean;
@@ -34,12 +34,14 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.typeDeclaredInPackageDeclarationFile = typeDeclaredInPackageDeclarationFile;
37
+ const tsutils = __importStar(require("ts-api-utils"));
37
38
  const ts = __importStar(require("typescript"));
38
39
  function findParentModuleDeclaration(node) {
39
40
  switch (node.kind) {
40
41
  case ts.SyntaxKind.ModuleDeclaration:
41
- // "namespace x {...}" should be ignored here
42
- if (node.flags & ts.NodeFlags.Namespace) {
42
+ // "namespace x {...}" and "global {...}" should be ignored here
43
+ if (node.flags &
44
+ (ts.NodeFlags.Namespace | ts.NodeFlags.GlobalAugmentation)) {
43
45
  break;
44
46
  }
45
47
  return ts.isStringLiteral(node.name)
@@ -53,6 +55,24 @@ function findParentModuleDeclaration(node) {
53
55
  function typeDeclaredInDeclareModule(packageName, declarations) {
54
56
  return declarations.some(declaration => findParentModuleDeclaration(declaration)?.name.text === packageName);
55
57
  }
58
+ function typeExportedFromDeclareModule(packageName, symbol, program) {
59
+ if (!symbol) {
60
+ return false;
61
+ }
62
+ const checker = program.getTypeChecker();
63
+ const moduleSymbol = checker
64
+ .getAmbientModules()
65
+ .find(ambientModule => ambientModule.name === `"${packageName}"`);
66
+ if (!moduleSymbol) {
67
+ return false;
68
+ }
69
+ return checker.getExportsOfModule(moduleSymbol).some(exportedSymbol => {
70
+ const resolvedSymbol = tsutils.isSymbolFlagSet(exportedSymbol, ts.SymbolFlags.Alias)
71
+ ? checker.getAliasedSymbol(exportedSymbol)
72
+ : exportedSymbol;
73
+ return resolvedSymbol === symbol;
74
+ });
75
+ }
56
76
  /**
57
77
  * Whether `packagePath` is `packageName` itself or something inside it, comparing
58
78
  * whole path components: `semver` covers `semver` and `semver/classes/semver.d.ts`,
@@ -76,8 +96,9 @@ function typeDeclaredInDeclarationFile(packageName, declarationFiles, program) {
76
96
  program.isSourceFileFromExternalLibrary(declaration));
77
97
  });
78
98
  }
79
- function typeDeclaredInPackageDeclarationFile(packageName, declarations, declarationFiles, program) {
99
+ function typeDeclaredInPackageDeclarationFile(packageName, symbol, declarations, declarationFiles, program) {
80
100
  return (typeDeclaredInDeclareModule(packageName, declarations) ||
81
- typeDeclaredInDeclarationFile(packageName, declarationFiles, program));
101
+ typeDeclaredInDeclarationFile(packageName, declarationFiles, program) ||
102
+ typeExportedFromDeclareModule(packageName, symbol, program));
82
103
  }
83
104
  //# sourceMappingURL=typeDeclaredInPackageDeclarationFile.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/type-utils",
3
- "version": "8.71.1-alpha.1",
3
+ "version": "8.71.1-alpha.10",
4
4
  "description": "Type utilities for working with TypeScript + ESLint together",
5
5
  "files": [
6
6
  "dist",
@@ -34,9 +34,9 @@
34
34
  "estree"
35
35
  ],
36
36
  "dependencies": {
37
- "@typescript-eslint/types": "8.71.1-alpha.1",
38
- "@typescript-eslint/typescript-estree": "8.71.1-alpha.1",
39
- "@typescript-eslint/utils": "8.71.1-alpha.1",
37
+ "@typescript-eslint/types": "8.71.1-alpha.10",
38
+ "@typescript-eslint/typescript-estree": "8.71.1-alpha.10",
39
+ "@typescript-eslint/utils": "8.71.1-alpha.10",
40
40
  "debug": "^4.4.3",
41
41
  "ts-api-utils": "^2.5.0"
42
42
  },
@@ -46,7 +46,7 @@
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/babel__code-frame": "^7.0.6",
49
- "@typescript-eslint/parser": "8.71.1-alpha.1",
49
+ "@typescript-eslint/parser": "8.71.1-alpha.10",
50
50
  "@typescript/native": "npm:typescript@^7.0.2",
51
51
  "@vitest/coverage-v8": "^4.0.18",
52
52
  "ajv": "^6.12.6",