Skip to content

Commit

Permalink
Merge pull request #1452 from YusukeHirao/hotfix/#1451
Browse files Browse the repository at this point in the history
Fix element type detection
  • Loading branch information
YusukeHirao committed Feb 10, 2024
2 parents 6172b30 + 3274a51 commit fd522e8
Show file tree
Hide file tree
Showing 48 changed files with 240 additions and 136 deletions.
6 changes: 3 additions & 3 deletions packages/@markuplint/astro-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@markuplint/astro-parser",
"version": "4.0.1",
"version": "4.0.2",
"description": "astro parser for markuplint",
"repository": "git@github.com:markuplint/markuplint.git",
"author": "Yusuke Hirao <yusukehirao@me.com>",
Expand All @@ -21,8 +21,8 @@
"clean": "tsc --build --clean"
},
"dependencies": {
"@markuplint/ml-ast": "4.0.0",
"@markuplint/parser-utils": "4.0.0",
"@markuplint/ml-ast": "4.0.1",
"@markuplint/parser-utils": "4.0.1",
"astro-eslint-parser": "^0.16.2"
},
"devDependencies": {
Expand Down
6 changes: 6 additions & 0 deletions packages/@markuplint/astro-parser/src/parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,4 +638,10 @@ describe('Issue', () => {
'[1:23]>[1:29](22,28)div: </div>',
]);
});

test('#1451', () => {
expect(parse('<div></div>').nodeList[0].elementType).toBe('html');
expect(parse('<x-div></x-div>').nodeList[0].elementType).toBe('web-component');
expect(parse('<Div></Div>').nodeList[0].elementType).toBe('authored');
});
});
12 changes: 12 additions & 0 deletions packages/@markuplint/astro-parser/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,18 @@ class AstroParser extends Parser<Node, State> {
};
}

/**
* > Variable names must be capitalized. For example, use `Element`, not `element`.
* > Otherwise, Astro will try to render your variable name as a literal HTML tag.
*
* @see https://docs.astro.build/en/basics/astro-syntax/#dynamic-html
* @param nodeName
* @param defaultPattern
*/
detectElementType(nodeName: string) {
return super.detectElementType(nodeName, /^[A-Z]/);
}

#updateScopeNS(
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
originNode: Node,
Expand Down
2 changes: 1 addition & 1 deletion packages/@markuplint/cli-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@markuplint/cli-utils",
"version": "4.0.0",
"version": "4.0.1",
"description": "Utilities for CLI of Markuplint",
"repository": "git@github.com:markuplint/markuplint.git",
"author": "Yusuke Hirao <yusukehirao@me.com>",
Expand Down
6 changes: 3 additions & 3 deletions packages/@markuplint/create-rule/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@markuplint/create-rule",
"version": "4.0.2",
"version": "4.0.3",
"description": "Rule generator for markuplint",
"repository": "git@github.com:markuplint/markuplint.git",
"author": "Yusuke Hirao <yusukehirao@me.com>",
Expand All @@ -25,8 +25,8 @@
"clean": "tsc --build --clean"
},
"dependencies": {
"@markuplint/cli-utils": "4.0.0",
"@markuplint/ml-core": "4.0.2",
"@markuplint/cli-utils": "4.0.1",
"@markuplint/ml-core": "4.0.3",
"glob": "^10.3.6",
"prettier": "^3.2.5",
"ts-node": "^10.9.2",
Expand Down
6 changes: 3 additions & 3 deletions packages/@markuplint/ejs-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@markuplint/ejs-parser",
"version": "4.0.0",
"version": "4.0.1",
"description": "EJS parser for markuplint",
"repository": "git@github.com:markuplint/markuplint.git",
"author": "Yusuke Hirao <yusukehirao@me.com>",
Expand All @@ -21,9 +21,9 @@
"clean": "tsc --build --clean"
},
"dependencies": {
"@markuplint/html-parser": "4.0.0"
"@markuplint/html-parser": "4.0.1"
},
"devDependencies": {
"@markuplint/parser-utils": "4.0.0"
"@markuplint/parser-utils": "4.0.1"
}
}
6 changes: 3 additions & 3 deletions packages/@markuplint/erb-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@markuplint/erb-parser",
"version": "4.0.0",
"version": "4.0.1",
"description": "eRuby template parser for markuplint",
"repository": "git@github.com:markuplint/markuplint.git",
"author": "Yusuke Hirao <yusukehirao@me.com>",
Expand All @@ -21,9 +21,9 @@
"clean": "tsc --build --clean"
},
"dependencies": {
"@markuplint/html-parser": "4.0.0"
"@markuplint/html-parser": "4.0.1"
},
"devDependencies": {
"@markuplint/parser-utils": "4.0.0"
"@markuplint/parser-utils": "4.0.1"
}
}
2 changes: 1 addition & 1 deletion packages/@markuplint/esm-adapter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@markuplint/esm-adapter",
"version": "4.0.0",
"version": "4.0.1",
"description": "A library for utilizing ESM-converted Markuplint modules through a subprocess from a CJS environment",
"repository": "git@github.com:markuplint/markuplint.git",
"author": "Yusuke Hirao <yusukehirao@me.com>",
Expand Down
18 changes: 9 additions & 9 deletions packages/@markuplint/file-resolver/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@markuplint/file-resolver",
"version": "4.0.2",
"version": "4.0.3",
"description": "The file resolver of markuplint",
"repository": "git@github.com:markuplint/markuplint.git",
"author": "Yusuke Hirao <yusukehirao@me.com>",
Expand All @@ -27,14 +27,14 @@
"@types/node": "20.11.17"
},
"dependencies": {
"@markuplint/html-parser": "4.0.0",
"@markuplint/ml-ast": "4.0.0",
"@markuplint/ml-config": "4.0.0",
"@markuplint/ml-core": "4.0.2",
"@markuplint/ml-spec": "4.0.0",
"@markuplint/parser-utils": "4.0.0",
"@markuplint/selector": "4.0.0",
"@markuplint/shared": "4.0.0",
"@markuplint/html-parser": "4.0.1",
"@markuplint/ml-ast": "4.0.1",
"@markuplint/ml-config": "4.0.1",
"@markuplint/ml-core": "4.0.3",
"@markuplint/ml-spec": "4.0.1",
"@markuplint/parser-utils": "4.0.1",
"@markuplint/selector": "4.0.1",
"@markuplint/shared": "4.0.1",
"cosmiconfig": "^9.0.0",
"debug": "^4.3.4",
"glob": "^10.3.6",
Expand Down
6 changes: 3 additions & 3 deletions packages/@markuplint/html-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@markuplint/html-parser",
"version": "4.0.0",
"version": "4.0.1",
"description": "HTML parser for markuplint",
"repository": "git@github.com:markuplint/markuplint.git",
"author": "Yusuke Hirao <yusukehirao@me.com>",
Expand All @@ -25,8 +25,8 @@
"clean": "tsc --build --clean"
},
"dependencies": {
"@markuplint/ml-ast": "4.0.0",
"@markuplint/parser-utils": "4.0.0",
"@markuplint/ml-ast": "4.0.1",
"@markuplint/parser-utils": "4.0.1",
"parse5": "7.1.2",
"type-fest": "^4.10.2"
}
Expand Down
8 changes: 4 additions & 4 deletions packages/@markuplint/html-spec/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@markuplint/html-spec",
"version": "4.0.1",
"version": "4.0.2",
"description": "A specification of HTML Living Standard for markuplint",
"repository": "git@github.com:markuplint/markuplint.git",
"author": "Yusuke Hirao <yusukehirao@me.com>",
Expand All @@ -17,10 +17,10 @@
"gen:prettier": "prettier --write index.json"
},
"devDependencies": {
"@markuplint/spec-generator": "4.0.0",
"@markuplint/test-tools": "4.0.0"
"@markuplint/spec-generator": "4.0.1",
"@markuplint/test-tools": "4.0.1"
},
"dependencies": {
"@markuplint/ml-spec": "4.0.0"
"@markuplint/ml-spec": "4.0.1"
}
}
2 changes: 1 addition & 1 deletion packages/@markuplint/i18n/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@markuplint/i18n",
"version": "4.0.0",
"version": "4.0.1",
"description": "Internationalization for markuplint",
"repository": "git@github.com:markuplint/markuplint.git",
"author": "Yusuke Hirao <yusukehirao@me.com>",
Expand Down
8 changes: 4 additions & 4 deletions packages/@markuplint/jsx-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@markuplint/jsx-parser",
"version": "4.0.2",
"version": "4.0.3",
"description": "JSX parser for markuplint",
"repository": "git@github.com:markuplint/markuplint.git",
"author": "Yusuke Hirao <yusukehirao@me.com>",
Expand All @@ -21,9 +21,9 @@
"clean": "tsc --build --clean"
},
"dependencies": {
"@markuplint/html-parser": "4.0.0",
"@markuplint/ml-ast": "4.0.0",
"@markuplint/parser-utils": "4.0.0",
"@markuplint/html-parser": "4.0.1",
"@markuplint/ml-ast": "4.0.1",
"@markuplint/parser-utils": "4.0.1",
"@typescript-eslint/types": "^6.21.0",
"@typescript-eslint/typescript-estree": "^6.21.0"
}
Expand Down
6 changes: 6 additions & 0 deletions packages/@markuplint/jsx-parser/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,4 +618,10 @@ const C = () => {
};`);
expect(nodeListToDebugMaps(doc.nodeList, true)).toStrictEqual(['[9:10]>[9:17](148,155)div: <div␣/>']);
});

test('#1451', () => {
expect(parse('<div></div>').nodeList[0].elementType).toBe('html');
expect(parse('<x-div></x-div>').nodeList[0].elementType).toBe('web-component');
expect(parse('<Div></Div>').nodeList[0].elementType).toBe('authored');
});
});
21 changes: 12 additions & 9 deletions packages/@markuplint/jsx-parser/src/parser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { JSXComment, JSXNode } from './jsx.js';
import type { ElementType, MLASTNodeTreeItem, MLASTParentNode } from '@markuplint/ml-ast';
import type { MLASTNodeTreeItem, MLASTParentNode } from '@markuplint/ml-ast';
import type { ChildToken, Token } from '@markuplint/parser-utils';

import { getNamespace } from '@markuplint/html-parser';
Expand Down Expand Up @@ -289,14 +289,17 @@ class JSXParser extends Parser<JSXNode, State> {
});
}

detectElementType(nodeName: string): ElementType {
return super.detectElementType(
nodeName,
/**
* @see https://reactjs.org/docs/jsx-in-depth.html#user-defined-components-must-be-capitalized
*/
/^[A-Z]|\./,
);
/**
* > We recommend naming components with a capital letter.
* > If you do have a component that starts with a lowercase letter,
* > assign it to a capitalized variable before using it in JSX.
*
* @see https://reactjs.org/docs/jsx-in-depth.html#user-defined-components-must-be-capitalized
* @param nodeName
* @returns
*/
detectElementType(nodeName: string) {
return super.detectElementType(nodeName, /^[A-Z]|\./);
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/@markuplint/liquid-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@markuplint/liquid-parser",
"version": "4.0.0",
"version": "4.0.1",
"description": "Liquid template parser for markuplint",
"repository": "git@github.com:markuplint/markuplint.git",
"author": "Yusuke Hirao <yusukehirao@me.com>",
Expand All @@ -21,9 +21,9 @@
"clean": "tsc --build --clean"
},
"dependencies": {
"@markuplint/html-parser": "4.0.0"
"@markuplint/html-parser": "4.0.1"
},
"devDependencies": {
"@markuplint/parser-utils": "4.0.0"
"@markuplint/parser-utils": "4.0.1"
}
}
2 changes: 1 addition & 1 deletion packages/@markuplint/ml-ast/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@markuplint/ml-ast",
"version": "4.0.0",
"version": "4.0.1",
"description": "The markuplint AST types.",
"repository": "git@github.com:markuplint/markuplint.git",
"author": "Yusuke Hirao <yusukehirao@me.com>",
Expand Down
8 changes: 4 additions & 4 deletions packages/@markuplint/ml-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@markuplint/ml-config",
"version": "4.0.0",
"version": "4.0.1",
"description": "JSON Schema and TypeScript types of markuplint configure JSON",
"repository": "git@github.com:markuplint/markuplint.git",
"author": "Yusuke Hirao <yusukehirao@me.com>",
Expand All @@ -24,9 +24,9 @@
"clean": "tsc --build --clean"
},
"dependencies": {
"@markuplint/ml-ast": "4.0.0",
"@markuplint/selector": "4.0.0",
"@markuplint/shared": "4.0.0",
"@markuplint/ml-ast": "4.0.1",
"@markuplint/selector": "4.0.1",
"@markuplint/shared": "4.0.1",
"@types/mustache": "^4.2.5",
"deepmerge": "^4.3.1",
"is-plain-object": "^5.0.0",
Expand Down
18 changes: 9 additions & 9 deletions packages/@markuplint/ml-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@markuplint/ml-core",
"version": "4.0.2",
"version": "4.0.3",
"description": "The core module of markuplint",
"repository": "git@github.com:markuplint/markuplint.git",
"author": "Yusuke Hirao <yusukehirao@me.com>",
Expand Down Expand Up @@ -29,14 +29,14 @@
},
"dependencies": {
"@markuplint/config-presets": "4.0.1",
"@markuplint/html-parser": "4.0.0",
"@markuplint/html-spec": "4.0.1",
"@markuplint/i18n": "4.0.0",
"@markuplint/ml-ast": "4.0.0",
"@markuplint/ml-config": "4.0.0",
"@markuplint/ml-spec": "4.0.0",
"@markuplint/parser-utils": "4.0.0",
"@markuplint/selector": "4.0.0",
"@markuplint/html-parser": "4.0.1",
"@markuplint/html-spec": "4.0.2",
"@markuplint/i18n": "4.0.1",
"@markuplint/ml-ast": "4.0.1",
"@markuplint/ml-config": "4.0.1",
"@markuplint/ml-spec": "4.0.1",
"@markuplint/parser-utils": "4.0.1",
"@markuplint/selector": "4.0.1",
"@types/debug": "^4.1.12",
"debug": "^4.3.4",
"is-plain-object": "^5.0.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/@markuplint/ml-spec/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@markuplint/ml-spec",
"version": "4.0.0",
"version": "4.0.1",
"description": "Types and schema that specs of the Markup languages for markuplint",
"repository": "git@github.com:markuplint/markuplint.git",
"author": "Yusuke Hirao <yusukehirao@me.com>",
Expand Down Expand Up @@ -32,14 +32,14 @@
"schema:prettier": "prettier --write \"./schemas/*.json\" \"./src/types/*.ts\" --log-level warn"
},
"dependencies": {
"@markuplint/ml-ast": "4.0.0",
"@markuplint/types": "4.0.0",
"@markuplint/ml-ast": "4.0.1",
"@markuplint/types": "4.0.1",
"dom-accessibility-api": "^0.6.3",
"is-plain-object": "^5.0.0",
"type-fest": "^4.10.2"
},
"devDependencies": {
"@markuplint/test-tools": "4.0.0",
"@markuplint/test-tools": "4.0.1",
"json-schema-to-typescript": "13.1.2"
}
}
6 changes: 3 additions & 3 deletions packages/@markuplint/mustache-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@markuplint/mustache-parser",
"version": "4.0.0",
"version": "4.0.1",
"description": "The mustache template parser for markuplint",
"repository": "git@github.com:markuplint/markuplint.git",
"author": "Yusuke Hirao <yusukehirao@me.com>",
Expand All @@ -21,9 +21,9 @@
"clean": "tsc --build --clean"
},
"dependencies": {
"@markuplint/html-parser": "4.0.0"
"@markuplint/html-parser": "4.0.1"
},
"devDependencies": {
"@markuplint/parser-utils": "4.0.0"
"@markuplint/parser-utils": "4.0.1"
}
}

0 comments on commit fd522e8

Please sign in to comment.