@spyglassmc/mcdoc 0.3.1 → 0.3.3

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.
@@ -4,20 +4,20 @@ export interface Attribute {
4
4
  name: string;
5
5
  value?: AttributeValue;
6
6
  }
7
- export declare type AttributeValue = McdocType | {
7
+ export type AttributeValue = McdocType | {
8
8
  kind: 'tree';
9
9
  values: AttributeTree;
10
10
  };
11
- export declare type AttributeTree = {
11
+ export type AttributeTree = {
12
12
  [key: string | number]: AttributeValue;
13
13
  };
14
- export declare type NumericRange = {
14
+ export type NumericRange = {
15
15
  kind: RangeKind;
16
16
  min?: number;
17
17
  max?: number;
18
18
  };
19
19
  export declare const StaticIndexKeywords: readonly ["fallback", "none", "unknown"];
20
- export declare type StaticIndexKeyword = typeof StaticIndexKeywords[number];
20
+ export type StaticIndexKeyword = (typeof StaticIndexKeywords)[number];
21
21
  export interface StaticIndex {
22
22
  kind: 'static';
23
23
  value: string;
@@ -28,28 +28,23 @@ export interface DynamicIndex {
28
28
  keyword: 'key' | 'parent';
29
29
  })[];
30
30
  }
31
- export declare type Index = StaticIndex | DynamicIndex;
31
+ export type Index = StaticIndex | DynamicIndex;
32
32
  /**
33
33
  * Corresponds to the IndexBodyNode
34
34
  */
35
- export declare type ParallelIndices = Index[];
35
+ export type ParallelIndices = Index[];
36
36
  export interface DispatcherData {
37
37
  registry: FullResourceLocation;
38
- index: ParallelIndices;
38
+ parallelIndices: ParallelIndices;
39
39
  }
40
- export interface TypeBase {
41
- kind: string;
42
- attributes?: Attribute[];
43
- indices?: ParallelIndices[];
44
- }
45
- export interface DispatcherType extends TypeBase, DispatcherData {
40
+ export interface DispatcherType extends DispatcherData {
46
41
  kind: 'dispatcher';
47
42
  }
48
- export interface StructType extends TypeBase {
43
+ export interface StructType {
49
44
  kind: 'struct';
50
45
  fields: StructTypeField[];
51
46
  }
52
- export declare type StructTypeField = StructTypePairField | StructTypeSpreadField;
47
+ export type StructTypeField = StructTypePairField | StructTypeSpreadField;
53
48
  export interface StructTypePairField {
54
49
  kind: 'pair';
55
50
  attributes?: Attribute[];
@@ -62,7 +57,7 @@ export interface StructTypeSpreadField {
62
57
  attributes?: Attribute[];
63
58
  type: McdocType;
64
59
  }
65
- export interface EnumType extends TypeBase {
60
+ export interface EnumType {
66
61
  kind: 'enum';
67
62
  enumKind?: EnumKind;
68
63
  values: EnumTypeField[];
@@ -72,25 +67,46 @@ export interface EnumTypeField {
72
67
  identifier: string;
73
68
  value: string | number | bigint;
74
69
  }
75
- export interface ReferenceType extends TypeBase {
70
+ export interface ReferenceType {
76
71
  kind: 'reference';
77
72
  path?: string;
78
- typeParameters?: McdocType[];
79
73
  }
80
- export interface UnionType<T extends McdocType = McdocType> extends TypeBase {
74
+ export interface UnionType<T extends McdocType = McdocType> {
81
75
  kind: 'union';
82
76
  members: T[];
83
77
  }
78
+ export interface AttributedType {
79
+ kind: 'attributed';
80
+ attribute: Attribute;
81
+ child: McdocType;
82
+ }
83
+ export interface IndexedType {
84
+ kind: 'indexed';
85
+ parallelIndices: Index[];
86
+ child: McdocType;
87
+ }
88
+ export interface TemplateType {
89
+ kind: 'template';
90
+ child: McdocType;
91
+ typeParams: {
92
+ path: string;
93
+ }[];
94
+ }
95
+ export interface ConcreteType {
96
+ kind: 'concrete';
97
+ child: McdocType;
98
+ typeArgs: McdocType[];
99
+ }
84
100
  export declare const EmptyUnion: UnionType<never> & NoIndices;
85
101
  export declare function createEmptyUnion(attributes?: Attribute[]): UnionType<never> & NoIndices;
86
- export interface KeywordType extends TypeBase {
87
- kind: 'any' | 'boolean';
102
+ export interface KeywordType {
103
+ kind: 'any' | 'boolean' | 'unsafe';
88
104
  }
89
- export interface StringType extends TypeBase {
105
+ export interface StringType {
90
106
  kind: 'string';
91
107
  lengthRange?: NumericRange;
92
108
  }
93
- export declare type LiteralValue = {
109
+ export type LiteralValue = {
94
110
  kind: 'boolean';
95
111
  value: boolean;
96
112
  } | {
@@ -101,66 +117,66 @@ export declare type LiteralValue = {
101
117
  value: number;
102
118
  suffix: 'b' | 's' | 'l' | 'f' | 'd' | undefined;
103
119
  };
104
- export interface LiteralType extends TypeBase {
120
+ export interface LiteralType {
105
121
  kind: 'literal';
106
122
  value: LiteralValue;
107
123
  }
108
124
  export declare const LiteralNumberSuffixes: readonly ["b", "s", "l", "f", "d"];
109
- export declare type LiteralNumberSuffix = typeof LiteralNumberSuffixes[number];
125
+ export type LiteralNumberSuffix = (typeof LiteralNumberSuffixes)[number];
110
126
  export declare const LiteralNumberCaseInsensitiveSuffixes: readonly ["b", "s", "l", "f", "d", "B", "S", "L", "F", "D"];
111
- export declare type LiteralNumberCaseInsensitiveSuffix = typeof LiteralNumberCaseInsensitiveSuffixes[number];
112
- export interface NumericType extends TypeBase {
127
+ export type LiteralNumberCaseInsensitiveSuffix = (typeof LiteralNumberCaseInsensitiveSuffixes)[number];
128
+ export interface NumericType {
113
129
  kind: NumericTypeKind;
114
130
  valueRange?: NumericRange;
115
131
  }
116
132
  export declare const NumericTypeIntKinds: readonly ["byte", "short", "int", "long"];
117
- export declare type NumericTypeIntKind = typeof NumericTypeIntKinds[number];
133
+ export type NumericTypeIntKind = (typeof NumericTypeIntKinds)[number];
118
134
  export declare const NumericTypeFloatKinds: readonly ["float", "double"];
119
- export declare type NumericTypeFloatKind = typeof NumericTypeFloatKinds[number];
135
+ export type NumericTypeFloatKind = (typeof NumericTypeFloatKinds)[number];
120
136
  export declare const NumericTypeKinds: readonly ["byte", "short", "int", "long", "float", "double"];
121
- export declare type NumericTypeKind = typeof NumericTypeKinds[number];
122
- export interface PrimitiveArrayType extends TypeBase {
137
+ export type NumericTypeKind = (typeof NumericTypeKinds)[number];
138
+ export interface PrimitiveArrayType {
123
139
  kind: 'byte_array' | 'int_array' | 'long_array';
124
140
  valueRange?: NumericRange;
125
141
  lengthRange?: NumericRange;
126
142
  }
127
143
  export declare const PrimitiveArrayValueKinds: readonly ["byte", "int", "long"];
128
- export declare type PrimitiveArrayValueKind = typeof PrimitiveArrayValueKinds[number];
144
+ export type PrimitiveArrayValueKind = (typeof PrimitiveArrayValueKinds)[number];
129
145
  export declare const PrimitiveArrayKinds: readonly ("byte_array" | "int_array" | "long_array")[];
130
- export declare type PrimitiveArrayKind = typeof PrimitiveArrayKinds[number];
131
- export interface ListType extends TypeBase {
146
+ export type PrimitiveArrayKind = (typeof PrimitiveArrayKinds)[number];
147
+ export interface ListType {
132
148
  kind: 'list';
133
149
  item: McdocType;
134
150
  lengthRange?: NumericRange;
135
151
  }
136
- export interface TupleType extends TypeBase {
152
+ export interface TupleType {
137
153
  kind: 'tuple';
138
154
  items: McdocType[];
139
155
  }
140
- export declare type McdocType = DispatcherType | EnumType | KeywordType | ListType | LiteralType | NumericType | PrimitiveArrayType | ReferenceType | StringType | StructType | TupleType | UnionType;
156
+ export type McdocType = DispatcherType | EnumType | KeywordType | ListType | LiteralType | NumericType | PrimitiveArrayType | ReferenceType | StringType | StructType | TupleType | UnionType | AttributedType | IndexedType | TemplateType | ConcreteType;
141
157
  export declare namespace McdocType {
142
158
  function toString(type: McdocType | undefined): string;
143
159
  }
144
160
  /**
145
161
  * A type that doesn't include a dispatcher type.
146
162
  */
147
- export declare type DispatchedType = Exclude<McdocType, DispatcherType | UnionType> | UnionType<DispatchedType>;
163
+ export type DispatchedType = Exclude<McdocType, DispatcherType | UnionType> | UnionType<DispatchedType>;
148
164
  /**
149
165
  * A type that doesn't include a reference type.
150
166
  */
151
- export declare type DereferencedType = Exclude<McdocType, ReferenceType | UnionType> | UnionType<DereferencedType>;
167
+ export type DereferencedType = Exclude<McdocType, ReferenceType | UnionType> | UnionType<DereferencedType>;
152
168
  /**
153
169
  * A type that doesn't include a dispatcher type or a reference type.
154
170
  */
155
- export declare type TangibleType = Exclude<McdocType, DispatcherType | ReferenceType | UnionType> | UnionType<TangibleType>;
171
+ export type TangibleType = Exclude<McdocType, DispatcherType | ReferenceType | UnionType> | UnionType<TangibleType>;
156
172
  /**
157
173
  * A type that is {@link TangibleType} and doesn't have any indices.
158
174
  */
159
- export declare type ResolvedType = (Exclude<McdocType, DispatcherType | ReferenceType | UnionType> | UnionType<ResolvedType>) & NoIndices;
160
- declare type NoIndices = {
175
+ export type ResolvedType = (Exclude<McdocType, DispatcherType | ReferenceType | UnionType> | UnionType<ResolvedType>) & NoIndices;
176
+ type NoIndices = {
161
177
  indices?: undefined;
162
178
  };
163
- export interface FlatStructType extends TypeBase {
179
+ export interface FlatStructType {
164
180
  kind: 'flat_struct';
165
181
  fields: Record<string, McdocType>;
166
182
  }
@@ -169,7 +185,7 @@ export declare const unionTypes: (a: McdocType, b: McdocType) => McdocType;
169
185
  export declare const simplifyUnionType: (union: UnionType) => McdocType;
170
186
  export declare const simplifyListType: (list: ListType) => ListType;
171
187
  export declare const simplifyType: (data: McdocType) => McdocType;
172
- export declare const checkAssignability: ({ source, target }: {
188
+ export declare const checkAssignability: ({ source, target, }: {
173
189
  source: McdocType | undefined;
174
190
  target: McdocType | undefined;
175
191
  }) => {
package/lib/type/index.js CHANGED
@@ -1,21 +1,53 @@
1
- import { Arrayable } from '@spyglassmc/core';
1
+ import { Arrayable, Dev } from '@spyglassmc/core';
2
2
  import { localeQuote, localize } from '@spyglassmc/locales';
3
3
  import { getRangeDelimiter } from '../node/index.js';
4
- export const StaticIndexKeywords = Object.freeze(['fallback', 'none', 'unknown']);
5
- export const EmptyUnion = Object.freeze({ kind: 'union', members: [] });
4
+ export const StaticIndexKeywords = Object.freeze([
5
+ 'fallback',
6
+ 'none',
7
+ 'unknown',
8
+ ]);
9
+ export const EmptyUnion = Object.freeze({
10
+ kind: 'union',
11
+ members: [],
12
+ });
6
13
  export function createEmptyUnion(attributes) {
7
14
  return {
8
15
  ...EmptyUnion,
9
- attributes,
16
+ // attributes,
10
17
  };
11
18
  }
12
- export const LiteralNumberSuffixes = Object.freeze(['b', 's', 'l', 'f', 'd']);
13
- export const LiteralNumberCaseInsensitiveSuffixes = Object.freeze([...LiteralNumberSuffixes, 'B', 'S', 'L', 'F', 'D']);
14
- export const NumericTypeIntKinds = Object.freeze(['byte', 'short', 'int', 'long']);
19
+ export const LiteralNumberSuffixes = Object.freeze([
20
+ 'b',
21
+ 's',
22
+ 'l',
23
+ 'f',
24
+ 'd',
25
+ ]);
26
+ export const LiteralNumberCaseInsensitiveSuffixes = Object.freeze([
27
+ ...LiteralNumberSuffixes,
28
+ 'B',
29
+ 'S',
30
+ 'L',
31
+ 'F',
32
+ 'D',
33
+ ]);
34
+ export const NumericTypeIntKinds = Object.freeze([
35
+ 'byte',
36
+ 'short',
37
+ 'int',
38
+ 'long',
39
+ ]);
15
40
  export const NumericTypeFloatKinds = Object.freeze(['float', 'double']);
16
- export const NumericTypeKinds = Object.freeze([...NumericTypeIntKinds, ...NumericTypeFloatKinds]);
17
- export const PrimitiveArrayValueKinds = Object.freeze(['byte', 'int', 'long']);
18
- export const PrimitiveArrayKinds = Object.freeze(PrimitiveArrayValueKinds.map(kind => `${kind}_array`));
41
+ export const NumericTypeKinds = Object.freeze([
42
+ ...NumericTypeIntKinds,
43
+ ...NumericTypeFloatKinds,
44
+ ]);
45
+ export const PrimitiveArrayValueKinds = Object.freeze([
46
+ 'byte',
47
+ 'int',
48
+ 'long',
49
+ ]);
50
+ export const PrimitiveArrayKinds = Object.freeze(PrimitiveArrayValueKinds.map((kind) => `${kind}_array`));
19
51
  export var McdocType;
20
52
  (function (McdocType) {
21
53
  function toString(type) {
@@ -24,7 +56,9 @@ export var McdocType;
24
56
  return '';
25
57
  }
26
58
  const { kind, min, max } = range;
27
- return min === max ? ` @ ${min}` : ` @ ${min ?? ''}${getRangeDelimiter(kind)}${max ?? ''}`;
59
+ return min === max
60
+ ? ` @ ${min}`
61
+ : ` @ ${min ?? ''}${getRangeDelimiter(kind)}${max ?? ''}`;
28
62
  };
29
63
  const indicesToString = (indices) => {
30
64
  const strings = [];
@@ -35,7 +69,9 @@ export var McdocType;
35
69
  else {
36
70
  strings.push(index.kind === 'static'
37
71
  ? `[${index.value}]`
38
- : `[[${index.accessor.map(v => typeof v === 'string' ? v : v.keyword).join('.')}]]`);
72
+ : `[[${index.accessor
73
+ .map((v) => (typeof v === 'string' ? v : v.keyword))
74
+ .join('.')}]]`);
39
75
  }
40
76
  }
41
77
  return `[${strings.join(', ')}]`;
@@ -47,18 +83,26 @@ export var McdocType;
47
83
  case 'any':
48
84
  case 'boolean':
49
85
  return type.kind;
86
+ case 'attributed':
87
+ return `#[${type.attribute.name}${type.attribute.value ? '=<value ...>' : ''}] ${toString(type.child)}`;
50
88
  case 'byte':
51
89
  return `byte${rangeToString(type.valueRange)}`;
52
90
  case 'byte_array':
53
91
  return `byte${rangeToString(type.valueRange)}[]${rangeToString(type.lengthRange)}`;
92
+ case 'concrete':
93
+ return `${toString(type.child)}${type.typeArgs.length
94
+ ? `<${type.typeArgs.map(toString).join(', ')}>`
95
+ : ''}`;
54
96
  case 'dispatcher':
55
- return `${type.registry ?? 'spyglass:unknown'}[${indicesToString(type.index)}]`;
97
+ return `${type.registry ?? 'spyglass:unknown'}[${indicesToString(type.parallelIndices)}]`;
56
98
  case 'double':
57
99
  return `double${rangeToString(type.valueRange)}`;
58
100
  case 'enum':
59
- return '<anonymous_enum>';
101
+ return '<enum ...>';
60
102
  case 'float':
61
103
  return `float${rangeToString(type.valueRange)}`;
104
+ case 'indexed':
105
+ return `${toString(type.child)}${indicesToString(type.parallelIndices)}`;
62
106
  case 'int':
63
107
  return `int${rangeToString(type.valueRange)}`;
64
108
  case 'int_array':
@@ -78,11 +122,19 @@ export var McdocType;
78
122
  case 'string':
79
123
  return `string${rangeToString(type.lengthRange)}`;
80
124
  case 'struct':
81
- return '<anonymous_compound>';
125
+ return '<struct ...>';
126
+ case 'template':
127
+ return `${toString(type.child)}${type.typeParams.length
128
+ ? `<${type.typeParams.map((v) => `?${v.path}`).join(', ')}>`
129
+ : ''}`;
82
130
  case 'tuple':
83
- return `[${type.items.map(v => toString(v)).join(',')}${type.items.length === 1 ? ',' : ''}]`;
131
+ return `[${type.items.map((v) => toString(v)).join(',')}${type.items.length === 1 ? ',' : ''}]`;
84
132
  case 'union':
85
133
  return `(${type.members.map(toString).join(' | ')})`;
134
+ case 'unsafe':
135
+ return 'unsafe';
136
+ default:
137
+ return Dev.assertNever(type);
86
138
  }
87
139
  }
88
140
  McdocType.toString = toString;
@@ -102,17 +154,19 @@ const areRangesMatch = (s, t) => {
102
154
  }
103
155
  const { min: sMin, max: sMax } = s;
104
156
  const { min: tMin, max: tMax } = t;
105
- return (tMin === undefined || (sMin !== undefined && sMin >= tMin)) &&
106
- (tMax === undefined || (sMax !== undefined && sMax <= tMax));
157
+ return ((tMin === undefined || (sMin !== undefined && sMin >= tMin)) &&
158
+ (tMax === undefined || (sMax !== undefined && sMax <= tMax)));
107
159
  };
108
160
  export const flattenUnionType = (union) => {
109
161
  const set = new Set();
110
162
  const add = (data) => {
111
163
  for (const existingMember of set) {
112
- if ((check(data, existingMember) & CheckResult.StrictlyAssignable) === CheckResult.StrictlyAssignable) {
164
+ if ((check(data, existingMember) & CheckResult.StrictlyAssignable) ===
165
+ CheckResult.StrictlyAssignable) {
113
166
  return;
114
167
  }
115
- if ((check(existingMember, data) & CheckResult.StrictlyAssignable) === CheckResult.StrictlyAssignable) {
168
+ if ((check(existingMember, data) & CheckResult.StrictlyAssignable) ===
169
+ CheckResult.StrictlyAssignable) {
116
170
  set.delete(existingMember);
117
171
  }
118
172
  }
@@ -132,17 +186,19 @@ export const flattenUnionType = (union) => {
132
186
  };
133
187
  };
134
188
  export const unionTypes = (a, b) => {
135
- if ((check(a, b) & CheckResult.StrictlyAssignable) === CheckResult.StrictlyAssignable) {
189
+ if ((check(a, b) & CheckResult.StrictlyAssignable) ===
190
+ CheckResult.StrictlyAssignable) {
136
191
  return b;
137
192
  }
138
- if ((check(b, a) & CheckResult.StrictlyAssignable) === CheckResult.StrictlyAssignable) {
193
+ if ((check(b, a) & CheckResult.StrictlyAssignable) ===
194
+ CheckResult.StrictlyAssignable) {
139
195
  return a;
140
196
  }
141
197
  const ans = {
142
198
  kind: 'union',
143
199
  members: [
144
- ...a.kind === 'union' ? a.members : [a],
145
- ...b.kind === 'union' ? b.members : [b],
200
+ ...(a.kind === 'union' ? a.members : [a]),
201
+ ...(b.kind === 'union' ? b.members : [b]),
146
202
  ],
147
203
  };
148
204
  return ans;
@@ -157,7 +213,7 @@ export const simplifyUnionType = (union) => {
157
213
  export const simplifyListType = (list) => ({
158
214
  kind: 'list',
159
215
  item: simplifyType(list.item),
160
- ...list.lengthRange ? { lengthRange: { ...list.lengthRange } } : {},
216
+ ...(list.lengthRange ? { lengthRange: { ...list.lengthRange } } : {}),
161
217
  });
162
218
  export const simplifyType = (data) => {
163
219
  if (data.kind === 'union') {
@@ -182,10 +238,10 @@ const check = (s, t, errors = []) => {
182
238
  ans = CheckResult.StrictlyAssignable;
183
239
  }
184
240
  else if (s.kind === 'union') {
185
- ans = assignableIfTrue(s.members.every(v => check(v, t, errors)));
241
+ ans = assignableIfTrue(s.members.every((v) => check(v, t, errors)));
186
242
  }
187
243
  else if (t.kind === 'union') {
188
- ans = assignableIfTrue(t.members.some(v => check(s, v)));
244
+ ans = assignableIfTrue(t.members.some((v) => check(s, v)));
189
245
  }
190
246
  else if (s.kind === 'boolean') {
191
247
  ans = strictlyAssignableIfTrue(t.kind === 'boolean' || t.kind === 'byte');
@@ -204,16 +260,31 @@ const check = (s, t, errors = []) => {
204
260
  ans = CheckResult.Nah;
205
261
  }
206
262
  }
207
- else if (s.kind === 'byte_array' || s.kind === 'int_array' || s.kind === 'long_array') {
208
- ans = strictlyAssignableIfTrue(t.kind === s.kind && areRangesMatch(s.lengthRange, t.lengthRange) && areRangesMatch(s.valueRange, t.valueRange));
263
+ else if (s.kind === 'byte_array' ||
264
+ s.kind === 'int_array' ||
265
+ s.kind === 'long_array') {
266
+ ans = strictlyAssignableIfTrue(t.kind === s.kind &&
267
+ areRangesMatch(s.lengthRange, t.lengthRange) &&
268
+ areRangesMatch(s.valueRange, t.valueRange));
209
269
  }
210
270
  else if (s.kind === 'struct' || s.kind === 'dispatcher') {
211
271
  ans = assignableIfTrue(t.kind === 'struct' || t.kind === 'dispatcher');
212
272
  }
213
273
  else if (s.kind === 'enum') {
214
- ans = assignableIfTrue((t.kind === 'byte' || t.kind === 'float' || t.kind === 'double' || t.kind === 'int' || t.kind === 'long' || t.kind === 'short' || t.kind === 'string') && (!s.enumKind || s.enumKind === t.kind));
215
- }
216
- else if (s.kind === 'float' || s.kind === 'double' || s.kind === 'int' || s.kind === 'long' || s.kind === 'short') {
274
+ ans = assignableIfTrue((t.kind === 'byte' ||
275
+ t.kind === 'float' ||
276
+ t.kind === 'double' ||
277
+ t.kind === 'int' ||
278
+ t.kind === 'long' ||
279
+ t.kind === 'short' ||
280
+ t.kind === 'string') &&
281
+ (!s.enumKind || s.enumKind === t.kind));
282
+ }
283
+ else if (s.kind === 'float' ||
284
+ s.kind === 'double' ||
285
+ s.kind === 'int' ||
286
+ s.kind === 'long' ||
287
+ s.kind === 'short') {
217
288
  if (t.kind === s.kind) {
218
289
  ans = strictlyAssignableIfTrue(areRangesMatch(s.valueRange, t.valueRange));
219
290
  }
@@ -248,7 +319,7 @@ const check = (s, t, errors = []) => {
248
319
  }
249
320
  return ans;
250
321
  };
251
- export const checkAssignability = ({ source, target }) => {
322
+ export const checkAssignability = ({ source, target, }) => {
252
323
  if (source === undefined || target === undefined) {
253
324
  return { isAssignable: true };
254
325
  }
@@ -256,17 +327,24 @@ export const checkAssignability = ({ source, target }) => {
256
327
  check(source, target, errors);
257
328
  return {
258
329
  isAssignable: errors.length === 0,
259
- ...errors.length ? { errorMessage: errors.reverse().map((m, i) => `${' '.repeat(i)}${m}`).join('\n') } : {},
330
+ ...(errors.length
331
+ ? {
332
+ errorMessage: errors
333
+ .reverse()
334
+ .map((m, i) => `${' '.repeat(i)}${m}`)
335
+ .join('\n'),
336
+ }
337
+ : {}),
260
338
  };
261
339
  };
262
340
  export function resolveType(inputType, ctx, value) {
263
341
  const type = getTangibleType(inputType, ctx, value);
264
- let ans = (() => {
342
+ const ans = (() => {
265
343
  if (type.kind === 'union') {
266
344
  return {
267
345
  kind: 'union',
268
- members: type.members.map(t => resolveType(t, ctx, value)),
269
- attributes: type.attributes,
346
+ members: type.members.map((t) => resolveType(t, ctx, value)),
347
+ // attributes: type.attributes,
270
348
  };
271
349
  }
272
350
  else {
@@ -276,9 +354,9 @@ export function resolveType(inputType, ctx, value) {
276
354
  };
277
355
  }
278
356
  })();
279
- for (const parallelIndices of type.indices ?? []) {
280
- ans = navigateParallelIndices(ans, parallelIndices, ctx, value);
281
- }
357
+ // for (const parallelIndices of type.indices ?? []) {
358
+ // ans = navigateParallelIndices(ans, parallelIndices, ctx, value)
359
+ // }
282
360
  return ans;
283
361
  }
284
362
  function dispatchType(type, ctx) {
@@ -298,7 +376,7 @@ function getTangibleType(type, ctx, value) {
298
376
  return getTangibleType(dereferencedType, ctx, value);
299
377
  }
300
378
  else if (type.kind === 'union') {
301
- ans = mapUnion(type, t => getTangibleType(t, ctx, value));
379
+ ans = mapUnion(type, (t) => getTangibleType(t, ctx, value));
302
380
  }
303
381
  else {
304
382
  ans = type;
@@ -312,27 +390,31 @@ function navigateParallelIndices(type, indices, ctx, value) {
312
390
  else {
313
391
  return {
314
392
  kind: 'union',
315
- members: indices.map(i => navigateIndex(type, i, ctx, value)),
316
- attributes: type.attributes,
393
+ members: indices.map((i) => navigateIndex(type, i, ctx, value)),
394
+ // attributes: type.attributes,
317
395
  };
318
396
  }
319
397
  }
320
398
  function navigateIndex(type, index, ctx, value) {
321
399
  if (type.kind === 'struct') {
322
400
  const key = index.kind === 'static'
323
- ? typeof index.value === 'string' ? index.value : undefined // Special static indices have no meaning on structs.
401
+ ? typeof index.value === 'string'
402
+ ? index.value
403
+ : undefined // Special static indices have no meaning on structs.
324
404
  : resolveDynamicIndex(index, value);
325
405
  if (key === undefined) {
326
- return createEmptyUnion(type.attributes);
406
+ // return createEmptyUnion(type.attributes)
407
+ return createEmptyUnion();
327
408
  }
328
409
  const flatStruct = flattenStruct(type, ctx, value);
329
410
  return resolveType(flatStruct.fields[key], ctx, value);
330
411
  }
331
412
  else if (type.kind === 'union') {
332
- return mapUnion(type, t => navigateIndex(t, index, ctx, value));
413
+ return mapUnion(type, (t) => navigateIndex(t, index, ctx, value));
333
414
  }
334
415
  else {
335
- return createEmptyUnion(type.attributes);
416
+ // return createEmptyUnion(type.attributes)
417
+ return createEmptyUnion();
336
418
  }
337
419
  }
338
420
  function resolveDynamicIndex(index, value) {
@@ -356,8 +438,8 @@ function mapUnion(type, mapper) {
356
438
  const ans = {
357
439
  kind: 'union',
358
440
  members: type.members.map(mapper),
359
- attributes: type.attributes,
360
- indices: type.indices,
441
+ // attributes: type.attributes,
442
+ // indices: type.indices,
361
443
  };
362
444
  return ans;
363
445
  }
@@ -365,13 +447,13 @@ function flattenStruct(type, ctx, value) {
365
447
  const ans = {
366
448
  kind: 'flat_struct',
367
449
  fields: Object.create(null),
368
- attributes: type.attributes,
369
- indices: type.indices,
450
+ // attributes: type.attributes,
451
+ // indices: type.indices,
370
452
  };
371
453
  for (const field of type.fields) {
372
454
  if (field.kind === 'spread') {
373
455
  const target = resolveType(field.type, ctx, value);
374
- addAttributes(ans, ...target.attributes ?? []);
456
+ // addAttributes(ans, ...target.attributes ?? [])
375
457
  if (target.kind === 'struct') {
376
458
  const flatTarget = flattenStruct(target, ctx, value);
377
459
  for (const [key, value] of Object.entries(flatTarget)) {
@@ -392,10 +474,10 @@ function flattenStruct(type, ctx, value) {
392
474
  }
393
475
  function addAttributes(type, ...attributes) {
394
476
  for (const attr of attributes) {
395
- type.attributes ??= [];
396
- if (!type.attributes.some(a => a.name === attr.name)) {
397
- type.attributes.push(attr);
398
- }
477
+ // type.attributes ??= []
478
+ // if (!type.attributes.some(a => a.name === attr.name)) {
479
+ // type.attributes.push(attr)
480
+ // }
399
481
  }
400
482
  }
401
483
  //# sourceMappingURL=index.js.map
@@ -12,9 +12,7 @@ export const uriBinder = (uris, ctx) => {
12
12
  if (!rel) {
13
13
  continue;
14
14
  }
15
- rel = rel
16
- .slice(0, -Extension.length)
17
- .replace(/(^|\/)mod$/, '');
15
+ rel = rel.slice(0, -Extension.length).replace(/(^|\/)mod$/, '');
18
16
  urisAndRels.push([uri, rel]);
19
17
  }
20
18
  // Now the value of `urisAndRels`:
@@ -23,8 +21,10 @@ export const uriBinder = (uris, ctx) => {
23
21
  // A special check for the directory named `mcdoc`:
24
22
  // If all files are put under this folder, we will treat that folder as the "root" instead.
25
23
  if (urisAndRels.every(([_, rel]) => rel.startsWith(McdocRootPrefix))) {
26
- urisAndRels = urisAndRels
27
- .map(([uri, rel]) => [uri, rel.slice(McdocRootPrefix.length)]);
24
+ urisAndRels = urisAndRels.map(([uri, rel]) => [
25
+ uri,
26
+ rel.slice(McdocRootPrefix.length),
27
+ ]);
28
28
  }
29
29
  // Now the value of `urisAndRels`:
30
30
  // file:///root/mcdoc/foo/mod.mcdoc -> foo
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spyglassmc/mcdoc",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -25,7 +25,7 @@
25
25
  "url": "https://github.com/SpyglassMC/Spyglass/issues"
26
26
  },
27
27
  "dependencies": {
28
- "@spyglassmc/core": "0.4.0",
29
- "@spyglassmc/locales": "0.3.0"
28
+ "@spyglassmc/core": "0.4.2",
29
+ "@spyglassmc/locales": "0.3.2"
30
30
  }
31
31
  }