@spyglassmc/nbt 0.3.2 → 0.3.4

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.
@@ -262,7 +262,8 @@ export function path(registry, id) {
262
262
  export function fieldValue(type, options) {
263
263
  const isInRange = (value, { kind, min = -Infinity, max = Infinity }) => {
264
264
  const comparator = (a, b, exclusive) => exclusive ? a < b : a <= b;
265
- return (comparator(min, value, kind & 0b10) && comparator(value, max, kind & 0b01));
265
+ return (comparator(min, value, kind & 0b10) &&
266
+ comparator(value, max, kind & 0b01));
266
267
  };
267
268
  const ExpectedTypes = {
268
269
  boolean: 'nbt:byte',
@@ -367,7 +368,9 @@ export function fieldValue(type, options) {
367
368
  valueNode = node.parent.parent;
368
369
  }
369
370
  if (core.PairNode.is(valueNode.parent)) {
370
- const structMcdocPath = valueNode.parent.key?.symbol?.parentSymbol?.path.join('::');
371
+ const structMcdocPath = valueNode.parent.key?.symbol
372
+ ?.parentSymbol
373
+ ?.path.join('::');
371
374
  const key = valueNode.parent.key?.value;
372
375
  const path = `${structMcdocPath}.${key}${suffix}`;
373
376
  const parserName = getSpecialStringParser(path);
@@ -64,7 +64,10 @@ const BlockItems = {
64
64
  ],
65
65
  // Torches.
66
66
  'minecraft:torch': ['minecraft:torch', 'minecraft:wall_torch'],
67
- 'minecraft:soul_torch': ['minecraft:soul_torch', 'minecraft:soul_wall_torch'],
67
+ 'minecraft:soul_torch': [
68
+ 'minecraft:soul_torch',
69
+ 'minecraft:soul_wall_torch',
70
+ ],
68
71
  'minecraft:redstone_torch': [
69
72
  'minecraft:redstone_torch',
70
73
  'minecraft:redstone_wall_torch',
@@ -1,18 +1,18 @@
1
1
  import * as core from '@spyglassmc/core';
2
2
  import type * as mcdoc from '@spyglassmc/mcdoc';
3
- export declare type NbtNode = NbtPrimitiveNode | NbtCompoundNode | NbtCollectionNode;
3
+ export type NbtNode = NbtPrimitiveNode | NbtCompoundNode | NbtCollectionNode;
4
4
  export declare namespace NbtNode {
5
5
  function is(node: core.AstNode | undefined): node is NbtNode;
6
6
  }
7
- export declare type NbtPrimitiveNode = NbtNumberNode | core.StringNode;
7
+ export type NbtPrimitiveNode = NbtNumberNode | core.StringNode;
8
8
  export declare namespace NbtPrimitiveNode {
9
9
  function is(node: core.AstNode | undefined): node is NbtPrimitiveNode;
10
10
  }
11
- export declare type NbtNumberNode = NbtIntegerAlikeNode | NbtFloatAlikeNode;
11
+ export type NbtNumberNode = NbtIntegerAlikeNode | NbtFloatAlikeNode;
12
12
  export declare namespace NbtNumberNode {
13
13
  function is(node: core.AstNode | undefined): node is NbtNumberNode;
14
14
  }
15
- export declare type NbtIntegerAlikeNode = NbtByteNode | NbtShortNode | NbtIntNode | NbtLongNode;
15
+ export type NbtIntegerAlikeNode = NbtByteNode | NbtShortNode | NbtIntNode | NbtLongNode;
16
16
  export declare namespace NbtIntegerAlikeNode {
17
17
  function is(node: core.AstNode | undefined): node is NbtIntegerAlikeNode;
18
18
  }
@@ -40,7 +40,7 @@ export interface NbtLongNode extends core.LongBaseNode {
40
40
  export declare namespace NbtLongNode {
41
41
  function is(node: core.AstNode | undefined): node is NbtLongNode;
42
42
  }
43
- export declare type NbtFloatAlikeNode = NbtFloatNode | NbtDoubleNode;
43
+ export type NbtFloatAlikeNode = NbtFloatNode | NbtDoubleNode;
44
44
  export declare namespace NbtFloatAlikeNode {
45
45
  function is(node: core.AstNode | undefined): node is NbtFloatAlikeNode;
46
46
  }
@@ -62,7 +62,7 @@ export interface NbtCompoundNode extends core.RecordBaseNode<core.StringNode, Nb
62
62
  export declare namespace NbtCompoundNode {
63
63
  function is(node: core.AstNode | undefined): node is NbtCompoundNode;
64
64
  }
65
- export declare type NbtCollectionNode = NbtListNode | NbtPrimitiveArrayNode;
65
+ export type NbtCollectionNode = NbtListNode | NbtPrimitiveArrayNode;
66
66
  export declare namespace NbtCollectionNode {
67
67
  function is(node: core.AstNode | undefined): node is NbtCollectionNode;
68
68
  }
@@ -73,7 +73,7 @@ export interface NbtListNode extends core.ListNode<NbtNode> {
73
73
  export declare namespace NbtListNode {
74
74
  function is(node: core.AstNode | undefined): node is NbtListNode;
75
75
  }
76
- export declare type NbtPrimitiveArrayNode = NbtByteArrayNode | NbtIntArrayNode | NbtLongArrayNode;
76
+ export type NbtPrimitiveArrayNode = NbtByteArrayNode | NbtIntArrayNode | NbtLongArrayNode;
77
77
  export declare namespace NbtPrimitiveArrayNode {
78
78
  function is(node: core.AstNode | undefined): node is NbtPrimitiveArrayNode;
79
79
  }
@@ -57,10 +57,22 @@ const key = (children, src, ctx) => {
57
57
  const node = core.string({
58
58
  colorTokenType: 'property',
59
59
  escapable: {},
60
- // No single quotes: https://bugs.mojang.com/browse/MC-175504
61
- quotes: ['"'],
60
+ // Single quotes supported since 1.20 Pre-release 2 (roughly pack format 15)
61
+ // https://bugs.mojang.com/browse/MC-175504
62
+ quotes: ['"', "'"],
62
63
  unquotable: {
63
- blockList: new Set(['\n', '\r', '\t', ' ', '"', '[', ']', '.', '{', '}']),
64
+ blockList: new Set([
65
+ '\n',
66
+ '\r',
67
+ '\t',
68
+ ' ',
69
+ '"',
70
+ '[',
71
+ ']',
72
+ '.',
73
+ '{',
74
+ '}',
75
+ ]),
64
76
  },
65
77
  })(src, ctx);
66
78
  children.push(node);
@@ -67,7 +67,8 @@ export const primitive = (src, ctx) => {
67
67
  if (core.Source.isBrigadierQuote(src.peek())) {
68
68
  return string(src, ctx);
69
69
  }
70
- const { result: unquotedResult, updateSrcAndCtx: updateUnquoted } = core.attempt(string, src, ctx);
70
+ const { result: unquotedResult, updateSrcAndCtx: updateUnquoted } = core
71
+ .attempt(string, src, ctx);
71
72
  for (const e of NumeralPatterns) {
72
73
  if (e.pattern.test(unquotedResult.value)) {
73
74
  if (e.group === 0 /* Group.Boolean */) {
@@ -82,13 +83,19 @@ export const primitive = (src, ctx) => {
82
83
  let isOutOfRange = false;
83
84
  const onOutOfRange = () => (isOutOfRange = true);
84
85
  const numeralParser = e.group === 2 /* Group.IntegerAlike */
85
- ? // As we already checked the format of the value with `e.pattern` in the if-block, there is no need to check
86
- // it again here in the parser, therefore we just pass in a simple /./ regex.
87
- core.integer({ pattern: /./, min: e.min, max: e.max, onOutOfRange })
86
+ // As we already checked the format of the value with `e.pattern` in the if-block, there is no need to check
87
+ // it again here in the parser, therefore we just pass in a simple /./ regex.
88
+ ? core.integer({
89
+ pattern: /./,
90
+ min: e.min,
91
+ max: e.max,
92
+ onOutOfRange,
93
+ })
88
94
  : e.group === 3 /* Group.LongAlike */
89
95
  ? core.long({ pattern: /./, min: e.min, max: e.max, onOutOfRange })
90
96
  : core.float({ pattern: /./, min: e.min, max: e.max, onOutOfRange });
91
- const { result: numeralResult, updateSrcAndCtx: updateNumeral } = core.attempt(numeralParser, src, ctx);
97
+ const { result: numeralResult, updateSrcAndCtx: updateNumeral } = core
98
+ .attempt(numeralParser, src, ctx);
92
99
  if (isOutOfRange) {
93
100
  ctx.err.report(localize('nbt.parser.number.out-of-range', localizeTag(e.type), localize('nbt.node.string'), e.min, e.max), unquotedResult, 2 /* core.ErrorSeverity.Warning */);
94
101
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spyglassmc/nbt",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
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.1",
29
- "@spyglassmc/locales": "0.3.1",
30
- "@spyglassmc/mcdoc": "0.3.2"
28
+ "@spyglassmc/core": "0.4.3",
29
+ "@spyglassmc/locales": "0.3.3",
30
+ "@spyglassmc/mcdoc": "0.3.4"
31
31
  }
32
32
  }