astronomical 1.0.0-beta.12

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.
@@ -0,0 +1,453 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.parseSource = exports.multiQuery = exports.query = exports.isAvailableFunction = exports.functions = void 0;
27
+ const traverse_1 = __importStar(require("./traverse"));
28
+ const parseQuery_1 = require("./parseQuery");
29
+ const meriyah_1 = require("meriyah");
30
+ const debugLogEnabled = false;
31
+ const log = {
32
+ debug: (...args) => {
33
+ if (debugLogEnabled)
34
+ console.debug(...args.map(x => typeof (x) == "object" && x != null && "valueOf" in x ? x.valueOf() : x));
35
+ }
36
+ };
37
+ exports.functions = {
38
+ "join": {
39
+ fn: (result) => {
40
+ if (result.length != 2)
41
+ throw new Error("Invalid number of arugments for join");
42
+ const [values, separators] = result;
43
+ if (separators.length != 1)
44
+ throw new Error("Invalid number of separators for join");
45
+ const separator = separators[0];
46
+ if (typeof separator != "string")
47
+ throw new Error("Separator must be a string");
48
+ if (values.length == 0)
49
+ return [];
50
+ return [values.join(separator)];
51
+ }
52
+ },
53
+ "concat": {
54
+ fn: (result) => {
55
+ if (result.some(x => x.length == 0))
56
+ return [];
57
+ return [result.flat().join("")];
58
+ }
59
+ },
60
+ "first": {
61
+ fn: (result) => {
62
+ if (result.length != 1)
63
+ throw new Error("Invalid number of arugments for first");
64
+ if (result[0].length == 0)
65
+ return [];
66
+ return [result.map(r => r[0])[0]];
67
+ }
68
+ },
69
+ "nthchild": {
70
+ fn: (result) => {
71
+ if (result.length != 2)
72
+ throw new Error("Invalid number of arguments for nthchild");
73
+ if (result[1].length != 1)
74
+ throw new Error("Invalid number of arguments for nthchild");
75
+ const x = result[1][0];
76
+ const number = typeof x == "number" ? x : parseInt(x);
77
+ return [result[0][number]];
78
+ }
79
+ }
80
+ };
81
+ const functionNames = Object.keys(exports.functions);
82
+ function isAvailableFunction(name) {
83
+ return functionNames.includes(name);
84
+ }
85
+ exports.isAvailableFunction = isAvailableFunction;
86
+ function beginHandle(queries, path) {
87
+ const rootPath = (0, traverse_1.createNodePath)(path, undefined, undefined, undefined);
88
+ return travHandle(queries, rootPath);
89
+ }
90
+ function breadCrumb(path) {
91
+ return {
92
+ valueOf() {
93
+ if (path.parentPath == undefined)
94
+ return "@" + path.node.type;
95
+ return breadCrumb(path.parentPath) + "." + (path.parentKey == path.key ? path.key : path.parentKey + "[" + path.key + "]") + "@" + path.node.type;
96
+ }
97
+ };
98
+ }
99
+ function createFilter(filter, filterResult) {
100
+ if (filter.type == "and" || filter.type == "or" || filter.type == "equals") {
101
+ return {
102
+ type: filter.type,
103
+ left: createFilter(filter.left, []),
104
+ right: createFilter(filter.right, [])
105
+ };
106
+ }
107
+ else if (filter.type == "literal") {
108
+ const r = [filter.value];
109
+ return {
110
+ node: filter,
111
+ result: r
112
+ };
113
+ }
114
+ return createFNode(filter, filterResult);
115
+ }
116
+ function createFNode(token, result) {
117
+ return {
118
+ node: token,
119
+ result: result
120
+ };
121
+ }
122
+ function addFilterChildrenToState(filter, state) {
123
+ if ("type" in filter && (filter.type == "and" || filter.type == "or" || filter.type == "equals")) {
124
+ addFilterChildrenToState(filter.left, state);
125
+ addFilterChildrenToState(filter.right, state);
126
+ }
127
+ else if ("node" in filter) {
128
+ if (filter.node.type == "child") {
129
+ log.debug("ADDING FILTER CHILD", filter.node);
130
+ state.child[state.depth + 1].push(filter);
131
+ }
132
+ if (filter.node.type == "descendant") {
133
+ log.debug("ADDING FILTER DESCENDANT", filter.node);
134
+ state.descendant[state.depth + 1].push(filter);
135
+ }
136
+ }
137
+ }
138
+ function createFNodeAndAddToState(token, result, state) {
139
+ log.debug("ADDING FNODE", token);
140
+ const fnode = createFNode(token, result);
141
+ if (token.type == "child") {
142
+ state.child[state.depth + 1].push(fnode);
143
+ }
144
+ else if (token.type == "descendant") {
145
+ state.descendant[state.depth + 1].push(fnode);
146
+ }
147
+ return fnode;
148
+ }
149
+ function isMatch(fnode, path) {
150
+ if (fnode.node.attribute) {
151
+ const m = fnode.node.value == path.parentKey || fnode.node.value == path.key;
152
+ if (m)
153
+ log.debug("ATTR MATCH", fnode.node.value, breadCrumb(path));
154
+ return m;
155
+ }
156
+ if (fnode.node.value == "*") {
157
+ return true;
158
+ }
159
+ const m = fnode.node.value == path.node.type;
160
+ if (m)
161
+ log.debug("NODE MATCH", fnode.node.value, breadCrumb(path));
162
+ return m;
163
+ }
164
+ function addIfTokenMatch(fnode, path, state) {
165
+ if (!isMatch(fnode, path))
166
+ return;
167
+ state.matches[state.depth].push([fnode, path]);
168
+ if (fnode.node.filter) {
169
+ const filter = createFilter(fnode.node.filter, []);
170
+ const filteredResult = [];
171
+ state.filters[state.depth].push({ filter: filter, qNode: fnode.node, node: path.node, result: filteredResult });
172
+ addFilterChildrenToState(filter, state);
173
+ const child = fnode.node.child;
174
+ if (child) {
175
+ if (child.type == "function") {
176
+ const fr = addFunction(fnode, child, path, state);
177
+ state.functionCalls[state.depth].push(fr);
178
+ }
179
+ else {
180
+ createFNodeAndAddToState(child, filteredResult, state);
181
+ }
182
+ }
183
+ }
184
+ else {
185
+ const child = fnode.node.child;
186
+ if (child?.type == "function") {
187
+ const fr = addFunction(fnode, child, path, state);
188
+ state.functionCalls[state.depth].push(fr);
189
+ }
190
+ else if (child && !fnode.node.binding && !fnode.node.resolve) {
191
+ createFNodeAndAddToState(child, fnode.result, state);
192
+ }
193
+ }
194
+ }
195
+ function addFunction(rootNode, functionCall, path, state) {
196
+ const functionNode = { node: rootNode.node, functionCall: functionCall, parameters: [], result: [] };
197
+ for (const param of functionCall.parameters) {
198
+ if (param.type == "literal") {
199
+ functionNode.parameters.push({ node: param, result: [param.value] });
200
+ }
201
+ else {
202
+ if (param.type == "function") {
203
+ functionNode.parameters.push(addFunction(functionNode, param, path, state));
204
+ }
205
+ else {
206
+ functionNode.parameters.push(createFNodeAndAddToState(param, [], state));
207
+ }
208
+ }
209
+ }
210
+ return functionNode;
211
+ }
212
+ function isPrimitive(value) {
213
+ return typeof value == "string" || typeof value == "number" || typeof value == "boolean";
214
+ }
215
+ function addPrimitiveAttributeIfMatch(fnode, path) {
216
+ if (!fnode.node.attribute || !fnode.node.value)
217
+ return;
218
+ if (fnode.node.child || fnode.node.filter)
219
+ return;
220
+ if (!Object.hasOwn(path.node, fnode.node.value))
221
+ return;
222
+ const lookup = path.get(fnode.node.value);
223
+ const nodes = (Array.isArray(lookup) ? lookup : [lookup])
224
+ .filter(n => n.node != undefined)
225
+ .filter(n => isPrimitive(n.node));
226
+ if (nodes.length == 0)
227
+ return;
228
+ log.debug("PRIMITIVE", fnode.node.value, nodes.map(n => n.node));
229
+ fnode.result.push(...nodes.map(n => n.node));
230
+ }
231
+ function evaluateFilter(filter, path) {
232
+ log.debug("EVALUATING FILTER", filter);
233
+ if ("type" in filter) {
234
+ if (filter.type == "and") {
235
+ const left = evaluateFilter(filter.left, path);
236
+ if (left.length == 0)
237
+ return [];
238
+ return evaluateFilter(filter.right, path);
239
+ }
240
+ if (filter.type == "or") {
241
+ const left = evaluateFilter(filter.left, path);
242
+ if (left.length > 0)
243
+ return left;
244
+ return evaluateFilter(filter.right, path);
245
+ }
246
+ if (filter.type == "equals") {
247
+ const left = evaluateFilter(filter.left, path);
248
+ const right = evaluateFilter(filter.right, path);
249
+ return left.filter(x => right.includes(x));
250
+ }
251
+ throw new Error("Unknown filter type: " + filter.type);
252
+ }
253
+ if (filter.node.type == "parent") {
254
+ return resolveFilterWithParent(filter.node, path);
255
+ }
256
+ return filter.result;
257
+ }
258
+ function isIdentifier(node) {
259
+ return node.type == "Identifier";
260
+ }
261
+ function resolveBinding(path) {
262
+ if (!isIdentifier(path.node))
263
+ return undefined;
264
+ log.debug("RESOLVING BINDING FOR ", path.node);
265
+ const name = path.node.name;
266
+ if (name == undefined || typeof name != "string")
267
+ return undefined;
268
+ //const binding = path.scope.getBinding(name);
269
+ const binding = (0, traverse_1.getBinding)(path.scopeId, name);
270
+ if (!binding)
271
+ return undefined;
272
+ log.debug("THIS IS THE BINDING", binding);
273
+ return binding.path;
274
+ }
275
+ function resolveFilterWithParent(node, path) {
276
+ let startNode = node;
277
+ let startPath = path;
278
+ while (startNode.type == "parent") {
279
+ if (!startNode.child)
280
+ throw new Error("Parent filter must have child");
281
+ if (!startPath.parentPath)
282
+ return [];
283
+ log.debug("STEP OUT", startNode, breadCrumb(startPath));
284
+ startNode = startNode.child;
285
+ startPath = startPath.parentPath;
286
+ }
287
+ return resolveDirectly(startNode, startPath);
288
+ }
289
+ const toArray = (value) => Array.isArray(value) ? value : [value];
290
+ function isDefined(value) {
291
+ return value != undefined && value != null;
292
+ }
293
+ let subQueryCounter = 0;
294
+ function resolveDirectly(node, path) {
295
+ let startNode = node;
296
+ const startPath = path;
297
+ let paths = [startPath];
298
+ while (startNode.attribute) {
299
+ const lookup = startNode.value;
300
+ if (!lookup)
301
+ throw new Error("Selector must have a value");
302
+ log.debug("STEP IN ", lookup, paths.map(p => breadCrumb(p)));
303
+ const nodes = paths.map(n => n.get(lookup)).map(toArray).flat().filter(n => n.node != undefined);
304
+ log.debug("LOOKUP", lookup, nodes.map(n => n.node), nodes.filter(n => n.node == undefined));
305
+ if (nodes.length == 0)
306
+ return [];
307
+ paths = nodes;
308
+ if (startNode.resolve) {
309
+ const resolved = paths.map(p => resolveBinding(p)).filter(isDefined).map(p => p.get("init")).flatMap(toArray).filter(p => p.node != undefined).filter(isDefined);
310
+ if (resolved.length > 0)
311
+ paths = resolved;
312
+ }
313
+ else if (startNode.binding) {
314
+ paths = paths.map(p => resolveBinding(p)).filter(isDefined);
315
+ }
316
+ if (!startNode.child) {
317
+ return paths.map(p => p.node);
318
+ }
319
+ startNode = startNode.child;
320
+ }
321
+ log.debug("DIRECT TRAV RESOLVE", startNode, paths.map(p => breadCrumb(p)));
322
+ const result = paths.flatMap(path => {
323
+ const subQueryKey = "subquery-" + subQueryCounter++;
324
+ return travHandle({ [subQueryKey]: startNode }, path)[subQueryKey];
325
+ });
326
+ log.debug("DIRECT TRAV RESOLVE RESULT", result);
327
+ return result;
328
+ }
329
+ function addResultIfTokenMatch(fnode, path, state) {
330
+ const filters = state.filters[state.depth].filter(f => f.node == path.node && f.qNode == fnode.node);
331
+ const matchingFilters = filters.filter(f => evaluateFilter(f.filter, path).length > 0);
332
+ log.debug("RESULT MATCH", fnode.node.value, breadCrumb(path), filters.length, matchingFilters.length);
333
+ if (filters.length > 0 && matchingFilters.length == 0)
334
+ return;
335
+ if (fnode.node.resolve) {
336
+ const [resolved] = toArray(resolveBinding(path)?.get("init")).filter(isDefined).filter(p => p.node != undefined);
337
+ if (fnode.node.child) {
338
+ const result = resolveDirectly(fnode.node.child, resolved ?? path);
339
+ fnode.result.push(...result);
340
+ }
341
+ else {
342
+ fnode.result.push(path.node);
343
+ }
344
+ }
345
+ else if (fnode.node.binding) {
346
+ const binding = resolveBinding(path);
347
+ if (binding) {
348
+ if (fnode.node.child) {
349
+ const result = resolveDirectly(fnode.node.child, binding);
350
+ fnode.result.push(...result);
351
+ }
352
+ else {
353
+ fnode.result.push(binding.node);
354
+ }
355
+ }
356
+ }
357
+ else if (!fnode.node.child) {
358
+ fnode.result.push(path.node);
359
+ }
360
+ else if (fnode.node.child.type == "function") {
361
+ const functionCallResult = state.functionCalls[state.depth].find(f => f.node == fnode.node);
362
+ if (!functionCallResult)
363
+ throw new Error("Did not find expected function call for " + fnode.node.child.function);
364
+ resolveFunctionCalls(fnode, functionCallResult, path, state);
365
+ }
366
+ else if (matchingFilters.length > 0) {
367
+ log.debug("HAS MATCHING FILTER", fnode.result.length, matchingFilters.length, breadCrumb(path));
368
+ fnode.result.push(...matchingFilters.flatMap(f => f.result));
369
+ }
370
+ }
371
+ function resolveFunctionCalls(fnode, functionCallResult, path, state) {
372
+ const parameterResults = [];
373
+ for (const p of functionCallResult.parameters) {
374
+ if ("parameters" in p) {
375
+ resolveFunctionCalls(p, p, path, state);
376
+ parameterResults.push(p.result);
377
+ }
378
+ else {
379
+ parameterResults.push(p.result);
380
+ }
381
+ }
382
+ const functionResult = exports.functions[functionCallResult.functionCall.function].fn(parameterResults);
383
+ log.debug("PARAMETER RESULTS", functionCallResult.functionCall.function, parameterResults, functionResult);
384
+ fnode.result.push(...functionResult);
385
+ }
386
+ function travHandle(queries, root) {
387
+ const results = Object.fromEntries(Object.keys(queries).map(name => [name, []]));
388
+ const state = {
389
+ depth: 0,
390
+ child: [[], []],
391
+ descendant: [[], []],
392
+ filters: [[], []],
393
+ matches: [[]],
394
+ functionCalls: [[]]
395
+ };
396
+ Object.entries(queries).forEach(([name, node]) => {
397
+ createFNodeAndAddToState(node, results[name], state);
398
+ });
399
+ state.child[state.depth + 1].forEach(fnode => addPrimitiveAttributeIfMatch(fnode, root));
400
+ state.descendant.slice(0, state.depth + 1).forEach(fnodes => fnodes.forEach(fnode => addPrimitiveAttributeIfMatch(fnode, root)));
401
+ (0, traverse_1.default)(root.node, {
402
+ enter(path, state) {
403
+ log.debug("ENTER", breadCrumb(path));
404
+ state.depth++;
405
+ state.child.push([]);
406
+ state.descendant.push([]);
407
+ state.filters.push([]);
408
+ state.matches.push([]);
409
+ state.functionCalls.push([]);
410
+ state.child[state.depth].forEach(fnode => addIfTokenMatch(fnode, path, state));
411
+ state.descendant.slice(0, state.depth + 1).forEach(fnodes => fnodes.forEach(fnode => addIfTokenMatch(fnode, path, state)));
412
+ },
413
+ exit(path, state) {
414
+ log.debug("EXIT", breadCrumb(path));
415
+ // Check for attributes as not all attributes are visited
416
+ state.child[state.depth + 1].forEach(fnode => addPrimitiveAttributeIfMatch(fnode, path));
417
+ state.descendant.forEach(fnodes => fnodes.forEach(fnode => addPrimitiveAttributeIfMatch(fnode, path)));
418
+ state.matches[state.depth].forEach(([fNode, path]) => addResultIfTokenMatch(fNode, path, state));
419
+ state.depth--;
420
+ state.child.pop();
421
+ state.descendant.pop();
422
+ state.filters.pop();
423
+ state.matches.pop();
424
+ state.functionCalls.pop();
425
+ }
426
+ }, root.scopeId, state, root);
427
+ return results;
428
+ }
429
+ const defaultKey = "__default__";
430
+ function query(code, query) {
431
+ return multiQuery(code, { [defaultKey]: query })[defaultKey];
432
+ }
433
+ exports.query = query;
434
+ function multiQuery(code, namedQueries) {
435
+ const start = Date.now();
436
+ const ast = typeof code == "string" ? parseSource(code) : code;
437
+ if (ast == null)
438
+ throw new Error("Could not pase code");
439
+ const queries = Object.fromEntries(Object.entries(namedQueries).map(([name, query]) => [name, (0, parseQuery_1.parse)(query)]));
440
+ const result = beginHandle(queries, ast);
441
+ log.debug("Query time: ", Date.now() - start);
442
+ return result;
443
+ }
444
+ exports.multiQuery = multiQuery;
445
+ function parseSource(source) {
446
+ try {
447
+ return (0, meriyah_1.parseScript)(source, { module: true, next: true, specDeviation: true });
448
+ }
449
+ catch (e) {
450
+ return (0, meriyah_1.parseScript)(source, { module: false, next: true, specDeviation: true });
451
+ }
452
+ }
453
+ exports.parseSource = parseSource;
@@ -0,0 +1,241 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isExportSpecifier = exports.isScopable = exports.isScope = exports.VISITOR_KEYS = exports.isBinding = exports.isVariableDeclarator = exports.isFunctionExpression = exports.isFunctionDeclaration = exports.isIdentifier = exports.isMemberExpression = exports.isAssignmentExpression = exports.isNode = void 0;
4
+ function isNode(candidate) {
5
+ return typeof candidate === "object" && candidate != null && "type" in candidate;
6
+ }
7
+ exports.isNode = isNode;
8
+ function isAssignmentExpression(node) {
9
+ return node.type === "AssignmentExpression";
10
+ }
11
+ exports.isAssignmentExpression = isAssignmentExpression;
12
+ function isMemberExpression(node) {
13
+ return node.type === "MemberExpression";
14
+ }
15
+ exports.isMemberExpression = isMemberExpression;
16
+ function isIdentifier(node) {
17
+ return node.type === "Identifier";
18
+ }
19
+ exports.isIdentifier = isIdentifier;
20
+ function isFunctionDeclaration(node) {
21
+ return node.type === "FunctionDeclaration";
22
+ }
23
+ exports.isFunctionDeclaration = isFunctionDeclaration;
24
+ function isFunctionExpression(node) {
25
+ return node.type === "FunctionExpression";
26
+ }
27
+ exports.isFunctionExpression = isFunctionExpression;
28
+ function isVariableDeclarator(node) {
29
+ return node.type === "VariableDeclarator";
30
+ }
31
+ exports.isVariableDeclarator = isVariableDeclarator;
32
+ function isBinding(node, parentNode, grandParentNode) {
33
+ if (grandParentNode &&
34
+ node.type === "Identifier" &&
35
+ parentNode.type === "Property" &&
36
+ grandParentNode.type === "ObjectExpression") {
37
+ return false;
38
+ }
39
+ const keys = bindingIdentifiersKeys[parentNode.type] ?? [];
40
+ if (keys) {
41
+ for (let i = 0; i < keys.length; i++) {
42
+ const key = keys[i];
43
+ const val =
44
+ // @ts-expect-error key must present in parent
45
+ parentNode[key];
46
+ if (Array.isArray(val)) {
47
+ if (val.indexOf(node) >= 0)
48
+ return true;
49
+ }
50
+ else {
51
+ if (val === node)
52
+ return true;
53
+ }
54
+ }
55
+ }
56
+ return false;
57
+ }
58
+ exports.isBinding = isBinding;
59
+ const bindingIdentifiersKeys = {
60
+ DeclareClass: ["id"],
61
+ DeclareFunction: ["id"],
62
+ DeclareModule: ["id"],
63
+ DeclareVariable: ["id"],
64
+ DeclareInterface: ["id"],
65
+ DeclareTypeAlias: ["id"],
66
+ DeclareOpaqueType: ["id"],
67
+ InterfaceDeclaration: ["id"],
68
+ TypeAlias: ["id"],
69
+ OpaqueType: ["id"],
70
+ CatchClause: ["param"],
71
+ LabeledStatement: ["label"],
72
+ UnaryExpression: ["argument"],
73
+ AssignmentExpression: ["left"],
74
+ ImportSpecifier: ["local"],
75
+ ImportNamespaceSpecifier: ["local"],
76
+ ImportDefaultSpecifier: ["local"],
77
+ ImportDeclaration: ["specifiers"],
78
+ ExportSpecifier: ["exported"],
79
+ ExportNamespaceSpecifier: ["exported"],
80
+ ExportDefaultSpecifier: ["exported"],
81
+ FunctionDeclaration: ["id", "params"],
82
+ FunctionExpression: ["id", "params"],
83
+ ArrowFunctionExpression: ["params"],
84
+ ObjectMethod: ["params"],
85
+ ClassMethod: ["params"],
86
+ ClassPrivateMethod: ["params"],
87
+ ForInStatement: ["left"],
88
+ ForOfStatement: ["left"],
89
+ ClassDeclaration: ["id"],
90
+ ClassExpression: ["id"],
91
+ RestElement: ["argument"],
92
+ UpdateExpression: ["argument"],
93
+ ObjectProperty: ["value"],
94
+ AssignmentPattern: ["left"],
95
+ ArrayPattern: ["elements"],
96
+ ObjectPattern: ["properties"],
97
+ VariableDeclaration: ["declarations"],
98
+ VariableDeclarator: ["id"],
99
+ };
100
+ exports.VISITOR_KEYS = {
101
+ ArrayExpression: ["elements"],
102
+ ArrayPattern: ["elements"],
103
+ ArrowFunctionExpression: ["params", "body"],
104
+ AssignmentExpression: ["left", "right"],
105
+ AssignmentPattern: ["left", "right"],
106
+ AwaitExpression: ["argument"],
107
+ BinaryExpression: ["left", "right"],
108
+ BlockStatement: ["body"],
109
+ BreakStatement: [],
110
+ CallExpression: ["callee", "arguments"],
111
+ CatchClause: ["param", "body"],
112
+ ChainExpression: ["expression"],
113
+ ClassBody: ["body"],
114
+ ClassDeclaration: ["id", "superClass", "body"],
115
+ ClassExpression: ["id", "superClass", "body"],
116
+ ConditionalExpression: ["test", "consequent", "alternate"],
117
+ ContinueStatement: [],
118
+ DebuggerStatement: [],
119
+ DoWhileStatement: ["body", "test"],
120
+ EmptyStatement: [],
121
+ ExportAllDeclaration: ["source"],
122
+ ExportDefaultDeclaration: ["declaration"],
123
+ ExportNamedDeclaration: ["declaration", "specifiers", "source"],
124
+ ExportSpecifier: ["local", "exported"],
125
+ ExpressionStatement: ["expression"],
126
+ ForInStatement: ["left", "right", "body"],
127
+ ForOfStatement: ["left", "right", "body"],
128
+ ForStatement: ["init", "test", "update", "body"],
129
+ FunctionDeclaration: ["id", "params", "body"],
130
+ FunctionExpression: ["id", "params", "body"],
131
+ Identifier: [],
132
+ IfStatement: ["test", "consequent", "alternate"],
133
+ ImportDeclaration: ["specifiers", "source"],
134
+ ImportDefaultSpecifier: ["local"],
135
+ ImportNamespaceSpecifier: ["local"],
136
+ ImportSpecifier: ["local", "imported"],
137
+ LabeledStatement: ["label", "body"],
138
+ Literal: [],
139
+ LogicalExpression: ["left", "right"],
140
+ MemberExpression: ["object", "property"],
141
+ MetaProperty: ["meta", "property"],
142
+ MethodDefinition: ["key", "value"],
143
+ NewExpression: ["callee", "arguments"],
144
+ ObjectExpression: ["properties"],
145
+ ObjectPattern: ["properties"],
146
+ Program: ["body"],
147
+ Property: ["key", "value"],
148
+ RestElement: ["argument"],
149
+ ReturnStatement: ["argument"],
150
+ SequenceExpression: ["expressions"],
151
+ SpreadElement: ["argument"],
152
+ Super: [],
153
+ SwitchCase: ["test", "consequent"],
154
+ SwitchStatement: ["discriminant", "cases"],
155
+ TaggedTemplateExpression: ["tag", "quasi"],
156
+ TemplateElement: [],
157
+ TemplateLiteral: ["quasis", "expressions"],
158
+ ThisExpression: [],
159
+ ThrowStatement: ["argument"],
160
+ TryStatement: ["block", "handler", "finalizer"],
161
+ UnaryExpression: ["argument"],
162
+ UpdateExpression: ["argument"],
163
+ VariableDeclaration: ["declarations"],
164
+ VariableDeclarator: ["id", "init"],
165
+ WhileStatement: ["test", "body"],
166
+ WithStatement: ["object", "body"],
167
+ YieldExpression: ["argument"],
168
+ ImportExpression: ["source"],
169
+ Decorator: ["expression"],
170
+ PropertyDefinition: ["key", "value"],
171
+ Import: ["source"],
172
+ JSXAttribute: ["name", "value"],
173
+ JSXNamespacedName: ["namespace", "name"],
174
+ JSXElement: ["openingElement", "closingElement", "children"],
175
+ JSXClosingElement: ["name"],
176
+ JSXOpeningElement: ["name", "attributes"],
177
+ JSXFragment: ["openingFragment", "closingFragment", "children"],
178
+ JSXOpeningFragment: [],
179
+ JSXClosingFragment: [],
180
+ JSXText: [],
181
+ JSXExpressionContainer: ["expression"],
182
+ JSXSpreadChild: ["expression"],
183
+ JSXEmptyExpression: [],
184
+ JSXSpreadAttribute: ["argument"],
185
+ JSXIdentifier: [],
186
+ PrivateIdentifier: [],
187
+ JSXMemberExpression: ["object", "property"],
188
+ ParenthesizedExpression: ["expression"],
189
+ StaticBlock: ["body"],
190
+ };
191
+ function isBlockStatement(node) { return node.type === "BlockStatement"; }
192
+ function isFunction(node) {
193
+ return node.type === "FunctionDeclaration" || node.type === "FunctionExpression";
194
+ }
195
+ function isCatchClause(node) { return node.type === "CatchClause"; }
196
+ function isPattern(node) {
197
+ switch (node.type) {
198
+ case "AssignmentPattern":
199
+ case "ArrayPattern":
200
+ case "ObjectPattern":
201
+ return true;
202
+ }
203
+ return false;
204
+ }
205
+ function isScope(node, parentNode) {
206
+ if (isBlockStatement(node) && (isFunction(parentNode) || isCatchClause(parentNode))) {
207
+ return false;
208
+ }
209
+ if (isPattern(node) && (isFunction(parentNode) || isCatchClause(parentNode))) {
210
+ return true;
211
+ }
212
+ return isFunctionDeclaration(parentNode) || isFunctionExpression(parentNode) || isScopable(node);
213
+ }
214
+ exports.isScope = isScope;
215
+ function isScopable(node) {
216
+ switch (node.type) {
217
+ case "BlockStatement":
218
+ case "CatchClause":
219
+ case "DoWhileStatement":
220
+ case "ForInStatement":
221
+ case "ForStatement":
222
+ case "FunctionDeclaration":
223
+ case "FunctionExpression":
224
+ case "Program":
225
+ case "MethodDefinition":
226
+ case "SwitchStatement":
227
+ case "WhileStatement":
228
+ case "ArrowFunctionExpression":
229
+ case "ClassExpression":
230
+ case "ClassDeclaration":
231
+ case "ForOfStatement":
232
+ case "StaticBlock":
233
+ return true;
234
+ }
235
+ return false;
236
+ }
237
+ exports.isScopable = isScopable;
238
+ function isExportSpecifier(node) {
239
+ return node.type === "ExportSpecifier";
240
+ }
241
+ exports.isExportSpecifier = isExportSpecifier;