File tree 1 file changed +9
-2
lines changed
1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,8 @@ export function transformSnippetVariables(
22
22
placeholderName ?: string | null ,
23
23
substitutions ?: Record < string , string >
24
24
) {
25
- var placeholderIndex = getMaxPlaceholderIndex ( parsedSnippet ) + 1 ;
25
+ let nextPlaceholderIndex = getMaxPlaceholderIndex ( parsedSnippet ) + 1 ;
26
+ const placeholderIndexMap : Record < string , number > = { } ;
26
27
27
28
parsedSnippet . walk ( ( candidate ) => {
28
29
if ( candidate instanceof Variable ) {
@@ -36,7 +37,13 @@ export function transformSnippetVariables(
36
37
new Text ( substitutions [ candidate . name ] ) ,
37
38
] ) ;
38
39
} else if ( ! KnownSnippetVariableNames [ candidate . name ] ) {
39
- const placeholder = new Placeholder ( placeholderIndex ++ ) ;
40
+ let placeholderIndex : number ;
41
+ if ( candidate . name in placeholderIndexMap ) {
42
+ placeholderIndex = placeholderIndexMap [ candidate . name ] ;
43
+ } else {
44
+ placeholderIndex = nextPlaceholderIndex ++ ;
45
+ }
46
+ const placeholder = new Placeholder ( placeholderIndex ) ;
40
47
candidate . children . forEach ( ( child ) => placeholder . appendChild ( child ) ) ;
41
48
candidate . parent . replace ( candidate , [ placeholder ] ) ;
42
49
}
You can’t perform that action at this time.
0 commit comments