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

Add mathml tag check #110

Merged
merged 2 commits into from
Nov 22, 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
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
Loading