@@ -268,60 +268,63 @@ process {
268268 $start = $scriptText.IndexOf ($item.Extent.Text , $myOffset )
269269 $end = $start + $item.Extent.Text.Length
270270 $skipUntil = $end # set SkipUntil
271- $AstReplacements [$item ] = $pso # and store the replacement.
271+ $AstReplacements [$item ] = $pso # and store the replacement.
272+ }
273+
274+ # region Special Properties
272275
273- # region Special Properties
274- # Because PowerShell can attach properties to any object,
275- # we can use the presence of attached properties to change context around the replacement .
276+ # Because PowerShell can attach properties to any object,
277+ # we can use the presence of attached properties to change context around the replacement.
278+ # This happens regardless of if there is already a replacement for the current item .
276279
277- # .SkipUntil or .IgnoreUntil can specify a new index or AST end point
278- foreach ($toSkipAlias in ' SkipUntil' , ' IgnoreUntil' ) {
279- foreach ($toSkipUntil in $pso .$toSkipAlias ) {
280- if ($toSkipUntil -is [int ] -and $toSkipUntil -gt $end ) {
281- $skipUntil = $toSkipUntil
282- } elseif ($toSkipUntil -is [Management.Automation.Language.Ast ]) {
283- $newSkipStart = $scriptText.IndexOf ($toSkipUntil.Extent.Text , $myOffset )
284- if ($newSkipStart -ne -1 ) {
285- $end = $newSkipStart + $toSkipUntil.Extent.Text.Length
286- if ($end -gt $skipUntil ) {
287- $skipUntil = $end
288- }
289- if ($toSkipUntil -ne $item ) {
290- $AstReplacements [$toSkipUntil ] = ' '
291- }
280+ # .SkipUntil or .IgnoreUntil can specify a new index or AST end point
281+ foreach ($toSkipAlias in ' SkipUntil' , ' IgnoreUntil' ) {
282+ foreach ($toSkipUntil in $pso .$toSkipAlias ) {
283+ if ($toSkipUntil -is [int ] -and $toSkipUntil -gt $end ) {
284+ $skipUntil = $toSkipUntil
285+ } elseif ($toSkipUntil -is [Management.Automation.Language.Ast ]) {
286+ $newSkipStart = $scriptText.IndexOf ($toSkipUntil.Extent.Text , $myOffset )
287+ if ($newSkipStart -ne -1 ) {
288+ $end = $newSkipStart + $toSkipUntil.Extent.Text.Length
289+ if ($end -gt $skipUntil ) {
290+ $skipUntil = $end
291+ }
292+ if ($toSkipUntil -ne $item ) {
293+ $AstReplacements [$toSkipUntil ] = ' '
292294 }
293295 }
294296 }
295297 }
298+ }
296299
297- # .ToRemove,.RemoveAST, or .RemoveElement will remove AST elements or ranges
298- foreach ($toRemoveAlias in ' ToRemove' , ' RemoveAST' , ' RemoveElement' ) {
299- foreach ($toRemove in $pso .$toRemoveAlias ) {
300- if ($toRemove -is [Management.Automation.Language.Ast ]) {
301- $AstReplacements [$toRemove ] = ' '
302- } elseif ($toRemove -match ' ^\d+,\d+$' ) {
303- $Replacements [$toRemove ] = ' '
304- }
300+ # .ToRemove,.RemoveAST, or .RemoveElement will remove AST elements or ranges
301+ foreach ($toRemoveAlias in ' ToRemove' , ' RemoveAST' , ' RemoveElement' ) {
302+ foreach ($toRemove in $pso .$toRemoveAlias ) {
303+ if ($toRemove -is [Management.Automation.Language.Ast ]) {
304+ $AstReplacements [$toRemove ] = ' '
305+ } elseif ($toRemove -match ' ^\d+,\d+$' ) {
306+ $Replacements [$toRemove ] = ' '
305307 }
306308 }
309+ }
307310
308- # .ToReplace,.ReplaceAST or .ReplaceElement will replace elements or ranges.
309- foreach ($toReplaceAlias in ' ToReplace' , ' ReplaceAST' , ' ReplaceElement' ) {
310- foreach ($toReplace in $pso .$toReplaceAlias ) {
311- if ($toReplace -isnot [Collections.IDictionary ]) {
312- continue
313- }
314- foreach ($tr in $toReplace.GetEnumerator ()) {
315- if ($tr.Key -is [Management.Automaton.Language.Ast ]) {
316- $AstReplacements [$tr.Key ] = $tr.Value
317- } elseif ($tr.Key -match ' ^\d+,\d+$' ) {
318- $textReplacements [" $ ( $tr.Key ) " ] = $tr.Value
319- }
311+ # .ToReplace,.ReplaceAST or .ReplaceElement will replace elements or ranges.
312+ foreach ($toReplaceAlias in ' ToReplace' , ' ReplaceAST' , ' ReplaceElement' ) {
313+ foreach ($toReplace in $pso .$toReplaceAlias ) {
314+ if ($toReplace -isnot [Collections.IDictionary ]) {
315+ continue
316+ }
317+ foreach ($tr in $toReplace.GetEnumerator ()) {
318+ if ($tr.Key -is [Management.Automaton.Language.Ast ]) {
319+ $AstReplacements [$tr.Key ] = $tr.Value
320+ } elseif ($tr.Key -match ' ^\d+,\d+$' ) {
321+ $textReplacements [" $ ( $tr.Key ) " ] = $tr.Value
320322 }
321323 }
322324 }
323- # endregion Special Properties
324325 }
326+ # endregion Special Properties
327+
325328 }
326329 # If the transpiler had output, do not process any more transpilers.
327330 if ($pipeScriptOutput ) { break }
0 commit comments