Skip to content

Commit 59e923a

Browse files
forgotten commit
1 parent d2663fe commit 59e923a

File tree

7 files changed

+57
-14
lines changed

7 files changed

+57
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
build/*
22
build.hxml
33
*.iml
4+
cSpell.json
45
.idea
56
lab
67
.vscode

extraParams.hxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
--macro include('jstack.JStack')
22
--macro keep('jstack.JStack')
3-
--macro jstack.Tools.addInjectmetaToMain()
3+
--macro jstack.Tools.addInjectMetaToMain()

haxelib.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"license" : "MIT",
55
"tags" : ["js", "stack", "callstack", "stacktrace"],
66
"description" : "Friendly stack traces for JS target. Makes haxe.CallStack point to haxe sources.",
7-
"version" : "1.0.0",
8-
"releasenote" : "jstack.JStack.onReady() in automatically injected now.",
7+
"version" : "1.0.1",
8+
"releasenote" : "Fix locating entry point.",
99
"classPath" : "src",
1010
"contributors" : ["RealyUniqueName"],
1111
"dependencies" : {}

src/jstack/JStack.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class JStack {
2626

2727
/**
2828
* Invoke `callback` when source map is loaded.
29-
* A call to this method is autonmatically injected in `static main()` function of your app.
29+
* A call to this method is automatically injected in `static main()` function of your app.
3030
* You don't need to use this method manually.
3131
*/
3232
static public function onReady (callback:Void->Void) : Void

src/jstack/Tools.hx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ class Tools {
2323
/**
2424
Inject `json.JStack.onReady()` into app entry point, so that app will not start untill source map is ready.
2525
**/
26-
static public function addInjectmetaToMain() : Void
26+
static public function addInjectMetaToMain() : Void
2727
{
28-
if (Compiler.getDefine('display') != null) return;
29-
if (Compiler.getDefine('debug') == null || Compiler.getDefine('js') == null) return;
28+
#if (display || !debug)
29+
return;
30+
#end
31+
if (Context.definedValue('js') == null) return;
3032

3133
var main : String = null;
3234
var args = Sys.args();
@@ -37,15 +39,15 @@ class Tools {
3739
}
3840
}
3941
if (main == null) {
40-
Context.warning('Failed to find entry point. Did you specify `-main` directive?', Context.currentPos());
41-
return;
42+
Context.warning('JStack: Failed to find entry point. Did you specify `-main` directive?', (macro {}).pos);
43+
return;
4244
}
43-
45+
4446
Compiler.addMetadata('@:build(jstack.Tools.injectInMain())', main);
4547
}
4648
#end
4749

48-
macro static public function injectInMain() : Array<Field>
50+
macro static public function injectInMain() : Array<Field>
4951
{
5052
var fields = Context.getBuildFields();
5153
var injected = false;
@@ -56,13 +58,14 @@ class Tools {
5658
switch (field.kind) {
5759
case FFun(fn):
5860
fn.expr = macro jstack.JStack.onReady(function() ${fn.expr});
59-
case _:
60-
Context.error('Failed to inject JStack in `main` function.', field.pos);
61+
injected = true;
62+
case _:
63+
Context.error('JStack: Failed to inject JStack in `main` function.', field.pos);
6164
}
6265
}
6366

6467
if (!injected) {
65-
Context.error('Failed to find static function main.', Context.currentPos());
68+
Context.error('JStack: Failed to find static function main.', (macro {}).pos);
6669
}
6770

6871
return fields;

test.hxml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-cp src
2+
-cp test
3+
-main Test
4+
-debug
5+
6+
extraParams.hxml
7+
8+
-js build/test.js

test/Test.hx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package;
2+
3+
import haxe.io.Path;
4+
import haxe.PosInfos;
5+
import haxe.CallStack;
6+
7+
class Test {
8+
static var pos:PosInfos;
9+
10+
static public function main() {
11+
try {
12+
throwException();
13+
} catch(e:Dynamic) {
14+
var fileName = new Path(pos.fileName).file;
15+
for(stackItem in CallStack.exceptionStack()) {
16+
switch(stackItem) {
17+
case FilePos(_, file, line) if(line == pos.lineNumber && fileName == new Path(file).file):
18+
trace('Test passed');
19+
return;
20+
case _:
21+
}
22+
}
23+
}
24+
throw "Test FAILED";
25+
}
26+
27+
static function throwException(?pos:PosInfos) {
28+
Test.pos = pos;
29+
throw 'wtf';
30+
}
31+
}

0 commit comments

Comments
 (0)