Skip to content

Commit f4f9263

Browse files
authored
Merge pull request #61 from ony3000/fix-prettier-3.7
Support Prettier v3.7
2 parents 4d2af43 + f76e600 commit f4f9263

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

src/core-parts/finder.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -514,14 +514,17 @@ export function findTargetBraceNodesForHtml(ast: AST, options: ResolvedOptions):
514514
function recursion(
515515
node: unknown,
516516
// biome-ignore lint/correctness/noUnusedFunctionParameters: Required for recursive calls.
517-
parentNode?: { type?: unknown },
517+
parentNode?: { kind: string; type?: undefined } | { kind?: undefined; type: string },
518518
): void {
519-
if (!isTypeof(node, z.object({ type: z.string() }))) {
519+
if (
520+
!isTypeof(node, z.object({ kind: z.string() })) &&
521+
!isTypeof(node, z.object({ type: z.string() }))
522+
) {
520523
return;
521524
}
522525

523526
Object.entries(node).forEach(([key, value]) => {
524-
if (key === 'type') {
527+
if (key === 'kind' || key === 'type') {
525528
return;
526529
}
527530

@@ -553,16 +556,18 @@ export function findTargetBraceNodesForHtml(ast: AST, options: ResolvedOptions):
553556
return;
554557
}
555558

559+
const nodeType = isTypeof(node, z.object({ kind: z.string() })) ? node.kind : node.type;
560+
556561
const [currentNodeRangeStart, currentNodeRangeEnd] = [
557562
node.sourceSpan.start.offset,
558563
node.sourceSpan.end.offset,
559564
];
560565
const currentASTNode: ASTNode = {
561-
type: node.type,
566+
type: nodeType,
562567
range: [currentNodeRangeStart, currentNodeRangeEnd],
563568
};
564569

565-
switch (node.type) {
570+
switch (nodeType) {
566571
case 'angularControlFlowBlock': {
567572
nonCommentNodes.push(currentASTNode);
568573

@@ -746,13 +751,19 @@ export function findTargetBraceNodesForVue(ast: AST, options: ResolvedOptions):
746751
*/
747752
const braceNodes: BraceNode[] = [];
748753

749-
function recursion(node: unknown, parentNode?: { type?: unknown }): void {
750-
if (!isTypeof(node, z.object({ type: z.string() }))) {
754+
function recursion(
755+
node: unknown,
756+
parentNode?: { kind: string; type?: undefined } | { kind?: undefined; type: string },
757+
): void {
758+
if (
759+
!isTypeof(node, z.object({ kind: z.string() })) &&
760+
!isTypeof(node, z.object({ type: z.string() }))
761+
) {
751762
return;
752763
}
753764

754765
Object.entries(node).forEach(([key, value]) => {
755-
if (key === 'type') {
766+
if (key === 'kind' || key === 'type') {
756767
return;
757768
}
758769

@@ -784,16 +795,19 @@ export function findTargetBraceNodesForVue(ast: AST, options: ResolvedOptions):
784795
return;
785796
}
786797

798+
const nodeType = isTypeof(node, z.object({ kind: z.string() })) ? node.kind : node.type;
799+
const parentNodeType = parentNode?.kind ?? parentNode?.type;
800+
787801
const [currentNodeRangeStart, currentNodeRangeEnd] = [
788802
node.sourceSpan.start.offset,
789803
node.sourceSpan.end.offset,
790804
];
791805
const currentASTNode: ASTNode = {
792-
type: node.type,
806+
type: nodeType,
793807
range: [currentNodeRangeStart, currentNodeRangeEnd],
794808
};
795809

796-
switch (node.type) {
810+
switch (nodeType) {
797811
case 'attribute': {
798812
nonCommentNodes.push(currentASTNode);
799813

@@ -811,7 +825,7 @@ export function findTargetBraceNodesForVue(ast: AST, options: ResolvedOptions):
811825
}),
812826
}),
813827
) &&
814-
parentNode.type === 'element' &&
828+
parentNodeType === 'element' &&
815829
isTypeof(
816830
node,
817831
z.object({

src/parsers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ async function advancedParse(
1414
defaultParser: Parser,
1515
options: ResolvedOptions,
1616
): Promise<AST> {
17-
const preprocessedText = defaultParser.preprocess
17+
const preprocessedText = await (defaultParser.preprocess
1818
? defaultParser.preprocess(text, options)
19-
: text;
19+
: text);
2020
let ast = await defaultParser.parse(preprocessedText, options);
2121

2222
if (parserName === 'svelte') {

0 commit comments

Comments
 (0)