From 32577d13c77dbfed08b0d4975b3666a5a38cbe3a Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Wed, 13 Jan 2021 16:31:55 +0200 Subject: [PATCH 1/2] We actually need to disable sourceMaps when we compile them as well --- js/compiler/compiler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From 73e38633f2bf8c065ebc464f5e2d21de32c39046 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Wed, 13 Jan 2021 17:09:44 +0200 Subject: [PATCH 2/2] Add a simple test to check sourcemaps are disabled --- js/module_loading_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) 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) + }) + } +}