Skip to content

Commit e6d641e

Browse files
committed
refactor: don't use modern syntax
1 parent a415b02 commit e6d641e

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

Diff for: src/context.js

+36-6
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,53 @@
11
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();
37
}
48

59
export function getPhysicalFilename(context) {
6-
return context.getPhysicalFilename?.() ?? getFilename(context);
10+
if (context.getPhysicalFilename) {
11+
return context.getPhysicalFilename();
12+
}
13+
14+
return getFilename(context);
715
}
816

917
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();
1123
}
1224

1325
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();
1533
}
1634

1735
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();
1943
}
2044

2145
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);
2353
}

0 commit comments

Comments
 (0)