From e03d92488a8456078d9bbb9b0811572bedd1b556 Mon Sep 17 00:00:00 2001 From: David Majda Date: Fri, 29 Jul 2016 11:51:58 +0200 Subject: [PATCH] Set the "found" property of syntax errors produced by "error" to null The property doesn't correspond to anything in the error's message. --- lib/compiler/passes/generate-js.js | 7 +------ lib/parser.js | 7 +------ spec/behavior/generated-parser-behavior.spec.js | 4 ++-- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/lib/compiler/passes/generate-js.js b/lib/compiler/passes/generate-js.js index 3afb1f5..13fd70f 100644 --- a/lib/compiler/passes/generate-js.js +++ b/lib/compiler/passes/generate-js.js @@ -1079,12 +1079,7 @@ function generateJS(ast, options) { ' function error(message, location) {', ' location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos)', '', - ' throw peg$buildException(', - ' message,', - ' null,', - ' input.substring(peg$savedPos, peg$currPos),', - ' location', - ' );', + ' throw peg$buildException(message, null, null, location);', ' }', '', ' function peg$literalExpectation(text, ignoreCase) {', diff --git a/lib/parser.js b/lib/parser.js index c45129e..d6b5f9b 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -534,12 +534,7 @@ function peg$parse(input, options) { function error(message, location) { location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos) - throw peg$buildException( - message, - null, - input.substring(peg$savedPos, peg$currPos), - location - ); + throw peg$buildException(message, null, null, location); } function peg$literalExpectation(text, ignoreCase) { diff --git a/spec/behavior/generated-parser-behavior.spec.js b/spec/behavior/generated-parser-behavior.spec.js index c4c5881..8c2724f 100644 --- a/spec/behavior/generated-parser-behavior.spec.js +++ b/spec/behavior/generated-parser-behavior.spec.js @@ -1218,7 +1218,7 @@ describe("generated parser behavior", function() { expect(parser).toFailToParse("a", { message: "a", - found: "a", + found: null, expected: null, location: { start: { offset: 0, line: 1, column: 1 }, @@ -1240,7 +1240,7 @@ describe("generated parser behavior", function() { expect(parser).toFailToParse("a", { message: "a", expected: null, - found: "a", + found: null, location: { start: { offset: 1, line: 1, column: 2 }, end: { offset: 2, line: 1, column: 3 }