@@ -41,6 +41,15 @@ function isScriptElement(node: AST.VNode): node is AST.VElement {
41
41
return node . type === "VElement" && node . name === "script"
42
42
}
43
43
44
+ /**
45
+ * Check whether the attribute node is a `lang` attribute.
46
+ * @param attribute The attribute node to check.
47
+ * @returns `true` if the attribute node is a `lang` attribute.
48
+ */
49
+ function isLang ( attribute : AST . VAttribute | AST . VDirective ) : attribute is AST . VAttribute {
50
+ return attribute . directive === false && attribute . key . name === "lang"
51
+ }
52
+
44
53
/**
45
54
* Parse the given source code.
46
55
* @param code The source code to parse.
@@ -66,6 +75,8 @@ export function parseForESLint(code: string, options: any): AST.ESLintExtendedPr
66
75
const locationCalcurator = new LocationCalculator ( tokenizer . gaps , tokenizer . lineTerminators )
67
76
const script = rootAST . children . find ( isScriptElement ) as AST . VElement | undefined // https://github.com/Microsoft/TypeScript/issues/7657
68
77
const template = rootAST . children . find ( isTemplateElement ) as AST . VElement | undefined
78
+ const templateLangAttr = template && template . startTag . attributes . find ( isLang ) as AST . VAttribute | undefined
79
+ const templateLang = ( templateLangAttr && templateLangAttr . value && templateLangAttr . value . value ) || "html"
69
80
const concreteInfo : AST . HasConcreteInfo = {
70
81
tokens : rootAST . tokens ,
71
82
comments : rootAST . comments ,
@@ -75,7 +86,7 @@ export function parseForESLint(code: string, options: any): AST.ESLintExtendedPr
75
86
result = ( script != null )
76
87
? parseScriptElement ( script , locationCalcurator , options )
77
88
: parseScript ( "" , options )
78
- result . ast . templateBody = ( template != null )
89
+ result . ast . templateBody = ( template != null && templateLang === "html" )
79
90
? Object . assign ( template , concreteInfo )
80
91
: undefined
81
92
}
0 commit comments