Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"lint": "biome lint --max-diagnostics=none src/ tests/",
"preview": "pnpm run build:plain && npm version prerelease --preid=alpha --git-tag-version=false && npm pack",
"preview:minor": "pnpm run build:plain && npm version preminor --preid=alpha --git-tag-version=false && npm pack",
"test": "vitest run --passWithNoTests"
"test": "vitest run --passWithNoTests",
"snapshot": "vitest -u"
},
"dependencies": {
"zod": "3.22.4"
Expand All @@ -39,7 +40,7 @@
"@trivago/prettier-plugin-sort-imports": "4.2.1",
"@types/node": "20.17.46",
"esbuild": "0.25.0",
"prettier": "3.1.0",
"prettier": "3.7.3",
"prettier-plugin-astro": "0.11.0",
"prettier-plugin-svelte": "3.0.0",
"rimraf": "5.0.1",
Expand Down
24 changes: 12 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 45 additions & 18 deletions src/core-parts/finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1499,14 +1499,23 @@ export function findTargetClassNameNodesForHtml(
*/
const classNameNodes: ClassNameNode[] = [];

function recursion(node: unknown, parentNode?: { type?: unknown }): void {
if (!isTypeof(node, z.object({ type: z.string() }))) {
function recursion(
node: unknown,
parentNode?: { kind: string; type?: undefined } | { kind?: undefined; type: string },
): void {
if (
!isTypeof(node, z.object({ kind: z.string() })) &&
!isTypeof(node, z.object({ type: z.string() }))
) {
return;
}

const nodeType = isTypeof(node, z.object({ kind: z.string() })) ? node.kind : node.type;
const parentNodeType = parentNode?.kind ?? parentNode?.type;

let recursiveProps: string[] = [];

switch (node.type) {
switch (nodeType) {
case 'element': {
recursiveProps = ['attrs', 'children'];
break;
Expand Down Expand Up @@ -1558,11 +1567,11 @@ export function findTargetClassNameNodesForHtml(
node.sourceSpan.end.offset,
];
const currentASTNode: ASTNode = {
type: node.type,
type: nodeType,
range: [currentNodeRangeStart, currentNodeRangeEnd],
};

switch (node.type) {
switch (nodeType) {
case 'attribute': {
nonCommentNodes.push(currentASTNode);

Expand All @@ -1578,7 +1587,7 @@ export function findTargetClassNameNodesForHtml(
name: z.string(),
}),
) &&
parentNode.type === 'element' &&
parentNodeType === 'element' &&
isTypeof(
node,
z.object({
Expand Down Expand Up @@ -1779,14 +1788,23 @@ export function findTargetClassNameNodesForVue(
*/
const classNameNodes: ClassNameNode[] = [];

function recursion(node: unknown, parentNode?: { type?: unknown }): void {
if (!isTypeof(node, z.object({ type: z.string() }))) {
function recursion(
node: unknown,
parentNode?: { kind: string; type?: undefined } | { kind?: undefined; type: string },
): void {
if (
!isTypeof(node, z.object({ kind: z.string() })) &&
!isTypeof(node, z.object({ type: z.string() }))
) {
return;
}

const nodeType = isTypeof(node, z.object({ kind: z.string() })) ? node.kind : node.type;
const parentNodeType = parentNode?.kind ?? parentNode?.type;

let recursiveProps: string[] = [];

switch (node.type) {
switch (nodeType) {
case 'element': {
recursiveProps = ['attrs', 'children'];
break;
Expand Down Expand Up @@ -1838,11 +1856,11 @@ export function findTargetClassNameNodesForVue(
node.sourceSpan.end.offset,
];
const currentASTNode: ASTNode = {
type: node.type,
type: nodeType,
range: [currentNodeRangeStart, currentNodeRangeEnd],
};

switch (node.type) {
switch (nodeType) {
case 'attribute': {
nonCommentNodes.push(currentASTNode);

Expand All @@ -1860,7 +1878,7 @@ export function findTargetClassNameNodesForVue(
name: z.string(),
}),
) &&
parentNode.type === 'element' &&
parentNodeType === 'element' &&
isTypeof(
node,
z.object({
Expand Down Expand Up @@ -2074,14 +2092,23 @@ export function findTargetClassNameNodesForAngular(
*/
const classNameNodes: ClassNameNode[] = [];

function recursion(node: unknown, parentNode?: { type?: unknown }): void {
if (!isTypeof(node, z.object({ type: z.string() }))) {
function recursion(
node: unknown,
parentNode?: { kind: string; type?: undefined } | { kind?: undefined; type: string },
): void {
if (
!isTypeof(node, z.object({ kind: z.string() })) &&
!isTypeof(node, z.object({ type: z.string() }))
) {
return;
}

const nodeType = isTypeof(node, z.object({ kind: z.string() })) ? node.kind : node.type;
const parentNodeType = parentNode?.kind ?? parentNode?.type;

let recursiveProps: string[] = [];

switch (node.type) {
switch (nodeType) {
case 'angularControlFlowBlock':
case 'root': {
recursiveProps = ['children'];
Expand Down Expand Up @@ -2134,11 +2161,11 @@ export function findTargetClassNameNodesForAngular(
node.sourceSpan.end.offset,
];
const currentASTNode: ASTNode = {
type: node.type,
type: nodeType,
range: [currentNodeRangeStart, currentNodeRangeEnd],
};

switch (node.type) {
switch (nodeType) {
case 'attribute': {
nonCommentNodes.push(currentASTNode);

Expand All @@ -2156,7 +2183,7 @@ export function findTargetClassNameNodesForAngular(
name: z.string(),
}),
) &&
parentNode.type === 'element' &&
parentNodeType === 'element' &&
isTypeof(
node,
z.object({
Expand Down
4 changes: 2 additions & 2 deletions src/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ async function advancedParse(
defaultParser: Parser,
options: ResolvedOptions,
): Promise<AST> {
const preprocessedText = defaultParser.preprocess
const preprocessedText = await (defaultParser.preprocess
? defaultParser.preprocess(text, options)
: text;
: text);
let ast = await defaultParser.parse(preprocessedText, options);

if (parserName === 'svelte') {
Expand Down
24 changes: 12 additions & 12 deletions tests/angular/string-literal-property/absolute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const fixtures: Fixture[] = [
<div
[class]="
classNames({
' lorem ipsum dolor sit amet ': true
' lorem ipsum dolor sit amet ': true,
})
"
>
Expand Down Expand Up @@ -80,7 +80,7 @@ const fixtures: Fixture[] = [
<div
[class]="
classNames({
'lorem ipsum dolor sit amet': true
'lorem ipsum dolor sit amet': true,
})
"
>
Expand All @@ -107,7 +107,7 @@ const fixtures: Fixture[] = [
[class]="
classNames({
'lorem ipsum dolor sit amet consectetur adipiscing
elit proin': true
elit proin': true,
})
"
>
Expand All @@ -134,7 +134,7 @@ const fixtures: Fixture[] = [
[class]="
classNames({
' lorem ipsum dolor sit amet consectetur
adipiscing elit proin ': true
adipiscing elit proin ': true,
})
"
>
Expand Down Expand Up @@ -166,7 +166,7 @@ const fixtures: Fixture[] = [
[class]="
classNames({
'lorem ipsum dolor sit amet consectetur adipiscing
elit proin': true
elit proin': true,
})
"
>
Expand Down Expand Up @@ -194,7 +194,7 @@ const fixtures: Fixture[] = [
classNames({
'lorem ipsum dolor sit amet consectetur adipiscing
elit proin ex massa hendrerit eu posuere eu
volutpat id neque pellentesque': true
volutpat id neque pellentesque': true,
})
"
>
Expand Down Expand Up @@ -222,7 +222,7 @@ const fixtures: Fixture[] = [
classNames({
' lorem ipsum dolor sit amet consectetur
adipiscing elit proin ex massa hendrerit eu
posuere eu volutpat id neque pellentesque ': true
posuere eu volutpat id neque pellentesque ': true,
})
"
>
Expand Down Expand Up @@ -255,7 +255,7 @@ const fixtures: Fixture[] = [
classNames({
'lorem ipsum dolor sit amet consectetur adipiscing
elit proin ex massa hendrerit eu posuere eu
volutpat id neque pellentesque': true
volutpat id neque pellentesque': true,
})
"
>
Expand All @@ -282,7 +282,7 @@ const fixtures: Fixture[] = [
[class]="
classNames({
'lorem ipsum dolor sit amet consectetur adipiscing
elit proin ex massa hendrerit eu posuere': true
elit proin ex massa hendrerit eu posuere': true,
})
"
>
Expand All @@ -309,7 +309,7 @@ const fixtures: Fixture[] = [
[className]="
classNames({
'lorem ipsum dolor sit amet consectetur adipiscing
elit proin ex massa hendrerit eu posuere': true
elit proin ex massa hendrerit eu posuere': true,
})
"
>
Expand All @@ -336,7 +336,7 @@ const fixtures: Fixture[] = [
[attr.class]="
classNames({
'lorem ipsum dolor sit amet consectetur adipiscing
elit proin ex massa hendrerit eu posuere': true
elit proin ex massa hendrerit eu posuere': true,
})
"
>
Expand All @@ -363,7 +363,7 @@ const fixtures: Fixture[] = [
[ngClass]="
classNames({
'lorem ipsum dolor sit amet consectetur adipiscing
elit proin ex massa hendrerit eu posuere': true
elit proin ex massa hendrerit eu posuere': true,
})
"
>
Expand Down
Loading