From 43816a25c37d90dc0f4c2eb899ea025fd3055a56 Mon Sep 17 00:00:00 2001 From: Maruthan G Date: Sat, 11 Apr 2026 14:18:33 +0530 Subject: [PATCH] fix: resolve #174 - fix regex for hyphenated tag names in HTML scanner --- src/parser/htmlScanner.ts | 2 +- src/test/scanner.test.ts | 45 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/parser/htmlScanner.ts b/src/parser/htmlScanner.ts index 01750bd..941c570 100644 --- a/src/parser/htmlScanner.ts +++ b/src/parser/htmlScanner.ts @@ -172,7 +172,7 @@ export function createScanner(input: string, initialOffset = 0, initialState: Sc let lastTypeValue: string | undefined; function nextElementName(): string { - return stream.advanceIfRegExp(/^[_:\w][_:\w-.\d]*/).toLowerCase(); + return stream.advanceIfRegExp(/^[_:\w][_:\w.\d-]*/).toLowerCase(); } function nextAttributeName(): string { diff --git a/src/test/scanner.test.ts b/src/test/scanner.test.ts index 93b2558..0928a12 100644 --- a/src/test/scanner.test.ts +++ b/src/test/scanner.test.ts @@ -831,4 +831,49 @@ suite('HTML Scanner', () => { }]); }); + test('Tag with Hyphenated Name (Vue custom element)', () => { + assertTokens([{ + input: 'content', + tokens: [ + { offset: 0, type: TokenType.StartTagOpen }, + { offset: 1, type: TokenType.StartTag, content: 's-c-feature' }, + { offset: 12, type: TokenType.StartTagClose }, + { offset: 13, type: TokenType.Content }, + { offset: 20, type: TokenType.EndTagOpen }, + { offset: 22, type: TokenType.EndTag, content: 's-c-feature' }, + { offset: 33, type: TokenType.EndTagClose } + ] + } + ]); + }); + + test('Self-closing Tag with Hyphenated Name', () => { + assertTokens([{ + input: '', + tokens: [ + { offset: 0, type: TokenType.StartTagOpen }, + { offset: 1, type: TokenType.StartTag, content: 'my-component' }, + { offset: 13, type: TokenType.Whitespace }, + { offset: 14, type: TokenType.StartTagSelfClose } + ] + } + ]); + }); + + test('Tag with Hyphenated Name and Attributes', () => { + assertTokens([{ + input: '', + tokens: [ + { offset: 0, type: TokenType.StartTagOpen }, + { offset: 1, type: TokenType.StartTag, content: 'el-button' }, + { offset: 10, type: TokenType.Whitespace }, + { offset: 11, type: TokenType.AttributeName }, + { offset: 15, type: TokenType.DelimiterAssign }, + { offset: 16, type: TokenType.AttributeValue }, + { offset: 25, type: TokenType.StartTagClose } + ] + } + ]); + }); + }); \ No newline at end of file