@flint.fyi/json-language 0.16.3 → 0.17.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/lib/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { JsonMinusNumericLiteral, JsonNode, JsonNodeName, JsonNodeVisitors, JsonNodesByName, JsonObjectExpression, JsonObjectExpressionStatement, JsonSourceFile } from "./nodes.js";
1
+ import { JsonNode, JsonSourceFile } from "./nodes.js";
2
2
  import { getJsonNodeRange } from "./getJsonNodeRange.js";
3
- import { JsonFileServices, jsonLanguage } from "./language.js";
4
- export { JsonFileServices, JsonMinusNumericLiteral, JsonNode, JsonNodeName, JsonNodeVisitors, JsonNodesByName, JsonObjectExpression, JsonObjectExpressionStatement, JsonSourceFile, getJsonNodeRange, jsonLanguage };
3
+ import { jsonLanguage } from "./language.js";
4
+ export { type JsonNode, type JsonSourceFile, getJsonNodeRange, jsonLanguage };
package/lib/language.d.ts CHANGED
@@ -5,7 +5,8 @@ import { Language } from "@flint.fyi/core";
5
5
  interface JsonFileServices {
6
6
  sourceFile: JsonSourceFile;
7
7
  }
8
+ /** @deprecated Use the new `momoa` based language exported from `@flint.fyi/json-language/new` instead */
8
9
  declare const jsonLanguage: Language<JsonNodeVisitors, JsonFileServices>;
9
10
  //#endregion
10
- export { JsonFileServices, jsonLanguage };
11
+ export { jsonLanguage };
11
12
  //# sourceMappingURL=language.d.ts.map
package/lib/language.js CHANGED
@@ -1,7 +1,8 @@
1
- import { createLanguage } from "@flint.fyi/core";
2
1
  import * as ts from "typescript";
2
+ import { createLanguage } from "@flint.fyi/core";
3
3
  //#region src/language.ts
4
4
  const kindOverrides = new Map([[ts.SyntaxKind.SourceFile, "JsonSourceFile"]]);
5
+ /** @deprecated Use the new `momoa` based language exported from `@flint.fyi/json-language/new` instead */
5
6
  const jsonLanguage = createLanguage({
6
7
  about: { name: "JSON" },
7
8
  createFileFactory: () => {
@@ -0,0 +1,8 @@
1
+ import { CharacterReportRange } from "@flint.fyi/core";
2
+ import { AnyNode } from "@humanwhocodes/momoa";
3
+
4
+ //#region src/new/getJsonNodeRange.d.ts
5
+ declare function getJsonNodeRange(node: AnyNode): CharacterReportRange;
6
+ //#endregion
7
+ export { getJsonNodeRange };
8
+ //# sourceMappingURL=getJsonNodeRange.d.ts.map
@@ -0,0 +1,11 @@
1
+ //#region src/new/getJsonNodeRange.ts
2
+ function getJsonNodeRange(node) {
3
+ return {
4
+ begin: node.range[0],
5
+ end: node.range[1]
6
+ };
7
+ }
8
+ //#endregion
9
+ export { getJsonNodeRange };
10
+
11
+ //# sourceMappingURL=getJsonNodeRange.js.map
@@ -0,0 +1,7 @@
1
+ import { ValueNode } from "@humanwhocodes/momoa";
2
+
3
+ //#region src/new/getNodeText.d.ts
4
+ declare function getNodeText(node: ValueNode, sourceText: string): string;
5
+ //#endregion
6
+ export { getNodeText };
7
+ //# sourceMappingURL=getNodeText.d.ts.map
@@ -0,0 +1,8 @@
1
+ //#region src/new/getNodeText.ts
2
+ function getNodeText(node, sourceText) {
3
+ return sourceText.slice(node.range[0], node.range[1]);
4
+ }
5
+ //#endregion
6
+ export { getNodeText };
7
+
8
+ //# sourceMappingURL=getNodeText.js.map
@@ -0,0 +1,5 @@
1
+ import { getJsonNodeRange } from "./getJsonNodeRange.js";
2
+ import { getNodeText } from "./getNodeText.js";
3
+ import { JsonVisitorKey } from "./nodes.js";
4
+ import { jsonLanguage } from "./language.js";
5
+ export { type JsonVisitorKey, getJsonNodeRange, getNodeText, jsonLanguage };
@@ -0,0 +1,4 @@
1
+ import { getJsonNodeRange } from "./getJsonNodeRange.js";
2
+ import { getNodeText } from "./getNodeText.js";
3
+ import { jsonLanguage } from "./language.js";
4
+ export { getJsonNodeRange, getNodeText, jsonLanguage };
@@ -0,0 +1,13 @@
1
+ import { JsonNodeVisitors } from "./nodes.js";
2
+ import { Language } from "@flint.fyi/core";
3
+ import { DocumentNode } from "@humanwhocodes/momoa";
4
+
5
+ //#region src/new/language.d.ts
6
+ interface JsonFileServices {
7
+ root: DocumentNode;
8
+ sourceText: string;
9
+ }
10
+ declare const jsonLanguage: Language<JsonNodeVisitors, JsonFileServices>;
11
+ //#endregion
12
+ export { jsonLanguage };
13
+ //# sourceMappingURL=language.d.ts.map
@@ -0,0 +1,36 @@
1
+ import { createLanguage } from "@flint.fyi/core";
2
+ import { parse, traverse } from "@humanwhocodes/momoa";
3
+ //#region src/new/language.ts
4
+ const jsonLanguage = createLanguage({
5
+ about: { name: "JSON" },
6
+ createFileFactory: () => {
7
+ return { createFile: (data) => {
8
+ return {
9
+ about: data,
10
+ services: {
11
+ root: parse(data.sourceText, {
12
+ mode: "json",
13
+ ranges: true
14
+ }),
15
+ sourceText: data.sourceText
16
+ }
17
+ };
18
+ } };
19
+ },
20
+ runFileVisitors: (file, options, runtime) => {
21
+ if (!runtime.visitors) return;
22
+ const { visitors } = runtime;
23
+ const visitorServices = {
24
+ options,
25
+ ...file.services
26
+ };
27
+ traverse(file.services.root, {
28
+ enter: (node) => visitors[node.type]?.(node, visitorServices),
29
+ exit: (node) => visitors[`${node.type}:exit`]?.(node, visitorServices)
30
+ });
31
+ }
32
+ });
33
+ //#endregion
34
+ export { jsonLanguage };
35
+
36
+ //# sourceMappingURL=language.js.map
@@ -0,0 +1,10 @@
1
+ import { WithExitKeys } from "@flint.fyi/core";
2
+ import { AnyNode } from "@humanwhocodes/momoa";
3
+
4
+ //#region src/new/nodes.d.ts
5
+ type JsonNodesByName = { [Node in AnyNode as Node["type"]]: Node };
6
+ type JsonNodeVisitors = WithExitKeys<JsonNodesByName>;
7
+ type JsonVisitorKey = AnyNode["type"];
8
+ //#endregion
9
+ export { JsonNodeVisitors, JsonVisitorKey };
10
+ //# sourceMappingURL=nodes.d.ts.map
package/lib/nodes.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { WithExitKeys } from "@flint.fyi/core";
2
1
  import * as ts from "typescript";
2
+ import { WithExitKeys } from "@flint.fyi/core";
3
3
  import { AST } from "@flint.fyi/typescript-language";
4
4
 
5
5
  //#region src/nodes.d.ts
@@ -12,12 +12,14 @@ type JsonNodeName = keyof JsonNodesByName;
12
12
  interface JsonNodesByName {
13
13
  ArrayLiteralExpression: AST.ArrayLiteralExpression;
14
14
  BooleanLiteral: AST.BooleanLiteral;
15
+ JsonExpression: AST.Expression;
15
16
  JsonMinusNumericLiteral: JsonMinusNumericLiteral;
16
17
  JsonObjectExpressionStatement: JsonObjectExpressionStatement;
17
18
  JsonSourceFile: JsonSourceFile;
18
19
  NullLiteral: AST.NullLiteral;
19
20
  NumericLiteral: AST.NumericLiteral;
20
21
  ObjectLiteralExpression: AST.ObjectLiteralExpression;
22
+ PropertyAssignment: AST.PropertyAssignment;
21
23
  StringLiteral: AST.StringLiteral;
22
24
  }
23
25
  type JsonNodeVisitors = WithExitKeys<JsonNodesByName>;
@@ -29,5 +31,5 @@ type JsonSourceFile = Omit<AST.SourceFile, "statements"> & {
29
31
  readonly statements: ts.NodeArray<JsonObjectExpressionStatement>;
30
32
  };
31
33
  //#endregion
32
- export { JsonMinusNumericLiteral, JsonNode, JsonNodeName, JsonNodeVisitors, JsonNodesByName, JsonObjectExpression, JsonObjectExpressionStatement, JsonSourceFile };
34
+ export { JsonNode, JsonNodeVisitors, JsonSourceFile };
33
35
  //# sourceMappingURL=nodes.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flint.fyi/json-language",
3
- "version": "0.16.3",
3
+ "version": "0.17.0",
4
4
  "description": "[Experimental] JSON language for Flint.",
5
5
  "homepage": "https://flint.fyi",
6
6
  "repository": {
@@ -16,16 +16,18 @@
16
16
  "sideEffects": false,
17
17
  "type": "module",
18
18
  "exports": {
19
- ".": "./lib/index.js"
19
+ ".": "./lib/index.js",
20
+ "./new": "./lib/new/index.js"
20
21
  },
21
22
  "files": [
22
23
  "lib/",
23
24
  "!lib/**/*.map"
24
25
  ],
25
26
  "dependencies": {
27
+ "@humanwhocodes/momoa": "^3.3.10",
26
28
  "typescript": "^5.9.0 || ^6.0.0",
27
- "@flint.fyi/core": "^0.22.0",
28
- "@flint.fyi/typescript-language": "^0.18.2"
29
+ "@flint.fyi/core": "^0.23.0",
30
+ "@flint.fyi/typescript-language": "^0.18.3"
29
31
  },
30
32
  "devDependencies": {
31
33
  "tsdown": "0.21.0",