Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support MathML elements #2457

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/rules/component-name-in-template-casing.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,12 @@ module.exports = {
}

if (
(!utils.isHtmlElementNode(node) && !utils.isSvgElementNode(node)) ||
(!utils.isHtmlElementNode(node) &&
!utils.isSvgElementNode(node) &&
!utils.isMathElementNode(node)) ||
utils.isHtmlWellKnownElementName(node.rawName) ||
utils.isSvgWellKnownElementName(node.rawName) ||
utils.isMathWellKnownElementName(node.rawName) ||
utils.isVueBuiltInElementName(node.rawName)
) {
return false
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/html-self-closing.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function getElementType(node) {
if (utils.isSvgElementNode(node)) {
return 'SVG'
}
if (utils.isMathMLElementNode(node)) {
if (utils.isMathElementNode(node)) {
return 'MATH'
}
return 'UNKNOWN'
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/no-deprecated-html-element-is.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ module.exports = {
function isValidElement(node) {
return (
!utils.isHtmlWellKnownElementName(node.rawName) &&
!utils.isSvgWellKnownElementName(node.rawName)
!utils.isSvgWellKnownElementName(node.rawName) &&
!utils.isMathWellKnownElementName(node.rawName)
)
}
return utils.defineTemplateBodyVisitor(context, {
Expand Down
7 changes: 6 additions & 1 deletion lib/rules/no-undef-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ module.exports = {
if (
utils.isHtmlWellKnownElementName(rawName) ||
utils.isSvgWellKnownElementName(rawName) ||
utils.isMathWellKnownElementName(rawName) ||
utils.isBuiltInComponentName(kebabCaseName)
) {
return false
Expand Down Expand Up @@ -177,7 +178,11 @@ module.exports = {
/** @type {TemplateListener} */
const templateBodyVisitor = {
VElement(node) {
if (!utils.isHtmlElementNode(node) && !utils.isSvgElementNode(node)) {
if (
!utils.isHtmlElementNode(node) &&
!utils.isSvgElementNode(node) &&
!utils.isMathElementNode(node)
) {
return
}
verifyName(node.rawName, node.startTag)
Expand Down
7 changes: 5 additions & 2 deletions lib/rules/no-unused-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ module.exports = {
/** @param {VElement} node */
VElement(node) {
if (
(!utils.isHtmlElementNode(node) && !utils.isSvgElementNode(node)) ||
(!utils.isHtmlElementNode(node) &&
!utils.isSvgElementNode(node) &&
!utils.isMathElementNode(node)) ||
utils.isHtmlWellKnownElementName(node.rawName) ||
utils.isSvgWellKnownElementName(node.rawName)
utils.isSvgWellKnownElementName(node.rawName) ||
utils.isMathWellKnownElementName(node.rawName)
) {
return
}
Expand Down
7 changes: 5 additions & 2 deletions lib/rules/script-setup-uses-vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,13 @@ module.exports = {
},
VElement(node) {
if (
(!utils.isHtmlElementNode(node) && !utils.isSvgElementNode(node)) ||
(!utils.isHtmlElementNode(node) &&
!utils.isSvgElementNode(node) &&
!utils.isMathElementNode(node)) ||
(node.rawName === node.name &&
(utils.isHtmlWellKnownElementName(node.rawName) ||
utils.isSvgWellKnownElementName(node.rawName))) ||
utils.isSvgWellKnownElementName(node.rawName) ||
utils.isMathWellKnownElementName(node.rawName))) ||
utils.isBuiltInComponentName(node.rawName)
) {
return
Expand Down
14 changes: 13 additions & 1 deletion lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const { getScope } = require('./scope')

const HTML_ELEMENT_NAMES = new Set(require('./html-elements.json'))
const SVG_ELEMENT_NAMES = new Set(require('./svg-elements.json'))
const MATH_ELEMENT_NAMES = new Set(require('./math-elements.json'))
const VOID_ELEMENT_NAMES = new Set(require('./void-elements.json'))
const VUE2_BUILTIN_COMPONENT_NAMES = new Set(
require('./vue2-builtin-components')
Expand Down Expand Up @@ -948,6 +949,8 @@ module.exports = {
!this.isHtmlWellKnownElementName(node.rawName)) ||
(this.isSvgElementNode(node) &&
!this.isSvgWellKnownElementName(node.rawName)) ||
(this.isMathElementNode(node) &&
!this.isMathWellKnownElementName(node.rawName)) ||
hasAttribute(node, 'is') ||
hasDirective(node, 'bind', 'is') ||
hasDirective(node, 'is')
Expand Down Expand Up @@ -977,7 +980,7 @@ module.exports = {
* @param {VElement} node The node to check.
* @returns {boolean} `true` if the node is a MathML element.
*/
isMathMLElementNode(node) {
isMathElementNode(node) {
return node.namespace === NS.MathML
},

Expand All @@ -999,6 +1002,15 @@ module.exports = {
return SVG_ELEMENT_NAMES.has(name)
},

/**
* Check whether the given name is a well-known MathML element or not.
* @param {string} name The name to check.
* @returns {boolean} `true` if the name is a well-known MathML element name.
*/
isMathWellKnownElementName(name) {
return MATH_ELEMENT_NAMES.has(name)
},

/**
* Check whether the given name is a void element name or not.
* @param {string} name The name to check.
Expand Down
34 changes: 34 additions & 0 deletions lib/utils/math-elements.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[
"math",
"maction",
"annotation",
"annotation-xml",
"menclose",
"merror",
"mfenced",
"mfrac",
"mi",
"mmultiscripts",
"mn",
"mo",
"mover",
"mpadded",
"mphantom",
"mprescripts",
"mroot",
"mrow",
"ms",
"semantics",
"mspace",
"msqrt",
"mstyle",
"msub",
"msup",
"msubsup",
"mtable",
"mtd",
"mtext",
"mtr",
"munder",
"munderover"
]
Loading