Skip to content

Commit 47ea285

Browse files
committed
fix(parser): properly set initial inXML state based on root ns
1 parent ef97e8b commit 47ea285

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

packages/compiler-core/src/parser.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,10 @@ export function baseParse(input: string, options?: ParserOptions): RootNode {
978978
? ParseMode.SFC
979979
: ParseMode.BASE
980980

981+
tokenizer.inXML =
982+
currentOptions.ns === Namespaces.SVG ||
983+
currentOptions.ns === Namespaces.MATH_ML
984+
981985
const delimiters = options?.delimiters
982986
if (delimiters) {
983987
tokenizer.delimiterOpen = toCharCodes(delimiters[0])

packages/compiler-dom/__tests__/parse.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,5 +481,20 @@ describe('DOM parser', () => {
481481
expect(elementForieng.ns).toBe(Namespaces.SVG)
482482
expect(element.ns).toBe(Namespaces.HTML)
483483
})
484+
485+
test('correct XML handling with root ns', () => {
486+
// when root ns is an XML namespace, there should be no special content
487+
// treatment for <script>, <style>, <textarea> etc.
488+
const ast = parse('<script><g/><g/></script>', {
489+
...parserOptions,
490+
ns: Namespaces.SVG
491+
})
492+
const elementSvg = ast.children[0] as ElementNode
493+
// should parse as nodes instead of text
494+
expect(elementSvg.children).toMatchObject([
495+
{ type: NodeTypes.ELEMENT, tag: 'g' },
496+
{ type: NodeTypes.ELEMENT, tag: 'g' }
497+
])
498+
})
484499
})
485500
})

0 commit comments

Comments
 (0)