@@ -52,6 +52,21 @@ function isLang(
52
52
return attribute . directive === false && attribute . key . name === "lang"
53
53
}
54
54
55
+ /**
56
+ * Get the `lang` attribute value from a given element.
57
+ * @param element The element to get.
58
+ * @param defaultLang The default value of the `lang` attribute.
59
+ * @returns The `lang` attribute value.
60
+ */
61
+ function getLang (
62
+ element : AST . VElement | undefined ,
63
+ defaultLang : string ,
64
+ ) : string {
65
+ const langAttr = element && element . startTag . attributes . find ( isLang )
66
+ const lang = langAttr && langAttr . value && langAttr . value . value
67
+ return lang || defaultLang
68
+ }
69
+
55
70
/**
56
71
* Parse the given source code.
57
72
* @param code The source code to parse.
@@ -86,27 +101,23 @@ export function parseForESLint(
86
101
)
87
102
const script = rootAST . children . find ( isScriptElement )
88
103
const template = rootAST . children . find ( isTemplateElement )
89
- const templateLangAttr =
90
- template && template . startTag . attributes . find ( isLang )
91
- const templateLang =
92
- ( templateLangAttr &&
93
- templateLangAttr . value &&
94
- templateLangAttr . value . value ) ||
95
- "html"
104
+ const templateLang = getLang ( template , "html" )
96
105
const concreteInfo : AST . HasConcreteInfo = {
97
106
tokens : rootAST . tokens ,
98
107
comments : rootAST . comments ,
99
108
errors : rootAST . errors ,
100
109
}
110
+ const templateBody =
111
+ template != null && templateLang === "html"
112
+ ? Object . assign ( template , concreteInfo )
113
+ : undefined
101
114
102
115
result =
103
116
script != null
104
117
? parseScriptElement ( script , locationCalcurator , options )
105
118
: parseScript ( "" , options )
106
- result . ast . templateBody =
107
- template != null && templateLang === "html"
108
- ? Object . assign ( template , concreteInfo )
109
- : undefined
119
+
120
+ result . ast . templateBody = templateBody
110
121
}
111
122
112
123
result . services = Object . assign (
0 commit comments