@flint.fyi/json-language 0.16.0 → 0.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { JsonNodesByName } from "./nodes.js";
1
+ import { JsonNodeVisitors, JsonNodesByName } from "./nodes.js";
2
2
  import { JsonFileServices, jsonLanguage } from "./language.js";
3
- export { JsonFileServices, JsonNodesByName, jsonLanguage };
3
+ export { JsonFileServices, JsonNodeVisitors, JsonNodesByName, jsonLanguage };
package/lib/language.d.ts CHANGED
@@ -1,12 +1,22 @@
1
1
  import { JsonNodesByName } from "./nodes.js";
2
2
  import * as _flint_fyi_core0 from "@flint.fyi/core";
3
- import * as ts$1 from "typescript";
3
+ import * as ts from "typescript";
4
4
 
5
5
  //#region src/language.d.ts
6
6
  interface JsonFileServices {
7
- sourceFile: ts$1.JsonSourceFile;
7
+ sourceFile: ts.JsonSourceFile;
8
8
  }
9
- declare const jsonLanguage: _flint_fyi_core0.Language<JsonNodesByName, JsonFileServices>;
9
+ declare const jsonLanguage: _flint_fyi_core0.Language<_flint_fyi_core0.Simplify<JsonNodesByName & {
10
+ "ArrayLiteralExpression:exit"?: ts.ArrayLiteralExpression;
11
+ "BooleanLiteral:exit"?: ts.BooleanLiteral;
12
+ "JsonMinusNumericLiteral:exit"?: ts.JsonMinusNumericLiteral;
13
+ "JsonObjectExpressionStatement:exit"?: ts.JsonObjectExpressionStatement;
14
+ "JsonSourceFile:exit"?: ts.JsonSourceFile;
15
+ "NullLiteral:exit"?: ts.NullLiteral;
16
+ "NumericLiteral:exit"?: ts.NumericLiteral;
17
+ "ObjectLiteralExpression:exit"?: ts.ObjectLiteralExpression;
18
+ "StringLiteral:exit"?: ts.StringLiteral;
19
+ }>, JsonFileServices>;
10
20
  //#endregion
11
21
  export { JsonFileServices, jsonLanguage };
12
22
  //# sourceMappingURL=language.d.ts.map
package/lib/language.js CHANGED
@@ -1,22 +1,31 @@
1
- import { createTypeScriptJsonFile } from "./createJsonFile.js";
2
1
  import { createLanguage } from "@flint.fyi/core";
3
- import fsSync from "node:fs";
2
+ import * as ts from "typescript";
4
3
 
5
4
  //#region src/language.ts
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
19
21
  };
22
+ const visit = (node) => {
23
+ const key = ts.SyntaxKind[node.kind];
24
+ visitors[key]?.(node, visitorServices);
25
+ node.forEachChild(visit);
26
+ visitors[`${key}:exit`]?.(node, visitorServices);
27
+ };
28
+ visit(file.services.sourceFile);
20
29
  }
21
30
  });
22
31
 
package/lib/nodes.d.ts CHANGED
@@ -1,17 +1,19 @@
1
- import * as ts$1 from "typescript";
1
+ import { WithExitKeys } from "@flint.fyi/core";
2
+ import * as ts from "typescript";
2
3
 
3
4
  //#region src/nodes.d.ts
4
5
  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;
6
+ ArrayLiteralExpression: ts.ArrayLiteralExpression;
7
+ BooleanLiteral: ts.BooleanLiteral;
8
+ JsonMinusNumericLiteral: ts.JsonMinusNumericLiteral;
9
+ JsonObjectExpressionStatement: ts.JsonObjectExpressionStatement;
10
+ JsonSourceFile: ts.JsonSourceFile;
11
+ NullLiteral: ts.NullLiteral;
12
+ NumericLiteral: ts.NumericLiteral;
13
+ ObjectLiteralExpression: ts.ObjectLiteralExpression;
14
+ StringLiteral: ts.StringLiteral;
14
15
  }
16
+ type JsonNodeVisitors = WithExitKeys<JsonNodesByName>;
15
17
  //#endregion
16
- export { JsonNodesByName };
18
+ export { JsonNodeVisitors, JsonNodesByName };
17
19
  //# 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.1",
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,10 +24,10 @@
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.20.0"
27
28
  },
28
29
  "devDependencies": {
29
- "tsdown": "0.19.0-beta.2",
30
+ "tsdown": "0.20.1",
30
31
  "vitest": "4.0.15"
31
32
  },
32
33
  "engines": {
@@ -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