Do not modify |options| passed to |PEG.buildParser|

Modifying |options| can lead to subtle bugs.
redux
David Majda 12 years ago
parent 75a78c083c
commit 6a1ec7631f

@ -1,12 +1,10 @@
/* Generates the parser code. */ /* Generates the parser code. */
PEG.compiler.passes.generateCode = function(ast, options) { PEG.compiler.passes.generateCode = function(ast, options) {
options = options || {}; options = clone(options) || {};
if (options.cache === undefined) { defaults(options, {
options.cache = false; cache: false,
} trackLineAndColumn: false
if (options.trackLineAndColumn === undefined) { });
options.trackLineAndColumn = false;
}
/* /*
* Codie 1.1.0 * Codie 1.1.0

@ -71,6 +71,22 @@ function values(object) {
return result; return result;
} }
function clone(object) {
var result = {};
for (var key in object) {
result[key] = object[key];
}
return result;
}
function defaults(object, defaults) {
for (var key in defaults) {
if (object[key] === undefined) {
object[key] = defaults[key];
}
}
}
/* /*
* Returns a string padded on the left to a desired length with a character. * Returns a string padded on the left to a desired length with a character.
* *

Loading…
Cancel
Save