Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve detection of string concatenation #288

Merged
merged 7 commits into from
Jun 11, 2024

Conversation

thecrypticace
Copy link
Contributor

Previously we'd check to see if a string literal was immediately nested inside a concat expression, for example:

export function Example() {
  return <div className={' flex ' + ' border ' + ' sm:hidden '} />
}

However, this breaks down when the strings being sorted are nested inside other expressions. For example, a ternary expression:

export function Example() {
  return <div class={'flex' + (standalone ? ' border ' : 'outline) + ' sm:hidden'}></div>
}

The way this works is if a string is nested inside a concat expression at any level then we'll do our best to keep the relevant whitespace. Obviously, due to runtime evaluation, we can't guarantee that all necessary whtiespace will be preserved, or that all unnecessary whitespace will be removed, but this improves the situation for the vast majority of cases.

Fixes #285

This depends on #287 and that PR must be merged first

@thecrypticace thecrypticace changed the title Improve concat expression detection Improve detection of string concatenation Jun 7, 2024
src/index.ts Outdated Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
Base automatically changed from feat/convert-to-typescript to main June 11, 2024 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Whitespace removal breaks on ternary conditions
2 participants