UNPKG

1.6 kBJavaScriptView Raw
1'use strict';
2
3exports.__esModule = true;
4
5/** @type {import('./contextCompat').getAncestors} */
6function getAncestors(context, node) {
7 const sourceCode = getSourceCode(context);
8
9 if (sourceCode && sourceCode.getAncestors) {
10 return sourceCode.getAncestors(node);
11 }
12
13 return context.getAncestors();
14}
15
16/** @type {import('./contextCompat').getDeclaredVariables} */
17function getDeclaredVariables(context, node) {
18 const sourceCode = getSourceCode(context);
19
20 if (sourceCode && sourceCode.getDeclaredVariables) {
21 return sourceCode.getDeclaredVariables(node);
22 }
23
24 return context.getDeclaredVariables(node);
25}
26
27/** @type {import('./contextCompat').getFilename} */
28function getFilename(context) {
29 if ('filename' in context) {
30 return context.filename;
31 }
32
33 return context.getFilename();
34}
35
36/** @type {import('./contextCompat').getPhysicalFilename} */
37function getPhysicalFilename(context) {
38 if (context.getPhysicalFilename) {
39 return context.getPhysicalFilename();
40 }
41
42 return getFilename(context);
43}
44
45/** @type {import('./contextCompat').getScope} */
46function getScope(context, node) {
47 const sourceCode = getSourceCode(context);
48
49 if (sourceCode && sourceCode.getScope) {
50 return sourceCode.getScope(node);
51 }
52
53 return context.getScope();
54}
55
56/** @type {import('./contextCompat').getSourceCode} */
57function getSourceCode(context) {
58 if ('sourceCode' in context) {
59 return context.sourceCode;
60 }
61
62 return context.getSourceCode();
63}
64
65module.exports = {
66 getAncestors,
67 getDeclaredVariables,
68 getFilename,
69 getPhysicalFilename,
70 getScope,
71 getSourceCode,
72};