-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix: avoid marking subtree as dynamic for inlined attributes #14269
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
3ce5ee7
fix: avoid marking subtree as dynamic for inlined attributes
paoloricciuti 509ca70
fix: i'm a silly goose 🪿
paoloricciuti 5770063
chore: refactor `is_inlinable_expression` to accept the attribute
paoloricciuti dec07f0
feat: inline dom expression too
paoloricciuti 72244cd
fix: special case literals with `"` in it and fix standalone case
paoloricciuti 63d96ca
chore: simpler check first
paoloricciuti d920a23
typo
Rich-Harris a8b38c0
add more stuff to snapshot test
Rich-Harris d52bfe7
simplify/speedup by doing the work once, during analysis
Rich-Harris 406a530
simplify
Rich-Harris 0e543de
simplify - no reason these cases should prevent inlining
Rich-Harris c445309
return template
Rich-Harris 0e35df7
name is incorrect
Rich-Harris ecfcb10
name is incorrect
Rich-Harris ee6f03e
fix escaping
Rich-Harris 76e3e8e
no longer necessary
Rich-Harris 61ec033
remove obsolete description
Rich-Harris 3e64dc5
better concatenation
Rich-Harris 8987391
fix test
Rich-Harris 2e13a2b
do the work at runtime
Rich-Harris cff8b1c
fix another thing
Rich-Harris 2ee6cd3
tidy
Rich-Harris b296137
tidy up
Rich-Harris fc91139
simplify
Rich-Harris 1a720ad
simplify
Rich-Harris eaa2df5
fix
Rich-Harris 6f77bd2
note to self
Rich-Harris ce63d39
another
Rich-Harris 7f0ca11
simplify
Rich-Harris 839e7e3
more accurate name
Rich-Harris ca3d6a6
simplify
Rich-Harris c5e3548
simplify
Rich-Harris 785f60d
explain what is happening
Rich-Harris 6f1d6be
tidy up
Rich-Harris 3acb74f
simplify
Rich-Harris 4b8c249
better inlining
Rich-Harris 5daef9b
update test
Rich-Harris 16ec011
colocate some code
Rich-Harris 056475f
better inlining
Rich-Harris 73d6384
use attribute metadata
Rich-Harris cf7c15c
Update packages/svelte/src/compiler/phases/2-analyze/visitors/Identif…
Rich-Harris 61b60ab
Apply suggestions from code review
Rich-Harris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'svelte': patch | ||
| --- | ||
|
|
||
| fix: avoid marking subtree as dynamic for inlined attributes | ||
Rich-Harris marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /** @import { AST, Binding } from '#compiler' */ | ||
| /** @import { Scope } from './scope' */ | ||
|
|
||
| /** | ||
| * Whether a variable can be referenced directly from template string. | ||
| * @param {Binding | undefined} binding | ||
| * @returns {boolean} | ||
| */ | ||
| function can_inline_variable(binding) { | ||
| return ( | ||
| !!binding && | ||
| // in a `<script module>` block | ||
| !binding.scope.parent && | ||
| // to prevent the need for escaping | ||
| binding.initial?.type === 'Literal' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @param {AST.Attribute} attribute | ||
| * @param {Scope} scope | ||
| */ | ||
| export function is_inlinable_expression(attribute, scope) { | ||
| if (attribute.value === true) return false; // not an expression | ||
| let nodes = Array.isArray(attribute.value) ? attribute.value : [attribute.value]; | ||
| let has_expression_tag = false; | ||
| for (let value of nodes) { | ||
| if (value.type === 'ExpressionTag') { | ||
| if (value.expression.type === 'Identifier') { | ||
benmccann marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const binding = scope.owner(value.expression.name)?.declarations.get(value.expression.name); | ||
| if (!can_inline_variable(binding)) { | ||
| return false; | ||
| } | ||
| } else { | ||
| return false; | ||
| } | ||
| has_expression_tag = true; | ||
| } | ||
| } | ||
| return has_expression_tag; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.