@@ -41,6 +41,15 @@ function isScriptElement(node: AST.VNode): node is AST.VElement {
4141 return node . type === "VElement" && node . name === "script"
4242}
4343
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+
4453/**
4554 * Parse the given source code.
4655 * @param code The source code to parse.
@@ -66,6 +75,8 @@ export function parseForESLint(code: string, options: any): AST.ESLintExtendedPr
6675 const locationCalcurator = new LocationCalculator ( tokenizer . gaps , tokenizer . lineTerminators )
6776 const script = rootAST . children . find ( isScriptElement ) as AST . VElement | undefined // https://github.com/Microsoft/TypeScript/issues/7657
6877 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"
6980 const concreteInfo : AST . HasConcreteInfo = {
7081 tokens : rootAST . tokens ,
7182 comments : rootAST . comments ,
@@ -75,7 +86,7 @@ export function parseForESLint(code: string, options: any): AST.ESLintExtendedPr
7586 result = ( script != null )
7687 ? parseScriptElement ( script , locationCalcurator , options )
7788 : parseScript ( "" , options )
78- result . ast . templateBody = ( template != null )
89+ result . ast . templateBody = ( template != null && templateLang === "html" )
7990 ? Object . assign ( template , concreteInfo )
8091 : undefined
8192 }
0 commit comments