File tree Expand file tree Collapse file tree 2 files changed +14
-7
lines changed
compiler/phases/3-transform Expand file tree Collapse file tree 2 files changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -270,6 +270,19 @@ export function clean_nodes(
270
270
271
271
var first = trimmed [ 0 ] ;
272
272
273
+ // Special case: Add a comment if this is a lone script tag. This ensures that our run_scripts logic in template.js
274
+ // will always be able to call node.replaceWith() on the script tag in order to make it run. If we don't add this
275
+ // and would still call node.replaceWith() on the script tag, it would be a no-op because the script tag has no parent.
276
+ if ( trimmed . length === 1 && first . type === 'RegularElement' && first . name === 'script' ) {
277
+ trimmed . push ( {
278
+ type : 'Comment' ,
279
+ data : '' ,
280
+ parent : first . parent ,
281
+ start : - 1 ,
282
+ end : - 1
283
+ } ) ;
284
+ }
285
+
273
286
return {
274
287
hoisted,
275
288
trimmed,
Original file line number Diff line number Diff line change @@ -185,13 +185,7 @@ function run_scripts(node) {
185
185
effect . nodes_end = clone ;
186
186
}
187
187
188
- // If node === script tag, replaceWith will do nothing because there's no parent yet
189
- if ( script === node ) {
190
- // but we can returns the cloned <script> immediately
191
- return clone ;
192
- } else {
193
- script . replaceWith ( clone ) ;
194
- }
188
+ script . replaceWith ( clone ) ;
195
189
}
196
190
return node ;
197
191
}
You can’t perform that action at this time.
0 commit comments