@@ -3,12 +3,13 @@ package typescript
33import (
44 "context"
55 "fmt"
6- "github.com/clarkmcc/go-typescript/packages"
7- _ "github.com/clarkmcc/go-typescript/versions/v4.7.2"
8- "github.com/dop251/goja"
96 "io"
107 "io/ioutil"
118 "strings"
9+
10+ "github.com/clarkmcc/go-typescript/packages"
11+ _ "github.com/clarkmcc/go-typescript/versions/v4.7.2"
12+ "github.com/dop251/goja"
1213)
1314
1415type EvaluateOptionFunc func (cfg * EvaluateConfig )
@@ -102,22 +103,8 @@ func EvaluateCtx(ctx context.Context, src io.Reader, opts ...EvaluateOptionFunc)
102103 for _ , fn := range opts {
103104 fn (cfg )
104105 }
105- done := make (chan struct {})
106- started := make (chan struct {})
106+ done := startInterruptable (ctx , cfg .Runtime )
107107 defer close (done )
108- go func () {
109- // Inform the parent go-routine that we've started, this prevents a race condition where the
110- // runtime would beat the context cancellation in unit tests even though the context started
111- // out in a 'cancelled' state.
112- close (started )
113- select {
114- case <- ctx .Done ():
115- cfg .Runtime .Interrupt ("context halt" )
116- case <- done :
117- return
118- }
119- }()
120- <- started
121108 if cfg .HasEvaluateBefore () {
122109 for _ , s := range cfg .EvaluateBefore {
123110 b , err := ioutil .ReadAll (s )
@@ -130,6 +117,7 @@ func EvaluateCtx(ctx context.Context, src io.Reader, opts ...EvaluateOptionFunc)
130117 }
131118 }
132119 }
120+
133121 b , err := ioutil .ReadAll (src )
134122 if err != nil {
135123 return nil , fmt .Errorf ("reading src: %w" , err )
@@ -149,9 +137,7 @@ func EvaluateCtx(ctx context.Context, src io.Reader, opts ...EvaluateOptionFunc)
149137 WithRuntime (cfg .Runtime ),
150138 WithPreventCancellation (),
151139 }
152- for _ , opt := range cfg .TranspileOptions {
153- opts = append (opts , opt )
154- }
140+ opts = append (opts , cfg .TranspileOptions ... )
155141 for _ , h := range cfg .ScriptPreTranspileHooks {
156142 script , err = h (script )
157143 if err != nil {
0 commit comments