// jumpToStatement generates an unconditional jump to the target statement. func (sg *stateGenerator) jumpToStatement(target codedom.Statement) string { // Check for resources that will be out of scope once the jump occurs. resources := sg.resources.OutOfScope(target.BasisNode()) if len(resources) == 0 { // No resources are moving out of scope, so simply set the next state. targetState := sg.generateStates(target, generateNewState) return sg.snippets().SetState(targetState.ID) } // Pop off any resources out of scope. data := struct { PopFunction codedom.RuntimeFunction Resources []resource Snippets snippets TargetState *state IsGenerator bool }{codedom.StatePopResourceFunction, resources, sg.snippets(), sg.generateStates(target, generateNewState), sg.isGeneratorFunction} popTemplateStr := ` {{ .PopFunction }}({{ range $index, $resource := .Resources }}{{ if $index }}, {{ end }} '{{ $resource.Name }}' {{ end }}).then(function() { {{ .Snippets.SetState .TargetState.ID }} {{ .Snippets.Continue .IsGenerator }} }).catch(function(err) { {{ .Snippets.Reject "err" }} }); ` return sg.templater.Execute("popjump", popTemplateStr, data) }