@@ -56,28 +56,30 @@ export function parseForESLint(code: string, options: any): AST.ESLintExtendedPr
5656 tokens : true ,
5757 } , options || { } )
5858
59+ let result : AST . ESLintExtendedProgram
5960 if ( ! isVueFile ( code , options ) ) {
60- return parseScript ( code , options )
61+ result = parseScript ( code , options )
6162 }
63+ else {
64+ const tokenizer = new HTMLTokenizer ( code )
65+ const rootAST = new HTMLParser ( tokenizer , options ) . parse ( )
66+ const locationCalcurator = new LocationCalculator ( tokenizer . gaps , tokenizer . lineTerminators )
67+ const script = rootAST . children . find ( isScriptElement ) as AST . VElement | undefined // https://github.com/Microsoft/TypeScript/issues/7657
68+ const template = rootAST . children . find ( isTemplateElement ) as AST . VElement | undefined
69+ const concreteInfo : AST . HasConcreteInfo = {
70+ tokens : rootAST . tokens ,
71+ comments : rootAST . comments ,
72+ errors : rootAST . errors ,
73+ }
6274
63- const tokenizer = new HTMLTokenizer ( code )
64- const rootAST = new HTMLParser ( tokenizer , options ) . parse ( )
65- const locationCalcurator = new LocationCalculator ( tokenizer . gaps , tokenizer . lineTerminators )
66- const script = rootAST . children . find ( isScriptElement ) as AST . VElement | undefined // https://github.com/Microsoft/TypeScript/issues/7657
67- const template = rootAST . children . find ( isTemplateElement ) as AST . VElement | undefined
68- const result = ( script != null )
69- ? parseScriptElement ( script , locationCalcurator , options )
70- : parseScript ( "" , options )
71- const concreteInfo : AST . HasConcreteInfo = {
72- tokens : rootAST . tokens ,
73- comments : rootAST . comments ,
74- errors : rootAST . errors ,
75+ result = ( script != null )
76+ ? parseScriptElement ( script , locationCalcurator , options )
77+ : parseScript ( "" , options )
78+ result . ast . templateBody = ( template != null )
79+ ? Object . assign ( template , concreteInfo )
80+ : undefined
7581 }
76- const templateBody = ( template != null )
77- ? Object . assign ( template , concreteInfo )
78- : undefined
7982
80- result . ast . templateBody = templateBody
8183 result . services = Object . assign ( result . services || { } , services . define ( result . ast ) )
8284
8385 return result
0 commit comments