fix: rework directive name handling #9470
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.
Unfortunately #9462 introduced a bug (cc @paoloricciuti and @dummdidumm) — a directive like
use:a.b.c-d
needs to becomeget(a).b['c-d']
ifa
is state (mutatis mutandis if it's a prop).This was surfaced by TypeScript as soon as I rewrote
member_expression_id_to_literal
to return an expression instead of a string (mostly because I wanteda.b.c-d
to result ina.b['c-d']
rather thana['b']['c-d']
, becauseserialize_get_binding
will only accept anIdentifier
.I also got rid of the snapshot test. We should use these extremely sparingly — most of the time we don't care that much about the precise nature of the generated code, we only care about whether the generated code is valid. Snapshot tests are annoying because they frequently need to be updated for reasons unrelated to the test itself.
I'm not sure I agree with the decision in #9462 to do this at transform time rather than parse time. For the sake of things like sourcemap generation, it's good to preserve as much information about node start/end as possible, and it means we can apply this logic in a single place. I haven't done that yet though, we should discuss.
Finally, by working through this problem I think I've uncovered a separate bug — animate/transition directives 'lock on' to the directive value at component init time, even though it may change by the time the directive takes effect. It's less broken than it is on main, but it's still broken. Will create a follow-up issue/PR for that once this is merged.