@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 +3 -3
- package/lib/language.d.ts +2 -1
- package/lib/language.js +2 -1
- package/lib/new/getJsonNodeRange.d.ts +8 -0
- package/lib/new/getJsonNodeRange.js +11 -0
- package/lib/new/getNodeText.d.ts +7 -0
- package/lib/new/getNodeText.js +8 -0
- package/lib/new/index.d.ts +5 -0
- package/lib/new/index.js +4 -0
- package/lib/new/language.d.ts +13 -0
- package/lib/new/language.js +36 -0
- package/lib/new/nodes.d.ts +10 -0
- package/lib/nodes.d.ts +4 -2
- package/package.json +6 -4
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { JsonNode, JsonSourceFile } from "./nodes.js";
|
|
2
2
|
import { getJsonNodeRange } from "./getJsonNodeRange.js";
|
|
3
|
-
import {
|
|
4
|
-
export {
|
|
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 {
|
|
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,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 };
|
package/lib/new/index.js
ADDED
|
@@ -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 {
|
|
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.
|
|
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.
|
|
28
|
-
"@flint.fyi/typescript-language": "^0.18.
|
|
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",
|