Fix crash when extras function doesn't return an array.

Fixes #745, which failed due to attempting to call `map` on a
non-array. This bails out at the same spot, but with a more
illuminating error message.
This commit is contained in:
Patrick Thomson 2020-09-30 16:19:34 -04:00
parent e24de9d225
commit 683a2da055

View file

@ -292,7 +292,12 @@ function grammar(baseGrammar, options) {
extras = options.extras
.call(ruleBuilder, ruleBuilder, baseGrammar.extras)
.map(normalize);
if (!Array.isArray(extras)) {
throw new Error("Grammar's 'extras' function must return an array.")
}
extras = extras.map(normalize);
}
let word = baseGrammar.word;