Skip to content

Commit

Permalink
Merge pull request #110 from ember-tooling/accept-mathml-tags
Browse files Browse the repository at this point in the history
Add mathml tag check
  • Loading branch information
NullVoxPopuli authored Nov 22, 2024
2 parents aaf293d + 718c5e1 commit 1f2d998
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"content-tag": "^2.0.1",
"eslint-scope": "^7.2.2",
"html-tags": "^3.3.1",
"mathml-tag-names": "^2.1.3",
"svg-tags": "^1.0.0"
},
"devDependencies": {
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/parser/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { visitorKeys: glimmerVisitorKeys } = require('@glimmer/syntax');
const { Reference, Scope, Variable, Definition } = require('eslint-scope');
const htmlTags = require('html-tags');
const svgTags = require('svg-tags');
const mathMLTags = require('mathml-tag-names');

let TypescriptScope = null;
try {
Expand Down Expand Up @@ -489,7 +490,7 @@ module.exports.convertAst = function convertAst(result, preprocessedResult, visi
if we do not find a variable we register it with a missing variable if
* it starts with upper case, it should be a component with a reference
* it includes a dot, it's a path which should have a reference
* it's NOT a standard html or svg tag, it should have a referenced variable
* it's NOT a standard html, svg or mathml tag, it should have a referenced variable
*/
const ignore =
// Local instance access
Expand All @@ -507,7 +508,9 @@ module.exports.convertAst = function convertAst(result, preprocessedResult, visi
const registerUndef =
isUpperCase(n.name[0]) ||
node.name.includes('.') ||
(!htmlTags.includes(node.name) && !svgTags.includes(node.name));
(!htmlTags.includes(node.name) &&
!svgTags.includes(node.name) &&
!mathMLTags.includes(node.name));

if (!ignore && (variable || registerUndef)) {
registerNodeInScope(n, scope, variable);
Expand Down
18 changes: 18 additions & 0 deletions tests/parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2721,6 +2721,24 @@ export const NotFound = <template>
expect(result.scopeManager.scopes[0].through.length).toBe(0);
});

it('mathml elements are not added to global scope', () => {
result = parseForESLint(
`<template>
<math><msqrt><mi>x</mi></msqrt></math>
<mi>x</mi>
</template>`,
{
filePath: 'example.gts',
comment: true,
loc: true,
range: true,
tokens: true,
}
);

expect(result.scopeManager.scopes[0].through.length).toBe(0);
});

it('custom-elements are ignored entirely, like they are in the browser', () => {
result = parseForESLint(
`<template>
Expand Down

0 comments on commit 1f2d998

Please sign in to comment.