fix(dsl): improve error message when a rule function returns undefined
This commit is contained in:
parent
12bd194937
commit
a59a530049
1 changed files with 5 additions and 1 deletions
|
|
@ -301,7 +301,11 @@ function grammar(baseGrammar, options) {
|
|||
if (typeof ruleFn !== "function") {
|
||||
throw new Error(`Grammar rules must all be functions. '${ruleName}' rule is not.`);
|
||||
}
|
||||
rules[ruleName] = normalize(ruleFn.call(ruleBuilder, ruleBuilder, baseGrammar.rules[ruleName]));
|
||||
const rule = ruleFn.call(ruleBuilder, ruleBuilder, baseGrammar.rules[ruleName]);
|
||||
if (rule === undefined) {
|
||||
throw new Error(`Rule '${ruleName}' returned undefined.`);
|
||||
}
|
||||
rules[ruleName] = normalize(rule);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue