Skip to content

Commit 3441f4a

Browse files
authored
Merge pull request #124 from ony3000/fix-svelte
Support formatting even when empty script tags are included, and independently adjusts line positions of nodes located after script tag
2 parents c436414 + ecafde0 commit 3441f4a

File tree

6 files changed

+3119
-3
lines changed

6 files changed

+3119
-3
lines changed

src/core-parts/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export function refineSvelteAst(preprocessedText: string, ast: AST) {
7777
}
7878

7979
const scriptTag = preprocessedText.slice(ast.instance.start, ast.instance.end);
80-
const matchResult = scriptTag.match(/ prettier:content="([^"]+)"/);
80+
const matchResult = scriptTag.match(/ prettier:content="([^"]*)"/);
8181

8282
if (matchResult === null) {
8383
return ast;
@@ -137,7 +137,10 @@ export function refineSvelteAst(preprocessedText: string, ast: AST) {
137137
}),
138138
)
139139
) {
140-
node.loc.start.line += restoreLineOffset;
140+
node.loc.start = {
141+
...node.loc.start,
142+
line: node.loc.start.line + restoreLineOffset,
143+
};
141144
}
142145
}
143146
if (ast.instance.end <= node.end) {
@@ -155,7 +158,10 @@ export function refineSvelteAst(preprocessedText: string, ast: AST) {
155158
}),
156159
)
157160
) {
158-
node.loc.end.line += restoreLineOffset;
161+
node.loc.end = {
162+
...node.loc.end,
163+
line: node.loc.end.line + restoreLineOffset,
164+
};
159165
}
160166
}
161167
}

0 commit comments

Comments
 (0)