UNPKG

7.84 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = generateMissingPluginMessage;
7const pluginNameMap = {
8 classProperties: {
9 syntax: {
10 name: "@babel/plugin-syntax-class-properties",
11 url: "https://git.io/vb4yQ"
12 },
13 transform: {
14 name: "@babel/plugin-proposal-class-properties",
15 url: "https://git.io/vb4SL"
16 }
17 },
18 classPrivateProperties: {
19 syntax: {
20 name: "@babel/plugin-syntax-class-properties",
21 url: "https://git.io/vb4yQ"
22 },
23 transform: {
24 name: "@babel/plugin-proposal-class-properties",
25 url: "https://git.io/vb4SL"
26 }
27 },
28 classPrivateMethods: {
29 syntax: {
30 name: "@babel/plugin-syntax-class-properties",
31 url: "https://git.io/vb4yQ"
32 },
33 transform: {
34 name: "@babel/plugin-proposal-private-methods",
35 url: "https://git.io/JvpRG"
36 }
37 },
38 classStaticBlock: {
39 syntax: {
40 name: "@babel/plugin-syntax-class-static-block",
41 url: "https://git.io/JTLB6"
42 },
43 transform: {
44 name: "@babel/plugin-proposal-class-static-block",
45 url: "https://git.io/JTLBP"
46 }
47 },
48 decimal: {
49 syntax: {
50 name: "@babel/plugin-syntax-decimal",
51 url: "https://git.io/JfKOH"
52 }
53 },
54 decorators: {
55 syntax: {
56 name: "@babel/plugin-syntax-decorators",
57 url: "https://git.io/vb4y9"
58 },
59 transform: {
60 name: "@babel/plugin-proposal-decorators",
61 url: "https://git.io/vb4ST"
62 }
63 },
64 doExpressions: {
65 syntax: {
66 name: "@babel/plugin-syntax-do-expressions",
67 url: "https://git.io/vb4yh"
68 },
69 transform: {
70 name: "@babel/plugin-proposal-do-expressions",
71 url: "https://git.io/vb4S3"
72 }
73 },
74 dynamicImport: {
75 syntax: {
76 name: "@babel/plugin-syntax-dynamic-import",
77 url: "https://git.io/vb4Sv"
78 }
79 },
80 exportDefaultFrom: {
81 syntax: {
82 name: "@babel/plugin-syntax-export-default-from",
83 url: "https://git.io/vb4SO"
84 },
85 transform: {
86 name: "@babel/plugin-proposal-export-default-from",
87 url: "https://git.io/vb4yH"
88 }
89 },
90 exportNamespaceFrom: {
91 syntax: {
92 name: "@babel/plugin-syntax-export-namespace-from",
93 url: "https://git.io/vb4Sf"
94 },
95 transform: {
96 name: "@babel/plugin-proposal-export-namespace-from",
97 url: "https://git.io/vb4SG"
98 }
99 },
100 flow: {
101 syntax: {
102 name: "@babel/plugin-syntax-flow",
103 url: "https://git.io/vb4yb"
104 },
105 transform: {
106 name: "@babel/preset-flow",
107 url: "https://git.io/JfeDn"
108 }
109 },
110 functionBind: {
111 syntax: {
112 name: "@babel/plugin-syntax-function-bind",
113 url: "https://git.io/vb4y7"
114 },
115 transform: {
116 name: "@babel/plugin-proposal-function-bind",
117 url: "https://git.io/vb4St"
118 }
119 },
120 functionSent: {
121 syntax: {
122 name: "@babel/plugin-syntax-function-sent",
123 url: "https://git.io/vb4yN"
124 },
125 transform: {
126 name: "@babel/plugin-proposal-function-sent",
127 url: "https://git.io/vb4SZ"
128 }
129 },
130 importMeta: {
131 syntax: {
132 name: "@babel/plugin-syntax-import-meta",
133 url: "https://git.io/vbKK6"
134 }
135 },
136 jsx: {
137 syntax: {
138 name: "@babel/plugin-syntax-jsx",
139 url: "https://git.io/vb4yA"
140 },
141 transform: {
142 name: "@babel/preset-react",
143 url: "https://git.io/JfeDR"
144 }
145 },
146 importAssertions: {
147 syntax: {
148 name: "@babel/plugin-syntax-import-assertions",
149 url: "https://git.io/JUbkv"
150 }
151 },
152 moduleStringNames: {
153 syntax: {
154 name: "@babel/plugin-syntax-module-string-names",
155 url: "https://git.io/JTL8G"
156 }
157 },
158 numericSeparator: {
159 syntax: {
160 name: "@babel/plugin-syntax-numeric-separator",
161 url: "https://git.io/vb4Sq"
162 },
163 transform: {
164 name: "@babel/plugin-proposal-numeric-separator",
165 url: "https://git.io/vb4yS"
166 }
167 },
168 optionalChaining: {
169 syntax: {
170 name: "@babel/plugin-syntax-optional-chaining",
171 url: "https://git.io/vb4Sc"
172 },
173 transform: {
174 name: "@babel/plugin-proposal-optional-chaining",
175 url: "https://git.io/vb4Sk"
176 }
177 },
178 pipelineOperator: {
179 syntax: {
180 name: "@babel/plugin-syntax-pipeline-operator",
181 url: "https://git.io/vb4yj"
182 },
183 transform: {
184 name: "@babel/plugin-proposal-pipeline-operator",
185 url: "https://git.io/vb4SU"
186 }
187 },
188 privateIn: {
189 syntax: {
190 name: "@babel/plugin-syntax-private-property-in-object",
191 url: "https://git.io/JfK3q"
192 },
193 transform: {
194 name: "@babel/plugin-proposal-private-property-in-object",
195 url: "https://git.io/JfK3O"
196 }
197 },
198 recordAndTuple: {
199 syntax: {
200 name: "@babel/plugin-syntax-record-and-tuple",
201 url: "https://git.io/JvKp3"
202 }
203 },
204 throwExpressions: {
205 syntax: {
206 name: "@babel/plugin-syntax-throw-expressions",
207 url: "https://git.io/vb4SJ"
208 },
209 transform: {
210 name: "@babel/plugin-proposal-throw-expressions",
211 url: "https://git.io/vb4yF"
212 }
213 },
214 typescript: {
215 syntax: {
216 name: "@babel/plugin-syntax-typescript",
217 url: "https://git.io/vb4SC"
218 },
219 transform: {
220 name: "@babel/preset-typescript",
221 url: "https://git.io/JfeDz"
222 }
223 },
224 asyncGenerators: {
225 syntax: {
226 name: "@babel/plugin-syntax-async-generators",
227 url: "https://git.io/vb4SY"
228 },
229 transform: {
230 name: "@babel/plugin-proposal-async-generator-functions",
231 url: "https://git.io/vb4yp"
232 }
233 },
234 logicalAssignment: {
235 syntax: {
236 name: "@babel/plugin-syntax-logical-assignment-operators",
237 url: "https://git.io/vAlBp"
238 },
239 transform: {
240 name: "@babel/plugin-proposal-logical-assignment-operators",
241 url: "https://git.io/vAlRe"
242 }
243 },
244 nullishCoalescingOperator: {
245 syntax: {
246 name: "@babel/plugin-syntax-nullish-coalescing-operator",
247 url: "https://git.io/vb4yx"
248 },
249 transform: {
250 name: "@babel/plugin-proposal-nullish-coalescing-operator",
251 url: "https://git.io/vb4Se"
252 }
253 },
254 objectRestSpread: {
255 syntax: {
256 name: "@babel/plugin-syntax-object-rest-spread",
257 url: "https://git.io/vb4y5"
258 },
259 transform: {
260 name: "@babel/plugin-proposal-object-rest-spread",
261 url: "https://git.io/vb4Ss"
262 }
263 },
264 optionalCatchBinding: {
265 syntax: {
266 name: "@babel/plugin-syntax-optional-catch-binding",
267 url: "https://git.io/vb4Sn"
268 },
269 transform: {
270 name: "@babel/plugin-proposal-optional-catch-binding",
271 url: "https://git.io/vb4SI"
272 }
273 }
274};
275pluginNameMap.privateIn.syntax = pluginNameMap.privateIn.transform;
276
277const getNameURLCombination = ({
278 name,
279 url
280}) => `${name} (${url})`;
281
282function generateMissingPluginMessage(missingPluginName, loc, codeFrame) {
283 let helpMessage = `Support for the experimental syntax '${missingPluginName}' isn't currently enabled ` + `(${loc.line}:${loc.column + 1}):\n\n` + codeFrame;
284 const pluginInfo = pluginNameMap[missingPluginName];
285
286 if (pluginInfo) {
287 const {
288 syntax: syntaxPlugin,
289 transform: transformPlugin
290 } = pluginInfo;
291
292 if (syntaxPlugin) {
293 const syntaxPluginInfo = getNameURLCombination(syntaxPlugin);
294
295 if (transformPlugin) {
296 const transformPluginInfo = getNameURLCombination(transformPlugin);
297 const sectionType = transformPlugin.name.startsWith("@babel/plugin") ? "plugins" : "presets";
298 helpMessage += `\n\nAdd ${transformPluginInfo} to the '${sectionType}' section of your Babel config to enable transformation.
299If you want to leave it as-is, add ${syntaxPluginInfo} to the 'plugins' section to enable parsing.`;
300 } else {
301 helpMessage += `\n\nAdd ${syntaxPluginInfo} to the 'plugins' section of your Babel config ` + `to enable parsing.`;
302 }
303 }
304 }
305
306 return helpMessage;
307}
\No newline at end of file