index.js 4.0 KB

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