@flint.fyi/json-language 0.16.0 → 0.16.2

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.
@@ -0,0 +1,8 @@
1
+ import { JsonNode, JsonSourceFile } from "./nodes.js";
2
+ import { CharacterReportRange } from "@flint.fyi/core";
3
+
4
+ //#region src/getJsonNodeRange.d.ts
5
+ declare function getJsonNodeRange(node: JsonNode, sourceFile: JsonSourceFile): CharacterReportRange;
6
+ //#endregion
7
+ export { getJsonNodeRange };
8
+ //# sourceMappingURL=getJsonNodeRange.d.ts.map
@@ -0,0 +1,11 @@
1
+ //#region src/getJsonNodeRange.ts
2
+ function getJsonNodeRange(node, sourceFile) {
3
+ return {
4
+ begin: node.getStart(sourceFile),
5
+ end: node.getEnd()
6
+ };
7
+ }
8
+ //#endregion
9
+ export { getJsonNodeRange };
10
+
11
+ //# sourceMappingURL=getJsonNodeRange.js.map
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- import { JsonNodesByName } from "./nodes.js";
1
+ import { JsonMinusNumericLiteral, JsonNode, JsonNodeName, JsonNodeVisitors, JsonNodesByName, JsonObjectExpression, JsonObjectExpressionStatement, JsonSourceFile } from "./nodes.js";
2
+ import { getJsonNodeRange } from "./getJsonNodeRange.js";
2
3
  import { JsonFileServices, jsonLanguage } from "./language.js";
3
- export { JsonFileServices, JsonNodesByName, jsonLanguage };
4
+ export { JsonFileServices, JsonMinusNumericLiteral, JsonNode, JsonNodeName, JsonNodeVisitors, JsonNodesByName, JsonObjectExpression, JsonObjectExpressionStatement, JsonSourceFile, getJsonNodeRange, jsonLanguage };
package/lib/index.js CHANGED
@@ -1,3 +1,3 @@
1
+ import { getJsonNodeRange } from "./getJsonNodeRange.js";
1
2
  import { jsonLanguage } from "./language.js";
2
-
3
- export { jsonLanguage };
3
+ export { getJsonNodeRange, jsonLanguage };
package/lib/language.d.ts CHANGED
@@ -1,12 +1,11 @@
1
- import { JsonNodesByName } from "./nodes.js";
2
- import * as _flint_fyi_core0 from "@flint.fyi/core";
3
- import * as ts$1 from "typescript";
1
+ import { JsonNodeVisitors, JsonSourceFile } from "./nodes.js";
2
+ import { Language } from "@flint.fyi/core";
4
3
 
5
4
  //#region src/language.d.ts
6
5
  interface JsonFileServices {
7
- sourceFile: ts$1.JsonSourceFile;
6
+ sourceFile: JsonSourceFile;
8
7
  }
9
- declare const jsonLanguage: _flint_fyi_core0.Language<JsonNodesByName, JsonFileServices>;
8
+ declare const jsonLanguage: Language<JsonNodeVisitors, JsonFileServices>;
10
9
  //#endregion
11
10
  export { JsonFileServices, jsonLanguage };
12
11
  //# sourceMappingURL=language.d.ts.map
package/lib/language.js CHANGED
@@ -1,25 +1,34 @@
1
- import { createTypeScriptJsonFile } from "./createJsonFile.js";
2
1
  import { createLanguage } from "@flint.fyi/core";
3
- import fsSync from "node:fs";
4
-
2
+ import * as ts from "typescript";
5
3
  //#region src/language.ts
4
+ const kindOverrides = new Map([[ts.SyntaxKind.SourceFile, "JsonSourceFile"]]);
6
5
  const jsonLanguage = createLanguage({
7
6
  about: { name: "JSON" },
8
7
  createFileFactory: () => {
9
- return {
10
- prepareFromDisk: (data) => {
11
- return { file: createTypeScriptJsonFile({
12
- ...data,
13
- sourceText: fsSync.readFileSync(data.filePathAbsolute, "utf8")
14
- }) };
15
- },
16
- prepareFromVirtual: (data) => {
17
- return { file: createTypeScriptJsonFile(data) };
18
- }
8
+ return { createFile: (data) => {
9
+ return {
10
+ about: data,
11
+ services: { sourceFile: ts.parseJsonText(data.filePathAbsolute, data.sourceText) }
12
+ };
13
+ } };
14
+ },
15
+ runFileVisitors: (file, options, runtime) => {
16
+ if (!runtime.visitors) return;
17
+ const { visitors } = runtime;
18
+ const visitorServices = {
19
+ options,
20
+ ...file.services
21
+ };
22
+ const visit = (node) => {
23
+ const key = kindOverrides.get(node.kind) ?? ts.SyntaxKind[node.kind];
24
+ visitors[key]?.(node, visitorServices);
25
+ node.forEachChild(visit);
26
+ visitors[`${key}:exit`]?.(node, visitorServices);
19
27
  };
28
+ visit(file.services.sourceFile);
20
29
  }
21
30
  });
22
-
23
31
  //#endregion
24
32
  export { jsonLanguage };
33
+
25
34
  //# sourceMappingURL=language.js.map
package/lib/nodes.d.ts CHANGED
@@ -1,17 +1,33 @@
1
- import * as ts$1 from "typescript";
1
+ import { WithExitKeys } from "@flint.fyi/core";
2
+ import * as ts from "typescript";
3
+ import { AST } from "@flint.fyi/typescript-language";
2
4
 
3
5
  //#region src/nodes.d.ts
6
+ type JsonMinusNumericLiteral = Omit<AST.PrefixUnaryExpression, "operand" | "operator"> & {
7
+ readonly operand: AST.NumericLiteral;
8
+ readonly operator: ts.SyntaxKind.MinusToken;
9
+ };
10
+ type JsonNode = JsonNodesByName[JsonNodeName];
11
+ type JsonNodeName = keyof JsonNodesByName;
4
12
  interface JsonNodesByName {
5
- ArrayLiteralExpression: ts$1.ArrayLiteralExpression;
6
- BooleanLiteral: ts$1.BooleanLiteral;
7
- JsonMinusNumericLiteral: ts$1.JsonMinusNumericLiteral;
8
- JsonObjectExpressionStatement: ts$1.JsonObjectExpressionStatement;
9
- JsonSourceFile: ts$1.JsonSourceFile;
10
- NullLiteral: ts$1.NullLiteral;
11
- NumericLiteral: ts$1.NumericLiteral;
12
- ObjectLiteralExpression: ts$1.ObjectLiteralExpression;
13
- StringLiteral: ts$1.StringLiteral;
13
+ ArrayLiteralExpression: AST.ArrayLiteralExpression;
14
+ BooleanLiteral: AST.BooleanLiteral;
15
+ JsonMinusNumericLiteral: JsonMinusNumericLiteral;
16
+ JsonObjectExpressionStatement: JsonObjectExpressionStatement;
17
+ JsonSourceFile: JsonSourceFile;
18
+ NullLiteral: AST.NullLiteral;
19
+ NumericLiteral: AST.NumericLiteral;
20
+ ObjectLiteralExpression: AST.ObjectLiteralExpression;
21
+ StringLiteral: AST.StringLiteral;
14
22
  }
23
+ type JsonNodeVisitors = WithExitKeys<JsonNodesByName>;
24
+ type JsonObjectExpression = AST.ArrayLiteralExpression | AST.BooleanLiteral | AST.NullLiteral | AST.NumericLiteral | AST.ObjectLiteralExpression | AST.StringLiteral | JsonMinusNumericLiteral;
25
+ type JsonObjectExpressionStatement = Omit<AST.ExpressionStatement, "expression"> & {
26
+ readonly expression: JsonObjectExpression;
27
+ };
28
+ type JsonSourceFile = Omit<AST.SourceFile, "statements"> & {
29
+ readonly statements: ts.NodeArray<JsonObjectExpressionStatement>;
30
+ };
15
31
  //#endregion
16
- export { JsonNodesByName };
32
+ export { JsonMinusNumericLiteral, JsonNode, JsonNodeName, JsonNodeVisitors, JsonNodesByName, JsonObjectExpression, JsonObjectExpressionStatement, JsonSourceFile };
17
33
  //# sourceMappingURL=nodes.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@flint.fyi/json-language",
3
- "version": "0.16.0",
3
+ "version": "0.16.2",
4
4
  "description": "[Experimental] JSON language for Flint.",
5
+ "homepage": "https://flint.fyi",
5
6
  "repository": {
6
7
  "type": "git",
7
8
  "url": "git+https://github.com/flint-fyi/flint.git",
@@ -23,11 +24,12 @@
23
24
  ],
24
25
  "dependencies": {
25
26
  "typescript": "^5.9.0 || ^6.0.0",
26
- "@flint.fyi/core": "^0.19.0"
27
+ "@flint.fyi/core": "^0.21.0",
28
+ "@flint.fyi/typescript-language": "^0.18.0"
27
29
  },
28
30
  "devDependencies": {
29
- "tsdown": "0.19.0-beta.2",
30
- "vitest": "4.0.15"
31
+ "tsdown": "0.21.0",
32
+ "vitest": "4.1.0"
31
33
  },
32
34
  "engines": {
33
35
  "node": ">=24.0.0"
@@ -36,6 +38,6 @@
36
38
  "access": "public"
37
39
  },
38
40
  "scripts": {
39
- "test": "vitest --typecheck --project json-language"
41
+ "test": "vitest --project json-language"
40
42
  }
41
43
  }
@@ -1,5 +0,0 @@
1
- import type { FileDiskData, LanguageFileDefinition } from "@flint.fyi/core";
2
- import type { JsonFileServices } from "./language.ts";
3
- import type { JsonNodesByName } from "./nodes.ts";
4
- export declare function createTypeScriptJsonFile(data: FileDiskData): LanguageFileDefinition<JsonNodesByName, JsonFileServices>;
5
- //# sourceMappingURL=createJsonFile.d.ts.map
@@ -1,26 +0,0 @@
1
- import ts from "typescript";
2
-
3
- //#region src/createJsonFile.ts
4
- function createTypeScriptJsonFile(data) {
5
- const sourceFile = ts.parseJsonText(data.filePathAbsolute, data.sourceText);
6
- return {
7
- about: data,
8
- runVisitors(options, runtime) {
9
- if (!runtime.visitors) return;
10
- const { visitors } = runtime;
11
- const fileServices = {
12
- options,
13
- sourceFile
14
- };
15
- const visit = (node) => {
16
- visitors[ts.SyntaxKind[node.kind]]?.(node, fileServices);
17
- node.forEachChild(visit);
18
- };
19
- sourceFile.forEachChild(visit);
20
- }
21
- };
22
- }
23
-
24
- //#endregion
25
- export { createTypeScriptJsonFile };
26
- //# sourceMappingURL=createJsonFile.js.map