@spyglassmc/nbt 0.3.51 → 0.3.53
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/index.js +49 -38
- package/package.json +4 -4
package/lib/checker/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as core from '@spyglassmc/core';
|
|
2
2
|
import { localeQuote, localize } from '@spyglassmc/locales';
|
|
3
3
|
import * as mcdoc from '@spyglassmc/mcdoc';
|
|
4
|
-
import { NbtCompoundNode, NbtNode, NbtPathFilterNode, NbtPathIndexNode, NbtPathKeyNode, NbtPrimitiveNode, NbtStringNode, } from '../node/index.js';
|
|
4
|
+
import { NbtByteNode, NbtCollectionNode, NbtCompoundNode, NbtIntegerAlikeNode, NbtListNode, NbtNode, NbtNumberNode, NbtPathFilterNode, NbtPathIndexNode, NbtPathKeyNode, NbtPrimitiveNode, NbtStringNode, } from '../node/index.js';
|
|
5
5
|
import { getBlocksFromItem, getEntityFromItem } from './mcdocUtil.js';
|
|
6
6
|
export const typed = (node, ctx) => {
|
|
7
7
|
typeDefinition(node.targetType)(node.children[0], ctx);
|
|
@@ -53,31 +53,42 @@ export function typeDefinition(typeDef, options = {}) {
|
|
|
53
53
|
mcdoc.runtime.checker.typeDefinition([{ originalNode: node, inferredType: inferType(node) }], typeDef, mcdoc.runtime.checker.McdocCheckerContext.create(ctx, {
|
|
54
54
|
allowMissingKeys: options.isPredicate || options.isMerge,
|
|
55
55
|
requireCanonical: options.isPredicate,
|
|
56
|
-
|
|
57
|
-
if (
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
tryConvertTo: (node, target) => {
|
|
57
|
+
if (target.kind === 'boolean' && NbtByteNode.is(node)) {
|
|
58
|
+
if (node.value === 0) {
|
|
59
|
+
return { kind: 'literal', value: { kind: 'boolean', value: false } };
|
|
60
|
+
}
|
|
61
|
+
else if (node.value === 1) {
|
|
62
|
+
return { kind: 'literal', value: { kind: 'boolean', value: true } };
|
|
63
|
+
}
|
|
63
64
|
}
|
|
64
|
-
if (
|
|
65
|
-
return
|
|
65
|
+
if (target.kind === 'tuple' && NbtListNode.is(node)) {
|
|
66
|
+
return {
|
|
67
|
+
kind: 'tuple',
|
|
68
|
+
items: [],
|
|
69
|
+
};
|
|
66
70
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
71
|
+
if (!options.isPredicate) {
|
|
72
|
+
if (NbtNumberNode.is(node)) {
|
|
73
|
+
const literalValue = mcdoc.LiteralNumericValue.makeIfValid(target.kind, node.value, NbtIntegerAlikeNode.is(node), true);
|
|
74
|
+
if (literalValue !== undefined) {
|
|
75
|
+
return { kind: 'literal', value: literalValue };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (NbtCollectionNode.is(node)) {
|
|
79
|
+
switch (target.kind) {
|
|
80
|
+
case 'list':
|
|
81
|
+
return { kind: 'list', item: { kind: 'any' } };
|
|
82
|
+
case 'byte_array':
|
|
83
|
+
case 'int_array':
|
|
84
|
+
case 'long_array':
|
|
85
|
+
return { kind: target.kind };
|
|
86
|
+
case 'tuple':
|
|
87
|
+
return { kind: 'tuple', items: [] };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
80
90
|
}
|
|
91
|
+
return undefined;
|
|
81
92
|
},
|
|
82
93
|
getChildren: node => {
|
|
83
94
|
const { type } = node;
|
|
@@ -99,7 +110,7 @@ export function typeDefinition(typeDef, options = {}) {
|
|
|
99
110
|
if (options.isPredicate && error.kind === 'invalid_collection_length') {
|
|
100
111
|
return;
|
|
101
112
|
}
|
|
102
|
-
mcdoc.runtime.checker.getDefaultErrorReporter(ctx,
|
|
113
|
+
mcdoc.runtime.checker.getDefaultErrorReporter(ctx, mcdoc.runtime.checker.getDefaultErrorRange)(error);
|
|
103
114
|
},
|
|
104
115
|
attachTypeInfo: (node, definition, desc = '') => {
|
|
105
116
|
node.typeDef = definition;
|
|
@@ -151,11 +162,7 @@ function inferType(node) {
|
|
|
151
162
|
case 'nbt:float':
|
|
152
163
|
return { kind: 'literal', value: { kind: 'float', value: node.value } };
|
|
153
164
|
case 'nbt:long':
|
|
154
|
-
return {
|
|
155
|
-
kind: 'literal',
|
|
156
|
-
// TODO: this should NOT change type from `bigint` to `number`
|
|
157
|
-
value: { kind: 'long', value: Number(node.value) },
|
|
158
|
-
};
|
|
165
|
+
return { kind: 'literal', value: { kind: 'long', value: node.value } };
|
|
159
166
|
case 'nbt:int':
|
|
160
167
|
return { kind: 'literal', value: { kind: 'int', value: node.value } };
|
|
161
168
|
case 'nbt:short':
|
|
@@ -232,16 +239,20 @@ export function path(registry, id) {
|
|
|
232
239
|
mcdoc.runtime.checker.typeDefinition([{ originalNode: link, inferredType: inferPath(link) }], typeDef, mcdoc.runtime.checker.McdocCheckerContext.create(ctx, {
|
|
233
240
|
allowMissingKeys: true,
|
|
234
241
|
requireCanonical: true,
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
242
|
+
tryConvertTo: (node, target) => {
|
|
243
|
+
if (NbtPathIndexNode.is(node.node)) {
|
|
244
|
+
switch (target.kind) {
|
|
245
|
+
case 'list':
|
|
246
|
+
return { kind: 'list', item: { kind: 'any' } };
|
|
247
|
+
case 'byte_array':
|
|
248
|
+
case 'int_array':
|
|
249
|
+
case 'long_array':
|
|
250
|
+
return { kind: target.kind };
|
|
251
|
+
case 'tuple':
|
|
252
|
+
return { kind: 'tuple', items: [] };
|
|
253
|
+
}
|
|
244
254
|
}
|
|
255
|
+
return undefined;
|
|
245
256
|
},
|
|
246
257
|
getChildren: (link) => {
|
|
247
258
|
while (link.next && link.node.type !== 'leaf' && NbtPathFilterNode.is(link.node)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spyglassmc/nbt",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.53",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"url": "https://github.com/SpyglassMC/Spyglass/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@spyglassmc/core": "0.4.
|
|
29
|
-
"@spyglassmc/locales": "0.3.
|
|
30
|
-
"@spyglassmc/mcdoc": "0.3.
|
|
28
|
+
"@spyglassmc/core": "0.4.47",
|
|
29
|
+
"@spyglassmc/locales": "0.3.24",
|
|
30
|
+
"@spyglassmc/mcdoc": "0.3.51"
|
|
31
31
|
}
|
|
32
32
|
}
|