Skip to content

Commit 385e9ec

Browse files
committed
feat(selector-parsing): added helper function to convert style selector locations to eslint locations
1 parent d9c6c3c commit 385e9ec

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/parser/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
type StyleContextUnknownLang,
4040
styleNodeLoc,
4141
styleNodeRange,
42+
styleSelectorNodeLoc,
4243
} from "./style-context.js";
4344
import { getGlobalsForSvelte, getGlobalsForSvelteScript } from "./globals.js";
4445
import type { NormalizedParserOptions } from "./parser-options.js";
@@ -251,6 +252,7 @@ function parseAsSvelte(
251252
},
252253
styleNodeLoc,
253254
styleNodeRange,
255+
styleSelectorNodeLoc,
254256
svelteParseContext,
255257
});
256258
resultScript.visitorKeys = Object.assign({}, KEYS, resultScript.visitorKeys);

src/parser/style-context.ts

+18
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,24 @@ export function styleNodeRange(
141141
];
142142
}
143143

144+
/**
145+
* Extracts a node location (like that of any ESLint node) from a parsed svelte selector node.
146+
*/
147+
export function styleSelectorNodeLoc(
148+
node: SelectorNode,
149+
): Partial<SourceLocation> {
150+
return {
151+
start:
152+
node.source?.start !== undefined
153+
? {
154+
line: node.source.start.line,
155+
column: node.source.start.column - 1,
156+
}
157+
: undefined,
158+
end: node.source?.end,
159+
};
160+
}
161+
144162
/**
145163
* Fixes PostCSS AST locations to be relative to the whole file instead of relative to the <style> element.
146164
*/

0 commit comments

Comments
 (0)