From 683a2da055ca223098298fae27b729dbcf13f69e Mon Sep 17 00:00:00 2001 From: Patrick Thomson Date: Wed, 30 Sep 2020 16:19:34 -0400 Subject: [PATCH] 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. --- cli/src/generate/dsl.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cli/src/generate/dsl.js b/cli/src/generate/dsl.js index 55594871..62fb1d70 100644 --- a/cli/src/generate/dsl.js +++ b/cli/src/generate/dsl.js @@ -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;