[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | function getSourceCode(context) {
|
---|
| 4 | return context.getSourceCode ? context.getSourceCode() : context.sourceCode;
|
---|
| 5 | }
|
---|
| 6 |
|
---|
| 7 | function getAncestors(context, node) {
|
---|
| 8 | const sourceCode = getSourceCode(context);
|
---|
| 9 | return sourceCode.getAncestors ? sourceCode.getAncestors(node) : context.getAncestors();
|
---|
| 10 | }
|
---|
| 11 |
|
---|
| 12 | function getScope(context, node) {
|
---|
| 13 | const sourceCode = getSourceCode(context);
|
---|
| 14 | if (sourceCode.getScope) {
|
---|
| 15 | return sourceCode.getScope(node);
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | return context.getScope();
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | function markVariableAsUsed(name, node, context) {
|
---|
| 22 | const sourceCode = getSourceCode(context);
|
---|
| 23 | return sourceCode.markVariableAsUsed
|
---|
| 24 | ? sourceCode.markVariableAsUsed(name, node)
|
---|
| 25 | : context.markVariableAsUsed(name);
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | function getFirstTokens(context, node, count) {
|
---|
| 29 | const sourceCode = getSourceCode(context);
|
---|
| 30 | return sourceCode.getFirstTokens ? sourceCode.getFirstTokens(node, count) : context.getFirstTokens(node, count);
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | function getText(context) {
|
---|
| 34 | const sourceCode = getSourceCode(context);
|
---|
| 35 | const args = Array.prototype.slice.call(arguments, 1);
|
---|
| 36 | return sourceCode.getText ? sourceCode.getText.apply(sourceCode, args) : context.getSource.apply(context, args);
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | module.exports = {
|
---|
| 40 | getAncestors,
|
---|
| 41 | getFirstTokens,
|
---|
| 42 | getScope,
|
---|
| 43 | getSourceCode,
|
---|
| 44 | getText,
|
---|
| 45 | markVariableAsUsed,
|
---|
| 46 | };
|
---|