Skip to content

Commit a7ed9e2

Browse files
authored
Merge branch 'main' into let-type
2 parents b62b247 + a4d31f0 commit a7ed9e2

File tree

3 files changed

+75
-5
lines changed

3 files changed

+75
-5
lines changed

Diff for: .changeset/smart-turkeys-fold.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte-eslint-parser": patch
3+
---
4+
5+
fix: update postcss to 8.4.28

Diff for: tests/src/parser/style-context.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ describe("Check for AST.", () => {
4141

4242
function styleContextToJson(styleContext: StyleContext): string {
4343
return JSON.stringify(styleContext, nodeReplacer, 2);
44-
}
4544

46-
function nodeReplacer(key: string, value: any): any {
47-
if (key === "file" || key === "url") {
48-
return undefined;
45+
function nodeReplacer(key: string, value: any): any {
46+
if (key === "file" || key === "url") {
47+
return undefined;
48+
}
49+
return value;
4950
}
50-
return value;
5151
}

Diff for: tools/update-fixtures.ts

+65
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,22 @@ import {
1414
import type ts from "typescript";
1515
import type ESTree from "estree";
1616
import * as tsESLintParser from "@typescript-eslint/parser";
17+
import type { SourceLocation } from "../src/ast";
1718

1819
const ERROR_FIXTURE_ROOT = path.resolve(
1920
__dirname,
2021
"../tests/fixtures/parser/error",
2122
);
2223

24+
const STYLE_CONTEXT_FIXTURE_ROOT = path.resolve(
25+
__dirname,
26+
"../tests/fixtures/parser/style-context",
27+
);
28+
const STYLE_LOCATION_FIXTURE_ROOT = path.resolve(
29+
__dirname,
30+
"../tests/fixtures/parser/style-location-converter",
31+
);
32+
2333
const RULES = [
2434
"no-unused-labels",
2535
"no-extra-label",
@@ -128,6 +138,61 @@ for (const { input, inputFileName, outputFileName, config } of listupFixtures(
128138
}
129139
}
130140

141+
for (const { input, inputFileName, outputFileName, config } of listupFixtures(
142+
STYLE_CONTEXT_FIXTURE_ROOT,
143+
)) {
144+
const result = parse(input, inputFileName, config);
145+
const styleContext = result.services.getStyleContext();
146+
fs.writeFileSync(
147+
outputFileName,
148+
`${styleContextToJson(styleContext)}\n`,
149+
"utf8",
150+
);
151+
}
152+
153+
/** StyleContext to JSON string */
154+
function styleContextToJson(styleContext: parser.StyleContext): string {
155+
return JSON.stringify(styleContext, nodeReplacer, 2);
156+
157+
/** JSON string replacer for StyleContext */
158+
function nodeReplacer(key: string, value: any): any {
159+
if (key === "file" || key === "url") {
160+
return undefined;
161+
}
162+
return value;
163+
}
164+
}
165+
166+
for (const { input, inputFileName, outputFileName, config } of listupFixtures(
167+
STYLE_LOCATION_FIXTURE_ROOT,
168+
)) {
169+
const services = parse(input, inputFileName, config).services;
170+
const styleContext = services.getStyleContext();
171+
if (styleContext.status !== "success") {
172+
continue;
173+
}
174+
const locations: [
175+
Partial<SourceLocation>,
176+
[number | undefined, number | undefined],
177+
][] = [
178+
[
179+
services.styleNodeLoc(styleContext.sourceAst),
180+
services.styleNodeRange(styleContext.sourceAst),
181+
],
182+
];
183+
styleContext.sourceAst.walk((node) => {
184+
locations.push([
185+
services.styleNodeLoc(node),
186+
services.styleNodeRange(node),
187+
]);
188+
});
189+
fs.writeFileSync(
190+
outputFileName,
191+
`${JSON.stringify(locations, undefined, 2)}\n`,
192+
"utf8",
193+
);
194+
}
195+
131196
// eslint-disable-next-line require-jsdoc -- X
132197
function createLinter() {
133198
const linter = new Linter();

0 commit comments

Comments
 (0)