10
10
// ------------------------------------------------------------------------------
11
11
12
12
const HTML_ELEMENT_NAMES = new Set ( require ( './html-elements.json' ) )
13
- const SVG_ELEMENT_NAMES = new Set ( require ( './svg-elements.json' ) )
14
13
const VOID_ELEMENT_NAMES = new Set ( require ( './void-elements.json' ) )
15
14
const assert = require ( 'assert' )
15
+ const vueEslintParser = require ( 'vue-eslint-parser' )
16
16
17
17
// ------------------------------------------------------------------------------
18
18
// Exports
@@ -38,24 +38,6 @@ module.exports = {
38
38
context . parserServices . registerTemplateBodyVisitor ( context , visitor )
39
39
} ,
40
40
41
- /**
42
- * Get the token store of template body from parser services.
43
- * If the parser service of `vue-eslint-parser` was not found,
44
- * this generates a warning.
45
- *
46
- * @returns {void }
47
- */
48
- getTemplateBodyTokenStore ( ) {
49
- if ( context . parserServices . getTemplateBodyTokenStore == null ) {
50
- context . report ( {
51
- loc : { line : 1 , column : 0 } ,
52
- message : 'Use the latest vue-eslint-parser. See also https://github.com/vuejs/eslint-plugin-vue#what-is-the-use-the-latest-vue-eslint-parser-error'
53
- } )
54
- return context . getSourceCode ( )
55
- }
56
- return context . parserServices . getTemplateBodyTokenStore ( )
57
- } ,
58
-
59
41
/**
60
42
* Check whether the given node is the root element or not.
61
43
* @param {ASTNode } node The element node to check.
@@ -200,34 +182,44 @@ module.exports = {
200
182
isCustomComponent ( node ) {
201
183
assert ( node && node . type === 'VElement' )
202
184
203
- const name = node . name
204
185
return (
205
- ! ( this . isHtmlElementName ( name ) || this . isSvgElementName ( name ) ) ||
206
- this . hasAttribute ( node , 'is' ) ||
207
- this . hasDirective ( node , 'bind' , 'is' )
186
+ ! ( this . isKnownHtmlElementNode ( node ) || this . isSvgElementNode ( node ) || this . isMathMLElementNode ( node ) ) ||
187
+ this . hasAttribute ( node , 'is' ) ||
188
+ this . hasDirective ( node , 'bind' , 'is' )
208
189
)
209
190
} ,
210
191
211
192
/**
212
- * Check whether the given name is a HTML element name or not.
213
- * @param {string } name The name to check.
214
- * @returns {boolean } `true` if the name is a HTML element name .
193
+ * Check whether the given node is a HTML element or not.
194
+ * @param {ASTNode } node The node to check.
195
+ * @returns {boolean } `true` if the node is a HTML element.
215
196
*/
216
- isHtmlElementName ( name ) {
217
- assert ( typeof name === 'string ' )
197
+ isKnownHtmlElementNode ( node ) {
198
+ assert ( node && node . type === 'VElement ' )
218
199
219
- return HTML_ELEMENT_NAMES . has ( name . toLowerCase ( ) )
200
+ return node . namespace === vueEslintParser . AST . NS . HTML && HTML_ELEMENT_NAMES . has ( node . name . toLowerCase ( ) )
220
201
} ,
221
202
222
203
/**
223
- * Check whether the given name is a SVG element name or not.
224
- * @param {string } name The name to check.
225
- * @returns {boolean } `true` if the name is a SVG element name .
204
+ * Check whether the given node is a SVG element or not.
205
+ * @param {ASTNode } node The node to check.
206
+ * @returns {boolean } `true` if the name is a SVG element.
226
207
*/
227
- isSvgElementName ( name ) {
228
- assert ( typeof name === 'string' )
208
+ isSvgElementNode ( node ) {
209
+ assert ( node && node . type === 'VElement' )
210
+
211
+ return node . namespace === vueEslintParser . AST . NS . SVG
212
+ } ,
213
+
214
+ /**
215
+ * Check whether the given name is a MathML element or not.
216
+ * @param {ASTNode } name The node to check.
217
+ * @returns {boolean } `true` if the node is a MathML element.
218
+ */
219
+ isMathMLElementNode ( node ) {
220
+ assert ( node && node . type === 'VElement' )
229
221
230
- return SVG_ELEMENT_NAMES . has ( name . toLowerCase ( ) )
222
+ return node . namespace === vueEslintParser . AST . NS . MathML
231
223
} ,
232
224
233
225
/**
0 commit comments