Found a neater trick how to defend against |undefined| redefinition

redux
David Majda 14 years ago
parent c3b5c2131a
commit 98da358ef4

@ -1,6 +1,6 @@
/* PEG.js compiler. */
(function() {
(function(undefined) {
/* ===== PEG ===== */
@ -39,7 +39,7 @@ PEG.GrammarError.prototype = Error.prototype;
PEG.ArrayUtils = {
/* Like Python's |range|, but without |step|. */
range: function(start, stop) {
if (typeof(stop) === "undefined") {
if (stop === undefined) {
stop = start;
start = 0;
}
@ -193,11 +193,11 @@ PEG.Compiler = {
/\$\{([a-zA-Z_][a-zA-Z0-9_]*)(\|([a-zA-Z_][a-zA-Z0-9_]*))?\}/g,
function(match, name, dummy, filter) {
var value = vars[name];
if (typeof(value) === "undefined") {
if (value === undefined) {
throw new Error("Undefined variable: \"" + name + "\".");
}
if (typeof(filter) !== "undefined" && filter != "") { // JavaScript engines differ here.
if (filter !== undefined && filter != "") { // JavaScript engines differ here.
if (filter === "string") {
return PEG.StringUtils.quote(value);
} else {
@ -297,7 +297,7 @@ PEG.Compiler = {
rule_ref:
function(node) {
if (typeof(ast.rules[node.name]) === "undefined") {
if (ast.rules[node.name] === undefined) {
throw new PEG.GrammarError(
"Referenced rule \"" + node.name + "\" does not exist."
);

Loading…
Cancel
Save