@flint.fyi/typescript-language 0.18.4 → 0.19.0

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 (72) hide show
  1. package/{lib/types/ast.d.ts → dist/index.d.mts} +777 -3
  2. package/dist/index.mjs +1104 -0
  3. package/package.json +9 -7
  4. package/lib/_virtual/_rolldown/runtime.js +0 -13
  5. package/lib/collectReferencedFilePaths.d.ts +0 -3
  6. package/lib/collectReferencedFilePaths.js +0 -38
  7. package/lib/convertTypeScriptDiagnosticToLanguageReport.d.ts +0 -17
  8. package/lib/convertTypeScriptDiagnosticToLanguageReport.js +0 -112
  9. package/lib/createTypeScriptServerHost.d.ts +0 -3
  10. package/lib/createTypeScriptServerHost.js +0 -101
  11. package/lib/directives/parseDirectivesFromTypeScriptFile.d.ts +0 -12
  12. package/lib/directives/parseDirectivesFromTypeScriptFile.js +0 -64
  13. package/lib/getFirstEnumValues.d.ts +0 -35
  14. package/lib/getFirstEnumValues.js +0 -46
  15. package/lib/getTSNodeRange.d.ts +0 -8
  16. package/lib/getTSNodeRange.js +0 -9
  17. package/lib/getTypeScriptFileCacheImpacts.d.ts +0 -3
  18. package/lib/getTypeScriptFileCacheImpacts.js +0 -11
  19. package/lib/index.d.ts +0 -26
  20. package/lib/index.js +0 -22
  21. package/lib/language.d.ts +0 -414
  22. package/lib/language.js +0 -117
  23. package/lib/nodes.d.ts +0 -203
  24. package/lib/normalizeRange.d.ts +0 -3
  25. package/lib/normalizeRange.js +0 -17
  26. package/lib/orderTypeScriptFilePaths.d.ts +0 -2
  27. package/lib/orderTypeScriptFilePaths.js +0 -90
  28. package/lib/package.js +0 -5
  29. package/lib/scope/identifierReferences.d.ts +0 -3
  30. package/lib/scope/identifierReferences.js +0 -89
  31. package/lib/scope/scopeManager.d.ts +0 -14
  32. package/lib/scope/scopeManager.js +0 -153
  33. package/lib/scope/scopes.d.ts +0 -7
  34. package/lib/scope/scopes.js +0 -64
  35. package/lib/scope/types.d.ts +0 -45
  36. package/lib/types/checker.d.ts +0 -22
  37. package/lib/utils/containsGlobalDeclarations.d.ts +0 -6
  38. package/lib/utils/containsGlobalDeclarations.js +0 -17
  39. package/lib/utils/createRuleTesterTSConfig.d.ts +0 -7
  40. package/lib/utils/createRuleTesterTSConfig.js +0 -16
  41. package/lib/utils/declarationIncludesGlobal.d.ts +0 -6
  42. package/lib/utils/declarationIncludesGlobal.js +0 -7
  43. package/lib/utils/declarationsIncludeGlobal.d.ts +0 -2
  44. package/lib/utils/declarationsIncludeGlobal.js +0 -7
  45. package/lib/utils/forEachChild.d.ts +0 -7
  46. package/lib/utils/forEachChild.js +0 -5
  47. package/lib/utils/getDeclarationsIfGlobal.d.ts +0 -6
  48. package/lib/utils/getDeclarationsIfGlobal.js +0 -8
  49. package/lib/utils/getModifyingReferences.d.ts +0 -10
  50. package/lib/utils/getModifyingReferences.js +0 -13
  51. package/lib/utils/hasSameTokens.d.ts +0 -6
  52. package/lib/utils/hasSameTokens.js +0 -30
  53. package/lib/utils/isBuiltinArrayMethod.d.ts +0 -13
  54. package/lib/utils/isBuiltinArrayMethod.js +0 -7
  55. package/lib/utils/isFunction.d.ts +0 -6
  56. package/lib/utils/isFunction.js +0 -6
  57. package/lib/utils/isGlobalDeclaration.d.ts +0 -6
  58. package/lib/utils/isGlobalDeclaration.js +0 -7
  59. package/lib/utils/isGlobalDeclarationOfName.d.ts +0 -10
  60. package/lib/utils/isGlobalDeclarationOfName.js +0 -21
  61. package/lib/utils/isGlobalVariable.d.ts +0 -12
  62. package/lib/utils/isGlobalVariable.js +0 -17
  63. package/lib/utils/isInlineArrayCreation.d.ts +0 -11
  64. package/lib/utils/isInlineArrayCreation.js +0 -43
  65. package/lib/utils/isStaticString.d.ts +0 -5
  66. package/lib/utils/isStaticString.js +0 -7
  67. package/lib/utils/isStringRawNoSubstitution.d.ts +0 -7
  68. package/lib/utils/isStringRawNoSubstitution.js +0 -9
  69. package/lib/utils/unwrapParentParenthesizedExpressions.d.ts +0 -6
  70. package/lib/utils/unwrapParentParenthesizedExpressions.js +0 -7
  71. package/lib/utils/unwrapParenthesizedNode.d.ts +0 -6
  72. package/lib/utils/unwrapParenthesizedNode.js +0 -7
package/lib/nodes.d.ts DELETED
@@ -1,203 +0,0 @@
1
- import { AnyKeyword, 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, 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, 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 } from "./types/ast.js";
2
- import { WithExitKeys } from "@flint.fyi/core";
3
-
4
- //#region src/nodes.d.ts
5
- interface TypeScriptNodesByName {
6
- AnyKeyword: AnyKeyword;
7
- ArrayBindingPattern: ArrayBindingPattern;
8
- ArrayLiteralExpression: ArrayLiteralExpression;
9
- ArrayType: ArrayTypeNode;
10
- ArrowFunction: ArrowFunction;
11
- AsExpression: AsExpression;
12
- AwaitExpression: AwaitExpression;
13
- BigIntKeyword: BigIntKeyword;
14
- BigIntLiteral: BigIntLiteral;
15
- BinaryExpression: BinaryExpression;
16
- BindingElement: BindingElement;
17
- Block: Block;
18
- BooleanKeyword: BooleanKeyword;
19
- BreakStatement: BreakStatement;
20
- CallExpression: CallExpression;
21
- CallSignature: CallSignatureDeclaration;
22
- CaseBlock: CaseBlock;
23
- CaseClause: CaseClause;
24
- CatchClause: CatchClause;
25
- ClassDeclaration: ClassDeclaration;
26
- ClassExpression: ClassExpression;
27
- ClassStaticBlockDeclaration: ClassStaticBlockDeclaration;
28
- CommaListExpression: CommaListExpression;
29
- ComputedPropertyName: ComputedPropertyName;
30
- ConditionalExpression: ConditionalExpression;
31
- ConditionalType: ConditionalTypeNode;
32
- Constructor: ConstructorDeclaration;
33
- ConstructorType: ConstructorTypeNode;
34
- ConstructSignature: ConstructSignatureDeclaration;
35
- ContinueStatement: ContinueStatement;
36
- DebuggerStatement: DebuggerStatement;
37
- Decorator: Decorator;
38
- DefaultClause: DefaultClause;
39
- DeleteExpression: DeleteExpression;
40
- DoStatement: DoStatement;
41
- ElementAccessExpression: ElementAccessExpression;
42
- EmptyStatement: EmptyStatement;
43
- EnumDeclaration: EnumDeclaration;
44
- EnumMember: EnumMember;
45
- ExportAssignment: ExportAssignment;
46
- ExportDeclaration: ExportDeclaration;
47
- ExportSpecifier: ExportSpecifier;
48
- ExpressionStatement: ExpressionStatement;
49
- ExpressionWithTypeArguments: ExpressionWithTypeArguments;
50
- ExternalModuleReference: ExternalModuleReference;
51
- FalseKeyword: FalseLiteral;
52
- ForInStatement: ForInStatement;
53
- ForOfStatement: ForOfStatement;
54
- ForStatement: ForStatement;
55
- FunctionDeclaration: FunctionDeclaration;
56
- FunctionExpression: FunctionExpression;
57
- FunctionType: FunctionTypeNode;
58
- GetAccessor: GetAccessorDeclaration;
59
- HeritageClause: HeritageClause;
60
- Identifier: Identifier;
61
- IfStatement: IfStatement;
62
- ImportAttribute: ImportAttribute;
63
- ImportAttributes: ImportAttributes;
64
- ImportClause: ImportClause;
65
- ImportDeclaration: ImportDeclaration;
66
- ImportEqualsDeclaration: ImportEqualsDeclaration;
67
- ImportKeyword: ImportExpression;
68
- ImportSpecifier: ImportSpecifier;
69
- ImportType: ImportTypeNode;
70
- IndexedAccessType: IndexedAccessTypeNode;
71
- IndexSignature: IndexSignatureDeclaration;
72
- InferType: InferTypeNode;
73
- InterfaceDeclaration: InterfaceDeclaration;
74
- IntersectionType: IntersectionTypeNode;
75
- IntrinsicKeyword: IntrinsicKeyword;
76
- JSDocAllType: JSDocAllType;
77
- JSDocFunctionType: JSDocFunctionType;
78
- JSDocLink: JSDocLink;
79
- JSDocLinkCode: JSDocLinkCode;
80
- JSDocLinkPlain: JSDocLinkPlain;
81
- JSDocMemberName: JSDocMemberName;
82
- JSDocNamepathType: JSDocNamepathType;
83
- JSDocNonNullableType: JSDocNonNullableType;
84
- JSDocNullableType: JSDocNullableType;
85
- JSDocOptionalType: JSDocOptionalType;
86
- JSDocParameterTag: JSDocParameterTag;
87
- JSDocPropertyTag: JSDocPropertyTag;
88
- JSDocReturnTag: JSDocReturnTag;
89
- JSDocSignature: JSDocSignature;
90
- JSDocTemplateTag: JSDocTemplateTag;
91
- JSDocText: JSDocText;
92
- JSDocTypeExpression: JSDocTypeExpression;
93
- JSDocTypeLiteral: JSDocTypeLiteral;
94
- JSDocUnknownType: JSDocUnknownType;
95
- JSDocVariadicType: JSDocVariadicType;
96
- JsxAttribute: JsxAttribute;
97
- JsxAttributes: JsxAttributes;
98
- JsxClosingElement: JsxClosingElement;
99
- JsxClosingFragment: JsxClosingFragment;
100
- JsxElement: JsxElement;
101
- JsxExpression: JsxExpression;
102
- JsxFragment: JsxFragment;
103
- JsxNamespacedName: JsxNamespacedName;
104
- JsxOpeningElement: JsxOpeningElement;
105
- JsxOpeningFragment: JsxOpeningFragment;
106
- JsxSelfClosingElement: JsxSelfClosingElement;
107
- JsxSpreadAttribute: JsxSpreadAttribute;
108
- JsxText: JsxText;
109
- LabeledStatement: LabeledStatement;
110
- LiteralType: LiteralTypeNode;
111
- MappedType: MappedTypeNode;
112
- MetaProperty: MetaProperty;
113
- MethodDeclaration: MethodDeclaration;
114
- MethodSignature: MethodSignature;
115
- MissingDeclaration: MissingDeclaration;
116
- ModuleBlock: ModuleBlock;
117
- ModuleDeclaration: ModuleDeclaration;
118
- NamedExports: NamedExports;
119
- NamedImports: NamedImports;
120
- NamedTupleMember: NamedTupleMember;
121
- NamespaceExport: NamespaceExport;
122
- NamespaceExportDeclaration: NamespaceExportDeclaration;
123
- NamespaceImport: NamespaceImport;
124
- NeverKeyword: NeverKeyword;
125
- NewExpression: NewExpression;
126
- NonNullExpression: NonNullExpression;
127
- NoSubstitutionTemplateLiteral: NoSubstitutionTemplateLiteral;
128
- NotEmittedStatement: NotEmittedStatement;
129
- NotEmittedTypeElement: NotEmittedTypeElement;
130
- NullKeyword: NullLiteral;
131
- NumberKeyword: NumberKeyword;
132
- NumericLiteral: NumericLiteral;
133
- ObjectBindingPattern: ObjectBindingPattern;
134
- ObjectKeyword: ObjectKeyword;
135
- ObjectLiteralExpression: ObjectLiteralExpression;
136
- OmittedExpression: OmittedExpression;
137
- OptionalType: OptionalTypeNode;
138
- Parameter: ParameterDeclaration;
139
- ParenthesizedExpression: ParenthesizedExpression;
140
- ParenthesizedType: ParenthesizedTypeNode;
141
- PartiallyEmittedExpression: PartiallyEmittedExpression;
142
- PostfixUnaryExpression: PostfixUnaryExpression;
143
- PrefixUnaryExpression: PrefixUnaryExpression;
144
- PrivateIdentifier: PrivateIdentifier;
145
- PropertyAccessExpression: PropertyAccessExpression;
146
- PropertyAssignment: PropertyAssignment;
147
- PropertyDeclaration: PropertyDeclaration;
148
- PropertySignature: PropertySignature;
149
- QualifiedName: QualifiedName;
150
- RegularExpressionLiteral: RegularExpressionLiteral;
151
- RestType: RestTypeNode;
152
- ReturnStatement: ReturnStatement;
153
- SatisfiesExpression: SatisfiesExpression;
154
- SemicolonClassElement: SemicolonClassElement;
155
- SetAccessor: SetAccessorDeclaration;
156
- ShorthandPropertyAssignment: ShorthandPropertyAssignment;
157
- SourceFile: SourceFile;
158
- SpreadAssignment: SpreadAssignment;
159
- SpreadElement: SpreadElement;
160
- StringKeyword: StringKeyword;
161
- StringLiteral: StringLiteral;
162
- SuperKeyword: SuperExpression;
163
- SwitchStatement: SwitchStatement;
164
- SymbolKeyword: SymbolKeyword;
165
- SyntheticExpression: SyntheticExpression;
166
- TaggedTemplateExpression: TaggedTemplateExpression;
167
- TemplateExpression: TemplateExpression;
168
- TemplateHead: TemplateHead;
169
- TemplateLiteralType: TemplateLiteralTypeNode;
170
- TemplateLiteralTypeSpan: TemplateLiteralTypeSpan;
171
- TemplateMiddle: TemplateMiddle;
172
- TemplateSpan: TemplateSpan;
173
- TemplateTail: TemplateTail;
174
- ThisKeyword: ThisExpression;
175
- ThisType: ThisTypeNode;
176
- ThrowStatement: ThrowStatement;
177
- TrueKeyword: TrueLiteral;
178
- TryStatement: TryStatement;
179
- TupleType: TupleTypeNode;
180
- TypeAliasDeclaration: TypeAliasDeclaration;
181
- TypeAssertionExpression: TypeAssertion;
182
- TypeLiteral: TypeLiteralNode;
183
- TypeOfExpression: TypeOfExpression;
184
- TypeOperator: TypeOperatorNode;
185
- TypeParameter: TypeParameterDeclaration;
186
- TypePredicate: TypePredicateNode;
187
- TypeQuery: TypeQueryNode;
188
- TypeReference: TypeReferenceNode;
189
- UndefinedKeyword: UndefinedKeyword;
190
- UnionType: UnionTypeNode;
191
- UnknownKeyword: UnknownKeyword;
192
- VariableDeclaration: VariableDeclaration;
193
- VariableDeclarationList: VariableDeclarationList;
194
- VariableStatement: VariableStatement;
195
- VoidExpression: VoidExpression;
196
- VoidKeyword: VoidKeyword;
197
- WhileStatement: WhileStatement;
198
- WithStatement: WithStatement;
199
- YieldExpression: YieldExpression;
200
- }
201
- type TypeScriptNodeVisitors = WithExitKeys<TypeScriptNodesByName>;
202
- //#endregion
203
- export { TypeScriptNodeVisitors, TypeScriptNodesByName };
@@ -1,3 +0,0 @@
1
- import { type CharacterReportRange, type NormalizedReportRangeObject } from "@flint.fyi/core";
2
- import type * as AST from "./types/ast.ts";
3
- export declare function normalizeRange(original: CharacterReportRange, sourceFile: AST.SourceFile): NormalizedReportRangeObject;
@@ -1,17 +0,0 @@
1
- import { getColumnAndLineOfPosition } from "@flint.fyi/core";
2
- //#region src/normalizeRange.ts
3
- function normalizeRange(original, sourceFile) {
4
- const onCharacters = isNode(original) ? {
5
- begin: original.getStart(sourceFile),
6
- end: original.getEnd()
7
- } : original;
8
- return {
9
- begin: getColumnAndLineOfPosition(sourceFile, onCharacters.begin),
10
- end: getColumnAndLineOfPosition(sourceFile, onCharacters.end)
11
- };
12
- }
13
- function isNode(value) {
14
- return typeof value === "object" && value !== null && "kind" in value;
15
- }
16
- //#endregion
17
- export { normalizeRange };
@@ -1,2 +0,0 @@
1
- import type { LinterHost } from "@flint.fyi/core";
2
- export declare function orderTypeScriptFilePaths(filePaths: readonly string[], host: LinterHost): string[];
@@ -1,90 +0,0 @@
1
- import { createTypeScriptServerHost } from "./createTypeScriptServerHost.js";
2
- import ts from "typescript";
3
- import { normalizePath, pathKey } from "@flint.fyi/utils";
4
- import { dirname, resolve } from "pathe";
5
- //#region src/orderTypeScriptFilePaths.ts
6
- const tsConfigFileName = "tsconfig.json";
7
- function orderTypeScriptFilePaths(filePaths, host) {
8
- if (filePaths.length < 2) return [...filePaths];
9
- const caseSensitiveFS = host.isCaseSensitiveFS();
10
- const cwd = host.getCurrentDirectory();
11
- const parseHost = {
12
- ...createTypeScriptServerHost(host),
13
- onUnRecoverableConfigFileDiagnostic() {}
14
- };
15
- const configByDirectory = /* @__PURE__ */ new Map();
16
- const parsedConfigByPath = /* @__PURE__ */ new Map();
17
- const configByFile = /* @__PURE__ */ new Map();
18
- function comparePaths(a, b) {
19
- return pathKey(a, caseSensitiveFS).localeCompare(pathKey(b, caseSensitiveFS));
20
- }
21
- function findConfigFile(directoryPath) {
22
- const directoryPathNormalized = normalizePath(directoryPath);
23
- const directoryKey = pathKey(directoryPathNormalized, caseSensitiveFS);
24
- if (configByDirectory.has(directoryKey)) return configByDirectory.get(directoryKey);
25
- const configPath = ts.findConfigFile(directoryPathNormalized, (path) => parseHost.fileExists(path), tsConfigFileName);
26
- const normalizedConfigPath = configPath == null ? void 0 : resolve(cwd, configPath);
27
- configByDirectory.set(directoryKey, normalizedConfigPath);
28
- return normalizedConfigPath;
29
- }
30
- function getParsedConfig(configPath) {
31
- const configKey = pathKey(configPath, caseSensitiveFS);
32
- if (parsedConfigByPath.has(configKey)) return parsedConfigByPath.get(configKey);
33
- const parsed = ts.getParsedCommandLineOfConfigFile(configPath, {}, parseHost);
34
- const parsedConfig = parsed == null ? void 0 : {
35
- fileNames: parsed.fileNames.map((fileName) => resolve(cwd, fileName)),
36
- references: (parsed.projectReferences ?? []).map((reference) => resolve(cwd, ts.resolveProjectReferencePath(reference))).sort(comparePaths)
37
- };
38
- parsedConfigByPath.set(configKey, parsedConfig);
39
- return parsedConfig;
40
- }
41
- function collectConfigsTopologically(configPath) {
42
- const orderedConfigs = [];
43
- const seen = /* @__PURE__ */ new Set();
44
- const visiting = /* @__PURE__ */ new Set();
45
- function visit(currentConfigPath) {
46
- const configKey = pathKey(currentConfigPath, caseSensitiveFS);
47
- if (seen.has(configKey) || visiting.has(configKey)) return;
48
- visiting.add(configKey);
49
- for (const reference of getParsedConfig(currentConfigPath)?.references ?? []) visit(reference);
50
- visiting.delete(configKey);
51
- seen.add(configKey);
52
- orderedConfigs.push(currentConfigPath);
53
- }
54
- visit(configPath);
55
- return orderedConfigs;
56
- }
57
- const fileInfos = filePaths.map((original) => {
58
- const absolute = resolve(cwd, original);
59
- const rootConfig = findConfigFile(dirname(absolute));
60
- return {
61
- absolute,
62
- original,
63
- rootConfig,
64
- rootConfigKey: rootConfig == null ? void 0 : pathKey(rootConfig, caseSensitiveFS)
65
- };
66
- });
67
- const rootConfigs = Array.from(new Set(fileInfos.map(({ rootConfig }) => rootConfig).filter((rootConfig) => rootConfig != null))).sort(comparePaths);
68
- const fileInfoByPath = new Map(fileInfos.map((fileInfo) => [pathKey(fileInfo.absolute, caseSensitiveFS), fileInfo]));
69
- const configRanks = /* @__PURE__ */ new Map();
70
- for (const rootConfig of rootConfigs) {
71
- const rootConfigKey = pathKey(rootConfig, caseSensitiveFS);
72
- for (const config of collectConfigsTopologically(rootConfig)) {
73
- const configKey = pathKey(config, caseSensitiveFS);
74
- if (!configRanks.has(configKey)) configRanks.set(configKey, configRanks.size);
75
- for (const fileName of getParsedConfig(config)?.fileNames ?? []) {
76
- const fileInfo = fileInfoByPath.get(pathKey(fileName, caseSensitiveFS));
77
- if (fileInfo?.rootConfigKey !== rootConfigKey) continue;
78
- const fileKey = pathKey(fileInfo.absolute, caseSensitiveFS);
79
- if (!configByFile.has(fileKey)) configByFile.set(fileKey, config);
80
- }
81
- }
82
- }
83
- return fileInfos.toSorted((a, b) => {
84
- const configA = configByFile.get(pathKey(a.absolute, caseSensitiveFS)) ?? a.rootConfig;
85
- const configB = configByFile.get(pathKey(b.absolute, caseSensitiveFS)) ?? b.rootConfig;
86
- return (configA == null ? Number.MAX_SAFE_INTEGER : configRanks.get(pathKey(configA, caseSensitiveFS)) ?? Number.MAX_SAFE_INTEGER) - (configB == null ? Number.MAX_SAFE_INTEGER : configRanks.get(pathKey(configB, caseSensitiveFS)) ?? Number.MAX_SAFE_INTEGER) || comparePaths(a.absolute, b.absolute);
87
- }).map(({ original }) => original);
88
- }
89
- //#endregion
90
- export { orderTypeScriptFilePaths };
package/lib/package.js DELETED
@@ -1,5 +0,0 @@
1
- //#region package.json
2
- var name = "@flint.fyi/typescript-language";
3
- var version = "0.18.4";
4
- //#endregion
5
- export { name, version };
@@ -1,3 +0,0 @@
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;
@@ -1,89 +0,0 @@
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 };
@@ -1,14 +0,0 @@
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 };
@@ -1,153 +0,0 @@
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 };
@@ -1,7 +0,0 @@
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;
@@ -1,64 +0,0 @@
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 };