react-intl 4.2.0 → 4.3.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.
@@ -4301,15 +4301,27 @@
4301
4301
  };
4302
4302
  }();
4303
4303
 
4304
+ var ErrorCode;
4305
+
4306
+ (function (ErrorCode) {
4307
+ // When we have a placeholder but no value to format
4308
+ ErrorCode["MISSING_VALUE"] = "MISSING_VALUE"; // When value supplied is invalid
4309
+
4310
+ ErrorCode["INVALID_VALUE"] = "INVALID_VALUE"; // When we need specific Intl API but it's not available
4311
+
4312
+ ErrorCode["MISSING_INTL_API"] = "MISSING_INTL_API";
4313
+ })(ErrorCode || (ErrorCode = {}));
4314
+
4304
4315
  var FormatError =
4305
4316
  /** @class */
4306
4317
  function (_super) {
4307
4318
  __extends$1(FormatError, _super);
4308
4319
 
4309
- function FormatError(msg, code) {
4320
+ function FormatError(msg, code, originalMessage) {
4310
4321
  var _this = _super.call(this, msg) || this;
4311
4322
 
4312
4323
  _this.code = code;
4324
+ _this.originalMessage = originalMessage;
4313
4325
  return _this;
4314
4326
  }
4315
4327
 
@@ -4325,29 +4337,50 @@
4325
4337
  function (_super) {
4326
4338
  __extends$1(InvalidValueError, _super);
4327
4339
 
4328
- function InvalidValueError(variableId, value, options) {
4329
- return _super.call(this, "Invalid values for \"" + variableId + "\": \"" + value + "\". Options are \"" + Object.keys(options).join('", "') + "\"", 1
4340
+ function InvalidValueError(variableId, value, options, originalMessage) {
4341
+ return _super.call(this, "Invalid values for \"" + variableId + "\": \"" + value + "\". Options are \"" + Object.keys(options).join('", "') + "\"", "INVALID_VALUE"
4330
4342
  /* INVALID_VALUE */
4331
- ) || this;
4343
+ , originalMessage) || this;
4332
4344
  }
4333
4345
 
4334
4346
  return InvalidValueError;
4335
4347
  }(FormatError);
4336
4348
 
4349
+ var InvalidValueTypeError =
4350
+ /** @class */
4351
+ function (_super) {
4352
+ __extends$1(InvalidValueTypeError, _super);
4353
+
4354
+ function InvalidValueTypeError(value, type, originalMessage) {
4355
+ return _super.call(this, "Value for \"" + value + "\" must be of type " + type, "INVALID_VALUE"
4356
+ /* INVALID_VALUE */
4357
+ , originalMessage) || this;
4358
+ }
4359
+
4360
+ return InvalidValueTypeError;
4361
+ }(FormatError);
4362
+
4337
4363
  var MissingValueError =
4338
4364
  /** @class */
4339
4365
  function (_super) {
4340
4366
  __extends$1(MissingValueError, _super);
4341
4367
 
4342
4368
  function MissingValueError(variableId, originalMessage) {
4343
- return _super.call(this, "The intl string context variable \"" + variableId + "\" was not provided to the string \"" + originalMessage + "\"", 0
4369
+ return _super.call(this, "The intl string context variable \"" + variableId + "\" was not provided to the string \"" + originalMessage + "\"", "MISSING_VALUE"
4344
4370
  /* MISSING_VALUE */
4345
- ) || this;
4371
+ , originalMessage) || this;
4346
4372
  }
4347
4373
 
4348
4374
  return MissingValueError;
4349
4375
  }(FormatError);
4350
4376
 
4377
+ var PART_TYPE;
4378
+
4379
+ (function (PART_TYPE) {
4380
+ PART_TYPE[PART_TYPE["literal"] = 0] = "literal";
4381
+ PART_TYPE[PART_TYPE["object"] = 1] = "object";
4382
+ })(PART_TYPE || (PART_TYPE = {}));
4383
+
4351
4384
  function mergeLiteral(parts) {
4352
4385
  if (parts.length < 2) {
4353
4386
  return parts;
@@ -4483,7 +4516,7 @@
4483
4516
  var formatFn = values[value_1];
4484
4517
 
4485
4518
  if (!isFormatXMLElementFn(formatFn)) {
4486
- throw new TypeError("Value for \"" + value_1 + "\" must be a function");
4519
+ throw new InvalidValueTypeError(value_1, 'function', originalMessage);
4487
4520
  }
4488
4521
 
4489
4522
  var parts = formatToParts(children, locales, formatters, formats, values);
@@ -4511,7 +4544,7 @@
4511
4544
  var opt = el.options[value] || el.options.other;
4512
4545
 
4513
4546
  if (!opt) {
4514
- throw new InvalidValueError(el.value, value, Object.keys(el.options));
4547
+ throw new InvalidValueError(el.value, value, Object.keys(el.options), originalMessage);
4515
4548
  }
4516
4549
 
4517
4550
  result.push.apply(result, formatToParts(opt.value, locales, formatters, formats, values));
@@ -4523,9 +4556,9 @@
4523
4556
 
4524
4557
  if (!opt) {
4525
4558
  if (!Intl.PluralRules) {
4526
- throw new FormatError("Intl.PluralRules is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-pluralrules\"\n", 2
4559
+ throw new FormatError("Intl.PluralRules is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-pluralrules\"\n", "MISSING_INTL_API"
4527
4560
  /* MISSING_INTL_API */
4528
- );
4561
+ , originalMessage);
4529
4562
  }
4530
4563
 
4531
4564
  var rule = formatters.getPluralRules(locales, {
@@ -4535,7 +4568,7 @@
4535
4568
  }
4536
4569
 
4537
4570
  if (!opt) {
4538
- throw new InvalidValueError(el.value, value, Object.keys(el.options));
4571
+ throw new InvalidValueError(el.value, value, Object.keys(el.options), originalMessage);
4539
4572
  }
4540
4573
 
4541
4574
  result.push.apply(result, formatToParts(opt.value, locales, formatters, formats, values, value - (el.offset || 0)));
@@ -4769,18 +4802,27 @@
4769
4802
  }
4770
4803
  }
4771
4804
 
4805
+ (function (ReactIntlErrorCode) {
4806
+ ReactIntlErrorCode["FORMAT_ERROR"] = "FORMAT_ERROR";
4807
+ ReactIntlErrorCode["UNSUPPORTED_FORMATTER"] = "UNSUPPORTED_FORMATTER";
4808
+ ReactIntlErrorCode["INVALID_CONFIG"] = "INVALID_CONFIG";
4809
+ ReactIntlErrorCode["MISSING_DATA"] = "MISSING_DATA";
4810
+ ReactIntlErrorCode["MISSING_TRANSLATION"] = "MISSING_TRANSLATION";
4811
+ })(exports.ReactIntlErrorCode || (exports.ReactIntlErrorCode = {}));
4812
+
4772
4813
  var ReactIntlError = /*#__PURE__*/function (_Error) {
4773
4814
  _inherits(ReactIntlError, _Error);
4774
4815
 
4775
4816
  var _super = _createSuper(ReactIntlError);
4776
4817
 
4777
- function ReactIntlError(code, message, exception) {
4818
+ function ReactIntlError(code, message, descriptor, exception) {
4778
4819
  var _this;
4779
4820
 
4780
4821
  _classCallCheck(this, ReactIntlError);
4781
4822
 
4782
4823
  _this = _super.call(this, "[React Intl Error ".concat(code, "] ").concat(message, " ").concat(exception ? "\n".concat(exception.stack) : ''));
4783
4824
  _this.code = code;
4825
+ _this.descriptor = descriptor;
4784
4826
 
4785
4827
  if (typeof Error.captureStackTrace === 'function') {
4786
4828
  Error.captureStackTrace(_assertThisInitialized(_this), ReactIntlError);
@@ -5472,7 +5514,7 @@
5472
5514
  var RelativeTimeFormat = Intl.RelativeTimeFormat;
5473
5515
 
5474
5516
  if (!RelativeTimeFormat) {
5475
- config.onError(new FormatError("Intl.RelativeTimeFormat is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-relativetimeformat\"\n", 2
5517
+ config.onError(new FormatError("Intl.RelativeTimeFormat is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-relativetimeformat\"\n", "MISSING_INTL_API"
5476
5518
  /* MISSING_INTL_API */
5477
5519
  ));
5478
5520
  }
@@ -5580,7 +5622,7 @@
5580
5622
  var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
5581
5623
 
5582
5624
  if (!Intl.PluralRules) {
5583
- onError(new FormatError("Intl.PluralRules is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-pluralrules\"\n", 2
5625
+ onError(new FormatError("Intl.PluralRules is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-pluralrules\"\n", "MISSING_INTL_API"
5584
5626
  /* MISSING_INTL_API */
5585
5627
  ));
5586
5628
  }
@@ -5662,7 +5704,7 @@
5662
5704
  } catch (e) {
5663
5705
  onError(new ReactIntlError("FORMAT_ERROR"
5664
5706
  /* FORMAT_ERROR */
5665
- , "Error formatting message: \"".concat(id, "\" for locale: \"").concat(locale, "\"") + (defaultMessage ? ', using default message as fallback.' : ''), e));
5707
+ , "Error formatting message: \"".concat(id, "\" for locale: \"").concat(locale, "\"") + (defaultMessage ? ', using default message as fallback.' : ''), messageDescriptor, e));
5666
5708
  }
5667
5709
  } else if (!defaultMessage || locale && locale.toLowerCase() !== defaultLocale.toLowerCase()) {
5668
5710
  // This prevents warnings from littering the console in development
@@ -5670,7 +5712,7 @@
5670
5712
  // default locale.
5671
5713
  onError(new ReactIntlError("MISSING_TRANSLATION"
5672
5714
  /* MISSING_TRANSLATION */
5673
- , "Missing message: \"".concat(id, "\" for locale: \"").concat(locale, "\"") + (defaultMessage ? ', using default message as fallback.' : '')));
5715
+ , "Missing message: \"".concat(id, "\" for locale: \"").concat(locale, "\"") + (defaultMessage ? ', using default message as fallback.' : ''), messageDescriptor));
5674
5716
  }
5675
5717
 
5676
5718
  if (!formattedMessageParts && defaultMessage) {
@@ -5681,14 +5723,14 @@
5681
5723
  } catch (e) {
5682
5724
  onError(new ReactIntlError("FORMAT_ERROR"
5683
5725
  /* FORMAT_ERROR */
5684
- , "Error formatting the default message for: \"".concat(id, "\""), e));
5726
+ , "Error formatting the default message for: \"".concat(id, "\""), messageDescriptor, e));
5685
5727
  }
5686
5728
  }
5687
5729
 
5688
5730
  if (!formattedMessageParts) {
5689
5731
  onError(new ReactIntlError("FORMAT_ERROR"
5690
5732
  /* FORMAT_ERROR */
5691
- , "Cannot format message: \"".concat(id, "\", ") + "using message ".concat(message || defaultMessage ? 'source' : 'id', " as fallback.")));
5733
+ , "Cannot format message: \"".concat(id, "\", ") + "using message ".concat(message || defaultMessage ? 'source' : 'id', " as fallback."), messageDescriptor));
5692
5734
 
5693
5735
  if (typeof message === 'string') {
5694
5736
  return message || defaultMessage || String(id);
@@ -5758,7 +5800,7 @@
5758
5800
  var ListFormat = Intl.ListFormat;
5759
5801
 
5760
5802
  if (!ListFormat) {
5761
- onError(new FormatError("Intl.ListFormat is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-listformat\"\n", 2
5803
+ onError(new FormatError("Intl.ListFormat is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-listformat\"\n", "MISSING_INTL_API"
5762
5804
  /* MISSING_INTL_API */
5763
5805
  ));
5764
5806
  }
@@ -5812,7 +5854,7 @@
5812
5854
  var DisplayNames = Intl.DisplayNames;
5813
5855
 
5814
5856
  if (!DisplayNames) {
5815
- onError(new FormatError("Intl.DisplayNames is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-displaynames\"\n", 2
5857
+ onError(new FormatError("Intl.DisplayNames is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-displaynames\"\n", "MISSING_INTL_API"
5816
5858
  /* MISSING_INTL_API */
5817
5859
  ));
5818
5860
  }