Skip to content

Commit

Permalink
Only parsing styles on-demand (#358)
Browse files Browse the repository at this point in the history
* Only parsing styles on-demand

* Added a changeset for on-demand style parsing

---------

Co-authored-by: Yosuke Ota <[email protected]>
  • Loading branch information
marekdedic and ota-meshi authored Jun 19, 2023
1 parent 8b28d21 commit 438be64
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/yellow-cats-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte-eslint-parser": minor
---

only parsing styles on-demand
5 changes: 4 additions & 1 deletion src/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export function parseForESLint(
const styleElement = ast.body.find(
(b): b is SvelteStyleElement => b.type === "SvelteStyleElement"
);
const styleContext = parseStyleContext(styleElement, ctx);
let styleContext: StyleContext | null = null;

resultScript.ast = ast as any;
resultScript.services = Object.assign(resultScript.services || {}, {
Expand All @@ -198,6 +198,9 @@ export function parseForESLint(
return resultTemplate.svelteAst.html;
},
getStyleContext() {
if (styleContext === null) {
styleContext = parseStyleContext(styleElement, ctx);
}
return styleContext;
},
styleNodeLoc,
Expand Down

0 comments on commit 438be64

Please sign in to comment.