From 37e360b94d42c1b64ab5f36fa9bb740e85e2a020 Mon Sep 17 00:00:00 2001 From: Hyeonjong Date: Fri, 4 Jul 2025 20:53:15 +0900 Subject: [PATCH 1/2] test: add tests that reproduce #104 --- .../__snapshots__/absolute.test.ts.snap | 25 +++++++++++++++++++ .../__snapshots__/relative.test.ts.snap | 25 +++++++++++++++++++ tests/babel/issue-104/absolute.test.ts | 12 +++++++++ tests/babel/issue-104/fixtures.ts | 23 +++++++++++++++++ tests/babel/issue-104/relative.test.ts | 12 +++++++++ .../__snapshots__/absolute.test.ts.snap | 25 +++++++++++++++++++ .../__snapshots__/relative.test.ts.snap | 25 +++++++++++++++++++ tests/typescript/issue-104/absolute.test.ts | 12 +++++++++ tests/typescript/issue-104/fixtures.ts | 23 +++++++++++++++++ tests/typescript/issue-104/relative.test.ts | 12 +++++++++ 10 files changed, 194 insertions(+) create mode 100644 tests/babel/issue-104/__snapshots__/absolute.test.ts.snap create mode 100644 tests/babel/issue-104/__snapshots__/relative.test.ts.snap create mode 100644 tests/babel/issue-104/absolute.test.ts create mode 100644 tests/babel/issue-104/fixtures.ts create mode 100644 tests/babel/issue-104/relative.test.ts create mode 100644 tests/typescript/issue-104/__snapshots__/absolute.test.ts.snap create mode 100644 tests/typescript/issue-104/__snapshots__/relative.test.ts.snap create mode 100644 tests/typescript/issue-104/absolute.test.ts create mode 100644 tests/typescript/issue-104/fixtures.ts create mode 100644 tests/typescript/issue-104/relative.test.ts diff --git a/tests/babel/issue-104/__snapshots__/absolute.test.ts.snap b/tests/babel/issue-104/__snapshots__/absolute.test.ts.snap new file mode 100644 index 00000000..d98c13bd --- /dev/null +++ b/tests/babel/issue-104/__snapshots__/absolute.test.ts.snap @@ -0,0 +1,25 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`'(1) JSX Assignment' > expectation 1`] = ` +"//-----------------------------------------------------------------------------| printWidth=80 (in snapshot) +function Foo() { + let elem = ( +
+ content +
+ ); + elem = ( +
+ content +
+ ); + return elem; +} +" +`; diff --git a/tests/babel/issue-104/__snapshots__/relative.test.ts.snap b/tests/babel/issue-104/__snapshots__/relative.test.ts.snap new file mode 100644 index 00000000..364ca4c2 --- /dev/null +++ b/tests/babel/issue-104/__snapshots__/relative.test.ts.snap @@ -0,0 +1,25 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`'(1) JSX Assignment' > expectation 1`] = ` +"//-----------------------------------------------------------------------------| printWidth=80 (in snapshot) +function Foo() { + let elem = ( +
+ content +
+ ); + elem = ( +
+ content +
+ ); + return elem; +} +" +`; diff --git a/tests/babel/issue-104/absolute.test.ts b/tests/babel/issue-104/absolute.test.ts new file mode 100644 index 00000000..12c96408 --- /dev/null +++ b/tests/babel/issue-104/absolute.test.ts @@ -0,0 +1,12 @@ +import { thisPlugin, testSnapshotEach } from '../../adaptor'; +import { baseOptions } from '../../settings'; +import { fixtures } from './fixtures'; + +const options = { + ...baseOptions, + plugins: [thisPlugin], + parser: 'babel', + endingPosition: 'absolute', +}; + +testSnapshotEach(fixtures, options); diff --git a/tests/babel/issue-104/fixtures.ts b/tests/babel/issue-104/fixtures.ts new file mode 100644 index 00000000..4c95577b --- /dev/null +++ b/tests/babel/issue-104/fixtures.ts @@ -0,0 +1,23 @@ +import type { Fixture } from '../../settings'; + +export const fixtures: Omit[] = [ + { + name: '(1) JSX Assignment', + input: ` +//-----------------------------------------------------------------------------| printWidth=80 (in snapshot) +function Foo() { + let elem = ( +
+ content +
+ ); + elem = ( +
+ content +
+ ); + return elem; +} +`, + }, +]; diff --git a/tests/babel/issue-104/relative.test.ts b/tests/babel/issue-104/relative.test.ts new file mode 100644 index 00000000..dc768c32 --- /dev/null +++ b/tests/babel/issue-104/relative.test.ts @@ -0,0 +1,12 @@ +import { thisPlugin, testSnapshotEach } from '../../adaptor'; +import { baseOptions } from '../../settings'; +import { fixtures } from './fixtures'; + +const options = { + ...baseOptions, + plugins: [thisPlugin], + parser: 'babel', + endingPosition: 'relative', +}; + +testSnapshotEach(fixtures, options); diff --git a/tests/typescript/issue-104/__snapshots__/absolute.test.ts.snap b/tests/typescript/issue-104/__snapshots__/absolute.test.ts.snap new file mode 100644 index 00000000..d98c13bd --- /dev/null +++ b/tests/typescript/issue-104/__snapshots__/absolute.test.ts.snap @@ -0,0 +1,25 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`'(1) JSX Assignment' > expectation 1`] = ` +"//-----------------------------------------------------------------------------| printWidth=80 (in snapshot) +function Foo() { + let elem = ( +
+ content +
+ ); + elem = ( +
+ content +
+ ); + return elem; +} +" +`; diff --git a/tests/typescript/issue-104/__snapshots__/relative.test.ts.snap b/tests/typescript/issue-104/__snapshots__/relative.test.ts.snap new file mode 100644 index 00000000..364ca4c2 --- /dev/null +++ b/tests/typescript/issue-104/__snapshots__/relative.test.ts.snap @@ -0,0 +1,25 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`'(1) JSX Assignment' > expectation 1`] = ` +"//-----------------------------------------------------------------------------| printWidth=80 (in snapshot) +function Foo() { + let elem = ( +
+ content +
+ ); + elem = ( +
+ content +
+ ); + return elem; +} +" +`; diff --git a/tests/typescript/issue-104/absolute.test.ts b/tests/typescript/issue-104/absolute.test.ts new file mode 100644 index 00000000..e90edbbd --- /dev/null +++ b/tests/typescript/issue-104/absolute.test.ts @@ -0,0 +1,12 @@ +import { thisPlugin, testSnapshotEach } from '../../adaptor'; +import { baseOptions } from '../../settings'; +import { fixtures } from './fixtures'; + +const options = { + ...baseOptions, + plugins: [thisPlugin], + parser: 'typescript', + endingPosition: 'absolute', +}; + +testSnapshotEach(fixtures, options); diff --git a/tests/typescript/issue-104/fixtures.ts b/tests/typescript/issue-104/fixtures.ts new file mode 100644 index 00000000..4c95577b --- /dev/null +++ b/tests/typescript/issue-104/fixtures.ts @@ -0,0 +1,23 @@ +import type { Fixture } from '../../settings'; + +export const fixtures: Omit[] = [ + { + name: '(1) JSX Assignment', + input: ` +//-----------------------------------------------------------------------------| printWidth=80 (in snapshot) +function Foo() { + let elem = ( +
+ content +
+ ); + elem = ( +
+ content +
+ ); + return elem; +} +`, + }, +]; diff --git a/tests/typescript/issue-104/relative.test.ts b/tests/typescript/issue-104/relative.test.ts new file mode 100644 index 00000000..751e3f45 --- /dev/null +++ b/tests/typescript/issue-104/relative.test.ts @@ -0,0 +1,12 @@ +import { thisPlugin, testSnapshotEach } from '../../adaptor'; +import { baseOptions } from '../../settings'; +import { fixtures } from './fixtures'; + +const options = { + ...baseOptions, + plugins: [thisPlugin], + parser: 'typescript', + endingPosition: 'relative', +}; + +testSnapshotEach(fixtures, options); From ef0f4aa191567bea5c911587e70f1eaf9b73bd72 Mon Sep 17 00:00:00 2001 From: Hyeonjong Date: Fri, 4 Jul 2025 20:58:33 +0900 Subject: [PATCH 2/2] fix: add property needed to recursively traverse jsx assignment --- src/core-parts/finder.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/core-parts/finder.ts b/src/core-parts/finder.ts index e3bea8be..f88ca9e3 100644 --- a/src/core-parts/finder.ts +++ b/src/core-parts/finder.ts @@ -148,6 +148,11 @@ export function findTargetClassNameNodes(ast: AST, options: ResolvedOptions): Cl recursiveProps = ['body']; break; } + case 'AssignmentExpression': + case 'LogicalExpression': { + recursiveProps = ['right']; + break; + } case 'BinaryExpression': { recursiveProps = ['left', 'right']; break; @@ -190,10 +195,6 @@ export function findTargetClassNameNodes(ast: AST, options: ResolvedOptions): Cl recursiveProps = ['attributes']; break; } - case 'LogicalExpression': { - recursiveProps = ['right']; - break; - } case 'ObjectExpression': { recursiveProps = ['properties']; break;