vscode-json-languageservice 4.2.0-next.2 → 4.2.1

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.
@@ -522,7 +522,7 @@ for (var schemaName in schemaContributions.schemas) {
522
522
  propertyObject['description'] = description;
523
523
  }
524
524
  else {
525
- console.log(property + ": localize('schema.json." + property + "', \"\")");
525
+ console.log("".concat(property, ": localize('schema.json.").concat(property, "', \"\")"));
526
526
  }
527
527
  }
528
528
  }
@@ -218,7 +218,7 @@ var JSONCompletion = /** @class */ (function () {
218
218
  if (propertySchema.suggestSortText !== undefined) {
219
219
  proposal.sortText = propertySchema.suggestSortText;
220
220
  }
221
- if (proposal.insertText && endsWith(proposal.insertText, "$1" + separatorAfter)) {
221
+ if (proposal.insertText && endsWith(proposal.insertText, "$1".concat(separatorAfter))) {
222
222
  proposal.command = {
223
223
  title: 'Suggest',
224
224
  command: 'editor.action.triggerSuggest'
@@ -243,7 +243,7 @@ var JSONCompletion = /** @class */ (function () {
243
243
  if (schemaPropertyNames_1.suggestSortText !== undefined) {
244
244
  proposal.sortText = schemaPropertyNames_1.suggestSortText;
245
245
  }
246
- if (proposal.insertText && endsWith(proposal.insertText, "$1" + separatorAfter)) {
246
+ if (proposal.insertText && endsWith(proposal.insertText, "$1".concat(separatorAfter))) {
247
247
  proposal.command = {
248
248
  title: 'Suggest',
249
249
  command: 'editor.action.triggerSuggest'
@@ -202,7 +202,7 @@ var JSONDocumentSymbols = /** @class */ (function () {
202
202
  if (name && name.trim()) {
203
203
  return name;
204
204
  }
205
- return "\"" + name + "\"";
205
+ return "\"".concat(name, "\"");
206
206
  };
207
207
  JSONDocumentSymbols.prototype.getDetail = function (node) {
208
208
  if (!node) {
@@ -262,10 +262,10 @@ var JSONDocumentSymbols = /** @class */ (function () {
262
262
  }
263
263
  var label;
264
264
  if (color.alpha === 1) {
265
- label = "#" + toTwoDigitHex(red256) + toTwoDigitHex(green256) + toTwoDigitHex(blue256);
265
+ label = "#".concat(toTwoDigitHex(red256)).concat(toTwoDigitHex(green256)).concat(toTwoDigitHex(blue256));
266
266
  }
267
267
  else {
268
- label = "#" + toTwoDigitHex(red256) + toTwoDigitHex(green256) + toTwoDigitHex(blue256) + toTwoDigitHex(Math.round(color.alpha * 255));
268
+ label = "#".concat(toTwoDigitHex(red256)).concat(toTwoDigitHex(green256)).concat(toTwoDigitHex(blue256)).concat(toTwoDigitHex(Math.round(color.alpha * 255)));
269
269
  }
270
270
  result.push({ label: label, textEdit: TextEdit.replace(range, JSON.stringify(label)) });
271
271
  return result;
@@ -86,7 +86,7 @@ var JSONHover = /** @class */ (function () {
86
86
  if (result.length > 0) {
87
87
  result += "\n\n";
88
88
  }
89
- result += "`" + toMarkdownCodeBlock(enumValue_1) + "`: " + markdownEnumValueDescription_1;
89
+ result += "`".concat(toMarkdownCodeBlock(enumValue_1), "`: ").concat(markdownEnumValueDescription_1);
90
90
  }
91
91
  return createHover([result]);
92
92
  }
@@ -13,7 +13,7 @@ export function findLinks(document, doc) {
13
13
  if (targetNode) {
14
14
  var targetPos = document.positionAt(targetNode.offset);
15
15
  links.push({
16
- target: document.uri + "#" + (targetPos.line + 1) + "," + (targetPos.character + 1),
16
+ target: "".concat(document.uri, "#").concat(targetPos.line + 1, ",").concat(targetPos.character + 1),
17
17
  range: createRange(document, node.valueNode)
18
18
  });
19
19
  }
@@ -59,7 +59,7 @@ var SchemaHandle = /** @class */ (function () {
59
59
  this.service = service;
60
60
  this.uri = uri;
61
61
  this.dependencies = new Set();
62
- this.anchors = new Map();
62
+ this.anchors = undefined;
63
63
  if (unresolvedSchemaContent) {
64
64
  this.unresolvedSchema = this.service.promise.resolve(new UnresolvedSchema(unresolvedSchemaContent));
65
65
  }
@@ -84,7 +84,7 @@ var SchemaHandle = /** @class */ (function () {
84
84
  this.resolvedSchema = undefined;
85
85
  this.unresolvedSchema = undefined;
86
86
  this.dependencies.clear();
87
- this.anchors.clear();
87
+ this.anchors = undefined;
88
88
  return hasChanges;
89
89
  };
90
90
  return SchemaHandle;
@@ -309,13 +309,11 @@ var JSONSchemaService = /** @class */ (function () {
309
309
  }
310
310
  }
311
311
  var contextService = this.contextService;
312
- var findSection = function (schema, path) {
313
- if (!path) {
314
- return schema;
315
- }
312
+ var findSectionByJSONPointer = function (schema, path) {
313
+ path = decodeURIComponent(path);
316
314
  var current = schema;
317
315
  if (path[0] === '/') {
318
- path = path.substr(1);
316
+ path = path.substring(1);
319
317
  }
320
318
  path.split('/').some(function (part) {
321
319
  part = part.replace(/~1/g, '/').replace(/~0/g, '~');
@@ -324,54 +322,39 @@ var JSONSchemaService = /** @class */ (function () {
324
322
  });
325
323
  return current;
326
324
  };
325
+ var findSchemaById = function (schema, handle, id) {
326
+ if (!handle.anchors) {
327
+ handle.anchors = collectAnchors(schema);
328
+ }
329
+ return handle.anchors.get(id);
330
+ };
327
331
  var merge = function (target, section) {
328
332
  for (var key in section) {
329
- if (section.hasOwnProperty(key) && !target.hasOwnProperty(key)) {
333
+ if (section.hasOwnProperty(key) && !target.hasOwnProperty(key) && key !== 'id' && key !== '$id') {
330
334
  target[key] = section[key];
331
335
  }
332
336
  }
333
337
  };
334
- var mergeByJsonPointer = function (target, sourceRoot, sourceURI, refSegment) {
335
- var path = refSegment ? decodeURIComponent(refSegment) : undefined;
336
- var section = findSection(sourceRoot, path);
338
+ var mergeRef = function (target, sourceRoot, sourceHandle, refSegment) {
339
+ var section;
340
+ if (refSegment === undefined || refSegment.length === 0) {
341
+ section = sourceRoot;
342
+ }
343
+ else if (refSegment.charAt(0) === '/') {
344
+ // A $ref to a JSON Pointer (i.e #/definitions/foo)
345
+ section = findSectionByJSONPointer(sourceRoot, refSegment);
346
+ }
347
+ else {
348
+ // A $ref to a sub-schema with an $id (i.e #hello)
349
+ section = findSchemaById(sourceRoot, sourceHandle, refSegment);
350
+ }
337
351
  if (section) {
338
352
  merge(target, section);
339
353
  }
340
354
  else {
341
- resolveErrors.push(localize('json.schema.invalidref', '$ref \'{0}\' in \'{1}\' can not be resolved.', path, sourceURI));
355
+ resolveErrors.push(localize('json.schema.invalidid', '$ref \'{0}\' in \'{1}\' can not be resolved.', refSegment, sourceHandle.uri));
342
356
  }
343
357
  };
344
- var isSubSchemaRef = function (refSegment) {
345
- // Check if the first character is not '/' to determine whether it's a sub schema reference or a JSON Pointer
346
- return !!refSegment && refSegment.charAt(0) !== '/';
347
- };
348
- var reconstructRefURI = function (uri, fragment, separator) {
349
- if (separator === void 0) { separator = '#'; }
350
- return normalizeId("" + uri + separator + fragment);
351
- };
352
- // To find which $refs point to which $ids we keep two maps:
353
- // pendingSubSchemas '$id' we expect to encounter (if they exist)
354
- // handle.anchors for the ones we have encountered
355
- var pendingSubSchemas = new Map();
356
- var tryMergeSubSchema = function (target, id, handle) {
357
- // Get the full URI for the current schema to avoid matching schema1#hello and schema2#hello to the same
358
- // reference by accident
359
- var fullId = reconstructRefURI(handle.uri, id);
360
- var resolved = handle.anchors.get(fullId);
361
- if (resolved) {
362
- merge(target, resolved);
363
- return true; // return success
364
- }
365
- // This subschema has not been resolved yet
366
- // Remember the target to merge later once resolved
367
- var pending = pendingSubSchemas.get(fullId);
368
- if (!pending) {
369
- pending = [];
370
- pendingSubSchemas.set(fullId, pending);
371
- }
372
- pending.push(target);
373
- return false; // return failure - merge didn't occur
374
- };
375
358
  var resolveExternalLink = function (node, uri, refSegment, parentHandle) {
376
359
  if (contextService && !/^[A-Za-z][A-Za-z0-9+\-.+]*:\/\/.*/.test(uri)) {
377
360
  uri = contextService.resolveRelativePath(uri, parentHandle.uri);
@@ -384,79 +367,13 @@ var JSONSchemaService = /** @class */ (function () {
384
367
  var loc = refSegment ? uri + '#' + refSegment : uri;
385
368
  resolveErrors.push(localize('json.schema.problemloadingref', 'Problems loading reference \'{0}\': {1}', loc, unresolvedSchema.errors[0]));
386
369
  }
387
- // A placeholder promise that might execute later a ref resolution for the newly resolved schema
388
- var externalLinkPromise = Promise.resolve(true);
389
- if (refSegment === undefined || !isSubSchemaRef(refSegment)) {
390
- // This is not a sub schema, merge the regular way
391
- mergeByJsonPointer(node, unresolvedSchema.schema, uri, refSegment);
392
- }
393
- else {
394
- // This is a reference to a subschema
395
- if (!tryMergeSubSchema(node, refSegment, referencedHandle)) {
396
- // We weren't able to merge currently so we'll try to resolve this schema first to obtain subschemas
397
- // that could be missed
398
- // to improve: it would be enough to find the nodes, no need to resolve the full schema
399
- externalLinkPromise = resolveRefs(unresolvedSchema.schema, unresolvedSchema.schema, referencedHandle);
400
- }
401
- }
402
- return externalLinkPromise.then(function () { return resolveRefs(node, unresolvedSchema.schema, referencedHandle); });
370
+ mergeRef(node, unresolvedSchema.schema, referencedHandle, refSegment);
371
+ return resolveRefs(node, unresolvedSchema.schema, referencedHandle);
403
372
  });
404
373
  };
405
374
  var resolveRefs = function (node, parentSchema, parentHandle) {
406
- if (!node || typeof node !== 'object') {
407
- return Promise.resolve(null);
408
- }
409
- var toWalk = [node];
410
- var seen = new Set();
411
375
  var openPromises = [];
412
- var collectEntries = function () {
413
- var entries = [];
414
- for (var _i = 0; _i < arguments.length; _i++) {
415
- entries[_i] = arguments[_i];
416
- }
417
- for (var _a = 0, entries_1 = entries; _a < entries_1.length; _a++) {
418
- var entry = entries_1[_a];
419
- if (typeof entry === 'object') {
420
- toWalk.push(entry);
421
- }
422
- }
423
- };
424
- var collectMapEntries = function () {
425
- var maps = [];
426
- for (var _i = 0; _i < arguments.length; _i++) {
427
- maps[_i] = arguments[_i];
428
- }
429
- for (var _a = 0, maps_1 = maps; _a < maps_1.length; _a++) {
430
- var map = maps_1[_a];
431
- if (typeof map === 'object') {
432
- for (var k in map) {
433
- var key = k;
434
- var entry = map[key];
435
- if (typeof entry === 'object') {
436
- toWalk.push(entry);
437
- }
438
- }
439
- }
440
- }
441
- };
442
- var collectArrayEntries = function () {
443
- var arrays = [];
444
- for (var _i = 0; _i < arguments.length; _i++) {
445
- arrays[_i] = arguments[_i];
446
- }
447
- for (var _a = 0, arrays_1 = arrays; _a < arrays_1.length; _a++) {
448
- var array = arrays_1[_a];
449
- if (Array.isArray(array)) {
450
- for (var _b = 0, array_1 = array; _b < array_1.length; _b++) {
451
- var entry = array_1[_b];
452
- if (typeof entry === 'object') {
453
- toWalk.push(entry);
454
- }
455
- }
456
- }
457
- }
458
- };
459
- var handleRef = function (next) {
376
+ _this.traverseNodes(node, function (next) {
460
377
  var seenRefs = new Set();
461
378
  while (next.$ref) {
462
379
  var ref = next.$ref;
@@ -471,67 +388,102 @@ var JSONSchemaService = /** @class */ (function () {
471
388
  // This is a reference inside the current schema
472
389
  if (!seenRefs.has(ref)) {
473
390
  var id = segments[1];
474
- if (id !== undefined && isSubSchemaRef(id)) { // A $ref to a sub-schema with an $id (i.e #hello)
475
- tryMergeSubSchema(next, id, handle);
476
- }
477
- else { // A $ref to a JSON Pointer (i.e #/definitions/foo)
478
- mergeByJsonPointer(next, parentSchema, parentHandle.uri, id); // can set next.$ref again, use seenRefs to avoid circle
479
- }
391
+ mergeRef(next, parentSchema, parentHandle, id);
480
392
  seenRefs.add(ref);
481
393
  }
482
394
  }
483
395
  }
484
- collectEntries(next.items, next.additionalItems, next.additionalProperties, next.not, next.contains, next.propertyNames, next.if, next.then, next.else);
485
- collectMapEntries(next.definitions, next.properties, next.patternProperties, next.dependencies);
486
- collectArrayEntries(next.anyOf, next.allOf, next.oneOf, next.items);
487
- };
488
- var handleId = function (next) {
489
- // TODO figure out should loops be preventse
396
+ });
397
+ return _this.promise.all(openPromises);
398
+ };
399
+ var collectAnchors = function (root) {
400
+ var result = new Map();
401
+ _this.traverseNodes(root, function (next) {
490
402
  var id = next.$id || next.id;
491
403
  if (typeof id === 'string' && id.charAt(0) === '#') {
492
- delete next.$id;
493
- delete next.id;
494
- // Use a blank separator, as the $id already has the '#'
495
- var fullId = reconstructRefURI(parentHandle.uri, id, '');
496
- var resolved = parentHandle.anchors.get(fullId);
497
- if (!resolved) {
498
- // it's resolved now
499
- parentHandle.anchors.set(fullId, next);
500
- }
501
- else if (resolved !== next) {
502
- // Duplicate may occur in recursive $refs, but as long as they are the same object
503
- // it's ok, otherwise report and error
404
+ // delete next.$id;
405
+ // delete next.id;
406
+ var anchor = id.substring(1);
407
+ if (result.has(anchor)) {
504
408
  resolveErrors.push(localize('json.schema.duplicateid', 'Duplicate id declaration: \'{0}\'', id));
505
409
  }
506
- // Resolve all pending requests and cleanup the queue list
507
- var pending = pendingSubSchemas.get(fullId);
508
- if (pending) {
509
- for (var _i = 0, pending_1 = pending; _i < pending_1.length; _i++) {
510
- var target = pending_1[_i];
511
- merge(target, next);
410
+ else {
411
+ result.set(anchor, next);
412
+ }
413
+ }
414
+ });
415
+ return result;
416
+ };
417
+ return resolveRefs(schema, schema, handle).then(function (_) {
418
+ return new ResolvedSchema(schema, resolveErrors);
419
+ });
420
+ };
421
+ JSONSchemaService.prototype.traverseNodes = function (root, handle) {
422
+ if (!root || typeof root !== 'object') {
423
+ return Promise.resolve(null);
424
+ }
425
+ var seen = new Set();
426
+ var collectEntries = function () {
427
+ var entries = [];
428
+ for (var _i = 0; _i < arguments.length; _i++) {
429
+ entries[_i] = arguments[_i];
430
+ }
431
+ for (var _a = 0, entries_1 = entries; _a < entries_1.length; _a++) {
432
+ var entry = entries_1[_a];
433
+ if (typeof entry === 'object') {
434
+ toWalk.push(entry);
435
+ }
436
+ }
437
+ };
438
+ var collectMapEntries = function () {
439
+ var maps = [];
440
+ for (var _i = 0; _i < arguments.length; _i++) {
441
+ maps[_i] = arguments[_i];
442
+ }
443
+ for (var _a = 0, maps_1 = maps; _a < maps_1.length; _a++) {
444
+ var map = maps_1[_a];
445
+ if (typeof map === 'object') {
446
+ for (var k in map) {
447
+ var key = k;
448
+ var entry = map[key];
449
+ if (typeof entry === 'object') {
450
+ toWalk.push(entry);
512
451
  }
513
- pendingSubSchemas.delete(fullId);
514
452
  }
515
453
  }
516
- };
517
- while (toWalk.length) {
518
- var next = toWalk.pop();
519
- if (seen.has(next)) {
520
- continue;
454
+ }
455
+ };
456
+ var collectArrayEntries = function () {
457
+ var arrays = [];
458
+ for (var _i = 0; _i < arguments.length; _i++) {
459
+ arrays[_i] = arguments[_i];
460
+ }
461
+ for (var _a = 0, arrays_1 = arrays; _a < arrays_1.length; _a++) {
462
+ var array = arrays_1[_a];
463
+ if (Array.isArray(array)) {
464
+ for (var _b = 0, array_1 = array; _b < array_1.length; _b++) {
465
+ var entry = array_1[_b];
466
+ if (typeof entry === 'object') {
467
+ toWalk.push(entry);
468
+ }
469
+ }
521
470
  }
522
- seen.add(next);
523
- handleId(next);
524
- handleRef(next);
525
471
  }
526
- return _this.promise.all(openPromises);
527
472
  };
528
- return resolveRefs(schema, schema, handle).then(function (_) {
529
- for (var unresolvedSubschemaId in pendingSubSchemas) {
530
- resolveErrors.push(localize('json.schema.idnotfound', 'Subschema with id \'{0}\' was not found', unresolvedSubschemaId));
473
+ var toWalk = [root];
474
+ var next = toWalk.pop();
475
+ while (next) {
476
+ if (!seen.has(next)) {
477
+ seen.add(next);
478
+ handle(next);
479
+ collectEntries(next.items, next.additionalItems, next.additionalProperties, next.not, next.contains, next.propertyNames, next.if, next.then, next.else);
480
+ collectMapEntries(next.definitions, next.properties, next.patternProperties, next.dependencies);
481
+ collectArrayEntries(next.anyOf, next.allOf, next.oneOf, next.items);
531
482
  }
532
- return new ResolvedSchema(schema, resolveErrors);
533
- });
483
+ next = toWalk.pop();
484
+ }
534
485
  };
486
+ ;
535
487
  JSONSchemaService.prototype.getSchemaFromProperty = function (resource, document) {
536
488
  var _a, _b;
537
489
  if (((_a = document.root) === null || _a === void 0 ? void 0 : _a.type) === 'object') {
@@ -624,7 +576,7 @@ var idCounter = 0;
624
576
  function normalizeId(id) {
625
577
  // remove trailing '#', normalize drive capitalization
626
578
  try {
627
- return URI.parse(id).toString();
579
+ return URI.parse(id).toString(true);
628
580
  }
629
581
  catch (e) {
630
582
  return id;
@@ -633,7 +585,7 @@ function normalizeId(id) {
633
585
  function normalizeResourceForMatching(resource) {
634
586
  // remove queries and fragments, normalize drive capitalization
635
587
  try {
636
- return URI.parse(resource).with({ fragment: null, query: null }).toString();
588
+ return URI.parse(resource).with({ fragment: null, query: null }).toString(true);
637
589
  }
638
590
  catch (e) {
639
591
  return resource;
@@ -58,8 +58,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
58
58
  resetSchema: function (uri) { return jsonSchemaService.onResourceChange(uri); },
59
59
  doValidation: jsonValidation.doValidation.bind(jsonValidation),
60
60
  getLanguageStatus: jsonValidation.getLanguageStatus.bind(jsonValidation),
61
- parseJSONDocument: function (document) { return jsonParser_1.parse(document, { collectComments: true }); },
62
- newJSONDocument: function (root, diagnostics) { return jsonParser_1.newJSONDocument(root, diagnostics); },
61
+ parseJSONDocument: function (document) { return (0, jsonParser_1.parse)(document, { collectComments: true }); },
62
+ newJSONDocument: function (root, diagnostics) { return (0, jsonParser_1.newJSONDocument)(root, diagnostics); },
63
63
  getMatchingSchemas: jsonSchemaService.getMatchingSchemas.bind(jsonSchemaService),
64
64
  doResolve: jsonCompletion.doResolve.bind(jsonCompletion),
65
65
  doComplete: jsonCompletion.doComplete.bind(jsonCompletion),
@@ -80,7 +80,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
80
80
  range = { offset: offset, length: length };
81
81
  }
82
82
  var options = { tabSize: o ? o.tabSize : 4, insertSpaces: (o === null || o === void 0 ? void 0 : o.insertSpaces) === true, insertFinalNewline: (o === null || o === void 0 ? void 0 : o.insertFinalNewline) === true, eol: '\n' };
83
- return jsonc_parser_1.format(d.getText(), range, options).map(function (e) {
83
+ return (0, jsonc_parser_1.format)(d.getText(), range, options).map(function (e) {
84
84
  return jsonLanguageTypes_1.TextEdit.replace(jsonLanguageTypes_1.Range.create(d.positionAt(e.offset), d.positionAt(e.offset + e.length)), e.content);
85
85
  });
86
86
  }
@@ -166,7 +166,7 @@ var __extends = (this && this.__extends) || (function () {
166
166
  }(ASTNodeImpl));
167
167
  exports.ObjectASTNodeImpl = ObjectASTNodeImpl;
168
168
  function asSchema(schema) {
169
- if (objects_1.isBoolean(schema)) {
169
+ if ((0, objects_1.isBoolean)(schema)) {
170
170
  return schema ? {} : { "not": {} };
171
171
  }
172
172
  return schema;
@@ -502,7 +502,7 @@ var __extends = (this && this.__extends) || (function () {
502
502
  var enumValueMatch = false;
503
503
  for (var _d = 0, _e = schema.enum; _d < _e.length; _d++) {
504
504
  var e = _e[_d];
505
- if (objects_1.equals(val, e)) {
505
+ if ((0, objects_1.equals)(val, e)) {
506
506
  enumValueMatch = true;
507
507
  break;
508
508
  }
@@ -517,9 +517,9 @@ var __extends = (this && this.__extends) || (function () {
517
517
  });
518
518
  }
519
519
  }
520
- if (objects_1.isDefined(schema.const)) {
520
+ if ((0, objects_1.isDefined)(schema.const)) {
521
521
  var val = getNodeValue(node);
522
- if (!objects_1.equals(val, schema.const)) {
522
+ if (!(0, objects_1.equals)(val, schema.const)) {
523
523
  validationResult.problems.push({
524
524
  location: { offset: node.offset, length: node.length },
525
525
  code: jsonLanguageTypes_1.ErrorCode.EnumValueMismatch,
@@ -552,7 +552,7 @@ var __extends = (this && this.__extends) || (function () {
552
552
  };
553
553
  }
554
554
  ;
555
- if (objects_1.isNumber(schema.multipleOf)) {
555
+ if ((0, objects_1.isNumber)(schema.multipleOf)) {
556
556
  var remainder = -1;
557
557
  if (Number.isInteger(schema.multipleOf)) {
558
558
  remainder = val % schema.multipleOf;
@@ -579,43 +579,43 @@ var __extends = (this && this.__extends) || (function () {
579
579
  }
580
580
  }
581
581
  function getExclusiveLimit(limit, exclusive) {
582
- if (objects_1.isNumber(exclusive)) {
582
+ if ((0, objects_1.isNumber)(exclusive)) {
583
583
  return exclusive;
584
584
  }
585
- if (objects_1.isBoolean(exclusive) && exclusive) {
585
+ if ((0, objects_1.isBoolean)(exclusive) && exclusive) {
586
586
  return limit;
587
587
  }
588
588
  return undefined;
589
589
  }
590
590
  function getLimit(limit, exclusive) {
591
- if (!objects_1.isBoolean(exclusive) || !exclusive) {
591
+ if (!(0, objects_1.isBoolean)(exclusive) || !exclusive) {
592
592
  return limit;
593
593
  }
594
594
  return undefined;
595
595
  }
596
596
  var exclusiveMinimum = getExclusiveLimit(schema.minimum, schema.exclusiveMinimum);
597
- if (objects_1.isNumber(exclusiveMinimum) && val <= exclusiveMinimum) {
597
+ if ((0, objects_1.isNumber)(exclusiveMinimum) && val <= exclusiveMinimum) {
598
598
  validationResult.problems.push({
599
599
  location: { offset: node.offset, length: node.length },
600
600
  message: localize('exclusiveMinimumWarning', 'Value is below the exclusive minimum of {0}.', exclusiveMinimum)
601
601
  });
602
602
  }
603
603
  var exclusiveMaximum = getExclusiveLimit(schema.maximum, schema.exclusiveMaximum);
604
- if (objects_1.isNumber(exclusiveMaximum) && val >= exclusiveMaximum) {
604
+ if ((0, objects_1.isNumber)(exclusiveMaximum) && val >= exclusiveMaximum) {
605
605
  validationResult.problems.push({
606
606
  location: { offset: node.offset, length: node.length },
607
607
  message: localize('exclusiveMaximumWarning', 'Value is above the exclusive maximum of {0}.', exclusiveMaximum)
608
608
  });
609
609
  }
610
610
  var minimum = getLimit(schema.minimum, schema.exclusiveMinimum);
611
- if (objects_1.isNumber(minimum) && val < minimum) {
611
+ if ((0, objects_1.isNumber)(minimum) && val < minimum) {
612
612
  validationResult.problems.push({
613
613
  location: { offset: node.offset, length: node.length },
614
614
  message: localize('minimumWarning', 'Value is below the minimum of {0}.', minimum)
615
615
  });
616
616
  }
617
617
  var maximum = getLimit(schema.maximum, schema.exclusiveMaximum);
618
- if (objects_1.isNumber(maximum) && val > maximum) {
618
+ if ((0, objects_1.isNumber)(maximum) && val > maximum) {
619
619
  validationResult.problems.push({
620
620
  location: { offset: node.offset, length: node.length },
621
621
  message: localize('maximumWarning', 'Value is above the maximum of {0}.', maximum)
@@ -623,20 +623,20 @@ var __extends = (this && this.__extends) || (function () {
623
623
  }
624
624
  }
625
625
  function _validateStringNode(node, schema, validationResult, matchingSchemas) {
626
- if (objects_1.isNumber(schema.minLength) && node.value.length < schema.minLength) {
626
+ if ((0, objects_1.isNumber)(schema.minLength) && node.value.length < schema.minLength) {
627
627
  validationResult.problems.push({
628
628
  location: { offset: node.offset, length: node.length },
629
629
  message: localize('minLengthWarning', 'String is shorter than the minimum length of {0}.', schema.minLength)
630
630
  });
631
631
  }
632
- if (objects_1.isNumber(schema.maxLength) && node.value.length > schema.maxLength) {
632
+ if ((0, objects_1.isNumber)(schema.maxLength) && node.value.length > schema.maxLength) {
633
633
  validationResult.problems.push({
634
634
  location: { offset: node.offset, length: node.length },
635
635
  message: localize('maxLengthWarning', 'String is longer than the maximum length of {0}.', schema.maxLength)
636
636
  });
637
637
  }
638
- if (objects_1.isString(schema.pattern)) {
639
- var regex = strings_1.extendedRegExp(schema.pattern);
638
+ if ((0, objects_1.isString)(schema.pattern)) {
639
+ var regex = (0, strings_1.extendedRegExp)(schema.pattern);
640
640
  if (!(regex === null || regex === void 0 ? void 0 : regex.test(node.value))) {
641
641
  validationResult.problems.push({
642
642
  location: { offset: node.offset, length: node.length },
@@ -746,13 +746,13 @@ var __extends = (this && this.__extends) || (function () {
746
746
  });
747
747
  }
748
748
  }
749
- if (objects_1.isNumber(schema.minItems) && node.items.length < schema.minItems) {
749
+ if ((0, objects_1.isNumber)(schema.minItems) && node.items.length < schema.minItems) {
750
750
  validationResult.problems.push({
751
751
  location: { offset: node.offset, length: node.length },
752
752
  message: localize('minItemsWarning', 'Array has too few items. Expected {0} or more.', schema.minItems)
753
753
  });
754
754
  }
755
- if (objects_1.isNumber(schema.maxItems) && node.items.length > schema.maxItems) {
755
+ if ((0, objects_1.isNumber)(schema.maxItems) && node.items.length > schema.maxItems) {
756
756
  validationResult.problems.push({
757
757
  location: { offset: node.offset, length: node.length },
758
758
  message: localize('maxItemsWarning', 'Array has too many items. Expected {0} or fewer.', schema.maxItems)
@@ -807,7 +807,7 @@ var __extends = (this && this.__extends) || (function () {
807
807
  var propertySchema = schema.properties[propertyName];
808
808
  var child = seenKeys[propertyName];
809
809
  if (child) {
810
- if (objects_1.isBoolean(propertySchema)) {
810
+ if ((0, objects_1.isBoolean)(propertySchema)) {
811
811
  if (!propertySchema) {
812
812
  var propertyNode = child.parent;
813
813
  validationResult.problems.push({
@@ -831,7 +831,7 @@ var __extends = (this && this.__extends) || (function () {
831
831
  if (schema.patternProperties) {
832
832
  for (var _f = 0, _g = Object.keys(schema.patternProperties); _f < _g.length; _f++) {
833
833
  var propertyPattern = _g[_f];
834
- var regex = strings_1.extendedRegExp(propertyPattern);
834
+ var regex = (0, strings_1.extendedRegExp)(propertyPattern);
835
835
  for (var _h = 0, _j = unprocessedProperties.slice(0); _h < _j.length; _h++) {
836
836
  var propertyName = _j[_h];
837
837
  if (regex === null || regex === void 0 ? void 0 : regex.test(propertyName)) {
@@ -839,7 +839,7 @@ var __extends = (this && this.__extends) || (function () {
839
839
  var child = seenKeys[propertyName];
840
840
  if (child) {
841
841
  var propertySchema = schema.patternProperties[propertyPattern];
842
- if (objects_1.isBoolean(propertySchema)) {
842
+ if ((0, objects_1.isBoolean)(propertySchema)) {
843
843
  if (!propertySchema) {
844
844
  var propertyNode = child.parent;
845
845
  validationResult.problems.push({
@@ -888,7 +888,7 @@ var __extends = (this && this.__extends) || (function () {
888
888
  }
889
889
  }
890
890
  }
891
- if (objects_1.isNumber(schema.maxProperties)) {
891
+ if ((0, objects_1.isNumber)(schema.maxProperties)) {
892
892
  if (node.properties.length > schema.maxProperties) {
893
893
  validationResult.problems.push({
894
894
  location: { offset: node.offset, length: node.length },
@@ -896,7 +896,7 @@ var __extends = (this && this.__extends) || (function () {
896
896
  });
897
897
  }
898
898
  }
899
- if (objects_1.isNumber(schema.minProperties)) {
899
+ if ((0, objects_1.isNumber)(schema.minProperties)) {
900
900
  if (node.properties.length < schema.minProperties) {
901
901
  validationResult.problems.push({
902
902
  location: { offset: node.offset, length: node.length },
@@ -1192,7 +1192,7 @@ var __extends = (this && this.__extends) || (function () {
1192
1192
  var tokenValue = scanner.getTokenValue();
1193
1193
  try {
1194
1194
  var numberValue = JSON.parse(tokenValue);
1195
- if (!objects_1.isNumber(numberValue)) {
1195
+ if (!(0, objects_1.isNumber)(numberValue)) {
1196
1196
  return _error(localize('InvalidNumberFormat', 'Invalid number format.'), jsonLanguageTypes_1.ErrorCode.Undefined, node);
1197
1197
  }
1198
1198
  node.value = numberValue;
@@ -534,7 +534,7 @@
534
534
  propertyObject['description'] = description;
535
535
  }
536
536
  else {
537
- console.log(property + ": localize('schema.json." + property + "', \"\")");
537
+ console.log("".concat(property, ": localize('schema.json.").concat(property, "', \"\")"));
538
538
  }
539
539
  }
540
540
  }
@@ -230,7 +230,7 @@
230
230
  if (propertySchema.suggestSortText !== undefined) {
231
231
  proposal.sortText = propertySchema.suggestSortText;
232
232
  }
233
- if (proposal.insertText && strings_1.endsWith(proposal.insertText, "$1" + separatorAfter)) {
233
+ if (proposal.insertText && (0, strings_1.endsWith)(proposal.insertText, "$1".concat(separatorAfter))) {
234
234
  proposal.command = {
235
235
  title: 'Suggest',
236
236
  command: 'editor.action.triggerSuggest'
@@ -255,7 +255,7 @@
255
255
  if (schemaPropertyNames_1.suggestSortText !== undefined) {
256
256
  proposal.sortText = schemaPropertyNames_1.suggestSortText;
257
257
  }
258
- if (proposal.insertText && strings_1.endsWith(proposal.insertText, "$1" + separatorAfter)) {
258
+ if (proposal.insertText && (0, strings_1.endsWith)(proposal.insertText, "$1".concat(separatorAfter))) {
259
259
  proposal.command = {
260
260
  title: 'Suggest',
261
261
  command: 'editor.action.triggerSuggest'
@@ -451,7 +451,7 @@
451
451
  if (s.schema.patternProperties && !propertyMatched) {
452
452
  for (var _a = 0, _b = Object.keys(s.schema.patternProperties); _a < _b.length; _a++) {
453
453
  var pattern = _b[_a];
454
- var regex = strings_1.extendedRegExp(pattern);
454
+ var regex = (0, strings_1.extendedRegExp)(pattern);
455
455
  if (regex === null || regex === void 0 ? void 0 : regex.test(parentKey)) {
456
456
  propertyMatched = true;
457
457
  var propertySchema = s.schema.patternProperties[pattern];
@@ -527,7 +527,7 @@
527
527
  var _this = this;
528
528
  if (arrayDepth === void 0) { arrayDepth = 0; }
529
529
  var hasProposals = false;
530
- if (objects_1.isDefined(schema.default)) {
530
+ if ((0, objects_1.isDefined)(schema.default)) {
531
531
  var type = schema.type;
532
532
  var value = schema.default;
533
533
  for (var i = arrayDepth; i > 0; i--) {
@@ -567,7 +567,7 @@
567
567
  var label = s.label;
568
568
  var insertText;
569
569
  var filterText;
570
- if (objects_1.isDefined(value)) {
570
+ if ((0, objects_1.isDefined)(value)) {
571
571
  var type_1 = schema.type;
572
572
  for (var i = arrayDepth; i > 0; i--) {
573
573
  value = [value];
@@ -608,7 +608,7 @@
608
608
  }
609
609
  };
610
610
  JSONCompletion.prototype.addEnumValueCompletions = function (schema, separatorAfter, collector) {
611
- if (objects_1.isDefined(schema.const)) {
611
+ if ((0, objects_1.isDefined)(schema.const)) {
612
612
  collector.add({
613
613
  kind: this.getSuggestionKind(schema.type),
614
614
  label: this.getLabelForValue(schema.const),
@@ -638,7 +638,7 @@
638
638
  }
639
639
  };
640
640
  JSONCompletion.prototype.collectTypes = function (schema, types) {
641
- if (Array.isArray(schema.enum) || objects_1.isDefined(schema.const)) {
641
+ if (Array.isArray(schema.enum) || (0, objects_1.isDefined)(schema.const)) {
642
642
  return;
643
643
  }
644
644
  var type = schema.type;
@@ -735,7 +735,7 @@
735
735
  }
736
736
  return JSON.stringify(value);
737
737
  };
738
- return json_1.stringifyObject(value, '', replacer) + separatorAfter;
738
+ return (0, json_1.stringifyObject)(value, '', replacer) + separatorAfter;
739
739
  };
740
740
  JSONCompletion.prototype.getInsertTextForGuessedValue = function (value, separatorAfter) {
741
741
  switch (typeof value) {
@@ -804,7 +804,7 @@
804
804
  if (Array.isArray(propertySchema.defaultSnippets)) {
805
805
  if (propertySchema.defaultSnippets.length === 1) {
806
806
  var body = propertySchema.defaultSnippets[0].body;
807
- if (objects_1.isDefined(body)) {
807
+ if ((0, objects_1.isDefined)(body)) {
808
808
  value = this.getInsertTextForSnippetValue(body, '');
809
809
  }
810
810
  }
@@ -816,7 +816,7 @@
816
816
  }
817
817
  nValueProposals += propertySchema.enum.length;
818
818
  }
819
- if (objects_1.isDefined(propertySchema.default)) {
819
+ if ((0, objects_1.isDefined)(propertySchema.default)) {
820
820
  if (!value) {
821
821
  value = this.getInsertTextForGuessedValue(propertySchema.default, '');
822
822
  }
@@ -928,14 +928,14 @@
928
928
  return undefined;
929
929
  };
930
930
  JSONCompletion.prototype.doesSupportMarkdown = function () {
931
- if (!objects_1.isDefined(this.supportsMarkdown)) {
931
+ if (!(0, objects_1.isDefined)(this.supportsMarkdown)) {
932
932
  var completion = this.clientCapabilities.textDocument && this.clientCapabilities.textDocument.completion;
933
933
  this.supportsMarkdown = completion && completion.completionItem && Array.isArray(completion.completionItem.documentationFormat) && completion.completionItem.documentationFormat.indexOf(jsonLanguageTypes_1.MarkupKind.Markdown) !== -1;
934
934
  }
935
935
  return this.supportsMarkdown;
936
936
  };
937
937
  JSONCompletion.prototype.doesSupportsCommitCharacters = function () {
938
- if (!objects_1.isDefined(this.supportsCommitCharacters)) {
938
+ if (!(0, objects_1.isDefined)(this.supportsCommitCharacters)) {
939
939
  var completion = this.clientCapabilities.textDocument && this.clientCapabilities.textDocument.completion;
940
940
  this.supportsCommitCharacters = completion && completion.completionItem && !!completion.completionItem.commitCharactersSupport;
941
941
  }
@@ -214,7 +214,7 @@
214
214
  if (name && name.trim()) {
215
215
  return name;
216
216
  }
217
- return "\"" + name + "\"";
217
+ return "\"".concat(name, "\"");
218
218
  };
219
219
  JSONDocumentSymbols.prototype.getDetail = function (node) {
220
220
  if (!node) {
@@ -245,7 +245,7 @@
245
245
  if (!s.inverted && s.schema && (s.schema.format === 'color' || s.schema.format === 'color-hex') && s.node && s.node.type === 'string') {
246
246
  var nodeId = String(s.node.offset);
247
247
  if (!visitedNode[nodeId]) {
248
- var color = colors_1.colorFromHex(Parser.getNodeValue(s.node));
248
+ var color = (0, colors_1.colorFromHex)(Parser.getNodeValue(s.node));
249
249
  if (color) {
250
250
  var range = getRange(document, s.node);
251
251
  result.push({ color: color, range: range });
@@ -274,10 +274,10 @@
274
274
  }
275
275
  var label;
276
276
  if (color.alpha === 1) {
277
- label = "#" + toTwoDigitHex(red256) + toTwoDigitHex(green256) + toTwoDigitHex(blue256);
277
+ label = "#".concat(toTwoDigitHex(red256)).concat(toTwoDigitHex(green256)).concat(toTwoDigitHex(blue256));
278
278
  }
279
279
  else {
280
- label = "#" + toTwoDigitHex(red256) + toTwoDigitHex(green256) + toTwoDigitHex(blue256) + toTwoDigitHex(Math.round(color.alpha * 255));
280
+ label = "#".concat(toTwoDigitHex(red256)).concat(toTwoDigitHex(green256)).concat(toTwoDigitHex(blue256)).concat(toTwoDigitHex(Math.round(color.alpha * 255)));
281
281
  }
282
282
  result.push({ label: label, textEdit: jsonLanguageTypes_1.TextEdit.replace(range, JSON.stringify(label)) });
283
283
  return result;
@@ -21,7 +21,7 @@
21
21
  var nestingLevels = [];
22
22
  var stack = [];
23
23
  var prevStart = -1;
24
- var scanner = jsonc_parser_1.createScanner(document.getText(), false);
24
+ var scanner = (0, jsonc_parser_1.createScanner)(document.getText(), false);
25
25
  var token = scanner.scan();
26
26
  function addRange(range) {
27
27
  ranges.push(range);
@@ -98,7 +98,7 @@
98
98
  if (result.length > 0) {
99
99
  result += "\n\n";
100
100
  }
101
- result += "`" + toMarkdownCodeBlock(enumValue_1) + "`: " + markdownEnumValueDescription_1;
101
+ result += "`".concat(toMarkdownCodeBlock(enumValue_1), "`: ").concat(markdownEnumValueDescription_1);
102
102
  }
103
103
  return createHover([result]);
104
104
  }
@@ -25,7 +25,7 @@
25
25
  if (targetNode) {
26
26
  var targetPos = document.positionAt(targetNode.offset);
27
27
  links.push({
28
- target: document.uri + "#" + (targetPos.line + 1) + "," + (targetPos.character + 1),
28
+ target: "".concat(document.uri, "#").concat(targetPos.line + 1, ",").concat(targetPos.character + 1),
29
29
  range: createRange(document, node.valueNode)
30
30
  });
31
31
  }
@@ -38,7 +38,7 @@
38
38
  patternString = patternString.substring(1);
39
39
  }
40
40
  this.globWrappers.push({
41
- regexp: glob_1.createRegex('**/' + patternString, { extended: true, globstar: true }),
41
+ regexp: (0, glob_1.createRegex)('**/' + patternString, { extended: true, globstar: true }),
42
42
  include: include,
43
43
  });
44
44
  }
@@ -71,7 +71,7 @@
71
71
  this.service = service;
72
72
  this.uri = uri;
73
73
  this.dependencies = new Set();
74
- this.anchors = new Map();
74
+ this.anchors = undefined;
75
75
  if (unresolvedSchemaContent) {
76
76
  this.unresolvedSchema = this.service.promise.resolve(new UnresolvedSchema(unresolvedSchemaContent));
77
77
  }
@@ -96,7 +96,7 @@
96
96
  this.resolvedSchema = undefined;
97
97
  this.unresolvedSchema = undefined;
98
98
  this.dependencies.clear();
99
- this.anchors.clear();
99
+ this.anchors = undefined;
100
100
  return hasChanges;
101
101
  };
102
102
  return SchemaHandle;
@@ -321,13 +321,11 @@
321
321
  }
322
322
  }
323
323
  var contextService = this.contextService;
324
- var findSection = function (schema, path) {
325
- if (!path) {
326
- return schema;
327
- }
324
+ var findSectionByJSONPointer = function (schema, path) {
325
+ path = decodeURIComponent(path);
328
326
  var current = schema;
329
327
  if (path[0] === '/') {
330
- path = path.substr(1);
328
+ path = path.substring(1);
331
329
  }
332
330
  path.split('/').some(function (part) {
333
331
  part = part.replace(/~1/g, '/').replace(/~0/g, '~');
@@ -336,54 +334,39 @@
336
334
  });
337
335
  return current;
338
336
  };
337
+ var findSchemaById = function (schema, handle, id) {
338
+ if (!handle.anchors) {
339
+ handle.anchors = collectAnchors(schema);
340
+ }
341
+ return handle.anchors.get(id);
342
+ };
339
343
  var merge = function (target, section) {
340
344
  for (var key in section) {
341
- if (section.hasOwnProperty(key) && !target.hasOwnProperty(key)) {
345
+ if (section.hasOwnProperty(key) && !target.hasOwnProperty(key) && key !== 'id' && key !== '$id') {
342
346
  target[key] = section[key];
343
347
  }
344
348
  }
345
349
  };
346
- var mergeByJsonPointer = function (target, sourceRoot, sourceURI, refSegment) {
347
- var path = refSegment ? decodeURIComponent(refSegment) : undefined;
348
- var section = findSection(sourceRoot, path);
350
+ var mergeRef = function (target, sourceRoot, sourceHandle, refSegment) {
351
+ var section;
352
+ if (refSegment === undefined || refSegment.length === 0) {
353
+ section = sourceRoot;
354
+ }
355
+ else if (refSegment.charAt(0) === '/') {
356
+ // A $ref to a JSON Pointer (i.e #/definitions/foo)
357
+ section = findSectionByJSONPointer(sourceRoot, refSegment);
358
+ }
359
+ else {
360
+ // A $ref to a sub-schema with an $id (i.e #hello)
361
+ section = findSchemaById(sourceRoot, sourceHandle, refSegment);
362
+ }
349
363
  if (section) {
350
364
  merge(target, section);
351
365
  }
352
366
  else {
353
- resolveErrors.push(localize('json.schema.invalidref', '$ref \'{0}\' in \'{1}\' can not be resolved.', path, sourceURI));
367
+ resolveErrors.push(localize('json.schema.invalidid', '$ref \'{0}\' in \'{1}\' can not be resolved.', refSegment, sourceHandle.uri));
354
368
  }
355
369
  };
356
- var isSubSchemaRef = function (refSegment) {
357
- // Check if the first character is not '/' to determine whether it's a sub schema reference or a JSON Pointer
358
- return !!refSegment && refSegment.charAt(0) !== '/';
359
- };
360
- var reconstructRefURI = function (uri, fragment, separator) {
361
- if (separator === void 0) { separator = '#'; }
362
- return normalizeId("" + uri + separator + fragment);
363
- };
364
- // To find which $refs point to which $ids we keep two maps:
365
- // pendingSubSchemas '$id' we expect to encounter (if they exist)
366
- // handle.anchors for the ones we have encountered
367
- var pendingSubSchemas = new Map();
368
- var tryMergeSubSchema = function (target, id, handle) {
369
- // Get the full URI for the current schema to avoid matching schema1#hello and schema2#hello to the same
370
- // reference by accident
371
- var fullId = reconstructRefURI(handle.uri, id);
372
- var resolved = handle.anchors.get(fullId);
373
- if (resolved) {
374
- merge(target, resolved);
375
- return true; // return success
376
- }
377
- // This subschema has not been resolved yet
378
- // Remember the target to merge later once resolved
379
- var pending = pendingSubSchemas.get(fullId);
380
- if (!pending) {
381
- pending = [];
382
- pendingSubSchemas.set(fullId, pending);
383
- }
384
- pending.push(target);
385
- return false; // return failure - merge didn't occur
386
- };
387
370
  var resolveExternalLink = function (node, uri, refSegment, parentHandle) {
388
371
  if (contextService && !/^[A-Za-z][A-Za-z0-9+\-.+]*:\/\/.*/.test(uri)) {
389
372
  uri = contextService.resolveRelativePath(uri, parentHandle.uri);
@@ -396,79 +379,13 @@
396
379
  var loc = refSegment ? uri + '#' + refSegment : uri;
397
380
  resolveErrors.push(localize('json.schema.problemloadingref', 'Problems loading reference \'{0}\': {1}', loc, unresolvedSchema.errors[0]));
398
381
  }
399
- // A placeholder promise that might execute later a ref resolution for the newly resolved schema
400
- var externalLinkPromise = Promise.resolve(true);
401
- if (refSegment === undefined || !isSubSchemaRef(refSegment)) {
402
- // This is not a sub schema, merge the regular way
403
- mergeByJsonPointer(node, unresolvedSchema.schema, uri, refSegment);
404
- }
405
- else {
406
- // This is a reference to a subschema
407
- if (!tryMergeSubSchema(node, refSegment, referencedHandle)) {
408
- // We weren't able to merge currently so we'll try to resolve this schema first to obtain subschemas
409
- // that could be missed
410
- // to improve: it would be enough to find the nodes, no need to resolve the full schema
411
- externalLinkPromise = resolveRefs(unresolvedSchema.schema, unresolvedSchema.schema, referencedHandle);
412
- }
413
- }
414
- return externalLinkPromise.then(function () { return resolveRefs(node, unresolvedSchema.schema, referencedHandle); });
382
+ mergeRef(node, unresolvedSchema.schema, referencedHandle, refSegment);
383
+ return resolveRefs(node, unresolvedSchema.schema, referencedHandle);
415
384
  });
416
385
  };
417
386
  var resolveRefs = function (node, parentSchema, parentHandle) {
418
- if (!node || typeof node !== 'object') {
419
- return Promise.resolve(null);
420
- }
421
- var toWalk = [node];
422
- var seen = new Set();
423
387
  var openPromises = [];
424
- var collectEntries = function () {
425
- var entries = [];
426
- for (var _i = 0; _i < arguments.length; _i++) {
427
- entries[_i] = arguments[_i];
428
- }
429
- for (var _a = 0, entries_1 = entries; _a < entries_1.length; _a++) {
430
- var entry = entries_1[_a];
431
- if (typeof entry === 'object') {
432
- toWalk.push(entry);
433
- }
434
- }
435
- };
436
- var collectMapEntries = function () {
437
- var maps = [];
438
- for (var _i = 0; _i < arguments.length; _i++) {
439
- maps[_i] = arguments[_i];
440
- }
441
- for (var _a = 0, maps_1 = maps; _a < maps_1.length; _a++) {
442
- var map = maps_1[_a];
443
- if (typeof map === 'object') {
444
- for (var k in map) {
445
- var key = k;
446
- var entry = map[key];
447
- if (typeof entry === 'object') {
448
- toWalk.push(entry);
449
- }
450
- }
451
- }
452
- }
453
- };
454
- var collectArrayEntries = function () {
455
- var arrays = [];
456
- for (var _i = 0; _i < arguments.length; _i++) {
457
- arrays[_i] = arguments[_i];
458
- }
459
- for (var _a = 0, arrays_1 = arrays; _a < arrays_1.length; _a++) {
460
- var array = arrays_1[_a];
461
- if (Array.isArray(array)) {
462
- for (var _b = 0, array_1 = array; _b < array_1.length; _b++) {
463
- var entry = array_1[_b];
464
- if (typeof entry === 'object') {
465
- toWalk.push(entry);
466
- }
467
- }
468
- }
469
- }
470
- };
471
- var handleRef = function (next) {
388
+ _this.traverseNodes(node, function (next) {
472
389
  var seenRefs = new Set();
473
390
  while (next.$ref) {
474
391
  var ref = next.$ref;
@@ -483,67 +400,102 @@
483
400
  // This is a reference inside the current schema
484
401
  if (!seenRefs.has(ref)) {
485
402
  var id = segments[1];
486
- if (id !== undefined && isSubSchemaRef(id)) { // A $ref to a sub-schema with an $id (i.e #hello)
487
- tryMergeSubSchema(next, id, handle);
488
- }
489
- else { // A $ref to a JSON Pointer (i.e #/definitions/foo)
490
- mergeByJsonPointer(next, parentSchema, parentHandle.uri, id); // can set next.$ref again, use seenRefs to avoid circle
491
- }
403
+ mergeRef(next, parentSchema, parentHandle, id);
492
404
  seenRefs.add(ref);
493
405
  }
494
406
  }
495
407
  }
496
- collectEntries(next.items, next.additionalItems, next.additionalProperties, next.not, next.contains, next.propertyNames, next.if, next.then, next.else);
497
- collectMapEntries(next.definitions, next.properties, next.patternProperties, next.dependencies);
498
- collectArrayEntries(next.anyOf, next.allOf, next.oneOf, next.items);
499
- };
500
- var handleId = function (next) {
501
- // TODO figure out should loops be preventse
408
+ });
409
+ return _this.promise.all(openPromises);
410
+ };
411
+ var collectAnchors = function (root) {
412
+ var result = new Map();
413
+ _this.traverseNodes(root, function (next) {
502
414
  var id = next.$id || next.id;
503
415
  if (typeof id === 'string' && id.charAt(0) === '#') {
504
- delete next.$id;
505
- delete next.id;
506
- // Use a blank separator, as the $id already has the '#'
507
- var fullId = reconstructRefURI(parentHandle.uri, id, '');
508
- var resolved = parentHandle.anchors.get(fullId);
509
- if (!resolved) {
510
- // it's resolved now
511
- parentHandle.anchors.set(fullId, next);
512
- }
513
- else if (resolved !== next) {
514
- // Duplicate may occur in recursive $refs, but as long as they are the same object
515
- // it's ok, otherwise report and error
416
+ // delete next.$id;
417
+ // delete next.id;
418
+ var anchor = id.substring(1);
419
+ if (result.has(anchor)) {
516
420
  resolveErrors.push(localize('json.schema.duplicateid', 'Duplicate id declaration: \'{0}\'', id));
517
421
  }
518
- // Resolve all pending requests and cleanup the queue list
519
- var pending = pendingSubSchemas.get(fullId);
520
- if (pending) {
521
- for (var _i = 0, pending_1 = pending; _i < pending_1.length; _i++) {
522
- var target = pending_1[_i];
523
- merge(target, next);
422
+ else {
423
+ result.set(anchor, next);
424
+ }
425
+ }
426
+ });
427
+ return result;
428
+ };
429
+ return resolveRefs(schema, schema, handle).then(function (_) {
430
+ return new ResolvedSchema(schema, resolveErrors);
431
+ });
432
+ };
433
+ JSONSchemaService.prototype.traverseNodes = function (root, handle) {
434
+ if (!root || typeof root !== 'object') {
435
+ return Promise.resolve(null);
436
+ }
437
+ var seen = new Set();
438
+ var collectEntries = function () {
439
+ var entries = [];
440
+ for (var _i = 0; _i < arguments.length; _i++) {
441
+ entries[_i] = arguments[_i];
442
+ }
443
+ for (var _a = 0, entries_1 = entries; _a < entries_1.length; _a++) {
444
+ var entry = entries_1[_a];
445
+ if (typeof entry === 'object') {
446
+ toWalk.push(entry);
447
+ }
448
+ }
449
+ };
450
+ var collectMapEntries = function () {
451
+ var maps = [];
452
+ for (var _i = 0; _i < arguments.length; _i++) {
453
+ maps[_i] = arguments[_i];
454
+ }
455
+ for (var _a = 0, maps_1 = maps; _a < maps_1.length; _a++) {
456
+ var map = maps_1[_a];
457
+ if (typeof map === 'object') {
458
+ for (var k in map) {
459
+ var key = k;
460
+ var entry = map[key];
461
+ if (typeof entry === 'object') {
462
+ toWalk.push(entry);
524
463
  }
525
- pendingSubSchemas.delete(fullId);
526
464
  }
527
465
  }
528
- };
529
- while (toWalk.length) {
530
- var next = toWalk.pop();
531
- if (seen.has(next)) {
532
- continue;
466
+ }
467
+ };
468
+ var collectArrayEntries = function () {
469
+ var arrays = [];
470
+ for (var _i = 0; _i < arguments.length; _i++) {
471
+ arrays[_i] = arguments[_i];
472
+ }
473
+ for (var _a = 0, arrays_1 = arrays; _a < arrays_1.length; _a++) {
474
+ var array = arrays_1[_a];
475
+ if (Array.isArray(array)) {
476
+ for (var _b = 0, array_1 = array; _b < array_1.length; _b++) {
477
+ var entry = array_1[_b];
478
+ if (typeof entry === 'object') {
479
+ toWalk.push(entry);
480
+ }
481
+ }
533
482
  }
534
- seen.add(next);
535
- handleId(next);
536
- handleRef(next);
537
483
  }
538
- return _this.promise.all(openPromises);
539
484
  };
540
- return resolveRefs(schema, schema, handle).then(function (_) {
541
- for (var unresolvedSubschemaId in pendingSubSchemas) {
542
- resolveErrors.push(localize('json.schema.idnotfound', 'Subschema with id \'{0}\' was not found', unresolvedSubschemaId));
485
+ var toWalk = [root];
486
+ var next = toWalk.pop();
487
+ while (next) {
488
+ if (!seen.has(next)) {
489
+ seen.add(next);
490
+ handle(next);
491
+ collectEntries(next.items, next.additionalItems, next.additionalProperties, next.not, next.contains, next.propertyNames, next.if, next.then, next.else);
492
+ collectMapEntries(next.definitions, next.properties, next.patternProperties, next.dependencies);
493
+ collectArrayEntries(next.anyOf, next.allOf, next.oneOf, next.items);
543
494
  }
544
- return new ResolvedSchema(schema, resolveErrors);
545
- });
495
+ next = toWalk.pop();
496
+ }
546
497
  };
498
+ ;
547
499
  JSONSchemaService.prototype.getSchemaFromProperty = function (resource, document) {
548
500
  var _a, _b;
549
501
  if (((_a = document.root) === null || _a === void 0 ? void 0 : _a.type) === 'object') {
@@ -636,7 +588,7 @@
636
588
  function normalizeId(id) {
637
589
  // remove trailing '#', normalize drive capitalization
638
590
  try {
639
- return vscode_uri_1.URI.parse(id).toString();
591
+ return vscode_uri_1.URI.parse(id).toString(true);
640
592
  }
641
593
  catch (e) {
642
594
  return id;
@@ -645,7 +597,7 @@
645
597
  function normalizeResourceForMatching(resource) {
646
598
  // remove queries and fragments, normalize drive capitalization
647
599
  try {
648
- return vscode_uri_1.URI.parse(resource).with({ fragment: null, query: null }).toString();
600
+ return vscode_uri_1.URI.parse(resource).with({ fragment: null, query: null }).toString(true);
649
601
  }
650
602
  catch (e) {
651
603
  return resource;
@@ -60,7 +60,7 @@
60
60
  function newRange(start, end) {
61
61
  return jsonLanguageTypes_1.Range.create(document.positionAt(start), document.positionAt(end));
62
62
  }
63
- var scanner = jsonc_parser_1.createScanner(document.getText(), true);
63
+ var scanner = (0, jsonc_parser_1.createScanner)(document.getText(), true);
64
64
  function getOffsetAfterNextToken(offset, expectedToken) {
65
65
  scanner.setPosition(offset);
66
66
  var token = scanner.scan();
@@ -115,14 +115,14 @@
115
115
  var idCounter = 0;
116
116
  function schemaAllowsComments(schemaRef) {
117
117
  if (schemaRef && typeof schemaRef === 'object') {
118
- if (objects_1.isBoolean(schemaRef.allowComments)) {
118
+ if ((0, objects_1.isBoolean)(schemaRef.allowComments)) {
119
119
  return schemaRef.allowComments;
120
120
  }
121
121
  if (schemaRef.allOf) {
122
122
  for (var _i = 0, _a = schemaRef.allOf; _i < _a.length; _i++) {
123
123
  var schema = _a[_i];
124
124
  var allow = schemaAllowsComments(schema);
125
- if (objects_1.isBoolean(allow)) {
125
+ if ((0, objects_1.isBoolean)(allow)) {
126
126
  return allow;
127
127
  }
128
128
  }
@@ -132,18 +132,18 @@
132
132
  }
133
133
  function schemaAllowsTrailingCommas(schemaRef) {
134
134
  if (schemaRef && typeof schemaRef === 'object') {
135
- if (objects_1.isBoolean(schemaRef.allowTrailingCommas)) {
135
+ if ((0, objects_1.isBoolean)(schemaRef.allowTrailingCommas)) {
136
136
  return schemaRef.allowTrailingCommas;
137
137
  }
138
138
  var deprSchemaRef = schemaRef;
139
- if (objects_1.isBoolean(deprSchemaRef['allowsTrailingCommas'])) { // deprecated
139
+ if ((0, objects_1.isBoolean)(deprSchemaRef['allowsTrailingCommas'])) { // deprecated
140
140
  return deprSchemaRef['allowsTrailingCommas'];
141
141
  }
142
142
  if (schemaRef.allOf) {
143
143
  for (var _i = 0, _a = schemaRef.allOf; _i < _a.length; _i++) {
144
144
  var schema = _a[_i];
145
145
  var allow = schemaAllowsTrailingCommas(schema);
146
- if (objects_1.isBoolean(allow)) {
146
+ if ((0, objects_1.isBoolean)(allow)) {
147
147
  return allow;
148
148
  }
149
149
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vscode-json-languageservice",
3
- "version": "4.2.0-next.2",
3
+ "version": "4.2.1",
4
4
  "description": "Language service for JSON",
5
5
  "main": "./lib/umd/jsonLanguageService.js",
6
6
  "typings": "./lib/umd/jsonLanguageService",
@@ -15,21 +15,21 @@
15
15
  "url": "https://github.com/Microsoft/vscode-json-languageservice"
16
16
  },
17
17
  "devDependencies": {
18
- "@types/mocha": "^9.0.0",
18
+ "@types/mocha": "^9.1.0",
19
19
  "@types/node": "^10.12.21",
20
- "@typescript-eslint/eslint-plugin": "^4.32.0",
21
- "@typescript-eslint/parser": "^4.32.0",
22
- "eslint": "^7.32.0",
23
- "mocha": "^9.1.2",
20
+ "@typescript-eslint/eslint-plugin": "^5.15.0",
21
+ "@typescript-eslint/parser": "^5.15.0",
22
+ "eslint": "^8.11.0",
23
+ "mocha": "^9.2.2",
24
24
  "rimraf": "^3.0.2",
25
- "typescript": "^4.1.3"
25
+ "typescript": "^4.5.5"
26
26
  },
27
27
  "dependencies": {
28
28
  "jsonc-parser": "^3.0.0",
29
- "vscode-languageserver-textdocument": "^1.0.1",
29
+ "vscode-languageserver-textdocument": "^1.0.3",
30
30
  "vscode-languageserver-types": "^3.16.0",
31
31
  "vscode-nls": "^5.0.0",
32
- "vscode-uri": "^3.0.2"
32
+ "vscode-uri": "^3.0.3"
33
33
  },
34
34
  "scripts": {
35
35
  "prepublishOnly": "npm run clean && npm run compile-esm && npm run test && npm run remove-sourcemap-refs",