@flint.fyi/typescript-language 0.18.4 → 0.20.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} +779 -3
  2. package/dist/index.mjs +1104 -0
  3. package/package.json +10 -8
  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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flint.fyi/typescript-language",
3
- "version": "0.18.4",
3
+ "version": "0.20.0",
4
4
  "description": "[Experimental] TypeScript language for Flint.",
5
5
  "homepage": "https://flint.fyi",
6
6
  "repository": {
@@ -16,26 +16,28 @@
16
16
  "sideEffects": true,
17
17
  "type": "module",
18
18
  "exports": {
19
- ".": "./lib/index.js"
19
+ ".": "./dist/index.mjs"
20
20
  },
21
21
  "files": [
22
- "lib/"
22
+ "dist/"
23
23
  ],
24
24
  "dependencies": {
25
25
  "@typescript-eslint/project-service": "^8.53.0",
26
+ "cached-factory": "^0.3.0",
26
27
  "debug-for-file": "^0.4.0",
27
28
  "pathe": "^2.0.3",
28
29
  "ts-api-utils": "^2.4.0",
29
30
  "typescript": "^5.9.0 || ^6.0.0",
30
- "@flint.fyi/utils": "^0.14.1",
31
- "@flint.fyi/core": "^0.23.1"
31
+ "@flint.fyi/core": "^0.25.0",
32
+ "@flint.fyi/utils": "^0.16.0"
32
33
  },
33
34
  "devDependencies": {
34
- "tsdown": "0.22.2",
35
- "vitest": "4.1.0"
35
+ "tsdown": "0.22.3",
36
+ "vitest": "4.1.0",
37
+ "@flint.fyi/build": "^0.1.0"
36
38
  },
37
39
  "engines": {
38
- "node": ">=24.0.0"
40
+ "node": ">=26.1.0"
39
41
  },
40
42
  "publishConfig": {
41
43
  "access": "public"
@@ -1,13 +0,0 @@
1
- //#region \0rolldown/runtime.js
2
- var __defProp = Object.defineProperty;
3
- var __exportAll = (all, no_symbols) => {
4
- let target = {};
5
- for (var name in all) __defProp(target, name, {
6
- get: all[name],
7
- enumerable: true
8
- });
9
- if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
10
- return target;
11
- };
12
- //#endregion
13
- export { __exportAll };
@@ -1,3 +0,0 @@
1
- import ts from "typescript";
2
- import type * as AST from "./types/ast.ts";
3
- export declare function collectReferencedFilePaths(program: ts.Program, sourceFile: AST.SourceFile): string[];
@@ -1,38 +0,0 @@
1
- import ts from "typescript";
2
- import * as tsutils from "ts-api-utils";
3
- import { nullThrows } from "@flint.fyi/utils";
4
- import * as path$1 from "node:path";
5
- //#region src/collectReferencedFilePaths.ts
6
- function collectReferencedFilePaths(program, sourceFile) {
7
- const modulePaths = /* @__PURE__ */ new Set();
8
- function resolveModulePath(moduleSpecifier) {
9
- const resolved = ts.resolveModuleName(moduleSpecifier, sourceFile.fileName, program.getCompilerOptions(), ts.sys);
10
- if (resolved.resolvedModule?.isExternalLibraryImport === false) return path$1.relative(process.cwd(), resolved.resolvedModule.resolvedFileName);
11
- }
12
- function visit(node) {
13
- let path;
14
- if (isImportDeclaration(node)) path = node.moduleSpecifier.text;
15
- else if (isImportCall(node)) path = node.arguments[0].text;
16
- else if (isAwaitImportCall(node)) path = node.expression.arguments[0].text;
17
- else if (isImportTypeNode(node)) path = node.argument.literal.text;
18
- const resolvedPath = path && resolveModulePath(path);
19
- if (resolvedPath) modulePaths.add(resolvedPath);
20
- ts.forEachChild(node, visit);
21
- }
22
- visit(sourceFile);
23
- return Array.from(modulePaths);
24
- }
25
- function isAwaitImportCall(node) {
26
- return ts.isAwaitExpression(node) && isImportCall(node.expression);
27
- }
28
- function isImportCall(node) {
29
- return ts.isCallExpression(node) && tsutils.isImportExpression(node.expression) && !!node.arguments.length && ts.isStringLiteral(nullThrows(node.arguments[0], "First argument is expected to be present by prior length check"));
30
- }
31
- function isImportDeclaration(node) {
32
- return ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier);
33
- }
34
- function isImportTypeNode(node) {
35
- return ts.isImportTypeNode(node) && ts.isLiteralTypeNode(node.argument) && ts.isStringLiteral(node.argument.literal);
36
- }
37
- //#endregion
38
- export { collectReferencedFilePaths };
@@ -1,17 +0,0 @@
1
- import ts from "typescript";
2
- import { LanguageReport, SourceFileWithLineMapAndFileName } from "@flint.fyi/core";
3
-
4
- //#region src/convertTypeScriptDiagnosticToLanguageReport.d.ts
5
- interface TSDiagnostic extends TSDiagnosticRelatedInformation {
6
- relatedInformation?: TSDiagnosticRelatedInformation[];
7
- }
8
- interface TSDiagnosticRelatedInformation {
9
- code: number;
10
- file: SourceFileWithLineMapAndFileName | undefined;
11
- length: number | undefined;
12
- messageText: string | ts.DiagnosticMessageChain;
13
- start: number | undefined;
14
- }
15
- declare function convertTypeScriptDiagnosticToLanguageReport(diagnostic: TSDiagnostic): LanguageReport;
16
- //#endregion
17
- export { TSDiagnostic, convertTypeScriptDiagnosticToLanguageReport };
@@ -1,112 +0,0 @@
1
- import ts from "typescript";
2
- import { getColumnAndLineOfPosition, getPositionOfColumnAndLine } from "@flint.fyi/core";
3
- //#region src/convertTypeScriptDiagnosticToLanguageReport.ts
4
- function convertTypeScriptDiagnosticToLanguageReport(diagnostic) {
5
- return {
6
- code: `TS${diagnostic.code}`,
7
- source: "typescript",
8
- text: formatReport(diagnostic),
9
- ...diagnostic.file !== void 0 && diagnostic.start !== void 0 && { range: {
10
- begin: diagnostic.start,
11
- end: diagnostic.start + (diagnostic.length ?? 0)
12
- } }
13
- };
14
- }
15
- function color(text, formatStyle) {
16
- return formatStyle + text + resetEscapeSequence;
17
- }
18
- function formatReport(diagnostic) {
19
- let output = "";
20
- if (diagnostic.file !== void 0) {
21
- output += formatLocation(diagnostic.file, diagnostic.start);
22
- output += " - ";
23
- }
24
- output += color(`TS${diagnostic.code}`, COLOR.Grey);
25
- output += ": ";
26
- output += ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
27
- if (diagnostic.file !== void 0) {
28
- output += "\n";
29
- output += formatCodeSpan(diagnostic.file, diagnostic.start, diagnostic.length, "", COLOR.Red);
30
- }
31
- if (diagnostic.relatedInformation) {
32
- output += "\n";
33
- for (const { file, length, messageText, start } of diagnostic.relatedInformation) {
34
- const indent = " ";
35
- if (file) {
36
- output += "\n";
37
- output += " " + formatLocation(file, start);
38
- output += formatCodeSpan(file, start, length, indent, COLOR.Cyan);
39
- }
40
- output += "\n";
41
- output += indent + ts.flattenDiagnosticMessageText(messageText, "\n");
42
- }
43
- }
44
- return output;
45
- }
46
- const gutterStyleSequence = "\x1B[7m";
47
- const ellipsis = "...";
48
- const gutterSeparator = " ";
49
- const resetEscapeSequence = "\x1B[0m";
50
- const COLOR = {
51
- Blue: "\x1B[94m",
52
- Cyan: "\x1B[96m",
53
- Grey: "\x1B[90m",
54
- Red: "\x1B[91m",
55
- Yellow: "\x1B[93m"
56
- };
57
- function displayFilename(name) {
58
- if (name.startsWith("./")) return name.slice(2);
59
- return name.slice(process.cwd().length + 1);
60
- }
61
- function formatCodeSpan(file, start, length, indent, squiggleColor) {
62
- const { column: firstLineChar, line: firstLine } = getColumnAndLineOfPosition(file, start);
63
- const { column: lastLineChar, line: lastLine } = getColumnAndLineOfPosition(file, start + length);
64
- const lastLineInFile = getColumnAndLineOfPosition(file, file.text.length).line;
65
- const hasMoreThanFiveLines = lastLine - firstLine >= 4;
66
- let gutterWidth = (lastLine + 1 + "").length;
67
- if (hasMoreThanFiveLines) gutterWidth = Math.max(3, gutterWidth);
68
- let context = "";
69
- for (let i = firstLine; i <= lastLine; i++) {
70
- context += "\n";
71
- if (hasMoreThanFiveLines && firstLine + 1 < i && i < lastLine - 1) {
72
- context += indent + color(ellipsis.padStart(gutterWidth), gutterStyleSequence) + " \n";
73
- i = lastLine - 1;
74
- }
75
- const lineStart = getPositionOfColumnAndLine(file, {
76
- column: 0,
77
- line: i
78
- });
79
- const lineEnd = i < lastLineInFile ? getPositionOfColumnAndLine(file, {
80
- column: 0,
81
- line: i + 1
82
- }) : file.text.length;
83
- let lineContent = file.text.slice(lineStart, lineEnd);
84
- lineContent = lineContent.trimEnd();
85
- lineContent = lineContent.replace(/\t/g, " ");
86
- context += indent + color((i + 1 + "").padStart(gutterWidth), gutterStyleSequence) + gutterSeparator;
87
- context += lineContent + "\n";
88
- context += indent + color("".padStart(gutterWidth), gutterStyleSequence) + gutterSeparator;
89
- context += squiggleColor;
90
- if (i === firstLine) {
91
- const lastCharForLine = i === lastLine ? lastLineChar : void 0;
92
- context += lineContent.slice(0, firstLineChar).replace(/\S/g, " ");
93
- context += lineContent.slice(firstLineChar, lastCharForLine).replace(/./g, "~");
94
- } else if (i === lastLine) context += lineContent.slice(0, lastLineChar).replace(/./g, "~");
95
- else context += lineContent.replace(/./g, "~");
96
- context += resetEscapeSequence;
97
- }
98
- return context;
99
- }
100
- function formatLocation(file, start) {
101
- const { column, line } = getColumnAndLineOfPosition(file, start);
102
- const relativeFileName = displayFilename(file.fileName);
103
- let output = "";
104
- output += color(relativeFileName, COLOR.Cyan);
105
- output += ":";
106
- output += color(`${line + 1}`, COLOR.Yellow);
107
- output += ":";
108
- output += color(`${column + 1}`, COLOR.Yellow);
109
- return output;
110
- }
111
- //#endregion
112
- export { convertTypeScriptDiagnosticToLanguageReport };
@@ -1,3 +0,0 @@
1
- import ts from "typescript";
2
- import { type LinterHost } from "@flint.fyi/core";
3
- export declare function createTypeScriptServerHost(host: LinterHost): ts.server.ServerHost;
@@ -1,101 +0,0 @@
1
- import ts from "typescript";
2
- import { commonlyIgnoredPaths } from "@flint.fyi/core";
3
- import { FlintAssertionError, assert } from "@flint.fyi/utils";
4
- import fs from "node:fs";
5
- import timers from "node:timers";
6
- import { resolve } from "pathe";
7
- //#region src/createTypeScriptServerHost.ts
8
- function serverHostMethodNotImplemented(methodName) {
9
- throw new FlintAssertionError(`ts.ServerHost's method '${methodName}' is not implemented.`);
10
- }
11
- const UV_DIRENT_TYPE = {
12
- UV_DIRENT_DIR: 2,
13
- UV_DIRENT_FILE: 1
14
- };
15
- const DirentCtor = fs.Dirent;
16
- function createTypeScriptServerHost(host) {
17
- return {
18
- ...ts.sys,
19
- args: [],
20
- clearImmediate: timers.clearImmediate,
21
- clearTimeout: timers.clearTimeout,
22
- createDirectory() {
23
- serverHostMethodNotImplemented("createDirectory");
24
- },
25
- directoryExists(directoryPath) {
26
- return host.fileTypeSync(resolve(host.getCurrentDirectory(), directoryPath)) === "directory";
27
- },
28
- exit() {
29
- serverHostMethodNotImplemented("exit");
30
- },
31
- fileExists(filePath) {
32
- return host.fileTypeSync(resolve(host.getCurrentDirectory(), filePath)) === "file";
33
- },
34
- readDirectory(directoryPath, extensions, exclude, include, depth) {
35
- const originalCwd = process.cwd.bind(process);
36
- process.cwd = () => host.getCurrentDirectory();
37
- const originalReadDirSync = fs.readdirSync;
38
- const patchedReaddirSync = (readPath, options) => {
39
- assert(typeof options === "object" && options != null && Object.keys(options).length === 1 && options.withFileTypes === true, `ts.sys.readDirectory passed unexpected options to fs.readdirSync: ${JSON.stringify(options)}`);
40
- assert(typeof readPath === "string", "ts.sys.readDirectory passed unexpected path to fs.readdirSync");
41
- try {
42
- fs.readdirSync = originalReadDirSync;
43
- return host.readDirectorySync(resolve(host.getCurrentDirectory(), readPath)).map((dirent) => new DirentCtor(dirent.name, dirent.type === "file" ? UV_DIRENT_TYPE.UV_DIRENT_FILE : UV_DIRENT_TYPE.UV_DIRENT_DIR, readPath));
44
- } finally {
45
- fs.readdirSync = patchedReaddirSync;
46
- }
47
- };
48
- fs.readdirSync = patchedReaddirSync;
49
- try {
50
- return ts.sys.readDirectory(directoryPath, extensions, exclude, include, depth);
51
- } finally {
52
- process.cwd = originalCwd;
53
- fs.readdirSync = originalReadDirSync;
54
- }
55
- },
56
- readFile(filePath) {
57
- return host.readFileSync(resolve(host.getCurrentDirectory(), filePath));
58
- },
59
- setImmediate: timers.setImmediate,
60
- setTimeout: timers.setTimeout,
61
- watchDirectory(directoryPath, callback, recursive = false) {
62
- const watcher = host.watchDirectorySync(resolve(host.getCurrentDirectory(), directoryPath), (filePathAbsolute) => {
63
- callback(filePathAbsolute);
64
- }, {
65
- ignoredPaths: commonlyIgnoredPaths,
66
- recursive
67
- });
68
- return { close() {
69
- watcher[Symbol.dispose]();
70
- } };
71
- },
72
- watchFile(filePath, callback) {
73
- const watcher = host.watchFileSync(resolve(host.getCurrentDirectory(), filePath), (event) => {
74
- let eventKind;
75
- switch (event) {
76
- case "changed":
77
- eventKind = ts.FileWatcherEventKind.Changed;
78
- break;
79
- case "created":
80
- eventKind = ts.FileWatcherEventKind.Created;
81
- break;
82
- case "deleted":
83
- eventKind = ts.FileWatcherEventKind.Deleted;
84
- break;
85
- }
86
- callback(filePath, eventKind);
87
- }, { ignoredPaths: commonlyIgnoredPaths });
88
- return { close() {
89
- watcher[Symbol.dispose]();
90
- } };
91
- },
92
- write() {
93
- serverHostMethodNotImplemented("write");
94
- },
95
- writeFile() {
96
- serverHostMethodNotImplemented("writeFile");
97
- }
98
- };
99
- }
100
- //#endregion
101
- export { createTypeScriptServerHost };
@@ -1,12 +0,0 @@
1
- import { SourceFile } from "../types/ast.js";
2
- import { NormalizedReportRangeObject } from "@flint.fyi/core";
3
-
4
- //#region src/directives/parseDirectivesFromTypeScriptFile.d.ts
5
- interface ExtractedDirective {
6
- range: NormalizedReportRangeObject;
7
- selection: string;
8
- type: string;
9
- }
10
- declare function extractDirectivesFromTypeScriptFile(sourceFile: SourceFile): ExtractedDirective[];
11
- //#endregion
12
- export { ExtractedDirective, extractDirectivesFromTypeScriptFile };
@@ -1,64 +0,0 @@
1
- import { normalizeRange } from "../normalizeRange.js";
2
- import ts from "typescript";
3
- import { DirectivesCollector } from "@flint.fyi/core";
4
- import * as tsutils from "ts-api-utils";
5
- import { nullThrows } from "@flint.fyi/utils";
6
- //#region src/directives/parseDirectivesFromTypeScriptFile.ts
7
- function extractDirectivesFromTypeScriptFile(sourceFile) {
8
- const directives = [];
9
- tsutils.forEachComment(sourceFile, (fullText, sourceRange) => {
10
- const commentText = fullText.slice(sourceRange.pos, sourceRange.end);
11
- const match = /^\/\/\s*flint-(\S+)(?:\s+(.+))?/.exec(commentText);
12
- if (!match) return;
13
- let range = normalizeRange({
14
- begin: sourceRange.pos,
15
- end: sourceRange.end
16
- }, sourceFile);
17
- const matches = match.slice(1);
18
- const type = nullThrows(matches[0], "First match is expected to be present by the regex match");
19
- const selection = matches[1] ?? "";
20
- if (type === "disable-next-line") range = extendRangeToNextCodeLine(sourceFile, range);
21
- directives.push({
22
- range,
23
- selection,
24
- type
25
- });
26
- });
27
- return directives;
28
- }
29
- function parseDirectivesFromTypeScriptFile(sourceFile) {
30
- const collector = new DirectivesCollector(sourceFile.statements.at(0)?.getStart(sourceFile) ?? sourceFile.text.length);
31
- for (const { range, selection, type } of extractDirectivesFromTypeScriptFile(sourceFile)) collector.add(range, selection, type);
32
- return collector.collect();
33
- }
34
- function computeNextCodeLine(sourceFile, directiveLine) {
35
- const lineStarts = sourceFile.getLineStarts();
36
- const nextLineStart = lineStarts[directiveLine + 1];
37
- if (nextLineStart === void 0) return;
38
- const scanner = ts.createScanner(sourceFile.languageVersion, true, sourceFile.languageVariant, sourceFile.text, void 0, nextLineStart);
39
- if (scanner.scan() === ts.SyntaxKind.EndOfFileToken) return;
40
- const tokenPos = scanner.getTokenStart();
41
- const codeLine = sourceFile.getLineAndCharacterOfPosition(tokenPos).line;
42
- for (let line = directiveLine + 1; line < codeLine; line++) {
43
- const start = lineStarts[line];
44
- const end = lineStarts[line + 1] ?? sourceFile.text.length;
45
- if (sourceFile.text.slice(start, end).trim() === "") return;
46
- }
47
- return codeLine;
48
- }
49
- function extendRangeToNextCodeLine(sourceFile, range) {
50
- const codeLine = computeNextCodeLine(sourceFile, range.begin.line);
51
- if (codeLine === void 0 || codeLine <= range.end.line + 1) return range;
52
- const endPosition = nullThrows(sourceFile.getLineStarts()[codeLine], "Code line start is expected to be present by the computed code line") - 1;
53
- const { character, line } = sourceFile.getLineAndCharacterOfPosition(endPosition);
54
- return {
55
- ...range,
56
- end: {
57
- column: character,
58
- line,
59
- raw: endPosition
60
- }
61
- };
62
- }
63
- //#endregion
64
- export { extractDirectivesFromTypeScriptFile, parseDirectivesFromTypeScriptFile };
@@ -1,35 +0,0 @@
1
- /**
2
- * Removes TypeScript enum values that alias earlier values.
3
- * @param original Any TypeScript enum with numeric values.
4
- * @returns A version of the enum with only the first occurrence of each value.
5
- * @example
6
- * Given the following enum:
7
- * ```ts
8
- * enum Example {
9
- * A = 1,
10
- * B = 2,
11
- * C = A
12
- * }
13
- * ```
14
- * Its original value looks like:
15
- * ```ts
16
- * {
17
- * 1: 'C', // <-- Points to 'C', the alias of 'A'
18
- * 2: 'B',
19
- * A: 1,
20
- * B: 2,
21
- * C: 1,
22
- * }
23
- * ```
24
- * Calling `getFirstEnumValues(Example)` would return:
25
- * ```ts
26
- * {
27
- * 1: 'A', // <-- Corrected to the original 'A'
28
- * 2: 'B',
29
- * A: 1,
30
- * B: 2,
31
- * C: 1,
32
- * }
33
- * ```
34
- */
35
- export declare function getFirstEnumValues<Keys extends string, Values extends number, Original extends Record<Keys | Values, Keys | Values>>(original: Original): Original;
@@ -1,46 +0,0 @@
1
- //#region src/getFirstEnumValues.ts
2
- /**
3
- * Removes TypeScript enum values that alias earlier values.
4
- * @param original Any TypeScript enum with numeric values.
5
- * @returns A version of the enum with only the first occurrence of each value.
6
- * @example
7
- * Given the following enum:
8
- * ```ts
9
- * enum Example {
10
- * A = 1,
11
- * B = 2,
12
- * C = A
13
- * }
14
- * ```
15
- * Its original value looks like:
16
- * ```ts
17
- * {
18
- * 1: 'C', // <-- Points to 'C', the alias of 'A'
19
- * 2: 'B',
20
- * A: 1,
21
- * B: 2,
22
- * C: 1,
23
- * }
24
- * ```
25
- * Calling `getFirstEnumValues(Example)` would return:
26
- * ```ts
27
- * {
28
- * 1: 'A', // <-- Corrected to the original 'A'
29
- * 2: 'B',
30
- * A: 1,
31
- * B: 2,
32
- * C: 1,
33
- * }
34
- * ```
35
- */
36
- function getFirstEnumValues(original) {
37
- const result = {};
38
- for (const key in original) {
39
- if (typeof original[key] !== "number") continue;
40
- if (!(key in result)) result[key] = original[key];
41
- if (!(original[key] in result)) result[original[key]] = key;
42
- }
43
- return result;
44
- }
45
- //#endregion
46
- export { getFirstEnumValues };
@@ -1,8 +0,0 @@
1
- import { SourceFile } from "./types/ast.js";
2
- import * as ts$1 from "typescript";
3
- import { CharacterReportRange } from "@flint.fyi/core";
4
-
5
- //#region src/getTSNodeRange.d.ts
6
- declare function getTSNodeRange(node: ts$1.Node, sourceFile: SourceFile): CharacterReportRange;
7
- //#endregion
8
- export { getTSNodeRange };
@@ -1,9 +0,0 @@
1
- //#region src/getTSNodeRange.ts
2
- function getTSNodeRange(node, sourceFile) {
3
- return {
4
- begin: node.getStart(sourceFile),
5
- end: node.getEnd()
6
- };
7
- }
8
- //#endregion
9
- export { getTSNodeRange };
@@ -1,3 +0,0 @@
1
- import type { LanguageFile, LanguageFileCacheImpacts } from "@flint.fyi/core";
2
- import type { TypeScriptFileServices } from "./language.ts";
3
- export declare function getTypeScriptFileCacheImpacts(file: LanguageFile<TypeScriptFileServices>): LanguageFileCacheImpacts;
@@ -1,11 +0,0 @@
1
- import { collectReferencedFilePaths } from "./collectReferencedFilePaths.js";
2
- import { containsGlobalDeclarations } from "./utils/containsGlobalDeclarations.js";
3
- //#region src/getTypeScriptFileCacheImpacts.ts
4
- function getTypeScriptFileCacheImpacts(file) {
5
- return {
6
- dependencies: ["tsconfig.json", ...collectReferencedFilePaths(file.services.program, file.services.sourceFile)],
7
- invalidatesCache: containsGlobalDeclarations(file.services.sourceFile)
8
- };
9
- }
10
- //#endregion
11
- export { getTypeScriptFileCacheImpacts };
package/lib/index.d.ts DELETED
@@ -1,26 +0,0 @@
1
- import { TSDiagnostic, convertTypeScriptDiagnosticToLanguageReport } from "./convertTypeScriptDiagnosticToLanguageReport.js";
2
- import { ast_d_exports } from "./types/ast.js";
3
- import { ExtractedDirective, extractDirectivesFromTypeScriptFile } from "./directives/parseDirectivesFromTypeScriptFile.js";
4
- import { getTSNodeRange } from "./getTSNodeRange.js";
5
- import { TypeScriptNodeVisitors, TypeScriptNodesByName } from "./nodes.js";
6
- import { Checker } from "./types/checker.js";
7
- import { NodeSyntaxKinds, TypeScriptFileServices, setVolarCreateFile, throwUnknownLanguageExtension, typescriptLanguage } from "./language.js";
8
- import { FunctionWithParameters, Scope, ScopeDefinition, ScopeDefinitionKind, ScopeManager, ScopeReference, ScopeVariable } from "./scope/types.js";
9
- import { createScopeManager, getScopeManager } from "./scope/scopeManager.js";
10
- import { createRuleTesterTSConfig } from "./utils/createRuleTesterTSConfig.js";
11
- import { declarationIncludesGlobal } from "./utils/declarationIncludesGlobal.js";
12
- import { forEachChild } from "./utils/forEachChild.js";
13
- import { getDeclarationsIfGlobal } from "./utils/getDeclarationsIfGlobal.js";
14
- import { getModifyingReferences } from "./utils/getModifyingReferences.js";
15
- import { hasSameTokens } from "./utils/hasSameTokens.js";
16
- import { BuiltInArrayMethodNode, isBuiltinArrayMethod } from "./utils/isBuiltinArrayMethod.js";
17
- import { isFunction } from "./utils/isFunction.js";
18
- import { isGlobalDeclaration } from "./utils/isGlobalDeclaration.js";
19
- import { isGlobalDeclarationOfName } from "./utils/isGlobalDeclarationOfName.js";
20
- import { isGlobalVariable } from "./utils/isGlobalVariable.js";
21
- import { isInlineArrayCreation } from "./utils/isInlineArrayCreation.js";
22
- import { isStaticString } from "./utils/isStaticString.js";
23
- import { isStringRawNoSubstitution } from "./utils/isStringRawNoSubstitution.js";
24
- import { unwrapParenthesizedNode } from "./utils/unwrapParenthesizedNode.js";
25
- import { unwrapParentParenthesizedExpressions } from "./utils/unwrapParentParenthesizedExpressions.js";
26
- export { type ast_d_exports as AST, type BuiltInArrayMethodNode, type Checker, type ExtractedDirective, type FunctionWithParameters, NodeSyntaxKinds, type Scope, type ScopeDefinition, type ScopeDefinitionKind, type ScopeManager, type ScopeReference, type ScopeVariable, type TSDiagnostic, type TypeScriptFileServices, type TypeScriptNodeVisitors, type TypeScriptNodesByName, convertTypeScriptDiagnosticToLanguageReport, createRuleTesterTSConfig, createScopeManager, declarationIncludesGlobal, extractDirectivesFromTypeScriptFile, forEachChild, getDeclarationsIfGlobal, getModifyingReferences, getScopeManager, getTSNodeRange, hasSameTokens, isBuiltinArrayMethod, isFunction, isGlobalDeclaration, isGlobalDeclarationOfName, isGlobalVariable, isInlineArrayCreation, isStaticString, isStringRawNoSubstitution, setVolarCreateFile, throwUnknownLanguageExtension, typescriptLanguage, unwrapParentParenthesizedExpressions, unwrapParenthesizedNode };
package/lib/index.js DELETED
@@ -1,22 +0,0 @@
1
- import { convertTypeScriptDiagnosticToLanguageReport } from "./convertTypeScriptDiagnosticToLanguageReport.js";
2
- import { extractDirectivesFromTypeScriptFile } from "./directives/parseDirectivesFromTypeScriptFile.js";
3
- import { getTSNodeRange } from "./getTSNodeRange.js";
4
- import { NodeSyntaxKinds, setVolarCreateFile, throwUnknownLanguageExtension, typescriptLanguage } from "./language.js";
5
- import { forEachChild } from "./utils/forEachChild.js";
6
- import { createScopeManager, getScopeManager } from "./scope/scopeManager.js";
7
- import { createRuleTesterTSConfig } from "./utils/createRuleTesterTSConfig.js";
8
- import { declarationIncludesGlobal } from "./utils/declarationIncludesGlobal.js";
9
- import { getDeclarationsIfGlobal } from "./utils/getDeclarationsIfGlobal.js";
10
- import { getModifyingReferences } from "./utils/getModifyingReferences.js";
11
- import { unwrapParenthesizedNode } from "./utils/unwrapParenthesizedNode.js";
12
- import { hasSameTokens } from "./utils/hasSameTokens.js";
13
- import { isBuiltinArrayMethod } from "./utils/isBuiltinArrayMethod.js";
14
- import { isFunction } from "./utils/isFunction.js";
15
- import { isGlobalDeclaration } from "./utils/isGlobalDeclaration.js";
16
- import { isGlobalDeclarationOfName } from "./utils/isGlobalDeclarationOfName.js";
17
- import { isGlobalVariable } from "./utils/isGlobalVariable.js";
18
- import { isInlineArrayCreation } from "./utils/isInlineArrayCreation.js";
19
- import { isStaticString } from "./utils/isStaticString.js";
20
- import { isStringRawNoSubstitution } from "./utils/isStringRawNoSubstitution.js";
21
- import { unwrapParentParenthesizedExpressions } from "./utils/unwrapParentParenthesizedExpressions.js";
22
- export { NodeSyntaxKinds, convertTypeScriptDiagnosticToLanguageReport, createRuleTesterTSConfig, createScopeManager, declarationIncludesGlobal, extractDirectivesFromTypeScriptFile, forEachChild, getDeclarationsIfGlobal, getModifyingReferences, getScopeManager, getTSNodeRange, hasSameTokens, isBuiltinArrayMethod, isFunction, isGlobalDeclaration, isGlobalDeclarationOfName, isGlobalVariable, isInlineArrayCreation, isStaticString, isStringRawNoSubstitution, setVolarCreateFile, throwUnknownLanguageExtension, typescriptLanguage, unwrapParentParenthesizedExpressions, unwrapParenthesizedNode };