Skip to content

Commit

Permalink
refactor: don't use modern syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Apr 7, 2024
1 parent a415b02 commit e6d641e
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions src/context.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,53 @@
export function getFilename(context) {
return context.filename ?? context.getFilename();
if ('filename' in context) {
return context.filename;
}

return context.getFilename();
}

export function getPhysicalFilename(context) {
return context.getPhysicalFilename?.() ?? getFilename(context);
if (context.getPhysicalFilename) {
return context.getPhysicalFilename();
}

return getFilename(context);
}

export function getSourceCode(context) {
return context.sourceCode ?? context.getSourceCode();
if ('sourceCode' in context) {
return context.sourceCode;
}

return context.getSourceCode();
}

export function getScope(context, node) {
return getSourceCode(context).getScope?.(node) ?? context.getScope();
const sourceCode = getSourceCode(context);

if (sourceCode && sourceCode.getScope) {
return sourceCode.getScope(node);
}

return context.getScope();
}

export function getAncestors(context, node) {
return getSourceCode(context).getAncestors?.(node) ?? context.getAncestors();
const sourceCode = getSourceCode(context);

if (sourceCode && sourceCode.getAncestors) {
return sourceCode.getAncestors(node);
}

return context.getAncestors();
}

export function getDeclaredVariables(context, node) {
return getSourceCode(context).getDeclaredVariables?.(node) ?? context.getDeclaredVariables(node);
const sourceCode = getSourceCode(context);

if (sourceCode && sourceCode.getDeclaredVariables) {
return sourceCode.getDeclaredVariables(node);
}

return context.getDeclaredVariables(node);
}

0 comments on commit e6d641e

Please sign in to comment.