here we analyse the typescript and parse the script:
|
const tsCtx = analyzeTypeScriptInSvelte(code, attrs, parserOptions, context); |
|
|
|
const result = parseScriptInSvelte(tsCtx.script, attrs, parserOptions); |
this basically:
- parses the
script + render + rootScope in order to analyse it, and tries to avoid type checking by turning off projects in TSESLint
- parses the
script as the main AST, with type checking enabled
The first results in this code path:
|
const result = parseScriptWithoutAnalyzeScope( |
|
code.script + code.render + code.rootScope, |
|
attrs, |
|
withoutProjectParserOptions(parserOptions), |
|
) as unknown as TSESParseForESLintResult; |
The second results in this code path:
|
const result = parseScriptWithoutAnalyzeScope(code, attrs, options); |
|
result._virtualScriptCode = code; |
|
return result; |
This means we ultimately end up parsing the script twice, though the first one is parsing it as part of a slightly larger source.
The TSESLint parser basically parses and type checks the same code twice for every file because of this.
Suggestion 1
We could probably just parse the larger of the two: script + render + rootScope.
Whatever expects just the script further down the line would need to be updated to account for the fact that it will now get a larger AST (extra stuff on the end).
Suggestion 2
Alternatively, we could parse script and share it between these two calls. Then we'd have to update the analysis function to parse render + rootScope as its own separate AST.
But if there's any logic that depends on having the full AST (all 3 parts), this won't really work.
here we analyse the typescript and parse the script:
svelte-eslint-parser/src/parser/typescript/index.ts
Lines 22 to 24 in 5b30e5c
this basically:
script + render + rootScopein order to analyse it, and tries to avoid type checking by turning off projects in TSESLintscriptas the main AST, with type checking enabledThe first results in this code path:
svelte-eslint-parser/src/parser/typescript/analyze/index.ts
Lines 54 to 58 in 5b30e5c
The second results in this code path:
svelte-eslint-parser/src/parser/script.ts
Lines 87 to 89 in 5b30e5c
This means we ultimately end up parsing the
scripttwice, though the first one is parsing it as part of a slightly larger source.The TSESLint parser basically parses and type checks the same code twice for every file because of this.
Suggestion 1
We could probably just parse the larger of the two:
script + render + rootScope.Whatever expects just the
scriptfurther down the line would need to be updated to account for the fact that it will now get a larger AST (extra stuff on the end).Suggestion 2
Alternatively, we could parse
scriptand share it between these two calls. Then we'd have to update the analysis function to parserender + rootScopeas its own separate AST.But if there's any logic that depends on having the full AST (all 3 parts), this won't really work.