Browse Source

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

Modifying |options| can lead to subtle bugs.
redux
David Majda 9 years ago
parent
commit
6a1ec7631f
  1. 12
      src/compiler/passes/generate-code.js
  2. 16
      src/utils.js

12
src/compiler/passes/generate-code.js

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

16
src/utils.js

@ -71,6 +71,22 @@ function values(object) {
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.
*

Loading…
Cancel
Save