|
9 | 9 | // Helpers
|
10 | 10 | // ------------------------------------------------------------------------------
|
11 | 11 |
|
12 |
| -const HTML_ELEMENT_NAMES = new Set(require('./html-elements.json')) |
13 |
| -const SVG_ELEMENT_NAMES = new Set(require('./svg-elements.json')) |
14 |
| -const VOID_ELEMENT_NAMES = new Set(require('./void-elements.json')) |
| 12 | +const HTML_TAG_NAMES = new Set(require('html-tag-names')) |
| 13 | +const SVG_TAG_NAMES = new Set(require('svg-tag-names')) |
| 14 | +const MATHML_TAG_NAMES = new Set(require('mathml-tag-names')) |
| 15 | +const VOID_TAG_NAMES = new Set(require('./void-elements.json')) |
15 | 16 | const assert = require('assert')
|
16 | 17 |
|
17 | 18 | // ------------------------------------------------------------------------------
|
@@ -67,8 +68,8 @@ module.exports = {
|
67 | 68 | assert(node && node.type === 'VElement')
|
68 | 69 |
|
69 | 70 | return (
|
70 |
| - node.parent.type === 'Program' || |
71 |
| - node.parent.parent.type === 'Program' |
| 71 | + node.parent.type === 'Program' || |
| 72 | + node.parent.parent.type === 'Program' |
72 | 73 | )
|
73 | 74 | },
|
74 | 75 |
|
@@ -194,53 +195,64 @@ module.exports = {
|
194 | 195 | )
|
195 | 196 | },
|
196 | 197 |
|
197 |
| - /** |
198 |
| - * Check whether the given node is a custom component or not. |
199 |
| - * @param {ASTNode} node The start tag node to check. |
200 |
| - * @returns {boolean} `true` if the node is a custom component. |
201 |
| - */ |
| 198 | + /** |
| 199 | + * Check whether the given node is a custom component or not. |
| 200 | + * @param {ASTNode} node The start tag node to check. |
| 201 | + * @returns {boolean} `true` if the node is a custom component. |
| 202 | + */ |
202 | 203 | isCustomComponent (node) {
|
203 | 204 | assert(node && node.type === 'VStartTag')
|
204 | 205 |
|
205 | 206 | const name = node.id.name
|
206 | 207 | return (
|
207 |
| - !(this.isHtmlElementName(name) || this.isSvgElementName(name)) || |
208 |
| - this.hasAttribute(node, 'is') || |
209 |
| - this.hasDirective(node, 'bind', 'is') |
| 208 | + !(this.isHtmlElementName(name) || this.isSvgElementName(name) || this.isMathMLElementName(name)) || |
| 209 | + this.hasAttribute(node, 'is') || |
| 210 | + this.hasDirective(node, 'bind', 'is') |
210 | 211 | )
|
211 | 212 | },
|
212 | 213 |
|
213 |
| - /** |
214 |
| - * Check whether the given name is a HTML element name or not. |
215 |
| - * @param {string} name The name to check. |
216 |
| - * @returns {boolean} `true` if the name is a HTML element name. |
217 |
| - */ |
| 214 | + /** |
| 215 | + * Check whether the given name is a HTML element name or not. |
| 216 | + * @param {string} name The name to check. |
| 217 | + * @returns {boolean} `true` if the name is a HTML element name. |
| 218 | + */ |
218 | 219 | isHtmlElementName (name) {
|
219 | 220 | assert(typeof name === 'string')
|
220 | 221 |
|
221 |
| - return HTML_ELEMENT_NAMES.has(name.toLowerCase()) |
| 222 | + return HTML_TAG_NAMES.has(name.toLowerCase()) |
222 | 223 | },
|
223 | 224 |
|
224 |
| - /** |
225 |
| - * Check whether the given name is a SVG element name or not. |
226 |
| - * @param {string} name The name to check. |
227 |
| - * @returns {boolean} `true` if the name is a SVG element name. |
228 |
| - */ |
| 225 | + /** |
| 226 | + * Check whether the given name is a SVG element name or not. |
| 227 | + * @param {string} name The name to check. |
| 228 | + * @returns {boolean} `true` if the name is a SVG element name. |
| 229 | + */ |
229 | 230 | isSvgElementName (name) {
|
230 | 231 | assert(typeof name === 'string')
|
231 | 232 |
|
232 |
| - return SVG_ELEMENT_NAMES.has(name.toLowerCase()) |
| 233 | + return SVG_TAG_NAMES.has(name.toLowerCase()) |
233 | 234 | },
|
234 | 235 |
|
235 |
| - /** |
236 |
| - * Check whether the given name is a void element name or not. |
237 |
| - * @param {string} name The name to check. |
238 |
| - * @returns {boolean} `true` if the name is a void element name. |
239 |
| - */ |
| 236 | + /** |
| 237 | + * Check whether the given name is a MathML element name or not. |
| 238 | + * @param {string} name The name to check. |
| 239 | + * @returns {boolean} `true` if the name is a HTML element name. |
| 240 | + */ |
| 241 | + isMathMLElementName (name) { |
| 242 | + assert(typeof name === 'string') |
| 243 | + |
| 244 | + return MATHML_TAG_NAMES.has(name.toLowerCase()) |
| 245 | + }, |
| 246 | + |
| 247 | + /** |
| 248 | + * Check whether the given name is a void element name or not. |
| 249 | + * @param {string} name The name to check. |
| 250 | + * @returns {boolean} `true` if the name is a void element name. |
| 251 | + */ |
240 | 252 | isVoidElementName (name) {
|
241 | 253 | assert(typeof name === 'string')
|
242 | 254 |
|
243 |
| - return VOID_ELEMENT_NAMES.has(name.toLowerCase()) |
| 255 | + return VOID_TAG_NAMES.has(name.toLowerCase()) |
244 | 256 | },
|
245 | 257 |
|
246 | 258 | /**
|
|
0 commit comments