index.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*istanbul ignore next*/"use strict";
  2. exports.__esModule = true;
  3. exports.MESSAGES = undefined;
  4. var _stringify = require("babel-runtime/core-js/json/stringify");
  5. var _stringify2 = _interopRequireDefault(_stringify);
  6. exports.get = get;
  7. /*istanbul ignore next*/exports.parseArgs = parseArgs;
  8. var /*istanbul ignore next*/_util = require("util");
  9. /*istanbul ignore next*/
  10. var util = _interopRequireWildcard(_util);
  11. /*istanbul ignore next*/
  12. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  13. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14. /**
  15. * Mapping of messages to be used in Babel.
  16. * Messages can include $0-style placeholders.
  17. */
  18. var MESSAGES = /*istanbul ignore next*/exports.MESSAGES = {
  19. tailCallReassignmentDeopt: "Function reference has been reassigned, so it will probably be dereferenced, therefore we can't optimise this with confidence",
  20. classesIllegalBareSuper: "Illegal use of bare super",
  21. classesIllegalSuperCall: "Direct super call is illegal in non-constructor, use super.$1() instead",
  22. scopeDuplicateDeclaration: "Duplicate declaration $1",
  23. settersNoRest: "Setters aren't allowed to have a rest",
  24. noAssignmentsInForHead: "No assignments allowed in for-in/of head",
  25. expectedMemberExpressionOrIdentifier: "Expected type MemberExpression or Identifier",
  26. invalidParentForThisNode: "We don't know how to handle this node within the current parent - please open an issue",
  27. readOnly: "$1 is read-only",
  28. unknownForHead: "Unknown node type $1 in ForStatement",
  29. didYouMean: "Did you mean $1?",
  30. codeGeneratorDeopt: "Note: The code generator has deoptimised the styling of $1 as it exceeds the max of $2.",
  31. missingTemplatesDirectory: "no templates directory - this is most likely the result of a broken `npm publish`. Please report to https://github.com/babel/babel/issues",
  32. unsupportedOutputType: "Unsupported output type $1",
  33. illegalMethodName: "Illegal method name $1",
  34. lostTrackNodePath: "We lost track of this node's position, likely because the AST was directly manipulated",
  35. modulesIllegalExportName: "Illegal export $1",
  36. modulesDuplicateDeclarations: "Duplicate module declarations with the same source but in different scopes",
  37. undeclaredVariable: "Reference to undeclared variable $1",
  38. undeclaredVariableType: "Referencing a type alias outside of a type annotation",
  39. undeclaredVariableSuggestion: "Reference to undeclared variable $1 - did you mean $2?",
  40. traverseNeedsParent: "You must pass a scope and parentPath unless traversing a Program/File. Instead of that you tried to traverse a $1 node without passing scope and parentPath.",
  41. traverseVerifyRootFunction: "You passed `traverse()` a function when it expected a visitor object, are you sure you didn't mean `{ enter: Function }`?",
  42. traverseVerifyVisitorProperty: "You passed `traverse()` a visitor object with the property $1 that has the invalid property $2",
  43. traverseVerifyNodeType: "You gave us a visitor for the node type $1 but it's not a valid type",
  44. pluginNotObject: "Plugin $2 specified in $1 was expected to return an object when invoked but returned $3",
  45. pluginNotFunction: "Plugin $2 specified in $1 was expected to return a function but returned $3",
  46. pluginUnknown: "Unknown plugin $1 specified in $2 at $3, attempted to resolve relative to $4",
  47. pluginInvalidProperty: "Plugin $2 specified in $1 provided an invalid property of $3"
  48. };
  49. /**
  50. * Get a message with $0 placeholders replaced by arguments.
  51. */
  52. /* eslint max-len: 0 */
  53. function get(key) {
  54. /*istanbul ignore next*/
  55. for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  56. args[_key - 1] = arguments[_key];
  57. }
  58. var msg = MESSAGES[key];
  59. if (!msg) throw new ReferenceError( /*istanbul ignore next*/"Unknown message " + /*istanbul ignore next*/(0, _stringify2.default)(key));
  60. // stringify args
  61. args = parseArgs(args);
  62. // replace $0 placeholders with args
  63. return msg.replace(/\$(\d+)/g, function (str, i) {
  64. return args[i - 1];
  65. });
  66. }
  67. /**
  68. * Stingify arguments to be used inside messages.
  69. */
  70. function parseArgs(args) {
  71. return args.map(function (val) {
  72. if (val != null && val.inspect) {
  73. return val.inspect();
  74. } else {
  75. try {
  76. return (/*istanbul ignore next*/(0, _stringify2.default)(val) || val + ""
  77. );
  78. } catch (e) {
  79. return util.inspect(val);
  80. }
  81. }
  82. });
  83. }