Skip to content

Commit

Permalink
feat(selector-parsing): added helper function to convert style select…
Browse files Browse the repository at this point in the history
…or locations to eslint locations
  • Loading branch information
marekdedic committed Dec 13, 2024
1 parent 4071eaa commit 8c2b801
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -251,6 +252,7 @@ function parseAsSvelte(
},
styleNodeLoc,
styleNodeRange,
styleSelectorNodeLoc,
svelteParseContext,
});
resultScript.visitorKeys = Object.assign({}, KEYS, resultScript.visitorKeys);
Expand Down
18 changes: 18 additions & 0 deletions src/parser/style-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SourceLocation> {
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 <style> element.
*/
Expand Down

0 comments on commit 8c2b801

Please sign in to comment.