@spyglassmc/json 0.1.2 → 0.3.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/checker/JsonChecker.d.ts +1 -1
- package/lib/checker/JsonChecker.js +1 -2
- package/lib/checker/index.d.ts +2 -2
- package/lib/checker/index.js +2 -18
- package/lib/checker/primitives/boolean.d.ts +2 -2
- package/lib/checker/primitives/boolean.js +6 -10
- package/lib/checker/primitives/index.d.ts +6 -6
- package/lib/checker/primitives/index.js +6 -22
- package/lib/checker/primitives/list.d.ts +2 -2
- package/lib/checker/primitives/list.js +12 -17
- package/lib/checker/primitives/number.d.ts +1 -1
- package/lib/checker/primitives/number.js +12 -15
- package/lib/checker/primitives/object.d.ts +2 -2
- package/lib/checker/primitives/object.js +36 -50
- package/lib/checker/primitives/string.d.ts +6 -6
- package/lib/checker/primitives/string.js +16 -45
- package/lib/checker/primitives/util.d.ts +2 -2
- package/lib/checker/primitives/util.js +15 -24
- package/lib/colorizer/index.d.ts +1 -1
- package/lib/colorizer/index.js +12 -42
- package/lib/completer/index.d.ts +1 -1
- package/lib/completer/index.js +24 -54
- package/lib/formatter/index.d.ts +1 -1
- package/lib/formatter/index.js +5 -32
- package/lib/index.d.ts +7 -7
- package/lib/index.js +11 -41
- package/lib/node/JsonAstNode.d.ts +4 -4
- package/lib/node/JsonAstNode.js +25 -51
- package/lib/node/index.d.ts +1 -1
- package/lib/node/index.js +1 -17
- package/lib/parser/array.d.ts +1 -1
- package/lib/parser/array.js +4 -31
- package/lib/parser/boolean.d.ts +1 -1
- package/lib/parser/boolean.js +5 -32
- package/lib/parser/entry.d.ts +1 -1
- package/lib/parser/entry.js +15 -42
- package/lib/parser/index.d.ts +5 -5
- package/lib/parser/index.js +5 -21
- package/lib/parser/null.d.ts +1 -1
- package/lib/parser/null.js +4 -31
- package/lib/parser/number.d.ts +1 -1
- package/lib/parser/number.js +2 -29
- package/lib/parser/object.d.ts +1 -1
- package/lib/parser/object.js +5 -32
- package/lib/parser/string.d.ts +1 -1
- package/lib/parser/string.js +4 -31
- package/package.json +4 -3
- package/lib/util.d.ts +0 -1
- package/lib/util.js +0 -2
|
@@ -1,31 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const core_1 = require("@spyglassmc/core");
|
|
5
|
-
const locales_1 = require("@spyglassmc/locales");
|
|
6
|
-
function ref(checker) {
|
|
1
|
+
import { ErrorReporter, Range, StateProxy } from '@spyglassmc/core';
|
|
2
|
+
import { arrayToMessage, localize } from '@spyglassmc/locales';
|
|
3
|
+
export function ref(checker) {
|
|
7
4
|
return (node, ctx) => {
|
|
8
5
|
return checker()(node, ctx);
|
|
9
6
|
};
|
|
10
7
|
}
|
|
11
|
-
|
|
12
|
-
function as(context, checker) {
|
|
8
|
+
export function as(context, checker) {
|
|
13
9
|
return (node, ctx) => {
|
|
14
10
|
checker(node, { ...ctx, context });
|
|
15
11
|
};
|
|
16
12
|
}
|
|
17
|
-
|
|
18
|
-
function attempt(checker, node, ctx) {
|
|
13
|
+
export function attempt(checker, node, ctx) {
|
|
19
14
|
// TODO: The code below is mostly copied from core with some changes to support `expectation`. Could be refactored... I guess.
|
|
20
15
|
const tempCtx = {
|
|
21
16
|
...ctx,
|
|
22
|
-
err: new
|
|
23
|
-
ops: new core_1.Operations(),
|
|
17
|
+
err: new ErrorReporter(),
|
|
24
18
|
symbols: ctx.symbols.clone(),
|
|
25
19
|
};
|
|
26
20
|
checker(node, tempCtx);
|
|
27
21
|
const tempExpectation = node.expectation;
|
|
28
|
-
|
|
22
|
+
StateProxy.undoChanges(node);
|
|
29
23
|
const totalErrorSpan = tempCtx.err.errors
|
|
30
24
|
.map(e => e.range.end - e.range.start)
|
|
31
25
|
.reduce((a, b) => a + b, 0);
|
|
@@ -35,13 +29,12 @@ function attempt(checker, node, ctx) {
|
|
|
35
29
|
expectation: tempExpectation,
|
|
36
30
|
updateNodeAndCtx: () => {
|
|
37
31
|
ctx.err.absorb(tempCtx.err);
|
|
38
|
-
|
|
32
|
+
StateProxy.redoChanges(node);
|
|
39
33
|
tempCtx.symbols.applyDelayedEdits();
|
|
40
34
|
},
|
|
41
35
|
};
|
|
42
36
|
}
|
|
43
|
-
|
|
44
|
-
function any(checkers = []) {
|
|
37
|
+
export function any(checkers = []) {
|
|
45
38
|
return (node, ctx) => {
|
|
46
39
|
if (checkers.length === 0) {
|
|
47
40
|
return;
|
|
@@ -53,25 +46,23 @@ function any(checkers = []) {
|
|
|
53
46
|
.filter(a => a.expectation?.map(e => e.type).includes(node.type));
|
|
54
47
|
const allExpectations = attempts.filter(a => a.expectation).flatMap(a => a.expectation);
|
|
55
48
|
if (sameTypeAttempts.length === 0) {
|
|
56
|
-
const allowedTypes = allExpectations.map(e =>
|
|
57
|
-
ctx.err.report(
|
|
49
|
+
const allowedTypes = allExpectations.map(e => localize(e.type.slice(5)));
|
|
50
|
+
ctx.err.report(localize('expected', arrayToMessage(allowedTypes, false)), node);
|
|
58
51
|
}
|
|
59
52
|
else {
|
|
60
53
|
sameTypeAttempts[0].updateNodeAndCtx();
|
|
61
54
|
}
|
|
62
|
-
|
|
55
|
+
node.expectation = allExpectations;
|
|
63
56
|
};
|
|
64
57
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const node = { type: 'json:null', range: core_1.Range.create(0) };
|
|
58
|
+
export function expectation(checker, ctx) {
|
|
59
|
+
const node = StateProxy.create({ type: 'json:null', range: Range.create(0) });
|
|
68
60
|
const tempCtx = {
|
|
69
61
|
...ctx,
|
|
70
|
-
err: new
|
|
62
|
+
err: new ErrorReporter(),
|
|
71
63
|
depth: (ctx.depth ?? 0) + 1,
|
|
72
64
|
};
|
|
73
65
|
checker(node, tempCtx);
|
|
74
66
|
return node.expectation;
|
|
75
67
|
}
|
|
76
|
-
exports.expectation = expectation;
|
|
77
68
|
//# sourceMappingURL=util.js.map
|
package/lib/colorizer/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Colorizer, MetaRegistry } from '@spyglassmc/core';
|
|
2
|
-
import type { JsonBooleanNode, JsonNullNode, JsonObjectNode } from '../node';
|
|
2
|
+
import type { JsonBooleanNode, JsonNullNode, JsonObjectNode } from '../node/index.js';
|
|
3
3
|
export declare const boolean: Colorizer<JsonBooleanNode>;
|
|
4
4
|
export declare const null_: Colorizer<JsonNullNode>;
|
|
5
5
|
export declare const object: Colorizer<JsonObjectNode>;
|
package/lib/colorizer/index.js
CHANGED
|
@@ -1,44 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.register = exports.object = exports.null_ = exports.boolean = void 0;
|
|
27
|
-
const core = __importStar(require("@spyglassmc/core"));
|
|
28
|
-
const core_1 = require("@spyglassmc/core");
|
|
29
|
-
const boolean = node => {
|
|
30
|
-
return [core_1.ColorToken.create(node, 'literal')];
|
|
1
|
+
import * as core from '@spyglassmc/core';
|
|
2
|
+
import { ColorToken } from '@spyglassmc/core';
|
|
3
|
+
export const boolean = node => {
|
|
4
|
+
return [ColorToken.create(node, 'literal')];
|
|
31
5
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return [core_1.ColorToken.create(node, 'literal')];
|
|
6
|
+
export const null_ = node => {
|
|
7
|
+
return [ColorToken.create(node, 'literal')];
|
|
35
8
|
};
|
|
36
|
-
|
|
37
|
-
const object = (node, ctx) => {
|
|
9
|
+
export const object = (node, ctx) => {
|
|
38
10
|
const ans = [];
|
|
39
11
|
for (const pair of node.children) {
|
|
40
12
|
if (pair.key) {
|
|
41
|
-
ans.push(
|
|
13
|
+
ans.push(ColorToken.create(pair.key, 'property'));
|
|
42
14
|
}
|
|
43
15
|
if (pair.value) {
|
|
44
16
|
const colorizer = ctx.meta.getColorizer(pair.value.type);
|
|
@@ -47,13 +19,11 @@ const object = (node, ctx) => {
|
|
|
47
19
|
}
|
|
48
20
|
return ans;
|
|
49
21
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
meta.registerColorizer('json:
|
|
53
|
-
meta.registerColorizer('json:null', exports.null_);
|
|
22
|
+
export function register(meta) {
|
|
23
|
+
meta.registerColorizer('json:boolean', boolean);
|
|
24
|
+
meta.registerColorizer('json:null', null_);
|
|
54
25
|
meta.registerColorizer('json:number', core.colorizer.number);
|
|
55
|
-
meta.registerColorizer('json:object',
|
|
26
|
+
meta.registerColorizer('json:object', object);
|
|
56
27
|
meta.registerColorizer('json:string', core.colorizer.string);
|
|
57
28
|
}
|
|
58
|
-
exports.register = register;
|
|
59
29
|
//# sourceMappingURL=index.js.map
|
package/lib/completer/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Completer, MetaRegistry } from '@spyglassmc/core';
|
|
2
|
-
import type { JsonArrayNode, JsonBooleanNode, JsonNode, JsonObjectNode } from '../node';
|
|
2
|
+
import type { JsonArrayNode, JsonBooleanNode, JsonNode, JsonObjectNode } from '../node/index.js';
|
|
3
3
|
export declare const JsonTriggerCharacters: string[];
|
|
4
4
|
export declare const entry: Completer<JsonNode>;
|
|
5
5
|
export declare const object: Completer<JsonObjectNode>;
|
package/lib/completer/index.js
CHANGED
|
@@ -1,33 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.register = exports.boolean = exports.array = exports.object = exports.entry = exports.JsonTriggerCharacters = void 0;
|
|
27
|
-
const core = __importStar(require("@spyglassmc/core"));
|
|
28
|
-
const core_1 = require("@spyglassmc/core");
|
|
29
|
-
const node_1 = require("../node");
|
|
30
|
-
exports.JsonTriggerCharacters = ['\n', ':', '"'];
|
|
1
|
+
import * as core from '@spyglassmc/core';
|
|
2
|
+
import { CompletionItem, Range } from '@spyglassmc/core';
|
|
3
|
+
import { JsonExpectation } from '../node/index.js';
|
|
4
|
+
export const JsonTriggerCharacters = ['\n', ':', '"'];
|
|
31
5
|
const SIMPLE_SNIPPETS = {
|
|
32
6
|
'json:object': '{$1}',
|
|
33
7
|
'json:array': '[$1]',
|
|
@@ -35,24 +9,23 @@ const SIMPLE_SNIPPETS = {
|
|
|
35
9
|
'json:boolean': '${1|false,true|}',
|
|
36
10
|
'json:number': '${1:0}',
|
|
37
11
|
};
|
|
38
|
-
const entry = (node, ctx) => {
|
|
12
|
+
export const entry = (node, ctx) => {
|
|
39
13
|
return core.completer.dispatch(node, ctx);
|
|
40
14
|
};
|
|
41
|
-
|
|
42
|
-
exports.object = core.completer.record({
|
|
15
|
+
export const object = core.completer.record({
|
|
43
16
|
key: (record, pair, ctx, range, insertValue, insertComma) => {
|
|
44
17
|
if (record.expectation) {
|
|
45
|
-
return unique(record.expectation.filter(
|
|
18
|
+
return unique(record.expectation.filter(JsonExpectation.isObject)
|
|
46
19
|
.flatMap(e => objectCompletion(range, record, e, ctx, insertValue, insertComma, pair?.key?.value)));
|
|
47
20
|
}
|
|
48
21
|
return [];
|
|
49
22
|
},
|
|
50
23
|
value: (record, pair, ctx) => {
|
|
51
|
-
if (pair.value && !
|
|
24
|
+
if (pair.value && !Range.isEmpty(pair.value)) {
|
|
52
25
|
return core.completer.dispatch(pair.value, ctx);
|
|
53
26
|
}
|
|
54
27
|
if (record.expectation) {
|
|
55
|
-
return unique(record.expectation.filter(
|
|
28
|
+
return unique(record.expectation.filter(JsonExpectation.isObject)
|
|
56
29
|
.filter(e => e.fields)
|
|
57
30
|
.map(e => e.fields.find(f => f.key === pair.key?.value))
|
|
58
31
|
.flatMap(f => valueCompletion(ctx.offset, f.value, ctx)));
|
|
@@ -60,32 +33,30 @@ exports.object = core.completer.record({
|
|
|
60
33
|
return [];
|
|
61
34
|
},
|
|
62
35
|
});
|
|
63
|
-
const array = (node, ctx) => {
|
|
36
|
+
export const array = (node, ctx) => {
|
|
64
37
|
const index = core.binarySearch(node.children, ctx.offset, (n, o) => n.sep
|
|
65
|
-
?
|
|
66
|
-
:
|
|
38
|
+
? Range.compareOffset(Range.translate(n, 0, -1), o, true)
|
|
39
|
+
: Range.compareOffset(n.range, o, true));
|
|
67
40
|
const item = index >= 0 ? node.children[index] : undefined;
|
|
68
41
|
if (item?.value) {
|
|
69
42
|
return core.completer.dispatch(item.value, ctx);
|
|
70
43
|
}
|
|
71
|
-
if (node.expectation &&
|
|
72
|
-
return unique(node.expectation.filter(
|
|
44
|
+
if (node.expectation && Range.contains(Range.translate(node, 1, -1), ctx.offset, true)) {
|
|
45
|
+
return unique(node.expectation.filter(JsonExpectation.isArray)
|
|
73
46
|
.filter(e => e.items)
|
|
74
47
|
.flatMap(e => valueCompletion(ctx.offset, e.items, ctx)));
|
|
75
48
|
}
|
|
76
49
|
return [];
|
|
77
50
|
};
|
|
78
|
-
|
|
79
|
-
const boolean = (node) => {
|
|
51
|
+
export const boolean = (node) => {
|
|
80
52
|
return ['false', 'true'].map(v => simpleCompletion(node, v));
|
|
81
53
|
};
|
|
82
|
-
exports.boolean = boolean;
|
|
83
54
|
const string = (node, ctx) => {
|
|
84
55
|
if (node.children?.length) {
|
|
85
56
|
return core.completer.string(node, ctx);
|
|
86
57
|
}
|
|
87
58
|
if (node.expectation) {
|
|
88
|
-
return unique(node.expectation.filter(
|
|
59
|
+
return unique(node.expectation.filter(JsonExpectation.isString)
|
|
89
60
|
.flatMap(e => stringCompletion(node, e, ctx)));
|
|
90
61
|
}
|
|
91
62
|
return [];
|
|
@@ -107,7 +78,7 @@ function objectCompletion(range, node, expectation, ctx, insertValue, insertComm
|
|
|
107
78
|
}
|
|
108
79
|
function fieldCompletion(range, field, insertValue, insertComma) {
|
|
109
80
|
const value = field.value?.[0] ? SIMPLE_SNIPPETS[field.value[0].type] : '';
|
|
110
|
-
return
|
|
81
|
+
return CompletionItem.create(field.key, range, {
|
|
111
82
|
kind: 10 /* CompletionKind.Property */,
|
|
112
83
|
detail: field.value?.map(e => e.typedoc).join(' | '),
|
|
113
84
|
sortText: `${field.deprecated ? 2 : field.opt ? 1 : 0}${field.key}`,
|
|
@@ -133,7 +104,7 @@ function valueCompletion(range, expectation, ctx) {
|
|
|
133
104
|
}
|
|
134
105
|
function stringCompletion(range, expectation, ctx) {
|
|
135
106
|
if (Array.isArray(expectation.pool)) {
|
|
136
|
-
return expectation.pool.map(v =>
|
|
107
|
+
return expectation.pool.map(v => CompletionItem.create(v, range, {
|
|
137
108
|
kind: 12 /* CompletionKind.Value */,
|
|
138
109
|
filterText: `"${v}"`,
|
|
139
110
|
insertText: `"${v}"`,
|
|
@@ -142,7 +113,7 @@ function stringCompletion(range, expectation, ctx) {
|
|
|
142
113
|
return [simpleCompletion(range, SIMPLE_SNIPPETS[expectation.type])];
|
|
143
114
|
}
|
|
144
115
|
function simpleCompletion(range, value) {
|
|
145
|
-
return
|
|
116
|
+
return CompletionItem.create(value.replace('$1', ''), range, {
|
|
146
117
|
kind: 12 /* CompletionKind.Value */,
|
|
147
118
|
insertText: value,
|
|
148
119
|
});
|
|
@@ -158,12 +129,11 @@ function unique(completions) {
|
|
|
158
129
|
});
|
|
159
130
|
return ans;
|
|
160
131
|
}
|
|
161
|
-
function register(meta) {
|
|
162
|
-
meta.registerCompleter('json:entry',
|
|
163
|
-
meta.registerCompleter('json:array',
|
|
164
|
-
meta.registerCompleter('json:boolean',
|
|
165
|
-
meta.registerCompleter('json:object',
|
|
132
|
+
export function register(meta) {
|
|
133
|
+
meta.registerCompleter('json:entry', entry);
|
|
134
|
+
meta.registerCompleter('json:array', array);
|
|
135
|
+
meta.registerCompleter('json:boolean', boolean);
|
|
136
|
+
meta.registerCompleter('json:object', object);
|
|
166
137
|
meta.registerCompleter('json:string', string);
|
|
167
138
|
}
|
|
168
|
-
exports.register = register;
|
|
169
139
|
//# sourceMappingURL=index.js.map
|
package/lib/formatter/index.d.ts
CHANGED
package/lib/formatter/index.js
CHANGED
|
@@ -1,36 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.register = void 0;
|
|
27
|
-
const core = __importStar(require("@spyglassmc/core"));
|
|
28
|
-
const lib_1 = require("../../../core/lib");
|
|
1
|
+
import * as core from '@spyglassmc/core';
|
|
2
|
+
import { indentFormatter } from '@spyglassmc/core';
|
|
29
3
|
const array = (node, ctx) => {
|
|
30
4
|
if (node.children.length === 0)
|
|
31
5
|
return '[]';
|
|
32
6
|
const values = node.children.map(child => {
|
|
33
|
-
const value = child.value && ctx.meta.getFormatter(child.value.type)(child.value,
|
|
7
|
+
const value = child.value && ctx.meta.getFormatter(child.value.type)(child.value, indentFormatter(ctx));
|
|
34
8
|
return `${ctx.indent(1)}${value ?? ''}`;
|
|
35
9
|
});
|
|
36
10
|
return `[\n${values.join(',\n')}\n${ctx.indent()}]`;
|
|
@@ -40,12 +14,12 @@ const object = (node, ctx) => {
|
|
|
40
14
|
return '{}';
|
|
41
15
|
const fields = node.children.map(child => {
|
|
42
16
|
const key = child.key && core.formatter.string(child.key, ctx);
|
|
43
|
-
const value = child.value && ctx.meta.getFormatter(child.value.type)(child.value,
|
|
17
|
+
const value = child.value && ctx.meta.getFormatter(child.value.type)(child.value, indentFormatter(ctx));
|
|
44
18
|
return `${ctx.indent(1)}${key ?? ''}: ${value ?? ''}`;
|
|
45
19
|
});
|
|
46
20
|
return `{\n${fields.join(',\n')}\n${ctx.indent()}}`;
|
|
47
21
|
};
|
|
48
|
-
function register(meta) {
|
|
22
|
+
export function register(meta) {
|
|
49
23
|
meta.registerFormatter('json:array', array);
|
|
50
24
|
meta.registerFormatter('json:boolean', core.formatter.boolean);
|
|
51
25
|
meta.registerFormatter('json:null', () => 'null');
|
|
@@ -53,5 +27,4 @@ function register(meta) {
|
|
|
53
27
|
meta.registerFormatter('json:object', object);
|
|
54
28
|
meta.registerFormatter('json:string', core.formatter.string);
|
|
55
29
|
}
|
|
56
|
-
exports.register = register;
|
|
57
30
|
//# sourceMappingURL=index.js.map
|
package/lib/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type * as core from '@spyglassmc/core';
|
|
2
|
-
export * as checker from './checker';
|
|
3
|
-
export * as colorizer from './colorizer';
|
|
4
|
-
export * as completer from './completer';
|
|
5
|
-
export * as formatter from './formatter';
|
|
6
|
-
export * from './node';
|
|
7
|
-
export * as parser from './parser';
|
|
8
|
-
export declare const initialize: core.
|
|
2
|
+
export * as checker from './checker/index.js';
|
|
3
|
+
export * as colorizer from './colorizer/index.js';
|
|
4
|
+
export * as completer from './completer/index.js';
|
|
5
|
+
export * as formatter from './formatter/index.js';
|
|
6
|
+
export * from './node/index.js';
|
|
7
|
+
export * as parser from './parser/index.js';
|
|
8
|
+
export declare const initialize: core.SyncProjectInitializer;
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.js
CHANGED
|
@@ -1,44 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/* istanbul ignore file */
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
})
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
-
if (mod && mod.__esModule) return mod;
|
|
21
|
-
var result = {};
|
|
22
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
-
__setModuleDefault(result, mod);
|
|
24
|
-
return result;
|
|
25
|
-
};
|
|
26
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
27
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
28
|
-
};
|
|
29
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.initialize = exports.parser = exports.formatter = exports.completer = exports.colorizer = exports.checker = void 0;
|
|
31
|
-
const colorizer = __importStar(require("./colorizer"));
|
|
32
|
-
const completer = __importStar(require("./completer"));
|
|
33
|
-
const formatter = __importStar(require("./formatter"));
|
|
34
|
-
const parser = __importStar(require("./parser"));
|
|
35
|
-
exports.checker = __importStar(require("./checker"));
|
|
36
|
-
exports.colorizer = __importStar(require("./colorizer"));
|
|
37
|
-
exports.completer = __importStar(require("./completer"));
|
|
38
|
-
exports.formatter = __importStar(require("./formatter"));
|
|
39
|
-
__exportStar(require("./node"), exports);
|
|
40
|
-
exports.parser = __importStar(require("./parser"));
|
|
41
|
-
const initialize = ({ meta }) => {
|
|
2
|
+
import * as colorizer from './colorizer/index.js';
|
|
3
|
+
import * as completer from './completer/index.js';
|
|
4
|
+
import * as formatter from './formatter/index.js';
|
|
5
|
+
import * as parser from './parser/index.js';
|
|
6
|
+
export * as checker from './checker/index.js';
|
|
7
|
+
export * as colorizer from './colorizer/index.js';
|
|
8
|
+
export * as completer from './completer/index.js';
|
|
9
|
+
export * as formatter from './formatter/index.js';
|
|
10
|
+
export * from './node/index.js';
|
|
11
|
+
export * as parser from './parser/index.js';
|
|
12
|
+
export const initialize = ({ meta }) => {
|
|
42
13
|
meta.registerLanguage('json', {
|
|
43
14
|
extensions: ['.json', '.mcmeta'],
|
|
44
15
|
triggerCharacters: completer.JsonTriggerCharacters,
|
|
@@ -49,5 +20,4 @@ const initialize = ({ meta }) => {
|
|
|
49
20
|
completer.register(meta);
|
|
50
21
|
formatter.register(meta);
|
|
51
22
|
};
|
|
52
|
-
exports.initialize = initialize;
|
|
53
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ItemNode, PairNode } from '@spyglassmc/core';
|
|
1
|
+
import type { DeepReadonly, ItemNode, PairNode } from '@spyglassmc/core';
|
|
2
2
|
import * as core from '@spyglassmc/core';
|
|
3
3
|
export declare type JsonNode = JsonObjectNode | JsonArrayNode | JsonStringNode | JsonNumberNode | JsonBooleanNode | JsonNullNode;
|
|
4
4
|
export declare type JsonRelatedNode = JsonNode | JsonPairNode | JsonItemNode;
|
|
@@ -11,9 +11,9 @@ interface JsonBaseAstNode {
|
|
|
11
11
|
}
|
|
12
12
|
export declare type JsonExpectation = JsonObjectExpectation | JsonArrayExpectation | JsonStringExpectation | JsonNumberExpectation | JsonBooleanExpectation;
|
|
13
13
|
export declare namespace JsonExpectation {
|
|
14
|
-
function isArray(e: JsonExpectation): e is JsonArrayExpectation
|
|
15
|
-
function isObject(e: JsonExpectation): e is JsonObjectExpectation
|
|
16
|
-
function isString(e: JsonExpectation): e is JsonStringExpectation
|
|
14
|
+
function isArray(e: DeepReadonly<JsonExpectation>): e is DeepReadonly<JsonArrayExpectation>;
|
|
15
|
+
function isObject(e: DeepReadonly<JsonExpectation>): e is DeepReadonly<JsonObjectExpectation>;
|
|
16
|
+
function isString(e: DeepReadonly<JsonExpectation>): e is DeepReadonly<JsonStringExpectation>;
|
|
17
17
|
}
|
|
18
18
|
interface JsonBaseExpectation {
|
|
19
19
|
typedoc: string;
|
package/lib/node/JsonAstNode.js
CHANGED
|
@@ -1,32 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.JsonNullNode = exports.JsonBooleanNode = exports.JsonNumberNode = exports.JsonStringNode = exports.JsonStringExpectation = exports.JsonItemNode = exports.JsonArrayNode = exports.JsonPairNode = exports.JsonObjectNode = exports.JsonExpectation = exports.JsonNode = void 0;
|
|
27
|
-
const core = __importStar(require("@spyglassmc/core"));
|
|
28
|
-
const parser_1 = require("../parser");
|
|
29
|
-
var JsonNode;
|
|
1
|
+
import * as core from '@spyglassmc/core';
|
|
2
|
+
import { JsonStringOptions } from '../parser/index.js';
|
|
3
|
+
export var JsonNode;
|
|
30
4
|
(function (JsonNode) {
|
|
31
5
|
function is(node) {
|
|
32
6
|
return (JsonObjectNode.is(node) ||
|
|
@@ -43,8 +17,8 @@ var JsonNode;
|
|
|
43
17
|
JsonItemNode.is(node));
|
|
44
18
|
}
|
|
45
19
|
JsonNode.isRelated = isRelated;
|
|
46
|
-
})(JsonNode
|
|
47
|
-
var JsonExpectation;
|
|
20
|
+
})(JsonNode || (JsonNode = {}));
|
|
21
|
+
export var JsonExpectation;
|
|
48
22
|
(function (JsonExpectation) {
|
|
49
23
|
function isArray(e) {
|
|
50
24
|
return e.type === 'json:array';
|
|
@@ -58,8 +32,8 @@ var JsonExpectation;
|
|
|
58
32
|
return e.type === 'json:string';
|
|
59
33
|
}
|
|
60
34
|
JsonExpectation.isString = isString;
|
|
61
|
-
})(JsonExpectation
|
|
62
|
-
var JsonObjectNode;
|
|
35
|
+
})(JsonExpectation || (JsonExpectation = {}));
|
|
36
|
+
export var JsonObjectNode;
|
|
63
37
|
(function (JsonObjectNode) {
|
|
64
38
|
/* istanbul ignore next */
|
|
65
39
|
function is(obj) {
|
|
@@ -74,16 +48,16 @@ var JsonObjectNode;
|
|
|
74
48
|
};
|
|
75
49
|
}
|
|
76
50
|
JsonObjectNode.mock = mock;
|
|
77
|
-
})(JsonObjectNode
|
|
78
|
-
var JsonPairNode;
|
|
51
|
+
})(JsonObjectNode || (JsonObjectNode = {}));
|
|
52
|
+
export var JsonPairNode;
|
|
79
53
|
(function (JsonPairNode) {
|
|
80
54
|
/* istanbul ignore next */
|
|
81
55
|
function is(obj) {
|
|
82
56
|
return obj.type === 'pair';
|
|
83
57
|
}
|
|
84
58
|
JsonPairNode.is = is;
|
|
85
|
-
})(JsonPairNode
|
|
86
|
-
var JsonArrayNode;
|
|
59
|
+
})(JsonPairNode || (JsonPairNode = {}));
|
|
60
|
+
export var JsonArrayNode;
|
|
87
61
|
(function (JsonArrayNode) {
|
|
88
62
|
function is(obj) {
|
|
89
63
|
return obj?.type === 'json:array';
|
|
@@ -97,24 +71,24 @@ var JsonArrayNode;
|
|
|
97
71
|
};
|
|
98
72
|
}
|
|
99
73
|
JsonArrayNode.mock = mock;
|
|
100
|
-
})(JsonArrayNode
|
|
101
|
-
var JsonItemNode;
|
|
74
|
+
})(JsonArrayNode || (JsonArrayNode = {}));
|
|
75
|
+
export var JsonItemNode;
|
|
102
76
|
(function (JsonItemNode) {
|
|
103
77
|
/* istanbul ignore next */
|
|
104
78
|
function is(obj) {
|
|
105
79
|
return obj.type === 'item';
|
|
106
80
|
}
|
|
107
81
|
JsonItemNode.is = is;
|
|
108
|
-
})(JsonItemNode
|
|
109
|
-
var JsonStringExpectation;
|
|
82
|
+
})(JsonItemNode || (JsonItemNode = {}));
|
|
83
|
+
export var JsonStringExpectation;
|
|
110
84
|
(function (JsonStringExpectation) {
|
|
111
85
|
/* istanbul ignore next */
|
|
112
86
|
function is(obj) {
|
|
113
87
|
return obj.type === 'json:string';
|
|
114
88
|
}
|
|
115
89
|
JsonStringExpectation.is = is;
|
|
116
|
-
})(JsonStringExpectation
|
|
117
|
-
var JsonStringNode;
|
|
90
|
+
})(JsonStringExpectation || (JsonStringExpectation = {}));
|
|
91
|
+
export var JsonStringNode;
|
|
118
92
|
(function (JsonStringNode) {
|
|
119
93
|
/* istanbul ignore next */
|
|
120
94
|
function is(obj) {
|
|
@@ -123,34 +97,34 @@ var JsonStringNode;
|
|
|
123
97
|
JsonStringNode.is = is;
|
|
124
98
|
function mock(range) {
|
|
125
99
|
return {
|
|
126
|
-
...core.StringNode.mock(range,
|
|
100
|
+
...core.StringNode.mock(range, JsonStringOptions),
|
|
127
101
|
type: 'json:string',
|
|
128
102
|
};
|
|
129
103
|
}
|
|
130
104
|
JsonStringNode.mock = mock;
|
|
131
|
-
})(JsonStringNode
|
|
132
|
-
var JsonNumberNode;
|
|
105
|
+
})(JsonStringNode || (JsonStringNode = {}));
|
|
106
|
+
export var JsonNumberNode;
|
|
133
107
|
(function (JsonNumberNode) {
|
|
134
108
|
/* istanbul ignore next */
|
|
135
109
|
function is(obj) {
|
|
136
110
|
return obj.type === 'json:number';
|
|
137
111
|
}
|
|
138
112
|
JsonNumberNode.is = is;
|
|
139
|
-
})(JsonNumberNode
|
|
140
|
-
var JsonBooleanNode;
|
|
113
|
+
})(JsonNumberNode || (JsonNumberNode = {}));
|
|
114
|
+
export var JsonBooleanNode;
|
|
141
115
|
(function (JsonBooleanNode) {
|
|
142
116
|
/* istanbul ignore next */
|
|
143
117
|
function is(obj) {
|
|
144
118
|
return obj.type === 'json:boolean';
|
|
145
119
|
}
|
|
146
120
|
JsonBooleanNode.is = is;
|
|
147
|
-
})(JsonBooleanNode
|
|
148
|
-
var JsonNullNode;
|
|
121
|
+
})(JsonBooleanNode || (JsonBooleanNode = {}));
|
|
122
|
+
export var JsonNullNode;
|
|
149
123
|
(function (JsonNullNode) {
|
|
150
124
|
/* istanbul ignore next */
|
|
151
125
|
function is(obj) {
|
|
152
126
|
return obj.type === 'json:null';
|
|
153
127
|
}
|
|
154
128
|
JsonNullNode.is = is;
|
|
155
|
-
})(JsonNullNode
|
|
129
|
+
})(JsonNullNode || (JsonNullNode = {}));
|
|
156
130
|
//# sourceMappingURL=JsonAstNode.js.map
|
package/lib/node/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './JsonAstNode';
|
|
1
|
+
export * from './JsonAstNode.js';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|