@@ -9,26 +9,25 @@ import { set_scope, get_rune } from '../../scope.js';
9
9
import { extract_identifiers , extract_paths , is_expression_async } from '../../../utils/ast.js' ;
10
10
import * as b from '../../../utils/builders.js' ;
11
11
import is_reference from 'is-reference' ;
12
- import { determine_namespace_for_children , transform_inspect_rune } from '../utils.js' ;
12
+ import { transform_inspect_rune } from '../utils.js' ;
13
13
import { is_element_node } from '../../nodes.js' ;
14
- import { BLOCK_OPEN_ELSE } from '../../../../internal/server/hydration.js' ;
15
14
import { filename } from '../../../state.js' ;
16
15
import { render_stylesheet } from '../css/index.js' ;
17
16
import { ConstTag } from './visitors/template/ConstTag.js' ;
18
17
import { DebugTag } from './visitors/template/DebugTag.js' ;
18
+ import { EachBlock } from './visitors/template/EachBlock.js' ;
19
19
import { Fragment } from './visitors/template/Fragment.js' ;
20
20
import { HtmlTag } from './visitors/template/HtmlTag.js' ;
21
+ import { IfBlock } from './visitors/template/IfBlock.js' ;
21
22
import { RegularElement } from './visitors/template/RegularElement.js' ;
22
23
import { RenderTag } from './visitors/template/RenderTag.js' ;
24
+ import { SvelteElement } from './visitors/template/SvelteElement.js' ;
23
25
import {
24
- block_close ,
25
- block_open ,
26
26
empty_comment ,
27
27
process_children ,
28
28
serialize_attribute_value ,
29
29
serialize_template
30
30
} from './visitors/template/shared/utils.js' ;
31
- import { serialize_element_attributes } from './visitors/template/shared/element.js' ;
32
31
33
32
/**
34
33
* @param {VariableDeclarator } declarator
@@ -832,125 +831,9 @@ const template_visitors = {
832
831
DebugTag,
833
832
RenderTag,
834
833
RegularElement,
835
- SvelteElement ( node , context ) {
836
- let tag = /** @type {Expression } */ ( context . visit ( node . tag ) ) ;
837
- if ( tag . type !== 'Identifier' ) {
838
- const tag_id = context . state . scope . generate ( '$$tag' ) ;
839
- context . state . init . push ( b . const ( tag_id , tag ) ) ;
840
- tag = b . id ( tag_id ) ;
841
- }
842
-
843
- if ( context . state . options . dev ) {
844
- if ( node . fragment . nodes . length > 0 ) {
845
- context . state . init . push ( b . stmt ( b . call ( '$.validate_void_dynamic_element' , b . thunk ( tag ) ) ) ) ;
846
- }
847
- context . state . init . push ( b . stmt ( b . call ( '$.validate_dynamic_element_tag' , b . thunk ( tag ) ) ) ) ;
848
- }
849
-
850
- const state = {
851
- ...context . state ,
852
- getteres : { ...context . state . getters } ,
853
- namespace : determine_namespace_for_children ( node , context . state . namespace ) ,
854
- template : [ ] ,
855
- init : [ ]
856
- } ;
857
-
858
- serialize_element_attributes ( node , { ...context , state } ) ;
859
-
860
- if ( context . state . options . dev ) {
861
- context . state . template . push ( b . stmt ( b . call ( '$.push_element' , tag , b . id ( '$$payload' ) ) ) ) ;
862
- }
863
-
864
- const attributes = b . block ( [ ...state . init , ...serialize_template ( state . template ) ] ) ;
865
- const children = /** @type {BlockStatement } */ ( context . visit ( node . fragment , state ) ) ;
866
-
867
- context . state . template . push (
868
- b . stmt (
869
- b . call (
870
- '$.element' ,
871
- b . id ( '$$payload' ) ,
872
- tag ,
873
- attributes . body . length > 0 && b . thunk ( attributes ) ,
874
- children . body . length > 0 && b . thunk ( children )
875
- )
876
- )
877
- ) ;
878
-
879
- if ( context . state . options . dev ) {
880
- context . state . template . push ( b . stmt ( b . call ( '$.pop_element' ) ) ) ;
881
- }
882
- } ,
883
- EachBlock ( node , context ) {
884
- const state = context . state ;
885
-
886
- const each_node_meta = node . metadata ;
887
- const collection = /** @type {Expression } */ ( context . visit ( node . expression ) ) ;
888
- const item = each_node_meta . item ;
889
- const index =
890
- each_node_meta . contains_group_binding || ! node . index
891
- ? each_node_meta . index
892
- : b . id ( node . index ) ;
893
-
894
- const array_id = state . scope . root . unique ( 'each_array' ) ;
895
- state . init . push ( b . const ( array_id , b . call ( '$.ensure_array_like' , collection ) ) ) ;
896
-
897
- /** @type {Statement[] } */
898
- const each = [ b . const ( item , b . member ( array_id , index , true ) ) ] ;
899
-
900
- if ( node . context . type !== 'Identifier' ) {
901
- each . push ( b . const ( /** @type {Pattern } */ ( node . context ) , item ) ) ;
902
- }
903
- if ( index . name !== node . index && node . index != null ) {
904
- each . push ( b . let ( node . index , index ) ) ;
905
- }
906
-
907
- each . push ( .../** @type {BlockStatement } */ ( context . visit ( node . body ) ) . body ) ;
908
-
909
- const for_loop = b . for (
910
- b . let ( index , b . literal ( 0 ) ) ,
911
- b . binary ( '<' , index , b . member ( array_id , b . id ( 'length' ) ) ) ,
912
- b . update ( '++' , index , false ) ,
913
- b . block ( each )
914
- ) ;
915
-
916
- if ( node . fallback ) {
917
- const open = b . stmt ( b . assignment ( '+=' , b . id ( '$$payload.out' ) , block_open ) ) ;
918
-
919
- const fallback = /** @type {BlockStatement } */ ( context . visit ( node . fallback ) ) ;
920
-
921
- fallback . body . unshift (
922
- b . stmt ( b . assignment ( '+=' , b . id ( '$$payload.out' ) , b . literal ( BLOCK_OPEN_ELSE ) ) )
923
- ) ;
924
-
925
- state . template . push (
926
- b . if (
927
- b . binary ( '!==' , b . member ( array_id , b . id ( 'length' ) ) , b . literal ( 0 ) ) ,
928
- b . block ( [ open , for_loop ] ) ,
929
- fallback
930
- ) ,
931
- block_close
932
- ) ;
933
- } else {
934
- state . template . push ( block_open , for_loop , block_close ) ;
935
- }
936
- } ,
937
- IfBlock ( node , context ) {
938
- const test = /** @type {Expression } */ ( context . visit ( node . test ) ) ;
939
-
940
- const consequent = /** @type {BlockStatement } */ ( context . visit ( node . consequent ) ) ;
941
-
942
- const alternate = node . alternate
943
- ? /** @type {BlockStatement } */ ( context . visit ( node . alternate ) )
944
- : b . block ( [ ] ) ;
945
-
946
- consequent . body . unshift ( b . stmt ( b . assignment ( '+=' , b . id ( '$$payload.out' ) , block_open ) ) ) ;
947
-
948
- alternate . body . unshift (
949
- b . stmt ( b . assignment ( '+=' , b . id ( '$$payload.out' ) , b . literal ( BLOCK_OPEN_ELSE ) ) )
950
- ) ;
951
-
952
- context . state . template . push ( b . if ( test , consequent , alternate ) , block_close ) ;
953
- } ,
834
+ SvelteElement,
835
+ EachBlock,
836
+ IfBlock,
954
837
AwaitBlock ( node , context ) {
955
838
context . state . template . push (
956
839
empty_comment ,
0 commit comments