Skip to content

Commit f426c19

Browse files
committed
Prevent null dereference issues in the optimizer
1 parent cda06dd commit f426c19

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

optimizer.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ function getMethod (logic, engine, methodName, above) {
8383
function checkIdioms (logic, engine, above) {
8484
if (logic.reduce && Array.isArray(logic.reduce)) {
8585
let [root, mapper, defaultValue] = logic.reduce
86-
if (mapper['+'] && mapper['+'].length === 2 && mapper['+'][0].var && mapper['+'][1].var) {
86+
if (mapper['+'] && mapper['+'].length === 2 && (mapper['+'][0] || 0).var && (mapper['+'][1] || 0).var) {
8787
const accumulatorFound = mapper['+'][0].var === 'accumulator' || mapper['+'][1].var === 'accumulator'
8888
const currentFound = mapper['+'][0].var === 'current' || mapper['+'][1].var === 'current'
8989
defaultValue = defaultValue || 0
9090
if (accumulatorFound && currentFound) return optimize({ '+': [{ '+': root }, defaultValue] }, engine, above)
9191
}
92-
if (mapper['*'] && mapper['*'].length === 2 && mapper['*'][0].var && mapper['*'][1].var) {
92+
if (mapper['*'] && mapper['*'].length === 2 && (mapper['*'][0] || 0).var && (mapper['*'][1] || 0).var) {
9393
const accumulatorFound = mapper['*'][0].var === 'accumulator' || mapper['*'][1].var === 'accumulator'
9494
const currentFound = mapper['*'][0].var === 'current' || mapper['*'][1].var === 'current'
9595
defaultValue = typeof defaultValue === 'undefined' ? 1 : defaultValue

0 commit comments

Comments
 (0)