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