@@ -1065,7 +1065,10 @@ function create_block(parent, name, nodes, context) {
10651065 after_update : [ ] ,
10661066 template : [ ] ,
10671067 metadata : {
1068- template_needs_import_node : false ,
1068+ context : {
1069+ template_needs_import_node : false ,
1070+ template_contains_script_tag : false
1071+ } ,
10691072 namespace,
10701073 bound_contenteditable : context . state . metadata . bound_contenteditable
10711074 }
@@ -1085,10 +1088,14 @@ function create_block(parent, name, nodes, context) {
10851088 node : id
10861089 } ) ;
10871090
1088- const callee = namespace === 'svg' ? '$.svg_template' : '$.template' ;
1089-
10901091 context . state . hoisted . push (
1091- b . var ( template_name , b . call ( callee , b . template ( [ b . quasi ( state . template . join ( '' ) , true ) ] , [ ] ) ) )
1092+ b . var (
1093+ template_name ,
1094+ b . call (
1095+ get_template_function ( namespace , state ) ,
1096+ b . template ( [ b . quasi ( state . template . join ( '' ) , true ) ] , [ ] )
1097+ )
1098+ )
10921099 ) ;
10931100
10941101 body . push (
@@ -1097,7 +1104,7 @@ function create_block(parent, name, nodes, context) {
10971104 b . call (
10981105 '$.open' ,
10991106 b . id ( '$$anchor' ) ,
1100- b . literal ( ! state . metadata . template_needs_import_node ) ,
1107+ b . literal ( ! state . metadata . context . template_needs_import_node ) ,
11011108 template_name
11021109 )
11031110 ) ,
@@ -1138,12 +1145,14 @@ function create_block(parent, name, nodes, context) {
11381145 // special case — we can use `$.comment` instead of creating a unique template
11391146 body . push ( b . var ( id , b . call ( '$.comment' , b . id ( '$$anchor' ) ) ) ) ;
11401147 } else {
1141- const callee = namespace === 'svg' ? '$.svg_template' : '$.template' ;
1142-
11431148 state . hoisted . push (
11441149 b . var (
11451150 template_name ,
1146- b . call ( callee , b . template ( [ b . quasi ( state . template . join ( '' ) , true ) ] , [ ] ) , b . true )
1151+ b . call (
1152+ get_template_function ( namespace , state ) ,
1153+ b . template ( [ b . quasi ( state . template . join ( '' ) , true ) ] , [ ] ) ,
1154+ b . true
1155+ )
11471156 )
11481157 ) ;
11491158
@@ -1153,7 +1162,7 @@ function create_block(parent, name, nodes, context) {
11531162 b . call (
11541163 '$.open_frag' ,
11551164 b . id ( '$$anchor' ) ,
1156- b . literal ( ! state . metadata . template_needs_import_node ) ,
1165+ b . literal ( ! state . metadata . context . template_needs_import_node ) ,
11571166 template_name
11581167 )
11591168 )
@@ -1217,6 +1226,23 @@ function create_block(parent, name, nodes, context) {
12171226 return body ;
12181227}
12191228
1229+ /**
1230+ *
1231+ * @param {import('#compiler').Namespace } namespace
1232+ * @param {import('../types.js').ComponentClientTransformState } state
1233+ * @returns
1234+ */
1235+ function get_template_function ( namespace , state ) {
1236+ const contains_script_tag = state . metadata . context . template_contains_script_tag ;
1237+ return namespace === 'svg'
1238+ ? contains_script_tag
1239+ ? '$.svg_template_with_script'
1240+ : '$.svg_template'
1241+ : contains_script_tag
1242+ ? '$.template_with_script'
1243+ : '$.template' ;
1244+ }
1245+
12201246/**
12211247 *
12221248 * @param {import('../types.js').ComponentClientTransformState } state
@@ -1847,6 +1873,9 @@ export const template_visitors = {
18471873 context . state . template . push ( '<!>' ) ;
18481874 return ;
18491875 }
1876+ if ( node . name === 'script' ) {
1877+ context . state . metadata . context . template_contains_script_tag = true ;
1878+ }
18501879
18511880 const metadata = context . state . metadata ;
18521881 const child_metadata = {
@@ -1885,7 +1914,7 @@ export const template_visitors = {
18851914 // custom element until the template is connected to the dom, which would
18861915 // cause problems when setting properties on the custom element.
18871916 // Therefore we need to use importNode instead, which doesn't have this caveat.
1888- metadata . template_needs_import_node = true ;
1917+ metadata . context . template_needs_import_node = true ;
18891918 }
18901919
18911920 for ( const attribute of node . attributes ) {
0 commit comments