@@ -229,15 +229,15 @@ export const sedCommand: Command = {
229229 lineStart === undefined ||
230230 ( lineNum >= lineStart && lineNum <= ( lineEnd ?? lineStart ) ) ;
231231
232- if ( sedCmd . type === "substitute" && inRange ) {
232+ if ( sedCmd . type === "substitute" && inRange && sedCmd . pattern ) {
233233 let flags = "" ;
234234 if ( sedCmd . global ) flags += "g" ;
235235 if ( sedCmd . ignoreCase ) flags += "i" ;
236- const regex = new RegExp ( sedCmd . pattern ! , flags ) ;
236+ const regex = new RegExp ( sedCmd . pattern , flags ) ;
237237
238238 // Handle & replacement
239239 line = line . replace ( regex , ( match ) =>
240- processReplacement ( sedCmd . replacement ! , match ) ,
240+ processReplacement ( sedCmd . replacement ?? "" , match ) ,
241241 ) ;
242242 } else if ( sedCmd . type === "delete" ) {
243243 if ( sedCmd . addressPattern ) {
@@ -315,13 +315,13 @@ export const sedCommand: Command = {
315315 lineStart === undefined ||
316316 ( lineNum >= lineStart && lineNum <= ( lineEnd ?? lineStart ) ) ;
317317
318- if ( sedCmd . type === "substitute" && inRange ) {
318+ if ( sedCmd . type === "substitute" && inRange && sedCmd . pattern ) {
319319 let flags = "" ;
320320 if ( sedCmd . global ) flags += "g" ;
321321 if ( sedCmd . ignoreCase ) flags += "i" ;
322- const regex = new RegExp ( sedCmd . pattern ! , flags ) ;
322+ const regex = new RegExp ( sedCmd . pattern , flags ) ;
323323 line = line . replace ( regex , ( match ) =>
324- processReplacement ( sedCmd . replacement ! , match ) ,
324+ processReplacement ( sedCmd . replacement ?? "" , match ) ,
325325 ) ;
326326 } else if ( sedCmd . type === "delete" ) {
327327 if ( sedCmd . addressPattern ) {
0 commit comments