-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |