Found a neater trick how to defend against |undefined| redefinition
This commit is contained in:
parent
c3b5c2131a
commit
98da358ef4
|
@ -1,6 +1,6 @@
|
||||||
/* PEG.js compiler. */
|
/* PEG.js compiler. */
|
||||||
|
|
||||||
(function() {
|
(function(undefined) {
|
||||||
|
|
||||||
/* ===== PEG ===== */
|
/* ===== PEG ===== */
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ PEG.GrammarError.prototype = Error.prototype;
|
||||||
PEG.ArrayUtils = {
|
PEG.ArrayUtils = {
|
||||||
/* Like Python's |range|, but without |step|. */
|
/* Like Python's |range|, but without |step|. */
|
||||||
range: function(start, stop) {
|
range: function(start, stop) {
|
||||||
if (typeof(stop) === "undefined") {
|
if (stop === undefined) {
|
||||||
stop = start;
|
stop = start;
|
||||||
start = 0;
|
start = 0;
|
||||||
}
|
}
|
||||||
|
@ -193,11 +193,11 @@ PEG.Compiler = {
|
||||||
/\$\{([a-zA-Z_][a-zA-Z0-9_]*)(\|([a-zA-Z_][a-zA-Z0-9_]*))?\}/g,
|
/\$\{([a-zA-Z_][a-zA-Z0-9_]*)(\|([a-zA-Z_][a-zA-Z0-9_]*))?\}/g,
|
||||||
function(match, name, dummy, filter) {
|
function(match, name, dummy, filter) {
|
||||||
var value = vars[name];
|
var value = vars[name];
|
||||||
if (typeof(value) === "undefined") {
|
if (value === undefined) {
|
||||||
throw new Error("Undefined variable: \"" + name + "\".");
|
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") {
|
if (filter === "string") {
|
||||||
return PEG.StringUtils.quote(value);
|
return PEG.StringUtils.quote(value);
|
||||||
} else {
|
} else {
|
||||||
|
@ -297,7 +297,7 @@ PEG.Compiler = {
|
||||||
|
|
||||||
rule_ref:
|
rule_ref:
|
||||||
function(node) {
|
function(node) {
|
||||||
if (typeof(ast.rules[node.name]) === "undefined") {
|
if (ast.rules[node.name] === undefined) {
|
||||||
throw new PEG.GrammarError(
|
throw new PEG.GrammarError(
|
||||||
"Referenced rule \"" + node.name + "\" does not exist."
|
"Referenced rule \"" + node.name + "\" does not exist."
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue