1
1
'use strict' ;
2
2
3
- var CASE_SENSITIVE_TAG_NAMES = require ( './constants' ) . CASE_SENSITIVE_TAG_NAMES
4
- var CASE_SENSITIVE_TAG_NAMES_LOWERCASE = CASE_SENSITIVE_TAG_NAMES . map ( function ( tag ) {
5
- return tag . toLowerCase ( ) ;
6
- } ) ;
3
+ var CASE_SENSITIVE_TAG_NAMES = require ( './constants' ) . CASE_SENSITIVE_TAG_NAMES ;
4
+
5
+ var caseSensitiveTagNamesMap = { } ;
6
+ var tagName ;
7
+ for ( var i = 0 , len = CASE_SENSITIVE_TAG_NAMES . length ; i < len ; i ++ ) {
8
+ tagName = CASE_SENSITIVE_TAG_NAMES [ i ] ;
9
+ caseSensitiveTagNamesMap [ tagName . toLowerCase ( ) ] = tagName ;
10
+ }
11
+
12
+ /**
13
+ * Gets case-sensitive tag name.
14
+ *
15
+ * @param {String } tagName - The lowercase tag name.
16
+ * @return {String|undefined }
17
+ */
18
+ function getCaseSensitiveTagName ( tagName ) {
19
+ return caseSensitiveTagNamesMap [ tagName ] ;
20
+ }
7
21
8
22
/**
9
23
* Format DOM attributes to an associative array.
@@ -25,20 +39,19 @@ function formatAttributes(attributes) {
25
39
}
26
40
27
41
/**
28
- * Correct the case of tag names. For case-sensitive SVG tags, return the proper
29
- * tag name; for all other tags, return the lowercased name.
42
+ * Corrects the tag name if it is case-sensitive ( SVG).
43
+ * Otherwise, returns the lowercase tag name (HTML) .
30
44
*
31
- * @param {String } tagName - The tag name to correct .
32
- * @return {String } - The corrected tag name.
45
+ * @param {String } tagName - The lowercase tag name.
46
+ * @return {String } - The formatted tag name.
33
47
*/
34
- function fixTagCase ( tagName ) {
35
- var correctedName = tagName . toLowerCase ( ) ;
36
- var caseSensitiveTagIndex = CASE_SENSITIVE_TAG_NAMES_LOWERCASE . indexOf ( correctedName ) ;
37
- // fix case if element is case-sensitive SVG
38
- if ( caseSensitiveTagIndex !== - 1 ) {
39
- correctedName = CASE_SENSITIVE_TAG_NAMES [ caseSensitiveTagIndex ] ;
48
+ function formatTagName ( tagName ) {
49
+ tagName = tagName . toLowerCase ( ) ;
50
+ var caseSensitiveTagName = getCaseSensitiveTagName ( tagName ) ;
51
+ if ( caseSensitiveTagName ) {
52
+ return caseSensitiveTagName ;
40
53
}
41
- return correctedName ;
54
+ return tagName ;
42
55
}
43
56
44
57
/**
@@ -75,8 +88,8 @@ function formatDOM(nodes, parentObj, directive) {
75
88
76
89
// set the node name if it's not "#text" or "#comment"
77
90
// e.g., "div"
78
- if ( node . nodeName . indexOf ( '#' ) !== 0 ) {
79
- nodeObj . name = fixTagCase ( node . nodeName ) ;
91
+ if ( node . nodeName [ 0 ] !== '#' ) {
92
+ nodeObj . name = formatTagName ( node . nodeName ) ;
80
93
// also, nodes of type "tag" have "attribs"
81
94
nodeObj . attribs = { } ; // default
82
95
if ( node . attributes && node . attributes . length ) {
0 commit comments