@spyglassmc/mcdoc 0.3.30 → 0.3.32

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.
@@ -10,6 +10,10 @@ const idValidator = validator.alternatives(validator.map(validator.string, v =>
10
10
  empty: validator.optional(validator.options('allowed')),
11
11
  exclude: validator.optional(validator.alternatives(validator.map(validator.string, v => [v]), validator.list(validator.string))),
12
12
  }), () => ({}));
13
+ const matchRegexValidator = validator.alternatives(validator.map(validator.string, v => ({ pattern: v })), validator.tree({
14
+ pattern: validator.string,
15
+ message: validator.optional(validator.string),
16
+ }));
13
17
  function getResourceLocationOptions({ registry, tags, definition, path }, requireCanonical, ctx, typeDef) {
14
18
  if (!registry) {
15
19
  if (typeDef?.kind === 'enum' && typeDef.enumKind === 'string') {
@@ -225,7 +229,28 @@ export function registerBuiltinAttributes(meta) {
225
229
  const error = message
226
230
  .replace(/^Invalid regular expression: /, '')
227
231
  .replace(/^\/.+\/: /, '');
228
- ctx.err.report(localize('invalid-regex-pattern', error), node, 2);
232
+ ctx.err.report(localize('invalid-regex-pattern', error), node, 2 /* core.ErrorSeverity.Warning */);
233
+ }
234
+ };
235
+ },
236
+ });
237
+ registerAttribute(meta, 'match_regex', matchRegexValidator, {
238
+ checker: (config, typeDef, _) => {
239
+ if (typeDef.kind !== 'literal' || typeDef.value.kind !== 'string') {
240
+ return undefined;
241
+ }
242
+ const pattern = config.pattern;
243
+ const value = typeDef.value.value;
244
+ return (node, ctx) => {
245
+ try {
246
+ const regex = RegExp(pattern);
247
+ if (!regex.test(value)) {
248
+ const message = config.message ?? localize('mismatching-regex-pattern', pattern);
249
+ ctx.err.report(message, node, 2 /* core.ErrorSeverity.Warning */);
250
+ }
251
+ }
252
+ catch (e) {
253
+ ctx.logger.warn(`Invalid regular expression in "match_regex" mcdoc attribute: ${pattern}`);
229
254
  }
230
255
  };
231
256
  },
@@ -753,13 +753,8 @@ function resolveIndices(parallelIndices, symbolMap, symbolQuery, context) {
753
753
  }
754
754
  function simplifyUnion(typeDef, context) {
755
755
  let dynamicData = false;
756
- const filterCanonical = context.ctx.requireCanonical
757
- && typeDef.members.some(m => m.attributes?.some(a => a.name === 'canonical'));
758
- const validMembers = typeDef.members
756
+ let validMembers = typeDef.members
759
757
  .filter(member => {
760
- if (filterCanonical && !member.attributes?.some(a => a.name === 'canonical')) {
761
- return false;
762
- }
763
758
  let keep = true;
764
759
  handleAttributes(member.attributes, context.ctx, (handler, config) => {
765
760
  if (!keep || !handler.filterElement) {
@@ -771,6 +766,11 @@ function simplifyUnion(typeDef, context) {
771
766
  });
772
767
  return keep;
773
768
  });
769
+ const filterCanonical = context.ctx.requireCanonical
770
+ && validMembers.some(m => m.attributes?.some(a => a.name === 'canonical'));
771
+ if (filterCanonical) {
772
+ validMembers = typeDef.members.filter(member => member.attributes?.some(a => a.name === 'canonical'));
773
+ }
774
774
  if (validMembers.length === 1) {
775
775
  return simplify(validMembers[0], context);
776
776
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spyglassmc/mcdoc",
3
- "version": "0.3.30",
3
+ "version": "0.3.32",
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.26",
29
- "@spyglassmc/locales": "0.3.12"
28
+ "@spyglassmc/core": "0.4.28",
29
+ "@spyglassmc/locales": "0.3.14"
30
30
  }
31
31
  }