Merge pull request #749 from tree-sitter/ensure-extras-is-array

Fix crash when extras function doesn't return an array.
This commit is contained in:
Patrick Thomson 2020-10-05 16:57:27 -04:00 committed by GitHub
commit 1f3248a3e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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;