Fix false-positive migrations in addEventListener
and JavaScript variable names
#18718
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 2 false-positives when running the upgrade tool on a Tailwind CSS v3 project converting it to a Tailwind CSS v4 project.
The issue occurs around migrations with short simple names that have a meaning outside if Tailwind CSS, e.g.
blur
andoutline
.This PR fixes 2 such cases:
The
addEventListener
case:We do this by special casing the
addEventListener(
case and making sure the first argument toaddEventListener
is never migrated.A JavaScript variable with default value:
The bug is relatively subtle here, but it has actually nothing to do with
outline
itself, but rather the fact that some quote character came before and after it on the same line...One of our heuristics for determining if a migration on these small words is safe, is to ensure that the candidate is inside of a string. Since we didn't do any kind of quote balancing, we would consider the
outline
to be inside of a string, even though it is not.So to actually solve this, we do some form of quote balancing to ensure that it's not inside of a string in this case.
Additionally, this PR also introduces a small refactor to the
is-safe-migration.test.ts
file where we now use atest.each
to ensure that failing tests in the middle don't prevent the rest of the tests from running.Test plan
Fixes: #18675