Skip to content

Commit

Permalink
Merge pull request #104 from mpalmerlee/fix-parse-error-not-a-function
Browse files Browse the repository at this point in the history
fix #92 this.parseError is not a function
  • Loading branch information
jgravois authored May 15, 2024
2 parents 738533d + 293723d commit 536a86c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/wkt/src/wkt.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

'SOURCE';

// surface parsing errors to calling code https://github.com/zaach/jison/issues/218
parser.yy.parseError = function (err) {
throw err;
};

function PointArray (point) {
this.data = [point];
this.type = 'PointArray';
Expand Down
13 changes: 13 additions & 0 deletions packages/wkt/test/wkt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1035,3 +1035,16 @@ test('should parse a GEOMETRYCOLLECTION with ZM property', function (t) {
}
});
});

test('should fail with friendly error message when wkt is invalid', function (t) {
t.plan(1);

const input = 'POINT(30,10)';

try {
wktToGeoJSON(input);
} catch (err) {
const error = err.toString();
t.deepEqual(error, 'Error: Unable to parse: Parse error on line 1:\nPOINT(30,10)\n--------^\nExpecting \'DOUBLE_TOK\', got \'COMMA\'');
}
});

0 comments on commit 536a86c

Please sign in to comment.