@dcf-micro/eslint-config 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/eslint-plugin-prettier.mjs +1716 -0
- package/dist/chunks/index.mjs +1341 -0
- package/dist/chunks/index10.mjs +39595 -0
- package/dist/chunks/index11.mjs +24 -0
- package/dist/chunks/index12.mjs +75273 -0
- package/dist/chunks/index13.mjs +55129 -0
- package/dist/chunks/index14.mjs +24 -0
- package/dist/chunks/index15.mjs +1441 -0
- package/dist/chunks/index2.mjs +31864 -0
- package/dist/chunks/index3.mjs +8154 -0
- package/dist/chunks/index4.mjs +24 -0
- package/dist/chunks/index5.mjs +44093 -0
- package/dist/chunks/index6.mjs +10371 -0
- package/dist/chunks/index7.mjs +21890 -0
- package/dist/chunks/index8.mjs +14424 -0
- package/dist/chunks/index9.mjs +194 -0
- package/dist/chunks/jiti.mjs +320 -0
- package/dist/index.d.mts +3897 -0
- package/dist/index.d.ts +3897 -0
- package/dist/index.mjs +4 -0
- package/dist/shared/eslint-config.BDBLGvXj.mjs +5282 -0
- package/dist/shared/eslint-config.BEdqg1el.mjs +12256 -0
- package/dist/shared/eslint-config.BKmXKm8B.mjs +5533 -0
- package/dist/shared/eslint-config.BjUMgISS.mjs +9012 -0
- package/dist/shared/eslint-config.Bk-3rH6Y.mjs +1355 -0
- package/dist/shared/eslint-config.BytuZ0Ec.mjs +20 -0
- package/dist/shared/eslint-config.C1V0I4Np.mjs +16900 -0
- package/dist/shared/eslint-config.CGxZQKHV.mjs +2091 -0
- package/dist/shared/eslint-config.COweQ1RR.mjs +5 -0
- package/dist/shared/eslint-config.CSnk9Q4w.mjs +9339 -0
- package/dist/shared/eslint-config.CWvTq0mr.mjs +2914 -0
- package/dist/shared/eslint-config.Ca4PTK8E.mjs +646 -0
- package/dist/shared/eslint-config.CmPTszkJ.mjs +3583 -0
- package/dist/shared/eslint-config.CqEANaNA.mjs +139622 -0
- package/dist/shared/eslint-config.CsePEcYJ.mjs +71 -0
- package/dist/shared/eslint-config.Cw6mETSZ.mjs +2580 -0
- package/dist/shared/eslint-config.DTVnsecK.mjs +1751 -0
- package/dist/shared/eslint-config.DWoU09EE.mjs +6958 -0
- package/dist/shared/eslint-config.DZvqTQUU.mjs +3818 -0
- package/dist/shared/eslint-config.Dhg7lT0g.mjs +1807 -0
- package/dist/shared/eslint-config.Du5y5qmf.mjs +200673 -0
- package/dist/shared/eslint-config.FKVuBSa4.mjs +394 -0
- package/dist/shared/eslint-config.I8d-HnmI.mjs +2654 -0
- package/dist/shared/eslint-config.YntqsQY1.mjs +40 -0
- package/dist/shared/eslint-config.uGTBNMD0.mjs +687 -0
- package/package.json +56 -0
|
@@ -0,0 +1,1355 @@
|
|
|
1
|
+
import { a as requireAcorn, r as requireAcornJsx } from './eslint-config.DWoU09EE.mjs';
|
|
2
|
+
|
|
3
|
+
var espree = {};
|
|
4
|
+
|
|
5
|
+
var eslintVisitorKeys = {};
|
|
6
|
+
|
|
7
|
+
var hasRequiredEslintVisitorKeys;
|
|
8
|
+
|
|
9
|
+
function requireEslintVisitorKeys () {
|
|
10
|
+
if (hasRequiredEslintVisitorKeys) return eslintVisitorKeys;
|
|
11
|
+
hasRequiredEslintVisitorKeys = 1;
|
|
12
|
+
|
|
13
|
+
/* eslint-disable jsdoc/valid-types -- doesn't allow `readonly`.
|
|
14
|
+
TODO: remove eslint-disable when https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/164 is fixed
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {{ readonly [type: string]: ReadonlyArray<string> }} VisitorKeys
|
|
18
|
+
*/
|
|
19
|
+
/* eslint-enable jsdoc/valid-types -- doesn't allow `readonly string[]`. TODO: check why */
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @type {VisitorKeys}
|
|
23
|
+
*/
|
|
24
|
+
const KEYS = {
|
|
25
|
+
ArrayExpression: [
|
|
26
|
+
"elements"
|
|
27
|
+
],
|
|
28
|
+
ArrayPattern: [
|
|
29
|
+
"elements"
|
|
30
|
+
],
|
|
31
|
+
ArrowFunctionExpression: [
|
|
32
|
+
"params",
|
|
33
|
+
"body"
|
|
34
|
+
],
|
|
35
|
+
AssignmentExpression: [
|
|
36
|
+
"left",
|
|
37
|
+
"right"
|
|
38
|
+
],
|
|
39
|
+
AssignmentPattern: [
|
|
40
|
+
"left",
|
|
41
|
+
"right"
|
|
42
|
+
],
|
|
43
|
+
AwaitExpression: [
|
|
44
|
+
"argument"
|
|
45
|
+
],
|
|
46
|
+
BinaryExpression: [
|
|
47
|
+
"left",
|
|
48
|
+
"right"
|
|
49
|
+
],
|
|
50
|
+
BlockStatement: [
|
|
51
|
+
"body"
|
|
52
|
+
],
|
|
53
|
+
BreakStatement: [
|
|
54
|
+
"label"
|
|
55
|
+
],
|
|
56
|
+
CallExpression: [
|
|
57
|
+
"callee",
|
|
58
|
+
"arguments"
|
|
59
|
+
],
|
|
60
|
+
CatchClause: [
|
|
61
|
+
"param",
|
|
62
|
+
"body"
|
|
63
|
+
],
|
|
64
|
+
ChainExpression: [
|
|
65
|
+
"expression"
|
|
66
|
+
],
|
|
67
|
+
ClassBody: [
|
|
68
|
+
"body"
|
|
69
|
+
],
|
|
70
|
+
ClassDeclaration: [
|
|
71
|
+
"id",
|
|
72
|
+
"superClass",
|
|
73
|
+
"body"
|
|
74
|
+
],
|
|
75
|
+
ClassExpression: [
|
|
76
|
+
"id",
|
|
77
|
+
"superClass",
|
|
78
|
+
"body"
|
|
79
|
+
],
|
|
80
|
+
ConditionalExpression: [
|
|
81
|
+
"test",
|
|
82
|
+
"consequent",
|
|
83
|
+
"alternate"
|
|
84
|
+
],
|
|
85
|
+
ContinueStatement: [
|
|
86
|
+
"label"
|
|
87
|
+
],
|
|
88
|
+
DebuggerStatement: [],
|
|
89
|
+
DoWhileStatement: [
|
|
90
|
+
"body",
|
|
91
|
+
"test"
|
|
92
|
+
],
|
|
93
|
+
EmptyStatement: [],
|
|
94
|
+
ExperimentalRestProperty: [
|
|
95
|
+
"argument"
|
|
96
|
+
],
|
|
97
|
+
ExperimentalSpreadProperty: [
|
|
98
|
+
"argument"
|
|
99
|
+
],
|
|
100
|
+
ExportAllDeclaration: [
|
|
101
|
+
"exported",
|
|
102
|
+
"source",
|
|
103
|
+
"attributes"
|
|
104
|
+
],
|
|
105
|
+
ExportDefaultDeclaration: [
|
|
106
|
+
"declaration"
|
|
107
|
+
],
|
|
108
|
+
ExportNamedDeclaration: [
|
|
109
|
+
"declaration",
|
|
110
|
+
"specifiers",
|
|
111
|
+
"source",
|
|
112
|
+
"attributes"
|
|
113
|
+
],
|
|
114
|
+
ExportSpecifier: [
|
|
115
|
+
"exported",
|
|
116
|
+
"local"
|
|
117
|
+
],
|
|
118
|
+
ExpressionStatement: [
|
|
119
|
+
"expression"
|
|
120
|
+
],
|
|
121
|
+
ForInStatement: [
|
|
122
|
+
"left",
|
|
123
|
+
"right",
|
|
124
|
+
"body"
|
|
125
|
+
],
|
|
126
|
+
ForOfStatement: [
|
|
127
|
+
"left",
|
|
128
|
+
"right",
|
|
129
|
+
"body"
|
|
130
|
+
],
|
|
131
|
+
ForStatement: [
|
|
132
|
+
"init",
|
|
133
|
+
"test",
|
|
134
|
+
"update",
|
|
135
|
+
"body"
|
|
136
|
+
],
|
|
137
|
+
FunctionDeclaration: [
|
|
138
|
+
"id",
|
|
139
|
+
"params",
|
|
140
|
+
"body"
|
|
141
|
+
],
|
|
142
|
+
FunctionExpression: [
|
|
143
|
+
"id",
|
|
144
|
+
"params",
|
|
145
|
+
"body"
|
|
146
|
+
],
|
|
147
|
+
Identifier: [],
|
|
148
|
+
IfStatement: [
|
|
149
|
+
"test",
|
|
150
|
+
"consequent",
|
|
151
|
+
"alternate"
|
|
152
|
+
],
|
|
153
|
+
ImportAttribute: [
|
|
154
|
+
"key",
|
|
155
|
+
"value"
|
|
156
|
+
],
|
|
157
|
+
ImportDeclaration: [
|
|
158
|
+
"specifiers",
|
|
159
|
+
"source",
|
|
160
|
+
"attributes"
|
|
161
|
+
],
|
|
162
|
+
ImportDefaultSpecifier: [
|
|
163
|
+
"local"
|
|
164
|
+
],
|
|
165
|
+
ImportExpression: [
|
|
166
|
+
"source",
|
|
167
|
+
"options"
|
|
168
|
+
],
|
|
169
|
+
ImportNamespaceSpecifier: [
|
|
170
|
+
"local"
|
|
171
|
+
],
|
|
172
|
+
ImportSpecifier: [
|
|
173
|
+
"imported",
|
|
174
|
+
"local"
|
|
175
|
+
],
|
|
176
|
+
JSXAttribute: [
|
|
177
|
+
"name",
|
|
178
|
+
"value"
|
|
179
|
+
],
|
|
180
|
+
JSXClosingElement: [
|
|
181
|
+
"name"
|
|
182
|
+
],
|
|
183
|
+
JSXClosingFragment: [],
|
|
184
|
+
JSXElement: [
|
|
185
|
+
"openingElement",
|
|
186
|
+
"children",
|
|
187
|
+
"closingElement"
|
|
188
|
+
],
|
|
189
|
+
JSXEmptyExpression: [],
|
|
190
|
+
JSXExpressionContainer: [
|
|
191
|
+
"expression"
|
|
192
|
+
],
|
|
193
|
+
JSXFragment: [
|
|
194
|
+
"openingFragment",
|
|
195
|
+
"children",
|
|
196
|
+
"closingFragment"
|
|
197
|
+
],
|
|
198
|
+
JSXIdentifier: [],
|
|
199
|
+
JSXMemberExpression: [
|
|
200
|
+
"object",
|
|
201
|
+
"property"
|
|
202
|
+
],
|
|
203
|
+
JSXNamespacedName: [
|
|
204
|
+
"namespace",
|
|
205
|
+
"name"
|
|
206
|
+
],
|
|
207
|
+
JSXOpeningElement: [
|
|
208
|
+
"name",
|
|
209
|
+
"attributes"
|
|
210
|
+
],
|
|
211
|
+
JSXOpeningFragment: [],
|
|
212
|
+
JSXSpreadAttribute: [
|
|
213
|
+
"argument"
|
|
214
|
+
],
|
|
215
|
+
JSXSpreadChild: [
|
|
216
|
+
"expression"
|
|
217
|
+
],
|
|
218
|
+
JSXText: [],
|
|
219
|
+
LabeledStatement: [
|
|
220
|
+
"label",
|
|
221
|
+
"body"
|
|
222
|
+
],
|
|
223
|
+
Literal: [],
|
|
224
|
+
LogicalExpression: [
|
|
225
|
+
"left",
|
|
226
|
+
"right"
|
|
227
|
+
],
|
|
228
|
+
MemberExpression: [
|
|
229
|
+
"object",
|
|
230
|
+
"property"
|
|
231
|
+
],
|
|
232
|
+
MetaProperty: [
|
|
233
|
+
"meta",
|
|
234
|
+
"property"
|
|
235
|
+
],
|
|
236
|
+
MethodDefinition: [
|
|
237
|
+
"key",
|
|
238
|
+
"value"
|
|
239
|
+
],
|
|
240
|
+
NewExpression: [
|
|
241
|
+
"callee",
|
|
242
|
+
"arguments"
|
|
243
|
+
],
|
|
244
|
+
ObjectExpression: [
|
|
245
|
+
"properties"
|
|
246
|
+
],
|
|
247
|
+
ObjectPattern: [
|
|
248
|
+
"properties"
|
|
249
|
+
],
|
|
250
|
+
PrivateIdentifier: [],
|
|
251
|
+
Program: [
|
|
252
|
+
"body"
|
|
253
|
+
],
|
|
254
|
+
Property: [
|
|
255
|
+
"key",
|
|
256
|
+
"value"
|
|
257
|
+
],
|
|
258
|
+
PropertyDefinition: [
|
|
259
|
+
"key",
|
|
260
|
+
"value"
|
|
261
|
+
],
|
|
262
|
+
RestElement: [
|
|
263
|
+
"argument"
|
|
264
|
+
],
|
|
265
|
+
ReturnStatement: [
|
|
266
|
+
"argument"
|
|
267
|
+
],
|
|
268
|
+
SequenceExpression: [
|
|
269
|
+
"expressions"
|
|
270
|
+
],
|
|
271
|
+
SpreadElement: [
|
|
272
|
+
"argument"
|
|
273
|
+
],
|
|
274
|
+
StaticBlock: [
|
|
275
|
+
"body"
|
|
276
|
+
],
|
|
277
|
+
Super: [],
|
|
278
|
+
SwitchCase: [
|
|
279
|
+
"test",
|
|
280
|
+
"consequent"
|
|
281
|
+
],
|
|
282
|
+
SwitchStatement: [
|
|
283
|
+
"discriminant",
|
|
284
|
+
"cases"
|
|
285
|
+
],
|
|
286
|
+
TaggedTemplateExpression: [
|
|
287
|
+
"tag",
|
|
288
|
+
"quasi"
|
|
289
|
+
],
|
|
290
|
+
TemplateElement: [],
|
|
291
|
+
TemplateLiteral: [
|
|
292
|
+
"quasis",
|
|
293
|
+
"expressions"
|
|
294
|
+
],
|
|
295
|
+
ThisExpression: [],
|
|
296
|
+
ThrowStatement: [
|
|
297
|
+
"argument"
|
|
298
|
+
],
|
|
299
|
+
TryStatement: [
|
|
300
|
+
"block",
|
|
301
|
+
"handler",
|
|
302
|
+
"finalizer"
|
|
303
|
+
],
|
|
304
|
+
UnaryExpression: [
|
|
305
|
+
"argument"
|
|
306
|
+
],
|
|
307
|
+
UpdateExpression: [
|
|
308
|
+
"argument"
|
|
309
|
+
],
|
|
310
|
+
VariableDeclaration: [
|
|
311
|
+
"declarations"
|
|
312
|
+
],
|
|
313
|
+
VariableDeclarator: [
|
|
314
|
+
"id",
|
|
315
|
+
"init"
|
|
316
|
+
],
|
|
317
|
+
WhileStatement: [
|
|
318
|
+
"test",
|
|
319
|
+
"body"
|
|
320
|
+
],
|
|
321
|
+
WithStatement: [
|
|
322
|
+
"object",
|
|
323
|
+
"body"
|
|
324
|
+
],
|
|
325
|
+
YieldExpression: [
|
|
326
|
+
"argument"
|
|
327
|
+
]
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
// Types.
|
|
331
|
+
const NODE_TYPES = Object.keys(KEYS);
|
|
332
|
+
|
|
333
|
+
// Freeze the keys.
|
|
334
|
+
for (const type of NODE_TYPES) {
|
|
335
|
+
Object.freeze(KEYS[type]);
|
|
336
|
+
}
|
|
337
|
+
Object.freeze(KEYS);
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* @author Toru Nagashima <https://github.com/mysticatea>
|
|
341
|
+
* See LICENSE file in root directory for full license.
|
|
342
|
+
*/
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* @typedef {import('./visitor-keys.js').VisitorKeys} VisitorKeys
|
|
346
|
+
*/
|
|
347
|
+
|
|
348
|
+
// List to ignore keys.
|
|
349
|
+
const KEY_BLACKLIST = new Set([
|
|
350
|
+
"parent",
|
|
351
|
+
"leadingComments",
|
|
352
|
+
"trailingComments"
|
|
353
|
+
]);
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Check whether a given key should be used or not.
|
|
357
|
+
* @param {string} key The key to check.
|
|
358
|
+
* @returns {boolean} `true` if the key should be used.
|
|
359
|
+
*/
|
|
360
|
+
function filterKey(key) {
|
|
361
|
+
return !KEY_BLACKLIST.has(key) && key[0] !== "_";
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
/* eslint-disable jsdoc/valid-types -- doesn't allow `readonly`.
|
|
366
|
+
TODO: remove eslint-disable when https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/164 is fixed
|
|
367
|
+
*/
|
|
368
|
+
/**
|
|
369
|
+
* Get visitor keys of a given node.
|
|
370
|
+
* @param {Object} node The AST node to get keys.
|
|
371
|
+
* @returns {readonly string[]} Visitor keys of the node.
|
|
372
|
+
*/
|
|
373
|
+
function getKeys(node) {
|
|
374
|
+
return Object.keys(node).filter(filterKey);
|
|
375
|
+
}
|
|
376
|
+
/* eslint-enable jsdoc/valid-types -- doesn't allow `readonly` */
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Make the union set with `KEYS` and given keys.
|
|
380
|
+
* @param {VisitorKeys} additionalKeys The additional keys.
|
|
381
|
+
* @returns {VisitorKeys} The union set.
|
|
382
|
+
*/
|
|
383
|
+
function unionWith(additionalKeys) {
|
|
384
|
+
const retv = /** @type {{ [type: string]: ReadonlyArray<string> }} */
|
|
385
|
+
(Object.assign({}, KEYS));
|
|
386
|
+
|
|
387
|
+
for (const type of Object.keys(additionalKeys)) {
|
|
388
|
+
if (Object.hasOwn(retv, type)) {
|
|
389
|
+
const keys = new Set(additionalKeys[type]);
|
|
390
|
+
|
|
391
|
+
for (const key of retv[type]) {
|
|
392
|
+
keys.add(key);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
retv[type] = Object.freeze(Array.from(keys));
|
|
396
|
+
} else {
|
|
397
|
+
retv[type] = Object.freeze(Array.from(additionalKeys[type]));
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
return Object.freeze(retv);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
eslintVisitorKeys.KEYS = KEYS;
|
|
405
|
+
eslintVisitorKeys.getKeys = getKeys;
|
|
406
|
+
eslintVisitorKeys.unionWith = unionWith;
|
|
407
|
+
return eslintVisitorKeys;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
var hasRequiredEspree;
|
|
411
|
+
|
|
412
|
+
function requireEspree () {
|
|
413
|
+
if (hasRequiredEspree) return espree;
|
|
414
|
+
hasRequiredEspree = 1;
|
|
415
|
+
|
|
416
|
+
Object.defineProperty(espree, '__esModule', { value: true });
|
|
417
|
+
|
|
418
|
+
var acorn = requireAcorn();
|
|
419
|
+
var jsx = requireAcornJsx();
|
|
420
|
+
var visitorKeys = requireEslintVisitorKeys();
|
|
421
|
+
|
|
422
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
423
|
+
|
|
424
|
+
function _interopNamespace(e) {
|
|
425
|
+
if (e && e.__esModule) return e;
|
|
426
|
+
var n = Object.create(null);
|
|
427
|
+
if (e) {
|
|
428
|
+
Object.keys(e).forEach(function (k) {
|
|
429
|
+
if (k !== 'default') {
|
|
430
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
431
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
432
|
+
enumerable: true,
|
|
433
|
+
get: function () { return e[k]; }
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
n["default"] = e;
|
|
439
|
+
return Object.freeze(n);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
var acorn__namespace = /*#__PURE__*/_interopNamespace(acorn);
|
|
443
|
+
var jsx__default = /*#__PURE__*/_interopDefaultLegacy(jsx);
|
|
444
|
+
var visitorKeys__namespace = /*#__PURE__*/_interopNamespace(visitorKeys);
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* @fileoverview Translates tokens between Acorn format and Esprima format.
|
|
448
|
+
* @author Nicholas C. Zakas
|
|
449
|
+
*/
|
|
450
|
+
|
|
451
|
+
//------------------------------------------------------------------------------
|
|
452
|
+
// Requirements
|
|
453
|
+
//------------------------------------------------------------------------------
|
|
454
|
+
|
|
455
|
+
// none!
|
|
456
|
+
|
|
457
|
+
//------------------------------------------------------------------------------
|
|
458
|
+
// Private
|
|
459
|
+
//------------------------------------------------------------------------------
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
// Esprima Token Types
|
|
463
|
+
const Token = {
|
|
464
|
+
Boolean: "Boolean",
|
|
465
|
+
Identifier: "Identifier",
|
|
466
|
+
PrivateIdentifier: "PrivateIdentifier",
|
|
467
|
+
Keyword: "Keyword",
|
|
468
|
+
Null: "Null",
|
|
469
|
+
Numeric: "Numeric",
|
|
470
|
+
Punctuator: "Punctuator",
|
|
471
|
+
String: "String",
|
|
472
|
+
RegularExpression: "RegularExpression",
|
|
473
|
+
Template: "Template",
|
|
474
|
+
JSXIdentifier: "JSXIdentifier",
|
|
475
|
+
JSXText: "JSXText"
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Converts part of a template into an Esprima token.
|
|
480
|
+
* @param {AcornToken[]} tokens The Acorn tokens representing the template.
|
|
481
|
+
* @param {string} code The source code.
|
|
482
|
+
* @returns {EsprimaToken} The Esprima equivalent of the template token.
|
|
483
|
+
* @private
|
|
484
|
+
*/
|
|
485
|
+
function convertTemplatePart(tokens, code) {
|
|
486
|
+
const firstToken = tokens[0],
|
|
487
|
+
lastTemplateToken = tokens.at(-1);
|
|
488
|
+
|
|
489
|
+
const token = {
|
|
490
|
+
type: Token.Template,
|
|
491
|
+
value: code.slice(firstToken.start, lastTemplateToken.end)
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
if (firstToken.loc) {
|
|
495
|
+
token.loc = {
|
|
496
|
+
start: firstToken.loc.start,
|
|
497
|
+
end: lastTemplateToken.loc.end
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
if (firstToken.range) {
|
|
502
|
+
token.start = firstToken.range[0];
|
|
503
|
+
token.end = lastTemplateToken.range[1];
|
|
504
|
+
token.range = [token.start, token.end];
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
return token;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Contains logic to translate Acorn tokens into Esprima tokens.
|
|
512
|
+
* @param {Object} acornTokTypes The Acorn token types.
|
|
513
|
+
* @param {string} code The source code Acorn is parsing. This is necessary
|
|
514
|
+
* to correct the "value" property of some tokens.
|
|
515
|
+
* @constructor
|
|
516
|
+
*/
|
|
517
|
+
function TokenTranslator(acornTokTypes, code) {
|
|
518
|
+
|
|
519
|
+
// token types
|
|
520
|
+
this._acornTokTypes = acornTokTypes;
|
|
521
|
+
|
|
522
|
+
// token buffer for templates
|
|
523
|
+
this._tokens = [];
|
|
524
|
+
|
|
525
|
+
// track the last curly brace
|
|
526
|
+
this._curlyBrace = null;
|
|
527
|
+
|
|
528
|
+
// the source code
|
|
529
|
+
this._code = code;
|
|
530
|
+
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
TokenTranslator.prototype = {
|
|
534
|
+
constructor: TokenTranslator,
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Translates a single Esprima token to a single Acorn token. This may be
|
|
538
|
+
* inaccurate due to how templates are handled differently in Esprima and
|
|
539
|
+
* Acorn, but should be accurate for all other tokens.
|
|
540
|
+
* @param {AcornToken} token The Acorn token to translate.
|
|
541
|
+
* @param {Object} extra Espree extra object.
|
|
542
|
+
* @returns {EsprimaToken} The Esprima version of the token.
|
|
543
|
+
*/
|
|
544
|
+
translate(token, extra) {
|
|
545
|
+
|
|
546
|
+
const type = token.type,
|
|
547
|
+
tt = this._acornTokTypes;
|
|
548
|
+
|
|
549
|
+
if (type === tt.name) {
|
|
550
|
+
token.type = Token.Identifier;
|
|
551
|
+
|
|
552
|
+
// TODO: See if this is an Acorn bug
|
|
553
|
+
if (token.value === "static") {
|
|
554
|
+
token.type = Token.Keyword;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
if (extra.ecmaVersion > 5 && (token.value === "yield" || token.value === "let")) {
|
|
558
|
+
token.type = Token.Keyword;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
} else if (type === tt.privateId) {
|
|
562
|
+
token.type = Token.PrivateIdentifier;
|
|
563
|
+
|
|
564
|
+
} else if (type === tt.semi || type === tt.comma ||
|
|
565
|
+
type === tt.parenL || type === tt.parenR ||
|
|
566
|
+
type === tt.braceL || type === tt.braceR ||
|
|
567
|
+
type === tt.dot || type === tt.bracketL ||
|
|
568
|
+
type === tt.colon || type === tt.question ||
|
|
569
|
+
type === tt.bracketR || type === tt.ellipsis ||
|
|
570
|
+
type === tt.arrow || type === tt.jsxTagStart ||
|
|
571
|
+
type === tt.incDec || type === tt.starstar ||
|
|
572
|
+
type === tt.jsxTagEnd || type === tt.prefix ||
|
|
573
|
+
type === tt.questionDot ||
|
|
574
|
+
(type.binop && !type.keyword) ||
|
|
575
|
+
type.isAssign) {
|
|
576
|
+
|
|
577
|
+
token.type = Token.Punctuator;
|
|
578
|
+
token.value = this._code.slice(token.start, token.end);
|
|
579
|
+
} else if (type === tt.jsxName) {
|
|
580
|
+
token.type = Token.JSXIdentifier;
|
|
581
|
+
} else if (type.label === "jsxText" || type === tt.jsxAttrValueToken) {
|
|
582
|
+
token.type = Token.JSXText;
|
|
583
|
+
} else if (type.keyword) {
|
|
584
|
+
if (type.keyword === "true" || type.keyword === "false") {
|
|
585
|
+
token.type = Token.Boolean;
|
|
586
|
+
} else if (type.keyword === "null") {
|
|
587
|
+
token.type = Token.Null;
|
|
588
|
+
} else {
|
|
589
|
+
token.type = Token.Keyword;
|
|
590
|
+
}
|
|
591
|
+
} else if (type === tt.num) {
|
|
592
|
+
token.type = Token.Numeric;
|
|
593
|
+
token.value = this._code.slice(token.start, token.end);
|
|
594
|
+
} else if (type === tt.string) {
|
|
595
|
+
|
|
596
|
+
if (extra.jsxAttrValueToken) {
|
|
597
|
+
extra.jsxAttrValueToken = false;
|
|
598
|
+
token.type = Token.JSXText;
|
|
599
|
+
} else {
|
|
600
|
+
token.type = Token.String;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
token.value = this._code.slice(token.start, token.end);
|
|
604
|
+
} else if (type === tt.regexp) {
|
|
605
|
+
token.type = Token.RegularExpression;
|
|
606
|
+
const value = token.value;
|
|
607
|
+
|
|
608
|
+
token.regex = {
|
|
609
|
+
flags: value.flags,
|
|
610
|
+
pattern: value.pattern
|
|
611
|
+
};
|
|
612
|
+
token.value = `/${value.pattern}/${value.flags}`;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
return token;
|
|
616
|
+
},
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* Function to call during Acorn's onToken handler.
|
|
620
|
+
* @param {AcornToken} token The Acorn token.
|
|
621
|
+
* @param {Object} extra The Espree extra object.
|
|
622
|
+
* @returns {void}
|
|
623
|
+
*/
|
|
624
|
+
onToken(token, extra) {
|
|
625
|
+
|
|
626
|
+
const tt = this._acornTokTypes,
|
|
627
|
+
tokens = extra.tokens,
|
|
628
|
+
templateTokens = this._tokens;
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* Flushes the buffered template tokens and resets the template
|
|
632
|
+
* tracking.
|
|
633
|
+
* @returns {void}
|
|
634
|
+
* @private
|
|
635
|
+
*/
|
|
636
|
+
const translateTemplateTokens = () => {
|
|
637
|
+
tokens.push(convertTemplatePart(this._tokens, this._code));
|
|
638
|
+
this._tokens = [];
|
|
639
|
+
};
|
|
640
|
+
|
|
641
|
+
if (token.type === tt.eof) {
|
|
642
|
+
|
|
643
|
+
// might be one last curlyBrace
|
|
644
|
+
if (this._curlyBrace) {
|
|
645
|
+
tokens.push(this.translate(this._curlyBrace, extra));
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
if (token.type === tt.backQuote) {
|
|
652
|
+
|
|
653
|
+
// if there's already a curly, it's not part of the template
|
|
654
|
+
if (this._curlyBrace) {
|
|
655
|
+
tokens.push(this.translate(this._curlyBrace, extra));
|
|
656
|
+
this._curlyBrace = null;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
templateTokens.push(token);
|
|
660
|
+
|
|
661
|
+
// it's the end
|
|
662
|
+
if (templateTokens.length > 1) {
|
|
663
|
+
translateTemplateTokens();
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
if (token.type === tt.dollarBraceL) {
|
|
669
|
+
templateTokens.push(token);
|
|
670
|
+
translateTemplateTokens();
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
if (token.type === tt.braceR) {
|
|
674
|
+
|
|
675
|
+
// if there's already a curly, it's not part of the template
|
|
676
|
+
if (this._curlyBrace) {
|
|
677
|
+
tokens.push(this.translate(this._curlyBrace, extra));
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
// store new curly for later
|
|
681
|
+
this._curlyBrace = token;
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
if (token.type === tt.template || token.type === tt.invalidTemplate) {
|
|
685
|
+
if (this._curlyBrace) {
|
|
686
|
+
templateTokens.push(this._curlyBrace);
|
|
687
|
+
this._curlyBrace = null;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
templateTokens.push(token);
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
if (this._curlyBrace) {
|
|
695
|
+
tokens.push(this.translate(this._curlyBrace, extra));
|
|
696
|
+
this._curlyBrace = null;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
tokens.push(this.translate(token, extra));
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
/**
|
|
704
|
+
* @fileoverview A collection of methods for processing Espree's options.
|
|
705
|
+
* @author Kai Cataldo
|
|
706
|
+
*/
|
|
707
|
+
|
|
708
|
+
//------------------------------------------------------------------------------
|
|
709
|
+
// Helpers
|
|
710
|
+
//------------------------------------------------------------------------------
|
|
711
|
+
|
|
712
|
+
const SUPPORTED_VERSIONS = [
|
|
713
|
+
3,
|
|
714
|
+
5,
|
|
715
|
+
6, // 2015
|
|
716
|
+
7, // 2016
|
|
717
|
+
8, // 2017
|
|
718
|
+
9, // 2018
|
|
719
|
+
10, // 2019
|
|
720
|
+
11, // 2020
|
|
721
|
+
12, // 2021
|
|
722
|
+
13, // 2022
|
|
723
|
+
14, // 2023
|
|
724
|
+
15, // 2024
|
|
725
|
+
16 // 2025
|
|
726
|
+
];
|
|
727
|
+
|
|
728
|
+
/**
|
|
729
|
+
* Get the latest ECMAScript version supported by Espree.
|
|
730
|
+
* @returns {number} The latest ECMAScript version.
|
|
731
|
+
*/
|
|
732
|
+
function getLatestEcmaVersion() {
|
|
733
|
+
return SUPPORTED_VERSIONS.at(-1);
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
/**
|
|
737
|
+
* Get the list of ECMAScript versions supported by Espree.
|
|
738
|
+
* @returns {number[]} An array containing the supported ECMAScript versions.
|
|
739
|
+
*/
|
|
740
|
+
function getSupportedEcmaVersions() {
|
|
741
|
+
return [...SUPPORTED_VERSIONS];
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
/**
|
|
745
|
+
* Normalize ECMAScript version from the initial config
|
|
746
|
+
* @param {(number|"latest")} ecmaVersion ECMAScript version from the initial config
|
|
747
|
+
* @throws {Error} throws an error if the ecmaVersion is invalid.
|
|
748
|
+
* @returns {number} normalized ECMAScript version
|
|
749
|
+
*/
|
|
750
|
+
function normalizeEcmaVersion(ecmaVersion = 5) {
|
|
751
|
+
|
|
752
|
+
let version = ecmaVersion === "latest" ? getLatestEcmaVersion() : ecmaVersion;
|
|
753
|
+
|
|
754
|
+
if (typeof version !== "number") {
|
|
755
|
+
throw new Error(`ecmaVersion must be a number or "latest". Received value of type ${typeof ecmaVersion} instead.`);
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// Calculate ECMAScript edition number from official year version starting with
|
|
759
|
+
// ES2015, which corresponds with ES6 (or a difference of 2009).
|
|
760
|
+
if (version >= 2015) {
|
|
761
|
+
version -= 2009;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
if (!SUPPORTED_VERSIONS.includes(version)) {
|
|
765
|
+
throw new Error("Invalid ecmaVersion.");
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
return version;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
/**
|
|
772
|
+
* Normalize sourceType from the initial config
|
|
773
|
+
* @param {string} sourceType to normalize
|
|
774
|
+
* @throws {Error} throw an error if sourceType is invalid
|
|
775
|
+
* @returns {string} normalized sourceType
|
|
776
|
+
*/
|
|
777
|
+
function normalizeSourceType(sourceType = "script") {
|
|
778
|
+
if (sourceType === "script" || sourceType === "module") {
|
|
779
|
+
return sourceType;
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
if (sourceType === "commonjs") {
|
|
783
|
+
return "script";
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
throw new Error("Invalid sourceType.");
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
/**
|
|
790
|
+
* Normalize parserOptions
|
|
791
|
+
* @param {Object} options the parser options to normalize
|
|
792
|
+
* @throws {Error} throw an error if found invalid option.
|
|
793
|
+
* @returns {Object} normalized options
|
|
794
|
+
*/
|
|
795
|
+
function normalizeOptions(options) {
|
|
796
|
+
const ecmaVersion = normalizeEcmaVersion(options.ecmaVersion);
|
|
797
|
+
const sourceType = normalizeSourceType(options.sourceType);
|
|
798
|
+
const ranges = options.range === true;
|
|
799
|
+
const locations = options.loc === true;
|
|
800
|
+
|
|
801
|
+
if (ecmaVersion !== 3 && options.allowReserved) {
|
|
802
|
+
|
|
803
|
+
// a value of `false` is intentionally allowed here, so a shared config can overwrite it when needed
|
|
804
|
+
throw new Error("`allowReserved` is only supported when ecmaVersion is 3");
|
|
805
|
+
}
|
|
806
|
+
if (typeof options.allowReserved !== "undefined" && typeof options.allowReserved !== "boolean") {
|
|
807
|
+
throw new Error("`allowReserved`, when present, must be `true` or `false`");
|
|
808
|
+
}
|
|
809
|
+
const allowReserved = ecmaVersion === 3 ? (options.allowReserved || "never") : false;
|
|
810
|
+
const ecmaFeatures = options.ecmaFeatures || {};
|
|
811
|
+
const allowReturnOutsideFunction = options.sourceType === "commonjs" ||
|
|
812
|
+
Boolean(ecmaFeatures.globalReturn);
|
|
813
|
+
|
|
814
|
+
if (sourceType === "module" && ecmaVersion < 6) {
|
|
815
|
+
throw new Error("sourceType 'module' is not supported when ecmaVersion < 2015. Consider adding `{ ecmaVersion: 2015 }` to the parser options.");
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
return Object.assign({}, options, {
|
|
819
|
+
ecmaVersion,
|
|
820
|
+
sourceType,
|
|
821
|
+
ranges,
|
|
822
|
+
locations,
|
|
823
|
+
allowReserved,
|
|
824
|
+
allowReturnOutsideFunction
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
/* eslint no-param-reassign: 0 -- stylistic choice */
|
|
829
|
+
|
|
830
|
+
|
|
831
|
+
const STATE = Symbol("espree's internal state");
|
|
832
|
+
const ESPRIMA_FINISH_NODE = Symbol("espree's esprimaFinishNode");
|
|
833
|
+
|
|
834
|
+
|
|
835
|
+
/**
|
|
836
|
+
* Converts an Acorn comment to a Esprima comment.
|
|
837
|
+
* @param {boolean} block True if it's a block comment, false if not.
|
|
838
|
+
* @param {string} text The text of the comment.
|
|
839
|
+
* @param {int} start The index at which the comment starts.
|
|
840
|
+
* @param {int} end The index at which the comment ends.
|
|
841
|
+
* @param {Location} startLoc The location at which the comment starts.
|
|
842
|
+
* @param {Location} endLoc The location at which the comment ends.
|
|
843
|
+
* @param {string} code The source code being parsed.
|
|
844
|
+
* @returns {Object} The comment object.
|
|
845
|
+
* @private
|
|
846
|
+
*/
|
|
847
|
+
function convertAcornCommentToEsprimaComment(block, text, start, end, startLoc, endLoc, code) {
|
|
848
|
+
let type;
|
|
849
|
+
|
|
850
|
+
if (block) {
|
|
851
|
+
type = "Block";
|
|
852
|
+
} else if (code.slice(start, start + 2) === "#!") {
|
|
853
|
+
type = "Hashbang";
|
|
854
|
+
} else {
|
|
855
|
+
type = "Line";
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
const comment = {
|
|
859
|
+
type,
|
|
860
|
+
value: text
|
|
861
|
+
};
|
|
862
|
+
|
|
863
|
+
if (typeof start === "number") {
|
|
864
|
+
comment.start = start;
|
|
865
|
+
comment.end = end;
|
|
866
|
+
comment.range = [start, end];
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
if (typeof startLoc === "object") {
|
|
870
|
+
comment.loc = {
|
|
871
|
+
start: startLoc,
|
|
872
|
+
end: endLoc
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
return comment;
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
var espree$1 = () => Parser => {
|
|
880
|
+
const tokTypes = Object.assign({}, Parser.acorn.tokTypes);
|
|
881
|
+
|
|
882
|
+
if (Parser.acornJsx) {
|
|
883
|
+
Object.assign(tokTypes, Parser.acornJsx.tokTypes);
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
return class Espree extends Parser {
|
|
887
|
+
constructor(opts, code) {
|
|
888
|
+
if (typeof opts !== "object" || opts === null) {
|
|
889
|
+
opts = {};
|
|
890
|
+
}
|
|
891
|
+
if (typeof code !== "string" && !(code instanceof String)) {
|
|
892
|
+
code = String(code);
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
// save original source type in case of commonjs
|
|
896
|
+
const originalSourceType = opts.sourceType;
|
|
897
|
+
const options = normalizeOptions(opts);
|
|
898
|
+
const ecmaFeatures = options.ecmaFeatures || {};
|
|
899
|
+
const tokenTranslator =
|
|
900
|
+
options.tokens === true
|
|
901
|
+
? new TokenTranslator(tokTypes, code)
|
|
902
|
+
: null;
|
|
903
|
+
|
|
904
|
+
/*
|
|
905
|
+
* Data that is unique to Espree and is not represented internally
|
|
906
|
+
* in Acorn.
|
|
907
|
+
*
|
|
908
|
+
* For ES2023 hashbangs, Espree will call `onComment()` during the
|
|
909
|
+
* constructor, so we must define state before having access to
|
|
910
|
+
* `this`.
|
|
911
|
+
*/
|
|
912
|
+
const state = {
|
|
913
|
+
originalSourceType: originalSourceType || options.sourceType,
|
|
914
|
+
tokens: tokenTranslator ? [] : null,
|
|
915
|
+
comments: options.comment === true ? [] : null,
|
|
916
|
+
impliedStrict: ecmaFeatures.impliedStrict === true && options.ecmaVersion >= 5,
|
|
917
|
+
ecmaVersion: options.ecmaVersion,
|
|
918
|
+
jsxAttrValueToken: false,
|
|
919
|
+
lastToken: null,
|
|
920
|
+
templateElements: []
|
|
921
|
+
};
|
|
922
|
+
|
|
923
|
+
// Initialize acorn parser.
|
|
924
|
+
super({
|
|
925
|
+
|
|
926
|
+
// do not use spread, because we don't want to pass any unknown options to acorn
|
|
927
|
+
ecmaVersion: options.ecmaVersion,
|
|
928
|
+
sourceType: options.sourceType,
|
|
929
|
+
ranges: options.ranges,
|
|
930
|
+
locations: options.locations,
|
|
931
|
+
allowReserved: options.allowReserved,
|
|
932
|
+
|
|
933
|
+
// Truthy value is true for backward compatibility.
|
|
934
|
+
allowReturnOutsideFunction: options.allowReturnOutsideFunction,
|
|
935
|
+
|
|
936
|
+
// Collect tokens
|
|
937
|
+
onToken(token) {
|
|
938
|
+
if (tokenTranslator) {
|
|
939
|
+
|
|
940
|
+
// Use `tokens`, `ecmaVersion`, and `jsxAttrValueToken` in the state.
|
|
941
|
+
tokenTranslator.onToken(token, state);
|
|
942
|
+
}
|
|
943
|
+
if (token.type !== tokTypes.eof) {
|
|
944
|
+
state.lastToken = token;
|
|
945
|
+
}
|
|
946
|
+
},
|
|
947
|
+
|
|
948
|
+
// Collect comments
|
|
949
|
+
onComment(block, text, start, end, startLoc, endLoc) {
|
|
950
|
+
if (state.comments) {
|
|
951
|
+
const comment = convertAcornCommentToEsprimaComment(block, text, start, end, startLoc, endLoc, code);
|
|
952
|
+
|
|
953
|
+
state.comments.push(comment);
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
}, code);
|
|
957
|
+
|
|
958
|
+
/*
|
|
959
|
+
* We put all of this data into a symbol property as a way to avoid
|
|
960
|
+
* potential naming conflicts with future versions of Acorn.
|
|
961
|
+
*/
|
|
962
|
+
this[STATE] = state;
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
tokenize() {
|
|
966
|
+
do {
|
|
967
|
+
this.next();
|
|
968
|
+
} while (this.type !== tokTypes.eof);
|
|
969
|
+
|
|
970
|
+
// Consume the final eof token
|
|
971
|
+
this.next();
|
|
972
|
+
|
|
973
|
+
const extra = this[STATE];
|
|
974
|
+
const tokens = extra.tokens;
|
|
975
|
+
|
|
976
|
+
if (extra.comments) {
|
|
977
|
+
tokens.comments = extra.comments;
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
return tokens;
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
finishNode(...args) {
|
|
984
|
+
const result = super.finishNode(...args);
|
|
985
|
+
|
|
986
|
+
return this[ESPRIMA_FINISH_NODE](result);
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
finishNodeAt(...args) {
|
|
990
|
+
const result = super.finishNodeAt(...args);
|
|
991
|
+
|
|
992
|
+
return this[ESPRIMA_FINISH_NODE](result);
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
parse() {
|
|
996
|
+
const extra = this[STATE];
|
|
997
|
+
const program = super.parse();
|
|
998
|
+
|
|
999
|
+
program.sourceType = extra.originalSourceType;
|
|
1000
|
+
|
|
1001
|
+
if (extra.comments) {
|
|
1002
|
+
program.comments = extra.comments;
|
|
1003
|
+
}
|
|
1004
|
+
if (extra.tokens) {
|
|
1005
|
+
program.tokens = extra.tokens;
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
/*
|
|
1009
|
+
* Adjust opening and closing position of program to match Esprima.
|
|
1010
|
+
* Acorn always starts programs at range 0 whereas Esprima starts at the
|
|
1011
|
+
* first AST node's start (the only real difference is when there's leading
|
|
1012
|
+
* whitespace or leading comments). Acorn also counts trailing whitespace
|
|
1013
|
+
* as part of the program whereas Esprima only counts up to the last token.
|
|
1014
|
+
*/
|
|
1015
|
+
if (program.body.length) {
|
|
1016
|
+
const [firstNode] = program.body;
|
|
1017
|
+
|
|
1018
|
+
if (program.range) {
|
|
1019
|
+
program.range[0] = firstNode.range[0];
|
|
1020
|
+
}
|
|
1021
|
+
if (program.loc) {
|
|
1022
|
+
program.loc.start = firstNode.loc.start;
|
|
1023
|
+
}
|
|
1024
|
+
program.start = firstNode.start;
|
|
1025
|
+
}
|
|
1026
|
+
if (extra.lastToken) {
|
|
1027
|
+
if (program.range) {
|
|
1028
|
+
program.range[1] = extra.lastToken.range[1];
|
|
1029
|
+
}
|
|
1030
|
+
if (program.loc) {
|
|
1031
|
+
program.loc.end = extra.lastToken.loc.end;
|
|
1032
|
+
}
|
|
1033
|
+
program.end = extra.lastToken.end;
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
|
|
1037
|
+
/*
|
|
1038
|
+
* https://github.com/eslint/espree/issues/349
|
|
1039
|
+
* Ensure that template elements have correct range information.
|
|
1040
|
+
* This is one location where Acorn produces a different value
|
|
1041
|
+
* for its start and end properties vs. the values present in the
|
|
1042
|
+
* range property. In order to avoid confusion, we set the start
|
|
1043
|
+
* and end properties to the values that are present in range.
|
|
1044
|
+
* This is done here, instead of in finishNode(), because Acorn
|
|
1045
|
+
* uses the values of start and end internally while parsing, making
|
|
1046
|
+
* it dangerous to change those values while parsing is ongoing.
|
|
1047
|
+
* By waiting until the end of parsing, we can safely change these
|
|
1048
|
+
* values without affect any other part of the process.
|
|
1049
|
+
*/
|
|
1050
|
+
this[STATE].templateElements.forEach(templateElement => {
|
|
1051
|
+
const startOffset = -1;
|
|
1052
|
+
const endOffset = templateElement.tail ? 1 : 2;
|
|
1053
|
+
|
|
1054
|
+
templateElement.start += startOffset;
|
|
1055
|
+
templateElement.end += endOffset;
|
|
1056
|
+
|
|
1057
|
+
if (templateElement.range) {
|
|
1058
|
+
templateElement.range[0] += startOffset;
|
|
1059
|
+
templateElement.range[1] += endOffset;
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
if (templateElement.loc) {
|
|
1063
|
+
templateElement.loc.start.column += startOffset;
|
|
1064
|
+
templateElement.loc.end.column += endOffset;
|
|
1065
|
+
}
|
|
1066
|
+
});
|
|
1067
|
+
|
|
1068
|
+
return program;
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
parseTopLevel(node) {
|
|
1072
|
+
if (this[STATE].impliedStrict) {
|
|
1073
|
+
this.strict = true;
|
|
1074
|
+
}
|
|
1075
|
+
return super.parseTopLevel(node);
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
/**
|
|
1079
|
+
* Overwrites the default raise method to throw Esprima-style errors.
|
|
1080
|
+
* @param {int} pos The position of the error.
|
|
1081
|
+
* @param {string} message The error message.
|
|
1082
|
+
* @throws {SyntaxError} A syntax error.
|
|
1083
|
+
* @returns {void}
|
|
1084
|
+
*/
|
|
1085
|
+
raise(pos, message) {
|
|
1086
|
+
const loc = Parser.acorn.getLineInfo(this.input, pos);
|
|
1087
|
+
const err = new SyntaxError(message);
|
|
1088
|
+
|
|
1089
|
+
err.index = pos;
|
|
1090
|
+
err.lineNumber = loc.line;
|
|
1091
|
+
err.column = loc.column + 1; // acorn uses 0-based columns
|
|
1092
|
+
throw err;
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
/**
|
|
1096
|
+
* Overwrites the default raise method to throw Esprima-style errors.
|
|
1097
|
+
* @param {int} pos The position of the error.
|
|
1098
|
+
* @param {string} message The error message.
|
|
1099
|
+
* @throws {SyntaxError} A syntax error.
|
|
1100
|
+
* @returns {void}
|
|
1101
|
+
*/
|
|
1102
|
+
raiseRecoverable(pos, message) {
|
|
1103
|
+
this.raise(pos, message);
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
/**
|
|
1107
|
+
* Overwrites the default unexpected method to throw Esprima-style errors.
|
|
1108
|
+
* @param {int} pos The position of the error.
|
|
1109
|
+
* @throws {SyntaxError} A syntax error.
|
|
1110
|
+
* @returns {void}
|
|
1111
|
+
*/
|
|
1112
|
+
unexpected(pos) {
|
|
1113
|
+
let message = "Unexpected token";
|
|
1114
|
+
|
|
1115
|
+
if (pos !== null && pos !== void 0) {
|
|
1116
|
+
this.pos = pos;
|
|
1117
|
+
|
|
1118
|
+
if (this.options.locations) {
|
|
1119
|
+
while (this.pos < this.lineStart) {
|
|
1120
|
+
this.lineStart = this.input.lastIndexOf("\n", this.lineStart - 2) + 1;
|
|
1121
|
+
--this.curLine;
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
this.nextToken();
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
if (this.end > this.start) {
|
|
1129
|
+
message += ` ${this.input.slice(this.start, this.end)}`;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
this.raise(this.start, message);
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
/*
|
|
1136
|
+
* Esprima-FB represents JSX strings as tokens called "JSXText", but Acorn-JSX
|
|
1137
|
+
* uses regular tt.string without any distinction between this and regular JS
|
|
1138
|
+
* strings. As such, we intercept an attempt to read a JSX string and set a flag
|
|
1139
|
+
* on extra so that when tokens are converted, the next token will be switched
|
|
1140
|
+
* to JSXText via onToken.
|
|
1141
|
+
*/
|
|
1142
|
+
jsx_readString(quote) { // eslint-disable-line camelcase -- required by API
|
|
1143
|
+
const result = super.jsx_readString(quote);
|
|
1144
|
+
|
|
1145
|
+
if (this.type === tokTypes.string) {
|
|
1146
|
+
this[STATE].jsxAttrValueToken = true;
|
|
1147
|
+
}
|
|
1148
|
+
return result;
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
/**
|
|
1152
|
+
* Performs last-minute Esprima-specific compatibility checks and fixes.
|
|
1153
|
+
* @param {ASTNode} result The node to check.
|
|
1154
|
+
* @returns {ASTNode} The finished node.
|
|
1155
|
+
*/
|
|
1156
|
+
[ESPRIMA_FINISH_NODE](result) {
|
|
1157
|
+
|
|
1158
|
+
// Acorn doesn't count the opening and closing backticks as part of templates
|
|
1159
|
+
// so we have to adjust ranges/locations appropriately.
|
|
1160
|
+
if (result.type === "TemplateElement") {
|
|
1161
|
+
|
|
1162
|
+
// save template element references to fix start/end later
|
|
1163
|
+
this[STATE].templateElements.push(result);
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
if (result.type.includes("Function") && !result.generator) {
|
|
1167
|
+
result.generator = false;
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
return result;
|
|
1171
|
+
}
|
|
1172
|
+
};
|
|
1173
|
+
};
|
|
1174
|
+
|
|
1175
|
+
const version$1 = "10.3.0";
|
|
1176
|
+
|
|
1177
|
+
/**
|
|
1178
|
+
* @fileoverview Main Espree file that converts Acorn into Esprima output.
|
|
1179
|
+
*
|
|
1180
|
+
* This file contains code from the following MIT-licensed projects:
|
|
1181
|
+
* 1. Acorn
|
|
1182
|
+
* 2. Babylon
|
|
1183
|
+
* 3. Babel-ESLint
|
|
1184
|
+
*
|
|
1185
|
+
* This file also contains code from Esprima, which is BSD licensed.
|
|
1186
|
+
*
|
|
1187
|
+
* Acorn is Copyright 2012-2015 Acorn Contributors (https://github.com/marijnh/acorn/blob/master/AUTHORS)
|
|
1188
|
+
* Babylon is Copyright 2014-2015 various contributors (https://github.com/babel/babel/blob/master/packages/babylon/AUTHORS)
|
|
1189
|
+
* Babel-ESLint is Copyright 2014-2015 Sebastian McKenzie <sebmck@gmail.com>
|
|
1190
|
+
*
|
|
1191
|
+
* Redistribution and use in source and binary forms, with or without
|
|
1192
|
+
* modification, are permitted provided that the following conditions are met:
|
|
1193
|
+
*
|
|
1194
|
+
* * Redistributions of source code must retain the above copyright
|
|
1195
|
+
* notice, this list of conditions and the following disclaimer.
|
|
1196
|
+
* * Redistributions in binary form must reproduce the above copyright
|
|
1197
|
+
* notice, this list of conditions and the following disclaimer in the
|
|
1198
|
+
* documentation and/or other materials provided with the distribution.
|
|
1199
|
+
*
|
|
1200
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
1201
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
1202
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
1203
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
|
1204
|
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
1205
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
1206
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
1207
|
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
1208
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
1209
|
+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1210
|
+
*
|
|
1211
|
+
* Esprima is Copyright (c) jQuery Foundation, Inc. and Contributors, All Rights Reserved.
|
|
1212
|
+
*
|
|
1213
|
+
* Redistribution and use in source and binary forms, with or without
|
|
1214
|
+
* modification, are permitted provided that the following conditions are met:
|
|
1215
|
+
*
|
|
1216
|
+
* * Redistributions of source code must retain the above copyright
|
|
1217
|
+
* notice, this list of conditions and the following disclaimer.
|
|
1218
|
+
* * Redistributions in binary form must reproduce the above copyright
|
|
1219
|
+
* notice, this list of conditions and the following disclaimer in the
|
|
1220
|
+
* documentation and/or other materials provided with the distribution.
|
|
1221
|
+
*
|
|
1222
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
1223
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
1224
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
1225
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
|
1226
|
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
1227
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
1228
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
1229
|
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
1230
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
1231
|
+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1232
|
+
*/
|
|
1233
|
+
|
|
1234
|
+
|
|
1235
|
+
// To initialize lazily.
|
|
1236
|
+
const parsers = {
|
|
1237
|
+
_regular: null,
|
|
1238
|
+
_jsx: null,
|
|
1239
|
+
|
|
1240
|
+
get regular() {
|
|
1241
|
+
if (this._regular === null) {
|
|
1242
|
+
this._regular = acorn__namespace.Parser.extend(espree$1());
|
|
1243
|
+
}
|
|
1244
|
+
return this._regular;
|
|
1245
|
+
},
|
|
1246
|
+
|
|
1247
|
+
get jsx() {
|
|
1248
|
+
if (this._jsx === null) {
|
|
1249
|
+
this._jsx = acorn__namespace.Parser.extend(jsx__default["default"](), espree$1());
|
|
1250
|
+
}
|
|
1251
|
+
return this._jsx;
|
|
1252
|
+
},
|
|
1253
|
+
|
|
1254
|
+
get(options) {
|
|
1255
|
+
const useJsx = Boolean(
|
|
1256
|
+
options &&
|
|
1257
|
+
options.ecmaFeatures &&
|
|
1258
|
+
options.ecmaFeatures.jsx
|
|
1259
|
+
);
|
|
1260
|
+
|
|
1261
|
+
return useJsx ? this.jsx : this.regular;
|
|
1262
|
+
}
|
|
1263
|
+
};
|
|
1264
|
+
|
|
1265
|
+
//------------------------------------------------------------------------------
|
|
1266
|
+
// Tokenizer
|
|
1267
|
+
//------------------------------------------------------------------------------
|
|
1268
|
+
|
|
1269
|
+
/**
|
|
1270
|
+
* Tokenizes the given code.
|
|
1271
|
+
* @param {string} code The code to tokenize.
|
|
1272
|
+
* @param {Object} options Options defining how to tokenize.
|
|
1273
|
+
* @returns {Token[]} An array of tokens.
|
|
1274
|
+
* @throws {SyntaxError} If the input code is invalid.
|
|
1275
|
+
* @private
|
|
1276
|
+
*/
|
|
1277
|
+
function tokenize(code, options) {
|
|
1278
|
+
const Parser = parsers.get(options);
|
|
1279
|
+
|
|
1280
|
+
// Ensure to collect tokens.
|
|
1281
|
+
if (!options || options.tokens !== true) {
|
|
1282
|
+
options = Object.assign({}, options, { tokens: true }); // eslint-disable-line no-param-reassign -- stylistic choice
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
return new Parser(options, code).tokenize();
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
//------------------------------------------------------------------------------
|
|
1289
|
+
// Parser
|
|
1290
|
+
//------------------------------------------------------------------------------
|
|
1291
|
+
|
|
1292
|
+
/**
|
|
1293
|
+
* Parses the given code.
|
|
1294
|
+
* @param {string} code The code to tokenize.
|
|
1295
|
+
* @param {Object} options Options defining how to tokenize.
|
|
1296
|
+
* @returns {ASTNode} The "Program" AST node.
|
|
1297
|
+
* @throws {SyntaxError} If the input code is invalid.
|
|
1298
|
+
*/
|
|
1299
|
+
function parse(code, options) {
|
|
1300
|
+
const Parser = parsers.get(options);
|
|
1301
|
+
|
|
1302
|
+
return new Parser(options, code).parse();
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
//------------------------------------------------------------------------------
|
|
1306
|
+
// Public
|
|
1307
|
+
//------------------------------------------------------------------------------
|
|
1308
|
+
|
|
1309
|
+
const version = version$1;
|
|
1310
|
+
const name = "espree";
|
|
1311
|
+
|
|
1312
|
+
/* istanbul ignore next */
|
|
1313
|
+
const VisitorKeys = (function() {
|
|
1314
|
+
return visitorKeys__namespace.KEYS;
|
|
1315
|
+
}());
|
|
1316
|
+
|
|
1317
|
+
// Derive node types from VisitorKeys
|
|
1318
|
+
/* istanbul ignore next */
|
|
1319
|
+
const Syntax = (function() {
|
|
1320
|
+
let key,
|
|
1321
|
+
types = {};
|
|
1322
|
+
|
|
1323
|
+
if (typeof Object.create === "function") {
|
|
1324
|
+
types = Object.create(null);
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
for (key in VisitorKeys) {
|
|
1328
|
+
if (Object.hasOwn(VisitorKeys, key)) {
|
|
1329
|
+
types[key] = key;
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
if (typeof Object.freeze === "function") {
|
|
1334
|
+
Object.freeze(types);
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
return types;
|
|
1338
|
+
}());
|
|
1339
|
+
|
|
1340
|
+
const latestEcmaVersion = getLatestEcmaVersion();
|
|
1341
|
+
|
|
1342
|
+
const supportedEcmaVersions = getSupportedEcmaVersions();
|
|
1343
|
+
|
|
1344
|
+
espree.Syntax = Syntax;
|
|
1345
|
+
espree.VisitorKeys = VisitorKeys;
|
|
1346
|
+
espree.latestEcmaVersion = latestEcmaVersion;
|
|
1347
|
+
espree.name = name;
|
|
1348
|
+
espree.parse = parse;
|
|
1349
|
+
espree.supportedEcmaVersions = supportedEcmaVersions;
|
|
1350
|
+
espree.tokenize = tokenize;
|
|
1351
|
+
espree.version = version;
|
|
1352
|
+
return espree;
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
export { requireEslintVisitorKeys as a, requireEspree as r };
|