UNPKG

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