-
-
Notifications
You must be signed in to change notification settings - Fork 62
/
parser.js
30 lines (27 loc) · 1.07 KB
/
parser.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
/**
* @see parserServices https://eslint.org/docs/developer-guide/working-with-rules#the-context-object
* @param {Object} context
* @param {Function} templateBodyVisitor
* @param {Function} scriptVisitor
* @returns
*/
function defineTemplateBodyVisitor(context, templateBodyVisitor, scriptVisitor) {
const parserServices = getParserServices(context);
if (parserServices == null || parserServices.defineTemplateBodyVisitor == null) {
// Default parser
return scriptVisitor;
}
// Using "vue-eslint-parser" requires this setup
// @see https://eslint.org/docs/developer-guide/working-with-rules#the-context-object
return parserServices.defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor);
}
/**
* This function is API compatible with eslint v8.x and eslint v9 or later.
* @see https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/#from-context-to-sourcecode
*/
function getParserServices(context) {
return context.sourceCode ? context.sourceCode.parserServices : context.parserServices;
}
module.exports = {
defineTemplateBodyVisitor,
};