File tree Expand file tree Collapse file tree 2 files changed +33
-2
lines changed
Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change 88[ ![ semantic-release] [ semantic-image ] ] [ semantic-url ]
99[ ![ js-standard-style] [ standard-image ]] [ standard-url ]
1010
11+ ## Install
12+
13+ ```
14+ npm install -S stack-sites
15+ ```
16+
17+ ``` js
18+ const stackSites = require (' stack-sites' )
19+ function foo () {
20+ const sites = stackSites ()
21+ // sites[0] - stackSites itself
22+ // sites[1] - this file
23+ // sites[2] - caller to this function
24+ const caller = sites[2 ]
25+ console .log (' I got called from %s line %d column %d' ,
26+ caller .filename , caller .line , caller .column
27+ )
28+ }
29+ module .exports = foo
30+ ```
31+
32+ ## Why?
33+
34+ V8 stack API does not return accurate source locations if the source file
35+ has been transpiled on load, see
36+ [ Accurate call sites] ( https://glebbahmutov.com/blog/accurate-call-sites/ )
37+ blog post. Exception stack on the other hand can take source maps into
38+ the account, producing correct line and column information.
39+
1140### Small print
1241
1342Author: Gleb Bahmutov < ; gleb.bahmutov@gmail.com > ; © ; 2017
1443
15-
1644* [ @bahmutov ] ( https://twitter.com/bahmutov )
1745* [ glebbahmutov.com] ( http://glebbahmutov.com )
1846* [ blog] ( http://glebbahmutov.com/blog )
1947
20-
2148License: MIT - do anything with the code, but don't blame me if it does not work.
2249
2350Support: if you find any problems with this module, email / tweet /
Original file line number Diff line number Diff line change 6767 "nsp" : " 2.6.2" ,
6868 "pre-git" : " 3.12.0" ,
6969 "standard" : " 8.6.0"
70+ },
71+ "dependencies" : {
72+ "check-more-types" : " 2.23.0" ,
73+ "lazy-ass" : " 1.5.0"
7074 }
7175}
You can’t perform that action at this time.
0 commit comments