Skip to content

Commit

Permalink
fix: excludes tagged templates starting with 'css' from line wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
ony3000 committed Sep 21, 2024
1 parent 5f8f107 commit 1d4091a
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/packages/core-parts/finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,31 @@ export function findTargetClassNameNodes(ast: any, options: ResolvedOptions): Cl
case 'TaggedTemplateExpression': {
nonCommentNodes.push(currentASTNode);

if (
isTypeof(
node,
z.object({
tag: z.object({
type: z.literal('Identifier'),
name: z.string(),
range: z.custom<NodeRange>((value) =>
isTypeof(value, z.tuple([z.number(), z.number()])),
),
}),
}),
) &&
node.tag.name === 'css'
) {
const [tagRangeStart, tagRangeEnd] = node.tag.range;

// Note: In fact, the tag name is not `prettierIgnoreNode`, but it is considered a kind of ignore comment to ignore the template literal that immediately follows it.
prettierIgnoreNodes.push({
type: node.tag.type,
range: [tagRangeStart, tagRangeEnd - 1],
});
break;
}

if (
(isTypeof(
node,
Expand Down Expand Up @@ -2610,6 +2635,31 @@ export function findTargetClassNameNodesForSvelte(
case 'TaggedTemplateExpression': {
nonCommentNodes.push(currentASTNode);

if (
isTypeof(
node,
z.object({
tag: z.object({
type: z.literal('Identifier'),
name: z.string(),
start: z.number(),
end: z.number(),
}),
}),
) &&
node.tag.name === 'css'
) {
const tagRangeStart = node.tag.start;
const tagRangeEnd = node.tag.end;

// Note: In fact, the tag name is not `prettierIgnoreNode`, but it is considered a kind of ignore comment to ignore the template literal that immediately follows it.
prettierIgnoreNodes.push({
type: node.tag.type,
range: [tagRangeStart, tagRangeEnd - 1],
});
break;
}

if (
(isTypeof(
node,
Expand Down

0 comments on commit 1d4091a

Please sign in to comment.