@flint.fyi/typescript-language 0.0.0 → 0.18.1
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.
- package/LICENSE.md +20 -0
- package/lib/_virtual/_rolldown/runtime.js +13 -0
- package/lib/collectReferencedFilePaths.js +9 -10
- package/lib/convertTypeScriptDiagnosticToLanguageReport.d.ts +18 -0
- package/lib/{convertTypeScriptDiagnosticToLanguageFileDiagnostic.js → convertTypeScriptDiagnosticToLanguageReport.js} +13 -10
- package/lib/createTypeScriptServerHost.d.ts +4 -0
- package/lib/createTypeScriptServerHost.js +99 -0
- package/lib/directives/parseDirectivesFromTypeScriptFile.js +33 -3
- package/lib/getFirstEnumValues.js +1 -1
- package/lib/getTSNodeRange.js +1 -1
- package/lib/getTypeScriptFileCacheImpacts.d.ts +4 -0
- package/lib/getTypeScriptFileCacheImpacts.js +9 -0
- package/lib/index.d.ts +8 -9
- package/lib/index.js +6 -8
- package/lib/language.d.ts +211 -5
- package/lib/language.js +108 -14
- package/lib/nodes.d.ts +3 -1
- package/lib/normalizeRange.js +1 -2
- package/lib/package.js +7 -0
- package/lib/types/ast.d.ts +2 -2
- package/lib/utils/createRuleTesterTSConfig.d.ts +8 -0
- package/lib/utils/createRuleTesterTSConfig.js +18 -0
- package/lib/utils/declarationIncludesGlobal.js +1 -1
- package/lib/utils/declarationsIncludeGlobal.js +1 -2
- package/lib/utils/getDeclarationsIfGlobal.d.ts +4 -5
- package/lib/utils/getDeclarationsIfGlobal.js +1 -2
- package/lib/utils/getModifyingReferences.d.ts +1 -3
- package/lib/utils/getModifyingReferences.js +13 -11
- package/lib/utils/hasSameTokens.d.ts +2 -2
- package/lib/utils/hasSameTokens.js +4 -5
- package/lib/utils/isBuiltinArrayMethod.d.ts +2 -3
- package/lib/utils/isBuiltinArrayMethod.js +1 -2
- package/lib/utils/isFunction.d.ts +2 -4
- package/lib/utils/isFunction.js +1 -1
- package/lib/utils/isGlobalDeclaration.d.ts +2 -4
- package/lib/utils/isGlobalDeclaration.js +1 -2
- package/lib/utils/isGlobalDeclarationOfName.d.ts +1 -2
- package/lib/utils/isGlobalDeclarationOfName.js +1 -2
- package/lib/utils/isGlobalVariable.d.ts +2 -5
- package/lib/utils/isGlobalVariable.js +1 -2
- package/lib/utils/isInlineArrayCreation.d.ts +0 -1
- package/lib/utils/isInlineArrayCreation.js +1 -2
- package/lib/utils/unwrapParentParenthesizedExpressions.d.ts +2 -2
- package/lib/utils/unwrapParentParenthesizedExpressions.js +4 -5
- package/lib/utils/unwrapParenthesizedNode.d.ts +7 -0
- package/lib/utils/unwrapParenthesizedNode.js +9 -0
- package/package.json +45 -52
- package/lib/_virtual/rolldown_runtime.js +0 -18
- package/lib/convertTypeScriptDiagnosticToLanguageFileDiagnostic.d.ts +0 -18
- package/lib/createTypeScriptFileFromProgram.d.ts +0 -12
- package/lib/createTypeScriptFileFromProgram.js +0 -41
- package/lib/createTypeScriptFileFromProjectService.d.ts +0 -8
- package/lib/createTypeScriptFileFromProjectService.js +0 -16
- package/lib/lib/convertTypeScriptDiagnosticToLanguageFileDiagnostic.d.ts +0 -2
- package/lib/lib/createTypeScriptFileFromProgram.d.ts +0 -5
- package/lib/lib/directives/parseDirectivesFromTypeScriptFile.d.ts +0 -2
- package/lib/lib/getTSNodeRange.d.ts +0 -3
- package/lib/lib/index.d.ts +0 -21
- package/lib/lib/language.d.ts +0 -5
- package/lib/lib/nodes.d.ts +0 -1
- package/lib/lib/prepareTypeScriptBasedLanguage.d.ts +0 -2
- package/lib/lib/types/ast.d.ts +0 -2066
- package/lib/lib/types/checker.d.ts +0 -23
- package/lib/lib/utils/declarationIncludesGlobal.d.ts +0 -1
- package/lib/lib/utils/getDeclarationsIfGlobal.d.ts +0 -2
- package/lib/lib/utils/getModifyingReferences.d.ts +0 -3
- package/lib/lib/utils/hasSameTokens.d.ts +0 -1
- package/lib/lib/utils/isBuiltinArrayMethod.d.ts +0 -2
- package/lib/lib/utils/isFunction.d.ts +0 -1
- package/lib/lib/utils/isGlobalDeclaration.d.ts +0 -1
- package/lib/lib/utils/isGlobalDeclarationOfName.d.ts +0 -2
- package/lib/lib/utils/isGlobalVariable.d.ts +0 -1
- package/lib/lib/utils/isInlineArrayCreation.d.ts +0 -1
- package/lib/lib/utils/unwrapParentParenthesizedExpressions.d.ts +0 -1
- package/lib/lib/utils/unwrapParenthesizedExpression.d.ts +0 -1
- package/lib/prepareTypeScriptBasedLanguage.d.ts +0 -16
- package/lib/prepareTypeScriptBasedLanguage.js +0 -55
- package/lib/prepareTypeScriptFile.d.ts +0 -14
- package/lib/prepareTypeScriptFile.js +0 -18
- package/lib/utils/unwrapParenthesizedExpression.d.ts +0 -7
- package/lib/utils/unwrapParenthesizedExpression.js +0 -10
package/lib/language.js
CHANGED
|
@@ -1,23 +1,117 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { convertTypeScriptDiagnosticToLanguageReport } from "./convertTypeScriptDiagnosticToLanguageReport.js";
|
|
2
|
+
import { parseDirectivesFromTypeScriptFile } from "./directives/parseDirectivesFromTypeScriptFile.js";
|
|
3
|
+
import { name, version } from "./package.js";
|
|
4
|
+
import { createTypeScriptServerHost } from "./createTypeScriptServerHost.js";
|
|
5
|
+
import { getFirstEnumValues } from "./getFirstEnumValues.js";
|
|
6
|
+
import { getTypeScriptFileCacheImpacts } from "./getTypeScriptFileCacheImpacts.js";
|
|
3
7
|
import { createLanguage } from "@flint.fyi/core";
|
|
4
|
-
|
|
8
|
+
import * as ts$1 from "typescript";
|
|
9
|
+
import { assert, nullThrows } from "@flint.fyi/utils";
|
|
10
|
+
import { createProjectService } from "@typescript-eslint/project-service";
|
|
11
|
+
import { debugForFile } from "debug-for-file";
|
|
12
|
+
import path from "node:path";
|
|
5
13
|
//#region src/language.ts
|
|
14
|
+
const log = debugForFile(import.meta.filename);
|
|
15
|
+
const NodeSyntaxKinds = getFirstEnumValues(ts$1.SyntaxKind);
|
|
16
|
+
const stateSymbol = Symbol.for("@flint.fyi/typescript-language/state");
|
|
17
|
+
const globalTyped = globalThis;
|
|
18
|
+
assert(globalTyped[stateSymbol] == null, `Two different versions of ${name} are imported: ${version} and ${globalTyped[stateSymbol]?.packageVersion}`);
|
|
19
|
+
const languageState = globalTyped[stateSymbol] = {
|
|
20
|
+
packageVersion: version,
|
|
21
|
+
volarCreateFile: null
|
|
22
|
+
};
|
|
23
|
+
function setVolarCreateFile(create) {
|
|
24
|
+
assert(languageState.volarCreateFile == null, "setVolarCreateFile is expected to be called only once");
|
|
25
|
+
languageState.volarCreateFile = create;
|
|
26
|
+
}
|
|
6
27
|
const typescriptLanguage = createLanguage({
|
|
7
28
|
about: { name: "TypeScript" },
|
|
8
|
-
createFileFactory: () => {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
29
|
+
createFileFactory: (host) => {
|
|
30
|
+
const { service } = createProjectService({ host: createTypeScriptServerHost(host) });
|
|
31
|
+
function createFile(data) {
|
|
32
|
+
log("Opening client file:", data.filePathAbsolute);
|
|
33
|
+
service.openClientFile(data.filePathAbsolute);
|
|
34
|
+
log("Retrieving client services:", data.filePathAbsolute);
|
|
35
|
+
const scriptInfo = nullThrows(service.getScriptInfo(data.filePathAbsolute), `Could not find script info for file: ${data.filePathAbsolute}`);
|
|
36
|
+
const program = nullThrows(nullThrows(service.getDefaultProjectForFile(scriptInfo.fileName, true), `Could not find default project for file: ${data.filePathAbsolute}`).getLanguageService(true).getProgram(), `Could not retrieve program for file: ${data.filePathAbsolute}`);
|
|
37
|
+
const sourceFile = nullThrows(program.getSourceFile(data.filePathAbsolute), `Could not retrieve source file for: ${data.filePathAbsolute}`);
|
|
38
|
+
const fileExtension = path.extname(data.filePathAbsolute);
|
|
39
|
+
if (typeScriptCoreSupportedExtensions.has(fileExtension)) return {
|
|
40
|
+
...parseDirectivesFromTypeScriptFile(sourceFile),
|
|
41
|
+
about: data,
|
|
42
|
+
language: typescriptLanguage,
|
|
43
|
+
services: {
|
|
44
|
+
program,
|
|
45
|
+
sourceFile,
|
|
46
|
+
typeChecker: program.getTypeChecker()
|
|
47
|
+
},
|
|
48
|
+
[Symbol.dispose]() {
|
|
49
|
+
service.closeClientFile(data.filePathAbsolute);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
if (languageState.volarCreateFile == null) throwUnknownLanguageExtension(data.filePathAbsolute);
|
|
53
|
+
return {
|
|
54
|
+
...languageState.volarCreateFile(data, program, sourceFile),
|
|
55
|
+
[Symbol.dispose]() {
|
|
56
|
+
service.closeClientFile(data.filePathAbsolute);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return { createFile };
|
|
61
|
+
},
|
|
62
|
+
getFileCacheImpacts: getTypeScriptFileCacheImpacts,
|
|
63
|
+
getLanguageReports(file) {
|
|
64
|
+
if ("__volarServices" in file) return file.__volarServices.getLanguageReports();
|
|
65
|
+
return ts$1.getPreEmitDiagnostics(file.services.program, file.services.sourceFile).map(convertTypeScriptDiagnosticToLanguageReport);
|
|
66
|
+
},
|
|
67
|
+
runFileVisitors(file, options, runtime) {
|
|
68
|
+
if (!runtime.visitors) return;
|
|
69
|
+
if ("__volarServices" in file) {
|
|
70
|
+
file.__volarServices.runVisitors(file, options, runtime);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const { visitors } = runtime;
|
|
74
|
+
const visitorServices = {
|
|
75
|
+
options,
|
|
76
|
+
...file.services
|
|
77
|
+
};
|
|
78
|
+
const visit = (node) => {
|
|
79
|
+
const key = NodeSyntaxKinds[node.kind];
|
|
80
|
+
visitors[key]?.(node, visitorServices);
|
|
81
|
+
node.forEachChild(visit);
|
|
82
|
+
visitors[`${key}:exit`]?.(node, visitorServices);
|
|
17
83
|
};
|
|
84
|
+
visit(file.services.sourceFile);
|
|
18
85
|
}
|
|
19
86
|
});
|
|
20
|
-
|
|
87
|
+
const typeScriptCoreSupportedExtensions = new Set([
|
|
88
|
+
".cjs",
|
|
89
|
+
".cts",
|
|
90
|
+
".d.cts",
|
|
91
|
+
".d.mts",
|
|
92
|
+
".d.ts",
|
|
93
|
+
".js",
|
|
94
|
+
".json",
|
|
95
|
+
".jsx",
|
|
96
|
+
".mjs",
|
|
97
|
+
".mts",
|
|
98
|
+
".ts",
|
|
99
|
+
".tsx"
|
|
100
|
+
]);
|
|
101
|
+
const fileExtToFlintPlugin = {
|
|
102
|
+
".astro": "@flint.fyi/astro",
|
|
103
|
+
".gjs": "@flint.fyi/ember",
|
|
104
|
+
".gts": "@flint.fyi/ember",
|
|
105
|
+
".mdx": "@flint.fyi/mdx",
|
|
106
|
+
".svelte": "@flint.fyi/svelte",
|
|
107
|
+
".vue": "@flint.fyi/vue"
|
|
108
|
+
};
|
|
109
|
+
function throwUnknownLanguageExtension(filename) {
|
|
110
|
+
const pluginName = fileExtToFlintPlugin[path.extname(filename)];
|
|
111
|
+
const message = pluginName ? `Did you install & import ${pluginName}?` : "Unknown extension.";
|
|
112
|
+
throw new Error(`Cannot process ${filename}. ${message}`);
|
|
113
|
+
}
|
|
21
114
|
//#endregion
|
|
22
|
-
export { typescriptLanguage };
|
|
115
|
+
export { NodeSyntaxKinds, setVolarCreateFile, throwUnknownLanguageExtension, typescriptLanguage };
|
|
116
|
+
|
|
23
117
|
//# sourceMappingURL=language.js.map
|
package/lib/nodes.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
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";
|
|
2
3
|
|
|
3
4
|
//#region src/nodes.d.ts
|
|
4
5
|
interface TypeScriptNodesByName {
|
|
@@ -197,6 +198,7 @@ interface TypeScriptNodesByName {
|
|
|
197
198
|
WithStatement: WithStatement;
|
|
198
199
|
YieldExpression: YieldExpression;
|
|
199
200
|
}
|
|
201
|
+
type TypeScriptNodeVisitors = WithExitKeys<TypeScriptNodesByName>;
|
|
200
202
|
//#endregion
|
|
201
|
-
export { TypeScriptNodesByName };
|
|
203
|
+
export { TypeScriptNodeVisitors, TypeScriptNodesByName };
|
|
202
204
|
//# sourceMappingURL=nodes.d.ts.map
|
package/lib/normalizeRange.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { getColumnAndLineOfPosition } from "@flint.fyi/core";
|
|
2
|
-
|
|
3
2
|
//#region src/normalizeRange.ts
|
|
4
3
|
function normalizeRange(original, sourceFile) {
|
|
5
4
|
const onCharacters = isNode(original) ? {
|
|
@@ -14,7 +13,7 @@ function normalizeRange(original, sourceFile) {
|
|
|
14
13
|
function isNode(value) {
|
|
15
14
|
return typeof value === "object" && value !== null && "kind" in value;
|
|
16
15
|
}
|
|
17
|
-
|
|
18
16
|
//#endregion
|
|
19
17
|
export { normalizeRange };
|
|
18
|
+
|
|
20
19
|
//# sourceMappingURL=normalizeRange.js.map
|
package/lib/package.js
ADDED
package/lib/types/ast.d.ts
CHANGED
|
@@ -1689,7 +1689,7 @@ interface SourceFile extends ts.Node {
|
|
|
1689
1689
|
*
|
|
1690
1690
|
* Note that this field is only set by the module resolution process when
|
|
1691
1691
|
* `moduleResolution` is `Node16` or `NodeNext`, which is implied by the `module` setting
|
|
1692
|
-
* of `Node16` or `NodeNext`, respectively, but may be
|
|
1692
|
+
* of `Node16` or `NodeNext`, respectively, but may be overridden (eg, by a `moduleResolution`
|
|
1693
1693
|
* of `node`). If so, this field will be unset and source files will be considered to be
|
|
1694
1694
|
* CommonJS-output-format by the node module transformer and type checker, regardless of extension or context.
|
|
1695
1695
|
*/
|
|
@@ -2066,5 +2066,5 @@ type ModifierParent = AccessorDeclaration | ArrowFunction | ClassDeclaration | C
|
|
|
2066
2066
|
type StatementParent = Block | CaseOrDefaultClause | IfStatement | IterationStatement | LabeledStatement | ModuleBlock | SourceFile | WithStatement;
|
|
2067
2067
|
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
2068
|
//#endregion
|
|
2069
|
-
export { AnyKeyword, ArrayBindingPattern, ArrayLiteralExpression, ArrayTypeNode, ArrowFunction, AsExpression, AwaitExpression, BigIntKeyword, BigIntLiteral, BinaryExpression, BindingElement, Block, BooleanKeyword, BreakStatement, CallExpression, CallSignatureDeclaration, CaseBlock, CaseClause, CatchClause, ClassDeclaration, ClassExpression, ClassStaticBlockDeclaration, CommaListExpression, ComputedPropertyName,
|
|
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
2070
|
//# sourceMappingURL=ast.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/utils/createRuleTesterTSConfig.d.ts
|
|
2
|
+
declare function createRuleTesterTSConfig(defaultCompilerOptions?: Record<string, unknown>): {
|
|
3
|
+
"tsconfig.base.json": string;
|
|
4
|
+
"tsconfig.json": string;
|
|
5
|
+
};
|
|
6
|
+
//#endregion
|
|
7
|
+
export { createRuleTesterTSConfig };
|
|
8
|
+
//# sourceMappingURL=createRuleTesterTSConfig.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/utils/createRuleTesterTSConfig.ts
|
|
2
|
+
function createRuleTesterTSConfig(defaultCompilerOptions) {
|
|
3
|
+
return {
|
|
4
|
+
"tsconfig.base.json": JSON.stringify({ compilerOptions: {
|
|
5
|
+
lib: ["esnext"],
|
|
6
|
+
moduleResolution: "bundler",
|
|
7
|
+
strict: true,
|
|
8
|
+
target: "esnext",
|
|
9
|
+
types: [],
|
|
10
|
+
...defaultCompilerOptions
|
|
11
|
+
} }, null, 2),
|
|
12
|
+
"tsconfig.json": JSON.stringify({ extends: "./tsconfig.base.json" }, null, 2)
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { createRuleTesterTSConfig };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=createRuleTesterTSConfig.js.map
|
|
@@ -3,7 +3,7 @@ function declarationIncludesGlobal(declaration) {
|
|
|
3
3
|
const sourceFile = declaration.getSourceFile();
|
|
4
4
|
return sourceFile.hasNoDefaultLib || /\/lib\.[^/]*\.d\.ts$/.test(sourceFile.fileName);
|
|
5
5
|
}
|
|
6
|
-
|
|
7
6
|
//#endregion
|
|
8
7
|
export { declarationIncludesGlobal };
|
|
8
|
+
|
|
9
9
|
//# sourceMappingURL=declarationIncludesGlobal.js.map
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { declarationIncludesGlobal } from "./declarationIncludesGlobal.js";
|
|
2
|
-
|
|
3
2
|
//#region src/utils/declarationsIncludeGlobal.ts
|
|
4
3
|
function declarationsIncludeGlobal(declarations) {
|
|
5
4
|
return declarations.some(declarationIncludesGlobal);
|
|
6
5
|
}
|
|
7
|
-
|
|
8
6
|
//#endregion
|
|
9
7
|
export { declarationsIncludeGlobal };
|
|
8
|
+
|
|
10
9
|
//# sourceMappingURL=declarationsIncludeGlobal.js.map
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Expression } from "../
|
|
2
|
-
import { Checker } from "../
|
|
3
|
-
import "
|
|
4
|
-
import * as typescript0 from "typescript";
|
|
1
|
+
import { Expression } from "../types/ast.js";
|
|
2
|
+
import { Checker } from "../types/checker.js";
|
|
3
|
+
import * as typescript from "typescript";
|
|
5
4
|
|
|
6
5
|
//#region src/utils/getDeclarationsIfGlobal.d.ts
|
|
7
|
-
declare function getDeclarationsIfGlobal(node: Expression, typeChecker: Checker):
|
|
6
|
+
declare function getDeclarationsIfGlobal(node: Expression, typeChecker: Checker): typescript.Declaration[] | undefined;
|
|
8
7
|
//#endregion
|
|
9
8
|
export { getDeclarationsIfGlobal };
|
|
10
9
|
//# sourceMappingURL=getDeclarationsIfGlobal.d.ts.map
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { declarationsIncludeGlobal } from "./declarationsIncludeGlobal.js";
|
|
2
|
-
|
|
3
2
|
//#region src/utils/getDeclarationsIfGlobal.ts
|
|
4
3
|
function getDeclarationsIfGlobal(node, typeChecker) {
|
|
5
4
|
const declarations = typeChecker.getSymbolAtLocation(node)?.getDeclarations();
|
|
6
5
|
return !!declarations && declarationsIncludeGlobal(declarations) ? declarations : void 0;
|
|
7
6
|
}
|
|
8
|
-
|
|
9
7
|
//#endregion
|
|
10
8
|
export { getDeclarationsIfGlobal };
|
|
9
|
+
|
|
11
10
|
//# sourceMappingURL=getDeclarationsIfGlobal.js.map
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { Identifier, SourceFile } from "../types/ast.js";
|
|
2
|
-
import { Checker } from "../
|
|
3
|
-
import "../lib/index.js";
|
|
2
|
+
import { Checker } from "../types/checker.js";
|
|
4
3
|
import ts from "typescript";
|
|
5
4
|
|
|
6
5
|
//#region src/utils/getModifyingReferences.d.ts
|
|
7
|
-
|
|
8
6
|
/**
|
|
9
7
|
* Gets all references to a variable that modify it (assignments, increments, decrements).
|
|
10
8
|
*
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
import * as tsutils from "ts-api-utils";
|
|
3
|
-
|
|
4
3
|
//#region src/utils/getModifyingReferences.ts
|
|
5
4
|
/**
|
|
6
5
|
* Gets all references to a variable that modify it (assignments, increments, decrements).
|
|
@@ -11,23 +10,26 @@ import * as tsutils from "ts-api-utils";
|
|
|
11
10
|
function getModifyingReferences(identifier, sourceFile, typeChecker) {
|
|
12
11
|
const symbol = typeChecker.getSymbolAtLocation(identifier);
|
|
13
12
|
if (!symbol?.valueDeclaration) return [];
|
|
14
|
-
const valueDeclaration = symbol
|
|
13
|
+
const { valueDeclaration } = symbol;
|
|
15
14
|
const modifyingReferences = [];
|
|
16
|
-
function
|
|
17
|
-
if (ts.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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;
|
|
24
23
|
}
|
|
24
|
+
}
|
|
25
|
+
function visit(node) {
|
|
26
|
+
if (isIdentifierForSameSymbol(node)) modifyingReferences.push(node);
|
|
25
27
|
ts.forEachChild(node, visit);
|
|
26
28
|
}
|
|
27
29
|
visit(sourceFile);
|
|
28
30
|
return modifyingReferences;
|
|
29
31
|
}
|
|
30
|
-
|
|
31
32
|
//#endregion
|
|
32
33
|
export { getModifyingReferences };
|
|
34
|
+
|
|
33
35
|
//# sourceMappingURL=getModifyingReferences.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyNode, SourceFile } from "../types/ast.js";
|
|
2
2
|
|
|
3
3
|
//#region src/utils/hasSameTokens.d.ts
|
|
4
|
-
declare function hasSameTokens(nodeA:
|
|
4
|
+
declare function hasSameTokens(nodeA: AnyNode, nodeB: AnyNode, sourceFile: SourceFile): boolean;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { hasSameTokens };
|
|
7
7
|
//# sourceMappingURL=hasSameTokens.d.ts.map
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { unwrapParenthesizedNode } from "./unwrapParenthesizedNode.js";
|
|
2
2
|
import ts from "typescript";
|
|
3
|
-
|
|
4
3
|
//#region src/utils/hasSameTokens.ts
|
|
5
4
|
function hasSameTokens(nodeA, nodeB, sourceFile) {
|
|
6
|
-
const queueA = [
|
|
7
|
-
const queueB = [
|
|
5
|
+
const queueA = [unwrapParenthesizedNode(nodeA)];
|
|
6
|
+
const queueB = [unwrapParenthesizedNode(nodeB)];
|
|
8
7
|
while (true) {
|
|
9
8
|
const currentA = queueA.shift();
|
|
10
9
|
const currentB = queueB.shift();
|
|
@@ -27,7 +26,7 @@ function areSameToken(nodeA, nodeB, sourceFile) {
|
|
|
27
26
|
if (nodeA.kind === ts.SyntaxKind.RegularExpressionLiteral) return sourceFile.text.slice(nodeA.getStart(sourceFile), nodeA.getEnd()) === sourceFile.text.slice(nodeB.getStart(sourceFile), nodeB.getEnd());
|
|
28
27
|
return true;
|
|
29
28
|
}
|
|
30
|
-
|
|
31
29
|
//#endregion
|
|
32
30
|
export { hasSameTokens };
|
|
31
|
+
|
|
33
32
|
//# sourceMappingURL=hasSameTokens.js.map
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { CallExpression, PropertyAccessExpression } from "../
|
|
2
|
-
import { Checker } from "../
|
|
3
|
-
import "../lib/index.js";
|
|
1
|
+
import { CallExpression, PropertyAccessExpression } from "../types/ast.js";
|
|
2
|
+
import { Checker } from "../types/checker.js";
|
|
4
3
|
import ts from "typescript";
|
|
5
4
|
|
|
6
5
|
//#region src/utils/isBuiltinArrayMethod.d.ts
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
|
-
|
|
3
2
|
//#region src/utils/isBuiltinArrayMethod.ts
|
|
4
3
|
function isBuiltinArrayMethod(name, node, typeChecker) {
|
|
5
4
|
return ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === name && typeChecker.isArrayType(typeChecker.getTypeAtLocation(node.expression.expression)) && !ts.isExpressionStatement(node.parent);
|
|
6
5
|
}
|
|
7
|
-
|
|
8
6
|
//#endregion
|
|
9
7
|
export { isBuiltinArrayMethod };
|
|
8
|
+
|
|
10
9
|
//# sourceMappingURL=isBuiltinArrayMethod.js.map
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { Expression } from "../
|
|
2
|
-
import { Checker } from "../
|
|
3
|
-
import "../lib/index.js";
|
|
4
|
-
|
|
1
|
+
import { Expression } from "../types/ast.js";
|
|
2
|
+
import { Checker } from "../types/checker.js";
|
|
5
3
|
//#region src/utils/isFunction.d.ts
|
|
6
4
|
declare function isFunction(node: Expression, typeChecker: Checker): boolean;
|
|
7
5
|
//#endregion
|
package/lib/utils/isFunction.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { Expression } from "../
|
|
2
|
-
import { Checker } from "../
|
|
3
|
-
import "../lib/index.js";
|
|
4
|
-
|
|
1
|
+
import { Expression } from "../types/ast.js";
|
|
2
|
+
import { Checker } from "../types/checker.js";
|
|
5
3
|
//#region src/utils/isGlobalDeclaration.d.ts
|
|
6
4
|
declare function isGlobalDeclaration(node: Expression, typeChecker: Checker): boolean;
|
|
7
5
|
//#endregion
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { getDeclarationsIfGlobal } from "./getDeclarationsIfGlobal.js";
|
|
2
|
-
|
|
3
2
|
//#region src/utils/isGlobalDeclaration.ts
|
|
4
3
|
function isGlobalDeclaration(node, typeChecker) {
|
|
5
4
|
return !!getDeclarationsIfGlobal(node, typeChecker);
|
|
6
5
|
}
|
|
7
|
-
|
|
8
6
|
//#endregion
|
|
9
7
|
export { isGlobalDeclaration };
|
|
8
|
+
|
|
10
9
|
//# sourceMappingURL=isGlobalDeclaration.js.map
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { declarationIncludesGlobal } from "./declarationIncludesGlobal.js";
|
|
2
2
|
import ts from "typescript";
|
|
3
|
-
|
|
4
3
|
//#region src/utils/isGlobalDeclarationOfName.ts
|
|
5
4
|
/**
|
|
6
5
|
* TODO: Use a scope analyzer (#400).
|
|
@@ -18,7 +17,7 @@ function isDeclarationOfName(node, name) {
|
|
|
18
17
|
if (ts.isClassDeclaration(node) || ts.isFunctionDeclaration(node) || ts.isInterfaceDeclaration(node) || ts.isVariableDeclaration(node)) return node.name && ts.isIdentifier(node.name) && node.name.text === name;
|
|
19
18
|
return false;
|
|
20
19
|
}
|
|
21
|
-
|
|
22
20
|
//#endregion
|
|
23
21
|
export { isGlobalDeclarationOfName };
|
|
22
|
+
|
|
24
23
|
//# sourceMappingURL=isGlobalDeclarationOfName.js.map
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { Expression } from "../
|
|
2
|
-
import { Checker } from "../
|
|
3
|
-
import "../lib/index.js";
|
|
4
|
-
|
|
1
|
+
import { Expression } from "../types/ast.js";
|
|
2
|
+
import { Checker } from "../types/checker.js";
|
|
5
3
|
//#region src/utils/isGlobalVariable.d.ts
|
|
6
|
-
|
|
7
4
|
/**
|
|
8
5
|
* Checks if a node is a reference to a global variable (e.g., Object, undefined, NaN).
|
|
9
6
|
* Global variables are those declared in TypeScript's lib files or are global identifiers
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { declarationsIncludeGlobal } from "./declarationsIncludeGlobal.js";
|
|
2
|
-
|
|
3
2
|
//#region src/utils/isGlobalVariable.ts
|
|
4
3
|
/**
|
|
5
4
|
* Checks if a node is a reference to a global variable (e.g., Object, undefined, NaN).
|
|
@@ -14,7 +13,7 @@ function isGlobalVariable(node, typeChecker) {
|
|
|
14
13
|
if (!declarations?.length) return true;
|
|
15
14
|
return declarationsIncludeGlobal(declarations);
|
|
16
15
|
}
|
|
17
|
-
|
|
18
16
|
//#endregion
|
|
19
17
|
export { isGlobalVariable };
|
|
18
|
+
|
|
20
19
|
//# sourceMappingURL=isGlobalVariable.js.map
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as ts$1 from "typescript";
|
|
2
|
-
|
|
3
2
|
//#region src/utils/isInlineArrayCreation.ts
|
|
4
3
|
const methodsReturningNewArray = new Set([
|
|
5
4
|
"concat",
|
|
@@ -40,7 +39,7 @@ function isInlineArrayCreation(node) {
|
|
|
40
39
|
if (ts$1.isNewExpression(node) && ts$1.isIdentifier(node.expression) && node.expression.text === "Array") return true;
|
|
41
40
|
return false;
|
|
42
41
|
}
|
|
43
|
-
|
|
44
42
|
//#endregion
|
|
45
43
|
export { isInlineArrayCreation };
|
|
44
|
+
|
|
46
45
|
//# sourceMappingURL=isInlineArrayCreation.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BinaryExpression, LeftHandSideExpressionParent, ParenthesizedExpression } from "../types/ast.js";
|
|
2
2
|
|
|
3
3
|
//#region src/utils/unwrapParentParenthesizedExpressions.d.ts
|
|
4
|
-
declare function
|
|
4
|
+
declare function unwrapParentParenthesizedExpressions(node: BinaryExpression | ParenthesizedExpression): LeftHandSideExpressionParent;
|
|
5
5
|
//#endregion
|
|
6
|
-
export {
|
|
6
|
+
export { unwrapParentParenthesizedExpressions };
|
|
7
7
|
//# sourceMappingURL=unwrapParentParenthesizedExpressions.d.ts.map
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { SyntaxKind } from "typescript";
|
|
2
|
-
|
|
3
2
|
//#region src/utils/unwrapParentParenthesizedExpressions.ts
|
|
4
|
-
function
|
|
5
|
-
return node.parent.kind === SyntaxKind.ParenthesizedExpression ?
|
|
3
|
+
function unwrapParentParenthesizedExpressions(node) {
|
|
4
|
+
return node.parent.kind === SyntaxKind.ParenthesizedExpression ? unwrapParentParenthesizedExpressions(node.parent) : node.parent;
|
|
6
5
|
}
|
|
7
|
-
|
|
8
6
|
//#endregion
|
|
9
|
-
export {
|
|
7
|
+
export { unwrapParentParenthesizedExpressions };
|
|
8
|
+
|
|
10
9
|
//# sourceMappingURL=unwrapParentParenthesizedExpressions.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AnyNode } from "../types/ast.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/unwrapParenthesizedNode.d.ts
|
|
4
|
+
declare function unwrapParenthesizedNode(node: AnyNode): AnyNode;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { unwrapParenthesizedNode };
|
|
7
|
+
//# sourceMappingURL=unwrapParenthesizedNode.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SyntaxKind } from "typescript";
|
|
2
|
+
//#region src/utils/unwrapParenthesizedNode.ts
|
|
3
|
+
function unwrapParenthesizedNode(node) {
|
|
4
|
+
return node.kind === SyntaxKind.ParenthesizedExpression ? unwrapParenthesizedNode(node.expression) : node;
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { unwrapParenthesizedNode };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=unwrapParenthesizedNode.js.map
|