@@ -303,10 +303,12 @@ export class Parser {
303
303
304
304
/**
305
305
* Detect the namespace of the new element.
306
- * @param name The value of a HTMLTagOpen token .
306
+ * @param token The StartTag token to detect .
307
307
* @returns The namespace of the new element.
308
308
*/
309
- private detectNamespace ( name : string ) : Namespace {
309
+ //eslint-disable-next-line complexity, require-jsdoc
310
+ private detectNamespace ( token : StartTag ) : Namespace {
311
+ const name = token . name
310
312
let ns = this . namespace
311
313
312
314
if ( ns === NS . MathML || ns === NS . SVG ) {
@@ -339,6 +341,15 @@ export class Parser {
339
341
}
340
342
}
341
343
344
+ if ( name === "template" ) {
345
+ const xmlns = token . attributes . find ( a => a . key . name === "xmlns" )
346
+ const value = xmlns && xmlns . value && xmlns . value . value
347
+
348
+ if ( value === NS . HTML || value === NS . MathML || value === NS . SVG ) {
349
+ return value
350
+ }
351
+ }
352
+
342
353
return ns
343
354
}
344
355
@@ -410,22 +421,7 @@ export class Parser {
410
421
this . closeCurrentElementIfNecessary ( token . name )
411
422
412
423
const parent = this . currentNode
413
- let namespace = this . detectNamespace ( token . name )
414
- if ( token . name === "template" ) {
415
- for ( const attribute of token . attributes ) {
416
- if ( attribute . key . name !== "xmlns" ) {
417
- continue
418
- }
419
- const value = attribute . value && attribute . value . value
420
- if (
421
- value === NS . HTML ||
422
- value === NS . MathML ||
423
- value === NS . SVG
424
- ) {
425
- namespace = value
426
- }
427
- }
428
- }
424
+ const namespace = this . detectNamespace ( token )
429
425
const element : VElement = {
430
426
type : "VElement" ,
431
427
range : [ token . range [ 0 ] , token . range [ 1 ] ] ,
0 commit comments