diff --git a/src/parser/index.ts b/src/parser/index.ts index 01f33526..084b9002 100644 --- a/src/parser/index.ts +++ b/src/parser/index.ts @@ -39,6 +39,7 @@ import { type StyleContextUnknownLang, styleNodeLoc, styleNodeRange, + styleSelectorNodeLoc, } from "./style-context.js"; import { getGlobalsForSvelte, getGlobalsForSvelteScript } from "./globals.js"; import type { NormalizedParserOptions } from "./parser-options.js"; @@ -251,6 +252,7 @@ function parseAsSvelte( }, styleNodeLoc, styleNodeRange, + styleSelectorNodeLoc, svelteParseContext, }); resultScript.visitorKeys = Object.assign({}, KEYS, resultScript.visitorKeys); diff --git a/src/parser/style-context.ts b/src/parser/style-context.ts index a4f0ca90..fa161c03 100644 --- a/src/parser/style-context.ts +++ b/src/parser/style-context.ts @@ -141,6 +141,24 @@ export function styleNodeRange( ]; } +/** + * Extracts a node location (like that of any ESLint node) from a parsed svelte selector node. + */ +export function styleSelectorNodeLoc( + node: SelectorNode, +): Partial { + return { + start: + node.source?.start !== undefined + ? { + line: node.source.start.line, + column: node.source.start.column - 1, + } + : undefined, + end: node.source?.end, + }; +} + /** * Fixes PostCSS AST locations to be relative to the whole file instead of relative to the