UNPKG

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