feat: simplify AST selector to work with compiled code #16
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.
Changes our AST selectors to only look for the
defaultMessage
property, and then checks if there is a sibling propertyid
with a matching string in the passed translation dictionary.This loosens how specific we are being in our selector but allows us to target a more robust set of compiled code (which is necessary to support transforming nextjs compiled code).
Because we still require an
id
property that has a string match in our passed-in string dictionary and adefaultMessage
as a part of the same object, this change feels relatively safe (in the scenario where we have this object in our compiled code it's highly likely this is actually a translateable string that we want to swap).It's important for the translated strings passed to the plugin to be in the format that we need them to end up as in the code, so if we are expecting to inline AST then we should pass in translations that have already been converted to AST.