vscode-json-languageservice 3.1.7 → 3.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.
@@ -27,7 +27,7 @@ var __extends = (this && this.__extends) || (function () {
27
27
  'use strict';
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  var Json = require("jsonc-parser");
30
- var objects = require("../utils/objects");
30
+ var objects_1 = require("../utils/objects");
31
31
  var jsonLanguageTypes_1 = require("../jsonLanguageTypes");
32
32
  var nls = require("vscode-nls");
33
33
  var vscode_uri_1 = require("vscode-uri");
@@ -154,7 +154,7 @@ var __extends = (this && this.__extends) || (function () {
154
154
  }(ASTNodeImpl));
155
155
  exports.ObjectASTNodeImpl = ObjectASTNodeImpl;
156
156
  function asSchema(schema) {
157
- if (typeof schema === 'boolean') {
157
+ if (objects_1.isBoolean(schema)) {
158
158
  return schema ? {} : { "not": {} };
159
159
  }
160
160
  return schema;
@@ -216,10 +216,10 @@ var __extends = (this && this.__extends) || (function () {
216
216
  return !!this.problems.length;
217
217
  };
218
218
  ValidationResult.prototype.mergeAll = function (validationResults) {
219
- var _this = this;
220
- validationResults.forEach(function (validationResult) {
221
- _this.merge(validationResult);
222
- });
219
+ for (var _i = 0, validationResults_1 = validationResults; _i < validationResults_1.length; _i++) {
220
+ var validationResult = validationResults_1[_i];
221
+ this.merge(validationResult);
222
+ }
223
223
  };
224
224
  ValidationResult.prototype.merge = function (validationResult) {
225
225
  this.problems = this.problems.concat(validationResult.problems);
@@ -380,9 +380,10 @@ var __extends = (this && this.__extends) || (function () {
380
380
  }
381
381
  }
382
382
  if (Array.isArray(schema.allOf)) {
383
- schema.allOf.forEach(function (subSchemaRef) {
383
+ for (var _i = 0, _a = schema.allOf; _i < _a.length; _i++) {
384
+ var subSchemaRef = _a[_i];
384
385
  validate(node, asSchema(subSchemaRef), validationResult, matchingSchemas);
385
- });
386
+ }
386
387
  }
387
388
  var notSchema = asSchema(schema.not);
388
389
  if (notSchema) {
@@ -396,16 +397,18 @@ var __extends = (this && this.__extends) || (function () {
396
397
  message: localize('notSchemaWarning', "Matches a schema that is not allowed.")
397
398
  });
398
399
  }
399
- subMatchingSchemas.schemas.forEach(function (ms) {
400
+ for (var _b = 0, _c = subMatchingSchemas.schemas; _b < _c.length; _b++) {
401
+ var ms = _c[_b];
400
402
  ms.inverted = !ms.inverted;
401
403
  matchingSchemas.add(ms);
402
- });
404
+ }
403
405
  }
404
406
  var testAlternatives = function (alternatives, maxOneMatch) {
405
407
  var matches = [];
406
408
  // remember the best match that is used for error messages
407
409
  var bestMatch = null;
408
- alternatives.forEach(function (subSchemaRef) {
410
+ for (var _i = 0, alternatives_1 = alternatives; _i < alternatives_1.length; _i++) {
411
+ var subSchemaRef = alternatives_1[_i];
409
412
  var subSchema = asSchema(subSchemaRef);
410
413
  var subValidationResult = new ValidationResult();
411
414
  var subMatchingSchemas = matchingSchemas.newSub();
@@ -436,7 +439,7 @@ var __extends = (this && this.__extends) || (function () {
436
439
  }
437
440
  }
438
441
  }
439
- });
442
+ }
440
443
  if (matches.length > 1 && maxOneMatch) {
441
444
  validationResult.problems.push({
442
445
  location: { offset: node.offset, length: 1 },
@@ -459,10 +462,9 @@ var __extends = (this && this.__extends) || (function () {
459
462
  testAlternatives(schema.oneOf, true);
460
463
  }
461
464
  var testBranch = function (schema) {
462
- var subSchema = asSchema(schema);
463
465
  var subValidationResult = new ValidationResult();
464
466
  var subMatchingSchemas = matchingSchemas.newSub();
465
- validate(node, subSchema, subValidationResult, subMatchingSchemas);
467
+ validate(node, asSchema(schema), subValidationResult, subMatchingSchemas);
466
468
  validationResult.merge(subValidationResult);
467
469
  validationResult.propertiesMatches += subValidationResult.propertiesMatches;
468
470
  validationResult.propertiesValueMatches += subValidationResult.propertiesValueMatches;
@@ -473,6 +475,7 @@ var __extends = (this && this.__extends) || (function () {
473
475
  var subValidationResult = new ValidationResult();
474
476
  var subMatchingSchemas = matchingSchemas.newSub();
475
477
  validate(node, subSchema, subValidationResult, subMatchingSchemas);
478
+ matchingSchemas.merge(subMatchingSchemas);
476
479
  if (!subValidationResult.hasProblems()) {
477
480
  if (thenSchema) {
478
481
  testBranch(thenSchema);
@@ -482,15 +485,16 @@ var __extends = (this && this.__extends) || (function () {
482
485
  testBranch(elseSchema);
483
486
  }
484
487
  };
485
- if (schema.if) {
486
- testCondition(schema.if, schema.then, schema.else);
488
+ var ifSchema = asSchema(schema.if);
489
+ if (ifSchema) {
490
+ testCondition(ifSchema, asSchema(schema.then), asSchema(schema.else));
487
491
  }
488
492
  if (Array.isArray(schema.enum)) {
489
493
  var val = getNodeValue(node);
490
494
  var enumValueMatch = false;
491
- for (var _i = 0, _a = schema.enum; _i < _a.length; _i++) {
492
- var e = _a[_i];
493
- if (objects.equals(val, e)) {
495
+ for (var _d = 0, _e = schema.enum; _d < _e.length; _d++) {
496
+ var e = _e[_d];
497
+ if (objects_1.equals(val, e)) {
494
498
  enumValueMatch = true;
495
499
  break;
496
500
  }
@@ -506,9 +510,9 @@ var __extends = (this && this.__extends) || (function () {
506
510
  });
507
511
  }
508
512
  }
509
- if (schema.const) {
513
+ if (objects_1.isDefined(schema.const)) {
510
514
  var val = getNodeValue(node);
511
- if (!objects.equals(val, schema.const)) {
515
+ if (!objects_1.equals(val, schema.const)) {
512
516
  validationResult.problems.push({
513
517
  location: { offset: node.offset, length: node.length },
514
518
  severity: vscode_languageserver_types_1.DiagnosticSeverity.Warning,
@@ -532,7 +536,7 @@ var __extends = (this && this.__extends) || (function () {
532
536
  }
533
537
  function _validateNumberNode(node, schema, validationResult, matchingSchemas) {
534
538
  var val = node.value;
535
- if (typeof schema.multipleOf === 'number') {
539
+ if (objects_1.isNumber(schema.multipleOf)) {
536
540
  if (val % schema.multipleOf !== 0) {
537
541
  validationResult.problems.push({
538
542
  location: { offset: node.offset, length: node.length },
@@ -542,22 +546,22 @@ var __extends = (this && this.__extends) || (function () {
542
546
  }
543
547
  }
544
548
  function getExclusiveLimit(limit, exclusive) {
545
- if (typeof exclusive === 'number') {
549
+ if (objects_1.isNumber(exclusive)) {
546
550
  return exclusive;
547
551
  }
548
- if (typeof exclusive === 'boolean' && exclusive) {
552
+ if (objects_1.isBoolean(exclusive) && exclusive) {
549
553
  return limit;
550
554
  }
551
555
  return void 0;
552
556
  }
553
557
  function getLimit(limit, exclusive) {
554
- if (typeof exclusive !== 'boolean' || !exclusive) {
558
+ if (!objects_1.isBoolean(exclusive) || !exclusive) {
555
559
  return limit;
556
560
  }
557
561
  return void 0;
558
562
  }
559
563
  var exclusiveMinimum = getExclusiveLimit(schema.minimum, schema.exclusiveMinimum);
560
- if (typeof exclusiveMinimum === 'number' && val <= exclusiveMinimum) {
564
+ if (objects_1.isNumber(exclusiveMinimum) && val <= exclusiveMinimum) {
561
565
  validationResult.problems.push({
562
566
  location: { offset: node.offset, length: node.length },
563
567
  severity: vscode_languageserver_types_1.DiagnosticSeverity.Warning,
@@ -565,7 +569,7 @@ var __extends = (this && this.__extends) || (function () {
565
569
  });
566
570
  }
567
571
  var exclusiveMaximum = getExclusiveLimit(schema.maximum, schema.exclusiveMaximum);
568
- if (typeof exclusiveMaximum === 'number' && val >= exclusiveMaximum) {
572
+ if (objects_1.isNumber(exclusiveMaximum) && val >= exclusiveMaximum) {
569
573
  validationResult.problems.push({
570
574
  location: { offset: node.offset, length: node.length },
571
575
  severity: vscode_languageserver_types_1.DiagnosticSeverity.Warning,
@@ -573,7 +577,7 @@ var __extends = (this && this.__extends) || (function () {
573
577
  });
574
578
  }
575
579
  var minimum = getLimit(schema.minimum, schema.exclusiveMinimum);
576
- if (typeof minimum === 'number' && val < minimum) {
580
+ if (objects_1.isNumber(minimum) && val < minimum) {
577
581
  validationResult.problems.push({
578
582
  location: { offset: node.offset, length: node.length },
579
583
  severity: vscode_languageserver_types_1.DiagnosticSeverity.Warning,
@@ -581,7 +585,7 @@ var __extends = (this && this.__extends) || (function () {
581
585
  });
582
586
  }
583
587
  var maximum = getLimit(schema.maximum, schema.exclusiveMaximum);
584
- if (typeof maximum === 'number' && val > maximum) {
588
+ if (objects_1.isNumber(maximum) && val > maximum) {
585
589
  validationResult.problems.push({
586
590
  location: { offset: node.offset, length: node.length },
587
591
  severity: vscode_languageserver_types_1.DiagnosticSeverity.Warning,
@@ -590,21 +594,21 @@ var __extends = (this && this.__extends) || (function () {
590
594
  }
591
595
  }
592
596
  function _validateStringNode(node, schema, validationResult, matchingSchemas) {
593
- if (schema.minLength && node.value.length < schema.minLength) {
597
+ if (objects_1.isNumber(schema.minLength) && node.value.length < schema.minLength) {
594
598
  validationResult.problems.push({
595
599
  location: { offset: node.offset, length: node.length },
596
600
  severity: vscode_languageserver_types_1.DiagnosticSeverity.Warning,
597
601
  message: localize('minLengthWarning', 'String is shorter than the minimum length of {0}.', schema.minLength)
598
602
  });
599
603
  }
600
- if (schema.maxLength && node.value.length > schema.maxLength) {
604
+ if (objects_1.isNumber(schema.maxLength) && node.value.length > schema.maxLength) {
601
605
  validationResult.problems.push({
602
606
  location: { offset: node.offset, length: node.length },
603
607
  severity: vscode_languageserver_types_1.DiagnosticSeverity.Warning,
604
608
  message: localize('maxLengthWarning', 'String is longer than the maximum length of {0}.', schema.maxLength)
605
609
  });
606
610
  }
607
- if (schema.pattern) {
611
+ if (objects_1.isString(schema.pattern)) {
608
612
  var regex = new RegExp(schema.pattern);
609
613
  if (!regex.test(node.value)) {
610
614
  validationResult.problems.push({
@@ -671,8 +675,9 @@ var __extends = (this && this.__extends) || (function () {
671
675
  }
672
676
  function _validateArrayNode(node, schema, validationResult, matchingSchemas) {
673
677
  if (Array.isArray(schema.items)) {
674
- var subSchemas_1 = schema.items;
675
- subSchemas_1.forEach(function (subSchemaRef, index) {
678
+ var subSchemas = schema.items;
679
+ for (var index = 0; index < subSchemas.length; index++) {
680
+ var subSchemaRef = subSchemas[index];
676
681
  var subSchema = asSchema(subSchemaRef);
677
682
  var itemValidationResult = new ValidationResult();
678
683
  var item = node.items[index];
@@ -680,13 +685,13 @@ var __extends = (this && this.__extends) || (function () {
680
685
  validate(item, subSchema, itemValidationResult, matchingSchemas);
681
686
  validationResult.mergePropertyMatch(itemValidationResult);
682
687
  }
683
- else if (node.items.length >= subSchemas_1.length) {
688
+ else if (node.items.length >= subSchemas.length) {
684
689
  validationResult.propertiesValueMatches++;
685
690
  }
686
- });
687
- if (node.items.length > subSchemas_1.length) {
691
+ }
692
+ if (node.items.length > subSchemas.length) {
688
693
  if (typeof schema.additionalItems === 'object') {
689
- for (var i = subSchemas_1.length; i < node.items.length; i++) {
694
+ for (var i = subSchemas.length; i < node.items.length; i++) {
690
695
  var itemValidationResult = new ValidationResult();
691
696
  validate(node.items[i], schema.additionalItems, itemValidationResult, matchingSchemas);
692
697
  validationResult.mergePropertyMatch(itemValidationResult);
@@ -696,19 +701,20 @@ var __extends = (this && this.__extends) || (function () {
696
701
  validationResult.problems.push({
697
702
  location: { offset: node.offset, length: node.length },
698
703
  severity: vscode_languageserver_types_1.DiagnosticSeverity.Warning,
699
- message: localize('additionalItemsWarning', 'Array has too many items according to schema. Expected {0} or fewer.', subSchemas_1.length)
704
+ message: localize('additionalItemsWarning', 'Array has too many items according to schema. Expected {0} or fewer.', subSchemas.length)
700
705
  });
701
706
  }
702
707
  }
703
708
  }
704
709
  else {
705
- var itemSchema_1 = asSchema(schema.items);
706
- if (itemSchema_1) {
707
- node.items.forEach(function (item) {
710
+ var itemSchema = asSchema(schema.items);
711
+ if (itemSchema) {
712
+ for (var _i = 0, _a = node.items; _i < _a.length; _i++) {
713
+ var item = _a[_i];
708
714
  var itemValidationResult = new ValidationResult();
709
- validate(item, itemSchema_1, itemValidationResult, matchingSchemas);
715
+ validate(item, itemSchema, itemValidationResult, matchingSchemas);
710
716
  validationResult.mergePropertyMatch(itemValidationResult);
711
- });
717
+ }
712
718
  }
713
719
  }
714
720
  var containsSchema = asSchema(schema.contains);
@@ -726,14 +732,14 @@ var __extends = (this && this.__extends) || (function () {
726
732
  });
727
733
  }
728
734
  }
729
- if (schema.minItems && node.items.length < schema.minItems) {
735
+ if (objects_1.isNumber(schema.minItems) && node.items.length < schema.minItems) {
730
736
  validationResult.problems.push({
731
737
  location: { offset: node.offset, length: node.length },
732
738
  severity: vscode_languageserver_types_1.DiagnosticSeverity.Warning,
733
739
  message: localize('minItemsWarning', 'Array has too few items. Expected {0} or more.', schema.minItems)
734
740
  });
735
741
  }
736
- if (schema.maxItems && node.items.length > schema.maxItems) {
742
+ if (objects_1.isNumber(schema.maxItems) && node.items.length > schema.maxItems) {
737
743
  validationResult.problems.push({
738
744
  location: { offset: node.offset, length: node.length },
739
745
  severity: vscode_languageserver_types_1.DiagnosticSeverity.Warning,
@@ -757,13 +763,15 @@ var __extends = (this && this.__extends) || (function () {
757
763
  function _validateObjectNode(node, schema, validationResult, matchingSchemas) {
758
764
  var seenKeys = Object.create(null);
759
765
  var unprocessedProperties = [];
760
- node.properties.forEach(function (node) {
761
- var key = node.keyNode.value;
762
- seenKeys[key] = node.valueNode;
766
+ for (var _i = 0, _a = node.properties; _i < _a.length; _i++) {
767
+ var propertyNode = _a[_i];
768
+ var key = propertyNode.keyNode.value;
769
+ seenKeys[key] = propertyNode.valueNode;
763
770
  unprocessedProperties.push(key);
764
- });
771
+ }
765
772
  if (Array.isArray(schema.required)) {
766
- schema.required.forEach(function (propertyName) {
773
+ for (var _b = 0, _c = schema.required; _b < _c.length; _b++) {
774
+ var propertyName = _c[_b];
767
775
  if (!seenKeys[propertyName]) {
768
776
  var keyNode = node.parent && node.parent.type === 'property' && node.parent.keyNode;
769
777
  var location = keyNode ? { offset: keyNode.offset, length: keyNode.length } : { offset: node.offset, length: 1 };
@@ -773,7 +781,7 @@ var __extends = (this && this.__extends) || (function () {
773
781
  message: localize('MissingRequiredPropWarning', 'Missing property "{0}".', propertyName)
774
782
  });
775
783
  }
776
- });
784
+ }
777
785
  }
778
786
  var propertyProcessed = function (prop) {
779
787
  var index = unprocessedProperties.indexOf(prop);
@@ -783,12 +791,13 @@ var __extends = (this && this.__extends) || (function () {
783
791
  }
784
792
  };
785
793
  if (schema.properties) {
786
- Object.keys(schema.properties).forEach(function (propertyName) {
794
+ for (var _d = 0, _e = Object.keys(schema.properties); _d < _e.length; _d++) {
795
+ var propertyName = _e[_d];
787
796
  propertyProcessed(propertyName);
788
797
  var propertySchema = schema.properties[propertyName];
789
798
  var child = seenKeys[propertyName];
790
799
  if (child) {
791
- if (typeof propertySchema === 'boolean') {
800
+ if (objects_1.isBoolean(propertySchema)) {
792
801
  if (!propertySchema) {
793
802
  var propertyNode = child.parent;
794
803
  validationResult.problems.push({
@@ -808,18 +817,20 @@ var __extends = (this && this.__extends) || (function () {
808
817
  validationResult.mergePropertyMatch(propertyValidationResult);
809
818
  }
810
819
  }
811
- });
820
+ }
812
821
  }
813
822
  if (schema.patternProperties) {
814
- Object.keys(schema.patternProperties).forEach(function (propertyPattern) {
823
+ for (var _f = 0, _g = Object.keys(schema.patternProperties); _f < _g.length; _f++) {
824
+ var propertyPattern = _g[_f];
815
825
  var regex = new RegExp(propertyPattern);
816
- unprocessedProperties.slice(0).forEach(function (propertyName) {
826
+ for (var _h = 0, _j = unprocessedProperties.slice(0); _h < _j.length; _h++) {
827
+ var propertyName = _j[_h];
817
828
  if (regex.test(propertyName)) {
818
829
  propertyProcessed(propertyName);
819
830
  var child = seenKeys[propertyName];
820
831
  if (child) {
821
832
  var propertySchema = schema.patternProperties[propertyPattern];
822
- if (typeof propertySchema === 'boolean') {
833
+ if (objects_1.isBoolean(propertySchema)) {
823
834
  if (!propertySchema) {
824
835
  var propertyNode = child.parent;
825
836
  validationResult.problems.push({
@@ -840,22 +851,24 @@ var __extends = (this && this.__extends) || (function () {
840
851
  }
841
852
  }
842
853
  }
843
- });
844
- });
854
+ }
855
+ }
845
856
  }
846
857
  if (typeof schema.additionalProperties === 'object') {
847
- unprocessedProperties.forEach(function (propertyName) {
858
+ for (var _k = 0, unprocessedProperties_1 = unprocessedProperties; _k < unprocessedProperties_1.length; _k++) {
859
+ var propertyName = unprocessedProperties_1[_k];
848
860
  var child = seenKeys[propertyName];
849
861
  if (child) {
850
862
  var propertyValidationResult = new ValidationResult();
851
863
  validate(child, schema.additionalProperties, propertyValidationResult, matchingSchemas);
852
864
  validationResult.mergePropertyMatch(propertyValidationResult);
853
865
  }
854
- });
866
+ }
855
867
  }
856
868
  else if (schema.additionalProperties === false) {
857
869
  if (unprocessedProperties.length > 0) {
858
- unprocessedProperties.forEach(function (propertyName) {
870
+ for (var _l = 0, unprocessedProperties_2 = unprocessedProperties; _l < unprocessedProperties_2.length; _l++) {
871
+ var propertyName = unprocessedProperties_2[_l];
859
872
  var child = seenKeys[propertyName];
860
873
  if (child) {
861
874
  var propertyNode = child.parent;
@@ -865,10 +878,10 @@ var __extends = (this && this.__extends) || (function () {
865
878
  message: schema.errorMessage || localize('DisallowedExtraPropWarning', 'Property {0} is not allowed.', propertyName)
866
879
  });
867
880
  }
868
- });
881
+ }
869
882
  }
870
883
  }
871
- if (schema.maxProperties) {
884
+ if (objects_1.isNumber(schema.maxProperties)) {
872
885
  if (node.properties.length > schema.maxProperties) {
873
886
  validationResult.problems.push({
874
887
  location: { offset: node.offset, length: node.length },
@@ -877,7 +890,7 @@ var __extends = (this && this.__extends) || (function () {
877
890
  });
878
891
  }
879
892
  }
880
- if (schema.minProperties) {
893
+ if (objects_1.isNumber(schema.minProperties)) {
881
894
  if (node.properties.length < schema.minProperties) {
882
895
  validationResult.problems.push({
883
896
  location: { offset: node.offset, length: node.length },
@@ -887,12 +900,14 @@ var __extends = (this && this.__extends) || (function () {
887
900
  }
888
901
  }
889
902
  if (schema.dependencies) {
890
- Object.keys(schema.dependencies).forEach(function (key) {
903
+ for (var _m = 0, _o = Object.keys(schema.dependencies); _m < _o.length; _m++) {
904
+ var key = _o[_m];
891
905
  var prop = seenKeys[key];
892
906
  if (prop) {
893
907
  var propertyDep = schema.dependencies[key];
894
908
  if (Array.isArray(propertyDep)) {
895
- propertyDep.forEach(function (requiredProp) {
909
+ for (var _p = 0, propertyDep_1 = propertyDep; _p < propertyDep_1.length; _p++) {
910
+ var requiredProp = propertyDep_1[_p];
896
911
  if (!seenKeys[requiredProp]) {
897
912
  validationResult.problems.push({
898
913
  location: { offset: node.offset, length: node.length },
@@ -903,7 +918,7 @@ var __extends = (this && this.__extends) || (function () {
903
918
  else {
904
919
  validationResult.propertiesValueMatches++;
905
920
  }
906
- });
921
+ }
907
922
  }
908
923
  else {
909
924
  var propertySchema = asSchema(propertyDep);
@@ -914,16 +929,17 @@ var __extends = (this && this.__extends) || (function () {
914
929
  }
915
930
  }
916
931
  }
917
- });
932
+ }
918
933
  }
919
934
  var propertyNames = asSchema(schema.propertyNames);
920
935
  if (propertyNames) {
921
- node.properties.forEach(function (f) {
936
+ for (var _q = 0, _r = node.properties; _q < _r.length; _q++) {
937
+ var f = _r[_q];
922
938
  var key = f.keyNode;
923
939
  if (key) {
924
940
  validate(key, propertyNames, validationResult, NoOpSchemaCollector.instance);
925
941
  }
926
- });
942
+ }
927
943
  }
928
944
  }
929
945
  }
@@ -1171,7 +1187,7 @@ var __extends = (this && this.__extends) || (function () {
1171
1187
  var tokenValue = scanner.getTokenValue();
1172
1188
  try {
1173
1189
  var numberValue = JSON.parse(tokenValue);
1174
- if (typeof numberValue !== 'number') {
1190
+ if (!objects_1.isNumber(numberValue)) {
1175
1191
  return _error(localize('InvalidNumberFormat', 'Invalid number format.'), jsonLanguageTypes_1.ErrorCode.Undefined, node);
1176
1192
  }
1177
1193
  node.value = numberValue;