Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some areas of the generated JS files are not covered by source maps. #943

Open
nevkontakte opened this issue Sep 24, 2019 · 1 comment
Open

Comments

@nevkontakte
Copy link
Contributor

@nevkontakte nevkontakte commented Sep 24, 2019

Hi folks, I was trying to see if I can help with Go 1.13 support, but I can't get source-map-support to work properly and deciphering stack traces is becoming difficult :/

My steps:

$ nvm use 10  # Activate node 10.x
$ npm install --global source-map-support
$ export NODE_PATH="$(npm root --global)"  # Without this node doesn't seem to find the package.
$ node --require source-map-support/register --eval ""  # Completes with no errors.
$ gopherjs test -v fmt

/home/aleks/go/src/github.com/gopherjs/gopherjs/test.784702578:4210
                _r = reflectlite.TypeOf((ptrType.nil)).Elem(); /* */ $s = 2; case 2: if($c) { $c = false; _r = _r.$blk(); } if (_r && _r.$blk !== undefined) { break s; }
                                        ^
TypeError: Cannot read property 'Elem' of undefined
    at Object.$init (/home/aleks/go/src/github.com/gopherjs/gopherjs/test.784702578:4210:41)
    at Object.$init (/home/aleks/go/src/github.com/gopherjs/gopherjs/test.784702578:7350:15)
    at Object.$init (/home/aleks/go/src/github.com/gopherjs/gopherjs/test.784702578:8306:14)
    at Object.$init (/home/aleks/go/src/github.com/gopherjs/gopherjs/test.784702578:45090:14)
    at $init (/home/aleks/go/src/github.com/gopherjs/gopherjs/test.784702578:45567:17)
    at $goroutine (/home/aleks/go/src/github.com/gopherjs/gopherjs/test.784702578:1478:19)
    at $runScheduled (/home/aleks/go/src/github.com/gopherjs/gopherjs/test.784702578:1518:7)
    at $schedule (/home/aleks/go/src/github.com/gopherjs/gopherjs/test.784702578:1534:5)
    at $go (/home/aleks/go/src/github.com/gopherjs/gopherjs/test.784702578:1510:3)
    at Object.<anonymous> (/home/aleks/go/src/github.com/gopherjs/gopherjs/test.784702578:45588:1)
    at Object.<anonymous> (/home/aleks/go/src/github.com/gopherjs/gopherjs/test.784702578:45591:4)
    at Module._compile (internal/modules/cjs/loader.js:654:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
    at Module.load (internal/modules/cjs/loader.js:566:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
    at Function.Module._load (internal/modules/cjs/loader.js:498:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:695:10)
    at startup (internal/bootstrap/node.js:201:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:516:3)
FAIL    fmt     0.620s

Note there isn't a warning about missing source-map-support module. It would be there if I didn't do the export NODE_PATH=... thing.

I also tried this:

$ gopherjs test -v -c fmt
$ ls fmt_test.js*
fmt_test.js  fmt_test.js.map
$ node --require source-map-support/register fmt_test.js

/home/aleks/go/src/github.com/gopherjs/gopherjs/fmt_test.js:4210
                _r = reflectlite.TypeOf((ptrType.nil)).Elem(); /* */ $s = 2; case 2: if($c) { $c = false; _r = _r.$blk(); } if (_r && _r.$blk !== undefined) { break s; }
                                        ^
TypeError: Cannot read property 'Elem' of undefined
    at Object.$init (/home/aleks/go/src/github.com/gopherjs/gopherjs/fmt_test.js:4210:41)
    at Object.$init (/home/aleks/go/src/github.com/gopherjs/gopherjs/fmt_test.js:7350:15)
    at Object.$init (/home/aleks/go/src/github.com/gopherjs/gopherjs/fmt_test.js:8306:14)
    at Object.$init (/home/aleks/go/src/github.com/gopherjs/gopherjs/fmt_test.js:45090:14)
    at $init (/home/aleks/go/src/github.com/gopherjs/gopherjs/fmt_test.js:45567:17)
    at $goroutine (/home/aleks/go/src/github.com/gopherjs/gopherjs/fmt_test.js:1478:19)
    at $runScheduled (/home/aleks/go/src/github.com/gopherjs/gopherjs/fmt_test.js:1518:7)
    at $schedule (/home/aleks/go/src/github.com/gopherjs/gopherjs/fmt_test.js:1534:5)
    at $go (/home/aleks/go/src/github.com/gopherjs/gopherjs/fmt_test.js:1510:3)
    at Object.<anonymous> (/home/aleks/go/src/github.com/gopherjs/gopherjs/fmt_test.js:45588:1)
    at Object.<anonymous> (/home/aleks/go/src/github.com/gopherjs/gopherjs/fmt_test.js:45591:4)
    at Module._compile (internal/modules/cjs/loader.js:654:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
    at Module.load (internal/modules/cjs/loader.js:566:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
    at Function.Module._load (internal/modules/cjs/loader.js:498:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:695:10)
    at startup (internal/bootstrap/node.js:201:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:516:3)

The result is exactly the same.

$ gopherjs version
GopherJS 1.13-wip
$ node --version
v10.0.0

For the reference, the compiled scripts: fmt_test.zip. Manual inspection doesn't seem to reveal any smoking gun.

Any suggestions? Thanks! :)

@nevkontakte nevkontakte changed the title Source maps have no effect Source maps have no effect in `gopherjs test` Sep 24, 2019
@nevkontakte
Copy link
Contributor Author

@nevkontakte nevkontakte commented Oct 6, 2019

I dug into the isse a little bit today and it looks like the source map support is working, but I got lucky enough to get a stack trace which lands into areas of the compiled code which are not mapped onto any original Go code.

For example:

    at Object.$init (/home/aleks/go/src/github.com/gopherjs/gopherjs/fmt_test.js:45090:14)

I used https://pastcompute.github.io/ScriptMapper/ to decode the source map and this is where this line ends up pointing at:

/fmt/stringer_test.go,45018,0,60,2,null
null,45019,0,null,null,null
null,45090,0,null,null,null <----
null,45091,0,null,null,null
...
null,45193,0,null,null,null
/fmt/fmt_test.go,45196,0,1421,30,null

The generated script:

	$init = function() {
		$pkg.$init = function() {};
		/* */ var $f, $c = false, $s = 0, $r; if (this !== undefined && this.$blk !== undefined) { $f = this; $c = true; $s = $f.$s; $r = $f.$r; } s: while (true) { switch ($s) { case 0:
                // ↓ Line 45090
		$r = bufio.$init(); /* */ $s = 1; case 1: if($c) { $c = false; $r = $r.$blk(); } if ($r && $r.$blk !== undefined) { break s; }
		$r = bytes.$init(); /* */ $s = 2; case 2: if($c) { $c = false; $r = $r.$blk(); } if ($r && $r.$blk !== undefined) { break s; }
		$r = errors.$init(); /* */ $s = 3; case 3: if($c) { $c = false; $r = $r.$blk(); } if ($r && $r.$blk !== undefined) { break s; }
		$r = fmt.$init(); /* */ $s = 4; case 4: if($c) { $c = false; $r = $r.$blk(); } if ($r && $r.$blk !== undefined) { break s; }

This code looks like some sort of GopherJS-generated package preamble, which is probably why it isn't mapped directly on the original source code. It would be nice, however to have it mapped at least into the file it was generated for.

@nevkontakte nevkontakte changed the title Source maps have no effect in `gopherjs test` Some areas of the generated JS files are not covered by source maps. Oct 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.