@flint.fyi/typescript-language 0.18.2 → 0.18.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.
Files changed (70) hide show
  1. package/lib/collectReferencedFilePaths.d.ts +0 -1
  2. package/lib/collectReferencedFilePaths.js +1 -3
  3. package/lib/convertTypeScriptDiagnosticToLanguageReport.d.ts +2 -3
  4. package/lib/convertTypeScriptDiagnosticToLanguageReport.js +3 -4
  5. package/lib/createTypeScriptServerHost.d.ts +1 -2
  6. package/lib/createTypeScriptServerHost.js +1 -3
  7. package/lib/directives/parseDirectivesFromTypeScriptFile.d.ts +1 -2
  8. package/lib/directives/parseDirectivesFromTypeScriptFile.js +2 -4
  9. package/lib/getFirstEnumValues.d.ts +0 -1
  10. package/lib/getFirstEnumValues.js +0 -2
  11. package/lib/getTSNodeRange.d.ts +2 -3
  12. package/lib/getTSNodeRange.js +0 -2
  13. package/lib/getTypeScriptFileCacheImpacts.d.ts +0 -1
  14. package/lib/getTypeScriptFileCacheImpacts.js +5 -3
  15. package/lib/index.d.ts +8 -3
  16. package/lib/index.js +5 -1
  17. package/lib/language.d.ts +393 -201
  18. package/lib/language.js +2 -4
  19. package/lib/nodes.d.ts +1 -2
  20. package/lib/normalizeRange.d.ts +0 -1
  21. package/lib/normalizeRange.js +0 -2
  22. package/lib/orderTypeScriptFilePaths.d.ts +0 -1
  23. package/lib/orderTypeScriptFilePaths.js +0 -2
  24. package/lib/package.js +1 -3
  25. package/lib/scope/identifierReferences.d.ts +3 -0
  26. package/lib/scope/identifierReferences.js +89 -0
  27. package/lib/scope/scopeManager.d.ts +14 -0
  28. package/lib/scope/scopeManager.js +153 -0
  29. package/lib/scope/scopes.d.ts +7 -0
  30. package/lib/scope/scopes.js +64 -0
  31. package/lib/scope/types.d.ts +45 -0
  32. package/lib/types/ast.d.ts +2 -2
  33. package/lib/types/checker.d.ts +1 -2
  34. package/lib/utils/containsGlobalDeclarations.d.ts +6 -0
  35. package/lib/utils/containsGlobalDeclarations.js +17 -0
  36. package/lib/utils/createRuleTesterTSConfig.d.ts +1 -2
  37. package/lib/utils/createRuleTesterTSConfig.js +0 -2
  38. package/lib/utils/declarationIncludesGlobal.d.ts +1 -2
  39. package/lib/utils/declarationIncludesGlobal.js +0 -2
  40. package/lib/utils/declarationsIncludeGlobal.d.ts +0 -1
  41. package/lib/utils/declarationsIncludeGlobal.js +0 -2
  42. package/lib/utils/forEachChild.d.ts +7 -0
  43. package/lib/utils/forEachChild.js +5 -0
  44. package/lib/utils/getDeclarationsIfGlobal.d.ts +2 -5
  45. package/lib/utils/getDeclarationsIfGlobal.js +0 -2
  46. package/lib/utils/getModifyingReferences.d.ts +2 -7
  47. package/lib/utils/getModifyingReferences.js +5 -27
  48. package/lib/utils/hasSameTokens.d.ts +1 -2
  49. package/lib/utils/hasSameTokens.js +0 -2
  50. package/lib/utils/isBuiltinArrayMethod.d.ts +1 -2
  51. package/lib/utils/isBuiltinArrayMethod.js +0 -2
  52. package/lib/utils/isFunction.d.ts +1 -2
  53. package/lib/utils/isFunction.js +0 -2
  54. package/lib/utils/isGlobalDeclaration.d.ts +1 -2
  55. package/lib/utils/isGlobalDeclaration.js +0 -2
  56. package/lib/utils/isGlobalDeclarationOfName.d.ts +1 -2
  57. package/lib/utils/isGlobalDeclarationOfName.js +0 -2
  58. package/lib/utils/isGlobalVariable.d.ts +1 -2
  59. package/lib/utils/isGlobalVariable.js +0 -2
  60. package/lib/utils/isInlineArrayCreation.d.ts +1 -2
  61. package/lib/utils/isInlineArrayCreation.js +0 -2
  62. package/lib/utils/isStaticString.d.ts +5 -0
  63. package/lib/utils/isStaticString.js +7 -0
  64. package/lib/utils/isStringRawNoSubstitution.d.ts +7 -0
  65. package/lib/utils/isStringRawNoSubstitution.js +9 -0
  66. package/lib/utils/unwrapParentParenthesizedExpressions.d.ts +1 -2
  67. package/lib/utils/unwrapParentParenthesizedExpressions.js +0 -2
  68. package/lib/utils/unwrapParenthesizedNode.d.ts +1 -2
  69. package/lib/utils/unwrapParenthesizedNode.js +0 -2
  70. package/package.json +5 -6
@@ -15,5 +15,3 @@ function isNode(value) {
15
15
  }
16
16
  //#endregion
17
17
  export { normalizeRange };
18
-
19
- //# sourceMappingURL=normalizeRange.js.map
@@ -1,3 +1,2 @@
1
1
  import type { LinterHost } from "@flint.fyi/core";
2
2
  export declare function orderTypeScriptFilePaths(filePaths: readonly string[], host: LinterHost): string[];
3
- //# sourceMappingURL=orderTypeScriptFilePaths.d.ts.map
@@ -88,5 +88,3 @@ function orderTypeScriptFilePaths(filePaths, host) {
88
88
  }
89
89
  //#endregion
90
90
  export { orderTypeScriptFilePaths };
91
-
92
- //# sourceMappingURL=orderTypeScriptFilePaths.js.map
package/lib/package.js CHANGED
@@ -1,7 +1,5 @@
1
1
  //#region package.json
2
2
  var name = "@flint.fyi/typescript-language";
3
- var version = "0.18.2";
3
+ var version = "0.18.4";
4
4
  //#endregion
5
5
  export { name, version };
6
-
7
- //# sourceMappingURL=package.js.map
@@ -0,0 +1,3 @@
1
+ import type * as AST from "../types/ast.ts";
2
+ export declare function isNonReferenceIdentifier(identifier: AST.Identifier): boolean;
3
+ export declare function isWriteReference(identifier: AST.Identifier): boolean;
@@ -0,0 +1,89 @@
1
+ import { SyntaxKind } from "typescript";
2
+ import * as tsutils from "ts-api-utils";
3
+ //#region src/scope/identifierReferences.ts
4
+ function isNonReferenceIdentifier(identifier) {
5
+ if (isIdentifierDeclaration(identifier) || isTypeReferenceIdentifier(identifier)) return true;
6
+ const { parent } = identifier;
7
+ switch (parent.kind) {
8
+ case SyntaxKind.BindingElement:
9
+ case SyntaxKind.ImportSpecifier: return parent.propertyName === identifier;
10
+ case SyntaxKind.BreakStatement:
11
+ case SyntaxKind.ContinueStatement:
12
+ case SyntaxKind.LabeledStatement: return parent.label === identifier;
13
+ case SyntaxKind.JsxAttribute:
14
+ case SyntaxKind.MethodDeclaration:
15
+ case SyntaxKind.MethodSignature:
16
+ case SyntaxKind.PropertyAccessExpression:
17
+ case SyntaxKind.PropertyAssignment:
18
+ case SyntaxKind.PropertyDeclaration:
19
+ case SyntaxKind.PropertySignature: return parent.name === identifier;
20
+ }
21
+ return false;
22
+ }
23
+ function isWriteReference(identifier) {
24
+ const { parent } = identifier;
25
+ if (isAssignmentTarget(identifier)) return true;
26
+ switch (parent.kind) {
27
+ case SyntaxKind.PostfixUnaryExpression:
28
+ case SyntaxKind.PrefixUnaryExpression: return parent.operand === identifier && (parent.operator === SyntaxKind.PlusPlusToken || parent.operator === SyntaxKind.MinusMinusToken);
29
+ default: return false;
30
+ }
31
+ }
32
+ function isAssignmentTarget(identifier) {
33
+ let current = identifier;
34
+ while (true) {
35
+ const parent = current.parent;
36
+ switch (parent.kind) {
37
+ case SyntaxKind.ArrayLiteralExpression:
38
+ case SyntaxKind.ObjectLiteralExpression:
39
+ case SyntaxKind.ShorthandPropertyAssignment:
40
+ current = parent;
41
+ continue;
42
+ case SyntaxKind.PropertyAssignment:
43
+ if (parent.name === current) return false;
44
+ current = parent;
45
+ continue;
46
+ case SyntaxKind.BinaryExpression: return parent.left === current && tsutils.isAssignmentKind(parent.operatorToken.kind);
47
+ case SyntaxKind.ForInStatement:
48
+ case SyntaxKind.ForOfStatement: return parent.initializer === current;
49
+ }
50
+ return false;
51
+ }
52
+ }
53
+ function isIdentifierDeclaration(identifier) {
54
+ const { parent } = identifier;
55
+ switch (parent.kind) {
56
+ case SyntaxKind.BindingElement:
57
+ case SyntaxKind.Parameter:
58
+ case SyntaxKind.VariableDeclaration: return isIdentifierWithinParent(identifier, parent.name);
59
+ case SyntaxKind.ClassDeclaration:
60
+ case SyntaxKind.ClassExpression:
61
+ case SyntaxKind.FunctionDeclaration:
62
+ case SyntaxKind.FunctionExpression:
63
+ case SyntaxKind.InterfaceDeclaration:
64
+ case SyntaxKind.ModuleDeclaration:
65
+ case SyntaxKind.TypeAliasDeclaration: return parent.name === identifier;
66
+ case SyntaxKind.ImportClause:
67
+ case SyntaxKind.ImportSpecifier:
68
+ case SyntaxKind.NamespaceImport: return parent.name === identifier;
69
+ }
70
+ return false;
71
+ }
72
+ function isIdentifierWithinParent(identifier, parent) {
73
+ let current = identifier;
74
+ while (current !== parent) {
75
+ const next = current.parent;
76
+ if (!next) return false;
77
+ current = next;
78
+ }
79
+ return true;
80
+ }
81
+ function isTypeReferenceIdentifier(identifier) {
82
+ let current = identifier;
83
+ while (current.parent.kind === SyntaxKind.QualifiedName) current = current.parent;
84
+ const parent = current.parent;
85
+ if (parent.kind !== SyntaxKind.TypeReference) return false;
86
+ return isIdentifierWithinParent(identifier, parent.typeName);
87
+ }
88
+ //#endregion
89
+ export { isNonReferenceIdentifier, isWriteReference };
@@ -0,0 +1,14 @@
1
+ import { AnyNode, Identifier, SourceFile } from "../types/ast.js";
2
+ import { FunctionWithParameters, Scope, ScopeDefinition, ScopeDefinitionKind, ScopeInternal, ScopeManager, ScopeReference, ScopeVariable } from "./types.js";
3
+
4
+ //#region src/scope/scopeManager.d.ts
5
+ declare function createScopeManager(sourceFile: SourceFile): {
6
+ findVariable(identifier: Identifier): ScopeVariable | undefined;
7
+ getDeclaredVariables(node: AnyNode): ScopeVariable[];
8
+ getReferencesInScope(node: AnyNode): ScopeReference[];
9
+ getScope(node: AnyNode): ScopeInternal;
10
+ globalScope: ScopeInternal;
11
+ };
12
+ declare function getScopeManager(sourceFile: SourceFile): ScopeManager;
13
+ //#endregion
14
+ export { createScopeManager, getScopeManager };
@@ -0,0 +1,153 @@
1
+ import { forEachChild } from "../utils/forEachChild.js";
2
+ import { isNonReferenceIdentifier, isWriteReference } from "./identifierReferences.js";
3
+ import { createScope, getReferencesInScope, getVariableDeclarationScope, isScopeBoundary, resolveVariable } from "./scopes.js";
4
+ import { SyntaxKind } from "typescript";
5
+ //#region src/scope/scopeManager.ts
6
+ const scopeManagers = /* @__PURE__ */ new WeakMap();
7
+ function createScopeManager(sourceFile) {
8
+ const declarationVariablesByIdentifier = /* @__PURE__ */ new WeakMap();
9
+ const declaredVariablesByNode = /* @__PURE__ */ new WeakMap();
10
+ const nodeScopes = /* @__PURE__ */ new WeakMap();
11
+ const globalScope = createScope(sourceFile, void 0);
12
+ function addBindingName(scope, name, node, kind) {
13
+ if (name.kind === SyntaxKind.Identifier) return [addVariable(scope, name, node, kind)];
14
+ const variables = [];
15
+ for (const element of name.elements) if (element.kind !== SyntaxKind.OmittedExpression) variables.push(...addBindingName(scope, element.name, node, kind));
16
+ return variables;
17
+ }
18
+ function addImportVariables(scope, node) {
19
+ if (!node.importClause || node.importClause.isTypeOnly) return;
20
+ if (node.importClause.name) addVariable(scope, node.importClause.name, node, "import");
21
+ const { namedBindings } = node.importClause;
22
+ if (!namedBindings) return;
23
+ if (namedBindings.kind === SyntaxKind.NamespaceImport) {
24
+ addVariable(scope, namedBindings.name, node, "import");
25
+ return;
26
+ }
27
+ for (const element of namedBindings.elements) {
28
+ if (element.isTypeOnly) continue;
29
+ addVariable(scope, element.name, node, "import");
30
+ }
31
+ }
32
+ function addParameters(scope, node) {
33
+ for (const parameter of node.parameters) {
34
+ const variables = addBindingName(scope, parameter.name, node, "parameter");
35
+ declaredVariablesByNode.set(parameter, variables);
36
+ }
37
+ }
38
+ function addVariable(scope, identifier, node, kind) {
39
+ let variable = scope.variablesByName.get(identifier.text);
40
+ if (!variable) {
41
+ variable = {
42
+ declarations: [],
43
+ definitions: [],
44
+ name: identifier.text,
45
+ references: [],
46
+ scope
47
+ };
48
+ scope.variablesByName.set(identifier.text, variable);
49
+ scope.variables.push(variable);
50
+ }
51
+ variable.declarations.push(identifier);
52
+ variable.definitions.push({
53
+ identifier,
54
+ kind,
55
+ node
56
+ });
57
+ declarationVariablesByIdentifier.set(identifier, variable);
58
+ const declaredVariables = declaredVariablesByNode.get(node) ?? [];
59
+ declaredVariables.push(variable);
60
+ declaredVariablesByNode.set(node, declaredVariables);
61
+ return variable;
62
+ }
63
+ function collectDeclarations(node, scope) {
64
+ const nodeScope = node !== sourceFile && isScopeBoundary(node) ? createScope(node, scope) : scope;
65
+ nodeScopes.set(node, nodeScope);
66
+ switch (node.kind) {
67
+ case SyntaxKind.ArrowFunction:
68
+ case SyntaxKind.Constructor:
69
+ case SyntaxKind.GetAccessor:
70
+ case SyntaxKind.MethodDeclaration:
71
+ case SyntaxKind.SetAccessor:
72
+ addParameters(nodeScope, node);
73
+ break;
74
+ case SyntaxKind.CatchClause:
75
+ if (node.variableDeclaration) addBindingName(nodeScope, node.variableDeclaration.name, node, "catch");
76
+ break;
77
+ case SyntaxKind.ClassDeclaration:
78
+ if (node.name) addVariable(nodeScope, node.name, node, "class");
79
+ break;
80
+ case SyntaxKind.ClassExpression:
81
+ if (node.name) addVariable(nodeScope, node.name, node, "class");
82
+ break;
83
+ case SyntaxKind.FunctionDeclaration:
84
+ if (node.name) addVariable(scope, node.name, node, "function");
85
+ addParameters(nodeScope, node);
86
+ break;
87
+ case SyntaxKind.FunctionExpression:
88
+ if (node.name) addVariable(nodeScope, node.name, node, "function");
89
+ addParameters(nodeScope, node);
90
+ break;
91
+ case SyntaxKind.ImportDeclaration:
92
+ addImportVariables(nodeScope, node);
93
+ break;
94
+ case SyntaxKind.VariableDeclaration:
95
+ if (node.parent.kind === SyntaxKind.CatchClause) {
96
+ forEachChild(node, (child) => {
97
+ collectDeclarations(child, nodeScope);
98
+ });
99
+ return;
100
+ }
101
+ addBindingName(getVariableDeclarationScope(node, nodeScope), node.name, node, "variable");
102
+ break;
103
+ }
104
+ forEachChild(node, (child) => {
105
+ collectDeclarations(child, nodeScope);
106
+ });
107
+ }
108
+ function collectReferences(node) {
109
+ if (node.kind === SyntaxKind.Identifier && !isNonReferenceIdentifier(node)) {
110
+ const scope = nodeScopes.get(node) ?? globalScope;
111
+ const variable = resolveVariable(scope, node.text);
112
+ const reference = {
113
+ from: scope,
114
+ identifier: node,
115
+ isWrite: isWriteReference(node),
116
+ text: node.text,
117
+ variable
118
+ };
119
+ scope.references.push(reference);
120
+ variable?.references.push(reference);
121
+ }
122
+ forEachChild(node, collectReferences);
123
+ }
124
+ collectDeclarations(sourceFile, globalScope);
125
+ collectReferences(sourceFile);
126
+ return {
127
+ findVariable(identifier) {
128
+ const declarationVariable = declarationVariablesByIdentifier.get(identifier);
129
+ if (declarationVariable) return declarationVariable;
130
+ return resolveVariable(nodeScopes.get(identifier) ?? globalScope, identifier.text);
131
+ },
132
+ getDeclaredVariables(node) {
133
+ return declaredVariablesByNode.get(node) ?? [];
134
+ },
135
+ getReferencesInScope(node) {
136
+ return getReferencesInScope(nodeScopes.get(node) ?? globalScope);
137
+ },
138
+ getScope(node) {
139
+ return nodeScopes.get(node) ?? globalScope;
140
+ },
141
+ globalScope
142
+ };
143
+ }
144
+ function getScopeManager(sourceFile) {
145
+ let scopeManager = scopeManagers.get(sourceFile);
146
+ if (!scopeManager) {
147
+ scopeManager = createScopeManager(sourceFile);
148
+ scopeManagers.set(sourceFile, scopeManager);
149
+ }
150
+ return scopeManager;
151
+ }
152
+ //#endregion
153
+ export { createScopeManager, getScopeManager };
@@ -0,0 +1,7 @@
1
+ import type * as AST from "../types/ast.ts";
2
+ import type { ScopeInternal, ScopeVariable } from "./types.ts";
3
+ export declare function createScope(block: AST.AnyNode, upper: ScopeInternal | undefined): ScopeInternal;
4
+ export declare function getReferencesInScope(scope: ScopeInternal): import("./types.ts").ScopeReference[];
5
+ export declare function getVariableDeclarationScope(node: AST.VariableDeclaration, scope: ScopeInternal): ScopeInternal;
6
+ export declare function isScopeBoundary(node: AST.AnyNode): boolean;
7
+ export declare function resolveVariable(scope: ScopeInternal, name: string): ScopeVariable | undefined;
@@ -0,0 +1,64 @@
1
+ import ts, { SyntaxKind } from "typescript";
2
+ //#region src/scope/scopes.ts
3
+ function createScope(block, upper) {
4
+ const variablesByName = /* @__PURE__ */ new Map();
5
+ const scope = {
6
+ block,
7
+ childScopes: [],
8
+ references: [],
9
+ upper,
10
+ variables: [],
11
+ variablesByName
12
+ };
13
+ Object.defineProperty(scope, "variablesByName", {
14
+ enumerable: false,
15
+ value: variablesByName
16
+ });
17
+ upper?.childScopes.push(scope);
18
+ return scope;
19
+ }
20
+ function getReferencesInScope(scope) {
21
+ const references = [...scope.references];
22
+ for (const childScope of scope.childScopes) if (!isFunctionLike(childScope.block)) references.push(...getReferencesInScope(childScope));
23
+ return references;
24
+ }
25
+ function getVariableDeclarationScope(node, scope) {
26
+ if (node.parent.kind === SyntaxKind.VariableDeclarationList && !(node.parent.flags & ts.NodeFlags.BlockScoped)) return findContainingVariableScope(scope);
27
+ return scope;
28
+ }
29
+ function isScopeBoundary(node) {
30
+ return isFunctionLike(node) || node.kind === SyntaxKind.CatchClause || node.kind === SyntaxKind.ClassExpression || node.kind === SyntaxKind.ForInStatement || node.kind === SyntaxKind.ForOfStatement || node.kind === SyntaxKind.ForStatement || isBlockScopeBoundary(node);
31
+ }
32
+ function resolveVariable(scope, name) {
33
+ let current = scope;
34
+ while (current) {
35
+ const variable = current.variablesByName.get(name);
36
+ if (variable) return variable;
37
+ current = current.upper;
38
+ }
39
+ }
40
+ function findContainingVariableScope(scope) {
41
+ let current = scope;
42
+ while (current.upper && !isVariableScopeBoundary(current.block)) current = current.upper;
43
+ return current;
44
+ }
45
+ function isBlockScopeBoundary(node) {
46
+ return node.kind === SyntaxKind.Block && node.parent.kind !== SyntaxKind.CatchClause && !isFunctionLike(node.parent);
47
+ }
48
+ function isFunctionLike(node) {
49
+ switch (node?.kind) {
50
+ case SyntaxKind.ArrowFunction:
51
+ case SyntaxKind.Constructor:
52
+ case SyntaxKind.FunctionDeclaration:
53
+ case SyntaxKind.FunctionExpression:
54
+ case SyntaxKind.GetAccessor:
55
+ case SyntaxKind.MethodDeclaration:
56
+ case SyntaxKind.SetAccessor: return true;
57
+ default: return false;
58
+ }
59
+ }
60
+ function isVariableScopeBoundary(node) {
61
+ return node.kind === SyntaxKind.SourceFile || isFunctionLike(node);
62
+ }
63
+ //#endregion
64
+ export { createScope, getReferencesInScope, getVariableDeclarationScope, isScopeBoundary, resolveVariable };
@@ -0,0 +1,45 @@
1
+ import { AnyNode, ArrowFunction, ConstructorDeclaration, FunctionDeclaration, FunctionExpression, GetAccessorDeclaration, Identifier, MethodDeclaration, SetAccessorDeclaration } from "../types/ast.js";
2
+
3
+ //#region src/scope/types.d.ts
4
+ type FunctionWithParameters = ArrowFunction | ConstructorDeclaration | FunctionDeclaration | FunctionExpression | GetAccessorDeclaration | MethodDeclaration | SetAccessorDeclaration;
5
+ interface Scope {
6
+ block: AnyNode;
7
+ childScopes: Scope[];
8
+ references: ScopeReference[];
9
+ upper: Scope | undefined;
10
+ variables: ScopeVariable[];
11
+ }
12
+ interface ScopeDefinition {
13
+ identifier: Identifier;
14
+ kind: ScopeDefinitionKind;
15
+ node: AnyNode;
16
+ }
17
+ type ScopeDefinitionKind = "catch" | "class" | "function" | "import" | "parameter" | "variable";
18
+ interface ScopeInternal extends Scope {
19
+ childScopes: ScopeInternal[];
20
+ upper: ScopeInternal | undefined;
21
+ variablesByName: Map<string, ScopeVariable>;
22
+ }
23
+ interface ScopeManager {
24
+ findVariable(identifier: Identifier): ScopeVariable | undefined;
25
+ getDeclaredVariables(node: AnyNode): ScopeVariable[];
26
+ getReferencesInScope(node: AnyNode): ScopeReference[];
27
+ getScope(node: AnyNode): Scope;
28
+ globalScope: Scope;
29
+ }
30
+ interface ScopeReference {
31
+ from: Scope;
32
+ identifier: Identifier;
33
+ isWrite: boolean;
34
+ text: string;
35
+ variable: ScopeVariable | undefined;
36
+ }
37
+ interface ScopeVariable {
38
+ declarations: Identifier[];
39
+ definitions: ScopeDefinition[];
40
+ name: string;
41
+ references: ScopeReference[];
42
+ scope: Scope;
43
+ }
44
+ //#endregion
45
+ export { FunctionWithParameters, Scope, ScopeDefinition, ScopeDefinitionKind, ScopeInternal, ScopeManager, ScopeReference, ScopeVariable };
@@ -1662,6 +1662,7 @@ interface SourceFile extends ts.Node {
1662
1662
  libReferenceDirectives: readonly ts.FileReference[];
1663
1663
  moduleName?: string;
1664
1664
  readonly parent: NullNode;
1665
+ path: ts.Path;
1665
1666
  referencedFiles: readonly ts.FileReference[];
1666
1667
  readonly statements: ts.NodeArray<Statement>;
1667
1668
  text: string;
@@ -2066,5 +2067,4 @@ type ModifierParent = AccessorDeclaration | ArrowFunction | ClassDeclaration | C
2066
2067
  type StatementParent = Block | CaseOrDefaultClause | IfStatement | IterationStatement | LabeledStatement | ModuleBlock | SourceFile | WithStatement;
2067
2068
  type TypeNodeParent = AccessorDeclaration | ArrayTypeNode | ArrowFunction | AsExpression | CallExpression | CallSignatureDeclaration | ConditionalTypeNode | ConstructorDeclaration | ConstructSignatureDeclaration | FunctionDeclaration | FunctionExpression | FunctionOrConstructorTypeNodeBase | IndexedAccessTypeNode | IndexSignatureDeclaration | IntersectionTypeNode | JSDocFunctionType | JSDocNamepathType | JSDocNonNullableType | JSDocNullableType | JSDocOptionalType | JSDocTypeExpression | JSDocVariadicType | JsxOpeningElement | JsxSelfClosingElement | MappedTypeNode | MethodDeclaration | MethodSignature | NamedTupleMember | NewExpression | NodeWithTypeArguments | OptionalTypeNode | ParameterDeclaration | ParenthesizedTypeNode | PropertyDeclaration | PropertySignature | RestTypeNode | SatisfiesExpression | TaggedTemplateExpression | TemplateLiteralTypeSpan | TupleTypeNode | TypeAliasDeclaration | TypeAssertion | TypeOperatorNode | TypeParameterDeclaration | TypePredicateNode | UnionTypeNode | VariableDeclaration;
2068
2069
  //#endregion
2069
- export { AnyKeyword, AnyNode, ArrayBindingPattern, ArrayLiteralExpression, ArrayTypeNode, ArrowFunction, AsExpression, AwaitExpression, BigIntKeyword, BigIntLiteral, BinaryExpression, BindingElement, Block, BooleanKeyword, BreakStatement, CallExpression, CallSignatureDeclaration, CaseBlock, CaseClause, CatchClause, ClassDeclaration, ClassExpression, ClassStaticBlockDeclaration, CommaListExpression, ComputedPropertyName, ConditionalExpression, ConditionalTypeNode, ConstructSignatureDeclaration, ConstructorDeclaration, ConstructorTypeNode, ContinueStatement, DebuggerStatement, Decorator, DefaultClause, DeleteExpression, DoStatement, ElementAccessExpression, EmptyStatement, EnumDeclaration, EnumMember, ExportAssignment, ExportDeclaration, ExportSpecifier, Expression, ExpressionStatement, ExpressionWithTypeArguments, ExternalModuleReference, FalseLiteral, ForInStatement, ForOfStatement, ForStatement, FunctionDeclaration, FunctionExpression, FunctionTypeNode, GetAccessorDeclaration, HeritageClause, Identifier, IfStatement, ImportAttribute, ImportAttributes, ImportClause, ImportDeclaration, ImportEqualsDeclaration, ImportExpression, ImportSpecifier, ImportTypeNode, IndexSignatureDeclaration, IndexedAccessTypeNode, InferTypeNode, InterfaceDeclaration, IntersectionTypeNode, IntrinsicKeyword, JSDocAllType, JSDocFunctionType, JSDocLink, JSDocLinkCode, JSDocLinkPlain, JSDocMemberName, JSDocNamepathType, JSDocNonNullableType, JSDocNullableType, JSDocOptionalType, JSDocParameterTag, JSDocPropertyTag, JSDocReturnTag, JSDocSignature, JSDocTemplateTag, JSDocText, JSDocTypeExpression, JSDocTypeLiteral, JSDocUnknownType, JSDocVariadicType, JsxAttribute, JsxAttributes, JsxClosingElement, JsxClosingFragment, JsxElement, JsxExpression, JsxFragment, JsxNamespacedName, JsxOpeningElement, JsxOpeningFragment, JsxSelfClosingElement, JsxSpreadAttribute, JsxText, LabeledStatement, LeftHandSideExpressionParent, LiteralTypeNode, MappedTypeNode, MetaProperty, MethodDeclaration, MethodSignature, MissingDeclaration, ModuleBlock, ModuleDeclaration, NamedExports, NamedImports, NamedTupleMember, NamespaceExport, NamespaceExportDeclaration, NamespaceImport, NeverKeyword, NewExpression, NoSubstitutionTemplateLiteral, NonNullExpression, NotEmittedStatement, NotEmittedTypeElement, NullLiteral, NumberKeyword, NumericLiteral, ObjectBindingPattern, ObjectKeyword, ObjectLiteralExpression, OmittedExpression, OptionalTypeNode, ParameterDeclaration, ParenthesizedExpression, ParenthesizedTypeNode, PartiallyEmittedExpression, PostfixUnaryExpression, PrefixUnaryExpression, PrivateIdentifier, PropertyAccessExpression, PropertyAssignment, PropertyDeclaration, PropertySignature, QualifiedName, RegularExpressionLiteral, RestTypeNode, ReturnStatement, SatisfiesExpression, SemicolonClassElement, SetAccessorDeclaration, ShorthandPropertyAssignment, SourceFile, SpreadAssignment, SpreadElement, StringKeyword, StringLiteral, SuperExpression, SwitchStatement, SymbolKeyword, SyntheticExpression, TaggedTemplateExpression, TemplateExpression, TemplateHead, TemplateLiteralTypeNode, TemplateLiteralTypeSpan, TemplateMiddle, TemplateSpan, TemplateTail, ThisExpression, ThisTypeNode, ThrowStatement, TrueLiteral, TryStatement, TupleTypeNode, TypeAliasDeclaration, TypeAssertion, TypeLiteralNode, TypeOfExpression, TypeOperatorNode, TypeParameterDeclaration, TypePredicateNode, TypeQueryNode, TypeReferenceNode, UndefinedKeyword, UnionTypeNode, UnknownKeyword, VariableDeclaration, VariableDeclarationList, VariableStatement, VoidExpression, VoidKeyword, WhileStatement, WithStatement, YieldExpression, ast_d_exports };
2070
- //# sourceMappingURL=ast.d.ts.map
2070
+ export { AnyKeyword, AnyNode, ArrayBindingPattern, ArrayLiteralExpression, ArrayTypeNode, ArrowFunction, AsExpression, AwaitExpression, BigIntKeyword, BigIntLiteral, BinaryExpression, BindingElement, Block, BooleanKeyword, BreakStatement, CallExpression, CallSignatureDeclaration, CaseBlock, CaseClause, CatchClause, ClassDeclaration, ClassExpression, ClassStaticBlockDeclaration, CommaListExpression, ComputedPropertyName, ConditionalExpression, ConditionalTypeNode, ConstructSignatureDeclaration, ConstructorDeclaration, ConstructorTypeNode, ContinueStatement, DebuggerStatement, Decorator, DefaultClause, DeleteExpression, DoStatement, ElementAccessExpression, EmptyStatement, EnumDeclaration, EnumMember, ExportAssignment, ExportDeclaration, ExportSpecifier, Expression, ExpressionStatement, ExpressionWithTypeArguments, ExternalModuleReference, FalseLiteral, ForInStatement, ForOfStatement, ForStatement, FunctionDeclaration, FunctionExpression, FunctionTypeNode, GetAccessorDeclaration, HeritageClause, Identifier, IfStatement, ImportAttribute, ImportAttributes, ImportClause, ImportDeclaration, ImportEqualsDeclaration, ImportExpression, ImportSpecifier, ImportTypeNode, IndexSignatureDeclaration, IndexedAccessTypeNode, InferTypeNode, InterfaceDeclaration, IntersectionTypeNode, IntrinsicKeyword, JSDocAllType, JSDocFunctionType, JSDocLink, JSDocLinkCode, JSDocLinkPlain, JSDocMemberName, JSDocNamepathType, JSDocNonNullableType, JSDocNullableType, JSDocOptionalType, JSDocParameterTag, JSDocPropertyTag, JSDocReturnTag, JSDocSignature, JSDocTemplateTag, JSDocText, JSDocTypeExpression, JSDocTypeLiteral, JSDocUnknownType, JSDocVariadicType, JsxAttribute, JsxAttributes, JsxClosingElement, JsxClosingFragment, JsxElement, JsxExpression, JsxFragment, JsxNamespacedName, JsxOpeningElement, JsxOpeningFragment, JsxSelfClosingElement, JsxSpreadAttribute, JsxText, LabeledStatement, LeftHandSideExpressionParent, LiteralTypeNode, MappedTypeNode, MetaProperty, MethodDeclaration, MethodSignature, MissingDeclaration, ModuleBlock, ModuleDeclaration, NamedExports, NamedImports, NamedTupleMember, NamespaceExport, NamespaceExportDeclaration, NamespaceImport, NeverKeyword, NewExpression, NoSubstitutionTemplateLiteral, NonNullExpression, NotEmittedStatement, NotEmittedTypeElement, NullLiteral, NumberKeyword, NumericLiteral, ObjectBindingPattern, ObjectKeyword, ObjectLiteralExpression, OmittedExpression, OptionalTypeNode, ParameterDeclaration, ParenthesizedExpression, ParenthesizedTypeNode, PartiallyEmittedExpression, PostfixUnaryExpression, PrefixUnaryExpression, PrivateIdentifier, PropertyAccessExpression, PropertyAssignment, PropertyDeclaration, PropertySignature, QualifiedName, RegularExpressionLiteral, RestTypeNode, ReturnStatement, SatisfiesExpression, SemicolonClassElement, SetAccessorDeclaration, ShorthandPropertyAssignment, SourceFile, SpreadAssignment, SpreadElement, StringKeyword, StringLiteral, SuperExpression, SwitchStatement, SymbolKeyword, SyntheticExpression, TaggedTemplateExpression, TemplateExpression, TemplateHead, TemplateLiteralTypeNode, TemplateLiteralTypeSpan, TemplateMiddle, TemplateSpan, TemplateTail, ThisExpression, ThisTypeNode, ThrowStatement, TrueLiteral, TryStatement, TupleTypeNode, TypeAliasDeclaration, TypeAssertion, TypeLiteralNode, TypeOfExpression, TypeOperatorNode, TypeParameterDeclaration, TypePredicateNode, TypeQueryNode, TypeReferenceNode, UndefinedKeyword, UnionTypeNode, UnknownKeyword, VariableDeclaration, VariableDeclarationList, VariableStatement, VoidExpression, VoidKeyword, WhileStatement, WithStatement, YieldExpression, ast_d_exports };
@@ -19,5 +19,4 @@ interface CheckerOverrides {
19
19
  getContextualTypeForArgumentAtIndex(node: Node, argIndex: number): Type;
20
20
  }
21
21
  //#endregion
22
- export { Checker };
23
- //# sourceMappingURL=checker.d.ts.map
22
+ export { Checker };
@@ -0,0 +1,6 @@
1
+ import ts from "typescript";
2
+ /**
3
+ * Inspects top-level statements of a TS source file to determine
4
+ * if it introduces or modifies entities in the global scope.
5
+ */
6
+ export declare function containsGlobalDeclarations(sourceFileNode: ts.SourceFile): boolean;
@@ -0,0 +1,17 @@
1
+ import ts from "typescript";
2
+ //#region src/utils/containsGlobalDeclarations.ts
3
+ /**
4
+ * Inspects top-level statements of a TS source file to determine
5
+ * if it introduces or modifies entities in the global scope.
6
+ */
7
+ function containsGlobalDeclarations(sourceFileNode) {
8
+ const isModule = ts.isExternalModule(sourceFileNode);
9
+ return sourceFileNode.statements.some((statement) => {
10
+ if (ts.isModuleDeclaration(statement) && statement.name.text === "global") return true;
11
+ if (isModule) return false;
12
+ if (!ts.canHaveModifiers(statement)) return false;
13
+ return ts.getModifiers(statement)?.some((mod) => mod.kind === ts.SyntaxKind.DeclareKeyword);
14
+ });
15
+ }
16
+ //#endregion
17
+ export { containsGlobalDeclarations };
@@ -4,5 +4,4 @@ declare function createRuleTesterTSConfig(defaultCompilerOptions?: Record<string
4
4
  "tsconfig.json": string;
5
5
  };
6
6
  //#endregion
7
- export { createRuleTesterTSConfig };
8
- //# sourceMappingURL=createRuleTesterTSConfig.d.ts.map
7
+ export { createRuleTesterTSConfig };
@@ -14,5 +14,3 @@ function createRuleTesterTSConfig(defaultCompilerOptions) {
14
14
  }
15
15
  //#endregion
16
16
  export { createRuleTesterTSConfig };
17
-
18
- //# sourceMappingURL=createRuleTesterTSConfig.js.map
@@ -3,5 +3,4 @@ import ts from "typescript";
3
3
  //#region src/utils/declarationIncludesGlobal.d.ts
4
4
  declare function declarationIncludesGlobal(declaration: ts.Declaration): boolean;
5
5
  //#endregion
6
- export { declarationIncludesGlobal };
7
- //# sourceMappingURL=declarationIncludesGlobal.d.ts.map
6
+ export { declarationIncludesGlobal };
@@ -5,5 +5,3 @@ function declarationIncludesGlobal(declaration) {
5
5
  }
6
6
  //#endregion
7
7
  export { declarationIncludesGlobal };
8
-
9
- //# sourceMappingURL=declarationIncludesGlobal.js.map
@@ -1,3 +1,2 @@
1
1
  import type ts from "typescript";
2
2
  export declare function declarationsIncludeGlobal(declarations: ts.Declaration[]): boolean;
3
- //# sourceMappingURL=declarationsIncludeGlobal.d.ts.map
@@ -5,5 +5,3 @@ function declarationsIncludeGlobal(declarations) {
5
5
  }
6
6
  //#endregion
7
7
  export { declarationsIncludeGlobal };
8
-
9
- //# sourceMappingURL=declarationsIncludeGlobal.js.map
@@ -0,0 +1,7 @@
1
+ import { AnyNode } from "../types/ast.js";
2
+ import ts from "typescript";
3
+
4
+ //#region src/utils/forEachChild.d.ts
5
+ declare const forEachChild: <T>(node: AnyNode, cbNode: (node: AnyNode) => T | undefined, cbNodes?: (nodes: ts.NodeArray<AnyNode>) => T | undefined) => T | undefined;
6
+ //#endregion
7
+ export { forEachChild };
@@ -0,0 +1,5 @@
1
+ import ts from "typescript";
2
+ //#region src/utils/forEachChild.ts
3
+ const forEachChild = ts.forEachChild;
4
+ //#endregion
5
+ export { forEachChild };
@@ -1,9 +1,6 @@
1
1
  import { Expression } from "../types/ast.js";
2
2
  import { Checker } from "../types/checker.js";
3
- import * as typescript from "typescript";
4
-
5
3
  //#region src/utils/getDeclarationsIfGlobal.d.ts
6
- declare function getDeclarationsIfGlobal(node: Expression, typeChecker: Checker): typescript.Declaration[] | undefined;
4
+ declare function getDeclarationsIfGlobal(node: Expression, typeChecker: Checker): import("typescript").Declaration[] | undefined;
7
5
  //#endregion
8
- export { getDeclarationsIfGlobal };
9
- //# sourceMappingURL=getDeclarationsIfGlobal.d.ts.map
6
+ export { getDeclarationsIfGlobal };
@@ -6,5 +6,3 @@ function getDeclarationsIfGlobal(node, typeChecker) {
6
6
  }
7
7
  //#endregion
8
8
  export { getDeclarationsIfGlobal };
9
-
10
- //# sourceMappingURL=getDeclarationsIfGlobal.js.map
@@ -1,15 +1,10 @@
1
1
  import { Identifier, SourceFile } from "../types/ast.js";
2
- import { Checker } from "../types/checker.js";
3
- import ts from "typescript";
4
2
 
5
3
  //#region src/utils/getModifyingReferences.d.ts
6
4
  /**
7
5
  * Gets all references to a variable that modify it (assignments, increments, decrements).
8
- *
9
- * TODO: Replace with a proper scope manager when available (see #400).
10
6
  * @returns An array of identifier nodes that modify the variable.
11
7
  */
12
- declare function getModifyingReferences(identifier: Identifier, sourceFile: SourceFile, typeChecker: Checker): ts.Identifier[];
8
+ declare function getModifyingReferences(identifier: Identifier, sourceFile: SourceFile): Identifier[];
13
9
  //#endregion
14
- export { getModifyingReferences };
15
- //# sourceMappingURL=getModifyingReferences.d.ts.map
10
+ export { getModifyingReferences };
@@ -1,35 +1,13 @@
1
- import ts from "typescript";
2
- import * as tsutils from "ts-api-utils";
1
+ import { getScopeManager } from "../scope/scopeManager.js";
3
2
  //#region src/utils/getModifyingReferences.ts
4
3
  /**
5
4
  * Gets all references to a variable that modify it (assignments, increments, decrements).
6
- *
7
- * TODO: Replace with a proper scope manager when available (see #400).
8
5
  * @returns An array of identifier nodes that modify the variable.
9
6
  */
10
- function getModifyingReferences(identifier, sourceFile, typeChecker) {
11
- const symbol = typeChecker.getSymbolAtLocation(identifier);
12
- if (!symbol?.valueDeclaration) return [];
13
- const { valueDeclaration } = symbol;
14
- const modifyingReferences = [];
15
- function isIdentifierForSameSymbol(node) {
16
- if (node.kind !== ts.SyntaxKind.Identifier) return false;
17
- if (typeChecker.getSymbolAtLocation(node)?.valueDeclaration !== valueDeclaration) return false;
18
- switch (node.parent.kind) {
19
- case ts.SyntaxKind.BinaryExpression: return tsutils.isAssignmentKind(node.parent.operatorToken.kind) && node.parent.left === node;
20
- case ts.SyntaxKind.PostfixUnaryExpression:
21
- case ts.SyntaxKind.PrefixUnaryExpression: return node.parent.operand === node;
22
- default: return false;
23
- }
24
- }
25
- function visit(node) {
26
- if (isIdentifierForSameSymbol(node)) modifyingReferences.push(node);
27
- ts.forEachChild(node, visit);
28
- }
29
- visit(sourceFile);
30
- return modifyingReferences;
7
+ function getModifyingReferences(identifier, sourceFile) {
8
+ const variable = getScopeManager(sourceFile).findVariable(identifier);
9
+ if (!variable || variable.declarations.length > 1) return [];
10
+ return variable.references.filter((reference) => reference.isWrite).map((reference) => reference.identifier);
31
11
  }
32
12
  //#endregion
33
13
  export { getModifyingReferences };
34
-
35
- //# sourceMappingURL=getModifyingReferences.js.map
@@ -3,5 +3,4 @@ import { AnyNode, SourceFile } from "../types/ast.js";
3
3
  //#region src/utils/hasSameTokens.d.ts
4
4
  declare function hasSameTokens(nodeA: AnyNode, nodeB: AnyNode, sourceFile: SourceFile): boolean;
5
5
  //#endregion
6
- export { hasSameTokens };
7
- //# sourceMappingURL=hasSameTokens.d.ts.map
6
+ export { hasSameTokens };
@@ -28,5 +28,3 @@ function areSameToken(nodeA, nodeB, sourceFile) {
28
28
  }
29
29
  //#endregion
30
30
  export { hasSameTokens };
31
-
32
- //# sourceMappingURL=hasSameTokens.js.map
@@ -10,5 +10,4 @@ type BuiltInArrayMethodNode = CallExpression & {
10
10
  };
11
11
  declare function isBuiltinArrayMethod(name: string, node: CallExpression, typeChecker: Checker): node is BuiltInArrayMethodNode;
12
12
  //#endregion
13
- export { isBuiltinArrayMethod };
14
- //# sourceMappingURL=isBuiltinArrayMethod.d.ts.map
13
+ export { BuiltInArrayMethodNode, isBuiltinArrayMethod };
@@ -5,5 +5,3 @@ function isBuiltinArrayMethod(name, node, typeChecker) {
5
5
  }
6
6
  //#endregion
7
7
  export { isBuiltinArrayMethod };
8
-
9
- //# sourceMappingURL=isBuiltinArrayMethod.js.map
@@ -3,5 +3,4 @@ import { Checker } from "../types/checker.js";
3
3
  //#region src/utils/isFunction.d.ts
4
4
  declare function isFunction(node: Expression, typeChecker: Checker): boolean;
5
5
  //#endregion
6
- export { isFunction };
7
- //# sourceMappingURL=isFunction.d.ts.map
6
+ export { isFunction };