Skip to content

Commit ff48b29

Browse files
use sourcemap haxe lib instead of js lib
1 parent 59e923a commit ff48b29

File tree

5 files changed

+24
-41
lines changed

5 files changed

+24
-41
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
This library automatically transforms `haxe.CallStack.callStack()` and `haxe.CallStack.exceptionStack()` results to make them point at Haxe sources instead of generated js file.
44
The only supported target is `js`.
55

6-
Works only in debug mode on js target. Does not affect your app if compiled without `-debug` flag or to some other target.
6+
Works only in debug mode or when `-D JSTACK_FORCE` is enabled on js target.
7+
Does not affect your app if compiled without `-debug` and `-D JSTACK_FORCE` flags or to some other target.
78

89
In debug mode Haxe generates a source map, which is utilized by JStack using [source-map library](https://github.com/mozilla/source-map) (bundled with JStack and embded automatically)
910

haxelib.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@
88
"releasenote" : "Fix locating entry point.",
99
"classPath" : "src",
1010
"contributors" : ["RealyUniqueName"],
11-
"dependencies" : {}
11+
"dependencies" : {
12+
"sourcemap" : ""
13+
}
1214
}

js/source-map.min.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/jstack/JStack.hx

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package jstack;
22

3-
#if (js && debug)
3+
#if (js && (debug || JSTACK_FORCE))
44

55
import haxe.CallStack;
6-
import haxe.Json;
6+
import sourcemap.SourcePos;
77
import js.Lib;
88
import haxe.io.Path;
99
import js.Browser;
1010
import haxe.Http;
1111

12+
using StringTools;
1213

1314
/**
1415
* Handles source map
@@ -48,24 +49,11 @@ class JStack {
4849
*/
4950
public function inject () : Void
5051
{
51-
Tools.embedSourceMapLib();
52-
53-
var consumer = null;
54-
if (untyped __js__("typeof window != 'undefined'")) {
55-
consumer = Lib.nativeThis.sourceMap.SourceMapConsumer;
56-
} else {
57-
consumer = untyped module.exports.SourceMapConsumer;
58-
}
59-
6052
loadSourceMap(function (sourceMapData:String) {
61-
var mapper = consumer(Json.parse(sourceMapData));
53+
var mapper = new SourceMap(sourceMapData);
6254

6355
CallStack.wrapCallSite = function (site) {
64-
var pos = mapper.originalPositionFor({
65-
line: site.getLineNumber(),
66-
column: site.getColumnNumber()
67-
});
68-
56+
var pos = mapper.originalPositionFor(site.getLineNumber(), site.getColumnNumber());
6957
return new StackPos(site, pos);
7058
}
7159

@@ -160,18 +148,15 @@ private class StackPos
160148
/** HX side */
161149
private var hx : Dynamic;
162150

163-
public function new (js:Dynamic, hx:Dynamic)
151+
public function new (js:Dynamic, hx:SourcePos)
164152
{
165-
if (hx.source != null) {
166-
hx.source = hx.source.replace('file://', '');
167-
}
168153
this.js = js;
169154
this.hx = hx;
170155
}
171156

172157
public function getFunctionName () return js.getFunctionName();
173-
public function getFileName () return (hx.line == null ? js.getFileName() : hx.source);
174-
public function getLineNumber () return (hx.line == null ? js.getLineNumber() : hx.line);
158+
public function getFileName () return (hx == null || hx.originalLine == null ? js.getFileName() : hx.source);
159+
public function getLineNumber () return (hx == null || hx.originalLine == null ? js.getLineNumber() : hx.originalLine);
175160

176161
}
177162

src/jstack/Tools.hx

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,15 @@ class Tools {
9393
}
9494

9595

96-
/**
97-
* Embeds source-map js library into compiled file
98-
*/
99-
macro static public function embedSourceMapLib () : Expr
100-
{
101-
var dir = Context.currentPos().getPosInfos().file.directory();
102-
var libFile = dir + '/' + SOURCE_MAP_LIB_FILE;
103-
var libCode = libFile.getContent();
104-
105-
return macro untyped __js__($v{libCode});
106-
}
107-
108-
109-
public function new () {
110-
}
96+
// /**
97+
// * Embeds source-map js library into compiled file
98+
// */
99+
// macro static public function embedSourceMapLib () : Expr
100+
// {
101+
// var dir = Context.currentPos().getPosInfos().file.directory();
102+
// var libFile = dir + '/' + SOURCE_MAP_LIB_FILE;
103+
// var libCode = libFile.getContent();
104+
105+
// return macro untyped __js__($v{libCode});
106+
// }
111107
}

0 commit comments

Comments
 (0)