Skip to content
This repository was archived by the owner on Sep 15, 2021. It is now read-only.

Commit 3197aca

Browse files
committed
Merge pull request #163 from zombie/162-experiment-errors
show parse errors on experiment tab, fix #162
2 parents 153f6ec + 1758799 commit 3197aca

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

client/js/experimentctrl.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ scanjsModule.controller('ExperimentCtrl', ['$scope', 'ScanSvc', function Experim
2424

2525
$scope.runScan = function () {
2626
$scope.results = [];
27+
$scope.error = null;
2728
ScanJS.loadRules(ScanSvc.rules);
2829
var code = $scope.codeMirror.getValue();
2930
try {
3031
var ast = acorn.parse(code, { locations: true });
32+
$scope.results = ScanJS.scan(ast);
3133
} catch(e) {
34+
$scope.error = e;
3235
console.error(e);
3336
}
34-
$scope.results = ScanJS.scan(ast);
3537
$scope.lastScan = $scope.runScan;
3638
};
3739

@@ -40,23 +42,21 @@ scanjsModule.controller('ExperimentCtrl', ['$scope', 'ScanSvc', function Experim
4042
ScanJS.loadRules([ruleData]);
4143

4244
$scope.results = [];
45+
$scope.error = null;
4346
var code = $scope.codeMirror.getValue();
4447
try {
4548
var ast = acorn.parse(code, { locations: true });
49+
$scope.results = ScanJS.scan(ast);
50+
//put ast on global variable for debugging purposes.
51+
window.ast = ast;
4652
} catch(e) {
53+
$scope.error = e;
4754
console.error(e);
4855
}
49-
50-
//put ast on global variable for debugging purposes.
51-
window.ast = ast;
52-
53-
//ScanJS.setResultCallback(found);
54-
$scope.results = ScanJS.scan(ast);
5556
$scope.lastScan = $scope.runManualScan;
5657
};
5758

5859
$scope.showResult = function (filename,line, col) {
59-
document.querySelector("#code-mirror-wrapper").classList.toggle("hidden",false);
6060
$scope.codeMirror.setCursor(line - 1, col || 0);
6161
$scope.codeMirror.focus();
6262
};

client/partials/experiment.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222
<h4>
2323
Results
2424
</h4>
25+
<div ng-if="error" id="parse-error">
26+
<div class="alert alert-danger" role="alert">
27+
<h4>
28+
<a href="" ng-click="showResult('', error.loc.line, error.loc.column)">line {{error.loc.line}}</a>
29+
::
30+
{{error.name}}
31+
</h4>
32+
{{error.message}}
33+
</div>
34+
</div>
2535
<table class="table table-striped" >
2636
<thead>
2737
<tr>

0 commit comments

Comments
 (0)