@@ -25,7 +25,7 @@ import TemplateScope from './nodes/shared/TemplateScope';
2525import fuzzymatch from '../utils/fuzzymatch' ;
2626import get_object from './utils/get_object' ;
2727import Slot from './nodes/Slot' ;
28- import { Node , ImportDeclaration , ExportNamedDeclaration , Identifier , ExpressionStatement , AssignmentExpression , Literal , Property , RestElement , ExportDefaultDeclaration , ExportAllDeclaration , FunctionDeclaration , FunctionExpression } from 'estree' ;
28+ import { Node , ImportDeclaration , ExportNamedDeclaration , Identifier , ExpressionStatement , AssignmentExpression , Literal , Property , RestElement , ExportDefaultDeclaration , ExportAllDeclaration , FunctionDeclaration , FunctionExpression , Statement } from 'estree' ;
2929import add_to_set from './utils/add_to_set' ;
3030import check_graph_for_cycles from './utils/check_graph_for_cycles' ;
3131import { print , b } from 'code-red' ;
@@ -38,6 +38,7 @@ import compiler_warnings from './compiler_warnings';
3838import compiler_errors from './compiler_errors' ;
3939import { extract_ignores_above_position , extract_svelte_ignore_from_comments } from '../utils/extract_svelte_ignore' ;
4040import check_enable_sourcemap from './utils/check_enable_sourcemap' ;
41+ import { flatten } from '../utils/flatten' ;
4142
4243interface ComponentOptions {
4344 namespace ?: string ;
@@ -1138,14 +1139,23 @@ export default class Component {
11381139 }
11391140 }
11401141
1141- if ( inserts . length > 0 ) {
1142- parent [ key ] . splice ( index + 1 , 0 , ...inserts ) ;
1143- }
1144- if ( props . length > 0 ) {
1145- parent [ key ] . splice ( index + 1 , 0 , b `let { ${ props } } = $$props;` ) ;
1146- }
1147- if ( node . declarations . length == 0 ) {
1148- parent [ key ] . splice ( index , 1 ) ;
1142+ if ( Array . isArray ( parent [ key ] ) ) {
1143+ if ( inserts . length > 0 ) {
1144+ inserts . reverse ( ) . forEach ( ( insert ) => {
1145+ parent [ key ] . splice ( index + 1 , 0 , ...insert ) ;
1146+ } ) ;
1147+ }
1148+ if ( props . length > 0 ) {
1149+ parent [ key ] . splice ( index + 1 , 0 , b `let { ${ props } } = $$props;` ) ;
1150+ }
1151+ if ( node . declarations . length == 0 ) {
1152+ parent [ key ] . splice ( index , 1 ) ;
1153+ }
1154+ } else if ( inserts . length > 0 ) {
1155+ this . replace ( {
1156+ type : 'BlockStatement' ,
1157+ body : flatten ( [ node , inserts ] ) as Statement [ ]
1158+ } ) ;
11491159 }
11501160
11511161 return this . skip ( ) ;
0 commit comments