Skip to content

Commit

Permalink
Add test and comment for element type detection in Vue
Browse files Browse the repository at this point in the history
  • Loading branch information
yusukehirao committed Feb 10, 2024
1 parent 855e55f commit 8757d62
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/@markuplint/vue-parser/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,4 +602,10 @@ h3 {
'[15:9]>[16:1](374,375)#text: ⏎',
]);
});

test('#1451', () => {
expect(parse('<template><div></div></template>').nodeList[0].elementType).toBe('html');
expect(parse('<template><x-div></x-div></template>').nodeList[0].elementType).toBe('web-component');
expect(parse('<template><Div></Div></template>').nodeList[0].elementType).toBe('authored');
});
});
19 changes: 17 additions & 2 deletions packages/@markuplint/vue-parser/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,30 @@ class VueParser extends Parser<ASTNode, State> {
return attr;
}

/**
* > In SFCs, it's recommended to use `PascalCase` tag names
* > for child components to differentiate from native HTML elements.
* > Although native HTML tag names are case-insensitive,
* > Vue SFC is a compiled format so we are able to use case-sensitive tag names in it.
* > We are also able to use `/>` to close a tag.
*
* @see https://vuejs.org/guide/essentials/component-basics#using-a-component
* @see https://vuejs.org/api/built-in-components.html
* @see https://vuejs.org/api/built-in-special-elements.html#built-in-special-elements
* @param nodeName
* @returns
*/
detectElementType(nodeName: string) {
return super.detectElementType(nodeName, [
'component',
'slot',
// Built-in components
'Transition',
'TransitionGroup',
'KeepAlive',
'Teleport',
'Suspense',
// Special elements
'component',
'slot',
// Backward compatibility
/^[A-Z]/,
]);
Expand Down

0 comments on commit 8757d62

Please sign in to comment.