@flint.fyi/typescript-language 0.0.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.
- package/README.md +9 -0
- package/lib/_virtual/rolldown_runtime.js +18 -0
- package/lib/collectReferencedFilePaths.d.ts +4 -0
- package/lib/collectReferencedFilePaths.js +41 -0
- package/lib/convertTypeScriptDiagnosticToLanguageFileDiagnostic.d.ts +18 -0
- package/lib/convertTypeScriptDiagnosticToLanguageFileDiagnostic.js +110 -0
- package/lib/createTypeScriptFileFromProgram.d.ts +12 -0
- package/lib/createTypeScriptFileFromProgram.js +41 -0
- package/lib/createTypeScriptFileFromProjectService.d.ts +8 -0
- package/lib/createTypeScriptFileFromProjectService.js +16 -0
- package/lib/directives/parseDirectivesFromTypeScriptFile.d.ts +13 -0
- package/lib/directives/parseDirectivesFromTypeScriptFile.js +36 -0
- package/lib/getFirstEnumValues.d.ts +36 -0
- package/lib/getFirstEnumValues.js +48 -0
- package/lib/getTSNodeRange.d.ts +9 -0
- package/lib/getTSNodeRange.js +11 -0
- package/lib/index.d.ts +22 -0
- package/lib/index.js +20 -0
- package/lib/language.d.ts +16 -0
- package/lib/language.js +23 -0
- package/lib/lib/convertTypeScriptDiagnosticToLanguageFileDiagnostic.d.ts +2 -0
- package/lib/lib/createTypeScriptFileFromProgram.d.ts +5 -0
- package/lib/lib/directives/parseDirectivesFromTypeScriptFile.d.ts +2 -0
- package/lib/lib/getTSNodeRange.d.ts +3 -0
- package/lib/lib/index.d.ts +21 -0
- package/lib/lib/language.d.ts +5 -0
- package/lib/lib/nodes.d.ts +1 -0
- package/lib/lib/prepareTypeScriptBasedLanguage.d.ts +2 -0
- package/lib/lib/types/ast.d.ts +2066 -0
- package/lib/lib/types/checker.d.ts +23 -0
- package/lib/lib/utils/declarationIncludesGlobal.d.ts +1 -0
- package/lib/lib/utils/getDeclarationsIfGlobal.d.ts +2 -0
- package/lib/lib/utils/getModifyingReferences.d.ts +3 -0
- package/lib/lib/utils/hasSameTokens.d.ts +1 -0
- package/lib/lib/utils/isBuiltinArrayMethod.d.ts +2 -0
- package/lib/lib/utils/isFunction.d.ts +1 -0
- package/lib/lib/utils/isGlobalDeclaration.d.ts +1 -0
- package/lib/lib/utils/isGlobalDeclarationOfName.d.ts +2 -0
- package/lib/lib/utils/isGlobalVariable.d.ts +1 -0
- package/lib/lib/utils/isInlineArrayCreation.d.ts +1 -0
- package/lib/lib/utils/unwrapParentParenthesizedExpressions.d.ts +1 -0
- package/lib/lib/utils/unwrapParenthesizedExpression.d.ts +1 -0
- package/lib/nodes.d.ts +202 -0
- package/lib/normalizeRange.d.ts +4 -0
- package/lib/normalizeRange.js +20 -0
- package/lib/prepareTypeScriptBasedLanguage.d.ts +16 -0
- package/lib/prepareTypeScriptBasedLanguage.js +55 -0
- package/lib/prepareTypeScriptFile.d.ts +14 -0
- package/lib/prepareTypeScriptFile.js +18 -0
- package/lib/types/ast.d.ts +2070 -0
- package/lib/types/checker.d.ts +23 -0
- package/lib/utils/declarationIncludesGlobal.d.ts +7 -0
- package/lib/utils/declarationIncludesGlobal.js +9 -0
- package/lib/utils/declarationsIncludeGlobal.d.ts +3 -0
- package/lib/utils/declarationsIncludeGlobal.js +10 -0
- package/lib/utils/getDeclarationsIfGlobal.d.ts +10 -0
- package/lib/utils/getDeclarationsIfGlobal.js +11 -0
- package/lib/utils/getModifyingReferences.d.ts +17 -0
- package/lib/utils/getModifyingReferences.js +33 -0
- package/lib/utils/hasSameTokens.d.ts +7 -0
- package/lib/utils/hasSameTokens.js +33 -0
- package/lib/utils/isBuiltinArrayMethod.d.ts +15 -0
- package/lib/utils/isBuiltinArrayMethod.js +10 -0
- package/lib/utils/isFunction.d.ts +9 -0
- package/lib/utils/isFunction.js +8 -0
- package/lib/utils/isGlobalDeclaration.d.ts +9 -0
- package/lib/utils/isGlobalDeclaration.js +10 -0
- package/lib/utils/isGlobalDeclarationOfName.d.ts +12 -0
- package/lib/utils/isGlobalDeclarationOfName.js +24 -0
- package/lib/utils/isGlobalVariable.d.ts +16 -0
- package/lib/utils/isGlobalVariable.js +20 -0
- package/lib/utils/isInlineArrayCreation.d.ts +13 -0
- package/lib/utils/isInlineArrayCreation.js +46 -0
- package/lib/utils/unwrapParentParenthesizedExpressions.d.ts +7 -0
- package/lib/utils/unwrapParentParenthesizedExpressions.js +10 -0
- package/lib/utils/unwrapParenthesizedExpression.d.ts +7 -0
- package/lib/utils/unwrapParenthesizedExpression.js +10 -0
- package/package.json +53 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CallExpression, Decorator, JsxOpeningElement, JsxSelfClosingElement, NewExpression, TaggedTemplateExpression } from "./ast.js";
|
|
2
|
+
import ts, { Node, Signature, TupleTypeReference, Type, TypeChecker, TypeReference } from "typescript";
|
|
3
|
+
|
|
4
|
+
//#region src/types/checker.d.ts
|
|
5
|
+
type Checker = CheckerOverrides & Omit<TypeChecker, keyof CheckerOverrides>;
|
|
6
|
+
interface CheckerOverrides {
|
|
7
|
+
getResolvedSignature(node: CallExpression | Decorator | JsxOpeningElement | JsxSelfClosingElement | NewExpression | TaggedTemplateExpression | ts.CallLikeExpression): Signature | undefined;
|
|
8
|
+
/** Improve narrowing, borrow from typescript-eslint */
|
|
9
|
+
isArrayType(type: Type): type is TypeReference;
|
|
10
|
+
isTupleType(type: Type): type is TupleTypeReference;
|
|
11
|
+
/**
|
|
12
|
+
* TS internal api
|
|
13
|
+
* Return the type of the given property in the given type, or undefined if no such property exists
|
|
14
|
+
*/
|
|
15
|
+
getTypeOfPropertyOfType(type: Type, propertyName: string): Type | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* TS internal api
|
|
18
|
+
*/
|
|
19
|
+
getContextualTypeForArgumentAtIndex(node: Node, argIndex: number): Type;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { Checker };
|
|
23
|
+
//# sourceMappingURL=checker.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/declarationIncludesGlobal.d.ts
|
|
4
|
+
declare function declarationIncludesGlobal(declaration: ts.Declaration): boolean;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { declarationIncludesGlobal };
|
|
7
|
+
//# sourceMappingURL=declarationIncludesGlobal.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/utils/declarationIncludesGlobal.ts
|
|
2
|
+
function declarationIncludesGlobal(declaration) {
|
|
3
|
+
const sourceFile = declaration.getSourceFile();
|
|
4
|
+
return sourceFile.hasNoDefaultLib || /\/lib\.[^/]*\.d\.ts$/.test(sourceFile.fileName);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
export { declarationIncludesGlobal };
|
|
9
|
+
//# sourceMappingURL=declarationIncludesGlobal.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { declarationIncludesGlobal } from "./declarationIncludesGlobal.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/declarationsIncludeGlobal.ts
|
|
4
|
+
function declarationsIncludeGlobal(declarations) {
|
|
5
|
+
return declarations.some(declarationIncludesGlobal);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
export { declarationsIncludeGlobal };
|
|
10
|
+
//# sourceMappingURL=declarationsIncludeGlobal.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Expression } from "../lib/types/ast.js";
|
|
2
|
+
import { Checker } from "../lib/types/checker.js";
|
|
3
|
+
import "../lib/index.js";
|
|
4
|
+
import * as typescript0 from "typescript";
|
|
5
|
+
|
|
6
|
+
//#region src/utils/getDeclarationsIfGlobal.d.ts
|
|
7
|
+
declare function getDeclarationsIfGlobal(node: Expression, typeChecker: Checker): typescript0.Declaration[] | undefined;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { getDeclarationsIfGlobal };
|
|
10
|
+
//# sourceMappingURL=getDeclarationsIfGlobal.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { declarationsIncludeGlobal } from "./declarationsIncludeGlobal.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/getDeclarationsIfGlobal.ts
|
|
4
|
+
function getDeclarationsIfGlobal(node, typeChecker) {
|
|
5
|
+
const declarations = typeChecker.getSymbolAtLocation(node)?.getDeclarations();
|
|
6
|
+
return !!declarations && declarationsIncludeGlobal(declarations) ? declarations : void 0;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
export { getDeclarationsIfGlobal };
|
|
11
|
+
//# sourceMappingURL=getDeclarationsIfGlobal.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Identifier, SourceFile } from "../types/ast.js";
|
|
2
|
+
import { Checker } from "../lib/types/checker.js";
|
|
3
|
+
import "../lib/index.js";
|
|
4
|
+
import ts from "typescript";
|
|
5
|
+
|
|
6
|
+
//#region src/utils/getModifyingReferences.d.ts
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Gets all references to a variable that modify it (assignments, increments, decrements).
|
|
10
|
+
*
|
|
11
|
+
* TODO: Replace with a proper scope manager when available (see #400).
|
|
12
|
+
* @returns An array of identifier nodes that modify the variable.
|
|
13
|
+
*/
|
|
14
|
+
declare function getModifyingReferences(identifier: Identifier, sourceFile: SourceFile, typeChecker: Checker): ts.Identifier[];
|
|
15
|
+
//#endregion
|
|
16
|
+
export { getModifyingReferences };
|
|
17
|
+
//# sourceMappingURL=getModifyingReferences.d.ts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import * as tsutils from "ts-api-utils";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/getModifyingReferences.ts
|
|
5
|
+
/**
|
|
6
|
+
* Gets all references to a variable that modify it (assignments, increments, decrements).
|
|
7
|
+
*
|
|
8
|
+
* TODO: Replace with a proper scope manager when available (see #400).
|
|
9
|
+
* @returns An array of identifier nodes that modify the variable.
|
|
10
|
+
*/
|
|
11
|
+
function getModifyingReferences(identifier, sourceFile, typeChecker) {
|
|
12
|
+
const symbol = typeChecker.getSymbolAtLocation(identifier);
|
|
13
|
+
if (!symbol?.valueDeclaration) return [];
|
|
14
|
+
const valueDeclaration = symbol.valueDeclaration;
|
|
15
|
+
const modifyingReferences = [];
|
|
16
|
+
function visit(node) {
|
|
17
|
+
if (ts.isIdentifier(node)) {
|
|
18
|
+
const nodeSymbol = typeChecker.getSymbolAtLocation(node);
|
|
19
|
+
if (nodeSymbol?.valueDeclaration && nodeSymbol.valueDeclaration === valueDeclaration) {
|
|
20
|
+
const parent = node.parent;
|
|
21
|
+
if (ts.isBinaryExpression(parent) && tsutils.isAssignmentKind(parent.operatorToken.kind) && parent.left === node) modifyingReferences.push(node);
|
|
22
|
+
else if ((ts.isPostfixUnaryExpression(parent) || ts.isPrefixUnaryExpression(parent)) && parent.operand === node) modifyingReferences.push(node);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
ts.forEachChild(node, visit);
|
|
26
|
+
}
|
|
27
|
+
visit(sourceFile);
|
|
28
|
+
return modifyingReferences;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { getModifyingReferences };
|
|
33
|
+
//# sourceMappingURL=getModifyingReferences.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Expression, SourceFile } from "../types/ast.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/hasSameTokens.d.ts
|
|
4
|
+
declare function hasSameTokens(nodeA: Expression, nodeB: Expression, sourceFile: SourceFile): boolean;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { hasSameTokens };
|
|
7
|
+
//# sourceMappingURL=hasSameTokens.d.ts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { unwrapParenthesizedExpression } from "./unwrapParenthesizedExpression.js";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/hasSameTokens.ts
|
|
5
|
+
function hasSameTokens(nodeA, nodeB, sourceFile) {
|
|
6
|
+
const queueA = [unwrapParenthesizedExpression(nodeA)];
|
|
7
|
+
const queueB = [unwrapParenthesizedExpression(nodeB)];
|
|
8
|
+
while (true) {
|
|
9
|
+
const currentA = queueA.shift();
|
|
10
|
+
const currentB = queueB.shift();
|
|
11
|
+
if (!currentA || !currentB) break;
|
|
12
|
+
if (currentA.kind !== currentB.kind) return false;
|
|
13
|
+
if (ts.isTokenKind(currentA.kind)) {
|
|
14
|
+
if (!areSameToken(currentA, currentB, sourceFile)) return false;
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
const childrenA = currentA.getChildren(sourceFile);
|
|
18
|
+
const childrenB = currentB.getChildren(sourceFile);
|
|
19
|
+
if (childrenA.length !== childrenB.length) return false;
|
|
20
|
+
queueA.push(...childrenA);
|
|
21
|
+
queueB.push(...childrenB);
|
|
22
|
+
}
|
|
23
|
+
return queueA.length === queueB.length;
|
|
24
|
+
}
|
|
25
|
+
function areSameToken(nodeA, nodeB, sourceFile) {
|
|
26
|
+
if (ts.isIdentifier(nodeA) || ts.isPrivateIdentifier(nodeA) || ts.isNumericLiteral(nodeA) || ts.isBigIntLiteral(nodeA) || ts.isStringLiteral(nodeA) || ts.isNoSubstitutionTemplateLiteral(nodeA)) return nodeA.text === nodeB.text;
|
|
27
|
+
if (nodeA.kind === ts.SyntaxKind.RegularExpressionLiteral) return sourceFile.text.slice(nodeA.getStart(sourceFile), nodeA.getEnd()) === sourceFile.text.slice(nodeB.getStart(sourceFile), nodeB.getEnd());
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { hasSameTokens };
|
|
33
|
+
//# sourceMappingURL=hasSameTokens.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CallExpression, PropertyAccessExpression } from "../lib/types/ast.js";
|
|
2
|
+
import { Checker } from "../lib/types/checker.js";
|
|
3
|
+
import "../lib/index.js";
|
|
4
|
+
import ts from "typescript";
|
|
5
|
+
|
|
6
|
+
//#region src/utils/isBuiltinArrayMethod.d.ts
|
|
7
|
+
type BuiltInArrayMethodNode = CallExpression & {
|
|
8
|
+
expression: PropertyAccessExpression & {
|
|
9
|
+
expression: ts.Expression;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
declare function isBuiltinArrayMethod(name: string, node: CallExpression, typeChecker: Checker): node is BuiltInArrayMethodNode;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { isBuiltinArrayMethod };
|
|
15
|
+
//# sourceMappingURL=isBuiltinArrayMethod.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/isBuiltinArrayMethod.ts
|
|
4
|
+
function isBuiltinArrayMethod(name, node, typeChecker) {
|
|
5
|
+
return ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === name && typeChecker.isArrayType(typeChecker.getTypeAtLocation(node.expression.expression)) && !ts.isExpressionStatement(node.parent);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
export { isBuiltinArrayMethod };
|
|
10
|
+
//# sourceMappingURL=isBuiltinArrayMethod.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Expression } from "../lib/types/ast.js";
|
|
2
|
+
import { Checker } from "../lib/types/checker.js";
|
|
3
|
+
import "../lib/index.js";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/isFunction.d.ts
|
|
6
|
+
declare function isFunction(node: Expression, typeChecker: Checker): boolean;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { isFunction };
|
|
9
|
+
//# sourceMappingURL=isFunction.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Expression } from "../lib/types/ast.js";
|
|
2
|
+
import { Checker } from "../lib/types/checker.js";
|
|
3
|
+
import "../lib/index.js";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/isGlobalDeclaration.d.ts
|
|
6
|
+
declare function isGlobalDeclaration(node: Expression, typeChecker: Checker): boolean;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { isGlobalDeclaration };
|
|
9
|
+
//# sourceMappingURL=isGlobalDeclaration.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { getDeclarationsIfGlobal } from "./getDeclarationsIfGlobal.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/isGlobalDeclaration.ts
|
|
4
|
+
function isGlobalDeclaration(node, typeChecker) {
|
|
5
|
+
return !!getDeclarationsIfGlobal(node, typeChecker);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
export { isGlobalDeclaration };
|
|
10
|
+
//# sourceMappingURL=isGlobalDeclaration.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Checker } from "../lib/types/checker.js";
|
|
2
|
+
import "../lib/index.js";
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/isGlobalDeclarationOfName.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* TODO: Use a scope analyzer (#400).
|
|
8
|
+
*/
|
|
9
|
+
declare function isGlobalDeclarationOfName(node: ts.Node, name: string, typeChecker: Checker): boolean;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { isGlobalDeclarationOfName };
|
|
12
|
+
//# sourceMappingURL=isGlobalDeclarationOfName.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { declarationIncludesGlobal } from "./declarationIncludesGlobal.js";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/isGlobalDeclarationOfName.ts
|
|
5
|
+
/**
|
|
6
|
+
* TODO: Use a scope analyzer (#400).
|
|
7
|
+
*/
|
|
8
|
+
function isGlobalDeclarationOfName(node, name, typeChecker) {
|
|
9
|
+
const declarations = typeChecker.getSymbolAtLocation(node)?.getDeclarations();
|
|
10
|
+
if (!declarations) return false;
|
|
11
|
+
return declarations.every((declaration) => {
|
|
12
|
+
if (ts.isVariableDeclaration(declaration) && declaration.initializer && ts.isIdentifier(declaration.initializer)) return isGlobalDeclarationOfName(declaration.initializer, name, typeChecker);
|
|
13
|
+
if (ts.isPropertySignature(declaration)) return isGlobalDeclarationOfName(declaration.parent, name, typeChecker);
|
|
14
|
+
return isDeclarationOfName(declaration, name) && declarationIncludesGlobal(declaration);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function isDeclarationOfName(node, name) {
|
|
18
|
+
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
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { isGlobalDeclarationOfName };
|
|
24
|
+
//# sourceMappingURL=isGlobalDeclarationOfName.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Expression } from "../lib/types/ast.js";
|
|
2
|
+
import { Checker } from "../lib/types/checker.js";
|
|
3
|
+
import "../lib/index.js";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/isGlobalVariable.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Checks if a node is a reference to a global variable (e.g., Object, undefined, NaN).
|
|
9
|
+
* Global variables are those declared in TypeScript's lib files or are global identifiers
|
|
10
|
+
* like undefined which have symbols but no user-defined declarations.
|
|
11
|
+
* TODO: Use a scope manager (#400).
|
|
12
|
+
*/
|
|
13
|
+
declare function isGlobalVariable(node: Expression, typeChecker: Checker): boolean;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { isGlobalVariable };
|
|
16
|
+
//# sourceMappingURL=isGlobalVariable.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { declarationsIncludeGlobal } from "./declarationsIncludeGlobal.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/isGlobalVariable.ts
|
|
4
|
+
/**
|
|
5
|
+
* Checks if a node is a reference to a global variable (e.g., Object, undefined, NaN).
|
|
6
|
+
* Global variables are those declared in TypeScript's lib files or are global identifiers
|
|
7
|
+
* like undefined which have symbols but no user-defined declarations.
|
|
8
|
+
* TODO: Use a scope manager (#400).
|
|
9
|
+
*/
|
|
10
|
+
function isGlobalVariable(node, typeChecker) {
|
|
11
|
+
const symbol = typeChecker.getSymbolAtLocation(node);
|
|
12
|
+
if (!symbol) return false;
|
|
13
|
+
const declarations = symbol.getDeclarations();
|
|
14
|
+
if (!declarations?.length) return true;
|
|
15
|
+
return declarationsIncludeGlobal(declarations);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { isGlobalVariable };
|
|
20
|
+
//# sourceMappingURL=isGlobalVariable.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as ts$1 from "typescript";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/isInlineArrayCreation.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Checks if a node represents an inline array creation expression.
|
|
7
|
+
* These are cases where a new array is created immediately before the method call,
|
|
8
|
+
* so mutating methods like .sort() or .reverse() are safe to use.
|
|
9
|
+
*/
|
|
10
|
+
declare function isInlineArrayCreation(node: ts$1.Expression): boolean;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { isInlineArrayCreation };
|
|
13
|
+
//# sourceMappingURL=isInlineArrayCreation.d.ts.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as ts$1 from "typescript";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/isInlineArrayCreation.ts
|
|
4
|
+
const methodsReturningNewArray = new Set([
|
|
5
|
+
"concat",
|
|
6
|
+
"entries",
|
|
7
|
+
"filter",
|
|
8
|
+
"flat",
|
|
9
|
+
"flatMap",
|
|
10
|
+
"from",
|
|
11
|
+
"keys",
|
|
12
|
+
"map",
|
|
13
|
+
"of",
|
|
14
|
+
"slice",
|
|
15
|
+
"split",
|
|
16
|
+
"values"
|
|
17
|
+
]);
|
|
18
|
+
const objectStaticMethods = new Set([
|
|
19
|
+
"entries",
|
|
20
|
+
"keys",
|
|
21
|
+
"values"
|
|
22
|
+
]);
|
|
23
|
+
/**
|
|
24
|
+
* Checks if a node represents an inline array creation expression.
|
|
25
|
+
* These are cases where a new array is created immediately before the method call,
|
|
26
|
+
* so mutating methods like .sort() or .reverse() are safe to use.
|
|
27
|
+
*/
|
|
28
|
+
function isInlineArrayCreation(node) {
|
|
29
|
+
if (ts$1.isArrayLiteralExpression(node)) return true;
|
|
30
|
+
if (ts$1.isParenthesizedExpression(node)) return isInlineArrayCreation(node.expression);
|
|
31
|
+
if (ts$1.isCallExpression(node)) {
|
|
32
|
+
if (ts$1.isPropertyAccessExpression(node.expression)) {
|
|
33
|
+
const methodName = node.expression.name.text;
|
|
34
|
+
if (ts$1.isIdentifier(node.expression.expression) && node.expression.expression.text === "Object" && objectStaticMethods.has(methodName)) return true;
|
|
35
|
+
if (ts$1.isIdentifier(node.expression.expression) && node.expression.expression.text === "Array" && (methodName === "from" || methodName === "of")) return true;
|
|
36
|
+
if (methodsReturningNewArray.has(methodName)) return true;
|
|
37
|
+
}
|
|
38
|
+
if (ts$1.isIdentifier(node.expression) && node.expression.text === "Array" && ts$1.isNewExpression(node.parent)) return true;
|
|
39
|
+
}
|
|
40
|
+
if (ts$1.isNewExpression(node) && ts$1.isIdentifier(node.expression) && node.expression.text === "Array") return true;
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
export { isInlineArrayCreation };
|
|
46
|
+
//# sourceMappingURL=isInlineArrayCreation.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BinaryExpression, LeftHandSideExpressionParent, ParenthesizedExpression } from "../types/ast.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/unwrapParentParenthesizedExpressions.d.ts
|
|
4
|
+
declare function unwrapParenthesizedExpressionsParent(node: BinaryExpression | ParenthesizedExpression): LeftHandSideExpressionParent;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { unwrapParenthesizedExpressionsParent };
|
|
7
|
+
//# sourceMappingURL=unwrapParentParenthesizedExpressions.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SyntaxKind } from "typescript";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/unwrapParentParenthesizedExpressions.ts
|
|
4
|
+
function unwrapParenthesizedExpressionsParent(node) {
|
|
5
|
+
return node.parent.kind === SyntaxKind.ParenthesizedExpression ? unwrapParenthesizedExpressionsParent(node.parent) : node.parent;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
export { unwrapParenthesizedExpressionsParent };
|
|
10
|
+
//# sourceMappingURL=unwrapParentParenthesizedExpressions.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ConciseBody, Expression } from "../types/ast.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/unwrapParenthesizedExpression.d.ts
|
|
4
|
+
declare function unwrapParenthesizedExpression(expression: ConciseBody | Expression): ConciseBody | Expression;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { unwrapParenthesizedExpression };
|
|
7
|
+
//# sourceMappingURL=unwrapParenthesizedExpression.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SyntaxKind } from "typescript";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/unwrapParenthesizedExpression.ts
|
|
4
|
+
function unwrapParenthesizedExpression(expression) {
|
|
5
|
+
return expression.kind === SyntaxKind.ParenthesizedExpression ? unwrapParenthesizedExpression(expression.expression) : expression;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
export { unwrapParenthesizedExpression };
|
|
10
|
+
//# sourceMappingURL=unwrapParenthesizedExpression.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flint.fyi/typescript-language",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "[Experimental] TypeScript language for Flint.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/flint-fyi/flint.git",
|
|
8
|
+
"directory": "packages/typescript-language"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"author": {
|
|
12
|
+
"name": "JoshuaKGoldberg",
|
|
13
|
+
"email": "npm@joshuakgoldberg.com"
|
|
14
|
+
},
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"type": "module",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"@flint.fyi/source": "./src/index.ts",
|
|
20
|
+
"default": "./lib/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"lib/",
|
|
25
|
+
"!lib/**/*.map"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"test": "vitest --typecheck --project typescript-language"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@flint.fyi/core": "workspace:^",
|
|
32
|
+
"@flint.fyi/utils": "workspace:^",
|
|
33
|
+
"@typescript-eslint/project-service": "^8.46.2",
|
|
34
|
+
"@typescript/vfs": "^1.6.1",
|
|
35
|
+
"cached-factory": "^0.1.0",
|
|
36
|
+
"debug-for-file": "^0.2.0",
|
|
37
|
+
"ts-api-utils": "^2.1.0",
|
|
38
|
+
"typescript": "^5.9.0 || ^6.0.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"tsdown": "0.19.0-beta.2",
|
|
42
|
+
"vitest": "4.0.15"
|
|
43
|
+
},
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=24.0.0"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public",
|
|
49
|
+
"exports": {
|
|
50
|
+
".": "./lib/index.js"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|