@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.
Files changed (78) hide show
  1. package/README.md +9 -0
  2. package/lib/_virtual/rolldown_runtime.js +18 -0
  3. package/lib/collectReferencedFilePaths.d.ts +4 -0
  4. package/lib/collectReferencedFilePaths.js +41 -0
  5. package/lib/convertTypeScriptDiagnosticToLanguageFileDiagnostic.d.ts +18 -0
  6. package/lib/convertTypeScriptDiagnosticToLanguageFileDiagnostic.js +110 -0
  7. package/lib/createTypeScriptFileFromProgram.d.ts +12 -0
  8. package/lib/createTypeScriptFileFromProgram.js +41 -0
  9. package/lib/createTypeScriptFileFromProjectService.d.ts +8 -0
  10. package/lib/createTypeScriptFileFromProjectService.js +16 -0
  11. package/lib/directives/parseDirectivesFromTypeScriptFile.d.ts +13 -0
  12. package/lib/directives/parseDirectivesFromTypeScriptFile.js +36 -0
  13. package/lib/getFirstEnumValues.d.ts +36 -0
  14. package/lib/getFirstEnumValues.js +48 -0
  15. package/lib/getTSNodeRange.d.ts +9 -0
  16. package/lib/getTSNodeRange.js +11 -0
  17. package/lib/index.d.ts +22 -0
  18. package/lib/index.js +20 -0
  19. package/lib/language.d.ts +16 -0
  20. package/lib/language.js +23 -0
  21. package/lib/lib/convertTypeScriptDiagnosticToLanguageFileDiagnostic.d.ts +2 -0
  22. package/lib/lib/createTypeScriptFileFromProgram.d.ts +5 -0
  23. package/lib/lib/directives/parseDirectivesFromTypeScriptFile.d.ts +2 -0
  24. package/lib/lib/getTSNodeRange.d.ts +3 -0
  25. package/lib/lib/index.d.ts +21 -0
  26. package/lib/lib/language.d.ts +5 -0
  27. package/lib/lib/nodes.d.ts +1 -0
  28. package/lib/lib/prepareTypeScriptBasedLanguage.d.ts +2 -0
  29. package/lib/lib/types/ast.d.ts +2066 -0
  30. package/lib/lib/types/checker.d.ts +23 -0
  31. package/lib/lib/utils/declarationIncludesGlobal.d.ts +1 -0
  32. package/lib/lib/utils/getDeclarationsIfGlobal.d.ts +2 -0
  33. package/lib/lib/utils/getModifyingReferences.d.ts +3 -0
  34. package/lib/lib/utils/hasSameTokens.d.ts +1 -0
  35. package/lib/lib/utils/isBuiltinArrayMethod.d.ts +2 -0
  36. package/lib/lib/utils/isFunction.d.ts +1 -0
  37. package/lib/lib/utils/isGlobalDeclaration.d.ts +1 -0
  38. package/lib/lib/utils/isGlobalDeclarationOfName.d.ts +2 -0
  39. package/lib/lib/utils/isGlobalVariable.d.ts +1 -0
  40. package/lib/lib/utils/isInlineArrayCreation.d.ts +1 -0
  41. package/lib/lib/utils/unwrapParentParenthesizedExpressions.d.ts +1 -0
  42. package/lib/lib/utils/unwrapParenthesizedExpression.d.ts +1 -0
  43. package/lib/nodes.d.ts +202 -0
  44. package/lib/normalizeRange.d.ts +4 -0
  45. package/lib/normalizeRange.js +20 -0
  46. package/lib/prepareTypeScriptBasedLanguage.d.ts +16 -0
  47. package/lib/prepareTypeScriptBasedLanguage.js +55 -0
  48. package/lib/prepareTypeScriptFile.d.ts +14 -0
  49. package/lib/prepareTypeScriptFile.js +18 -0
  50. package/lib/types/ast.d.ts +2070 -0
  51. package/lib/types/checker.d.ts +23 -0
  52. package/lib/utils/declarationIncludesGlobal.d.ts +7 -0
  53. package/lib/utils/declarationIncludesGlobal.js +9 -0
  54. package/lib/utils/declarationsIncludeGlobal.d.ts +3 -0
  55. package/lib/utils/declarationsIncludeGlobal.js +10 -0
  56. package/lib/utils/getDeclarationsIfGlobal.d.ts +10 -0
  57. package/lib/utils/getDeclarationsIfGlobal.js +11 -0
  58. package/lib/utils/getModifyingReferences.d.ts +17 -0
  59. package/lib/utils/getModifyingReferences.js +33 -0
  60. package/lib/utils/hasSameTokens.d.ts +7 -0
  61. package/lib/utils/hasSameTokens.js +33 -0
  62. package/lib/utils/isBuiltinArrayMethod.d.ts +15 -0
  63. package/lib/utils/isBuiltinArrayMethod.js +10 -0
  64. package/lib/utils/isFunction.d.ts +9 -0
  65. package/lib/utils/isFunction.js +8 -0
  66. package/lib/utils/isGlobalDeclaration.d.ts +9 -0
  67. package/lib/utils/isGlobalDeclaration.js +10 -0
  68. package/lib/utils/isGlobalDeclarationOfName.d.ts +12 -0
  69. package/lib/utils/isGlobalDeclarationOfName.js +24 -0
  70. package/lib/utils/isGlobalVariable.d.ts +16 -0
  71. package/lib/utils/isGlobalVariable.js +20 -0
  72. package/lib/utils/isInlineArrayCreation.d.ts +13 -0
  73. package/lib/utils/isInlineArrayCreation.js +46 -0
  74. package/lib/utils/unwrapParentParenthesizedExpressions.d.ts +7 -0
  75. package/lib/utils/unwrapParentParenthesizedExpressions.js +10 -0
  76. package/lib/utils/unwrapParenthesizedExpression.d.ts +7 -0
  77. package/lib/utils/unwrapParenthesizedExpression.js +10 -0
  78. package/package.json +53 -0
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ <h1 align="center"><code>@flint.fyi/typescript-language</code></h1>
2
+
3
+ <p align="center">
4
+ [Experimental] TypeScript language for Flint.
5
+ ❤️‍🔥
6
+ </p>
7
+
8
+ This is an internal package for Flint.
9
+ Documentation will eventually be added.
@@ -0,0 +1,18 @@
1
+ //#region rolldown:runtime
2
+ var __defProp = Object.defineProperty;
3
+ var __exportAll = (all, symbols) => {
4
+ let target = {};
5
+ for (var name in all) {
6
+ __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ }
11
+ if (symbols) {
12
+ __defProp(target, Symbol.toStringTag, { value: "Module" });
13
+ }
14
+ return target;
15
+ };
16
+
17
+ //#endregion
18
+ export { __exportAll };
@@ -0,0 +1,4 @@
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[];
4
+ //# sourceMappingURL=collectReferencedFilePaths.d.ts.map
@@ -0,0 +1,41 @@
1
+ import ts from "typescript";
2
+ import { nullThrows } from "@flint.fyi/utils";
3
+ import * as path$1 from "node:path";
4
+ import * as tsutils from "ts-api-utils";
5
+
6
+ //#region src/collectReferencedFilePaths.ts
7
+ function collectReferencedFilePaths(program, sourceFile) {
8
+ const modulePaths = /* @__PURE__ */ new Set();
9
+ function resolveModulePath(moduleSpecifier) {
10
+ const resolved = ts.resolveModuleName(moduleSpecifier, sourceFile.fileName, program.getCompilerOptions(), ts.sys);
11
+ if (resolved.resolvedModule?.isExternalLibraryImport === false) return path$1.relative(process.cwd(), resolved.resolvedModule.resolvedFileName);
12
+ }
13
+ function visit(node) {
14
+ let path$2;
15
+ if (isImportDeclaration(node)) path$2 = node.moduleSpecifier.text;
16
+ else if (isImportCall(node)) path$2 = node.arguments[0].text;
17
+ else if (isAwaitImportCall(node)) path$2 = node.expression.arguments[0].text;
18
+ else if (isImportTypeNode(node)) path$2 = node.argument.literal.text;
19
+ const resolvedPath = path$2 && resolveModulePath(path$2);
20
+ if (resolvedPath) modulePaths.add(resolvedPath);
21
+ ts.forEachChild(node, visit);
22
+ }
23
+ visit(sourceFile);
24
+ return Array.from(modulePaths);
25
+ }
26
+ function isAwaitImportCall(node) {
27
+ return ts.isAwaitExpression(node) && isImportCall(node.expression);
28
+ }
29
+ function isImportCall(node) {
30
+ return ts.isCallExpression(node) && tsutils.isImportExpression(node.expression) && node.arguments.length > 0 && ts.isStringLiteral(nullThrows(node.arguments[0], "First argument is expected to be present by prior length check"));
31
+ }
32
+ function isImportDeclaration(node) {
33
+ return ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier);
34
+ }
35
+ function isImportTypeNode(node) {
36
+ return ts.isImportTypeNode(node) && ts.isLiteralTypeNode(node.argument) && ts.isStringLiteral(node.argument.literal);
37
+ }
38
+
39
+ //#endregion
40
+ export { collectReferencedFilePaths };
41
+ //# sourceMappingURL=collectReferencedFilePaths.js.map
@@ -0,0 +1,18 @@
1
+ import { LanguageFileDiagnostic, SourceFileWithLineMapAndFileName } from "@flint.fyi/core";
2
+ import ts from "typescript";
3
+
4
+ //#region src/convertTypeScriptDiagnosticToLanguageFileDiagnostic.d.ts
5
+ interface TSBasedDiagnostic extends TSBasedDiagnosticRelatedInformation {
6
+ relatedInformation?: TSBasedDiagnosticRelatedInformation[];
7
+ }
8
+ interface TSBasedDiagnosticRelatedInformation {
9
+ code: number;
10
+ file: SourceFileWithLineMapAndFileName | undefined;
11
+ length: number | undefined;
12
+ messageText: string | ts.DiagnosticMessageChain;
13
+ start: number | undefined;
14
+ }
15
+ declare function convertTypeScriptDiagnosticToLanguageFileDiagnostic(diagnostic: TSBasedDiagnostic): LanguageFileDiagnostic;
16
+ //#endregion
17
+ export { convertTypeScriptDiagnosticToLanguageFileDiagnostic };
18
+ //# sourceMappingURL=convertTypeScriptDiagnosticToLanguageFileDiagnostic.d.ts.map
@@ -0,0 +1,110 @@
1
+ import { getColumnAndLineOfPosition, getPositionOfColumnAndLine } from "@flint.fyi/core";
2
+ import ts, { flattenDiagnosticMessageText } from "typescript";
3
+
4
+ //#region src/convertTypeScriptDiagnosticToLanguageFileDiagnostic.ts
5
+ function convertTypeScriptDiagnosticToLanguageFileDiagnostic(diagnostic) {
6
+ return {
7
+ code: `TS${diagnostic.code}`,
8
+ text: formatDiagnostic(diagnostic)
9
+ };
10
+ }
11
+ function color(text, formatStyle) {
12
+ return formatStyle + text + resetEscapeSequence;
13
+ }
14
+ function formatDiagnostic(diagnostic) {
15
+ let output = "";
16
+ if (diagnostic.file !== void 0) {
17
+ output += formatLocation(diagnostic.file, diagnostic.start);
18
+ output += " - ";
19
+ }
20
+ output += color(`TS${diagnostic.code}`, COLOR.Grey);
21
+ output += ": ";
22
+ output += ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
23
+ if (diagnostic.file !== void 0) {
24
+ output += "\n";
25
+ output += formatCodeSpan(diagnostic.file, diagnostic.start, diagnostic.length, "", COLOR.Red);
26
+ }
27
+ if (diagnostic.relatedInformation) {
28
+ output += "\n";
29
+ for (const { file, length, messageText, start } of diagnostic.relatedInformation) {
30
+ const indent = " ";
31
+ if (file) {
32
+ output += "\n";
33
+ output += " " + formatLocation(file, start);
34
+ output += formatCodeSpan(file, start, length, indent, COLOR.Cyan);
35
+ }
36
+ output += "\n";
37
+ output += indent + flattenDiagnosticMessageText(messageText, "\n");
38
+ }
39
+ }
40
+ return output;
41
+ }
42
+ const gutterStyleSequence = "\x1B[7m";
43
+ const ellipsis = "...";
44
+ const gutterSeparator = " ";
45
+ const resetEscapeSequence = "\x1B[0m";
46
+ const COLOR = {
47
+ Blue: "\x1B[94m",
48
+ Cyan: "\x1B[96m",
49
+ Grey: "\x1B[90m",
50
+ Red: "\x1B[91m",
51
+ Yellow: "\x1B[93m"
52
+ };
53
+ function displayFilename(name) {
54
+ if (name.startsWith("./")) return name.slice(2);
55
+ return name.slice(process.cwd().length + 1);
56
+ }
57
+ function formatCodeSpan(file, start, length, indent, squiggleColor) {
58
+ const { column: firstLineChar, line: firstLine } = getColumnAndLineOfPosition(file, start);
59
+ const { column: lastLineChar, line: lastLine } = getColumnAndLineOfPosition(file, start + length);
60
+ const lastLineInFile = getColumnAndLineOfPosition(file, file.text.length).line;
61
+ const hasMoreThanFiveLines = lastLine - firstLine >= 4;
62
+ let gutterWidth = (lastLine + 1 + "").length;
63
+ if (hasMoreThanFiveLines) gutterWidth = Math.max(3, gutterWidth);
64
+ let context = "";
65
+ for (let i = firstLine; i <= lastLine; i++) {
66
+ context += "\n";
67
+ if (hasMoreThanFiveLines && firstLine + 1 < i && i < lastLine - 1) {
68
+ context += indent + color(ellipsis.padStart(gutterWidth), gutterStyleSequence) + gutterSeparator + "\n";
69
+ i = lastLine - 1;
70
+ }
71
+ const lineStart = getPositionOfColumnAndLine(file, {
72
+ column: 0,
73
+ line: i
74
+ });
75
+ const lineEnd = i < lastLineInFile ? getPositionOfColumnAndLine(file, {
76
+ column: 0,
77
+ line: i + 1
78
+ }) : file.text.length;
79
+ let lineContent = file.text.slice(lineStart, lineEnd);
80
+ lineContent = lineContent.trimEnd();
81
+ lineContent = lineContent.replace(/\t/g, " ");
82
+ context += indent + color((i + 1 + "").padStart(gutterWidth), gutterStyleSequence) + gutterSeparator;
83
+ context += lineContent + "\n";
84
+ context += indent + color("".padStart(gutterWidth), gutterStyleSequence) + gutterSeparator;
85
+ context += squiggleColor;
86
+ if (i === firstLine) {
87
+ const lastCharForLine = i === lastLine ? lastLineChar : void 0;
88
+ context += lineContent.slice(0, firstLineChar).replace(/\S/g, " ");
89
+ context += lineContent.slice(firstLineChar, lastCharForLine).replace(/./g, "~");
90
+ } else if (i === lastLine) context += lineContent.slice(0, lastLineChar).replace(/./g, "~");
91
+ else context += lineContent.replace(/./g, "~");
92
+ context += resetEscapeSequence;
93
+ }
94
+ return context;
95
+ }
96
+ function formatLocation(file, start) {
97
+ const { column, line } = getColumnAndLineOfPosition(file, start);
98
+ const relativeFileName = displayFilename(file.fileName);
99
+ let output = "";
100
+ output += color(relativeFileName, COLOR.Cyan);
101
+ output += ":";
102
+ output += color(`${line + 1}`, COLOR.Yellow);
103
+ output += ":";
104
+ output += color(`${column + 1}`, COLOR.Yellow);
105
+ return output;
106
+ }
107
+
108
+ //#endregion
109
+ export { convertTypeScriptDiagnosticToLanguageFileDiagnostic };
110
+ //# sourceMappingURL=convertTypeScriptDiagnosticToLanguageFileDiagnostic.js.map
@@ -0,0 +1,12 @@
1
+ import { SourceFile } from "./types/ast.js";
2
+ import "./nodes.js";
3
+ import "./language.js";
4
+ import { LanguageFileCacheImpacts } from "@flint.fyi/core";
5
+ import ts from "typescript";
6
+
7
+ //#region src/createTypeScriptFileFromProgram.d.ts
8
+ declare const NodeSyntaxKinds: typeof ts.SyntaxKind;
9
+ declare function collectTypeScriptFileCacheImpacts(program: ts.Program, sourceFile: SourceFile): LanguageFileCacheImpacts;
10
+ //#endregion
11
+ export { NodeSyntaxKinds, collectTypeScriptFileCacheImpacts };
12
+ //# sourceMappingURL=createTypeScriptFileFromProgram.d.ts.map
@@ -0,0 +1,41 @@
1
+ import { convertTypeScriptDiagnosticToLanguageFileDiagnostic } from "./convertTypeScriptDiagnosticToLanguageFileDiagnostic.js";
2
+ import { collectReferencedFilePaths } from "./collectReferencedFilePaths.js";
3
+ import { getFirstEnumValues } from "./getFirstEnumValues.js";
4
+ import ts, { SyntaxKind } from "typescript";
5
+
6
+ //#region src/createTypeScriptFileFromProgram.ts
7
+ const NodeSyntaxKinds = getFirstEnumValues(SyntaxKind);
8
+ function collectTypeScriptFileCacheImpacts(program, sourceFile) {
9
+ return { dependencies: ["tsconfig.json", ...collectReferencedFilePaths(program, sourceFile)] };
10
+ }
11
+ function createTypeScriptFileFromProgram(data, program, sourceFile) {
12
+ return {
13
+ about: {
14
+ ...data,
15
+ sourceText: sourceFile.text
16
+ },
17
+ cache: collectTypeScriptFileCacheImpacts(program, sourceFile),
18
+ getDiagnostics() {
19
+ return ts.getPreEmitDiagnostics(program, sourceFile).map(convertTypeScriptDiagnosticToLanguageFileDiagnostic);
20
+ },
21
+ runVisitors(options, runtime) {
22
+ if (!runtime.visitors) return;
23
+ const { visitors } = runtime;
24
+ const fileServices = {
25
+ options,
26
+ program,
27
+ sourceFile,
28
+ typeChecker: program.getTypeChecker()
29
+ };
30
+ const visit = (node) => {
31
+ visitors[NodeSyntaxKinds[node.kind]]?.(node, fileServices);
32
+ node.forEachChild(visit);
33
+ };
34
+ visit(sourceFile);
35
+ }
36
+ };
37
+ }
38
+
39
+ //#endregion
40
+ export { NodeSyntaxKinds, collectTypeScriptFileCacheImpacts, createTypeScriptFileFromProgram };
41
+ //# sourceMappingURL=createTypeScriptFileFromProgram.js.map
@@ -0,0 +1,8 @@
1
+ import type * as ts from "typescript";
2
+ import type * as AST from "./types/ast.ts";
3
+ export declare function createTypeScriptFileFromProjectService(filePathAbsolute: string, program: ts.Program, service: ts.server.ProjectService): {
4
+ program: ts.Program;
5
+ sourceFile: AST.SourceFile;
6
+ [Symbol.dispose](): void;
7
+ };
8
+ //# sourceMappingURL=createTypeScriptFileFromProjectService.d.ts.map
@@ -0,0 +1,16 @@
1
+ //#region src/createTypeScriptFileFromProjectService.ts
2
+ function createTypeScriptFileFromProjectService(filePathAbsolute, program, service) {
3
+ const sourceFile = program.getSourceFile(filePathAbsolute);
4
+ if (!sourceFile) throw new Error(`Could not retrieve source file for: ${filePathAbsolute}`);
5
+ return {
6
+ program,
7
+ sourceFile,
8
+ [Symbol.dispose]() {
9
+ service.closeClientFile(filePathAbsolute);
10
+ }
11
+ };
12
+ }
13
+
14
+ //#endregion
15
+ export { createTypeScriptFileFromProjectService };
16
+ //# sourceMappingURL=createTypeScriptFileFromProjectService.js.map
@@ -0,0 +1,13 @@
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 };
13
+ //# sourceMappingURL=parseDirectivesFromTypeScriptFile.d.ts.map
@@ -0,0 +1,36 @@
1
+ import { normalizeRange } from "../normalizeRange.js";
2
+ import { DirectivesCollector } from "@flint.fyi/core";
3
+ import { nullThrows } from "@flint.fyi/utils";
4
+ import * as tsutils from "ts-api-utils";
5
+
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
+ const 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
+ directives.push({
21
+ range,
22
+ selection,
23
+ type
24
+ });
25
+ });
26
+ return directives;
27
+ }
28
+ function parseDirectivesFromTypeScriptFile(sourceFile) {
29
+ const collector = new DirectivesCollector(sourceFile.statements.at(0)?.getStart(sourceFile) ?? sourceFile.text.length);
30
+ for (const { range, selection, type } of extractDirectivesFromTypeScriptFile(sourceFile)) collector.add(range, selection, type);
31
+ return collector.collect();
32
+ }
33
+
34
+ //#endregion
35
+ export { extractDirectivesFromTypeScriptFile, parseDirectivesFromTypeScriptFile };
36
+ //# sourceMappingURL=parseDirectivesFromTypeScriptFile.js.map
@@ -0,0 +1,36 @@
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;
36
+ //# sourceMappingURL=getFirstEnumValues.d.ts.map
@@ -0,0 +1,48 @@
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
+
46
+ //#endregion
47
+ export { getFirstEnumValues };
48
+ //# sourceMappingURL=getFirstEnumValues.js.map
@@ -0,0 +1,9 @@
1
+ import { SourceFile } from "./types/ast.js";
2
+ import { CharacterReportRange } from "@flint.fyi/core";
3
+ import * as ts$1 from "typescript";
4
+
5
+ //#region src/getTSNodeRange.d.ts
6
+ declare function getTSNodeRange(node: ts$1.Node, sourceFile: SourceFile): CharacterReportRange;
7
+ //#endregion
8
+ export { getTSNodeRange };
9
+ //# sourceMappingURL=getTSNodeRange.d.ts.map
@@ -0,0 +1,11 @@
1
+ //#region src/getTSNodeRange.ts
2
+ function getTSNodeRange(node, sourceFile) {
3
+ return {
4
+ begin: node.getStart(sourceFile),
5
+ end: node.getEnd()
6
+ };
7
+ }
8
+
9
+ //#endregion
10
+ export { getTSNodeRange };
11
+ //# sourceMappingURL=getTSNodeRange.js.map
package/lib/index.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import { convertTypeScriptDiagnosticToLanguageFileDiagnostic } from "./convertTypeScriptDiagnosticToLanguageFileDiagnostic.js";
2
+ import { ast_d_exports } from "./types/ast.js";
3
+ import { TypeScriptNodesByName } from "./nodes.js";
4
+ import { Checker } from "./types/checker.js";
5
+ import { TypeScriptFileServices, typescriptLanguage } from "./language.js";
6
+ import { NodeSyntaxKinds, collectTypeScriptFileCacheImpacts } from "./createTypeScriptFileFromProgram.js";
7
+ import { ExtractedDirective, extractDirectivesFromTypeScriptFile } from "./directives/parseDirectivesFromTypeScriptFile.js";
8
+ import { getTSNodeRange } from "./getTSNodeRange.js";
9
+ import { TypeScriptBasedLanguageFile, TypeScriptBasedLanguageFileFactoryDefinition, prepareTypeScriptBasedLanguage } from "./prepareTypeScriptBasedLanguage.js";
10
+ import { declarationIncludesGlobal } from "./utils/declarationIncludesGlobal.js";
11
+ import { getDeclarationsIfGlobal } from "./utils/getDeclarationsIfGlobal.js";
12
+ import { getModifyingReferences } from "./utils/getModifyingReferences.js";
13
+ import { hasSameTokens } from "./utils/hasSameTokens.js";
14
+ import { isBuiltinArrayMethod } from "./utils/isBuiltinArrayMethod.js";
15
+ import { isFunction } from "./utils/isFunction.js";
16
+ import { isGlobalDeclaration } from "./utils/isGlobalDeclaration.js";
17
+ import { isGlobalDeclarationOfName } from "./utils/isGlobalDeclarationOfName.js";
18
+ import { isGlobalVariable } from "./utils/isGlobalVariable.js";
19
+ import { isInlineArrayCreation } from "./utils/isInlineArrayCreation.js";
20
+ import { unwrapParenthesizedExpression } from "./utils/unwrapParenthesizedExpression.js";
21
+ import { unwrapParenthesizedExpressionsParent } from "./utils/unwrapParentParenthesizedExpressions.js";
22
+ export { type ast_d_exports as AST, type Checker, type ExtractedDirective, NodeSyntaxKinds, type TypeScriptBasedLanguageFile, type TypeScriptBasedLanguageFileFactoryDefinition, TypeScriptFileServices, type TypeScriptNodesByName, collectTypeScriptFileCacheImpacts, convertTypeScriptDiagnosticToLanguageFileDiagnostic, declarationIncludesGlobal, extractDirectivesFromTypeScriptFile, getDeclarationsIfGlobal, getModifyingReferences, getTSNodeRange, hasSameTokens, isBuiltinArrayMethod, isFunction, isGlobalDeclaration, isGlobalDeclarationOfName, isGlobalVariable, isInlineArrayCreation, prepareTypeScriptBasedLanguage, typescriptLanguage, unwrapParenthesizedExpression, unwrapParenthesizedExpressionsParent };
package/lib/index.js ADDED
@@ -0,0 +1,20 @@
1
+ import { convertTypeScriptDiagnosticToLanguageFileDiagnostic } from "./convertTypeScriptDiagnosticToLanguageFileDiagnostic.js";
2
+ import { NodeSyntaxKinds, collectTypeScriptFileCacheImpacts } from "./createTypeScriptFileFromProgram.js";
3
+ import { extractDirectivesFromTypeScriptFile } from "./directives/parseDirectivesFromTypeScriptFile.js";
4
+ import { getTSNodeRange } from "./getTSNodeRange.js";
5
+ import { prepareTypeScriptBasedLanguage } from "./prepareTypeScriptBasedLanguage.js";
6
+ import { typescriptLanguage } from "./language.js";
7
+ import { declarationIncludesGlobal } from "./utils/declarationIncludesGlobal.js";
8
+ import { getDeclarationsIfGlobal } from "./utils/getDeclarationsIfGlobal.js";
9
+ import { getModifyingReferences } from "./utils/getModifyingReferences.js";
10
+ import { unwrapParenthesizedExpression } from "./utils/unwrapParenthesizedExpression.js";
11
+ import { hasSameTokens } from "./utils/hasSameTokens.js";
12
+ import { isBuiltinArrayMethod } from "./utils/isBuiltinArrayMethod.js";
13
+ import { isFunction } from "./utils/isFunction.js";
14
+ import { isGlobalDeclaration } from "./utils/isGlobalDeclaration.js";
15
+ import { isGlobalDeclarationOfName } from "./utils/isGlobalDeclarationOfName.js";
16
+ import { isGlobalVariable } from "./utils/isGlobalVariable.js";
17
+ import { isInlineArrayCreation } from "./utils/isInlineArrayCreation.js";
18
+ import { unwrapParenthesizedExpressionsParent } from "./utils/unwrapParentParenthesizedExpressions.js";
19
+
20
+ export { NodeSyntaxKinds, collectTypeScriptFileCacheImpacts, convertTypeScriptDiagnosticToLanguageFileDiagnostic, declarationIncludesGlobal, extractDirectivesFromTypeScriptFile, getDeclarationsIfGlobal, getModifyingReferences, getTSNodeRange, hasSameTokens, isBuiltinArrayMethod, isFunction, isGlobalDeclaration, isGlobalDeclarationOfName, isGlobalVariable, isInlineArrayCreation, prepareTypeScriptBasedLanguage, typescriptLanguage, unwrapParenthesizedExpression, unwrapParenthesizedExpressionsParent };
@@ -0,0 +1,16 @@
1
+ import { SourceFile } from "./types/ast.js";
2
+ import { TypeScriptNodesByName } from "./nodes.js";
3
+ import { Checker } from "./types/checker.js";
4
+ import * as _flint_fyi_core1 from "@flint.fyi/core";
5
+ import * as ts$1 from "typescript";
6
+
7
+ //#region src/language.d.ts
8
+ interface TypeScriptFileServices {
9
+ program: ts$1.Program;
10
+ sourceFile: SourceFile;
11
+ typeChecker: Checker;
12
+ }
13
+ declare const typescriptLanguage: _flint_fyi_core1.Language<TypeScriptNodesByName, TypeScriptFileServices>;
14
+ //#endregion
15
+ export { TypeScriptFileServices, typescriptLanguage };
16
+ //# sourceMappingURL=language.d.ts.map
@@ -0,0 +1,23 @@
1
+ import { prepareTypeScriptBasedLanguage } from "./prepareTypeScriptBasedLanguage.js";
2
+ import { prepareTypeScriptFile } from "./prepareTypeScriptFile.js";
3
+ import { createLanguage } from "@flint.fyi/core";
4
+
5
+ //#region src/language.ts
6
+ const typescriptLanguage = createLanguage({
7
+ about: { name: "TypeScript" },
8
+ createFileFactory: () => {
9
+ const language = prepareTypeScriptBasedLanguage();
10
+ return {
11
+ prepareFromDisk(data) {
12
+ return prepareTypeScriptFile(data, language.createFromDisk(data.filePathAbsolute));
13
+ },
14
+ prepareFromVirtual(data) {
15
+ return prepareTypeScriptFile(data, language.createFromVirtual(data.filePathAbsolute, data.sourceText));
16
+ }
17
+ };
18
+ }
19
+ });
20
+
21
+ //#endregion
22
+ export { typescriptLanguage };
23
+ //# sourceMappingURL=language.js.map
@@ -0,0 +1,2 @@
1
+ import { LanguageFileDiagnostic, SourceFileWithLineMapAndFileName } from "@flint.fyi/core";
2
+ import ts from "typescript";
@@ -0,0 +1,5 @@
1
+ import "./types/ast.js";
2
+ import "./nodes.js";
3
+ import "./language.js";
4
+ import { LanguageFileCacheImpacts } from "@flint.fyi/core";
5
+ import ts from "typescript";
@@ -0,0 +1,2 @@
1
+ import "../types/ast.js";
2
+ import { NormalizedReportRangeObject } from "@flint.fyi/core";
@@ -0,0 +1,3 @@
1
+ import "./types/ast.js";
2
+ import { CharacterReportRange } from "@flint.fyi/core";
3
+ import "typescript";
@@ -0,0 +1,21 @@
1
+ import "./convertTypeScriptDiagnosticToLanguageFileDiagnostic.js";
2
+ import "./types/ast.js";
3
+ import "./nodes.js";
4
+ import { Checker } from "./types/checker.js";
5
+ import "./language.js";
6
+ import "./createTypeScriptFileFromProgram.js";
7
+ import "./directives/parseDirectivesFromTypeScriptFile.js";
8
+ import "./getTSNodeRange.js";
9
+ import "./prepareTypeScriptBasedLanguage.js";
10
+ import "./utils/declarationIncludesGlobal.js";
11
+ import "./utils/getDeclarationsIfGlobal.js";
12
+ import "./utils/getModifyingReferences.js";
13
+ import "./utils/hasSameTokens.js";
14
+ import "./utils/isBuiltinArrayMethod.js";
15
+ import "./utils/isFunction.js";
16
+ import "./utils/isGlobalDeclaration.js";
17
+ import "./utils/isGlobalDeclarationOfName.js";
18
+ import "./utils/isGlobalVariable.js";
19
+ import "./utils/isInlineArrayCreation.js";
20
+ import "./utils/unwrapParenthesizedExpression.js";
21
+ import "./utils/unwrapParentParenthesizedExpressions.js";
@@ -0,0 +1,5 @@
1
+ import "./types/ast.js";
2
+ import "./nodes.js";
3
+ import "./types/checker.js";
4
+ import "@flint.fyi/core";
5
+ import "typescript";
@@ -0,0 +1 @@
1
+ import "./types/ast.js";
@@ -0,0 +1,2 @@
1
+ import "./types/ast.js";
2
+ import ts from "typescript";