@spyglassmc/mcdoc 0.3.1 → 0.3.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,8 +1,8 @@
1
1
  import { ColorToken } from '@spyglassmc/core';
2
- export const identifier = node => {
2
+ export const identifier = (node) => {
3
3
  return [ColorToken.create(node, 'variable')];
4
4
  };
5
- export const literal = node => {
5
+ export const literal = (node) => {
6
6
  return [ColorToken.create(node, node.colorTokenType ?? 'literal')];
7
7
  };
8
8
  export function registerMcdocColorizer(meta) {
@@ -13,7 +13,7 @@ export declare const TopLevelNode: Readonly<{
13
13
  }>;
14
14
  export interface DispatchStatementNode extends AstNode {
15
15
  type: 'mcdoc:dispatch_statement';
16
- children: (CommentNode | AttributeNode | LiteralNode | ResourceLocationNode | IndexBodyNode | TypeNode)[];
16
+ children: (CommentNode | AttributeNode | LiteralNode | ResourceLocationNode | IndexBodyNode | TypeParamBlockNode | TypeNode)[];
17
17
  }
18
18
  export declare const DispatchStatementNode: Readonly<{
19
19
  destruct(node: DispatchStatementNode): {
@@ -21,6 +21,7 @@ export declare const DispatchStatementNode: Readonly<{
21
21
  location?: ResourceLocationNode;
22
22
  index?: IndexBodyNode;
23
23
  target?: TypeNode;
24
+ typeParams?: TypeParamBlockNode;
24
25
  };
25
26
  is(node: AstNode | undefined): node is DispatchStatementNode;
26
27
  }>;
@@ -76,12 +77,12 @@ export declare const TypeNode: Readonly<{
76
77
  }>;
77
78
  export interface TypeBaseNode<CN extends AstNode> extends AstNode {
78
79
  type: `mcdoc:${string}`;
79
- children: (CommentNode | AttributeNode | IndexBodyNode | CN)[];
80
+ children: (CommentNode | AttributeNode | IndexBodyNode | TypeArgBlockNode | CN)[];
80
81
  }
81
82
  export declare const TypeBaseNode: Readonly<{
82
83
  destruct(node: TypeBaseNode<any>): {
84
+ appendixes: (IndexBodyNode | TypeArgBlockNode)[];
83
85
  attributes: AttributeNode[];
84
- indices: IndexBodyNode[];
85
86
  };
86
87
  }>;
87
88
  export interface AttributeNode extends AstNode {
@@ -135,6 +136,16 @@ export interface AttributeTreeNamedKeyValuePair {
135
136
  key: IdentifierNode | StringNode;
136
137
  value: AttributeValueNode;
137
138
  }
139
+ export interface TypeArgBlockNode extends AstNode {
140
+ type: 'mcdoc:type_arg_block';
141
+ children: (CommentNode | TypeNode)[];
142
+ }
143
+ export declare const TypeArgBlockNode: Readonly<{
144
+ destruct(node: TypeArgBlockNode): {
145
+ args: TypeNode[];
146
+ };
147
+ is(node: AstNode | undefined): node is TypeArgBlockNode;
148
+ }>;
138
149
  export interface AnyTypeNode extends TypeBaseNode<LiteralNode> {
139
150
  type: 'mcdoc:type/any';
140
151
  }
@@ -321,13 +332,12 @@ export declare const StructNode: Readonly<{
321
332
  };
322
333
  is(node: AstNode | undefined): node is StructNode;
323
334
  }>;
324
- export interface ReferenceTypeNode extends TypeBaseNode<PathNode | TypeNode> {
335
+ export interface ReferenceTypeNode extends TypeBaseNode<PathNode> {
325
336
  type: 'mcdoc:type/reference';
326
337
  }
327
338
  export declare const ReferenceTypeNode: Readonly<{
328
339
  destruct(node: ReferenceTypeNode): {
329
340
  path: PathNode;
330
- typeParameters: TypeNode[];
331
341
  };
332
342
  is(node: AstNode | undefined): node is ReferenceTypeNode;
333
343
  }>;
@@ -466,12 +476,13 @@ export declare const StructInjectionNode: Readonly<{
466
476
  }>;
467
477
  export interface TypeAliasNode extends AstNode {
468
478
  type: 'mcdoc:type_alias';
469
- children: (CommentNode | DocCommentsNode | LiteralNode | IdentifierNode | TypeParamBlockNode | TypeNode)[];
479
+ children: (CommentNode | PrelimNode | LiteralNode | IdentifierNode | TypeParamBlockNode | TypeNode)[];
470
480
  }
471
481
  export declare const TypeAliasNode: Readonly<{
472
482
  destruct(node: TypeAliasNode): {
483
+ attributes: AttributeNode[];
473
484
  docComments?: DocCommentsNode;
474
- identifier?: IdentifierNode;
485
+ identifier: IdentifierNode;
475
486
  keyword: LiteralNode;
476
487
  typeParams?: TypeParamBlockNode;
477
488
  rhs?: TypeNode;
package/lib/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { atArray, CommentNode, FloatNode, ResourceLocationNode, StringNode } from '@spyglassmc/core';
1
+ import { atArray, CommentNode, FloatNode, ResourceLocationNode, StringNode, } from '@spyglassmc/core';
2
2
  export const ModuleNode = Object.freeze({
3
3
  is(node) {
4
4
  return node?.type === 'mcdoc:module';
@@ -22,10 +22,12 @@ export const DispatchStatementNode = Object.freeze({
22
22
  location: node.children.find(ResourceLocationNode.is),
23
23
  index: node.children.find(IndexBodyNode.is),
24
24
  target: node.children.find(TypeNode.is),
25
+ typeParams: node.children.find(TypeParamBlockNode.is),
25
26
  };
26
27
  },
27
28
  is(node) {
28
- return node?.type === 'mcdoc:dispatch_statement';
29
+ return (node?.type ===
30
+ 'mcdoc:dispatch_statement');
29
31
  },
30
32
  });
31
33
  export const LiteralNode = Object.freeze({
@@ -50,7 +52,10 @@ export const IndexNode = Object.freeze({
50
52
  });
51
53
  export const StaticIndexNode = Object.freeze({
52
54
  is(node) {
53
- return LiteralNode.is(node) || IdentifierNode.is(node) || StringNode.is(node) || ResourceLocationNode.is(node);
55
+ return (LiteralNode.is(node) ||
56
+ IdentifierNode.is(node) ||
57
+ StringNode.is(node) ||
58
+ ResourceLocationNode.is(node));
54
59
  },
55
60
  });
56
61
  export const IdentifierNode = Object.freeze({
@@ -65,12 +70,12 @@ export const DynamicIndexNode = Object.freeze({
65
70
  };
66
71
  },
67
72
  is(node) {
68
- return node?.type === 'mcdoc:dynamic_index';
73
+ return (node?.type === 'mcdoc:dynamic_index');
69
74
  },
70
75
  });
71
76
  export const AccessorKeyNode = Object.freeze({
72
77
  is(node) {
73
- return LiteralNode.is(node) || IdentifierNode.is(node) || StringNode.is(node);
78
+ return (LiteralNode.is(node) || IdentifierNode.is(node) || StringNode.is(node));
74
79
  },
75
80
  });
76
81
  export const TypeNode = Object.freeze({
@@ -93,8 +98,8 @@ export const TypeNode = Object.freeze({
93
98
  export const TypeBaseNode = Object.freeze({
94
99
  destruct(node) {
95
100
  return {
101
+ appendixes: node.children.filter((n) => IndexBodyNode.is(n) || TypeArgBlockNode.is(n)),
96
102
  attributes: node.children.filter(AttributeNode.is),
97
- indices: node.children.filter(IndexBodyNode.is),
98
103
  };
99
104
  },
100
105
  });
@@ -122,7 +127,7 @@ export const AttributeTreeNode = Object.freeze({
122
127
  };
123
128
  },
124
129
  is(node) {
125
- return node?.type === 'mcdoc:attribute/tree';
130
+ return (node?.type === 'mcdoc:attribute/tree');
126
131
  },
127
132
  });
128
133
  export const AttributeTreePosValuesNode = Object.freeze({
@@ -132,7 +137,8 @@ export const AttributeTreePosValuesNode = Object.freeze({
132
137
  };
133
138
  },
134
139
  is(node) {
135
- return node?.type === 'mcdoc:attribute/tree/pos';
140
+ return (node?.type ===
141
+ 'mcdoc:attribute/tree/pos');
136
142
  },
137
143
  });
138
144
  export const AttributeTreeNamedValuesNode = Object.freeze({
@@ -156,7 +162,18 @@ export const AttributeTreeNamedValuesNode = Object.freeze({
156
162
  return ans;
157
163
  },
158
164
  is(node) {
159
- return node?.type === 'mcdoc:attribute/tree/named';
165
+ return (node?.type ===
166
+ 'mcdoc:attribute/tree/named');
167
+ },
168
+ });
169
+ export const TypeArgBlockNode = Object.freeze({
170
+ destruct(node) {
171
+ return {
172
+ args: node.children.filter(TypeNode.is),
173
+ };
174
+ },
175
+ is(node) {
176
+ return (node?.type === 'mcdoc:type_arg_block');
160
177
  },
161
178
  });
162
179
  export const AnyTypeNode = Object.freeze({
@@ -189,7 +206,7 @@ export const LiteralTypeNode = Object.freeze({
189
206
  });
190
207
  export const LiteralTypeValueNode = Object.freeze({
191
208
  is(node) {
192
- return LiteralNode.is(node) || TypedNumberNode.is(node) || StringNode.is(node);
209
+ return (LiteralNode.is(node) || TypedNumberNode.is(node) || StringNode.is(node));
193
210
  },
194
211
  });
195
212
  export const TypedNumberNode = Object.freeze({
@@ -207,11 +224,12 @@ export const NumericTypeNode = Object.freeze({
207
224
  destruct(node) {
208
225
  return {
209
226
  numericKind: node.children.find(LiteralNode.is),
210
- valueRange: node.children.find(FloatRangeNode.is) || node.children.find(IntRangeNode.is),
227
+ valueRange: node.children.find(FloatRangeNode.is) ||
228
+ node.children.find(IntRangeNode.is),
211
229
  };
212
230
  },
213
231
  is(node) {
214
- return node?.type === 'mcdoc:type/numeric_type';
232
+ return (node?.type === 'mcdoc:type/numeric_type');
215
233
  },
216
234
  });
217
235
  export const RangeExclusiveChar = '<';
@@ -294,7 +312,8 @@ export const PrimitiveArrayTypeNode = Object.freeze({
294
312
  };
295
313
  },
296
314
  is(node) {
297
- return node?.type === 'mcdoc:type/primitive_array';
315
+ return (node?.type ===
316
+ 'mcdoc:type/primitive_array');
298
317
  },
299
318
  });
300
319
  export const ListTypeNode = Object.freeze({
@@ -328,7 +347,15 @@ export const TupleTypeNode = Object.freeze({
328
347
  return node?.type === 'mcdoc:type/tuple';
329
348
  },
330
349
  });
331
- const EnumKinds = new Set(['byte', 'short', 'int', 'long', 'float', 'double', 'string']);
350
+ const EnumKinds = new Set([
351
+ 'byte',
352
+ 'short',
353
+ 'int',
354
+ 'long',
355
+ 'float',
356
+ 'double',
357
+ 'string',
358
+ ]);
332
359
  export const EnumNode = Object.freeze({
333
360
  kinds: EnumKinds,
334
361
  destruct(node) {
@@ -360,14 +387,14 @@ export const DocCommentsNode = Object.freeze({
360
387
  if (!node) {
361
388
  return undefined;
362
389
  }
363
- let comments = node.children.map(doc => doc.comment);
390
+ let comments = node.children.map((doc) => doc.comment);
364
391
  // If every comment contains a leading space or is empty, stripe the leading spaces off.
365
392
  // e.g. /// This is an example doc comment.
366
393
  // ///
367
394
  // /// Another line.
368
395
  // should be converted to "This is an example doc comment.\n\nAnother line."
369
- if (comments.every(s => s.length === 0 || s.startsWith(' '))) {
370
- comments = comments.map(s => s.slice(1));
396
+ if (comments.every((s) => s.length === 0 || s.startsWith(' '))) {
397
+ comments = comments.map((s) => s.slice(1));
371
398
  }
372
399
  return comments.join('\n');
373
400
  },
@@ -424,11 +451,10 @@ export const ReferenceTypeNode = Object.freeze({
424
451
  destruct(node) {
425
452
  return {
426
453
  path: node.children.find(PathNode.is),
427
- typeParameters: node.children.filter(TypeNode.is),
428
454
  };
429
455
  },
430
456
  is(node) {
431
- return node?.type === 'mcdoc:type/reference';
457
+ return (node?.type === 'mcdoc:type/reference');
432
458
  },
433
459
  });
434
460
  export const TypeParamBlockNode = Object.freeze({
@@ -438,7 +464,8 @@ export const TypeParamBlockNode = Object.freeze({
438
464
  };
439
465
  },
440
466
  is(node) {
441
- return node?.type === 'mcdoc:type_param_block';
467
+ return (node?.type ===
468
+ 'mcdoc:type_param_block');
442
469
  },
443
470
  });
444
471
  export const TypeParamNode = Object.freeze({
@@ -490,12 +517,15 @@ export const StructPairFieldNode = Object.freeze({
490
517
  };
491
518
  },
492
519
  is(node) {
493
- return node?.type === 'mcdoc:struct/field/pair';
520
+ return (node?.type ===
521
+ 'mcdoc:struct/field/pair');
494
522
  },
495
523
  });
496
524
  export const StructKeyNode = Object.freeze({
497
525
  is(node) {
498
- return StringNode.is(node) || IdentifierNode.is(node) || StructMapKeyNode.is(node);
526
+ return (StringNode.is(node) ||
527
+ IdentifierNode.is(node) ||
528
+ StructMapKeyNode.is(node));
499
529
  },
500
530
  });
501
531
  export const StructMapKeyNode = Object.freeze({
@@ -505,7 +535,7 @@ export const StructMapKeyNode = Object.freeze({
505
535
  };
506
536
  },
507
537
  is(node) {
508
- return node?.type === 'mcdoc:struct/map_key';
538
+ return (node?.type === 'mcdoc:struct/map_key');
509
539
  },
510
540
  });
511
541
  export const StructSpreadFieldNode = Object.freeze({
@@ -516,7 +546,8 @@ export const StructSpreadFieldNode = Object.freeze({
516
546
  };
517
547
  },
518
548
  is(node) {
519
- return node?.type === 'mcdoc:struct/field/spread';
549
+ return (node?.type ===
550
+ 'mcdoc:struct/field/spread');
520
551
  },
521
552
  });
522
553
  export const DispatcherTypeNode = Object.freeze({
@@ -527,7 +558,7 @@ export const DispatcherTypeNode = Object.freeze({
527
558
  };
528
559
  },
529
560
  is(node) {
530
- return node?.type === 'mcdoc:type/dispatcher';
561
+ return (node?.type === 'mcdoc:type/dispatcher');
531
562
  },
532
563
  });
533
564
  export const UnionTypeNode = Object.freeze({
@@ -557,17 +588,19 @@ export const InjectionContentNode = Object.freeze({
557
588
  });
558
589
  export const EnumInjectionNode = Object.freeze({
559
590
  is(node) {
560
- return node?.type === 'mcdoc:injection/enum';
591
+ return (node?.type === 'mcdoc:injection/enum');
561
592
  },
562
593
  });
563
594
  export const StructInjectionNode = Object.freeze({
564
595
  is(node) {
565
- return node?.type === 'mcdoc:injection/struct';
596
+ return (node?.type ===
597
+ 'mcdoc:injection/struct');
566
598
  },
567
599
  });
568
600
  export const TypeAliasNode = Object.freeze({
569
601
  destruct(node) {
570
602
  return {
603
+ attributes: node.children.filter(AttributeNode.is),
571
604
  docComments: node.children.find(DocCommentsNode.is),
572
605
  identifier: node.children.find(IdentifierNode.is),
573
606
  keyword: node.children.find(LiteralNode.is),
@@ -587,7 +620,7 @@ export const UseStatementNode = Object.freeze({
587
620
  };
588
621
  },
589
622
  is(node) {
590
- return node?.type === 'mcdoc:use_statement';
623
+ return (node?.type === 'mcdoc:use_statement');
591
624
  },
592
625
  });
593
626
  //# sourceMappingURL=index.js.map
@@ -25,7 +25,7 @@ export declare const typedNumber: InfallibleParser<TypedNumberNode>;
25
25
  export declare const enum_: Parser<EnumNode>;
26
26
  export declare const struct: Parser<StructNode>;
27
27
  export declare const injection: Parser<InjectionNode>;
28
- export declare const typeAlias: Parser<TypeAliasNode>;
28
+ export declare const typeAliasStatement: Parser<TypeAliasNode>;
29
29
  export declare const useStatement: Parser<UseStatementNode>;
30
30
  export declare const module_: Parser<ModuleNode>;
31
31
  export declare const anyType: Parser<AnyTypeNode>;