|
1 | 1 | export function getFilename(context) {
|
2 |
| - return context.filename ?? context.getFilename(); |
| 2 | + if ('filename' in context) { |
| 3 | + return context.filename; |
| 4 | + } |
| 5 | + |
| 6 | + return context.getFilename(); |
3 | 7 | }
|
4 | 8 |
|
5 | 9 | export function getPhysicalFilename(context) {
|
6 |
| - return context.getPhysicalFilename?.() ?? getFilename(context); |
| 10 | + if (context.getPhysicalFilename) { |
| 11 | + return context.getPhysicalFilename(); |
| 12 | + } |
| 13 | + |
| 14 | + return getFilename(context); |
7 | 15 | }
|
8 | 16 |
|
9 | 17 | export function getSourceCode(context) {
|
10 |
| - return context.sourceCode ?? context.getSourceCode(); |
| 18 | + if ('sourceCode' in context) { |
| 19 | + return context.sourceCode; |
| 20 | + } |
| 21 | + |
| 22 | + return context.getSourceCode(); |
11 | 23 | }
|
12 | 24 |
|
13 | 25 | export function getScope(context, node) {
|
14 |
| - return getSourceCode(context).getScope?.(node) ?? context.getScope(); |
| 26 | + const sourceCode = getSourceCode(context); |
| 27 | + |
| 28 | + if (sourceCode && sourceCode.getScope) { |
| 29 | + return sourceCode.getScope(node); |
| 30 | + } |
| 31 | + |
| 32 | + return context.getScope(); |
15 | 33 | }
|
16 | 34 |
|
17 | 35 | export function getAncestors(context, node) {
|
18 |
| - return getSourceCode(context).getAncestors?.(node) ?? context.getAncestors(); |
| 36 | + const sourceCode = getSourceCode(context); |
| 37 | + |
| 38 | + if (sourceCode && sourceCode.getAncestors) { |
| 39 | + return sourceCode.getAncestors(node); |
| 40 | + } |
| 41 | + |
| 42 | + return context.getAncestors(); |
19 | 43 | }
|
20 | 44 |
|
21 | 45 | export function getDeclaredVariables(context, node) {
|
22 |
| - return getSourceCode(context).getDeclaredVariables?.(node) ?? context.getDeclaredVariables(node); |
| 46 | + const sourceCode = getSourceCode(context); |
| 47 | + |
| 48 | + if (sourceCode && sourceCode.getDeclaredVariables) { |
| 49 | + return sourceCode.getDeclaredVariables(node); |
| 50 | + } |
| 51 | + |
| 52 | + return context.getDeclaredVariables(node); |
23 | 53 | }
|
0 commit comments