11import MagicString from 'magic-string' ;
22import { BaseNode } from '../../interfaces' ;
3- import { transform , TransformationArray } from '../utils/node-utils' ;
3+ import { isImplicitlyClosedBlock , transform , TransformationArray } from '../utils/node-utils' ;
44import { InlineComponent } from './InlineComponent' ;
55import { IGNORE_POSITION_COMMENT , surroundWithIgnoreComments } from '../../utils/ignore' ;
66import { Element } from './Element' ;
@@ -38,9 +38,13 @@ export function handleSnippet(
3838 ? `};return __sveltets_2_any(0)}`
3939 : `};return __sveltets_2_any(0)};` ;
4040
41- str . overwrite ( endSnippet , snippetBlock . end , afterSnippet , {
42- contentOnly : true
43- } ) ;
41+ if ( isImplicitlyClosedBlock ( endSnippet , snippetBlock ) ) {
42+ str . prependLeft ( snippetBlock . end , afterSnippet ) ;
43+ } else {
44+ str . overwrite ( endSnippet , snippetBlock . end , afterSnippet , {
45+ contentOnly : true
46+ } ) ;
47+ }
4448
4549 const lastParameter = snippetBlock . parameters ?. at ( - 1 ) ;
4650
@@ -63,7 +67,23 @@ export function handleSnippet(
6367 const afterParameters = ` => { async ()${ IGNORE_POSITION_COMMENT } => {` ;
6468
6569 if ( isImplicitProp ) {
66- str . overwrite ( snippetBlock . start , snippetBlock . expression . start , '' , { contentOnly : true } ) ;
70+ /** Can happen in loose parsing mode, e.g. code is currently `{#snippet }` */
71+ const emptyId = snippetBlock . expression . start === snippetBlock . expression . end ;
72+
73+ if ( emptyId ) {
74+ // Give intellisense a way to map into the right position for implicit prop completion
75+ str . overwrite ( snippetBlock . start , snippetBlock . expression . start - 1 , '' , {
76+ contentOnly : true
77+ } ) ;
78+ str . overwrite ( snippetBlock . expression . start - 1 , snippetBlock . expression . start , ' ' , {
79+ contentOnly : true
80+ } ) ;
81+ } else {
82+ str . overwrite ( snippetBlock . start , snippetBlock . expression . start , '' , {
83+ contentOnly : true
84+ } ) ;
85+ }
86+
6787 const transforms : TransformationArray = [ '(' ] ;
6888
6989 if ( parameters ) {
@@ -82,12 +102,12 @@ export function handleSnippet(
82102
83103 if ( component instanceof InlineComponent ) {
84104 component . addImplicitSnippetProp (
85- [ snippetBlock . expression . start , snippetBlock . expression . end ] ,
105+ [ snippetBlock . expression . start - ( emptyId ? 1 : 0 ) , snippetBlock . expression . end ] ,
86106 transforms
87107 ) ;
88108 } else {
89109 component . addAttribute (
90- [ [ snippetBlock . expression . start , snippetBlock . expression . end ] ] ,
110+ [ [ snippetBlock . expression . start - ( emptyId ? 1 : 0 ) , snippetBlock . expression . end ] ] ,
91111 transforms
92112 ) ;
93113 }
@@ -109,7 +129,7 @@ export function handleSnippet(
109129 afterParameters
110130 ) ;
111131
112- transform ( str , snippetBlock . start , startEnd , startEnd , transforms ) ;
132+ transform ( str , snippetBlock . start , startEnd , transforms ) ;
113133 }
114134}
115135
0 commit comments