Extract special @("@")md:…
syntax in Razor files
#17427
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes an extraction issue in Razor files where
@@md:bg-red-500
can't always be extracted properly. We already convert@@md:bg-red-500
to@md:bg-red-500
but in certain situations Razor will emit the double@@
to the DOM.A workaround in Razor land would be to write
@("@")md:bg-red-500
instead. See: dotnet/aspnetcore#38595 But then we don't extract the@md:bg-red-500
properly anymore.This is where this PR comes in, essentially we will pre process the Razor contents and apply the following replacement internally:
Notice that the
)
looks like it's replaced with@
. This will have a small side effect later when we get to the testing part.But this way we properly see the
@md:bg-red-500
class during class extraction.Warning
There is technically a bug here because of the replacement with
@
, because if you now run thenpx @tailwindcss/upgrade@latest
tool, then we would replace)md:bg-red-500
if changes are required, not the@("@")md:bg-red-500
part. We can try to fix that in this PR but it seems unlikely that we will actually run into this issue realistically speaking. I think fixing the actual extraction here is much more important than the upgrade tooling that could fail if we ever have to migrate@md:…
to something else.Fixes: #17424
Test plan
Added a test to verify the fix
Existing tests pass
Verified this in the extractor tool, but it looks a tiny bit funky.
Typically we remove characters by replacing it with a space
. But this time, we replace it with some spaces and an
@
character that didn't exist at that specific position. If you look at the diff above, you will notice that)
was replaced with@
.That's why in the extractor tool it is highlighted that it could extract it, but it's just funny looking because it highlights
)md:bg-red-500