@spyglassmc/nbt 0.1.1 → 0.1.2

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.
@@ -1,7 +1,6 @@
1
1
  import * as core from '@spyglassmc/core';
2
- import * as nbtdoc from '@spyglassmc/nbtdoc';
3
- import type { NbtNode, NbtPathNode } from '../node';
4
- import { NbtCompoundNode, NbtPrimitiveNode } from '../node';
2
+ import * as mcdoc from '@spyglassmc/mcdoc';
3
+ import type { NbtCompoundNode, NbtNode, NbtPathNode, NbtPrimitiveNode } from '../node';
5
4
  interface Options {
6
5
  allowUnknownKey?: boolean;
7
6
  isPredicate?: boolean;
@@ -13,28 +12,24 @@ declare global {
13
12
  }
14
13
  /**
15
14
  * @param id If the registry is under the `custom` namespace, `id` can only be a string. Otherwise it can be a string, string array, or `undefined`.
16
- * If set to `undefined` or an empty array, all nbtdoc compound definitions for this registry will be merged for checking, and unknown keys are allowed.
15
+ * If set to `undefined` or an empty array, all mcdoc compound definitions for this registry will be merged for checking, and unknown keys are allowed.
17
16
  */
18
- export declare function index(registry: nbtdoc.ExtendableRootRegistry, id: core.FullResourceLocation | readonly core.FullResourceLocation[] | undefined, options?: Options): core.SyncChecker<NbtCompoundNode>;
19
- export declare function index(registry: nbtdoc.ResolvedRootRegistry, id: core.FullResourceLocation, options?: Options): core.SyncChecker<NbtCompoundNode>;
17
+ export declare function index(registry: string, id: core.FullResourceLocation | readonly core.FullResourceLocation[] | undefined, options?: Options): core.SyncChecker<NbtCompoundNode>;
18
+ export declare function index(registry: string, id: core.FullResourceLocation, options?: Options): core.SyncChecker<NbtCompoundNode>;
20
19
  /**
21
- * @param identifier An identifier of nbtdoc compound definition. e.g. `::minecraft::util::invitem::InventoryItem`
20
+ * @param identifier An identifier of mcdoc compound definition. e.g. `::minecraft::util::invitem::InventoryItem`
22
21
  */
23
22
  export declare function definition(identifier: `::${string}::${string}`, options?: Options): core.SyncChecker<NbtCompoundNode>;
24
23
  export declare function blockStates(blocks: string[], _options?: Options): core.SyncChecker<NbtCompoundNode>;
25
24
  /**
26
25
  * @param path The {@link core.SymbolPath} to the compound definition.
27
26
  */
28
- export declare function compound(data: ResolvedCompoundData, options?: Options): core.SyncChecker<NbtCompoundNode>;
27
+ export declare function compound(data: any, options?: Options): core.SyncChecker<NbtCompoundNode>;
29
28
  export declare function enum_(path: core.SymbolPath | undefined, _options?: Options): core.SyncChecker<NbtPrimitiveNode>;
30
29
  /**
31
- * @param id If set to `undefined` or an empty array, all nbtdoc compound definitions for this registry will be merged for checking, and unknown keys are allowed.
30
+ * @param id If set to `undefined` or an empty array, all mcdoc compound definitions for this registry will be merged for checking, and unknown keys are allowed.
32
31
  */
33
- export declare function path(registry: nbtdoc.ExtendableRootRegistry, id: core.FullResourceLocation | readonly core.FullResourceLocation[] | undefined): core.SyncChecker<NbtPathNode>;
34
- export declare function fieldValue(type: nbtdoc.NbtdocType, options: Options): core.SyncChecker<NbtNode>;
35
- declare type ResolvedCompoundData = Record<string, {
36
- data: nbtdoc.NbtdocType;
37
- query: core.SymbolQuery;
38
- }>;
32
+ export declare function path(registry: string, id: core.FullResourceLocation | readonly core.FullResourceLocation[] | undefined): core.SyncChecker<NbtPathNode>;
33
+ export declare function fieldValue(type: mcdoc.McdocType, options: Options): core.SyncChecker<NbtNode>;
39
34
  export {};
40
35
  //# sourceMappingURL=index.d.ts.map
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -21,47 +25,46 @@ var __importStar = (this && this.__importStar) || function (mod) {
21
25
  Object.defineProperty(exports, "__esModule", { value: true });
22
26
  exports.fieldValue = exports.path = exports.enum_ = exports.compound = exports.blockStates = exports.definition = exports.index = void 0;
23
27
  const core = __importStar(require("@spyglassmc/core"));
24
- const nbtdoc = __importStar(require("@spyglassmc/nbtdoc"));
25
- const nbtdoc_1 = require("@spyglassmc/nbtdoc");
28
+ const mcdoc = __importStar(require("@spyglassmc/mcdoc"));
26
29
  const lib_1 = require("../../../locales/lib");
27
30
  const node_1 = require("../node");
28
31
  const util_1 = require("../util");
29
- const nbtdocUtil_1 = require("./nbtdocUtil");
32
+ const mcdocUtil_1 = require("./mcdocUtil");
30
33
  function index(registry, id, options = {}) {
31
34
  switch (registry) {
32
35
  case 'custom:blockitemstates':
33
- const blockIds = (0, nbtdocUtil_1.getBlocksFromItem)(id);
36
+ const blockIds = (0, mcdocUtil_1.getBlocksFromItem)(id);
34
37
  return blockIds
35
38
  ? blockStates(blockIds, options)
36
39
  : core.checker.noop;
37
40
  case 'custom:blockstates':
38
41
  return blockStates([id], options);
39
42
  case 'custom:spawnitemtag':
40
- const entityId = (0, nbtdocUtil_1.getEntityFromItem)(id);
43
+ const entityId = (0, mcdocUtil_1.getEntityFromItem)(id);
41
44
  return entityId
42
45
  ? index('entity_type', entityId, options)
43
46
  : core.checker.noop;
44
47
  default:
45
48
  return (node, ctx) => {
46
- const { allowUnknownKey, value } = resolveRootRegistry(registry, id, ctx, node);
47
- options.allowUnknownKey || (options.allowUnknownKey = allowUnknownKey);
48
- compound(value, options)(node, ctx);
49
+ // const { allowUnknownKey, value } = resolveRootRegistry(registry, id, ctx, node)
50
+ // options.allowUnknownKey ||= allowUnknownKey
51
+ // compound(value, options)(node, ctx)
49
52
  };
50
53
  }
51
54
  }
52
55
  exports.index = index;
53
56
  /**
54
- * @param identifier An identifier of nbtdoc compound definition. e.g. `::minecraft::util::invitem::InventoryItem`
57
+ * @param identifier An identifier of mcdoc compound definition. e.g. `::minecraft::util::invitem::InventoryItem`
55
58
  */
56
59
  function definition(identifier, options = {}) {
57
60
  const index = identifier.lastIndexOf('::');
58
61
  const module = identifier.slice(0, index);
59
62
  const compoundDef = identifier.slice(index + 2);
60
- const path = { category: 'nbtdoc', path: [module, compoundDef] };
63
+ const path = { category: 'mcdoc', path: [module, compoundDef] };
61
64
  return (node, ctx) => {
62
- const { allowUnknownKey, value } = resolveSymbolPaths([path], ctx, node);
63
- options.allowUnknownKey || (options.allowUnknownKey = allowUnknownKey);
64
- compound(value, options)(node, ctx);
65
+ // const { allowUnknownKey, value } = resolveSymbolPaths([path], ctx, node)
66
+ // options.allowUnknownKey ||= allowUnknownKey
67
+ // compound(value, options)(node, ctx)
65
68
  };
66
69
  }
67
70
  exports.definition = definition;
@@ -74,23 +77,23 @@ function blockStates(blocks, _options = {}) {
74
77
  }
75
78
  // Type check.
76
79
  if (valueNode.type === 'nbt:byte' && (ctx.src.slice(valueNode.range).toLowerCase() === 'false' || ctx.src.slice(valueNode.range).toLowerCase() === 'true')) {
77
- ctx.err.report((0, lib_1.localize)('nbt.checker.block-states.fake-boolean'), valueNode, 2 /* Warning */);
80
+ ctx.err.report((0, lib_1.localize)('nbt.checker.block-states.fake-boolean'), valueNode, 2 /* core.ErrorSeverity.Warning */);
78
81
  continue;
79
82
  }
80
83
  else if (valueNode.type !== 'string' && valueNode.type !== 'nbt:int') {
81
- ctx.err.report((0, lib_1.localize)('nbt.checker.block-states.unexpected-value-type'), valueNode, 2 /* Warning */);
84
+ ctx.err.report((0, lib_1.localize)('nbt.checker.block-states.unexpected-value-type'), valueNode, 2 /* core.ErrorSeverity.Warning */);
82
85
  continue;
83
86
  }
84
87
  if (Object.keys(states).includes(keyNode.value)) {
85
88
  // The current state exists. Check the value.
86
89
  const stateValues = states[keyNode.value];
87
90
  if (!stateValues.includes(valueNode.value.toString())) {
88
- ctx.err.report((0, lib_1.localize)('expected-got', stateValues, (0, lib_1.localeQuote)(valueNode.value.toString())), valueNode, 2 /* Warning */);
91
+ ctx.err.report((0, lib_1.localize)('expected-got', stateValues, (0, lib_1.localeQuote)(valueNode.value.toString())), valueNode, 2 /* core.ErrorSeverity.Warning */);
89
92
  }
90
93
  }
91
94
  else {
92
95
  // The current state doesn't exist.
93
- ctx.err.report((0, lib_1.localize)('nbt.checker.block-states.unknown-state', (0, lib_1.localeQuote)(keyNode.value), blocks), keyNode, 2 /* Warning */);
96
+ ctx.err.report((0, lib_1.localize)('nbt.checker.block-states.unknown-state', (0, lib_1.localeQuote)(keyNode.value), blocks), keyNode, 2 /* core.ErrorSeverity.Warning */);
94
97
  }
95
98
  }
96
99
  };
@@ -112,7 +115,7 @@ function compound(data, options = {}) {
112
115
  fieldValue(fieldData.data, options)(valueNode, ctx);
113
116
  }
114
117
  else if (!options.allowUnknownKey) {
115
- ctx.err.report((0, lib_1.localize)('unknown-key', (0, lib_1.localeQuote)(key)), keyNode, 2 /* Warning */);
118
+ ctx.err.report((0, lib_1.localize)('unknown-key', (0, lib_1.localeQuote)(key)), keyNode, 2 /* core.ErrorSeverity.Warning */);
116
119
  }
117
120
  }
118
121
  };
@@ -123,143 +126,149 @@ function enum_(path, _options = {}) {
123
126
  return core.checker.noop;
124
127
  }
125
128
  return (node, ctx) => {
126
- const query = ctx.symbols.query(ctx.doc, path.category, ...path.path);
127
- const data = query.symbol?.data;
128
- // Check type.
129
- if (data?.enumType && node.type !== data.enumType && node.type !== `nbt:${data.enumType}`) {
130
- ctx.err.report((0, lib_1.localize)('expected', (0, lib_1.localize)(`nbt.node.${data.enumType}`)), node, 2 /* Warning */);
131
- }
132
- // Get all enum members.
133
- const enumMembers = {};
134
- query.forEachMember((name, memberQuery) => {
135
- const value = memberQuery.symbol?.data?.value;
136
- if (value !== undefined) {
137
- enumMembers[name] = value.toString();
138
- }
139
- });
140
- // Check value.
141
- if (!Object.values(enumMembers).includes(node.value.toString())) {
142
- ctx.err.report((0, lib_1.localize)('expected', Object.entries(enumMembers).map(([k, v]) => `${k} = ${v}`)), node, 2 /* Warning */);
143
- }
129
+ // const query = ctx.symbols.query(ctx.doc, path.category, ...path.path)
130
+ // const data = query.symbol?.data as mcdoc.EnumNode.SymbolData | undefined
131
+ // // Check type.
132
+ // if (data?.enumKind && node.type !== data.enumKind && node.type !== `nbt:${data.enumKind}`) {
133
+ // ctx.err.report(localize('expected', localize(`nbt.node.${data.enumKind}`)), node, core.ErrorSeverity.Warning)
134
+ // }
135
+ // // Get all enum members.
136
+ // const enumMembers: Record<string, string> = {}
137
+ // query.forEachMember((name, memberQuery) => {
138
+ // const value = (memberQuery.symbol?.data as mcdoc.EnumFieldNode.SymbolData | undefined)?.value
139
+ // if (value !== undefined) {
140
+ // enumMembers[name] = value.toString()
141
+ // }
142
+ // })
143
+ // // Check value.
144
+ // if (!Object.values(enumMembers).includes(node.value.toString())) {
145
+ // ctx.err.report(localize('expected',
146
+ // Object.entries(enumMembers).map(([k, v]) => `${k} = ${v}`)
147
+ // ), node, core.ErrorSeverity.Warning)
148
+ // }
144
149
  };
145
150
  }
146
151
  exports.enum_ = enum_;
147
152
  /**
148
- * @param id If set to `undefined` or an empty array, all nbtdoc compound definitions for this registry will be merged for checking, and unknown keys are allowed.
153
+ * @param id If set to `undefined` or an empty array, all mcdoc compound definitions for this registry will be merged for checking, and unknown keys are allowed.
149
154
  */
150
155
  function path(registry, id) {
151
156
  return (node, ctx) => {
152
- const resolveResult = resolveRootRegistry(registry, id, ctx, undefined);
153
- let data = { type: 'resolved_compound', data: resolveResult.value };
154
- let targetType = { type: 'index', index: { registry, path: [] } };
155
- const options = { allowUnknownKey: resolveResult.allowUnknownKey, isPredicate: true };
156
- let currentCompound;
157
- for (const child of node.children) {
158
- if (node_1.NbtCompoundNode.is(child)) {
159
- // Compound filter.
160
- currentCompound = child;
161
- if (data?.type === 'resolved_compound') {
162
- compound(data.data, options)(child, ctx);
163
- }
164
- else {
165
- ctx.err.report((0, lib_1.localize)('nbt.checker.path.unexpected-filter'), child, 2 /* Warning */);
166
- }
167
- }
168
- else if (core.StringNode.is(child)) {
169
- // Key.
170
- if (data?.type === 'resolved_compound') {
171
- const fieldData = data.data[child.value];
172
- if (fieldData) {
173
- fieldData.query.enter({ usage: { type: 'reference', node: child } });
174
- if (fieldData.data.type === 'byte_array' || fieldData.data.type === 'int_array' || fieldData.data.type === 'long_array' || fieldData.data.type === 'list') {
175
- data = fieldData.data;
176
- }
177
- else {
178
- const resolveResult = resolveSymbolData(fieldData.data, ctx, currentCompound);
179
- if (resolveResult.value) {
180
- options.allowUnknownKey || (options.allowUnknownKey = resolveResult.allowUnknownKey);
181
- data.data = resolveResult.value;
182
- }
183
- else {
184
- data = undefined;
185
- }
186
- }
187
- targetType = fieldData.data;
188
- }
189
- else {
190
- if (!options.allowUnknownKey) {
191
- ctx.err.report((0, lib_1.localize)('unknown-key', (0, lib_1.localeQuote)(child.value)), child, 2 /* Warning */);
192
- }
193
- targetType = undefined;
194
- break;
195
- }
196
- }
197
- else {
198
- ctx.err.report((0, lib_1.localize)('nbt.checker.path.unexpected-key'), child, 2 /* Warning */);
199
- targetType = undefined;
200
- break;
201
- }
202
- currentCompound = undefined;
203
- }
204
- else {
205
- // Index.
206
- if (data?.type === 'byte_array' || data?.type === 'int_array' || data?.type === 'long_array' || data?.type === 'list') {
207
- // Check content.
208
- if (child.children !== undefined) {
209
- const [content] = child.children;
210
- if (content.type === 'integer') {
211
- const absIndex = content.value < 0 ? -1 - content.value : content.value;
212
- const [, maxLength] = data.lengthRange ?? [undefined, undefined];
213
- if (maxLength !== undefined && absIndex >= maxLength) {
214
- ctx.err.report((0, lib_1.localize)('nbt.checker.path.index-out-of-bound', content.value, maxLength), content, 2 /* Warning */);
215
- }
216
- }
217
- else {
218
- let isUnexpectedFilter = true;
219
- if (data.type === 'list') {
220
- const { allowUnknownKey, value } = resolveSymbolData(data.item, ctx, currentCompound);
221
- options.allowUnknownKey || (options.allowUnknownKey = allowUnknownKey);
222
- if (value) {
223
- isUnexpectedFilter = false;
224
- compound(value, options)(content, ctx);
225
- }
226
- }
227
- if (isUnexpectedFilter) {
228
- ctx.err.report((0, lib_1.localize)('nbt.checker.path.unexpected-filter'), content, 2 /* Warning */);
229
- targetType = undefined;
230
- break;
231
- }
232
- currentCompound = content;
233
- }
234
- }
235
- // Set data for the next iteration.
236
- if (data.type === 'list') {
237
- const { allowUnknownKey, value } = resolveSymbolData(data.item, ctx, currentCompound);
238
- options.allowUnknownKey || (options.allowUnknownKey = allowUnknownKey);
239
- targetType = data.item;
240
- if (value) {
241
- data = { type: 'resolved_compound', data: value };
242
- }
243
- else {
244
- data = undefined;
245
- }
246
- }
247
- else {
248
- targetType = {
249
- type: data.type.split('_')[0],
250
- valueRange: data.valueRange,
251
- };
252
- data = undefined;
253
- }
254
- }
255
- else {
256
- ctx.err.report((0, lib_1.localize)('nbt.checker.path.unexpected-index'), child, 2 /* Warning */);
257
- targetType = undefined;
258
- break;
259
- }
260
- }
261
- }
262
- ctx.ops.set(node, 'targetType', targetType);
157
+ // const resolveResult = resolveRootRegistry(registry, id, ctx, undefined)
158
+ // let targetType: mcdoc.McdocType | undefined = {
159
+ // kind: 'dispatcher',
160
+ // registry,
161
+ // index: ((): mcdoc.DispatcherData['index'] => {
162
+ // if (id === undefined) {
163
+ // return { kind: 'static', value: { keyword: '()' } }
164
+ // } else if (typeof id === 'string') {
165
+ // return { kind: 'static', value: id }
166
+ // } else {
167
+ // return id.map(v => ({ kind: 'static', value: v }))
168
+ // }
169
+ // })(),
170
+ // }
171
+ // const options: Options = { allowUnknownKey: resolveResult.allowUnknownKey, isPredicate: true }
172
+ // let currentCompound: NbtCompoundNode | undefined
173
+ // for (const child of node.children) {
174
+ // if (NbtCompoundNode.is(child)) {
175
+ // // Compound filter.
176
+ // currentCompound = child
177
+ // if (data?.type === 'union') {
178
+ // }
179
+ // if (data?.type === 'resolved_compound') {
180
+ // compound(data.data, options)(child, ctx)
181
+ // } else {
182
+ // ctx.err.report(localize('nbt.checker.path.unexpected-filter'), child, core.ErrorSeverity.Warning)
183
+ // }
184
+ // } else if (core.StringNode.is(child)) {
185
+ // // Key.
186
+ // if (data?.type === 'union') {
187
+ // }
188
+ // if (data?.type === 'resolved_compound') {
189
+ // const fieldData: ResolvedCompoundData[string] = data.data[child.value]
190
+ // if (fieldData) {
191
+ // fieldData.query.enter({ usage: { type: 'reference', node: child } })
192
+ // if (fieldData.data.type === 'byte_array' || fieldData.data.type === 'int_array' || fieldData.data.type === 'long_array' || fieldData.data.type === 'list' || fieldData.data.type === 'union') {
193
+ // data = fieldData.data
194
+ // } else {
195
+ // const resolveResult = resolveSymbolData(fieldData.data, ctx, currentCompound)
196
+ // if (resolveResult.value) {
197
+ // options.allowUnknownKey ||= resolveResult.allowUnknownKey
198
+ // data.data = resolveResult.value
199
+ // } else {
200
+ // data = undefined
201
+ // }
202
+ // }
203
+ // targetType = fieldData.data
204
+ // } else {
205
+ // if (!options.allowUnknownKey) {
206
+ // ctx.err.report(localize('unknown-key', localeQuote(child.value)), child, core.ErrorSeverity.Warning)
207
+ // }
208
+ // targetType = undefined
209
+ // break
210
+ // }
211
+ // } else {
212
+ // ctx.err.report(localize('nbt.checker.path.unexpected-key'), child, core.ErrorSeverity.Warning)
213
+ // targetType = undefined
214
+ // break
215
+ // }
216
+ // currentCompound = undefined
217
+ // } else {
218
+ // // Index.
219
+ // if (data?.type === 'byte_array' || data?.type === 'int_array' || data?.type === 'long_array' || data?.type === 'list') {
220
+ // // Check content.
221
+ // if (child.children !== undefined) {
222
+ // const [content] = child.children
223
+ // if (content.type === 'integer') {
224
+ // const absIndex = content.value < 0 ? -1 - content.value : content.value
225
+ // const [, maxLength] = data.lengthRange ?? [undefined, undefined]
226
+ // if (maxLength !== undefined && absIndex >= maxLength) {
227
+ // ctx.err.report(localize('nbt.checker.path.index-out-of-bound', content.value, maxLength), content, core.ErrorSeverity.Warning)
228
+ // }
229
+ // } else {
230
+ // let isUnexpectedFilter = true
231
+ // if (data.type === 'list') {
232
+ // const { allowUnknownKey, value } = resolveSymbolData(data.item, ctx, currentCompound)
233
+ // options.allowUnknownKey ||= allowUnknownKey
234
+ // if (value) {
235
+ // isUnexpectedFilter = false
236
+ // compound(value, options)(content, ctx)
237
+ // }
238
+ // }
239
+ // if (isUnexpectedFilter) {
240
+ // ctx.err.report(localize('nbt.checker.path.unexpected-filter'), content, core.ErrorSeverity.Warning)
241
+ // targetType = undefined
242
+ // break
243
+ // }
244
+ // currentCompound = content
245
+ // }
246
+ // }
247
+ // // Set data for the next iteration.
248
+ // if (data.type === 'list') {
249
+ // const { allowUnknownKey, value } = resolveSymbolData(data.item, ctx, currentCompound)
250
+ // options.allowUnknownKey ||= allowUnknownKey
251
+ // targetType = data.item
252
+ // if (value) {
253
+ // data = { type: 'resolved_compound', data: value }
254
+ // } else {
255
+ // data = undefined
256
+ // }
257
+ // } else {
258
+ // targetType = {
259
+ // type: data.type.split('_')[0] as 'byte' | 'int' | 'long',
260
+ // valueRange: data.valueRange,
261
+ // }
262
+ // data = undefined
263
+ // }
264
+ // } else {
265
+ // ctx.err.report(localize('nbt.checker.path.unexpected-index'), child, core.ErrorSeverity.Warning)
266
+ // targetType = undefined
267
+ // break
268
+ // }
269
+ // }
270
+ // }
271
+ // ctx.ops.set(node, 'targetType', targetType)
263
272
  };
264
273
  }
265
274
  exports.path = path;
@@ -269,11 +278,8 @@ function fieldValue(type, options) {
269
278
  boolean: 'nbt:byte',
270
279
  byte: 'nbt:byte',
271
280
  byte_array: 'nbt:byte_array',
272
- compound: 'nbt:compound',
273
281
  double: 'nbt:double',
274
282
  float: 'nbt:float',
275
- id: 'string',
276
- index: 'nbt:compound',
277
283
  int: 'nbt:int',
278
284
  int_array: 'nbt:int_array',
279
285
  list: 'nbt:list',
@@ -281,18 +287,20 @@ function fieldValue(type, options) {
281
287
  long_array: 'nbt:long_array',
282
288
  short: 'nbt:short',
283
289
  string: 'string',
290
+ struct: 'nbt:compound',
291
+ tuple: 'nbt:list',
284
292
  };
285
293
  return (node, ctx) => {
286
294
  // Rough type check.
287
- if (type.type !== 'enum' && type.type !== 'union' && node.type !== ExpectedTypes[type.type]) {
288
- ctx.err.report((0, lib_1.localize)('expected', (0, util_1.localizeTag)(ExpectedTypes[type.type])), node, 2 /* Warning */);
295
+ if (type.kind !== 'any' && type.kind !== 'dispatcher' && type.kind !== 'enum' && type.kind !== 'literal' && type.kind !== 'reference' && type.kind !== 'union' && node.type !== ExpectedTypes[type.kind]) {
296
+ ctx.err.report((0, lib_1.localize)('expected', (0, util_1.localizeTag)(ExpectedTypes[type.kind])), node, 2 /* core.ErrorSeverity.Warning */);
289
297
  return;
290
298
  }
291
- switch (type.type) {
299
+ switch (type.kind) {
292
300
  case 'boolean':
293
301
  node = node;
294
302
  if (node.value !== 0 && node.value !== 1) {
295
- ctx.err.report((0, lib_1.localize)('nbt.checker.boolean.out-of-range', (0, lib_1.localeQuote)('0b'), (0, lib_1.localeQuote)('1b')), node, 2 /* Warning */);
303
+ ctx.err.report((0, lib_1.localize)('nbt.checker.boolean.out-of-range', (0, lib_1.localeQuote)('0b'), (0, lib_1.localeQuote)('1b')), node, 2 /* core.ErrorSeverity.Warning */);
296
304
  }
297
305
  break;
298
306
  case 'byte_array':
@@ -300,12 +308,12 @@ function fieldValue(type, options) {
300
308
  case 'long_array':
301
309
  node = node;
302
310
  if (type.lengthRange && !isInRange(node.children.length, type.lengthRange)) {
303
- ctx.err.report((0, lib_1.localize)('expected', (0, lib_1.localize)('nbt.checker.collection.length-between', (0, util_1.localizeTag)(node.type), type.lengthRange[0] ?? '-∞', type.lengthRange[1] ?? '+∞')), node, 2 /* Warning */);
311
+ ctx.err.report((0, lib_1.localize)('expected', (0, lib_1.localize)('nbt.checker.collection.length-between', (0, util_1.localizeTag)(node.type), type.lengthRange[0] ?? '-∞', type.lengthRange[1] ?? '+∞')), node, 2 /* core.ErrorSeverity.Warning */);
304
312
  }
305
313
  if (type.valueRange) {
306
314
  for (const { value: childNode } of node.children) {
307
315
  if (childNode && !isInRange(Number(childNode.value), type.valueRange)) {
308
- ctx.err.report((0, lib_1.localize)('number.between', type.valueRange[0] ?? '-∞', type.valueRange[1] ?? '+∞'), node, 2 /* Warning */);
316
+ ctx.err.report((0, lib_1.localize)('number.between', type.valueRange[0] ?? '-∞', type.valueRange[1] ?? '+∞'), node, 2 /* core.ErrorSeverity.Warning */);
309
317
  }
310
318
  }
311
319
  }
@@ -318,32 +326,25 @@ function fieldValue(type, options) {
318
326
  case 'double':
319
327
  node = node;
320
328
  if (type.valueRange && !isInRange(Number(node.value), type.valueRange)) {
321
- ctx.err.report((0, lib_1.localize)('number.between', type.valueRange[0] ?? '-∞', type.valueRange[1] ?? '+∞'), node, 2 /* Warning */);
322
- }
323
- break;
324
- case 'index':
325
- node = node;
326
- const id = resolveFieldPath(node.parent?.parent, type.index.path);
327
- if (type.index.registry) {
328
- if (nbtdoc_1.ExtendableRootRegistry.is(type.index.registry)) {
329
- index(type.index.registry, id ? core.ResourceLocation.lengthen(id) : undefined, options)(node, ctx);
330
- }
331
- else if (id) {
332
- index(type.index.registry, core.ResourceLocation.lengthen(id), options)(node, ctx);
333
- }
329
+ ctx.err.report((0, lib_1.localize)('number.between', type.valueRange[0] ?? '-∞', type.valueRange[1] ?? '+∞'), node, 2 /* core.ErrorSeverity.Warning */);
334
330
  }
335
331
  break;
336
- case 'id':
332
+ case 'dispatcher':
337
333
  node = node;
338
- core.parseStringValue(core.resourceLocation(type.registry
339
- ? { category: type.registry, isPredicate: options.isPredicate }
340
- : { allowUnknown: true, pool: [], isPredicate: options.isPredicate }), node.value, node.valueMap, ctx);
334
+ // const id = resolveFieldPath(node.parent?.parent, type.index.path)
335
+ // if (type.index.registry) {
336
+ // if (ExtendableRootRegistry.is(type.index.registry)) {
337
+ // index(type.index.registry, id ? core.ResourceLocation.lengthen(id) : undefined, options)(node, ctx)
338
+ // } else if (id) {
339
+ // index(type.index.registry, core.ResourceLocation.lengthen(id), options)(node, ctx)
340
+ // }
341
+ // }
341
342
  break;
342
343
  case 'list':
343
344
  node = node;
344
- type = nbtdoc.simplifyListType(type);
345
+ type = mcdoc.simplifyListType(type);
345
346
  if (type.lengthRange && !isInRange(node.children.length, type.lengthRange)) {
346
- ctx.err.report((0, lib_1.localize)('expected', (0, lib_1.localize)('nbt.checker.collection.length-between', (0, util_1.localizeTag)(node.type), type.lengthRange[0] ?? '-∞', type.lengthRange[1] ?? '+∞')), node, 2 /* Warning */);
347
+ ctx.err.report((0, lib_1.localize)('expected', (0, lib_1.localize)('nbt.checker.collection.length-between', (0, util_1.localizeTag)(node.type), type.lengthRange[0] ?? '-∞', type.lengthRange[1] ?? '+∞')), node, 2 /* core.ErrorSeverity.Warning */);
347
348
  }
348
349
  for (const { value: childNode } of node.children) {
349
350
  if (childNode) {
@@ -360,10 +361,10 @@ function fieldValue(type, options) {
360
361
  valueNode = node.parent.parent;
361
362
  }
362
363
  if (core.PairNode.is(valueNode.parent)) {
363
- const compoundNbtdocPath = valueNode.parent.key?.symbol?.parentSymbol?.path.join('::');
364
+ const structMcdocPath = valueNode.parent.key?.symbol?.parentSymbol?.path.join('::');
364
365
  const key = valueNode.parent.key?.value;
365
- const path = `${compoundNbtdocPath}.${key}${suffix}`;
366
- const parserName = (0, nbtdocUtil_1.getSpecialStringParser)(path);
366
+ const path = `${structMcdocPath}.${key}${suffix}`;
367
+ const parserName = (0, mcdocUtil_1.getSpecialStringParser)(path);
367
368
  if (parserName) {
368
369
  try {
369
370
  const parser = ctx.meta.getParser(parserName);
@@ -379,23 +380,19 @@ function fieldValue(type, options) {
379
380
  }
380
381
  }
381
382
  break;
382
- case 'compound':
383
+ case 'reference':
383
384
  node = node;
384
- if (type.symbol) {
385
- const { allowUnknownKey, value } = resolveSymbolPaths([type.symbol], ctx, node);
386
- compound(value, { ...options, allowUnknownKey: options.allowUnknownKey || allowUnknownKey })(node, ctx);
387
- }
388
- break;
389
- case 'enum':
390
- node = node;
391
- enum_(type.symbol, options)(node, ctx);
385
+ // if (type.symbol) {
386
+ // const { allowUnknownKey, value } = resolveSymbolPaths([type.symbol], ctx, node)
387
+ // compound(value, { ...options, allowUnknownKey: options.allowUnknownKey || allowUnknownKey })(node, ctx)
388
+ // }
392
389
  break;
393
390
  case 'union':
394
- type = nbtdoc.flattenUnionType(type);
391
+ type = mcdoc.flattenUnionType(type);
395
392
  if (type.members.length === 0) {
396
393
  ctx.err.report((0, lib_1.localize)('nbt.checker.compound.field.union-empty-members'), core.PairNode.is(node.parent)
397
394
  ? (node.parent.key ?? node.parent)
398
- : node, 2 /* Warning */);
395
+ : node, 2 /* core.ErrorSeverity.Warning */);
399
396
  }
400
397
  else {
401
398
  core.checker.any(type.members.map(t => fieldValue(t, options)))(node, ctx);
@@ -405,188 +402,4 @@ function fieldValue(type, options) {
405
402
  };
406
403
  }
407
404
  exports.fieldValue = fieldValue;
408
- function resolveFieldPath(compound, fieldPath) {
409
- let node = compound;
410
- for (const path of fieldPath) {
411
- if (!node) {
412
- break;
413
- }
414
- if (typeof path === 'object') {
415
- // Super.
416
- node = node.parent;
417
- }
418
- else {
419
- // Field key.
420
- if (!node_1.NbtCompoundNode.is(node)) {
421
- break;
422
- }
423
- node = node.children.find(({ key }) => key?.value === path)?.value;
424
- }
425
- }
426
- return node && node_1.NbtPrimitiveNode.is(node)
427
- ? node.value.toString()
428
- : undefined;
429
- }
430
- const getUnwrapper = (out) => (result) => {
431
- out.allowUnknownKey || (out.allowUnknownKey = result.allowUnknownKey);
432
- return result.value;
433
- };
434
- const map = (result, cb) => {
435
- const ans = cb(result.value);
436
- return {
437
- allowUnknownKey: result.allowUnknownKey || ans.allowUnknownKey,
438
- value: ans.value,
439
- };
440
- };
441
- function getPathsFromRootRegistry(registry, inputIds, ctx) {
442
- if (!registry) {
443
- return { allowUnknownKey: true, value: [] };
444
- }
445
- const normalizeIds = (input, descriptionQuery) => {
446
- let allowUnknownKey = false;
447
- let ids;
448
- if (input === undefined || (Array.isArray(input) && input.length === 0)) {
449
- ids = Object.keys(descriptionQuery.visibleMembers);
450
- allowUnknownKey = true;
451
- }
452
- else if (!Array.isArray(input)) {
453
- ids = [input];
454
- }
455
- else {
456
- ids = input;
457
- }
458
- return { allowUnknownKey, value: ids };
459
- };
460
- const collectPaths = (ids, descriptionQuery) => {
461
- let allowUnknownKey = false;
462
- const paths = new core.SymbolPathCollector();
463
- descriptionQuery.ifKnown(() => {
464
- for (const id of ids) {
465
- descriptionQuery.member(id, member => member
466
- .ifKnown(symbol => paths.add(symbol.relations?.describedBy))
467
- .else(() => descriptionQuery.member('@default', defaultMember => {
468
- allowUnknownKey = true;
469
- paths.add(defaultMember.symbol?.relations?.describedBy);
470
- })));
471
- }
472
- });
473
- return { allowUnknownKey, value: paths.collect() };
474
- };
475
- const descriptionQuery = ctx.symbols.query(ctx.doc, 'nbtdoc/description', registry);
476
- return map(normalizeIds(inputIds, descriptionQuery), ids => collectPaths(ids, descriptionQuery));
477
- }
478
- function resolveSymbolPaths(paths, ctx, compound) {
479
- if (paths.length === 0) {
480
- return { allowUnknownKey: true, value: {} };
481
- }
482
- const getDefinitionQuery = (path) => {
483
- return {
484
- allowUnknownKey: (0, nbtdocUtil_1.isExpandableCompound)(path.path.join('::')),
485
- value: ctx.symbols.query(ctx.doc, path.category, ...path.path),
486
- };
487
- };
488
- const getPathsFromSuper = (extendable) => {
489
- if (extendable.type === 'compound') {
490
- return { allowUnknownKey: false, value: extendable.symbol ? [extendable.symbol] : [] };
491
- }
492
- else {
493
- const id = resolveFieldPath(compound, extendable.index.path);
494
- return getPathsFromRootRegistry(extendable.index.registry, id ? core.ResourceLocation.lengthen(id) : undefined, ctx);
495
- }
496
- };
497
- const getPathsRecursively = (paths) => {
498
- const collector = new core.SymbolPathCollector();
499
- const out = { allowUnknownKey: false };
500
- const unwrap = getUnwrapper(out);
501
- const iterate = (paths) => {
502
- for (const path of paths) {
503
- if (collector.has(path)) {
504
- continue;
505
- }
506
- collector.add(path);
507
- const query = unwrap(getDefinitionQuery(path));
508
- const data = query.symbol?.data;
509
- if (data) {
510
- const superPaths = data.extends ? unwrap(getPathsFromSuper(data.extends)) : [];
511
- iterate(superPaths);
512
- }
513
- else {
514
- out.allowUnknownKey = true;
515
- }
516
- }
517
- };
518
- iterate(paths);
519
- return { allowUnknownKey: out.allowUnknownKey, value: collector.collect() };
520
- };
521
- const ans = Object.create(null);
522
- const out = { allowUnknownKey: false };
523
- const unwrap = getUnwrapper(out);
524
- const allPaths = unwrap(getPathsRecursively(paths));
525
- for (const path of allPaths) {
526
- const query = unwrap(getDefinitionQuery(path));
527
- query.forEachMember((key, keyQuery) => {
528
- const data = keyQuery.symbol?.data;
529
- if (!data) {
530
- return;
531
- }
532
- if (ans[key]) {
533
- ans[key].data = nbtdoc.unionTypes(ans[key].data, data.fieldType);
534
- }
535
- else {
536
- ans[key] = { data: data.fieldType, query: keyQuery };
537
- }
538
- });
539
- }
540
- return { allowUnknownKey: out.allowUnknownKey, value: ans };
541
- }
542
- /**
543
- * @param registry If `undefined`, allows unknown key.
544
- * @param id If `undefined` or an empty array, merges all available definitions and allows unknown key.
545
- */
546
- function resolveRootRegistry(registry, inputIds, ctx, compound) {
547
- const out = { allowUnknownKey: false };
548
- const unwrap = getUnwrapper(out);
549
- const paths = unwrap(getPathsFromRootRegistry(registry, inputIds, ctx));
550
- const data = unwrap(resolveSymbolPaths(paths, ctx, compound));
551
- return { allowUnknownKey: out.allowUnknownKey, value: data };
552
- }
553
- function resolveSymbolData(data, ctx, compound) {
554
- const out = { allowUnknownKey: false };
555
- const unwrap = getUnwrapper(out);
556
- const paths = unwrap(getPathsFromSymbolData(data, ctx, compound));
557
- if (!paths) {
558
- return { allowUnknownKey: out.allowUnknownKey, value: undefined };
559
- }
560
- const ans = unwrap(resolveSymbolPaths(paths, ctx, compound));
561
- return { allowUnknownKey: out.allowUnknownKey, value: ans };
562
- }
563
- function getPathsFromSymbolData(data, ctx, compound) {
564
- const collector = new core.SymbolPathCollector();
565
- const out = { allowUnknownKey: false };
566
- const unwrap = getUnwrapper(out);
567
- const iterate = (data) => {
568
- if (data.type === 'compound') {
569
- collector.add(data.symbol);
570
- return true;
571
- }
572
- else if (data.type === 'index') {
573
- const id = resolveFieldPath(compound, data.index.path);
574
- const paths = unwrap(getPathsFromRootRegistry(data.index.registry, id ? core.ResourceLocation.lengthen(id) : undefined, ctx));
575
- for (const path of paths) {
576
- collector.add(path);
577
- }
578
- return true;
579
- }
580
- else if (data.type === 'union') {
581
- let ans = false;
582
- for (const member of data.members) {
583
- ans || (ans = iterate(member));
584
- }
585
- return ans;
586
- }
587
- return false;
588
- };
589
- const isCompoundData = iterate(data);
590
- return { allowUnknownKey: out.allowUnknownKey, value: isCompoundData ? collector.collect() : undefined };
591
- }
592
405
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,9 @@
1
+ import type * as core from '@spyglassmc/core';
2
+ export declare function getBlocksFromItem(item: core.FullResourceLocation): core.FullResourceLocation[] | undefined;
3
+ export declare function getEntityFromItem(item: core.FullResourceLocation): core.FullResourceLocation | undefined;
4
+ export declare function getSpecialStringParser(mcdocPath: string): string | undefined;
5
+ /**
6
+ * @param mcdocPath Path of the mcdoc compound definition.
7
+ */
8
+ export declare function isExpandableCompound(mcdocPath: string): boolean;
9
+ //# sourceMappingURL=mcdocUtil.d.ts.map
@@ -148,8 +148,8 @@ const SpecialStrings = {
148
148
  '::minecraft::item::book::WrittenBook.pages[]': 'mcfunction:component',
149
149
  '::minecraft::item::ItemBase.CanDestroy[]': 'mcfunction:block_predicate',
150
150
  };
151
- function getSpecialStringParser(nbtdocPath) {
152
- return SpecialStrings[nbtdocPath];
151
+ function getSpecialStringParser(mcdocPath) {
152
+ return SpecialStrings[mcdocPath];
153
153
  }
154
154
  exports.getSpecialStringParser = getSpecialStringParser;
155
155
  const ExpandableCompounds = [
@@ -159,10 +159,10 @@ const ExpandableCompounds = [
159
159
  '::minecraft::util::Any',
160
160
  ];
161
161
  /**
162
- * @param nbtdocPath Path of the nbtdoc compound definition.
162
+ * @param mcdocPath Path of the mcdoc compound definition.
163
163
  */
164
- function isExpandableCompound(nbtdocPath) {
165
- return ExpandableCompounds.includes(nbtdocPath);
164
+ function isExpandableCompound(mcdocPath) {
165
+ return ExpandableCompounds.includes(mcdocPath);
166
166
  }
167
167
  exports.isExpandableCompound = isExpandableCompound;
168
- //# sourceMappingURL=nbtdocUtil.js.map
168
+ //# sourceMappingURL=mcdocUtil.js.map
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
package/lib/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,5 +1,5 @@
1
1
  import * as core from '@spyglassmc/core';
2
- import type * as nbtdoc from '@spyglassmc/nbtdoc';
2
+ import type * as mcdoc from '@spyglassmc/mcdoc';
3
3
  export declare type NbtNode = NbtPrimitiveNode | NbtCompoundNode | NbtCollectionNode;
4
4
  export declare namespace NbtNode {
5
5
  function is(node: core.AstNode | undefined): node is NbtNode;
@@ -98,7 +98,7 @@ export declare namespace NbtLongArrayNode {
98
98
  export interface NbtPathNode extends core.AstNode {
99
99
  type: 'nbt:path';
100
100
  children: (core.StringNode | NbtCompoundNode | NbtPathIndexNode)[];
101
- targetType?: nbtdoc.NbtdocType | undefined;
101
+ targetType?: mcdoc.McdocType | undefined;
102
102
  }
103
103
  export declare namespace NbtPathNode {
104
104
  function is(node: core.AstNode | undefined): node is NbtPathNode;
package/lib/node/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -24,13 +28,13 @@ const core = __importStar(require("@spyglassmc/core"));
24
28
  const collection_1 = require("./collection");
25
29
  const compound_1 = require("./compound");
26
30
  const primitive_1 = require("./primitive");
27
- const entry = (src, ctx) => core.failOnEmpty(core.any([
28
- primitive_1.primitive,
29
- compound_1.compound,
30
- collection_1.list,
31
- collection_1.byteArray,
32
- collection_1.intArray,
33
- collection_1.longArray,
31
+ const entry = (src, ctx) => core.failOnEmpty(core.select([
32
+ { predicate: src => src.tryPeek('[B;'), parser: collection_1.byteArray },
33
+ { predicate: src => src.tryPeek('[I;'), parser: collection_1.intArray },
34
+ { predicate: src => src.tryPeek('[L;'), parser: collection_1.longArray },
35
+ { predicate: src => src.tryPeek('['), parser: collection_1.list },
36
+ { predicate: src => src.tryPeek('{'), parser: compound_1.compound },
37
+ { parser: primitive_1.primitive },
34
38
  ]))(src, ctx);
35
39
  exports.entry = entry;
36
40
  //# sourceMappingURL=entry.js.map
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -25,15 +29,15 @@ const locales_1 = require("@spyglassmc/locales");
25
29
  const util_1 = require("../util");
26
30
  const FloatMaximum = (2 - (2 ** -23)) * (2 ** 127);
27
31
  const NumeralPatterns = [
28
- { pattern: /^[-+]?(?:0|[1-9][0-9]*)b$/i, type: 'nbt:byte', hasSuffix: true, group: 2 /* IntegerAlike */, min: -128, max: 127 },
29
- { pattern: /^[-+]?(?:0|[1-9][0-9]*)s$/i, type: 'nbt:short', hasSuffix: true, group: 2 /* IntegerAlike */, min: -32768, max: 32767 },
30
- { pattern: /^[-+]?(?:0|[1-9][0-9]*)$/, type: 'nbt:int', hasSuffix: false, group: 2 /* IntegerAlike */, min: -2147483648, max: 2147483647 },
31
- { pattern: /^[-+]?(?:0|[1-9][0-9]*)l$/i, type: 'nbt:long', hasSuffix: true, group: 3 /* LongAlike */, min: -9223372036854775808n, max: 9223372036854775807n },
32
- { pattern: /^[-+]?(?:[0-9]+\.?|[0-9]*\.[0-9]+)(?:e[-+]?[0-9]+)?f$/i, type: 'nbt:float', hasSuffix: true, group: 1 /* FloatAlike */, min: -FloatMaximum, max: FloatMaximum },
33
- { pattern: /^[-+]?(?:[0-9]+\.|[0-9]*\.[0-9]+)(?:e[-+]?[0-9]+)?$/i, type: 'nbt:double', hasSuffix: false, group: 1 /* FloatAlike */, min: -Number.MAX_VALUE, max: Number.MAX_VALUE },
34
- { pattern: /^[-+]?(?:[0-9]+\.?|[0-9]*\.[0-9]+)(?:e[-+]?[0-9]+)?d$/i, type: 'nbt:double', hasSuffix: true, group: 1 /* FloatAlike */, min: -Number.MAX_VALUE, max: Number.MAX_VALUE },
35
- { pattern: /^true$/i, type: 'nbt:byte', value: 1, group: 0 /* Boolean */ },
36
- { pattern: /^false$/i, type: 'nbt:byte', value: 0, group: 0 /* Boolean */ },
32
+ { pattern: /^[-+]?(?:0|[1-9][0-9]*)b$/i, type: 'nbt:byte', hasSuffix: true, group: 2 /* Group.IntegerAlike */, min: -128, max: 127 },
33
+ { pattern: /^[-+]?(?:0|[1-9][0-9]*)s$/i, type: 'nbt:short', hasSuffix: true, group: 2 /* Group.IntegerAlike */, min: -32768, max: 32767 },
34
+ { pattern: /^[-+]?(?:0|[1-9][0-9]*)$/, type: 'nbt:int', hasSuffix: false, group: 2 /* Group.IntegerAlike */, min: -2147483648, max: 2147483647 },
35
+ { pattern: /^[-+]?(?:0|[1-9][0-9]*)l$/i, type: 'nbt:long', hasSuffix: true, group: 3 /* Group.LongAlike */, min: -9223372036854775808n, max: 9223372036854775807n },
36
+ { pattern: /^[-+]?(?:[0-9]+\.?|[0-9]*\.[0-9]+)(?:e[-+]?[0-9]+)?f$/i, type: 'nbt:float', hasSuffix: true, group: 1 /* Group.FloatAlike */, min: -FloatMaximum, max: FloatMaximum },
37
+ { pattern: /^[-+]?(?:[0-9]+\.|[0-9]*\.[0-9]+)(?:e[-+]?[0-9]+)?$/i, type: 'nbt:double', hasSuffix: false, group: 1 /* Group.FloatAlike */, min: -Number.MAX_VALUE, max: Number.MAX_VALUE },
38
+ { pattern: /^[-+]?(?:[0-9]+\.?|[0-9]*\.[0-9]+)(?:e[-+]?[0-9]+)?d$/i, type: 'nbt:double', hasSuffix: true, group: 1 /* Group.FloatAlike */, min: -Number.MAX_VALUE, max: Number.MAX_VALUE },
39
+ { pattern: /^true$/i, type: 'nbt:byte', value: 1, group: 0 /* Group.Boolean */ },
40
+ { pattern: /^false$/i, type: 'nbt:byte', value: 0, group: 0 /* Group.Boolean */ },
37
41
  ];
38
42
  exports.string = core.brigadierString;
39
43
  const primitive = (src, ctx) => {
@@ -43,7 +47,7 @@ const primitive = (src, ctx) => {
43
47
  const { result: unquotedResult, updateSrcAndCtx: updateUnquoted } = core.attempt(exports.string, src, ctx);
44
48
  for (const e of NumeralPatterns) {
45
49
  if (e.pattern.test(unquotedResult.value)) {
46
- if (e.group === 0 /* Boolean */) {
50
+ if (e.group === 0 /* Group.Boolean */) {
47
51
  const ans = {
48
52
  type: 'nbt:byte',
49
53
  range: unquotedResult.range,
@@ -54,16 +58,16 @@ const primitive = (src, ctx) => {
54
58
  }
55
59
  let isOutOfRange = false;
56
60
  const onOutOfRange = () => isOutOfRange = true;
57
- const numeralParser = e.group === 2 /* IntegerAlike */
61
+ const numeralParser = e.group === 2 /* Group.IntegerAlike */
58
62
  // As we already checked the format of the value with `e.pattern` in the if-block, there is no need to check
59
63
  // it again here in the parser, therefore we just pass in a simple /./ regex.
60
64
  ? core.integer({ pattern: /./, min: e.min, max: e.max, onOutOfRange })
61
- : e.group === 3 /* LongAlike */
65
+ : e.group === 3 /* Group.LongAlike */
62
66
  ? core.long({ pattern: /./, min: e.min, max: e.max, onOutOfRange })
63
67
  : core.float({ pattern: /./, min: e.min, max: e.max, onOutOfRange });
64
68
  const { result: numeralResult, updateSrcAndCtx: updateNumeral } = core.attempt(numeralParser, src, ctx);
65
69
  if (isOutOfRange) {
66
- ctx.err.report((0, locales_1.localize)('nbt.parser.number.out-of-range', (0, util_1.localizeTag)(e.type), (0, locales_1.localize)('nbt.node.string'), e.min, e.max), unquotedResult, 2 /* Warning */);
70
+ ctx.err.report((0, locales_1.localize)('nbt.parser.number.out-of-range', (0, util_1.localizeTag)(e.type), (0, locales_1.localize)('nbt.node.string'), e.min, e.max), unquotedResult, 2 /* core.ErrorSeverity.Warning */);
67
71
  break;
68
72
  }
69
73
  updateNumeral();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spyglassmc/nbt",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "SPGoding",
@@ -24,8 +24,8 @@
24
24
  "url": "https://github.com/SpyglassMC/Spyglass/issues"
25
25
  },
26
26
  "dependencies": {
27
- "@spyglassmc/core": "0.1.1",
28
- "@spyglassmc/locales": "0.1.1",
29
- "@spyglassmc/nbtdoc": "0.1.1"
27
+ "@spyglassmc/core": "0.1.2",
28
+ "@spyglassmc/locales": "0.1.2",
29
+ "@spyglassmc/mcdoc": "0.1.0"
30
30
  }
31
31
  }
@@ -1,9 +0,0 @@
1
- import type * as core from '../../../core/lib';
2
- export declare function getBlocksFromItem(item: core.FullResourceLocation): core.FullResourceLocation[] | undefined;
3
- export declare function getEntityFromItem(item: core.FullResourceLocation): core.FullResourceLocation | undefined;
4
- export declare function getSpecialStringParser(nbtdocPath: string): string | undefined;
5
- /**
6
- * @param nbtdocPath Path of the nbtdoc compound definition.
7
- */
8
- export declare function isExpandableCompound(nbtdocPath: string): boolean;
9
- //# sourceMappingURL=nbtdocUtil.d.ts.map