From 98da358ef4705b1e6ff3315b30f17806959bd8e9 Mon Sep 17 00:00:00 2001 From: David Majda Date: Sat, 24 Jul 2010 16:35:06 +0200 Subject: [PATCH] Found a neater trick how to defend against |undefined| redefinition --- lib/compiler.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/compiler.js b/lib/compiler.js index 575ae4a..47e2d08 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -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." );