diff --git a/js/compiler/compiler.go b/js/compiler/compiler.go index f72de6a8175..8eaafd5f2a6 100644 --- a/js/compiler/compiler.go +++ b/js/compiler/compiler.go @@ -74,7 +74,7 @@ func (c *Compiler) Transform(src, filename string) (code string, srcmap *SourceM func (c *Compiler) Compile(src, filename, pre, post string, strict bool, compatMode lib.CompatibilityMode) (*goja.Program, string, error) { code := pre + src + post - ast, err := parser.ParseFile(nil, filename, code, 0) + ast, err := parser.ParseFile(nil, filename, code, 0, parser.WithDisableSourceMaps) if err != nil { if compatMode == lib.CompatibilityModeExtended { code, _, err = c.Transform(src, filename) diff --git a/js/module_loading_test.go b/js/module_loading_test.go index 9516b6636dd..fa82d70f850 100644 --- a/js/module_loading_test.go +++ b/js/module_loading_test.go @@ -493,3 +493,36 @@ func TestLoadingUnexistingModuleDoesntPanic(t *testing.T) { }) } } + +func TestLoadingSourceMapsDoesntErrorOut(t *testing.T) { + fs := afero.NewMemMapFs() + data := `exports.default = function() {} +//# sourceMappingURL=test.min.js.map` + require.NoError(t, afero.WriteFile(fs, "/script.js", []byte(data), 0o644)) + r1, err := getSimpleRunner(t, "/script.js", data, fs) + require.NoError(t, err) + + arc := r1.MakeArchive() + buf := &bytes.Buffer{} + require.NoError(t, arc.Write(buf)) + arc, err = lib.ReadArchive(buf) + require.NoError(t, err) + r2, err := NewFromArchive(testutils.NewLogger(t), arc, lib.RuntimeOptions{}) + require.NoError(t, err) + + runners := map[string]*Runner{"Source": r1, "Archive": r2} + for name, r := range runners { + r := r + t.Run(name, func(t *testing.T) { + ch := newDevNullSampleChannel() + defer close(ch) + initVU, err := r.NewVU(1, ch) + require.NoError(t, err) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + vu := initVU.Activate(&lib.VUActivationParams{RunContext: ctx}) + err = vu.RunOnce() + require.NoError(t, err) + }) + } +}