File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed
packages/svelte/src/compiler/phases/3-transform/server/visitors Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -14,13 +14,16 @@ import { build_template } from './shared/utils.js';
1414 */
1515export function SvelteElement ( node , context ) {
1616 let tag = /** @type {Expression } */ ( context . visit ( node . tag ) ) ;
17- if ( tag . type !== 'Identifier' ) {
18- const tag_id = context . state . scope . generate ( '$$tag' ) ;
19- context . state . init . push ( b . const ( tag_id , tag ) ) ;
20- tag = b . id ( tag_id ) ;
21- }
2217
2318 if ( dev ) {
19+ // Ensure getters/function calls aren't called multiple times.
20+ // If we ever start referencing `tag` more than once in prod, move this out of the if block.
21+ if ( tag . type !== 'Identifier' ) {
22+ const tag_id = context . state . scope . generate ( '$$tag' ) ;
23+ context . state . init . push ( b . const ( tag_id , tag ) ) ;
24+ tag = b . id ( tag_id ) ;
25+ }
26+
2427 if ( node . fragment . nodes . length > 0 ) {
2528 context . state . init . push ( b . stmt ( b . call ( '$.validate_void_dynamic_element' , b . thunk ( tag ) ) ) ) ;
2629 }
You can’t perform that action at this time.
0 commit comments