@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,2914 @@
|
|
|
1
|
+
import require$$0 from 'path';
|
|
2
|
+
import { r as requireSemver } from './eslint-config.I8d-HnmI.mjs';
|
|
3
|
+
import require$$2$1 from 'module';
|
|
4
|
+
import { a as getAugmentedNamespace } from './eslint-config.BDBLGvXj.mjs';
|
|
5
|
+
import { a as requireAcorn$1, r as requireAcornJsx } from './eslint-config.DWoU09EE.mjs';
|
|
6
|
+
import { r as requireEslintVisitorKeys } from './eslint-config.FKVuBSa4.mjs';
|
|
7
|
+
|
|
8
|
+
var lib = {};
|
|
9
|
+
|
|
10
|
+
var parser = {};
|
|
11
|
+
|
|
12
|
+
var espree$1 = {};
|
|
13
|
+
|
|
14
|
+
var requireUtils$1 = {};
|
|
15
|
+
|
|
16
|
+
var hasRequiredRequireUtils;
|
|
17
|
+
|
|
18
|
+
function requireRequireUtils () {
|
|
19
|
+
if (hasRequiredRequireUtils) return requireUtils$1;
|
|
20
|
+
hasRequiredRequireUtils = 1;
|
|
21
|
+
var __importDefault = (requireUtils$1 && requireUtils$1.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(requireUtils$1, "__esModule", { value: true });
|
|
25
|
+
requireUtils$1.loadNewest = requireUtils$1.requireFromCwd = requireUtils$1.requireFromLinter = requireUtils$1.getRequireFromCwd = requireUtils$1.getRequireFromLinter = requireUtils$1.createRequire = void 0;
|
|
26
|
+
const path_1 = __importDefault(require$$0);
|
|
27
|
+
const semver_1 = requireSemver();
|
|
28
|
+
function createRequire(filename) {
|
|
29
|
+
const Module = require$$2$1;
|
|
30
|
+
const fn = Module.createRequire ||
|
|
31
|
+
Module.createRequireFromPath ||
|
|
32
|
+
((filename2) => {
|
|
33
|
+
const mod = new Module(filename2);
|
|
34
|
+
mod.filename = filename2;
|
|
35
|
+
mod.paths = Module._nodeModulePaths(path_1.default.dirname(filename2));
|
|
36
|
+
mod._compile("module.exports = require;", filename2);
|
|
37
|
+
return mod.exports;
|
|
38
|
+
});
|
|
39
|
+
return fn(filename);
|
|
40
|
+
}
|
|
41
|
+
requireUtils$1.createRequire = createRequire;
|
|
42
|
+
function isLinterPath(p) {
|
|
43
|
+
return (p.includes(`eslint${path_1.default.sep}lib${path_1.default.sep}linter${path_1.default.sep}linter.js`) ||
|
|
44
|
+
p.includes(`eslint${path_1.default.sep}lib${path_1.default.sep}linter.js`));
|
|
45
|
+
}
|
|
46
|
+
function getRequireFromLinter() {
|
|
47
|
+
const linterPath = Object.keys(require.cache).find(isLinterPath);
|
|
48
|
+
if (linterPath) {
|
|
49
|
+
try {
|
|
50
|
+
return createRequire(linterPath);
|
|
51
|
+
}
|
|
52
|
+
catch (_a) {
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
requireUtils$1.getRequireFromLinter = getRequireFromLinter;
|
|
58
|
+
function getRequireFromCwd() {
|
|
59
|
+
try {
|
|
60
|
+
const cwd = process.cwd();
|
|
61
|
+
const relativeTo = path_1.default.join(cwd, "__placeholder__.js");
|
|
62
|
+
return createRequire(relativeTo);
|
|
63
|
+
}
|
|
64
|
+
catch (_a) {
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
requireUtils$1.getRequireFromCwd = getRequireFromCwd;
|
|
69
|
+
function requireFromLinter(module) {
|
|
70
|
+
var _a;
|
|
71
|
+
try {
|
|
72
|
+
return (_a = getRequireFromLinter()) === null || _a === void 0 ? void 0 : _a(module);
|
|
73
|
+
}
|
|
74
|
+
catch (_b) {
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
requireUtils$1.requireFromLinter = requireFromLinter;
|
|
79
|
+
function requireFromCwd(module) {
|
|
80
|
+
var _a;
|
|
81
|
+
try {
|
|
82
|
+
return (_a = getRequireFromCwd()) === null || _a === void 0 ? void 0 : _a(module);
|
|
83
|
+
}
|
|
84
|
+
catch (_b) {
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
requireUtils$1.requireFromCwd = requireFromCwd;
|
|
89
|
+
function loadNewest(items) {
|
|
90
|
+
let target = null;
|
|
91
|
+
for (const item of items) {
|
|
92
|
+
const pkg = item.getPkg();
|
|
93
|
+
if (pkg != null && (!target || (0, semver_1.lte)(target.version, pkg.version))) {
|
|
94
|
+
target = { version: pkg.version, get: item.get };
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return target.get();
|
|
98
|
+
}
|
|
99
|
+
requireUtils$1.loadNewest = loadNewest;
|
|
100
|
+
return requireUtils$1;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const name$2 = "espree";
|
|
104
|
+
const description$2 = "An Esprima-compatible JavaScript parser built on Acorn";
|
|
105
|
+
const author$1 = "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>";
|
|
106
|
+
const homepage$2 = "https://github.com/eslint/espree";
|
|
107
|
+
const main$2 = "dist/espree.cjs";
|
|
108
|
+
const type$1 = "module";
|
|
109
|
+
const exports$2 = {
|
|
110
|
+
".": [
|
|
111
|
+
{
|
|
112
|
+
"import": "./espree.js",
|
|
113
|
+
require: "./dist/espree.cjs",
|
|
114
|
+
"default": "./dist/espree.cjs"
|
|
115
|
+
},
|
|
116
|
+
"./dist/espree.cjs"
|
|
117
|
+
],
|
|
118
|
+
"./package.json": "./package.json"
|
|
119
|
+
};
|
|
120
|
+
const version$2 = "9.6.1";
|
|
121
|
+
const files$1 = [
|
|
122
|
+
"lib",
|
|
123
|
+
"dist/espree.cjs",
|
|
124
|
+
"espree.js"
|
|
125
|
+
];
|
|
126
|
+
const engines$2 = {
|
|
127
|
+
node: "^12.22.0 || ^14.17.0 || >=16.0.0"
|
|
128
|
+
};
|
|
129
|
+
const repository$2 = "eslint/espree";
|
|
130
|
+
const bugs$1 = {
|
|
131
|
+
url: "https://github.com/eslint/espree/issues"
|
|
132
|
+
};
|
|
133
|
+
const funding$1 = "https://opencollective.com/eslint";
|
|
134
|
+
const license$2 = "BSD-2-Clause";
|
|
135
|
+
const dependencies = {
|
|
136
|
+
acorn: "^8.9.0",
|
|
137
|
+
"acorn-jsx": "^5.3.2",
|
|
138
|
+
"eslint-visitor-keys": "^3.4.1"
|
|
139
|
+
};
|
|
140
|
+
const devDependencies$1 = {
|
|
141
|
+
"@rollup/plugin-commonjs": "^17.1.0",
|
|
142
|
+
"@rollup/plugin-json": "^4.1.0",
|
|
143
|
+
"@rollup/plugin-node-resolve": "^11.2.0",
|
|
144
|
+
c8: "^7.11.0",
|
|
145
|
+
chai: "^4.3.6",
|
|
146
|
+
eslint: "^8.44.0",
|
|
147
|
+
"eslint-config-eslint": "^8.0.0",
|
|
148
|
+
"eslint-plugin-n": "^16.0.0",
|
|
149
|
+
"eslint-release": "^3.2.0",
|
|
150
|
+
"esprima-fb": "^8001.2001.0-dev-harmony-fb",
|
|
151
|
+
globals: "^13.20.0",
|
|
152
|
+
"lint-staged": "^13.2.0",
|
|
153
|
+
mocha: "^9.2.2",
|
|
154
|
+
"npm-run-all": "^4.1.5",
|
|
155
|
+
rollup: "^2.41.2",
|
|
156
|
+
shelljs: "^0.3.0",
|
|
157
|
+
yorkie: "^2.0.0"
|
|
158
|
+
};
|
|
159
|
+
const keywords$1 = [
|
|
160
|
+
"ast",
|
|
161
|
+
"ecmascript",
|
|
162
|
+
"javascript",
|
|
163
|
+
"parser",
|
|
164
|
+
"syntax",
|
|
165
|
+
"acorn"
|
|
166
|
+
];
|
|
167
|
+
const gitHooks = {
|
|
168
|
+
"pre-commit": "lint-staged"
|
|
169
|
+
};
|
|
170
|
+
const scripts$2 = {
|
|
171
|
+
unit: "npm-run-all -s unit:*",
|
|
172
|
+
"unit:esm": "c8 mocha --color --reporter progress --timeout 30000 'tests/lib/**/*.js'",
|
|
173
|
+
"unit:cjs": "mocha --color --reporter progress --timeout 30000 tests/lib/commonjs.cjs",
|
|
174
|
+
test: "npm-run-all -p unit lint",
|
|
175
|
+
lint: "eslint . --report-unused-disable-directives",
|
|
176
|
+
fixlint: "npm run lint -- --fix",
|
|
177
|
+
build: "rollup -c rollup.config.js",
|
|
178
|
+
"build:debug": "npm run build -- -m",
|
|
179
|
+
"update-version": "node tools/update-version.js",
|
|
180
|
+
pretest: "npm run build",
|
|
181
|
+
prepublishOnly: "npm run update-version && npm run build",
|
|
182
|
+
"sync-docs": "node sync-docs.js",
|
|
183
|
+
"generate-release": "eslint-generate-release",
|
|
184
|
+
"generate-alpharelease": "eslint-generate-prerelease alpha",
|
|
185
|
+
"generate-betarelease": "eslint-generate-prerelease beta",
|
|
186
|
+
"generate-rcrelease": "eslint-generate-prerelease rc",
|
|
187
|
+
"publish-release": "eslint-publish-release"
|
|
188
|
+
};
|
|
189
|
+
const _package$4 = {
|
|
190
|
+
name: name$2,
|
|
191
|
+
description: description$2,
|
|
192
|
+
author: author$1,
|
|
193
|
+
homepage: homepage$2,
|
|
194
|
+
main: main$2,
|
|
195
|
+
type: type$1,
|
|
196
|
+
exports: exports$2,
|
|
197
|
+
version: version$2,
|
|
198
|
+
files: files$1,
|
|
199
|
+
engines: engines$2,
|
|
200
|
+
repository: repository$2,
|
|
201
|
+
bugs: bugs$1,
|
|
202
|
+
funding: funding$1,
|
|
203
|
+
license: license$2,
|
|
204
|
+
dependencies: dependencies,
|
|
205
|
+
devDependencies: devDependencies$1,
|
|
206
|
+
keywords: keywords$1,
|
|
207
|
+
gitHooks: gitHooks,
|
|
208
|
+
scripts: scripts$2
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const _package$5 = {
|
|
212
|
+
__proto__: null,
|
|
213
|
+
author: author$1,
|
|
214
|
+
bugs: bugs$1,
|
|
215
|
+
default: _package$4,
|
|
216
|
+
dependencies: dependencies,
|
|
217
|
+
description: description$2,
|
|
218
|
+
devDependencies: devDependencies$1,
|
|
219
|
+
engines: engines$2,
|
|
220
|
+
exports: exports$2,
|
|
221
|
+
files: files$1,
|
|
222
|
+
funding: funding$1,
|
|
223
|
+
gitHooks: gitHooks,
|
|
224
|
+
homepage: homepage$2,
|
|
225
|
+
keywords: keywords$1,
|
|
226
|
+
license: license$2,
|
|
227
|
+
main: main$2,
|
|
228
|
+
name: name$2,
|
|
229
|
+
repository: repository$2,
|
|
230
|
+
scripts: scripts$2,
|
|
231
|
+
type: type$1,
|
|
232
|
+
version: version$2
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const require$$4 = /*@__PURE__*/getAugmentedNamespace(_package$5);
|
|
236
|
+
|
|
237
|
+
var espree = {};
|
|
238
|
+
|
|
239
|
+
var hasRequiredEspree$1;
|
|
240
|
+
|
|
241
|
+
function requireEspree$1 () {
|
|
242
|
+
if (hasRequiredEspree$1) return espree;
|
|
243
|
+
hasRequiredEspree$1 = 1;
|
|
244
|
+
|
|
245
|
+
Object.defineProperty(espree, '__esModule', { value: true });
|
|
246
|
+
|
|
247
|
+
var acorn = requireAcorn$1();
|
|
248
|
+
var jsx = requireAcornJsx();
|
|
249
|
+
var visitorKeys = requireEslintVisitorKeys();
|
|
250
|
+
|
|
251
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
252
|
+
|
|
253
|
+
function _interopNamespace(e) {
|
|
254
|
+
if (e && e.__esModule) return e;
|
|
255
|
+
var n = Object.create(null);
|
|
256
|
+
if (e) {
|
|
257
|
+
Object.keys(e).forEach(function (k) {
|
|
258
|
+
if (k !== 'default') {
|
|
259
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
260
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
261
|
+
enumerable: true,
|
|
262
|
+
get: function () { return e[k]; }
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
n["default"] = e;
|
|
268
|
+
return Object.freeze(n);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
var acorn__namespace = /*#__PURE__*/_interopNamespace(acorn);
|
|
272
|
+
var jsx__default = /*#__PURE__*/_interopDefaultLegacy(jsx);
|
|
273
|
+
var visitorKeys__namespace = /*#__PURE__*/_interopNamespace(visitorKeys);
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* @fileoverview Translates tokens between Acorn format and Esprima format.
|
|
277
|
+
* @author Nicholas C. Zakas
|
|
278
|
+
*/
|
|
279
|
+
|
|
280
|
+
//------------------------------------------------------------------------------
|
|
281
|
+
// Requirements
|
|
282
|
+
//------------------------------------------------------------------------------
|
|
283
|
+
|
|
284
|
+
// none!
|
|
285
|
+
|
|
286
|
+
//------------------------------------------------------------------------------
|
|
287
|
+
// Private
|
|
288
|
+
//------------------------------------------------------------------------------
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
// Esprima Token Types
|
|
292
|
+
const Token = {
|
|
293
|
+
Boolean: "Boolean",
|
|
294
|
+
Identifier: "Identifier",
|
|
295
|
+
PrivateIdentifier: "PrivateIdentifier",
|
|
296
|
+
Keyword: "Keyword",
|
|
297
|
+
Null: "Null",
|
|
298
|
+
Numeric: "Numeric",
|
|
299
|
+
Punctuator: "Punctuator",
|
|
300
|
+
String: "String",
|
|
301
|
+
RegularExpression: "RegularExpression",
|
|
302
|
+
Template: "Template",
|
|
303
|
+
JSXIdentifier: "JSXIdentifier",
|
|
304
|
+
JSXText: "JSXText"
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Converts part of a template into an Esprima token.
|
|
309
|
+
* @param {AcornToken[]} tokens The Acorn tokens representing the template.
|
|
310
|
+
* @param {string} code The source code.
|
|
311
|
+
* @returns {EsprimaToken} The Esprima equivalent of the template token.
|
|
312
|
+
* @private
|
|
313
|
+
*/
|
|
314
|
+
function convertTemplatePart(tokens, code) {
|
|
315
|
+
const firstToken = tokens[0],
|
|
316
|
+
lastTemplateToken = tokens[tokens.length - 1];
|
|
317
|
+
|
|
318
|
+
const token = {
|
|
319
|
+
type: Token.Template,
|
|
320
|
+
value: code.slice(firstToken.start, lastTemplateToken.end)
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
if (firstToken.loc) {
|
|
324
|
+
token.loc = {
|
|
325
|
+
start: firstToken.loc.start,
|
|
326
|
+
end: lastTemplateToken.loc.end
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (firstToken.range) {
|
|
331
|
+
token.start = firstToken.range[0];
|
|
332
|
+
token.end = lastTemplateToken.range[1];
|
|
333
|
+
token.range = [token.start, token.end];
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
return token;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Contains logic to translate Acorn tokens into Esprima tokens.
|
|
341
|
+
* @param {Object} acornTokTypes The Acorn token types.
|
|
342
|
+
* @param {string} code The source code Acorn is parsing. This is necessary
|
|
343
|
+
* to correct the "value" property of some tokens.
|
|
344
|
+
* @constructor
|
|
345
|
+
*/
|
|
346
|
+
function TokenTranslator(acornTokTypes, code) {
|
|
347
|
+
|
|
348
|
+
// token types
|
|
349
|
+
this._acornTokTypes = acornTokTypes;
|
|
350
|
+
|
|
351
|
+
// token buffer for templates
|
|
352
|
+
this._tokens = [];
|
|
353
|
+
|
|
354
|
+
// track the last curly brace
|
|
355
|
+
this._curlyBrace = null;
|
|
356
|
+
|
|
357
|
+
// the source code
|
|
358
|
+
this._code = code;
|
|
359
|
+
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
TokenTranslator.prototype = {
|
|
363
|
+
constructor: TokenTranslator,
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Translates a single Esprima token to a single Acorn token. This may be
|
|
367
|
+
* inaccurate due to how templates are handled differently in Esprima and
|
|
368
|
+
* Acorn, but should be accurate for all other tokens.
|
|
369
|
+
* @param {AcornToken} token The Acorn token to translate.
|
|
370
|
+
* @param {Object} extra Espree extra object.
|
|
371
|
+
* @returns {EsprimaToken} The Esprima version of the token.
|
|
372
|
+
*/
|
|
373
|
+
translate(token, extra) {
|
|
374
|
+
|
|
375
|
+
const type = token.type,
|
|
376
|
+
tt = this._acornTokTypes;
|
|
377
|
+
|
|
378
|
+
if (type === tt.name) {
|
|
379
|
+
token.type = Token.Identifier;
|
|
380
|
+
|
|
381
|
+
// TODO: See if this is an Acorn bug
|
|
382
|
+
if (token.value === "static") {
|
|
383
|
+
token.type = Token.Keyword;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (extra.ecmaVersion > 5 && (token.value === "yield" || token.value === "let")) {
|
|
387
|
+
token.type = Token.Keyword;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
} else if (type === tt.privateId) {
|
|
391
|
+
token.type = Token.PrivateIdentifier;
|
|
392
|
+
|
|
393
|
+
} else if (type === tt.semi || type === tt.comma ||
|
|
394
|
+
type === tt.parenL || type === tt.parenR ||
|
|
395
|
+
type === tt.braceL || type === tt.braceR ||
|
|
396
|
+
type === tt.dot || type === tt.bracketL ||
|
|
397
|
+
type === tt.colon || type === tt.question ||
|
|
398
|
+
type === tt.bracketR || type === tt.ellipsis ||
|
|
399
|
+
type === tt.arrow || type === tt.jsxTagStart ||
|
|
400
|
+
type === tt.incDec || type === tt.starstar ||
|
|
401
|
+
type === tt.jsxTagEnd || type === tt.prefix ||
|
|
402
|
+
type === tt.questionDot ||
|
|
403
|
+
(type.binop && !type.keyword) ||
|
|
404
|
+
type.isAssign) {
|
|
405
|
+
|
|
406
|
+
token.type = Token.Punctuator;
|
|
407
|
+
token.value = this._code.slice(token.start, token.end);
|
|
408
|
+
} else if (type === tt.jsxName) {
|
|
409
|
+
token.type = Token.JSXIdentifier;
|
|
410
|
+
} else if (type.label === "jsxText" || type === tt.jsxAttrValueToken) {
|
|
411
|
+
token.type = Token.JSXText;
|
|
412
|
+
} else if (type.keyword) {
|
|
413
|
+
if (type.keyword === "true" || type.keyword === "false") {
|
|
414
|
+
token.type = Token.Boolean;
|
|
415
|
+
} else if (type.keyword === "null") {
|
|
416
|
+
token.type = Token.Null;
|
|
417
|
+
} else {
|
|
418
|
+
token.type = Token.Keyword;
|
|
419
|
+
}
|
|
420
|
+
} else if (type === tt.num) {
|
|
421
|
+
token.type = Token.Numeric;
|
|
422
|
+
token.value = this._code.slice(token.start, token.end);
|
|
423
|
+
} else if (type === tt.string) {
|
|
424
|
+
|
|
425
|
+
if (extra.jsxAttrValueToken) {
|
|
426
|
+
extra.jsxAttrValueToken = false;
|
|
427
|
+
token.type = Token.JSXText;
|
|
428
|
+
} else {
|
|
429
|
+
token.type = Token.String;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
token.value = this._code.slice(token.start, token.end);
|
|
433
|
+
} else if (type === tt.regexp) {
|
|
434
|
+
token.type = Token.RegularExpression;
|
|
435
|
+
const value = token.value;
|
|
436
|
+
|
|
437
|
+
token.regex = {
|
|
438
|
+
flags: value.flags,
|
|
439
|
+
pattern: value.pattern
|
|
440
|
+
};
|
|
441
|
+
token.value = `/${value.pattern}/${value.flags}`;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
return token;
|
|
445
|
+
},
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Function to call during Acorn's onToken handler.
|
|
449
|
+
* @param {AcornToken} token The Acorn token.
|
|
450
|
+
* @param {Object} extra The Espree extra object.
|
|
451
|
+
* @returns {void}
|
|
452
|
+
*/
|
|
453
|
+
onToken(token, extra) {
|
|
454
|
+
|
|
455
|
+
const tt = this._acornTokTypes,
|
|
456
|
+
tokens = extra.tokens,
|
|
457
|
+
templateTokens = this._tokens;
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Flushes the buffered template tokens and resets the template
|
|
461
|
+
* tracking.
|
|
462
|
+
* @returns {void}
|
|
463
|
+
* @private
|
|
464
|
+
*/
|
|
465
|
+
const translateTemplateTokens = () => {
|
|
466
|
+
tokens.push(convertTemplatePart(this._tokens, this._code));
|
|
467
|
+
this._tokens = [];
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
if (token.type === tt.eof) {
|
|
471
|
+
|
|
472
|
+
// might be one last curlyBrace
|
|
473
|
+
if (this._curlyBrace) {
|
|
474
|
+
tokens.push(this.translate(this._curlyBrace, extra));
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
if (token.type === tt.backQuote) {
|
|
481
|
+
|
|
482
|
+
// if there's already a curly, it's not part of the template
|
|
483
|
+
if (this._curlyBrace) {
|
|
484
|
+
tokens.push(this.translate(this._curlyBrace, extra));
|
|
485
|
+
this._curlyBrace = null;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
templateTokens.push(token);
|
|
489
|
+
|
|
490
|
+
// it's the end
|
|
491
|
+
if (templateTokens.length > 1) {
|
|
492
|
+
translateTemplateTokens();
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
if (token.type === tt.dollarBraceL) {
|
|
498
|
+
templateTokens.push(token);
|
|
499
|
+
translateTemplateTokens();
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
if (token.type === tt.braceR) {
|
|
503
|
+
|
|
504
|
+
// if there's already a curly, it's not part of the template
|
|
505
|
+
if (this._curlyBrace) {
|
|
506
|
+
tokens.push(this.translate(this._curlyBrace, extra));
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
// store new curly for later
|
|
510
|
+
this._curlyBrace = token;
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
if (token.type === tt.template || token.type === tt.invalidTemplate) {
|
|
514
|
+
if (this._curlyBrace) {
|
|
515
|
+
templateTokens.push(this._curlyBrace);
|
|
516
|
+
this._curlyBrace = null;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
templateTokens.push(token);
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
if (this._curlyBrace) {
|
|
524
|
+
tokens.push(this.translate(this._curlyBrace, extra));
|
|
525
|
+
this._curlyBrace = null;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
tokens.push(this.translate(token, extra));
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* @fileoverview A collection of methods for processing Espree's options.
|
|
534
|
+
* @author Kai Cataldo
|
|
535
|
+
*/
|
|
536
|
+
|
|
537
|
+
//------------------------------------------------------------------------------
|
|
538
|
+
// Helpers
|
|
539
|
+
//------------------------------------------------------------------------------
|
|
540
|
+
|
|
541
|
+
const SUPPORTED_VERSIONS = [
|
|
542
|
+
3,
|
|
543
|
+
5,
|
|
544
|
+
6, // 2015
|
|
545
|
+
7, // 2016
|
|
546
|
+
8, // 2017
|
|
547
|
+
9, // 2018
|
|
548
|
+
10, // 2019
|
|
549
|
+
11, // 2020
|
|
550
|
+
12, // 2021
|
|
551
|
+
13, // 2022
|
|
552
|
+
14, // 2023
|
|
553
|
+
15 // 2024
|
|
554
|
+
];
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Get the latest ECMAScript version supported by Espree.
|
|
558
|
+
* @returns {number} The latest ECMAScript version.
|
|
559
|
+
*/
|
|
560
|
+
function getLatestEcmaVersion() {
|
|
561
|
+
return SUPPORTED_VERSIONS[SUPPORTED_VERSIONS.length - 1];
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* Get the list of ECMAScript versions supported by Espree.
|
|
566
|
+
* @returns {number[]} An array containing the supported ECMAScript versions.
|
|
567
|
+
*/
|
|
568
|
+
function getSupportedEcmaVersions() {
|
|
569
|
+
return [...SUPPORTED_VERSIONS];
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Normalize ECMAScript version from the initial config
|
|
574
|
+
* @param {(number|"latest")} ecmaVersion ECMAScript version from the initial config
|
|
575
|
+
* @throws {Error} throws an error if the ecmaVersion is invalid.
|
|
576
|
+
* @returns {number} normalized ECMAScript version
|
|
577
|
+
*/
|
|
578
|
+
function normalizeEcmaVersion(ecmaVersion = 5) {
|
|
579
|
+
|
|
580
|
+
let version = ecmaVersion === "latest" ? getLatestEcmaVersion() : ecmaVersion;
|
|
581
|
+
|
|
582
|
+
if (typeof version !== "number") {
|
|
583
|
+
throw new Error(`ecmaVersion must be a number or "latest". Received value of type ${typeof ecmaVersion} instead.`);
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
// Calculate ECMAScript edition number from official year version starting with
|
|
587
|
+
// ES2015, which corresponds with ES6 (or a difference of 2009).
|
|
588
|
+
if (version >= 2015) {
|
|
589
|
+
version -= 2009;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
if (!SUPPORTED_VERSIONS.includes(version)) {
|
|
593
|
+
throw new Error("Invalid ecmaVersion.");
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
return version;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Normalize sourceType from the initial config
|
|
601
|
+
* @param {string} sourceType to normalize
|
|
602
|
+
* @throws {Error} throw an error if sourceType is invalid
|
|
603
|
+
* @returns {string} normalized sourceType
|
|
604
|
+
*/
|
|
605
|
+
function normalizeSourceType(sourceType = "script") {
|
|
606
|
+
if (sourceType === "script" || sourceType === "module") {
|
|
607
|
+
return sourceType;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
if (sourceType === "commonjs") {
|
|
611
|
+
return "script";
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
throw new Error("Invalid sourceType.");
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
/**
|
|
618
|
+
* Normalize parserOptions
|
|
619
|
+
* @param {Object} options the parser options to normalize
|
|
620
|
+
* @throws {Error} throw an error if found invalid option.
|
|
621
|
+
* @returns {Object} normalized options
|
|
622
|
+
*/
|
|
623
|
+
function normalizeOptions(options) {
|
|
624
|
+
const ecmaVersion = normalizeEcmaVersion(options.ecmaVersion);
|
|
625
|
+
const sourceType = normalizeSourceType(options.sourceType);
|
|
626
|
+
const ranges = options.range === true;
|
|
627
|
+
const locations = options.loc === true;
|
|
628
|
+
|
|
629
|
+
if (ecmaVersion !== 3 && options.allowReserved) {
|
|
630
|
+
|
|
631
|
+
// a value of `false` is intentionally allowed here, so a shared config can overwrite it when needed
|
|
632
|
+
throw new Error("`allowReserved` is only supported when ecmaVersion is 3");
|
|
633
|
+
}
|
|
634
|
+
if (typeof options.allowReserved !== "undefined" && typeof options.allowReserved !== "boolean") {
|
|
635
|
+
throw new Error("`allowReserved`, when present, must be `true` or `false`");
|
|
636
|
+
}
|
|
637
|
+
const allowReserved = ecmaVersion === 3 ? (options.allowReserved || "never") : false;
|
|
638
|
+
const ecmaFeatures = options.ecmaFeatures || {};
|
|
639
|
+
const allowReturnOutsideFunction = options.sourceType === "commonjs" ||
|
|
640
|
+
Boolean(ecmaFeatures.globalReturn);
|
|
641
|
+
|
|
642
|
+
if (sourceType === "module" && ecmaVersion < 6) {
|
|
643
|
+
throw new Error("sourceType 'module' is not supported when ecmaVersion < 2015. Consider adding `{ ecmaVersion: 2015 }` to the parser options.");
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
return Object.assign({}, options, {
|
|
647
|
+
ecmaVersion,
|
|
648
|
+
sourceType,
|
|
649
|
+
ranges,
|
|
650
|
+
locations,
|
|
651
|
+
allowReserved,
|
|
652
|
+
allowReturnOutsideFunction
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
/* eslint no-param-reassign: 0 -- stylistic choice */
|
|
657
|
+
|
|
658
|
+
|
|
659
|
+
const STATE = Symbol("espree's internal state");
|
|
660
|
+
const ESPRIMA_FINISH_NODE = Symbol("espree's esprimaFinishNode");
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* Converts an Acorn comment to a Esprima comment.
|
|
665
|
+
* @param {boolean} block True if it's a block comment, false if not.
|
|
666
|
+
* @param {string} text The text of the comment.
|
|
667
|
+
* @param {int} start The index at which the comment starts.
|
|
668
|
+
* @param {int} end The index at which the comment ends.
|
|
669
|
+
* @param {Location} startLoc The location at which the comment starts.
|
|
670
|
+
* @param {Location} endLoc The location at which the comment ends.
|
|
671
|
+
* @param {string} code The source code being parsed.
|
|
672
|
+
* @returns {Object} The comment object.
|
|
673
|
+
* @private
|
|
674
|
+
*/
|
|
675
|
+
function convertAcornCommentToEsprimaComment(block, text, start, end, startLoc, endLoc, code) {
|
|
676
|
+
let type;
|
|
677
|
+
|
|
678
|
+
if (block) {
|
|
679
|
+
type = "Block";
|
|
680
|
+
} else if (code.slice(start, start + 2) === "#!") {
|
|
681
|
+
type = "Hashbang";
|
|
682
|
+
} else {
|
|
683
|
+
type = "Line";
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
const comment = {
|
|
687
|
+
type,
|
|
688
|
+
value: text
|
|
689
|
+
};
|
|
690
|
+
|
|
691
|
+
if (typeof start === "number") {
|
|
692
|
+
comment.start = start;
|
|
693
|
+
comment.end = end;
|
|
694
|
+
comment.range = [start, end];
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
if (typeof startLoc === "object") {
|
|
698
|
+
comment.loc = {
|
|
699
|
+
start: startLoc,
|
|
700
|
+
end: endLoc
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
return comment;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
var espree$1 = () => Parser => {
|
|
708
|
+
const tokTypes = Object.assign({}, Parser.acorn.tokTypes);
|
|
709
|
+
|
|
710
|
+
if (Parser.acornJsx) {
|
|
711
|
+
Object.assign(tokTypes, Parser.acornJsx.tokTypes);
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
return class Espree extends Parser {
|
|
715
|
+
constructor(opts, code) {
|
|
716
|
+
if (typeof opts !== "object" || opts === null) {
|
|
717
|
+
opts = {};
|
|
718
|
+
}
|
|
719
|
+
if (typeof code !== "string" && !(code instanceof String)) {
|
|
720
|
+
code = String(code);
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
// save original source type in case of commonjs
|
|
724
|
+
const originalSourceType = opts.sourceType;
|
|
725
|
+
const options = normalizeOptions(opts);
|
|
726
|
+
const ecmaFeatures = options.ecmaFeatures || {};
|
|
727
|
+
const tokenTranslator =
|
|
728
|
+
options.tokens === true
|
|
729
|
+
? new TokenTranslator(tokTypes, code)
|
|
730
|
+
: null;
|
|
731
|
+
|
|
732
|
+
/*
|
|
733
|
+
* Data that is unique to Espree and is not represented internally
|
|
734
|
+
* in Acorn.
|
|
735
|
+
*
|
|
736
|
+
* For ES2023 hashbangs, Espree will call `onComment()` during the
|
|
737
|
+
* constructor, so we must define state before having access to
|
|
738
|
+
* `this`.
|
|
739
|
+
*/
|
|
740
|
+
const state = {
|
|
741
|
+
originalSourceType: originalSourceType || options.sourceType,
|
|
742
|
+
tokens: tokenTranslator ? [] : null,
|
|
743
|
+
comments: options.comment === true ? [] : null,
|
|
744
|
+
impliedStrict: ecmaFeatures.impliedStrict === true && options.ecmaVersion >= 5,
|
|
745
|
+
ecmaVersion: options.ecmaVersion,
|
|
746
|
+
jsxAttrValueToken: false,
|
|
747
|
+
lastToken: null,
|
|
748
|
+
templateElements: []
|
|
749
|
+
};
|
|
750
|
+
|
|
751
|
+
// Initialize acorn parser.
|
|
752
|
+
super({
|
|
753
|
+
|
|
754
|
+
// do not use spread, because we don't want to pass any unknown options to acorn
|
|
755
|
+
ecmaVersion: options.ecmaVersion,
|
|
756
|
+
sourceType: options.sourceType,
|
|
757
|
+
ranges: options.ranges,
|
|
758
|
+
locations: options.locations,
|
|
759
|
+
allowReserved: options.allowReserved,
|
|
760
|
+
|
|
761
|
+
// Truthy value is true for backward compatibility.
|
|
762
|
+
allowReturnOutsideFunction: options.allowReturnOutsideFunction,
|
|
763
|
+
|
|
764
|
+
// Collect tokens
|
|
765
|
+
onToken(token) {
|
|
766
|
+
if (tokenTranslator) {
|
|
767
|
+
|
|
768
|
+
// Use `tokens`, `ecmaVersion`, and `jsxAttrValueToken` in the state.
|
|
769
|
+
tokenTranslator.onToken(token, state);
|
|
770
|
+
}
|
|
771
|
+
if (token.type !== tokTypes.eof) {
|
|
772
|
+
state.lastToken = token;
|
|
773
|
+
}
|
|
774
|
+
},
|
|
775
|
+
|
|
776
|
+
// Collect comments
|
|
777
|
+
onComment(block, text, start, end, startLoc, endLoc) {
|
|
778
|
+
if (state.comments) {
|
|
779
|
+
const comment = convertAcornCommentToEsprimaComment(block, text, start, end, startLoc, endLoc, code);
|
|
780
|
+
|
|
781
|
+
state.comments.push(comment);
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
}, code);
|
|
785
|
+
|
|
786
|
+
/*
|
|
787
|
+
* We put all of this data into a symbol property as a way to avoid
|
|
788
|
+
* potential naming conflicts with future versions of Acorn.
|
|
789
|
+
*/
|
|
790
|
+
this[STATE] = state;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
tokenize() {
|
|
794
|
+
do {
|
|
795
|
+
this.next();
|
|
796
|
+
} while (this.type !== tokTypes.eof);
|
|
797
|
+
|
|
798
|
+
// Consume the final eof token
|
|
799
|
+
this.next();
|
|
800
|
+
|
|
801
|
+
const extra = this[STATE];
|
|
802
|
+
const tokens = extra.tokens;
|
|
803
|
+
|
|
804
|
+
if (extra.comments) {
|
|
805
|
+
tokens.comments = extra.comments;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
return tokens;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
finishNode(...args) {
|
|
812
|
+
const result = super.finishNode(...args);
|
|
813
|
+
|
|
814
|
+
return this[ESPRIMA_FINISH_NODE](result);
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
finishNodeAt(...args) {
|
|
818
|
+
const result = super.finishNodeAt(...args);
|
|
819
|
+
|
|
820
|
+
return this[ESPRIMA_FINISH_NODE](result);
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
parse() {
|
|
824
|
+
const extra = this[STATE];
|
|
825
|
+
const program = super.parse();
|
|
826
|
+
|
|
827
|
+
program.sourceType = extra.originalSourceType;
|
|
828
|
+
|
|
829
|
+
if (extra.comments) {
|
|
830
|
+
program.comments = extra.comments;
|
|
831
|
+
}
|
|
832
|
+
if (extra.tokens) {
|
|
833
|
+
program.tokens = extra.tokens;
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
/*
|
|
837
|
+
* Adjust opening and closing position of program to match Esprima.
|
|
838
|
+
* Acorn always starts programs at range 0 whereas Esprima starts at the
|
|
839
|
+
* first AST node's start (the only real difference is when there's leading
|
|
840
|
+
* whitespace or leading comments). Acorn also counts trailing whitespace
|
|
841
|
+
* as part of the program whereas Esprima only counts up to the last token.
|
|
842
|
+
*/
|
|
843
|
+
if (program.body.length) {
|
|
844
|
+
const [firstNode] = program.body;
|
|
845
|
+
|
|
846
|
+
if (program.range) {
|
|
847
|
+
program.range[0] = firstNode.range[0];
|
|
848
|
+
}
|
|
849
|
+
if (program.loc) {
|
|
850
|
+
program.loc.start = firstNode.loc.start;
|
|
851
|
+
}
|
|
852
|
+
program.start = firstNode.start;
|
|
853
|
+
}
|
|
854
|
+
if (extra.lastToken) {
|
|
855
|
+
if (program.range) {
|
|
856
|
+
program.range[1] = extra.lastToken.range[1];
|
|
857
|
+
}
|
|
858
|
+
if (program.loc) {
|
|
859
|
+
program.loc.end = extra.lastToken.loc.end;
|
|
860
|
+
}
|
|
861
|
+
program.end = extra.lastToken.end;
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
|
|
865
|
+
/*
|
|
866
|
+
* https://github.com/eslint/espree/issues/349
|
|
867
|
+
* Ensure that template elements have correct range information.
|
|
868
|
+
* This is one location where Acorn produces a different value
|
|
869
|
+
* for its start and end properties vs. the values present in the
|
|
870
|
+
* range property. In order to avoid confusion, we set the start
|
|
871
|
+
* and end properties to the values that are present in range.
|
|
872
|
+
* This is done here, instead of in finishNode(), because Acorn
|
|
873
|
+
* uses the values of start and end internally while parsing, making
|
|
874
|
+
* it dangerous to change those values while parsing is ongoing.
|
|
875
|
+
* By waiting until the end of parsing, we can safely change these
|
|
876
|
+
* values without affect any other part of the process.
|
|
877
|
+
*/
|
|
878
|
+
this[STATE].templateElements.forEach(templateElement => {
|
|
879
|
+
const startOffset = -1;
|
|
880
|
+
const endOffset = templateElement.tail ? 1 : 2;
|
|
881
|
+
|
|
882
|
+
templateElement.start += startOffset;
|
|
883
|
+
templateElement.end += endOffset;
|
|
884
|
+
|
|
885
|
+
if (templateElement.range) {
|
|
886
|
+
templateElement.range[0] += startOffset;
|
|
887
|
+
templateElement.range[1] += endOffset;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
if (templateElement.loc) {
|
|
891
|
+
templateElement.loc.start.column += startOffset;
|
|
892
|
+
templateElement.loc.end.column += endOffset;
|
|
893
|
+
}
|
|
894
|
+
});
|
|
895
|
+
|
|
896
|
+
return program;
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
parseTopLevel(node) {
|
|
900
|
+
if (this[STATE].impliedStrict) {
|
|
901
|
+
this.strict = true;
|
|
902
|
+
}
|
|
903
|
+
return super.parseTopLevel(node);
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
/**
|
|
907
|
+
* Overwrites the default raise method to throw Esprima-style errors.
|
|
908
|
+
* @param {int} pos The position of the error.
|
|
909
|
+
* @param {string} message The error message.
|
|
910
|
+
* @throws {SyntaxError} A syntax error.
|
|
911
|
+
* @returns {void}
|
|
912
|
+
*/
|
|
913
|
+
raise(pos, message) {
|
|
914
|
+
const loc = Parser.acorn.getLineInfo(this.input, pos);
|
|
915
|
+
const err = new SyntaxError(message);
|
|
916
|
+
|
|
917
|
+
err.index = pos;
|
|
918
|
+
err.lineNumber = loc.line;
|
|
919
|
+
err.column = loc.column + 1; // acorn uses 0-based columns
|
|
920
|
+
throw err;
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
/**
|
|
924
|
+
* Overwrites the default raise method to throw Esprima-style errors.
|
|
925
|
+
* @param {int} pos The position of the error.
|
|
926
|
+
* @param {string} message The error message.
|
|
927
|
+
* @throws {SyntaxError} A syntax error.
|
|
928
|
+
* @returns {void}
|
|
929
|
+
*/
|
|
930
|
+
raiseRecoverable(pos, message) {
|
|
931
|
+
this.raise(pos, message);
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
/**
|
|
935
|
+
* Overwrites the default unexpected method to throw Esprima-style errors.
|
|
936
|
+
* @param {int} pos The position of the error.
|
|
937
|
+
* @throws {SyntaxError} A syntax error.
|
|
938
|
+
* @returns {void}
|
|
939
|
+
*/
|
|
940
|
+
unexpected(pos) {
|
|
941
|
+
let message = "Unexpected token";
|
|
942
|
+
|
|
943
|
+
if (pos !== null && pos !== void 0) {
|
|
944
|
+
this.pos = pos;
|
|
945
|
+
|
|
946
|
+
if (this.options.locations) {
|
|
947
|
+
while (this.pos < this.lineStart) {
|
|
948
|
+
this.lineStart = this.input.lastIndexOf("\n", this.lineStart - 2) + 1;
|
|
949
|
+
--this.curLine;
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
this.nextToken();
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
if (this.end > this.start) {
|
|
957
|
+
message += ` ${this.input.slice(this.start, this.end)}`;
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
this.raise(this.start, message);
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
/*
|
|
964
|
+
* Esprima-FB represents JSX strings as tokens called "JSXText", but Acorn-JSX
|
|
965
|
+
* uses regular tt.string without any distinction between this and regular JS
|
|
966
|
+
* strings. As such, we intercept an attempt to read a JSX string and set a flag
|
|
967
|
+
* on extra so that when tokens are converted, the next token will be switched
|
|
968
|
+
* to JSXText via onToken.
|
|
969
|
+
*/
|
|
970
|
+
jsx_readString(quote) { // eslint-disable-line camelcase -- required by API
|
|
971
|
+
const result = super.jsx_readString(quote);
|
|
972
|
+
|
|
973
|
+
if (this.type === tokTypes.string) {
|
|
974
|
+
this[STATE].jsxAttrValueToken = true;
|
|
975
|
+
}
|
|
976
|
+
return result;
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
/**
|
|
980
|
+
* Performs last-minute Esprima-specific compatibility checks and fixes.
|
|
981
|
+
* @param {ASTNode} result The node to check.
|
|
982
|
+
* @returns {ASTNode} The finished node.
|
|
983
|
+
*/
|
|
984
|
+
[ESPRIMA_FINISH_NODE](result) {
|
|
985
|
+
|
|
986
|
+
// Acorn doesn't count the opening and closing backticks as part of templates
|
|
987
|
+
// so we have to adjust ranges/locations appropriately.
|
|
988
|
+
if (result.type === "TemplateElement") {
|
|
989
|
+
|
|
990
|
+
// save template element references to fix start/end later
|
|
991
|
+
this[STATE].templateElements.push(result);
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
if (result.type.includes("Function") && !result.generator) {
|
|
995
|
+
result.generator = false;
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
return result;
|
|
999
|
+
}
|
|
1000
|
+
};
|
|
1001
|
+
};
|
|
1002
|
+
|
|
1003
|
+
const version$1 = "9.6.1";
|
|
1004
|
+
|
|
1005
|
+
/* eslint-disable jsdoc/no-multi-asterisks -- needed to preserve original formatting of licences */
|
|
1006
|
+
|
|
1007
|
+
|
|
1008
|
+
// To initialize lazily.
|
|
1009
|
+
const parsers = {
|
|
1010
|
+
_regular: null,
|
|
1011
|
+
_jsx: null,
|
|
1012
|
+
|
|
1013
|
+
get regular() {
|
|
1014
|
+
if (this._regular === null) {
|
|
1015
|
+
this._regular = acorn__namespace.Parser.extend(espree$1());
|
|
1016
|
+
}
|
|
1017
|
+
return this._regular;
|
|
1018
|
+
},
|
|
1019
|
+
|
|
1020
|
+
get jsx() {
|
|
1021
|
+
if (this._jsx === null) {
|
|
1022
|
+
this._jsx = acorn__namespace.Parser.extend(jsx__default["default"](), espree$1());
|
|
1023
|
+
}
|
|
1024
|
+
return this._jsx;
|
|
1025
|
+
},
|
|
1026
|
+
|
|
1027
|
+
get(options) {
|
|
1028
|
+
const useJsx = Boolean(
|
|
1029
|
+
options &&
|
|
1030
|
+
options.ecmaFeatures &&
|
|
1031
|
+
options.ecmaFeatures.jsx
|
|
1032
|
+
);
|
|
1033
|
+
|
|
1034
|
+
return useJsx ? this.jsx : this.regular;
|
|
1035
|
+
}
|
|
1036
|
+
};
|
|
1037
|
+
|
|
1038
|
+
//------------------------------------------------------------------------------
|
|
1039
|
+
// Tokenizer
|
|
1040
|
+
//------------------------------------------------------------------------------
|
|
1041
|
+
|
|
1042
|
+
/**
|
|
1043
|
+
* Tokenizes the given code.
|
|
1044
|
+
* @param {string} code The code to tokenize.
|
|
1045
|
+
* @param {Object} options Options defining how to tokenize.
|
|
1046
|
+
* @returns {Token[]} An array of tokens.
|
|
1047
|
+
* @throws {SyntaxError} If the input code is invalid.
|
|
1048
|
+
* @private
|
|
1049
|
+
*/
|
|
1050
|
+
function tokenize(code, options) {
|
|
1051
|
+
const Parser = parsers.get(options);
|
|
1052
|
+
|
|
1053
|
+
// Ensure to collect tokens.
|
|
1054
|
+
if (!options || options.tokens !== true) {
|
|
1055
|
+
options = Object.assign({}, options, { tokens: true }); // eslint-disable-line no-param-reassign -- stylistic choice
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
return new Parser(options, code).tokenize();
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
//------------------------------------------------------------------------------
|
|
1062
|
+
// Parser
|
|
1063
|
+
//------------------------------------------------------------------------------
|
|
1064
|
+
|
|
1065
|
+
/**
|
|
1066
|
+
* Parses the given code.
|
|
1067
|
+
* @param {string} code The code to tokenize.
|
|
1068
|
+
* @param {Object} options Options defining how to tokenize.
|
|
1069
|
+
* @returns {ASTNode} The "Program" AST node.
|
|
1070
|
+
* @throws {SyntaxError} If the input code is invalid.
|
|
1071
|
+
*/
|
|
1072
|
+
function parse(code, options) {
|
|
1073
|
+
const Parser = parsers.get(options);
|
|
1074
|
+
|
|
1075
|
+
return new Parser(options, code).parse();
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
//------------------------------------------------------------------------------
|
|
1079
|
+
// Public
|
|
1080
|
+
//------------------------------------------------------------------------------
|
|
1081
|
+
|
|
1082
|
+
const version = version$1;
|
|
1083
|
+
const name = "espree";
|
|
1084
|
+
|
|
1085
|
+
/* istanbul ignore next */
|
|
1086
|
+
const VisitorKeys = (function() {
|
|
1087
|
+
return visitorKeys__namespace.KEYS;
|
|
1088
|
+
}());
|
|
1089
|
+
|
|
1090
|
+
// Derive node types from VisitorKeys
|
|
1091
|
+
/* istanbul ignore next */
|
|
1092
|
+
const Syntax = (function() {
|
|
1093
|
+
let key,
|
|
1094
|
+
types = {};
|
|
1095
|
+
|
|
1096
|
+
if (typeof Object.create === "function") {
|
|
1097
|
+
types = Object.create(null);
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
for (key in VisitorKeys) {
|
|
1101
|
+
if (Object.hasOwnProperty.call(VisitorKeys, key)) {
|
|
1102
|
+
types[key] = key;
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
if (typeof Object.freeze === "function") {
|
|
1107
|
+
Object.freeze(types);
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
return types;
|
|
1111
|
+
}());
|
|
1112
|
+
|
|
1113
|
+
const latestEcmaVersion = getLatestEcmaVersion();
|
|
1114
|
+
|
|
1115
|
+
const supportedEcmaVersions = getSupportedEcmaVersions();
|
|
1116
|
+
|
|
1117
|
+
espree.Syntax = Syntax;
|
|
1118
|
+
espree.VisitorKeys = VisitorKeys;
|
|
1119
|
+
espree.latestEcmaVersion = latestEcmaVersion;
|
|
1120
|
+
espree.name = name;
|
|
1121
|
+
espree.parse = parse;
|
|
1122
|
+
espree.supportedEcmaVersions = supportedEcmaVersions;
|
|
1123
|
+
espree.tokenize = tokenize;
|
|
1124
|
+
espree.version = version;
|
|
1125
|
+
return espree;
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
var hasRequiredEspree;
|
|
1129
|
+
|
|
1130
|
+
function requireEspree () {
|
|
1131
|
+
if (hasRequiredEspree) return espree$1;
|
|
1132
|
+
hasRequiredEspree = 1;
|
|
1133
|
+
Object.defineProperty(espree$1, "__esModule", { value: true });
|
|
1134
|
+
espree$1.getNewestEspreeKind = espree$1.getEspree = void 0;
|
|
1135
|
+
const require_utils_1 = requireRequireUtils();
|
|
1136
|
+
const semver_1 = requireSemver();
|
|
1137
|
+
let espreeCache = null;
|
|
1138
|
+
function getEspree() {
|
|
1139
|
+
if (!espreeCache) {
|
|
1140
|
+
espreeCache = (0, require_utils_1.loadNewest)([
|
|
1141
|
+
{
|
|
1142
|
+
getPkg() {
|
|
1143
|
+
return (0, require_utils_1.requireFromCwd)("espree/package.json");
|
|
1144
|
+
},
|
|
1145
|
+
get() {
|
|
1146
|
+
return (0, require_utils_1.requireFromCwd)("espree");
|
|
1147
|
+
},
|
|
1148
|
+
},
|
|
1149
|
+
{
|
|
1150
|
+
getPkg() {
|
|
1151
|
+
return (0, require_utils_1.requireFromLinter)("espree/package.json");
|
|
1152
|
+
},
|
|
1153
|
+
get() {
|
|
1154
|
+
return (0, require_utils_1.requireFromLinter)("espree");
|
|
1155
|
+
},
|
|
1156
|
+
},
|
|
1157
|
+
{
|
|
1158
|
+
getPkg() {
|
|
1159
|
+
return require$$4;
|
|
1160
|
+
},
|
|
1161
|
+
get() {
|
|
1162
|
+
return requireEspree$1();
|
|
1163
|
+
},
|
|
1164
|
+
},
|
|
1165
|
+
]);
|
|
1166
|
+
}
|
|
1167
|
+
return espreeCache;
|
|
1168
|
+
}
|
|
1169
|
+
espree$1.getEspree = getEspree;
|
|
1170
|
+
let kindCache = null;
|
|
1171
|
+
function getNewestEspreeKind() {
|
|
1172
|
+
if (kindCache) {
|
|
1173
|
+
return kindCache;
|
|
1174
|
+
}
|
|
1175
|
+
const cwdPkg = (0, require_utils_1.requireFromCwd)("espree/package.json");
|
|
1176
|
+
const linterPkg = (0, require_utils_1.requireFromLinter)("espree/package.json");
|
|
1177
|
+
const self = require$$4;
|
|
1178
|
+
let target = {
|
|
1179
|
+
kind: "self",
|
|
1180
|
+
version: self.version,
|
|
1181
|
+
};
|
|
1182
|
+
if (cwdPkg != null && (0, semver_1.lte)(target.version, cwdPkg.version)) {
|
|
1183
|
+
target = { kind: "cwd", version: cwdPkg.version };
|
|
1184
|
+
}
|
|
1185
|
+
if (linterPkg != null && (0, semver_1.lte)(target.version, linterPkg.version)) {
|
|
1186
|
+
target = { kind: "linter", version: linterPkg.version };
|
|
1187
|
+
}
|
|
1188
|
+
return (kindCache = target.kind);
|
|
1189
|
+
}
|
|
1190
|
+
espree$1.getNewestEspreeKind = getNewestEspreeKind;
|
|
1191
|
+
return espree$1;
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
var visitorKeys = {};
|
|
1195
|
+
|
|
1196
|
+
const name$1 = "eslint-visitor-keys";
|
|
1197
|
+
const version$1 = "3.4.3";
|
|
1198
|
+
const description$1 = "Constants and utilities about visitor keys to traverse AST.";
|
|
1199
|
+
const type = "module";
|
|
1200
|
+
const main$1 = "dist/eslint-visitor-keys.cjs";
|
|
1201
|
+
const types$1 = "./dist/index.d.ts";
|
|
1202
|
+
const exports$1 = {
|
|
1203
|
+
".": [
|
|
1204
|
+
{
|
|
1205
|
+
"import": "./lib/index.js",
|
|
1206
|
+
require: "./dist/eslint-visitor-keys.cjs"
|
|
1207
|
+
},
|
|
1208
|
+
"./dist/eslint-visitor-keys.cjs"
|
|
1209
|
+
],
|
|
1210
|
+
"./package.json": "./package.json"
|
|
1211
|
+
};
|
|
1212
|
+
const files = [
|
|
1213
|
+
"dist/index.d.ts",
|
|
1214
|
+
"dist/visitor-keys.d.ts",
|
|
1215
|
+
"dist/eslint-visitor-keys.cjs",
|
|
1216
|
+
"dist/eslint-visitor-keys.d.cts",
|
|
1217
|
+
"lib"
|
|
1218
|
+
];
|
|
1219
|
+
const engines$1 = {
|
|
1220
|
+
node: "^12.22.0 || ^14.17.0 || >=16.0.0"
|
|
1221
|
+
};
|
|
1222
|
+
const devDependencies = {
|
|
1223
|
+
"@types/estree": "^0.0.51",
|
|
1224
|
+
"@types/estree-jsx": "^0.0.1",
|
|
1225
|
+
"@typescript-eslint/parser": "^5.14.0",
|
|
1226
|
+
c8: "^7.11.0",
|
|
1227
|
+
chai: "^4.3.6",
|
|
1228
|
+
eslint: "^7.29.0",
|
|
1229
|
+
"eslint-config-eslint": "^7.0.0",
|
|
1230
|
+
"eslint-plugin-jsdoc": "^35.4.0",
|
|
1231
|
+
"eslint-plugin-node": "^11.1.0",
|
|
1232
|
+
"eslint-release": "^3.2.0",
|
|
1233
|
+
esquery: "^1.4.0",
|
|
1234
|
+
"json-diff": "^0.7.3",
|
|
1235
|
+
mocha: "^9.2.1",
|
|
1236
|
+
opener: "^1.5.2",
|
|
1237
|
+
rollup: "^2.70.0",
|
|
1238
|
+
"rollup-plugin-dts": "^4.2.3",
|
|
1239
|
+
tsd: "^0.19.1",
|
|
1240
|
+
typescript: "^4.6.2"
|
|
1241
|
+
};
|
|
1242
|
+
const scripts$1 = {
|
|
1243
|
+
build: "npm run build:cjs && npm run build:types",
|
|
1244
|
+
"build:cjs": "rollup -c",
|
|
1245
|
+
"build:debug": "npm run build:cjs -- -m && npm run build:types",
|
|
1246
|
+
"build:keys": "node tools/build-keys-from-ts",
|
|
1247
|
+
"build:types": "tsc",
|
|
1248
|
+
lint: "eslint .",
|
|
1249
|
+
prepare: "npm run build",
|
|
1250
|
+
"release:generate:latest": "eslint-generate-release",
|
|
1251
|
+
"release:generate:alpha": "eslint-generate-prerelease alpha",
|
|
1252
|
+
"release:generate:beta": "eslint-generate-prerelease beta",
|
|
1253
|
+
"release:generate:rc": "eslint-generate-prerelease rc",
|
|
1254
|
+
"release:publish": "eslint-publish-release",
|
|
1255
|
+
test: "mocha tests/lib/**/*.cjs && c8 mocha tests/lib/**/*.js && npm run test:types",
|
|
1256
|
+
"test:open-coverage": "c8 report --reporter lcov && opener coverage/lcov-report/index.html",
|
|
1257
|
+
"test:types": "tsd"
|
|
1258
|
+
};
|
|
1259
|
+
const repository$1 = "eslint/eslint-visitor-keys";
|
|
1260
|
+
const funding = "https://opencollective.com/eslint";
|
|
1261
|
+
const keywords = [
|
|
1262
|
+
];
|
|
1263
|
+
const author = "Toru Nagashima (https://github.com/mysticatea)";
|
|
1264
|
+
const license$1 = "Apache-2.0";
|
|
1265
|
+
const bugs = {
|
|
1266
|
+
url: "https://github.com/eslint/eslint-visitor-keys/issues"
|
|
1267
|
+
};
|
|
1268
|
+
const homepage$1 = "https://github.com/eslint/eslint-visitor-keys#readme";
|
|
1269
|
+
const _package$2 = {
|
|
1270
|
+
name: name$1,
|
|
1271
|
+
version: version$1,
|
|
1272
|
+
description: description$1,
|
|
1273
|
+
type: type,
|
|
1274
|
+
main: main$1,
|
|
1275
|
+
types: types$1,
|
|
1276
|
+
exports: exports$1,
|
|
1277
|
+
files: files,
|
|
1278
|
+
engines: engines$1,
|
|
1279
|
+
devDependencies: devDependencies,
|
|
1280
|
+
scripts: scripts$1,
|
|
1281
|
+
repository: repository$1,
|
|
1282
|
+
funding: funding,
|
|
1283
|
+
keywords: keywords,
|
|
1284
|
+
author: author,
|
|
1285
|
+
license: license$1,
|
|
1286
|
+
bugs: bugs,
|
|
1287
|
+
homepage: homepage$1
|
|
1288
|
+
};
|
|
1289
|
+
|
|
1290
|
+
const _package$3 = {
|
|
1291
|
+
__proto__: null,
|
|
1292
|
+
author: author,
|
|
1293
|
+
bugs: bugs,
|
|
1294
|
+
default: _package$2,
|
|
1295
|
+
description: description$1,
|
|
1296
|
+
devDependencies: devDependencies,
|
|
1297
|
+
engines: engines$1,
|
|
1298
|
+
exports: exports$1,
|
|
1299
|
+
files: files,
|
|
1300
|
+
funding: funding,
|
|
1301
|
+
homepage: homepage$1,
|
|
1302
|
+
keywords: keywords,
|
|
1303
|
+
license: license$1,
|
|
1304
|
+
main: main$1,
|
|
1305
|
+
name: name$1,
|
|
1306
|
+
repository: repository$1,
|
|
1307
|
+
scripts: scripts$1,
|
|
1308
|
+
type: type,
|
|
1309
|
+
types: types$1,
|
|
1310
|
+
version: version$1
|
|
1311
|
+
};
|
|
1312
|
+
|
|
1313
|
+
const require$$1 = /*@__PURE__*/getAugmentedNamespace(_package$3);
|
|
1314
|
+
|
|
1315
|
+
var hasRequiredVisitorKeys;
|
|
1316
|
+
|
|
1317
|
+
function requireVisitorKeys () {
|
|
1318
|
+
if (hasRequiredVisitorKeys) return visitorKeys;
|
|
1319
|
+
hasRequiredVisitorKeys = 1;
|
|
1320
|
+
Object.defineProperty(visitorKeys, "__esModule", { value: true });
|
|
1321
|
+
visitorKeys.getVisitorKeys = void 0;
|
|
1322
|
+
const require_utils_1 = requireRequireUtils();
|
|
1323
|
+
const jsonKeys = {
|
|
1324
|
+
Program: ["body"],
|
|
1325
|
+
JSONExpressionStatement: ["expression"],
|
|
1326
|
+
JSONArrayExpression: ["elements"],
|
|
1327
|
+
JSONObjectExpression: ["properties"],
|
|
1328
|
+
JSONProperty: ["key", "value"],
|
|
1329
|
+
JSONIdentifier: [],
|
|
1330
|
+
JSONLiteral: [],
|
|
1331
|
+
JSONUnaryExpression: ["argument"],
|
|
1332
|
+
JSONTemplateLiteral: ["quasis", "expressions"],
|
|
1333
|
+
JSONTemplateElement: [],
|
|
1334
|
+
JSONBinaryExpression: ["left", "right"],
|
|
1335
|
+
};
|
|
1336
|
+
let cache = null;
|
|
1337
|
+
function getVisitorKeys() {
|
|
1338
|
+
if (!cache) {
|
|
1339
|
+
const vk = (0, require_utils_1.loadNewest)([
|
|
1340
|
+
{
|
|
1341
|
+
getPkg() {
|
|
1342
|
+
return (0, require_utils_1.requireFromCwd)("eslint-visitor-keys/package.json");
|
|
1343
|
+
},
|
|
1344
|
+
get() {
|
|
1345
|
+
return (0, require_utils_1.requireFromCwd)("eslint-visitor-keys");
|
|
1346
|
+
},
|
|
1347
|
+
},
|
|
1348
|
+
{
|
|
1349
|
+
getPkg() {
|
|
1350
|
+
return (0, require_utils_1.requireFromLinter)("eslint-visitor-keys/package.json");
|
|
1351
|
+
},
|
|
1352
|
+
get() {
|
|
1353
|
+
return (0, require_utils_1.requireFromLinter)("eslint-visitor-keys");
|
|
1354
|
+
},
|
|
1355
|
+
},
|
|
1356
|
+
{
|
|
1357
|
+
getPkg() {
|
|
1358
|
+
return require$$1;
|
|
1359
|
+
},
|
|
1360
|
+
get() {
|
|
1361
|
+
return requireEslintVisitorKeys();
|
|
1362
|
+
},
|
|
1363
|
+
},
|
|
1364
|
+
]);
|
|
1365
|
+
cache = vk.unionWith(jsonKeys);
|
|
1366
|
+
}
|
|
1367
|
+
return cache;
|
|
1368
|
+
}
|
|
1369
|
+
visitorKeys.getVisitorKeys = getVisitorKeys;
|
|
1370
|
+
return visitorKeys;
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
var convert = {};
|
|
1374
|
+
|
|
1375
|
+
var validate = {};
|
|
1376
|
+
|
|
1377
|
+
var errors = {};
|
|
1378
|
+
|
|
1379
|
+
var utils = {};
|
|
1380
|
+
|
|
1381
|
+
var hasRequiredUtils;
|
|
1382
|
+
|
|
1383
|
+
function requireUtils () {
|
|
1384
|
+
if (hasRequiredUtils) return utils;
|
|
1385
|
+
hasRequiredUtils = 1;
|
|
1386
|
+
Object.defineProperty(utils, "__esModule", { value: true });
|
|
1387
|
+
utils.isRegExpLiteral = void 0;
|
|
1388
|
+
function isRegExpLiteral(node) {
|
|
1389
|
+
return (Boolean(node.regex) ||
|
|
1390
|
+
node.raw.startsWith("/"));
|
|
1391
|
+
}
|
|
1392
|
+
utils.isRegExpLiteral = isRegExpLiteral;
|
|
1393
|
+
return utils;
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
var hasRequiredErrors;
|
|
1397
|
+
|
|
1398
|
+
function requireErrors () {
|
|
1399
|
+
if (hasRequiredErrors) return errors;
|
|
1400
|
+
hasRequiredErrors = 1;
|
|
1401
|
+
Object.defineProperty(errors, "__esModule", { value: true });
|
|
1402
|
+
errors.throwUnexpectedNodeError = errors.throwInvalidNumberError = errors.throwUnexpectedSpaceError = errors.throwUnexpectedCommentError = errors.throwUnexpectedTokenError = errors.throwUnexpectedError = errors.throwExpectedTokenError = errors.ParseError = void 0;
|
|
1403
|
+
const utils_1 = requireUtils();
|
|
1404
|
+
class ParseError extends SyntaxError {
|
|
1405
|
+
constructor(message, offset, line, column) {
|
|
1406
|
+
super(message);
|
|
1407
|
+
this.index = offset;
|
|
1408
|
+
this.lineNumber = line;
|
|
1409
|
+
this.column = column;
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
errors.ParseError = ParseError;
|
|
1413
|
+
function throwExpectedTokenError(name, beforeToken) {
|
|
1414
|
+
const locs = getLocation(beforeToken);
|
|
1415
|
+
const err = new ParseError(`Expected token '${name}'.`, locs.end, locs.loc.end.line, locs.loc.end.column + 1);
|
|
1416
|
+
throw err;
|
|
1417
|
+
}
|
|
1418
|
+
errors.throwExpectedTokenError = throwExpectedTokenError;
|
|
1419
|
+
function throwUnexpectedError(name, token) {
|
|
1420
|
+
const locs = getLocation(token);
|
|
1421
|
+
const err = new ParseError(`Unexpected ${name}.`, locs.start, locs.loc.start.line, locs.loc.start.column + 1);
|
|
1422
|
+
throw err;
|
|
1423
|
+
}
|
|
1424
|
+
errors.throwUnexpectedError = throwUnexpectedError;
|
|
1425
|
+
function throwUnexpectedTokenError(name, token) {
|
|
1426
|
+
return throwUnexpectedError(`token '${name}'`, token);
|
|
1427
|
+
}
|
|
1428
|
+
errors.throwUnexpectedTokenError = throwUnexpectedTokenError;
|
|
1429
|
+
function throwUnexpectedCommentError(token) {
|
|
1430
|
+
return throwUnexpectedError("comment", token);
|
|
1431
|
+
}
|
|
1432
|
+
errors.throwUnexpectedCommentError = throwUnexpectedCommentError;
|
|
1433
|
+
function throwUnexpectedSpaceError(beforeToken) {
|
|
1434
|
+
const locs = getLocation(beforeToken);
|
|
1435
|
+
const err = new ParseError("Unexpected whitespace.", locs.end, locs.loc.end.line, locs.loc.end.column + 1);
|
|
1436
|
+
throw err;
|
|
1437
|
+
}
|
|
1438
|
+
errors.throwUnexpectedSpaceError = throwUnexpectedSpaceError;
|
|
1439
|
+
function throwInvalidNumberError(text, token) {
|
|
1440
|
+
const locs = getLocation(token);
|
|
1441
|
+
const err = new ParseError(`Invalid number ${text}.`, locs.start, locs.loc.start.line, locs.loc.start.column + 1);
|
|
1442
|
+
throw err;
|
|
1443
|
+
}
|
|
1444
|
+
errors.throwInvalidNumberError = throwInvalidNumberError;
|
|
1445
|
+
function throwUnexpectedNodeError(node, tokens, offset) {
|
|
1446
|
+
if (node.type === "Identifier" || node.type === "JSONIdentifier") {
|
|
1447
|
+
const locs = getLocation(node);
|
|
1448
|
+
const err = new ParseError(`Unexpected identifier '${node.name}'.`, locs.start, locs.loc.start.line, locs.loc.start.column + 1);
|
|
1449
|
+
throw err;
|
|
1450
|
+
}
|
|
1451
|
+
if (node.type === "Literal" || node.type === "JSONLiteral") {
|
|
1452
|
+
const type = node.bigint
|
|
1453
|
+
? "bigint"
|
|
1454
|
+
: (0, utils_1.isRegExpLiteral)(node)
|
|
1455
|
+
? "regex"
|
|
1456
|
+
: node.value === null
|
|
1457
|
+
? "null"
|
|
1458
|
+
: typeof node.value;
|
|
1459
|
+
const locs = getLocation(node);
|
|
1460
|
+
const err = new ParseError(`Unexpected ${type} literal.`, locs.start, locs.loc.start.line, locs.loc.start.column + 1);
|
|
1461
|
+
throw err;
|
|
1462
|
+
}
|
|
1463
|
+
if (node.type === "TemplateLiteral" || node.type === "JSONTemplateLiteral") {
|
|
1464
|
+
const locs = getLocation(node);
|
|
1465
|
+
const err = new ParseError("Unexpected template literal.", locs.start, locs.loc.start.line, locs.loc.start.column + 1);
|
|
1466
|
+
throw err;
|
|
1467
|
+
}
|
|
1468
|
+
if (node.type.endsWith("Expression") && node.type !== "FunctionExpression") {
|
|
1469
|
+
const name = node.type
|
|
1470
|
+
.replace(/^JSON/u, "")
|
|
1471
|
+
.replace(/\B([A-Z])/gu, " $1")
|
|
1472
|
+
.toLowerCase();
|
|
1473
|
+
const locs = getLocation(node);
|
|
1474
|
+
const err = new ParseError(`Unexpected ${name}.`, locs.start, locs.loc.start.line, locs.loc.start.column + 1);
|
|
1475
|
+
throw err;
|
|
1476
|
+
}
|
|
1477
|
+
const index = node.range[0] + (offset || 0);
|
|
1478
|
+
const t = tokens.findTokenByOffset(index);
|
|
1479
|
+
const name = (t === null || t === void 0 ? void 0 : t.value) || "unknown";
|
|
1480
|
+
const locs = getLocation(t || node);
|
|
1481
|
+
const err = new ParseError(`Unexpected token '${name}'.`, locs.start, locs.loc.start.line, locs.loc.start.column + 1);
|
|
1482
|
+
throw err;
|
|
1483
|
+
}
|
|
1484
|
+
errors.throwUnexpectedNodeError = throwUnexpectedNodeError;
|
|
1485
|
+
function getLocation(token) {
|
|
1486
|
+
var _a, _b, _c, _d;
|
|
1487
|
+
const start = (_b = (_a = token.range) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : token.start;
|
|
1488
|
+
const end = (_d = (_c = token.range) === null || _c === void 0 ? void 0 : _c[1]) !== null && _d !== void 0 ? _d : token.end;
|
|
1489
|
+
const loc = token.loc;
|
|
1490
|
+
return { start, end, loc };
|
|
1491
|
+
}
|
|
1492
|
+
return errors;
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
var tokenStore = {};
|
|
1496
|
+
|
|
1497
|
+
var hasRequiredTokenStore;
|
|
1498
|
+
|
|
1499
|
+
function requireTokenStore () {
|
|
1500
|
+
if (hasRequiredTokenStore) return tokenStore;
|
|
1501
|
+
hasRequiredTokenStore = 1;
|
|
1502
|
+
Object.defineProperty(tokenStore, "__esModule", { value: true });
|
|
1503
|
+
tokenStore.isComma = tokenStore.TokenStore = void 0;
|
|
1504
|
+
class TokenStore {
|
|
1505
|
+
constructor(tokens) {
|
|
1506
|
+
this.tokens = tokens;
|
|
1507
|
+
}
|
|
1508
|
+
add(token) {
|
|
1509
|
+
this.tokens.push(token);
|
|
1510
|
+
}
|
|
1511
|
+
findIndexByOffset(offset) {
|
|
1512
|
+
return this.tokens.findIndex((token) => token.range[0] <= offset && offset < token.range[1]);
|
|
1513
|
+
}
|
|
1514
|
+
findTokenByOffset(offset) {
|
|
1515
|
+
return this.tokens[this.findIndexByOffset(offset)];
|
|
1516
|
+
}
|
|
1517
|
+
getFirstToken(nodeOrToken) {
|
|
1518
|
+
return this.findTokenByOffset(nodeOrToken.range[0]);
|
|
1519
|
+
}
|
|
1520
|
+
getLastToken(nodeOrToken) {
|
|
1521
|
+
return this.findTokenByOffset(nodeOrToken.range[1] - 1);
|
|
1522
|
+
}
|
|
1523
|
+
getTokenBefore(nodeOrToken, filter) {
|
|
1524
|
+
const tokenIndex = this.findIndexByOffset(nodeOrToken.range[0]);
|
|
1525
|
+
for (let index = tokenIndex - 1; index >= 0; index--) {
|
|
1526
|
+
const token = this.tokens[index];
|
|
1527
|
+
if (!filter || filter(token)) {
|
|
1528
|
+
return token;
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
return null;
|
|
1532
|
+
}
|
|
1533
|
+
getTokenAfter(nodeOrToken, filter) {
|
|
1534
|
+
const tokenIndex = this.findIndexByOffset(nodeOrToken.range[0]);
|
|
1535
|
+
for (let index = tokenIndex + 1; index < this.tokens.length; index++) {
|
|
1536
|
+
const token = this.tokens[index];
|
|
1537
|
+
if (!filter || filter(token)) {
|
|
1538
|
+
return token;
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
return null;
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
tokenStore.TokenStore = TokenStore;
|
|
1545
|
+
function isComma(token) {
|
|
1546
|
+
return token.type === "Punctuator" && token.value === ",";
|
|
1547
|
+
}
|
|
1548
|
+
tokenStore.isComma = isComma;
|
|
1549
|
+
return tokenStore;
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
var hasRequiredValidate;
|
|
1553
|
+
|
|
1554
|
+
function requireValidate () {
|
|
1555
|
+
if (hasRequiredValidate) return validate;
|
|
1556
|
+
hasRequiredValidate = 1;
|
|
1557
|
+
Object.defineProperty(validate, "__esModule", { value: true });
|
|
1558
|
+
validate.isStaticValueIdentifier = validate.validateNode = void 0;
|
|
1559
|
+
const errors_1 = requireErrors();
|
|
1560
|
+
const token_store_1 = requireTokenStore();
|
|
1561
|
+
const utils_1 = requireUtils();
|
|
1562
|
+
const lineBreakPattern = /\r\n|[\n\r\u2028\u2029]/u;
|
|
1563
|
+
const octalNumericLiteralPattern = /^0o/iu;
|
|
1564
|
+
const legacyOctalNumericLiteralPattern = /^0\d/u;
|
|
1565
|
+
const binaryNumericLiteralPattern = /^0b/iu;
|
|
1566
|
+
const unicodeCodepointEscapePattern = /\\u\{[\dA-Fa-f]+\}/uy;
|
|
1567
|
+
function hasUnicodeCodepointEscapes(code) {
|
|
1568
|
+
let escaped = false;
|
|
1569
|
+
for (let index = 0; index < code.length - 4; index++) {
|
|
1570
|
+
if (escaped) {
|
|
1571
|
+
escaped = false;
|
|
1572
|
+
continue;
|
|
1573
|
+
}
|
|
1574
|
+
const char = code[index];
|
|
1575
|
+
if (char === "\\") {
|
|
1576
|
+
unicodeCodepointEscapePattern.lastIndex = index;
|
|
1577
|
+
if (unicodeCodepointEscapePattern.test(code)) {
|
|
1578
|
+
return true;
|
|
1579
|
+
}
|
|
1580
|
+
escaped = true;
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
return false;
|
|
1584
|
+
}
|
|
1585
|
+
function validateNode(node, tokens, ctx) {
|
|
1586
|
+
if (node.type === "ObjectExpression") {
|
|
1587
|
+
validateObjectExpressionNode(node, tokens, ctx);
|
|
1588
|
+
return;
|
|
1589
|
+
}
|
|
1590
|
+
if (node.type === "Property") {
|
|
1591
|
+
validatePropertyNode(node, tokens, ctx);
|
|
1592
|
+
return;
|
|
1593
|
+
}
|
|
1594
|
+
if (node.type === "ArrayExpression") {
|
|
1595
|
+
validateArrayExpressionNode(node, tokens, ctx);
|
|
1596
|
+
return;
|
|
1597
|
+
}
|
|
1598
|
+
if (node.type === "Literal") {
|
|
1599
|
+
validateLiteralNode(node, tokens, ctx);
|
|
1600
|
+
return;
|
|
1601
|
+
}
|
|
1602
|
+
if (node.type === "UnaryExpression") {
|
|
1603
|
+
validateUnaryExpressionNode(node, tokens, ctx);
|
|
1604
|
+
return;
|
|
1605
|
+
}
|
|
1606
|
+
if (node.type === "Identifier") {
|
|
1607
|
+
validateIdentifierNode(node, tokens, ctx);
|
|
1608
|
+
return;
|
|
1609
|
+
}
|
|
1610
|
+
if (node.type === "TemplateLiteral") {
|
|
1611
|
+
validateTemplateLiteralNode(node, tokens, ctx);
|
|
1612
|
+
return;
|
|
1613
|
+
}
|
|
1614
|
+
if (node.type === "TemplateElement") {
|
|
1615
|
+
validateTemplateElementNode(node, tokens);
|
|
1616
|
+
return;
|
|
1617
|
+
}
|
|
1618
|
+
if (node.type === "BinaryExpression") {
|
|
1619
|
+
validateBinaryExpressionNode(node, tokens, ctx);
|
|
1620
|
+
return;
|
|
1621
|
+
}
|
|
1622
|
+
throw (0, errors_1.throwUnexpectedNodeError)(node, tokens);
|
|
1623
|
+
}
|
|
1624
|
+
validate.validateNode = validateNode;
|
|
1625
|
+
function validateObjectExpressionNode(node, tokens, ctx) {
|
|
1626
|
+
if (node.type !== "ObjectExpression") {
|
|
1627
|
+
throw (0, errors_1.throwUnexpectedNodeError)(node, tokens);
|
|
1628
|
+
}
|
|
1629
|
+
for (const prop of node.properties) {
|
|
1630
|
+
setParent(prop, node);
|
|
1631
|
+
}
|
|
1632
|
+
if (!ctx.trailingCommas) {
|
|
1633
|
+
const token = tokens.getTokenBefore(tokens.getLastToken(node));
|
|
1634
|
+
if (token && (0, token_store_1.isComma)(token)) {
|
|
1635
|
+
throw (0, errors_1.throwUnexpectedTokenError)(",", token);
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
function validatePropertyNode(node, tokens, ctx) {
|
|
1640
|
+
if (node.type !== "Property") {
|
|
1641
|
+
throw (0, errors_1.throwUnexpectedNodeError)(node, tokens);
|
|
1642
|
+
}
|
|
1643
|
+
setParent(node.key, node);
|
|
1644
|
+
setParent(node.value, node);
|
|
1645
|
+
if (node.computed) {
|
|
1646
|
+
throw (0, errors_1.throwUnexpectedNodeError)(node, tokens);
|
|
1647
|
+
}
|
|
1648
|
+
if (node.method) {
|
|
1649
|
+
throw (0, errors_1.throwUnexpectedNodeError)(node.value, tokens);
|
|
1650
|
+
}
|
|
1651
|
+
if (node.shorthand) {
|
|
1652
|
+
throw (0, errors_1.throwExpectedTokenError)(":", node);
|
|
1653
|
+
}
|
|
1654
|
+
if (node.kind !== "init") {
|
|
1655
|
+
throw (0, errors_1.throwExpectedTokenError)(":", tokens.getFirstToken(node));
|
|
1656
|
+
}
|
|
1657
|
+
if (node.key.type === "Literal") {
|
|
1658
|
+
const keyValueType = typeof node.key.value;
|
|
1659
|
+
if (keyValueType === "number") {
|
|
1660
|
+
if (!ctx.numberProperties) {
|
|
1661
|
+
throw (0, errors_1.throwUnexpectedNodeError)(node.key, tokens);
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
else if (keyValueType !== "string") {
|
|
1665
|
+
throw (0, errors_1.throwUnexpectedNodeError)(node.key, tokens);
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
else if (node.key.type === "Identifier") {
|
|
1669
|
+
if (!ctx.unquoteProperties) {
|
|
1670
|
+
throw (0, errors_1.throwUnexpectedNodeError)(node.key, tokens);
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
else {
|
|
1674
|
+
throw (0, errors_1.throwUnexpectedNodeError)(node.key, tokens);
|
|
1675
|
+
}
|
|
1676
|
+
if (node.value.type === "Identifier") {
|
|
1677
|
+
if (!isStaticValueIdentifier(node.value, ctx)) {
|
|
1678
|
+
throw (0, errors_1.throwUnexpectedNodeError)(node.value, tokens);
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
function validateArrayExpressionNode(node, tokens, ctx) {
|
|
1683
|
+
if (node.type !== "ArrayExpression") {
|
|
1684
|
+
throw (0, errors_1.throwUnexpectedNodeError)(node, tokens);
|
|
1685
|
+
}
|
|
1686
|
+
if (!ctx.trailingCommas) {
|
|
1687
|
+
const token = tokens.getTokenBefore(tokens.getLastToken(node));
|
|
1688
|
+
if (token && (0, token_store_1.isComma)(token)) {
|
|
1689
|
+
throw (0, errors_1.throwUnexpectedTokenError)(",", token);
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
node.elements.forEach((child, index) => {
|
|
1693
|
+
if (!child) {
|
|
1694
|
+
if (ctx.sparseArrays) {
|
|
1695
|
+
return;
|
|
1696
|
+
}
|
|
1697
|
+
const beforeIndex = index - 1;
|
|
1698
|
+
const before = beforeIndex >= 0
|
|
1699
|
+
? tokens.getLastToken(node.elements[beforeIndex])
|
|
1700
|
+
: tokens.getFirstToken(node);
|
|
1701
|
+
throw (0, errors_1.throwUnexpectedTokenError)(",", tokens.getTokenAfter(before, token_store_1.isComma));
|
|
1702
|
+
}
|
|
1703
|
+
if (child.type === "Identifier") {
|
|
1704
|
+
if (!isStaticValueIdentifier(child, ctx)) {
|
|
1705
|
+
throw (0, errors_1.throwUnexpectedNodeError)(child, tokens);
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
setParent(child, node);
|
|
1709
|
+
});
|
|
1710
|
+
}
|
|
1711
|
+
function validateLiteralNode(node, tokens, ctx) {
|
|
1712
|
+
if (node.type !== "Literal") {
|
|
1713
|
+
throw (0, errors_1.throwUnexpectedNodeError)(node, tokens);
|
|
1714
|
+
}
|
|
1715
|
+
if ((0, utils_1.isRegExpLiteral)(node)) {
|
|
1716
|
+
if (!ctx.regExpLiterals) {
|
|
1717
|
+
throw (0, errors_1.throwUnexpectedNodeError)(node, tokens);
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
else if (node.bigint) {
|
|
1721
|
+
if (!ctx.bigintLiterals) {
|
|
1722
|
+
throw (0, errors_1.throwUnexpectedNodeError)(node, tokens);
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
else {
|
|
1726
|
+
validateLiteral(node, ctx);
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
function validateLiteral(node, ctx) {
|
|
1730
|
+
const value = node.value;
|
|
1731
|
+
if ((!ctx.invalidJsonNumbers ||
|
|
1732
|
+
!ctx.leadingOrTrailingDecimalPoints ||
|
|
1733
|
+
!ctx.numericSeparators) &&
|
|
1734
|
+
typeof value === "number") {
|
|
1735
|
+
const text = node.raw;
|
|
1736
|
+
if (!ctx.leadingOrTrailingDecimalPoints) {
|
|
1737
|
+
if (text.startsWith(".")) {
|
|
1738
|
+
throw (0, errors_1.throwUnexpectedTokenError)(".", node);
|
|
1739
|
+
}
|
|
1740
|
+
if (text.endsWith(".")) {
|
|
1741
|
+
throw (0, errors_1.throwUnexpectedTokenError)(".", {
|
|
1742
|
+
range: [node.range[1] - 1, node.range[1]],
|
|
1743
|
+
loc: {
|
|
1744
|
+
start: {
|
|
1745
|
+
line: node.loc.end.line,
|
|
1746
|
+
column: node.loc.end.column - 1,
|
|
1747
|
+
},
|
|
1748
|
+
end: node.loc.end,
|
|
1749
|
+
},
|
|
1750
|
+
});
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
if (!ctx.numericSeparators) {
|
|
1754
|
+
if (text.includes("_")) {
|
|
1755
|
+
const index = text.indexOf("_");
|
|
1756
|
+
throw (0, errors_1.throwUnexpectedTokenError)("_", {
|
|
1757
|
+
range: [node.range[0] + index, node.range[0] + index + 1],
|
|
1758
|
+
loc: {
|
|
1759
|
+
start: {
|
|
1760
|
+
line: node.loc.start.line,
|
|
1761
|
+
column: node.loc.start.column + index,
|
|
1762
|
+
},
|
|
1763
|
+
end: {
|
|
1764
|
+
line: node.loc.start.line,
|
|
1765
|
+
column: node.loc.start.column + index + 1,
|
|
1766
|
+
},
|
|
1767
|
+
},
|
|
1768
|
+
});
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
if (!ctx.octalNumericLiterals) {
|
|
1772
|
+
if (octalNumericLiteralPattern.test(text)) {
|
|
1773
|
+
throw (0, errors_1.throwUnexpectedError)("octal numeric literal", node);
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
if (!ctx.legacyOctalNumericLiterals) {
|
|
1777
|
+
if (legacyOctalNumericLiteralPattern.test(text)) {
|
|
1778
|
+
throw (0, errors_1.throwUnexpectedError)("legacy octal numeric literal", node);
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
if (!ctx.binaryNumericLiterals) {
|
|
1782
|
+
if (binaryNumericLiteralPattern.test(text)) {
|
|
1783
|
+
throw (0, errors_1.throwUnexpectedError)("binary numeric literal", node);
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1786
|
+
if (!ctx.invalidJsonNumbers) {
|
|
1787
|
+
try {
|
|
1788
|
+
JSON.parse(text);
|
|
1789
|
+
}
|
|
1790
|
+
catch (_a) {
|
|
1791
|
+
throw (0, errors_1.throwInvalidNumberError)(text, node);
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
if ((!ctx.multilineStrings ||
|
|
1796
|
+
!ctx.singleQuotes ||
|
|
1797
|
+
!ctx.unicodeCodepointEscapes) &&
|
|
1798
|
+
typeof value === "string") {
|
|
1799
|
+
if (!ctx.singleQuotes) {
|
|
1800
|
+
if (node.raw.startsWith("'")) {
|
|
1801
|
+
throw (0, errors_1.throwUnexpectedError)("single quoted", node);
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
if (!ctx.multilineStrings) {
|
|
1805
|
+
if (lineBreakPattern.test(node.raw)) {
|
|
1806
|
+
throw (0, errors_1.throwUnexpectedError)("multiline string", node);
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
if (!ctx.unicodeCodepointEscapes) {
|
|
1810
|
+
if (hasUnicodeCodepointEscapes(node.raw)) {
|
|
1811
|
+
throw (0, errors_1.throwUnexpectedError)("unicode codepoint escape", node);
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
return undefined;
|
|
1816
|
+
}
|
|
1817
|
+
function validateUnaryExpressionNode(node, tokens, ctx) {
|
|
1818
|
+
if (node.type !== "UnaryExpression") {
|
|
1819
|
+
throw (0, errors_1.throwUnexpectedNodeError)(node, tokens);
|
|
1820
|
+
}
|
|
1821
|
+
const operator = node.operator;
|
|
1822
|
+
if (operator === "+") {
|
|
1823
|
+
if (!ctx.plusSigns) {
|
|
1824
|
+
throw (0, errors_1.throwUnexpectedTokenError)("+", node);
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
else if (operator !== "-") {
|
|
1828
|
+
throw (0, errors_1.throwUnexpectedNodeError)(node, tokens);
|
|
1829
|
+
}
|
|
1830
|
+
const argument = node.argument;
|
|
1831
|
+
if (argument.type === "Literal") {
|
|
1832
|
+
if (typeof argument.value !== "number") {
|
|
1833
|
+
throw (0, errors_1.throwUnexpectedNodeError)(argument, tokens);
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
else if (argument.type === "Identifier") {
|
|
1837
|
+
if (!isNumberIdentifier(argument, ctx)) {
|
|
1838
|
+
throw (0, errors_1.throwUnexpectedNodeError)(argument, tokens);
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
else {
|
|
1842
|
+
throw (0, errors_1.throwUnexpectedNodeError)(argument, tokens);
|
|
1843
|
+
}
|
|
1844
|
+
if (!ctx.spacedSigns) {
|
|
1845
|
+
if (node.range[0] + 1 < argument.range[0]) {
|
|
1846
|
+
throw (0, errors_1.throwUnexpectedSpaceError)(tokens.getFirstToken(node));
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
setParent(argument, node);
|
|
1850
|
+
}
|
|
1851
|
+
function validateIdentifierNode(node, tokens, ctx) {
|
|
1852
|
+
if (node.type !== "Identifier") {
|
|
1853
|
+
throw (0, errors_1.throwUnexpectedNodeError)(node, tokens);
|
|
1854
|
+
}
|
|
1855
|
+
if (!ctx.escapeSequenceInIdentifier) {
|
|
1856
|
+
if (node.name.length < node.range[1] - node.range[0]) {
|
|
1857
|
+
throw (0, errors_1.throwUnexpectedError)("escape sequence", node);
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
function validateTemplateLiteralNode(node, tokens, ctx) {
|
|
1862
|
+
if (node.type !== "TemplateLiteral") {
|
|
1863
|
+
throw (0, errors_1.throwUnexpectedNodeError)(node, tokens);
|
|
1864
|
+
}
|
|
1865
|
+
if (!ctx.templateLiterals) {
|
|
1866
|
+
throw (0, errors_1.throwUnexpectedNodeError)(node, tokens);
|
|
1867
|
+
}
|
|
1868
|
+
if (node.expressions.length) {
|
|
1869
|
+
const token = tokens.getFirstToken(node.quasis[0]);
|
|
1870
|
+
const loc = {
|
|
1871
|
+
loc: {
|
|
1872
|
+
start: {
|
|
1873
|
+
line: token.loc.end.line,
|
|
1874
|
+
column: token.loc.end.column - 2,
|
|
1875
|
+
},
|
|
1876
|
+
end: token.loc.end,
|
|
1877
|
+
},
|
|
1878
|
+
range: [token.range[1] - 2, token.range[1]],
|
|
1879
|
+
};
|
|
1880
|
+
throw (0, errors_1.throwUnexpectedTokenError)("$", loc);
|
|
1881
|
+
}
|
|
1882
|
+
if (!ctx.unicodeCodepointEscapes) {
|
|
1883
|
+
if (hasUnicodeCodepointEscapes(node.quasis[0].value.raw)) {
|
|
1884
|
+
throw (0, errors_1.throwUnexpectedError)("unicode codepoint escape", node);
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
for (const q of node.quasis) {
|
|
1888
|
+
setParent(q, node);
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
function validateTemplateElementNode(node, tokens) {
|
|
1892
|
+
if (node.type !== "TemplateElement") {
|
|
1893
|
+
throw (0, errors_1.throwUnexpectedNodeError)(node, tokens);
|
|
1894
|
+
}
|
|
1895
|
+
const { cooked } = node.value;
|
|
1896
|
+
if (cooked == null) {
|
|
1897
|
+
throw (0, errors_1.throwUnexpectedNodeError)(node, tokens);
|
|
1898
|
+
}
|
|
1899
|
+
const startOffset = -1;
|
|
1900
|
+
const endOffset = node.tail ? 1 : 2;
|
|
1901
|
+
node.start += startOffset;
|
|
1902
|
+
node.end += endOffset;
|
|
1903
|
+
node.range[0] += startOffset;
|
|
1904
|
+
node.range[1] += endOffset;
|
|
1905
|
+
node.loc.start.column += startOffset;
|
|
1906
|
+
node.loc.end.column += endOffset;
|
|
1907
|
+
}
|
|
1908
|
+
function validateBinaryExpressionNode(node, tokens, ctx) {
|
|
1909
|
+
if (node.type !== "BinaryExpression") {
|
|
1910
|
+
throw (0, errors_1.throwUnexpectedNodeError)(node, tokens);
|
|
1911
|
+
}
|
|
1912
|
+
if (!ctx.staticExpressions) {
|
|
1913
|
+
throw (0, errors_1.throwUnexpectedNodeError)(node, tokens);
|
|
1914
|
+
}
|
|
1915
|
+
const { operator, left, right } = node;
|
|
1916
|
+
if (operator !== "+" &&
|
|
1917
|
+
operator !== "-" &&
|
|
1918
|
+
operator !== "*" &&
|
|
1919
|
+
operator !== "/" &&
|
|
1920
|
+
operator !== "%" &&
|
|
1921
|
+
operator !== "**") {
|
|
1922
|
+
throw throwOperatorError();
|
|
1923
|
+
}
|
|
1924
|
+
validateExpr(left, throwOperatorError);
|
|
1925
|
+
validateExpr(right, () => (0, errors_1.throwUnexpectedNodeError)(right, tokens));
|
|
1926
|
+
function validateExpr(expr, throwError) {
|
|
1927
|
+
if (expr.type === "Literal") {
|
|
1928
|
+
if (typeof expr.value !== "number") {
|
|
1929
|
+
throw throwError();
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
else if (expr.type !== "BinaryExpression" &&
|
|
1933
|
+
expr.type !== "UnaryExpression") {
|
|
1934
|
+
throw throwError();
|
|
1935
|
+
}
|
|
1936
|
+
setParent(expr, node);
|
|
1937
|
+
}
|
|
1938
|
+
function throwOperatorError() {
|
|
1939
|
+
throw (0, errors_1.throwUnexpectedTokenError)(operator, tokens.getTokenAfter(tokens.getFirstToken(node), (t) => t.value === operator) || node);
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
function isStaticValueIdentifier(node, ctx) {
|
|
1943
|
+
if (isNumberIdentifier(node, ctx)) {
|
|
1944
|
+
return true;
|
|
1945
|
+
}
|
|
1946
|
+
return node.name === "undefined" && ctx.undefinedKeywords;
|
|
1947
|
+
}
|
|
1948
|
+
validate.isStaticValueIdentifier = isStaticValueIdentifier;
|
|
1949
|
+
function isNumberIdentifier(node, ctx) {
|
|
1950
|
+
if (node.name === "Infinity" && ctx.infinities) {
|
|
1951
|
+
return true;
|
|
1952
|
+
}
|
|
1953
|
+
if (node.name === "NaN" && ctx.nans) {
|
|
1954
|
+
return true;
|
|
1955
|
+
}
|
|
1956
|
+
return false;
|
|
1957
|
+
}
|
|
1958
|
+
function setParent(prop, parent) {
|
|
1959
|
+
prop.parent = parent;
|
|
1960
|
+
}
|
|
1961
|
+
return validate;
|
|
1962
|
+
}
|
|
1963
|
+
|
|
1964
|
+
var acorn = {};
|
|
1965
|
+
|
|
1966
|
+
const name = "acorn";
|
|
1967
|
+
const description = "ECMAScript parser";
|
|
1968
|
+
const homepage = "https://github.com/acornjs/acorn";
|
|
1969
|
+
const main = "dist/acorn.js";
|
|
1970
|
+
const types = "dist/acorn.d.ts";
|
|
1971
|
+
const module = "dist/acorn.mjs";
|
|
1972
|
+
const exports = {
|
|
1973
|
+
".": [
|
|
1974
|
+
{
|
|
1975
|
+
"import": "./dist/acorn.mjs",
|
|
1976
|
+
require: "./dist/acorn.js",
|
|
1977
|
+
"default": "./dist/acorn.js"
|
|
1978
|
+
},
|
|
1979
|
+
"./dist/acorn.js"
|
|
1980
|
+
],
|
|
1981
|
+
"./package.json": "./package.json"
|
|
1982
|
+
};
|
|
1983
|
+
const version = "8.14.1";
|
|
1984
|
+
const engines = {
|
|
1985
|
+
node: ">=0.4.0"
|
|
1986
|
+
};
|
|
1987
|
+
const maintainers = [
|
|
1988
|
+
{
|
|
1989
|
+
name: "Marijn Haverbeke",
|
|
1990
|
+
email: "marijnh@gmail.com",
|
|
1991
|
+
web: "https://marijnhaverbeke.nl"
|
|
1992
|
+
},
|
|
1993
|
+
{
|
|
1994
|
+
name: "Ingvar Stepanyan",
|
|
1995
|
+
email: "me@rreverser.com",
|
|
1996
|
+
web: "https://rreverser.com/"
|
|
1997
|
+
},
|
|
1998
|
+
{
|
|
1999
|
+
name: "Adrian Heine",
|
|
2000
|
+
web: "http://adrianheine.de"
|
|
2001
|
+
}
|
|
2002
|
+
];
|
|
2003
|
+
const repository = {
|
|
2004
|
+
type: "git",
|
|
2005
|
+
url: "git+https://github.com/acornjs/acorn.git"
|
|
2006
|
+
};
|
|
2007
|
+
const license = "MIT";
|
|
2008
|
+
const scripts = {
|
|
2009
|
+
prepare: "cd ..; npm run build:main"
|
|
2010
|
+
};
|
|
2011
|
+
const bin = {
|
|
2012
|
+
acorn: "bin/acorn"
|
|
2013
|
+
};
|
|
2014
|
+
const _package = {
|
|
2015
|
+
name: name,
|
|
2016
|
+
description: description,
|
|
2017
|
+
homepage: homepage,
|
|
2018
|
+
main: main,
|
|
2019
|
+
types: types,
|
|
2020
|
+
module: module,
|
|
2021
|
+
exports: exports,
|
|
2022
|
+
version: version,
|
|
2023
|
+
engines: engines,
|
|
2024
|
+
maintainers: maintainers,
|
|
2025
|
+
repository: repository,
|
|
2026
|
+
license: license,
|
|
2027
|
+
scripts: scripts,
|
|
2028
|
+
bin: bin
|
|
2029
|
+
};
|
|
2030
|
+
|
|
2031
|
+
const _package$1 = {
|
|
2032
|
+
__proto__: null,
|
|
2033
|
+
bin: bin,
|
|
2034
|
+
default: _package,
|
|
2035
|
+
description: description,
|
|
2036
|
+
engines: engines,
|
|
2037
|
+
exports: exports,
|
|
2038
|
+
homepage: homepage,
|
|
2039
|
+
license: license,
|
|
2040
|
+
main: main,
|
|
2041
|
+
maintainers: maintainers,
|
|
2042
|
+
module: module,
|
|
2043
|
+
name: name,
|
|
2044
|
+
repository: repository,
|
|
2045
|
+
scripts: scripts,
|
|
2046
|
+
types: types,
|
|
2047
|
+
version: version
|
|
2048
|
+
};
|
|
2049
|
+
|
|
2050
|
+
const require$$2 = /*@__PURE__*/getAugmentedNamespace(_package$1);
|
|
2051
|
+
|
|
2052
|
+
var hasRequiredAcorn;
|
|
2053
|
+
|
|
2054
|
+
function requireAcorn () {
|
|
2055
|
+
if (hasRequiredAcorn) return acorn;
|
|
2056
|
+
hasRequiredAcorn = 1;
|
|
2057
|
+
Object.defineProperty(acorn, "__esModule", { value: true });
|
|
2058
|
+
acorn.getAcorn = void 0;
|
|
2059
|
+
const module_1 = require$$2$1;
|
|
2060
|
+
const require_utils_1 = requireRequireUtils();
|
|
2061
|
+
let acornCache;
|
|
2062
|
+
function getAcorn() {
|
|
2063
|
+
if (!acornCache) {
|
|
2064
|
+
acornCache = (0, require_utils_1.loadNewest)([
|
|
2065
|
+
{
|
|
2066
|
+
getPkg() {
|
|
2067
|
+
return (0, require_utils_1.requireFromCwd)("acorn/package.json");
|
|
2068
|
+
},
|
|
2069
|
+
get() {
|
|
2070
|
+
return (0, require_utils_1.requireFromCwd)("acorn");
|
|
2071
|
+
},
|
|
2072
|
+
},
|
|
2073
|
+
{
|
|
2074
|
+
getPkg() {
|
|
2075
|
+
return requireFromEspree("acorn/package.json");
|
|
2076
|
+
},
|
|
2077
|
+
get() {
|
|
2078
|
+
return requireFromEspree("acorn");
|
|
2079
|
+
},
|
|
2080
|
+
},
|
|
2081
|
+
{
|
|
2082
|
+
getPkg() {
|
|
2083
|
+
return require$$2;
|
|
2084
|
+
},
|
|
2085
|
+
get() {
|
|
2086
|
+
return requireAcorn$1();
|
|
2087
|
+
},
|
|
2088
|
+
},
|
|
2089
|
+
]);
|
|
2090
|
+
}
|
|
2091
|
+
return acornCache;
|
|
2092
|
+
}
|
|
2093
|
+
acorn.getAcorn = getAcorn;
|
|
2094
|
+
function requireFromEspree(module) {
|
|
2095
|
+
try {
|
|
2096
|
+
return (0, module_1.createRequire)(getEspreePath())(module);
|
|
2097
|
+
}
|
|
2098
|
+
catch (_a) {
|
|
2099
|
+
}
|
|
2100
|
+
return null;
|
|
2101
|
+
}
|
|
2102
|
+
function getEspreePath() {
|
|
2103
|
+
return (0, require_utils_1.loadNewest)([
|
|
2104
|
+
{
|
|
2105
|
+
getPkg() {
|
|
2106
|
+
return (0, require_utils_1.requireFromCwd)("espree/package.json");
|
|
2107
|
+
},
|
|
2108
|
+
get() {
|
|
2109
|
+
return (0, require_utils_1.getRequireFromCwd)().resolve("espree");
|
|
2110
|
+
},
|
|
2111
|
+
},
|
|
2112
|
+
{
|
|
2113
|
+
getPkg() {
|
|
2114
|
+
return (0, require_utils_1.requireFromLinter)("espree/package.json");
|
|
2115
|
+
},
|
|
2116
|
+
get() {
|
|
2117
|
+
return (0, require_utils_1.getRequireFromLinter)().resolve("espree");
|
|
2118
|
+
},
|
|
2119
|
+
},
|
|
2120
|
+
{
|
|
2121
|
+
getPkg() {
|
|
2122
|
+
return require$$4;
|
|
2123
|
+
},
|
|
2124
|
+
get() {
|
|
2125
|
+
return require.resolve("espree");
|
|
2126
|
+
},
|
|
2127
|
+
},
|
|
2128
|
+
]);
|
|
2129
|
+
}
|
|
2130
|
+
return acorn;
|
|
2131
|
+
}
|
|
2132
|
+
|
|
2133
|
+
var hasRequiredConvert;
|
|
2134
|
+
|
|
2135
|
+
function requireConvert () {
|
|
2136
|
+
if (hasRequiredConvert) return convert;
|
|
2137
|
+
hasRequiredConvert = 1;
|
|
2138
|
+
Object.defineProperty(convert, "__esModule", { value: true });
|
|
2139
|
+
convert.convertProgramNode = convert.TokenConvertor = void 0;
|
|
2140
|
+
const validate_1 = requireValidate();
|
|
2141
|
+
const errors_1 = requireErrors();
|
|
2142
|
+
const acorn_1 = requireAcorn();
|
|
2143
|
+
class TokenConvertor {
|
|
2144
|
+
constructor(ctx, code) {
|
|
2145
|
+
this.templateBuffer = [];
|
|
2146
|
+
this.ctx = ctx;
|
|
2147
|
+
this.code = code;
|
|
2148
|
+
this.tokTypes = (0, acorn_1.getAcorn)().tokTypes;
|
|
2149
|
+
}
|
|
2150
|
+
convertToken(token) {
|
|
2151
|
+
const { tokTypes } = this;
|
|
2152
|
+
let type, value;
|
|
2153
|
+
const additional = {};
|
|
2154
|
+
if (token.type === tokTypes.string) {
|
|
2155
|
+
type = "String";
|
|
2156
|
+
value = this.code.slice(...token.range);
|
|
2157
|
+
}
|
|
2158
|
+
else if (token.type === tokTypes.num) {
|
|
2159
|
+
type = "Numeric";
|
|
2160
|
+
value = this.code.slice(...token.range);
|
|
2161
|
+
}
|
|
2162
|
+
else if (token.type.keyword) {
|
|
2163
|
+
if (token.type.keyword === "true" || token.type.keyword === "false") {
|
|
2164
|
+
type = "Boolean";
|
|
2165
|
+
}
|
|
2166
|
+
else if (token.type.keyword === "null") {
|
|
2167
|
+
type = "Null";
|
|
2168
|
+
}
|
|
2169
|
+
else {
|
|
2170
|
+
type = "Keyword";
|
|
2171
|
+
}
|
|
2172
|
+
value = token.value;
|
|
2173
|
+
}
|
|
2174
|
+
else if (token.type === tokTypes.braceL ||
|
|
2175
|
+
token.type === tokTypes.braceR ||
|
|
2176
|
+
token.type === tokTypes.bracketL ||
|
|
2177
|
+
token.type === tokTypes.bracketR ||
|
|
2178
|
+
token.type === tokTypes.colon ||
|
|
2179
|
+
token.type === tokTypes.comma ||
|
|
2180
|
+
token.type === tokTypes.plusMin) {
|
|
2181
|
+
type = "Punctuator";
|
|
2182
|
+
value = this.code.slice(...token.range);
|
|
2183
|
+
}
|
|
2184
|
+
else if (token.type === tokTypes.name) {
|
|
2185
|
+
type = "Identifier";
|
|
2186
|
+
value = token.value;
|
|
2187
|
+
}
|
|
2188
|
+
else if (token.type === tokTypes.backQuote) {
|
|
2189
|
+
if (this.templateBuffer.length > 0) {
|
|
2190
|
+
const first = this.templateBuffer[0];
|
|
2191
|
+
this.templateBuffer.length = 0;
|
|
2192
|
+
return {
|
|
2193
|
+
type: "Template",
|
|
2194
|
+
value: this.code.slice(first.start, token.end),
|
|
2195
|
+
range: [first.start, token.end],
|
|
2196
|
+
loc: {
|
|
2197
|
+
start: first.loc.start,
|
|
2198
|
+
end: token.loc.end,
|
|
2199
|
+
},
|
|
2200
|
+
};
|
|
2201
|
+
}
|
|
2202
|
+
this.templateBuffer.push(token);
|
|
2203
|
+
return null;
|
|
2204
|
+
}
|
|
2205
|
+
else if (token.type === tokTypes.template) {
|
|
2206
|
+
if (this.templateBuffer.length === 0) {
|
|
2207
|
+
return (0, errors_1.throwUnexpectedTokenError)(this.code.slice(...token.range), token);
|
|
2208
|
+
}
|
|
2209
|
+
this.templateBuffer.push(token);
|
|
2210
|
+
return null;
|
|
2211
|
+
}
|
|
2212
|
+
else if (token.type === tokTypes.regexp) {
|
|
2213
|
+
const reValue = token.value;
|
|
2214
|
+
type = "RegularExpression";
|
|
2215
|
+
additional.regex = {
|
|
2216
|
+
flags: reValue.flags,
|
|
2217
|
+
pattern: reValue.pattern,
|
|
2218
|
+
};
|
|
2219
|
+
value = `/${reValue.pattern}/${reValue.flags}`;
|
|
2220
|
+
}
|
|
2221
|
+
else if (this.ctx.parentheses &&
|
|
2222
|
+
(token.type === tokTypes.parenL || token.type === tokTypes.parenR)) {
|
|
2223
|
+
type = "Punctuator";
|
|
2224
|
+
value = this.code.slice(...token.range);
|
|
2225
|
+
}
|
|
2226
|
+
else if (this.ctx.staticExpressions &&
|
|
2227
|
+
(token.type === tokTypes.star ||
|
|
2228
|
+
token.type === tokTypes.slash ||
|
|
2229
|
+
token.type === tokTypes.modulo ||
|
|
2230
|
+
token.type === tokTypes.starstar)) {
|
|
2231
|
+
type = "Punctuator";
|
|
2232
|
+
value = this.code.slice(...token.range);
|
|
2233
|
+
}
|
|
2234
|
+
else {
|
|
2235
|
+
return (0, errors_1.throwUnexpectedTokenError)(this.code.slice(...token.range), token);
|
|
2236
|
+
}
|
|
2237
|
+
token.type = type;
|
|
2238
|
+
token.value = value;
|
|
2239
|
+
for (const k in additional) {
|
|
2240
|
+
token[k] = additional[k];
|
|
2241
|
+
}
|
|
2242
|
+
return token;
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2245
|
+
convert.TokenConvertor = TokenConvertor;
|
|
2246
|
+
function convertProgramNode(node, tokens, ctx, code) {
|
|
2247
|
+
if (node.type !== "JSONObjectExpression" &&
|
|
2248
|
+
node.type !== "JSONArrayExpression" &&
|
|
2249
|
+
node.type !== "JSONLiteral" &&
|
|
2250
|
+
node.type !== "JSONUnaryExpression" &&
|
|
2251
|
+
node.type !== "JSONIdentifier" &&
|
|
2252
|
+
node.type !== "JSONTemplateLiteral" &&
|
|
2253
|
+
node.type !== "JSONBinaryExpression") {
|
|
2254
|
+
return (0, errors_1.throwUnexpectedNodeError)(node, tokens);
|
|
2255
|
+
}
|
|
2256
|
+
if (node.type === "JSONIdentifier") {
|
|
2257
|
+
if (!(0, validate_1.isStaticValueIdentifier)(node, ctx)) {
|
|
2258
|
+
return (0, errors_1.throwUnexpectedNodeError)(node, tokens);
|
|
2259
|
+
}
|
|
2260
|
+
}
|
|
2261
|
+
const body = Object.assign(Object.assign({ type: "JSONExpressionStatement", expression: node }, cloneLocation(node)), { parent: null });
|
|
2262
|
+
setParent(node, body);
|
|
2263
|
+
const end = code.length;
|
|
2264
|
+
const endLoc = (0, acorn_1.getAcorn)().getLineInfo(code, end);
|
|
2265
|
+
const nn = {
|
|
2266
|
+
type: "Program",
|
|
2267
|
+
body: [body],
|
|
2268
|
+
comments: [],
|
|
2269
|
+
tokens: [],
|
|
2270
|
+
range: [0, end],
|
|
2271
|
+
loc: {
|
|
2272
|
+
start: {
|
|
2273
|
+
line: 1,
|
|
2274
|
+
column: 0,
|
|
2275
|
+
},
|
|
2276
|
+
end: {
|
|
2277
|
+
line: endLoc.line,
|
|
2278
|
+
column: endLoc.column,
|
|
2279
|
+
},
|
|
2280
|
+
},
|
|
2281
|
+
parent: null,
|
|
2282
|
+
};
|
|
2283
|
+
setParent(body, nn);
|
|
2284
|
+
return nn;
|
|
2285
|
+
}
|
|
2286
|
+
convert.convertProgramNode = convertProgramNode;
|
|
2287
|
+
function cloneLocation(node) {
|
|
2288
|
+
const range = node.range;
|
|
2289
|
+
const loc = node.loc;
|
|
2290
|
+
return {
|
|
2291
|
+
range: [range[0], range[1]],
|
|
2292
|
+
loc: {
|
|
2293
|
+
start: {
|
|
2294
|
+
line: loc.start.line,
|
|
2295
|
+
column: loc.start.column,
|
|
2296
|
+
},
|
|
2297
|
+
end: {
|
|
2298
|
+
line: loc.end.line,
|
|
2299
|
+
column: loc.end.column,
|
|
2300
|
+
},
|
|
2301
|
+
},
|
|
2302
|
+
};
|
|
2303
|
+
}
|
|
2304
|
+
function setParent(prop, parent) {
|
|
2305
|
+
prop.parent = parent;
|
|
2306
|
+
}
|
|
2307
|
+
return convert;
|
|
2308
|
+
}
|
|
2309
|
+
|
|
2310
|
+
var extendParser = {};
|
|
2311
|
+
|
|
2312
|
+
var hasRequiredExtendParser;
|
|
2313
|
+
|
|
2314
|
+
function requireExtendParser () {
|
|
2315
|
+
if (hasRequiredExtendParser) return extendParser;
|
|
2316
|
+
hasRequiredExtendParser = 1;
|
|
2317
|
+
Object.defineProperty(extendParser, "__esModule", { value: true });
|
|
2318
|
+
extendParser.getAnyTokenErrorParser = extendParser.getParser = void 0;
|
|
2319
|
+
const validate_1 = requireValidate();
|
|
2320
|
+
const acorn_1 = requireAcorn();
|
|
2321
|
+
const errors_1 = requireErrors();
|
|
2322
|
+
const convert_1 = requireConvert();
|
|
2323
|
+
let parserCache;
|
|
2324
|
+
const PRIVATE = Symbol("ExtendParser#private");
|
|
2325
|
+
const PRIVATE_PROCESS_NODE = Symbol("ExtendParser#processNode");
|
|
2326
|
+
function getParser() {
|
|
2327
|
+
if (parserCache) {
|
|
2328
|
+
return parserCache;
|
|
2329
|
+
}
|
|
2330
|
+
parserCache = class ExtendParser extends (0, acorn_1.getAcorn)().Parser {
|
|
2331
|
+
constructor(options, code, pos) {
|
|
2332
|
+
super((() => {
|
|
2333
|
+
const tokenConvertor = new convert_1.TokenConvertor(options.ctx, code);
|
|
2334
|
+
const onToken = options.onToken ||
|
|
2335
|
+
((token) => {
|
|
2336
|
+
const t = tokenConvertor.convertToken(token);
|
|
2337
|
+
if (t) {
|
|
2338
|
+
this[PRIVATE].tokenStore.add(t);
|
|
2339
|
+
}
|
|
2340
|
+
});
|
|
2341
|
+
return {
|
|
2342
|
+
ecmaVersion: options.ecmaVersion,
|
|
2343
|
+
sourceType: options.sourceType,
|
|
2344
|
+
ranges: true,
|
|
2345
|
+
locations: true,
|
|
2346
|
+
allowReserved: true,
|
|
2347
|
+
onToken,
|
|
2348
|
+
onComment: (block, text, start, end, startLoc, endLoc) => {
|
|
2349
|
+
const comment = {
|
|
2350
|
+
type: block ? "Block" : "Line",
|
|
2351
|
+
value: text,
|
|
2352
|
+
range: [start, end],
|
|
2353
|
+
loc: {
|
|
2354
|
+
start: startLoc,
|
|
2355
|
+
end: endLoc,
|
|
2356
|
+
},
|
|
2357
|
+
};
|
|
2358
|
+
if (!this[PRIVATE].ctx.comments) {
|
|
2359
|
+
throw (0, errors_1.throwUnexpectedCommentError)(comment);
|
|
2360
|
+
}
|
|
2361
|
+
this[PRIVATE].comments.push(comment);
|
|
2362
|
+
},
|
|
2363
|
+
};
|
|
2364
|
+
})(), code, pos);
|
|
2365
|
+
this[PRIVATE] = {
|
|
2366
|
+
code,
|
|
2367
|
+
ctx: options.ctx,
|
|
2368
|
+
tokenStore: options.tokenStore,
|
|
2369
|
+
comments: options.comments,
|
|
2370
|
+
nodes: options.nodes,
|
|
2371
|
+
};
|
|
2372
|
+
}
|
|
2373
|
+
finishNode(...args) {
|
|
2374
|
+
const result = super.finishNode(...args);
|
|
2375
|
+
return this[PRIVATE_PROCESS_NODE](result);
|
|
2376
|
+
}
|
|
2377
|
+
finishNodeAt(...args) {
|
|
2378
|
+
const result = super.finishNodeAt(...args);
|
|
2379
|
+
return this[PRIVATE_PROCESS_NODE](result);
|
|
2380
|
+
}
|
|
2381
|
+
[PRIVATE_PROCESS_NODE](node) {
|
|
2382
|
+
const { tokenStore, ctx, nodes } = this[PRIVATE];
|
|
2383
|
+
(0, validate_1.validateNode)(node, tokenStore, ctx);
|
|
2384
|
+
nodes.push(node);
|
|
2385
|
+
return node;
|
|
2386
|
+
}
|
|
2387
|
+
raise(pos, message) {
|
|
2388
|
+
const loc = (0, acorn_1.getAcorn)().getLineInfo(this[PRIVATE].code, pos);
|
|
2389
|
+
const err = new errors_1.ParseError(message, pos, loc.line, loc.column + 1);
|
|
2390
|
+
throw err;
|
|
2391
|
+
}
|
|
2392
|
+
raiseRecoverable(pos, message) {
|
|
2393
|
+
this.raise(pos, message);
|
|
2394
|
+
}
|
|
2395
|
+
unexpected(pos) {
|
|
2396
|
+
if (pos != null) {
|
|
2397
|
+
this.raise(pos, "Unexpected token.");
|
|
2398
|
+
return;
|
|
2399
|
+
}
|
|
2400
|
+
const start = this.start;
|
|
2401
|
+
const end = this.end;
|
|
2402
|
+
const token = this[PRIVATE].code.slice(start, end);
|
|
2403
|
+
if (token) {
|
|
2404
|
+
const message = `Unexpected token '${token}'.`;
|
|
2405
|
+
this.raise(start, message);
|
|
2406
|
+
}
|
|
2407
|
+
else {
|
|
2408
|
+
if (!this[PRIVATE].nodes.length) {
|
|
2409
|
+
this.raise(0, "Expected to be an expression, but got empty.");
|
|
2410
|
+
}
|
|
2411
|
+
if (this[PRIVATE].tokenStore.tokens.length) {
|
|
2412
|
+
const last = this[PRIVATE].tokenStore.tokens[this[PRIVATE].tokenStore.tokens.length - 1];
|
|
2413
|
+
this.raise(last.range[0], `Unexpected token '${last.value}'.`);
|
|
2414
|
+
}
|
|
2415
|
+
this.raise(start, "Unexpected token.");
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
};
|
|
2419
|
+
return parserCache;
|
|
2420
|
+
}
|
|
2421
|
+
extendParser.getParser = getParser;
|
|
2422
|
+
function getAnyTokenErrorParser() {
|
|
2423
|
+
const parser = class ExtendParser extends getParser() {
|
|
2424
|
+
constructor(options, code, pos) {
|
|
2425
|
+
super(Object.assign(Object.assign({}, options), { onToken: (token) => {
|
|
2426
|
+
return (0, errors_1.throwUnexpectedTokenError)(code.slice(...token.range), token);
|
|
2427
|
+
} }), code, pos);
|
|
2428
|
+
}
|
|
2429
|
+
};
|
|
2430
|
+
return parser;
|
|
2431
|
+
}
|
|
2432
|
+
extendParser.getAnyTokenErrorParser = getAnyTokenErrorParser;
|
|
2433
|
+
return extendParser;
|
|
2434
|
+
}
|
|
2435
|
+
|
|
2436
|
+
var hasRequiredParser;
|
|
2437
|
+
|
|
2438
|
+
function requireParser () {
|
|
2439
|
+
if (hasRequiredParser) return parser;
|
|
2440
|
+
hasRequiredParser = 1;
|
|
2441
|
+
Object.defineProperty(parser, "__esModule", { value: true });
|
|
2442
|
+
parser.parseForESLint = void 0;
|
|
2443
|
+
const espree_1 = requireEspree();
|
|
2444
|
+
const visitor_keys_1 = requireVisitorKeys();
|
|
2445
|
+
const convert_1 = requireConvert();
|
|
2446
|
+
const token_store_1 = requireTokenStore();
|
|
2447
|
+
const semver_1 = requireSemver();
|
|
2448
|
+
const extend_parser_1 = requireExtendParser();
|
|
2449
|
+
const DEFAULT_ECMA_VERSION = "latest";
|
|
2450
|
+
function parseForESLint(code, options) {
|
|
2451
|
+
var _a, _b, _c, _d;
|
|
2452
|
+
const parserOptions = Object.assign({ filePath: "<input>", ecmaVersion: DEFAULT_ECMA_VERSION }, options || {}, {
|
|
2453
|
+
loc: true,
|
|
2454
|
+
range: true,
|
|
2455
|
+
raw: true,
|
|
2456
|
+
tokens: true,
|
|
2457
|
+
comment: true,
|
|
2458
|
+
eslintVisitorKeys: true,
|
|
2459
|
+
eslintScopeManager: true,
|
|
2460
|
+
});
|
|
2461
|
+
parserOptions.ecmaVersion = normalizeEcmaVersion(parserOptions.ecmaVersion);
|
|
2462
|
+
const ctx = getJSONSyntaxContext(parserOptions.jsonSyntax);
|
|
2463
|
+
const tokens = [];
|
|
2464
|
+
const comments = [];
|
|
2465
|
+
const tokenStore = new token_store_1.TokenStore(tokens);
|
|
2466
|
+
const nodes = [];
|
|
2467
|
+
parserOptions.ctx = ctx;
|
|
2468
|
+
parserOptions.tokenStore = tokenStore;
|
|
2469
|
+
parserOptions.comments = comments;
|
|
2470
|
+
parserOptions.nodes = nodes;
|
|
2471
|
+
const baseAst = (0, extend_parser_1.getParser)().parseExpressionAt(code, 0, parserOptions);
|
|
2472
|
+
for (const node of nodes) {
|
|
2473
|
+
node.type = `JSON${node.type}`;
|
|
2474
|
+
}
|
|
2475
|
+
const ast = (0, convert_1.convertProgramNode)(baseAst, tokenStore, ctx, code);
|
|
2476
|
+
let lastIndex = Math.max(baseAst.range[1], (_b = (_a = tokens[tokens.length - 1]) === null || _a === void 0 ? void 0 : _a.range[1]) !== null && _b !== void 0 ? _b : 0, (_d = (_c = comments[comments.length - 1]) === null || _c === void 0 ? void 0 : _c.range[1]) !== null && _d !== void 0 ? _d : 0);
|
|
2477
|
+
let lastChar = code[lastIndex];
|
|
2478
|
+
while (lastChar === "\n" ||
|
|
2479
|
+
lastChar === "\r" ||
|
|
2480
|
+
lastChar === " " ||
|
|
2481
|
+
lastChar === "\t") {
|
|
2482
|
+
lastIndex++;
|
|
2483
|
+
lastChar = code[lastIndex];
|
|
2484
|
+
}
|
|
2485
|
+
if (lastIndex < code.length) {
|
|
2486
|
+
(0, extend_parser_1.getAnyTokenErrorParser)().parseExpressionAt(code, lastIndex, parserOptions);
|
|
2487
|
+
}
|
|
2488
|
+
ast.tokens = tokens;
|
|
2489
|
+
ast.comments = comments;
|
|
2490
|
+
return {
|
|
2491
|
+
ast,
|
|
2492
|
+
visitorKeys: (0, visitor_keys_1.getVisitorKeys)(),
|
|
2493
|
+
services: {
|
|
2494
|
+
isJSON: true,
|
|
2495
|
+
},
|
|
2496
|
+
};
|
|
2497
|
+
}
|
|
2498
|
+
parser.parseForESLint = parseForESLint;
|
|
2499
|
+
function getJSONSyntaxContext(str) {
|
|
2500
|
+
const upperCase = str === null || str === void 0 ? void 0 : str.toUpperCase();
|
|
2501
|
+
if (upperCase === "JSON") {
|
|
2502
|
+
return {
|
|
2503
|
+
trailingCommas: false,
|
|
2504
|
+
comments: false,
|
|
2505
|
+
plusSigns: false,
|
|
2506
|
+
spacedSigns: false,
|
|
2507
|
+
leadingOrTrailingDecimalPoints: false,
|
|
2508
|
+
infinities: false,
|
|
2509
|
+
nans: false,
|
|
2510
|
+
numericSeparators: false,
|
|
2511
|
+
binaryNumericLiterals: false,
|
|
2512
|
+
octalNumericLiterals: false,
|
|
2513
|
+
legacyOctalNumericLiterals: false,
|
|
2514
|
+
invalidJsonNumbers: false,
|
|
2515
|
+
multilineStrings: false,
|
|
2516
|
+
unquoteProperties: false,
|
|
2517
|
+
singleQuotes: false,
|
|
2518
|
+
numberProperties: false,
|
|
2519
|
+
undefinedKeywords: false,
|
|
2520
|
+
sparseArrays: false,
|
|
2521
|
+
regExpLiterals: false,
|
|
2522
|
+
templateLiterals: false,
|
|
2523
|
+
bigintLiterals: false,
|
|
2524
|
+
unicodeCodepointEscapes: false,
|
|
2525
|
+
escapeSequenceInIdentifier: false,
|
|
2526
|
+
parentheses: false,
|
|
2527
|
+
staticExpressions: false,
|
|
2528
|
+
};
|
|
2529
|
+
}
|
|
2530
|
+
if (upperCase === "JSONC") {
|
|
2531
|
+
return {
|
|
2532
|
+
trailingCommas: true,
|
|
2533
|
+
comments: true,
|
|
2534
|
+
plusSigns: false,
|
|
2535
|
+
spacedSigns: false,
|
|
2536
|
+
leadingOrTrailingDecimalPoints: false,
|
|
2537
|
+
infinities: false,
|
|
2538
|
+
nans: false,
|
|
2539
|
+
numericSeparators: false,
|
|
2540
|
+
binaryNumericLiterals: false,
|
|
2541
|
+
octalNumericLiterals: false,
|
|
2542
|
+
legacyOctalNumericLiterals: false,
|
|
2543
|
+
invalidJsonNumbers: false,
|
|
2544
|
+
multilineStrings: false,
|
|
2545
|
+
unquoteProperties: false,
|
|
2546
|
+
singleQuotes: false,
|
|
2547
|
+
numberProperties: false,
|
|
2548
|
+
undefinedKeywords: false,
|
|
2549
|
+
sparseArrays: false,
|
|
2550
|
+
regExpLiterals: false,
|
|
2551
|
+
templateLiterals: false,
|
|
2552
|
+
bigintLiterals: false,
|
|
2553
|
+
unicodeCodepointEscapes: false,
|
|
2554
|
+
escapeSequenceInIdentifier: false,
|
|
2555
|
+
parentheses: false,
|
|
2556
|
+
staticExpressions: false,
|
|
2557
|
+
};
|
|
2558
|
+
}
|
|
2559
|
+
if (upperCase === "JSON5") {
|
|
2560
|
+
return {
|
|
2561
|
+
trailingCommas: true,
|
|
2562
|
+
comments: true,
|
|
2563
|
+
plusSigns: true,
|
|
2564
|
+
spacedSigns: true,
|
|
2565
|
+
leadingOrTrailingDecimalPoints: true,
|
|
2566
|
+
infinities: true,
|
|
2567
|
+
nans: true,
|
|
2568
|
+
numericSeparators: false,
|
|
2569
|
+
binaryNumericLiterals: false,
|
|
2570
|
+
octalNumericLiterals: false,
|
|
2571
|
+
legacyOctalNumericLiterals: false,
|
|
2572
|
+
invalidJsonNumbers: true,
|
|
2573
|
+
multilineStrings: true,
|
|
2574
|
+
unquoteProperties: true,
|
|
2575
|
+
singleQuotes: true,
|
|
2576
|
+
numberProperties: false,
|
|
2577
|
+
undefinedKeywords: false,
|
|
2578
|
+
sparseArrays: false,
|
|
2579
|
+
regExpLiterals: false,
|
|
2580
|
+
templateLiterals: false,
|
|
2581
|
+
bigintLiterals: false,
|
|
2582
|
+
unicodeCodepointEscapes: false,
|
|
2583
|
+
escapeSequenceInIdentifier: false,
|
|
2584
|
+
parentheses: false,
|
|
2585
|
+
staticExpressions: false,
|
|
2586
|
+
};
|
|
2587
|
+
}
|
|
2588
|
+
return {
|
|
2589
|
+
trailingCommas: true,
|
|
2590
|
+
comments: true,
|
|
2591
|
+
plusSigns: true,
|
|
2592
|
+
spacedSigns: true,
|
|
2593
|
+
leadingOrTrailingDecimalPoints: true,
|
|
2594
|
+
infinities: true,
|
|
2595
|
+
nans: true,
|
|
2596
|
+
numericSeparators: true,
|
|
2597
|
+
binaryNumericLiterals: true,
|
|
2598
|
+
octalNumericLiterals: true,
|
|
2599
|
+
legacyOctalNumericLiterals: true,
|
|
2600
|
+
invalidJsonNumbers: true,
|
|
2601
|
+
multilineStrings: true,
|
|
2602
|
+
unquoteProperties: true,
|
|
2603
|
+
singleQuotes: true,
|
|
2604
|
+
numberProperties: true,
|
|
2605
|
+
undefinedKeywords: true,
|
|
2606
|
+
sparseArrays: true,
|
|
2607
|
+
regExpLiterals: true,
|
|
2608
|
+
templateLiterals: true,
|
|
2609
|
+
bigintLiterals: true,
|
|
2610
|
+
unicodeCodepointEscapes: true,
|
|
2611
|
+
escapeSequenceInIdentifier: true,
|
|
2612
|
+
parentheses: true,
|
|
2613
|
+
staticExpressions: true,
|
|
2614
|
+
};
|
|
2615
|
+
}
|
|
2616
|
+
function normalizeEcmaVersion(version) {
|
|
2617
|
+
const espree = (0, espree_1.getEspree)();
|
|
2618
|
+
const latestEcmaVersion = getLatestEcmaVersion(espree);
|
|
2619
|
+
if (version == null || version === "latest") {
|
|
2620
|
+
return latestEcmaVersion;
|
|
2621
|
+
}
|
|
2622
|
+
return Math.min(getEcmaVersionYear(version), latestEcmaVersion);
|
|
2623
|
+
}
|
|
2624
|
+
function getLatestEcmaVersion(espree) {
|
|
2625
|
+
if (espree.latestEcmaVersion == null) {
|
|
2626
|
+
for (const { v, latest } of [
|
|
2627
|
+
{ v: "6.1.0", latest: 2020 },
|
|
2628
|
+
{ v: "4.0.0", latest: 2019 },
|
|
2629
|
+
]) {
|
|
2630
|
+
if ((0, semver_1.lte)(v, espree.version)) {
|
|
2631
|
+
return latest;
|
|
2632
|
+
}
|
|
2633
|
+
}
|
|
2634
|
+
return 2018;
|
|
2635
|
+
}
|
|
2636
|
+
return getEcmaVersionYear(espree.latestEcmaVersion);
|
|
2637
|
+
}
|
|
2638
|
+
function getEcmaVersionYear(version) {
|
|
2639
|
+
return version > 5 && version < 2015 ? version + 2009 : version;
|
|
2640
|
+
}
|
|
2641
|
+
return parser;
|
|
2642
|
+
}
|
|
2643
|
+
|
|
2644
|
+
var traverse = {};
|
|
2645
|
+
|
|
2646
|
+
var hasRequiredTraverse;
|
|
2647
|
+
|
|
2648
|
+
function requireTraverse () {
|
|
2649
|
+
if (hasRequiredTraverse) return traverse;
|
|
2650
|
+
hasRequiredTraverse = 1;
|
|
2651
|
+
Object.defineProperty(traverse, "__esModule", { value: true });
|
|
2652
|
+
traverse.traverseNodes = traverse.getNodes = traverse.getKeys = traverse.getFallbackKeys = void 0;
|
|
2653
|
+
const visitor_keys_1 = requireVisitorKeys();
|
|
2654
|
+
function fallbackKeysFilter(key) {
|
|
2655
|
+
let value = null;
|
|
2656
|
+
return (key !== "comments" &&
|
|
2657
|
+
key !== "leadingComments" &&
|
|
2658
|
+
key !== "loc" &&
|
|
2659
|
+
key !== "parent" &&
|
|
2660
|
+
key !== "range" &&
|
|
2661
|
+
key !== "tokens" &&
|
|
2662
|
+
key !== "trailingComments" &&
|
|
2663
|
+
(value = this[key]) !== null &&
|
|
2664
|
+
typeof value === "object" &&
|
|
2665
|
+
(typeof value.type === "string" || Array.isArray(value)));
|
|
2666
|
+
}
|
|
2667
|
+
function getFallbackKeys(node) {
|
|
2668
|
+
return Object.keys(node).filter(fallbackKeysFilter, node);
|
|
2669
|
+
}
|
|
2670
|
+
traverse.getFallbackKeys = getFallbackKeys;
|
|
2671
|
+
function getKeys(node, visitorKeys) {
|
|
2672
|
+
const keys = (visitorKeys || (0, visitor_keys_1.getVisitorKeys)())[node.type] || getFallbackKeys(node);
|
|
2673
|
+
return keys.filter((key) => !getNodes(node, key).next().done);
|
|
2674
|
+
}
|
|
2675
|
+
traverse.getKeys = getKeys;
|
|
2676
|
+
function* getNodes(node, key) {
|
|
2677
|
+
const child = node[key];
|
|
2678
|
+
if (Array.isArray(child)) {
|
|
2679
|
+
for (const c of child) {
|
|
2680
|
+
if (isNode(c)) {
|
|
2681
|
+
yield c;
|
|
2682
|
+
}
|
|
2683
|
+
}
|
|
2684
|
+
}
|
|
2685
|
+
else if (isNode(child)) {
|
|
2686
|
+
yield child;
|
|
2687
|
+
}
|
|
2688
|
+
}
|
|
2689
|
+
traverse.getNodes = getNodes;
|
|
2690
|
+
function isNode(x) {
|
|
2691
|
+
return x !== null && typeof x === "object" && typeof x.type === "string";
|
|
2692
|
+
}
|
|
2693
|
+
function traverse$1(node, parent, visitor) {
|
|
2694
|
+
visitor.enterNode(node, parent);
|
|
2695
|
+
const keys = getKeys(node, visitor.visitorKeys);
|
|
2696
|
+
for (const key of keys) {
|
|
2697
|
+
for (const child of getNodes(node, key)) {
|
|
2698
|
+
traverse$1(child, node, visitor);
|
|
2699
|
+
}
|
|
2700
|
+
}
|
|
2701
|
+
visitor.leaveNode(node, parent);
|
|
2702
|
+
}
|
|
2703
|
+
function traverseNodes(node, visitor) {
|
|
2704
|
+
traverse$1(node, null, visitor);
|
|
2705
|
+
}
|
|
2706
|
+
traverse.traverseNodes = traverseNodes;
|
|
2707
|
+
return traverse;
|
|
2708
|
+
}
|
|
2709
|
+
|
|
2710
|
+
var ast = {};
|
|
2711
|
+
|
|
2712
|
+
var hasRequiredAst;
|
|
2713
|
+
|
|
2714
|
+
function requireAst () {
|
|
2715
|
+
if (hasRequiredAst) return ast;
|
|
2716
|
+
hasRequiredAst = 1;
|
|
2717
|
+
Object.defineProperty(ast, "__esModule", { value: true });
|
|
2718
|
+
ast.getStaticJSONValue = ast.isUndefinedIdentifier = ast.isNumberIdentifier = ast.isExpression = void 0;
|
|
2719
|
+
function isExpression(node) {
|
|
2720
|
+
if (node.type === "JSONIdentifier" || node.type === "JSONLiteral") {
|
|
2721
|
+
const parent = node.parent;
|
|
2722
|
+
if (parent.type === "JSONProperty" && parent.key === node) {
|
|
2723
|
+
return false;
|
|
2724
|
+
}
|
|
2725
|
+
return true;
|
|
2726
|
+
}
|
|
2727
|
+
if (node.type === "JSONObjectExpression" ||
|
|
2728
|
+
node.type === "JSONArrayExpression" ||
|
|
2729
|
+
node.type === "JSONUnaryExpression" ||
|
|
2730
|
+
node.type === "JSONTemplateLiteral" ||
|
|
2731
|
+
node.type === "JSONBinaryExpression") {
|
|
2732
|
+
return true;
|
|
2733
|
+
}
|
|
2734
|
+
return false;
|
|
2735
|
+
}
|
|
2736
|
+
ast.isExpression = isExpression;
|
|
2737
|
+
function isNumberIdentifier(node) {
|
|
2738
|
+
return (isExpression(node) && (node.name === "Infinity" || node.name === "NaN"));
|
|
2739
|
+
}
|
|
2740
|
+
ast.isNumberIdentifier = isNumberIdentifier;
|
|
2741
|
+
function isUndefinedIdentifier(node) {
|
|
2742
|
+
return isExpression(node) && node.name === "undefined";
|
|
2743
|
+
}
|
|
2744
|
+
ast.isUndefinedIdentifier = isUndefinedIdentifier;
|
|
2745
|
+
const resolver = {
|
|
2746
|
+
Program(node) {
|
|
2747
|
+
if (node.body.length !== 1 ||
|
|
2748
|
+
node.body[0].type !== "JSONExpressionStatement") {
|
|
2749
|
+
throw new Error("Illegal argument");
|
|
2750
|
+
}
|
|
2751
|
+
return getStaticJSONValue(node.body[0]);
|
|
2752
|
+
},
|
|
2753
|
+
JSONExpressionStatement(node) {
|
|
2754
|
+
return getStaticJSONValue(node.expression);
|
|
2755
|
+
},
|
|
2756
|
+
JSONObjectExpression(node) {
|
|
2757
|
+
const object = {};
|
|
2758
|
+
for (const prop of node.properties) {
|
|
2759
|
+
Object.assign(object, getStaticJSONValue(prop));
|
|
2760
|
+
}
|
|
2761
|
+
return object;
|
|
2762
|
+
},
|
|
2763
|
+
JSONProperty(node) {
|
|
2764
|
+
const keyName = node.key.type === "JSONLiteral" ? `${node.key.value}` : node.key.name;
|
|
2765
|
+
return {
|
|
2766
|
+
[keyName]: getStaticJSONValue(node.value),
|
|
2767
|
+
};
|
|
2768
|
+
},
|
|
2769
|
+
JSONArrayExpression(node) {
|
|
2770
|
+
const array = [];
|
|
2771
|
+
for (let index = 0; index < node.elements.length; index++) {
|
|
2772
|
+
const element = node.elements[index];
|
|
2773
|
+
if (element) {
|
|
2774
|
+
array[index] = getStaticJSONValue(element);
|
|
2775
|
+
}
|
|
2776
|
+
}
|
|
2777
|
+
return array;
|
|
2778
|
+
},
|
|
2779
|
+
JSONLiteral(node) {
|
|
2780
|
+
if (node.regex) {
|
|
2781
|
+
try {
|
|
2782
|
+
return new RegExp(node.regex.pattern, node.regex.flags);
|
|
2783
|
+
}
|
|
2784
|
+
catch (_a) {
|
|
2785
|
+
return `/${node.regex.pattern}/${node.regex.flags}`;
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
if (node.bigint != null) {
|
|
2789
|
+
try {
|
|
2790
|
+
return BigInt(node.bigint);
|
|
2791
|
+
}
|
|
2792
|
+
catch (_b) {
|
|
2793
|
+
return `${node.bigint}`;
|
|
2794
|
+
}
|
|
2795
|
+
}
|
|
2796
|
+
return node.value;
|
|
2797
|
+
},
|
|
2798
|
+
JSONUnaryExpression(node) {
|
|
2799
|
+
const value = getStaticJSONValue(node.argument);
|
|
2800
|
+
return node.operator === "-" ? -value : value;
|
|
2801
|
+
},
|
|
2802
|
+
JSONBinaryExpression(node) {
|
|
2803
|
+
const left = getStaticJSONValue(node.left);
|
|
2804
|
+
const right = getStaticJSONValue(node.right);
|
|
2805
|
+
return node.operator === "+"
|
|
2806
|
+
? left + right
|
|
2807
|
+
: node.operator === "-"
|
|
2808
|
+
? left - right
|
|
2809
|
+
: node.operator === "*"
|
|
2810
|
+
? left * right
|
|
2811
|
+
: node.operator === "/"
|
|
2812
|
+
? left / right
|
|
2813
|
+
: node.operator === "%"
|
|
2814
|
+
? left % right
|
|
2815
|
+
: node.operator === "**"
|
|
2816
|
+
? Math.pow(left, right)
|
|
2817
|
+
: (() => {
|
|
2818
|
+
throw new Error(`Unknown operator: ${node.operator}`);
|
|
2819
|
+
})();
|
|
2820
|
+
},
|
|
2821
|
+
JSONIdentifier(node) {
|
|
2822
|
+
if (node.name === "Infinity") {
|
|
2823
|
+
return Infinity;
|
|
2824
|
+
}
|
|
2825
|
+
if (node.name === "NaN") {
|
|
2826
|
+
return NaN;
|
|
2827
|
+
}
|
|
2828
|
+
if (node.name === "undefined") {
|
|
2829
|
+
return undefined;
|
|
2830
|
+
}
|
|
2831
|
+
throw new Error("Illegal argument");
|
|
2832
|
+
},
|
|
2833
|
+
JSONTemplateLiteral(node) {
|
|
2834
|
+
return getStaticJSONValue(node.quasis[0]);
|
|
2835
|
+
},
|
|
2836
|
+
JSONTemplateElement(node) {
|
|
2837
|
+
return node.value.cooked;
|
|
2838
|
+
},
|
|
2839
|
+
};
|
|
2840
|
+
function getStaticJSONValue(node) {
|
|
2841
|
+
return resolver[node.type](node);
|
|
2842
|
+
}
|
|
2843
|
+
ast.getStaticJSONValue = getStaticJSONValue;
|
|
2844
|
+
return ast;
|
|
2845
|
+
}
|
|
2846
|
+
|
|
2847
|
+
var meta = {};
|
|
2848
|
+
|
|
2849
|
+
var hasRequiredMeta;
|
|
2850
|
+
|
|
2851
|
+
function requireMeta () {
|
|
2852
|
+
if (hasRequiredMeta) return meta;
|
|
2853
|
+
hasRequiredMeta = 1;
|
|
2854
|
+
Object.defineProperty(meta, "__esModule", { value: true });
|
|
2855
|
+
meta.version = meta.name = void 0;
|
|
2856
|
+
meta.name = "jsonc-eslint-parser";
|
|
2857
|
+
meta.version = "2.4.0";
|
|
2858
|
+
return meta;
|
|
2859
|
+
}
|
|
2860
|
+
|
|
2861
|
+
var hasRequiredLib;
|
|
2862
|
+
|
|
2863
|
+
function requireLib () {
|
|
2864
|
+
if (hasRequiredLib) return lib;
|
|
2865
|
+
hasRequiredLib = 1;
|
|
2866
|
+
(function (exports) {
|
|
2867
|
+
var __createBinding = (lib && lib.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2868
|
+
if (k2 === undefined) k2 = k;
|
|
2869
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
2870
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
2871
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
2872
|
+
}
|
|
2873
|
+
Object.defineProperty(o, k2, desc);
|
|
2874
|
+
}) : (function(o, m, k, k2) {
|
|
2875
|
+
if (k2 === undefined) k2 = k;
|
|
2876
|
+
o[k2] = m[k];
|
|
2877
|
+
}));
|
|
2878
|
+
var __setModuleDefault = (lib && lib.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
2879
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
2880
|
+
}) : function(o, v) {
|
|
2881
|
+
o["default"] = v;
|
|
2882
|
+
});
|
|
2883
|
+
var __importStar = (lib && lib.__importStar) || function (mod) {
|
|
2884
|
+
if (mod && mod.__esModule) return mod;
|
|
2885
|
+
var result = {};
|
|
2886
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
2887
|
+
__setModuleDefault(result, mod);
|
|
2888
|
+
return result;
|
|
2889
|
+
};
|
|
2890
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2891
|
+
exports.parseJSON = exports.isUndefinedIdentifier = exports.isNumberIdentifier = exports.isExpression = exports.getStaticJSONValue = exports.traverseNodes = exports.VisitorKeys = exports.parseForESLint = exports.name = exports.meta = void 0;
|
|
2892
|
+
const parser_1 = requireParser();
|
|
2893
|
+
Object.defineProperty(exports, "parseForESLint", { enumerable: true, get: function () { return parser_1.parseForESLint; } });
|
|
2894
|
+
const traverse_1 = requireTraverse();
|
|
2895
|
+
Object.defineProperty(exports, "traverseNodes", { enumerable: true, get: function () { return traverse_1.traverseNodes; } });
|
|
2896
|
+
const ast_1 = requireAst();
|
|
2897
|
+
Object.defineProperty(exports, "getStaticJSONValue", { enumerable: true, get: function () { return ast_1.getStaticJSONValue; } });
|
|
2898
|
+
Object.defineProperty(exports, "isExpression", { enumerable: true, get: function () { return ast_1.isExpression; } });
|
|
2899
|
+
Object.defineProperty(exports, "isNumberIdentifier", { enumerable: true, get: function () { return ast_1.isNumberIdentifier; } });
|
|
2900
|
+
Object.defineProperty(exports, "isUndefinedIdentifier", { enumerable: true, get: function () { return ast_1.isUndefinedIdentifier; } });
|
|
2901
|
+
const visitor_keys_1 = requireVisitorKeys();
|
|
2902
|
+
exports.meta = __importStar(requireMeta());
|
|
2903
|
+
var meta_1 = requireMeta();
|
|
2904
|
+
Object.defineProperty(exports, "name", { enumerable: true, get: function () { return meta_1.name; } });
|
|
2905
|
+
exports.VisitorKeys = (0, visitor_keys_1.getVisitorKeys)();
|
|
2906
|
+
function parseJSON(code, options) {
|
|
2907
|
+
return (0, parser_1.parseForESLint)(code, options).ast;
|
|
2908
|
+
}
|
|
2909
|
+
exports.parseJSON = parseJSON;
|
|
2910
|
+
} (lib));
|
|
2911
|
+
return lib;
|
|
2912
|
+
}
|
|
2913
|
+
|
|
2914
|
+
export { requireLib as r };
|