Skip to content

Commit 9d280d2

Browse files
committed
Exposing styleNodeLoc and styleNodeRange functions as part of the parser services
1 parent 3b7a64c commit 9d280d2

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/parser/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import {
2929
type StyleContextParseError,
3030
type StyleContextSuccess,
3131
type StyleContextUnknownLang,
32+
styleNodeLoc,
33+
styleNodeRange,
3234
} from "./style-context";
3335

3436
export {
@@ -198,6 +200,8 @@ export function parseForESLint(
198200
getStyleContext() {
199201
return styleContext;
200202
},
203+
styleNodeLoc,
204+
styleNodeRange,
201205
});
202206
resultScript.visitorKeys = Object.assign({}, KEYS, resultScript.visitorKeys);
203207

tests/src/parser/style-location-coverter.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ import type { Node } from "postcss";
55

66
import { parseForESLint } from "../../../src";
77
import type { SourceLocation } from "../../../src/ast";
8-
import {
9-
styleNodeLoc,
10-
styleNodeRange,
11-
} from "../../../src/parser/style-context";
128
import { generateParserOptions, listupFixtures } from "./test-utils";
139

1410
const STYLE_CONTEXT_FIXTURE_ROOT = path.resolve(
@@ -29,26 +25,29 @@ describe("Check for AST.", () => {
2925
meetRequirements,
3026
} of listupFixtures(STYLE_CONTEXT_FIXTURE_ROOT)) {
3127
describe(inputFileName, () => {
32-
let result: any;
28+
let services: any;
3329

3430
it("most to generate the expected style context.", () => {
35-
result = parse(input, inputFileName, config);
31+
services = parse(input, inputFileName, config).services;
3632
if (!meetRequirements("test")) {
3733
return;
3834
}
39-
const styleContext = result.services.getStyleContext();
35+
const styleContext = services.getStyleContext();
4036
assert.strictEqual(styleContext.status, "success");
4137
const locations: [
4238
Partial<SourceLocation>,
4339
[number | undefined, number | undefined]
4440
][] = [
4541
[
46-
styleNodeLoc(styleContext.sourceAst),
47-
styleNodeRange(styleContext.sourceAst),
42+
services.styleNodeLoc(styleContext.sourceAst),
43+
services.styleNodeRange(styleContext.sourceAst),
4844
],
4945
];
5046
styleContext.sourceAst.walk((node: Node) => {
51-
locations.push([styleNodeLoc(node), styleNodeRange(node)]);
47+
locations.push([
48+
services.styleNodeLoc(node),
49+
services.styleNodeRange(node),
50+
]);
5251
});
5352
const output = fs.readFileSync(outputFileName, "utf8");
5453
assert.strictEqual(

0 commit comments

Comments
 (0)